import{k as e}from"./utils-BakkG8Vx.js";import{F as t,I as n,Y as r,t as i}from"./content_renderer-CoENEE63.js";async function a(e,n){let a=await t.getNote(e);if(!a)return;let o=n.closest(`section.include-note`),c=o.attr(`data-box-size`)===`expandable`,l=$(`<div class="include-note-wrapper">`),u=await r.createLink(a.noteId,{showTooltip:!1});if(c){let e=$(`<div class="include-note-title-row">`),t=$(`<button class="include-note-toggle bx bx-chevron-right" aria-expanded="false">`),n=$(`<h4 class="include-note-title">`).append(u);e.append(t,n),l.append(e);let{$renderedContent:r,type:o}=await i.getRenderedContent(a),s=$(`<div class="include-note-content type-${o}" style="display: none;">`).append(r);l.append(s),t.on(`click`,e=>{e.stopPropagation();let n=t.attr(`aria-expanded`)===`true`;t.attr(`aria-expanded`,String(!n)),t.toggleClass(`expanded`),s.slideToggle(200)})}else{l.append($(`<h4 class="include-note-title">`).append(u));let{$renderedContent:e,type:t}=await i.getRenderedContent(a);l.append($(`<div class="include-note-content type-${t}">`).append(e))}n.empty().append(l),s(o[0],e,n)}var o=new WeakMap;function s(e,t,n){let r=o.get(e);r&&r.disconnect();let i=new MutationObserver(e=>{for(let r of e)if(r.type===`attributes`&&r.attributeName===`data-box-size`){a(t,n);break}});i.observe(e,{attributes:!0,attributeFilter:[`data-box-size`]}),o.set(e,i)}function c(e,t){let n=e.querySelectorAll(`section[data-note-id="${t}"]`);for(let e of n)a(t,$(e))}function l(t,n){let r=$(t);r.on(`dblclick`,`img`,e=>u($(e.target))),r.on(`click`,`img`,t=>{t.stopPropagation();let r=t.which===1,i=t.which===2,a=e.isCtrlKey(t),o=r&&a&&t.shiftKey||i&&t.shiftKey;r&&a||i?d($(t.target),o):r&&n&&u($(t.target))})}async function u(e){let t=await f(e);t?n.tabManager.getActiveContext()?.setNote(t.noteId,{viewScope:t.viewScope}):window.open(e.prop(`src`),`_blank`)}async function d(e,t=!1){let r=await f(e);r?n.tabManager.openTabWithNoteWithHoisting(r.noteId,{activate:t,viewScope:r.viewScope}):window.open(e.prop(`src`),`_blank`)}async function f(e){let n=e.prop(`src`),r=n.match(/\/api\/images\/([A-Za-z0-9_]+)\//);if(r)return{noteId:r[1],viewScope:{}};let i=n.match(/\/api\/attachments\/([A-Za-z0-9_]+)\/image\//);if(i){let e=i[1],n=await t.getAttachment(e);return n?{noteId:n.ownerId,viewScope:{viewMode:`attachments`,attachmentId:e}}:null}return null}export{c as n,l as r,a as t};