@abtasty/progress-bar 1.3.8 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/main.js +1 -1
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -17,4 +17,4 @@
17
17
  ${O.call(this,{reachQuantity:t,progressBarStripesColor:n,progressBarBackgroundColor:r,progressBarColor:o,colorBlindMode:a,progressBarBorderRadius:l,progressBarHeight:c})}
18
18
  ${W.call(this,{subLayout:s,textLabelContent:i,reachQuantity:t,textColor:h,textAlign:d,fontSize:u})}
19
19
  </div>
20
- `}e()&&Number(ABTASTY_S.USER.additionalInformation.account_iframe_less_mode);const H=()=>({hub:Object.create(null),emit(e,t){(this.hub[e]||[]).forEach(e=>e(t))},on(e,t){this.hub[e]||(this.hub[e]=[]),this.hub[e].push(t)},off(e,t){const s=(this.hub[e]||[]).findIndex(e=>e===t);s>-1&&this.hub[e].splice(s,1),0===this.hub[e].length&&delete this.hub[e]}}),U=(e,t)=>{const s=Object.entries(t),i=Object.entries(e);return s.length===i.length&&s.every((e,t)=>{let[s,n]=e;const[r,o]=i[t];return s===r&&([n,o].every(e=>e&&"object"==typeof e)?U(n,o):!![n,o].every(e=>"function"==typeof e)||n===o)})},j=/\s/g,q=/\d(\d|\.|\s|,)*/,F=/(\d)(,)(\d+)/,z=/\d+(,\d{3})+(?!\d)/,G=/\d+(\.\d{3})+(?!\d)/,Y=/\d+\s{1}\d{3,}/,K=/,\d{2,}/,Q=/\.\d{2,}/,J=/\d+/,X=/\./g,Z=/,/g,ee=/(\d{1,3})(\.\d{2}|,\d{2}|\s{1}|\.|,)\s+\d+/i,te=/(\.|,)(\d+)(\.|,)?\s+\d+/i;function se(e){const t=e.toString().match(q);t||h("could not parse source value, using 0");let s=t?t[0]:"0";return s=s.replace(ee,"$1$2").replace(te,"$1$2").replace(z,e=>e.replace(Z,"")).replace(j,"").replace(G,e=>e.replace(X,"")).replace(F,"$1.$3"),s=Number.parseFloat(s),s}function ie(e){this.encode=e,this.decode=se}function ne(e,t){let s=Math.floor(e).toString(),i=s.length;for(;i>3;)i+=-3,s=s.slice(0,i)+t+s.slice(i);return s}function re(e,t){const s=e.toString();return s.indexOf(".")>0?`${t}${s.substring(s.indexOf(".")+1)}`:""}class oe{constructor(e){this.originalValue=e,this.formatter=function(e){return z.test(e)?new ie(e=>`${ne(e,",")}${re(e,".")}`):G.test(e)?new ie(e=>`${ne(e,".")}${re(e,",")}`):Y.test(e)?K.test(e)?new ie(e=>`${ne(e," ")}${re(e,",")}`):(Q.test(e),new ie(e=>`${ne(e," ")}${re(e,".")}`)):K.test(e)?new ie(e=>`${ne(e,"")}${re(e,",")}`):Q.test(e)?new ie(e=>`${ne(e,"")}${re(e,".")}`):(J.test(e),new ie(e=>e))}(e),this.numericValue=this.formatter.decode(e)}formatNumber(e){const t=this.formatter.encode(e).toString(),s=[".",","].some(e=>t.includes(e)),i="value"===DATA.variableUnitType;return s&&i?Number(t).toFixed(2):t}}class ae{constructor(e){let{parentContainer:t}=e;this.eventHub=H(),this.renderContent=M,this.parentContainer=t,this.baseClassName="progressbar_container",this.className=`${this.baseClassName}_${t.uniqueId}`,this.styleRules=[],this.externalValue=0,this.mainContainer=this.parentContainer.domElement.querySelector(`.${this.parentContainer.contentClassName}`),this.value=this.getValue(),this.contentElement=this.getContentElement(),this.styleElement=this.getStyleElement(),this.sourceElementObserver=null,this.sourceValueObserver=new MutationObserver(this.handleValueUpdate.bind(this)),this.parentContainer.children=this,this.goalReachedPreviewMode=!1,this.goalReached=!1,this.valueComparedOnce=!1}static getValueFromElement(){const{variableElement:t}=DATA,s=document.querySelector(t);let i=s?s.textContent:"0";return e()&&s&&s.isSameNode(document.body)&&(i="67"),new oe(i)}start(){const{goalReachedPreview:t,variableType:s,reachQuantity:i,variableElement:n}=DATA;if(this.goalReachedPreviewMode=e()&&t,this.eventHub.on("refreshContent",()=>{"element"===s&&this.eventHub.emit("valueElementUpdated")}),this.eventHub.on("valueElementUpdated",()=>{const e=this.getValue();U(e,this.value)&&this.valueComparedOnce||(this.valueComparedOnce=!0,this.value=e,this.eventHub.emit("valueUpdated"))}),this.eventHub.on("sourceElementPresence",t=>{t&&!this.goalReached?(this.eventHub.emit("valueElementUpdated"),this.parentContainer.domElement.hidden=!1,e()||this.sourceValueObserver.observe(document.body,{childList:!0,subtree:!0,characterData:!0})):(this.sourceValueObserver.disconnect(),this.parentContainer.domElement.hidden=!0,h("source element could not be found, hiding the progress bar widget"))}),this.eventHub.on("valueUpdated",()=>this.checkGoalReached(i)),t||this.eventHub.on("externalUpdate",e=>{this.externalValue=Number.parseFloat(e),this.value=this.getValue(),this.eventHub.emit("valueUpdated")}),this.goalReachedPreviewMode)this.eventHub.emit("valueUpdated");else switch(s){case"javascript":this.getValueFromScript();break;case"element":this.sourceElementObserver=u(n,e=>{this.eventHub.emit("sourceElementPresence",e)})}}handleValueUpdate(){const{variableElement:e}=DATA,t=document.querySelector(e);this.eventHub.emit(t?"valueElementUpdated":"sourceElementPresence")}checkGoalReached(t){const{displayReachedMessage:s,reachedMessage:i}=DATA,n=this.goalReachedPreviewMode?+t:this.value.targetValue.numericValue,r=[this,t];n>=+t&&!this.goalReached?(this.goalReached=!0,s&&(r.push(i),this.replaceCurrentMessage(D.call(...r))),e()||(this.parentContainer.recurrence.setValidationRecurrence(),h("target goal has been reached"))):n<+t&&(this.goalReached=!1,this.replaceCurrentMessage(D.call(this,t)))}replaceCurrentMessage(e){const t=this.mainContainer.querySelector(".abtasty_progress_definition");t&&(t.innerHTML=e)}insertInParentContainer(){document.head.appendChild(this.styleElement),this.mainContainer.appendChild(this.contentElement)}refreshContent(){this.eventHub.emit("refreshContent")}getValueFromScript(){const{variableJavascript:e}=DATA,t=this.eventHub;this.updaterFn=new Function(`(function externalUpdater(update){${e}})(this.update)`),this.updaterFn.call({update:e=>(t.emit("externalUpdate",e),e)})}getValue(){const{variableType:e,variableDisplayingValue:t,reachQuantity:s,variableUnitType:i}=DATA,n={element:()=>ae.getValueFromElement(),javascript:()=>new oe(this.externalValue)}[e](),r={remaining:()=>Math.max(0,Math.round(100*(s-n.numericValue))/100),accumulated:()=>n.numericValue}[t](),o={value:()=>r,percent:()=>Math.min(r,s)/s*100}[i]();return{targetValue:n,calculatedValue:r,displayingValue:o}}getContentElement(){const{variableDisplayingValue:e,variableUnitType:t}=DATA;this.textVariablesContent=DATA[`textVariablesContent_${t}_${e}`];const s=document.createElement("div");return s.insertAdjacentHTML("beforeend",this.renderContent(DATA)),s}addStyleRules(e){this.styleRules=this.styleRules.concat(e.map(function(e){const t=e.replace(/;/g," !important;");return t.indexOf("{")>1?`#${this.parentContainer.widgetContainerId} .${this.className} ${t}`:t}.bind(this)))}getStyleElement(){const{textColor:t,textAlign:s}=DATA,i=document.createElement("style");i.type="text/css",e()&&i.setAttribute("abtasty-script-added","true");const n=void 0!==t?`color: ${t};`:"",r=void 0!==s?`text-align: ${s};`:"";return this.addStyleRules(["p {","margin: 0;","white-space: pre-line;",n,r,"}",n&&n.length?["span {",n,"}"].join(""):""]),i.textContent=this.styleRules.join(" "),i}}!function(){h("Widget launch");const e=(()=>{const{layout:e}=DATA;let t;switch(e){case"popin":t=new N;break;case"bannerTop":case"bannerBottom":t=new k;break;case"free":t=new L;break;default:t=new E}return t})(),t=new ae({parentContainer:e});e.init(!0).then(s=>{let{response:i}=s;i&&(t.insertInParentContainer(),t.start(),e.show())})}()}();
20
+ `}e()&&Number(ABTASTY_S.USER.additionalInformation.account_iframe_less_mode);const H=()=>({hub:Object.create(null),emit(e,t){(this.hub[e]||[]).forEach(e=>e(t))},on(e,t){this.hub[e]||(this.hub[e]=[]),this.hub[e].push(t)},off(e,t){const s=(this.hub[e]||[]).findIndex(e=>e===t);s>-1&&this.hub[e].splice(s,1),0===this.hub[e].length&&delete this.hub[e]}}),U=(e,t)=>{const s=Object.entries(t),i=Object.entries(e);return s.length===i.length&&s.every((e,t)=>{let[s,n]=e;const[r,o]=i[t];return s===r&&([n,o].every(e=>e&&"object"==typeof e)?U(n,o):!![n,o].every(e=>"function"==typeof e)||n===o)})},j=/\s/g,q=/\d(\d|\.|\s|,)*/,F=/(\d)(,)(\d+)/,z=/\d+(,\d{3})+(?!\d)/,G=/\d+(\.\d{3})+(?!\d)/,Y=/\d+\s{1}\d{3,}/,K=/,\d{2,}/,Q=/\.\d{2,}/,J=/\d+/,X=/\./g,Z=/,/g,ee=/(\d{1,3})(\.\d{2}|,\d{2}|\s{1}|\.|,)\s+\d+/i,te=/(\.|,)(\d+)(\.|,)?\s+\d+/i;function se(e){const t=e.toString().match(q);t||h("could not parse source value, using 0");let s=t?t[0]:"0";return s=s.replace(ee,"$1$2").replace(te,"$1$2").replace(z,e=>e.replace(Z,"")).replace(j,"").replace(G,e=>e.replace(X,"")).replace(F,"$1.$3"),s=Number.parseFloat(s),s}function ie(e){this.encode=e,this.decode=se}function ne(e,t){let s=Math.floor(e).toString(),i=s.length;for(;i>3;)i+=-3,s=s.slice(0,i)+t+s.slice(i);return s}function re(e,t){const s=e.toString();return s.indexOf(".")>0?`${t}${s.substring(s.indexOf(".")+1)}`:""}class oe{constructor(e){this.originalValue=e,this.formatter=function(e){return z.test(e)?new ie(e=>`${ne(e,",")}${re(e,".")}`):G.test(e)?new ie(e=>`${ne(e,".")}${re(e,",")}`):Y.test(e)?K.test(e)?new ie(e=>`${ne(e," ")}${re(e,",")}`):(Q.test(e),new ie(e=>`${ne(e," ")}${re(e,".")}`)):K.test(e)?new ie(e=>`${ne(e,"")}${re(e,",")}`):Q.test(e)?new ie(e=>`${ne(e,"")}${re(e,".")}`):(J.test(e),new ie(e=>e))}(e),this.numericValue=this.formatter.decode(e)}formatNumber(e){const t=[".",","],s=this.formatter.encode(e).toString(),i=t.some(e=>s.includes(e)),n="value"===DATA.variableUnitType,r=e.toFixed(2),o=s.includes(t[1])?r.replace(...t):r;return i&&n?o:s}}class ae{constructor(e){let{parentContainer:t}=e;this.eventHub=H(),this.renderContent=M,this.parentContainer=t,this.baseClassName="progressbar_container",this.className=`${this.baseClassName}_${t.uniqueId}`,this.styleRules=[],this.externalValue=0,this.mainContainer=this.parentContainer.domElement.querySelector(`.${this.parentContainer.contentClassName}`),this.value=this.getValue(),this.contentElement=this.getContentElement(),this.styleElement=this.getStyleElement(),this.sourceElementObserver=null,this.sourceValueObserver=new MutationObserver(this.handleValueUpdate.bind(this)),this.parentContainer.children=this,this.goalReachedPreviewMode=!1,this.goalReached=!1,this.valueComparedOnce=!1}static getValueFromElement(){const{variableElement:t}=DATA,s=document.querySelector(t);let i=s?s.textContent:"0";return e()&&s&&s.isSameNode(document.body)&&(i="67"),new oe(i)}start(){const{goalReachedPreview:t,variableType:s,reachQuantity:i,variableElement:n}=DATA;if(this.goalReachedPreviewMode=e()&&t,this.eventHub.on("refreshContent",()=>{"element"===s&&this.eventHub.emit("valueElementUpdated")}),this.eventHub.on("valueElementUpdated",()=>{const e=this.getValue();U(e,this.value)&&this.valueComparedOnce||(this.valueComparedOnce=!0,this.value=e,this.eventHub.emit("valueUpdated"))}),this.eventHub.on("sourceElementPresence",t=>{t&&!this.goalReached?(this.eventHub.emit("valueElementUpdated"),this.parentContainer.domElement.hidden=!1,e()||this.sourceValueObserver.observe(document.body,{childList:!0,subtree:!0,characterData:!0})):(this.sourceValueObserver.disconnect(),this.parentContainer.domElement.hidden=!0,h("source element could not be found, hiding the progress bar widget"))}),this.eventHub.on("valueUpdated",()=>this.checkGoalReached(i)),t||this.eventHub.on("externalUpdate",e=>{this.externalValue=Number.parseFloat(e),this.value=this.getValue(),this.eventHub.emit("valueUpdated")}),this.goalReachedPreviewMode)this.eventHub.emit("valueUpdated");else switch(s){case"javascript":this.getValueFromScript();break;case"element":this.sourceElementObserver=u(n,e=>{this.eventHub.emit("sourceElementPresence",e)})}}handleValueUpdate(){const{variableElement:e}=DATA,t=document.querySelector(e);this.eventHub.emit(t?"valueElementUpdated":"sourceElementPresence")}checkGoalReached(t){const{displayReachedMessage:s,reachedMessage:i}=DATA,n=this.goalReachedPreviewMode?+t:this.value.targetValue.numericValue,r=[this,t];n>=+t&&!this.goalReached?(this.goalReached=!0,s&&(r.push(i),this.replaceCurrentMessage(D.call(...r))),e()||(this.parentContainer.recurrence.setValidationRecurrence(),h("target goal has been reached"))):n<+t&&(this.goalReached=!1,this.replaceCurrentMessage(D.call(this,t)))}replaceCurrentMessage(e){const t=this.mainContainer.querySelector(".abtasty_progress_definition");t&&(t.innerHTML=e)}insertInParentContainer(){document.head.appendChild(this.styleElement),this.mainContainer.appendChild(this.contentElement)}refreshContent(){this.eventHub.emit("refreshContent")}getValueFromScript(){const{variableJavascript:e}=DATA,t=this.eventHub;this.updaterFn=new Function(`(function externalUpdater(update){${e}})(this.update)`),this.updaterFn.call({update:e=>(t.emit("externalUpdate",e),e)})}getValue(){const{variableType:e,variableDisplayingValue:t,reachQuantity:s,variableUnitType:i}=DATA,n={element:()=>ae.getValueFromElement(),javascript:()=>new oe(this.externalValue)}[e](),r={remaining:()=>Math.max(0,Math.round(100*(s-n.numericValue))/100),accumulated:()=>n.numericValue}[t](),o={value:()=>r,percent:()=>Math.min(r,s)/s*100}[i]();return{targetValue:n,calculatedValue:r,displayingValue:o}}getContentElement(){const{variableDisplayingValue:e,variableUnitType:t}=DATA;this.textVariablesContent=DATA[`textVariablesContent_${t}_${e}`];const s=document.createElement("div");return s.insertAdjacentHTML("beforeend",this.renderContent(DATA)),s}addStyleRules(e){this.styleRules=this.styleRules.concat(e.map(function(e){const t=e.replace(/;/g," !important;");return t.indexOf("{")>1?`#${this.parentContainer.widgetContainerId} .${this.className} ${t}`:t}.bind(this)))}getStyleElement(){const{textColor:t,textAlign:s}=DATA,i=document.createElement("style");i.type="text/css",e()&&i.setAttribute("abtasty-script-added","true");const n=void 0!==t?`color: ${t};`:"",r=void 0!==s?`text-align: ${s};`:"";return this.addStyleRules(["p {","margin: 0;","white-space: pre-line;",n,r,"}",n&&n.length?["span {",n,"}"].join(""):""]),i.textContent=this.styleRules.join(" "),i}}!function(){h("Widget launch");const e=(()=>{const{layout:e}=DATA;let t;switch(e){case"popin":t=new N;break;case"bannerTop":case"bannerBottom":t=new k;break;case"free":t=new L;break;default:t=new E}return t})(),t=new ae({parentContainer:e});e.init(!0).then(s=>{let{response:i}=s;i&&(t.insertInParentContainer(),t.start(),e.show())})}()}();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@abtasty/progress-bar",
3
3
  "description": "Allow you to add a progress bar on you website",
4
- "version": "1.3.8",
4
+ "version": "1.3.9",
5
5
  "form": "dist/form.js",
6
6
  "main": "dist/main.js",
7
7
  "files": [