← Back
Editing: product-image-frontend.js
(globalThis.webpackChunkwebpackWcBlocksFrontendJsonp=globalThis.webpackChunkwebpackWcBlocksFrontendJsonp||[]).push([[232,442],{3651:(e,t,o)=>{"use strict";o.d(t,{p:()=>l});var n=o(4921),a=o(3993),s=o(7356),i=o(9786);function r(e={}){const t={};return(0,i.getCSSRules)(e,{selector:""}).forEach(e=>{t[e.key]=e.value}),t}function c(e,t){return e&&t?`has-${(0,s.c)(t)}-${e}`:""}const l=e=>{const t=(e=>{const t=(0,a.isObject)(e)?e:{style:{}};let o=t.style;return(0,a.isString)(o)&&(o=JSON.parse(o)||{}),(0,a.isObject)(o)||(o={}),{...t,style:o}})(e),o=function(e){const{backgroundColor:t,textColor:o,gradient:s,style:i}=e,l=c("background-color",t),d=c("color",o),g=function(e){if(e)return`has-${e}-gradient-background`}(s),p=g||i?.color?.gradient;return{className:(0,n.A)(d,g,{[l]:!p&&!!l,"has-text-color":o||i?.color?.text,"has-background":t||i?.color?.background||s||i?.color?.gradient,"has-link-color":(0,a.isObject)(i?.elements?.link)?i?.elements?.link?.color:void 0}),style:r({color:i?.color||{}})}}(t),s=function(e){const t=e.style?.border||{};return{className:function(e){const{borderColor:t,style:o}=e,a=t?c("border-color",t):"";return(0,n.A)({"has-border-color":!!t||!!o?.border?.color,[a]:!!a})}(e),style:r({border:t})}}(t),i=function(e){return{className:void 0,style:r({spacing:e.style?.spacing||{}})}}(t),l=(e=>{const t=(0,a.isObject)(e.style.typography)?e.style.typography:{},o=(0,a.isString)(t.fontFamily)?t.fontFamily:"";return{className:e.fontFamily?`has-${e.fontFamily}-font-family`:o,style:{fontSize:e.fontSize?`var(--wp--preset--font-size--${e.fontSize})`:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,textDecoration:t.textDecoration,textTransform:t.textTransform}}})(t);return{className:(0,n.A)(l.className,o.className,s.className,i.className),style:{...l.style,...o.style,...s.style,...i.style}}}},4521:(e,t,o)=>{"use strict";o.r(t),o.d(t,{default:()=>S});var n=o(1616),a=o(6087),s=o(7723),i=o(4921),r=o(5703),c=o(2796),l=o(3651),d=o(8032),g=o(8537),p=o(3993),u=o(6475);o(6222);let m=function(e){return e.SINGLE="single",e.THUMBNAIL="thumbnail",e.CROPPED="cropped",e}({});var h=o(790);const f=e=>{const{aspectRatio:t,height:o,width:n,scale:a}=e;return{height:o,width:n,objectFit:a,aspectRatio:t}},y=({padding:e,paddingTop:t,paddingRight:o,paddingBottom:n,paddingLeft:a})=>{const s={};return void 0!==e&&(s.padding=e),void 0!==t&&(s.paddingTop=t),void 0!==o&&(s.paddingRight=o),void 0!==n&&(s.paddingBottom=n),void 0!==a&&(s.paddingLeft=a),s},b=e=>{const t=(0,r.getSetting)("placeholderImgSrcFullSize",r.PLACEHOLDER_IMG_SRC);return(0,h.jsx)("img",{...e,src:t,alt:"",width:void 0,height:void 0})},k=({image:e,loaded:t,fallbackAlt:o,width:n,scale:a,height:s,aspectRatio:i})=>{const{src:r,srcset:c,sizes:l,alt:d}=e||{},g={alt:d||o,hidden:!t,src:r,srcSet:c,sizes:l},p=f({height:s,width:n,scale:a,aspectRatio:i});return e?(0,h.jsx)("img",{style:p,"data-testid":"product-image",...g}):(0,h.jsx)(b,{style:p})},w=e=>{const{product:t}=e;return!(0,p.isEmpty)(t)&&(void 0===(o=e.showSaleBadge)||o);var o},v=(0,n.withProductDataContext)(e=>{const{aspectRatio:t,children:o,className:n,height:p,imageId:v,imageSizing:x,scale:S,showProductLink:N=!0,style:R,width:C,isAdmin:_,product:j,isResolving:A,...L}=e,B=(0,l.p)(e),{padding:P,paddingTop:F,paddingRight:$,paddingBottom:E,paddingLeft:T,...z}=B.style,D=(0,a.isValidElement)(o)?(0,a.cloneElement)(o,{style:{...o.props.style,...y({padding:P,paddingTop:F,paddingRight:$,paddingBottom:E,paddingLeft:T})}}):o,{parentClassName:O}=(0,c.useInnerBlockLayoutContext)(),{product:I,isLoading:H}=(0,c.useProductDataContext)({isAdmin:_,product:j,isResolving:A}),{dispatchStoreEvent:J}=(0,d.y)(),M=((e,t,o,n)=>e&&e.dimensions&&e.dimensions.aspectRatio&&"string"==typeof e.dimensions.aspectRatio?e.dimensions.aspectRatio:t&&"string"==typeof t?t:!n||n!==m.THUMBNAIL&&n!==m.CROPPED?void 0:o??void 0)(R,t,(0,r.getSetting)("thumbnailAspectRatio",null),x),W=`wc-block-components-product-image--aspect-ratio-${M?M.replace("/","-"):"auto"}`;if(!I?.id){const e=f({height:p,width:C,scale:S,aspectRatio:M});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("div",{className:(0,i.A)(n,"wc-block-components-product-image",W,{[`${O}__product-image`]:O},B.className),style:z,children:(0,h.jsx)(b,{style:e})}),D]})}const U=((e,t)=>e.images.length?t&&e.images.find(e=>e.id===t)||e.images[0]:null)(I,v);U&&(U.alt=U.alt||(0,g.decodeEntities)(I.name));const G=N?"a":a.Fragment,K=I?.name? // translators: %s is the product name. // translators: %s is the product name. (0,s.sprintf)((0,s.__)("Link to %s","woocommerce"),I.name):"",V={href:N?I?.permalink:void 0,...N&&{"aria-label":K,onClick:()=>{J("product-view-link",{product:I})}}};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)("div",{className:(0,i.A)(n,"wc-block-components-product-image",W,{[`${O}__product-image`]:O},B.className),style:z,children:[w(e)&&(0,h.jsx)(u.default,{align:e.saleBadgeAlign||"right",...L}),(0,h.jsx)(G,{...!_&&N&&V,children:(0,h.jsx)(k,{fallbackAlt:(0,g.decodeEntities)(I.name),image:U,loaded:!H,width:C,height:p,scale:S,aspectRatio:M})})]}),D]})}),x=JSON.parse('{"uK":{"showProductLink":{"type":"boolean","default":true},"showSaleBadge":{"type":"boolean","default":true},"saleBadgeAlign":{"type":"string","default":"right"},"imageSizing":{"type":"string","default":"single"},"productId":{"type":"number","default":0},"width":{"type":"string"},"height":{"type":"string"},"scale":{"type":"string","default":"cover"},"aspectRatio":{"type":"string"}}}'),S=(0,n.withFilteredAttributes)(x.uK)(v)},6475:(e,t,o)=>{"use strict";o.r(t),o.d(t,{Block:()=>g,default:()=>p});var n=o(7723),a=o(910),s=o(4921),i=o(4656),r=o(2796),c=o(3651),l=o(1616);o(4324);var d=o(790);const g=e=>{const{className:t,align:o,isDescendentOfSingleProductTemplate:l}=e,g=(0,c.p)(e),{parentClassName:p}=(0,r.useInnerBlockLayoutContext)(),{product:u}=(0,r.useProductDataContext)();if(!(u.id&&u.on_sale||l))return null;const m="amount"===e.badgeContent||"percentage"===e.badgeContent;let h=e.saleText||(0,n.__)("Sale","woocommerce");if(m&&"grouped"!==u.type){const t="prices"in u?u.prices:void 0,o=(e=>{const t=Number(e?.regular_price),o=t-Number(e?.price);return t>0&&o>0?{amount:o,percentage:Math.round(o/t*100)}:null})(t);if(o){if("percentage"===e.badgeContent&&0===o.percentage)return null;const s="percentage"===e.badgeContent?(0,n.sprintf)(/* translators: %s: discount percentage. %% is the percent sign. */ /* translators: %s: discount percentage. %% is the percent sign. */ (0,n.__)("%s%%","woocommerce"),o.percentage):(0,a.formatPrice)(o.amount,(0,a.getCurrencyFromPriceResponse)(t));h="variable"===u.type?(0,n.sprintf)(/* translators: %s: approximate discount for a variable product in the editor. */ /* translators: %s: approximate discount for a variable product in the editor. */ (0,n.__)("Up to %s","woocommerce"),s):`${e.prefix??""}${s}${e.suffix??""}`}}const f="string"==typeof o?`wc-block-components-product-sale-badge--align-${o}`:"";return(0,d.jsx)("div",{className:(0,s.A)("wc-block-components-product-sale-badge",t,f,{[`${p}__product-onsale`]:p},g.className),style:g.style,children:(0,d.jsx)(i.Label,{label:h,screenReaderLabel:(0,n.sprintf)(/* translators: %s: sale badge text. */ /* translators: %s: sale badge text. */ (0,n.__)("Product on sale: %s","woocommerce"),h)})})},p=(0,l.withProductDataContext)(g)},6222:()=>{},4324:()=>{}}]);
Save File
Cancel