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modelContext"in navigator&&e.push(navigator.modelContext),e},c=["createField","deleteFields","deletePages","detectFields","download","focusField","getAnnotatedPage","getDocumentContent","getFields","goTo","loadDocument","movePage","rotatePage","selectTool","setFieldValue","submit"],u=e=>e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`),p=e=>e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase()),m=(e,t)=>{if(Array.isArray(e)){return e.map(e=>m(e,t))}if((e=>{if("object"!=typeof e||null===e||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t})(e)){const n={};for(const[o,i]of Object.entries(e)){const e=t(o);"__proto__"!==e&&(n[e]=m(i,t))}return n}return e},f={debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}},g=e=>{const t=t=>(n,o)=>{try{Promise.resolve(e[t](n,o)).catch(()=>{})}catch{}};return{debug:t("debug"),info:t("info"),warn:t("warn"),error:t("error")}},h=e=>{if("object"!=typeof e||null===e||!("success"in e))return!1;if(!0===e.success)return!0;if(!1===e.success){if(!("error"in e))return!1;const t=e.error;return"object"==typeof t&&null!==t&&("code"in t&&"message"in t&&("string"==typeof t.code&&"string"==typeof t.message&&/^(bad_request|forbidden|unexpected):/.test(t.code)))}return!1},b=6e4,y=()=>"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`req_${Math.random().toString(36).slice(2)}_${Date.now().toString(36)}`,w=({getIframe:e,editorOrigin:t,logger:n=f,onDispose:o,onStateChange:i,webMCP:r})=>{const a=g(n),s=new Map;let d={kind:"booting"},c=null,w=!1;const v=e=>a.error("iframe.listener_threw",{message:e instanceof Error?e.message:String(e)}),_=()=>{const e=new Set;return{subscribe:t=>(e.add(t),()=>e.delete(t)),emit:t=>{for(const n of e)try{n(t)}catch(e){v(e)}},clear:()=>e.clear()}},E={EDITOR_READY:_(),DOCUMENT_LOADED:_(),PAGE_FOCUSED:_(),SUBMISSION_SENT:_()},D=new AbortController,T=(e=>{if(void 0===e)return{enabled:!1};switch(e.enabled){case!1:return{enabled:!1};case!0:return{enabled:!0,exclude:e.exclude??[]};default:return{enabled:!1}}})(r);let x=!1;const S=e=>{d=e,i?.(e),"booting"!==e.kind&&T.enabled&&!x&&(0!==l().length?(x=!0,Promise.resolve().then(function(){return le}).then(({registerWebMCPTools:e})=>{e({dispatch:(e,t)=>F(e,t,"wire"),exclude:T.exclude,signal:D.signal,logger:a})||(x=!1)}).catch(e=>{x=!1,a.error("webmcp.load_failed",{message:e instanceof Error?e.message:String(e)})})):a.info("webmcp.unavailable",{reason:"no_model_context"}))},F=(n,o,i)=>new Promise(r=>{if(w)return void r({success:!1,error:{code:"unexpected:bridge_disposed",message:"Editor bridge was disposed"}});const d=e();if(null===d||null===d.contentWindow)return void r({success:!1,error:{code:"unexpected:iframe_not_mounted",message:"Editor iframe is not mounted"}});const l=y(),c=Date.now();a.info("iframe.request_sent",{request_id:l,type:n,timeout_ms:b});const p=setTimeout(()=>{s.delete(l),a.error("iframe.request_timed_out",{request_id:l,type:n,elapsed_ms:Date.now()-c}),r({success:!1,error:{code:"unexpected:timeout",message:`Editor request '${n}' timed out after 60000ms`}})},b);s.set(l,{resolve:e=>r((e=>e.success?{success:!0,data:e.data}:e)(e)),resultShape:i,wireType:n,startedAtMs:c,timeoutId:p});try{const e=JSON.stringify({type:n,request_id:l,data:(f=o,m(f,u))});d.contentWindow.postMessage(e,t),a.debug("iframe.request_posted",{request_id:l,type:n,char_count:e.length})}catch(e){clearTimeout(p),s.delete(l),r({success:!1,error:{code:"unexpected:unknown",message:`Failed to post '${n}': ${e instanceof Error?e.message:String(e)}`}})}var f}),L=(e,t)=>F(e,t,"sdk"),P=new Set;let O=null;const U=()=>{null!==O&&(clearInterval(O),O=null),P.clear()},C=e=>{switch(d.kind){case"documentLoaded":return void("editor_ready_event"===e&&S({kind:"editorReady"}));case"booting":return void S({kind:"editorReady"});case"editorReady":return}};let R=null;const A=()=>{null!==R&&(clearTimeout(R),R=null)},I=()=>{"documentLoaded"!==d.kind&&(A(),U(),S({kind:"documentLoaded",documentId:c}))},M=()=>{const n=e();if(null===n||null===n.contentWindow)return;const o=y();try{n.contentWindow.postMessage(JSON.stringify({type:"GET_FIELDS",request_id:o,data:{}}),t),P.add(o)}catch{}};R=setTimeout(()=>{R=null,"booting"===d.kind&&a.warn("editor.ready_fallback_timeout",{timeout_ms:3e4}),C("fallback"),U()},3e4),M(),O=setInterval(M,500);const j=n=>{if(n.origin!==t)return;const o=e();if(null===o||n.source!==o.contentWindow)return;const i=(()=>{if("string"!=typeof n.data)return null;try{const e=JSON.parse(n.data);return"object"==typeof e&&null!==e?e:null}catch{return null}})();if(null===i)return;if(a.debug("iframe.message_received",{type:i.type,request_id:i.request_id}),"EDITOR_READY"===i.type)return C("editor_ready_event"),void E.EDITOR_READY.emit({});if("DOCUMENT_LOADED"===i.type){const e=i.data?.document_id;return"string"==typeof e&&""!==e&&(E.DOCUMENT_LOADED.emit({document_id:e}),c!==e&&(c=e,"documentLoaded"===d.kind))?void S({kind:"documentLoaded",documentId:c}):void I()}if("SUBMISSION_SENT"===i.type){const e=(e=>{const t=e?.document_id,n=e?.submission_id;return"string"==typeof t&&"string"==typeof n?{document_id:t,submission_id:n}:null})(i.data);return void(null!==e&&E.SUBMISSION_SENT.emit(e))}if("PAGE_FOCUSED"===i.type){const e=(e=>{const t=e?.previous_page,n=e?.current_page,o=e?.total_pages;return null!==t&&"number"!=typeof t||"number"!=typeof n||"number"!=typeof o?null:{previous_page:t,current_page:n,total_pages:o}})(i.data);return void(null!==e&&E.PAGE_FOCUSED.emit(e))}if("REQUEST_RESULT"!==i.type)return;const r="string"==typeof i.data?.request_id?i.data.request_id:null;if(null===r)return;if(P.has(r)){P.delete(r),C("probe");const e=i.data?.result;return void(h(e)&&!0===e.success&&I())}const l=s.get(r);if(void 0===l)return void a.debug("iframe.request_unmatched",{request_id:r});s.delete(r),clearTimeout(l.timeoutId);const u=i.data?.result,f=(()=>{if(!h(u))return{success:!1,error:{code:"unexpected:malformed_result",message:"REQUEST_RESULT payload had no valid result"}};if(!0===u.success&&!("data"in u))return{success:!0,data:null};switch(l.resultShape){case"wire":return u;case"sdk":{const e=m(u,p);return h(e)?e:{success:!1,error:{code:"unexpected:malformed_result",message:"REQUEST_RESULT payload had no valid result"}}}default:return l.resultShape,u}})();a.info("iframe.request_received",{request_id:r,type:l.wireType,elapsed_ms:Date.now()-l.startedAtMs,success:f.success}),l.resolve(f)};window.addEventListener("message",j);return{actions:{createField:e=>L("CREATE_FIELD",e),deleteFields:e=>L("DELETE_FIELDS",e??{}),deletePages:e=>L("DELETE_PAGES",e),detectFields:()=>L("DETECT_FIELDS",{}),download:()=>L("DOWNLOAD",{}),focusField:e=>L("FOCUS_FIELD",e),getAnnotatedPage:e=>L("GET_ANNOTATED_PAGE",e),getDocumentContent:e=>L("GET_DOCUMENT_CONTENT",e??{}),getFields:()=>L("GET_FIELDS",{}),goTo:e=>L("GO_TO",e),loadDocument:e=>L("LOAD_DOCUMENT",e),movePage:e=>L("MOVE_PAGE",e),rotatePage:e=>L("ROTATE_PAGE",e),selectTool:e=>L("SELECT_TOOL",e),setFieldValue:e=>L("SET_FIELD_VALUE",e),submit:e=>L("SUBMIT",e)},events:{on:(e,t)=>E[e].subscribe(t)},lifecycle:{dispose:()=>{if(!w){w=!0,D.abort(),window.removeEventListener("message",j),A(),U();for(const{timeoutId:e,resolve:t}of s.values())clearTimeout(e),t({success:!1,error:{code:"unexpected:bridge_disposed",message:"Editor bridge was disposed"}});s.clear();for(const e of Object.values(E))e.clear();o?.()}}}}},v=class extends Error{code;constructor(e,t){super(t),this.name="EmbedConfigError",this.code=e}},_=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/,E=52428800,D=e=>e.includes(".nil")||e.includes("localhost"),T=e=>e instanceof File?"a File":e instanceof Blob?"a Blob":null===e?"null":Array.isArray(e)?"an array":"a "+typeof e,x=new Set(c),S=new Set(Object.keys({enabled:!0,exclude:!0})),F=e=>{if(void 0===e)return;if("object"!=typeof e||null===e||Array.isArray(e))throw new v("invalid_document",`document must be an object with one of url / dataUrl / file (received ${T(e)}).`);const t=["url"in e?"url":null,"dataUrl"in e?"dataUrl":null,"file"in e?"file":null].filter(e=>null!==e);if(1!==t.length){const e=0===t.length?"none":t.join(" + ");throw new v("invalid_document",`document needs exactly one source: { url: string }, { dataUrl: string }, or { file: Blob } (got ${e}).`)}"url"in e?(e=>{if("string"!=typeof e){const t=e instanceof Blob?" To embed a Blob or File, use document: { file } instead.":"";throw new v("invalid_document",`document.url must be a string (received ${T(e)}).${t}`)}const t=(()=>{try{return new URL(e)}catch{return null}})();if(null===t)throw new v("invalid_document",`document.url must be a valid absolute URL (received '${e}').`);if("data:"===t.protocol)throw new v("invalid_document","document.url is a data URL. Use document: { dataUrl } instead.");if("blob:"===t.protocol)throw new v("invalid_document","document.url is a blob: URL. Pass the Blob itself via document: { file } instead.");if("https:"!==t.protocol&&"http:"!==t.protocol)throw new v("invalid_document",`document.url must be an http(s) URL (received '${e}').`)})(e.url):"dataUrl"in e?(e=>{if("string"!=typeof e){const t=e instanceof Blob?" To embed a Blob or File, use document: { file } instead.":"";throw new v("invalid_document",`document.dataUrl must be a string (received ${T(e)}).${t}`)}if(/^https?:\/\//i.test(e))throw new v("invalid_document","document.dataUrl looks like an http(s) URL. Use document: { url } instead.");if(!e.startsWith("data:"))throw new v("invalid_document","document.dataUrl must be a data URL (it should start with 'data:').")})(e.dataUrl):"file"in e&&(e=>{if(!(e instanceof Blob)){const t="string"==typeof e?" For a URL or a data URL, use document: { url } or document: { dataUrl }.":"";throw new v("invalid_document",`document.file must be a Blob or File (received ${T(e)}).${t}`)}})(e.file)},L=/^\/(?:[a-z]{2}\/)?documents\/[^/]+\/?$/,P=({editorOrigin:e,locale:t,encodedContext:n,hasDocumentUrl:o,openFallbackUrl:i})=>{const r=new URL(`/${t??"en"}/editor`,e);return null!==n&&r.searchParams.set("context",n),o&&r.searchParams.set("loadingPlaceholder","true"),null!==i&&r.searchParams.set("open",i),r.href},O=e=>new Promise((t,n)=>{const o=new FileReader;o.onload=()=>t("string"==typeof o.result?o.result:""),o.onerror=()=>n(o.error??new Error("Failed to read document")),o.readAsDataURL(e)}),U=async(e,t)=>{try{const n=await fetch(e,{method:"GET",credentials:"same-origin",signal:t});if(!n.ok)return await(n.body?.cancel().catch(()=>{})),null;const o=n.headers.get("content-length");if(null!==o&&Number(o)>E)return await(n.body?.cancel().catch(()=>{})),null;const i=n.body;if(null===i)return null;const r=await(async(e,t)=>{const n=e.getReader(),o=[];let i=0;for(;;){const{done:e,value:r}=await n.read();if(e)return o;if(i+=r.byteLength,i>t)return await n.cancel(),null;o.push(new Uint8Array(r))}})(i,E);if(null===r)return null;const a=n.headers.get("content-type")??"application/pdf";return await O(new Blob(r,{type:a}))}catch{return null}},C=()=>{let e=()=>{};const t=new Promise(t=>{e=t});return{onStateChange:t=>{"booting"!==t.kind&&e()},whenReady:e=>{t.then(e)}}},R=e=>{const{embed:t,embedDocument:n,signal:o,safeLogger:i,onHostFetchFail:r,whenReady:a}=e,s=((e,t)=>"dataUrl"in e?Promise.resolve(e.dataUrl):"file"in e?O(e.file).catch(()=>null):U(e.url,t))(n,o),d=(e=>void 0!==e.name?e.name:"url"in e?(e=>{const[t]=e.substring(e.lastIndexOf("/")+1).split("?");return t??""})(e.url):"file"in e&&e.file instanceof File?e.file.name:void 0)(n);a(()=>{(async()=>{const e=await s;if(o.aborted)return;if(null===e)return void 0!==r?void r():void i.error("load_document_failed",{code:"unexpected:unknown",message:"could not resolve the document to a data URL; ?open fallback is unavailable on an attached iframe"});const a=await t.actions.loadDocument({dataUrl:e,name:d,page:n.page});a.success||i.error("load_document_failed",{code:a.error.code,message:a.error.message})})()})},A=(e,t,{document:n,locale:o,context:i,iframeAttrs:r,logger:a=f,webMCP:s},d)=>{const l=void 0!==n&&"url"in n,c=(e=>{if(void 0===e)return null;try{return encodeURIComponent(btoa(JSON.stringify(e)))}catch{return null}})(i),u=document.createElement("iframe");if(u.title=r?.title??"SimplePDF",u.setAttribute("referrerPolicy","no-referrer-when-downgrade"),u.setAttribute("allow",r?.allow??"clipboard-read; clipboard-write; web-share"),void 0!==r?.sandbox){u.setAttribute("sandbox",r.sandbox);const e=r.sandbox.split(/\s+/).map(e=>e.toLowerCase());e.includes("allow-downloads")||console.warn('[SimplePDF] The iframe "sandbox" attribute is missing "allow-downloads": the editor\'s Download button will be silently blocked by the browser. Add "allow-downloads" to your sandbox tokens.'),e.includes("allow-modals")||console.warn('[SimplePDF] The iframe "sandbox" attribute is missing "allow-modals": the editor\'s "Print document" action will be silently ignored by the browser. Add "allow-modals" to your sandbox tokens.')}void 0!==r?.className&&(u.className=r.className),u.style.border="0",u.style.width="100%",u.style.height="100%",void 0!==r?.style&&Object.assign(u.style,r.style),u.src=null!==d?(()=>{const e=new URL(d.url.href);return null!==c&&e.searchParams.set("context",c),e.href})():P({editorOrigin:t,locale:o,encodedContext:c,hasDocumentUrl:l,openFallbackUrl:null}),e.appendChild(u);const p=new AbortController,m=g(a),h=C(),b=w({getIframe:()=>u,editorOrigin:t,logger:m,onStateChange:h.onStateChange,onDispose:()=>{p.abort(),u.remove()},webMCP:s});return void 0!==n&&null===d&&R({embed:b,embedDocument:n,signal:p.signal,safeLogger:m,whenReady:h.whenReady,onHostFetchFail:()=>{"url"in n&&(u.src=P({editorOrigin:t,locale:o,encodedContext:c,hasDocumentUrl:!1,openFallbackUrl:n.url}))}}),b},I=e=>{if("object"!=typeof e||!e)throw new v("invalid_config",`createEmbed expects a config object { target, companyIdentifier, ... } (received ${T(e)}).`);if((e=>{if("string"!=typeof e||""===e)throw new v("invalid_company_identifier","companyIdentifier is required: the .simplepdf.com subdomain from your SimplePDF account.");if(!_.test(e))throw new v("invalid_company_identifier",`companyIdentifier '${e}' is not a valid DNS label (lowercase letters, digits, internal hyphens)`)})(e.companyIdentifier),void 0!==e.baseDomain&&"string"!=typeof e.baseDomain)throw new v("invalid_config",`baseDomain must be a string (received ${T(e.baseDomain)}).`);F(e.document),(e=>{if(void 0===e)return;const t=()=>new v("invalid_config",`webMCP must be { enabled: false } or { enabled: true, exclude?: MethodName[] } (received ${T(e)}).`);if("object"!=typeof e||null===e||!("enabled"in e)||"boolean"!=typeof e.enabled)throw t();const n=Object.keys(e).filter(e=>!S.has(e));if(n.length>0)throw new v("invalid_config",`webMCP has no option ${n.join(", ")} (known: ${[...S].join(", ")}).`);const o="exclude"in e?e.exclude:void 0;if(void 0===o)return;if(!Array.isArray(o))throw t();const i=o;if(!i.every(e=>"string"==typeof e))throw t();const r=i.filter(e=>!x.has(e));if(r.length>0)throw new v("invalid_config",`webMCP.exclude names no tool: ${r.join(", ")} (known: ${c.join(", ")}).`)})(e.webMCP);const t=e.baseDomain??"simplepdf.com",n=((e,t)=>{if(void 0===e||!("url"in e))return null;const n=(()=>{try{return new URL(e.url)}catch{return null}})();if(null===n)return null;const o=D(t);return("https:"===n.protocol||o&&"http:"===n.protocol)&&(()=>{if(!n.host.endsWith(`.${t}`))return!1;const e=n.host.slice(0,n.host.length-t.length-1);return e.length>0&&!e.includes(".")})()&&L.test(n.pathname)?{url:n,origin:n.origin}:null})(e.document,t),o=n?.origin??(({companyIdentifier:e,baseDomain:t})=>`${D(t)?"http":"https"}://${e}.${t}`)({companyIdentifier:e.companyIdentifier,baseDomain:t}),i=(e=>{if(e instanceof HTMLElement)return e;if("string"!=typeof e)throw new v("invalid_target",`target must be a CSS selector or an HTMLElement (received ${T(e)}).`);const t=document.querySelector(e);if(null===t||!(t instanceof HTMLElement))throw new v("invalid_target",`createEmbed target '${e}' did not match an element`);return t})(e.target);return i instanceof HTMLIFrameElement?((e,t,{document:n,logger:o=f,webMCP:i},r)=>{if(null!==r)throw new v("invalid_document","a SimplePDF documents URL loads by navigating the iframe, which createEmbed only does when it creates one (a container target). For an existing