@j-ho/react-lazyload-image
Version:
React Image Lazy Load Component
666 lines (663 loc) • 22.7 kB
JavaScript
import Se, { memo as cr, useRef as fr, useState as dr, useEffect as vr } from "react";
var N = { exports: {} }, F = {};
/**
* @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 _e;
function gr() {
if (_e) return F;
_e = 1;
var w = Se, E = Symbol.for("react.element"), x = Symbol.for("react.fragment"), R = Object.prototype.hasOwnProperty, A = w.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, I = { key: !0, ref: !0, __self: !0, __source: !0 };
function _(m, c, y) {
var f, b = {}, C = null, M = null;
y !== void 0 && (C = "" + y), c.key !== void 0 && (C = "" + c.key), c.ref !== void 0 && (M = c.ref);
for (f in c) R.call(c, f) && !I.hasOwnProperty(f) && (b[f] = c[f]);
if (m && m.defaultProps) for (f in c = m.defaultProps, c) b[f] === void 0 && (b[f] = c[f]);
return { $$typeof: E, type: m, key: C, ref: M, props: b, _owner: A.current };
}
return F.Fragment = x, F.jsx = _, F.jsxs = _, F;
}
var W = {};
/**
* @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 Ce;
function pr() {
return Ce || (Ce = 1, process.env.NODE_ENV !== "production" && function() {
var w = Se, E = Symbol.for("react.element"), x = Symbol.for("react.portal"), R = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), I = Symbol.for("react.profiler"), _ = Symbol.for("react.provider"), m = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), b = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), M = Symbol.for("react.offscreen"), q = Symbol.iterator, we = "@@iterator";
function Ae(e) {
if (e === null || typeof e != "object")
return null;
var r = q && e[q] || e[we];
return typeof r == "function" ? r : null;
}
var T = w.__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];
Te("error", e, t);
}
}
function Te(e, r, t) {
{
var n = T.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 je = !1, Oe = !1, xe = !1, ke = !1, De = !1, X;
X = Symbol.for("react.module.reference");
function Fe(e) {
return !!(typeof e == "string" || typeof e == "function" || e === R || e === I || De || e === A || e === y || e === f || ke || e === M || je || Oe || xe || typeof e == "object" && e !== null && (e.$$typeof === C || e.$$typeof === b || e.$$typeof === _ || e.$$typeof === m || e.$$typeof === c || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === X || e.getModuleId !== void 0));
}
function We(e, r, t) {
var n = e.displayName;
if (n)
return n;
var o = r.displayName || r.name || "";
return o !== "" ? t + "(" + o + ")" : t;
}
function Q(e) {
return e.displayName || "Context";
}
function h(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 R:
return "Fragment";
case x:
return "Portal";
case I:
return "Profiler";
case A:
return "StrictMode";
case y:
return "Suspense";
case f:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case m:
var r = e;
return Q(r) + ".Consumer";
case _:
var t = e;
return Q(t._context) + ".Provider";
case c:
return We(e, e.render, "ForwardRef");
case b:
var n = e.displayName || null;
return n !== null ? n : h(e.type) || "Memo";
case C: {
var o = e, u = o._payload, i = o._init;
try {
return h(i(u));
} catch {
return null;
}
}
}
return null;
}
var P = Object.assign, k = 0, ee, re, te, ne, ae, ie, oe;
function ue() {
}
ue.__reactDisabledLog = !0;
function Me() {
{
if (k === 0) {
ee = console.log, re = console.info, te = console.warn, ne = console.error, ae = console.group, ie = console.groupCollapsed, oe = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: ue,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
k++;
}
}
function Ye() {
{
if (k--, k === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: P({}, e, {
value: ee
}),
info: P({}, e, {
value: re
}),
warn: P({}, e, {
value: te
}),
error: P({}, e, {
value: ne
}),
group: P({}, e, {
value: ae
}),
groupCollapsed: P({}, e, {
value: ie
}),
groupEnd: P({}, e, {
value: oe
})
});
}
k < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var $ = T.ReactCurrentDispatcher, G;
function Y(e, r, t) {
{
if (G === void 0)
try {
throw Error();
} catch (o) {
var n = o.stack.trim().match(/\n( *(at )?)/);
G = n && n[1] || "";
}
return `
` + G + e;
}
}
var z = !1, V;
{
var Ve = typeof WeakMap == "function" ? WeakMap : Map;
V = new Ve();
}
function se(e, r) {
if (!e || z)
return "";
{
var t = V.get(e);
if (t !== void 0)
return t;
}
var n;
z = !0;
var o = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var u;
u = $.current, $.current = null, Me();
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" && V.set(e, p), p;
}
while (s >= 1 && l >= 0);
break;
}
}
} finally {
z = !1, $.current = u, Ye(), Error.prepareStackTrace = o;
}
var O = e ? e.displayName || e.name : "", S = O ? Y(O) : "";
return typeof e == "function" && V.set(e, S), S;
}
function Ze(e, r, t) {
return se(e, !1);
}
function Le(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function Z(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return se(e, Le(e));
if (typeof e == "string")
return Y(e);
switch (e) {
case y:
return Y("Suspense");
case f:
return Y("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case c:
return Ze(e.render);
case b:
return Z(e.type, r, t);
case C: {
var n = e, o = n._payload, u = n._init;
try {
return Z(u(o), r, t);
} catch {
}
}
}
return "";
}
var D = Object.prototype.hasOwnProperty, le = {}, ce = T.ReactDebugCurrentFrame;
function L(e) {
if (e) {
var r = e._owner, t = Z(e.type, e._source, r ? r.type : null);
ce.setExtraStackFrame(t);
} else
ce.setExtraStackFrame(null);
}
function Ne(e, r, t, n, o) {
{
var u = Function.call.bind(D);
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) && (L(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), L(null)), a instanceof Error && !(a.message in le) && (le[a.message] = !0, L(o), d("Failed %s type: %s", t, a.message), L(null));
}
}
}
var $e = Array.isArray;
function U(e) {
return $e(e);
}
function Ge(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function ze(e) {
try {
return fe(e), !1;
} catch {
return !0;
}
}
function fe(e) {
return "" + e;
}
function de(e) {
if (ze(e))
return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ge(e)), fe(e);
}
var ve = T.ReactCurrentOwner, Ue = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, ge, pe;
function Je(e) {
if (D.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Be(e) {
if (D.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function He(e, r) {
typeof e.ref == "string" && ve.current;
}
function Ke(e, r) {
{
var t = function() {
ge || (ge = !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 qe(e, r) {
{
var t = function() {
pe || (pe = !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 Xe = function(e, r, t, n, o, u, i) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: E,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: i,
// Record the component responsible for creating this element.
_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 Qe(e, r, t, n, o) {
{
var u, i = {}, a = null, v = null;
t !== void 0 && (de(t), a = "" + t), Be(r) && (de(r.key), a = "" + r.key), Je(r) && (v = r.ref, He(r, o));
for (u in r)
D.call(r, u) && !Ue.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 && Ke(i, l), v && qe(i, l);
}
return Xe(e, a, v, o, n, ve.current, i);
}
}
var J = T.ReactCurrentOwner, be = T.ReactDebugCurrentFrame;
function j(e) {
if (e) {
var r = e._owner, t = Z(e.type, e._source, r ? r.type : null);
be.setExtraStackFrame(t);
} else
be.setExtraStackFrame(null);
}
var B;
B = !1;
function H(e) {
return typeof e == "object" && e !== null && e.$$typeof === E;
}
function me() {
{
if (J.current) {
var e = h(J.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function er(e) {
return "";
}
var ye = {};
function rr(e) {
{
var r = me();
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 Re(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = rr(r);
if (ye[t])
return;
ye[t] = !0;
var n = "";
e && e._owner && e._owner !== J.current && (n = " It was passed a child from " + h(e._owner.type) + "."), j(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), j(null);
}
}
function Ie(e, r) {
{
if (typeof e != "object")
return;
if (U(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
H(n) && Re(n, r);
}
else if (H(e))
e._store && (e._store.validated = !0);
else if (e) {
var o = Ae(e);
if (typeof o == "function" && o !== e.entries)
for (var u = o.call(e), i; !(i = u.next()).done; )
H(i.value) && Re(i.value, r);
}
}
}
function tr(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 === c || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === b))
t = r.propTypes;
else
return;
if (t) {
var n = h(r);
Ne(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !B) {
B = !0;
var o = h(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 nr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
j(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), j(null);
break;
}
}
e.ref !== null && (j(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), j(null));
}
}
var he = {};
function Ee(e, r, t, n, o, u) {
{
var i = Fe(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 = er();
v ? a += v : a += me();
var s;
e === null ? s = "null" : U(e) ? s = "array" : e !== void 0 && e.$$typeof === E ? (s = "<" + (h(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 = Qe(e, r, t, o, u);
if (l == null)
return l;
if (i) {
var p = r.children;
if (p !== void 0)
if (n)
if (U(p)) {
for (var O = 0; O < p.length; O++)
Ie(p[O], 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
Ie(p, e);
}
if (D.call(r, "key")) {
var S = h(e), g = Object.keys(r).filter(function(lr) {
return lr !== "key";
}), K = g.length > 0 ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!he[S + K]) {
var sr = 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} />`, K, S, sr, S), he[S + K] = !0;
}
}
return e === R ? nr(l) : tr(l), l;
}
}
function ar(e, r, t) {
return Ee(e, r, t, !0);
}
function ir(e, r, t) {
return Ee(e, r, t, !1);
}
var or = ir, ur = ar;
W.Fragment = R, W.jsx = or, W.jsxs = ur;
}()), W;
}
var Pe;
function br() {
return Pe || (Pe = 1, process.env.NODE_ENV === "production" ? N.exports = gr() : N.exports = pr()), N.exports;
}
var mr = br();
const yr = cr(
({
src: w,
placeholderSrc: E = "data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMzAwIDMwMCIgd2lkdGg9IjMwMCIgaGVpZ2h0PSIzMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImZsb3dpbmdHcmFkaWVudCIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjY2NjY2NjIiAvPgogICAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjY2NjY2NjIiAvPgogICAgICA8YW5pbWF0ZVRyYW5zZm9ybQogICAgICAgIGF0dHJpYnV0ZU5hbWU9ImdyYWRpZW50VHJhbnNmb3JtIgogICAgICAgIHR5cGU9InRyYW5zbGF0ZSIKICAgICAgICBmcm9tPSItMSwwIgogICAgICAgIHRvPSIxLDAiCiAgICAgICAgZHVyPSIxLjVzIgogICAgICAgIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIgogICAgICAvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICA8L2RlZnM+CiAgPHJlY3Qgd2lkdGg9IjMwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9InVybCgjZmxvd2luZ0dyYWRpZW50KSIgLz4KPC9zdmc+",
// Default placeholder
alt: x = "",
threshold: R = 0.1,
// Default threshold
...A
}) => {
const I = fr(null), [_, m] = dr(!1);
vr(() => {
if (!("IntersectionObserver" in window)) {
m(!0);
return;
}
const y = new IntersectionObserver(
([b]) => {
b.isIntersecting && I.current && (m(!0), y.disconnect());
},
{ threshold: R }
// Use the threshold from props
), f = I.current;
return f && y.observe(f), () => {
y.disconnect();
};
}, [R]);
const c = _ && w ? w : E;
return /* @__PURE__ */ mr.jsx("img", { ref: I, src: c, alt: x, ...A });
}
);
yr.displayName = "LazyImage";
export {
yr as default
};