')||o.trim().startsWith("<")?t.innerHTML=o:t.innerHTML=renderMarkdown(o)}r.appendChild(t)}if(e.tags.length>0){const t=document.createElement("div");t.className="note-tags",e.tags.forEach(o=>{if(isTechnicalTag(o))return;const n=createTagPill({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=`
`,r.appendChild(l);const s=`palette-${e.id}`,d=`archive-${e.id}`;i.innerHTML=`\n
\n
\n
\n \n
\n
\n
\n
\n \x3c!-- Real Actions --\x3e\n
\n
\n `;const c=i.querySelector(".note-delete-btn");c?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),confirm(window.ShaarliProI18n.t("Delete this note?"))&&deleteEntitySilently(e.deleteUrl).then(()=>{window.location.href=n?"/?searchtags=shaarli-archive":"/?searchtags=note"}).catch(t=>{console.error("Delete failed:",t),alert(window.ShaarliProI18n.t("Error deleting."))})});const u=i.querySelector(".note-open-editor-btn");u?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),syncNoteFromCardElement(e,a),openNoteModal(e)});const m=i.querySelector(`#${s}`);m.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),openBackgroundStudioPanel({anchorEl:m,mode:"entity",entityId:e.id,editUrl:e.editUrl,currentColor:getElementVisualColor(a),currentFilter:getElementVisualFilter(a),currentBackground:getElementVisualBackground(a),title:window.ShaarliProI18n.t("My images & colors")})});i.querySelector(`#${d}`).addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),e.editUrl&&"#"!==e.editUrl&&addTagToNote(e.editUrl,"shaarli-archive").then(()=>{a.remove()}).catch(t=>{console.error("Error archiving note:",t),alert(window.ShaarliProI18n.t("Error archiving note."))})}),r.appendChild(i),a.appendChild(r),t.appendChild(a)})}function setModalPinButtonState(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 renderModalTags(t,e){if(!t)return;t.innerHTML="";const o=(e||[]).filter(t=>t&&!isTechnicalTag(t)),n=getModalCurrentEntity(t.closest(".note-modal-overlay")||getOpenModalOverlay()),a=!(!n||!n.editUrl||"#"===n.editUrl);0!==o.length?(t.classList.remove("is-empty"),o.forEach(e=>{const o=createTagPill({tag:e,onRemoveClass:"note-tag-remove-btn",tagClass:"note-tag",canRemove:a});t.appendChild(o)})):t.classList.add("is-empty")}function openNoteModal(t){const e=document.querySelector(".note-modal-overlay");if(!e)return;const o=e.querySelector(".note-modal"),n=e.querySelector("#note-modal-title"),a=e.querySelector("#note-modal-description-source"),r=e.querySelector("#note-modal-description-preview"),i=e.querySelector("#note-modal-tags"),l=e.querySelector("#note-modal-edit"),s=e.querySelector("#note-modal-pin"),d=e.querySelector("#note-modal-color-popup"),c=(e.querySelector("#note-modal-format-btn"),e.querySelector("#note-modal-formatting"),t=>{a&&r&&(t?(e.classList.add("note-modal-editing"),r.setAttribute("aria-hidden","true"),a.removeAttribute("aria-hidden")):(e.classList.remove("note-modal-editing"),r.setAttribute("aria-hidden","false"),a.setAttribute("aria-hidden","true")))});e.currentNote=t,o.className="note-modal",applyNoteVisualState(o,t),o.dataset.noteId=t.id||"",o.dataset.editUrl=t.editUrl||"",o.dataset.deleteUrl=t.deleteUrl||"",o.dataset.background=t.background||"none";const u=(t.tags||[]).filter(t=>t&&!isTechnicalTag(t));o.dataset.tags=u.join("||"),n&&(n.value=t.title||""),a&&(a.value=(t._noteMarkdown||t.descText||"").trim()),r&&(r.innerHTML=renderMarkdown((t._noteMarkdown||t.descText||"").trim())),c(!1),renderModalTags(i,u),l&&(l.href=t.editUrl||"#"),d&&(d.innerHTML=generateModalPaletteButtons(t),d.classList.remove("open")),setModalPinButtonState(s,!!t.isPinned),e._noteEditorState||(e._noteEditorState={hasChanges:!1,isSaving:!1,lastSavedTitle:"",lastSavedMarkdown:""});const m=e._noteEditorState;if(m.hasChanges=!1,m.lastSavedTitle=n&&"string"==typeof n.value?n.value.trim():"",m.lastSavedMarkdown=a&&"string"==typeof a.value?a.value.trim():"",!e._noteEditorBound){e._noteEditorBound=!0,n?.addEventListener("input",()=>{e._noteEditorState&&(e._noteEditorState.hasChanges=!0)}),a?.addEventListener("input",()=>{e._noteEditorState&&(e._noteEditorState.hasChanges=!0),r&&(r.innerHTML=renderMarkdown(a.value||""))}),r?.addEventListener("click",()=>{c(!0),a?.focus({preventScroll:!0})}),r?.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),c(!0),a?.focus({preventScroll:!0}))}),a?.addEventListener("blur",()=>{c(!1)});const t=t=>{const o=e.querySelector("#note-modal-formatting");o&&(t?(o.classList.add("open"),o.setAttribute("aria-hidden","false"),e.classList.add("show-formatting")):(o.classList.remove("open"),o.setAttribute("aria-hidden","true"),e.classList.remove("show-formatting")))};e._setNoteModalFormattingVisible=t;const o=e.querySelector("#note-modal-format-btn");o?.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation();const n=e.querySelector("#note-modal-formatting"),a=n&&n.classList.contains("open");t(!a)}),e.querySelectorAll(".note-format-btn").forEach(t=>{t.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation();const n=e.querySelector("#note-modal-description-source");n&&(c(!0),applyKeepNoteFormatting(n,t.dataset.noteFormat||""),e._noteEditorState&&(e._noteEditorState.hasChanges=!0))})})}"function"==typeof e._setNoteModalFormattingVisible&&e._setNoteModalFormattingVisible(!1),hydrateNoteFromEditForm(t).then(()=>{e.currentNote===t&&(n&&t._noteTitle&&(n.value=t._noteTitle),a&&(a.value=(t._noteMarkdown||"").trim()),r&&(r.innerHTML=renderMarkdown(a?a.value:"")),c(!1),m.lastSavedTitle=n&&"string"==typeof n.value?n.value.trim():"",m.lastSavedMarkdown=a&&"string"==typeof a.value?a.value.trim():"")}),e.classList.add("open"),document.body.classList.add("note-modal-open"),n?.focus({preventScroll:!0})}async function saveOpenNoteEditorModal(t){if(!t||!t.currentNote)return;const e=t.currentNote,o=t.querySelector("#note-modal-title"),n=t.querySelector("#note-modal-description-source"),a=o&&"string"==typeof o.value?o.value.trim():"",r=n&&"string"==typeof n.value?n.value.trim():"",i=t._noteEditorState||{hasChanges:!1,isSaving:!1,lastSavedTitle:"",lastSavedMarkdown:""};if(!a&&!r)return;if(!(i.hasChanges||a!==(i.lastSavedTitle||"")||r!==(i.lastSavedMarkdown||""))||i.isSaving)return;i.isSaving=!0,t._noteEditorState=i,await hydrateNoteFromEditForm(e),await persistNoteChanges(e,{title:a,markdown:r}),e.title=a,e._noteTitle=a,e._noteMarkdown=r,e.descText=r;const l=document.querySelector(`.note-card[data-id="${CSS.escape(String(e.id))}"]`);if(l){const t=l.querySelector(".note-inner .note-title");t&&(t.textContent=a);const o=l.querySelector(".note-inner .note-body");o&&(o.innerHTML=renderMarkdown(r),e.descHtml=o.innerHTML)}i.lastSavedTitle=a,i.lastSavedMarkdown=r,i.hasChanges=!1,i.isSaving=!1}function generateModalPaletteButtons(t){return generateUnifiedPaletteMenu({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 generatePaletteButtons(t){return generateUnifiedPaletteMenu({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:"entity"})}function addTagToNote(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.includes(e)||a.push(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 initPinnedItems(){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 a=t.querySelector(".mdi-pin-outline, .mdi-pin"),r=t.querySelector(".link-title, .note-title"),i=r?r.querySelector("i.mdi-pin"):null;if(e){if(o.push(t),t.classList.add("is-pinned-tag"),a&&(a.classList.remove("mdi-pin-outline"),a.classList.add("mdi-pin"),a.parentElement&&a.parentElement.classList.add("active")),r&&!i){const t=document.createElement("i");t.className="mdi mdi-pin",t.style.color="var(--primary)",t.style.marginRight="8px",r.prepend(t)}}else t.classList.remove("is-pinned-tag"),a&&(a.classList.remove("mdi-pin"),a.classList.add("mdi-pin-outline"),a.parentElement&&a.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]);"function"==typeof organizePinnedBookmarks&&window.requestAnimationFrame(organizePinnedBookmarks),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 a=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&&(a=t.href)}n&&a&&togglePinTag(n,a,e)}},{once:!1})}function togglePinTag(t,e,o){const n=o.querySelector("i");let a=!1;n&&(n.classList.contains("mdi-pin-outline")?(n.classList.remove("mdi-pin-outline"),n.classList.add("mdi-pin"),o.classList.add("active"),a=!0):(n.classList.remove("mdi-pin"),n.classList.add("mdi-pin-outline"),o.classList.remove("active"),a=!1));const r=o.closest(".link-outer, .note-card");if(r){r.classList.toggle("is-pinned-tag",a);const t=r.querySelector(".link-title, .note-title");if(t){let e=t.querySelector("i.mdi-pin");if(a){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=r.querySelector(".note-tags");if(e||(e=r.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(a){if(!t)if(r.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,getFormFieldValue(t))});let n=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());const r="shaarli-pin";return a?n.includes(r)||n.push(r):n=n.filter(t=>t!==r),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&&"function"==typeof organizePinnedBookmarks&&window.requestAnimationFrame(organizePinnedBookmarks)}).catch(t=>console.error(t))}window.setModalNoteColor=function(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o)return;setNoteColor(o.id,t,o.editUrl),o.color=t;const n=e.querySelector(".note-modal");n&&applyNoteVisualState(n,o);const a=e.querySelector(".note-modal-palette");a&&(a.innerHTML=generateModalPaletteButtons(o),a.classList.add("open"),positionPalettePopup(a))},window.setModalNoteFontColor=function(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o)return;setNoteFontColor(o.id,t,o.editUrl),o.fontColor=t;const n=e.querySelector(".note-modal");n&&applyNoteVisualState(n,o);const a=e.querySelector(".note-modal-palette");a&&(a.innerHTML=generateModalPaletteButtons(o),a.classList.add("open"),positionPalettePopup(a))},window.setModalNoteFilter=function(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o)return;const n=normalizeFilterKey(t)||"none";setNoteFilter(o.id,n,o.editUrl),o.filter=n;const a=e.querySelector(".note-modal");a&&applyNoteVisualState(a,o);const r=e.querySelector(".note-modal-palette");r&&(r.innerHTML=generateModalPaletteButtons(o),r.classList.add("open"),positionPalettePopup(r))},window.setNoteColor=function(t,e,o){setNoteColorVisual(t,e);const n=document.querySelector(`.link-outer[data-id="${t}"]`);if(n){const e=n.querySelector(".bookmark-palette .palette-popup");if(e){const a=getElementVisualColor(n),r=getElementVisualFilter(n);e.innerHTML=generateBookmarkPaletteButtons(t,o,a,r)}}const a=getOpenModalOverlay(),r=getModalCurrentEntity(a);if(a&&r&&String(r.id)===String(t)){r.color=e;const t=a.querySelector(".note-modal");t&&applyNoteVisualState(t,r);const o=a.querySelector(".note-modal-palette");o&&(o.innerHTML=generateModalPaletteButtons(r))}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,getFormFieldValue(t))});let a=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());if(a=a.filter(t=>!t.startsWith("note-color-")),a=a.filter(t=>!t.startsWith("note-custom-")),a=a.filter(t=>{if(!t.startsWith("note-"))return!0;const e=t.substring(5);return!NOTE_COLOR_OPTIONS.some(t=>t.key===e)}),"default"!==e)if("string"==typeof e&&e.startsWith("custom:")){const t=e.substring(7).replace("#","");a.push(`note-color-${t}`)}else a.push(`note-color-${e}`);return 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 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=normalizeFilterKey(e)||"none",a=document.querySelector(`.note-card[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=getElementVisualBackground(a),r=getElementVisualFontColor(a);applyNoteVisualState(a,{color:e,filter:n,background:o,fontColor:r})}const r=document.querySelector(`.link-outer[data-id="${t}"]`);if(r){const e=Array.from(r.classList).find(t=>t.startsWith("note-color-")),a=e?e.replace("note-color-",""):r.dataset.color||"default",i=getElementVisualBackground(r),l=getElementVisualFontColor(r);applyNoteVisualState(r,{color:a,filter:n,background:i,fontColor:l});const s=r.querySelector(".bookmark-palette .palette-popup");s&&(s.innerHTML=generateBookmarkPaletteButtons(t,o,a,n))}const i=getOpenModalOverlay(),l=getModalCurrentEntity(i);if(i&&l&&String(l.id)===String(t)){l.filter=n;const t=i.querySelector(".note-modal");t&&applyNoteVisualState(t,l);const e=i.querySelector(".note-modal-palette");e&&(e.innerHTML=generateModalPaletteButtons(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,getFormFieldValue(t))});let a=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return a=a.filter(t=>!t.startsWith("notefilter-")),n&&"none"!==n&&a.push(`notefilter-${n}`),o.set("lf_tags",a.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":normalizeBackgroundKey(e)||"none",a=document.querySelector(`.note-card[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=getElementVisualFontColor(a);applyNoteVisualState(a,{color:e,filter:o,background:n,fontColor:r})}const r=document.querySelector(`.link-outer[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=getElementVisualFontColor(r);applyNoteVisualState(r,{color:e,filter:o,background:n,fontColor:a})}const i=getOpenModalOverlay(),l=getModalCurrentEntity(i);if(i&&l&&String(l.id)===String(t)){l.background=n;const t=i.querySelector(".note-modal");t&&applyNoteVisualState(t,l);const e=i.querySelector(".note-modal-palette");e&&(e.innerHTML=generateModalPaletteButtons(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,getFormFieldValue(t))});let a=(o.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());return a=a.filter(t=>!t.startsWith("notebg-")),n&&"none"!==n&&a.push(`notebg-${n}`),o.set("lf_tags",a.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=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o)return;const n="none"===t?"none":normalizeBackgroundKey(t)||"none";setNoteBackground(o.id,n,o.editUrl),o.background=n;const a=e.querySelector(".note-modal");a&&applyNoteVisualState(a,o);const r=e.querySelector(".note-modal-palette");r&&(r.innerHTML=generateModalPaletteButtons(o),r.classList.add("open"),positionPalettePopup(r))};let colorPickerPanelInitialized=!1;function ensureColorPickerPanel(){if(colorPickerPanelInitialized)return;if(document.getElementById("shaarli-color-picker"))return void(colorPickerPanelInitialized=!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")||closeColorPickerPanel())}),document.addEventListener("keydown",t=>{if("Escape"!==t.key)return;const e=document.getElementById("shaarli-color-picker");e&&e.classList.contains("open")&&closeColorPickerPanel()}),colorPickerPanelInitialized=!0}function closeColorPickerPanel(){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",a=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?setModalNoteFontColorVisual(e):setNoteFontColorVisual(a,e)}if(!o&&"background"===e){const e=t.dataset.prevColorKey||"default";"modal"===n?setModalNoteColorVisual(e):setNoteColorVisual(a,e)}t.dataset.skipRestore="0",t.classList.remove("open"),t.style.display="none",t.setAttribute("aria-hidden","true")}function openColorPickerPanel({mode:t,entityId:e,editUrl:o,type:n}){ensureColorPickerPanel();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 r="dark"===getCurrentThemeMode()?"#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=getOpenModalOverlay(),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=getOpenModalOverlay(),e=t?t.querySelector(".note-modal"):null;if(e){const t="custom"===e.dataset.color,n=e.dataset.customColor||"";o=t&&n?`custom:${n}`:getElementVisualColor(e)}}else{const t=document.querySelector(`.note-card[data-id="${e}"]`),n=document.querySelector(`.link-outer[data-id="${e}"]`),a=t||n;if(a){const t="custom"===a.dataset.color,e=a.dataset.customColor||"";o=t&&e?`custom:${e}`:getElementVisualColor(a)}}a.dataset.prevColorKey=o}else a.dataset.prevColorKey="";a.innerHTML=`\n \n
\n \n `;let i=210,l=50,s=50,d=r;const c=a.querySelector("#color-gradient"),u=a.querySelector("#color-cursor"),m=a.querySelector("#hue-slider"),p=a.querySelector("#hex-input"),f=a.querySelector("#color-preview");function g(){if(d=function(t,e,o){const n=o*e,a=n*(1-Math.abs(t/60%2-1)),r=o-n;let i,l,s;t<60?(i=n,l=a,s=0):t<120?(i=a,l=n,s=0):t<180?(i=0,l=n,s=a):t<240?(i=0,l=a,s=n):t<300?(i=a,l=0,s=n):(i=n,l=0,s=a);const d=t=>Math.round(255*(t+r)).toString(16).padStart(2,"0");return`#${d(i)}${d(l)}${d(s)}`.toUpperCase()}(i,l/100,s/100),c.style.background=`linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${i}, 100%, 50%))`,u.style.left=`${l}%`,u.style.top=100-s+"%",f.style.backgroundColor=d,p.value=d,"font"===(a.dataset.type||"background")){const t=`custom:${d}`,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?setModalNoteFontColorVisual(t):setNoteFontColorVisual(o,t)}if("background"===(a.dataset.type||"background")){const t=`custom:${d}`,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?setModalNoteColorVisual(t):setNoteColorVisual(o,t)}}function h(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,a=parseInt(e[3],16)/255,r=Math.max(o,n,a),i=r-Math.min(o,n,a);let l=0;return 0!==i&&(l=r===o?((n-a)/i+6)%6*60:r===n?60*((a-o)/i+2):60*((o-n)/i+4)),{h:l,s:0===r?0:i/r,v:r}}(t);i=e.h,l=100*e.s,s=100*e.v,m.value=i,g()}let y=!1;if(c.addEventListener("mousedown",t=>{y=!0;const e=c.getBoundingClientRect();l=Math.max(0,Math.min(100,(t.clientX-e.left)/e.width*100)),s=Math.max(0,Math.min(100,100-(t.clientY-e.top)/e.height*100)),g()}),document.addEventListener("mousemove",t=>{if(!y)return;const e=c.getBoundingClientRect();l=Math.max(0,Math.min(100,(t.clientX-e.left)/e.width*100)),s=Math.max(0,Math.min(100,100-(t.clientY-e.top)/e.height*100)),g()}),document.addEventListener("mouseup",()=>{y=!1}),m.addEventListener("input",t=>{i=parseInt(t.target.value),g()}),p.addEventListener("input",t=>{const e=t.target.value;/^#[0-9A-F]{6}$/i.test(e)&&h(e)}),"font"===(a.dataset.type||"background")){const t=a.dataset.prevFontColorKey||"auto";let e=r;if("string"==typeof t&&t.startsWith("custom:"))e=t.substring(7);else if("auto"!==t){const o=NOTE_FONT_COLOR_OPTIONS.find(e=>e.key===t);o&&o.value&&"auto"!==o.value&&(e=o.value)}h(e)}else if("background"===(a.dataset.type||"background")){const t=a.dataset.prevColorKey||"default";let e=r;"string"==typeof t&&t.startsWith("custom:")&&(e=t.substring(7)),h(e)}else h(r);a.style.display="block",a.style.visibility="hidden",positionColorPickerPanel(a,t),a.style.visibility="visible",a.classList.add("open"),a.setAttribute("aria-hidden","false")}function positionColorPickerPanel(t,e){if(!t)return;const o=document.getElementById("shaarli-bg-studio"),n=12;if(o&&o.classList.contains("open")){const e=o.getBoundingClientRect(),a=t.getBoundingClientRect(),r=Math.max(1,a.width),i=Math.max(1,a.height);let l=e.right+10,s=e.top;l+r>window.innerWidth-n&&(l=e.left-r-10),l
window.innerWidth-n&&(l=window.innerWidth-n-r),s+i>window.innerHeight-n&&(s=window.innerHeight-n-i),st.key===e);a=t?t.value:"auto"}const r=t=>{t&&("auto"===a?t.style.removeProperty("--note-card-fg"):t.style.setProperty("--note-card-fg",a),t.dataset.fontColor=e)};r(o),r(n);const i=getOpenModalOverlay(),l=getModalCurrentEntity(i);if(i&&l&&String(l.id)===String(t)){r(i.querySelector(".note-modal"))}}function setModalNoteFontColorVisual(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);e&&o&&setNoteFontColorVisual(o.id,t)}function setNoteColorVisual(t,e){const o=document.querySelector(`.note-card[data-id="${t}"]`),n=document.querySelector(`.link-outer[data-id="${t}"]`),a=t=>{if(!t)return;const o={color:getElementVisualColor(t),filter:getElementVisualFilter(t),background:getElementVisualBackground(t),fontColor:getElementVisualFontColor(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=getReadableForegroundForBackground(o);return void(n&&t.style.setProperty("--note-card-fg",n))}t.dataset.customColor="",applyNoteVisualState(t,{...o,color:e})};a(o),a(n);const r=getOpenModalOverlay(),i=getModalCurrentEntity(r);if(r&&i&&String(i.id)===String(t)){a(r.querySelector(".note-modal"))}}function setModalNoteColorVisual(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);e&&o&&setNoteColorVisual(o.id,t)}function setNoteFontColor(t,e,o){setNoteFontColorVisual(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,getFormFieldValue(t))});let a=(n.get("lf_tags")||"").split(/[\s,]+/).filter(t=>""!==t.trim());if(a=a.filter(t=>!t.startsWith("font-")),"auto"!==e)if(e.startsWith("custom:"))a.push(`font-${e.substring(7).replace("#","")}`);else{const t=NOTE_FONT_COLOR_OPTIONS.find(t=>t.key===e);t&&"auto"!==t.value&&a.push(`font-${t.value.substring(1)}`)}return 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 save font color")}).catch(t=>{console.error("Error saving note font color:",t)})}function setModalNoteFontColor(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o)return;setNoteFontColor(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=NOTE_FONT_COLOR_OPTIONS.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}}function setModalCustomFontColor(t){setModalNoteFontColor(`custom:${t}`)}function setModalCustomNoteColor(t){const e=getOpenModalOverlay(),o=getModalCurrentEntity(e);if(!e||!o||!o.editUrl)return;const n=e.querySelector(".note-modal");n&&(n.style.backgroundColor=t,n.style.removeProperty("border-color"),n.dataset.color="custom",n.dataset.customColor=t),fetch(o.editUrl).then(t=>t.text()).then(e=>{const o=(new DOMParser).parseFromString(e,"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());a=a.filter(t=>!t.startsWith("note-color-")),a=a.filter(t=>!t.startsWith("note-custom-")),a=a.filter(t=>{if(!t.startsWith("note-"))return!0;const e=t.substring(5);return!NOTE_COLOR_OPTIONS.some(t=>t.key===e)});const r=t.replace("#","");return a.push(`note-color-${r}`),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 save custom color")}).catch(t=>{console.error("Error saving custom color:",t)})}document.addEventListener("click",t=>{const e=t.target.closest("[data-color-picker-action]");if(!e)return;const o=document.getElementById("shaarli-color-picker");if(!o)return;const n=e.dataset.colorPickerAction;if("close"!==n){if("apply"===n){const t=o.dataset.mode||"entity",e=o.dataset.entityId||"",n=o.dataset.editUrl||"",a=o.dataset.type||"background",r=o.querySelector("#hex-input"),i=r?r.value:"#ffffff";if("draft"===t){const t=document.getElementById("shaarli-bg-studio");return t&&"function"==typeof t.__draftApply&&("font"===a?(t.dataset.fontColor=`custom:${i}`,t.__draftApply({fontColor:`custom:${i}`})):(t.dataset.color=`custom:${i}`,t.__draftApply({color:`custom:${i}`})),renderBackgroundStudioPanel(t)),o.dataset.skipRestore="1",void closeColorPickerPanel()}"font"===a?"modal"===t?setModalCustomFontColor(i):setNoteFontColor(e,`custom:${i}`,n):"modal"===t?setModalCustomNoteColor(i):setNoteColor(e,`custom:${i}`,n),o.dataset.skipRestore="1",closeColorPickerPanel()}}else closeColorPickerPanel()});
\ No newline at end of file
+!function(){"use strict";function t(t){return"undefined"!=typeof window&&"function"==typeof window.renderMarkdown?window.renderMarkdown(t):String(t||"").replace(/\n/g," ")}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),P=n.some(w)||c||b.some(w),q=n.some(y)||p||b.some(y),I=document.getElementById("links-list"),$=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,">"),n=t=>String(t).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(`${e}`),o}),e=e.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(t,e,o)=>{const a=r(o);return a?` `:t}),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(t,e,o)=>{const a=r(o);return a?`${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)=>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(""),s=!1),d&&(l.push(""),d=!1),c&&(l.push(""),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(`${o(p.join("\n"))} `),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('
');const i=t.match(/^\s*(#{1,6})\s+(.+)$/);if(i){f();const t=i[1].length;return void l.push(`${a(i[2])} `)}const h=t.match(/^\s*>\s?(.*)$/);if(h)return f(),void l.push(`${a(h[1])} `);const g=t.match(/^\s*[-*]\s+\[( |x|X)\]\s+(.+)$/);if(g){s&&(l.push(""),s=!1),d&&(l.push(""),d=!1),c||(l.push(''),c=!0);const t="x"===String(g[1]).toLowerCase();return void l.push(`${a(g[2])} `)}const b=t.match(/^\s*\d+\.\s+(.+)$/);if(b)return s&&(l.push(" "),s=!1),c&&(l.push(""),c=!1),d||(l.push(""),d=!0),void l.push(`${a(b[1])} `);const y=t.match(/^\s*[-*+]\s+(.+)$/);if(y)return d&&(l.push(" "),d=!1),c&&(l.push(""),c=!1),s||(l.push(""),s=!0),void l.push(`${a(y[1])} `);f(),l.push(`${a(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,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(""," ");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>/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>/g,"$1");i(o,n,t)}};const D=function(){if(V(),window.requestAnimationFrame(k),bt(),I&&$)if(P)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 \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 \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 \n \n \n \n \n \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=E(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 \n \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),L=rt(c);return{id:e,title:n,descHtml:d,descText:c,items:S,_todoHeaderLines:L.headerLines,_todoFooterLines:L.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 \n \n
\n
\n
${window.ShaarliProI18n.t("Add list item")}\n
\n
\n
\n
\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"),L=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")||L.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()}(I,$)}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Todo:",t),x()}else if(S)try{dt(I,$),f()}catch(t){console.error("[custom_views] Erreur lors de l'initialisation de la vue Note:",t),x()}else if(q)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 Archive \n ${window.ShaarliProI18n.t("Archived notes")}
\n `,r.appendChild(a);const i=document.createElement("div");i.className="notes-tools",i.innerHTML='\n \n \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 \n \n
\n
\n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
Fermer \n
\n
\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")})})}(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=C();new MutationObserver(t=>{if(!t.some(t=>"data-theme"===t.attributeName))return;const o=C();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[aria-label="Modifier ce bookmark"], 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}(),L().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 L(){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=E("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:P(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 E(t){return"string"!=typeof t?"":t.trim().toLowerCase().replace(/[\s_]+/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function P(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 C(){return"dark"===document.documentElement.getAttribute("data-theme")?"dark":"light"}function q(t,e=C()){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 I(t,e=C()){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 $(t=C()){const e="dark"===t?"dark":"light";return y.filter(t=>t.paths&&t.paths[e])}function x(t,e=C()){const o=E(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 E(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?(qt(t),o.dataset.fontColor=t,R(o)):(Ct(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?(qt("auto"),o.dataset.fontColor="auto",R(o)):(Ct(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=E(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;lwindow.innerWidth-o&&(s=window.innerWidth-o-r.width);swindow.innerHeight-o&&(l=window.innerHeight-o-r.height);l{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:q(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"]},...$().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`${"none"===e.key?`
`:`
`}
${e.label}
`}).join(""),b=f.filter(t=>"default"!==t.key&&"custom"!==t.key).map(t=>{const e=d===t.key,o=t.color||"";return` `}).join("")+`\n \n `,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` `}).join("")+`\n \n `,w=n.map(t=>((t,e,o)=>{const n=u===t;return` `})(t.key,t.icon,t.label)).join(""),k=!!(t.dataset.query||"").trim();if(t.innerHTML=`\n \n ${g}
\n \n \n \n \n \n
\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:q(l),c=I(d),u=M(e.filter||"none"),m=E(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=E(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[aria-label="Modifier ce bookmark"], 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 \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 \n
Couleurs
\n
${[` `,...o.filter(t=>"default"!==t.key).map(t=>{const e=q(t);return` `})].join("")}
\n
\n
\n \n
Filtres
\n
${[` `,...n.filter(t=>"none"!==t.key).map(t=>` `)].join("")}
\n
\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=E(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=` `,r.appendChild(l);const s=`palette-${e.id}`;i.innerHTML=`\n \n \n
\n
\n \n \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`${o.map(t=>`${nt(String(t.text||""))} `).join("")}${n?'... ':""} `}function nt(t){return String(t).replace(/&/g,"&").replace(//g,">").replace(/\"/g,""").replace(/'/g,"'")}function rt(t){const e=String(t||"").replace(/ /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{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 \n \n \n \n \n \n \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="notes-top-bar-inner";const s=document.createElement("div");s.className="note-input-container";const d=()=>{s.classList.remove("is-editing","is-enhanced","todo-draft-mode"),O(s,{color:"default",filter:"none",background:"none",fontColor:"auto"}),s.innerHTML=`\n \n `;const t=s.querySelector(".note-input-collapsed"),o=s.querySelector(".note-create-note-btn"),n=(t="note")=>{if("list"===t){s.classList.add("is-editing","todo-draft-mode"),s.innerHTML=`\n \n `;const t=s.querySelector(".todo-draft-title"),e=s.querySelector(".todo-draft-list"),o=s.querySelector(".todo-draft-add-btn"),n=s.querySelector(".note-input-close-btn"),r=s.querySelector(".note-input-palette-btn");let a=!1,i=!1,l={color:"default",filter:"none",background:"none",fontColor:"auto"};O(s,l);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 \n \n \n \n \n \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 d();if(!a)return document.removeEventListener("pointerdown",p,!0),void d();i=!0;try{const t=o.map(t=>`- [${t.checked?"x":" "}] ${t.text}`).join("\n");await J({title:e,markdown:t,visual:l}),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")||s.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:l.color||"default",currentFilter:l.filter||"none",currentBackground:l.background||"none",currentFontColor:l.fontColor||"auto",title:window.ShaarliProI18n.t("My images & colors")});const e=document.getElementById("shaarli-bg-studio");e&&(e.__draftApply=t=>{l={...l,...t||{}},O(s,l)})}),void t?.focus({preventScroll:!0})}s.classList.add("is-editing"),s.innerHTML='\n \n ';const o=s.querySelector(".note-input-title"),n=s.querySelector(".note-input-description-source"),r=s.querySelector(".note-input-close-btn"),a=s.querySelector(".note-input-palette-btn"),i=s.querySelector(".note-input-format-btn"),l=s.querySelector(".note-formatting-bar");let c=!1,u=!1,m={color:"default",filter:"none",background:"none",fontColor:"auto"};O(s,m);i?.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=l&&l.classList.contains("open");var o;o=!e,l&&(o?(l.classList.add("open"),l.setAttribute("aria-hidden","false"),s.classList.add("show-formatting")):(l.classList.remove("open"),l.setAttribute("aria-hidden","true"),s.classList.remove("show-formatting")))}),s.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 d();if(!c)return document.removeEventListener("pointerdown",f,!0),void d();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")||s.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(s,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")})};d(),l.appendChild(s),i.appendChild(l);const c=document.createElement("div");c.className="notes-tools",c.innerHTML='\n \n \n ',i.appendChild(c),a.appendChild(i);const u=document.createElement("div");u.className="notes-content-area";const p=Array.from(o.querySelectorAll(".link-outer")).map(t=>ct(t));ut(u,p,"grid"),a.appendChild(u),o.style.display="none",o.parentNode?o.parentNode.insertBefore(a,o):n.appendChild(a);const f=window.location.hash;if(f&&f.startsWith("#open-note-")){const t=f.replace("#open-note-",""),e=p.find(e=>String(e.id)===String(t));e&&(history.replaceState(null,null,window.location.pathname+window.location.search),setTimeout(()=>{ft(e)},100))}const h=document.createElement("div");h.className="note-modal-overlay",h.innerHTML='\n \n \n
\n
\n
\n
\n H1 \n H2 \n H3 \n Aa \n \n B \n I \n U \n S \n \n \n \n \n \n \n \n \n \n X \n
\n
\n
\n
\n
\n
\n \n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Fermer \n
\n
\n ',document.body.appendChild(h);const g=a.querySelector("#btn-view-grid"),b=a.querySelector("#btn-view-list");g.addEventListener("click",()=>{g.classList.add("active"),b.classList.remove("active"),ut(u,p,"grid")}),b.addEventListener("click",()=>{b.classList.add("active"),g.classList.remove("active"),ut(u,p,"list")});const y=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}(h),h.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."))}};h.querySelector("#note-modal-close").addEventListener("click",t=>{t.preventDefault(),y()}),h.addEventListener("click",t=>{t.target===h&&y()}),h.querySelector("#note-modal-edit").addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=h.querySelector("#note-modal-title");e?.focus({preventScroll:!0})});const v=h.querySelector("#note-modal-pin"),w=h.querySelector("#note-modal-color-btn"),k=h.querySelector("#note-modal-color-popup");w.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=h.querySelector(".note-modal");j({anchorEl:w,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")})}),v.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=h.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;if(!o||!n)return;yt(o,n,v);const r=v.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(h.querySelector("#note-modal-tags"),a),h.currentNote&&(h.currentNote.isPinned=r,h.currentNote.tags=a)}),h.querySelector("#note-modal-delete").addEventListener("click",()=>{if(!confirm(window.ShaarliProI18n.t("Delete this note?")))return;const t=h.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."))})}),h.querySelector("#note-modal-archive").addEventListener("click",t=>{t.preventDefault();const e=h.querySelector(".note-modal"),o=e.dataset.noteId,n=e.dataset.editUrl;o&&n&>(n,"shaarli-archive").then(()=>{h.currentNote&&(h.currentNote.tags.includes("shaarli-archive")||h.currentNote.tags.push("shaarli-archive"));const t=document.querySelector(`.note-card[data-id="${o}"]`);t&&t.remove();const e=p.findIndex(t=>String(t.id)===String(o));e>-1&&p.splice(e,1),h.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."))})}),h.addEventListener("click",t=>{t.target.closest(".note-modal-color-picker")||k.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:"#",L=k&&k.querySelector('a[href*="delete"]')?k.querySelector('a[href*="delete"]').href:"#",E=k&&k.querySelector('a[href*="pin"]')?k.querySelector('a[href*="pin"]').href:"#",P=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:L,pinUrl:E,isPinned:P}}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=` `,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('')||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.appendChild(s);const u=`palette-${o.id}`,p=`archive-${o.id}`;l.innerHTML=`\n
\n
\n
\n \n
\n
\n
\n
\n \x3c!-- Real Actions --\x3e\n
\n
\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;Ct(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){Et(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":E(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":E(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?Lt(e):St(r,e)}if(!o&&"background"===e){const e=t.dataset.prevColorKey||"default";"modal"===n?Pt(e):Et(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"===C()?"#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 \n
\n \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?Lt(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?Pt(t):Et(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
window.innerWidth-o&&(l=window.innerWidth-o-a),s+i>window.innerHeight-o&&(s=window.innerHeight-o-i),st.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 Lt(t){const e=h(),o=g(e);e&&o&&St(o.id,t)}function Et(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=I(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 Pt(t){const e=h(),o=g(e);e&&o&&Et(o.id,t)}function Ct(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 qt(t){const e=h(),o=g(e);if(!e||!o)return;Ct(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){qt(`custom:${t}`)}(s):Ct(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()})}();
\ No newline at end of file
diff --git a/shaarli-pro/dist/manifest.json b/shaarli-pro/dist/manifest.json
index cded17d..fc1c655 100644
--- a/shaarli-pro/dist/manifest.json
+++ b/shaarli-pro/dist/manifest.json
@@ -1,5 +1,5 @@
{
- "generatedAt": "2026-08-09T13:02:05.428Z",
+ "generatedAt": "2026-08-09T14:36:19.907Z",
"files": {
"css/style.css": {
"dist": "dist/style.min.css",
@@ -63,8 +63,8 @@
},
"js/custom_views.js": {
"dist": "dist/custom_views.min.js",
- "hash": "595e6e4ac4c0",
- "size": 143968
+ "hash": "61de59908cac",
+ "size": 132471
},
"js/awesomplete.min.js": {
"dist": "dist/awesomplete.min.js",
diff --git a/shaarli-pro/includes.html b/shaarli-pro/includes.html
index bc1ce38..32e29dc 100644
--- a/shaarli-pro/includes.html
+++ b/shaarli-pro/includes.html
@@ -83,11 +83,11 @@
{loop="$plugins_includes.css_files"}
-
+
{/loop}
{if="is_file('data/user.css')"}
-
+
{/if}