@salla.sa/base 1.6.13 → 1.6.15-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,4345 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("process")):"function"==typeof define&&define.amd?define(["exports","process"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Salla={},e.process)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t);function i(e,t=!1){e+="";let r,n=["٠","١","٢","٣","٤","٥","٦","٧","٨","٩"],i=["0","1","2","3","4","5","6","7","8","9"],o=(t=t||!Salla.config.get("store.settings.arabic_numbers_enabled"))?n:i,s=t?i:n;for(let t=0;t<o.length;t++)r=new RegExp(o[t],"g"),e=e.replace(r,s[t]);return e}function o(e){let t=(e.match(/\./g)||[]).length;return t&&1!==t?o(e.replace(/\.(.+)\./g,".$1")):e}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a=Array.isArray,l="object"==typeof s&&s&&s.Object===Object&&s,c="object"==typeof self&&self&&self.Object===Object&&self,u=l||c||Function("return this")(),f=u.Symbol,h=f,p=Object.prototype,d=p.hasOwnProperty,v=p.toString,y=h?h.toStringTag:void 0;var g=function(e){var t=d.call(e,y),r=e[y];try{e[y]=void 0;var n=!0}catch(e){}var i=v.call(e);return n&&(t?e[y]=r:delete e[y]),i},_=Object.prototype.toString;var m=g,b=function(e){return _.call(e)},w=f?f.toStringTag:void 0;var L=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":w&&w in Object(e)?m(e):b(e)};var S=L,j=function(e){return null!=e&&"object"==typeof e};var E=function(e){return"symbol"==typeof e||j(e)&&"[object Symbol]"==S(e)},x=a,k=E,O=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,A=/^\w*$/;var T=function(e,t){if(x(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!k(e))||(A.test(e)||!O.test(e)||null!=t&&e in Object(t))};var P=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},F=L,$=P;var N,M=function(e){if(!$(e))return!1;var t=F(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},z=u["__core-js_shared__"],R=(N=/[^.]+$/.exec(z&&z.keys&&z.keys.IE_PROTO||""))?"Symbol(src)_1."+N:"";var I=function(e){return!!R&&R in e},C=Function.prototype.toString;var U=M,D=I,G=P,W=function(e){if(null!=e){try{return C.call(e)}catch(e){}try{return e+""}catch(e){}}return""},J=/^\[object .+?Constructor\]$/,q=Function.prototype,H=Object.prototype,K=q.toString,B=H.hasOwnProperty,Z=RegExp("^"+K.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Q=function(e){return!(!G(e)||D(e))&&(U(e)?Z:J).test(W(e))},V=function(e,t){return null==e?void 0:e[t]};var X=function(e,t){var r=V(e,t);return Q(r)?r:void 0},Y=X(Object,"create"),ee=Y;var te=function(){this.__data__=ee?ee(null):{},this.size=0};var re=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},ne=Y,ie=Object.prototype.hasOwnProperty;var oe=function(e){var t=this.__data__;if(ne){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return ie.call(t,e)?t[e]:void 0},se=Y,ae=Object.prototype.hasOwnProperty;var le=Y;var ce=te,ue=re,fe=oe,he=function(e){var t=this.__data__;return se?void 0!==t[e]:ae.call(t,e)},pe=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=le&&void 0===t?"__lodash_hash_undefined__":t,this};function de(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}de.prototype.clear=ce,de.prototype.delete=ue,de.prototype.get=fe,de.prototype.has=he,de.prototype.set=pe;var ve=de;var ye=function(){this.__data__=[],this.size=0};var ge=function(e,t){return e===t||e!=e&&t!=t};var _e=function(e,t){for(var r=e.length;r--;)if(ge(e[r][0],t))return r;return-1},me=_e,be=Array.prototype.splice;var we=_e;var Le=_e;var Se=_e;var je=ye,Ee=function(e){var t=this.__data__,r=me(t,e);return!(r<0)&&(r==t.length-1?t.pop():be.call(t,r,1),--this.size,!0)},xe=function(e){var t=this.__data__,r=we(t,e);return r<0?void 0:t[r][1]},ke=function(e){return Le(this.__data__,e)>-1},Oe=function(e,t){var r=this.__data__,n=Se(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};function Ae(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Ae.prototype.clear=je,Ae.prototype.delete=Ee,Ae.prototype.get=xe,Ae.prototype.has=ke,Ae.prototype.set=Oe;var Te=Ae,Pe=X(u,"Map"),Fe=ve,$e=Te,Ne=Pe;var Me=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var ze=function(e,t){var r=e.__data__;return Me(t)?r["string"==typeof t?"string":"hash"]:r.map},Re=ze;var Ie=ze;var Ce=ze;var Ue=ze;var De=function(){this.size=0,this.__data__={hash:new Fe,map:new(Ne||$e),string:new Fe}},Ge=function(e){var t=Re(this,e).delete(e);return this.size-=t?1:0,t},We=function(e){return Ie(this,e).get(e)},Je=function(e){return Ce(this,e).has(e)},qe=function(e,t){var r=Ue(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function He(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}He.prototype.clear=De,He.prototype.delete=Ge,He.prototype.get=We,He.prototype.has=Je,He.prototype.set=qe;var Ke=He;function Be(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=t?t.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=e.apply(this,n);return r.cache=o.set(i,s)||o,s};return r.cache=new(Be.Cache||Ke),r}Be.Cache=Ke;var Ze=Be;var Qe=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ve=/\\(\\)?/g,Xe=function(e){var t=Ze(e,(function(e){return 500===r.size&&r.clear(),e})),r=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(Qe,(function(e,r,n,i){t.push(n?i.replace(Ve,"$1"):r||e)})),t})),Ye=Xe;var et=function(e,t){for(var r=-1,n=null==e?0:e.length,i=Array(n);++r<n;)i[r]=t(e[r],r,e);return i},tt=a,rt=E,nt=f?f.prototype:void 0,it=nt?nt.toString:void 0;var ot=function e(t){if("string"==typeof t)return t;if(tt(t))return et(t,e)+"";if(rt(t))return it?it.call(t):"";var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r},st=ot;var at=a,lt=T,ct=Ye,ut=function(e){return null==e?"":st(e)};var ft=E;var ht=function(e,t){return at(e)?e:lt(e,t)?[e]:ct(ut(e))},pt=function(e){if("string"==typeof e||ft(e))return e;var t=e+"";return"0"==t&&1/e==-Infinity?"-0":t};var dt=function(e,t){for(var r=0,n=(t=ht(t,e)).length;null!=e&&r<n;)e=e[pt(t[r++])];return r&&r==n?e:void 0};var vt=function(e,t,r){var n=null==e?void 0:dt(e,t);return void 0===n?r:n};function yt(e,t,r){let n=e[0];return r&&0==e.length?Array.isArray(r)?(r.push(t),r):[r,t]:Array.isArray(r)?(r.push(t),r):"string"==typeof r?[r,t]:r?(r[n]=yt(e.slice(1),t,r[n]),r):n?{[n]:yt(e.slice(1),t)}:""===n?[t]:t}function gt(e){return Salla.config.get("store.url",window.location.href.split("/").slice(0,-1).join("/")).rtrim("/")+"/"+e.ltrim("/")}var _t={digitsOnly:function(e){return i(e,!0).replace(/[^0-9.]/g,"").replace("..",".").rtrim(".")},inputDigitsOnly:function e(t,r=!1){if("string"==typeof t)return document.querySelectorAll(t).forEach((t=>e(t,r)));if(!t)return void Salla.logger.warn("Can't find Object With Id: "+t);let n=Salla.helpers.digitsOnly(t.value);return t.min&&n<t.min?t.value=t.min:t.max&&n>t.max?t.value=t.max:t.maxLength>=1&&n.toString().length>t.maxLength?t.value=n.toString().substring(0,t.maxLength):t.value=r||t.dataset.hasOwnProperty("digitsWithDecimal")?o(n):n.replace(/\D/g,"")},number:i,money:function(e){return i(e?.amount|e)+" "+Salla.config.currency(e?.currency).symbol},setNested:function(e,t,r){let n=e,i=t.split("."),o=i.length;for(let e=0;e<o-1;e++){let t=i[e];n[t]||(n[t]={}),n=n[t]}return n[i[o-1]]=r,e},getNested:function(e,t,r){let n=vt(e,t);return void 0!==n?n:r},inputData:function(e,t,r={}){if(e.includes("[")){let n=e.split("]").join("").split("[");return{name:n[0],value:yt(n.slice(1),t,r[n[0]])}}return{name:e,value:t}},url:{get:gt,asset:function(e){return function(e){return window.location.origin+"/"+e.ltrim("/")}("themes/"+Salla.config.get("theme.name")+"/"+e.ltrim("/"))},cdn:function(e){return"https://cdn.salla.network/"+e.ltrim("/")},is_page:function(e){return e&&Salla.config.get("page.slug")===e},api:function(e){return Salla.config.get("store.api",gt("")).rtrim("/")+"/"+e.ltrim("/")}},addParamToUrl:function(e,t){if(!t||!e)return window.location.href;let r=new RegExp("([?&])"+e+"=[^&]+[&]?","g"),n=window.location.href.replace(r,"$1").replace(/&$|\?$/,"");return n+=(n.includes("?")?"&":"?")+e+"="+encodeURIComponent(t),n.replace(/&$|\?$/,"")},debounce:function(e,t){t=t||100;let r,n=[];return function(...i){return clearTimeout(r),r=setTimeout((()=>{let t=e(...i);n.forEach((e=>e(t))),n=[]}),t),new Promise((e=>n.push(e)))}}},mt=function(e){let t={log:function(t,r){if(!e)return;"trace"===salla.config.get("debug")&&(r="trace");let n=e.log,i=void 0===r?n:this.__dict__[r]||n,o=["%cTwilight","color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;"],s={event:"#CFF680",backend:"#7b68ee"}[r];s&&(o[0]+="%c"+r[0].toUpperCase()+r.substring(1),o.push(`margin-left: 5px;color: ${s};font-weight:bold; border:1px solid ${s}; padding: 2px 6px; border-radius: 5px;`)),i.call(e,...o.concat(...t))},__dict__:{trace:e.trace,debug:e.debug,info:e.info,warn:e.warn,error:e.error}};return{event:function(){t.log(arguments,"event")},trace:function(){t.log(arguments,"trace")},debug:function(){t.log(arguments,"debug")},info:function(){t.log(arguments,"info")},warn:function(){t.log(arguments,"warn")},error:function(){t.log(arguments,"error")},log:function(){t.log(arguments,void 0)},backend:function(){t.log(arguments,"backend")},logs:function(e){[e].flat().forEach((e=>e&&t.log([e].flat(),"backend")))}}}(console);var bt={exports:{}};!function(e,t){!function(t){var r=Object.hasOwnProperty,i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},o="object"==typeof n.default&&"function"==typeof n.default.nextTick,s="function"==typeof Symbol,a="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,c=s?a&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function u(){this._events={},this._conf&&f.call(this,this._conf)}function f(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function h(e,t){var r="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(r+=" Event name: "+t+"."),void 0!==n.default&&n.default.emitWarning){var i=new Error(r);i.name="MaxListenersExceededWarning",i.emitter=this,i.count=e,n.default.emitWarning(i)}else console.error(r),console.trace&&console.trace()}var p=function(e,t,r){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,r];default:for(var i=new Array(n);n--;)i[n]=arguments[n];return i}};function d(e,r){for(var n={},i=e.length,o=r?r.length:0,s=0;s<i;s++)n[e[s]]=s<o?r[s]:t;return n}function v(e,t,r){var n,i;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(r.on||r.off)&&(n=r.on,i=r.off),t.addEventListener?(n=t.addEventListener,i=t.removeEventListener):t.addListener?(n=t.addListener,i=t.removeListener):t.on&&(n=t.on,i=t.off),!n&&!i)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof i)throw TypeError("off method must be a function");this._on=n,this._off=i;var o=e._observers;o?o.push(this):e._observers=[this]}function y(e,n,i,o){var s=Object.assign({},n);if(!e)return s;if("object"!=typeof e)throw TypeError("options must be an object");var a,l,c,u=Object.keys(e),f=u.length;function h(e){throw Error('Invalid "'+a+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(a=u[p],!o&&!r.call(n,a))throw Error('Unknown "'+a+'" option');(l=e[a])!==t&&(c=i[a],s[a]=c?c(l,h):l)}return s}function g(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),r=e.length,n=e[0],i=e[1];return 1===r?function(e,r){if(typeof e===n)return e;r(t)}:2===r?function(e,r){var o=typeof e;if(o===n||o===i)return e;r(t)}:function(n,i){for(var o=typeof n,s=r;s-- >0;)if(o===e[s])return n;i(t)}}Object.assign(v.prototype,{subscribe:function(e,t,r){var n=this,i=this._target,o=this._emitter,s=this._listeners,a=function(){var n=p.apply(null,arguments),s={data:n,name:t,original:e};if(r){var a=r.call(i,s);!1!==a&&o.emit.apply(o,[s.name].concat(n))}else o.emit.apply(o,[t].concat(n))};if(s[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,o._newListener&&o._removeListener&&!n._onNewListener?(this._onNewListener=function(r){r===t&&null===s[e]&&(s[e]=a,n._on.call(i,e,a))},o.on("newListener",this._onNewListener),this._onRemoveListener=function(r){r===t&&!o.hasListeners(r)&&s[e]&&(s[e]=null,n._off.call(i,e,a))},s[e]=null,o.on("removeListener",this._onRemoveListener)):(s[e]=a,n._on.call(i,e,a))},unsubscribe:function(e){var t,r,n,i=this,o=this._listeners,s=this._emitter,a=this._off,l=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function u(){i._onNewListener&&(s.off("newListener",i._onNewListener),s.off("removeListener",i._onRemoveListener),i._onNewListener=null,i._onRemoveListener=null);var e=L.call(s,i);s._observers.splice(e,1)}if(e){if(!(t=o[e]))return;a.call(l,e,t),delete o[e],--this._listenersCount||u()}else{for(n=(r=c(o)).length;n-- >0;)e=r[n],a.call(l,e,o[e]);this._listeners={},this._listenersCount=0,u()}}});var m=_(["function"]),b=_(["object","function"]);function w(e,t,r){var n,i,o,s=0,a=new e((function(l,c,u){function f(){i&&(i=null),s&&(clearTimeout(s),s=0)}r=y(r,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!r.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof u;var h=function(e){f(),l(e)},p=function(e){f(),c(e)};n?t(h,p,u):(i=[function(e){p(e||Error("canceled"))}],t(h,p,(function(e){if(o)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");i.push(e)})),o=!0),r.timeout>0&&(s=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",s=0,a.cancel(e),c(e)}),r.timeout))}));return n||(a.cancel=function(e){if(i){for(var t=i.length,r=1;r<t;r++)i[r](e);i[0](e),i=null}}),a}function L(e){var t=this._observers;if(!t)return-1;for(var r=t.length,n=0;n<r;n++)if(t[n]._target===e)return n;return-1}function S(e,t,r,n,i){if(!r)return null;if(0===n){var o=typeof t;if("string"===o){var s,a,l=0,u=0,f=this.delimiter,h=f.length;if(-1!==(a=t.indexOf(f))){s=new Array(5);do{s[l++]=t.slice(u,a),u=a+h}while(-1!==(a=t.indexOf(f,u)));s[l++]=t.slice(u),t=s,i=l}else t=[t],i=1}else"object"===o?i=t.length:(t=[t],i=1)}var p,d,v,y,g,_,m,b=null,w=t[n],L=t[n+1];if(n===i)r._listeners&&("function"==typeof r._listeners?(e&&e.push(r._listeners),b=[r]):(e&&e.push.apply(e,r._listeners),b=[r]));else{if("*"===w){for(a=(_=c(r)).length;a-- >0;)"_listeners"!==(p=_[a])&&(m=S(e,t,r[p],n+1,i))&&(b?b.push.apply(b,m):b=m);return b}if("**"===w){for((g=n+1===i||n+2===i&&"*"===L)&&r._listeners&&(b=S(e,t,r,i,i)),a=(_=c(r)).length;a-- >0;)"_listeners"!==(p=_[a])&&("*"===p||"**"===p?(r[p]._listeners&&!g&&(m=S(e,t,r[p],i,i))&&(b?b.push.apply(b,m):b=m),m=S(e,t,r[p],n,i)):m=S(e,t,r[p],p===L?n+2:n,i),m&&(b?b.push.apply(b,m):b=m));return b}r[w]&&(b=S(e,t,r[w],n+1,i))}if((d=r["*"])&&S(e,t,d,n+1,i),v=r["**"])if(n<i)for(v._listeners&&S(e,t,v,i,i),a=(_=c(v)).length;a-- >0;)"_listeners"!==(p=_[a])&&(p===L?S(e,t,v[p],n+2,i):p===w?S(e,t,v[p],n+1,i):((y={})[p]=v[p],S(e,t,{"**":y},n+1,i)));else v._listeners?S(e,t,v,i,i):v["*"]&&v["*"]._listeners&&S(e,t,v["*"],i,i);return b}function j(e,t,r){var n,i,o=0,s=0,a=this.delimiter,l=a.length;if("string"==typeof e)if(-1!==(n=e.indexOf(a))){i=new Array(5);do{i[o++]=e.slice(s,n),s=n+l}while(-1!==(n=e.indexOf(a,s)));i[o++]=e.slice(s)}else i=[e],o=1;else i=e,o=e.length;if(o>1)for(n=0;n+1<o;n++)if("**"===i[n]&&"**"===i[n+1])return;var c,u=this.listenerTree;for(n=0;n<o;n++)if(u=u[c=i[n]]||(u[c]={}),n===o-1)return u._listeners?("function"==typeof u._listeners&&(u._listeners=[u._listeners]),r?u._listeners.unshift(t):u._listeners.push(t),!u._listeners.warned&&this._maxListeners>0&&u._listeners.length>this._maxListeners&&(u._listeners.warned=!0,h.call(this,u._listeners.length,c))):u._listeners=t,!0;return!0}function E(e,t,r,n){for(var i,o,s,a,l=c(e),u=l.length,f=e._listeners;u-- >0;)i=e[o=l[u]],s="_listeners"===o?r:r?r.concat(o):[o],a=n||"symbol"==typeof o,f&&t.push(a?s:s.join(this.delimiter)),"object"==typeof i&&E.call(this,i,t,s,a);return t}function x(e){for(var t,r,n,i=c(e),o=i.length;o-- >0;)(t=e[r=i[o]])&&(n=!0,"_listeners"===r||x(t)||delete e[r]);return n}function k(e,t,r){this.emitter=e,this.event=t,this.listener=r}function O(e,r,i){if(!0===i)a=!0;else if(!1===i)s=!0;else{if(!i||"object"!=typeof i)throw TypeError("options should be an object or true");var s=i.async,a=i.promisify,c=i.nextTick,u=i.objectify}if(s||c||a){var f=r,h=r._origin||r;if(c&&!o)throw Error("process.nextTick is not supported");a===t&&(a="AsyncFunction"===r.constructor.name),r=function(){var e=arguments,t=this,r=this.event;return a?c?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=r,f.apply(t,e)})):(c?n.default.nextTick:l)((function(){t.event=r,f.apply(t,e)}))},r._async=!0,r._origin=h}return[r,u?new k(this,e,r):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,f.call(this,e)}k.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,r,n){if("object"!=typeof e)throw TypeError("target musts be an object");var o=this;function s(t){if("object"!=typeof t)throw TypeError("events must be an object");var r,i=n.reducers,s=L.call(o,e);r=-1===s?new v(o,e,n):o._observers[s];for(var a,l=c(t),u=l.length,f="function"==typeof i,h=0;h<u;h++)a=l[h],r.subscribe(a,t[a]||a,f?i:i&&i[a])}return n=y(n,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),i(r)?s(d(r)):s("string"==typeof r?d(r.split(/\s+/)):r),this},A.prototype.stopListeningTo=function(e,t){var r=this._observers;if(!r)return!1;var n,i=r.length,o=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;i-- >0;)n=r[i],e&&n._target!==e||(n.unsubscribe(t),o=!0);return o},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,r){return this._once(e,t,!1,r)},A.prototype.prependOnceListener=function(e,t,r){return this._once(e,t,!0,r)},A.prototype._once=function(e,t,r,n){return this._many(e,1,t,r,n)},A.prototype.many=function(e,t,r,n){return this._many(e,t,r,!1,n)},A.prototype.prependMany=function(e,t,r,n){return this._many(e,t,r,!0,n)},A.prototype._many=function(e,t,r,n,i){var o=this;if("function"!=typeof r)throw new Error("many only accepts instances of Function");function s(){return 0==--t&&o.off(e,s),r.apply(this,arguments)}return s._origin=r,this._on(e,s,n,i)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||u.call(this);var e,t,r,n,i,o,a=arguments[0],l=this.wildcard;if("newListener"===a&&!this._newListener&&!this._events.newListener)return!1;if(l&&(e=a,"newListener"!==a&&"removeListener"!==a&&"object"==typeof a)){if(r=a.length,s)for(n=0;n<r;n++)if("symbol"==typeof a[n]){o=!0;break}o||(a=a.join(this.delimiter))}var c,f=arguments.length;if(this._all&&this._all.length)for(n=0,r=(c=this._all.slice()).length;n<r;n++)switch(this.event=a,f){case 1:c[n].call(this,a);break;case 2:c[n].call(this,a,arguments[1]);break;case 3:c[n].call(this,a,arguments[1],arguments[2]);break;default:c[n].apply(this,arguments)}if(l)c=[],S.call(this,c,e,this.listenerTree,0,r);else{if("function"==typeof(c=this._events[a])){switch(this.event=a,f){case 1:c.call(this);break;case 2:c.call(this,arguments[1]);break;case 3:c.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),i=1;i<f;i++)t[i-1]=arguments[i];c.apply(this,t)}return!0}c&&(c=c.slice())}if(c&&c.length){if(f>3)for(t=new Array(f-1),i=1;i<f;i++)t[i-1]=arguments[i];for(n=0,r=c.length;n<r;n++)switch(this.event=a,f){case 1:c[n].call(this);break;case 2:c[n].call(this,arguments[1]);break;case 3:c[n].call(this,arguments[1],arguments[2]);break;default:c[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===a)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||u.call(this);var e,t,r,n,i,o,a=arguments[0],l=this.wildcard;if("newListener"===a&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(l&&(e=a,"newListener"!==a&&"removeListener"!==a&&"object"==typeof a)){if(n=a.length,s)for(i=0;i<n;i++)if("symbol"==typeof a[i]){t=!0;break}t||(a=a.join(this.delimiter))}var c,f=[],h=arguments.length;if(this._all)for(i=0,n=this._all.length;i<n;i++)switch(this.event=a,h){case 1:f.push(this._all[i].call(this,a));break;case 2:f.push(this._all[i].call(this,a,arguments[1]));break;case 3:f.push(this._all[i].call(this,a,arguments[1],arguments[2]));break;default:f.push(this._all[i].apply(this,arguments))}if(l?(c=[],S.call(this,c,e,this.listenerTree,0)):c=this._events[a],"function"==typeof c)switch(this.event=a,h){case 1:f.push(c.call(this));break;case 2:f.push(c.call(this,arguments[1]));break;case 3:f.push(c.call(this,arguments[1],arguments[2]));break;default:for(r=new Array(h-1),o=1;o<h;o++)r[o-1]=arguments[o];f.push(c.apply(this,r))}else if(c&&c.length){if(c=c.slice(),h>3)for(r=new Array(h-1),o=1;o<h;o++)r[o-1]=arguments[o];for(i=0,n=c.length;i<n;i++)switch(this.event=a,h){case 1:f.push(c[i].call(this));break;case 2:f.push(c[i].call(this,arguments[1]));break;case 3:f.push(c[i].call(this,arguments[1],arguments[2]));break;default:f.push(c[i].apply(this,r))}}else if(!this.ignoreErrors&&!this._all&&"error"===a)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,r){return this._on(e,t,!1,r)},A.prototype.prependListener=function(e,t,r){return this._on(e,t,!0,r)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,r,n,i){if("function"==typeof e)return this._onAny(e,r),this;if("function"!=typeof r)throw new Error("on only accepts instances of Function");this._events||u.call(this);var o,s=this;return i!==t&&(r=(o=O.call(this,e,r,i))[0],s=o[1]),this._newListener&&this.emit("newListener",e,r),this.wildcard?(j.call(this,e,r,n),s):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(r):this._events[e].push(r),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,h.call(this,this._events[e].length,e))):this._events[e]=r,s)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var r,n=[];if(this.wildcard){var o="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=S.call(this,null,o,this.listenerTree,0)))return this}else{if(!this._events[e])return this;r=this._events[e],n.push({_listeners:r})}for(var s=0;s<n.length;s++){var a=n[s];if(r=a._listeners,i(r)){for(var l=-1,c=0,u=r.length;c<u;c++)if(r[c]===t||r[c].listener&&r[c].listener===t||r[c]._origin&&r[c]._origin===t){l=c;break}if(l<0)continue;return this.wildcard?a._listeners.splice(l,1):this._events[e].splice(l,1),0===r.length&&(this.wildcard?delete a._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(r===t||r.listener&&r.listener===t||r._origin&&r._origin===t)&&(this.wildcard?delete a._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&x(this.listenerTree),this},A.prototype.offAny=function(e){var t,r=0,n=0;if(e&&this._all&&this._all.length>0){for(r=0,n=(t=this._all).length;r<n;r++)if(e===t[r])return t.splice(r,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(r=0,n=t.length;r<n;r++)this.emit("removeListenerAny",t[r]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||u.call(this),this;if(this.wildcard){var r,n=S.call(this,null,e,this.listenerTree,0);if(!n)return this;for(r=0;r<n.length;r++)n[r]._listeners=null;this.listenerTree&&x(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var r,n,i,o,s,a=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!a)return[];for(o=(r=c(a)).length,i=[];o-- >0;)"function"==typeof(n=a[r[o]])?i.push(n):i.push.apply(i,n);return i}if(this.wildcard){if(!(s=this.listenerTree))return[];var l=[],u="string"==typeof e?e.split(this.delimiter):e.slice();return S.call(this,l,u,s,0),l}return a&&(n=a[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?E.call(this,this.listenerTree,[],null,e):t?c(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var r=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return S.call(this,r,n,this.listenerTree,0),r.length>0}var i=this._events,o=this._all;return!!(o&&o.length||i&&(e===t?c(i).length:i[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,r){var n=this,i=typeof r;return"number"===i?r={timeout:r}:"function"===i&&(r={filter:r}),w((r=y(r,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:g})).Promise,(function(t,i,o){function s(){var o=r.filter;if(!o||o.apply(n,arguments))if(n.off(e,s),r.handleError){var a=arguments[0];a?i(a):t(p.apply(null,arguments).slice(1))}else t(p.apply(null,arguments))}o((function(){n.off(e,s)})),n._on(e,s,!1)}),{timeout:r.timeout,overload:r.overload})};var T=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return T._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");T._maxListeners=e},enumerable:!0},once:{value:function(e,t,r){return w((r=y(r,{Promise:Promise,timeout:0,overload:!1},{Promise:g})).Promise,(function(r,n,i){var o;if("function"==typeof e.addEventListener)return o=function(){r(p.apply(null,arguments))},i((function(){e.removeEventListener(t,o)})),void e.addEventListener(t,o,{once:!0});var s,a=function(){s&&e.removeListener("error",s),r(p.apply(null,arguments))};"error"!==t&&(s=function(r){e.removeListener(t,a),n(r)},e.once("error",s)),i((function(){s&&e.removeListener("error",s),e.removeListener(t,a)})),e.once(t,a)}),{timeout:r.timeout,overload:r.overload})},writable:!0,configurable:!0}}),Object.defineProperties(T,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}()}(bt);var wt=bt.exports;var Lt=Object.assign?Object.assign:function(e,t,r,n){for(var i=1;i<arguments.length;i++)Ot(Object(arguments[i]),(function(t,r){e[r]=t}));return e},St=function(){if(Object.create)return function(e,t,r,n){var i=kt(arguments,1);return Lt.apply(this,[Object.create(e)].concat(i))};{function e(){}return function(t,r,n,i){var o=kt(arguments,1);return e.prototype=t,Lt.apply(this,[new e].concat(o))}}}(),jt=String.prototype.trim?function(e){return String.prototype.trim.call(e)}:function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},Et="undefined"!=typeof window?window:s,xt={assign:Lt,create:St,trim:jt,bind:function(e,t){return function(){return t.apply(e,Array.prototype.slice.call(arguments,0))}},slice:kt,each:Ot,map:function(e,t){var r=Tt(e)?[]:{};return At(e,(function(e,n){return r[n]=t(e,n),!1})),r},pluck:At,isList:Tt,isFunction:function(e){return e&&"[object Function]"==={}.toString.call(e)},isObject:function(e){return e&&"[object Object]"==={}.toString.call(e)},Global:Et};function kt(e,t){return Array.prototype.slice.call(e,t||0)}function Ot(e,t){At(e,(function(e,r){return t(e,r),!1}))}function At(e,t){if(Tt(e)){for(var r=0;r<e.length;r++)if(t(e[r],r))return e[r]}else for(var n in e)if(e.hasOwnProperty(n)&&t(e[n],n))return e[n]}function Tt(e){return null!=e&&"function"!=typeof e&&"number"==typeof e.length}var Pt=xt.slice,Ft=xt.pluck,$t=xt.each,Nt=xt.bind,Mt=xt.create,zt=xt.isList,Rt=xt.isFunction,It=xt.isObject,Ct={createStore:Dt},Ut={version:"2.0.12",enabled:!1,get:function(e,t){var r=this.storage.read(this._namespacePrefix+e);return this._deserialize(r,t)},set:function(e,t){return void 0===t?this.remove(e):(this.storage.write(this._namespacePrefix+e,this._serialize(t)),t)},remove:function(e){this.storage.remove(this._namespacePrefix+e)},each:function(e){var t=this;this.storage.each((function(r,n){e.call(t,t._deserialize(r),(n||"").replace(t._namespaceRegexp,""))}))},clearAll:function(){this.storage.clearAll()},hasNamespace:function(e){return this._namespacePrefix=="__storejs_"+e+"_"},createStore:function(){return Dt.apply(this,arguments)},addPlugin:function(e){this._addPlugin(e)},namespace:function(e){return Dt(this.storage,this.plugins,e)}};function Dt(e,t,r){r||(r=""),e&&!zt(e)&&(e=[e]),t&&!zt(t)&&(t=[t]);var n=r?"__storejs_"+r+"_":"",i=r?new RegExp("^"+n):null;if(!/^[a-zA-Z0-9_\-]*$/.test(r))throw new Error("store.js namespaces can only have alphanumerics + underscores and dashes");var o={_namespacePrefix:n,_namespaceRegexp:i,_testStorage:function(e){try{var t="__storejs__test__";e.write(t,t);var r=e.read(t)===t;return e.remove(t),r}catch(e){return!1}},_assignPluginFnProp:function(e,t){var r=this[t];this[t]=function(){var t=Pt(arguments,0),n=this;function i(){if(r)return $t(arguments,(function(e,r){t[r]=e})),r.apply(n,t)}var o=[i].concat(t);return e.apply(n,o)}},_serialize:function(e){return JSON.stringify(e)},_deserialize:function(e,t){if(!e)return t;var r="";try{r=JSON.parse(e)}catch(t){r=e}return void 0!==r?r:t},_addStorage:function(e){this.enabled||this._testStorage(e)&&(this.storage=e,this.enabled=!0)},_addPlugin:function(e){var t=this;if(zt(e))$t(e,(function(e){t._addPlugin(e)}));else if(!Ft(this.plugins,(function(t){return e===t}))){if(this.plugins.push(e),!Rt(e))throw new Error("Plugins must be function values that return objects");var r=e.call(this);if(!It(r))throw new Error("Plugins must return an object of function properties");$t(r,(function(r,n){if(!Rt(r))throw new Error("Bad plugin property: "+n+" from plugin "+e.name+". Plugins should only return functions.");t._assignPluginFnProp(r,n)}))}},addStorage:function(e){!function(){var e="undefined"==typeof console?null:console;if(e){(e.warn?e.warn:e.log).apply(e,arguments)}}("store.addStorage(storage) is deprecated. Use createStore([storages])"),this._addStorage(e)}},s=Mt(o,Ut,{plugins:[]});return s.raw={},$t(s,(function(e,t){Rt(e)&&(s.raw[t]=Nt(s,e))})),$t(e,(function(e){s._addStorage(e)})),$t(t,(function(e){s._addPlugin(e)})),s}var Gt=xt.Global,Wt={name:"localStorage",read:qt,write:function(e,t){return Jt().setItem(e,t)},each:function(e){for(var t=Jt().length-1;t>=0;t--){var r=Jt().key(t);e(qt(r),r)}},remove:function(e){return Jt().removeItem(e)},clearAll:function(){return Jt().clear()}};function Jt(){return Gt.localStorage}function qt(e){return Jt().getItem(e)}var Ht=xt.Global,Kt={name:"sessionStorage",read:Zt,write:function(e,t){return Bt().setItem(e,t)},each:function(e){for(var t=Bt().length-1;t>=0;t--){var r=Bt().key(t);e(Zt(r),r)}},remove:function(e){return Bt().removeItem(e)},clearAll:function(){return Bt().clear()}};function Bt(){return Ht.sessionStorage}function Zt(e){return Bt().getItem(e)}var Qt=xt.trim,Vt={name:"cookieStorage",read:function(e){if(!e||!tr(e))return null;var t="(?:^|.*;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(Xt.cookie.replace(new RegExp(t),"$1"))},write:function(e,t){if(!e)return;Xt.cookie=escape(e)+"="+escape(t)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:Yt,remove:er,clearAll:function(){Yt((function(e,t){er(t)}))}},Xt=xt.Global.document;function Yt(e){for(var t=Xt.cookie.split(/; ?/g),r=t.length-1;r>=0;r--)if(Qt(t[r])){var n=t[r].split("="),i=unescape(n[0]);e(unescape(n[1]),i)}}function er(e){e&&tr(e)&&(Xt.cookie=escape(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function tr(e){return new RegExp("(?:^|;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(Xt.cookie)}var rr={name:"memoryStorage",read:function(e){return nr[e]},write:function(e,t){nr[e]=t},each:function(e){for(var t in nr)nr.hasOwnProperty(t)&&e(nr[t],t)},remove:function(e){delete nr[e]},clearAll:function(e){nr={}}},nr={};const ir=Ct.createStore([Wt,Kt,Vt,rr],[]);"undefined"==typeof global?(window.salla=window.salla||window.Salla||{},window.Salla=window.salla):(global.salla=global.salla||global.Salla||{},global.Salla=global.salla),Salla.config=new class{constructor(e={},t={}){this.default_properties=t,this.properties_={...this.default_properties,...e}}merge(e){return Object.assign(this.properties_,e),this.properties_.store={...this.default_properties.store,...this.properties_.store},this}set(e,t){return e.includes(".")?(Salla.helpers.setNested(this.properties_,e,t),this):(this.properties_[e]=t,this)}get(e,t=null){return e.includes(".")?Salla.helpers.getNested(this.properties_,e,t):this.properties_.hasOwnProperty(e)?this.properties_[e]||t:t||void 0}all(){return this.properties_}},Salla.logger=mt,Salla.event=new class extends wt{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.delimiter="::","undefined"!=typeof document&&(this.body=document.querySelector("body")),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"]}createAndDispatch(e,...t){this.dispatch(e,...t)}emit(e,...t){let r=e.replace("::",".");if(!this.noneFireableActions.includes(r)&&void 0!==Salla.call&&"function"==typeof Salla.call(r))return Salla.log(`'Salla.${r}(...)' triggered using event '${e}'`),r=r.split("."),void salla[r[0]][r[1]](...t);super.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),!this.ingoreLogEvents.includes(e)&&(void 0!==Salla.config&&Salla.config.get("debug")||this.logableEvents.includes(e))&&void 0!==Salla.logger&&Salla.logger.event(e,...t),this.dispatchMobileEvent(e,{...t.values()})}dispatch(e,...t){return this.emit(e,...t)}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,r]of Object.entries(e))this.dispatch(t,r);else Salla.log("No Events To Dispatch!",e)}addListener(e,t){return this.on(e,t)}addEventListener(e,t){return this.on(e,t)}listen(e,t){return this.on(e,t)}registerGlobalListener(e,t){return this.onAny(t)}dispatchMobileEvent(e,t={}){if(!("undefined"!=typeof window&&window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){Salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){Salla.log(e,"The native context does not exist yet")}}},Salla.storage=new class{constructor(){Salla.event.on("storage::item.remove",(e=>this.remove(e))),Salla.event.on("storage::item.set",((e,t)=>this.set(e,t))),this.store=ir}set(e,t){if(e.includes(".")){let r=e.split(".")[0],n={[r]:this.store.get(r)};return n=Salla.helpers.setNested(n,e,t),this.store.set(r,n[r])}return this.store.set(e,t)}remove(e){return this.store.remove(e)}get(e,t){if(e.includes(".")){let t=e.split(".")[0];return Salla.helpers.getNested({[t]:this.store.get(t)},e)}return this.store.get(e,t)}},Salla.cookie=new class{constructor(){Salla.event.on("cookies::remove",(e=>this.remove(e))),Salla.event.on("cookies::add",((e,t)=>this.set(e,t)))}get(e){return document.cookie.split("; ").find((t=>t.startsWith(e+"=")))?.split("=")[1]}set(e,t="",r=10){let n="";if(r){let e=new Date;e.setTime(e.getTime()+24*r*60*60*1e3),n="; expires="+e.toUTCString()}return document.cookie=`${e}=${t}${n}"; path=/; secure; SameSite=Lax"`,this}remove(e){return document.cookie=`${e}=; Max-Age=0; path=/;`,this}},Salla.helpers=_t,Salla.log=Salla.logger.log,Salla.money=Salla.helpers.money,Salla.url=Salla.helpers.url,Salla.versions={base:"2.8.6-y.0"};var or=Salla;e.default=or,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ /* Version: 1.6.14 - September 17, 2022 21:53:40 */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('process')) :
4
+ typeof define === 'function' && define.amd ? define(['exports', 'process'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Salla = {}, global.process));
6
+ })(this, (function (exports, process) { 'use strict';
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var process__default = /*#__PURE__*/_interopDefaultLegacy(process);
11
+
12
+ /**
13
+ * @param num
14
+ * @param {boolean} isToEnglish
15
+ * @return {string}
16
+ */
17
+ function number(num, isToEnglish = false) {
18
+ num = num + ""; //make sure that number will be converted to string;
19
+
20
+ isToEnglish = isToEnglish || !Salla.config.get('store.settings.arabic_numbers_enabled');
21
+ let ar = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
22
+ let en = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
23
+ let find = isToEnglish ? ar : en;
24
+ let replace = isToEnglish ? en : ar;
25
+ let regex;
26
+
27
+ for (let i = 0; i < find.length; i++) {
28
+ regex = new RegExp(find[i], "g");
29
+ num = num.replace(regex, replace[i]);
30
+ }
31
+
32
+ return num;
33
+ }
34
+ /**
35
+ * when need to get digit's only from string "Jamal12Hi" => 12, or "١٢٣" => 123
36
+ * @param {string} num
37
+ * @return {string}
38
+ */
39
+
40
+ function digitsOnly(num) {
41
+ return number(num, true).replace(/[^0-9.]/g, '').replace('..', '.').rtrim('.'); // without this: `Salla.helpers.digitsOnly('١٬٦٠٠ ر.س')` => `1600.`
42
+ }
43
+ /**
44
+ * @param {HTMLInputElement|string} input - selector or input object
45
+ * @param {boolean} is_decimal
46
+ * @return {string|*|void}
47
+ */
48
+
49
+ function inputDigitsOnly(input, is_decimal = false) {
50
+ if (typeof input == 'string') {
51
+ return document.querySelectorAll(input).forEach(el => inputDigitsOnly(el, is_decimal));
52
+ }
53
+
54
+ if (!input) {
55
+ Salla.logger.warn('Can\'t find Object With Id: ' + input);
56
+ return;
57
+ }
58
+
59
+ let new_val = Salla.helpers.digitsOnly(input.value);
60
+
61
+ if (input.min && new_val < input.min) {
62
+ return input.value = input.min;
63
+ }
64
+
65
+ if (input.max && new_val > input.max) {
66
+ return input.value = input.max;
67
+ }
68
+
69
+ if (input.maxLength >= 1 && new_val.toString().length > input.maxLength) {
70
+ return input.value = new_val.toString().substring(0, input.maxLength);
71
+ }
72
+
73
+ return input.value = is_decimal || input.dataset.hasOwnProperty('digitsWithDecimal') ? getOnlyDecimal(new_val) : new_val.replace(/\D/g, '');
74
+ }
75
+ function getOnlyDecimal(value) {
76
+ let dotsCount = (value.match(/\./g) || []).length;
77
+
78
+ if (!dotsCount || dotsCount === 1) {
79
+ return value;
80
+ } // if there is more than one dotes, remove the last dot.
81
+ // Ex: 123.545.66 => 123.54566
82
+
83
+
84
+ return getOnlyDecimal(value.replace(/\.(.+)\./g, '.$1'));
85
+ }
86
+ /**
87
+ * @param {string|number|{amount: number,currency: string}} money
88
+ * @return string
89
+ */
90
+
91
+ function money(money) {
92
+ return number(money?.amount | money) + ' ' + Salla.config.currency(money?.currency).symbol;
93
+ }
94
+
95
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
96
+
97
+ /**
98
+ * Checks if `value` is classified as an `Array` object.
99
+ *
100
+ * @static
101
+ * @memberOf _
102
+ * @since 0.1.0
103
+ * @category Lang
104
+ * @param {*} value The value to check.
105
+ * @returns {boolean} Returns `true` if `value` is an array, else `false`.
106
+ * @example
107
+ *
108
+ * _.isArray([1, 2, 3]);
109
+ * // => true
110
+ *
111
+ * _.isArray(document.body.children);
112
+ * // => false
113
+ *
114
+ * _.isArray('abc');
115
+ * // => false
116
+ *
117
+ * _.isArray(_.noop);
118
+ * // => false
119
+ */
120
+ var isArray$3 = Array.isArray;
121
+ var isArray_1 = isArray$3;
122
+
123
+ /** Detect free variable `global` from Node.js. */
124
+ var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
125
+ var _freeGlobal = freeGlobal$1;
126
+
127
+ var freeGlobal = _freeGlobal;
128
+ /** Detect free variable `self`. */
129
+
130
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
131
+ /** Used as a reference to the global object. */
132
+
133
+ var root$3 = freeGlobal || freeSelf || Function('return this')();
134
+ var _root = root$3;
135
+
136
+ var root$2 = _root;
137
+ /** Built-in value references. */
138
+
139
+ var Symbol$4 = root$2.Symbol;
140
+ var _Symbol = Symbol$4;
141
+
142
+ var Symbol$3 = _Symbol;
143
+ /** Used for built-in method references. */
144
+
145
+ var objectProto$4 = Object.prototype;
146
+ /** Used to check objects for own properties. */
147
+
148
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
149
+ /**
150
+ * Used to resolve the
151
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
152
+ * of values.
153
+ */
154
+
155
+ var nativeObjectToString$1 = objectProto$4.toString;
156
+ /** Built-in value references. */
157
+
158
+ var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : undefined;
159
+ /**
160
+ * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
161
+ *
162
+ * @private
163
+ * @param {*} value The value to query.
164
+ * @returns {string} Returns the raw `toStringTag`.
165
+ */
166
+
167
+ function getRawTag$1(value) {
168
+ var isOwn = hasOwnProperty$3.call(value, symToStringTag$1),
169
+ tag = value[symToStringTag$1];
170
+
171
+ try {
172
+ value[symToStringTag$1] = undefined;
173
+ var unmasked = true;
174
+ } catch (e) {}
175
+
176
+ var result = nativeObjectToString$1.call(value);
177
+
178
+ if (unmasked) {
179
+ if (isOwn) {
180
+ value[symToStringTag$1] = tag;
181
+ } else {
182
+ delete value[symToStringTag$1];
183
+ }
184
+ }
185
+
186
+ return result;
187
+ }
188
+
189
+ var _getRawTag = getRawTag$1;
190
+
191
+ /** Used for built-in method references. */
192
+ var objectProto$3 = Object.prototype;
193
+ /**
194
+ * Used to resolve the
195
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
196
+ * of values.
197
+ */
198
+
199
+ var nativeObjectToString = objectProto$3.toString;
200
+ /**
201
+ * Converts `value` to a string using `Object.prototype.toString`.
202
+ *
203
+ * @private
204
+ * @param {*} value The value to convert.
205
+ * @returns {string} Returns the converted string.
206
+ */
207
+
208
+ function objectToString$1(value) {
209
+ return nativeObjectToString.call(value);
210
+ }
211
+
212
+ var _objectToString = objectToString$1;
213
+
214
+ var Symbol$2 = _Symbol,
215
+ getRawTag = _getRawTag,
216
+ objectToString = _objectToString;
217
+ /** `Object#toString` result references. */
218
+
219
+ var nullTag = '[object Null]',
220
+ undefinedTag = '[object Undefined]';
221
+ /** Built-in value references. */
222
+
223
+ var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : undefined;
224
+ /**
225
+ * The base implementation of `getTag` without fallbacks for buggy environments.
226
+ *
227
+ * @private
228
+ * @param {*} value The value to query.
229
+ * @returns {string} Returns the `toStringTag`.
230
+ */
231
+
232
+ function baseGetTag$2(value) {
233
+ if (value == null) {
234
+ return value === undefined ? undefinedTag : nullTag;
235
+ }
236
+
237
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
238
+ }
239
+
240
+ var _baseGetTag = baseGetTag$2;
241
+
242
+ /**
243
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
244
+ * and has a `typeof` result of "object".
245
+ *
246
+ * @static
247
+ * @memberOf _
248
+ * @since 4.0.0
249
+ * @category Lang
250
+ * @param {*} value The value to check.
251
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
252
+ * @example
253
+ *
254
+ * _.isObjectLike({});
255
+ * // => true
256
+ *
257
+ * _.isObjectLike([1, 2, 3]);
258
+ * // => true
259
+ *
260
+ * _.isObjectLike(_.noop);
261
+ * // => false
262
+ *
263
+ * _.isObjectLike(null);
264
+ * // => false
265
+ */
266
+
267
+ function isObjectLike$1(value) {
268
+ return value != null && typeof value == 'object';
269
+ }
270
+
271
+ var isObjectLike_1 = isObjectLike$1;
272
+
273
+ var baseGetTag$1 = _baseGetTag,
274
+ isObjectLike = isObjectLike_1;
275
+ /** `Object#toString` result references. */
276
+
277
+ var symbolTag = '[object Symbol]';
278
+ /**
279
+ * Checks if `value` is classified as a `Symbol` primitive or object.
280
+ *
281
+ * @static
282
+ * @memberOf _
283
+ * @since 4.0.0
284
+ * @category Lang
285
+ * @param {*} value The value to check.
286
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
287
+ * @example
288
+ *
289
+ * _.isSymbol(Symbol.iterator);
290
+ * // => true
291
+ *
292
+ * _.isSymbol('abc');
293
+ * // => false
294
+ */
295
+
296
+ function isSymbol$3(value) {
297
+ return typeof value == 'symbol' || isObjectLike(value) && baseGetTag$1(value) == symbolTag;
298
+ }
299
+
300
+ var isSymbol_1 = isSymbol$3;
301
+
302
+ var isArray$2 = isArray_1,
303
+ isSymbol$2 = isSymbol_1;
304
+ /** Used to match property names within property paths. */
305
+
306
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
307
+ reIsPlainProp = /^\w*$/;
308
+ /**
309
+ * Checks if `value` is a property name and not a property path.
310
+ *
311
+ * @private
312
+ * @param {*} value The value to check.
313
+ * @param {Object} [object] The object to query keys on.
314
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
315
+ */
316
+
317
+ function isKey$1(value, object) {
318
+ if (isArray$2(value)) {
319
+ return false;
320
+ }
321
+
322
+ var type = typeof value;
323
+
324
+ if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol$2(value)) {
325
+ return true;
326
+ }
327
+
328
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
329
+ }
330
+
331
+ var _isKey = isKey$1;
332
+
333
+ /**
334
+ * Checks if `value` is the
335
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
336
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
337
+ *
338
+ * @static
339
+ * @memberOf _
340
+ * @since 0.1.0
341
+ * @category Lang
342
+ * @param {*} value The value to check.
343
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
344
+ * @example
345
+ *
346
+ * _.isObject({});
347
+ * // => true
348
+ *
349
+ * _.isObject([1, 2, 3]);
350
+ * // => true
351
+ *
352
+ * _.isObject(_.noop);
353
+ * // => true
354
+ *
355
+ * _.isObject(null);
356
+ * // => false
357
+ */
358
+
359
+ function isObject$4(value) {
360
+ var type = typeof value;
361
+ return value != null && (type == 'object' || type == 'function');
362
+ }
363
+
364
+ var isObject_1 = isObject$4;
365
+
366
+ var baseGetTag = _baseGetTag,
367
+ isObject$3 = isObject_1;
368
+ /** `Object#toString` result references. */
369
+
370
+ var asyncTag = '[object AsyncFunction]',
371
+ funcTag = '[object Function]',
372
+ genTag = '[object GeneratorFunction]',
373
+ proxyTag = '[object Proxy]';
374
+ /**
375
+ * Checks if `value` is classified as a `Function` object.
376
+ *
377
+ * @static
378
+ * @memberOf _
379
+ * @since 0.1.0
380
+ * @category Lang
381
+ * @param {*} value The value to check.
382
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
383
+ * @example
384
+ *
385
+ * _.isFunction(_);
386
+ * // => true
387
+ *
388
+ * _.isFunction(/abc/);
389
+ * // => false
390
+ */
391
+
392
+ function isFunction$3(value) {
393
+ if (!isObject$3(value)) {
394
+ return false;
395
+ } // The use of `Object#toString` avoids issues with the `typeof` operator
396
+ // in Safari 9 which returns 'object' for typed arrays and other constructors.
397
+
398
+
399
+ var tag = baseGetTag(value);
400
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
401
+ }
402
+
403
+ var isFunction_1 = isFunction$3;
404
+
405
+ var root$1 = _root;
406
+ /** Used to detect overreaching core-js shims. */
407
+
408
+ var coreJsData$1 = root$1['__core-js_shared__'];
409
+ var _coreJsData = coreJsData$1;
410
+
411
+ var coreJsData = _coreJsData;
412
+ /** Used to detect methods masquerading as native. */
413
+
414
+ var maskSrcKey = function () {
415
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
416
+ return uid ? 'Symbol(src)_1.' + uid : '';
417
+ }();
418
+ /**
419
+ * Checks if `func` has its source masked.
420
+ *
421
+ * @private
422
+ * @param {Function} func The function to check.
423
+ * @returns {boolean} Returns `true` if `func` is masked, else `false`.
424
+ */
425
+
426
+
427
+ function isMasked$1(func) {
428
+ return !!maskSrcKey && maskSrcKey in func;
429
+ }
430
+
431
+ var _isMasked = isMasked$1;
432
+
433
+ /** Used for built-in method references. */
434
+ var funcProto$1 = Function.prototype;
435
+ /** Used to resolve the decompiled source of functions. */
436
+
437
+ var funcToString$1 = funcProto$1.toString;
438
+ /**
439
+ * Converts `func` to its source code.
440
+ *
441
+ * @private
442
+ * @param {Function} func The function to convert.
443
+ * @returns {string} Returns the source code.
444
+ */
445
+
446
+ function toSource$1(func) {
447
+ if (func != null) {
448
+ try {
449
+ return funcToString$1.call(func);
450
+ } catch (e) {}
451
+
452
+ try {
453
+ return func + '';
454
+ } catch (e) {}
455
+ }
456
+
457
+ return '';
458
+ }
459
+
460
+ var _toSource = toSource$1;
461
+
462
+ var isFunction$2 = isFunction_1,
463
+ isMasked = _isMasked,
464
+ isObject$2 = isObject_1,
465
+ toSource = _toSource;
466
+ /**
467
+ * Used to match `RegExp`
468
+ * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
469
+ */
470
+
471
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
472
+ /** Used to detect host constructors (Safari). */
473
+
474
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
475
+ /** Used for built-in method references. */
476
+
477
+ var funcProto = Function.prototype,
478
+ objectProto$2 = Object.prototype;
479
+ /** Used to resolve the decompiled source of functions. */
480
+
481
+ var funcToString = funcProto.toString;
482
+ /** Used to check objects for own properties. */
483
+
484
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
485
+ /** Used to detect if a method is native. */
486
+
487
+ var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$2).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
488
+ /**
489
+ * The base implementation of `_.isNative` without bad shim checks.
490
+ *
491
+ * @private
492
+ * @param {*} value The value to check.
493
+ * @returns {boolean} Returns `true` if `value` is a native function,
494
+ * else `false`.
495
+ */
496
+
497
+ function baseIsNative$1(value) {
498
+ if (!isObject$2(value) || isMasked(value)) {
499
+ return false;
500
+ }
501
+
502
+ var pattern = isFunction$2(value) ? reIsNative : reIsHostCtor;
503
+ return pattern.test(toSource(value));
504
+ }
505
+
506
+ var _baseIsNative = baseIsNative$1;
507
+
508
+ /**
509
+ * Gets the value at `key` of `object`.
510
+ *
511
+ * @private
512
+ * @param {Object} [object] The object to query.
513
+ * @param {string} key The key of the property to get.
514
+ * @returns {*} Returns the property value.
515
+ */
516
+
517
+ function getValue$1(object, key) {
518
+ return object == null ? undefined : object[key];
519
+ }
520
+
521
+ var _getValue = getValue$1;
522
+
523
+ var baseIsNative = _baseIsNative,
524
+ getValue = _getValue;
525
+ /**
526
+ * Gets the native function at `key` of `object`.
527
+ *
528
+ * @private
529
+ * @param {Object} object The object to query.
530
+ * @param {string} key The key of the method to get.
531
+ * @returns {*} Returns the function if it's native, else `undefined`.
532
+ */
533
+
534
+ function getNative$2(object, key) {
535
+ var value = getValue(object, key);
536
+ return baseIsNative(value) ? value : undefined;
537
+ }
538
+
539
+ var _getNative = getNative$2;
540
+
541
+ var getNative$1 = _getNative;
542
+ /* Built-in method references that are verified to be native. */
543
+
544
+ var nativeCreate$4 = getNative$1(Object, 'create');
545
+ var _nativeCreate = nativeCreate$4;
546
+
547
+ var nativeCreate$3 = _nativeCreate;
548
+ /**
549
+ * Removes all key-value entries from the hash.
550
+ *
551
+ * @private
552
+ * @name clear
553
+ * @memberOf Hash
554
+ */
555
+
556
+ function hashClear$1() {
557
+ this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
558
+ this.size = 0;
559
+ }
560
+
561
+ var _hashClear = hashClear$1;
562
+
563
+ /**
564
+ * Removes `key` and its value from the hash.
565
+ *
566
+ * @private
567
+ * @name delete
568
+ * @memberOf Hash
569
+ * @param {Object} hash The hash to modify.
570
+ * @param {string} key The key of the value to remove.
571
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
572
+ */
573
+
574
+ function hashDelete$1(key) {
575
+ var result = this.has(key) && delete this.__data__[key];
576
+ this.size -= result ? 1 : 0;
577
+ return result;
578
+ }
579
+
580
+ var _hashDelete = hashDelete$1;
581
+
582
+ var nativeCreate$2 = _nativeCreate;
583
+ /** Used to stand-in for `undefined` hash values. */
584
+
585
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
586
+ /** Used for built-in method references. */
587
+
588
+ var objectProto$1 = Object.prototype;
589
+ /** Used to check objects for own properties. */
590
+
591
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
592
+ /**
593
+ * Gets the hash value for `key`.
594
+ *
595
+ * @private
596
+ * @name get
597
+ * @memberOf Hash
598
+ * @param {string} key The key of the value to get.
599
+ * @returns {*} Returns the entry value.
600
+ */
601
+
602
+ function hashGet$1(key) {
603
+ var data = this.__data__;
604
+
605
+ if (nativeCreate$2) {
606
+ var result = data[key];
607
+ return result === HASH_UNDEFINED$1 ? undefined : result;
608
+ }
609
+
610
+ return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
611
+ }
612
+
613
+ var _hashGet = hashGet$1;
614
+
615
+ var nativeCreate$1 = _nativeCreate;
616
+ /** Used for built-in method references. */
617
+
618
+ var objectProto = Object.prototype;
619
+ /** Used to check objects for own properties. */
620
+
621
+ var hasOwnProperty = objectProto.hasOwnProperty;
622
+ /**
623
+ * Checks if a hash value for `key` exists.
624
+ *
625
+ * @private
626
+ * @name has
627
+ * @memberOf Hash
628
+ * @param {string} key The key of the entry to check.
629
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
630
+ */
631
+
632
+ function hashHas$1(key) {
633
+ var data = this.__data__;
634
+ return nativeCreate$1 ? data[key] !== undefined : hasOwnProperty.call(data, key);
635
+ }
636
+
637
+ var _hashHas = hashHas$1;
638
+
639
+ var nativeCreate = _nativeCreate;
640
+ /** Used to stand-in for `undefined` hash values. */
641
+
642
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
643
+ /**
644
+ * Sets the hash `key` to `value`.
645
+ *
646
+ * @private
647
+ * @name set
648
+ * @memberOf Hash
649
+ * @param {string} key The key of the value to set.
650
+ * @param {*} value The value to set.
651
+ * @returns {Object} Returns the hash instance.
652
+ */
653
+
654
+ function hashSet$1(key, value) {
655
+ var data = this.__data__;
656
+ this.size += this.has(key) ? 0 : 1;
657
+ data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
658
+ return this;
659
+ }
660
+
661
+ var _hashSet = hashSet$1;
662
+
663
+ var hashClear = _hashClear,
664
+ hashDelete = _hashDelete,
665
+ hashGet = _hashGet,
666
+ hashHas = _hashHas,
667
+ hashSet = _hashSet;
668
+ /**
669
+ * Creates a hash object.
670
+ *
671
+ * @private
672
+ * @constructor
673
+ * @param {Array} [entries] The key-value pairs to cache.
674
+ */
675
+
676
+ function Hash$1(entries) {
677
+ var index = -1,
678
+ length = entries == null ? 0 : entries.length;
679
+ this.clear();
680
+
681
+ while (++index < length) {
682
+ var entry = entries[index];
683
+ this.set(entry[0], entry[1]);
684
+ }
685
+ } // Add methods to `Hash`.
686
+
687
+
688
+ Hash$1.prototype.clear = hashClear;
689
+ Hash$1.prototype['delete'] = hashDelete;
690
+ Hash$1.prototype.get = hashGet;
691
+ Hash$1.prototype.has = hashHas;
692
+ Hash$1.prototype.set = hashSet;
693
+ var _Hash = Hash$1;
694
+
695
+ /**
696
+ * Removes all key-value entries from the list cache.
697
+ *
698
+ * @private
699
+ * @name clear
700
+ * @memberOf ListCache
701
+ */
702
+
703
+ function listCacheClear$1() {
704
+ this.__data__ = [];
705
+ this.size = 0;
706
+ }
707
+
708
+ var _listCacheClear = listCacheClear$1;
709
+
710
+ /**
711
+ * Performs a
712
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
713
+ * comparison between two values to determine if they are equivalent.
714
+ *
715
+ * @static
716
+ * @memberOf _
717
+ * @since 4.0.0
718
+ * @category Lang
719
+ * @param {*} value The value to compare.
720
+ * @param {*} other The other value to compare.
721
+ * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
722
+ * @example
723
+ *
724
+ * var object = { 'a': 1 };
725
+ * var other = { 'a': 1 };
726
+ *
727
+ * _.eq(object, object);
728
+ * // => true
729
+ *
730
+ * _.eq(object, other);
731
+ * // => false
732
+ *
733
+ * _.eq('a', 'a');
734
+ * // => true
735
+ *
736
+ * _.eq('a', Object('a'));
737
+ * // => false
738
+ *
739
+ * _.eq(NaN, NaN);
740
+ * // => true
741
+ */
742
+
743
+ function eq$1(value, other) {
744
+ return value === other || value !== value && other !== other;
745
+ }
746
+
747
+ var eq_1 = eq$1;
748
+
749
+ var eq = eq_1;
750
+ /**
751
+ * Gets the index at which the `key` is found in `array` of key-value pairs.
752
+ *
753
+ * @private
754
+ * @param {Array} array The array to inspect.
755
+ * @param {*} key The key to search for.
756
+ * @returns {number} Returns the index of the matched value, else `-1`.
757
+ */
758
+
759
+ function assocIndexOf$4(array, key) {
760
+ var length = array.length;
761
+
762
+ while (length--) {
763
+ if (eq(array[length][0], key)) {
764
+ return length;
765
+ }
766
+ }
767
+
768
+ return -1;
769
+ }
770
+
771
+ var _assocIndexOf = assocIndexOf$4;
772
+
773
+ var assocIndexOf$3 = _assocIndexOf;
774
+ /** Used for built-in method references. */
775
+
776
+ var arrayProto = Array.prototype;
777
+ /** Built-in value references. */
778
+
779
+ var splice = arrayProto.splice;
780
+ /**
781
+ * Removes `key` and its value from the list cache.
782
+ *
783
+ * @private
784
+ * @name delete
785
+ * @memberOf ListCache
786
+ * @param {string} key The key of the value to remove.
787
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
788
+ */
789
+
790
+ function listCacheDelete$1(key) {
791
+ var data = this.__data__,
792
+ index = assocIndexOf$3(data, key);
793
+
794
+ if (index < 0) {
795
+ return false;
796
+ }
797
+
798
+ var lastIndex = data.length - 1;
799
+
800
+ if (index == lastIndex) {
801
+ data.pop();
802
+ } else {
803
+ splice.call(data, index, 1);
804
+ }
805
+
806
+ --this.size;
807
+ return true;
808
+ }
809
+
810
+ var _listCacheDelete = listCacheDelete$1;
811
+
812
+ var assocIndexOf$2 = _assocIndexOf;
813
+ /**
814
+ * Gets the list cache value for `key`.
815
+ *
816
+ * @private
817
+ * @name get
818
+ * @memberOf ListCache
819
+ * @param {string} key The key of the value to get.
820
+ * @returns {*} Returns the entry value.
821
+ */
822
+
823
+ function listCacheGet$1(key) {
824
+ var data = this.__data__,
825
+ index = assocIndexOf$2(data, key);
826
+ return index < 0 ? undefined : data[index][1];
827
+ }
828
+
829
+ var _listCacheGet = listCacheGet$1;
830
+
831
+ var assocIndexOf$1 = _assocIndexOf;
832
+ /**
833
+ * Checks if a list cache value for `key` exists.
834
+ *
835
+ * @private
836
+ * @name has
837
+ * @memberOf ListCache
838
+ * @param {string} key The key of the entry to check.
839
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
840
+ */
841
+
842
+ function listCacheHas$1(key) {
843
+ return assocIndexOf$1(this.__data__, key) > -1;
844
+ }
845
+
846
+ var _listCacheHas = listCacheHas$1;
847
+
848
+ var assocIndexOf = _assocIndexOf;
849
+ /**
850
+ * Sets the list cache `key` to `value`.
851
+ *
852
+ * @private
853
+ * @name set
854
+ * @memberOf ListCache
855
+ * @param {string} key The key of the value to set.
856
+ * @param {*} value The value to set.
857
+ * @returns {Object} Returns the list cache instance.
858
+ */
859
+
860
+ function listCacheSet$1(key, value) {
861
+ var data = this.__data__,
862
+ index = assocIndexOf(data, key);
863
+
864
+ if (index < 0) {
865
+ ++this.size;
866
+ data.push([key, value]);
867
+ } else {
868
+ data[index][1] = value;
869
+ }
870
+
871
+ return this;
872
+ }
873
+
874
+ var _listCacheSet = listCacheSet$1;
875
+
876
+ var listCacheClear = _listCacheClear,
877
+ listCacheDelete = _listCacheDelete,
878
+ listCacheGet = _listCacheGet,
879
+ listCacheHas = _listCacheHas,
880
+ listCacheSet = _listCacheSet;
881
+ /**
882
+ * Creates an list cache object.
883
+ *
884
+ * @private
885
+ * @constructor
886
+ * @param {Array} [entries] The key-value pairs to cache.
887
+ */
888
+
889
+ function ListCache$1(entries) {
890
+ var index = -1,
891
+ length = entries == null ? 0 : entries.length;
892
+ this.clear();
893
+
894
+ while (++index < length) {
895
+ var entry = entries[index];
896
+ this.set(entry[0], entry[1]);
897
+ }
898
+ } // Add methods to `ListCache`.
899
+
900
+
901
+ ListCache$1.prototype.clear = listCacheClear;
902
+ ListCache$1.prototype['delete'] = listCacheDelete;
903
+ ListCache$1.prototype.get = listCacheGet;
904
+ ListCache$1.prototype.has = listCacheHas;
905
+ ListCache$1.prototype.set = listCacheSet;
906
+ var _ListCache = ListCache$1;
907
+
908
+ var getNative = _getNative,
909
+ root = _root;
910
+ /* Built-in method references that are verified to be native. */
911
+
912
+ var Map$1 = getNative(root, 'Map');
913
+ var _Map = Map$1;
914
+
915
+ var Hash = _Hash,
916
+ ListCache = _ListCache,
917
+ Map = _Map;
918
+ /**
919
+ * Removes all key-value entries from the map.
920
+ *
921
+ * @private
922
+ * @name clear
923
+ * @memberOf MapCache
924
+ */
925
+
926
+ function mapCacheClear$1() {
927
+ this.size = 0;
928
+ this.__data__ = {
929
+ 'hash': new Hash(),
930
+ 'map': new (Map || ListCache)(),
931
+ 'string': new Hash()
932
+ };
933
+ }
934
+
935
+ var _mapCacheClear = mapCacheClear$1;
936
+
937
+ /**
938
+ * Checks if `value` is suitable for use as unique object key.
939
+ *
940
+ * @private
941
+ * @param {*} value The value to check.
942
+ * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
943
+ */
944
+
945
+ function isKeyable$1(value) {
946
+ var type = typeof value;
947
+ return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
948
+ }
949
+
950
+ var _isKeyable = isKeyable$1;
951
+
952
+ var isKeyable = _isKeyable;
953
+ /**
954
+ * Gets the data for `map`.
955
+ *
956
+ * @private
957
+ * @param {Object} map The map to query.
958
+ * @param {string} key The reference key.
959
+ * @returns {*} Returns the map data.
960
+ */
961
+
962
+ function getMapData$4(map, key) {
963
+ var data = map.__data__;
964
+ return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
965
+ }
966
+
967
+ var _getMapData = getMapData$4;
968
+
969
+ var getMapData$3 = _getMapData;
970
+ /**
971
+ * Removes `key` and its value from the map.
972
+ *
973
+ * @private
974
+ * @name delete
975
+ * @memberOf MapCache
976
+ * @param {string} key The key of the value to remove.
977
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
978
+ */
979
+
980
+ function mapCacheDelete$1(key) {
981
+ var result = getMapData$3(this, key)['delete'](key);
982
+ this.size -= result ? 1 : 0;
983
+ return result;
984
+ }
985
+
986
+ var _mapCacheDelete = mapCacheDelete$1;
987
+
988
+ var getMapData$2 = _getMapData;
989
+ /**
990
+ * Gets the map value for `key`.
991
+ *
992
+ * @private
993
+ * @name get
994
+ * @memberOf MapCache
995
+ * @param {string} key The key of the value to get.
996
+ * @returns {*} Returns the entry value.
997
+ */
998
+
999
+ function mapCacheGet$1(key) {
1000
+ return getMapData$2(this, key).get(key);
1001
+ }
1002
+
1003
+ var _mapCacheGet = mapCacheGet$1;
1004
+
1005
+ var getMapData$1 = _getMapData;
1006
+ /**
1007
+ * Checks if a map value for `key` exists.
1008
+ *
1009
+ * @private
1010
+ * @name has
1011
+ * @memberOf MapCache
1012
+ * @param {string} key The key of the entry to check.
1013
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1014
+ */
1015
+
1016
+ function mapCacheHas$1(key) {
1017
+ return getMapData$1(this, key).has(key);
1018
+ }
1019
+
1020
+ var _mapCacheHas = mapCacheHas$1;
1021
+
1022
+ var getMapData = _getMapData;
1023
+ /**
1024
+ * Sets the map `key` to `value`.
1025
+ *
1026
+ * @private
1027
+ * @name set
1028
+ * @memberOf MapCache
1029
+ * @param {string} key The key of the value to set.
1030
+ * @param {*} value The value to set.
1031
+ * @returns {Object} Returns the map cache instance.
1032
+ */
1033
+
1034
+ function mapCacheSet$1(key, value) {
1035
+ var data = getMapData(this, key),
1036
+ size = data.size;
1037
+ data.set(key, value);
1038
+ this.size += data.size == size ? 0 : 1;
1039
+ return this;
1040
+ }
1041
+
1042
+ var _mapCacheSet = mapCacheSet$1;
1043
+
1044
+ var mapCacheClear = _mapCacheClear,
1045
+ mapCacheDelete = _mapCacheDelete,
1046
+ mapCacheGet = _mapCacheGet,
1047
+ mapCacheHas = _mapCacheHas,
1048
+ mapCacheSet = _mapCacheSet;
1049
+ /**
1050
+ * Creates a map cache object to store key-value pairs.
1051
+ *
1052
+ * @private
1053
+ * @constructor
1054
+ * @param {Array} [entries] The key-value pairs to cache.
1055
+ */
1056
+
1057
+ function MapCache$1(entries) {
1058
+ var index = -1,
1059
+ length = entries == null ? 0 : entries.length;
1060
+ this.clear();
1061
+
1062
+ while (++index < length) {
1063
+ var entry = entries[index];
1064
+ this.set(entry[0], entry[1]);
1065
+ }
1066
+ } // Add methods to `MapCache`.
1067
+
1068
+
1069
+ MapCache$1.prototype.clear = mapCacheClear;
1070
+ MapCache$1.prototype['delete'] = mapCacheDelete;
1071
+ MapCache$1.prototype.get = mapCacheGet;
1072
+ MapCache$1.prototype.has = mapCacheHas;
1073
+ MapCache$1.prototype.set = mapCacheSet;
1074
+ var _MapCache = MapCache$1;
1075
+
1076
+ var MapCache = _MapCache;
1077
+ /** Error message constants. */
1078
+
1079
+ var FUNC_ERROR_TEXT = 'Expected a function';
1080
+ /**
1081
+ * Creates a function that memoizes the result of `func`. If `resolver` is
1082
+ * provided, it determines the cache key for storing the result based on the
1083
+ * arguments provided to the memoized function. By default, the first argument
1084
+ * provided to the memoized function is used as the map cache key. The `func`
1085
+ * is invoked with the `this` binding of the memoized function.
1086
+ *
1087
+ * **Note:** The cache is exposed as the `cache` property on the memoized
1088
+ * function. Its creation may be customized by replacing the `_.memoize.Cache`
1089
+ * constructor with one whose instances implement the
1090
+ * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
1091
+ * method interface of `clear`, `delete`, `get`, `has`, and `set`.
1092
+ *
1093
+ * @static
1094
+ * @memberOf _
1095
+ * @since 0.1.0
1096
+ * @category Function
1097
+ * @param {Function} func The function to have its output memoized.
1098
+ * @param {Function} [resolver] The function to resolve the cache key.
1099
+ * @returns {Function} Returns the new memoized function.
1100
+ * @example
1101
+ *
1102
+ * var object = { 'a': 1, 'b': 2 };
1103
+ * var other = { 'c': 3, 'd': 4 };
1104
+ *
1105
+ * var values = _.memoize(_.values);
1106
+ * values(object);
1107
+ * // => [1, 2]
1108
+ *
1109
+ * values(other);
1110
+ * // => [3, 4]
1111
+ *
1112
+ * object.a = 2;
1113
+ * values(object);
1114
+ * // => [1, 2]
1115
+ *
1116
+ * // Modify the result cache.
1117
+ * values.cache.set(object, ['a', 'b']);
1118
+ * values(object);
1119
+ * // => ['a', 'b']
1120
+ *
1121
+ * // Replace `_.memoize.Cache`.
1122
+ * _.memoize.Cache = WeakMap;
1123
+ */
1124
+
1125
+ function memoize$1(func, resolver) {
1126
+ if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
1127
+ throw new TypeError(FUNC_ERROR_TEXT);
1128
+ }
1129
+
1130
+ var memoized = function () {
1131
+ var args = arguments,
1132
+ key = resolver ? resolver.apply(this, args) : args[0],
1133
+ cache = memoized.cache;
1134
+
1135
+ if (cache.has(key)) {
1136
+ return cache.get(key);
1137
+ }
1138
+
1139
+ var result = func.apply(this, args);
1140
+ memoized.cache = cache.set(key, result) || cache;
1141
+ return result;
1142
+ };
1143
+
1144
+ memoized.cache = new (memoize$1.Cache || MapCache)();
1145
+ return memoized;
1146
+ } // Expose `MapCache`.
1147
+
1148
+
1149
+ memoize$1.Cache = MapCache;
1150
+ var memoize_1 = memoize$1;
1151
+
1152
+ var memoize = memoize_1;
1153
+ /** Used as the maximum memoize cache size. */
1154
+
1155
+ var MAX_MEMOIZE_SIZE = 500;
1156
+ /**
1157
+ * A specialized version of `_.memoize` which clears the memoized function's
1158
+ * cache when it exceeds `MAX_MEMOIZE_SIZE`.
1159
+ *
1160
+ * @private
1161
+ * @param {Function} func The function to have its output memoized.
1162
+ * @returns {Function} Returns the new memoized function.
1163
+ */
1164
+
1165
+ function memoizeCapped$1(func) {
1166
+ var result = memoize(func, function (key) {
1167
+ if (cache.size === MAX_MEMOIZE_SIZE) {
1168
+ cache.clear();
1169
+ }
1170
+
1171
+ return key;
1172
+ });
1173
+ var cache = result.cache;
1174
+ return result;
1175
+ }
1176
+
1177
+ var _memoizeCapped = memoizeCapped$1;
1178
+
1179
+ var memoizeCapped = _memoizeCapped;
1180
+ /** Used to match property names within property paths. */
1181
+
1182
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
1183
+ /** Used to match backslashes in property paths. */
1184
+
1185
+ var reEscapeChar = /\\(\\)?/g;
1186
+ /**
1187
+ * Converts `string` to a property path array.
1188
+ *
1189
+ * @private
1190
+ * @param {string} string The string to convert.
1191
+ * @returns {Array} Returns the property path array.
1192
+ */
1193
+
1194
+ var stringToPath$1 = memoizeCapped(function (string) {
1195
+ var result = [];
1196
+
1197
+ if (string.charCodeAt(0) === 46
1198
+ /* . */
1199
+ ) {
1200
+ result.push('');
1201
+ }
1202
+
1203
+ string.replace(rePropName, function (match, number, quote, subString) {
1204
+ result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
1205
+ });
1206
+ return result;
1207
+ });
1208
+ var _stringToPath = stringToPath$1;
1209
+
1210
+ /**
1211
+ * A specialized version of `_.map` for arrays without support for iteratee
1212
+ * shorthands.
1213
+ *
1214
+ * @private
1215
+ * @param {Array} [array] The array to iterate over.
1216
+ * @param {Function} iteratee The function invoked per iteration.
1217
+ * @returns {Array} Returns the new mapped array.
1218
+ */
1219
+
1220
+ function arrayMap$1(array, iteratee) {
1221
+ var index = -1,
1222
+ length = array == null ? 0 : array.length,
1223
+ result = Array(length);
1224
+
1225
+ while (++index < length) {
1226
+ result[index] = iteratee(array[index], index, array);
1227
+ }
1228
+
1229
+ return result;
1230
+ }
1231
+
1232
+ var _arrayMap = arrayMap$1;
1233
+
1234
+ var Symbol$1 = _Symbol,
1235
+ arrayMap = _arrayMap,
1236
+ isArray$1 = isArray_1,
1237
+ isSymbol$1 = isSymbol_1;
1238
+ /** Used as references for various `Number` constants. */
1239
+
1240
+ var INFINITY$1 = 1 / 0;
1241
+ /** Used to convert symbols to primitives and strings. */
1242
+
1243
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
1244
+ symbolToString = symbolProto ? symbolProto.toString : undefined;
1245
+ /**
1246
+ * The base implementation of `_.toString` which doesn't convert nullish
1247
+ * values to empty strings.
1248
+ *
1249
+ * @private
1250
+ * @param {*} value The value to process.
1251
+ * @returns {string} Returns the string.
1252
+ */
1253
+
1254
+ function baseToString$1(value) {
1255
+ // Exit early for strings to avoid a performance hit in some environments.
1256
+ if (typeof value == 'string') {
1257
+ return value;
1258
+ }
1259
+
1260
+ if (isArray$1(value)) {
1261
+ // Recursively convert values (susceptible to call stack limits).
1262
+ return arrayMap(value, baseToString$1) + '';
1263
+ }
1264
+
1265
+ if (isSymbol$1(value)) {
1266
+ return symbolToString ? symbolToString.call(value) : '';
1267
+ }
1268
+
1269
+ var result = value + '';
1270
+ return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
1271
+ }
1272
+
1273
+ var _baseToString = baseToString$1;
1274
+
1275
+ var baseToString = _baseToString;
1276
+ /**
1277
+ * Converts `value` to a string. An empty string is returned for `null`
1278
+ * and `undefined` values. The sign of `-0` is preserved.
1279
+ *
1280
+ * @static
1281
+ * @memberOf _
1282
+ * @since 4.0.0
1283
+ * @category Lang
1284
+ * @param {*} value The value to convert.
1285
+ * @returns {string} Returns the converted string.
1286
+ * @example
1287
+ *
1288
+ * _.toString(null);
1289
+ * // => ''
1290
+ *
1291
+ * _.toString(-0);
1292
+ * // => '-0'
1293
+ *
1294
+ * _.toString([1, 2, 3]);
1295
+ * // => '1,2,3'
1296
+ */
1297
+
1298
+ function toString$1(value) {
1299
+ return value == null ? '' : baseToString(value);
1300
+ }
1301
+
1302
+ var toString_1 = toString$1;
1303
+
1304
+ var isArray = isArray_1,
1305
+ isKey = _isKey,
1306
+ stringToPath = _stringToPath,
1307
+ toString = toString_1;
1308
+ /**
1309
+ * Casts `value` to a path array if it's not one.
1310
+ *
1311
+ * @private
1312
+ * @param {*} value The value to inspect.
1313
+ * @param {Object} [object] The object to query keys on.
1314
+ * @returns {Array} Returns the cast property path array.
1315
+ */
1316
+
1317
+ function castPath$1(value, object) {
1318
+ if (isArray(value)) {
1319
+ return value;
1320
+ }
1321
+
1322
+ return isKey(value, object) ? [value] : stringToPath(toString(value));
1323
+ }
1324
+
1325
+ var _castPath = castPath$1;
1326
+
1327
+ var isSymbol = isSymbol_1;
1328
+ /** Used as references for various `Number` constants. */
1329
+
1330
+ var INFINITY = 1 / 0;
1331
+ /**
1332
+ * Converts `value` to a string key if it's not a string or symbol.
1333
+ *
1334
+ * @private
1335
+ * @param {*} value The value to inspect.
1336
+ * @returns {string|symbol} Returns the key.
1337
+ */
1338
+
1339
+ function toKey$1(value) {
1340
+ if (typeof value == 'string' || isSymbol(value)) {
1341
+ return value;
1342
+ }
1343
+
1344
+ var result = value + '';
1345
+ return result == '0' && 1 / value == -INFINITY ? '-0' : result;
1346
+ }
1347
+
1348
+ var _toKey = toKey$1;
1349
+
1350
+ var castPath = _castPath,
1351
+ toKey = _toKey;
1352
+ /**
1353
+ * The base implementation of `_.get` without support for default values.
1354
+ *
1355
+ * @private
1356
+ * @param {Object} object The object to query.
1357
+ * @param {Array|string} path The path of the property to get.
1358
+ * @returns {*} Returns the resolved value.
1359
+ */
1360
+
1361
+ function baseGet$1(object, path) {
1362
+ path = castPath(path, object);
1363
+ var index = 0,
1364
+ length = path.length;
1365
+
1366
+ while (object != null && index < length) {
1367
+ object = object[toKey(path[index++])];
1368
+ }
1369
+
1370
+ return index && index == length ? object : undefined;
1371
+ }
1372
+
1373
+ var _baseGet = baseGet$1;
1374
+
1375
+ var baseGet = _baseGet;
1376
+ /**
1377
+ * Gets the value at `path` of `object`. If the resolved value is
1378
+ * `undefined`, the `defaultValue` is returned in its place.
1379
+ *
1380
+ * @static
1381
+ * @memberOf _
1382
+ * @since 3.7.0
1383
+ * @category Object
1384
+ * @param {Object} object The object to query.
1385
+ * @param {Array|string} path The path of the property to get.
1386
+ * @param {*} [defaultValue] The value returned for `undefined` resolved values.
1387
+ * @returns {*} Returns the resolved value.
1388
+ * @example
1389
+ *
1390
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
1391
+ *
1392
+ * _.get(object, 'a[0].b.c');
1393
+ * // => 3
1394
+ *
1395
+ * _.get(object, ['a', '0', 'b', 'c']);
1396
+ * // => 3
1397
+ *
1398
+ * _.get(object, 'a.b.c', 'default');
1399
+ * // => 'default'
1400
+ */
1401
+
1402
+ function get(object, path, defaultValue) {
1403
+ var result = object == null ? undefined : baseGet(object, path);
1404
+ return result === undefined ? defaultValue : result;
1405
+ }
1406
+
1407
+ var get_1 = get;
1408
+
1409
+ /**
1410
+ * To use it, you need some moves:
1411
+ * 1- First : you should have global variable:`let my_debounce;`
1412
+ * 2- Next : make your own function: `function my_debounce_fn(callback,...data){...}`
1413
+ * 3- Next : in your method, check if it's not existed yet, use this helper method to create it: `if(!my_debounce){my_debounce=Salla.helpers.debounce((fn, ...inner_data) => fn(...inner_data), 500)}`
1414
+ * 4- Next : then delay the passed callback: `my_debounce(callback, ...data);`
1415
+ * 5- Finally : use it: `my_debounce(() =>{...yourRepeatableLogic})`
1416
+ * will be something like:
1417
+ *
1418
+ * ```
1419
+ * let my_debounce;
1420
+ * function my_debounce_fn(callback,...data){
1421
+ * if(!my_debounce){
1422
+ * //inline method
1423
+ * my_debounce=Salla.helpers.debounce((fn, ...inner_data) => fn(...inner_data), 500);
1424
+ * }
1425
+ * return my_debounce(callback, ...data);
1426
+ * }
1427
+ * // use it like:
1428
+ * my_debounce_fn((my_data)=>Salla.log(my_data), 'hello there - 1');
1429
+ * my_debounce_fn((my_data)=>Salla.log(my_data), 'hello there - 2');
1430
+ * my_debounce_fn((my_data)=>Salla.log(my_data), 'hello there - 3');
1431
+ * my_debounce_fn((my_data)=>Salla.log(my_data), 'hello there - 4');
1432
+ * //output=> `hello there - 4`
1433
+ * ```
1434
+ * 😎Or just use Salla appHelpers:`app.debounce((my_data)=>Salla.log(my_data), 'hello there - *')`
1435
+ *
1436
+ * @param fn
1437
+ * @param delay
1438
+ * @return {function(...[*]): Promise<unknown>}
1439
+ */
1440
+
1441
+ function debounce(fn, delay) {
1442
+ delay = delay || 100;
1443
+ let resolves = [];
1444
+ let timer;
1445
+ return function (...args) {
1446
+ clearTimeout(timer);
1447
+ timer = setTimeout(() => {
1448
+ let result = fn(...args);
1449
+ resolves.forEach(r => r(result));
1450
+ resolves = [];
1451
+ }, delay);
1452
+ return new Promise(r => resolves.push(r));
1453
+ };
1454
+ }
1455
+ /**
1456
+ * Use It When You want to grab data from input names with brackets Ex.
1457
+ * <input name="products[0][id]" value...>
1458
+ * <input name="products[0][name]" value...>
1459
+ * <input name="products[1][id]" value...>
1460
+ * <input name="products[1][name]" value...>
1461
+ * will be like: {products:[{id:.., name:..},{id:.., name:..}]}
1462
+ * @param name
1463
+ * @param value
1464
+ * @param dataset
1465
+ * @return {{name, value}|{name, value: (*|[*, *]|[string, *]|{}|[*])}}
1466
+ */
1467
+
1468
+
1469
+ function getInputDataWithName(name, value, dataset = {}) {
1470
+ if (name.includes("[")) {
1471
+ let nameLevels = name.split("]").join("").split("[");
1472
+ return {
1473
+ name: nameLevels[0],
1474
+ value: getLeveledData(nameLevels.slice(1), value, dataset[nameLevels[0]])
1475
+ };
1476
+ }
1477
+
1478
+ return {
1479
+ name: name,
1480
+ value: value
1481
+ };
1482
+ }
1483
+ /**
1484
+ * in case input name is array for example "jamal[4655]" let's fix it
1485
+ * This Helper method to get suitable array data, Ex.
1486
+ * jamal[]=1
1487
+ * jamal[]=2
1488
+ * final result will be: {jamal:[1,2]}
1489
+ *
1490
+ * @param {String[]} nameLevels
1491
+ * @param {string|mixed} value
1492
+ * @param {{}|undefined} existedData
1493
+ * @return {*[]|*|(string|*)[]|{}}
1494
+ */
1495
+
1496
+
1497
+ function getLeveledData(nameLevels, value, existedData) {
1498
+ let currentName = nameLevels[0]; //it's an array, so add value ass array
1499
+
1500
+ if (existedData && nameLevels.length == 0) {
1501
+ if (Array.isArray(existedData)) {
1502
+ existedData.push(value);
1503
+ return existedData;
1504
+ } //todo::handle in case it's object
1505
+
1506
+
1507
+ return [existedData, value];
1508
+ }
1509
+
1510
+ if (Array.isArray(existedData)) {
1511
+ existedData.push(value);
1512
+ return existedData;
1513
+ }
1514
+
1515
+ if (typeof existedData === "string") {
1516
+ return [existedData, value];
1517
+ } //it's nested data
1518
+
1519
+
1520
+ if (existedData) {
1521
+ existedData[currentName] = getLeveledData(nameLevels.slice(1), value, existedData[currentName]);
1522
+ return existedData;
1523
+ }
1524
+
1525
+ if (currentName) {
1526
+ return {
1527
+ [currentName]: getLeveledData(nameLevels.slice(1), value)
1528
+ };
1529
+ } //handling "[]" without name
1530
+
1531
+
1532
+ return currentName === "" ? [value] : value;
1533
+ }
1534
+ /*
1535
+ window.onbeforeunload = function (event) {
1536
+ Salla.document.event.leaving(event);
1537
+ if (!Salla.config.get("canLeave")) {
1538
+ event.preventDefault();
1539
+ return false;
1540
+ }
1541
+ };
1542
+ */
1543
+
1544
+
1545
+ function setNested(object, key, value) {
1546
+ let schema = object;
1547
+ let keys = key.split(".");
1548
+ let len = keys.length;
1549
+
1550
+ for (let i = 0; i < len - 1; i++) {
1551
+ let elem = keys[i];
1552
+ if (!schema[elem]) schema[elem] = {};
1553
+ schema = schema[elem];
1554
+ }
1555
+
1556
+ schema[keys[len - 1]] = value;
1557
+ return object;
1558
+ }
1559
+
1560
+ function getNested(object, key, default_) {
1561
+ let data = get_1(object, key);
1562
+ return data !== undefined ? data : default_;
1563
+ }
1564
+ /**
1565
+ * @param {string } url
1566
+ * @return string
1567
+ */
1568
+
1569
+
1570
+ function url(url) {
1571
+ return Salla.config.get("store.url", window.location.href.split("/").slice(0, -1).join("/")).rtrim("/") + "/" + url.ltrim("/");
1572
+ }
1573
+
1574
+ function addParamToUrl(key, value) {
1575
+ if (!value || !key) {
1576
+ return window.location.href;
1577
+ }
1578
+
1579
+ let regex = new RegExp("([?&])" + key + "=[^&]+[&]?", "g");
1580
+ let url = window.location.href.replace(regex, "$1").replace(/&$|\?$/, ""); //remove old one
1581
+
1582
+ url += (url.includes("?") ? "&" : "?") + key + "=" + encodeURIComponent(value);
1583
+ return url.replace(/&$|\?$/, "");
1584
+ } //this will get it without username if it's salla domain ex: Salla.sa/test will ignore test
1585
+
1586
+
1587
+ function baseUrl(path) {
1588
+ return window.location.origin + "/" + path.ltrim("/");
1589
+ }
1590
+
1591
+ function asset(path) {
1592
+ return baseUrl("themes/" + Salla.config.get("theme.name") + "/" + path.ltrim("/"));
1593
+ }
1594
+
1595
+ function cdn(path) {
1596
+ return "https://cdn.salla.network/" + path.ltrim("/");
1597
+ }
1598
+ /**
1599
+ * Return url for api
1600
+ * @example Salla.url.api('test') => https://my_store.test/api/v1/test
1601
+ * @param path
1602
+ * @return {string}
1603
+ */
1604
+
1605
+
1606
+ function api(path) {
1607
+ return Salla.config.get("store.api", url("")).rtrim("/") + "/" + path.ltrim("/");
1608
+ }
1609
+
1610
+ function is_page(pageName) {
1611
+ return pageName && Salla.config.get("page.slug") === pageName;
1612
+ }
1613
+ /**
1614
+ * @type {{debounce: (function(*, *=): function(...[*]): Promise<unknown>), inputData: ((function(*=, *=, *): ({name, value}|{name, value: (*|*[]|(string|*)[]|{})}))|*), digitsOnly: ((function(*=, *=): (undefined|*))|*)}}
1615
+ */
1616
+
1617
+
1618
+ var Helpers = {
1619
+ // Numbers helpers
1620
+ digitsOnly: digitsOnly,
1621
+ inputDigitsOnly: inputDigitsOnly,
1622
+ number: number,
1623
+ money: money,
1624
+ // Nested objects helpers
1625
+ setNested: setNested,
1626
+ getNested: getNested,
1627
+ inputData: getInputDataWithName,
1628
+ // Url helpers
1629
+ url: {
1630
+ get: url,
1631
+ asset: asset,
1632
+ cdn: cdn,
1633
+ is_page: is_page,
1634
+ api: api
1635
+ },
1636
+ addParamToUrl: addParamToUrl,
1637
+ // other
1638
+ debounce: debounce
1639
+ };
1640
+
1641
+ /**
1642
+ * A logger to help us to use Salla.logger.log like console.log
1643
+ *
1644
+ * @namespace Salla.logger
1645
+ *
1646
+ * @credits @Ammar Hasan
1647
+ * @see https://stackoverflow.com/a/21856736
1648
+ *
1649
+ */
1650
+
1651
+ var Logger = (function (c) {
1652
+
1653
+ let proxy = {
1654
+ log: function (a, type) {
1655
+ if (!c) {
1656
+ return;
1657
+ /* return or call your custom function here */
1658
+ } // let's force trace for all logs when the debug is trace level
1659
+
1660
+
1661
+ if (salla.config.get('debug') === 'trace') {
1662
+ type = 'trace';
1663
+ }
1664
+
1665
+ let colorableTypes = {
1666
+ event: '#CFF680',
1667
+ backend: '#7b68ee'
1668
+ };
1669
+ let l = c.log,
1670
+ f = type === undefined ? l : this.__dict__[type] || l;
1671
+ let style = ['%cTwilight', 'color: #5cd5c4;font-weight:bold; border:1px solid #5cd5c4; padding: 2px 6px; border-radius: 5px;'];
1672
+ let color = colorableTypes[type];
1673
+
1674
+ if (color) {
1675
+ style[0] += '%c' + type[0].toUpperCase() + type.substring(1);
1676
+ style.push(`margin-left: 5px;color: ${color};font-weight:bold; border:1px solid ${color}; padding: 2px 6px; border-radius: 5px;`);
1677
+ }
1678
+
1679
+ f.call(c, ...style.concat(...a));
1680
+ },
1681
+ __dict__: {
1682
+ "trace": c.trace,
1683
+ "debug": c.debug,
1684
+ "info": c.info,
1685
+ "warn": c.warn,
1686
+ "error": c.error
1687
+ }
1688
+ };
1689
+ return {
1690
+ event: function () {
1691
+ proxy.log(arguments, "event");
1692
+ },
1693
+ trace: function () {
1694
+ proxy.log(arguments, "trace");
1695
+ },
1696
+ debug: function () {
1697
+ proxy.log(arguments, "debug");
1698
+ },
1699
+ info: function () {
1700
+ proxy.log(arguments, "info");
1701
+ },
1702
+ warn: function () {
1703
+ proxy.log(arguments, "warn");
1704
+ },
1705
+ error: function () {
1706
+ proxy.log(arguments, "error");
1707
+ },
1708
+ log: function () {
1709
+ proxy.log(arguments, undefined);
1710
+ },
1711
+ //use this to pass messages from backEnd, no need to add documentations, because it will no passed in production
1712
+ backend: function () {
1713
+ proxy.log(arguments, "backend");
1714
+ },
1715
+ //this for internal usage to pass multi logs using one function, no need to add it to documentation @see \Salla\Core\Traits\WithStageLogger::debug
1716
+ logs: function (logs) {
1717
+ [logs].flat().forEach(logData => logData && proxy.log([logData].flat(), 'backend'));
1718
+ }
1719
+ };
1720
+ })(console);
1721
+
1722
+ /**
1723
+ * @namespace Salla.config
1724
+ *
1725
+ * @property {any} properties_
1726
+ */
1727
+ class Config {
1728
+ constructor(properties = {}, default_properties = {}) {
1729
+ this.default_properties = default_properties;
1730
+ this.properties_ = { ...this.default_properties,
1731
+ ...properties
1732
+ };
1733
+ }
1734
+
1735
+ merge(config) {
1736
+ Object.assign(this.properties_, config);
1737
+ this.properties_.store = { ...this.default_properties.store,
1738
+ ...this.properties_.store
1739
+ };
1740
+ return this;
1741
+ }
1742
+
1743
+ set(key, value) {
1744
+ if (key.includes(".")) {
1745
+ Salla.helpers.setNested(this.properties_, key, value);
1746
+ return this;
1747
+ }
1748
+
1749
+ this.properties_[key] = value;
1750
+ return this;
1751
+ }
1752
+ /**
1753
+ * @param {string} key
1754
+ * @param {null|any} default_
1755
+ * @return {any}
1756
+ */
1757
+
1758
+
1759
+ get(key, default_ = null) {
1760
+ if (key.includes(".")) {
1761
+ return Salla.helpers.getNested(this.properties_, key, default_);
1762
+ }
1763
+
1764
+ return this.properties_.hasOwnProperty(key) ? this.properties_[key] || default_ : default_ || undefined;
1765
+ }
1766
+
1767
+ all() {
1768
+ return this.properties_;
1769
+ }
1770
+
1771
+ }
1772
+
1773
+ var eventemitter2 = {exports: {}};
1774
+
1775
+ (function (module, exports) {
1776
+ !function (undefined$1) {
1777
+ var hasOwnProperty = Object.hasOwnProperty;
1778
+ var isArray = Array.isArray ? Array.isArray : function _isArray(obj) {
1779
+ return Object.prototype.toString.call(obj) === "[object Array]";
1780
+ };
1781
+ var defaultMaxListeners = 10;
1782
+ var nextTickSupported = typeof process__default["default"] == 'object' && typeof process__default["default"].nextTick == 'function';
1783
+ var symbolsSupported = typeof Symbol === 'function';
1784
+ var reflectSupported = typeof Reflect === 'object';
1785
+ var setImmediateSupported = typeof setImmediate === 'function';
1786
+
1787
+ var _setImmediate = setImmediateSupported ? setImmediate : setTimeout;
1788
+
1789
+ var ownKeys = symbolsSupported ? reflectSupported && typeof Reflect.ownKeys === 'function' ? Reflect.ownKeys : function (obj) {
1790
+ var arr = Object.getOwnPropertyNames(obj);
1791
+ arr.push.apply(arr, Object.getOwnPropertySymbols(obj));
1792
+ return arr;
1793
+ } : Object.keys;
1794
+
1795
+ function init() {
1796
+ this._events = {};
1797
+
1798
+ if (this._conf) {
1799
+ configure.call(this, this._conf);
1800
+ }
1801
+ }
1802
+
1803
+ function configure(conf) {
1804
+ if (conf) {
1805
+ this._conf = conf;
1806
+ conf.delimiter && (this.delimiter = conf.delimiter);
1807
+
1808
+ if (conf.maxListeners !== undefined$1) {
1809
+ this._maxListeners = conf.maxListeners;
1810
+ }
1811
+
1812
+ conf.wildcard && (this.wildcard = conf.wildcard);
1813
+ conf.newListener && (this._newListener = conf.newListener);
1814
+ conf.removeListener && (this._removeListener = conf.removeListener);
1815
+ conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak);
1816
+ conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors);
1817
+
1818
+ if (this.wildcard) {
1819
+ this.listenerTree = {};
1820
+ }
1821
+ }
1822
+ }
1823
+
1824
+ function logPossibleMemoryLeak(count, eventName) {
1825
+ var errorMsg = '(node) warning: possible EventEmitter memory ' + 'leak detected. ' + count + ' listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.';
1826
+
1827
+ if (this.verboseMemoryLeak) {
1828
+ errorMsg += ' Event name: ' + eventName + '.';
1829
+ }
1830
+
1831
+ if (typeof process__default["default"] !== 'undefined' && process__default["default"].emitWarning) {
1832
+ var e = new Error(errorMsg);
1833
+ e.name = 'MaxListenersExceededWarning';
1834
+ e.emitter = this;
1835
+ e.count = count;
1836
+ process__default["default"].emitWarning(e);
1837
+ } else {
1838
+ console.error(errorMsg);
1839
+
1840
+ if (console.trace) {
1841
+ console.trace();
1842
+ }
1843
+ }
1844
+ }
1845
+
1846
+ var toArray = function (a, b, c) {
1847
+ var n = arguments.length;
1848
+
1849
+ switch (n) {
1850
+ case 0:
1851
+ return [];
1852
+
1853
+ case 1:
1854
+ return [a];
1855
+
1856
+ case 2:
1857
+ return [a, b];
1858
+
1859
+ case 3:
1860
+ return [a, b, c];
1861
+
1862
+ default:
1863
+ var arr = new Array(n);
1864
+
1865
+ while (n--) {
1866
+ arr[n] = arguments[n];
1867
+ }
1868
+
1869
+ return arr;
1870
+ }
1871
+ };
1872
+
1873
+ function toObject(keys, values) {
1874
+ var obj = {};
1875
+ var key;
1876
+ var len = keys.length;
1877
+ var valuesCount = values ? values.length : 0;
1878
+
1879
+ for (var i = 0; i < len; i++) {
1880
+ key = keys[i];
1881
+ obj[key] = i < valuesCount ? values[i] : undefined$1;
1882
+ }
1883
+
1884
+ return obj;
1885
+ }
1886
+
1887
+ function TargetObserver(emitter, target, options) {
1888
+ this._emitter = emitter;
1889
+ this._target = target;
1890
+ this._listeners = {};
1891
+ this._listenersCount = 0;
1892
+ var on, off;
1893
+
1894
+ if (options.on || options.off) {
1895
+ on = options.on;
1896
+ off = options.off;
1897
+ }
1898
+
1899
+ if (target.addEventListener) {
1900
+ on = target.addEventListener;
1901
+ off = target.removeEventListener;
1902
+ } else if (target.addListener) {
1903
+ on = target.addListener;
1904
+ off = target.removeListener;
1905
+ } else if (target.on) {
1906
+ on = target.on;
1907
+ off = target.off;
1908
+ }
1909
+
1910
+ if (!on && !off) {
1911
+ throw Error('target does not implement any known event API');
1912
+ }
1913
+
1914
+ if (typeof on !== 'function') {
1915
+ throw TypeError('on method must be a function');
1916
+ }
1917
+
1918
+ if (typeof off !== 'function') {
1919
+ throw TypeError('off method must be a function');
1920
+ }
1921
+
1922
+ this._on = on;
1923
+ this._off = off;
1924
+ var _observers = emitter._observers;
1925
+
1926
+ if (_observers) {
1927
+ _observers.push(this);
1928
+ } else {
1929
+ emitter._observers = [this];
1930
+ }
1931
+ }
1932
+
1933
+ Object.assign(TargetObserver.prototype, {
1934
+ subscribe: function (event, localEvent, reducer) {
1935
+ var observer = this;
1936
+ var target = this._target;
1937
+ var emitter = this._emitter;
1938
+ var listeners = this._listeners;
1939
+
1940
+ var handler = function () {
1941
+ var args = toArray.apply(null, arguments);
1942
+ var eventObj = {
1943
+ data: args,
1944
+ name: localEvent,
1945
+ original: event
1946
+ };
1947
+
1948
+ if (reducer) {
1949
+ var result = reducer.call(target, eventObj);
1950
+
1951
+ if (result !== false) {
1952
+ emitter.emit.apply(emitter, [eventObj.name].concat(args));
1953
+ }
1954
+
1955
+ return;
1956
+ }
1957
+
1958
+ emitter.emit.apply(emitter, [localEvent].concat(args));
1959
+ };
1960
+
1961
+ if (listeners[event]) {
1962
+ throw Error('Event \'' + event + '\' is already listening');
1963
+ }
1964
+
1965
+ this._listenersCount++;
1966
+
1967
+ if (emitter._newListener && emitter._removeListener && !observer._onNewListener) {
1968
+ this._onNewListener = function (_event) {
1969
+ if (_event === localEvent && listeners[event] === null) {
1970
+ listeners[event] = handler;
1971
+
1972
+ observer._on.call(target, event, handler);
1973
+ }
1974
+ };
1975
+
1976
+ emitter.on('newListener', this._onNewListener);
1977
+
1978
+ this._onRemoveListener = function (_event) {
1979
+ if (_event === localEvent && !emitter.hasListeners(_event) && listeners[event]) {
1980
+ listeners[event] = null;
1981
+
1982
+ observer._off.call(target, event, handler);
1983
+ }
1984
+ };
1985
+
1986
+ listeners[event] = null;
1987
+ emitter.on('removeListener', this._onRemoveListener);
1988
+ } else {
1989
+ listeners[event] = handler;
1990
+
1991
+ observer._on.call(target, event, handler);
1992
+ }
1993
+ },
1994
+ unsubscribe: function (event) {
1995
+ var observer = this;
1996
+ var listeners = this._listeners;
1997
+ var emitter = this._emitter;
1998
+ var handler;
1999
+ var events;
2000
+ var off = this._off;
2001
+ var target = this._target;
2002
+ var i;
2003
+
2004
+ if (event && typeof event !== 'string') {
2005
+ throw TypeError('event must be a string');
2006
+ }
2007
+
2008
+ function clearRefs() {
2009
+ if (observer._onNewListener) {
2010
+ emitter.off('newListener', observer._onNewListener);
2011
+ emitter.off('removeListener', observer._onRemoveListener);
2012
+ observer._onNewListener = null;
2013
+ observer._onRemoveListener = null;
2014
+ }
2015
+
2016
+ var index = findTargetIndex.call(emitter, observer);
2017
+
2018
+ emitter._observers.splice(index, 1);
2019
+ }
2020
+
2021
+ if (event) {
2022
+ handler = listeners[event];
2023
+ if (!handler) return;
2024
+ off.call(target, event, handler);
2025
+ delete listeners[event];
2026
+
2027
+ if (! --this._listenersCount) {
2028
+ clearRefs();
2029
+ }
2030
+ } else {
2031
+ events = ownKeys(listeners);
2032
+ i = events.length;
2033
+
2034
+ while (i-- > 0) {
2035
+ event = events[i];
2036
+ off.call(target, event, listeners[event]);
2037
+ }
2038
+
2039
+ this._listeners = {};
2040
+ this._listenersCount = 0;
2041
+ clearRefs();
2042
+ }
2043
+ }
2044
+ });
2045
+
2046
+ function resolveOptions(options, schema, reducers, allowUnknown) {
2047
+ var computedOptions = Object.assign({}, schema);
2048
+ if (!options) return computedOptions;
2049
+
2050
+ if (typeof options !== 'object') {
2051
+ throw TypeError('options must be an object');
2052
+ }
2053
+
2054
+ var keys = Object.keys(options);
2055
+ var length = keys.length;
2056
+ var option, value;
2057
+ var reducer;
2058
+
2059
+ function reject(reason) {
2060
+ throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : ''));
2061
+ }
2062
+
2063
+ for (var i = 0; i < length; i++) {
2064
+ option = keys[i];
2065
+
2066
+ if (!allowUnknown && !hasOwnProperty.call(schema, option)) {
2067
+ throw Error('Unknown "' + option + '" option');
2068
+ }
2069
+
2070
+ value = options[option];
2071
+
2072
+ if (value !== undefined$1) {
2073
+ reducer = reducers[option];
2074
+ computedOptions[option] = reducer ? reducer(value, reject) : value;
2075
+ }
2076
+ }
2077
+
2078
+ return computedOptions;
2079
+ }
2080
+
2081
+ function constructorReducer(value, reject) {
2082
+ if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) {
2083
+ reject('value must be a constructor');
2084
+ }
2085
+
2086
+ return value;
2087
+ }
2088
+
2089
+ function makeTypeReducer(types) {
2090
+ var message = 'value must be type of ' + types.join('|');
2091
+ var len = types.length;
2092
+ var firstType = types[0];
2093
+ var secondType = types[1];
2094
+
2095
+ if (len === 1) {
2096
+ return function (v, reject) {
2097
+ if (typeof v === firstType) {
2098
+ return v;
2099
+ }
2100
+
2101
+ reject(message);
2102
+ };
2103
+ }
2104
+
2105
+ if (len === 2) {
2106
+ return function (v, reject) {
2107
+ var kind = typeof v;
2108
+ if (kind === firstType || kind === secondType) return v;
2109
+ reject(message);
2110
+ };
2111
+ }
2112
+
2113
+ return function (v, reject) {
2114
+ var kind = typeof v;
2115
+ var i = len;
2116
+
2117
+ while (i-- > 0) {
2118
+ if (kind === types[i]) return v;
2119
+ }
2120
+
2121
+ reject(message);
2122
+ };
2123
+ }
2124
+
2125
+ var functionReducer = makeTypeReducer(['function']);
2126
+ var objectFunctionReducer = makeTypeReducer(['object', 'function']);
2127
+
2128
+ function makeCancelablePromise(Promise, executor, options) {
2129
+ var isCancelable;
2130
+ var callbacks;
2131
+ var timer = 0;
2132
+ var subscriptionClosed;
2133
+ var promise = new Promise(function (resolve, reject, onCancel) {
2134
+ options = resolveOptions(options, {
2135
+ timeout: 0,
2136
+ overload: false
2137
+ }, {
2138
+ timeout: function (value, reject) {
2139
+ value *= 1;
2140
+
2141
+ if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) {
2142
+ reject('timeout must be a positive number');
2143
+ }
2144
+
2145
+ return value;
2146
+ }
2147
+ });
2148
+ isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function';
2149
+
2150
+ function cleanup() {
2151
+ if (callbacks) {
2152
+ callbacks = null;
2153
+ }
2154
+
2155
+ if (timer) {
2156
+ clearTimeout(timer);
2157
+ timer = 0;
2158
+ }
2159
+ }
2160
+
2161
+ var _resolve = function (value) {
2162
+ cleanup();
2163
+ resolve(value);
2164
+ };
2165
+
2166
+ var _reject = function (err) {
2167
+ cleanup();
2168
+ reject(err);
2169
+ };
2170
+
2171
+ if (isCancelable) {
2172
+ executor(_resolve, _reject, onCancel);
2173
+ } else {
2174
+ callbacks = [function (reason) {
2175
+ _reject(reason || Error('canceled'));
2176
+ }];
2177
+ executor(_resolve, _reject, function (cb) {
2178
+ if (subscriptionClosed) {
2179
+ throw Error('Unable to subscribe on cancel event asynchronously');
2180
+ }
2181
+
2182
+ if (typeof cb !== 'function') {
2183
+ throw TypeError('onCancel callback must be a function');
2184
+ }
2185
+
2186
+ callbacks.push(cb);
2187
+ });
2188
+ subscriptionClosed = true;
2189
+ }
2190
+
2191
+ if (options.timeout > 0) {
2192
+ timer = setTimeout(function () {
2193
+ var reason = Error('timeout');
2194
+ reason.code = 'ETIMEDOUT';
2195
+ timer = 0;
2196
+ promise.cancel(reason);
2197
+ reject(reason);
2198
+ }, options.timeout);
2199
+ }
2200
+ });
2201
+
2202
+ if (!isCancelable) {
2203
+ promise.cancel = function (reason) {
2204
+ if (!callbacks) {
2205
+ return;
2206
+ }
2207
+
2208
+ var length = callbacks.length;
2209
+
2210
+ for (var i = 1; i < length; i++) {
2211
+ callbacks[i](reason);
2212
+ } // internal callback to reject the promise
2213
+
2214
+
2215
+ callbacks[0](reason);
2216
+ callbacks = null;
2217
+ };
2218
+ }
2219
+
2220
+ return promise;
2221
+ }
2222
+
2223
+ function findTargetIndex(observer) {
2224
+ var observers = this._observers;
2225
+
2226
+ if (!observers) {
2227
+ return -1;
2228
+ }
2229
+
2230
+ var len = observers.length;
2231
+
2232
+ for (var i = 0; i < len; i++) {
2233
+ if (observers[i]._target === observer) return i;
2234
+ }
2235
+
2236
+ return -1;
2237
+ } // Attention, function return type now is array, always !
2238
+ // It has zero elements if no any matches found and one or more
2239
+ // elements (leafs) if there are matches
2240
+ //
2241
+
2242
+
2243
+ function searchListenerTree(handlers, type, tree, i, typeLength) {
2244
+ if (!tree) {
2245
+ return null;
2246
+ }
2247
+
2248
+ if (i === 0) {
2249
+ var kind = typeof type;
2250
+
2251
+ if (kind === 'string') {
2252
+ var ns,
2253
+ n,
2254
+ l = 0,
2255
+ j = 0,
2256
+ delimiter = this.delimiter,
2257
+ dl = delimiter.length;
2258
+
2259
+ if ((n = type.indexOf(delimiter)) !== -1) {
2260
+ ns = new Array(5);
2261
+
2262
+ do {
2263
+ ns[l++] = type.slice(j, n);
2264
+ j = n + dl;
2265
+ } while ((n = type.indexOf(delimiter, j)) !== -1);
2266
+
2267
+ ns[l++] = type.slice(j);
2268
+ type = ns;
2269
+ typeLength = l;
2270
+ } else {
2271
+ type = [type];
2272
+ typeLength = 1;
2273
+ }
2274
+ } else if (kind === 'object') {
2275
+ typeLength = type.length;
2276
+ } else {
2277
+ type = [type];
2278
+ typeLength = 1;
2279
+ }
2280
+ }
2281
+
2282
+ var listeners = null,
2283
+ branch,
2284
+ xTree,
2285
+ xxTree,
2286
+ isolatedBranch,
2287
+ endReached,
2288
+ currentType = type[i],
2289
+ nextType = type[i + 1],
2290
+ branches,
2291
+ _listeners;
2292
+
2293
+ if (i === typeLength) {
2294
+ //
2295
+ // If at the end of the event(s) list and the tree has listeners
2296
+ // invoke those listeners.
2297
+ //
2298
+ if (tree._listeners) {
2299
+ if (typeof tree._listeners === 'function') {
2300
+ handlers && handlers.push(tree._listeners);
2301
+ listeners = [tree];
2302
+ } else {
2303
+ handlers && handlers.push.apply(handlers, tree._listeners);
2304
+ listeners = [tree];
2305
+ }
2306
+ }
2307
+ } else {
2308
+ if (currentType === '*') {
2309
+ //
2310
+ // If the event emitted is '*' at this part
2311
+ // or there is a concrete match at this patch
2312
+ //
2313
+ branches = ownKeys(tree);
2314
+ n = branches.length;
2315
+
2316
+ while (n-- > 0) {
2317
+ branch = branches[n];
2318
+
2319
+ if (branch !== '_listeners') {
2320
+ _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength);
2321
+
2322
+ if (_listeners) {
2323
+ if (listeners) {
2324
+ listeners.push.apply(listeners, _listeners);
2325
+ } else {
2326
+ listeners = _listeners;
2327
+ }
2328
+ }
2329
+ }
2330
+ }
2331
+
2332
+ return listeners;
2333
+ } else if (currentType === '**') {
2334
+ endReached = i + 1 === typeLength || i + 2 === typeLength && nextType === '*';
2335
+
2336
+ if (endReached && tree._listeners) {
2337
+ // The next element has a _listeners, add it to the handlers.
2338
+ listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength);
2339
+ }
2340
+
2341
+ branches = ownKeys(tree);
2342
+ n = branches.length;
2343
+
2344
+ while (n-- > 0) {
2345
+ branch = branches[n];
2346
+
2347
+ if (branch !== '_listeners') {
2348
+ if (branch === '*' || branch === '**') {
2349
+ if (tree[branch]._listeners && !endReached) {
2350
+ _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength);
2351
+
2352
+ if (_listeners) {
2353
+ if (listeners) {
2354
+ listeners.push.apply(listeners, _listeners);
2355
+ } else {
2356
+ listeners = _listeners;
2357
+ }
2358
+ }
2359
+ }
2360
+
2361
+ _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength);
2362
+ } else if (branch === nextType) {
2363
+ _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength);
2364
+ } else {
2365
+ // No match on this one, shift into the tree but not in the type array.
2366
+ _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength);
2367
+ }
2368
+
2369
+ if (_listeners) {
2370
+ if (listeners) {
2371
+ listeners.push.apply(listeners, _listeners);
2372
+ } else {
2373
+ listeners = _listeners;
2374
+ }
2375
+ }
2376
+ }
2377
+ }
2378
+
2379
+ return listeners;
2380
+ } else if (tree[currentType]) {
2381
+ listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength);
2382
+ }
2383
+ }
2384
+
2385
+ xTree = tree['*'];
2386
+
2387
+ if (xTree) {
2388
+ //
2389
+ // If the listener tree will allow any match for this part,
2390
+ // then recursively explore all branches of the tree
2391
+ //
2392
+ searchListenerTree(handlers, type, xTree, i + 1, typeLength);
2393
+ }
2394
+
2395
+ xxTree = tree['**'];
2396
+
2397
+ if (xxTree) {
2398
+ if (i < typeLength) {
2399
+ if (xxTree._listeners) {
2400
+ // If we have a listener on a '**', it will catch all, so add its handler.
2401
+ searchListenerTree(handlers, type, xxTree, typeLength, typeLength);
2402
+ } // Build arrays of matching next branches and others.
2403
+
2404
+
2405
+ branches = ownKeys(xxTree);
2406
+ n = branches.length;
2407
+
2408
+ while (n-- > 0) {
2409
+ branch = branches[n];
2410
+
2411
+ if (branch !== '_listeners') {
2412
+ if (branch === nextType) {
2413
+ // We know the next element will match, so jump twice.
2414
+ searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength);
2415
+ } else if (branch === currentType) {
2416
+ // Current node matches, move into the tree.
2417
+ searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength);
2418
+ } else {
2419
+ isolatedBranch = {};
2420
+ isolatedBranch[branch] = xxTree[branch];
2421
+ searchListenerTree(handlers, type, {
2422
+ '**': isolatedBranch
2423
+ }, i + 1, typeLength);
2424
+ }
2425
+ }
2426
+ }
2427
+ } else if (xxTree._listeners) {
2428
+ // We have reached the end and still on a '**'
2429
+ searchListenerTree(handlers, type, xxTree, typeLength, typeLength);
2430
+ } else if (xxTree['*'] && xxTree['*']._listeners) {
2431
+ searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength);
2432
+ }
2433
+ }
2434
+
2435
+ return listeners;
2436
+ }
2437
+
2438
+ function growListenerTree(type, listener, prepend) {
2439
+ var len = 0,
2440
+ j = 0,
2441
+ i,
2442
+ delimiter = this.delimiter,
2443
+ dl = delimiter.length,
2444
+ ns;
2445
+
2446
+ if (typeof type === 'string') {
2447
+ if ((i = type.indexOf(delimiter)) !== -1) {
2448
+ ns = new Array(5);
2449
+
2450
+ do {
2451
+ ns[len++] = type.slice(j, i);
2452
+ j = i + dl;
2453
+ } while ((i = type.indexOf(delimiter, j)) !== -1);
2454
+
2455
+ ns[len++] = type.slice(j);
2456
+ } else {
2457
+ ns = [type];
2458
+ len = 1;
2459
+ }
2460
+ } else {
2461
+ ns = type;
2462
+ len = type.length;
2463
+ } //
2464
+ // Looks for two consecutive '**', if so, don't add the event at all.
2465
+ //
2466
+
2467
+
2468
+ if (len > 1) {
2469
+ for (i = 0; i + 1 < len; i++) {
2470
+ if (ns[i] === '**' && ns[i + 1] === '**') {
2471
+ return;
2472
+ }
2473
+ }
2474
+ }
2475
+
2476
+ var tree = this.listenerTree,
2477
+ name;
2478
+
2479
+ for (i = 0; i < len; i++) {
2480
+ name = ns[i];
2481
+ tree = tree[name] || (tree[name] = {});
2482
+
2483
+ if (i === len - 1) {
2484
+ if (!tree._listeners) {
2485
+ tree._listeners = listener;
2486
+ } else {
2487
+ if (typeof tree._listeners === 'function') {
2488
+ tree._listeners = [tree._listeners];
2489
+ }
2490
+
2491
+ if (prepend) {
2492
+ tree._listeners.unshift(listener);
2493
+ } else {
2494
+ tree._listeners.push(listener);
2495
+ }
2496
+
2497
+ if (!tree._listeners.warned && this._maxListeners > 0 && tree._listeners.length > this._maxListeners) {
2498
+ tree._listeners.warned = true;
2499
+ logPossibleMemoryLeak.call(this, tree._listeners.length, name);
2500
+ }
2501
+ }
2502
+
2503
+ return true;
2504
+ }
2505
+ }
2506
+
2507
+ return true;
2508
+ }
2509
+
2510
+ function collectTreeEvents(tree, events, root, asArray) {
2511
+ var branches = ownKeys(tree);
2512
+ var i = branches.length;
2513
+ var branch, branchName, path;
2514
+ var hasListeners = tree['_listeners'];
2515
+ var isArrayPath;
2516
+
2517
+ while (i-- > 0) {
2518
+ branchName = branches[i];
2519
+ branch = tree[branchName];
2520
+
2521
+ if (branchName === '_listeners') {
2522
+ path = root;
2523
+ } else {
2524
+ path = root ? root.concat(branchName) : [branchName];
2525
+ }
2526
+
2527
+ isArrayPath = asArray || typeof branchName === 'symbol';
2528
+ hasListeners && events.push(isArrayPath ? path : path.join(this.delimiter));
2529
+
2530
+ if (typeof branch === 'object') {
2531
+ collectTreeEvents.call(this, branch, events, path, isArrayPath);
2532
+ }
2533
+ }
2534
+
2535
+ return events;
2536
+ }
2537
+
2538
+ function recursivelyGarbageCollect(root) {
2539
+ var keys = ownKeys(root);
2540
+ var i = keys.length;
2541
+ var obj, key, flag;
2542
+
2543
+ while (i-- > 0) {
2544
+ key = keys[i];
2545
+ obj = root[key];
2546
+
2547
+ if (obj) {
2548
+ flag = true;
2549
+
2550
+ if (key !== '_listeners' && !recursivelyGarbageCollect(obj)) {
2551
+ delete root[key];
2552
+ }
2553
+ }
2554
+ }
2555
+
2556
+ return flag;
2557
+ }
2558
+
2559
+ function Listener(emitter, event, listener) {
2560
+ this.emitter = emitter;
2561
+ this.event = event;
2562
+ this.listener = listener;
2563
+ }
2564
+
2565
+ Listener.prototype.off = function () {
2566
+ this.emitter.off(this.event, this.listener);
2567
+ return this;
2568
+ };
2569
+
2570
+ function setupListener(event, listener, options) {
2571
+ if (options === true) {
2572
+ promisify = true;
2573
+ } else if (options === false) {
2574
+ async = true;
2575
+ } else {
2576
+ if (!options || typeof options !== 'object') {
2577
+ throw TypeError('options should be an object or true');
2578
+ }
2579
+
2580
+ var async = options.async;
2581
+ var promisify = options.promisify;
2582
+ var nextTick = options.nextTick;
2583
+ var objectify = options.objectify;
2584
+ }
2585
+
2586
+ if (async || nextTick || promisify) {
2587
+ var _listener = listener;
2588
+
2589
+ var _origin = listener._origin || listener;
2590
+
2591
+ if (nextTick && !nextTickSupported) {
2592
+ throw Error('process.nextTick is not supported');
2593
+ }
2594
+
2595
+ if (promisify === undefined$1) {
2596
+ promisify = listener.constructor.name === 'AsyncFunction';
2597
+ }
2598
+
2599
+ listener = function () {
2600
+ var args = arguments;
2601
+ var context = this;
2602
+ var event = this.event;
2603
+ return promisify ? nextTick ? Promise.resolve() : new Promise(function (resolve) {
2604
+ _setImmediate(resolve);
2605
+ }).then(function () {
2606
+ context.event = event;
2607
+ return _listener.apply(context, args);
2608
+ }) : (nextTick ? process__default["default"].nextTick : _setImmediate)(function () {
2609
+ context.event = event;
2610
+
2611
+ _listener.apply(context, args);
2612
+ });
2613
+ };
2614
+
2615
+ listener._async = true;
2616
+ listener._origin = _origin;
2617
+ }
2618
+
2619
+ return [listener, objectify ? new Listener(this, event, listener) : this];
2620
+ }
2621
+
2622
+ function EventEmitter(conf) {
2623
+ this._events = {};
2624
+ this._newListener = false;
2625
+ this._removeListener = false;
2626
+ this.verboseMemoryLeak = false;
2627
+ configure.call(this, conf);
2628
+ }
2629
+
2630
+ EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property
2631
+
2632
+ EventEmitter.prototype.listenTo = function (target, events, options) {
2633
+ if (typeof target !== 'object') {
2634
+ throw TypeError('target musts be an object');
2635
+ }
2636
+
2637
+ var emitter = this;
2638
+ options = resolveOptions(options, {
2639
+ on: undefined$1,
2640
+ off: undefined$1,
2641
+ reducers: undefined$1
2642
+ }, {
2643
+ on: functionReducer,
2644
+ off: functionReducer,
2645
+ reducers: objectFunctionReducer
2646
+ });
2647
+
2648
+ function listen(events) {
2649
+ if (typeof events !== 'object') {
2650
+ throw TypeError('events must be an object');
2651
+ }
2652
+
2653
+ var reducers = options.reducers;
2654
+ var index = findTargetIndex.call(emitter, target);
2655
+ var observer;
2656
+
2657
+ if (index === -1) {
2658
+ observer = new TargetObserver(emitter, target, options);
2659
+ } else {
2660
+ observer = emitter._observers[index];
2661
+ }
2662
+
2663
+ var keys = ownKeys(events);
2664
+ var len = keys.length;
2665
+ var event;
2666
+ var isSingleReducer = typeof reducers === 'function';
2667
+
2668
+ for (var i = 0; i < len; i++) {
2669
+ event = keys[i];
2670
+ observer.subscribe(event, events[event] || event, isSingleReducer ? reducers : reducers && reducers[event]);
2671
+ }
2672
+ }
2673
+
2674
+ isArray(events) ? listen(toObject(events)) : typeof events === 'string' ? listen(toObject(events.split(/\s+/))) : listen(events);
2675
+ return this;
2676
+ };
2677
+
2678
+ EventEmitter.prototype.stopListeningTo = function (target, event) {
2679
+ var observers = this._observers;
2680
+
2681
+ if (!observers) {
2682
+ return false;
2683
+ }
2684
+
2685
+ var i = observers.length;
2686
+ var observer;
2687
+ var matched = false;
2688
+
2689
+ if (target && typeof target !== 'object') {
2690
+ throw TypeError('target should be an object');
2691
+ }
2692
+
2693
+ while (i-- > 0) {
2694
+ observer = observers[i];
2695
+
2696
+ if (!target || observer._target === target) {
2697
+ observer.unsubscribe(event);
2698
+ matched = true;
2699
+ }
2700
+ }
2701
+
2702
+ return matched;
2703
+ }; // By default EventEmitters will print a warning if more than
2704
+ // 10 listeners are added to it. This is a useful default which
2705
+ // helps finding memory leaks.
2706
+ //
2707
+ // Obviously not all Emitters should be limited to 10. This function allows
2708
+ // that to be increased. Set to zero for unlimited.
2709
+
2710
+
2711
+ EventEmitter.prototype.delimiter = '.';
2712
+
2713
+ EventEmitter.prototype.setMaxListeners = function (n) {
2714
+ if (n !== undefined$1) {
2715
+ this._maxListeners = n;
2716
+ if (!this._conf) this._conf = {};
2717
+ this._conf.maxListeners = n;
2718
+ }
2719
+ };
2720
+
2721
+ EventEmitter.prototype.getMaxListeners = function () {
2722
+ return this._maxListeners;
2723
+ };
2724
+
2725
+ EventEmitter.prototype.event = '';
2726
+
2727
+ EventEmitter.prototype.once = function (event, fn, options) {
2728
+ return this._once(event, fn, false, options);
2729
+ };
2730
+
2731
+ EventEmitter.prototype.prependOnceListener = function (event, fn, options) {
2732
+ return this._once(event, fn, true, options);
2733
+ };
2734
+
2735
+ EventEmitter.prototype._once = function (event, fn, prepend, options) {
2736
+ return this._many(event, 1, fn, prepend, options);
2737
+ };
2738
+
2739
+ EventEmitter.prototype.many = function (event, ttl, fn, options) {
2740
+ return this._many(event, ttl, fn, false, options);
2741
+ };
2742
+
2743
+ EventEmitter.prototype.prependMany = function (event, ttl, fn, options) {
2744
+ return this._many(event, ttl, fn, true, options);
2745
+ };
2746
+
2747
+ EventEmitter.prototype._many = function (event, ttl, fn, prepend, options) {
2748
+ var self = this;
2749
+
2750
+ if (typeof fn !== 'function') {
2751
+ throw new Error('many only accepts instances of Function');
2752
+ }
2753
+
2754
+ function listener() {
2755
+ if (--ttl === 0) {
2756
+ self.off(event, listener);
2757
+ }
2758
+
2759
+ return fn.apply(this, arguments);
2760
+ }
2761
+
2762
+ listener._origin = fn;
2763
+ return this._on(event, listener, prepend, options);
2764
+ };
2765
+
2766
+ EventEmitter.prototype.emit = function () {
2767
+ if (!this._events && !this._all) {
2768
+ return false;
2769
+ }
2770
+
2771
+ this._events || init.call(this);
2772
+ var type = arguments[0],
2773
+ ns,
2774
+ wildcard = this.wildcard;
2775
+ var args, l, i, j, containsSymbol;
2776
+
2777
+ if (type === 'newListener' && !this._newListener) {
2778
+ if (!this._events.newListener) {
2779
+ return false;
2780
+ }
2781
+ }
2782
+
2783
+ if (wildcard) {
2784
+ ns = type;
2785
+
2786
+ if (type !== 'newListener' && type !== 'removeListener') {
2787
+ if (typeof type === 'object') {
2788
+ l = type.length;
2789
+
2790
+ if (symbolsSupported) {
2791
+ for (i = 0; i < l; i++) {
2792
+ if (typeof type[i] === 'symbol') {
2793
+ containsSymbol = true;
2794
+ break;
2795
+ }
2796
+ }
2797
+ }
2798
+
2799
+ if (!containsSymbol) {
2800
+ type = type.join(this.delimiter);
2801
+ }
2802
+ }
2803
+ }
2804
+ }
2805
+
2806
+ var al = arguments.length;
2807
+ var handler;
2808
+
2809
+ if (this._all && this._all.length) {
2810
+ handler = this._all.slice();
2811
+
2812
+ for (i = 0, l = handler.length; i < l; i++) {
2813
+ this.event = type;
2814
+
2815
+ switch (al) {
2816
+ case 1:
2817
+ handler[i].call(this, type);
2818
+ break;
2819
+
2820
+ case 2:
2821
+ handler[i].call(this, type, arguments[1]);
2822
+ break;
2823
+
2824
+ case 3:
2825
+ handler[i].call(this, type, arguments[1], arguments[2]);
2826
+ break;
2827
+
2828
+ default:
2829
+ handler[i].apply(this, arguments);
2830
+ }
2831
+ }
2832
+ }
2833
+
2834
+ if (wildcard) {
2835
+ handler = [];
2836
+ searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l);
2837
+ } else {
2838
+ handler = this._events[type];
2839
+
2840
+ if (typeof handler === 'function') {
2841
+ this.event = type;
2842
+
2843
+ switch (al) {
2844
+ case 1:
2845
+ handler.call(this);
2846
+ break;
2847
+
2848
+ case 2:
2849
+ handler.call(this, arguments[1]);
2850
+ break;
2851
+
2852
+ case 3:
2853
+ handler.call(this, arguments[1], arguments[2]);
2854
+ break;
2855
+
2856
+ default:
2857
+ args = new Array(al - 1);
2858
+
2859
+ for (j = 1; j < al; j++) args[j - 1] = arguments[j];
2860
+
2861
+ handler.apply(this, args);
2862
+ }
2863
+
2864
+ return true;
2865
+ } else if (handler) {
2866
+ // need to make copy of handlers because list can change in the middle
2867
+ // of emit call
2868
+ handler = handler.slice();
2869
+ }
2870
+ }
2871
+
2872
+ if (handler && handler.length) {
2873
+ if (al > 3) {
2874
+ args = new Array(al - 1);
2875
+
2876
+ for (j = 1; j < al; j++) args[j - 1] = arguments[j];
2877
+ }
2878
+
2879
+ for (i = 0, l = handler.length; i < l; i++) {
2880
+ this.event = type;
2881
+
2882
+ switch (al) {
2883
+ case 1:
2884
+ handler[i].call(this);
2885
+ break;
2886
+
2887
+ case 2:
2888
+ handler[i].call(this, arguments[1]);
2889
+ break;
2890
+
2891
+ case 3:
2892
+ handler[i].call(this, arguments[1], arguments[2]);
2893
+ break;
2894
+
2895
+ default:
2896
+ handler[i].apply(this, args);
2897
+ }
2898
+ }
2899
+
2900
+ return true;
2901
+ } else if (!this.ignoreErrors && !this._all && type === 'error') {
2902
+ if (arguments[1] instanceof Error) {
2903
+ throw arguments[1]; // Unhandled 'error' event
2904
+ } else {
2905
+ throw new Error("Uncaught, unspecified 'error' event.");
2906
+ }
2907
+ }
2908
+
2909
+ return !!this._all;
2910
+ };
2911
+
2912
+ EventEmitter.prototype.emitAsync = function () {
2913
+ if (!this._events && !this._all) {
2914
+ return false;
2915
+ }
2916
+
2917
+ this._events || init.call(this);
2918
+ var type = arguments[0],
2919
+ wildcard = this.wildcard,
2920
+ ns,
2921
+ containsSymbol;
2922
+ var args, l, i, j;
2923
+
2924
+ if (type === 'newListener' && !this._newListener) {
2925
+ if (!this._events.newListener) {
2926
+ return Promise.resolve([false]);
2927
+ }
2928
+ }
2929
+
2930
+ if (wildcard) {
2931
+ ns = type;
2932
+
2933
+ if (type !== 'newListener' && type !== 'removeListener') {
2934
+ if (typeof type === 'object') {
2935
+ l = type.length;
2936
+
2937
+ if (symbolsSupported) {
2938
+ for (i = 0; i < l; i++) {
2939
+ if (typeof type[i] === 'symbol') {
2940
+ containsSymbol = true;
2941
+ break;
2942
+ }
2943
+ }
2944
+ }
2945
+
2946
+ if (!containsSymbol) {
2947
+ type = type.join(this.delimiter);
2948
+ }
2949
+ }
2950
+ }
2951
+ }
2952
+
2953
+ var promises = [];
2954
+ var al = arguments.length;
2955
+ var handler;
2956
+
2957
+ if (this._all) {
2958
+ for (i = 0, l = this._all.length; i < l; i++) {
2959
+ this.event = type;
2960
+
2961
+ switch (al) {
2962
+ case 1:
2963
+ promises.push(this._all[i].call(this, type));
2964
+ break;
2965
+
2966
+ case 2:
2967
+ promises.push(this._all[i].call(this, type, arguments[1]));
2968
+ break;
2969
+
2970
+ case 3:
2971
+ promises.push(this._all[i].call(this, type, arguments[1], arguments[2]));
2972
+ break;
2973
+
2974
+ default:
2975
+ promises.push(this._all[i].apply(this, arguments));
2976
+ }
2977
+ }
2978
+ }
2979
+
2980
+ if (wildcard) {
2981
+ handler = [];
2982
+ searchListenerTree.call(this, handler, ns, this.listenerTree, 0);
2983
+ } else {
2984
+ handler = this._events[type];
2985
+ }
2986
+
2987
+ if (typeof handler === 'function') {
2988
+ this.event = type;
2989
+
2990
+ switch (al) {
2991
+ case 1:
2992
+ promises.push(handler.call(this));
2993
+ break;
2994
+
2995
+ case 2:
2996
+ promises.push(handler.call(this, arguments[1]));
2997
+ break;
2998
+
2999
+ case 3:
3000
+ promises.push(handler.call(this, arguments[1], arguments[2]));
3001
+ break;
3002
+
3003
+ default:
3004
+ args = new Array(al - 1);
3005
+
3006
+ for (j = 1; j < al; j++) args[j - 1] = arguments[j];
3007
+
3008
+ promises.push(handler.apply(this, args));
3009
+ }
3010
+ } else if (handler && handler.length) {
3011
+ handler = handler.slice();
3012
+
3013
+ if (al > 3) {
3014
+ args = new Array(al - 1);
3015
+
3016
+ for (j = 1; j < al; j++) args[j - 1] = arguments[j];
3017
+ }
3018
+
3019
+ for (i = 0, l = handler.length; i < l; i++) {
3020
+ this.event = type;
3021
+
3022
+ switch (al) {
3023
+ case 1:
3024
+ promises.push(handler[i].call(this));
3025
+ break;
3026
+
3027
+ case 2:
3028
+ promises.push(handler[i].call(this, arguments[1]));
3029
+ break;
3030
+
3031
+ case 3:
3032
+ promises.push(handler[i].call(this, arguments[1], arguments[2]));
3033
+ break;
3034
+
3035
+ default:
3036
+ promises.push(handler[i].apply(this, args));
3037
+ }
3038
+ }
3039
+ } else if (!this.ignoreErrors && !this._all && type === 'error') {
3040
+ if (arguments[1] instanceof Error) {
3041
+ return Promise.reject(arguments[1]); // Unhandled 'error' event
3042
+ } else {
3043
+ return Promise.reject("Uncaught, unspecified 'error' event.");
3044
+ }
3045
+ }
3046
+
3047
+ return Promise.all(promises);
3048
+ };
3049
+
3050
+ EventEmitter.prototype.on = function (type, listener, options) {
3051
+ return this._on(type, listener, false, options);
3052
+ };
3053
+
3054
+ EventEmitter.prototype.prependListener = function (type, listener, options) {
3055
+ return this._on(type, listener, true, options);
3056
+ };
3057
+
3058
+ EventEmitter.prototype.onAny = function (fn) {
3059
+ return this._onAny(fn, false);
3060
+ };
3061
+
3062
+ EventEmitter.prototype.prependAny = function (fn) {
3063
+ return this._onAny(fn, true);
3064
+ };
3065
+
3066
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
3067
+
3068
+ EventEmitter.prototype._onAny = function (fn, prepend) {
3069
+ if (typeof fn !== 'function') {
3070
+ throw new Error('onAny only accepts instances of Function');
3071
+ }
3072
+
3073
+ if (!this._all) {
3074
+ this._all = [];
3075
+ } // Add the function to the event listener collection.
3076
+
3077
+
3078
+ if (prepend) {
3079
+ this._all.unshift(fn);
3080
+ } else {
3081
+ this._all.push(fn);
3082
+ }
3083
+
3084
+ return this;
3085
+ };
3086
+
3087
+ EventEmitter.prototype._on = function (type, listener, prepend, options) {
3088
+ if (typeof type === 'function') {
3089
+ this._onAny(type, listener);
3090
+
3091
+ return this;
3092
+ }
3093
+
3094
+ if (typeof listener !== 'function') {
3095
+ throw new Error('on only accepts instances of Function');
3096
+ }
3097
+
3098
+ this._events || init.call(this);
3099
+ var returnValue = this,
3100
+ temp;
3101
+
3102
+ if (options !== undefined$1) {
3103
+ temp = setupListener.call(this, type, listener, options);
3104
+ listener = temp[0];
3105
+ returnValue = temp[1];
3106
+ } // To avoid recursion in the case that type == "newListeners"! Before
3107
+ // adding it to the listeners, first emit "newListeners".
3108
+
3109
+
3110
+ if (this._newListener) {
3111
+ this.emit('newListener', type, listener);
3112
+ }
3113
+
3114
+ if (this.wildcard) {
3115
+ growListenerTree.call(this, type, listener, prepend);
3116
+ return returnValue;
3117
+ }
3118
+
3119
+ if (!this._events[type]) {
3120
+ // Optimize the case of one listener. Don't need the extra array object.
3121
+ this._events[type] = listener;
3122
+ } else {
3123
+ if (typeof this._events[type] === 'function') {
3124
+ // Change to array.
3125
+ this._events[type] = [this._events[type]];
3126
+ } // If we've already got an array, just add
3127
+
3128
+
3129
+ if (prepend) {
3130
+ this._events[type].unshift(listener);
3131
+ } else {
3132
+ this._events[type].push(listener);
3133
+ } // Check for listener leak
3134
+
3135
+
3136
+ if (!this._events[type].warned && this._maxListeners > 0 && this._events[type].length > this._maxListeners) {
3137
+ this._events[type].warned = true;
3138
+ logPossibleMemoryLeak.call(this, this._events[type].length, type);
3139
+ }
3140
+ }
3141
+
3142
+ return returnValue;
3143
+ };
3144
+
3145
+ EventEmitter.prototype.off = function (type, listener) {
3146
+ if (typeof listener !== 'function') {
3147
+ throw new Error('removeListener only takes instances of Function');
3148
+ }
3149
+
3150
+ var handlers,
3151
+ leafs = [];
3152
+
3153
+ if (this.wildcard) {
3154
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
3155
+ leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0);
3156
+ if (!leafs) return this;
3157
+ } else {
3158
+ // does not use listeners(), so no side effect of creating _events[type]
3159
+ if (!this._events[type]) return this;
3160
+ handlers = this._events[type];
3161
+ leafs.push({
3162
+ _listeners: handlers
3163
+ });
3164
+ }
3165
+
3166
+ for (var iLeaf = 0; iLeaf < leafs.length; iLeaf++) {
3167
+ var leaf = leafs[iLeaf];
3168
+ handlers = leaf._listeners;
3169
+
3170
+ if (isArray(handlers)) {
3171
+ var position = -1;
3172
+
3173
+ for (var i = 0, length = handlers.length; i < length; i++) {
3174
+ if (handlers[i] === listener || handlers[i].listener && handlers[i].listener === listener || handlers[i]._origin && handlers[i]._origin === listener) {
3175
+ position = i;
3176
+ break;
3177
+ }
3178
+ }
3179
+
3180
+ if (position < 0) {
3181
+ continue;
3182
+ }
3183
+
3184
+ if (this.wildcard) {
3185
+ leaf._listeners.splice(position, 1);
3186
+ } else {
3187
+ this._events[type].splice(position, 1);
3188
+ }
3189
+
3190
+ if (handlers.length === 0) {
3191
+ if (this.wildcard) {
3192
+ delete leaf._listeners;
3193
+ } else {
3194
+ delete this._events[type];
3195
+ }
3196
+ }
3197
+
3198
+ if (this._removeListener) this.emit("removeListener", type, listener);
3199
+ return this;
3200
+ } else if (handlers === listener || handlers.listener && handlers.listener === listener || handlers._origin && handlers._origin === listener) {
3201
+ if (this.wildcard) {
3202
+ delete leaf._listeners;
3203
+ } else {
3204
+ delete this._events[type];
3205
+ }
3206
+
3207
+ if (this._removeListener) this.emit("removeListener", type, listener);
3208
+ }
3209
+ }
3210
+
3211
+ this.listenerTree && recursivelyGarbageCollect(this.listenerTree);
3212
+ return this;
3213
+ };
3214
+
3215
+ EventEmitter.prototype.offAny = function (fn) {
3216
+ var i = 0,
3217
+ l = 0,
3218
+ fns;
3219
+
3220
+ if (fn && this._all && this._all.length > 0) {
3221
+ fns = this._all;
3222
+
3223
+ for (i = 0, l = fns.length; i < l; i++) {
3224
+ if (fn === fns[i]) {
3225
+ fns.splice(i, 1);
3226
+ if (this._removeListener) this.emit("removeListenerAny", fn);
3227
+ return this;
3228
+ }
3229
+ }
3230
+ } else {
3231
+ fns = this._all;
3232
+
3233
+ if (this._removeListener) {
3234
+ for (i = 0, l = fns.length; i < l; i++) this.emit("removeListenerAny", fns[i]);
3235
+ }
3236
+
3237
+ this._all = [];
3238
+ }
3239
+
3240
+ return this;
3241
+ };
3242
+
3243
+ EventEmitter.prototype.removeListener = EventEmitter.prototype.off;
3244
+
3245
+ EventEmitter.prototype.removeAllListeners = function (type) {
3246
+ if (type === undefined$1) {
3247
+ !this._events || init.call(this);
3248
+ return this;
3249
+ }
3250
+
3251
+ if (this.wildcard) {
3252
+ var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0),
3253
+ leaf,
3254
+ i;
3255
+ if (!leafs) return this;
3256
+
3257
+ for (i = 0; i < leafs.length; i++) {
3258
+ leaf = leafs[i];
3259
+ leaf._listeners = null;
3260
+ }
3261
+
3262
+ this.listenerTree && recursivelyGarbageCollect(this.listenerTree);
3263
+ } else if (this._events) {
3264
+ this._events[type] = null;
3265
+ }
3266
+
3267
+ return this;
3268
+ };
3269
+
3270
+ EventEmitter.prototype.listeners = function (type) {
3271
+ var _events = this._events;
3272
+ var keys, listeners, allListeners;
3273
+ var i;
3274
+ var listenerTree;
3275
+
3276
+ if (type === undefined$1) {
3277
+ if (this.wildcard) {
3278
+ throw Error('event name required for wildcard emitter');
3279
+ }
3280
+
3281
+ if (!_events) {
3282
+ return [];
3283
+ }
3284
+
3285
+ keys = ownKeys(_events);
3286
+ i = keys.length;
3287
+ allListeners = [];
3288
+
3289
+ while (i-- > 0) {
3290
+ listeners = _events[keys[i]];
3291
+
3292
+ if (typeof listeners === 'function') {
3293
+ allListeners.push(listeners);
3294
+ } else {
3295
+ allListeners.push.apply(allListeners, listeners);
3296
+ }
3297
+ }
3298
+
3299
+ return allListeners;
3300
+ } else {
3301
+ if (this.wildcard) {
3302
+ listenerTree = this.listenerTree;
3303
+ if (!listenerTree) return [];
3304
+ var handlers = [];
3305
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
3306
+ searchListenerTree.call(this, handlers, ns, listenerTree, 0);
3307
+ return handlers;
3308
+ }
3309
+
3310
+ if (!_events) {
3311
+ return [];
3312
+ }
3313
+
3314
+ listeners = _events[type];
3315
+
3316
+ if (!listeners) {
3317
+ return [];
3318
+ }
3319
+
3320
+ return typeof listeners === 'function' ? [listeners] : listeners;
3321
+ }
3322
+ };
3323
+
3324
+ EventEmitter.prototype.eventNames = function (nsAsArray) {
3325
+ var _events = this._events;
3326
+ return this.wildcard ? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : _events ? ownKeys(_events) : [];
3327
+ };
3328
+
3329
+ EventEmitter.prototype.listenerCount = function (type) {
3330
+ return this.listeners(type).length;
3331
+ };
3332
+
3333
+ EventEmitter.prototype.hasListeners = function (type) {
3334
+ if (this.wildcard) {
3335
+ var handlers = [];
3336
+ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
3337
+ searchListenerTree.call(this, handlers, ns, this.listenerTree, 0);
3338
+ return handlers.length > 0;
3339
+ }
3340
+
3341
+ var _events = this._events;
3342
+ var _all = this._all;
3343
+ return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type]));
3344
+ };
3345
+
3346
+ EventEmitter.prototype.listenersAny = function () {
3347
+ if (this._all) {
3348
+ return this._all;
3349
+ } else {
3350
+ return [];
3351
+ }
3352
+ };
3353
+
3354
+ EventEmitter.prototype.waitFor = function (event, options) {
3355
+ var self = this;
3356
+ var type = typeof options;
3357
+
3358
+ if (type === 'number') {
3359
+ options = {
3360
+ timeout: options
3361
+ };
3362
+ } else if (type === 'function') {
3363
+ options = {
3364
+ filter: options
3365
+ };
3366
+ }
3367
+
3368
+ options = resolveOptions(options, {
3369
+ timeout: 0,
3370
+ filter: undefined$1,
3371
+ handleError: false,
3372
+ Promise: Promise,
3373
+ overload: false
3374
+ }, {
3375
+ filter: functionReducer,
3376
+ Promise: constructorReducer
3377
+ });
3378
+ return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) {
3379
+ function listener() {
3380
+ var filter = options.filter;
3381
+
3382
+ if (filter && !filter.apply(self, arguments)) {
3383
+ return;
3384
+ }
3385
+
3386
+ self.off(event, listener);
3387
+
3388
+ if (options.handleError) {
3389
+ var err = arguments[0];
3390
+ err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1));
3391
+ } else {
3392
+ resolve(toArray.apply(null, arguments));
3393
+ }
3394
+ }
3395
+
3396
+ onCancel(function () {
3397
+ self.off(event, listener);
3398
+ });
3399
+
3400
+ self._on(event, listener, false);
3401
+ }, {
3402
+ timeout: options.timeout,
3403
+ overload: options.overload
3404
+ });
3405
+ };
3406
+
3407
+ function once(emitter, name, options) {
3408
+ options = resolveOptions(options, {
3409
+ Promise: Promise,
3410
+ timeout: 0,
3411
+ overload: false
3412
+ }, {
3413
+ Promise: constructorReducer
3414
+ });
3415
+ var _Promise = options.Promise;
3416
+ return makeCancelablePromise(_Promise, function (resolve, reject, onCancel) {
3417
+ var handler;
3418
+
3419
+ if (typeof emitter.addEventListener === 'function') {
3420
+ handler = function () {
3421
+ resolve(toArray.apply(null, arguments));
3422
+ };
3423
+
3424
+ onCancel(function () {
3425
+ emitter.removeEventListener(name, handler);
3426
+ });
3427
+ emitter.addEventListener(name, handler, {
3428
+ once: true
3429
+ });
3430
+ return;
3431
+ }
3432
+
3433
+ var eventListener = function () {
3434
+ errorListener && emitter.removeListener('error', errorListener);
3435
+ resolve(toArray.apply(null, arguments));
3436
+ };
3437
+
3438
+ var errorListener;
3439
+
3440
+ if (name !== 'error') {
3441
+ errorListener = function (err) {
3442
+ emitter.removeListener(name, eventListener);
3443
+ reject(err);
3444
+ };
3445
+
3446
+ emitter.once('error', errorListener);
3447
+ }
3448
+
3449
+ onCancel(function () {
3450
+ errorListener && emitter.removeListener('error', errorListener);
3451
+ emitter.removeListener(name, eventListener);
3452
+ });
3453
+ emitter.once(name, eventListener);
3454
+ }, {
3455
+ timeout: options.timeout,
3456
+ overload: options.overload
3457
+ });
3458
+ }
3459
+
3460
+ var prototype = EventEmitter.prototype;
3461
+ Object.defineProperties(EventEmitter, {
3462
+ defaultMaxListeners: {
3463
+ get: function () {
3464
+ return prototype._maxListeners;
3465
+ },
3466
+ set: function (n) {
3467
+ if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) {
3468
+ throw TypeError('n must be a non-negative number');
3469
+ }
3470
+
3471
+ prototype._maxListeners = n;
3472
+ },
3473
+ enumerable: true
3474
+ },
3475
+ once: {
3476
+ value: once,
3477
+ writable: true,
3478
+ configurable: true
3479
+ }
3480
+ });
3481
+ Object.defineProperties(prototype, {
3482
+ _maxListeners: {
3483
+ value: defaultMaxListeners,
3484
+ writable: true,
3485
+ configurable: true
3486
+ },
3487
+ _observers: {
3488
+ value: null,
3489
+ writable: true,
3490
+ configurable: true
3491
+ }
3492
+ });
3493
+
3494
+ if (typeof undefined$1 === 'function' && undefined$1.amd) {
3495
+ // AMD. Register as an anonymous module.
3496
+ undefined$1(function () {
3497
+ return EventEmitter;
3498
+ });
3499
+ } else {
3500
+ // CommonJS
3501
+ module.exports = EventEmitter;
3502
+ }
3503
+ }();
3504
+ })(eventemitter2);
3505
+
3506
+ var EventEmitter = eventemitter2.exports;
3507
+
3508
+ /**
3509
+ * @namespace Salla.event
3510
+ *
3511
+ * @property {string} delimiter
3512
+ * @property {array} loggableEvents - log errors or important events.
3513
+ */
3514
+
3515
+ class Emitter extends EventEmitter {
3516
+ constructor() {
3517
+ let delimiter = "::";
3518
+ super({
3519
+ wildcard: true,
3520
+ delimiter: delimiter,
3521
+ newListener: false,
3522
+ removeListener: false,
3523
+ maxListeners: 10,
3524
+ verboseMemoryLeak: false,
3525
+ ignoreErrors: false
3526
+ });
3527
+ this.delimiter = delimiter;
3528
+
3529
+ if (typeof document !== "undefined") {
3530
+ this.body = document.querySelector("body");
3531
+ }
3532
+
3533
+ this.logableEvents = ["cart::item.added.failed", "cart::item.deleted.failed"];
3534
+ this.ingoreLogEvents = ["document::click", "document::keyup", "document::change" //'document::submit',
3535
+ ];
3536
+ this.noneFireableActions = ["document.request"];
3537
+ }
3538
+ /**
3539
+ * @param {string} event_name
3540
+ * @param data
3541
+ *
3542
+ * @deprecated , legacy code, use dispatch() instead
3543
+ */
3544
+
3545
+
3546
+ createAndDispatch(event_name, ...data) {
3547
+ this.dispatch(event_name, ...data);
3548
+ }
3549
+
3550
+ emit(event_name, ...data) {
3551
+ /**
3552
+ * if the event, is api/event method, call it,
3553
+ * ex: cart::quick.add call Salla.api.cart.quickAdd(...data)
3554
+ * we don't used Salla.call(actionName)(...data), to avoid losing this scope in our apis.
3555
+ *
3556
+ * @deprecated don't use it anymore
3557
+ */
3558
+ let actionName = event_name.replace("::", ".");
3559
+
3560
+ if (!this.noneFireableActions.includes(actionName) && typeof Salla.call !== "undefined" && typeof Salla.call(actionName) === "function") {
3561
+ Salla.log(`'Salla.${actionName}(...)' triggered using event '${event_name}'`);
3562
+ actionName = actionName.split("."); //['cart','addItem']
3563
+
3564
+ salla[actionName[0]][actionName[1]](...data);
3565
+ return;
3566
+ }
3567
+
3568
+ super.emit(event_name, ...data); // let's send the event to data layer
3569
+
3570
+ if (typeof window !== "undefined") {
3571
+ window.dataLayer = window.dataLayer || [];
3572
+ window.dataLayer.push(Object.assign({
3573
+ event: event_name
3574
+ }, ...data.values()));
3575
+ } //if there is need to log errors, or events, lets do it here.
3576
+
3577
+
3578
+ if (!this.ingoreLogEvents.includes(event_name) && (typeof Salla.config !== "undefined" && Salla.config.get("debug") || this.logableEvents.includes(event_name)) && typeof Salla.logger !== "undefined") {
3579
+ Salla.logger.event(event_name, ...data);
3580
+ }
3581
+
3582
+ this.dispatchMobileEvent(event_name, { ...data.values()
3583
+ });
3584
+ }
3585
+ /**
3586
+ * Fire Event with data
3587
+ *
3588
+ * @param {string} event_name - action name like `cart::addItem` or event name like `cart::item.added`
3589
+ * @param {any|undefined} data
3590
+ * @data {{payload}} data
3591
+ */
3592
+
3593
+
3594
+ dispatch(event_name, ...data) {
3595
+ return this.emit(event_name, ...data);
3596
+ }
3597
+ /**
3598
+ * Fire multi events using object of events
3599
+ *
3600
+ * @param {Object.<string, *>} events
3601
+ */
3602
+
3603
+
3604
+ dispatchEvents(events) {
3605
+ if (!events || typeof events !== "object") {
3606
+ Salla.log("No Events To Dispatch!", events);
3607
+ return;
3608
+ }
3609
+
3610
+ for (const [event_name, payload] of Object.entries(events)) {
3611
+ this.dispatch(event_name, payload);
3612
+ }
3613
+ }
3614
+ /**
3615
+ * Alias for on function
3616
+ *
3617
+ * @param {string} eventName
3618
+ * @param {function} callback
3619
+ * @deprecated use on
3620
+ */
3621
+
3622
+
3623
+ addListener(eventName, callback) {
3624
+ return this.on(eventName, callback);
3625
+ }
3626
+ /**
3627
+ * Alias for on function
3628
+ *
3629
+ * @param {string} eventName
3630
+ * @param {function} callback
3631
+ * @deprecated use on
3632
+ */
3633
+
3634
+
3635
+ addEventListener(eventName, callback) {
3636
+ return this.on(eventName, callback);
3637
+ }
3638
+ /**
3639
+ * Alias for this.addListener
3640
+ * @param {string} eventName
3641
+ * @param {function} callback
3642
+ */
3643
+
3644
+
3645
+ listen(eventName, callback) {
3646
+ return this.on(eventName, callback);
3647
+ }
3648
+ /**
3649
+ * Register Global listener will allow you to track all events in salla,
3650
+ * all Salla events will push to it.
3651
+ *
3652
+ * @param {string} name
3653
+ * @param {function} callback
3654
+ * @deprecated use onAny
3655
+ */
3656
+
3657
+
3658
+ registerGlobalListener(name, callback) {
3659
+ return this.onAny(callback);
3660
+ }
3661
+ /**
3662
+ * This help to push an event to mobile app.
3663
+ *
3664
+ * @param eventName
3665
+ * @param details
3666
+ * @returns {string}
3667
+ */
3668
+
3669
+
3670
+ dispatchMobileEvent(eventName, details = {}) {
3671
+ if (typeof window === "undefined" || !window.dataLayer || !dataLayer[0] || !dataLayer[0].page || !dataLayer[0].page.mobileApp) {
3672
+ return "";
3673
+ }
3674
+
3675
+ if (window.webkit) {
3676
+ try {
3677
+ window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({
3678
+ event: eventName,
3679
+ details: details
3680
+ }));
3681
+ } catch (err) {
3682
+ Salla.log(err, "The native context does not exist yet");
3683
+ }
3684
+
3685
+ return;
3686
+ }
3687
+
3688
+ if (Android) {
3689
+ try {
3690
+ Android.customEventWithData(eventName, JSON.stringify({
3691
+ details: details
3692
+ }));
3693
+ } catch (err) {
3694
+ Salla.log(err, "The native context does not exist yet");
3695
+ }
3696
+ }
3697
+ }
3698
+
3699
+ }
3700
+
3701
+ var assign = make_assign();
3702
+ var create$1 = make_create();
3703
+ var trim$1 = make_trim();
3704
+ var Global$3 = typeof window !== 'undefined' ? window : commonjsGlobal;
3705
+ var util$4 = {
3706
+ assign: assign,
3707
+ create: create$1,
3708
+ trim: trim$1,
3709
+ bind: bind$1,
3710
+ slice: slice$1,
3711
+ each: each$5,
3712
+ map: map,
3713
+ pluck: pluck$1,
3714
+ isList: isList$1,
3715
+ isFunction: isFunction$1,
3716
+ isObject: isObject$1,
3717
+ Global: Global$3
3718
+ };
3719
+
3720
+ function make_assign() {
3721
+ if (Object.assign) {
3722
+ return Object.assign;
3723
+ } else {
3724
+ return function shimAssign(obj, props1, props2, etc) {
3725
+ for (var i = 1; i < arguments.length; i++) {
3726
+ each$5(Object(arguments[i]), function (val, key) {
3727
+ obj[key] = val;
3728
+ });
3729
+ }
3730
+
3731
+ return obj;
3732
+ };
3733
+ }
3734
+ }
3735
+
3736
+ function make_create() {
3737
+ if (Object.create) {
3738
+ return function create(obj, assignProps1, assignProps2, etc) {
3739
+ var assignArgsList = slice$1(arguments, 1);
3740
+ return assign.apply(this, [Object.create(obj)].concat(assignArgsList));
3741
+ };
3742
+ } else {
3743
+ function F() {} // eslint-disable-line no-inner-declarations
3744
+
3745
+
3746
+ return function create(obj, assignProps1, assignProps2, etc) {
3747
+ var assignArgsList = slice$1(arguments, 1);
3748
+ F.prototype = obj;
3749
+ return assign.apply(this, [new F()].concat(assignArgsList));
3750
+ };
3751
+ }
3752
+ }
3753
+
3754
+ function make_trim() {
3755
+ if (String.prototype.trim) {
3756
+ return function trim(str) {
3757
+ return String.prototype.trim.call(str);
3758
+ };
3759
+ } else {
3760
+ return function trim(str) {
3761
+ return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
3762
+ };
3763
+ }
3764
+ }
3765
+
3766
+ function bind$1(obj, fn) {
3767
+ return function () {
3768
+ return fn.apply(obj, Array.prototype.slice.call(arguments, 0));
3769
+ };
3770
+ }
3771
+
3772
+ function slice$1(arr, index) {
3773
+ return Array.prototype.slice.call(arr, index || 0);
3774
+ }
3775
+
3776
+ function each$5(obj, fn) {
3777
+ pluck$1(obj, function (val, key) {
3778
+ fn(val, key);
3779
+ return false;
3780
+ });
3781
+ }
3782
+
3783
+ function map(obj, fn) {
3784
+ var res = isList$1(obj) ? [] : {};
3785
+ pluck$1(obj, function (v, k) {
3786
+ res[k] = fn(v, k);
3787
+ return false;
3788
+ });
3789
+ return res;
3790
+ }
3791
+
3792
+ function pluck$1(obj, fn) {
3793
+ if (isList$1(obj)) {
3794
+ for (var i = 0; i < obj.length; i++) {
3795
+ if (fn(obj[i], i)) {
3796
+ return obj[i];
3797
+ }
3798
+ }
3799
+ } else {
3800
+ for (var key in obj) {
3801
+ if (obj.hasOwnProperty(key)) {
3802
+ if (fn(obj[key], key)) {
3803
+ return obj[key];
3804
+ }
3805
+ }
3806
+ }
3807
+ }
3808
+ }
3809
+
3810
+ function isList$1(val) {
3811
+ return val != null && typeof val != 'function' && typeof val.length == 'number';
3812
+ }
3813
+
3814
+ function isFunction$1(val) {
3815
+ return val && {}.toString.call(val) === '[object Function]';
3816
+ }
3817
+
3818
+ function isObject$1(val) {
3819
+ return val && {}.toString.call(val) === '[object Object]';
3820
+ }
3821
+
3822
+ var util$3 = util$4;
3823
+ var slice = util$3.slice;
3824
+ var pluck = util$3.pluck;
3825
+ var each$4 = util$3.each;
3826
+ var bind = util$3.bind;
3827
+ var create = util$3.create;
3828
+ var isList = util$3.isList;
3829
+ var isFunction = util$3.isFunction;
3830
+ var isObject = util$3.isObject;
3831
+ var storeEngine = {
3832
+ createStore: createStore
3833
+ };
3834
+ var storeAPI = {
3835
+ version: '2.0.12',
3836
+ enabled: false,
3837
+ // get returns the value of the given key. If that value
3838
+ // is undefined, it returns optionalDefaultValue instead.
3839
+ get: function (key, optionalDefaultValue) {
3840
+ var data = this.storage.read(this._namespacePrefix + key);
3841
+ return this._deserialize(data, optionalDefaultValue);
3842
+ },
3843
+ // set will store the given value at key and returns value.
3844
+ // Calling set with value === undefined is equivalent to calling remove.
3845
+ set: function (key, value) {
3846
+ if (value === undefined) {
3847
+ return this.remove(key);
3848
+ }
3849
+
3850
+ this.storage.write(this._namespacePrefix + key, this._serialize(value));
3851
+ return value;
3852
+ },
3853
+ // remove deletes the key and value stored at the given key.
3854
+ remove: function (key) {
3855
+ this.storage.remove(this._namespacePrefix + key);
3856
+ },
3857
+ // each will call the given callback once for each key-value pair
3858
+ // in this store.
3859
+ each: function (callback) {
3860
+ var self = this;
3861
+ this.storage.each(function (val, namespacedKey) {
3862
+ callback.call(self, self._deserialize(val), (namespacedKey || '').replace(self._namespaceRegexp, ''));
3863
+ });
3864
+ },
3865
+ // clearAll will remove all the stored key-value pairs in this store.
3866
+ clearAll: function () {
3867
+ this.storage.clearAll();
3868
+ },
3869
+ // additional functionality that can't live in plugins
3870
+ // ---------------------------------------------------
3871
+ // hasNamespace returns true if this store instance has the given namespace.
3872
+ hasNamespace: function (namespace) {
3873
+ return this._namespacePrefix == '__storejs_' + namespace + '_';
3874
+ },
3875
+ // createStore creates a store.js instance with the first
3876
+ // functioning storage in the list of storage candidates,
3877
+ // and applies the the given mixins to the instance.
3878
+ createStore: function () {
3879
+ return createStore.apply(this, arguments);
3880
+ },
3881
+ addPlugin: function (plugin) {
3882
+ this._addPlugin(plugin);
3883
+ },
3884
+ namespace: function (namespace) {
3885
+ return createStore(this.storage, this.plugins, namespace);
3886
+ }
3887
+ };
3888
+
3889
+ function _warn() {
3890
+ var _console = typeof console == 'undefined' ? null : console;
3891
+
3892
+ if (!_console) {
3893
+ return;
3894
+ }
3895
+
3896
+ var fn = _console.warn ? _console.warn : _console.log;
3897
+ fn.apply(_console, arguments);
3898
+ }
3899
+
3900
+ function createStore(storages, plugins, namespace) {
3901
+ if (!namespace) {
3902
+ namespace = '';
3903
+ }
3904
+
3905
+ if (storages && !isList(storages)) {
3906
+ storages = [storages];
3907
+ }
3908
+
3909
+ if (plugins && !isList(plugins)) {
3910
+ plugins = [plugins];
3911
+ }
3912
+
3913
+ var namespacePrefix = namespace ? '__storejs_' + namespace + '_' : '';
3914
+ var namespaceRegexp = namespace ? new RegExp('^' + namespacePrefix) : null;
3915
+ var legalNamespaces = /^[a-zA-Z0-9_\-]*$/; // alpha-numeric + underscore and dash
3916
+
3917
+ if (!legalNamespaces.test(namespace)) {
3918
+ throw new Error('store.js namespaces can only have alphanumerics + underscores and dashes');
3919
+ }
3920
+
3921
+ var _privateStoreProps = {
3922
+ _namespacePrefix: namespacePrefix,
3923
+ _namespaceRegexp: namespaceRegexp,
3924
+ _testStorage: function (storage) {
3925
+ try {
3926
+ var testStr = '__storejs__test__';
3927
+ storage.write(testStr, testStr);
3928
+ var ok = storage.read(testStr) === testStr;
3929
+ storage.remove(testStr);
3930
+ return ok;
3931
+ } catch (e) {
3932
+ return false;
3933
+ }
3934
+ },
3935
+ _assignPluginFnProp: function (pluginFnProp, propName) {
3936
+ var oldFn = this[propName];
3937
+
3938
+ this[propName] = function pluginFn() {
3939
+ var args = slice(arguments, 0);
3940
+ var self = this; // super_fn calls the old function which was overwritten by
3941
+ // this mixin.
3942
+
3943
+ function super_fn() {
3944
+ if (!oldFn) {
3945
+ return;
3946
+ }
3947
+
3948
+ each$4(arguments, function (arg, i) {
3949
+ args[i] = arg;
3950
+ });
3951
+ return oldFn.apply(self, args);
3952
+ } // Give mixing function access to super_fn by prefixing all mixin function
3953
+ // arguments with super_fn.
3954
+
3955
+
3956
+ var newFnArgs = [super_fn].concat(args);
3957
+ return pluginFnProp.apply(self, newFnArgs);
3958
+ };
3959
+ },
3960
+ _serialize: function (obj) {
3961
+ return JSON.stringify(obj);
3962
+ },
3963
+ _deserialize: function (strVal, defaultVal) {
3964
+ if (!strVal) {
3965
+ return defaultVal;
3966
+ } // It is possible that a raw string value has been previously stored
3967
+ // in a storage without using store.js, meaning it will be a raw
3968
+ // string value instead of a JSON serialized string. By defaulting
3969
+ // to the raw string value in case of a JSON parse error, we allow
3970
+ // for past stored values to be forwards-compatible with store.js
3971
+
3972
+
3973
+ var val = '';
3974
+
3975
+ try {
3976
+ val = JSON.parse(strVal);
3977
+ } catch (e) {
3978
+ val = strVal;
3979
+ }
3980
+
3981
+ return val !== undefined ? val : defaultVal;
3982
+ },
3983
+ _addStorage: function (storage) {
3984
+ if (this.enabled) {
3985
+ return;
3986
+ }
3987
+
3988
+ if (this._testStorage(storage)) {
3989
+ this.storage = storage;
3990
+ this.enabled = true;
3991
+ }
3992
+ },
3993
+ _addPlugin: function (plugin) {
3994
+ var self = this; // If the plugin is an array, then add all plugins in the array.
3995
+ // This allows for a plugin to depend on other plugins.
3996
+
3997
+ if (isList(plugin)) {
3998
+ each$4(plugin, function (plugin) {
3999
+ self._addPlugin(plugin);
4000
+ });
4001
+ return;
4002
+ } // Keep track of all plugins we've seen so far, so that we
4003
+ // don't add any of them twice.
4004
+
4005
+
4006
+ var seenPlugin = pluck(this.plugins, function (seenPlugin) {
4007
+ return plugin === seenPlugin;
4008
+ });
4009
+
4010
+ if (seenPlugin) {
4011
+ return;
4012
+ }
4013
+
4014
+ this.plugins.push(plugin); // Check that the plugin is properly formed
4015
+
4016
+ if (!isFunction(plugin)) {
4017
+ throw new Error('Plugins must be function values that return objects');
4018
+ }
4019
+
4020
+ var pluginProperties = plugin.call(this);
4021
+
4022
+ if (!isObject(pluginProperties)) {
4023
+ throw new Error('Plugins must return an object of function properties');
4024
+ } // Add the plugin function properties to this store instance.
4025
+
4026
+
4027
+ each$4(pluginProperties, function (pluginFnProp, propName) {
4028
+ if (!isFunction(pluginFnProp)) {
4029
+ throw new Error('Bad plugin property: ' + propName + ' from plugin ' + plugin.name + '. Plugins should only return functions.');
4030
+ }
4031
+
4032
+ self._assignPluginFnProp(pluginFnProp, propName);
4033
+ });
4034
+ },
4035
+ // Put deprecated properties in the private API, so as to not expose it to accidential
4036
+ // discovery through inspection of the store object.
4037
+ // Deprecated: addStorage
4038
+ addStorage: function (storage) {
4039
+ _warn('store.addStorage(storage) is deprecated. Use createStore([storages])');
4040
+
4041
+ this._addStorage(storage);
4042
+ }
4043
+ };
4044
+ var store = create(_privateStoreProps, storeAPI, {
4045
+ plugins: []
4046
+ });
4047
+ store.raw = {};
4048
+ each$4(store, function (prop, propName) {
4049
+ if (isFunction(prop)) {
4050
+ store.raw[propName] = bind(store, prop);
4051
+ }
4052
+ });
4053
+ each$4(storages, function (storage) {
4054
+ store._addStorage(storage);
4055
+ });
4056
+ each$4(plugins, function (plugin) {
4057
+ store._addPlugin(plugin);
4058
+ });
4059
+ return store;
4060
+ }
4061
+
4062
+ var util$2 = util$4;
4063
+ var Global$2 = util$2.Global;
4064
+ var localStorage_1 = {
4065
+ name: 'localStorage',
4066
+ read: read$3,
4067
+ write: write$3,
4068
+ each: each$3,
4069
+ remove: remove$3,
4070
+ clearAll: clearAll$3
4071
+ };
4072
+
4073
+ function localStorage() {
4074
+ return Global$2.localStorage;
4075
+ }
4076
+
4077
+ function read$3(key) {
4078
+ return localStorage().getItem(key);
4079
+ }
4080
+
4081
+ function write$3(key, data) {
4082
+ return localStorage().setItem(key, data);
4083
+ }
4084
+
4085
+ function each$3(fn) {
4086
+ for (var i = localStorage().length - 1; i >= 0; i--) {
4087
+ var key = localStorage().key(i);
4088
+ fn(read$3(key), key);
4089
+ }
4090
+ }
4091
+
4092
+ function remove$3(key) {
4093
+ return localStorage().removeItem(key);
4094
+ }
4095
+
4096
+ function clearAll$3() {
4097
+ return localStorage().clear();
4098
+ }
4099
+
4100
+ var util$1 = util$4;
4101
+ var Global$1 = util$1.Global;
4102
+ var sessionStorage_1 = {
4103
+ name: 'sessionStorage',
4104
+ read: read$2,
4105
+ write: write$2,
4106
+ each: each$2,
4107
+ remove: remove$2,
4108
+ clearAll: clearAll$2
4109
+ };
4110
+
4111
+ function sessionStorage() {
4112
+ return Global$1.sessionStorage;
4113
+ }
4114
+
4115
+ function read$2(key) {
4116
+ return sessionStorage().getItem(key);
4117
+ }
4118
+
4119
+ function write$2(key, data) {
4120
+ return sessionStorage().setItem(key, data);
4121
+ }
4122
+
4123
+ function each$2(fn) {
4124
+ for (var i = sessionStorage().length - 1; i >= 0; i--) {
4125
+ var key = sessionStorage().key(i);
4126
+ fn(read$2(key), key);
4127
+ }
4128
+ }
4129
+
4130
+ function remove$2(key) {
4131
+ return sessionStorage().removeItem(key);
4132
+ }
4133
+
4134
+ function clearAll$2() {
4135
+ return sessionStorage().clear();
4136
+ }
4137
+
4138
+ // doesn't work but cookies do. This implementation is adopted from
4139
+ // https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
4140
+
4141
+ var util = util$4;
4142
+ var Global = util.Global;
4143
+ var trim = util.trim;
4144
+ var cookieStorage = {
4145
+ name: 'cookieStorage',
4146
+ read: read$1,
4147
+ write: write$1,
4148
+ each: each$1,
4149
+ remove: remove$1,
4150
+ clearAll: clearAll$1
4151
+ };
4152
+ var doc = Global.document;
4153
+
4154
+ function read$1(key) {
4155
+ if (!key || !_has(key)) {
4156
+ return null;
4157
+ }
4158
+
4159
+ var regexpStr = "(?:^|.*;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
4160
+ return unescape(doc.cookie.replace(new RegExp(regexpStr), "$1"));
4161
+ }
4162
+
4163
+ function each$1(callback) {
4164
+ var cookies = doc.cookie.split(/; ?/g);
4165
+
4166
+ for (var i = cookies.length - 1; i >= 0; i--) {
4167
+ if (!trim(cookies[i])) {
4168
+ continue;
4169
+ }
4170
+
4171
+ var kvp = cookies[i].split('=');
4172
+ var key = unescape(kvp[0]);
4173
+ var val = unescape(kvp[1]);
4174
+ callback(val, key);
4175
+ }
4176
+ }
4177
+
4178
+ function write$1(key, data) {
4179
+ if (!key) {
4180
+ return;
4181
+ }
4182
+
4183
+ doc.cookie = escape(key) + "=" + escape(data) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
4184
+ }
4185
+
4186
+ function remove$1(key) {
4187
+ if (!key || !_has(key)) {
4188
+ return;
4189
+ }
4190
+
4191
+ doc.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
4192
+ }
4193
+
4194
+ function clearAll$1() {
4195
+ each$1(function (_, key) {
4196
+ remove$1(key);
4197
+ });
4198
+ }
4199
+
4200
+ function _has(key) {
4201
+ return new RegExp("(?:^|;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=").test(doc.cookie);
4202
+ }
4203
+
4204
+ // is functions (meaning store.get(), store.set(), etc will all function).
4205
+ // However, stored values will not persist when the browser navigates to
4206
+ // a new page or reloads the current page.
4207
+
4208
+ var memoryStorage_1 = {
4209
+ name: 'memoryStorage',
4210
+ read: read,
4211
+ write: write,
4212
+ each: each,
4213
+ remove: remove,
4214
+ clearAll: clearAll
4215
+ };
4216
+ var memoryStorage = {};
4217
+
4218
+ function read(key) {
4219
+ return memoryStorage[key];
4220
+ }
4221
+
4222
+ function write(key, data) {
4223
+ memoryStorage[key] = data;
4224
+ }
4225
+
4226
+ function each(callback) {
4227
+ for (var key in memoryStorage) {
4228
+ if (memoryStorage.hasOwnProperty(key)) {
4229
+ callback(memoryStorage[key], key);
4230
+ }
4231
+ }
4232
+ }
4233
+
4234
+ function remove(key) {
4235
+ delete memoryStorage[key];
4236
+ }
4237
+
4238
+ function clearAll(key) {
4239
+ memoryStorage = {};
4240
+ }
4241
+
4242
+ const localStore = storeEngine.createStore([localStorage_1, sessionStorage_1, cookieStorage, memoryStorage_1], []);
4243
+ /**
4244
+ * @namespace Salla.storage
4245
+ */
4246
+
4247
+ class Storage {
4248
+ constructor() {
4249
+ Salla.event.on("storage::item.remove", key => this.remove(key));
4250
+ Salla.event.on("storage::item.set", (key, value) => this.set(key, value));
4251
+ this.store = localStore;
4252
+ }
4253
+
4254
+ set(key, value) {
4255
+ if (key.includes(".")) {
4256
+ let firstKey = key.split(".")[0];
4257
+ let parentObject = {
4258
+ [firstKey]: this.store.get(firstKey)
4259
+ };
4260
+ parentObject = Salla.helpers.setNested(parentObject, key, value);
4261
+ return this.store.set(firstKey, parentObject[firstKey]);
4262
+ }
4263
+
4264
+ return this.store.set(key, value);
4265
+ }
4266
+
4267
+ remove(key) {
4268
+ return this.store.remove(key);
4269
+ }
4270
+
4271
+ get(key, value) {
4272
+ if (key.includes(".")) {
4273
+ let firstKey = key.split(".")[0];
4274
+ return Salla.helpers.getNested({
4275
+ [firstKey]: this.store.get(firstKey)
4276
+ }, key);
4277
+ }
4278
+
4279
+ return this.store.get(key, value);
4280
+ }
4281
+
4282
+ }
4283
+
4284
+ /**
4285
+ * @namespace Salla.cookie
4286
+ */
4287
+ class Cookie {
4288
+ constructor() {
4289
+ Salla.event.on("cookies::remove", key => this.remove(key));
4290
+ Salla.event.on("cookies::add", (key, value) => this.set(key, value));
4291
+ }
4292
+
4293
+ get(key) {
4294
+ return document.cookie.split("; ").find(row => row.startsWith(key + "="))?.split("=")[1];
4295
+ }
4296
+
4297
+ set(key, value = "", days = 10) {
4298
+ let expires = "";
4299
+
4300
+ if (days) {
4301
+ let date = new Date();
4302
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
4303
+ expires = "; expires=" + date.toUTCString();
4304
+ }
4305
+
4306
+ document.cookie = `${key}=${value}${expires}"; path=/; secure; SameSite=Lax"`;
4307
+ return this;
4308
+ }
4309
+
4310
+ remove(key) {
4311
+ document.cookie = `${key}=; Max-Age=0; path=/;`;
4312
+ return this;
4313
+ }
4314
+
4315
+ }
4316
+
4317
+ if (typeof global === 'undefined') {
4318
+ window.salla = window.salla || window.Salla || {};
4319
+ window.Salla = window.salla;
4320
+ } else {
4321
+ global.salla = global.salla || global.Salla || {};
4322
+ global.Salla = global.salla;
4323
+ } // loading helpers object and link it to salla
4324
+
4325
+ Salla.config = new Config();
4326
+ Salla.logger = Logger;
4327
+ Salla.event = new Emitter();
4328
+ Salla.storage = new Storage();
4329
+ Salla.cookie = new Cookie();
4330
+ Salla.helpers = Helpers; // alias
4331
+
4332
+ Salla.log = Salla.logger.log;
4333
+ Salla.money = Salla.helpers.money;
4334
+ Salla.url = Salla.helpers.url;
4335
+ Salla.versions = {
4336
+ base: '1.6.14'
4337
+ };
4338
+ var Salla$1 = Salla;
4339
+
4340
+ exports["default"] = Salla$1;
4341
+
4342
+ Object.defineProperty(exports, '__esModule', { value: true });
4343
+
4344
+ }));
2
4345
  //# sourceMappingURL=base.min.js.map