1import{t as e}from"./H_PjY6_i.js";var t=e({default:()=>l}),o=["image/jpeg","image/png","image/webp"],i={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"},r=5242880,s=512,n=e=>{if(e.type&&o.includes(e.type))return e.type;const t=e.name?.split(".").pop()?.toLowerCase();return t&&i[t]?i[t]:e.type||""},a=()=>"undefined"==typeof window?null:(window.__teachingJobUploadState||(window.__teachingJobUploadState={promises:new Map,waitForPending:async()=>{const e=Array.from(window.__teachingJobUploadState.promises.values());await Promise.allSettled(e)}}),window.__teachingJobUploadState);function l(e={}){return{photoUrl:e.photoUrl||"",photoAlt:e.photoAlt||"Candidate photo",presignUrl:e.presignUrl||"/resumes/photo/presign",confirmUrl:e.confirmUrl||"",hiddenInputName:e.hiddenInputName||"",uploadedKey:e.uploadedKey||"",updatedEvent:e.updatedEvent||"candidate-profile-photo-updated",file:null,fileMimeType:"",sourceUrl:"",zoom:1,offsetX:0,offsetY:0,isCropOpen:!1,isUploading:!1,error:"",get csrfToken(){return document.querySelector('meta[name="csrf-token"]')?.content||""},chooseFile(){this.$refs.photoInput?.click()},handleFile(e){if(!e)return;this.error="";const t=n(e);o.includes(t)?e.size>r?this.error="Photo size must be less than 5MB.":(this.clearSourceUrl(),this.file=e,this.fileMimeType=t,this.sourceUrl=URL.createObjectURL(e),this.zoom=1,this.offsetX=0,this.offsetY=0,window.dispatchEvent(new CustomEvent("close-searchable-selects")),document.body.classList.add("overflow-hidden"),this.isCropOpen=!0):this.error="Please upload a JPG, PNG, or WEBP image."},closeCrop(e=!1){this.isUploading&&!e||(this.isCropOpen=!1,document.body.classList.remove("overflow-hidden"),this.file=null,this.fileMimeType="",this.clearSourceUrl(),this.$refs.photoInput&&(this.$refs.photoInput.value=""))},async uploadCroppedPhoto(){if(!this.file)return;const e=a(),t=`resume-photo:${this.hiddenInputName||this.confirmUrl||this.presignUrl}`,o=this._uploadCroppedPhoto();e&&e.promises.set(t,o);try{await o}finally{e&&e.promises.delete(t)}},async _uploadCroppedPhoto(){this.isUploading=!0,this.error="";try{const e=await this.cropFile(),{upload_url:t,key:o}=await this.presign(e.type||this.fileMimeType);if(!(await fetch(t,{method:"PUT",body:e,headers:{"Content-Type":e.type}})).ok)throw new Error("Photo upload failed. Please try again.");if(!this.confirmUrl)return this.photoUrl&&this.photoUrl.startsWith("blob:")&&URL.revokeObjectURL(this.photoUrl),this.uploadedKey=o,this.photoUrl=URL.createObjectURL(e),void this.closeCrop(!0);const i=await fetch(this.confirmUrl,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":this.csrfToken,Accept:"application/json"},body:JSON.stringify({key:o,original_name:e.name})});if(!i.ok){const e=await i.json().catch(()=>({}));throw new Error(e.message||"Photo could not be saved. Please try again.")}const r=await i.json();this.photoUrl=this.withCacheBust(r.url||this.photoUrl),this.publishPhotoUrl(this.photoUrl),this.closeCrop(!0)}catch(e){this.error=e instanceof Error?e.message:"Photo could not be saved. Please try again."}finally{this.isUploading=!1}},async presign(e){const t=await fetch(this.presignUrl,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":this.csrfToken,Accept:"application/json"},body:JSON.stringify({mime_type:e})});if(!t.ok){const e=await t.json().catch(()=>({}));throw new Error(e.message||"Upload could not be prepared. Please try again.")}return t.json()},async cropFile(){const e=await this.loadImage(this.sourceUrl),t=document.createElement("canvas");t.width=s,t.height=s;const o=t.getContext("2d");if(!o)throw new Error("Your browser could not prepare this photo.");o.fillStyle="#ffffff",o.fillRect(0,0,s,s);const i=Math.max(s/e.naturalWidth,s/e.naturalHeight)*Number(this.zoom||1),r=e.naturalWidth*i,n=e.naturalHeight*i,a=(s-r)/2+2*Number(this.offsetX||0),l=(s-n)/2+2*Number(this.offsetY||0);o.drawImage(e,a,l,r,n);const h=this.fileMimeType||this.file.type||"image/jpeg",p=await new Promise(e=>{t.toBlob(e,h,.9)});if(!(p instanceof Blob))throw new Error("Your browser could not crop this photo.");const c=this.extensionForType(h);return new File([p],`profile-photo.${c}`,{type:p.type||h,lastModified:Date.now()})},loadImage:e=>new Promise((t,o)=>{const i=new Image;i.onload=()=>t(i),i.onerror=()=>o(new Error("Photo preview could not be loaded.")),i.src=e}),extensionForType:e=>"image/png"===e?"png":"image/webp"===e?"webp":"jpg",withCacheBust(e){if(!e)return"";
1try{if(new URL(e,window.location.href).searchParams.has("X-Amz-Signature"))return e}catch{return e}return`${e}${e.includes("?")?"&":"?"}v=${Date.now()}`},publishPhotoUrl(e){window.dispatchEvent(new CustomEvent(this.updatedEvent,{detail:{url:e}}))},clearSourceUrl(){this.sourceUrl&&(URL.revokeObjectURL(this.sourceUrl),this.sourceUrl="")}}}export{t as n,l as t};
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.