@salla.sa/twilight 2.0.284 → 2.0.285

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.
package/dist/cjs/index.js CHANGED
@@ -17,7 +17,7 @@ module=eventemitter2$1,function(e){var t=Object.hasOwnProperty,i=Array.isArray?A
17
17
  * https://infinite-scroll.com
18
18
  * Copyright 2018-2020 Metafizzy
19
19
  */
20
- function(e){window,e.exports&&(e.exports=function(e){return e}(core.exports,pageLoad.exports,scrollWatch.exports,history$1.exports,button.exports,status.exports))}(js);var TheInfiniteScroll=js.exports;class InfiniteScroll extends Action{constructor(e,t){super(e,t),this.options={path:".infinite-scroll-btn",history:"push",status:".infinite-scroll-status",append:".list-block"},this.fetchOptions={headers:{"S-INFINITE-SCROLL":!0}},this.instances=[]}initiate(e,t,i){i=this.getCustomOptions(t,i);let n="string"!=typeof e?e:document.querySelector(e),r=i.path;if(!n||!r||"string"==typeof r&&!document.querySelector(r))return void salla.log(n?"Path Option (a link that has next page link) Not Existed!":"Container For InfiniteScroll not Existed!");let s=new TheInfiniteScroll(n,i);return s.on("scrollThreshold",salla.infiniteScroll.event.scrollThreshold),s.on("request",salla.infiniteScroll.event.request),s.on("load",salla.infiniteScroll.event.load),s.on("append",salla.infiniteScroll.event.append),s.on("error",salla.infiniteScroll.event.error),s.on("last",salla.infiniteScroll.event.last),s.on("history",salla.infiniteScroll.event.history),this.instances.push(s),s}getCustomOptions(e,t){return(t="object"==typeof e&&e||t||this.options).fetchOptions=this.fetchOptions,t.path=t.path||this.options.path,t.button=t.button||t.path,t.status=t.status||this.options.status,t.hasOwnProperty("history")||(t.history=this.options.history),t.nextPage=t.nextPage||t.next_page,t.append="string"==typeof e&&e||t.append||this.options.append,t}}function injectValueToFromData(e,t,i){return e instanceof FormData?e.append(t,i):e[t]=i,e}function number(e,t=!1){e+="";let i,n=["٠","١","٢","٣","٤","٥","٦","٧","٨","٩"],r=["0","1","2","3","4","5","6","7","8","9"],s=(t=t||!salla.config.get("store.settings.arabic_numbers_enabled"))?n:r,a=t?r:n;for(let t=0;t<s.length;t++)i=new RegExp(s[t],"g"),e=e.replace(i,a[t]);return e}function digitsOnly(e){return number(e,!0).replace(/[^0-9.]/g,"").replace("..",".").rtrim(".")}function inputDigitsOnly(e,t=!1){if("string"==typeof e)return document.querySelectorAll(e).forEach((e=>inputDigitsOnly(e,t)));if(!e)return void salla.log("Can't find Object With Id: "+e);let i=salla.helpers.digitsOnly(e.value);return e.min&&i<e.min?e.value=e.min:e.max&&i>e.max?e.value=e.max:e.maxLength>=1&&i.toString().length>e.maxLength?e.value=i.toString().substring(0,e.maxLength):e.value=t||e.dataset.hasOwnProperty("digitsWithDecimal")?getOnlyDecimal(i):i.replace(/\D/g,"")}function getOnlyDecimal(e){let t=(e.match(/\./g)||[]).length;return t&&1!==t?getOnlyDecimal(e.replace(/\.(.+)\./g,".$1")):e}function money(e){return number(e?.amount|e)+" "+salla.config.currency(e?.currency).symbol}function debounce(e,t){t=t||100;let i,n=[];return function(...r){return clearTimeout(i),i=setTimeout((()=>{let t=e(...r);n.forEach((e=>e(t))),n=[]}),t),new Promise((e=>n.push(e)))}}function getInputDataWithName(e,t,i={}){if(e.includes("[")){let n=e.split("]").join("").split("[");return{name:n[0],value:getLeveledData(n.slice(1),t,i[n[0]])}}return{name:e,value:t}}function getLeveledData(e,t,i){let n=e[0];return i&&0==e.length?Array.isArray(i)?(i.push(t),i):[i,t]:Array.isArray(i)?(i.push(t),i):"string"==typeof i?[i,t]:i?(i[n]=getLeveledData(e.slice(1),t,i[n]),i):n?{[n]:getLeveledData(e.slice(1),t)}:""===n?[t]:t}function setNested(e,t,i){let n=e,r=t.split("."),s=r.length;for(let e=0;e<s-1;e++){let t=r[e];n[t]||(n[t]={}),n=n[t]}return n[r[s-1]]=i,e}function getNested(e,t,i){let n=t.split(".");for(let t of n){try{e=e[t]}catch(t){e=i||void 0}if(!e)return e}return e||i||void 0}function url(e){return salla.config.get("store.url","/")+e}function addParamToUrl(e,t){if(!t||!e)return window.location.href;let i=new RegExp("([?&])"+e+"=[^&]+[&]?","g"),n=window.location.href.replace(i,"$1").replace(/&$|\?$/,"");return n+=(n.includes("?")?"&":"?")+e+"="+encodeURIComponent(t),n.replace(/&$|\?$/,"")}function baseUrl$1(e){return window.location.origin+"/"+e.ltrim("/")}function asset(e){return baseUrl$1("themes/"+salla.config.get("theme.name")+"/"+e.ltrim("/"))}function api$1(e){return salla.config.get("store.api",url("")).rtrim("/")+"/"+e.ltrim("/")}function is_page(e){return e&&salla.config.get("page.slug")===e}String.prototype.toStudlyCase=function(){return this.trim().replace(/([^a-zA-Z\d].)/g,(function(e){return e.toUpperCase().replace(/[^a-zA-Z\d]/g,"")}))},String.prototype.toDatasetName=function(){return this.startsWith("data-")?this.substr(5).toStudlyCase():this.toStudlyCase()},String.prototype.toSelector=function(){return this.trim().startsWith(".")||this.trim().startsWith("#")?this:"#"+this},String.prototype.replaceArray=function(e,t){for(var i,n=this,r=0;r<e.length;r++)i=new RegExp(e[r],"g"),n=n.replace(i,t[r]);return n},String.prototype.rtrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("["+e+"]*$"),"")},String.prototype.ltrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("^["+e+"]*"),"")},String.prototype.digitsOnly=function(){return salla.helpers.digitsOnly(this)},Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){for(var t=this;t;){if(t.matches(e))return t;t=t.parentElement}}),Element.prototype.getElementSallaData=function(e,...t){if(!this.getAttribute)return;if(this.hasAttribute("data-json"))try{return JSON.parse(this.getAttribute("data-json"))}catch(e){}let i=this.getAttribute("data-function");if(i&&window[i])return"function"==typeof window[i]?this.getFilteredData(window[i].call(this,...t)):this.getFilteredData(window[i]);let n=this.hasAttribute("data-form-selector")?document.querySelector(this.dataset.formSelector):void 0;if(n="FORM"===this.tagName?this:n||this.closest("form")||this.closest("[salla-form-data]")||this,n&&"FORM"===n.tagName)return this.getFilteredData(new FormData(n),null,n);let r=n.querySelectorAll("[name]");if(!r.length)return this.getFilteredData();let s=Object.assign({},this.dataset);return r.forEach((e=>{if(!["checkbox","radio"].includes(e.type)||e.checked)try{let t=salla.helpers.inputData(e.name,e.value,s);s[t.name]=t.value}catch(t){salla.log(e.name+" can't be send")}})),this.getFilteredData(s)},Element.prototype.canEventFireHook=function(e){return!!this.hasAttribute&&this.hasAttribute(salla.api.hooksPrefix+e.type)},Element.prototype.hasAttributeStartsWith=function(e,t){e=e.toLowerCase();for(var i=0;i<this.attributes.length;i++){let n=this.attributes[i].name.toLowerCase();if(0===n.indexOf(e))return!t||n}return!1},HTMLFormElement.prototype.getAjaxFormData=function(e){var t=this.querySelectorAll('input[type="file"]');t.forEach((e=>{e.files.length||e.setAttribute("disabled","")}));var i=new FormData(this);return t.forEach((e=>{e.files.length||e.removeAttribute("disabled")})),{formData:this.getFilteredData(i,e),url:this.getAttribute("action"),method:this.getAttribute("method")||"post",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},Element.prototype.getFilteredData=function(e=null,t=null,i=null){return e=e||i?.dataset||this.dataset,i&&this.name&&void 0!==this.value&&(e=injectValueToFromData(e,this.name,this.value)),["filterBeforeSubmit","filterBeforeSend"].forEach((n=>{let r=i?.dataset[n]||this.dataset[n];if(r){var s=window[r];if("function"==typeof s){if(!s(e,i||this,t)&&e)throw`Data failed to be pass verify function window.${r}(formData, element, event)!`;return s(e,i||this,t)}salla.log("window."+r+"() not found!")}})),e},HTMLAnchorElement.prototype.getAjaxFormData=function(e){return{formData:this.getFilteredData(null,e),url:this.getAttribute("href"),method:this.dataset.type||"get",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},window.onbeforeunload=function(e){if(salla.document.event.leaving(e),!salla.config.get("canLeave"))return e.preventDefault(),!1};var Helpers={digitsOnly:digitsOnly,inputDigitsOnly:inputDigitsOnly,number:number,money:money,setNested:setNested,getNested:getNested,inputData:getInputDataWithName,url:{get:url,asset:asset,cdn:asset,is_page:is_page,api:api$1},addParamToUrl:addParamToUrl,debounce:debounce};class AppHelpers{toggleClassIf(e,t,i,n){return document.querySelectorAll(e).forEach((e=>this.toggleElementClassIf(e,t,i,n))),this}toggleElementClassIf(e,t,i,n){t=Array.isArray(t)?t:t.split(" "),i=Array.isArray(i)?i:i.split(" ");let r=n(e);return e?.classList.remove(...r?i:t),e?.classList.add(...r?t:i),this}isValidEmail(e){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())}element(e){return"object"==typeof e?e:document.querySelector(e)}watchElement(e,t){return this[e]=this.element(t),this}watchElements(e){return Object.entries(e).forEach((e=>this.watchElement(e[0],e[1]))),this}on(e,t,i,n={}){return"object"==typeof t?(this.element(t).addEventListener(e,i,n),this):(document.querySelectorAll(t).forEach((t=>t.addEventListener(e,i,n))),this)}onClick(e,t){return this.on("click",e,t)}onKeyUp(e,t){return this.on("keyup",e,t)}onEnter(e,t){return this.onKeyUp(e,(e=>13===e.keyCode&&t(e))),this}all(e,t){return document.querySelectorAll(e).forEach(t),this}hideElement(e){return this.element(e).style.display="none",this}showElement(e,t="block"){return this.element(e).style.display=t,this}removeClass(e,t){return this.element(e).classList.remove(...Array.from(arguments).slice(1)),this}addClass(e,t){return this.element(e).classList.add(...Array.from(arguments).slice(1)),this}debounce(e,...t){return this.debounce_||(this.debounce_=salla.helpers.debounce(((e,...t)=>e(...t)),500)),this.debounce_(e,...t)}}class SallaForm{async submit(e,t=null){let i=t;if("SubmitEvent"===t?.constructor?.name){if(t.preventDefault(),"FORM"!==t.target?.tagName)return salla.log("Failed find the target element for submit action. make sure you submit a form element"),new Promise((()=>{throw"Failed find the target element for submit action. make sure you submit a form element"}));"SALLA-BUTTON"===t?.submitter?.parentElement?.tagName&&t.submitter.parentElement.load(),i=t.target.getElementSallaData(),salla.log("Data from element",i)}if(/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm.test(e))return salla.twilight.request(e,i,"post").finally((()=>{loaderSupported&&t?.submitter?.parentElement.stop()}));let n=e.split("."),r=n.splice(-1);return await salla.call(n.join("."))[r](i).finally((()=>t?.submitter?.parentElement?.stop())).catch((e=>{throw salla.log(e),e}))}onSubmit(e,t){return salla.form.submit(e,t),!1}onChange(e,t){return t?.currentTarget?"FORM"!==t?.currentTarget?.tagName||t.currentTarget.checkValidity()?(salla.form.submit(e,t.currentTarget.getElementSallaData()),!0):(salla.log(`Trying to trigger '${e}' without filling required fields!`),!1):(salla.log(`Trying to trigger '${e}' without event!`),!1)}}class SallaCookie{constructor(e){e.on("cookies::remove",(e=>this.remove(e))),e.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="",i=10){let n="";if(i){let e=new Date;e.setTime(e.getTime()+24*i*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}}class SallaConfig{constructor(e){this.triedToGetCurrencies_=!1,this.languages_=[],this.triedToGetLanguages_=!1,this.currencies_={},this.properties_=e||{debug:"development"===process.env.NODE_ENV,token:null,fastRequests:!0,canLeave:!0},this.properties_.currencies||(this.properties_.currencies={SAR:{code:"SAR",name:"ريال سعودي",symbol:"ر.س",amount:1,country_code:"sa"}})}merge(e){return Object.assign(this.properties_,e),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}isUser(){return"user"===this.get("user.type")}isGuest(){return!this.isUser()}async languages(){if(this.triedToGetLanguages_)return this.languages_;this.triedToGetLanguages_=!0;let e=!0;return(await salla.document.api.request("languages",null,"get"))?.data?.map((t=>{e&&(this.languages_=[],e=!1),t.code=t.code||t.iso_code,t.url=salla.url.get(t.code),t.is_rtl=t.is_rtl||t.rtl,this.languages_.push(t)})),this.set("languages",this.languages_),this.languages_}async currencies(){if(this.triedToGetCurrencies_)return this.currencies_;this.triedToGetCurrencies_=!0;let e=!0;return(await salla.currency.api.list())?.data?.map((t=>{e&&(this.currencies_={},e=!1),t.country_code=t.code.substr(0,2).toLowerCase(),this.currencies_[t.code]=t})),this.set("currencies",this.currencies_),this.currencies_}currency(e){return e??=this.get("user.currency_code"),this.get("currencies."+e)||Object.values(this.get("currencies"))[0]}languageCode(){return this.get("user.language_code",window.locale||navigator.language||navigator.userLanguage||"ar")}}var lang={exports:{}};
20
+ function(e){window,e.exports&&(e.exports=function(e){return e}(core.exports,pageLoad.exports,scrollWatch.exports,history$1.exports,button.exports,status.exports))}(js);var TheInfiniteScroll=js.exports;class InfiniteScroll extends Action{constructor(e,t){super(e,t),this.options={path:".infinite-scroll-btn",history:"push",status:".infinite-scroll-status",append:".list-block"},this.fetchOptions={headers:{"S-INFINITE-SCROLL":!0}},this.instances=[]}initiate(e,t,i){i=this.getCustomOptions(t,i);let n="string"!=typeof e?e:document.querySelector(e),r=i.path;if(!n||!r||"string"==typeof r&&!document.querySelector(r))return void salla.log(n?"Path Option (a link that has next page link) Not Existed!":"Container For InfiniteScroll not Existed!");let s=new TheInfiniteScroll(n,i);return s.on("scrollThreshold",salla.infiniteScroll.event.scrollThreshold),s.on("request",salla.infiniteScroll.event.request),s.on("load",salla.infiniteScroll.event.load),s.on("append",salla.infiniteScroll.event.append),s.on("error",salla.infiniteScroll.event.error),s.on("last",salla.infiniteScroll.event.last),s.on("history",salla.infiniteScroll.event.history),this.instances.push(s),s}getCustomOptions(e,t){return(t="object"==typeof e&&e||t||this.options).fetchOptions=this.fetchOptions,t.path=t.path||this.options.path,t.button=t.button||t.path,t.status=t.status||this.options.status,t.hasOwnProperty("history")||(t.history=this.options.history),t.nextPage=t.nextPage||t.next_page,t.append="string"==typeof e&&e||t.append||this.options.append,t}}function injectValueToFromData(e,t,i){return e instanceof FormData?e.append(t,i):e[t]=i,e}function number(e,t=!1){e+="";let i,n=["٠","١","٢","٣","٤","٥","٦","٧","٨","٩"],r=["0","1","2","3","4","5","6","7","8","9"],s=(t=t||!salla.config.get("store.settings.arabic_numbers_enabled"))?n:r,a=t?r:n;for(let t=0;t<s.length;t++)i=new RegExp(s[t],"g"),e=e.replace(i,a[t]);return e}function digitsOnly(e){return number(e,!0).replace(/[^0-9.]/g,"").replace("..",".").rtrim(".")}function inputDigitsOnly(e,t=!1){if("string"==typeof e)return document.querySelectorAll(e).forEach((e=>inputDigitsOnly(e,t)));if(!e)return void salla.log("Can't find Object With Id: "+e);let i=salla.helpers.digitsOnly(e.value);return e.min&&i<e.min?e.value=e.min:e.max&&i>e.max?e.value=e.max:e.maxLength>=1&&i.toString().length>e.maxLength?e.value=i.toString().substring(0,e.maxLength):e.value=t||e.dataset.hasOwnProperty("digitsWithDecimal")?getOnlyDecimal(i):i.replace(/\D/g,"")}function getOnlyDecimal(e){let t=(e.match(/\./g)||[]).length;return t&&1!==t?getOnlyDecimal(e.replace(/\.(.+)\./g,".$1")):e}function money(e){return number(e?.amount|e)+" "+salla.config.currency(e?.currency).symbol}function debounce(e,t){t=t||100;let i,n=[];return function(...r){return clearTimeout(i),i=setTimeout((()=>{let t=e(...r);n.forEach((e=>e(t))),n=[]}),t),new Promise((e=>n.push(e)))}}function getInputDataWithName(e,t,i={}){if(e.includes("[")){let n=e.split("]").join("").split("[");return{name:n[0],value:getLeveledData(n.slice(1),t,i[n[0]])}}return{name:e,value:t}}function getLeveledData(e,t,i){let n=e[0];return i&&0==e.length?Array.isArray(i)?(i.push(t),i):[i,t]:Array.isArray(i)?(i.push(t),i):"string"==typeof i?[i,t]:i?(i[n]=getLeveledData(e.slice(1),t,i[n]),i):n?{[n]:getLeveledData(e.slice(1),t)}:""===n?[t]:t}function setNested(e,t,i){let n=e,r=t.split("."),s=r.length;for(let e=0;e<s-1;e++){let t=r[e];n[t]||(n[t]={}),n=n[t]}return n[r[s-1]]=i,e}function getNested(e,t,i){let n=t.split(".");for(let t of n){try{e=e[t]}catch(t){e=i||void 0}if(!e)return e}return e||i||void 0}function url(e){return salla.config.get("store.url","/")+e}function addParamToUrl(e,t){if(!t||!e)return window.location.href;let i=new RegExp("([?&])"+e+"=[^&]+[&]?","g"),n=window.location.href.replace(i,"$1").replace(/&$|\?$/,"");return n+=(n.includes("?")?"&":"?")+e+"="+encodeURIComponent(t),n.replace(/&$|\?$/,"")}function baseUrl$1(e){return window.location.origin+"/"+e.ltrim("/")}function asset(e){return baseUrl$1("themes/"+salla.config.get("theme.name")+"/"+e.ltrim("/"))}function api$1(e){return salla.config.get("store.api",url("")).rtrim("/")+"/"+e.ltrim("/")}function is_page(e){return e&&salla.config.get("page.slug")===e}String.prototype.toStudlyCase=function(){return this.trim().replace(/([^a-zA-Z\d].)/g,(function(e){return e.toUpperCase().replace(/[^a-zA-Z\d]/g,"")}))},String.prototype.toDatasetName=function(){return this.startsWith("data-")?this.substr(5).toStudlyCase():this.toStudlyCase()},String.prototype.toSelector=function(){return this.trim().startsWith(".")||this.trim().startsWith("#")?this:"#"+this},String.prototype.replaceArray=function(e,t){for(var i,n=this,r=0;r<e.length;r++)i=new RegExp(e[r],"g"),n=n.replace(i,t[r]);return n},String.prototype.rtrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("["+e+"]*$"),"")},String.prototype.ltrim=function(e){return void 0===e&&(e="\\s"),this.replace(new RegExp("^["+e+"]*"),"")},String.prototype.digitsOnly=function(){return salla.helpers.digitsOnly(this)},Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){for(var t=this;t;){if(t.matches(e))return t;t=t.parentElement}}),Element.prototype.getElementSallaData=function(e,...t){if(!this.getAttribute)return;if(this.hasAttribute("data-json"))try{return JSON.parse(this.getAttribute("data-json"))}catch(e){}let i=this.getAttribute("data-function");if(i&&window[i])return"function"==typeof window[i]?this.getFilteredData(window[i].call(this,...t)):this.getFilteredData(window[i]);let n=this.hasAttribute("data-form-selector")?document.querySelector(this.dataset.formSelector):void 0;if(n="FORM"===this.tagName?this:n||this.closest("form")||this.closest("[salla-form-data]")||this,n&&"FORM"===n.tagName)return this.getFilteredData(new FormData(n),null,n);let r=n.querySelectorAll("[name]");if(!r.length)return this.getFilteredData();let s=Object.assign({},this.dataset);return r.forEach((e=>{if(!["checkbox","radio"].includes(e.type)||e.checked)try{let t=salla.helpers.inputData(e.name,e.value,s);s[t.name]=t.value}catch(t){salla.log(e.name+" can't be send")}})),this.getFilteredData(s)},Element.prototype.canEventFireHook=function(e){return!!this.hasAttribute&&this.hasAttribute(salla.api.hooksPrefix+e.type)},Element.prototype.hasAttributeStartsWith=function(e,t){e=e.toLowerCase();for(var i=0;i<this.attributes.length;i++){let n=this.attributes[i].name.toLowerCase();if(0===n.indexOf(e))return!t||n}return!1},HTMLFormElement.prototype.getAjaxFormData=function(e){var t=this.querySelectorAll('input[type="file"]');t.forEach((e=>{e.files.length||e.setAttribute("disabled","")}));var i=new FormData(this);return t.forEach((e=>{e.files.length||e.removeAttribute("disabled")})),{formData:this.getFilteredData(i,e),url:this.getAttribute("action"),method:this.getAttribute("method")||"post",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},Element.prototype.getFilteredData=function(e=null,t=null,i=null){return e=e||i?.dataset||this.dataset,i&&this.name&&void 0!==this.value&&(e=injectValueToFromData(e,this.name,this.value)),["filterBeforeSubmit","filterBeforeSend"].forEach((n=>{let r=i?.dataset[n]||this.dataset[n];if(r){var s=window[r];if("function"==typeof s){if(!s(e,i||this,t)&&e)throw`Data failed to be pass verify function window.${r}(formData, element, event)!`;return s(e,i||this,t)}salla.log("window."+r+"() not found!")}})),e},HTMLAnchorElement.prototype.getAjaxFormData=function(e){return{formData:this.getFilteredData(null,e),url:this.getAttribute("href"),method:this.dataset.type||"get",events:{success:this.dataset.onSuccess,fail:this.dataset.onFail}}},window.onbeforeunload=function(e){if(salla.document.event.leaving(e),!salla.config.get("canLeave"))return e.preventDefault(),!1};var Helpers={digitsOnly:digitsOnly,inputDigitsOnly:inputDigitsOnly,number:number,money:money,setNested:setNested,getNested:getNested,inputData:getInputDataWithName,url:{get:url,asset:asset,cdn:asset,is_page:is_page,api:api$1},addParamToUrl:addParamToUrl,debounce:debounce};class AppHelpers{toggleClassIf(e,t,i,n){return document.querySelectorAll(e).forEach((e=>this.toggleElementClassIf(e,t,i,n))),this}toggleElementClassIf(e,t,i,n){t=Array.isArray(t)?t:t.split(" "),i=Array.isArray(i)?i:i.split(" ");let r=n(e);return e?.classList.remove(...r?i:t),e?.classList.add(...r?t:i),this}isValidEmail(e){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())}element(e){return"object"==typeof e?e:document.querySelector(e)}watchElement(e,t){return this[e]=this.element(t),this}watchElements(e){return Object.entries(e).forEach((e=>this.watchElement(e[0],e[1]))),this}on(e,t,i,n={}){return"object"==typeof t?(this.element(t).addEventListener(e,i,n),this):(document.querySelectorAll(t).forEach((t=>t.addEventListener(e,i,n))),this)}onClick(e,t){return this.on("click",e,t)}onKeyUp(e,t){return this.on("keyup",e,t)}onEnter(e,t){return this.onKeyUp(e,(e=>13===e.keyCode&&t(e))),this}all(e,t){return document.querySelectorAll(e).forEach(t),this}hideElement(e){return this.element(e).style.display="none",this}showElement(e,t="block"){return this.element(e).style.display=t,this}removeClass(e,t){return this.element(e).classList.remove(...Array.from(arguments).slice(1)),this}addClass(e,t){return this.element(e).classList.add(...Array.from(arguments).slice(1)),this}debounce(e,...t){return this.debounce_||(this.debounce_=salla.helpers.debounce(((e,...t)=>e(...t)),500)),this.debounce_(e,...t)}}class SallaForm{async submit(e,t=null){let i=t;if("SubmitEvent"===t?.constructor?.name){if(t.preventDefault(),"FORM"!==t.target?.tagName)return salla.log("Failed find the target element for submit action. make sure you submit a form element"),new Promise((()=>{throw"Failed find the target element for submit action. make sure you submit a form element"}));"SALLA-BUTTON"===t?.submitter?.parentElement?.tagName&&t.submitter.parentElement.load(),i=t.target.getElementSallaData(),salla.log("Data from element",i)}if(/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm.test(e))return salla.twilight.request(e,i,"post").finally((()=>{loaderSupported&&t?.submitter?.parentElement.stop()}));let n=e.split("."),r=n.splice(-1);return await salla.call(n.join("."))[r](i).finally((()=>t?.submitter?.parentElement?.stop())).catch((e=>{throw salla.log(e),e}))}onSubmit(e,t){return salla.form.submit(e,t),!1}onChange(e,t){return t?.currentTarget?"FORM"!==t?.currentTarget?.tagName||t.currentTarget.checkValidity()?(salla.form.submit(e,t.currentTarget.getElementSallaData()),!0):(salla.log(`Trying to trigger '${e}' without filling required fields!`),!1):(salla.log(`Trying to trigger '${e}' without event!`),!1)}}class SallaCookie{constructor(e){e.on("cookies::remove",(e=>this.remove(e))),e.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="",i=10){let n="";if(i){let e=new Date;e.setTime(e.getTime()+24*i*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}}class SallaConfig{constructor(e){this.triedToGetCurrencies_=!1,this.languages_=[],this.triedToGetLanguages_=!1,this.currencies_={},this.properties_=e||{debug:"development"===process.env.NODE_ENV,token:null,fastRequests:!0,canLeave:!0},this.properties_.currencies||(this.properties_.currencies={SAR:{code:"SAR",name:"ريال سعودي",symbol:"ر.س",amount:1,country_code:"sa"}}),this.properties_.store.api||(this.properties_.store.api="https://api.salla.dev/store/v1/")}merge(e){return Object.assign(this.properties_,e),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}isUser(){return"user"===this.get("user.type")}isGuest(){return!this.isUser()}async languages(){if(this.triedToGetLanguages_)return this.languages_;this.triedToGetLanguages_=!0;let e=!0;return(await salla.document.api.request("languages",null,"get"))?.data?.map((t=>{e&&(this.languages_=[],e=!1),t.code=t.code||t.iso_code,t.url=salla.url.get(t.code),t.is_rtl=t.is_rtl||t.rtl,this.languages_.push(t)})),this.set("languages",this.languages_),this.languages_}async currencies(){if(this.triedToGetCurrencies_)return this.currencies_;this.triedToGetCurrencies_=!0;let e=!0;return(await salla.currency.api.list())?.data?.map((t=>{e&&(this.currencies_={},e=!1),t.country_code=t.code.substr(0,2).toLowerCase(),this.currencies_[t.code]=t})),this.set("currencies",this.currencies_),this.currencies_}currency(e){return e??=this.get("user.currency_code"),this.get("currencies."+e)||Object.values(this.get("currencies"))[0]}languageCode(){return this.get("user.language_code",window.locale||navigator.language||navigator.userLanguage||"ar")}}var lang={exports:{}};
21
21
  /*!
22
22
  * Lang.js for Laravel localization in JavaScript.
23
23
  *