UNPKG

simple-image-magnifier

Version:

Image Magnifier JavaScript (Typescript) | Image Zoom on Hover using | Image Hover Effect

722 lines (719 loc) 23.4 kB
import ke, { useState as pr, useRef as J, useCallback as re, useEffect as te } from "react"; import gr from "./simple-image-magnifier.js"; var q = { exports: {} }, W = {}; /** * @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 xe; function mr() { if (xe) return W; xe = 1; var j = ke, b = Symbol.for("react.element"), _ = Symbol.for("react.fragment"), E = Object.prototype.hasOwnProperty, w = j.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, k = { key: !0, ref: !0, __self: !0, __source: !0 }; function T(h, f, R) { var c, g = {}, y = null, O = null; R !== void 0 && (y = "" + R), f.key !== void 0 && (y = "" + f.key), f.ref !== void 0 && (O = f.ref); for (c in f) E.call(f, c) && !k.hasOwnProperty(c) && (g[c] = f[c]); if (h && h.defaultProps) for (c in f = h.defaultProps, f) g[c] === void 0 && (g[c] = f[c]); return { $$typeof: b, type: h, key: y, ref: O, props: g, _owner: w.current }; } return W.Fragment = _, W.jsx = T, W.jsxs = T, W; } var Y = {}; /** * @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 je; function yr() { return je || (je = 1, process.env.NODE_ENV !== "production" && function() { var j = ke, b = Symbol.for("react.element"), _ = Symbol.for("react.portal"), E = Symbol.for("react.fragment"), w = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), T = Symbol.for("react.provider"), h = Symbol.for("react.context"), f = Symbol.for("react.forward_ref"), R = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), g = Symbol.for("react.memo"), y = Symbol.for("react.lazy"), O = Symbol.for("react.offscreen"), A = Symbol.iterator, S = "@@iterator"; function Fe(e) { if (e === null || typeof e != "object") return null; var r = A && e[A] || e[S]; return typeof r == "function" ? r : null; } var F = j.__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 = F.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 Ie = !1, Ae = !1, $e = !1, Le = !1, We = !1, ne; ne = Symbol.for("react.module.reference"); function Ye(e) { return !!(typeof e == "string" || typeof e == "function" || e === E || e === k || We || e === w || e === R || e === c || Le || e === O || Ie || Ae || $e || typeof e == "object" && e !== null && (e.$$typeof === y || e.$$typeof === g || e.$$typeof === T || e.$$typeof === h || e.$$typeof === f || // 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 === ne || e.getModuleId !== void 0)); } function Me(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 C(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 E: return "Fragment"; case _: return "Portal"; case k: return "Profiler"; case w: return "StrictMode"; case R: return "Suspense"; case c: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case h: var r = e; return ae(r) + ".Consumer"; case T: var t = e; return ae(t._context) + ".Provider"; case f: return Me(e, e.render, "ForwardRef"); case g: var n = e.displayName || null; return n !== null ? n : C(e.type) || "Memo"; case y: { var o = e, u = o._payload, i = o._init; try { return C(i(u)); } catch { return null; } } } return null; } var P = Object.assign, $ = 0, ie, oe, ue, se, le, fe, ce; function de() { } de.__reactDisabledLog = !0; function Ve() { { if ($ === 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 }); } $++; } } function Ue() { { if ($--, $ === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: P({}, e, { value: ie }), info: P({}, e, { value: oe }), warn: P({}, e, { value: ue }), error: P({}, e, { value: se }), group: P({}, e, { value: le }), groupCollapsed: P({}, e, { value: fe }), groupEnd: P({}, e, { value: ce }) }); } $ < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var K = F.ReactCurrentDispatcher, z; function M(e, r, t) { { if (z === void 0) try { throw Error(); } catch (o) { var n = o.stack.trim().match(/\n( *(at )?)/); z = n && n[1] || ""; } return ` ` + z + e; } } var G = !1, V; { var Ne = typeof WeakMap == "function" ? WeakMap : Map; V = new Ne(); } function ve(e, r) { if (!e || G) return ""; { var t = V.get(e); if (t !== void 0) return t; } var n; G = !0; var o = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var u; u = K.current, K.current = null, Ve(); 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 (p) { n = p; } Reflect.construct(e, [], i); } else { try { i.call(); } catch (p) { n = p; } e.call(i.prototype); } } else { try { throw Error(); } catch (p) { n = p; } e(); } } catch (p) { if (p && n && typeof p.stack == "string") { for (var a = p.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 m = ` ` + a[s].replace(" at new ", " at "); return e.displayName && m.includes("<anonymous>") && (m = m.replace("<anonymous>", e.displayName)), typeof e == "function" && V.set(e, m), m; } while (s >= 1 && l >= 0); break; } } } finally { G = !1, K.current = u, Ue(), Error.prepareStackTrace = o; } var I = e ? e.displayName || e.name : "", x = I ? M(I) : ""; return typeof e == "function" && V.set(e, x), x; } function Je(e, r, t) { return ve(e, !1); } function qe(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function U(e, r, t) { if (e == null) return ""; if (typeof e == "function") return ve(e, qe(e)); if (typeof e == "string") return M(e); switch (e) { case R: return M("Suspense"); case c: return M("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case f: return Je(e.render); case g: return U(e.type, r, t); case y: { var n = e, o = n._payload, u = n._init; try { return U(u(o), r, t); } catch { } } } return ""; } var L = Object.prototype.hasOwnProperty, pe = {}, ge = F.ReactDebugCurrentFrame; function N(e) { if (e) { var r = e._owner, t = U(e.type, e._source, r ? r.type : null); ge.setExtraStackFrame(t); } else ge.setExtraStackFrame(null); } function Be(e, r, t, n, o) { { var u = Function.call.bind(L); 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) && (N(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), N(null)), a instanceof Error && !(a.message in pe) && (pe[a.message] = !0, N(o), d("Failed %s type: %s", t, a.message), N(null)); } } } var Ke = Array.isArray; function X(e) { return Ke(e); } function ze(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Ge(e) { try { return me(e), !1; } catch { return !0; } } function me(e) { return "" + e; } function ye(e) { if (Ge(e)) return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), me(e); } var be = F.ReactCurrentOwner, Xe = { key: !0, ref: !0, __self: !0, __source: !0 }, Ee, he; function He(e) { if (L.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function Ze(e) { if (L.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function Qe(e, r) { typeof e.ref == "string" && be.current; } function er(e, r) { { var t = function() { Ee || (Ee = !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 rr(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 tr = function(e, r, t, n, o, u, i) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: b, // 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 nr(e, r, t, n, o) { { var u, i = {}, a = null, v = null; t !== void 0 && (ye(t), a = "" + t), Ze(r) && (ye(r.key), a = "" + r.key), He(r) && (v = r.ref, Qe(r, o)); for (u in r) L.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 && er(i, l), v && rr(i, l); } return tr(e, a, v, o, n, be.current, i); } } var H = F.ReactCurrentOwner, Re = F.ReactDebugCurrentFrame; function D(e) { if (e) { var r = e._owner, t = U(e.type, e._source, r ? r.type : null); Re.setExtraStackFrame(t); } else Re.setExtraStackFrame(null); } var Z; Z = !1; function Q(e) { return typeof e == "object" && e !== null && e.$$typeof === b; } function _e() { { if (H.current) { var e = C(H.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function ar(e) { return ""; } var Te = {}; function ir(e) { { var r = _e(); 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 Oe(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = ir(r); if (Te[t]) return; Te[t] = !0; var n = ""; e && e._owner && e._owner !== H.current && (n = " It was passed a child from " + C(e._owner.type) + "."), D(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), D(null); } } function Se(e, r) { { if (typeof e != "object") return; if (X(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; Q(n) && Oe(n, r); } else if (Q(e)) e._store && (e._store.validated = !0); else if (e) { var o = Fe(e); if (typeof o == "function" && o !== e.entries) for (var u = o.call(e), i; !(i = u.next()).done; ) Q(i.value) && Oe(i.value, r); } } } function or(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 || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === g)) t = r.propTypes; else return; if (t) { var n = C(r); Be(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !Z) { Z = !0; var o = C(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 ur(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { D(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), D(null); break; } } e.ref !== null && (D(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), D(null)); } } var Ce = {}; function Pe(e, r, t, n, o, u) { { var i = Ye(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 = ar(); v ? a += v : a += _e(); var s; e === null ? s = "null" : X(e) ? s = "array" : e !== void 0 && e.$$typeof === b ? (s = "<" + (C(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 = nr(e, r, t, o, u); if (l == null) return l; if (i) { var m = r.children; if (m !== void 0) if (n) if (X(m)) { for (var I = 0; I < m.length; I++) Se(m[I], e); Object.freeze && Object.freeze(m); } 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 Se(m, e); } if (L.call(r, "key")) { var x = C(e), p = Object.keys(r).filter(function(vr) { return vr !== "key"; }), ee = p.length > 0 ? "{key: someKey, " + p.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!Ce[x + ee]) { var dr = p.length > 0 ? "{" + p.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} />`, ee, x, dr, x), Ce[x + ee] = !0; } } return e === E ? ur(l) : or(l), l; } } function sr(e, r, t) { return Pe(e, r, t, !0); } function lr(e, r, t) { return Pe(e, r, t, !1); } var fr = lr, cr = sr; Y.Fragment = E, Y.jsx = fr, Y.jsxs = cr; }()), Y; } var we; function br() { return we || (we = 1, process.env.NODE_ENV === "production" ? q.exports = mr() : q.exports = yr()), q.exports; } var B = br(); const Rr = ({ srcPreview: j, srcOriginal: b, width: _ = 400, height: E = 600, className: w = "", objectFit: k = "cover" }) => { const [T, h] = pr(!1), f = J(null), R = J(null), c = J(null), g = J(() => { }), y = re(() => { h(!0); }, []), O = re(() => { h(!1), console.error("Failed to load original image:", b); }, [b]), A = re(() => { f.current && R.current && c.current && T && (g.current = gr( f.current, R.current, c.current )); }, [T]); return te(() => { A(); }, [A]), te(() => { const S = c.current; return S && (S.addEventListener("load", y), S.addEventListener("error", O)), () => { S && (S.removeEventListener("load", y), S.removeEventListener("error", O)); }; }, [y, O]), te(() => { g.current(); }, [b, j, _, E]), /* @__PURE__ */ B.jsxs( "div", { ref: f, className: w, style: { position: "relative", overflow: "hidden", width: typeof _ == "number" ? _ + "px" : _ ?? "100%", height: typeof E == "number" ? E + "px" : _ ?? "100%" }, children: [ /* @__PURE__ */ B.jsx( "img", { ref: R, src: j, alt: "Preview", style: { position: "relative", zIndex: "1", objectFit: k ?? "cover", width: "100%", height: "100%", transitionProperty: "opacity", transitionTimingFunction: "cubic-bezier(0.4, 0, 0.2, 1)", transitionDuration: "300ms" } } ), /* @__PURE__ */ B.jsx( "img", { ref: c, src: b, alt: "Original", style: { position: "absolute", maxWidth: "none", opacity: 0 } } ), !T && /* @__PURE__ */ B.jsx( "div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", color: "#fff", backgroundColor: "rgba(107 114 128 / 0.5)" }, children: "⏱" } ) ] } ); }; export { Rr as default };