react-balochi-input
Version:
Seamless Balochi typing in React, no system adjustments needed.
28 lines (24 loc) • 15.2 kB
JavaScript
(function(g,P){typeof exports=="object"&&typeof module<"u"?module.exports=P(require("react")):typeof define=="function"&&define.amd?define(["react"],P):(g=typeof globalThis<"u"?globalThis:g||self,g["Balochi Input React"]=P(g.React))})(this,function(g){"use strict";var P={exports:{}},L={};/**
* @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 te;function Pe(){if(te)return L;te=1;var Y=g,w=Symbol.for("react.element"),V=Symbol.for("react.fragment"),C=Object.prototype.hasOwnProperty,x=Y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,F={key:!0,ref:!0,__self:!0,__source:!0};function j(b,d,O){var v,E={},R=null,A=null;O!==void 0&&(R=""+O),d.key!==void 0&&(R=""+d.key),d.ref!==void 0&&(A=d.ref);for(v in d)C.call(d,v)&&!F.hasOwnProperty(v)&&(E[v]=d[v]);if(b&&b.defaultProps)for(v in d=b.defaultProps,d)E[v]===void 0&&(E[v]=d[v]);return{$$typeof:w,type:b,key:R,ref:A,props:E,_owner:x.current}}return L.Fragment=V,L.jsx=j,L.jsxs=j,L}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 ne;function xe(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var Y=g,w=Symbol.for("react.element"),V=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),j=Symbol.for("react.provider"),b=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),A=Symbol.for("react.offscreen"),m=Symbol.iterator,_="@@iterator";function p(e){if(e===null||typeof e!="object")return null;var r=m&&e[m]||e[_];return typeof r=="function"?r:null}var c=Y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function s(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];k("error",e,t)}}function k(e,r,t){{var n=c.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,De=!1,Fe=!1,Ae=!1,Ie=!1,ae;ae=Symbol.for("react.module.reference");function Me(e){return!!(typeof e=="string"||typeof e=="function"||e===C||e===F||Ie||e===x||e===O||e===v||Ae||e===A||ke||De||Fe||typeof e=="object"&&e!==null&&(e.$$typeof===R||e.$$typeof===E||e.$$typeof===j||e.$$typeof===b||e.$$typeof===d||e.$$typeof===ae||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 ie(e){return e.displayName||"Context"}function T(e){if(e==null)return null;if(typeof e.tag=="number"&&s("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 C:return"Fragment";case V:return"Portal";case F:return"Profiler";case x:return"StrictMode";case O:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case b:var r=e;return ie(r)+".Consumer";case j:var t=e;return ie(t._context)+".Provider";case d:return Le(e,e.render,"ForwardRef");case E:var n=e.displayName||null;return n!==null?n:T(e.type)||"Memo";case R:{var o=e,u=o._payload,i=o._init;try{return T(i(u))}catch{return null}}}return null}var D=Object.assign,N=0,oe,ue,se,fe,le,ce,de;function ve(){}ve.__reactDisabledLog=!0;function We(){{if(N===0){oe=console.log,ue=console.info,se=console.warn,fe=console.error,le=console.group,ce=console.groupCollapsed,de=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}}function Ye(){{if(N--,N===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:oe}),info:D({},e,{value:ue}),warn:D({},e,{value:se}),error:D({},e,{value:fe}),group:D({},e,{value:le}),groupCollapsed:D({},e,{value:ce}),groupEnd:D({},e,{value:de})})}N<0&&s("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var z=c.ReactCurrentDispatcher,q;function B(e,r,t){{if(q===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);q=n&&n[1]||""}return`
`+q+e}}var H=!1,$;{var Ve=typeof WeakMap=="function"?WeakMap:Map;$=new Ve}function pe(e,r){if(!e||H)return"";{var t=$.get(e);if(t!==void 0)return t}var n;H=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=z.current,z.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(S){n=S}Reflect.construct(e,[],i)}else{try{i.call()}catch(S){n=S}e.call(i.prototype)}}else{try{throw Error()}catch(S){n=S}e()}}catch(S){if(S&&n&&typeof S.stack=="string"){for(var a=S.stack.split(`
`),h=n.stack.split(`
`),f=a.length-1,l=h.length-1;f>=1&&l>=0&&a[f]!==h[l];)l--;for(;f>=1&&l>=0;f--,l--)if(a[f]!==h[l]){if(f!==1||l!==1)do if(f--,l--,l<0||a[f]!==h[l]){var y=`
`+a[f].replace(" at new "," at ");return e.displayName&&y.includes("<anonymous>")&&(y=y.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,y),y}while(f>=1&&l>=0);break}}}finally{H=!1,z.current=u,Ye(),Error.prepareStackTrace=o}var M=e?e.displayName||e.name:"",Oe=M?B(M):"";return typeof e=="function"&&$.set(e,Oe),Oe}function Ne(e,r,t){return pe(e,!1)}function Ue(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function J(e,r,t){if(e==null)return"";if(typeof e=="function")return pe(e,Ue(e));if(typeof e=="string")return B(e);switch(e){case O:return B("Suspense");case v:return B("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return Ne(e.render);case E:return J(e.type,r,t);case R:{var n=e,o=n._payload,u=n._init;try{return J(u(o),r,t)}catch{}}}return""}var K=Object.prototype.hasOwnProperty,he={},ye=c.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);ye.setExtraStackFrame(t)}else ye.setExtraStackFrame(null)}function Be(e,r,t,n,o){{var u=Function.call.bind(K);for(var i in e)if(u(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var h=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 h.name="Invariant Violation",h}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(f){a=f}a&&!(a instanceof Error)&&(G(o),s("%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 he)&&(he[a.message]=!0,G(o),s("Failed %s type: %s",t,a.message),G(null))}}}var $e=Array.isArray;function X(e){return $e(e)}function Je(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ke(e){try{return ge(e),!1}catch{return!0}}function ge(e){return""+e}function Ee(e){if(Ke(e))return s("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Je(e)),ge(e)}var U=c.ReactCurrentOwner,Ge={key:!0,ref:!0,__self:!0,__source:!0},be,me,Z;Z={};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 qe(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 He(e,r){if(typeof e.ref=="string"&&U.current&&r&&U.current.stateNode!==r){var t=T(U.current.type);Z[t]||(s('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',T(U.current.type),e.ref),Z[t]=!0)}}function Xe(e,r){{var t=function(){be||(be=!0,s("%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,s("%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:w,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,h=null;t!==void 0&&(Ee(t),a=""+t),qe(r)&&(Ee(r.key),a=""+r.key),ze(r)&&(h=r.ref,He(r,o));for(u in r)K.call(r,u)&&!Ge.hasOwnProperty(u)&&(i[u]=r[u]);if(e&&e.defaultProps){var f=e.defaultProps;for(u in f)i[u]===void 0&&(i[u]=f[u])}if(a||h){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&Xe(i,l),h&&Ze(i,l)}return Qe(e,a,h,o,n,U.current,i)}}var Q=c.ReactCurrentOwner,Re=c.ReactDebugCurrentFrame;function I(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);Re.setExtraStackFrame(t)}else Re.setExtraStackFrame(null)}var ee;ee=!1;function re(e){return typeof e=="object"&&e!==null&&e.$$typeof===w}function _e(){{if(Q.current){var e=T(Q.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function rr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var Te={};function tr(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 Se(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=tr(r);if(Te[t])return;Te[t]=!0;var n="";e&&e._owner&&e._owner!==Q.current&&(n=" It was passed a child from "+T(e._owner.type)+"."),I(e),s('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 we(e,r){{if(typeof e!="object")return;if(X(e))for(var t=0;t<e.length;t++){var n=e[t];re(n)&&Se(n,r)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var o=p(e);if(typeof o=="function"&&o!==e.entries)for(var u=o.call(e),i;!(i=u.next()).done;)re(i.value)&&Se(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===d||r.$$typeof===E))t=r.propTypes;else return;if(t){var n=T(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ee){ee=!0;var o=T(r);s("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&s("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),s("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),s("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}function Ce(e,r,t,n,o,u){{var i=Me(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 h=rr(o);h?a+=h:a+=_e();var f;e===null?f="null":X(e)?f="array":e!==void 0&&e.$$typeof===w?(f="<"+(T(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):f=typeof e,s("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",f,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 M=0;M<y.length;M++)we(y[M],e);Object.freeze&&Object.freeze(y)}else s("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 we(y,e)}return e===C?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;W.Fragment=C,W.jsx=ur,W.jsxs=sr}()),W}process.env.NODE_ENV==="production"?P.exports=Pe():P.exports=xe();var je=P.exports;return({className:Y,onChange:w,value:V,placeholder:C,allowSwitching:x=!1,...F})=>{const[j,b]=g.useState(!1),[d,O]=g.useState(!1),v=m=>{const _={q:"ق",w:"و",e:"ع",r:"ر",t:"ت",y:"ے",u:"ء",i:"ی",o:"ہ",p:"پ",a:"ا",s:"س",d:"د",f:"ف",g:"گ",h:"ھ",j:"ج",k:"ک",l:"ل",z:"ز",x:"ش",c:"چ",v:"ط",b:"ب",n:"ن",m:"م",Q:"ءُ",W:"ؤ",E:"ءِ",R:"ڑ",T:"ٹ",Y:"ئے",U:"ٰ",I:"ئ",O:"ْ",P:"ُ",A:"آ",S:"ص",D:"ڈ",F:"ءَ",G:"غ",H:"ح",J:"ض",K:"خ",L:"ئِے",Z:"ذ",X:"ژ",C:"ث",V:"ظ",B:"یٔ",N:"ں",M:"اَنت","`":"ً",";":"؛","'":"ۂ",",":"،",".":"۔","/":"ْ"},p={",":"ِ","<":"ِ",".":"َ",">":"َ","/":"؟","?":"؟",";":":",":":":","'":"‘",'"':"‘",0:"ّ",")":"ّ"};let c="";for(let s=0;s<m.length;s++){const k=m[s];j&&p[k]?c+=p[k]:_[k]?c+=_[k]:c+=k}return c},[E,R]=g.useState(v(V||""));g.useEffect(()=>{const m=p=>{(p.key==="Shift"||p.getModifierState&&p.getModifierState("CapsLock"))&&b(!0),p.ctrlKey&&p.keyCode===32&&x&&O(c=>!c)},_=p=>{(p.key==="Shift"||p.getModifierState&&p.getModifierState("CapsLock"))&&b(!1)};return window.addEventListener("keydown",m),window.addEventListener("keyup",_),()=>{window.removeEventListener("keydown",m),window.removeEventListener("keyup",_)}},[x]);const A=m=>{const{nativeEvent:_,target:p}=m,{value:c}=p;let s;_.inputType==="insertText"&&!d?s=c.slice(0,-1)+v(c.charAt(c.length-1)):s=c,R(s),w&&w(s)};return je.jsx("input",{dir:"rtl",type:"text",className:Y,value:E,onChange:A,placeholder:C,...F})}});