@uziee/document-scanner 1.1.5 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +606 -444
- package/dist/index.umd.js +11 -11
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(V,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],D):(V=typeof globalThis<"u"?globalThis:V||self,D(V.DocumentScanner={},V.React))})(this,function(V,D){"use strict";var se={exports:{}},Q={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var be;function Le(){if(be)return Q;be=1;var M=D,r=Symbol.for("react.element"),o=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,c=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,g={key:!0,ref:!0,__self:!0,__source:!0};function u(l,i,b){var s,p={},m=null,d=null;b!==void 0&&(m=""+b),i.key!==void 0&&(m=""+i.key),i.ref!==void 0&&(d=i.ref);for(s in i)a.call(i,s)&&!g.hasOwnProperty(s)&&(p[s]=i[s]);if(l&&l.defaultProps)for(s in i=l.defaultProps,i)p[s]===void 0&&(p[s]=i[s]);return{$$typeof:r,type:l,key:m,ref:d,props:p,_owner:c.current}}return Q.Fragment=o,Q.jsx=u,Q.jsxs=u,Q}var Z={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var ye;function ze(){return ye||(ye=1,{}.NODE_ENV!=="production"&&function(){var M=D,r=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),i=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),s=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),d=Symbol.for("react.offscreen"),_=Symbol.iterator,P="@@iterator";function y(e){if(e===null||typeof e!="object")return null;var t=_&&e[_]||e[P];return typeof t=="function"?t:null}var v=M.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function f(e){{for(var t=arguments.length,n=new Array(t>1?t-1:0),h=1;h<t;h++)n[h-1]=arguments[h];C("error",e,n)}}function C(e,t,n){{var h=v.ReactDebugCurrentFrame,E=h.getStackAddendum();E!==""&&(t+="%s",n=n.concat([E]));var S=n.map(function(R){return String(R)});S.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,S)}}var I=!1,U=!1,W=!1,L=!1,B=!1,re;re=Symbol.for("react.module.reference");function N(e){return!!(typeof e=="string"||typeof e=="function"||e===a||e===g||B||e===c||e===b||e===s||L||e===d||I||U||W||typeof e=="object"&&e!==null&&(e.$$typeof===m||e.$$typeof===p||e.$$typeof===u||e.$$typeof===l||e.$$typeof===i||e.$$typeof===re||e.getModuleId!==void 0))}function $(e,t,n){var h=e.displayName;if(h)return h;var E=t.displayName||t.name||"";return E!==""?n+"("+E+")":n}function Y(e){return e.displayName||"Context"}function O(e){if(e==null)return null;if(typeof e.tag=="number"&&f("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 a:return"Fragment";case o:return"Portal";case g:return"Profiler";case c:return"StrictMode";case b:return"Suspense";case s:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case l:var t=e;return Y(t)+".Consumer";case u:var n=e;return Y(n._context)+".Provider";case i:return $(e,e.render,"ForwardRef");case p:var h=e.displayName||null;return h!==null?h:O(e.type)||"Memo";case m:{var E=e,S=E._payload,R=E._init;try{return O(R(S))}catch{return null}}}return null}var z=Object.assign,H=0,J,X,xe,Re,Ce,Ee,_e;function Se(){}Se.__reactDisabledLog=!0;function Be(){{if(H===0){J=console.log,X=console.info,xe=console.warn,Re=console.error,Ce=console.group,Ee=console.groupCollapsed,_e=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Se,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}H++}}function He(){{if(H--,H===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:z({},e,{value:J}),info:z({},e,{value:X}),warn:z({},e,{value:xe}),error:z({},e,{value:Re}),group:z({},e,{value:Ce}),groupCollapsed:z({},e,{value:Ee}),groupEnd:z({},e,{value:_e})})}H<0&&f("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var le=v.ReactCurrentDispatcher,ce;function ne(e,t,n){{if(ce===void 0)try{throw Error()}catch(E){var h=E.stack.trim().match(/\n( *(at )?)/);ce=h&&h[1]||""}return`
|
|
18
|
+
`+ce+e}}var ue=!1,oe;{var Je=typeof WeakMap=="function"?WeakMap:Map;oe=new Je}function je(e,t){if(!e||ue)return"";{var n=oe.get(e);if(n!==void 0)return n}var h;ue=!0;var E=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var S;S=le.current,le.current=null,Be();try{if(t){var R=function(){throw Error()};if(Object.defineProperty(R.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(R,[])}catch(F){h=F}Reflect.construct(e,[],R)}else{try{R.call()}catch(F){h=F}e.call(R.prototype)}}else{try{throw Error()}catch(F){h=F}e()}}catch(F){if(F&&h&&typeof F.stack=="string"){for(var x=F.stack.split(`
|
|
19
|
+
`),k=h.stack.split(`
|
|
20
|
+
`),T=x.length-1,w=k.length-1;T>=1&&w>=0&&x[T]!==k[w];)w--;for(;T>=1&&w>=0;T--,w--)if(x[T]!==k[w]){if(T!==1||w!==1)do if(T--,w--,w<0||x[T]!==k[w]){var A=`
|
|
21
|
+
`+x[T].replace(" at new "," at ");return e.displayName&&A.includes("<anonymous>")&&(A=A.replace("<anonymous>",e.displayName)),typeof e=="function"&&oe.set(e,A),A}while(T>=1&&w>=0);break}}}finally{ue=!1,le.current=S,He(),Error.prepareStackTrace=E}var q=e?e.displayName||e.name:"",K=q?ne(q):"";return typeof e=="function"&&oe.set(e,K),K}function Ke(e,t,n){return je(e,!1)}function $e(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function ae(e,t,n){if(e==null)return"";if(typeof e=="function")return je(e,$e(e));if(typeof e=="string")return ne(e);switch(e){case b:return ne("Suspense");case s:return ne("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case i:return Ke(e.render);case p:return ae(e.type,t,n);case m:{var h=e,E=h._payload,S=h._init;try{return ae(S(E),t,n)}catch{}}}return""}var ee=Object.prototype.hasOwnProperty,Te={},we=v.ReactDebugCurrentFrame;function ie(e){if(e){var t=e._owner,n=ae(e.type,e._source,t?t.type:null);we.setExtraStackFrame(n)}else we.setExtraStackFrame(null)}function Xe(e,t,n,h,E){{var S=Function.call.bind(ee);for(var R in e)if(S(e,R)){var x=void 0;try{if(typeof e[R]!="function"){var k=Error((h||"React class")+": "+n+" type `"+R+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[R]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw k.name="Invariant Violation",k}x=e[R](t,R,h,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(T){x=T}x&&!(x instanceof Error)&&(ie(E),f("%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).",h||"React class",n,R,typeof x),ie(null)),x instanceof Error&&!(x.message in Te)&&(Te[x.message]=!0,ie(E),f("Failed %s type: %s",n,x.message),ie(null))}}}var Ge=Array.isArray;function fe(e){return Ge(e)}function qe(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,n=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function Qe(e){try{return Oe(e),!1}catch{return!0}}function Oe(e){return""+e}function Pe(e){if(Qe(e))return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(e)),Oe(e)}var te=v.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},De,ke,de;de={};function et(e){if(ee.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function tt(e){if(ee.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function rt(e,t){if(typeof e.ref=="string"&&te.current&&t&&te.current.stateNode!==t){var n=O(te.current.type);de[n]||(f('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',O(te.current.type),e.ref),de[n]=!0)}}function nt(e,t){{var n=function(){De||(De=!0,f("%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)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function ot(e,t){{var n=function(){ke||(ke=!0,f("%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)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var at=function(e,t,n,h,E,S,R){var x={$$typeof:r,type:e,key:t,ref:n,props:R,_owner:S};return x._store={},Object.defineProperty(x._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(x,"_self",{configurable:!1,enumerable:!1,writable:!1,value:h}),Object.defineProperty(x,"_source",{configurable:!1,enumerable:!1,writable:!1,value:E}),Object.freeze&&(Object.freeze(x.props),Object.freeze(x)),x};function it(e,t,n,h,E){{var S,R={},x=null,k=null;n!==void 0&&(Pe(n),x=""+n),tt(t)&&(Pe(t.key),x=""+t.key),et(t)&&(k=t.ref,rt(t,E));for(S in t)ee.call(t,S)&&!Ze.hasOwnProperty(S)&&(R[S]=t[S]);if(e&&e.defaultProps){var T=e.defaultProps;for(S in T)R[S]===void 0&&(R[S]=T[S])}if(x||k){var w=typeof e=="function"?e.displayName||e.name||"Unknown":e;x&&nt(R,w),k&&ot(R,w)}return at(e,x,k,E,h,te.current,R)}}var he=v.ReactCurrentOwner,Fe=v.ReactDebugCurrentFrame;function G(e){if(e){var t=e._owner,n=ae(e.type,e._source,t?t.type:null);Fe.setExtraStackFrame(n)}else Fe.setExtraStackFrame(null)}var ve;ve=!1;function pe(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function Ie(){{if(he.current){var e=O(he.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function st(e){{if(e!==void 0){var t=e.fileName.replace(/^.*[\\\/]/,""),n=e.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+
|
|
25
|
+
Check your code at `+t+":"+n+"."}return""}}var Ae={};function lt(e){{var t=Ie();if(!t){var n=typeof e=="string"?e:e.displayName||e.name;n&&(t=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+
|
|
27
|
+
Check the top-level render call using <`+n+">.")}return t}}function Me(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=lt(t);if(Ae[n])return;Ae[n]=!0;var h="";e&&e._owner&&e._owner!==he.current&&(h=" It was passed a child from "+O(e._owner.type)+"."),G(e),f('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,h),G(null)}}function We(e,t){{if(typeof e!="object")return;if(fe(e))for(var n=0;n<e.length;n++){var h=e[n];pe(h)&&Me(h,t)}else if(pe(e))e._store&&(e._store.validated=!0);else if(e){var E=y(e);if(typeof E=="function"&&E!==e.entries)for(var S=E.call(e),R;!(R=S.next()).done;)pe(R.value)&&Me(R.value,t)}}}function ct(e){{var t=e.type;if(t==null||typeof t=="string")return;var n;if(typeof t=="function")n=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===i||t.$$typeof===p))n=t.propTypes;else return;if(n){var h=O(t);Xe(n,e.props,"prop",h,e)}else if(t.PropTypes!==void 0&&!ve){ve=!0;var E=O(t);f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",E||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&f("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ut(e){{for(var t=Object.keys(e.props),n=0;n<t.length;n++){var h=t[n];if(h!=="children"&&h!=="key"){G(e),f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),G(null);break}}e.ref!==null&&(G(e),f("Invalid attribute `ref` supplied to `React.Fragment`."),G(null))}}var Ye={};function Ue(e,t,n,h,E,S){{var R=N(e);if(!R){var x="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(x+=" 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 k=st(E);k?x+=k:x+=Ie();var T;e===null?T="null":fe(e)?T="array":e!==void 0&&e.$$typeof===r?(T="<"+(O(e.type)||"Unknown")+" />",x=" Did you accidentally export a JSX literal instead of a component?"):T=typeof e,f("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",T,x)}var w=it(e,t,n,E,S);if(w==null)return w;if(R){var A=t.children;if(A!==void 0)if(h)if(fe(A)){for(var q=0;q<A.length;q++)We(A[q],e);Object.freeze&&Object.freeze(A)}else f("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(A,e)}if(ee.call(t,"key")){var K=O(e),F=Object.keys(t).filter(function(gt){return gt!=="key"}),ge=F.length>0?"{key: someKey, "+F.join(": ..., ")+": ...}":"{key: someKey}";if(!Ye[K+ge]){var pt=F.length>0?"{"+F.join(": ..., ")+": ...}":"{}";f(`A props object containing a "key" prop is being spread into JSX:
|
|
28
28
|
let props = %s;
|
|
29
29
|
<%s {...props} />
|
|
30
30
|
React keys must be passed directly to JSX without using spread:
|
|
31
31
|
let props = %s;
|
|
32
|
-
<%s key={someKey} {...props} />`,Re,$,pr,$),Ye[$+Re]=!0}}return e===P?cr(y):lr(y),y}}function ur(e,r,t){return Ue(e,r,t,!0)}function fr(e,r,t){return Ue(e,r,t,!1)}var dr=fr,vr=ur;ee.Fragment=P,ee.jsx=dr,ee.jsxs=vr}()),ee}({}).NODE_ENV==="production"?ce.exports=Le():ce.exports=Ne();var f=ce.exports;const we=({onCapture:Y})=>{const m=E.useRef(null),U=E.useRef(null),P=E.useRef(null),[M,G]=E.useState(!1),[A,L]=E.useState(null),[d,J]=E.useState([]),x=E.useRef(null),k=E.useRef([]),S=E.useRef(0);E.useEffect(()=>{P.current||(P.current=document.createElement("canvas"));let c=null;async function v(){try{const s=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment",width:{ideal:1920}}});m.current&&(m.current.srcObject=s,m.current.play(),c=requestAnimationFrame(l))}catch(s){console.error("Camera access error:",s)}}function l(){var s;if(((s=m.current)==null?void 0:s.readyState)>=2){const T=m.current,D=U.current;if(!D)return;const g=D.getContext("2d");D.width!==T.videoWidth&&(D.width=T.videoWidth,D.height=T.videoHeight),g.drawImage(T,0,0);const w=ae(T);if(w){x.current&&X(w,x.current)?S.current=Math.min(15,S.current+1):S.current=0,k.current.push(w),k.current.length>10&&k.current.shift();const _=ue(k.current);x.current=_,S.current>5&&(G(!0),L(_))}else S.current=Math.max(0,S.current-2),S.current===0&&(x.current=null,G(!1),L(null))}c=requestAnimationFrame(l)}return v(),()=>cancelAnimationFrame(c)},[]);const X=(c,v)=>Math.abs(c.tl[0]-v.tl[0])+Math.abs(c.tl[1]-v.tl[1])<50,ae=c=>{const l=Math.floor(c.videoWidth*.15),s=Math.floor(c.videoHeight*.15),T=P.current.getContext("2d");P.current.width=l,P.current.height=s,T.drawImage(c,0,0,l,s);const D=T.getImageData(0,0,l,s).data;let g=[l,s],w=[0,s],_=[l,0],N=[0,0],b=0;for(let p=10;p<s-10;p++)for(let j=10;j<l-10;j++){const K=(p*l+j)*4,V=D[K],B=D[K+1],re=D[K+2];V>180&&B>180&&re>170&&Math.abs(V-B)<25&&Math.abs(B-re)<25&&(b++,j+p<g[0]+g[1]&&(g=[j,p]),j-p>w[0]-w[1]&&(w=[j,p]),j-p<_[0]-_[1]&&(_=[j,p]),j+p>N[0]+N[1]&&(N=[j,p]))}const F=w[0]-g[0],C=_[1]-g[1];return b<l*s*.08||F<l*.3||C<s*.3?null:{tl:[g[0]/.15,g[1]/.15],tr:[w[0]/.15,w[1]/.15],bl:[_[0]/.15,_[1]/.15],br:[N[0]/.15,N[1]/.15]}},ue=c=>{const v={tl:[0,0],tr:[0,0],bl:[0,0],br:[0,0]};return c.forEach(l=>{["tl","tr","bl","br"].forEach(s=>{v[s][0]+=l[s][0]/c.length,v[s][1]+=l[s][1]/c.length})}),v},fe=()=>{const c=m.current,v=x.current;if(!c||!v)return;const l=1240,s=1754,T=document.createElement("canvas");T.width=l,T.height=s;const D=T.getContext("2d"),g=document.createElement("canvas");g.width=c.videoWidth,g.height=c.videoHeight,g.getContext("2d").drawImage(c,0,0);const w=g.getContext("2d").getImageData(0,0,g.width,g.height),_=D.createImageData(l,s);for(let b=0;b<s;b++)for(let F=0;F<l;F++){const C=F/l,p=b/s,j=Math.floor((1-C)*(1-p)*v.tl[0]+C*(1-p)*v.tr[0]+(1-C)*p*v.bl[0]+C*p*v.br[0]),K=Math.floor((1-C)*(1-p)*v.tl[1]+C*(1-p)*v.tr[1]+(1-C)*p*v.bl[1]+C*p*v.br[1]),V=(b*l+F)*4,B=(K*g.width+j)*4;_.data[V]=w.data[B],_.data[V+1]=w.data[B+1],_.data[V+2]=w.data[B+2],_.data[V+3]=255}D.putImageData(_,0,0);const N=T.toDataURL("image/jpeg",.92);J(b=>[...b,N])},H=()=>{d.length>0&&Y(d)},R=()=>{if(!A||!m.current)return"";const c=m.current.videoWidth,v=m.current.videoHeight,l=s=>`${s[0]/c*100},${s[1]/v*100}`;return`${l(A.tl)} ${l(A.tr)} ${l(A.br)} ${l(A.bl)}`};return f.jsxs("div",{style:{position:"fixed",inset:0,backgroundColor:"#000",fontFamily:"system-ui, -apple-system, sans-serif",overflow:"hidden"},children:[f.jsx("video",{ref:m,style:{display:"none"},playsInline:!0,muted:!0}),f.jsx("canvas",{ref:U,style:{width:"100vw",height:"100vh",objectFit:"cover"}}),f.jsx("svg",{viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10},children:A&&f.jsx("polygon",{points:R(),fill:"rgba(0, 255, 70, 0.15)",stroke:"#00FF46",strokeWidth:"0.5",style:{transition:"all 0.1s ease-out"}})}),f.jsx("div",{style:{position:"absolute",top:0,width:"100%",padding:"40px 0 20px",background:"linear-gradient(rgba(0,0,0,0.6), transparent)",textAlign:"center",zIndex:20},children:f.jsx("div",{style:{display:"inline-block",padding:"6px 16px",borderRadius:"20px",backgroundColor:M?"#00FF46":"rgba(255,255,255,0.2)",color:M?"#000":"#fff",fontSize:"12px",fontWeight:"bold"},children:M?"READY TO SCAN":"POSITION DOCUMENT"})}),f.jsxs("div",{style:{position:"absolute",bottom:0,width:"100%",height:"160px",background:"linear-gradient(transparent, rgba(0,0,0,0.8))",display:"flex",alignItems:"center",justifyContent:"space-around",zIndex:20},children:[f.jsxs("div",{onClick:H,style:{width:"64px",height:"64px",position:"relative",cursor:d.length>0?"pointer":"default",opacity:d.length>0?1:.4,transition:"transform 0.2s"},onMouseDown:c=>d.length>0&&(c.currentTarget.style.transform="scale(0.9)"),onMouseUp:c=>c.currentTarget.style.transform="scale(1)",children:[d.length>0?f.jsxs(f.Fragment,{children:[f.jsx("img",{src:d[d.length-1],style:{width:"100%",height:"100%",objectFit:"cover",border:"2px solid #fff",borderRadius:"4px"},alt:"preview"}),f.jsx("div",{style:{position:"absolute",top:"-8px",right:"-8px",background:"#00FF46",color:"#000",width:"22px",height:"22px",borderRadius:"50%",fontSize:"12px",fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid #000"},children:d.length})]}):f.jsx("div",{style:{width:"100%",height:"100%",borderRadius:"4px",backgroundColor:"rgba(255,255,255,0.1)",border:"1px dashed #555"}}),f.jsx("span",{style:{fontSize:"10px",display:"block",textAlign:"center",marginTop:"4px",color:"#fff"},children:"DONE"})]}),f.jsx("button",{onClick:fe,disabled:!M,style:{width:"84px",height:"84px",borderRadius:"50%",border:`4px solid ${M?"#00FF46":"#555"}`,backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:f.jsx("div",{style:{width:"68px",height:"68px",borderRadius:"50%",backgroundColor:M?"#fff":"#444"}})}),f.jsx("div",{style:{width:"64px"}})]})]})};function Ve(){const[Y,m]=E.useState(null);return f.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[f.jsx("h1",{children:"JS Doc Scanner"}),Y?f.jsxs("div",{children:[f.jsx("h3",{children:"Scanned Result:"}),Y==null?void 0:Y.map((U,P)=>f.jsx("img",{src:U,style:{width:"100%",maxWidth:"400px",border:"2px solid #ccc",margin:"10px"}},P)),f.jsx("br",{}),f.jsx("button",{onClick:()=>m(null),children:"Scan Again"})]}):f.jsx(we,{onCapture:U=>m(U)})]})}z.App=Ve,z.DocumentScanner=we,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});
|
|
32
|
+
<%s key={someKey} {...props} />`,ge,K,pt,K),Ye[K+ge]=!0}}return e===a?ut(w):ct(w),w}}function ft(e,t,n){return Ue(e,t,n,!0)}function dt(e,t,n){return Ue(e,t,n,!1)}var ht=dt,vt=ft;Z.Fragment=a,Z.jsx=ht,Z.jsxs=vt}()),Z}({}).NODE_ENV==="production"?se.exports=Le():se.exports=ze();var j=se.exports;class Ve{constructor(){this.procCanvas=document.createElement("canvas"),this.procCtx=this.procCanvas.getContext("2d",{willReadFrequently:!0}),this.smoothCorners=null,this.missCount=0}detect(r,o=.18){const a=Math.floor(r.videoWidth*o),c=Math.floor(r.videoHeight*o);if(!a||!c)return null;this.procCanvas.width=a,this.procCanvas.height=c,this.procCtx.drawImage(r,0,0,a,c);const u=this.procCtx.getImageData(0,0,a,c).data,{brightness:l,saturation:i,avgBright:b,isTexturedBackground:s}=this.analyzeImage(u,a,c),p=this.createPaperMask(u,l,i,a,c,b,s);this.cleanMask(p,a,c,s);const m=this.findLargestBlob(p,a,c);if(!m||m.size<a*c*.06)return this.handleMiss();const d=this.findRegionCorners(m.pixels,a,c);if(!d)return this.handleMiss();if(!this.validateQuad(d,a,c))return this.handleMiss();const _={tl:[d.tl[0]/o,d.tl[1]/o],tr:[d.tr[0]/o,d.tr[1]/o],br:[d.br[0]/o,d.br[1]/o],bl:[d.bl[0]/o,d.bl[1]/o]};return this.missCount=0,this.smooth(_)}analyzeImage(r,o,a){const c=new Float32Array(o*a),g=new Float32Array(o*a);let u=0,l=0;for(let p=0,m=0;p<r.length;p+=4,m++){const d=r[p],_=r[p+1],P=r[p+2],y=(d+_+P)/3;c[m]=y,u+=y,y>150&&l++;const v=Math.max(d,_,P),f=Math.min(d,_,P);g[m]=v>0?(v-f)/v:0}const i=u/(o*a),s=l/(o*a)>.5||i>160;return{brightness:c,saturation:g,avgBright:i,isTexturedBackground:s}}createPaperMask(r,o,a,c,g,u,l){const i=new Uint8Array(c*g),b=l?this.calcLocalVariance(o,c,g):null;let s;l?s=u+15:s=Math.max(120,u);const p=.3,m=l?400:9999;for(let d=0;d<c*g;d++){const _=o[d],P=a[d];if(_<s||P>p)continue;const y=d*4,v=r[y],f=r[y+1],C=r[y+2];Math.abs(v-f)+Math.abs(f-C)+Math.abs(v-C)>80||l&&b&&b[d]>m||(i[d]=1)}return i}calcLocalVariance(r,o,a){const c=new Float32Array(o*a),u=Math.floor(3/2);for(let l=u;l<a-u;l++)for(let i=u;i<o-u;i++){let b=0,s=0,p=0;for(let d=-u;d<=u;d++)for(let _=-u;_<=u;_++){const P=r[(l+d)*o+(i+_)];b+=P,s+=P*P,p++}const m=b/p;c[l*o+i]=s/p-m*m}return c}cleanMask(r,o,a,c){const g=c?2:1;for(let u=0;u<g;u++){const l=new Uint8Array(o*a);for(let i=1;i<a-1;i++)for(let b=1;b<o-1;b++){const s=i*o+b;r[s]&&r[s-1]&&r[s+1]&&r[s-o]&&r[s+o]&&(l[s]=1)}for(let i=0;i<o*a;i++)r[i]=l[i]}for(let u=0;u<g;u++){const l=new Uint8Array(o*a);for(let i=1;i<a-1;i++)for(let b=1;b<o-1;b++){const s=i*o+b;(r[s]||r[s-1]||r[s+1]||r[s-o]||r[s+o])&&(l[s]=1)}for(let i=0;i<o*a;i++)r[i]=l[i]}}findLargestBlob(r,o,a){const c=new Uint8Array(o*a);let g=null,u=0;for(let l=0;l<a;l++)for(let i=0;i<o;i++){const b=l*o+i;if(!r[b]||c[b])continue;const s=new Set,p=[[i,l]];for(;p.length>0;){const[m,d]=p.pop();if(m<0||m>=o||d<0||d>=a)continue;const _=d*o+m;c[_]||!r[_]||(c[_]=1,s.add(_),p.push([m-1,d],[m+1,d],[m,d-1],[m,d+1]))}s.size>u&&(u=s.size,g={pixels:s,size:s.size})}return g}findRegionCorners(r,o,a){let c=0,g=0;for(const y of r){const v=y%o,f=Math.floor(y/o);c+=v,g+=f}const u=c/r.size,l=g/r.size;let i=null,b=1/0,s=null,p=-1/0,m=null,d=-1/0,_=null,P=-1/0;for(const y of r){const v=y%o,f=Math.floor(y/o);if(v<=u&&f<=l){const C=v+f;C<b&&(b=C,i=[v,f])}if(v>=u&&f<=l){const C=v-f;C>p&&(p=C,s=[v,f])}if(v>=u&&f>=l){const C=v+f;C>d&&(d=C,m=[v,f])}if(v<=u&&f>=l){const C=f-v;C>P&&(P=C,_=[v,f])}}return!i||!s||!m||!_?null:{tl:i,tr:s,br:m,bl:_}}validateQuad(r,o,a){const{tl:c,tr:g,br:u,bl:l}=r;for(const y of[c,g,u,l])if(!y||y[0]<0||y[0]>=o||y[1]<0||y[1]>=a)return!1;if(c[0]>=g[0]-5||l[0]>=u[0]-5||c[1]>=l[1]-5||g[1]>=u[1]-5)return!1;const i=Math.hypot(g[0]-c[0],g[1]-c[1]),b=Math.hypot(u[0]-l[0],u[1]-l[1]),s=Math.hypot(l[0]-c[0],l[1]-c[1]),p=Math.hypot(u[0]-g[0],u[1]-g[1]),m=(i+b)/2,d=(s+p)/2;if(m<10||d<10)return!1;const _=m/d;return!(_<.3||_>3.5||i/b>2.5||b/i>2.5||s/p>2.5||p/s>2.5||.5*Math.abs((g[0]-l[0])*(c[1]-u[1])-(c[0]-u[0])*(g[1]-l[1]))<o*a*.05)}smooth(r){if(!this.smoothCorners)return this.smoothCorners=r,r;if(this.cornerDistance(this.smoothCorners,r)>50)return this.smoothCorners=r,r;const a=.35;return this.smoothCorners={tl:this.lerp(this.smoothCorners.tl,r.tl,a),tr:this.lerp(this.smoothCorners.tr,r.tr,a),br:this.lerp(this.smoothCorners.br,r.br,a),bl:this.lerp(this.smoothCorners.bl,r.bl,a)},this.smoothCorners}cornerDistance(r,o){let a=0;for(const c of["tl","tr","br","bl"]){const g=r[c][0]-o[c][0],u=r[c][1]-o[c][1];a+=Math.sqrt(g*g+u*u)}return a/4}lerp(r,o,a){return[r[0]+a*(o[0]-r[0]),r[1]+a*(o[1]-r[1])]}handleMiss(){return this.missCount++,this.missCount<8&&this.smoothCorners?this.smoothCorners:null}reset(){this.smoothCorners=null,this.missCount=0}}const me=({onCapture:M})=>{const r=D.useRef(null),o=D.useRef(null),[a,c]=D.useState(!1),[g,u]=D.useState(null),[l,i]=D.useState([]),b=D.useRef(null),s=D.useRef(null),p=D.useRef(0);D.useEffect(()=>{b.current||(b.current=new Ve);let y=null;async function v(){try{const C=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment",width:{ideal:1920}}});r.current&&(r.current.srcObject=C,r.current.play(),y=requestAnimationFrame(f))}catch(C){console.error("Camera access error:",C)}}function f(){var C;if(((C=r.current)==null?void 0:C.readyState)>=2){const I=r.current,U=o.current;if(!U)return;const W=U.getContext("2d");U.width!==I.videoWidth&&(U.width=I.videoWidth,U.height=I.videoHeight),W.drawImage(I,0,0);const L=b.current.detect(I,.18);L?(s.current&&m(L,s.current)?p.current=Math.min(15,p.current+1):p.current=0,s.current=L,p.current>5&&(c(!0),u(L))):(p.current=Math.max(0,p.current-2),p.current===0&&(s.current=null,c(!1),u(null)))}y=requestAnimationFrame(f)}return v(),()=>{cancelAnimationFrame(y),b.current&&b.current.reset()}},[]);const m=(y,v)=>Math.abs(y.tl[0]-v.tl[0])+Math.abs(y.tl[1]-v.tl[1])<50,d=()=>{const y=r.current,v=s.current;if(!y||!v)return;const f=1240,C=1754,I=document.createElement("canvas");I.width=f,I.height=C;const U=I.getContext("2d"),W=document.createElement("canvas");W.width=y.videoWidth,W.height=y.videoHeight,W.getContext("2d").drawImage(y,0,0);const L=W.getContext("2d").getImageData(0,0,W.width,W.height),B=U.createImageData(f,C);for(let N=0;N<C;N++)for(let $=0;$<f;$++){const Y=$/f,O=N/C,z=Math.floor((1-Y)*(1-O)*v.tl[0]+Y*(1-O)*v.tr[0]+(1-Y)*O*v.bl[0]+Y*O*v.br[0]),H=Math.floor((1-Y)*(1-O)*v.tl[1]+Y*(1-O)*v.tr[1]+(1-Y)*O*v.bl[1]+Y*O*v.br[1]),J=(N*f+$)*4,X=(H*W.width+z)*4;B.data[J]=L.data[X],B.data[J+1]=L.data[X+1],B.data[J+2]=L.data[X+2],B.data[J+3]=255}U.putImageData(B,0,0);const re=I.toDataURL("image/jpeg",.92);i(N=>[...N,re])},_=()=>{l.length>0&&M(l)},P=()=>{if(!g||!r.current)return"";const y=r.current.videoWidth,v=r.current.videoHeight,f=C=>`${C[0]/y*100},${C[1]/v*100}`;return`${f(g.tl)} ${f(g.tr)} ${f(g.br)} ${f(g.bl)}`};return j.jsxs("div",{style:{position:"fixed",inset:0,backgroundColor:"#000",fontFamily:"system-ui, -apple-system, sans-serif",overflow:"hidden"},children:[j.jsx("video",{ref:r,style:{display:"none"},playsInline:!0,muted:!0}),j.jsx("canvas",{ref:o,style:{width:"100vw",height:"100vh",objectFit:"cover"}}),j.jsx("svg",{viewBox:"0 0 100 100",preserveAspectRatio:"none",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:10},children:g&&j.jsx("polygon",{points:P(),fill:"rgba(0, 255, 70, 0.15)",stroke:"#00FF46",strokeWidth:"0.5",style:{transition:"all 0.1s ease-out"}})}),j.jsx("div",{style:{position:"absolute",top:0,width:"100%",padding:"40px 0 20px",background:"linear-gradient(rgba(0,0,0,0.6), transparent)",textAlign:"center",zIndex:20},children:j.jsx("div",{style:{display:"inline-block",padding:"6px 16px",borderRadius:"20px",backgroundColor:a?"#00FF46":"rgba(255,255,255,0.2)",color:a?"#000":"#fff",fontSize:"12px",fontWeight:"bold"},children:a?"READY TO SCAN":"POSITION DOCUMENT"})}),j.jsxs("div",{style:{position:"absolute",bottom:0,width:"100%",height:"160px",background:"linear-gradient(transparent, rgba(0,0,0,0.8))",display:"flex",alignItems:"center",justifyContent:"space-around",zIndex:20},children:[j.jsxs("div",{onClick:_,style:{width:"64px",height:"64px",position:"relative",cursor:l.length>0?"pointer":"default",opacity:l.length>0?1:.4,transition:"transform 0.2s"},onMouseDown:y=>l.length>0&&(y.currentTarget.style.transform="scale(0.9)"),onMouseUp:y=>y.currentTarget.style.transform="scale(1)",children:[l.length>0?j.jsxs(j.Fragment,{children:[j.jsx("img",{src:l[l.length-1],style:{width:"100%",height:"100%",objectFit:"cover",border:"2px solid #fff",borderRadius:"4px"},alt:"preview"}),j.jsx("div",{style:{position:"absolute",top:"-8px",right:"-8px",background:"#00FF46",color:"#000",width:"22px",height:"22px",borderRadius:"50%",fontSize:"12px",fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid #000"},children:l.length})]}):j.jsx("div",{style:{width:"100%",height:"100%",borderRadius:"4px",backgroundColor:"rgba(255,255,255,0.1)",border:"1px dashed #555"}}),j.jsx("span",{style:{fontSize:"10px",display:"block",textAlign:"center",marginTop:"4px",color:"#fff"},children:"DONE"})]}),j.jsx("button",{onClick:d,disabled:!a,style:{width:"84px",height:"84px",borderRadius:"50%",border:`4px solid ${a?"#00FF46":"#555"}`,backgroundColor:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:j.jsx("div",{style:{width:"68px",height:"68px",borderRadius:"50%",backgroundColor:a?"#fff":"#444"}})}),j.jsx("div",{style:{width:"64px"}})]})]})};function Ne(){const[M,r]=D.useState(null);return j.jsxs("div",{style:{textAlign:"center",padding:"20px",fontFamily:"sans-serif"},children:[j.jsx("h1",{children:"JS Doc Scanner"}),M?j.jsxs("div",{children:[j.jsx("h3",{children:"Scanned Result:"}),M==null?void 0:M.map((o,a)=>j.jsx("img",{src:o,style:{width:"100%",maxWidth:"400px",border:"2px solid #ccc",margin:"10px"}},a)),j.jsx("br",{}),j.jsx("button",{onClick:()=>r(null),children:"Scan Again"})]}):j.jsx(me,{onCapture:o=>r(o)})]})}V.App=Ne,V.DocumentScanner=me,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uziee/document-scanner",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "A lightweight, zero-dependency React document scanner with real-time edge detection, stability filtering, and perspective correction (bilinear warping) for high-resolution A4 captures.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|