const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./print-BGH9UAEa.css","./ck-content-Oos6fubM.css"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-DXCjA0eP.js";import{i as t}from"./src-BFy5RBR8.js";import{h as n,i as r}from"./utils-BakkG8Vx.js";import{C as i,a,d as o,f as s,t as c,v as l,y as u}from"./hooks.module-5xe-uC6c.js";import{F as d,a as f,t as p}from"./content_renderer-CoENEE63.js";import{t as m}from"./jsxRuntime.module--xb8gfv5.js";import{i as h,t as g}from"./NoteList-DSkThDng.js";i(),o();async function _(){let t=window.location.hash.substring(1).split(`/`).at(-1);if(!t)return;if(await e(()=>Promise.resolve({}),__vite__mapDeps([0]),import.meta.url),!n()){let e=document.createElement(`style`);e.textContent=`@page { margin: 2cm; }`,document.head.appendChild(e)}let r=document.createElement(`link`);r.rel=`stylesheet`,r.href=`api/fonts`,document.head.appendChild(r);let i=await d.getNote(t),a=document.createElement(`div`);l(m(v,{note:i,noteId:t}),a),document.body.appendChild(a)}function v({note:e,noteId:t}){let i=c(!1),o=s(e=>{if(n()){let{ipcRenderer:t}=r(`electron`);t.send(`print-progress`,e)}else window.dispatchEvent(new CustomEvent(`note-load-progress`,{detail:{progress:e}}))},[]),l=s(e=>{i.current||=(window.dispatchEvent(new CustomEvent(`note-ready`,{detail:e})),window._noteReady=e,!0)},[]),d=e&&{note:e,onReady:l,onProgressChanged:o};return!e||!d?m(x,{noteId:t}):(a(()=>{document.body.dataset.noteType=e.type},[e]),m(u,{children:e.type===`book`?m(b,{...d}):m(y,{...d})}))}function y({note:n,onReady:r}){let i=c(null);return a(()=>{async function a(){let r=i.current;if(n.type===`spreadsheet`)r.innerHTML=t((await n.getBlob())?.content??``);else{n.type===`text`&&await e(()=>Promise.resolve({}),__vite__mapDeps([1]),import.meta.url);let{$renderedContent:t}=await p.getRenderedContent(n,{noChildrenList:!0});r.replaceChildren(...t);let i=Array.from(r.querySelectorAll(`img`));await Promise.all(i.map(e=>e.complete?Promise.resolve():new Promise(t=>{e.addEventListener(`load`,()=>t(),{once:!0}),e.addEventListener(`error`,()=>t(),{once:!0})}))),n.type===`text`&&await f(r)}await S(n),await document.fonts.ready}a().then(()=>requestAnimationFrame(()=>r({type:`single-note`})))},[n]),m(u,{children:[m(`h1`,{children:n.title}),m(`main`,{ref:i})]})}function b({note:e,onReady:t,onProgressChanged:n}){return m(g,{viewType:h(e),isEnabled:!0,note:e,notePath:e.getBestNotePath().join(`/`),ntxId:`print`,highlightedTokens:null,media:`print`,onReady:async n=>{await S(e),await document.fonts.ready,t(n)},onProgressChanged:n})}function x({noteId:e}){return m(`main`,{children:[m(`p`,{children:`The note you are trying to print could not be found.`}),m(`small`,{children:e})]})}async function S(e){let t=await e.getRelationTargets(`printCss`),n=[];for(let e of t){if(!e||e.type!==`code`&&e.mime!==`text/css`)continue;let t=document.createElement(`link`);t.href=`/api/notes/${e.noteId}/download`,t.rel=`stylesheet`;let r=$.Deferred();n.push(r.promise()),t.onload=()=>r.resolve(),document.head.appendChild(t)}await Promise.allSettled(n)}_();