1 line
130 KiB
JavaScript
1 line
130 KiB
JavaScript
!function(){"use strict";function t(t){return"undefined"!=typeof window&&"function"==typeof window.renderMarkdown?window.renderMarkdown(t):String(t||"").replace(/\n/g,"<br>")}function e(t,e){if("undefined"!=typeof window&&"function"==typeof window.applyKeepNoteFormatting)return window.applyKeepNoteFormatting(t,e)}document.addEventListener("DOMContentLoaded",function(){const t=new URLSearchParams(window.location.search),e=t.get("searchtags")||t.get("searchTags")||"",o=window.location.pathname.match(/\/tag\/(.+)$/),n=(e+" "+(o?decodeURIComponent(o[1]):"")).toLowerCase().split(/[\s,]+/).filter(t=>t),d=!!document.querySelector('.sidebar-link[aria-label="Notes"].active, .header-nav-link[aria-label="Notes"].active, .sidebar-link[href*="searchtags=note"].active, .sidebar-link[href*="searchtags=shaarli-note"].active')||!!document.querySelector('.sidebar-link[aria-label="'+window.ShaarliProI18n.t("Notes")+'"].active, .header-nav-link[aria-label="'+window.ShaarliProI18n.t("Notes")+'"].active'),c=!!document.querySelector('.sidebar-link[aria-label="Mes tâches"].active, .header-nav-link[aria-label="Mes tâches"].active, .sidebar-link[href*="searchtags=shaarli-todo"].active, .sidebar-link[href*="searchtags=todo"].active')||!!document.querySelector('.sidebar-link[aria-label="'+window.ShaarliProI18n.t("My tasks")+'"].active, .header-nav-link[aria-label="'+window.ShaarliProI18n.t("My tasks")+'"].active'),p=!!document.querySelector('.sidebar-link[aria-label="Archive"].active, .header-nav-link[aria-label="Archive"].active, .sidebar-link[href*="searchtags=shaarli-archive"].active, .sidebar-link[href*="searchtags=shaarli-archiver"].active')||!!document.querySelector('.sidebar-link[aria-label="'+window.ShaarliProI18n.t("Archive")+'"].active, .header-nav-link[aria-label="'+window.ShaarliProI18n.t("Archive")+'"].active'),b=Array.from(document.querySelectorAll(".search-tag-chip")).map(t=>(t.textContent||"").trim().toLowerCase()),y=t=>"shaarli-archive"===t||"shaarli-archiver"===t,v=t=>"note"===t||"shaarli-note"===t||"#note"===t,w=t=>"todo"===t||"shaarli-todo"===t||"#todo"===t,S=n.some(v)||d||b.some(v),E=n.some(w)||c||b.some(w),C=n.some(y)||p||b.some(y),q=document.getElementById("links-list"),I=document.querySelector(".content-container"),x=()=>{try{document.body.classList.remove("view-todo","view-notes","view-archive")}catch(t){}const t=document.querySelector(".content-toolbar");t&&(t.style.display="");const e=document.getElementById("links-list");e&&(e.style.display=""),document.querySelectorAll(".notes-wrapper.todo-wrapper").forEach(t=>t.remove())};window.renderMarkdown=function(t){if(!t)return"";const e=String(t).replace(/\r\n?/g,"\n"),o=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),n=t=>String(t).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),r=t=>{const e=String(t||"").trim();return e&&/^(https?:|mailto:|\/)/i.test(e)?e:""},a=t=>{let e=o(t||"");const a=[];return e=e.replace(/`([^`\n]+)`/g,(t,e)=>{const o=`__MD_CODE_${a.length}__`;return a.push(`<code>${e}</code>`),o}),e=e.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,o)=>{const a=r(o);return a?`<img src="${n(a)}" alt="${n(e)}" loading="lazy" />`:t}),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,o)=>{const a=r(o);return a?`<a href="${n(a)}" target="_blank" rel="noopener noreferrer">${e}</a>`:t}),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/__(.+?)__/g,"<strong>$1</strong>"),e=e.replace(/~~(.+?)~~/g,"<del>$1</del>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/_(.+?)_/g,"<em>$1</em>"),e=e.replace(/<u>([\s\S]*?)<\/u>/g,"<u>$1</u>"),e=e.replace(/__MD_CODE_(\d+)__/g,(t,e)=>a[Number(e)]||""),e},i=e.split("\n"),l=[];let s=!1,d=!1,c=!1,u=!1,m="",p=[];const f=()=>{s&&(l.push("</ul>"),s=!1),d&&(l.push("</ol>"),d=!1),c&&(l.push("</ul>"),c=!1)};if(i.forEach(t=>{const e=t.trim(),r=e.match(/^```\s*([\w-]+)?\s*$/);if(r){if(f(),u){const t=m?` data-lang="${n(m)}"`:"";l.push(`<pre class="md-code-block"><code${t}>${o(p.join("\n"))}</code></pre>`),u=!1,m="",p=[]}else u=!0,m=r[1]||"",p=[];return}if(u)return void p.push(t);if(!e)return f(),void l.push('<div class="md-spacer"></div>');const i=t.match(/^\s*(#{1,6})\s+(.+)$/);if(i){f();const t=i[1].length;return void l.push(`<h${t}>${a(i[2])}</h${t}>`)}const h=t.match(/^\s*>\s?(.*)$/);if(h)return f(),void l.push(`<blockquote>${a(h[1])}</blockquote>`);const g=t.match(/^\s*[-*]\s+\[( |x|X)\]\s+(.+)$/);if(g){s&&(l.push("</ul>"),s=!1),d&&(l.push("</ol>"),d=!1),c||(l.push('<ul class="md-todo-list">'),c=!0);const t="x"===String(g[1]).toLowerCase();return void l.push(`<li class="md-todo-item${t?" is-checked":""}"><span class="md-todo-box" aria-hidden="true"><i class="mdi mdi-check"></i></span><span class="md-todo-text">${a(g[2])}</span></li>`)}const b=t.match(/^\s*\d+\.\s+(.+)$/);if(b)return s&&(l.push("</ul>"),s=!1),c&&(l.push("</ul>"),c=!1),d||(l.push("<ol>"),d=!0),void l.push(`<li>${a(b[1])}</li>`);const y=t.match(/^\s*[-*+]\s+(.+)$/);if(y)return d&&(l.push("</ol>"),d=!1),c&&(l.push("</ul>"),c=!1),s||(l.push("<ul>"),s=!0),void l.push(`<li>${a(y[1])}</li>`);f(),l.push(`<p>${a(t)}</p>`)}),u){const t=m?` data-lang="${n(m)}"`:"";l.push(`<pre class="md-code-block"><code${t}>${o(p.join("\n"))}</code></pre>`)}return f(),l.join("")},window.applyKeepNoteFormatting=function(t,e){if(!t||!e)return;const o=t.selectionStart||0,n=t.selectionEnd||0,r=String(t.value||""),a=r.slice(o,n),i=(e,o,n,a="end")=>{const i=r.slice(0,e)+n+r.slice(o);if(t.value=i,t.focus({preventScroll:!0}),"select"===a)t.setSelectionRange(e,e+n.length);else{const o=e+n.length;t.setSelectionRange(o,o)}},l=(e,i)=>{const l=a||"",s=`${e}${l}${i}`,d=r.slice(0,o)+s+r.slice(n);t.value=d;const c=o+e.length,u=c+l.length;t.focus({preventScroll:!0}),t.setSelectionRange(c,u)},s=e=>{const{lineStart:a,lineEnd:i}=(()=>{const t=r.slice(0,o),e=r.slice(n),a=t.lastIndexOf("\n")+1,i=e.indexOf("\n");return{lineStart:a,lineEnd:-1===i?r.length:n+i}})(),l=r.slice(a,i).split(/\r?\n/).map(e).join("\n"),s=r.slice(0,a)+l+r.slice(i);t.value=s,t.focus({preventScroll:!0}),t.setSelectionRange(a,a+l.length)};if("bold"===e)return l("**","**");if("italic"===e)return l("*","*");if("underline"===e)return l("<u>","</u>");if("strike"===e)return l("~~","~~");if("code"===e)return l("`","`");if("link"===e){const e=`[${a||"Texte du lien"}](https://)`;i(o,n,e);const r=o+e.length-1;return void t.setSelectionRange(r,r)}if("image"===e){const e=``;i(o,n,e);const r=o+e.length-1;return void t.setSelectionRange(r,r)}if("quote"===e)return s(t=>t.startsWith("> ")?t:`> ${t}`);if("ul"===e)return s(t=>{const e=t.trim();return e?/^[-*+]\s+/.test(e)?t:`- ${e}`:"- "});if("ol"===e)return s((t,e)=>{const o=t.trim();return o?/^\d+\.\s+/.test(o)?t:`${e+1}. ${o}`:`${e+1}. `});if("todo"===e)return s(t=>{const e=t.trim();return e?/^[-*]\s+\[( |x|X)\]\s+/.test(e)?t:`- [ ] ${e}`:"- [ ] "});if("codeblock"===e){return void i(o,n,`\n\`\`\`\n${a||"code"}\n\`\`\`\n`,"select")}if("h1"===e||"h2"===e||"h3"===e||"p"===e){const t="h1"===e?"# ":"h2"===e?"## ":"h3"===e?"### ":"";return s(e=>{const o=e.replace(/^\s*(#{1,6}\s+)/,"");return t?t+o:o})}if("clear"===e){if(!a)return s(t=>t.replace(/^\s*(#{1,6}\s+)/,"").replace(/^\s*>\s?/,"").replace(/^\s*[-*+]\s+\[( |x|X)\]\s+/,"").replace(/^\s*[-*+]\s+/,"").replace(/^\s*\d+\.\s+/,"").replace(/\*\*(.*?)\*\*/g,"$1").replace(/__(.*?)__/g,"$1").replace(/~~(.*?)~~/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/_(.*?)_/g,"$1").replace(/`(.*?)`/g,"$1").replace(/<u>(.*?)<\/u>/g,"$1"));const t=a.replace(/\*\*(.*?)\*\*/g,"$1").replace(/__(.*?)__/g,"$1").replace(/~~(.*?)~~/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/_(.*?)_/g,"$1").replace(/`(.*?)`/g,"$1").replace(/<u>(.*?)<\/u>/g,"$1");i(o,n,t)}};const D=function(){if(V(),window.requestAnimationFrame(k),bt(),q&&I)if(E)try{!function(t,e){document.body.classList.add("view-todo","view-notes");const o=document.querySelector(".content-toolbar");o&&(o.style.display="none");const n=document.createElement("div");n.className="notes-wrapper todo-wrapper";const d=document.createElement("div");d.className="notes-top-bar";const c=document.createElement("div");c.className="note-input-container todo-input-container";const u=()=>{c.classList.remove("is-editing","todo-draft-mode","is-enhanced"),O(c,{color:"default",filter:"none",background:"none",fontColor:"auto"}),c.innerHTML=`\n <div class="note-input-collapsed">\n <span class="note-input-placeholder">${window.ShaarliProI18n.t("Create a task...")}</span>\n <div class="note-input-actions">\n <button type="button" class="todo-open-draft-btn" title="${window.ShaarliProI18n.t("Create a list")}"><i class="mdi mdi-check-circle-outline"></i></button>\n </div>\n </div>\n `;const t=c.querySelector(".note-input-collapsed"),e=c.querySelector(".todo-open-draft-btn"),o=()=>{c.classList.add("is-editing","todo-draft-mode"),c.innerHTML=`\n <div class="note-input-expanded todo-draft-expanded">\n <input type="text" class="note-input-title todo-draft-title" placeholder="${window.ShaarliProI18n.t("List title")}" autocomplete="off" />\n <div class="todo-draft-list" role="list"></div>\n <button type="button" class="todo-draft-add-btn"><i class="mdi mdi-plus"></i> ${window.ShaarliProI18n.t("Add list item")}</button>\n <div class="note-input-expanded-actions">\n <div class="note-input-actions-left">\n <button type="button" class="note-input-palette-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n </div>\n <button type="button" class="note-input-close-btn">Fermer</button>\n </div>\n </div>\n `;const t=c.querySelector(".todo-draft-title"),e=c.querySelector(".todo-draft-list"),o=c.querySelector(".todo-draft-add-btn"),n=c.querySelector(".note-input-close-btn"),d=c.querySelector(".note-input-palette-btn");let m=!1,p=!1,f={color:"default",filter:"none",background:"none",fontColor:"auto"};O(c,f);const h=(t={text:"",checked:!1},o=!1)=>{if(!e)return null;const n=document.createElement("div");n.className="todo-draft-row",n.innerHTML=`\n <label class="todo-checklist-box" title="${window.ShaarliProI18n.t("Mark as completed")}">\n <input type="checkbox" class="todo-item-checkbox" ${t.checked?"checked":""} />\n <span class="todo-checklist-box-ui"></span>\n </label>\n <input type="text" class="todo-item-text" placeholder="${window.ShaarliProI18n.t("List item")}" value="${nt(t.text||"")}" />\n <button type="button" class="todo-item-delete" title="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-close"></i></button>\n `,e.appendChild(n);const r=n.querySelector(".todo-item-checkbox"),a=n.querySelector(".todo-item-text"),i=n.querySelector(".todo-item-delete"),l=()=>{n.classList.toggle("is-checked",!(!r||!r.checked))};return l(),r?.addEventListener("change",()=>{m=!0,l()}),a?.addEventListener("input",()=>{m=!0}),i?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),m=!0,n.remove(),e.querySelector(".todo-draft-row")||h({text:"",checked:!1},!0)}),o&&a&&a.focus({preventScroll:!0}),n},g=()=>e?Array.from(e.querySelectorAll(".todo-draft-row")).map(t=>{const e=t.querySelector(".todo-item-checkbox"),o=t.querySelector(".todo-item-text"),n=o&&"string"==typeof o.value?o.value.trim():"";return{checked:!(!e||!e.checked),text:n}}).filter(t=>t.text):[];h({text:"",checked:!1},!1),o?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),m=!0,h({text:"",checked:!1},!0)}),t?.addEventListener("input",()=>{m=!0});const b=async()=>{if(p)return;const e=t&&"string"==typeof t.value?t.value.trim():"",o=g();if(!e&&0===o.length)return document.removeEventListener("pointerdown",y,!0),void u();if(!m)return document.removeEventListener("pointerdown",y,!0),void u();p=!0;try{await async function({title:t,items:e=[],visual:o=null}){const n="undefined"!=typeof shaarli&&shaarli.basePath?shaarli.basePath:"",d=window.ShaarItRules?window.ShaarItRules.generateTodoUrl():"",c=`${n}/admin/shaare?post=${encodeURIComponent(d)}&tags=todo`,{action:u,baseData:m}=await z(c),p=new URLSearchParams(m.toString());p.set("lf_url",d),p.set("lf_title",t||"");const f=(Array.isArray(e)?e:[]).map(t=>({checked:!(!t||!t.checked),text:String(t&&t.text||"").trim()})).filter(t=>t.text),h=f.map(t=>`- [${t.checked?"x":" "}] ${t.text}`).join("\n");p.set("lf_description",h);let g=(p.get("lf_tags")||"").trim().split(/[\s,]+/).filter(t=>""!==t.trim());g=g.filter(t=>"note"!==t&&"shaarli-note"!==t),g.includes("todo")||g.push("todo");if(o){const t=o.color||"default",e=M(o.filter||"")||"none",n=L(o.background||"")||"none",d=o.fontColor||"auto";if(g=g.filter(t=>!t.startsWith(i)),g=g.filter(t=>!t.startsWith(l)),g=g.filter(t=>!t.startsWith(s)),g=g.filter(t=>!t.startsWith(a)),t&&"default"!==t)if("string"==typeof t&&t.startsWith("custom:")){const e=t.substring(7).replace("#","");e&&g.push(`${i}${e}`)}else g.push(`${i}${t}`);if(e&&"none"!==e&&g.push(`${l}${e}`),n&&"none"!==n&&g.push(`${s}${n}`),d&&"auto"!==d)if("string"==typeof d&&d.startsWith("custom:")){const t=d.substring(7).replace("#","");t&&g.push(`${a}${t}`)}else{const t=r.find(t=>t.key===d);t&&t.value&&"auto"!==t.value&&g.push(`${a}${t.value.substring(1)}`)}}p.set("lf_tags",g.join(" ")),p.get("returnurl")||p.set("returnurl",window.location.href);p.append("save_edit","1");const b=await fetch(u,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:p.toString()});if(!b.ok)throw new Error(`Failed to create todo (status ${b.status})`)}({title:e,items:o,visual:f}),window.location.reload()}catch(t){console.error("Error creating todo:",t),alert(window.ShaarliProI18n.t("Error creating todo.")),p=!1}};n?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),b()});const y=t=>{t.target&&t.target.closest&&t.target.closest("#shaarli-bg-studio")||t.target&&t.target.closest&&t.target.closest(".bg-studio-panel")||c.contains(t.target)||b()};document.addEventListener("pointerdown",y,!0),d?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),j({anchorEl:d,mode:"draft",entityId:"draft-new-todo",editUrl:"",currentColor:f.color||"default",currentFilter:f.filter||"none",currentBackground:f.background||"none",currentFontColor:f.fontColor||"auto",title:window.ShaarliProI18n.t("My images & colors")});const e=document.getElementById("shaarli-bg-studio");e&&(e.__draftApply=t=>{f={...f,...t||{}},O(c,f)})}),t?.focus({preventScroll:!0})};t?.addEventListener("click",t=>{t.target.closest("button")||o()}),e?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),o()})};u(),d.appendChild(c);const p=document.createElement("div");p.className="notes-tools",p.innerHTML=`\n <button class="icon-btn active" id="btn-view-grid" title="${window.ShaarliProI18n.t("Grid view")}"><i class="mdi mdi-view-dashboard-outline"></i></button>\n <button class="icon-btn" id="btn-view-list" title="${window.ShaarliProI18n.t("List view")}"><i class="mdi mdi-view-agenda-outline"></i></button>\n `,d.appendChild(p),n.appendChild(d);const h=document.createElement("div");h.className="notes-content-area";const g=Array.from(t.querySelectorAll(".link-outer")),b=g.map(t=>function(t){if(!t)return null;const e=t.dataset.id,o=t.querySelector(".link-title"),n=o?o.textContent.trim():"",r=t.querySelector(".link-description"),d=r?r.innerHTML:"",c=r?r.textContent:"",u=[];t.querySelectorAll(".link-tag-list a").forEach(t=>{const e=(t.textContent||"").trim();e&&u.push(e)});const{color:m,filter:p,background:f,fontColor:h}=K(u),g=u.filter(t=>!t.startsWith(i)&&(!t.startsWith("note-custom-")&&(!t.startsWith(l)&&(!t.startsWith(s)&&!t.startsWith(a))))),b=t.querySelector(".link-actions"),y=b&&b.querySelector('a[href*="admin/shaare"]')?b.querySelector('a[href*="admin/shaare"]').href:"#",v=b&&b.querySelector('a[href*="delete"]')?b.querySelector('a[href*="delete"]').href:"#",w=b&&b.querySelector('a[href*="pin"]')?b.querySelector('a[href*="pin"]').href:"#",k=g.includes("shaarli-pin"),S=function(t,e){const o=[];if(t){const e=Array.from(t.querySelectorAll('input[type="checkbox"]'));if(e.length>0)return e.forEach(t=>{const e=t.closest("li")||t.parentElement;let n="";if(e){const t=e.cloneNode(!0);t.querySelectorAll('input[type="checkbox"]').forEach(t=>t.remove()),n=(t.textContent||"").trim()}o.push({checked:!!t.checked,text:n})}),o}const n=String(e||"").split(/\r?\n/),r=t?t.innerHTML:n.join("\n"),a=rt(r);return a.items}(r,c),$=rt(c);return{id:e,title:n,descHtml:d,descText:c,items:S,_todoHeaderLines:$.headerLines,_todoFooterLines:$.footerLines,tags:g,color:m,filter:p,background:f,fontColor:h,editUrl:y,deleteUrl:v,pinUrl:w,isPinned:k}}(t)).filter(t=>t);n.appendChild(h),t.style.display="none",t.parentNode?t.parentNode.insertBefore(n,t):e.appendChild(n);et(h,b,"grid");const y=document.createElement("div");y.className="note-modal-overlay todo-modal-overlay",y.innerHTML=`\n <div class="note-modal note-color-default todo-modal">\n <div class="note-modal-header">\n <h2 class="note-title" id="todo-modal-title"></h2>\n <button type="button" class="note-modal-pin-toggle" id="todo-modal-pin" title="${window.ShaarliProI18n.t("Pin")}">\n <i class="mdi mdi-pin-outline"></i>\n </button>\n </div>\n <div class="note-modal-content">\n <div class="todo-checklist" id="todo-modal-checklist"></div>\n <button type="button" class="todo-add-item-btn" id="todo-modal-add-item"><i class="mdi mdi-plus"></i> ${window.ShaarliProI18n.t("Add list item")}</button>\n </div>\n <div class="note-modal-tags is-empty" id="todo-modal-tags"></div>\n <div class="note-modal-actions">\n <div class="note-modal-actions-left">\n <div class="note-modal-color-picker">\n <button type="button" id="todo-modal-color-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n <div class="palette-popup note-modal-palette" id="todo-modal-color-popup"></div>\n </div>\n <a href="#" id="todo-modal-edit" title="${window.ShaarliProI18n.t("Edit")}"><i class="mdi mdi-pencil-outline"></i></a>\n <button type="button" id="todo-modal-delete" title="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-delete-outline"></i></button>\n </div>\n <button type="button" class="note-modal-close-btn" id="todo-modal-close">Fermer</button>\n </div>\n </div>\n `,document.body.appendChild(y);const v=n.querySelector("#btn-view-grid"),w=n.querySelector("#btn-view-list");v.addEventListener("click",()=>{v.classList.add("active"),w.classList.remove("active"),et(h,b,"grid")}),w.addEventListener("click",()=>{w.classList.add("active"),v.classList.remove("active"),et(h,b,"list")}),y.querySelector("#todo-modal-close").addEventListener("click",()=>{y.classList.remove("open")}),y.addEventListener("click",t=>{t.target===y&&y.classList.remove("open")});const k=y.querySelector("#todo-modal-pin"),S=y.querySelector("#todo-modal-color-btn"),$=y.querySelector("#todo-modal-color-popup");S.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=y.querySelector(".note-modal");j({anchorEl:S,mode:"modal",entityId:e&&e.dataset.todoId||"",editUrl:e&&e.dataset.editUrl||"",currentColor:e?_(e):"default",currentFilter:e?U(e):"none",currentBackground:e?A(e):"none",currentFontColor:e?T(e):"auto",title:window.ShaarliProI18n.t("My images & colors")})}),k.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=y.querySelector(".note-modal"),o=e.dataset.todoId,n=e.dataset.editUrl;if(!o||!n)return;yt(o,n,k);const r=k.classList.contains("active");let a=(e.dataset.tags||"").split("||").filter(t=>t);r?a.includes("shaarli-pin")||a.push("shaarli-pin"):a=a.filter(t=>"shaarli-pin"!==t),e.dataset.tags=a.join("||"),pt(y.querySelector("#todo-modal-tags"),a),y.currentTodo&&(y.currentTodo.isPinned=r,y.currentTodo.tags=a)}),y.querySelector("#todo-modal-delete").addEventListener("click",()=>{if(!confirm(window.ShaarliProI18n.t("Delete this task?")))return;const t=y.querySelector(".note-modal"),e=t.dataset.deleteUrl;t.dataset.todoId;e&&"#"!==e&&m(e).then(()=>{window.location.href="/?searchtags=todo"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})}),y.addEventListener("click",t=>{t.target.closest(".note-modal-color-picker")||$.classList.remove("open")}),y.querySelector("#todo-modal-add-item").addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),y.currentTodo&&function(t,e){e.items||(e.items=[]);e.items.push({checked:!1,text:""}),at(t,e);const o=t.querySelectorAll(".todo-item-text"),n=o&&o.length?o[o.length-1]:null;n&&n.focus();it(t,e)}(y,y.currentTodo)}),f()}(q,I)}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Todo:",t),x()}else if(S)try{dt(q,I),f()}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Note:",t),x()}else if(C)try{!function(t,e){document.body.classList.add("view-notes","view-archive");const o=document.querySelector(".content-toolbar");o&&(o.style.display="none");const n=document.createElement("div");n.className="notes-wrapper archive-wrapper";const r=document.createElement("div");r.className="notes-top-bar archive-top-bar";const a=document.createElement("div");a.className="archive-title-container",a.innerHTML=`\n <h1 class="archive-title"><i class="mdi mdi-archive-arrow-down-outline"></i> Archive</h1>\n <p class="archive-subtitle">${window.ShaarliProI18n.t("Archived notes")}</p>\n `,r.appendChild(a);const i=document.createElement("div");i.className="notes-tools",i.innerHTML=`\n <button class="icon-btn active" id="btn-view-grid" title="${window.ShaarliProI18n.t("Grid view")}"><i class="mdi mdi-view-dashboard-outline"></i></button>\n <button class="icon-btn" id="btn-view-list" title="${window.ShaarliProI18n.t("List view")}"><i class="mdi mdi-view-agenda-outline"></i></button>\n `,r.appendChild(i),n.appendChild(r);const l=document.createElement("div");l.className="notes-content-area";const s=Array.from(t.querySelectorAll(".link-outer")),d=s.map(t=>ct(t)).filter(t=>(t.tags||[]).some(t=>"shaarli-archive"===t||"shaarli-archiver"===t));ut(l,d,"grid",!0),n.appendChild(l),t.style.display="none",t.parentNode?t.parentNode.insertBefore(n,t):e.appendChild(n);const c=document.createElement("div");c.className="note-modal-overlay",c.innerHTML=`\n <div class="note-modal note-color-default">\n <div class="note-modal-header">\n <h2 class="note-title" id="note-modal-title"></h2>\n <button type="button" class="note-modal-pin-toggle" id="note-modal-pin" title="${window.ShaarliProI18n.t("Pin")}">\n <i class="mdi mdi-pin-outline"></i>\n </button>\n </div>\n <div class="note-modal-content"></div>\n <div class="note-modal-tags is-empty" id="note-modal-tags"></div>\n <div class="note-modal-actions">\n <div class="note-modal-actions-left">\n <div class="note-modal-color-picker">\n <button type="button" id="note-modal-color-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n <div class="palette-popup note-modal-palette" id="note-modal-color-popup"></div>\n </div>\n <button type="button" title="${window.ShaarliProI18n.t("Reminder")}"><i class="mdi mdi-bell-outline"></i></button>\n <button type="button" title="${window.ShaarliProI18n.t("Collaborator")}"><i class="mdi mdi-account-plus-outline"></i></button>\n <button type="button" title="${window.ShaarliProI18n.t("Image")}"><i class="mdi mdi-image-outline"></i></button>\n <button type="button" id="note-modal-unarchive" title="${window.ShaarliProI18n.t("Unarchive")}"><i class="mdi mdi-archive-arrow-up-outline"></i></button>\n <a href="#" id="note-modal-edit" title="${window.ShaarliProI18n.t("Edit")}"><i class="mdi mdi-pencil-outline"></i></a>\n <button type="button" id="note-modal-delete" title="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-delete-outline"></i></button>\n </div>\n <button type="button" class="note-modal-close-btn" id="note-modal-close">Fermer</button>\n </div>\n </div>\n `,document.body.appendChild(c);const p=n.querySelector("#btn-view-grid"),f=n.querySelector("#btn-view-list");p.addEventListener("click",()=>{p.classList.add("active"),f.classList.remove("active"),ut(l,d,"grid",!0)}),f.addEventListener("click",()=>{f.classList.add("active"),p.classList.remove("active"),ut(l,d,"list",!0)}),c.querySelector("#note-modal-close").addEventListener("click",()=>{c.classList.remove("open")}),c.addEventListener("click",t=>{t.target===c&&c.classList.remove("open")});const h=c.querySelector("#note-modal-pin"),g=c.querySelector("#note-modal-color-btn"),b=c.querySelector("#note-modal-color-popup");g.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=c.querySelector(".note-modal");j({anchorEl:g,mode:"modal",entityId:e&&e.dataset.noteId||"",editUrl:e&&e.dataset.editUrl||"",currentColor:e?_(e):"default",currentFilter:e?U(e):"none",currentBackground:e?A(e):"none",currentFontColor:e?T(e):"auto",title:window.ShaarliProI18n.t("My images & colors")})}),h.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=c.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;if(!o||!n)return;yt(o,n,h);const r=h.classList.contains("active");let a=(e.dataset.tags||"").split("||").filter(t=>t);r?a.includes("shaarli-pin")||a.push("shaarli-pin"):a=a.filter(t=>"shaarli-pin"!==t),e.dataset.tags=a.join("||"),pt(c.querySelector("#note-modal-tags"),a),c.currentNote&&(c.currentNote.isPinned=r,c.currentNote.tags=a)}),c.querySelector("#note-modal-delete").addEventListener("click",()=>{if(!confirm(window.ShaarliProI18n.t("Delete this note?")))return;const t=c.querySelector(".note-modal"),e=t.dataset.deleteUrl;t.dataset.noteId;e&&"#"!==e&&m(e).then(()=>{window.location.href="/?searchtags=shaarli-archive"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})}),c.querySelector("#note-modal-unarchive").addEventListener("click",t=>{t.preventDefault();const e=c.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;o&&n&&u(n,"shaarli-archive").then(()=>{c.currentNote&&(c.currentNote.tags=(c.currentNote.tags||[]).filter(t=>"shaarli-archive"!==t));const t=document.querySelector(`.note-card[data-id="${o}"]`);t&&t.remove();const e=d.findIndex(t=>String(t.id)===String(o));e>-1&&d.splice(e,1),c.classList.remove("open")}).catch(t=>{console.error("Error unarchiving note:",t),alert(window.ShaarliProI18n.t("Error unarchiving note."))})}),c.addEventListener("click",t=>{t.target.closest(".note-modal-color-picker")||b.classList.remove("open")}),document.addEventListener("click",t=>{t.target.closest(".note-hover-actions .palette-popup")&&!t.target.closest('.note-hover-actions [id^="palette-"]')&&document.querySelectorAll(".note-hover-actions .palette-popup.open").forEach(t=>{t.classList.remove("open")})})}(q,I),f()}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Archive:",t),x()}else f()};!function(){if(N)return;const t=document.documentElement;if(!t)return;let e=P();new MutationObserver(t=>{if(!t.some(t=>"data-theme"===t.attributeName))return;const o=P();o!==e&&(e=o,document.querySelectorAll(".note-card, .note-modal, .link-outer, .note-input-container").forEach(t=>{O(t,{color:_(t),filter:U(t),background:A(t),fontColor:T(t)})}),function(){document.querySelectorAll(".note-card").forEach(t=>{const e=t.querySelector(".note-hover-actions .palette-popup");if(!e)return;const o=t.dataset.id||"";if(!o)return;const n=t.querySelector('.note-hover-actions a[href*="/admin/shaare/"], .note-hover-actions a[href*="do=editlink"], .note-hover-actions a[title="Edit"]');var r;e.innerHTML=G({entityId:(r={id:o,editUrl:n&&n.href?n.href:"#",color:_(t),background:A(t)})&&r.id?r.id:"",editUrl:r&&r.editUrl?r.editUrl:"",currentColor:r&&r.color?r.color:"default",currentFilter:r&&r.filter?r.filter:"none",mode:"entity"})}),document.querySelectorAll(".link-outer").forEach(t=>{const e=t.querySelector(".bookmark-palette .palette-popup");if(!e)return;const o=t.dataset.id||t.getAttribute("data-id")||t.id;if(!o)return;const n=t.querySelector(".link-actions"),r=n?n.querySelector(`a[title="${window.ShaarliProI18n.t("Edit")}"], a[href*="/admin/shaare/"]`):null;e.innerHTML=X(o,r&&r.href?r.href:"#",_(t),A(t))});const t=h(),e=g(t);if(!t||!e)return;const o=t.querySelector(".note-modal");o&&(e.color=_(o),e.background=A(o));const n=t.querySelector(".note-modal-palette");n&&(n.innerHTML=ht(e))}())}).observe(t,{attributes:!0,attributeFilter:["data-theme"]}),N=!0}(),$().then(()=>{D()}).catch(t=>{console.error("Erreur lors du chargement des backgrounds:",t),D()})});const o=[{key:"default",label:window.ShaarliProI18n.t("Default"),light:"#f8fafc",dark:"#20293A"},{key:"red",label:window.ShaarliProI18n.t("Red"),light:"#f28b82",dark:"#9c2116"},{key:"orange",label:window.ShaarliProI18n.t("Orange"),light:"#fbbc04",dark:"#9c7a16"},{key:"yellow",label:window.ShaarliProI18n.t("Yellow"),light:"#fff475",dark:"#9c9116"},{key:"green",label:window.ShaarliProI18n.t("Green"),light:"#ccff90",dark:"#5e9c16"},{key:"teal",label:window.ShaarliProI18n.t("Mint"),light:"#a7ffeb",dark:"#169c7d"},{key:"blue",label:window.ShaarliProI18n.t("Light blue"),light:"#cbf0f8",dark:"#16849c"},{key:"darkblue",label:window.ShaarliProI18n.t("Blue"),light:"#aecbfa",dark:"#16499c"},{key:"purple",label:window.ShaarliProI18n.t("Purple"),light:"#d7aefb",dark:"#5d169c"},{key:"pink",label:window.ShaarliProI18n.t("Pink"),light:"#fdcfe8",dark:"#9c165f"},{key:"brown",label:window.ShaarliProI18n.t("Beige"),light:"#e6c9a8",dark:"#9c5d16"},{key:"grey",label:window.ShaarliProI18n.t("Gray"),light:"#e8eaed",dark:"#4e5764"},{key:"custom",label:window.ShaarliProI18n.t("Custom"),light:"#custom",dark:"#custom"}],n=[{key:"none",label:window.ShaarliProI18n.t("None"),icon:"mdi-close-circle-outline"},{key:"glass",label:window.ShaarliProI18n.t("Glass"),icon:"mdi-blur"},{key:"vignette",label:window.ShaarliProI18n.t("Vignette"),icon:"mdi-vignette"},{key:"lined",label:window.ShaarliProI18n.t("Lined"),icon:"mdi-format-align-justify"},{key:"grid",label:window.ShaarliProI18n.t("Grid"),icon:"mdi-grid"},{key:"noise",label:window.ShaarliProI18n.t("Noise"),icon:"mdi-grain"},{key:"dots",label:window.ShaarliProI18n.t("Dots"),icon:"mdi-dots-grid"},{key:"stripes",label:window.ShaarliProI18n.t("Stripes"),icon:"mdi-slash-forward"}],r=[{key:"auto",label:window.ShaarliProI18n.t("Auto"),value:"auto"},{key:"light",label:window.ShaarliProI18n.t("Light"),value:"#f5f7fb"},{key:"dark",label:window.ShaarliProI18n.t("Dark"),value:"#202124"},{key:"white",label:window.ShaarliProI18n.t("White"),value:"#ffffff"},{key:"black",label:window.ShaarliProI18n.t("Black"),value:"#000000"},{key:"custom",label:window.ShaarliProI18n.t("Custom"),value:"custom"}],a="font-",i="note-color-",l="notefilter-",s="notebg-";function d(t){if("string"!=typeof t)return!1;const e=t.trim().toLowerCase();if(!e)return!1;if("note"===e||"#note"===e)return!0;if("shaarli-note"===e)return!0;if("todo"===e||"#todo"===e)return!0;if("shaarli-todo"===e)return!0;if("shaarli-pin"===e)return!0;if("brain-dump"===e)return!0;if(e.startsWith(a))return!0;if(e.startsWith(i))return!0;if(e.startsWith(l))return!0;if(e.startsWith(s))return!0;if(e.startsWith("notefilter-"))return!0;if(e.startsWith("notebg-"))return!0;if(e.startsWith("note-color-"))return!0;if(e.startsWith("note-")){const t=e.substring(5);if(o.some(e=>e.key===t))return!0}return!1}function c({tag:t,onRemoveClass:e="tag-remove-btn",tagClass:o="tag-pill"}){const n=document.createElement("span");n.className=o,n.dataset.tag=t;const r=document.createElement("span");r.className=`${o}-text`,r.textContent=t,n.appendChild(r);if(!(!arguments[0]||!Object.prototype.hasOwnProperty.call(arguments[0],"canRemove")||!!arguments[0].canRemove))return n;const a=document.createElement("button");return a.type="button",a.className=e,a.dataset.tag=t,a.setAttribute("aria-label",`Supprimer le tag ${t}`),a.title=window.ShaarliProI18n.t("Delete"),a.innerHTML="×",n.appendChild(a),n}function u(t,e){return fetch(t).then(t=>t.text()).then(t=>{const o=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!o)throw new Error("Could not find edit form");const n=new URLSearchParams;o.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&n.append(t.name,t.value||"on"):t.name&&n.append(t.name,Y(t))});let r=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return r=r.filter(t=>t!==e),n.set("lf_tags",r.join(" ")),n.append("save_edit","1"),fetch(o.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to update tags");return t})}function m(t){return t&&"#"!==t?fetch(t).then(t=>{if(!t.ok)throw new Error("Delete request failed");return t}):Promise.reject("Invalid delete URL")}let p=!1;function f(){p||(document.querySelectorAll(".link-tag-list .link-tag").forEach(t=>{const e=(t.dataset.tag||t.textContent||"").trim();e&&("shaarli-pin"!==e?d(e)&&t.classList.add("is-tech-tag"):t.classList.add("is-tech-tag"))}),document.addEventListener("click",function(t){const e=t.target.closest(".tag-remove-btn, .note-tag-remove-btn");if(!e)return;t.preventDefault(),t.stopPropagation();const o=(e.dataset.tag||"").trim();if(!o)return;const n=e.closest(".link-tag, .note-tag"),r=e.closest(".link-outer, .note-card, .note-modal");let a="";if(r&&r.classList.contains("note-card"))a=r.dataset.editUrl||"";else if(r&&r.classList.contains("note-modal"))a=r.dataset.editUrl||"";else{const t=r?r.querySelector(".link-actions"):null,e=t?t.querySelector('a[href*="admin/shaare"]'):null;a=e?e.href:""}a&&u(a,o).then(()=>{if(n&&n.remove(),r&&r.classList.contains("note-card")){let t=(r.dataset.tags||"").split("||").filter(t=>t);t=t.filter(t=>t!==o),r.dataset.tags=t.join("||");const e=h(),n=g(e);if(e&&n&&String(n.id)===String(r.dataset.id)){n.tags=(n.tags||[]).filter(t=>t!==o);pt(e.querySelector(".note-modal-tags"),n.tags)}}if(r&&r.classList.contains("note-modal")){let t=(r.dataset.tags||"").split("||").filter(t=>t);t=t.filter(t=>t!==o),r.dataset.tags=t.join("||");const e=h(),n=g(e);if(e&&n){n.tags=(n.tags||[]).filter(t=>t!==o);pt(e.querySelector(".note-modal-tags"),n.tags)}const a=r.dataset.noteId||r.dataset.todoId||(n&&n.id?String(n.id):""),i=a?document.querySelector(`.note-card[data-id="${a}"]`):null;if(i){const t=i.querySelector(`.note-tag[data-tag="${CSS.escape(o)}"]`);t&&t.remove();let e=(i.dataset.tags||"").split("||").filter(t=>t);e=e.filter(t=>t!==o),i.dataset.tags=e.join("||")}}}).catch(t=>{console.error("Error removing tag:",t),alert(window.ShaarliProI18n.t("Error removing tag."))})}),p=!0)}function h(){return document.querySelector(".note-modal-overlay.open")}function g(t){return t&&(t.currentTodo||t.currentNote)||null}const b=`${function(){const t=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).find(t=>t.href&&(t.href.includes("/custom_views.css")||t.href.includes("/custom_views.min.css")));if(t&&t.href){const e=new URL(t.href,window.location.origin).pathname.replace(/\/(css|dist)\/custom_views(\.min)?\.css$/,"");if(e)return e}const e=Array.from(document.querySelectorAll("script[src]")).find(t=>t.src&&(t.src.includes("/custom_views.js")||t.src.includes("/custom_views.min.js")));if(e&&e.src){const t=new URL(e.src,window.location.origin).pathname.replace(/\/(js|dist)\/custom_views(\.min)?\.js$/,"");if(t)return t}return window.shaarli&&"string"==typeof window.shaarli.assetPath&&""!==window.shaarli.assetPath.trim()?window.shaarli.assetPath.replace(/\/$/,""):"/tpl/shaarli-pro"}().replace(/\/$/,"")}/img`;let y=[],v=!1,w=null;function k(){const t=document.getElementById("links-list");if(!t)return;const e=t.querySelector(".pinned-section-head"),o=t.querySelector(".normal-section-head"),n=t.querySelector(".compact-table-head");if(!e||!o||!n)return;const r=Array.from(t.getElementsByClassName("link-outer"));if(!r.length)return;const a=t=>{if(t.classList.contains("is-sticky")||t.classList.contains("is-pinned-tag"))return!0;const e=t.querySelectorAll(".link-tag-list a, .link-tag-list .link-tag-link, .note-tag");for(const t of e){if("shaarli-pin"===(t.textContent||"").trim().toLowerCase())return!0}return!1},i=r.filter(t=>a(t)),l=r.filter(t=>!a(t));t.classList.toggle("has-pinned",i.length>0),t.classList.toggle("has-normal",l.length>0);const s=document.createDocumentFragment();s.appendChild(e),i.forEach(t=>s.appendChild(t)),s.appendChild(o),s.appendChild(n),l.forEach(t=>s.appendChild(t)),t.replaceChildren(s)}window.__shaarliCustomViewsVersion="1.0.5-inline-bg-manifest","undefined"!=typeof console&&console&&console.info,document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("links-list");if(!t)return;k(),["view-grid-btn","view-list-btn","view-compact-btn"].forEach(t=>{const e=document.getElementById(t);e&&e.addEventListener("click",()=>{window.requestAnimationFrame(k)})}),t.addEventListener("click",t=>{t.target.closest('a[href*="/pin?token="]')&&window.setTimeout(()=>{window.location.reload()},500)})});const S=[{key:"cafe",label:window.ShaarliProI18n.t("Coffee"),files:{light:"bg-light-cafe.jpg",dark:"bg-dark-cafe.jpg"}},{key:"codes",label:"Codes",files:{light:"bg-light-codes.jpg",dark:"bg-dark-codes.jpg"}},{key:"dune",label:"Dune",files:{light:"bg-light-dune.jpg",dark:"bg-dark-dune.jpg"}},{key:"feuille-ligne",label:"Feuille Ligne",files:{light:"bg-light-feuilleLigne.jpg",dark:"bg-dark-feuilleLigne.jpg"}},{key:"feuille-quadrillage",label:"Feuille Quadrillage",files:{light:"bg-light-feuilleQuadrille.jpg",dark:"bg-dark-feuilleQuadrille.jpg"}},{key:"fleurs",label:"Fleurs",files:{light:"bg-light-fleurs.jpg",dark:"bg-dark-fleurs.jpg"}},{key:"foret",label:window.ShaarliProI18n.t("Forest"),files:{light:"bg-light-foret.jpg",dark:"bg-dark-foret.jpg"}},{key:"grid",label:"Grid",files:{light:"bg-light-grid.jpg",dark:"bg-dark-grid.jpg"}},{key:"journal",label:"Journal",files:{light:"bg-light-journal.jpg",dark:"bg-dark-journal.jpg"}},{key:"lecture",label:"Lecture",files:{light:"bg-light-lecture.jpg",dark:"bg-dark-lecture.jpg"}},{key:"legumes",label:window.ShaarliProI18n.t("Vegetables"),files:{light:"bg-light-legumes.jpg",dark:"bg-dark-legumes.jpg"}},{key:"montagnes",label:"Montagnes",files:{light:"bg-light-montagnes.jpg",dark:"bg-dark-montagnes.jpg"}},{key:"ocean",label:window.ShaarliProI18n.t("Ocean"),files:{light:"bg-light-ocean.jpg",dark:"bg-dark-ocean.jpg"}},{key:"radio",label:"Radio",files:{light:"bg-light-radio.jpg",dark:"bg-dark-radio.jpg"}},{key:"sports",label:"Sports",files:{light:"bg-light-sports.jpg",dark:"bg-dark-sports.jpg"}},{key:"vague1",label:"Vague 1",files:{light:"bg-light-vague1.jpg",dark:"bg-dark-vague1.jpg"}},{key:"vague2",label:"Vague 2",files:{light:"bg-light-vague2.jpg",dark:"bg-dark-vague2.jpg"}},{key:"ville",label:"Ville",files:{light:"bg-light-ville.jpg",dark:"bg-dark-ville.jpg"}},{key:"voyage",label:"Voyage",files:{light:"bg-light-voyage.jpg",dark:"bg-dark-voyage.jpg"}}];function $(){return v?Promise.resolve(y):w||(y=function(t){const e=Array.isArray(t)?t:t&&Array.isArray(t.backgrounds)?t.backgrounds:[],o={};return e.forEach(t=>{if(!t||"object"!=typeof t)return;const e=L("string"==typeof t.key?t.key:t.label||"");if(!e)return;const n=t.files&&"object"==typeof t.files?t.files:{},r="string"==typeof n.light?n.light.trim():"",a="string"==typeof n.dark?n.dark.trim():"";(r||a)&&(o[e]||(o[e]={key:e,label:E(t.label||"",e),paths:{light:"",dark:""}}),r&&(o[e].paths.light=`note-bg-light/${r}`),a&&(o[e].paths.dark=`note-bg-dark/${a}`))}),Object.values(o).sort((t,e)=>t.label.localeCompare(e.label,"fr",{sensitivity:"base"}))}(S),v=!0,w=Promise.resolve(y),w)}function L(t){return"string"!=typeof t?"":t.trim().toLowerCase().replace(/[\s_]+/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function E(t,e){return("string"==typeof t&&""!==t.trim()?t:e).replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().split(" ").filter(t=>""!==t).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function P(){return"dark"===document.documentElement.getAttribute("data-theme")?"dark":"light"}function C(t,e=P()){if(!t||"object"!=typeof t)return"";const o="dark"===e?"dark":"light",n="string"==typeof t[o]?t[o].trim():"",r="string"==typeof t.light?t.light.trim():"",a="string"==typeof t.dark?t.dark.trim():"";return n||r||a}function q(t,e=P()){const o=function(t){if("string"!=typeof t)return null;const e=t.trim(),o=/^#([0-9a-f]{3})$/i.exec(e);if(o)return{r:parseInt(o[1].charAt(0).repeat(2),16),g:parseInt(o[1].charAt(1).repeat(2),16),b:parseInt(o[1].charAt(2).repeat(2),16)};const n=/^#([0-9a-f]{6})$/i.exec(e);return n?{r:parseInt(n[1].slice(0,2),16),g:parseInt(n[1].slice(2,4),16),b:parseInt(n[1].slice(4,6),16)}:null}(t);if(!o)return"dark"===e?"#e8eaed":"#202124";return(.299*o.r+.587*o.g+.114*o.b)/255>.56?"#202124":"#f5f7fb"}function I(t=P()){const e="dark"===t?"dark":"light";return y.filter(t=>t.paths&&t.paths[e])}function x(t,e=P()){const o=L(t);if(!o)return"";const n=y.find(t=>t.key===o);if(!n||!n.paths)return"";const r="dark"===e?"dark":"light",a=n.paths[r]||"";return a?`${b}/${a}`:""}function _(t){if(!t)return"default";if("custom"===t.dataset.color&&t.dataset.customColor)return`custom:${t.dataset.customColor}`;const e=Array.from(t.classList).find(t=>t.startsWith("note-color-"));return e?e.replace("note-color-",""):t.dataset.color||"default"}function A(t){if(!t)return"none";return L(t.dataset.background||"")||"none"}function M(t){if("string"!=typeof t)return"none";const e=t.trim().toLowerCase();return n.some(t=>t.key===e)?e:"none"}function U(t){return t?M(t.dataset.filter||""):"none"}function T(t){return t&&t.dataset.fontColor||"auto"}let N=!1;function D(t){if(!t||!t.classList.contains("open"))return;t.classList.remove("open-down"),t.style.left="",t.style.right="";if(t.getBoundingClientRect().top<8){t.classList.add("open-down");t.getBoundingClientRect().bottom>window.innerHeight-8&&t.classList.remove("open-down")}let e=t.getBoundingClientRect();e.right>window.innerWidth-8&&(t.style.left="auto",t.style.right="0",e=t.getBoundingClientRect()),e.left<8&&(t.style.left="0",t.style.right="auto")}let F=!1;function H(){const t=document.getElementById("shaarli-bg-studio");t&&(t.classList.remove("open"),t.style.display="none",t.setAttribute("aria-hidden","true"),t.__anchorEl=null)}function j({anchorEl:t,mode:e,entityId:o,editUrl:n,currentColor:r,currentFilter:a,currentBackground:i,currentFontColor:l,title:s}){!function(){if(F)return;if(document.getElementById("shaarli-bg-studio"))return void(F=!0);const t=document.createElement("div");t.id="shaarli-bg-studio",t.className="bg-studio-panel",t.setAttribute("role","dialog"),t.setAttribute("aria-modal","false"),t.setAttribute("aria-hidden","true"),t.style.display="none",document.body.appendChild(t),t.addEventListener("click",t=>{const e=t.target.closest("button[data-bg-studio-action]");if(!e)return;const o=document.getElementById("shaarli-bg-studio");if(!o)return;const n=o.dataset.mode||"entity",r=o.dataset.entityId||"",a=o.dataset.editUrl||"",i=t=>{"function"==typeof o.__draftApply&&o.__draftApply(t)},l=e.dataset.bgStudioAction;if("close"!==l){if("set-color"===l){const t=e.dataset.colorKey||"default";return void("draft"===n?(o.dataset.color=t,i({color:t}),R(o)):"modal"===n?(setModalNoteColor(t),o.dataset.color=t,R(o)):(setNoteColor(r,t,a),o.dataset.color=t,R(o)))}if("set-background"===l){const t=e.dataset.bgKey||"none";return void("draft"===n?(o.dataset.background=t,i({background:t}),R(o)):"modal"===n?(setModalNoteBackground(t),o.dataset.background=t,R(o)):(setNoteBackground(r,t,a),o.dataset.background=t,R(o)))}if("set-filter"===l){const t=e.dataset.filter||"none",l=M(t||"")||"none";return void("draft"===n?(o.dataset.filter=l,i({filter:l}),R(o)):"modal"===n?(setModalNoteFilter(t),o.dataset.filter=l,R(o)):(setNoteFilter(r,t,a),o.dataset.filter=l,R(o)))}if("set-query"===l){o.dataset.query="",R(o);const t=o.querySelector(".bg-studio-search-input");return void(t&&t.focus())}if("set-defaults"!==l)if("reset-font-color"!==l)if("open-color-picker"!==l)if("open-font-color-picker"!==l){if("set-font-color"===l){const t=e.dataset.fontColorKey||"auto";return void("draft"===n?(o.dataset.fontColor=t,i({fontColor:t}),R(o)):"modal"===n?(Ct(t),o.dataset.fontColor=t,R(o)):(Pt(r,t,a),o.dataset.fontColor=t,R(o)))}}else kt({mode:n,entityId:r,editUrl:a,type:"font"});else kt({mode:n,entityId:r,editUrl:a,type:"background"});else"draft"===n?(o.dataset.fontColor="auto",i({fontColor:"auto"}),R(o)):"modal"===n?(Ct("auto"),o.dataset.fontColor="auto",R(o)):(Pt(r,"auto",a),o.dataset.fontColor="auto",R(o));else"draft"===n?(o.dataset.color="default",o.dataset.background="none",i({color:"default",background:"none"}),R(o)):"modal"===n?(setModalNoteColor("default"),o.dataset.color="default",o.dataset.background="none",R(o)):(setNoteColor(r,"default",a),o.dataset.color="default",o.dataset.background="none",R(o))}else H()}),t.addEventListener("keydown",e=>{const o=e.target&&e.target.closest?e.target.closest("button"):null;if(!o)return;if("Enter"===e.key||" "===e.key)return void((o.hasAttribute("data-bg-studio-action")||o.classList.contains("bg-studio-thumb")||o.classList.contains("bg-studio-swatch"))&&(e.preventDefault(),o.click()));const n=(t,e)=>{if(!t||0===t.length)return;const o=t[Math.max(0,Math.min(t.length-1,e))];o&&"function"==typeof o.focus&&o.focus()};if(o.classList.contains("bg-studio-thumb")){const r=Array.from(t.querySelectorAll(".bg-studio-gallery .bg-studio-thumb")),a=r.indexOf(o);if(-1===a)return;const i=2;return void("ArrowRight"===e.key?(e.preventDefault(),n(r,a+i)):"ArrowLeft"===e.key?(e.preventDefault(),n(r,a-i)):"ArrowDown"===e.key?(e.preventDefault(),n(r,a+1)):"ArrowUp"===e.key&&(e.preventDefault(),n(r,a-1)))}if(o.classList.contains("bg-studio-swatch")){const r=Array.from(t.querySelectorAll(".bg-studio-swatches .bg-studio-swatch")),a=r.indexOf(o);if(-1===a)return;return void("ArrowRight"===e.key?(e.preventDefault(),n(r,a+1)):"ArrowLeft"===e.key&&(e.preventDefault(),n(r,a-1)))}}),t.addEventListener("input",t=>{const e=t.target&&t.target.matches(".bg-studio-search-input")?t.target:null;if(!e)return;const o=document.getElementById("shaarli-bg-studio");o&&(o.dataset.query=e.value||"",window.clearTimeout(o.__searchTimer),o.__searchTimer=window.setTimeout(()=>{R(o)},150))}),F=!0}();const d=document.getElementById("shaarli-bg-studio");d&&(d.dataset.mode=e||"entity",d.dataset.entityId=o||"",d.dataset.editUrl=n||"",d.dataset.color=r||"default",d.dataset.filter=M(a||"")||"none",d.dataset.background=L(i||"")||"none",d.dataset.fontColor=l||d.dataset.fontColor||"auto",d.dataset.query=d.dataset.query||"",d.dataset.title=s||window.ShaarliProI18n.t("My images & colors"),d.__anchorEl=t||null,R(d),d.style.display="block",d.classList.add("open"),d.setAttribute("aria-hidden","false"),function(t,e){if(!t)return;const o=12,n=e&&e.getBoundingClientRect?e.getBoundingClientRect():null;t.style.left="",t.style.top="",t.style.right="",t.style.bottom="";const r=t.getBoundingClientRect(),a=n?n.top-r.height-10:o,i=n?n.left:o;let l=a;l<o&&(l=n?n.bottom+10:o);let s=i;s+r.width>window.innerWidth-o&&(s=window.innerWidth-o-r.width);s<o&&(s=o);l+r.height>window.innerHeight-o&&(l=window.innerHeight-o-r.height);l<o&&(l=o);t.style.left=`${Math.round(s)}px`,t.style.top=`${Math.round(l)}px`}(d,t),window.requestAnimationFrame(()=>{const t=d.querySelector(".bg-studio-search-input");t&&"function"==typeof t.focus&&(t.focus(),t.select())}))}function B(t){return String(t||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim()}function W(t,e){const o=B(`${t||""} ${e||""}`);return t&&"none"!==t?o.includes("degrade")||o.includes("gradient")?"gradient":o.includes("grid")||o.includes("quadrill")||o.includes("lign")||o.includes("feuille")?"grid":o.includes("damier")||o.includes("checker")||o.includes("texture")?"texture":"image":"solid"}function R(t){if(!t)return;const e=document.activeElement,a=!!(e&&t.contains(e)&&e.classList&&e.classList.contains("bg-studio-search-input")),i=a&&"number"==typeof e.selectionStart?e.selectionStart:null,l=a&&"number"==typeof e.selectionEnd?e.selectionEnd:null,s=t.dataset.title||window.ShaarliProI18n.t("My images & colors"),d=t.dataset.color||"default",c="string"==typeof d&&d.startsWith("custom:"),u=t.dataset.filter||"none",m=t.dataset.fontColor||"auto",p=B(t.dataset.query||""),{colors:f,backgrounds:h}={colors:o.map(t=>({type:"color",key:t.key,label:t.label,color:C(t),keywords:[t.key,t.label]})),backgrounds:[{type:"background",category:"solid",key:"none",label:window.ShaarliProI18n.t("Solid color"),keywords:["none","sans image","solid","uni"]},...I().map(t=>({type:"background",category:W(t.key,t.label),key:t.key,label:t.label,url:x(t.key),keywords:[t.key,t.label,"image","background"]}))]},g=h.filter(t=>{if(!p)return!0;return B([t.label,t.key,"image","background"].join(" ")).includes(p)}).map(e=>{const o=t.dataset.background===e.key,n=`class="bg-studio-thumb ${o?"is-active":""}" type="button"`;return`<div class="bg-studio-tile">${"none"===e.key?`<button ${n} data-bg-studio-action="set-background" data-bg-key="none" title="${e.label}" aria-label="${e.label}" aria-pressed="${o}"><span class="bg-studio-thumb-solid"></span></button>`:`<button ${n} data-bg-studio-action="set-background" data-bg-key="${e.key}" title="${e.label}" aria-label="${e.label}" aria-pressed="${o}" style="background-image:url('${e.url||""}')"></button>`}<div class="bg-studio-thumb-label">${e.label}</div></div>`}).join(""),b=f.filter(t=>"default"!==t.key&&"custom"!==t.key).map(t=>{const e=d===t.key,o=t.color||"";return`<button class="bg-studio-swatch ${e?"is-active":""}" type="button" data-bg-studio-action="set-color" data-color-key="${t.key}" title="${o}" aria-label="${t.label}" aria-pressed="${e}" style="background-color:${o}"></button>`}).join("")+`<button class="bg-studio-swatch bg-studio-swatch-custom ${c?"is-active":""}" type="button" data-bg-studio-action="open-color-picker" title="${window.ShaarliProI18n.t("Custom color")}" aria-label="${window.ShaarliProI18n.t("Custom color")}" aria-pressed="${c}">\n <i class="mdi mdi-plus" aria-hidden="true"></i>\n </button>`,y="string"==typeof m&&m.startsWith("custom:"),v=r.filter(t=>"custom"!==t.key).map(t=>{const e=m===t.key,o=t.value||"auto",n="auto"===o?"background: linear-gradient(135deg, #f5f7fb 50%, #202124 50%);":`background-color: ${o};`;return`<button class="bg-studio-swatch ${e?"is-active":""}" type="button" data-bg-studio-action="set-font-color" data-font-color-key="${t.key}" title="${t.label}" aria-label="${t.label}" aria-pressed="${e}" style="${n}"></button>`}).join("")+`<button class="bg-studio-swatch bg-studio-swatch-custom ${y?"is-active":""}" type="button" data-bg-studio-action="open-font-color-picker" title="${window.ShaarliProI18n.t("Custom font color")}" aria-label="${window.ShaarliProI18n.t("Custom font color")}" aria-pressed="${y}">\n <i class="mdi mdi-plus" aria-hidden="true"></i>\n </button>`,w=n.map(t=>((t,e,o)=>{const n=u===t;return`<button class="bg-studio-filter-btn ${n?"is-active":""}" type="button" data-bg-studio-action="set-filter" data-filter="${t}" title="${o}" aria-label="${o}" aria-pressed="${n}"><i class="mdi ${e}" aria-hidden="true"></i></button>`})(t.key,t.icon,t.label)).join(""),k=!!(t.dataset.query||"").trim();if(t.innerHTML=`\n <div class="bg-studio-header">\n <div class="bg-studio-title">${s}</div>\n <button class="bg-studio-close" type="button" data-bg-studio-action="close" title="${window.ShaarliProI18n.t("Close")}" aria-label="${window.ShaarliProI18n.t("Close")}"><i class="mdi mdi-close" aria-hidden="true"></i></button>\n </div>\n <div class="bg-studio-gallery" role="list">${g}</div>\n <div class="bg-studio-rows">\n <div class="bg-studio-row">\n <div class="bg-studio-row-heading">\n <div class="bg-studio-row-label">Colors:</div>\n <button type="button" class="bg-studio-reset" data-bg-studio-action="set-defaults" title="${window.ShaarliProI18n.t("Reset")}" aria-label="${window.ShaarliProI18n.t("Reset")}"><i class="mdi mdi-refresh" aria-hidden="true"></i></button>\n </div>\n <div class="bg-studio-swatches" role="list">${b}</div>\n </div>\n <div class="bg-studio-row">\n <div class="bg-studio-row-heading">\n <div class="bg-studio-row-label">Font:</div>\n <button type="button" class="bg-studio-reset" data-bg-studio-action="reset-font-color" title="${window.ShaarliProI18n.t("Reset")}" aria-label="${window.ShaarliProI18n.t("Reset")}"><i class="mdi mdi-refresh" aria-hidden="true"></i></button>\n </div>\n <div class="bg-studio-swatches bg-studio-swatches-font" role="list">${v}</div>\n </div>\n <div class="bg-studio-row">\n <div class="bg-studio-row-label">Filtres:</div>\n <div class="bg-studio-filters">${w}</div>\n </div>\n </div>\n <div class="bg-studio-search">\n <i class="mdi mdi-magnify" aria-hidden="true"></i>\n <input class="bg-studio-search-input" type="search" placeholder="${window.ShaarliProI18n.t("Search my images… (filter by color or filter)")}" value="${t.dataset.query||""}" />\n <button class="bg-studio-clear" type="button" data-bg-studio-action="set-query" title="${window.ShaarliProI18n.t("Clear search")}" aria-label="${window.ShaarliProI18n.t("Clear search")}" style="${k?"":"display:none"}"><i class="mdi mdi-close-circle-outline" aria-hidden="true"></i></button>\n </div>\n `,a){const e=t.querySelector(".bg-studio-search-input");if(e&&"function"==typeof e.focus&&(e.focus({preventScroll:!0}),"function"==typeof e.setSelectionRange)){const t=(e.value||"").length,o="number"==typeof i?Math.max(0,Math.min(t,i)):t,n="number"==typeof l?Math.max(0,Math.min(t,l)):t;try{e.setSelectionRange(o,n)}catch(t){}}}}function O(t,e){if(!t||!e)return;const n=e.color||"default",a="string"==typeof n&&n.startsWith("custom:"),i=a?n.substring(7):"",l=a?null:function(t){const e="string"==typeof t?t.trim().toLowerCase():"";return o.find(t=>t.key===e)||o.find(t=>"default"===t.key)||null}(n),s=a?"custom":l?l.key:"default",d=a?i:C(l),c=q(d),u=M(e.filter||"none"),m=L(e.background||"")||"none",p=e.fontColor||"auto";if(Array.from(t.classList).forEach(e=>{e.startsWith("note-color-")&&t.classList.remove(e),e.startsWith("note-filter-")&&t.classList.remove(e)}),t.classList.add(`note-color-${s}`),"none"!==u&&t.classList.add(`note-filter-${u}`),d&&"default"!==s?(t.style.backgroundColor=d,t.style.removeProperty("border-color")):t.style.removeProperty("background-color"),c&&"default"!==s?t.style.setProperty("--note-card-fg",c):t.style.removeProperty("--note-card-fg"),p&&"auto"!==p){let e=null;if("string"==typeof p&&p.startsWith("custom:"))e=p.substring(7);else{const t=r.find(t=>t.key===p);t&&t.value&&"auto"!==t.value&&(e=t.value)}e&&t.style.setProperty("--note-card-fg",e)}if(m&&"none"!==m){const e=x(m);e?(t.classList.add("note-has-bg"),t.style.setProperty("--note-bg-image",`url('${e}')`),t.dataset.background=m):(t.classList.remove("note-has-bg"),t.style.removeProperty("--note-bg-image"),t.dataset.background="none")}else t.classList.remove("note-has-bg"),t.style.removeProperty("--note-bg-image"),t.dataset.background="none";t.dataset.color=s,t.dataset.customColor=a&&i?i:"",t.dataset.filter=u,t.dataset.fontColor=p}function K(t){const e=Array.isArray(t)?t:[];let n="default";const r=e.find(t=>"string"==typeof t&&t.startsWith(i));if(r){const t=r.substring(i.length);/^[0-9A-Fa-f]{6}$/.test(t)?n=`custom:#${t.toUpperCase()}`:o.some(e=>e.key===t)&&(n=t)}else{const t=e.find(t=>"string"==typeof t&&t.startsWith("note-custom-"));if(t){const e=t.substring(12);/^[0-9A-Fa-f]{6}$/.test(e)&&(n=`custom:#${e.toUpperCase()}`)}const r=e.find(t=>"string"==typeof t&&t.startsWith("note-"));if(r){const t=r.substring(5);o.some(e=>e.key===t)&&(n=t)}}let d="none";const c=e.find(t=>"string"==typeof t&&t.startsWith(l));if(c){const t=M(c.substring(l.length));t&&"none"!==t&&(d=t)}let u="none";const m=e.find(t=>"string"==typeof t&&t.startsWith(s));if(m){const t=L(m.substring(s.length));t&&(u=t)}let p="auto";const f=e.find(t=>"string"==typeof t&&t.startsWith(a));if(f){const t=f.substring(a.length),e=t.startsWith("#")?t:`#${t}`;/^#[0-9A-Fa-f]{6}$/.test(e)&&(p=`custom:${e.toUpperCase()}`)}return{color:n,filter:d,background:u,fontColor:p}}function V(){const t=Array.from(document.querySelectorAll(".link-outer"));0!==t.length&&(t.forEach(t=>{const e=t.dataset.id||t.getAttribute("data-id")||t.id;if(!e)return;const o=Array.from(t.querySelectorAll(".link-tag a")).map(t=>(t.textContent||"").trim()),{color:n,filter:r,background:a,fontColor:i}=K(o);O(t,{color:n,filter:r,background:a,fontColor:i});const l=t.querySelector(".link-actions");if(!l)return;if(l.querySelector(".bookmark-palette"))return;const s=l.querySelector(`a[title="${window.ShaarliProI18n.t("Edit")}"], a[href*="/admin/shaare/"]`);if(!s||!s.href)return;const d=s.href,c=`bookmark-palette-${e}`,u=document.createElement("div");u.className="bookmark-palette",u.style.position="relative",u.innerHTML=`\n <button type="button" title="${window.ShaarliProI18n.t("Color")}" aria-label="${window.ShaarliProI18n.t("Color")}" id="${c}"><i class="mdi mdi-palette-outline" aria-hidden="true"></i></button>\n `;const m=Array.from(l.querySelectorAll(`a[href*="/pin"], a[aria-label*="${window.ShaarliProI18n.t("Pin")}"], a[title*="${window.ShaarliProI18n.t("Pin")}"]`))[0];m&&m.parentNode===l?l.insertBefore(u,m):s&&s.parentNode===l?l.insertBefore(u,s.nextSibling):l.appendChild(u);const p=u.querySelector(`#${c}`);p&&p.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),j({anchorEl:p,mode:"entity",entityId:e,editUrl:d,currentColor:_(t),currentFilter:U(t),currentBackground:A(t),currentFontColor:T(t),title:window.ShaarliProI18n.t("My images & colors")})})}),document.addEventListener("click",t=>{t.target.closest(".bookmark-palette")||t.target.closest("#shaarli-bg-studio")||H()}))}function X(t,e,o,n){return G({entityId:t,editUrl:e,currentColor:o,currentFilter:n,mode:"entity"})}function G({entityId:t,editUrl:e,currentColor:r,currentFilter:a,mode:i}){const l=r||"default",s=M(a||"")||"none",d="modal"===i?t=>`setModalNoteColor('${t}')`:o=>`setNoteColor('${t}', '${o}', '${e}')`,c="modal"===i?t=>`setModalNoteFilter('${t}')`:o=>`setNoteFilter('${t}', '${o}', '${e}')`;return`\n <div class="palette-section">\n <div class="palette-section-title">Couleurs</div>\n <div class="palette-row palette-row-colors">${[`<button class="palette-btn palette-btn-default ${"default"===l?"is-active":""}" type="button" title="${window.ShaarliProI18n.t("Default")}" aria-label="${window.ShaarliProI18n.t("Default")}" aria-pressed="${"default"===l}" onclick="${d("default")}"><i class="mdi mdi-format-color-reset" aria-hidden="true"></i></button>`,...o.filter(t=>"default"!==t.key).map(t=>{const e=C(t);return`<button class="palette-btn note-color-${t.key} ${l===t.key?"is-active":""}" type="button" title="${t.label}" aria-label="${t.label}" aria-pressed="${l===t.key}" onclick="${d(t.key)}" style="background-color:${e}"></button>`})].join("")}</div>\n </div>\n <div class="palette-divider"></div>\n <div class="palette-section">\n <div class="palette-section-title">Filtres</div>\n <div class="palette-row palette-row-filters">${[`<button class="palette-btn palette-btn-filter-none ${"none"===s?"is-active":""}" type="button" title="Aucun" aria-label="Aucun" aria-pressed="${"none"===s}" onclick="${c("none")}"><i class="mdi mdi-close-circle-outline" aria-hidden="true"></i></button>`,...n.filter(t=>"none"!==t.key).map(t=>`<button class="palette-btn palette-btn-filter ${s===t.key?"is-active":""}" type="button" title="${t.label}" aria-label="${t.label}" aria-pressed="${s===t.key}" onclick="${c(t.key)}"><i class="mdi ${t.icon}" aria-hidden="true"></i></button>`)].join("")}</div>\n </div>\n `}function Q(t,e){if(!t||!e)return;const o=Array.from(e.classList).find(t=>t.startsWith("note-color-"));o&&(t.color=o.replace("note-color-","")||"default");const n=e.dataset.filter;t.filter=n&&"none"!==n?n:"none";const r=e.dataset.background;t.background=r&&"none"!==r?r:"none"}function Y(t){if(!t)return"";if("TEXTAREA"===(t.tagName||"").toUpperCase()){const e="string"==typeof t.value?t.value:"";if(e&&""!==e.trim())return e;return"string"==typeof t.textContent?t.textContent:""}return t.value}async function z(t){const e=await fetch(t,{credentials:"same-origin"}),o=await e.text(),n=(new DOMParser).parseFromString(o,"text/html").querySelector('form[name="linkform"]');if(!n)throw new Error("Could not find edit form");const r=new URLSearchParams;return n.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&r.append(t.name,t.value||"on"):t.name&&r.append(t.name,Y(t))}),{action:n.action,baseData:r}}async function J({title:t,markdown:e,visual:o=null}){const n="undefined"!=typeof shaarli&&shaarli.basePath?shaarli.basePath:"",d=window.ShaarItRules?window.ShaarItRules.generateNoteUrl():"",c=`${n}/admin/shaare?post=${encodeURIComponent(d)}&tags=note`,{action:u,baseData:m}=await z(c),p=new URLSearchParams(m.toString());p.set("lf_url",d),p.set("lf_title",t||""),p.set("lf_description",e||"");let f=(p.get("lf_tags")||"").trim().split(/[\s,]+/).filter(t=>""!==t.trim());if(f=f.filter(t=>"shaarli-todo"!==t),f.includes("note")||f.push("note"),f.includes("shaarli-note")||f.push("shaarli-note"),o){const t=o.color||"default",e=M(o.filter||"")||"none",n=L(o.background||"")||"none",d=o.fontColor||"auto";if(f=f.filter(t=>!t.startsWith(i)),f=f.filter(t=>!t.startsWith(l)),f=f.filter(t=>!t.startsWith(s)),f=f.filter(t=>!t.startsWith(a)),t&&"default"!==t)if("string"==typeof t&&t.startsWith("custom:")){const e=t.substring(7).replace("#","");e&&f.push(`${i}${e}`)}else f.push(`${i}${t}`);if(e&&"none"!==e&&f.push(`${l}${e}`),n&&"none"!==n&&f.push(`${s}${n}`),d&&"auto"!==d)if("string"==typeof d&&d.startsWith("custom:")){const t=d.substring(7).replace("#","");t&&f.push(`${a}${t}`)}else{const t=r.find(t=>t.key===d);t&&t.value&&"auto"!==t.value&&f.push(`${a}${t.value.substring(1)}`)}}p.set("lf_tags",f.join(" ")),p.get("returnurl")||p.set("returnurl",window.location.href),p.append("save_edit","1");const h=await fetch(u,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:p.toString()});if(!h.ok)throw new Error(`Failed to create note (status ${h.status})`)}async function Z(t){if(t&&t.editUrl&&"#"!==t.editUrl&&!t._noteHydrated)return t._noteHydratePromise||(t._noteHydratePromise=(async()=>{try{const{action:e,baseData:o}=await z(t.editUrl);t._noteEditAction=e,t._noteEditBaseData=o,t._noteMarkdown=o.get("lf_description")||"",t._noteTitle=o.get("lf_title")||"",t._noteHydrated=!0}catch(t){console.error("Error hydrating note edit form:",t)}finally{t._noteHydratePromise=null}})()),t._noteHydratePromise}async function tt(t,{title:e,markdown:o},n=0){if(!t||!t.editUrl||"#"===t.editUrl)return;const r=async()=>{const{action:e,baseData:o}=await z(t.editUrl);t._noteEditAction=e,t._noteEditBaseData=o};t._noteEditAction&&t._noteEditBaseData&&t._noteEditBaseData.get&&t._noteEditBaseData.get("token")||await r();const a=new URLSearchParams(t._noteEditBaseData.toString());a.set("lf_title",e||""),a.set("lf_description",o||"");let i=(a.get("lf_tags")||"").trim().split(/[\s,]+/).filter(t=>""!==t.trim());i=i.filter(t=>"shaarli-todo"!==t),i.includes("note")||i.push("note"),i.includes("shaarli-note")||i.push("shaarli-note"),a.set("lf_tags",i.join(" ")),a.append("save_edit","1");const l=await fetch(t._noteEditAction,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:a.toString()});if(!l.ok){if(403===l.status&&n<1)return t._noteEditAction="",t._noteEditBaseData=null,await r(),tt(t,{title:e,markdown:o},n+1);throw new Error("Failed to save note")}}function et(t,e,o){if(!t)return;t.innerHTML="",t.className="grid"===o?"notes-masonry":"notes-list-view";const n=(e||[]).slice();n.sort((t,e)=>{const o=(t.tags||[]).includes("shaarli-pin");return(e.tags||[]).includes("shaarli-pin")-o}),n.forEach(e=>{const n=document.createElement("div");n.className="note-card todo-card",n.dataset.id=e.id,n.dataset.editUrl=e.editUrl||"",n.dataset.tags=(e.tags||[]).filter(t=>t).join("||"),e._todoCardEl=n,O(n,e),"list"===o&&n.classList.add("list-mode"),n.addEventListener("click",t=>{t.target.closest("button")||t.target.closest("a")||t.target.closest(".note-hover-actions")||(Q(e,n),async function(t){const e=document.querySelector(".todo-modal-overlay");if(!e)return;const o=e.querySelector(".note-modal"),n=e.querySelector("#todo-modal-title"),r=e.querySelector("#todo-modal-tags"),a=e.querySelector("#todo-modal-edit"),i=e.querySelector("#todo-modal-pin"),l=e.querySelector("#todo-modal-color-popup");e.currentTodo=t,o.className="note-modal todo-modal",O(o,t),o.dataset.todoId=t.id||"",o.dataset.editUrl=t.editUrl||"",o.dataset.deleteUrl=t.deleteUrl||"",o.dataset.background=t.background||"none";const s=(t.tags||[]).filter(t=>t&&!d(t));o.dataset.tags=s.join("||"),n.textContent=t.title||window.ShaarliProI18n.t("Untitled"),pt(r,s),a&&(a.href=t.editUrl||"#");l&&(l.innerHTML=G({entityId:t&&t.id?t.id:"",editUrl:t&&t.editUrl?t.editUrl:"",currentColor:t&&t.color?t.color:"default",currentFilter:t&&t.filter?t.filter:"none",mode:"modal"}),l.classList.remove("open"));mt(i,!!t.isPinned),e.classList.add("open"),at(e,t);const c=`${t.id}-${Date.now()}`;if(e._todoLoadKey=c,t.editUrl&&"#"!==t.editUrl)try{const o=await fetch(t.editUrl,{credentials:"same-origin"});if(!o.ok)return void console.error("Todo modal load failed (edit form fetch not ok).",{id:t&&t.id,url:t&&t.editUrl,status:o&&o.status});const n=await o.text();if(e._todoLoadKey!==c)return;const r=new DOMParser,a=r.parseFromString(n,"text/html").querySelector('form[name="linkform"]');if(!a)return void console.error("Todo modal load failed (edit form not found).",{id:t&&t.id,url:t&&t.editUrl,status:o&&o.status});const i=new URLSearchParams;a.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&i.append(t.name,t.value||"on"):t.name&&i.append(t.name,Y(t))}),t._todoEditAction=a.action,t._todoEditBaseData=i;const l=rt(i.get("lf_description")||"");t._todoHeaderLines=l.headerLines,t._todoFooterLines=l.footerLines,t.items=l.items,at(e,t)}catch(t){console.error("Error loading todo markdown:",t)}}(e))});const r=document.createElement("div");if(r.className="note-inner",e.title){const t=document.createElement("h3");t.className="note-title",t.textContent=e.title,r.appendChild(t)}const a=document.createElement("div");if(a.className="note-body todo-checklist-preview-wrap",a.innerHTML=ot(e.items||[]),r.appendChild(a),(e.tags||[]).length>0){const t=document.createElement("div");t.className="note-tags",e.tags.forEach(o=>{if(d(o))return;const n=c({tag:o,onRemoveClass:"note-tag-remove-btn",tagClass:"note-tag",canRemove:!!e.editUrl&&"#"!==e.editUrl});t.appendChild(n)}),r.appendChild(t)}const i=document.createElement("div");i.className="note-hover-actions";const l=document.createElement("a");l.href=e.pinUrl,l.title=e.isPinned?"Unpin":"Pin",l.className="note-pin-corner "+(e.isPinned?"active":""),l.innerHTML=`<i class="mdi mdi-pin${e.isPinned?"":"-outline"}"></i>`,r.appendChild(l);const s=`palette-${e.id}`;i.innerHTML=`\n <div style="position:relative;">\n <button title="${window.ShaarliProI18n.t("Color")}" id="${s}"><i class="mdi mdi-palette-outline"></i></button>\n </div>\n <div class="spacer"></div>\n <a href="${e.editUrl}" title="${window.ShaarliProI18n.t("Edit")}"><i class="mdi mdi-pencil-outline"></i></a>\n <button title="${window.ShaarliProI18n.t("Delete")}" class="todo-delete-btn"><i class="mdi mdi-delete-outline"></i></button>\n `;const u=i.querySelector(".todo-delete-btn");u?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),confirm(window.ShaarliProI18n.t("Delete this task?"))&&m(e.deleteUrl).then(()=>{window.location.href="/?searchtags=todo"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})});const p=i.querySelector(`#${s}`);p.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),j({anchorEl:p,mode:"entity",entityId:e.id,editUrl:e.editUrl,currentColor:_(n),currentFilter:U(n),currentBackground:A(n),title:window.ShaarliProI18n.t("My images & colors")})}),r.appendChild(i),n.appendChild(r),t.appendChild(n),async function(t){if(t&&t.editUrl&&"#"!==t.editUrl&&!t._todoHydrated)t._todoHydratePromise||(t._todoHydratePromise=(async()=>{try{const e=await fetch(t.editUrl,{credentials:"same-origin"});if(!e.ok)return void console.error("Todo hydration failed (edit form fetch not ok).",{id:t&&t.id,url:t&&t.editUrl,status:e&&e.status});const o=await e.text(),n=(new DOMParser).parseFromString(o,"text/html").querySelector('form[name="linkform"]');if(!n)return void console.error("Todo hydration failed (edit form not found).",{id:t&&t.id,url:t&&t.editUrl,status:e&&e.status});const r=new URLSearchParams;n.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&r.append(t.name,t.value||"on"):t.name&&r.append(t.name,Y(t))}),t._todoEditAction=n.action,t._todoEditBaseData=r;const a=rt(r.get("lf_description")||"");t._todoHeaderLines=a.headerLines,t._todoFooterLines=a.footerLines,t.items=a.items,lt(t),t._todoHydrated=!0}catch(t){console.error("Error hydrating todo markdown:",t)}finally{t._todoHydratePromise=null}})()),t._todoHydratePromise}(e)})}function ot(t){const e=Array.isArray(t)?t:[],o=e.slice(0,8),n=e.length>8;return`<ul class="todo-checklist-preview">${o.map(t=>`<li class="todo-checklist-preview-item${!!t.checked?" is-checked":""}"><span class="todo-checklist-preview-box"><i class="mdi mdi-check"></i></span><span class="todo-checklist-preview-text">${nt(String(t.text||""))}</span></li>`).join("")}${n?'<li class="todo-checklist-preview-more">...</li>':""}</ul>`}function nt(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}function rt(t){const e=String(t||"").replace(/<br\s*\/?\s*>/gi,"\n").replace(/<\/(p|div|li|h\d)\s*>/gi,"\n");let o=e;try{const t=document.createElement("div");t.innerHTML=e;const n=Array.from(t.querySelectorAll('input[type="checkbox"]'));if(n.length>0){const t=[];return n.forEach(e=>{const o=e.closest("li")||e.parentElement;let n="";if(o){const t=o.cloneNode(!0);t.querySelectorAll('input[type="checkbox"]').forEach(t=>t.remove()),n=(t.textContent||"").trim()}t.push({checked:!!e.checked,text:n})}),{headerLines:[],footerLines:[],items:t}}const r=Array.from(t.querySelectorAll("li"));if(r.length>0){const t=r.map(t=>({checked:!1,text:(t.textContent||"").trim()})).filter(t=>t.text);if(t.length>0)return{headerLines:[],footerLines:[],items:t}}o=t.textContent||e}catch(t){o=e}const n=o.split(/\r?\n/),r=[/^\s*[-*+]\s*\[([ xX])\]\s*(.*)$/,/^\s*\[([ xX])\]\s*(.*)$/,/^\s*☐\s*(.*)$/,/^\s*☑\s*(.*)$/];let a=-1,i=-1;const l=[];n.forEach((t,e)=>{let o=!1;for(let n=0;n<r.length;n++){const s=r[n],d=t.match(s);if(d){o=!0,-1===a&&(a=e),i=e,2===n?l.push({checked:!1,text:(d[1]||"").trim()}):3===n?l.push({checked:!0,text:(d[1]||"").trim()}):l.push({checked:"x"===String(d[1]||"").toLowerCase(),text:(d[2]||"").trim()});break}}});return{headerLines:-1===a?n.slice():n.slice(0,a),footerLines:-1===i?[]:n.slice(i+1),items:l}}function at(t,e){const o=t.querySelector("#todo-modal-checklist");if(!o)return;o.innerHTML="";(Array.isArray(e.items)?e.items:[]).forEach((n,r)=>{const a=document.createElement("div");a.className="todo-checklist-row",a.dataset.index=String(r),a.setAttribute("draggable","true"),a.classList.toggle("is-checked",!!n.checked),a.innerHTML=`\n <button type="button" class="todo-drag-handle" aria-label="${window.ShaarliProI18n.t("Move")}"><i class="mdi mdi-dots-grid"></i></button>\n <label class="todo-checklist-box">\n <input type="checkbox" class="todo-item-checkbox" ${n.checked?"checked":""}>\n <span class="todo-checklist-box-ui"></span>\n </label>\n <input type="text" class="todo-item-text" value="${nt(n.text||"")}" placeholder="">\n <button type="button" class="todo-item-delete" aria-label="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-close"></i></button>\n `;const i=a.querySelector(".todo-item-checkbox"),l=a.querySelector(".todo-item-text"),s=a.querySelector(".todo-item-delete");i.addEventListener("change",()=>{e.items[r].checked=i.checked,it(t,e),a.classList.toggle("is-checked",i.checked)}),l.addEventListener("input",()=>{e.items[r].text=l.value,it(t,e)}),s.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),e.items.splice(r,1),at(t,e),it(t,e)}),a.addEventListener("dragstart",t=>{a.classList.add("is-dragging"),t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",String(r))}),a.addEventListener("dragend",()=>{a.classList.remove("is-dragging")}),o.appendChild(a)}),o.dataset.dndInit||(o.addEventListener("dragover",t=>{t.preventDefault();const e=o.querySelector(".todo-checklist-row.is-dragging");if(!e)return;const n=(r=o,a=t.clientY,[...r.querySelectorAll(".todo-checklist-row:not(.is-dragging)")].reduce((t,e)=>{const o=e.getBoundingClientRect(),n=a-o.top-o.height/2;return n<0&&n>t.offset?{offset:n,element:e}:t},{offset:Number.NEGATIVE_INFINITY,element:null}).element);var r,a;null==n?o.appendChild(e):o.insertBefore(e,n)},{passive:!1}),o.addEventListener("drop",e=>{e.preventDefault();const n=t&&t.currentTodo?t.currentTodo:null;if(!n)return;const r=Array.from(o.querySelectorAll(".todo-checklist-row")),a=[];r.forEach(t=>{const e=Number(t.dataset.index);!Number.isNaN(e)&&n.items&&n.items[e]&&a.push(n.items[e])}),n.items=a,at(t,n),it(t,n)}),o.dataset.dndInit="1")}function it(t,e){t&&e&&(t._todoSaveTimer&&clearTimeout(t._todoSaveTimer),lt(e),t._todoSaveTimer=setTimeout(()=>{st(e).catch(t=>{console.error("Error saving todo:",t),alert(window.ShaarliProI18n.t("Error saving todo.")+" "+window.ShaarliProI18n.t("Please refresh the page."))})},600))}function lt(t){if(!t||!t.id)return;let e=t._todoCardEl&&t._todoCardEl.isConnected?t._todoCardEl:null;if(e||(e=document.querySelector(`.note-card.todo-card[data-id="${String(t.id)}"]`)),!e){e=Array.from(document.querySelectorAll(".note-card.todo-card")).find(e=>String(e.dataset.id||"")===String(t.id))||null}if(!e)return;const o=e.querySelector(".todo-checklist-preview-wrap");o&&(o.innerHTML=ot(t.items||[]))}async function st(t,e=0){if(!t||!t.editUrl||"#"===t.editUrl)return;const o=async()=>{const e=await fetch(t.editUrl,{credentials:"same-origin"}),o=await e.text(),n=(new DOMParser).parseFromString(o,"text/html").querySelector('form[name="linkform"]');if(!n)throw new Error("Could not find edit form");const r=new URLSearchParams;n.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&r.append(t.name,t.value||"on"):t.name&&r.append(t.name,Y(t))}),t._todoEditAction=n.action,t._todoEditBaseData=r;const a=rt(r.get("lf_description")||"");t._todoHeaderLines=a.headerLines,t._todoFooterLines=a.footerLines};t._todoEditAction&&t._todoEditBaseData&&t._todoEditBaseData.get&&t._todoEditBaseData.get("token")||await o();const n=function(t){const e=Array.isArray(t._todoHeaderLines)?t._todoHeaderLines:[],o=Array.isArray(t._todoFooterLines)?t._todoFooterLines:[],n=(Array.isArray(t.items)?t.items:[]).map(t=>`- [${t.checked?"x":" "}] ${String(t.text||"").trim()}`),r=[];return e.forEach(t=>r.push(t)),n.forEach(t=>r.push(t)),o.forEach(t=>r.push(t)),r.join("\n").replace(/\s+$/g,"")}(t),r=new URLSearchParams(t._todoEditBaseData.toString());r.set("lf_description",n);let a=(r.get("lf_tags")||"").trim().split(/[\s,]+/).filter(t=>""!==t.trim());a=a.filter(t=>"note"!==t&&"shaarli-note"!==t),a.includes("shaarli-todo")||a.push("shaarli-todo"),r.set("lf_tags",a.join(" ")),r.append("save_edit","1");const i=await fetch(t._todoEditAction,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!i.ok){if(403===i.status&&e<1)return t._todoEditAction="",t._todoEditBaseData=null,await o(),st(t,e+1);throw new Error("Failed to save todo")}}function dt(o,n){document.body.classList.add("view-notes");"undefined"!=typeof shaarli&&shaarli.basePath&&shaarli.basePath;const r=document.querySelector(".content-toolbar");r&&(r.style.display="none");const a=document.createElement("div");a.className="notes-wrapper";const i=document.createElement("div");i.className="notes-top-bar";const l=document.createElement("div");l.className="note-input-container";const s=()=>{l.classList.remove("is-editing","is-enhanced","todo-draft-mode"),O(l,{color:"default",filter:"none",background:"none",fontColor:"auto"}),l.innerHTML=`\n <div class="note-input-collapsed">\n <span class="note-input-placeholder">${window.ShaarliProI18n.t("Create a note...")}</span>\n <div class="note-input-actions note-input-type-actions">\n <button type="button" class="note-create-note-btn" title="${window.ShaarliProI18n.t("Create a note")}"><i class="mdi mdi-note-outline"></i></button>\n </div>\n </div>\n `;const t=l.querySelector(".note-input-collapsed"),o=l.querySelector(".note-create-note-btn"),n=(t="note")=>{if("list"===t){l.classList.add("is-editing","todo-draft-mode"),l.innerHTML=`\n <div class="note-input-expanded todo-draft-expanded">\n <input type="text" class="note-input-title todo-draft-title" placeholder="${window.ShaarliProI18n.t("List title")}" autocomplete="off" />\n <div class="todo-draft-list" role="list"></div>\n <button type="button" class="todo-draft-add-btn"><i class="mdi mdi-plus"></i> ${window.ShaarliProI18n.t("Add list item")}</button>\n <div class="note-input-expanded-actions">\n <div class="note-input-actions-left">\n <button type="button" class="note-input-palette-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n </div>\n <button type="button" class="note-input-close-btn">Fermer</button>\n </div>\n </div>\n `;const t=l.querySelector(".todo-draft-title"),e=l.querySelector(".todo-draft-list"),o=l.querySelector(".todo-draft-add-btn"),n=l.querySelector(".note-input-close-btn"),r=l.querySelector(".note-input-palette-btn");let a=!1,i=!1,d={color:"default",filter:"none",background:"none",fontColor:"auto"};O(l,d);const c=(t={text:"",checked:!1},o=!1)=>{if(!e)return null;const n=document.createElement("div");n.className="todo-draft-row",n.innerHTML=`\n <label class="todo-checklist-box" title="${window.ShaarliProI18n.t("Mark as completed")}">\n <input type="checkbox" class="todo-item-checkbox" ${t.checked?"checked":""} />\n <span class="todo-checklist-box-ui"></span>\n </label>\n <input type="text" class="todo-item-text" placeholder="${window.ShaarliProI18n.t("List item")}" value="${nt(t.text||"")}" />\n <button type="button" class="todo-item-delete" title="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-close"></i></button>\n `,e.appendChild(n);const r=n.querySelector(".todo-item-checkbox"),i=n.querySelector(".todo-item-text"),l=n.querySelector(".todo-item-delete"),s=()=>{n.classList.toggle("is-checked",!(!r||!r.checked))};return s(),r?.addEventListener("change",()=>{a=!0,s()}),i?.addEventListener("input",()=>{a=!0}),l?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),a=!0,n.remove(),e.querySelector(".todo-draft-row")||c({text:"",checked:!1},!0)}),o&&i&&i.focus({preventScroll:!0}),n},u=()=>e?Array.from(e.querySelectorAll(".todo-draft-row")).map(t=>{const e=t.querySelector(".todo-item-checkbox"),o=t.querySelector(".todo-item-text"),n=o&&"string"==typeof o.value?o.value.trim():"";return{checked:!(!e||!e.checked),text:n}}).filter(t=>t.text):[];c({text:"",checked:!1},!1),o?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),a=!0,c({text:"",checked:!1},!0)}),t?.addEventListener("input",()=>{a=!0});const m=async()=>{if(i)return;const e=t&&"string"==typeof t.value?t.value.trim():"",o=u();if(!e&&0===o.length)return document.removeEventListener("pointerdown",p,!0),void s();if(!a)return document.removeEventListener("pointerdown",p,!0),void s();i=!0;try{const t=o.map(t=>`- [${t.checked?"x":" "}] ${t.text}`).join("\n");await J({title:e,markdown:t,visual:d}),window.location.reload()}catch(t){console.error("Error creating checklist note:",t),alert(window.ShaarliProI18n.t("Error creating checklist note.")),i=!1}};n?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),m()});const p=t=>{t.target&&t.target.closest&&t.target.closest("#shaarli-bg-studio")||t.target&&t.target.closest&&t.target.closest(".bg-studio-panel")||l.contains(t.target)||m()};return document.addEventListener("pointerdown",p,!0),r?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),j({anchorEl:r,mode:"draft",entityId:"draft-new-todo-from-note",editUrl:"",currentColor:d.color||"default",currentFilter:d.filter||"none",currentBackground:d.background||"none",currentFontColor:d.fontColor||"auto",title:window.ShaarliProI18n.t("My images & colors")});const e=document.getElementById("shaarli-bg-studio");e&&(e.__draftApply=t=>{d={...d,...t||{}},O(l,d)})}),void t?.focus({preventScroll:!0})}l.classList.add("is-editing"),l.innerHTML=`\n <div class="note-input-expanded">\n <input type="text" class="note-input-title" placeholder="${window.ShaarliProI18n.t("Title")}" />\n <textarea class="note-input-description-source" rows="8" placeholder="${window.ShaarliProI18n.t("Write your note in Markdown...")}"></textarea>\n <div class="note-formatting-bar" aria-hidden="true">\n <button type="button" class="note-format-btn" data-note-format="h1" title="${window.ShaarliProI18n.t("Heading 1")}">H1</button>\n <button type="button" class="note-format-btn" data-note-format="h2" title="${window.ShaarliProI18n.t("Heading 2")}">H2</button>\n <button type="button" class="note-format-btn" data-note-format="h3" title="${window.ShaarliProI18n.t("Heading 3")}">H3</button>\n <button type="button" class="note-format-btn" data-note-format="p" title="${window.ShaarliProI18n.t("Text")}">Aa</button>\n <span class="note-format-sep" aria-hidden="true"></span>\n <button type="button" class="note-format-btn" data-note-format="bold" title="${window.ShaarliProI18n.t("Bold")}"><b>B</b></button>\n <button type="button" class="note-format-btn" data-note-format="italic" title="${window.ShaarliProI18n.t("Italic")}"><i>I</i></button>\n <button type="button" class="note-format-btn" data-note-format="underline" title="${window.ShaarliProI18n.t("Underline")}"><u>U</u></button>\n <button type="button" class="note-format-btn" data-note-format="strike" title="${window.ShaarliProI18n.t("Strikethrough")}"><s>S</s></button>\n <button type="button" class="note-format-btn" data-note-format="code" title="${window.ShaarliProI18n.t("Inline code")}"><i class="mdi mdi-code-tags"></i></button>\n <span class="note-format-sep" aria-hidden="true"></span>\n <button type="button" class="note-format-btn" data-note-format="ul" title="${window.ShaarliProI18n.t("Bulleted list")}"><i class="mdi mdi-format-list-bulleted"></i></button>\n <button type="button" class="note-format-btn" data-note-format="ol" title="${window.ShaarliProI18n.t("Numbered list")}"><i class="mdi mdi-format-list-numbered"></i></button>\n <button type="button" class="note-format-btn" data-note-format="todo" title="${window.ShaarliProI18n.t("Checklist")}"><i class="mdi mdi-format-list-checks"></i></button>\n <button type="button" class="note-format-btn" data-note-format="quote" title="${window.ShaarliProI18n.t("Quote")}"><i class="mdi mdi-format-quote-open"></i></button>\n <button type="button" class="note-format-btn" data-note-format="link" title="${window.ShaarliProI18n.t("Link")}"><i class="mdi mdi-link-variant"></i></button>\n <button type="button" class="note-format-btn" data-note-format="image" title="${window.ShaarliProI18n.t("Image")}"><i class="mdi mdi-image-outline"></i></button>\n <button type="button" class="note-format-btn" data-note-format="codeblock" title="${window.ShaarliProI18n.t("Code block")}"><i class="mdi mdi-code-braces"></i></button>\n <button type="button" class="note-format-btn" data-note-format="clear" title="${window.ShaarliProI18n.t("Clear formatting")}">X</button>\n </div>\n <div class="note-input-expanded-actions">\n <div class="note-input-actions-left">\n <button type="button" class="note-input-format-btn" title="${window.ShaarliProI18n.t("Formatting options")}"><i class="mdi mdi-format-text"></i></button>\n <button type="button" class="note-input-palette-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n </div>\n <button type="button" class="note-input-close-btn">Fermer</button>\n </div>\n </div>\n `;const o=l.querySelector(".note-input-title"),n=l.querySelector(".note-input-description-source"),r=l.querySelector(".note-input-close-btn"),a=l.querySelector(".note-input-palette-btn"),i=l.querySelector(".note-input-format-btn"),d=l.querySelector(".note-formatting-bar");let c=!1,u=!1,m={color:"default",filter:"none",background:"none",fontColor:"auto"};O(l,m);i?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=d&&d.classList.contains("open");var o;o=!e,d&&(o?(d.classList.add("open"),d.setAttribute("aria-hidden","false"),l.classList.add("show-formatting")):(d.classList.remove("open"),d.setAttribute("aria-hidden","true"),l.classList.remove("show-formatting")))}),l.querySelectorAll(".note-format-btn").forEach(t=>{t.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),n&&(e(n,t.dataset.noteFormat||""),c=!0)})}),o?.addEventListener("input",()=>{c=!0}),n?.addEventListener("input",()=>{c=!0});const p=async()=>{if(u)return;const{title:t,markdown:e}={title:o&&"string"==typeof o.value?o.value.trim():"",markdown:n&&"string"==typeof n.value?n.value.trim():""};if(!t&&!e)return document.removeEventListener("pointerdown",f,!0),void s();if(!c)return document.removeEventListener("pointerdown",f,!0),void s();u=!0;try{await J({title:t,markdown:e,visual:m}),window.location.reload()}catch(t){console.error("Error creating note:",t),alert(window.ShaarliProI18n.t("Error creating note.")),u=!1}};r?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),p()});const f=t=>{t.target&&t.target.closest&&t.target.closest("#shaarli-bg-studio")||t.target&&t.target.closest&&t.target.closest(".bg-studio-panel")||t.target&&t.target.closest&&t.target.closest(".note-formatting-bar")||l.contains(t.target)||p()};document.addEventListener("pointerdown",f,!0),a?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),j({anchorEl:a,mode:"draft",entityId:"draft-new-note",editUrl:"",currentColor:m.color||"default",currentFilter:m.filter||"none",currentBackground:m.background||"none",currentFontColor:m.fontColor||"auto",title:window.ShaarliProI18n.t("My images & colors")});const e=document.getElementById("shaarli-bg-studio");e&&(e.__draftApply=t=>{m={...m,...t||{}},O(l,m)})}),o?.focus({preventScroll:!0})};t?.addEventListener("click",t=>{t.target.closest("button")||n("note")}),o?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),n("note")})};s(),i.appendChild(l);const d=document.createElement("div");d.className="notes-tools",d.innerHTML=`\n <button class="icon-btn active" id="btn-view-grid" title="${window.ShaarliProI18n.t("Grid view")}"><i class="mdi mdi-view-dashboard-outline"></i></button>\n <button class="icon-btn" id="btn-view-list" title="${window.ShaarliProI18n.t("List view")}"><i class="mdi mdi-view-agenda-outline"></i></button>\n `,i.appendChild(d),a.appendChild(i);const c=document.createElement("div");c.className="notes-content-area";const u=Array.from(o.querySelectorAll(".link-outer")).map(t=>ct(t));ut(c,u,"grid"),a.appendChild(c),o.style.display="none",o.parentNode?o.parentNode.insertBefore(a,o):n.appendChild(a);const p=window.location.hash;if(p&&p.startsWith("#open-note-")){const t=p.replace("#open-note-",""),e=u.find(e=>String(e.id)===String(t));e&&(history.replaceState(null,null,window.location.pathname+window.location.search),setTimeout(()=>{ft(e)},100))}const f=document.createElement("div");f.className="note-modal-overlay",f.innerHTML=`\n <div class="note-modal" role="dialog" aria-modal="true">\n <div class="note-modal-header">\n <input type="text" class="note-title note-modal-title-input" id="note-modal-title" placeholder="${window.ShaarliProI18n.t("Title")}" />\n <button type="button" class="note-modal-pin-toggle" id="note-modal-pin" title="${window.ShaarliProI18n.t("Pin")}">\n <i class="mdi mdi-pin-outline"></i>\n </button>\n </div>\n <div class="note-modal-content">\n <div class="note-modal-description-preview note-body" id="note-modal-description-preview" role="button" tabindex="0" aria-label="${window.ShaarliProI18n.t("Click to edit")}"></div>\n <textarea class="note-modal-description-source" id="note-modal-description-source" rows="8"></textarea>\n <div class="note-formatting-bar" id="note-modal-formatting" aria-hidden="true">\n <button type="button" class="note-format-btn" data-note-format="h1" title="${window.ShaarliProI18n.t("Heading 1")}">H1</button>\n <button type="button" class="note-format-btn" data-note-format="h2" title="${window.ShaarliProI18n.t("Heading 2")}">H2</button>\n <button type="button" class="note-format-btn" data-note-format="h3" title="${window.ShaarliProI18n.t("Heading 3")}">H3</button>\n <button type="button" class="note-format-btn" data-note-format="p" title="${window.ShaarliProI18n.t("Text")}">Aa</button>\n <span class="note-format-sep" aria-hidden="true"></span>\n <button type="button" class="note-format-btn" data-note-format="bold" title="${window.ShaarliProI18n.t("Bold")}"><b>B</b></button>\n <button type="button" class="note-format-btn" data-note-format="italic" title="${window.ShaarliProI18n.t("Italic")}"><i>I</i></button>\n <button type="button" class="note-format-btn" data-note-format="underline" title="${window.ShaarliProI18n.t("Underline")}"><u>U</u></button>\n <button type="button" class="note-format-btn" data-note-format="strike" title="${window.ShaarliProI18n.t("Strikethrough")}"><s>S</s></button>\n <button type="button" class="note-format-btn" data-note-format="code" title="${window.ShaarliProI18n.t("Inline code")}"><i class="mdi mdi-code-tags"></i></button>\n <span class="note-format-sep" aria-hidden="true"></span>\n <button type="button" class="note-format-btn" data-note-format="ul" title="${window.ShaarliProI18n.t("Bulleted list")}"><i class="mdi mdi-format-list-bulleted"></i></button>\n <button type="button" class="note-format-btn" data-note-format="ol" title="${window.ShaarliProI18n.t("Numbered list")}"><i class="mdi mdi-format-list-numbered"></i></button>\n <button type="button" class="note-format-btn" data-note-format="todo" title="${window.ShaarliProI18n.t("Checklist")}"><i class="mdi mdi-format-list-checks"></i></button>\n <button type="button" class="note-format-btn" data-note-format="quote" title="${window.ShaarliProI18n.t("Quote")}"><i class="mdi mdi-format-quote-open"></i></button>\n <button type="button" class="note-format-btn" data-note-format="link" title="${window.ShaarliProI18n.t("Link")}"><i class="mdi mdi-link-variant"></i></button>\n <button type="button" class="note-format-btn" data-note-format="image" title="${window.ShaarliProI18n.t("Image")}"><i class="mdi mdi-image-outline"></i></button>\n <button type="button" class="note-format-btn" data-note-format="codeblock" title="${window.ShaarliProI18n.t("Code block")}"><i class="mdi mdi-code-braces"></i></button>\n <button type="button" class="note-format-btn" data-note-format="clear" title="${window.ShaarliProI18n.t("Clear formatting")}">X</button>\n </div>\n </div>\n <div class="note-modal-tags is-empty" id="note-modal-tags"></div>\n <div class="note-modal-actions">\n <div class="note-modal-actions-left">\n <div class="note-modal-color-picker">\n <button type="button" id="note-modal-color-btn" title="${window.ShaarliProI18n.t("Color")}"><i class="mdi mdi-palette-outline"></i></button>\n <div class="palette-popup note-modal-palette" id="note-modal-color-popup"></div>\n </div>\n <button type="button" id="note-modal-format-btn" title="${window.ShaarliProI18n.t("Formatting options")}"><i class="mdi mdi-format-text"></i></button>\n <button type="button" title="${window.ShaarliProI18n.t("Reminder")}"><i class="mdi mdi-bell-outline"></i></button>\n <button type="button" title="${window.ShaarliProI18n.t("Collaborator")}"><i class="mdi mdi-account-plus-outline"></i></button>\n <button type="button" title="${window.ShaarliProI18n.t("Image")}"><i class="mdi mdi-image-outline"></i></button>\n <button type="button" id="note-modal-archive" title="${window.ShaarliProI18n.t("Archive")}"><i class="mdi mdi-archive-arrow-down-outline"></i></button>\n <a href="#" id="note-modal-edit" title="${window.ShaarliProI18n.t("Edit")}"><i class="mdi mdi-pencil-outline"></i></a>\n <button type="button" id="note-modal-delete" title="${window.ShaarliProI18n.t("Delete")}"><i class="mdi mdi-delete-outline"></i></button>\n </div>\n <button type="button" class="note-modal-close-btn" id="note-modal-close">Fermer</button>\n </div>\n </div>\n `,document.body.appendChild(f);const h=a.querySelector("#btn-view-grid"),g=a.querySelector("#btn-view-list");h.addEventListener("click",()=>{h.classList.add("active"),g.classList.remove("active"),ut(c,u,"grid")}),g.addEventListener("click",()=>{g.classList.add("active"),h.classList.remove("active"),ut(c,u,"list")});const b=async()=>{try{await async function(e){if(!e||!e.currentNote)return;const o=e.currentNote,n=e.querySelector("#note-modal-title"),r=e.querySelector("#note-modal-description-source"),a=n&&"string"==typeof n.value?n.value.trim():"",i=r&&"string"==typeof r.value?r.value.trim():"",l=e._noteEditorState||{hasChanges:!1,isSaving:!1,lastSavedTitle:"",lastSavedMarkdown:""};if(!a&&!i)return;if(!l.hasChanges&&a===(l.lastSavedTitle||"")&&i===(l.lastSavedMarkdown||"")||l.isSaving)return;l.isSaving=!0,e._noteEditorState=l,await Z(o),await tt(o,{title:a,markdown:i}),o.title=a,o._noteTitle=a,o._noteMarkdown=i,o.descText=i;const s=document.querySelector(`.note-card[data-id="${CSS.escape(String(o.id))}"]`);if(s){const e=s.querySelector(".note-inner .note-title");e&&(e.textContent=a);const n=s.querySelector(".note-inner .note-body");n&&(n.innerHTML=t(i),o.descHtml=n.innerHTML)}l.lastSavedTitle=a,l.lastSavedMarkdown=i,l.hasChanges=!1,l.isSaving=!1}(f),f.classList.remove("open"),document.body.classList.remove("note-modal-open")}catch(t){console.error("Error saving note from modal:",t),alert(window.ShaarliProI18n.t("Error saving note."))}};f.querySelector("#note-modal-close").addEventListener("click",t=>{t.preventDefault(),b()}),f.addEventListener("click",t=>{t.target===f&&b()}),f.querySelector("#note-modal-edit").addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=f.querySelector("#note-modal-title");e?.focus({preventScroll:!0})});const y=f.querySelector("#note-modal-pin"),v=f.querySelector("#note-modal-color-btn"),w=f.querySelector("#note-modal-color-popup");v.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=f.querySelector(".note-modal");j({anchorEl:v,mode:"modal",entityId:e&&e.dataset.noteId||"",editUrl:e&&e.dataset.editUrl||"",currentColor:e?_(e):"default",currentFilter:e?U(e):"none",currentBackground:e?A(e):"none",currentFontColor:e?T(e):"auto",title:window.ShaarliProI18n.t("My images & colors")})}),y.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=f.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;if(!o||!n)return;yt(o,n,y);const r=y.classList.contains("active");let a=(e.dataset.tags||"").split("||").filter(t=>t);r?a.includes("shaarli-pin")||a.push("shaarli-pin"):a=a.filter(t=>"shaarli-pin"!==t),e.dataset.tags=a.join("||"),pt(f.querySelector("#note-modal-tags"),a),f.currentNote&&(f.currentNote.isPinned=r,f.currentNote.tags=a)}),f.querySelector("#note-modal-delete").addEventListener("click",()=>{if(!confirm(window.ShaarliProI18n.t("Delete this note?")))return;const t=f.querySelector(".note-modal"),e=t.dataset.deleteUrl;t.dataset.noteId;e&&"#"!==e&&m(e).then(()=>{window.location.href="/?searchtags=note"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})}),f.querySelector("#note-modal-archive").addEventListener("click",t=>{t.preventDefault();const e=f.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;o&&n&>(n,"shaarli-archive").then(()=>{f.currentNote&&(f.currentNote.tags.includes("shaarli-archive")||f.currentNote.tags.push("shaarli-archive"));const t=document.querySelector(`.note-card[data-id="${o}"]`);t&&t.remove();const e=u.findIndex(t=>String(t.id)===String(o));e>-1&&u.splice(e,1),f.classList.remove("open"),document.body.classList.remove("note-modal-open")}).catch(t=>{console.error("Error archiving note:",t),alert(window.ShaarliProI18n.t("Error archiving note."))})}),f.addEventListener("click",t=>{t.target.closest(".note-modal-color-picker")||w.classList.remove("open")}),document.addEventListener("click",t=>{t.target.closest(".note-hover-actions .palette-popup")&&!t.target.closest('.note-hover-actions [id^="palette-"]')&&document.querySelectorAll(".note-hover-actions .palette-popup.open").forEach(t=>{t.classList.remove("open")})})}function ct(t){const e=t.dataset.id,n=t.querySelector(".link-title"),r=n?n.textContent.trim():"",d=t.querySelector(".link-description"),c=d?d.innerHTML:"",u=d?d.textContent:"";let m=null;if(d){const t=d.querySelector("img");t&&(m=t.src)}const p=t.querySelector(".link-url"),f=p?p.textContent.trim():"",h=[];t.querySelectorAll(".link-tag-list a").forEach(t=>{const e=(t.textContent||"").trim();e&&h.push(e)});const{color:g,filter:b,background:y,fontColor:v}=K(h),w=h.filter(t=>!t.startsWith(i)&&(!t.startsWith("note-custom-")&&(!(t=>{if("string"!=typeof t)return!1;if(!t.startsWith("note-"))return!1;const e=t.substring(5);return o.some(t=>t.key===e)})(t)&&(!t.startsWith(l)&&(!t.startsWith(s)&&!t.startsWith(a)))))),k=(w.includes("shaarli-pin"),t.querySelector(".link-actions")),S=k&&k.querySelector('a[href*="admin/shaare"]')?k.querySelector('a[href*="admin/shaare"]').href:"#",$=k&&k.querySelector('a[href*="delete"]')?k.querySelector('a[href*="delete"]').href:"#",L=k&&k.querySelector('a[href*="pin"]')?k.querySelector('a[href*="pin"]').href:"#",E=w.includes("shaarli-pin");return{id:e,title:r,descHtml:c,descText:u,coverImage:m,url:f,tags:w,color:g,filter:b,background:y,fontColor:v,editUrl:S,deleteUrl:$,pinUrl:L,isPinned:E}}function ut(e,o,n,r=!1){let a;e.innerHTML="",e.className="grid"===n?"notes-masonry":"notes-list-view",a=r?o.filter(t=>(t.tags||[]).some(t=>"shaarli-archive"===t||"shaarli-archiver"===t)):o.filter(t=>!(t.tags||[]).some(t=>"shaarli-archive"===t||"shaarli-archiver"===t)),a.sort((t,e)=>{const o=t.tags.includes("shaarli-pin");return e.tags.includes("shaarli-pin")-o}),a.forEach(o=>{const a=document.createElement("div");if(a.className="note-card",a.dataset.id=o.id,a.dataset.editUrl=o.editUrl||"",a.dataset.tags=(o.tags||[]).filter(t=>t).join("||"),O(a,o),"list"===n&&a.classList.add("list-mode"),a.addEventListener("click",t=>{t.target.closest("button")||t.target.closest("a")||t.target.closest(".note-hover-actions")||(Q(o,a),ft(o))}),o.coverImage&&"grid"===n){const t=document.createElement("div");t.className="note-cover",t.innerHTML=`<img src="${o.coverImage}" alt="Cover">`,a.appendChild(t)}const i=document.createElement("div");if(i.className="note-inner",o.title){const t=document.createElement("h3");t.className="note-title",t.textContent=o.title,i.appendChild(t)}if(o.descHtml||o.descText||o._noteMarkdown){const e=document.createElement("div");if(e.className="note-body",void 0!==o._noteMarkdown)e.innerHTML=t(o._noteMarkdown);else{const n=o.descText||"";n.trim().startsWith('<div class="markdown">')||n.trim().startsWith("<")?e.innerHTML=n:e.innerHTML=t(n)}i.appendChild(e)}if(o.tags.length>0){const t=document.createElement("div");t.className="note-tags",o.tags.forEach(e=>{if(d(e))return;const n=c({tag:e,onRemoveClass:"note-tag-remove-btn",tagClass:"note-tag",canRemove:!!o.editUrl&&"#"!==o.editUrl});t.appendChild(n)}),i.appendChild(t)}const l=document.createElement("div");l.className="note-hover-actions";const s=document.createElement("a");s.href=o.pinUrl,s.title=o.isPinned?"Unpin":"Pin",s.className="note-pin-corner "+(o.isPinned?"active":""),s.innerHTML=`<i class="mdi mdi-pin${o.isPinned?"":"-outline"}"></i>`,i.appendChild(s);const u=`palette-${o.id}`,p=`archive-${o.id}`;l.innerHTML=`\n <button title="${window.ShaarliProI18n.t("Reminder")}"><i class="mdi mdi-bell-outline"></i></button>\n <button title="${window.ShaarliProI18n.t("Collaborator")}"><i class="mdi mdi-account-plus-outline"></i></button>\n <div style="position:relative;">\n <button title="${window.ShaarliProI18n.t("Color")}" id="${u}"><i class="mdi mdi-palette-outline"></i></button>\n </div>\n <button title="${window.ShaarliProI18n.t("Image")}"><i class="mdi mdi-image-outline"></i></button>\n <button title="${window.ShaarliProI18n.t("Archive")}" id="${p}"><i class="mdi mdi-archive-arrow-down-outline"></i></button>\n <div class="spacer"></div>\n \x3c!-- Real Actions --\x3e\n <button type="button" class="note-open-editor-btn" title="${window.ShaarliProI18n.t("Edit")}"><i class="mdi mdi-pencil-outline"></i></button>\n <button title="${window.ShaarliProI18n.t("Delete")}" class="note-delete-btn"><i class="mdi mdi-delete-outline"></i></button>\n `;const f=l.querySelector(".note-delete-btn");f?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),confirm(window.ShaarliProI18n.t("Delete this note?"))&&m(o.deleteUrl).then(()=>{window.location.href=r?"/?searchtags=shaarli-archive":"/?searchtags=note"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})});const h=l.querySelector(".note-open-editor-btn");h?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),Q(o,a),ft(o)});const g=l.querySelector(`#${u}`);g.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),j({anchorEl:g,mode:"entity",entityId:o.id,editUrl:o.editUrl,currentColor:_(a),currentFilter:U(a),currentBackground:A(a),title:window.ShaarliProI18n.t("My images & colors")})});l.querySelector(`#${p}`).addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),o.editUrl&&"#"!==o.editUrl&>(o.editUrl,"shaarli-archive").then(()=>{a.remove()}).catch(t=>{console.error("Error archiving note:",t),alert(window.ShaarliProI18n.t("Error archiving note."))})}),i.appendChild(l),a.appendChild(i),e.appendChild(a)})}function mt(t,e){if(!t)return;t.classList.toggle("active",e),t.title=e?window.ShaarliProI18n.t("Unpin"):window.ShaarliProI18n.t("Pin");const o=t.querySelector("i");o&&(o.className="mdi "+(e?"mdi-pin":"mdi-pin-outline"))}function pt(t,e){if(!t)return;t.innerHTML="";const o=(e||[]).filter(t=>t&&!d(t)),n=g(t.closest(".note-modal-overlay")||h()),r=!(!n||!n.editUrl||"#"===n.editUrl);0!==o.length?(t.classList.remove("is-empty"),o.forEach(e=>{const o=c({tag:e,onRemoveClass:"note-tag-remove-btn",tagClass:"note-tag",canRemove:r});t.appendChild(o)})):t.classList.add("is-empty")}function ft(o){const n=document.querySelector(".note-modal-overlay");if(!n)return;const r=n.querySelector(".note-modal"),a=n.querySelector("#note-modal-title"),i=n.querySelector("#note-modal-description-source"),l=n.querySelector("#note-modal-description-preview"),s=n.querySelector("#note-modal-tags"),c=n.querySelector("#note-modal-edit"),u=n.querySelector("#note-modal-pin"),m=n.querySelector("#note-modal-color-popup"),p=(n.querySelector("#note-modal-format-btn"),n.querySelector("#note-modal-formatting"),t=>{i&&l&&(t?(n.classList.add("note-modal-editing"),l.setAttribute("aria-hidden","true"),i.removeAttribute("aria-hidden")):(n.classList.remove("note-modal-editing"),l.setAttribute("aria-hidden","false"),i.setAttribute("aria-hidden","true")))});n.currentNote=o,r.className="note-modal",O(r,o),r.dataset.noteId=o.id||"",r.dataset.editUrl=o.editUrl||"",r.dataset.deleteUrl=o.deleteUrl||"",r.dataset.background=o.background||"none";const f=(o.tags||[]).filter(t=>t&&!d(t));r.dataset.tags=f.join("||"),a&&(a.value=o.title||""),i&&(i.value=(o._noteMarkdown||o.descText||"").trim()),l&&(l.innerHTML=t((o._noteMarkdown||o.descText||"").trim())),p(!1),pt(s,f),c&&(c.href=o.editUrl||"#"),m&&(m.innerHTML=ht(o),m.classList.remove("open")),mt(u,!!o.isPinned),n._noteEditorState||(n._noteEditorState={hasChanges:!1,isSaving:!1,lastSavedTitle:"",lastSavedMarkdown:""});const h=n._noteEditorState;if(h.hasChanges=!1,h.lastSavedTitle=a&&"string"==typeof a.value?a.value.trim():"",h.lastSavedMarkdown=i&&"string"==typeof i.value?i.value.trim():"",!n._noteEditorBound){n._noteEditorBound=!0,a?.addEventListener("input",()=>{n._noteEditorState&&(n._noteEditorState.hasChanges=!0)}),i?.addEventListener("input",()=>{n._noteEditorState&&(n._noteEditorState.hasChanges=!0),l&&(l.innerHTML=t(i.value||""))}),l?.addEventListener("click",()=>{p(!0),i?.focus({preventScroll:!0})}),l?.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),p(!0),i?.focus({preventScroll:!0}))}),i?.addEventListener("blur",()=>{p(!1)});const o=t=>{const e=n.querySelector("#note-modal-formatting");e&&(t?(e.classList.add("open"),e.setAttribute("aria-hidden","false"),n.classList.add("show-formatting")):(e.classList.remove("open"),e.setAttribute("aria-hidden","true"),n.classList.remove("show-formatting")))};n._setNoteModalFormattingVisible=o;const r=n.querySelector("#note-modal-format-btn");r?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=n.querySelector("#note-modal-formatting"),r=e&&e.classList.contains("open");o(!r)}),n.querySelectorAll(".note-format-btn").forEach(t=>{t.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation();const r=n.querySelector("#note-modal-description-source");r&&(p(!0),e(r,t.dataset.noteFormat||""),n._noteEditorState&&(n._noteEditorState.hasChanges=!0))})})}"function"==typeof n._setNoteModalFormattingVisible&&n._setNoteModalFormattingVisible(!1),Z(o).then(()=>{n.currentNote===o&&(a&&o._noteTitle&&(a.value=o._noteTitle),i&&(i.value=(o._noteMarkdown||"").trim()),l&&(l.innerHTML=t(i?i.value:"")),p(!1),h.lastSavedTitle=a&&"string"==typeof a.value?a.value.trim():"",h.lastSavedMarkdown=i&&"string"==typeof i.value?i.value.trim():"")}),n.classList.add("open"),document.body.classList.add("note-modal-open"),a?.focus({preventScroll:!0})}function ht(t){return G({entityId:t&&t.id?t.id:"",editUrl:t&&t.editUrl?t.editUrl:"",currentColor:t&&t.color?t.color:"default",currentFilter:t&&t.filter?t.filter:"none",mode:"modal"})}function gt(t,e){return fetch(t).then(t=>t.text()).then(t=>{const o=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!o)throw new Error("Could not find edit form");const n=new URLSearchParams;o.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&n.append(t.name,t.value||"on"):t.name&&n.append(t.name,Y(t))});let r=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return r.includes(e)||r.push(e),n.set("lf_tags",r.join(" ")),n.append("save_edit","1"),fetch(o.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to update tags");return t})}function bt(){const t=document.querySelector(".links-list, .notes-masonry, .notes-list-view");if(!t)return;const e=Array.from(t.children),o=[];if(e.forEach(t=>{if(t.classList.contains("link-outer")||t.classList.contains("note-card")){let e=!1;t.innerHTML;const n=t.querySelectorAll(".link-tag-list a, .note-tag");for(let t of n)if("shaarli-pin"===t.textContent.trim()){e=!0;break}const r=t.querySelector(".mdi-pin-outline, .mdi-pin"),a=t.querySelector(".link-title, .note-title"),i=a?a.querySelector("i.mdi-pin"):null;if(e){if(o.push(t),t.classList.add("is-pinned-tag"),r&&(r.classList.remove("mdi-pin-outline"),r.classList.add("mdi-pin"),r.parentElement&&r.parentElement.classList.add("active")),a&&!i){const t=document.createElement("i");t.className="mdi mdi-pin",t.style.color="var(--primary)",t.style.marginRight="8px",a.prepend(t)}}else t.classList.remove("is-pinned-tag"),r&&(r.classList.remove("mdi-pin"),r.classList.add("mdi-pin-outline"),r.parentElement&&r.parentElement.classList.remove("active")),i&&i.remove()}}),t.classList.contains("links-list"))for(let e=o.length-1;e>=0;e--)t.prepend(o[e]);window.requestAnimationFrame(k),document.addEventListener("click",function(t){const e=t.target.closest('a[href*="do=pin"], .note-hover-actions a[href*="pin"], .note-pin-corner[href*="pin"], .link-actions a[href*="pin"]');if(e){t.preventDefault(),t.stopPropagation();const o=e.closest(".link-outer, .note-card"),n=o?o.dataset.id:null;let r=e.href.replace("do=pin","do=editlink").replace("pin","editlink");if(o){const t=o.querySelector('a[href*="edit_link"], a[href*="admin/shaare"]');t&&(r=t.href)}n&&r&&yt(n,r,e)}},{once:!1})}function yt(t,e,o){const n=o.querySelector("i");let r=!1;n&&(n.classList.contains("mdi-pin-outline")?(n.classList.remove("mdi-pin-outline"),n.classList.add("mdi-pin"),o.classList.add("active"),r=!0):(n.classList.remove("mdi-pin"),n.classList.add("mdi-pin-outline"),o.classList.remove("active"),r=!1));const a=o.closest(".link-outer, .note-card");if(a){a.classList.toggle("is-pinned-tag",r);const t=a.querySelector(".link-title, .note-title");if(t){let e=t.querySelector("i.mdi-pin");if(r){if(!e){const e=document.createElement("i");e.className="mdi mdi-pin",e.style.color="var(--primary)",e.style.marginRight="8px",t.prepend(e)}}else e&&e.remove()}let e=a.querySelector(".note-tags");if(e||(e=a.querySelector(".link-tag-list")),e){let t=null;const o=e.querySelectorAll("*");for(let e of o)if("shaarli-pin"===e.textContent.trim()){if(e.classList.contains("note-tag")){t=e;break}if("A"===e.tagName){t=e.parentElement.classList.contains("label-tag")?e.parentElement:e;break}}if(r){if(!t)if(a.classList.contains("note-card")){const t=document.createElement("span");t.className="note-tag",t.textContent="shaarli-pin",e.appendChild(t)}else{const t=document.createElement("span");t.className="link-tag";const o=document.createElement("a");o.href="?searchtags=shaarli-pin",o.textContent="shaarli-pin",t.appendChild(o),e.children.length>0&&e.appendChild(document.createTextNode(" ")),e.appendChild(t)}}else if(t){const e=t.previousSibling;t.remove(),e&&e.nodeType===Node.TEXT_NODE&&!e.textContent.trim()&&e.remove()}}}fetch(e).then(t=>t.text()).then(t=>{const e=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!e)throw new Error("Could not find edit form");const o=new URLSearchParams;e.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&o.append(t.name,t.value||"on"):t.name&&o.append(t.name,Y(t))});let n=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());const a="shaarli-pin";return r?n.includes(a)||n.push(a):n=n.filter(t=>t!==a),o.set("lf_tags",n.join(" ")),o.append("save_edit","1"),fetch(e.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString()})}).then(t=>{t.ok&&window.requestAnimationFrame(k)}).catch(t=>console.error(t))}window.setModalNoteColor=function(t){const e=h(),o=g(e);if(!e||!o)return;setNoteColor(o.id,t,o.editUrl),o.color=t;const n=e.querySelector(".note-modal");n&&O(n,o);const r=e.querySelector(".note-modal-palette");r&&(r.innerHTML=ht(o),r.classList.add("open"),D(r))},window.setModalNoteFontColor=function(t){const e=h(),o=g(e);if(!e||!o)return;Pt(o.id,t,o.editUrl),o.fontColor=t;const n=e.querySelector(".note-modal");n&&O(n,o);const r=e.querySelector(".note-modal-palette");r&&(r.innerHTML=ht(o),r.classList.add("open"),D(r))},window.setModalNoteFilter=function(t){const e=h(),o=g(e);if(!e||!o)return;const n=M(t)||"none";setNoteFilter(o.id,n,o.editUrl),o.filter=n;const r=e.querySelector(".note-modal");r&&O(r,o);const a=e.querySelector(".note-modal-palette");a&&(a.innerHTML=ht(o),a.classList.add("open"),D(a))},window.setNoteColor=function(t,e,n){Lt(t,e);const r=document.querySelector(`.link-outer[data-id="${t}"]`);if(r){const e=r.querySelector(".bookmark-palette .palette-popup");if(e){const o=_(r),a=U(r);e.innerHTML=X(t,n,o,a)}}const a=h(),l=g(a);if(a&&l&&String(l.id)===String(t)){l.color=e;const t=a.querySelector(".note-modal");t&&O(t,l);const o=a.querySelector(".note-modal-palette");o&&(o.innerHTML=ht(l))}fetch(n).then(t=>t.text()).then(t=>{const n=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!n)throw new Error("Could not find edit form");const r=new URLSearchParams;n.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&r.append(t.name,t.value||"on"):t.name&&r.append(t.name,Y(t))});let a=(r.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());if(a=a.filter(t=>!t.startsWith(i)),a=a.filter(t=>!t.startsWith("note-custom-")),a=a.filter(t=>{if(!t.startsWith("note-"))return!0;const e=t.substring(5);return!o.some(t=>t.key===e)}),"default"!==e)if("string"==typeof e&&e.startsWith("custom:")){const t=e.substring(7).replace("#","");a.push(`${i}${t}`)}else a.push(`${i}${e}`);return r.set("lf_tags",a.join(" ")),r.append("save_edit","1"),fetch(n.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to save color")}).catch(t=>{console.error("Error saving note color:",t),alert(window.ShaarliProI18n.t("Failed to save color.")+" "+window.ShaarliProI18n.t("Please refresh the page."))})},window.setNoteFilter=function(t,e,o){const n=M(e)||"none",r=document.querySelector(`.note-card[data-id="${t}"]`);if(r){const t=Array.from(r.classList).find(t=>t.startsWith("note-color-")),e=t?t.replace("note-color-",""):r.dataset.color||"default",o=A(r),a=T(r);O(r,{color:e,filter:n,background:o,fontColor:a})}const a=document.querySelector(`.link-outer[data-id="${t}"]`);if(a){const e=Array.from(a.classList).find(t=>t.startsWith("note-color-")),r=e?e.replace("note-color-",""):a.dataset.color||"default",i=A(a),l=T(a);O(a,{color:r,filter:n,background:i,fontColor:l});const s=a.querySelector(".bookmark-palette .palette-popup");s&&(s.innerHTML=X(t,o,r,n))}const i=h(),s=g(i);if(i&&s&&String(s.id)===String(t)){s.filter=n;const t=i.querySelector(".note-modal");t&&O(t,s);const e=i.querySelector(".note-modal-palette");e&&(e.innerHTML=ht(s))}fetch(o).then(t=>t.text()).then(t=>{const e=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!e)throw new Error("Could not find edit form");const o=new URLSearchParams;e.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&o.append(t.name,t.value||"on"):t.name&&o.append(t.name,Y(t))});let r=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return r=r.filter(t=>!t.startsWith(l)),n&&"none"!==n&&r.push(`${l}${n}`),o.set("lf_tags",r.join(" ")),o.append("save_edit","1"),fetch(e.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to save filter")}).catch(t=>{console.error("Error saving note filter:",t),alert(window.ShaarliProI18n.t("Failed to save filter.")+" "+window.ShaarliProI18n.t("Please refresh the page."))})},window.setNoteBackground=function(t,e,o){const n="none"===e?"none":L(e)||"none",r=document.querySelector(`.note-card[data-id="${t}"]`);if(r){const t=Array.from(r.classList).find(t=>t.startsWith("note-color-")),e=t?t.replace("note-color-",""):r.dataset.color||"default",o=r.dataset.filter||"none",a=T(r);O(r,{color:e,filter:o,background:n,fontColor:a})}const a=document.querySelector(`.link-outer[data-id="${t}"]`);if(a){const t=Array.from(a.classList).find(t=>t.startsWith("note-color-")),e=t?t.replace("note-color-",""):a.dataset.color||"default",o=a.dataset.filter||"none",r=T(a);O(a,{color:e,filter:o,background:n,fontColor:r})}const i=h(),l=g(i);if(i&&l&&String(l.id)===String(t)){l.background=n;const t=i.querySelector(".note-modal");t&&O(t,l);const e=i.querySelector(".note-modal-palette");e&&(e.innerHTML=ht(l))}fetch(o).then(t=>t.text()).then(t=>{const e=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!e)throw new Error("Could not find edit form");const o=new URLSearchParams;e.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&o.append(t.name,t.value||"on"):t.name&&o.append(t.name,Y(t))});let r=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return r=r.filter(t=>!t.startsWith(s)),n&&"none"!==n&&r.push(`${s}${n}`),o.set("lf_tags",r.join(" ")),o.append("save_edit","1"),fetch(e.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to save background")}).catch(t=>{console.error("Error saving note background:",t),alert(window.ShaarliProI18n.t("Failed to save background.")+" "+window.ShaarliProI18n.t("Please refresh the page."))})},window.setModalNoteBackground=function(t){const e=h(),o=g(e);if(!e||!o)return;const n="none"===t?"none":L(t)||"none";setNoteBackground(o.id,n,o.editUrl),o.background=n;const r=e.querySelector(".note-modal");r&&O(r,o);const a=e.querySelector(".note-modal-palette");a&&(a.innerHTML=ht(o),a.classList.add("open"),D(a))};let vt=!1;function wt(){const t=document.getElementById("shaarli-color-picker");if(!t)return;const e=t.dataset.type||"background",o="1"===t.dataset.skipRestore,n=t.dataset.mode||"entity",r=t.dataset.entityId||"";if(!o&&"draft"===n)return t.dataset.skipRestore="0",t.classList.remove("open"),t.style.display="none",void t.setAttribute("aria-hidden","true");if(!o&&"font"===e){const e=t.dataset.prevFontColorKey||"auto";"modal"===n?$t(e):St(r,e)}if(!o&&"background"===e){const e=t.dataset.prevColorKey||"default";"modal"===n?Et(e):Lt(r,e)}t.dataset.skipRestore="0",t.classList.remove("open"),t.style.display="none",t.setAttribute("aria-hidden","true")}function kt({mode:t,entityId:e,editUrl:o,type:n}){!function(){if(vt)return;if(document.getElementById("shaarli-color-picker"))return void(vt=!0);const t=document.createElement("div");t.id="shaarli-color-picker",t.className="color-picker-panel",t.setAttribute("role","dialog"),t.setAttribute("aria-modal","false"),t.setAttribute("aria-hidden","true"),t.style.display="none",document.body.appendChild(t),document.addEventListener("click",t=>{const e=document.getElementById("shaarli-color-picker");e&&e.classList.contains("open")&&(t.target.closest("#shaarli-color-picker")||t.target.closest("#shaarli-bg-studio")||wt())}),document.addEventListener("keydown",t=>{if("Escape"!==t.key)return;const e=document.getElementById("shaarli-color-picker");e&&e.classList.contains("open")&&wt()}),vt=!0}();const a=document.getElementById("shaarli-color-picker");if(!a)return;a.dataset.mode=t||"entity",a.dataset.entityId=e||"",a.dataset.editUrl=o||"",a.dataset.type=n||"background";const i="dark"===P()?"#20293A":"#ffffff";if("font"===(n||"background")){let o="auto";if("draft"===(t||"entity")){const t=document.getElementById("shaarli-bg-studio");o=t&&t.dataset.fontColor||"auto"}else if("modal"===(t||"entity")){const t=h(),e=t?t.querySelector(".note-modal"):null;o=e&&e.dataset.fontColor?e.dataset.fontColor:"auto"}else{const t=document.querySelector(`.note-card[data-id="${e}"]`),n=document.querySelector(`.link-outer[data-id="${e}"]`);o=t&&t.dataset.fontColor?t.dataset.fontColor:n&&n.dataset.fontColor?n.dataset.fontColor:"auto"}a.dataset.prevFontColorKey=o}else a.dataset.prevFontColorKey="";if("background"===(n||"background")){let o="default";if("draft"===(t||"entity")){const t=document.getElementById("shaarli-bg-studio");t&&(o=t.dataset.color||"default")}else if("modal"===(t||"entity")){const t=h(),e=t?t.querySelector(".note-modal"):null;if(e){const t="custom"===e.dataset.color,n=e.dataset.customColor||"";o=t&&n?`custom:${n}`:_(e)}}else{const t=document.querySelector(`.note-card[data-id="${e}"]`),n=document.querySelector(`.link-outer[data-id="${e}"]`),r=t||n;if(r){const t="custom"===r.dataset.color,e=r.dataset.customColor||"";o=t&&e?`custom:${e}`:_(r)}}a.dataset.prevColorKey=o}else a.dataset.prevColorKey="";a.innerHTML=`\n <div class="color-picker-header">\n <div class="color-picker-title">${"font"===n?"Couleur du texte":window.ShaarliProI18n.t("Custom color")}</div>\n <button class="color-picker-close" type="button" data-color-picker-action="close" title="${window.ShaarliProI18n.t("Close")}" aria-label="${window.ShaarliProI18n.t("Close")}"><i class="mdi mdi-close" aria-hidden="true"></i></button>\n </div>\n <div class="color-picker-body">\n <div class="color-picker-gradient">\n <div class="color-picker-gradient-inner" id="color-gradient">\n <div class="color-picker-cursor" id="color-cursor"></div>\n </div>\n </div>\n <div class="color-picker-hue">\n <input type="range" min="0" max="360" value="210" class="color-picker-hue-slider" id="hue-slider">\n </div>\n <div class="color-picker-preview-row">\n <div class="color-picker-preview" id="color-preview"></div>\n <div class="color-picker-inputs">\n <div class="color-picker-input-group">\n <label>Hex</label>\n <input type="text" id="hex-input" value="${i}" maxlength="7">\n </div>\n </div>\n </div>\n </div>\n <div class="color-picker-footer">\n <button type="button" class="color-picker-btn color-picker-btn-secondary" data-color-picker-action="close">Annuler</button>\n <button type="button" class="color-picker-btn color-picker-btn-primary" data-color-picker-action="apply">Appliquer</button>\n </div>\n `;let l=210,s=50,d=50,c=i;const u=a.querySelector("#color-gradient"),m=a.querySelector("#color-cursor"),p=a.querySelector("#hue-slider"),f=a.querySelector("#hex-input"),g=a.querySelector("#color-preview");function b(){if(c=function(t,e,o){const n=o*e,r=n*(1-Math.abs(t/60%2-1)),a=o-n;let i,l,s;t<60?(i=n,l=r,s=0):t<120?(i=r,l=n,s=0):t<180?(i=0,l=n,s=r):t<240?(i=0,l=r,s=n):t<300?(i=r,l=0,s=n):(i=n,l=0,s=r);const d=t=>Math.round(255*(t+a)).toString(16).padStart(2,"0");return`#${d(i)}${d(l)}${d(s)}`.toUpperCase()}(l,s/100,d/100),u.style.background=`linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${l}, 100%, 50%))`,m.style.left=`${s}%`,m.style.top=100-d+"%",g.style.backgroundColor=c,f.value=c,"font"===(a.dataset.type||"background")){const t=`custom:${c}`,e=a.dataset.mode||"entity",o=a.dataset.entityId||"";if("draft"===e){const e=document.getElementById("shaarli-bg-studio");e&&"function"==typeof e.__draftApply&&e.__draftApply({fontColor:t})}else"modal"===e?$t(t):St(o,t)}if("background"===(a.dataset.type||"background")){const t=`custom:${c}`,e=a.dataset.mode||"entity",o=a.dataset.entityId||"";if("draft"===e){const e=document.getElementById("shaarli-bg-studio");e&&"function"==typeof e.__draftApply&&e.__draftApply({color:t})}else"modal"===e?Et(t):Lt(o,t)}}function y(t){const e=function(t){const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);if(!e)return{h:0,s:0,v:0};const o=parseInt(e[1],16)/255,n=parseInt(e[2],16)/255,r=parseInt(e[3],16)/255,a=Math.max(o,n,r),i=a-Math.min(o,n,r);let l=0;return 0!==i&&(l=a===o?((n-r)/i+6)%6*60:a===n?60*((r-o)/i+2):60*((o-n)/i+4)),{h:l,s:0===a?0:i/a,v:a}}(t);l=e.h,s=100*e.s,d=100*e.v,p.value=l,b()}let v=!1;if(u.addEventListener("mousedown",t=>{v=!0;const e=u.getBoundingClientRect();s=Math.max(0,Math.min(100,(t.clientX-e.left)/e.width*100)),d=Math.max(0,Math.min(100,100-(t.clientY-e.top)/e.height*100)),b()}),document.addEventListener("mousemove",t=>{if(!v)return;const e=u.getBoundingClientRect();s=Math.max(0,Math.min(100,(t.clientX-e.left)/e.width*100)),d=Math.max(0,Math.min(100,100-(t.clientY-e.top)/e.height*100)),b()}),document.addEventListener("mouseup",()=>{v=!1}),p.addEventListener("input",t=>{l=parseInt(t.target.value),b()}),f.addEventListener("input",t=>{const e=t.target.value;/^#[0-9A-F]{6}$/i.test(e)&&y(e)}),"font"===(a.dataset.type||"background")){const t=a.dataset.prevFontColorKey||"auto";let e=i;if("string"==typeof t&&t.startsWith("custom:"))e=t.substring(7);else if("auto"!==t){const o=r.find(e=>e.key===t);o&&o.value&&"auto"!==o.value&&(e=o.value)}y(e)}else if("background"===(a.dataset.type||"background")){const t=a.dataset.prevColorKey||"default";let e=i;"string"==typeof t&&t.startsWith("custom:")&&(e=t.substring(7)),y(e)}else y(i);a.style.display="block",a.style.visibility="hidden",function(t){if(!t)return;const e=document.getElementById("shaarli-bg-studio"),o=12;if(e&&e.classList.contains("open")){const n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=Math.max(1,r.width),i=Math.max(1,r.height);let l=n.right+10,s=n.top;l+a>window.innerWidth-o&&(l=n.left-a-10),l<o&&(l=o),l+a>window.innerWidth-o&&(l=window.innerWidth-o-a),s+i>window.innerHeight-o&&(s=window.innerHeight-o-i),s<o&&(s=o),t.style.left=`${Math.round(l)}px`,t.style.top=`${Math.round(s)}px`,t.style.right="",t.style.bottom=""}else{const e=t.getBoundingClientRect(),n=Math.max(1,e.width),r=Math.max(1,e.height),a=Math.max(o,Math.min((window.innerWidth-n)/2,window.innerWidth-o-n)),i=Math.max(o,Math.min((window.innerHeight-r)/2,window.innerHeight-o-r));t.style.left=`${Math.round(a)}px`,t.style.top=`${Math.round(i)}px`}}(a),a.style.visibility="visible",a.classList.add("open"),a.setAttribute("aria-hidden","false")}function St(t,e){const o=document.querySelector(`.note-card[data-id="${t}"]`),n=document.querySelector(`.link-outer[data-id="${t}"]`);let a="auto";if("string"==typeof e&&e.startsWith("custom:"))a=e.substring(7);else if("auto"!==e){const t=r.find(t=>t.key===e);a=t?t.value:"auto"}const i=t=>{t&&("auto"===a?t.style.removeProperty("--note-card-fg"):t.style.setProperty("--note-card-fg",a),t.dataset.fontColor=e)};i(o),i(n);const l=h(),s=g(l);if(l&&s&&String(s.id)===String(t)){i(l.querySelector(".note-modal"))}}function $t(t){const e=h(),o=g(e);e&&o&&St(o.id,t)}function Lt(t,e){const o=document.querySelector(`.note-card[data-id="${t}"]`),n=document.querySelector(`.link-outer[data-id="${t}"]`),r=t=>{if(!t)return;const o={color:_(t),filter:U(t),background:A(t),fontColor:T(t)};if("string"==typeof e&&e.startsWith("custom:")){const o=e.substring(7);Array.from(t.classList).forEach(e=>{e.startsWith("note-color-")&&t.classList.remove(e)}),t.classList.add("note-color-custom"),t.style.backgroundColor=o,t.style.removeProperty("border-color"),t.dataset.color="custom",t.dataset.customColor=o;const n=q(o);return void(n&&t.style.setProperty("--note-card-fg",n))}t.dataset.customColor="",O(t,{...o,color:e})};r(o),r(n);const a=h(),i=g(a);if(a&&i&&String(i.id)===String(t)){r(a.querySelector(".note-modal"))}}function Et(t){const e=h(),o=g(e);e&&o&&Lt(o.id,t)}function Pt(t,e,o){St(t,e),fetch(o).then(t=>t.text()).then(t=>{const o=(new DOMParser).parseFromString(t,"text/html").querySelector('form[name="linkform"]');if(!o)throw new Error("Could not find edit form");const n=new URLSearchParams;o.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&n.append(t.name,t.value||"on"):t.name&&n.append(t.name,Y(t))});let i=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());if(i=i.filter(t=>!t.startsWith(a)),"auto"!==e)if(e.startsWith("custom:"))i.push(`${a}${e.substring(7).replace("#","")}`);else{const t=r.find(t=>t.key===e);t&&"auto"!==t.value&&i.push(`${a}${t.value.substring(1)}`)}return n.set("lf_tags",i.join(" ")),n.append("save_edit","1"),fetch(o.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to save font color")}).catch(t=>{console.error("Error saving note font color:",t)})}function Ct(t){const e=h(),o=g(e);if(!e||!o)return;Pt(o.id,t,o.editUrl),o.fontColor=t;const n=e.querySelector(".note-modal");if(n){let e="auto";if(String(t||"").startsWith("custom:"))e=String(t).substring(7);else if("auto"!==t){const o=r.find(e=>e.key===t);e=o?o.value:"auto"}"auto"===e?n.style.removeProperty("--note-card-fg"):n.style.setProperty("--note-card-fg",e),n.dataset.fontColor=t}}document.addEventListener("click",t=>{const e=t.target.closest("[data-color-picker-action]");if(!e)return;const n=document.getElementById("shaarli-color-picker");if(!n)return;const r=e.dataset.colorPickerAction;if("close"!==r){if("apply"===r){const t=n.dataset.mode||"entity",e=n.dataset.entityId||"",r=n.dataset.editUrl||"",a=n.dataset.type||"background",l=n.querySelector("#hex-input"),s=l?l.value:"#ffffff";if("draft"===t){const t=document.getElementById("shaarli-bg-studio");return t&&"function"==typeof t.__draftApply&&("font"===a?(t.dataset.fontColor=`custom:${s}`,t.__draftApply({fontColor:`custom:${s}`})):(t.dataset.color=`custom:${s}`,t.__draftApply({color:`custom:${s}`})),R(t)),n.dataset.skipRestore="1",void wt()}"font"===a?"modal"===t?function(t){Ct(`custom:${t}`)}(s):Pt(e,`custom:${s}`,r):"modal"===t?function(t){const e=h(),n=g(e);if(!e||!n||!n.editUrl)return;const r=e.querySelector(".note-modal");r&&(r.style.backgroundColor=t,r.style.removeProperty("border-color"),r.dataset.color="custom",r.dataset.customColor=t);fetch(n.editUrl).then(t=>t.text()).then(e=>{const n=(new DOMParser).parseFromString(e,"text/html").querySelector('form[name="linkform"]');if(!n)throw new Error("Could not find edit form");const r=new URLSearchParams;n.querySelectorAll("input, textarea").forEach(t=>{"checkbox"===t.type?t.checked&&r.append(t.name,t.value||"on"):t.name&&r.append(t.name,Y(t))});let a=(r.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());a=a.filter(t=>!t.startsWith(i)),a=a.filter(t=>!t.startsWith("note-custom-")),a=a.filter(t=>{if(!t.startsWith("note-"))return!0;const e=t.substring(5);return!o.some(t=>t.key===e)});const l=t.replace("#","");return a.push(`${i}${l}`),r.set("lf_tags",a.join(" ")),r.append("save_edit","1"),fetch(n.action,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()})}).then(t=>{if(!t.ok)throw new Error("Failed to save custom color")}).catch(t=>{console.error("Error saving custom color:",t)})}(s):setNoteColor(e,`custom:${s}`,r),n.dataset.skipRestore="1",wt()}}else wt()})}(); |