@j-ho/react-lazyload-image
Version:
React Image Lazy Load Component
31 lines (28 loc) • 15 kB
JavaScript
(function(b,I){typeof exports=="object"&&typeof module<"u"?module.exports=I(require("react")):typeof define=="function"&&define.amd?define(["react"],I):(b=typeof globalThis<"u"?globalThis:b||self,b.LazyImage=I(b.React))})(this,function(b){"use strict";var I={exports:{}},D={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Q;function Ae(){if(Q)return D;Q=1;var T=b,C=Symbol.for("react.element"),W=Symbol.for("react.fragment"),h=Object.prototype.hasOwnProperty,j=T.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,E={key:!0,ref:!0,__self:!0,__source:!0};function P(m,f,R){var c,y={},S=null,V=null;R!==void 0&&(S=""+R),f.key!==void 0&&(S=""+f.key),f.ref!==void 0&&(V=f.ref);for(c in f)h.call(f,c)&&!E.hasOwnProperty(c)&&(y[c]=f[c]);if(m&&m.defaultProps)for(c in f=m.defaultProps,f)y[c]===void 0&&(y[c]=f[c]);return{$$typeof:C,type:m,key:S,ref:V,props:y,_owner:j.current}}return D.Fragment=W,D.jsx=P,D.jsxs=P,D}var F={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var q;function Te(){return q||(q=1,process.env.NODE_ENV!=="production"&&function(){var T=b,C=Symbol.for("react.element"),W=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),j=Symbol.for("react.strict_mode"),E=Symbol.for("react.profiler"),P=Symbol.for("react.provider"),m=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),c=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),V=Symbol.for("react.offscreen"),te=Symbol.iterator,xe="@@iterator";function ke(e){if(e===null||typeof e!="object")return null;var r=te&&e[te]||e[xe];return typeof r=="function"?r:null}var O=T.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function d(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];De("error",e,t)}}function De(e,r,t){{var n=O.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var u=t.map(function(i){return String(i)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var Fe=!1,We=!1,Me=!1,Ye=!1,Ve=!1,ne;ne=Symbol.for("react.module.reference");function Ze(e){return!!(typeof e=="string"||typeof e=="function"||e===h||e===E||Ve||e===j||e===R||e===c||Ye||e===V||Fe||We||Me||typeof e=="object"&&e!==null&&(e.$$typeof===S||e.$$typeof===y||e.$$typeof===P||e.$$typeof===m||e.$$typeof===f||e.$$typeof===ne||e.getModuleId!==void 0))}function Le(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function ae(e){return e.displayName||"Context"}function _(e){if(e==null)return null;if(typeof e.tag=="number"&&d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case h:return"Fragment";case W:return"Portal";case E:return"Profiler";case j:return"StrictMode";case R:return"Suspense";case c:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case m:var r=e;return ae(r)+".Consumer";case P:var t=e;return ae(t._context)+".Provider";case f:return Le(e,e.render,"ForwardRef");case y:var n=e.displayName||null;return n!==null?n:_(e.type)||"Memo";case S:{var o=e,u=o._payload,i=o._init;try{return _(i(u))}catch{return null}}}return null}var w=Object.assign,M=0,ie,oe,ue,se,le,fe,ce;function de(){}de.__reactDisabledLog=!0;function Ne(){{if(M===0){ie=console.log,oe=console.info,ue=console.warn,se=console.error,le=console.group,fe=console.groupCollapsed,ce=console.groupEnd;var e={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}M++}}function Ge(){{if(M--,M===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:w({},e,{value:ie}),info:w({},e,{value:oe}),warn:w({},e,{value:ue}),error:w({},e,{value:se}),group:w({},e,{value:le}),groupCollapsed:w({},e,{value:fe}),groupEnd:w({},e,{value:ce})})}M<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var z=O.ReactCurrentDispatcher,U;function Z(e,r,t){{if(U===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);U=n&&n[1]||""}return`
`+U+e}}var J=!1,L;{var ze=typeof WeakMap=="function"?WeakMap:Map;L=new ze}function ve(e,r){if(!e||J)return"";{var t=L.get(e);if(t!==void 0)return t}var n;J=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=z.current,z.current=null,Ne();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(g){n=g}Reflect.construct(e,[],i)}else{try{i.call()}catch(g){n=g}e.call(i.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var a=g.stack.split(`
`),v=n.stack.split(`
`),s=a.length-1,l=v.length-1;s>=1&&l>=0&&a[s]!==v[l];)l--;for(;s>=1&&l>=0;s--,l--)if(a[s]!==v[l]){if(s!==1||l!==1)do if(s--,l--,l<0||a[s]!==v[l]){var p=`
`+a[s].replace(" at new "," at ");return e.displayName&&p.includes("<anonymous>")&&(p=p.replace("<anonymous>",e.displayName)),typeof e=="function"&&L.set(e,p),p}while(s>=1&&l>=0);break}}}finally{J=!1,z.current=u,Ge(),Error.prepareStackTrace=o}var k=e?e.displayName||e.name:"",A=k?Z(k):"";return typeof e=="function"&&L.set(e,A),A}function Ue(e,r,t){return ve(e,!1)}function Je(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function N(e,r,t){if(e==null)return"";if(typeof e=="function")return ve(e,Je(e));if(typeof e=="string")return Z(e);switch(e){case R:return Z("Suspense");case c:return Z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ue(e.render);case y:return N(e.type,r,t);case S:{var n=e,o=n._payload,u=n._init;try{return N(u(o),r,t)}catch{}}}return""}var Y=Object.prototype.hasOwnProperty,ge={},pe=O.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,t=N(e.type,e._source,r?r.type:null);pe.setExtraStackFrame(t)}else pe.setExtraStackFrame(null)}function Be(e,r,t,n,o){{var u=Function.call.bind(Y);for(var i in e)if(u(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var v=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw v.name="Invariant Violation",v}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(G(o),d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),G(null)),a instanceof Error&&!(a.message in ge)&&(ge[a.message]=!0,G(o),d("Failed %s type: %s",t,a.message),G(null))}}}var He=Array.isArray;function B(e){return He(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function $e(e){try{return be(e),!1}catch{return!0}}function be(e){return""+e}function ye(e){if($e(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),be(e)}var me=O.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Re,he;function Qe(e){if(Y.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function qe(e){if(Y.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function er(e,r){typeof e.ref=="string"&&me.current}function rr(e,r){{var t=function(){Re||(Re=!0,d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function tr(e,r){{var t=function(){he||(he=!0,d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var nr=function(e,r,t,n,o,u,i){var a={$$typeof:C,type:e,key:r,ref:t,props:i,_owner:u};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ar(e,r,t,n,o){{var u,i={},a=null,v=null;t!==void 0&&(ye(t),a=""+t),qe(r)&&(ye(r.key),a=""+r.key),Qe(r)&&(v=r.ref,er(r,o));for(u in r)Y.call(r,u)&&!Xe.hasOwnProperty(u)&&(i[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)i[u]===void 0&&(i[u]=s[u])}if(a||v){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&rr(i,l),v&&tr(i,l)}return nr(e,a,v,o,n,me.current,i)}}var H=O.ReactCurrentOwner,Ie=O.ReactDebugCurrentFrame;function x(e){if(e){var r=e._owner,t=N(e.type,e._source,r?r.type:null);Ie.setExtraStackFrame(t)}else Ie.setExtraStackFrame(null)}var K;K=!1;function $(e){return typeof e=="object"&&e!==null&&e.$$typeof===C}function Ee(){{if(H.current){var e=_(H.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function ir(e){return""}var _e={};function or(e){{var r=Ee();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function Ce(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(_e[t])return;_e[t]=!0;var n="";e&&e._owner&&e._owner!==H.current&&(n=" It was passed a child from "+_(e._owner.type)+"."),x(e),d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),x(null)}}function Pe(e,r){{if(typeof e!="object")return;if(B(e))for(var t=0;t<e.length;t++){var n=e[t];$(n)&&Ce(n,r)}else if($(e))e._store&&(e._store.validated=!0);else if(e){var o=ke(e);if(typeof o=="function"&&o!==e.entries)for(var u=o.call(e),i;!(i=u.next()).done;)$(i.value)&&Ce(i.value,r)}}}function ur(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===y))t=r.propTypes;else return;if(t){var n=_(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!K){K=!0;var o=_(r);d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){x(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),x(null);break}}e.ref!==null&&(x(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),x(null))}}var Se={};function we(e,r,t,n,o,u){{var i=Ze(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var v=ir();v?a+=v:a+=Ee();var s;e===null?s="null":B(e)?s="array":e!==void 0&&e.$$typeof===C?(s="<"+(_(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",s,a)}var l=ar(e,r,t,o,u);if(l==null)return l;if(i){var p=r.children;if(p!==void 0)if(n)if(B(p)){for(var k=0;k<p.length;k++)Pe(p[k],e);Object.freeze&&Object.freeze(p)}else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Pe(p,e)}if(Y.call(r,"key")){var A=_(e),g=Object.keys(r).filter(function(gr){return gr!=="key"}),X=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!Se[A+X]){var vr=g.length>0?"{"+g.join(": ..., ")+": ...}":"{}";d(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,X,A,vr,A),Se[A+X]=!0}}return e===h?sr(l):ur(l),l}}function lr(e,r,t){return we(e,r,t,!0)}function fr(e,r,t){return we(e,r,t,!1)}var cr=fr,dr=lr;F.Fragment=h,F.jsx=cr,F.jsxs=dr}()),F}var ee;function je(){return ee||(ee=1,process.env.NODE_ENV==="production"?I.exports=Ae():I.exports=Te()),I.exports}var Oe=je();const re=b.memo(({src:T,placeholderSrc:C="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMzAwIDMwMCIgd2lkdGg9IjMwMCIgaGVpZ2h0PSIzMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImZsb3dpbmdHcmFkaWVudCIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjY2NjY2NjIiAvPgogICAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjY2NjY2NjIiAvPgogICAgICA8YW5pbWF0ZVRyYW5zZm9ybQogICAgICAgIGF0dHJpYnV0ZU5hbWU9ImdyYWRpZW50VHJhbnNmb3JtIgogICAgICAgIHR5cGU9InRyYW5zbGF0ZSIKICAgICAgICBmcm9tPSItMSwwIgogICAgICAgIHRvPSIxLDAiCiAgICAgICAgZHVyPSIxLjVzIgogICAgICAgIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIgogICAgICAvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICA8L2RlZnM+CiAgPHJlY3Qgd2lkdGg9IjMwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9InVybCgjZmxvd2luZ0dyYWRpZW50KSIgLz4KPC9zdmc+",alt:W="",threshold:h=.1,...j})=>{const E=b.useRef(null),[P,m]=b.useState(!1);b.useEffect(()=>{if(!("IntersectionObserver"in window)){m(!0);return}const R=new IntersectionObserver(([y])=>{y.isIntersecting&&E.current&&(m(!0),R.disconnect())},{threshold:h}),c=E.current;return c&&R.observe(c),()=>{R.disconnect()}},[h]);const f=P&&T?T:C;return Oe.jsx("img",{ref:E,src:f,alt:W,...j})});return re.displayName="LazyImage",re});