!function(){var e,t,n,a,r,i,o,d,l,c,h,s,u,f=new WeakMap,p=null,g=null,v=null,m=!1,x=null,b=0,y=!1,w=!1,C=null,M=null,k=!1,T=0,E=document.createElement("canvas"),D=E.getContext("2d",{willReadFrequently:!0});function j(e,t,n,a){var r=e.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,e.width,e.height).data,i=e.width,o=e.height,d=document.createElement("canvas");d.width=n,d.height=a;for(var l=d.getContext("2d"),c=l.createImageData(n,a),h=c.data,s=function(e,t){var n,a=[],r=[];for(n=0;4>n;n++){var i=e[n][0],o=e[n][1],d=t[n][0],l=t[n][1];a.push([d,l,1,0,0,0,-d*i,-l*i]),r.push(i),a.push([0,0,0,d,l,1,-d*o,-l*o]),r.push(o)}for(var c=0;8>c;c++){var h,s=c;for(h=c+1;8>h;h++)Math.abs(a[h][c])>Math.abs(a[s][c])&&(s=h);var u=a[c];a[c]=a[s],a[s]=u;var f=r[c];r[c]=r[s],r[s]=f;var p=a[c][c]||1e-9;for(h=c+1;8>h;h++){for(var g=a[h][c]/p,v=c;8>v;v++)a[h][v]-=g*a[c][v];r[h]-=g*r[c]}}for(var m=new Array(8),x=7;x>=0;x--){for(var b=r[x],y=x+1;8>y;y++)b-=a[x][y]*m[y];m[x]=b/(a[x][x]||1e-9)}return m.push(1),m}(t,[[0,0],[n,0],[n,a],[0,a]]),u=0;a>u;u++)for(var f=0;n>f;f++){var p=s[6]*f+s[7]*u+s[8],g=(s[0]*f+s[1]*u+s[2])/p,v=(s[3]*f+s[4]*u+s[5])/p,m=4*(u*n+f),x=Math.floor(g),b=Math.floor(v);if(x>=0&&b>=0&&i-1>x&&o-1>b){var y=g-x,w=v-b,C=4*(b*i+x),M=C+4,k=C+4*i,T=k+4,E=(1-y)*(1-w),D=y*(1-w),j=(1-y)*w,L=y*w;h[m]=r[C]*E+r[M]*D+r[k]*j+r[T]*L,h[m+1]=r[C+1]*E+r[M+1]*D+r[k+1]*j+r[T+1]*L,h[m+2]=r[C+2]*E+r[M+2]*D+r[k+2]*j+r[T+2]*L,h[m+3]=255}else if(x>=0&&b>=0&&i>x&&o>b){var R=4*(b*i+x);h[m]=r[R],h[m+1]=r[R+1],h[m+2]=r[R+2],h[m+3]=255}else h[m]=255,h[m+1]=255,h[m+2]=255,h[m+3]=255}return l.putImageData(c,0,0),d}function L(e,t){var n=e[0]-t[0],a=e[1]-t[1];return Math.sqrt(n*n+a*a)}function R(){if(g=requestAnimationFrame(R),!(y||w||k)&&t.videoWidth)if(T>0)T--;else{var e=function(e){var t=e.videoWidth,n=e.videoHeight;if(!t||!n)return null;var a=240/t,r=240,i=Math.round(n*a);E.width=r,E.height=i,D.drawImage(e,0,0,r,i);var o,d=D.getImageData(0,0,r,i).data,l=r*i,c=new Uint8Array(l),h=new Int32Array(256);for(o=0;l>o;o++){var s=4*o,u=.299*d[s]+.587*d[s+1]+.114*d[s+2]|0;c[o]=u,h[u]++}var f=0;for(o=0;256>o;o++)f+=o*h[o];var p=0,g=0,v=0,m=128;for(o=0;256>o;o++)if(g+=h[o]){var x=l-g;if(!x)break;var b=(p+=o*h[o])/g,y=(f-p)/x,w=g*x*(b-y)*(b-y);w>v&&(v=w,m=o)}var C=new Uint8Array(l);for(o=0;l>o;o++)C[o]=c[o]>m?1:0;var M=new Int32Array(l),k=0,T=0,j=0,L=new Int32Array(l);for(o=0;l>o;o++)if(C[o]&&!M[o]){k++;var R=0,I=0;for(L[R++]=o,M[o]=k;R;){var A=L[--R];I++;var P=A%r,q=A/r|0;P>0&&C[A-1]&&!M[A-1]&&(M[A-1]=k,L[R++]=A-1),239>P&&C[A+1]&&!M[A+1]&&(M[A+1]=k,L[R++]=A+1),q>0&&C[A-r]&&!M[A-r]&&(M[A-r]=k,L[R++]=A-r),i-1>q&&C[A+r]&&!M[A+r]&&(M[A+r]=k,L[R++]=A+r)}I>j&&(j=I,T=k)}if(j<.1*l)return null;if(j>.92*l)return null;for(var S=!1,F=!1,H=!1,W=!1,z=0;r>z;z++)M[z]===T&&(H=!0),M[(i-1)*r+z]===T&&(W=!0);for(var U=0;i>U;U++)M[U*r]===T&&(S=!0),M[U*r+r-1]===T&&(F=!0);if(S&&F&&H&&W)return null;for(var B=null,O=null,X=null,G=null,K=1e9,Q=-1e9,Y=1e9,J=-1e9,N=0;i>N;N++)for(var V=0;r>V;V++)if(M[N*r+V]===T){var Z=V+N,$=V-N;K>Z&&(K=Z,B=[V,N]),Z>Q&&(Q=Z,X=[V,N]),Y>$&&(Y=$,G=[V,N]),$>J&&(J=$,O=[V,N])}if(!(B&&O&&X&&G))return null;var _=[B,O,X,G],ee=[];for(o=0;4>o;o++){var te=_[o],ne=_[(o+1)%4];ee.push(Math.sqrt((te[0]-ne[0])*(te[0]-ne[0])+(te[1]-ne[1])*(te[1]-ne[1])))}if(Math.min.apply(null,ee)<38.4)return null;var ae=Math.abs(_[0][0]*_[1][1]-_[1][0]*_[0][1]+(_[1][0]*_[2][1]-_[2][0]*_[1][1])+(_[2][0]*_[3][1]-_[3][0]*_[2][1])+(_[3][0]*_[0][1]-_[0][0]*_[3][1]))/2;return ae>0?.72>j/ae||ae>.94*l?null:_.map(function(e){return[e[0]/r*t,e[1]/i*n]}):null}(t);if(function(e){var n=t.getBoundingClientRect();a.width=n.width,a.height=n.height;var r=a.getContext("2d");if(r.clearRect(0,0,a.width,a.height),!e)return;var i=t.videoWidth,o=t.videoHeight,d=Math.max(n.width/i,n.height/o),l=(n.width-i*d)/2,c=(n.height-o*d)/2;r.strokeStyle="#2f7cf6",r.lineWidth=3,r.fillStyle="rgba(47,124,246,0.16)",r.beginPath(),r.moveTo(e[0][0]*d+l,e[0][1]*d+c);for(var h=1;4>h;h++)r.lineTo(e[h][0]*d+l,e[h][1]*d+c);r.closePath(),r.fill(),r.stroke(),r.fillStyle="#2f7cf6";for(var s=0;4>s;s++)r.beginPath(),r.arc(e[s][0]*d+l,e[s][1]*d+c,6,0,6.2832),r.fill()}(e),!e)return x=null,b=0,void(r.textContent="ضع الفاتورة داخل الإطار");var n=function(e,t){if(!e||!t)return 1e9;for(var n=0,a=0;4>a;a++){var r=e[a][0]-t[a][0],i=e[a][1]-t[a][1],o=Math.sqrt(r*r+i*i);o>n&&(n=o)}return n}(e,x);x=e,.02*t.videoWidth>n?b++:b=0,r.textContent=m?"جارٍ المسح الضوئي... ثبّت الجهاز":"اضغط الزر للالتقاط",m&&b>=10&&(b=0,20>(f.get(v)||[]).length&&I(e))}}function I(e){y=!0,r.textContent="جارٍ المعالجة...";var n,a,i,o,d=(n=document.createElement("canvas"),a=t.videoWidth,i=t.videoHeight,o=Math.min(1,1700/Math.max(a,i)),n.width=Math.round(a*o),n.height=Math.round(i*o),n.getContext("2d").drawImage(t,0,0,n.width,n.height),{cv:n,sc:o}),l=d.cv.width,c=d.cv.height,h=e?e.map(function(e){return[e[0]*d.sc,e[1]*d.sc]}):[[.12*l,.12*c],[.88*l,.12*c],[.88*l,.88*c],[.12*l,.88*c]];setTimeout(function(){var e={src:d.cv,quad:h,mode:"color",rot:0};A(e);var t=f.get(v)||[];t.push(e),f.set(v,t),y=!1,z(e)},30)}function A(e){var t=function(e){var t=(L(e[0],e[1])+L(e[3],e[2]))/2,n=(L(e[0],e[3])+L(e[1],e[2]))/2;if(!(t>20&&n>20))return[1240,1754];var a=1700/Math.max(t,n);return[Math.max(500,Math.round(t*a)),Math.max(500,Math.round(n*a))]}(e.quad),n=j(e.src,e.quad,t[0],t[1]);!function(e,t){if("raw"===t)return e;var n,a=e.getContext("2d",{willReadFrequently:!0}),r=e.width,i=e.height,o=a.getImageData(0,0,r,i),d=o.data,l=r*i,c=new Float32Array(l);for(n=0;l>n;n++){var h=4*n;c[n]=.299*d[h]+.587*d[h+1]+.114*d[h+2]}for(var s=new Float64Array((r+1)*(i+1)),u=0;i>u;u++)for(var f=0,p=0;r>p;p++)f+=c[u*r+p],s[(u+1)*(r+1)+(p+1)]=s[u*(r+1)+(p+1)]+f;for(var g=Math.max(14,r/7|0),v=0;i>v;v++)for(var m=Math.max(0,v-g),x=Math.min(i-1,v+g),b=0;r>b;b++){var y=Math.max(0,b-g),w=Math.min(r-1,b+g),C=(w-y+1)*(x-m+1),M=(s[(x+1)*(r+1)+(w+1)]-s[m*(r+1)+(w+1)]-s[(x+1)*(r+1)+y]+s[m*(r+1)+y])/C;40>M&&(M=40);var k=4*(b+v*r);if("bw"===t){var T=c[v*r+b]/M,E=255*(T=(T=(T-.8)/.22)>1?1:T>0?T:0)|0;d[k]=E,d[k+1]=E,d[k+2]=E}else{var D=248/M,j=d[k]*D,L=d[k+1]*D,R=d[k+2]*D;j=1.12*(j-18),L=1.12*(L-18),R=1.12*(R-18),d[k]=j>255?255:j>0?j:0,d[k+1]=L>255?255:L>0?L:0,d[k+2]=R>255?255:R>0?R:0}d[k+3]=255}a.putImageData(o,0,0)}(n,e.mode),n=function(e,t){if(!t)return e;var n=document.createElement("canvas"),a=90===t||270===t;n.width=a?e.height:e.width,n.height=a?e.width:e.height;var r=n.getContext("2d");return r.translate(n.width/2,n.height/2),r.rotate(t*Math.PI/180),r.drawImage(e,-e.width/2,-e.height/2),n}(n,e.rot),e.cv=n,e.w=n.width,e.h=n.height,e.url=n.toDataURL("image/jpeg",.55)}function P(e){for(var t=e.toDataURL("image/jpeg",.8),n=atob(t.split(",")[1]),a=new Uint8Array(n.length),r=0;n.length>r;r++)a[r]=n.charCodeAt(r);return a}function q(e){var t=new TextEncoder,n=[],a=0;function r(e){var r="string"==typeof e?t.encode(e):e;n.push(r),a+=r.length}var i,o=[0];r("%PDF-1.4\n");var d=2+3*e.length,l="";for(i=0;e.length>i;i++)l+=3+3*i+" 0 R ";o[1]=a,r("1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n"),o[2]=a,r("2 0 obj\n<< /Type /Pages /Kids ["+l+"] /Count "+e.length+" >>\nendobj\n");for(var c=0;e.length>c;c++){var h=e[c],s=P(h.cv),u=Math.round(595*h.h/h.w),f=3+3*c,p=f+1,g=f+2;o[f]=a,r(f+" 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 "+u+"] /Resources << /XObject << /Im0 "+g+" 0 R >> >> /Contents "+p+" 0 R >>\nendobj\n");var v="q 595 0 0 "+u+" 0 0 cm /Im0 Do Q";o[p]=a,r(p+" 0 obj\n<< /Length "+v.length+" >>\nstream\n"+v+"\nendstream\nendobj\n"),o[g]=a,r(g+" 0 obj\n<< /Type /XObject /Subtype /Image /Width "+h.w+" /Height "+h.h+" /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length "+s.length+" >>\nstream\n"),r(s),r("\nendstream\nendobj\n")}for(var m=a,x="xref\n0 "+(d+1)+"\n0000000000 65535 f \n",b=1;d>=b;b++)x+=("0000000000"+o[b]).slice(-10)+" 00000 n \n";r(x+="trailer\n<< /Size "+(d+1)+" /Root 1 0 R >>\nstartxref\n"+m+"\n%%EOF\n");for(var y=new Uint8Array(a),w=0,C=0;n.length>C;C++)y.set(n[C],w),w+=n[C].length;return y}function S(e,t){var n=document.createElement("button");return n.type="button",n.textContent=e,n.style.cssText="border:0;border-radius:22px;padding:10px 16px;font:600 13.5px system-ui,sans-serif;"+(t||""),n}function F(){var e=f.get(v)||[];s.innerHTML="";for(var t=Math.max(0,e.length-3);e.length>t;t++){var n=document.createElement("img");n.src=e[t].url,n.style.cssText="width:42px;border:2px solid #fff;border-radius:5px;display:block",s.appendChild(n)}if(e.length){var a=document.createElement("div");a.textContent=e.length,a.style.cssText="color:#fff;font:700 13px system-ui,sans-serif;align-self:center",s.appendChild(a),u.style.display="inline-block"}else u.style.display="none"}function H(e){w=!1,c.innerHTML="";var t=document.createElement("img");t.src=e.url,t.style.cssText="max-width:100%;max-height:100%;border-radius:6px;box-shadow:0 2px 14px rgba(0,0,0,.6)",c.appendChild(t),h.innerHTML="";var n=S("color"===e.mode?"✦ ملوّن":"bw"===e.mode?"◐ أبيض وأسود":"○ بدون تحسين","raw"===e.mode?"background:#22303c;color:#cfd8e3":"background:#cfe0ff;color:#123"),a=S("⟳ تدوير","background:#22303c;color:#cfd8e3"),r=S("⛶ اقتصاص يدوي","background:#22303c;color:#cfd8e3"),i=S("🗑 حذف","background:#3a1f1a;color:#f0b9a4"),o=S("+ صفحة أخرى","background:#22303c;color:#cfd8e3"),d=S("حفظ ✓","background:#2f7cf6;color:#fff;padding:11px 24px;font-size:15px");n.onclick=function(){e.mode="color"===e.mode?"bw":"bw"===e.mode?"raw":"color",A(e),H(e),F()},a.onclick=function(){e.rot=(e.rot+90)%360,A(e),H(e),F()},r.onclick=function(){z(e)},i.onclick=function(){var t=f.get(v)||[],n=t.indexOf(e);n>-1&&t.splice(n,1),f.set(v,t),F(),W()},o.onclick=function(){W()},d.onclick=function(){U()},h.appendChild(n),h.appendChild(a),h.appendChild(r),h.appendChild(i),h.appendChild(o),h.appendChild(d),l.style.display="flex",k=!0,F()}function W(){l.style.display="none",w=!1,k=!1,x=null,b=0,T=30}function z(e){w=!0,k=!0,M=e,l.style.display="flex",c.innerHTML="";var t=document.createElement("canvas"),n=e.src,a=Math.min(1,820/Math.max(n.width,n.height));function r(){var e=t.getContext("2d");e.clearRect(0,0,t.width,t.height),e.drawImage(n,0,0,t.width,t.height),e.strokeStyle="#2f7cf6",e.lineWidth=3,e.beginPath(),e.moveTo(C[0][0],C[0][1]);for(var a=1;4>a;a++)e.lineTo(C[a][0],C[a][1]);e.closePath(),e.stroke(),e.fillStyle="#2f7cf6";for(var r=0;4>r;r++)e.beginPath(),e.arc(C[r][0],C[r][1],12,0,6.2832),e.fill()}t.width=Math.round(n.width*a),t.height=Math.round(n.height*a),t.style.cssText="max-width:100%;max-height:100%;touch-action:none",C=e.quad.map(function(e){return[e[0]*a,e[1]*a]});var i=-1;function o(e){var n=t.getBoundingClientRect(),a=e.touches?e.touches[0]:e;return[(a.clientX-n.left)*(t.width/n.width),(a.clientY-n.top)*(t.height/n.height)]}function d(e){for(var t=o(e),n=-1,a=1e9,r=0;4>r;r++){var d=C[r][0]-t[0],l=C[r][1]-t[1],c=d*d+l*l;a>c&&(a=c,n=r)}8100>a&&(i=n),e.preventDefault()}function s(e){if(!(0>i)){var n=o(e);C[i]=[Math.max(0,Math.min(t.width,n[0])),Math.max(0,Math.min(t.height,n[1]))],r(),e.preventDefault()}}t.addEventListener("touchstart",function(e){d(e)},{passive:!1}),t.addEventListener("touchmove",function(e){s(e)},{passive:!1}),t.addEventListener("touchend",function(){i=-1}),t.addEventListener("mousedown",d),t.addEventListener("mousemove",s),t.addEventListener("mouseup",function(){i=-1}),r(),c.appendChild(t),h.innerHTML="";var u=document.createElement("div");u.textContent="اسحب الزوايا الأربع إلى حواف الفاتورة",u.style.cssText="width:100%;text-align:center;color:#9fb3c8;font:600 13px system-ui,sans-serif;margin-bottom:2px",h.appendChild(u);var f=S("تطبيق ✓","background:#2f7cf6;color:#fff;padding:11px 24px;font-size:15px"),p=S("رجوع","background:#22303c;color:#cfd8e3");f.onclick=function(){M.quad=C.map(function(e){return[e[0]/a,e[1]/a]}),w=!1,A(M),H(M),F()},p.onclick=function(){w=!1,H(M)},h.appendChild(f),h.appendChild(p)}function U(){g&&cancelAnimationFrame(g),g=null,p&&(p.getTracks().forEach(function(e){e.stop()}),p=null),W(),e.style.display="none",v&&window.DLScanDone&&window.DLScanDone(v)}window.DLScan={open:function(g){e||function(){(e=document.createElement("div")).style.cssText="position:fixed;top:0;left:0;right:0;bottom:0;background:#000;z-index:2147483000;display:none;flex-direction:column;direction:rtl";var p=document.createElement("div");p.style.cssText="position:absolute;top:0;left:0;right:0;display:flex;justify-content:space-between;align-items:center;padding:12px 14px;z-index:5",d=S("✕","background:rgba(0,0,0,.5);color:#fff;font-size:17px;padding:7px 13px"),o=S("الالتقاط اليدوي","background:rgba(255,255,255,.9);color:#111"),p.appendChild(d),p.appendChild(o),(n=document.createElement("div")).style.cssText="flex:1;position:relative;overflow:hidden;background:#000",(t=document.createElement("video")).setAttribute("playsinline",""),t.muted=!0,t.style.cssText="width:100%;height:100%;object-fit:cover;display:block",(a=document.createElement("canvas")).style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none",(r=document.createElement("div")).style.cssText="position:absolute;top:62px;left:50%;transform:translateX(-50%);background:rgba(0,0,0,.6);color:#fff;padding:8px 16px;border-radius:20px;font:600 13px system-ui,sans-serif;white-space:nowrap",r.textContent="ضع الفاتورة داخل الإطار",n.appendChild(t),n.appendChild(a),n.appendChild(r),n.appendChild(p);var g=document.createElement("div");g.style.cssText="flex:none;background:#000;padding:14px;display:flex;align-items:center;justify-content:center;gap:18px",(i=document.createElement("button")).type="button",i.style.cssText="width:66px;height:66px;border-radius:50%;background:#fff;border:5px solid #bbb",(s=document.createElement("div")).style.cssText="position:absolute;left:14px;bottom:14px;display:flex;gap:6px;align-items:flex-end",u=S("التالي ✓","background:#2f7cf6;color:#fff;padding:12px 22px;font-size:15px;display:none"),g.appendChild(i),g.style.position="relative",g.appendChild(s);var w=document.createElement("div");w.style.cssText="position:absolute;right:14px;bottom:14px",w.appendChild(u),g.appendChild(w),(l=document.createElement("div")).style.cssText="display:none;position:absolute;top:0;left:0;right:0;bottom:0;background:#0d1117;z-index:10;flex-direction:column;direction:rtl",(c=document.createElement("div")).style.cssText="flex:1;display:flex;align-items:center;justify-content:center;overflow:hidden;padding:10px",(h=document.createElement("div")).style.cssText="flex:none;display:flex;gap:8px;padding:12px;justify-content:center;flex-wrap:wrap;background:#0d1117",l.appendChild(c),l.appendChild(h),e.appendChild(n),e.appendChild(g),e.appendChild(l),document.body.appendChild(e),d.onclick=function(){U()},o.onclick=function()z't􅴱ѕ ѕbfbfbf bb܃bfbff bbf(bfbfbf bb܃bff+bf#f(չѥСإmtѠ$ȹѕ ѕbfbbbfbbbfbf bf$ffbfbbbԹչѥTձı\屔􉙱٥ѽȹ٥̘٥ѽȹ٥̹U͕5٥ѽȹ٥̹U͕5٥홅5艕٥ɽЉݥѠՑѡչѥɕɸйɍ=й䠥ѡչѥHэչѥȹѕ ѕbbbfGbăfbbbffbff+bb耈񔹵ͅȹѕ ѕbffbff+bbbf+băfbbf#fbff(fbbbffbbfbAչѥɕɸСmuչѥمȁСmtɕɸйѠ܁ mġХt艅ѥձչѥ혹͕Сmt