@kanaksan/tamil-calendar-widget
Version:
A reusable React widget for displaying Tamil daily calendar sheets
33 lines (29 loc) • 18.2 kB
JavaScript
;var vr=Object.defineProperty;var hr=(u,i,o)=>i in u?vr(u,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):u[i]=o;var ve=(u,i,o)=>(hr(u,typeof i!="symbol"?i+"":i,o),o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react");var he={exports:{}},J={};/**
* @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 We;function pr(){if(We)return J;We=1;var u=A,i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),g=Object.prototype.hasOwnProperty,m=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function D(p,f,P){var y,C={},b=null,S=null;P!==void 0&&(b=""+P),f.key!==void 0&&(b=""+f.key),f.ref!==void 0&&(S=f.ref);for(y in f)g.call(f,y)&&!j.hasOwnProperty(y)&&(C[y]=f[y]);if(p&&p.defaultProps)for(y in f=p.defaultProps,f)C[y]===void 0&&(C[y]=f[y]);return{$$typeof:i,type:p,key:b,ref:S,props:C,_owner:m.current}}return J.Fragment=o,J.jsx=D,J.jsxs=D,J}var G={};/**
* @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 Ye;function gr(){return Ye||(Ye=1,process.env.NODE_ENV!=="production"&&function(){var u=A,i=Symbol.for("react.element"),o=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),D=Symbol.for("react.provider"),p=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),y=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),S=Symbol.for("react.offscreen"),H=Symbol.iterator,N="@@iterator";function z(e){if(e===null||typeof e!="object")return null;var r=H&&e[H]||e[N];return typeof r=="function"?r:null}var E=u.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),a=1;a<r;a++)t[a-1]=arguments[a];M("error",e,t)}}function M(e,r,t){{var a=E.ReactDebugCurrentFrame,l=a.getStackAddendum();l!==""&&(r+="%s",t=t.concat([l]));var c=t.map(function(s){return String(s)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var ae=!1,x=!1,L=!1,F=!1,U=!1,k;k=Symbol.for("react.module.reference");function X(e){return!!(typeof e=="string"||typeof e=="function"||e===g||e===j||U||e===m||e===P||e===y||F||e===S||ae||x||L||typeof e=="object"&&e!==null&&(e.$$typeof===b||e.$$typeof===C||e.$$typeof===D||e.$$typeof===p||e.$$typeof===f||e.$$typeof===k||e.getModuleId!==void 0))}function Z(e,r,t){var a=e.displayName;if(a)return a;var l=r.displayName||r.name||"";return l!==""?t+"("+l+")":t}function V(e){return e.displayName||"Context"}function w(e){if(e==null)return null;if(typeof e.tag=="number"&&h("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 g:return"Fragment";case o:return"Portal";case j:return"Profiler";case m:return"StrictMode";case P:return"Suspense";case y:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case p:var r=e;return V(r)+".Consumer";case D:var t=e;return V(t._context)+".Provider";case f:return Z(e,e.render,"ForwardRef");case C:var a=e.displayName||null;return a!==null?a:w(e.type)||"Memo";case b:{var l=e,c=l._payload,s=l._init;try{return w(s(c))}catch{return null}}}return null}var I=Object.assign,q=0,ge,me,ye,be,Re,Ee,_e;function Te(){}Te.__reactDisabledLog=!0;function Ne(){{if(q===0){ge=console.log,me=console.info,ye=console.warn,be=console.error,Re=console.group,Ee=console.groupCollapsed,_e=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Te,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}q++}}function Me(){{if(q--,q===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:I({},e,{value:ge}),info:I({},e,{value:me}),warn:I({},e,{value:ye}),error:I({},e,{value:be}),group:I({},e,{value:Re}),groupCollapsed:I({},e,{value:Ee}),groupEnd:I({},e,{value:_e})})}q<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ne=E.ReactCurrentDispatcher,ie;function Q(e,r,t){{if(ie===void 0)try{throw Error()}catch(l){var a=l.stack.trim().match(/\n( *(at )?)/);ie=a&&a[1]||""}return`
`+ie+e}}var se=!1,ee;{var Le=typeof WeakMap=="function"?WeakMap:Map;ee=new Le}function Ce(e,r){if(!e||se)return"";{var t=ee.get(e);if(t!==void 0)return t}var a;se=!0;var l=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=ne.current,ne.current=null,Ne();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(_){a=_}Reflect.construct(e,[],s)}else{try{s.call()}catch(_){a=_}e.call(s.prototype)}}else{try{throw Error()}catch(_){a=_}e()}}catch(_){if(_&&a&&typeof _.stack=="string"){for(var n=_.stack.split(`
`),R=a.stack.split(`
`),d=n.length-1,v=R.length-1;d>=1&&v>=0&&n[d]!==R[v];)v--;for(;d>=1&&v>=0;d--,v--)if(n[d]!==R[v]){if(d!==1||v!==1)do if(d--,v--,v<0||n[d]!==R[v]){var T=`
`+n[d].replace(" at new "," at ");return e.displayName&&T.includes("<anonymous>")&&(T=T.replace("<anonymous>",e.displayName)),typeof e=="function"&&ee.set(e,T),T}while(d>=1&&v>=0);break}}}finally{se=!1,ne.current=c,Me(),Error.prepareStackTrace=l}var Y=e?e.displayName||e.name:"",$=Y?Q(Y):"";return typeof e=="function"&&ee.set(e,$),$}function Ve(e,r,t){return Ce(e,!1)}function qe(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function re(e,r,t){if(e==null)return"";if(typeof e=="function")return Ce(e,qe(e));if(typeof e=="string")return Q(e);switch(e){case P:return Q("Suspense");case y:return Q("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ve(e.render);case C:return re(e.type,r,t);case b:{var a=e,l=a._payload,c=a._init;try{return re(c(l),r,t)}catch{}}}return""}var K=Object.prototype.hasOwnProperty,we={},Oe=E.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=re(e.type,e._source,r?r.type:null);Oe.setExtraStackFrame(t)}else Oe.setExtraStackFrame(null)}function Ke(e,r,t,a,l){{var c=Function.call.bind(K);for(var s in e)if(c(e,s)){var n=void 0;try{if(typeof e[s]!="function"){var R=Error((a||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw R.name="Invariant Violation",R}n=e[s](r,s,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(d){n=d}n&&!(n instanceof Error)&&(te(l),h("%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).",a||"React class",t,s,typeof n),te(null)),n instanceof Error&&!(n.message in we)&&(we[n.message]=!0,te(l),h("Failed %s type: %s",t,n.message),te(null))}}}var Be=Array.isArray;function oe(e){return Be(e)}function Je(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ge(e){try{return je(e),!1}catch{return!0}}function je(e){return""+e}function Pe(e){if(Ge(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Je(e)),je(e)}var B=E.ReactCurrentOwner,He={key:!0,ref:!0,__self:!0,__source:!0},Se,xe,le;le={};function ze(e){if(K.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Xe(e){if(K.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Ze(e,r){if(typeof e.ref=="string"&&B.current&&r&&B.current.stateNode!==r){var t=w(B.current.type);le[t]||(h('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',w(B.current.type),e.ref),le[t]=!0)}}function Qe(e,r){{var t=function(){Se||(Se=!0,h("%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 er(e,r){{var t=function(){xe||(xe=!0,h("%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 rr=function(e,r,t,a,l,c,s){var n={$$typeof:i,type:e,key:r,ref:t,props:s,_owner:c};return n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(n,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(n,"_source",{configurable:!1,enumerable:!1,writable:!1,value:l}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n};function tr(e,r,t,a,l){{var c,s={},n=null,R=null;t!==void 0&&(Pe(t),n=""+t),Xe(r)&&(Pe(r.key),n=""+r.key),ze(r)&&(R=r.ref,Ze(r,l));for(c in r)K.call(r,c)&&!He.hasOwnProperty(c)&&(s[c]=r[c]);if(e&&e.defaultProps){var d=e.defaultProps;for(c in d)s[c]===void 0&&(s[c]=d[c])}if(n||R){var v=typeof e=="function"?e.displayName||e.name||"Unknown":e;n&&Qe(s,v),R&&er(s,v)}return rr(e,n,R,l,a,B.current,s)}}var ce=E.ReactCurrentOwner,ke=E.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=re(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(t)}else ke.setExtraStackFrame(null)}var ue;ue=!1;function fe(e){return typeof e=="object"&&e!==null&&e.$$typeof===i}function Ae(){{if(ce.current){var e=w(ce.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function ar(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var De={};function nr(e){{var r=Ae();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 Ie(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=nr(r);if(De[t])return;De[t]=!0;var a="";e&&e._owner&&e._owner!==ce.current&&(a=" It was passed a child from "+w(e._owner.type)+"."),W(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,a),W(null)}}function $e(e,r){{if(typeof e!="object")return;if(oe(e))for(var t=0;t<e.length;t++){var a=e[t];fe(a)&&Ie(a,r)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var l=z(e);if(typeof l=="function"&&l!==e.entries)for(var c=l.call(e),s;!(s=c.next()).done;)fe(s.value)&&Ie(s.value,r)}}}function ir(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===C))t=r.propTypes;else return;if(t){var a=w(r);Ke(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!ue){ue=!0;var l=w(r);h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",l||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&h("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 a=r[t];if(a!=="children"&&a!=="key"){W(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),W(null);break}}e.ref!==null&&(W(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var Fe={};function Ue(e,r,t,a,l,c){{var s=X(e);if(!s){var n="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(n+=" 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 R=ar(l);R?n+=R:n+=Ae();var d;e===null?d="null":oe(e)?d="array":e!==void 0&&e.$$typeof===i?(d="<"+(w(e.type)||"Unknown")+" />",n=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",d,n)}var v=tr(e,r,t,l,c);if(v==null)return v;if(s){var T=r.children;if(T!==void 0)if(a)if(oe(T)){for(var Y=0;Y<T.length;Y++)$e(T[Y],e);Object.freeze&&Object.freeze(T)}else h("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 $e(T,e)}if(K.call(r,"key")){var $=w(e),_=Object.keys(r).filter(function(dr){return dr!=="key"}),de=_.length>0?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}";if(!Fe[$+de]){var fr=_.length>0?"{"+_.join(": ..., ")+": ...}":"{}";h(`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} />`,de,$,fr,$),Fe[$+de]=!0}}return e===g?sr(v):ir(v),v}}function or(e,r,t){return Ue(e,r,t,!0)}function lr(e,r,t){return Ue(e,r,t,!1)}var cr=lr,ur=or;G.Fragment=g,G.jsx=cr,G.jsxs=ur}()),G}process.env.NODE_ENV==="production"?he.exports=pr():he.exports=gr();var O=he.exports;class mr{constructor(){ve(this,"cache",{});ve(this,"CACHE_DURATION",24*60*60*1e3)}getCacheKey(i,o){return`${i}_${o}`}getCachedImage(i,o){const g=this.getCacheKey(i,o),m=this.cache[g];return m?Date.now()>m.expiresAt?(this.removeCachedImage(i,o),null):m.url:null}setCachedImage(i,o,g){const m=this.getCacheKey(i,o);this.cache[m]={url:g,timestamp:Date.now(),expiresAt:Date.now()+this.CACHE_DURATION}}removeCachedImage(i,o){const g=this.getCacheKey(i,o),m=this.cache[g];m&&(URL.revokeObjectURL(m.url),delete this.cache[g])}clearCache(){Object.values(this.cache).forEach(i=>{URL.revokeObjectURL(i.url)}),this.cache={}}cleanupExpired(){const i=Date.now();Object.keys(this.cache).forEach(o=>{this.cache[o].expiresAt<i&&(URL.revokeObjectURL(this.cache[o].url),delete this.cache[o])})}}const pe=new mr,yr=u=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(u))return!1;const o=new Date(u);return o instanceof Date&&!isNaN(o.getTime())},br=(u,i)=>{const o=u.replace(/\/$/,"");return o.includes("/daily-sheet")?`${o}/${i}`:`${o}/api/calendar/daily-sheet/${i}`},Rr=u=>{if(u.name==="TypeError"&&u.message.includes("fetch"))return"Network error: Unable to connect to the calendar service. Please check your internet connection.";if(u.status)switch(u.status){case 401:return"Authentication failed: Invalid API key or token. Please contact support for a valid API URL.";case 403:return"Access denied: Your API key does not have permission to access this resource.";case 404:return"Calendar not found: No calendar available for the selected date.";case 429:return"Rate limit exceeded: Too many requests. Please try again later.";case 500:return"Server error: The calendar service is temporarily unavailable. Please try again later.";default:return`Error ${u.status}: Unable to load calendar. Please try again.`}return"Unable to load Tamil calendar. Please check your API URL and try again."};const Er=({apiUrl:u,date:i,width:o=400,height:g,alt:m="Tamil Daily Calendar",className:j="",style:D={},onLoad:p,onError:f,showLoader:P=!0,loaderComponent:y,errorComponent:C})=>{const[b,S]=A.useState(null),[H,N]=A.useState(!1),[z,E]=A.useState(null),h=A.useCallback(async(x,L)=>{try{N(!0),E(null);const F=pe.getCachedImage(x,L);if(F){S(F),N(!1),p==null||p();return}const U=br(x,L),k=await fetch(U,{method:"GET",headers:{Accept:"image/jpeg, image/png, image/*"}});if(!k.ok){const V=new Error(`HTTP ${k.status}: ${k.statusText}`);throw V.status=k.status,V}const X=await k.blob();if(!X.type.startsWith("image/"))throw new Error("Invalid response: Expected image data");const Z=URL.createObjectURL(X);pe.setCachedImage(x,L,Z),S(Z),p==null||p()}catch(F){const U=Rr(F);E(U),f==null||f(new Error(U))}finally{N(!1)}},[p,f]);A.useEffect(()=>{if(!u){E("API URL is required");return}if(!i){E("Date is required");return}if(!yr(i)){E("Invalid date format. Please use YYYY-MM-DD format");return}return S(null),E(null),h(u,i),()=>{b&&URL.revokeObjectURL(b)}},[u,i,h]),A.useEffect(()=>()=>{b&&URL.revokeObjectURL(b)},[b]);const M={width:o,height:g||"auto",...D},ae={width:"100%",height:g?"100%":"auto",objectFit:g?"contain":"initial",display:"block"};return H&&P?O.jsx("div",{className:`tamil-calendar-widget tamil-calendar-loading ${j}`,style:M,children:y||O.jsxs("div",{className:"tamil-calendar-loader",children:[O.jsx("div",{className:"tamil-calendar-spinner"}),O.jsx("p",{children:"Loading Tamil Calendar..."})]})}):z?O.jsx("div",{className:`tamil-calendar-widget tamil-calendar-error ${j}`,style:M,children:C||O.jsxs("div",{className:"tamil-calendar-error-content",children:[O.jsx("div",{className:"tamil-calendar-error-icon",children:"⚠️"}),O.jsx("p",{className:"tamil-calendar-error-message",children:z})]})}):b?O.jsx("div",{className:`tamil-calendar-widget ${j}`,style:M,children:O.jsx("img",{src:b,alt:m,style:ae,onLoad:()=>p==null?void 0:p(),onError:()=>{const x="Failed to display calendar image";E(x),f==null||f(new Error(x))}})}):null};exports.TamilCalendarWidget=Er;exports.imageCache=pe;