FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-order-bump2.js
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{s as speak}from"./index2.js";import{i as intervalString}from"./price.js";import{s as state}from"./mutations2.js";import{r as removeCheckoutLineItem,a as addCheckoutLineItem,t as trackOrderBump}from"./mutations4.js";import{d as defineCustomElement$2}from"./sc-choice2.js";import{d as defineCustomElement$1}from"./sc-divider2.js";const scOrderBumpCss=":host {\n display: block;\n}\n\n.bump {\n display: grid;\n gap: 1em;\n}\n.bump__text {\n display: grid;\n gap: 0.25em;\n}\n.bump__tag {\n background: var(--sc-color-primary-500);\n color: var(--sc-color-white);\n border-radius: var(--sc-input-border-radius-medium);\n padding: var(--sc-spacing-x-small);\n font-size: var(--sc-font-size-x-small);\n}\n.bump__product {\n display: flex;\n align-items: center;\n gap: var(--sc-choice-padding, 1.3em 1.1em);\n line-height: var(--sc-line-height-dense);\n}\n.bump__product--wrapper {\n container-type: inline-size;\n}\n@container (max-width: 325px) {\n .bump__product {\n flex-direction: column;\n align-items: start;\n }\n}\n.bump__title {\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n line-clamp: 2;\n overflow: hidden;\n text-overflow: ellipsis;\n word-break: break-word;\n}\n.bump__product-title {\n font-weight: var(--sc-font-weight-semibold);\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n line-clamp: 2;\n overflow: hidden;\n text-overflow: ellipsis;\n word-break: break-word;\n}\n.bump__product-description {\n color: var(--sc-input-label-color);\n}\n.bump__image {\n width: var(--sc-product-line-item-image-size, 4em);\n height: var(--sc-product-line-item-image-size, 4em);\n flex: 0 0 var(--sc-product-line-item-image-size, 4em);\n object-fit: cover;\n border-radius: 4px;\n border: 1px solid var(--sc-color-gray-200);\n display: block;\n box-shadow: var(--sc-input-box-shadow);\n}\n.bump__price--has-discount {\n display: flex;\n align-items: baseline;\n gap: var(--sc-spacing-x-small);\n}\n.bump__price--has-discount .bump__original-price {\n text-decoration: line-through;\n color: var(--sc-color-gray-500);\n font-size: var(--sc-font-size-small);\n}\n.bump__price .bump__new-price {\n font-size: var(--sc-font-size-large);\n color: var(--sc-color-gray-700);\n}\n.bump__price .bump__interval {\n color: var(--sc-color-gray-500);\n}\n.bump__amount {\n display: flex;\n align-items: center;\n gap: var(--sc-spacing-x-small);\n flex-wrap: wrap;\n margin-top: var(--sc-spacing-xx-small);\n}",ScOrderBumpStyle0=scOrderBumpCss,ScOrderBump=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.bump=void 0,this.showControl=void 0}lineItem(){var e,i,n;return null===(n=null===(i=null===(e=null==state?void 0:state.checkout)||void 0===e?void 0:e.line_items)||void 0===i?void 0:i.data)||void 0===n?void 0:n.find((e=>{var i;return(null==e?void 0:e.bump)===(null===(i=this.bump)||void 0===i?void 0:i.id)}))}updateLineItem(){var e,i,n,t;const o=(null===(e=this.bump.price)||void 0===e?void 0:e.id)||(null===(i=this.bump)||void 0===i?void 0:i.price);if(this.lineItem())return removeCheckoutLineItem(null===(n=this.lineItem())||void 0===n?void 0:n.id),void speak(wp.i18n.__("Order bump Removed.","surecart"));addCheckoutLineItem({bump:null===(t=this.bump)||void 0===t?void 0:t.id,price:o,quantity:1}),speak(wp.i18n.__("Order bump applied.","surecart"))}componentDidLoad(){var e;trackOrderBump(null===(e=this.bump)||void 0===e?void 0:e.id)}newPrice(){var e,i,n,t,o,r;let d=null,a=(null===(i=null===(e=this.bump)||void 0===e?void 0:e.price)||void 0===i?void 0:i.amount)||0;if((null===(n=this.bump)||void 0===n?void 0:n.amount_off)&&(d=Math.max(0,a-(null===(t=this.bump)||void 0===t?void 0:t.amount_off))),null===(o=this.bump)||void 0===o?void 0:o.percent_off){const e=a*((null===(r=this.bump)||void 0===r?void 0:r.percent_off)/100);d=Math.max(0,a-e)}return d}renderInterval(){var e;const i=intervalString(null===(e=this.bump)||void 0===e?void 0:e.price,{labels:{interval:"/",period:wp.i18n.__("for","surecart")}});return i.trim().length?h("span",{class:"bump__interval"},i):null}renderPrice(){var e,i,n,t,o,r,d,a,s;return h("div",{slot:"description",class:{bump__price:!0,"bump__price--has-discount":!!(null===(e=this.bump)||void 0===e?void 0:e.percent_off)||!!(null===(i=this.bump)||void 0===i?void 0:i.amount_off)},part:"price"},!(!(null===(n=this.bump)||void 0===n?void 0:n.percent_off)&&!(null===(t=this.bump)||void 0===t?void 0:t.amount_off))&&h("span",{"aria-label": /** translators: %s: old price */ wp.i18n.sprintf(wp.i18n.__("Originally priced at %s.","surecart"),null===(o=this.bump)||void 0===o?void 0:o.subtotal_display_amount),class:"bump__original-price"},null===(r=this.bump)||void 0===r?void 0:r.subtotal_display_amount),h("span",null,h("span",{"aria-hidden":"true"},0===(null===(d=this.bump)||void 0===d?void 0:d.total_amount)&&wp.i18n.__("Free","surecart"),(null===(a=this.bump)||void 0===a?void 0:a.total_amount)>0&&h("span",{class:"bump__new-price"},null===(s=this.bump)||void 0===s?void 0:s.total_display_amount),this.renderInterval())))}renderDiscount(){var e,i,n,t,o,r,d;return(null===(e=this.bump)||void 0===e?void 0:e.amount_off)?h("div",{class:"bump__tag","aria-label": /** translators: %1$s: amount off, %2$s: currency */ wp.i18n.sprintf(wp.i18n.__("You save %1$s%2$s.","surecart"),null===(i=this.bump)||void 0===i?void 0:i.amount_off,(null===(n=this.bump)||void 0===n?void 0:n.price).currency)},h("span",{"aria-hidden":"true"},wp.i18n._x("Save","Save money","surecart")," ",null===(t=this.bump)||void 0===t?void 0:t.amount_off_display_amount)):(null===(o=this.bump)||void 0===o?void 0:o.percent_off)?h("div",{class:"bump__tag","aria-label": /** translators: %s: amount percent off */ wp.i18n.sprintf(wp.i18n.__("You save %s%%.","surecart"),null===(r=this.bump)||void 0===r?void 0:r.percent_off)},h("span",{"aria-hidden":"true"},wp.i18n.sprintf( /** translators: %s: amount percent off */ wp.i18n._x("Save %s%%","Save money","surecart"),null===(d=this.bump)||void 0===d?void 0:d.percent_off))):void 0}render(){var e,i,n,t,o,r,d,a,s,l,c,u,p,m,v,b,_,f;const g=null===(i=null===(e=this.bump)||void 0===e?void 0:e.price)||void 0===i?void 0:i.product;return h("sc-choice",{key:"983d78c5de4e40b4d66f6e755e49000c3ba2e07f",value:null===(n=this.bump)||void 0===n?void 0:n.id,type:"checkbox",showControl:this.showControl,checked:!!this.lineItem(),onClick:e=>{e.preventDefault(),e.stopImmediatePropagation(),this.updateLineItem()},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.stopImmediatePropagation(),this.updateLineItem())},exportparts:"base, control, checked-icon, title"},h("div",{key:"54a1819dbbfc23855d4a0920cd853973077fcb58",part:"base-content",class:"bump"},h("div",{key:"6261d9ede9267a35093f1271bcf48c98840cd605",class:"bump__text"},h("div",{key:"8eb1bd33b2592dc8358720b53ca3640bd03fd8b0",class:"bump__title","aria-label":wp.i18n.sprintf( /* translators: %s: order bump name */ wp.i18n.__("Product: %s.","surecart"),(null===(o=null===(t=this.bump)||void 0===t?void 0:t.metadata)||void 0===o?void 0:o.cta)||(null===(r=this.bump)||void 0===r?void 0:r.name)||(null==g?void 0:g.name))},h("span",{key:"fd3214f1fc3f0e0bdd909d92d96339cc2a1b86a4","aria-hidden":"true"},(null===(a=null===(d=this.bump)||void 0===d?void 0:d.metadata)||void 0===a?void 0:a.cta)||(null===(s=this.bump)||void 0===s?void 0:s.name)||(null==g?void 0:g.name))),h("div",{key:"ef1e4657efc6dc4755641de2154d49e405f4d484",class:"bump__amount"},this.renderPrice(),this.renderDiscount()))),(null===(c=null===(l=this.bump)||void 0===l?void 0:l.metadata)||void 0===c?void 0:c.description)&&h("div",{key:"2e3a416ed1918562a4c1f49113cba05729b87ec3",slot:"footer",class:"bump__product--wrapper"},h("sc-divider",{key:"4d06a09e82fd1ecd41c01bdb048c5a76b0e33d69",style:{"--spacing":"var(--sc-spacing-medium)"}}),h("div",{key:"38c660a40700423b3f3a727f1db8f164a736daeb",class:"bump__product"},!!(null===(u=null==g?void 0:g.line_item_image)||void 0===u?void 0:u.src)&&h("img",{key:"df9c423d1eceadc3e61bc3530ae79c8bbb44a684",...null==g?void 0:g.line_item_image,class:"bump__image"}),h("div",{key:"0698bdcb6b3029cdccb97c5e7dc356cd60d3dab9",class:"bump__product-text"},!!(null===(m=null===(p=this.bump)||void 0===p?void 0:p.metadata)||void 0===m?void 0:m.cta)&&h("div",{key:"6f717ff6352c7fc1c48a4e29a934435bbb9406f1",class:"bump__product-title","aria-hidden":"true"},this.bump.name||(null==g?void 0:g.name)),!!(null===(b=null===(v=this.bump)||void 0===v?void 0:v.metadata)||void 0===b?void 0:b.description)&&h("div",{key:"4747ed4352a726279216fe07b174fd446b69b165",class:"bump__product-description","aria-label":wp.i18n.sprintf( /* translators: %s: Product description */ wp.i18n.__("Product description: %s.","surecart"),null===(_=this.bump)||void 0===_?void 0:_.rendered_description)},h("span",{key:"f863722bbe36276c26bc2da9f0381f8917f800f6","aria-hidden":"true",innerHTML:null===(f=this.bump)||void 0===f?void 0:f.rendered_description}))))))}static get style(){return ScOrderBumpStyle0}},[1,"sc-order-bump",{bump:[16],showControl:[516,"show-control"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-order-bump","sc-choice","sc-divider"].forEach((e=>{switch(e){case"sc-order-bump":customElements.get(e)||customElements.define(e,ScOrderBump);break;case"sc-choice":customElements.get(e)||defineCustomElement$2();break;case"sc-divider":customElements.get(e)||defineCustomElement$1()}}))}export{ScOrderBump as S,defineCustomElement as d};
Save
Back