const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./print-BUBQQceH.css","./render_to_html-CR0yRz4U.js","./lib-u36oR1k0.js","./rolldown-runtime-DAXXjFlN.js","./workbook_model-CeXzIW3o.js","./ck-content-Dqw7eKpv.css"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-HclGiUj8.js";import{a as t,i as n,l as r}from"./preact.module-CNakwbc9.js";import{a as i,d as a,f as o,t as s}from"./hooks.module-BrXTvcfS.js";import{H as c,i as l,s as u,t as d}from"./content_renderer-DOj8g78V.js";import{T as f}from"./i18n-BaLR3UdQ.js";import{t as p}from"./jsxRuntime.module-Cao1NCKs.js";import{o as m,t as h}from"./NoteList-CZrzG4tO.js";r(),a();async function g(){let t=window.location.hash.substring(1).split(`/`).at(-1);if(!t)return;if(await e(()=>Promise.resolve({}),__vite__mapDeps([0]),import.meta.url),!f()){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 c.getNote(t),a=document.createElement(`div`);n(p(_,{note:i,noteId:t}),a),document.body.appendChild(a)}function _({note:e,noteId:n}){let r=s(!1),a=o(e=>{window.electronApi?window.electronApi.printing.sendPrintProgress(e):window.dispatchEvent(new CustomEvent(`note-load-progress`,{detail:{progress:e}}))},[]),c=o(e=>{r.current||=(window.dispatchEvent(new CustomEvent(`note-ready`,{detail:e})),window._noteReady=e,!0)},[]),l=e&&{note:e,onReady:c,onProgressChanged:a};return i(()=>{e&&(document.body.dataset.noteType=e.type)},[e]),!e||!l?p(b,{noteId:n}):p(t,{children:e.type===`book`?p(y,{...l}):p(v,{...l})})}function v({note:n,onReady:r}){let a=s(null);return i(()=>{async function t(){let t=a.current;if(t){if(n.type===`spreadsheet`){let{renderSpreadsheetToHtml:r}=await e(async()=>{let{renderSpreadsheetToHtml:e}=await import(`./render_to_html-CR0yRz4U.js`);return{renderSpreadsheetToHtml:e}},__vite__mapDeps([1,2,3,4]),import.meta.url);t.innerHTML=r((await n.getBlob())?.content??``)}else{n.type===`text`&&await e(()=>Promise.resolve({}),__vite__mapDeps([5]),import.meta.url);let{$renderedContent:r}=await d.getRenderedContent(n,{noChildrenList:!0,expandNestedIncludes:!0,mediaEnvironment:`native`});t.replaceChildren(...r),await l(t);let i=Array.from(t.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 u(t)}await x(n),await document.fonts.ready}}t().then(()=>requestAnimationFrame(()=>r({type:`single-note`})))},[n]),p(t,{children:[p(`h1`,{children:n.title}),p(`main`,{ref:a})]})}function y({note:e,onReady:t,onProgressChanged:n}){return p(h,{viewType:m(e),isEnabled:!0,note:e,notePath:e.getBestNotePath().join(`/`),ntxId:`print`,highlightedTokens:null,media:`print`,onReady:async n=>{await x(e),await document.fonts.ready,t(n)},onProgressChanged:n})}function b({noteId:e}){return p(`main`,{children:[p(`p`,{children:`The note you are trying to print could not be found.`}),p(`small`,{children:e})]})}async function x(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)}g();export{_ as App,y as CollectionRenderer,b as Error404,v as SingleNoteRenderer,x as loadCustomCss,g as main};