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