mealz-components 1.3.10 → 1.3.11

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 +1 @@
1
- import{t as l}from"../assets/custom-element-BhZVzxrc.js";import"../assets/lit-element-4gw3YGga.js";import{h as u}from"../assets/session-handler-BPS5vj92.js";import{N as g}from"../assets/no-shadow-element-CaVIVF-o.js";import{V as d}from"../assets/viewport-listener-DAXSJTi3.js";import"../assets/Subject-rBVVIydv.js";import"../assets/OperatorSubscriber-CcnWrfoX.js";import"../assets/async-CcgIcE7w.js";var m=Object.defineProperty,I=Object.getOwnPropertyDescriptor,C=(t,e,i,r)=>{for(var s=r>1?void 0:r?I(e,i):e,a=t.length-1,c;a>=0;a--)(c=t[a])&&(s=(r?c(e,i,s):c(s))||s);return r&&s&&m(e,i,s),s};let n=class extends g{constructor(){super(...arguments),this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.getInitialStatus(),this.listenInView(),this.subscriptions.push(window.mealzInternal.basket.recipeDataInBasket$().subscribe(t=>{const e=t.find(i=>i.id===this.recipeId);e&&(this.updatedRecipeId=e.id,this.updatedGuests=e.guests,this.updateDOM())}))}disconnectedCallback(){var t,e;super.disconnectedCallback(),this.subscriptions.forEach(i=>i.unsubscribe()),(t=this.priceViewportObserver)==null||t.disconnect(),(e=this.analyticsViewportObserver)==null||e.disconnect()}render(){this.recipeCardTop=this.querySelector(".mealz-recipe-card__top"),this.recipeCardCta=this.querySelector(".mealz-recipe-card__cta"),this.recipeCardTop&&(this.recipeCardTop.addEventListener("click",()=>this.recipeCardTopClick()),this.recipeCardCta&&this.recipeCardCta.addEventListener("click",()=>this.recipeCardCtaClick()))}listenInView(){this.priceViewportObserver=new d(this,()=>{this.handleIntersection()}),this.analyticsViewportObserver=new d(this,()=>{this.sendAnalyticsShow()},{threshold:.8,debounce:1e3})}handleIntersection(){this.recipePricing=this.querySelector("mealz-recipe-pricing"),this.recipePricing&&(this.recipePricing.fetchPrice(this.posId,this.guests,this.recipeId),this.priceViewportObserver.disconnect())}getInitialStatus(){var p;const t=(p=this.attributes["starting-data"])==null?void 0:p.value;if(!t)return;const{id:e,guests:i,posId:r,path:s,categoryId:a,initialTabIndex:c,sessionId:h}=JSON.parse(t);if(this.posId=r,this.recipeId=e,this.analyticsPath=s,this.categoryId=a,this.guests=i,this.initialTabIndex=c,u(h),!i){this.guests=this.getGuests();const o=this.querySelector(".mealz-recipe-card__counter p");o&&(o.innerHTML=this.guests.toString())}this.removeAttribute("starting-data")}recipeCardTopClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}recipeCardCtaClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}getGuests(){const t=localStorage.getItem("_miam/preferences/guests");if(t){const e=+t;if(!isNaN(e)&&e>0&&e<=30)return e}return 4}updateDOM(){if(this.recipeId!==this.updatedRecipeId)return;const t=this.querySelector(".mealz-recipe-card__counter p");t&&(this.guests=this.updatedGuests??this.getGuests(),t.innerHTML=this.guests.toString())}sendAnalyticsShow(){window.mealzInternal.analytics.sendEvent("recipe.show",this.analyticsPath,{recipe_id:this.recipeId,category_id:this.categoryId})}};n=C([l("mealz-recipe-card")],n);customElements.get("mealz-recipe-card")||customElements.define("mealz-recipe-card",n);
1
+ import{N as u}from"../assets/no-shadow-element-CaVIVF-o.js";import{V as p}from"../assets/viewport-listener-DAXSJTi3.js";import{t as I}from"../assets/custom-element-BhZVzxrc.js";import"../assets/lit-element-4gw3YGga.js";import{h as g}from"../assets/session-handler-BPS5vj92.js";import"../assets/Subject-rBVVIydv.js";import"../assets/OperatorSubscriber-CcnWrfoX.js";import"../assets/async-CcgIcE7w.js";class n{constructor(){this.trackedRecipes=new Map,this.hasScrolled=!1,this.scrollListener=null,this.cleanupInterval=null,this.MAX_RECIPES=1e3,this.CLEANUP_INTERVAL=5*60*1e3,this.handlePageUnload=()=>{this.destroy()},this.setupScrollListener(),this.startAutoCleanup(),this.setupPageUnloadListener()}static getInstance(){return n.instance||(n.instance=new n),n.instance}trackRecipeShow(e,i,r){const s=Date.now(),c=!this.trackedRecipes.get(e),l=this.hasScrolled;!c&&!l||(this.trackedRecipes.size>=this.MAX_RECIPES&&this.cleanOldRecipes(),this.trackedRecipes.set(e,s),window.mealzInternal.analytics.sendEvent("recipe.show",i,{recipe_id:e,category_id:r}))}cleanOldRecipes(){const i=Date.now()-60*60*1e3;for(const[r,s]of this.trackedRecipes.entries())s<i&&this.trackedRecipes.delete(r)}clearAllRecipes(){this.trackedRecipes.clear()}destroy(){this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener),this.scrollListener=null),window.removeEventListener("beforeunload",this.handlePageUnload),this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null),this.trackedRecipes.clear(),this.hasScrolled=!1,n.instance=null}setupScrollListener(){let e;this.scrollListener=()=>{this.hasScrolled=!0,clearTimeout(e),e=window.setTimeout(()=>{this.hasScrolled=!1},2e3)},window.addEventListener("scroll",this.scrollListener)}startAutoCleanup(){this.cleanupInterval=window.setInterval(()=>{this.cleanOldRecipes()},this.CLEANUP_INTERVAL)}setupPageUnloadListener(){window.addEventListener("beforeunload",this.handlePageUnload)}}var w=Object.defineProperty,m=Object.getOwnPropertyDescriptor,f=(t,e,i,r)=>{for(var s=r>1?void 0:r?m(e,i):e,a=t.length-1,c;a>=0;a--)(c=t[a])&&(s=(r?c(e,i,s):c(s))||s);return r&&s&&w(e,i,s),s};let o=class extends u{constructor(){super(...arguments),this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.getInitialStatus(),this.listenInView(),this.subscriptions.push(window.mealzInternal.basket.recipeDataInBasket$().subscribe(t=>{const e=t.find(i=>i.id===this.recipeId);e&&(this.updatedRecipeId=e.id,this.updatedGuests=e.guests,this.updateDOM())}))}disconnectedCallback(){var e,i;super.disconnectedCallback(),this.subscriptions.forEach(r=>r.unsubscribe()),(e=this.priceViewportObserver)==null||e.disconnect(),(i=this.analyticsViewportObserver)==null||i.disconnect(),n.getInstance().cleanOldRecipes()}render(){this.recipeCardTop=this.querySelector(".mealz-recipe-card__top"),this.recipeCardCta=this.querySelector(".mealz-recipe-card__cta"),this.recipeCardTop&&(this.recipeCardTop.addEventListener("click",()=>this.recipeCardTopClick()),this.recipeCardCta&&this.recipeCardCta.addEventListener("click",()=>this.recipeCardCtaClick()))}listenInView(){this.priceViewportObserver=new p(this,()=>{this.handleIntersection()}),this.analyticsViewportObserver=new p(this,()=>{this.sendAnalyticsShow()},{threshold:.8,debounce:1e3})}handleIntersection(){this.recipePricing=this.querySelector("mealz-recipe-pricing"),this.recipePricing&&(this.recipePricing.fetchPrice(this.posId,this.guests,this.recipeId),this.priceViewportObserver.disconnect())}getInitialStatus(){var h;const t=(h=this.attributes["starting-data"])==null?void 0:h.value;if(!t)return;const{id:e,guests:i,posId:r,path:s,categoryId:a,initialTabIndex:c,sessionId:l}=JSON.parse(t);if(this.posId=r,this.recipeId=e,this.analyticsPath=s,this.categoryId=a,this.guests=i,this.initialTabIndex=c,g(l),!i){this.guests=this.getGuests();const d=this.querySelector(".mealz-recipe-card__counter p");d&&(d.innerHTML=this.guests.toString())}this.removeAttribute("starting-data")}recipeCardTopClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}recipeCardCtaClick(){window.mealzInternal.recipes.openDetails(this.recipeId,this.guests,this.initialTabIndex,this.analyticsPath,this.categoryId)}getGuests(){const t=localStorage.getItem("_miam/preferences/guests");if(t){const e=+t;if(!isNaN(e)&&e>0&&e<=30)return e}return 4}updateDOM(){if(this.recipeId!==this.updatedRecipeId)return;const t=this.querySelector(".mealz-recipe-card__counter p");t&&(this.guests=this.updatedGuests??this.getGuests(),t.innerHTML=this.guests.toString(),this.updatedRecipeId&&this.updatedGuests&&this.recipePricing&&this.recipePricing.fetchPrice(this.posId,this.guests,this.recipeId))}sendAnalyticsShow(){n.getInstance().trackRecipeShow(this.recipeId,this.analyticsPath,this.categoryId)}};o=f([I("mealz-recipe-card")],o);customElements.get("mealz-recipe-card")||customElements.define("mealz-recipe-card",o);
@@ -1 +1 @@
1
- .mealz-recipe-pricing{line-height:100%;max-width:70px}.mealz-recipe-pricing .mealz-recipe-pricing__wrapper .mealz-recipe-pricing__wrapper__subline{color:#1f354380;font-weight:500;line-height:100%}.mealz-recipe-pricing .hidden{display:none}.mealz-recipe-pricing .active{display:block}.mealz-recipe-pricing__loading{width:70px;height:24px;border-radius:.25rem;animation:skeleton-loading 1s linear infinite alternate}@keyframes skeleton-loading{0%{background-color:#c2cfd6}to{background-color:#f0f3f5}}
1
+ .mealz-recipe-pricing{line-height:100%;max-width:70px;opacity:1;transition:opacity .05s ease-in-out}.mealz-recipe-pricing.re-rendering{opacity:.98}.mealz-recipe-pricing .mealz-recipe-pricing__wrapper .mealz-recipe-pricing__wrapper__subline{color:#1f354380;font-weight:500;line-height:100%}.mealz-recipe-pricing .hidden{display:none}.mealz-recipe-pricing .active{display:block}.mealz-recipe-pricing__loading{width:70px;height:24px;border-radius:.25rem;animation:skeleton-loading 1s linear infinite alternate}@keyframes skeleton-loading{0%{background-color:#c2cfd6}to{background-color:#f0f3f5}}
@@ -1 +1 @@
1
- import{t as l}from"../assets/custom-element-BhZVzxrc.js";import"../assets/lit-element-4gw3YGga.js";import{N as u}from"../assets/no-shadow-element-CaVIVF-o.js";import{k as h,O as f,o as p,c as o}from"../assets/OperatorSubscriber-CcnWrfoX.js";import{S as d}from"../assets/Subject-rBVVIydv.js";var m=function(e){h(r,e);function r(i){var t=e.call(this)||this;return t._value=i,t}return Object.defineProperty(r.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),r.prototype._subscribe=function(i){var t=e.prototype._subscribe.call(this,i);return!t.closed&&i.next(this._value),t},r.prototype.getValue=function(){var i=this,t=i.hasError,s=i.thrownError,c=i._value;if(t)throw s;return this._throwIfClosed(),c},r.prototype.next=function(i){e.prototype.next.call(this,this._value=i)},r}(d),g=new f(function(e){return e.complete()});function b(e){return e<=0?function(){return g}:p(function(r,i){var t=0;r.subscribe(o(i,function(s){++t<=e&&(i.next(s),e<=t&&i.complete())}))})}function v(e){return p(function(r,i){var t=!1,s=0;r.subscribe(o(i,function(c){return(t||(t=!e(c,s++)))&&i.next(c)}))})}var P=Object.defineProperty,_=Object.getOwnPropertyDescriptor,y=(e,r,i,t)=>{for(var s=t>1?void 0:t?_(r,i):r,c=e.length-1,n;c>=0;c--)(n=e[c])&&(s=(t?n(r,i,s):n(s))||s);return t&&s&&P(r,i,s),s};let a=class extends u{constructor(){super(...arguments),this.formattedPrice="",this.rendered=new m(!1),this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.getInitialStatus(),this.subscriptions.push(window.mealzInternal.recipes.guestsUpdated().subscribe(e=>{e.recipeId===this.recipeId&&(this.serves=e.guests,this.recalculatePrice())}),this.rendered.pipe(v(e=>!e),b(1)).subscribe(()=>{this.subscriptions.push(window.mealzInternal.basket.recipeDataInBasket$().subscribe(e=>{e&&(this.recipePricingValue=e.find(r=>r.id===this.recipeId),this.recalculatePrice())}))}))}disconnectedCallback(){super.disconnectedCallback(),this.subscriptions.forEach(e=>e.unsubscribe())}fetchPrice(e,r,i=null){i||(i=this.recipeId),this.subscriptions.push(window.mealzInternal.recipes.fetchPricing(i,e,r).subscribe(t=>{t!=null&&t.price_per_serve&&this.applyCurrencyDisplay(t.price_per_serve)}))}render(){this.recipePricing=this.querySelector(".mealz-recipe-pricing"),this.recipePricing}getInitialStatus(){var s;const e=(s=this.attributes["starting-data"])==null?void 0:s.value;if(!e)return;const{recipeId:r,pricePerServe:i,serves:t}=JSON.parse(e);this.recipeId=r,this.pricePerServe=(i==null?void 0:i.toString())??null,this.serves=t,this.applyCurrencyDisplay(this.pricePerServe)}applyCurrencyDisplay(e){const r=parseFloat(e);isNaN(r)||(this.formattedPrice=r.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),this.updateDOM())}showPrice(){var i,t;let e=(i=this.recipePricing)==null?void 0:i.querySelector(".mealz-recipe-pricing__loading"),r=(t=this.recipePricing)==null?void 0:t.querySelector(".mealz-recipe-pricing__wrapper");e==null||e.classList.replace("active","hidden"),r==null||r.classList.replace("hidden","active")}updateDOM(){var r;const e=(r=this.recipePricing)==null?void 0:r.querySelector(".mealz-recipe-pricing__wrapper__price");e&&(e.innerHTML=this.formattedPrice+" €",this.showPrice())}recalculatePrice(){if(this.recipePricingValue){const e=(parseFloat(this.recipePricingValue.price)/this.recipePricingValue.guests).toString();this.applyCurrencyDisplay(e)}}};a=y([l("mealz-recipe-pricing")],a);customElements.get("mealz-recipe-pricing")||customElements.define("mealz-recipe-pricing",a);
1
+ import{N as h}from"../assets/no-shadow-element-CaVIVF-o.js";import{t as u}from"../assets/custom-element-BhZVzxrc.js";import"../assets/lit-element-4gw3YGga.js";import{k as d,O as m,o as l,c as p}from"../assets/OperatorSubscriber-CcnWrfoX.js";import{S as f}from"../assets/Subject-rBVVIydv.js";var P=function(r){d(e,r);function e(i){var t=r.call(this)||this;return t._value=i,t}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(i){var t=r.prototype._subscribe.call(this,i);return!t.closed&&i.next(this._value),t},e.prototype.getValue=function(){var i=this,t=i.hasError,s=i.thrownError,n=i._value;if(t)throw s;return this._throwIfClosed(),n},e.prototype.next=function(i){r.prototype.next.call(this,this._value=i)},e}(f),v=new m(function(r){return r.complete()});function y(r){return r<=0?function(){return v}:l(function(e,i){var t=0;e.subscribe(p(i,function(s){++t<=r&&(i.next(s),r<=t&&i.complete())}))})}function g(r){return l(function(e,i){var t=!1,s=0;e.subscribe(p(i,function(n){return(t||(t=!r(n,s++)))&&i.next(n)}))})}class c{constructor(){this.priceMemorized=new Map,this.displayedPrices=new Set,this.cleanupInterval=null,this.MAX_MEMO_SIZE=500,this.CLEANUP_INTERVAL=10*60*1e3,this.handlePageUnload=()=>{this.destroy()},this.startAutoCleanup(),this.setupPageUnloadListener()}static getInstance(){return c.instance||(c.instance=new c),c.instance}getMemorizedPrice(e,i){const t=`${e}-${i}`;return this.priceMemorized.get(t)}memorizedPrice(e,i,t){const s=`${e}-${i}`;this.priceMemorized.size>=this.MAX_MEMO_SIZE&&this.cleanOldPrices(),this.priceMemorized.set(s,{price:t,guests:i})}isPriceDisplayed(e,i){const t=`${e}-${i}`;return this.displayedPrices.has(t)}markPriceAsDisplayed(e,i){const t=`${e}-${i}`;this.displayedPrices.add(t)}cleanOldPrices(){this.priceMemorized.size>this.MAX_MEMO_SIZE*.8&&Array.from(this.priceMemorized.entries()).slice(0,Math.floor(this.priceMemorized.size*.3)).forEach(([t])=>{this.priceMemorized.delete(t),this.displayedPrices.delete(t)})}clearAllPrices(){this.priceMemorized.clear(),this.displayedPrices.clear()}destroy(){window.removeEventListener("beforeunload",this.handlePageUnload),this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null),this.priceMemorized.clear(),this.displayedPrices.clear(),c.instance=null}startAutoCleanup(){this.cleanupInterval=window.setInterval(()=>{this.cleanOldPrices()},this.CLEANUP_INTERVAL)}setupPageUnloadListener(){window.addEventListener("beforeunload",this.handlePageUnload)}}var b=Object.defineProperty,_=Object.getOwnPropertyDescriptor,z=(r,e,i,t)=>{for(var s=t>1?void 0:t?_(e,i):e,n=r.length-1,a;n>=0;n--)(a=r[n])&&(s=(t?a(e,i,s):a(s))||s);return t&&s&&b(e,i,s),s};let o=class extends h{constructor(){super(...arguments),this.formattedPrice="",this.rendered=new P(!1),this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.classList.add("re-rendering"),this.getInitialStatus(),this.subscriptions.push(window.mealzInternal.recipes.guestsUpdated().subscribe(r=>{r.recipeId===this.recipeId&&(this.serves=r.guests,this.recalculatePrice())}),this.rendered.pipe(g(r=>!r),y(1)).subscribe(()=>{this.subscriptions.push(window.mealzInternal.basket.recipeDataInBasket$().subscribe(r=>{r&&(this.recipePricingValue=r.find(e=>e.id===this.recipeId),this.recalculatePrice())}))})),requestAnimationFrame(()=>{this.classList.remove("re-rendering")})}disconnectedCallback(){super.disconnectedCallback(),this.subscriptions.forEach(r=>r.unsubscribe())}fetchPrice(r,e,i=null){i||(i=this.recipeId);const t=c.getInstance(),s=t.getMemorizedPrice(i,e);if(s){requestAnimationFrame(()=>{this.applyCurrencyDisplay(s.price),t.markPriceAsDisplayed(i,e)});return}this.subscriptions.push(window.mealzInternal.recipes.fetchPricing(i,r,e).subscribe(n=>{n!=null&&n.price_per_serve&&(t.memorizedPrice(i,e,n.price_per_serve),requestAnimationFrame(()=>{this.applyCurrencyDisplay(n.price_per_serve),t.markPriceAsDisplayed(i,e)}))}))}render(){this.recipePricing=this.querySelector(".mealz-recipe-pricing"),this.recipePricing&&this.recipeId&&this.pricePerServe&&c.getInstance().isPriceDisplayed(this.recipeId,this.serves)&&requestAnimationFrame(()=>{this.applyCurrencyDisplay(this.pricePerServe)})}getInitialStatus(){var s;const r=(s=this.attributes["starting-data"])==null?void 0:s.value;if(!r)return;const{recipeId:e,pricePerServe:i,serves:t}=JSON.parse(r);this.recipeId=e,this.pricePerServe=(i==null?void 0:i.toString())??null,this.serves=t,this.applyCurrencyDisplay(this.pricePerServe)}applyCurrencyDisplay(r){const e=parseFloat(r);isNaN(e)||(this.formattedPrice=e.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),this.updateDOM())}showPrice(){var i,t;let r=(i=this.recipePricing)==null?void 0:i.querySelector(".mealz-recipe-pricing__loading"),e=(t=this.recipePricing)==null?void 0:t.querySelector(".mealz-recipe-pricing__wrapper");r==null||r.classList.replace("active","hidden"),e==null||e.classList.replace("hidden","active")}updateDOM(){var e;const r=(e=this.recipePricing)==null?void 0:e.querySelector(".mealz-recipe-pricing__wrapper__price");r&&(r.innerHTML=this.formattedPrice+" €",this.showPrice())}recalculatePrice(){if(this.recipePricingValue){const r=(parseFloat(this.recipePricingValue.price)/this.recipePricingValue.guests).toString();requestAnimationFrame(()=>{this.applyCurrencyDisplay(r);const e=c.getInstance();e.memorizedPrice(this.recipeId,this.recipePricingValue.guests,r),e.markPriceAsDisplayed(this.recipeId,this.recipePricingValue.guests)})}}};o=z([u("mealz-recipe-pricing")],o);customElements.get("mealz-recipe-pricing")||customElements.define("mealz-recipe-pricing",o);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mealz-components",
3
3
  "type": "module",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
5
5
  "main": "./dist/mealz-components.js",
6
6
  "module": "./dist/mealz-components.js",
7
7
  "scripts": {