1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[187],{187:(e,t,n)=>{n.r(t),n.d(t,{BuilderCanvas:()=>c});var l=n(99609),r=n(44089),i=n(36877),a=n(71864);function o(e){var t,n,r,o;let{field:s,pageWidth:c,pageHeight:u,zoom:d,selected:p,showSample:h,sample:f,defaultFontSize:g,offPage:x,onPointerDown:m,onSelect:w}=e,b="table"===s.field_type,y=b?Math.max(1,Number(null!=(n=null==(t=s.table_config)?void 0:t.rows)?n:1)):0,v=(null!=(r=s.font_size)?r:g)*d,N="static_text"===s.field_type?s.static_text||"Static text":"input"===s.field_type?s.input_default||"<".concat(s.label||s.input_key||"Input",">"):h&&f?f:s.label||s.field_key||"Field",k=s.wrap_text?N:N.replace(/[ \t]*[\r\n]+[ \t]*/g," "),_=(0,i.useRef)(null);return(0,i.useLayoutEffect)(()=>{let e=_.current,t=null==e?void 0:e.parentElement;if(!e||!t||(e.style.fontSize="".concat(v,"px"),!s.shrink_to_fit))return;let n=()=>e.scrollWidth<=e.clientWidth&&e.scrollHeight<=t.clientHeight;if(n())return;let l=4*d,r=l,i=v,a=l;for(let t=0;t<8;t+=1){let t=(r+i)/2;e.style.fontSize="".concat(t,"px"),n()?(a=t,r=t):i=t}e.style.fontSize="".concat(a,"px")},[v,d,k,s.shrink_to_fit,s.wrap_text,s.w,s.h,c,u]),(0,l.jsxs)("button",{type:"button","aria-label":s.label||s.field_key||"Field","aria-pressed":p,onClick:e=>{e.stopPropagation(),w()},onPointerDown:e=>m(e,"move"),className:(0,a.cn)("absolute cursor-move select-none rounded-[2px] border leading-tight",p?"z-20 border-primary bg-primary/15 ring-2 ring-primary":"z-10 border-sky-500/70 bg-sky-500/10 hover:bg-sky-500/20",x&&"border-destructive bg-destructive/15"),style:{left:"".concat(s.x*c,"px"),top:"".concat(s.y*u,"px"),width:"".concat(s.w*c,"px"),height:"".concat(s.h*u,"px")},children:[(0,l.jsx)("span",{className:(0,a.cn)("flex h-full items-center overflow-hidden",s.wrap_text?"whitespace-pre-wrap":"whitespace-nowrap"),style:{paddingInline:"".concat(4*d,"px"),justifyContent:s.wrap_text?"flex-start":"center"===s.align?"center":"right"===s.align?"flex-end":"flex-start",direction:s.text_direction,fontWeight:s.bold?700:400,fontStyle:s.italic?"italic":"normal",textDecoration:s.underline?"underline":"none",color:null!=(o=s.color)?o:void 0},children:(0,l.jsx)("span",{ref:_,className:(0,a.cn)(s.wrap_text?"w-full break-words":"truncate"),style:{textAlign:s.wrap_text?s.align:void 0},children:k})}),b&&y>1?Array.from({length:y-1},(e,t)=>(0,l.jsx)("span",{className:"pointer-events-none absolute inset-x-0 border-t border-dashed border-sky-500/60",style:{to
1p:"".concat((t+1)/y*100,"%")}},t)):null,s.all_pages?(0,l.jsx)("span",{className:"pointer-events-none absolute -top-1.5 -right-1.5 rounded-sm bg-emerald-600 px-1 text-[9px] font-semibold text-white",children:"ALL"}):null,p?(0,l.jsx)("span",{onPointerDown:e=>{e.stopPropagation(),m(e,"resize")},className:"absolute -right-1.5 -bottom-1.5 size-3 cursor-se-resize rounded-full border border-white bg-primary","aria-hidden":!0}):null]})}var s=n(32427);function c(e){let{fileUrl:t,fields:n,selectedId:c,zoom:d,showSample:p,samples:h,pageCount:f,defaultFontSize:g,onSelect:x,onChange:m,onDropField:w,onDelete:b,onPagesLoaded:y}=e,[v,N]=(0,i.useState)([]),[k,_]=(0,i.useState)(null),[j,E]=(0,i.useState)(!0),[D,M]=(0,i.useState)({x:null,y:null}),S=(0,i.useRef)(new Map),P=(0,i.useRef)(null),z=(0,i.useRef)(y);(0,i.useEffect)(()=>{z.current=y},[y]),(0,i.useEffect)(()=>{let e=!1;return E(!0),_(null),(0,s.v9)(t).then(s.VJ).then(t=>{e||(N(t),z.current(t.map(e=>({page:e.pageNumber,width:e.width,height:e.height,rotation:e.rotation}))))}).catch(t=>{e||_(t instanceof Error?t.message:"Could not open this PDF")}).finally(()=>{e||E(!1)}),()=>{e=!0}},[t]),(0,i.useEffect)(()=>{let e=[];for(let t of v){let n=S.current.get(t.pageNumber);if(!n)continue;let l=(0,s.B7)(t,n,d);l&&e.push(l)}return()=>{for(let t of e)try{t.cancel()}catch(e){}}},[v,d]);let A=v.length,C=(0,i.useMemo)(()=>{let e=new Map;for(let l of n){let n=l.page>A?A:l.page;for(let r of l.all_pages?v.map(e=>e.pageNumber):[n]){var t;e.has(r)||e.set(r,[]),null==(t=e.get(r))||t.push(l)}}return e},[n,v,A]),I=(0,i.useCallback)((e,t,n,l,r,i)=>{var a;e.preventDefault(),e.stopPropagation(),x(t.clientId);let o=e.clientX,s=e.clientY,c={x:t.x,y:t.y,w:t.w,h:t.h},p=(null!=(a=C.get(i))?a:[]).filter(e=>e.clientId!==t.clientId),h=null,f=null,g=e=>{let i=(e.clientX-o)/d/l,a=(e.clientY-s)/d/r;if("move"===n){let e=u(c.x+i,0,1-c.w),n=u(c.y+a,0,1-c.h),o=function(e,t,n,l,r,i,a){let o=6/i,s=6/a,c=e,u=t,d=null,p=null;for(let i of r){for(let t of[i.x,i.x+i.w])Math.abs(e-t)<o?(c=t,d=t):Math.abs(e+n-t)<o&&(c=t-n,d=t);for(let e of[i.y,i.y+i.h])Math.abs(t-e)<s?(u=e,p=e):Math.abs(t+l-e)<s&&(u=e-l,p=e)}return{x:c,y:u,guides:{x:d,y:p}}}(e,n,c.w,c.h,p,l*d,r*d);e=o.x,n=o.y,M(o.guides),m(t.clientId,{x:e,y:n})}else{let e=u(c.w+i,8/l,1-c.x),n=u(c.h+a,8/r,1-c.y);m(t.clientId,{w:e,h:n})}},w=e=>{f=e,null===h&&(h=window.requestAnimationFrame(()=>{h=null,f&&g(f)}))},b=()=>{null!==h&&window.cancelAnimationFrame(h),f&&g(f),M({x:null,y:null}),window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",b)};window.addEventListener("pointermove",w),window.addEventListener("pointerup",b)},[C,m,x,d]);return((0,i.useEffect)(()=>{let e=e=>{var t;let l=e.target;if(l&&["INPUT","TEXTAREA","SELECT"].includes(l.tagName))return;if("Escape"===e.key)return void x(null);if(!c)return;let r=n.find(e=>e.clientId===c);if(!r)return;let i=null!=(t=v.find(e=>e.pageNumber===r.page))?t:v[0];if(!i)return;if("Delete"===e.key||"Backspace"===e.key){e.preventDefault(),b(c);return}let a=e.shiftKey?10:1,o={ArrowLeft:[-a/i.width,0],ArrowRight:[a/i.width,0],ArrowUp:[0,-a/i.height],ArrowDown:[0,a/i.height]}[e.key];o&&(e.preventDefault(),m(c,{x:u(r.x+o[0],0,1-r.w),y:u(r.y+o[1],0,1-r.h)}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[c,n,v,m,b,x]),j)?(0,l.jsxs)("div",{className:"flex h-full items-center justify-center gap-2 text-sm text-muted-foreground",children:[(0,l.jsx)(r.A,{className:"size-4 animate-spin"})," Loading documentâ¦"]}):k?(0,l.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-destructive",children:k}):(0,l.jsxs)("div",{ref:P,className:"flex flex-col items-center gap-6 p-6",children:[v.map(e=>{var t;let n=e.width*d,r=e.height*d,i=null!=(t=C.get(e.pageNumber))?t:[];return(0,l.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,l.jsxs)("div",{className:"text-xs text-muted-foreground",children:["Page ",e.pageNumber," of ",f]}),(0,l.jsxs)("div",{className:"relative bg-white shadow-sm ring-1 ring-border",style:{width:n,height:r},onDragOver:e=>e.preventDefault(),onDrop:t=>{t.preventDefault();let l=t.currentTarget.getBoundingClientRect();w(e.pageNumber,u((t.clientX-l.left)/n,0,1),u((t.clientY-l.top)/r,0,1))},children:[(0,l.jsx)("canvas",{ref:t=>{t?S.current.set(e.pageNumber,t):S.current.delete(e.pageNumber)},className:"pointer-events-none absolute inset-0"}),(0,l.jsx)("button",{type:"button","aria-label":"Deselect field (page ".concat(e.pageNumber,")"),className:"absolute inset-0 z-0 cursor-default",onClick:()=>x(null)}),null!==D.x?(0,l.jsx)("div",{className:"pointer-events-none absolute inset-y-0 w-px bg-pink-500",style:{left:D.x*n}}):null,null!==D.y?(0,l.jsx)("div",{className:"pointer-events-none absolute inset-x-0 h-px bg-pink-500",style:{to
1p:D.y*r}}):null,i.map(t=>(0,l.jsx)(o,{field:t,pageWidth:n,pageHeight:r,zoom:d,selected:t.clientId===c,showSample:p,sample:t.field_key?h[t.field_key]:null,defaultFontSize:g,offPage:t.page>f,onSelect:()=>x(t.clientId),onPointerDown:(n,l)=>I(n,t,l,e.width,e.height,e.pageNumber)},"".concat(t.clientId,"-").concat(e.pageNumber)))]})]},e.pageNumber)}),(0,l.jsx)("div",{className:(0,a.cn)("h-4",0===v.length&&"hidden")})]})}function u(e,t,n){return Math.min(Math.max(e,t),Math.max(t,n))}},32427:(e,t,n)=>{n.d(t,{B7:()=>o,VJ:()=>a,v9:()=>i});let l=null;async function r(){return l||(l=Promise.all([n.e(33582),n.e(58816)]).then(n.bind(n,83604)).then(e=>(e.GlobalWorkerOptions.workerSrc=new n.U(n(61034)).toString(),e))),l}async function i(e){return(await r()).getDocument({url:e}).promise}async function a(e){let t=[];for(let n=1;n<=e.numPages;n+=1){let l=await e.getPage(n),r=l.getViewport({scale:1});t.push({pageNumber:n,width:r.width,height:r.height,rotation:r.rotation,page:l})}return t}function o(e,t,n){let l=t.getContext("2d");if(!l)return null;let r=Math.max(window.devicePixelRatio||1,2),i=e.page.getViewport({scale:n});t.width=Math.floor(i.width*r),t.height=Math.floor(i.height*r),t.style.width="".concat(Math.floor(i.width),"px"),t.style.height="".concat(Math.floor(i.height),"px");let a=e.page.render({canvas:t,canvasContext:l,viewport:i,transform:1===r?void 0:[r,0,0,r,0,0]});return{cancel:()=>a.cancel()}}},61034:(e,t,n)=>{e.exports=n.p+"static/media/pdf.worker.min.d35b48ba.mjs"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.