function renderMarkdown(t){return"undefined"!=typeof window&&"function"==typeof window.renderMarkdown?window.renderMarkdown(t):String(t||"").replace(/\n/g,"
")}function applyKeepNoteFormatting(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),a=!!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'),r=!!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'),i=!!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'),l=Array.from(document.querySelectorAll(".search-tag-chip")).map(t=>(t.textContent||"").trim().toLowerCase()),s=t=>"shaarli-archive"===t||"shaarli-archiver"===t,d=t=>"note"===t||"shaarli-note"===t||"#note"===t,c=t=>"todo"===t||"shaarli-todo"===t||"#todo"===t,u=n.some(d)||a||l.some(d),m=n.some(c)||r||l.some(c),p=n.some(s)||i||l.some(s),f=document.getElementById("links-list"),g=document.querySelector(".content-container"),h=()=>{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,">"),n=t=>String(t).replace(/&/g,"&").replace(/"/g,""").replace(//g,">"),a=t=>{const e=String(t||"").trim();return e&&/^(https?:|mailto:|\/)/i.test(e)?e:""},r=t=>{let e=o(t||"");const r=[];return e=e.replace(/`([^`\n]+)`/g,(t,e)=>{const o=`__MD_CODE_${r.length}__`;return r.push(`${e}`),o}),e=e.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,o)=>{const r=a(o);return r?``:t}),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,o)=>{const r=a(o);return r?`${e}`:t}),e=e.replace(/\*\*(.+?)\*\*/g,"$1"),e=e.replace(/__(.+?)__/g,"$1"),e=e.replace(/~~(.+?)~~/g,"
$1"),e=e.replace(/\*(.+?)\*/g,"$1"),e=e.replace(/_(.+?)_/g,"$1"),e=e.replace(/<u>([\s\S]*?)<\/u>/g,"$1"),e=e.replace(/__MD_CODE_(\d+)__/g,(t,e)=>r[Number(e)]||""),e},i=e.split("\n"),l=[];let s=!1,d=!1,c=!1,u=!1,m="",p=[];const f=()=>{s&&(l.push(""),s=!1),d&&(l.push(""),d=!1),c&&(l.push(""),c=!1)};if(i.forEach(t=>{const e=t.trim(),a=e.match(/^```\s*([\w-]+)?\s*$/);if(a){if(f(),u){const t=m?` data-lang="${n(m)}"`:"";l.push(`
${o(p.join("\n"))}`),u=!1,m="",p=[]}else u=!0,m=a[1]||"",p=[];return}if(u)return void p.push(t);if(!e)return f(),void l.push('');const i=t.match(/^\s*(#{1,6})\s+(.+)$/);if(i){f();const t=i[1].length;return void l.push(`${r(g[1])}`);const h=t.match(/^\s*[-*]\s+\[( |x|X)\]\s+(.+)$/);if(h){s&&(l.push(""),s=!1),d&&(l.push(""),d=!1),c||(l.push('
${r(t)}
`)}),u){const t=m?` data-lang="${n(m)}"`:"";l.push(`${o(p.join("\n"))}`)}return f(),l.join("")},window.applyKeepNoteFormatting=function(t,e){if(!t||!e)return;const o=t.selectionStart||0,n=t.selectionEnd||0,a=String(t.value||""),r=a.slice(o,n),i=(e,o,n,r="end")=>{const i=a.slice(0,e)+n+a.slice(o);if(t.value=i,t.focus({preventScroll:!0}),"select"===r)t.setSelectionRange(e,e+n.length);else{const o=e+n.length;t.setSelectionRange(o,o)}},l=(e,i)=>{const l=r||"",s=`${e}${l}${i}`,d=a.slice(0,o)+s+a.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:r,lineEnd:i}=(()=>{const t=a.slice(0,o),e=a.slice(n),r=t.lastIndexOf("\n")+1,i=e.indexOf("\n");return{lineStart:r,lineEnd:-1===i?a.length:n+i}})(),l=a.slice(r,i).split(/\r?\n/).map(e).join("\n"),s=a.slice(0,r)+l+a.slice(i);t.value=s,t.focus({preventScroll:!0}),t.setSelectionRange(r,r+l.length)};if("bold"===e)return l("**","**");if("italic"===e)return l("*","*");if("underline"===e)return l("","");if("strike"===e)return l("~~","~~");if("code"===e)return l("`","`");if("link"===e){const e=`[${r||"Texte du lien"}](https://)`;i(o,n,e);const a=o+e.length-1;return void t.setSelectionRange(a,a)}if("image"===e){const e=``;i(o,n,e);const a=o+e.length-1;return void t.setSelectionRange(a,a)}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${r||"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(!r)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>/g,"$1"));const t=r.replace(/\*\*(.*?)\*\*/g,"$1").replace(/__(.*?)__/g,"$1").replace(/~~(.*?)~~/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/_(.*?)_/g,"$1").replace(/`(.*?)`/g,"$1").replace(/(.*?)<\/u>/g,"$1");i(o,n,t)}};const y=function(){if("function"==typeof initBookmarkPaletteButtons&&initBookmarkPaletteButtons(),"function"==typeof organizePinnedBookmarks&&window.requestAnimationFrame(organizePinnedBookmarks),"function"==typeof initPinnedItems&&initPinnedItems(),f&&g)if(m)try{initTodoView(f,g)}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Todo:",t),h()}else if(u)try{initNoteView(f,g),"function"==typeof initTagDisplayAndRemoval&&initTagDisplayAndRemoval()}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Note:",t),h()}else if(p)try{initArchiveView(f,g),"function"==typeof initTagDisplayAndRemoval&&initTagDisplayAndRemoval()}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Archive:",t),h()}else"function"==typeof initTagDisplayAndRemoval&&initTagDisplayAndRemoval()};initThemeModeBackgroundSync(),"function"==typeof loadBackgroundOptions?loadBackgroundOptions().then(()=>{y()}).catch(t=>{console.error("Erreur lors du chargement des backgrounds:",t),y()}):y()});const NOTE_COLOR_OPTIONS=[{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"}],NOTE_FILTER_OPTIONS=[{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"}],NOTE_FONT_COLOR_OPTIONS=[{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"}],NOTE_FONT_COLOR_TAG_PREFIX="font-",NOTE_COLOR_TAG_PREFIX="note-color-",NOTE_FILTER_TAG_PREFIX="notefilter-",NOTE_BACKGROUND_TAG_PREFIX="notebg-";function isTechnicalTag(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("font-"))return!0;if(e.startsWith("note-color-"))return!0;if(e.startsWith("notefilter-"))return!0;if(e.startsWith("notebg-"))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(NOTE_COLOR_OPTIONS.some(e=>e.key===t))return!0}return!1}function createTagPill({tag:t,onRemoveClass:e="tag-remove-btn",tagClass:o="tag-pill"}){const n=document.createElement("span");n.className=o,n.dataset.tag=t;const a=document.createElement("span");a.className=`${o}-text`,a.textContent=t,n.appendChild(a);if(!(!arguments[0]||!Object.prototype.hasOwnProperty.call(arguments[0],"canRemove")||!!arguments[0].canRemove))return n;const r=document.createElement("button");return r.type="button",r.className=e,r.dataset.tag=t,r.setAttribute("aria-label",`Supprimer le tag ${t}`),r.title=window.ShaarliProI18n.t("Delete"),r.innerHTML="×",n.appendChild(r),n}function removeTagFromEntity(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,getFormFieldValue(t))});let a=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return a=a.filter(t=>t!==e),n.set("lf_tags",a.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 deleteEntitySilently(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 tagDisplayRemovalInitialized=!1;function initTagDisplayAndRemoval(){tagDisplayRemovalInitialized||(document.querySelectorAll(".link-tag-list .link-tag").forEach(t=>{const e=(t.dataset.tag||t.textContent||"").trim();e&&("shaarli-pin"!==e?isTechnicalTag(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"),a=e.closest(".link-outer, .note-card, .note-modal");let r="";if(a&&a.classList.contains("note-card"))r=a.dataset.editUrl||"";else if(a&&a.classList.contains("note-modal"))r=a.dataset.editUrl||"";else{const t=a?a.querySelector(".link-actions"):null,e=t?t.querySelector('a[href*="admin/shaare"]'):null;r=e?e.href:""}r&&removeTagFromEntity(r,o).then(()=>{if(n&&n.remove(),a&&a.classList.contains("note-card")){let t=(a.dataset.tags||"").split("||").filter(t=>t);t=t.filter(t=>t!==o),a.dataset.tags=t.join("||");const e=getOpenModalOverlay(),n=getModalCurrentEntity(e);if(e&&n&&String(n.id)===String(a.dataset.id)){n.tags=(n.tags||[]).filter(t=>t!==o);renderModalTags(e.querySelector(".note-modal-tags"),n.tags)}}if(a&&a.classList.contains("note-modal")){let t=(a.dataset.tags||"").split("||").filter(t=>t);t=t.filter(t=>t!==o),a.dataset.tags=t.join("||");const e=getOpenModalOverlay(),n=getModalCurrentEntity(e);if(e&&n){n.tags=(n.tags||[]).filter(t=>t!==o);renderModalTags(e.querySelector(".note-modal-tags"),n.tags)}const r=a.dataset.noteId||a.dataset.todoId||(n&&n.id?String(n.id):""),i=r?document.querySelector(`.note-card[data-id="${r}"]`):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."))})}),tagDisplayRemovalInitialized=!0)}function getOpenModalOverlay(){return document.querySelector(".note-modal-overlay.open")}function getModalCurrentEntity(t){return t&&(t.currentTodo||t.currentNote)||null}function resolveThemeAssetBasePath(){const t=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).find(t=>t.href&&t.href.includes("/custom_views.css"));if(t&&t.href){const e=new URL(t.href,window.location.origin).pathname.replace(/\/css\/custom_views\.css$/,"");if(e)return e}const e=Array.from(document.querySelectorAll("script[src]")).find(t=>t.src&&t.src.includes("/custom_views.js"));if(e&&e.src){const t=new URL(e.src,window.location.origin).pathname.replace(/\/js\/custom_views\.js$/,"");if(t)return t}return window.shaarli&&"string"==typeof window.shaarli.assetPath&&""!==window.shaarli.assetPath.trim()?window.shaarli.assetPath.replace(/\/$/,""):"/tpl/shaarli-pro"}const NOTE_BACKGROUND_ASSET_ROOT=`${resolveThemeAssetBasePath().replace(/\/$/,"")}/img`;let NOTE_BACKGROUND_OPTIONS=[],isBackgroundOptionsLoaded=!1,backgroundOptionsLoadPromise=null;function organizePinnedBookmarks(){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 a=Array.from(t.getElementsByClassName("link-outer"));if(!a.length)return;const r=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=a.filter(t=>r(t)),l=a.filter(t=>!r(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)}function initPinnedBookmarksSeparation(){const t=document.getElementById("links-list");if(!t)return;organizePinnedBookmarks();["view-grid-btn","view-list-btn","view-compact-btn"].forEach(t=>{const e=document.getElementById(t);e&&e.addEventListener("click",()=>{window.requestAnimationFrame(organizePinnedBookmarks)})}),t.addEventListener("click",t=>{t.target.closest('a[href*="/pin?token="]')&&window.setTimeout(()=>{window.location.reload()},500)})}window.__shaarliCustomViewsVersion="1.0.5-inline-bg-manifest","undefined"!=typeof console&&console&&console.info,document.addEventListener("DOMContentLoaded",initPinnedBookmarksSeparation);const NOTE_BACKGROUND_MANIFEST_INLINE=[{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 loadBackgroundOptions(){return isBackgroundOptionsLoaded?Promise.resolve(NOTE_BACKGROUND_OPTIONS):backgroundOptionsLoadPromise||(NOTE_BACKGROUND_OPTIONS=normalizeDynamicBackgroundOptions(NOTE_BACKGROUND_MANIFEST_INLINE),isBackgroundOptionsLoaded=!0,backgroundOptionsLoadPromise=Promise.resolve(NOTE_BACKGROUND_OPTIONS),backgroundOptionsLoadPromise)}function normalizeBackgroundKey(t){return"string"!=typeof t?"":t.trim().toLowerCase().replace(/[\s_]+/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function formatBackgroundLabel(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 getCurrentThemeMode(){return"dark"===document.documentElement.getAttribute("data-theme")?"dark":"light"}function getColorOption(t){const e="string"==typeof t?t.trim().toLowerCase():"";return NOTE_COLOR_OPTIONS.find(t=>t.key===e)||NOTE_COLOR_OPTIONS.find(t=>"default"===t.key)||null}function getThemeColorValue(t,e=getCurrentThemeMode()){if(!t||"object"!=typeof t)return"";const o="dark"===e?"dark":"light",n="string"==typeof t[o]?t[o].trim():"",a="string"==typeof t.light?t.light.trim():"",r="string"==typeof t.dark?t.dark.trim():"";return n||a||r}function parseHexColor(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}function getReadableForegroundForBackground(t,e=getCurrentThemeMode()){const o=parseHexColor(t);if(!o)return"dark"===e?"#e8eaed":"#202124";return(.299*o.r+.587*o.g+.114*o.b)/255>.56?"#202124":"#f5f7fb"}function normalizeDynamicBackgroundOptions(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=normalizeBackgroundKey("string"==typeof t.key?t.key:t.label||"");if(!e)return;const n=t.files&&"object"==typeof t.files?t.files:{},a="string"==typeof n.light?n.light.trim():"",r="string"==typeof n.dark?n.dark.trim():"";(a||r)&&(o[e]||(o[e]={key:e,label:formatBackgroundLabel(t.label||"",e),paths:{light:"",dark:""}}),a&&(o[e].paths.light=`note-bg-light/${a}`),r&&(o[e].paths.dark=`note-bg-dark/${r}`))}),Object.values(o).sort((t,e)=>t.label.localeCompare(e.label,"fr",{sensitivity:"base"}))}function getAvailableBackgroundOptionsForMode(t=getCurrentThemeMode()){const e="dark"===t?"dark":"light";return NOTE_BACKGROUND_OPTIONS.filter(t=>t.paths&&t.paths[e])}function getNoteBackgroundUrl(t,e=getCurrentThemeMode()){const o=normalizeBackgroundKey(t);if(!o)return"";const n=NOTE_BACKGROUND_OPTIONS.find(t=>t.key===o);if(!n||!n.paths)return"";const a="dark"===e?"dark":"light",r=n.paths[a]||"";return r?`${NOTE_BACKGROUND_ASSET_ROOT}/${r}`:""}function getElementVisualColor(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 getElementVisualBackground(t){if(!t)return"none";return normalizeBackgroundKey(t.dataset.background||"")||"none"}function normalizeFilterKey(t){if("string"!=typeof t)return"none";const e=t.trim().toLowerCase();return NOTE_FILTER_OPTIONS.some(t=>t.key===e)?e:"none"}function getElementVisualFilter(t){return t?normalizeFilterKey(t.dataset.filter||""):"none"}function getElementVisualFontColor(t){return t&&t.dataset.fontColor||"auto"}function refreshNoteFilterVisuals(){document.querySelectorAll(".note-card, .note-modal, .link-outer, .note-input-container").forEach(t=>{applyNoteVisualState(t,{color:getElementVisualColor(t),filter:getElementVisualFilter(t),background:getElementVisualBackground(t),fontColor:getElementVisualFontColor(t)})})}function refreshBackgroundPalettes(){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"]');e.innerHTML=generatePaletteButtons({id:o,editUrl:n&&n.href?n.href:"#",color:getElementVisualColor(t),background:getElementVisualBackground(t)})}),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"),a=n?n.querySelector('a[title=window.ShaarliProI18n.t("Edit")], a[aria-label="Modifier ce bookmark"], a[href*="/admin/shaare/"]'):null;e.innerHTML=generateBookmarkPaletteButtons(o,a&&a.href?a.href:"#",getElementVisualColor(t),getElementVisualBackground(t))});const t=getOpenModalOverlay(),e=getModalCurrentEntity(t);if(!t||!e)return;const o=t.querySelector(".note-modal");o&&(e.color=getElementVisualColor(o),e.background=getElementVisualBackground(o));const n=t.querySelector(".note-modal-palette");n&&(n.innerHTML=generateModalPaletteButtons(e))}function parseBackgroundManifestPayload(t){const e="string"==typeof t?t.trim():"";if(!e)return[];try{return JSON.parse(e)}catch(t){const o=e.indexOf("["),n=e.lastIndexOf("]");if(-1===o||-1===n||n<=o)throw t;const a=e.slice(o,n+1);return JSON.parse(a)}}let isThemeModeBackgroundSyncInitialized=!1;function initThemeModeBackgroundSync(){if(isThemeModeBackgroundSyncInitialized)return;const t=document.documentElement;if(!t)return;let e=getCurrentThemeMode();new MutationObserver(t=>{if(!t.some(t=>"data-theme"===t.attributeName))return;const o=getCurrentThemeMode();o!==e&&(e=o,refreshNoteFilterVisuals(),refreshBackgroundPalettes())}).observe(t,{attributes:!0,attributeFilter:["data-theme"]}),isThemeModeBackgroundSyncInitialized=!0}function positionPalettePopup(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 backgroundStudioPanelInitialized=!1;function ensureBackgroundStudioPanel(){if(backgroundStudioPanelInitialized)return;if(document.getElementById("shaarli-bg-studio"))return void(backgroundStudioPanelInitialized=!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",a=o.dataset.entityId||"",r=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}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteColor(t),o.dataset.color=t,renderBackgroundStudioPanel(o)):(setNoteColor(a,t,r),o.dataset.color=t,renderBackgroundStudioPanel(o)))}if("set-background"===l){const t=e.dataset.bgKey||"none";return void("draft"===n?(o.dataset.background=t,i({background:t}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteBackground(t),o.dataset.background=t,renderBackgroundStudioPanel(o)):(setNoteBackground(a,t,r),o.dataset.background=t,renderBackgroundStudioPanel(o)))}if("set-filter"===l){const t=e.dataset.filter||"none",l=normalizeFilterKey(t||"")||"none";return void("draft"===n?(o.dataset.filter=l,i({filter:l}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteFilter(t),o.dataset.filter=l,renderBackgroundStudioPanel(o)):(setNoteFilter(a,t,r),o.dataset.filter=l,renderBackgroundStudioPanel(o)))}if("set-query"===l){o.dataset.query="",renderBackgroundStudioPanel(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}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteFontColor(t),o.dataset.fontColor=t,renderBackgroundStudioPanel(o)):(setNoteFontColor(a,t,r),o.dataset.fontColor=t,renderBackgroundStudioPanel(o)))}}else openColorPickerPanel({mode:n,entityId:a,editUrl:r,type:"font"});else openColorPickerPanel({mode:n,entityId:a,editUrl:r,type:"background"});else"draft"===n?(o.dataset.fontColor="auto",i({fontColor:"auto"}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteFontColor("auto"),o.dataset.fontColor="auto",renderBackgroundStudioPanel(o)):(setNoteFontColor(a,"auto",r),o.dataset.fontColor="auto",renderBackgroundStudioPanel(o));else"draft"===n?(o.dataset.color="default",o.dataset.background="none",i({color:"default",background:"none"}),renderBackgroundStudioPanel(o)):"modal"===n?(setModalNoteColor("default"),o.dataset.color="default",o.dataset.background="none",renderBackgroundStudioPanel(o)):(setNoteColor(a,"default",r),o.dataset.color="default",o.dataset.background="none",renderBackgroundStudioPanel(o))}else closeBackgroundStudioPanel()}),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 a=Array.from(t.querySelectorAll(".bg-studio-gallery .bg-studio-thumb")),r=a.indexOf(o);if(-1===r)return;const i=2;return void("ArrowRight"===e.key?(e.preventDefault(),n(a,r+i)):"ArrowLeft"===e.key?(e.preventDefault(),n(a,r-i)):"ArrowDown"===e.key?(e.preventDefault(),n(a,r+1)):"ArrowUp"===e.key&&(e.preventDefault(),n(a,r-1)))}if(o.classList.contains("bg-studio-swatch")){const a=Array.from(t.querySelectorAll(".bg-studio-swatches .bg-studio-swatch")),r=a.indexOf(o);if(-1===r)return;return void("ArrowRight"===e.key?(e.preventDefault(),n(a,r+1)):"ArrowLeft"===e.key&&(e.preventDefault(),n(a,r-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(()=>{renderBackgroundStudioPanel(o)},150))}),backgroundStudioPanelInitialized=!0}function closeBackgroundStudioPanel(){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 openBackgroundStudioPanel({anchorEl:t,mode:e,entityId:o,editUrl:n,currentColor:a,currentFilter:r,currentBackground:i,currentFontColor:l,title:s}){ensureBackgroundStudioPanel();const d=document.getElementById("shaarli-bg-studio");d&&(d.dataset.mode=e||"entity",d.dataset.entityId=o||"",d.dataset.editUrl=n||"",d.dataset.color=a||"default",d.dataset.filter=normalizeFilterKey(r||"")||"none",d.dataset.background=normalizeBackgroundKey(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,renderBackgroundStudioPanel(d),d.style.display="block",d.classList.add("open"),d.setAttribute("aria-hidden","false"),positionBackgroundStudioPanel(d,t),window.requestAnimationFrame(()=>{const t=d.querySelector(".bg-studio-search-input");t&&"function"==typeof t.focus&&(t.focus(),t.select())}))}function positionBackgroundStudioPanel(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 a=t.getBoundingClientRect(),r=n?n.top-a.height-10:o,i=n?n.left:o;let l=r;l${window.ShaarliProI18n.t("Archived notes")}
\n `,a.appendChild(r);const i=document.createElement("div");i.className="notes-tools",i.innerHTML='\n \n \n ',a.appendChild(i),n.appendChild(a);const l=document.createElement("div");l.className="notes-content-area";const s=Array.from(t.querySelectorAll(".link-outer")).map(t=>parseNoteFromLink(t)).filter(t=>(t.tags||[]).some(t=>"shaarli-archive"===t||"shaarli-archiver"===t));renderNotes(l,s,"grid",!0),n.appendChild(l),t.style.display="none",t.parentNode?t.parentNode.insertBefore(n,t):e.appendChild(n);const d=document.createElement("div");d.className="note-modal-overlay",d.innerHTML='\n \n ',document.body.appendChild(d);const c=n.querySelector("#btn-view-grid"),u=n.querySelector("#btn-view-list");c.addEventListener("click",()=>{c.classList.add("active"),u.classList.remove("active"),renderNotes(l,s,"grid",!0)}),u.addEventListener("click",()=>{u.classList.add("active"),c.classList.remove("active"),renderNotes(l,s,"list",!0)}),d.querySelector("#note-modal-close").addEventListener("click",()=>{d.classList.remove("open")}),d.addEventListener("click",t=>{t.target===d&&d.classList.remove("open")});const m=d.querySelector("#note-modal-pin"),p=d.querySelector("#note-modal-color-btn"),f=d.querySelector("#note-modal-color-popup");p.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=d.querySelector(".note-modal");openBackgroundStudioPanel({anchorEl:p,mode:"modal",entityId:e&&e.dataset.noteId||"",editUrl:e&&e.dataset.editUrl||"",currentColor:e?getElementVisualColor(e):"default",currentFilter:e?getElementVisualFilter(e):"none",currentBackground:e?getElementVisualBackground(e):"none",currentFontColor:e?getElementVisualFontColor(e):"auto",title:window.ShaarliProI18n.t("My images & colors")})}),m.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=d.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;if(!o||!n)return;togglePinTag(o,n,m);const a=m.classList.contains("active");let r=(e.dataset.tags||"").split("||").filter(t=>t);a?r.includes("shaarli-pin")||r.push("shaarli-pin"):r=r.filter(t=>"shaarli-pin"!==t),e.dataset.tags=r.join("||"),renderModalTags(d.querySelector("#note-modal-tags"),r),d.currentNote&&(d.currentNote.isPinned=a,d.currentNote.tags=r)}),d.querySelector("#note-modal-delete").addEventListener("click",()=>{if(!confirm(window.ShaarliProI18n.t("Delete this note?")))return;const t=d.querySelector(".note-modal"),e=t.dataset.deleteUrl;t.dataset.noteId;e&&"#"!==e&&deleteEntitySilently(e).then(()=>{window.location.href="/?searchtags=shaarli-archive"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})}),d.querySelector("#note-modal-unarchive").addEventListener("click",t=>{t.preventDefault();const e=d.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;o&&n&&removeTagFromEntity(n,"shaarli-archive").then(()=>{d.currentNote&&(d.currentNote.tags=(d.currentNote.tags||[]).filter(t=>"shaarli-archive"!==t));const t=document.querySelector(`.note-card[data-id="${o}"]`);t&&t.remove();const e=s.findIndex(t=>String(t.id)===String(o));e>-1&&s.splice(e,1),d.classList.remove("open")}).catch(t=>{console.error("Error unarchiving note:",t),alert(window.ShaarliProI18n.t("Error unarchiving note."))})}),d.addEventListener("click",t=>{t.target.closest(".note-modal-color-picker")||f.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 parseNoteFromLink(t){const e=t.dataset.id,o=t.querySelector(".link-title"),n=o?o.textContent.trim():"",a=t.querySelector(".link-description"),r=a?a.innerHTML:"",i=a?a.textContent:"";let l=null;if(a){const t=a.querySelector("img");t&&(l=t.src)}const s=t.querySelector(".link-url"),d=s?s.textContent.trim():"",c=[];t.querySelectorAll(".link-tag-list a").forEach(t=>{const e=(t.textContent||"").trim();e&&c.push(e)});const{color:u,filter:m,background:p,fontColor:f}=extractNoteVisualStateFromTags(c),g=c.filter(t=>!t.startsWith("note-color-")&&(!t.startsWith("note-custom-")&&(!(t=>{if("string"!=typeof t)return!1;if(!t.startsWith("note-"))return!1;const e=t.substring(5);return NOTE_COLOR_OPTIONS.some(t=>t.key===e)})(t)&&(!t.startsWith("notefilter-")&&(!t.startsWith("notebg-")&&!t.startsWith("font-")))))),h=(g.includes("shaarli-pin"),t.querySelector(".link-actions")),y=h&&h.querySelector('a[href*="admin/shaare"]')?h.querySelector('a[href*="admin/shaare"]').href:"#",b=h&&h.querySelector('a[href*="delete"]')?h.querySelector('a[href*="delete"]').href:"#",v=h&&h.querySelector('a[href*="pin"]')?h.querySelector('a[href*="pin"]').href:"#",w=g.includes("shaarli-pin");return{id:e,title:n,descHtml:r,descText:i,coverImage:l,url:d,tags:g,color:u,filter:m,background:p,fontColor:f,editUrl:y,deleteUrl:b,pinUrl:v,isPinned:w}}function renderNotes(t,e,o,n=!1){let a;t.innerHTML="",t.className="grid"===o?"notes-masonry":"notes-list-view",a=n?e.filter(t=>(t.tags||[]).some(t=>"shaarli-archive"===t||"shaarli-archiver"===t)):e.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(e=>{const a=document.createElement("div");if(a.className="note-card",a.dataset.id=e.id,a.dataset.editUrl=e.editUrl||"",a.dataset.tags=(e.tags||[]).filter(t=>t).join("||"),applyNoteVisualState(a,e),"list"===o&&a.classList.add("list-mode"),a.addEventListener("click",t=>{t.target.closest("button")||t.target.closest("a")||t.target.closest(".note-hover-actions")||(syncNoteFromCardElement(e,a),openNoteModal(e))}),e.coverImage&&"grid"===o){const t=document.createElement("div");t.className="note-cover",t.innerHTML=`