najwer23morsels 0.16.2 → 0.16.4
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/lib/Picture.js +1 -1
- package/package.json +1 -1
package/lib/Picture.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{useState as i,useRef as t}from"react";import{u as
|
|
1
|
+
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{useState as i,useRef as o,useEffect as t}from"react";import{u as c}from"./useWindowSize-CAQRbyxi.js";import{T as a}from"./TextBox-dHL75Jj9.js";import{g as n}from"./getCssVariableStyle-CBKDTT0s.js";import{s as l}from"./style-inject.es-BnTDb6vU.js";var u={n23mPictureFigure:"Picture-module_n23mPictureFigure__uStTO",n23mPicture:"Picture-module_n23mPicture__LpndY",border:"Picture-module_border__yjTpQ",loaded:"Picture-module_loaded__fpjpQ",cacheLoaded:"Picture-module_cacheLoaded__IunbX"};l("@layer n23mPicture{.Picture-module_n23mPictureFigure__uStTO{margin:0;padding:0}.Picture-module_n23mPicture__LpndY{box-sizing:border-box;display:block;&.Picture-module_border__yjTpQ{border:2px solid var(--picture-bc);padding:5px}& img{display:grid;height:auto;max-height:var(--picture-mh,unset);opacity:0;width:100%}&.Picture-module_loaded__fpjpQ img{opacity:1;transition:opacity .25s ease-in-out}&.Picture-module_cacheLoaded__IunbX img{opacity:1}}}");const d=(e,r=25)=>{const[c,a]=i(null),n=o(null);return t(()=>{if(!e)return void a(null);const i=new Image;n.current=i;const o=new Promise((r,o)=>{i.onload=()=>r(i),i.onerror=()=>o(new Error("Image load error")),i.src=e});return((e,r,i=null)=>{let o;const t=new Promise((r,t)=>{o=setTimeout(()=>t(i),e)});return Promise.race([r,t]).finally(()=>{clearTimeout(o)})})(r,o,"Image not loaded from cache").then(()=>a(!0)).catch(()=>a(!1)).finally(()=>{n.current=null}),()=>{n.current&&(n.current.onload=null,n.current.onerror=null,n.current=null)}},[e,r]),c},m=({children:o,className:t,style:l,draggable:m=!1,alt:s,src:p,srcDesktop:g,srcMobile:_,ar:h,arMobile:b,arDesktop:P,border:f=!1,borderColor:x="black",loading:y="lazy",srcset:j,sizes:w,maxHeight:S,maxHeightMobile:T,maxHeightDesktop:z,figcaption:L,figcaptionColor:k,...I})=>{const[v,F]=i(!1),{width:Q}=c(),C=g&&Q>=768?g:_&&Q<768?_:p||"",D=d(C,25);return e("figure",{className:u.n23mPictureFigure,children:[e("picture",{className:["n23mPicture",u.n23mPicture,f&&u.border,v&&!D&&u.loaded,D&&u.cacheLoaded,t].filter(Boolean).join(" "),...I,style:{...n({"--picture-bc":x,"--picture-mh":z||T?T&&Q<767.98?T:z||T:S}),...l},children:[g&&r("source",{media:"(min-width: 768px)",srcSet:g}),_&&r("source",{media:"(max-width: 767.98px)",srcSet:_}),r("img",{sizes:w,srcSet:j,width:P||b?b&&Q<767.98?b:P||b:h,height:1,src:C,alt:s,loading:y,onLoad:()=>F(!0),draggable:m})]}),L&&r("figcaption",{children:r(a,{tag:"p",desktopSize:12,mobileSize:12,color:k,margin:"3px 0 3px 0",children:L})})]})};export{m as Picture};
|