/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var st=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var pt=Object.prototype.hasOwnProperty;var ut=(B,o)=>{for(var e in o)st(B,e,{get:o[e],enumerable:!0})},mt=(B,o,e,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of ht(o))!pt.call(B,t)&&t!==e&&st(B,t,{get:()=>o[t],enumerable:!(i=dt(o,t))||i.enumerable});return B};var gt=B=>mt(st({},"__esModule",{value:!0}),B);var ft={};ut(ft,{default:()=>K});module.exports=gt(ft);var y=require("obsidian");async function ct(B,o=1600,e=1200,i=.7){return new Promise((t,a)=>{let s=new Image;s.crossOrigin="Anonymous",s.onload=()=>{let{width:d,height:n}=s,r=d,u=n;if(d>o||n>e){let g=o/d,S=e/n,l=Math.min(g,S);r=d*l,u=n*l}let m=document.createElement("canvas");m.width=r,m.height=u;let c=m.getContext("2d");if(!c){a("Canvas context not available");return}c.drawImage(s,0,0,r,u);let T=m.toDataURL("image/jpeg",i);t(T)},s.onerror=d=>a(d),s.src=B})}var J=class{constructor(o){this.data={};this.saveQueue=null;this.isSaving=!1;this.plugin=o}async load(){try{let o=await this.plugin.loadData();this.data=o||{}}catch(o){console.error("Error loading notes data:",o),this.data={}}}async saveWithRetry(o=3){let e=null;for(let i=0;isetTimeout(a,100*(i+1)))}if(e)throw console.error("Failed to save notes after retries:",e),e}async save(){if(this.isSaving)return this.saveQueue||(this.saveQueue=new Promise(async o=>{await this.saveWithRetry(),this.isSaving=!1,this.saveQueue=null,o()})),this.saveQueue;this.isSaving=!0;try{await this.saveWithRetry()}finally{this.isSaving=!1}}getNote(o){try{return this.data[o]||""}catch(e){return console.error("Error getting note:",e),""}}async setNote(o,e){try{this.data[o]!==e&&(this.data[o]=e,await this.save())}catch(i){throw console.error("Error setting note:",i),i}}async cleanupNotesForSlider(o,e){try{let i=!1,t=[];for(let a of Object.keys(this.data))if(a.startsWith(`${o}-`)){let s=a.substring(o.length+1);e.includes(s)||(t.push(a),i=!0)}if(i){for(let a of t)delete this.data[a];await this.save()}}catch(i){throw console.error("Error cleaning up notes:",i),i}}async clearAllNotes(){try{this.data={},await this.save()}catch(o){throw console.error("Error clearing notes:",o),o}}};var _=require("obsidian"),tt=class{constructor(o){this.drawing=!1;this.startX=0;this.startY=0;this.currentTool="freehand";this.currentGeometricTool="line";this.color="#FF0000";this.lineWidth=2;this.previewImageData=null;this.resizeCanvasBound=()=>{this.resizeCanvas()};this.handlePointerDown=o=>{this.drawing=!0,this.startX=o.offsetX,this.startY=o.offsetY,(this.currentTool==="rectangle"||this.currentTool==="circle"||this.currentTool==="line")&&(this.previewImageData=this.ctx.getImageData(0,0,this.canvas.width,this.canvas.height)),(this.currentTool==="freehand"||this.currentTool==="eraser"||this.currentTool==="laser")&&(this.ctx.beginPath(),this.ctx.moveTo(this.startX,this.startY))};this.handlePointerMove=o=>{if(!this.drawing)return;let e=o.offsetX,i=o.offsetY;if(this.currentTool==="rectangle"||this.currentTool==="circle"||this.currentTool==="line"){if(this.previewImageData&&this.ctx.putImageData(this.previewImageData,0,0),this.ctx.strokeStyle=this.color,this.ctx.lineWidth=this.lineWidth,this.ctx.lineCap="round",this.currentTool==="rectangle"){let t=e-this.startX,a=i-this.startY;this.ctx.strokeRect(this.startX,this.startY,t,a)}else if(this.currentTool==="circle"){let t=Math.sqrt(Math.pow(e-this.startX,2)+Math.pow(i-this.startY,2));this.ctx.beginPath(),this.ctx.arc(this.startX,this.startY,t,0,Math.PI*2),this.ctx.stroke()}else this.currentTool==="line"&&(this.ctx.beginPath(),this.ctx.moveTo(this.startX,this.startY),this.ctx.lineTo(e,i),this.ctx.stroke());return}this.currentTool==="freehand"?(this.ctx.strokeStyle=this.color,this.ctx.lineWidth=this.lineWidth,this.ctx.lineCap="round",this.ctx.lineTo(e,i),this.ctx.stroke()):this.currentTool==="laser"?(this.ctx.strokeStyle=this.color,this.ctx.lineWidth=1,this.ctx.lineCap="round",this.ctx.shadowColor=this.color,this.ctx.shadowBlur=10,this.ctx.lineTo(e,i),this.ctx.stroke(),this.ctx.shadowBlur=0):this.currentTool==="eraser"&&(this.ctx.globalCompositeOperation="destination-out",this.ctx.lineWidth=this.lineWidth,this.ctx.lineTo(e,i),this.ctx.stroke(),this.ctx.globalCompositeOperation="source-over")};this.handlePointerUp=o=>{if(!this.drawing)return;this.drawing=!1;let e=o.offsetX,i=o.offsetY;if(this.ctx.strokeStyle=this.currentTool==="eraser"?"rgba(0,0,0,1)":this.color,this.ctx.lineWidth=this.lineWidth,this.ctx.lineCap="round",this.currentTool==="rectangle"){this.previewImageData&&(this.ctx.putImageData(this.previewImageData,0,0),this.previewImageData=null);let t=e-this.startX,a=i-this.startY;this.ctx.strokeRect(this.startX,this.startY,t,a)}else if(this.currentTool==="circle"){this.previewImageData&&(this.ctx.putImageData(this.previewImageData,0,0),this.previewImageData=null);let t=Math.sqrt(Math.pow(e-this.startX,2)+Math.pow(i-this.startY,2));this.ctx.beginPath(),this.ctx.arc(this.startX,this.startY,t,0,Math.PI*2),this.ctx.stroke()}else this.currentTool==="line"?(this.previewImageData&&(this.ctx.putImageData(this.previewImageData,0,0),this.previewImageData=null),this.ctx.beginPath(),this.ctx.moveTo(this.startX,this.startY),this.ctx.lineTo(e,i),this.ctx.stroke()):this.currentTool==="laser"&&setTimeout(()=>{this.clear()},200)};this.container=o,this.canvas=document.createElement("canvas"),this.canvas.classList.add("drawing-canvas"),this.container.appendChild(this.canvas),this.resizeCanvas();let e=this.canvas.getContext("2d");if(!e)throw new Error("Cannot get 2D context");this.ctx=e,this.toolbar=document.createElement("div"),this.toolbar.classList.add("drawing-toolbar"),this.container.appendChild(this.toolbar),this.createToolbar(),this.enableDrawing(),window.addEventListener("resize",this.resizeCanvasBound)}resizeCanvas(){this.canvas.width=this.container.clientWidth,this.canvas.height=this.container.clientHeight}resetToolbarHighlights(){Array.from(this.toolbar.children).forEach(o=>{o.classList.remove("active-tool")})}createToolbar(){let o=document.createElement("button");o.textContent="",(0,_.setIcon)(o,"pencil"),o.title="Freehand",o.classList.add("drawing-btn","freehand-btn"),o.onclick=()=>{this.currentTool="freehand",this.resetToolbarHighlights(),o.classList.add("active-tool"),r.value=this.lineWidth.toString(),n.value=this.lineWidth.toString(),r.style.display="",n.style.display=""},this.toolbar.appendChild(o);let e=document.createElement("button");e.textContent="",(0,_.setIcon)(e,"slash"),e.title="Line",e.classList.add("drawing-btn","line-btn"),e.onclick=()=>{this.currentTool="line",this.currentGeometricTool="line",this.resetToolbarHighlights(),e.classList.add("active-tool"),r.value=this.lineWidth.toString(),n.value=this.lineWidth.toString(),r.style.display="",n.style.display=""},this.toolbar.appendChild(e);let i=document.createElement("button");i.textContent="",(0,_.setIcon)(i,"square"),i.title="Rectangle",i.classList.add("drawing-btn","rect-btn"),i.onclick=()=>{this.currentTool="rectangle",this.currentGeometricTool="rectangle",this.resetToolbarHighlights(),i.classList.add("active-tool"),r.value=this.lineWidth.toString(),n.value=this.lineWidth.toString(),r.style.display="",n.style.display=""},this.toolbar.appendChild(i);let t=document.createElement("button");t.textContent="",(0,_.setIcon)(t,"circle"),t.title="Circle",t.classList.add("drawing-btn","circle-btn"),t.onclick=()=>{this.currentTool="circle",this.currentGeometricTool="circle",this.resetToolbarHighlights(),t.classList.add("active-tool"),r.value=this.lineWidth.toString(),n.value=this.lineWidth.toString(),r.style.display="",n.style.display=""},this.toolbar.appendChild(t);let a=document.createElement("button");a.textContent="",(0,_.setIcon)(a,"eraser"),a.title="Eraser",a.classList.add("drawing-btn","eraser-btn"),a.onclick=()=>{this.currentTool="eraser",this.resetToolbarHighlights(),a.classList.add("active-tool"),r.value=this.lineWidth.toString(),n.value=this.lineWidth.toString(),r.style.display="",n.style.display=""},this.toolbar.appendChild(a);let s=document.createElement("button");s.textContent="",(0,_.setIcon)(s,"activity"),s.title="Laser (temporary)",s.classList.add("drawing-btn","laser-btn"),s.onclick=()=>{this.currentTool="laser",this.resetToolbarHighlights(),s.classList.add("active-tool"),r.style.display="none",n.style.display="none"},this.toolbar.appendChild(s);let d=document.createElement("input");d.type="color",d.value=this.color,d.classList.add("drawing-color-input"),d.onchange=()=>{this.color=d.value},this.toolbar.appendChild(d);let n=document.createElement("input");n.type="number",n.min="1",n.max="30",n.value=this.lineWidth.toString(),n.classList.add("drawing-linewidth-input"),n.onchange=()=>{this.lineWidth=Number(n.value),r.value=n.value},this.toolbar.appendChild(n);let r=document.createElement("input");r.type="range",r.min="1",r.max="30",r.value=this.lineWidth.toString(),r.className="drawing-size-slider",r.oninput=u=>{let m=u.target.value;this.lineWidth=Number(m),n.value=m},this.toolbar.appendChild(r)}enableDrawing(){this.canvas.addEventListener("pointerdown",this.handlePointerDown),this.canvas.addEventListener("pointermove",this.handlePointerMove),this.canvas.addEventListener("pointerup",this.handlePointerUp),this.canvas.addEventListener("pointerout",this.handlePointerUp)}disableDrawing(){this.canvas.removeEventListener("pointerdown",this.handlePointerDown),this.canvas.removeEventListener("pointermove",this.handlePointerMove),this.canvas.removeEventListener("pointerup",this.handlePointerUp),this.canvas.removeEventListener("pointerout",this.handlePointerUp)}clear(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)}getAnnotation(){return this.canvas.toDataURL("image/png")}destroy(){window.removeEventListener("resize",this.resizeCanvasBound),this.disableDrawing(),this.toolbar.parentNode&&this.toolbar.parentNode.removeChild(this.toolbar),this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}};var Q=class{constructor(o,e,i={}){var s,d,n;this.mediaElement=o,this.container=e,this.options={height:(s=i.height)!=null?s:"100px",gradientType:(d=i.gradientType)!=null?d:"blue-red",customColors:i.customColors};let t=(n=this.options.height)!=null?n:"100px";this.canvas=document.createElement("canvas"),this.canvas.classList.add("visualizer-canvas");let a=t.replace("px","");this.canvas.classList.add(`visualizer-height-${a}`),this.canvas.width=e.clientWidth,this.canvas.height=parseInt(t,10),this.canvasCtx=this.canvas.getContext("2d"),e.appendChild(this.canvas),this.audioContext=new(window.AudioContext||window.webkitAudioContext),this.source=this.audioContext.createMediaElementSource(this.mediaElement),this.analyser=this.audioContext.createAnalyser(),this.analyser.fftSize=512,this.analyser.smoothingTimeConstant=.05,this.analyser.minDecibels=-100,this.analyser.maxDecibels=-30,this.source.connect(this.analyser),this.analyser.connect(this.audioContext.destination),this.animationFrameId=0,this.draw()}draw(){let o=this.analyser.frequencyBinCount,e=new Uint8Array(o),i=Math.floor(o/2),t=2,a=this.canvas.width,s=this.canvas.height,d=a/2,n=s/2,u=d/i*.6,m=()=>{this.analyser.getByteFrequencyData(e),this.canvasCtx.clearRect(0,0,a,s);for(let c=0;c0){l=this.canvasCtx.createLinearGradient(0,n,0,n-S);let L=this.options.customColors.length;for(let D=0;D{o=!0,s.preventDefault()},i=s=>{if(!o||!this.element)return;let n=this.element.querySelector(".compare-image-container").getBoundingClientRect(),r;this.options.orientation==="vertical"?r=(("touches"in s?s.touches[0].pageX:s.pageX)-n.left)/n.width*100:r=(("touches"in s?s.touches[0].pageY:s.pageY)-n.top)/n.height*100,this.updateSliderPosition(r)},t=()=>{o=!1};this.slider.addEventListener("mousedown",e),document.addEventListener("mousemove",i),document.addEventListener("mouseup",t),this.slider.addEventListener("touchstart",e),document.addEventListener("touchmove",i),document.addEventListener("touchend",t);let a=()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",t),document.removeEventListener("touchmove",i),document.removeEventListener("touchend",t)};this.element._compareCleanup=a}destroy(){this.element&&(this.element._compareCleanup&&this.element._compareCleanup(),this.element.parentNode&&this.element.parentNode.removeChild(this.element),this.element=null,this.slider=null)}};var vt={enableDrawingAnnotation:!1,enableVisualizer:!1,visualizerColor:"#00ff00",visualizerHeight:"50px",compressionQuality:1,enableCompression:!0,enableCompareMode:!0},ot=class extends y.Plugin{constructor(){super(...arguments);this.filePathCache=new Map;this.markdownCache=new Map;this.drawingData={};this.activeSliderContent=null;this.keydownHandlerInitialized=!1}async onload(){console.log("Loading Media Slider Plugin..."),await this.loadSettings(),this.addSettingTab(new nt(this.app,this)),this.notesManager=new J(this),await this.notesManager.load(),await this.loadDrawingData(),this.registerMarkdownCodeBlockProcessor("media-slider",async(e,i,t)=>{await this.createMediaSlider(e,i,t)})}async loadSettings(){this.settings=Object.assign({},vt,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}refreshSliders(){this.app.workspace.getLeavesOfType("markdown").forEach(e=>{e.view instanceof y.MarkdownView&&typeof e.view.load=="function"&&e.view.load()})}async loadDrawingData(){let e=await this.loadData();this.drawingData=(e==null?void 0:e.drawings)||{}}async saveDrawingData(){let e=await this.loadData()||{};e.drawings=this.drawingData,await this.saveData(e)}async cleanupDrawingData(e,i){for(let t of Object.keys(this.drawingData))if(t.startsWith(`${e}-`)){let a=t.substring(e.length+1);i.includes(a)||delete this.drawingData[t]}await this.saveDrawingData()}getCachedResourcePath(e){if(this.filePathCache.has(e))return this.filePathCache.get(e);let i=this.app.vault.adapter.getResourcePath(e);return this.filePathCache.set(e,i),i}getMediaSource(e){let i=e.match(/!\[(.*?)\]\((.*?)\)/);i&&(e=i[2].trim());let t=e.match(/!?\[\[(.*?)(?:\|(.*?))?\]\]/);if(t&&(e=t[1].trim()),e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1).trim()),e.startsWith("http://")||e.startsWith("https://"))try{return decodeURIComponent(e)}catch(s){return e}if(!this.app.vault.getAbstractFileByPath(e)){let s=this.app.vault.getFiles().filter(d=>d.name.toLowerCase()===e.toLowerCase());s.length>0?e=s[0].path:console.error("File not found in vault:",e)}return this.getCachedResourcePath(e)}isYouTubeURL(e){return e.includes("youtube.com/watch")||e.includes("youtu.be/")}getYouTubeEmbedURL(e){let i="",t=/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&]+)/,a=e.match(t);return a&&a[1]&&(i=a[1]),`https://www.youtube.com/embed/${i}`}getYouTubeThumbnail(e){let i="",t=/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&]+)/,a=e.match(t);return a&&a[1]&&(i=a[1]),`https://img.youtube.com/vi/${i}/hqdefault.jpg`}async getMarkdownContent(e){if(this.markdownCache.has(e))return this.markdownCache.get(e);let i=this.app.vault.getAbstractFileByPath(e);if(i instanceof y.TFile){let t=await this.app.vault.read(i);return this.markdownCache.set(e,t),t}else return console.warn("Abstract file is not a TFile:",i),""}throttle(e,i){let t=0;return(...a)=>{let s=Date.now();if(!(s-tl.trim()==="---"),c=0;if(m!==-1){let l=u.slice(m+1).findIndex(C=>C.trim()==="---");l!==-1&&(c=m+l+2)}let T=c+t+1;u.splice(T,0,`![[${i}]]`),r[0]="```media-slider";for(let l=0;ld.replace(/```$/,`![[${i}]] \`\`\``));if(s===a){console.log("No media-slider code block replaced. Possibly none found or multiple blocks exist.");return}await this.app.vault.modify(t,s)}async getFolderMedia(e,i){let t=this.app.vault.getAbstractFileByPath(e);if(!t||!("children"in t))return console.error("Folder not found or not a folder:",e),[];let a=[],s=["png","jpg","jpeg","gif","svg","webp","bmp","avif","mp4","webm","mkv","mov","ogv","mp3","ogg","wav","flac","m4a","pdf","md"];i.fileTypes&&Array.isArray(i.fileTypes)&&(s=i.fileTypes);let d=i.recursive!==!1,n=r=>{r.children?(r===t||d)&&r.children.forEach(n):"extension"in r&&s.includes(r.extension.toLowerCase())&&a.push(r.path)};return n(t),a.sort()}parseMediaFiles(e){let i=[];for(let a of e){let s="",d=null,n=null,r=a.match(/!?\[(.*?)\]\((.*?)(?:\s*\|\s*(.*?))?\)/);if(r){s=r[2].trim(),d=r[3]?r[3].trim():r[1]?r[1].trim():null,i.push({path:s,caption:d,compareGroup:n});continue}let u=a.match(/!?\[\[(.*?)(?:\|(.*?))?\s*\|\|\s*([\w\d-]+)\s*\]\]/);if(u){s=u[1].trim(),d=u[2]?u[2].trim():null,n=u[3].trim(),i.push({path:s,caption:d,compareGroup:n});continue}let m=a.match(/!?\[\[(.*?)(?:\|(.*?))?\]\]/);if(m){s=m[1].trim(),d=m[2]?m[2].trim():null,i.push({path:s,caption:d,compareGroup:null});continue}a.trim()&&(s=a.trim(),i.push({path:s,caption:null,compareGroup:null}))}let t=new Map;for(let a of i)if(a.compareGroup){let s=a.compareGroup.split("-")[0];t.has(s)||t.set(s,{files:[],processed:!1});let d=t.get(s);d&&d.files.push({path:a.path,caption:a.caption})}return{fileEntries:i,compareGroups:t}}async createMediaSlider(e,i,t){let a=e.match(/---\n([\s\S]+?)\n---/),d=e.replace(/---\n[\s\S]+?\n---/,"").trim().split(` `).map(l=>l.trim()).filter(Boolean),n={sliderId:"",carouselShowThumbnails:!0,thumbnailPosition:"bottom",captionMode:"overlay",autoplay:!1,slideshowSpeed:0,width:"100%",height:"380px",transitionEffect:"fade",transitionDuration:.1,enhancedView:!0,interactiveNotes:!1,fileTypes:null,recursive:!1,compression:null,compareMode:{enabled:this.settings.enableCompareMode,orientation:"vertical",initialPosition:50,showLabels:!1,label1:"",label2:"",swapImages:!1}};if(a)try{let l=(0,y.parseYaml)(a[1]);if(n=Object.assign({},n,l),l.compareMode!==void 0)if(typeof l.compareMode=="boolean"){let C=Object.assign({},n.compareMode,{enabled:l.compareMode}),x=["orientation","initialPosition","showLabels","label1","label2","swapImages"];for(let L of x)l[L]!==void 0&&(C[L]=l[L]);n.compareMode=C}else typeof l.compareMode=="object"&&(n.compareMode=Object.assign({},n.compareMode,l.compareMode))}catch(l){console.error("Failed to parse media-slider metadata:",l)}let r=n.sliderId;r||(r=`slider-${ot.sliderCounter++}`);let u=[];for(let l of d){let C=l.match(/!?\[\[(.*?\/)\]\]/);if(C){let x=C[1].endsWith("/")?C[1].slice(0,-1):C[1],L=await this.getFolderMedia(x,n);u=u.concat(L.map(D=>`![[${D}]]`))}else u.push(l)}let{fileEntries:m,compareGroups:c}=this.parseMediaFiles(u),T=[],g=new Set;for(let l of m)if(l.compareGroup){let C=l.compareGroup.split("-")[0];if(!g.has(C))if(g.add(C),n.compareMode&&n.compareMode.enabled)T.push(`__COMPARE_GROUP_${C}`);else{let x=c.get(C);if(x&&x.files.length>=2)for(let L of x.files)T.push(L.caption?`![[${L.path}|${L.caption}]]`:`![[${L.path}]]`)}}else T.push(l.caption?`![[${l.path}|${l.caption}]]`:`![[${l.path}]]`);let S=T.map(l=>{var D;if(l.startsWith("__COMPARE_GROUP_"))return l;let C=l.match(/!?\[\[(.*?)(?:\|(.*?))?\]\]/);if(!C)return"";let x=C[1].trim(),L=((D=C[2])!=null?D:"").trim();return L?`${x}|${L}`:x}).filter(Boolean);if(S.length===0){i.createEl("p",{text:"No valid media files found."});return}await this.notesManager.cleanupNotesForSlider(r,S).catch(console.error),await this.cleanupDrawingData(r,S).catch(console.error),this.renderSlider(i,S,n,r,t,c)}renderSlider(e,i,t,a,s,d=new Map){e.querySelectorAll(".fullscreen-btn, .copy-btn, .notes-toggle-btn, .drawing-toggle-btn").forEach(p=>p.remove()),e.empty();let n,r=e.createDiv("media-slider-wrapper");t.carouselShowThumbnails&&(t.thumbnailPosition==="left"||t.thumbnailPosition==="right")?r.classList.add("flex-row"):r.classList.add("flex-column","center");let u=r.createDiv("slider-content");u.style.setProperty("--slider-width",t.width),u.style.setProperty("--slider-height",t.height),u.style.setProperty("--transition-duration",t.transitionDuration+"ms");let m=u.createDiv("slider-container"),c=m.createDiv("media-wrapper"),T=u.createDiv("slider-caption-container"),g=null,S=[];t.carouselShowThumbnails&&(g=document.createElement("div"),g.classList.add("thumbnail-container"),t.thumbnailPosition==="left"||t.thumbnailPosition==="right"?g.classList.add("vertical"):g.classList.add("horizontal"),t.thumbnailPosition==="top"||t.thumbnailPosition==="left"?r.insertBefore(g,u):r.appendChild(g));let l=0,C="next",x={};if(t.enhancedView){let p=r.createEl("button",{cls:"fullscreen-btn"});(0,y.setIcon)(p,"maximize"),p.onclick=()=>{document.fullscreenElement?(document.exitFullscreen(),m.classList.remove("fullscreen-slider")):(r.requestFullscreen().catch(E=>console.error("Error enabling fullscreen:",E)),m.classList.add("fullscreen-slider"))};let f=r.createEl("button",{cls:"copy-btn"});(0,y.setIcon)(f,"copy"),f.onclick=async()=>{let E=i[l];if(E.startsWith("__COMPARE_GROUP_"))return;let[I]=E.split("|").map(M=>M.trim()),P=`![[${I}]]`;try{await navigator.clipboard.writeText(P),console.log("Copied markdown link to clipboard:",P)}catch(M){console.error("Failed to copy markdown link:",M)}}}let L=null,D=null;if(t.interactiveNotes){let p=r.createEl("button",{cls:"notes-toggle-btn"});(0,y.setIcon)(p,"sticky-note"),L=r.createDiv("notes-container"),D=document.createElement("textarea"),D.classList.add("notes-textarea"),D.placeholder="Add your notes here...",L.appendChild(D);let f=document.createElement("button");f.classList.add("notes-save-btn"),(0,y.setIcon)(f,"save"),f.onclick=async()=>{let E=`${a}-${i[l]}`;D&&await this.notesManager.setNote(E,D.value),L&&L.classList.remove("visible")},L.appendChild(f),p.onclick=()=>{if(L&&(L.classList.toggle("visible"),L.classList.contains("visible")&&D)){let E=`${a}-${i[l]}`;D.value=this.notesManager.getNote(E)}}}let h=null,v=null;if(this.settings.enableDrawingAnnotation){let p=r.createEl("button",{cls:"drawing-toggle-btn"});(0,y.setIcon)(p,"edit-3"),n=f=>{let E=m.querySelector(".drawing-overlay");E&&E.remove();let I=this.drawingData[f];I?(m.createEl("img",{attr:{src:I}}).classList.add("drawing-overlay"),v||(v=r.createEl("button",{cls:"clear-drawing-btn"}),(0,y.setIcon)(v,"trash"),v.onclick=async()=>{delete this.drawingData[f],await this.saveDrawingData();let M=m.querySelector(".drawing-overlay");M&&M.remove(),v.remove(),v=null})):v&&(v.remove(),v=null)},p.onclick=async()=>{let f=`${a}-${i[l]}`;if(h){let E=h.getAnnotation();this.drawingData[f]=E,await this.saveDrawingData(),h.destroy(),h=null,(0,y.setIcon)(p,"edit-3"),n==null||n(f)}else{if(this.drawingData[f]){delete this.drawingData[f],await this.saveDrawingData();let E=m.querySelector(".drawing-overlay");E&&E.remove(),v&&(v.remove(),v=null)}h=new tt(m),(0,y.setIcon)(p,"save")}}}let H=async()=>{var f,E,I,P,M,j,V,U;switch(Object.values(x).forEach(w=>{w.destroy()}),Object.keys(x).forEach(w=>{delete x[w]}),c.classList.remove("transition-fade-in","transition-slide-next-in","transition-slide-prev-in","transition-zoom-in","transition-slide-up-in","transition-slide-down-in","transition-flip-in","transition-flip-vertical-in","transition-rotate-in","transition-blur-in","transition-squeeze-in","transition-fade-out","transition-slide-next-out","transition-slide-prev-out","transition-zoom-out","transition-slide-up-out","transition-slide-down-out","transition-flip-out","transition-flip-vertical-out","transition-rotate-out","transition-blur-out","transition-squeeze-out"),t.transitionEffect){case"fade":c.classList.add("transition-fade-out");break;case"slide":c.classList.add(C==="next"?"transition-slide-next-out":"transition-slide-prev-out");break;case"zoom":c.classList.add("transition-zoom-out");break;case"slide-up":c.classList.add("transition-slide-up-out");break;case"slide-down":c.classList.add("transition-slide-down-out");break;case"flip":c.classList.add("transition-flip-out");break;case"flip-vertical":c.classList.add("transition-flip-vertical-out");break;case"rotate":c.classList.add("transition-rotate-out");break;case"blur":c.classList.add("transition-blur-out");break;case"squeeze":c.classList.add("transition-squeeze-out");break;default:c.classList.add("transition-fade-out")}if(await new Promise(w=>setTimeout(w,t.transitionDuration)),c.empty(),t.captionMode==="below"&&T.empty(),S.length>0){S.forEach((z,k)=>{z.classList.toggle("active-thumbnail",k===l)});let w=S[l];if(w&&g){let z=g.getBoundingClientRect(),k=w.getBoundingClientRect();if(t.thumbnailPosition==="left"||t.thumbnailPosition==="right"){let A=w.offsetTop-z.height/2+k.height/2;g.scrollTo({top:A,behavior:"smooth"})}else{let A=w.offsetLeft-z.width/2+k.width/2;g.scrollTo({left:A,behavior:"smooth"})}}}let p=i[l];if(console.log("Current entry:",p),p&&p.startsWith("__COMPARE_GROUP_")){let w=p.slice(16);console.log("Rendering compare group:",w),console.log("Available groups:",Array.from(d.keys()));let z=d.get(w);if(console.log("Group data:",z),z&&z.files.length>=2){let k=z.files[0],A=z.files[1];console.log("Compare files:",k.path,A.path);try{let Y=this.getMediaSource(k.path),b=this.getMediaSource(A.path);if(console.log("Image paths:",Y,b),(f=t.compareMode)!=null&&f.enabled){let R={orientation:((E=t.compareMode)==null?void 0:E.orientation)||"vertical",initialPosition:((I=t.compareMode)==null?void 0:I.initialPosition)||50,showLabels:((P=t.compareMode)==null?void 0:P.showLabels)||!1,label1:((M=t.compareMode)==null?void 0:M.label1)||"Before",label2:((j=t.compareMode)==null?void 0:j.label2)||"After",swapImages:((V=t.compareMode)==null?void 0:V.swapImages)||!1,enabled:!0},G=new et(c,Y,b,k.caption,A.caption,R);G.render(),x[w]=G}else{let R=c.createEl("img",{attr:{src:Y}});R.classList.add("slider-media"),this.addZoomPanSupport(R,m),k.caption&&(t.captionMode==="overlay"?c.createEl("div",{text:k.caption}).classList.add("slider-caption-overlay"):T.createEl("div",{text:k.caption}).classList.add("slider-caption"));let G=c.createEl("img",{attr:{src:b}});G.classList.add("slider-media"),this.addZoomPanSupport(G,m),A.caption&&(t.captionMode==="overlay"?c.createEl("div",{text:A.caption}).classList.add("slider-caption-overlay"):T.createEl("div",{text:A.caption}).classList.add("slider-caption"))}}catch(Y){console.error("Error rendering comparison:",Y),c.createEl("div",{text:`Error rendering comparison: ${Y.message||"Unknown error"}`})}}else{let k=z?`Not enough images in group ${w} (found ${((U=z.files)==null?void 0:U.length)||0}, need at least 2)`:`Group ${w} not found`;console.error(k),c.createEl("div",{text:k})}}else{let[w,z]=p.split("|").map(b=>b.trim());if(!w.includes(".")){let b=this.app.metadataCache.getFirstLinkpathDest(w,"");b&&b.extension==="md"&&(w=b.path)}let k=this.getMediaSource(w),A=this.settings.enableCompression;t.compression!==null&&t.compression!==void 0&&(t.compression==="off"||t.compression===!1?A=!1:A=!0);let Y=typeof t.compression=="number"?t.compression:this.settings.compressionQuality;if(/\.(png|jpg|jpeg|gif|svg|webp|bmp|avif)$/i.test(w))try{if(/\.gif$/i.test(w)){let b=c.createEl("img",{attr:{src:k}});b.classList.add("slider-media","gif-media"),this.addZoomPanSupport(b,m)}else if(/\.svg$/i.test(w)){let b=c.createEl("img",{attr:{src:k}});b.classList.add("slider-media"),this.addZoomPanSupport(b,m)}else if(A){let b=await ct(k,1600,1200,Y),R=c.createEl("img",{attr:{src:b}});R.classList.add("slider-media"),this.addZoomPanSupport(R,m)}else{let b=c.createEl("img",{attr:{src:k}});b.classList.add("slider-media"),this.addZoomPanSupport(b,m)}}catch(b){console.error("Error processing image:",b);let R=c.createEl("img",{attr:{src:k}});R.classList.add("slider-media"),this.addZoomPanSupport(R,m)}else if(/\.(mp4|webm|mkv|mov|ogv)$/i.test(w)){let b=c.createEl("video",{attr:{src:k,controls:"true"}});t.autoplay&&b.setAttribute("autoplay","true"),b.classList.add("slider-media"),this.settings.enableVisualizer&&new Q(b,m,{color:this.settings.visualizerColor,height:this.settings.visualizerHeight})}else if(/\.(mp3|ogg|wav|flac|webm|3gp||m4a)$/i.test(w)){let b=c.createEl("audio",{attr:{src:k,controls:"true"}});b.classList.add("slider-media","audio-media"),this.settings.enableVisualizer&&new Q(b,m,{color:this.settings.visualizerColor,height:this.settings.visualizerHeight})}else if(/\.(pdf)$/i.test(w))c.createEl("div",{cls:"pdf-container"}).createEl("iframe",{attr:{src:k,width:"100%",height:"100%",frameborder:"0",allowfullscreen:"true"}}).classList.add("slider-media","pdf-media");else if(/\.(md)$/i.test(w)){let b=this.app.vault.getAbstractFileByPath(w);if(b&&b instanceof y.TFile){let R=await this.getMarkdownContent(w);c.empty(),c.style.display="block",await y.MarkdownRenderer.render(this.app,R,c,b.path,this)}}else if(this.isYouTubeURL(w)){let b=this.getYouTubeEmbedURL(w);c.createEl("iframe",{attr:{src:b,frameborder:"0",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowfullscreen:"true",width:"100%",height:"100%"}}).classList.add("slider-media")}else c.createEl("a",{text:"Open File",attr:{href:k,target:"_blank"}}).classList.add("slider-media");z&&(t.captionMode==="overlay"?c.createEl("div",{text:z}).classList.add("slider-caption-overlay"):T.createEl("div",{text:z}).classList.add("slider-caption"))}switch(c.offsetWidth,c.classList.remove("transition-fade-out","transition-slide-next-out","transition-slide-prev-out","transition-zoom-out","transition-slide-up-out","transition-slide-down-out","transition-flip-out","transition-flip-vertical-out","transition-rotate-out","transition-blur-out","transition-squeeze-out"),t.transitionEffect){case"fade":c.classList.add("transition-fade-in");break;case"slide":c.classList.add(C==="next"?"transition-slide-next-in":"transition-slide-prev-in");break;case"zoom":c.classList.add("transition-zoom-in");break;case"slide-up":c.classList.add("transition-slide-up-in");break;case"slide-down":c.classList.add("transition-slide-down-in");break;case"flip":c.classList.add("transition-flip-in");break;case"flip-vertical":c.classList.add("transition-flip-vertical-in");break;case"rotate":c.classList.add("transition-rotate-in");break;case"blur":c.classList.add("transition-blur-in");break;case"squeeze":c.classList.add("transition-squeeze-in");break;default:c.classList.add("transition-fade-in")}if(t.interactiveNotes&&D){let w=`${a}-${i[l]}`;D.value=this.notesManager.getNote(w)}if(this.settings.enableDrawingAnnotation){let w=`${a}-${i[l]}`;n==null||n(w)}},F=this.throttle(H,100),$=()=>{C="prev",l=(l-1+i.length)%i.length,F()},W=()=>{C="next",l=(l+1)%i.length,F()},X=u.createEl("button",{cls:"slider-btn prev"}),q=u.createEl("button",{cls:"slider-btn next"});(0,y.setIcon)(X,"chevron-left"),(0,y.setIcon)(q,"chevron-right"),X.onclick=$,q.onclick=W,X.addEventListener("touchstart",p=>{p.preventDefault(),$()},{passive:!1}),q.addEventListener("touchstart",p=>{p.preventDefault(),W()},{passive:!1}),u.tabIndex=0,u.addEventListener("focus",()=>{this.activeSliderContent=u}),u.addEventListener("wheel",p=>{let f=p.target;f&&(f.matches("input, textarea")||Math.abs(p.deltaX)>Math.abs(p.deltaY)&&(p.deltaX>30?(W(),p.preventDefault()):p.deltaX<-30&&($(),p.preventDefault())))});let O=0;u.addEventListener("touchstart",p=>{O=p.touches[0].clientX}),u.addEventListener("touchend",p=>{let f=p.changedTouches[0].clientX,E=O-f;Math.abs(E)>50&&(E>0?W():$())}),g&&(g.empty(),i.forEach((p,f)=>{var E;if(p.startsWith("__COMPARE_GROUP_")){let I=p.replace("__COMPARE_GROUP_",""),P=d.get(I);if(P&&P.files.length>0){let M=g.createEl("div",{cls:"thumbnail compare-thumbnail"});if(M.classList.add(t.compareMode.orientation==="horizontal"?"compare-horizontal":"compare-vertical"),P.files.length>=2){let j=P.files[0],V=P.files[1];try{let U=this.getMediaSource(j.path),w=this.getMediaSource(V.path),z=/\.(png|jpg|jpeg|gif|svg|webp|bmp|avif)$/i.test(j.path),k=/\.(png|jpg|jpeg|gif|svg|webp|bmp|avif)$/i.test(V.path);if(z&&k){let A=M.createEl("div",{cls:"compare-thumb-container"}),Y=A.createEl("img",{attr:{src:U},cls:"compare-thumb-left"}),b=A.createEl("img",{attr:{src:w},cls:"compare-thumb-right"}),R=A.createEl("div",{cls:"compare-thumb-divider"}),G=M.createEl("div",{text:"\u27F7",cls:"compare-thumb-icon"})}else M.textContent="COMP",M.classList.add("thumbnail-placeholder")}catch(U){console.error("Error creating compare thumbnail:",U),M.textContent="ERR",M.classList.add("thumbnail-placeholder")}}else M.textContent="CMP",M.classList.add("thumbnail-placeholder");(t.thumbnailPosition==="left"||t.thumbnailPosition==="right")&&M.classList.add("vertical-thumb"),M.onclick=()=>{l=f,F()},S.push(M)}}else{let[I]=p.split("|").map(M=>M.trim()),P;if(this.isYouTubeURL(I)){let M=this.getYouTubeThumbnail(I);P=g.createEl("img",{attr:{src:M},cls:"thumbnail"})}else if(/\.(png|jpg|jpeg|gif|svg|webp|bmp|avif)$/i.test(I))P=g.createEl("img",{attr:{src:this.getMediaSource(I)},cls:"thumbnail"});else{let M=((E=I.split(".").pop())==null?void 0:E.toUpperCase())||"FILE";P=g.createEl("div",{text:M}),P.classList.add("thumbnail-placeholder")}(t.thumbnailPosition==="left"||t.thumbnailPosition==="right")&&P.classList.add("vertical-thumb"),P.tabIndex=0,P.onclick=()=>{l=f,F()},S.push(P)}}),g.tabIndex=0);let Z=null,N=!0,rt=()=>{t.slideshowSpeed>0&&N&&(Z=setInterval(W,t.slideshowSpeed*1e3))},it=()=>{Z&&(clearInterval(Z),Z=null)},lt=()=>{let p=this.app.workspace.activeLeaf,f=!!(p&&p.view instanceof y.MarkdownView&&p.view.file&&p.view.file.path===s.sourcePath),E=N;N=f,E&&!N?it():!E&&N&&t.slideshowSpeed>0&&rt()};t.slideshowSpeed>0&&(lt(),N&&rt()),this.registerEvent(this.app.workspace.on("active-leaf-change",lt)),this.registerEvent(this.app.workspace.on("layout-change",()=>{!this.app.workspace.getLeavesOfType("markdown").some(f=>f.view instanceof y.MarkdownView?f.view.file&&f.view.file.path===s.sourcePath:!1)&&N&&(N=!1,it())})),this.register(()=>{it(),Object.values(x).forEach(p=>{p.destroy()})}),F(),r.tabIndex=0,e.appendChild(r),this.keydownHandlerInitialized||(document.addEventListener("keydown",p=>{let f=p.target;if(this.activeSliderContent&&f&&f instanceof HTMLElement){let E=f.tagName.toLowerCase();if(E!=="input"&&E!=="textarea"){if(p.key==="ArrowLeft"){let I=this.activeSliderContent.closest(".media-slider-wrapper");if(I){let P=I.querySelector(".slider-btn.prev");P&&(P.click(),p.preventDefault())}}else if(p.key==="ArrowRight"){let I=this.activeSliderContent.closest(".media-slider-wrapper");if(I){let P=I.querySelector(".slider-btn.next");P&&(P.click(),p.preventDefault())}}}}}),document.addEventListener("click",p=>{let f=p.target;if(!f)return;let E=f.closest(".slider-content");E&&!f.matches("input, textarea")&&(this.activeSliderContent=E)}),this.keydownHandlerInitialized=!0)}addZoomPanSupport(e,i){let t=1,a=0,s=0,d=!1,n=0,r=0,u=1,m=1,c=5,T=i.querySelector(".zoom-controls");T&&T.remove();let g=i.createEl("div",{cls:"zoom-controls"}),S=g.createEl("button",{cls:"zoom-btn"});(0,y.setIcon)(S,"zoom-in");let l=g.createEl("button",{cls:"zoom-btn"});(0,y.setIcon)(l,"zoom-out");let C=g.createEl("button",{cls:"zoom-btn"});(0,y.setIcon)(C,"refresh-cw"),e.classList.add("can-zoom"),e.addEventListener("dblclick",h=>{if(h.preventDefault(),h.stopPropagation(),t>1)D();else{let v=e.getBoundingClientRect(),H=h.clientX-v.left,F=h.clientY-v.top,$=H/v.width,W=F/v.height;t=1.25,a=-($*v.width*(t-1)),s=-(W*v.height*(t-1)),x()}});let x=()=>{e.style.transform=`translate(${a}px, ${s}px) scale(${t})`,e.classList.add("img-transformed"),d?e.classList.add("dragging"):e.classList.remove("dragging"),g.style.opacity=t>1?"1":"0.5",l.disabled=t<=m,C.disabled=t<=m&&a===0&&s===0,t>1?e.classList.add("zoomed"):e.classList.remove("zoomed")},L=(h,v,H)=>{let F=e.getBoundingClientRect(),$=F.left+F.width/2,W=F.top+F.height/2,X=v-$,q=H-W,O=t;return t=Math.max(m,Math.min(c,t+h)),t!==O?(h>0?(a-=X*(t/O-1),s-=q*(t/O-1)):(a=a*(t/O),s=s*(t/O)),x(),!0):!1},D=()=>{t=1,a=0,s=0,x()};S.addEventListener("click",h=>{h.stopPropagation();let v=i.getBoundingClientRect();L(.5,v.left+v.width/2,v.top+v.height/2)}),l.addEventListener("click",h=>{h.stopPropagation();let v=i.getBoundingClientRect();L(-.5,v.left+v.width/2,v.top+v.height/2)}),C.addEventListener("click",h=>{h.stopPropagation(),D()}),i.addEventListener("wheel",h=>{if(h.ctrlKey||h.metaKey){h.preventDefault(),h.stopPropagation();let v=h.deltaY<0?.2:-.2,H=i.getBoundingClientRect();L(v,h.clientX-H.left,h.clientY-H.top)}},{passive:!1}),e.addEventListener("mousedown",h=>{t>1&&(d=!0,n=h.clientX-a,r=h.clientY-s,h.preventDefault(),h.stopPropagation())}),document.addEventListener("mousemove",h=>{d&&(a=h.clientX-n,s=h.clientY-r,x(),h.preventDefault(),h.stopPropagation())}),document.addEventListener("mouseup",h=>{d&&(d=!1,x(),h.preventDefault(),h.stopPropagation())}),e.addEventListener("touchstart",h=>{if(h.touches.length===1&&t>1)d=!0,n=h.touches[0].clientX-a,r=h.touches[0].clientY-s,h.preventDefault();else if(h.touches.length===2){h.preventDefault();let v=h.touches[0],H=h.touches[1];u=t,n=(v.clientX+H.clientX)/2,r=(v.clientY+H.clientY)/2}},{passive:!1}),e.addEventListener("touchmove",h=>{if(h.touches.length===1&&d)a=h.touches[0].clientX-n,s=h.touches[0].clientY-r,x(),h.preventDefault();else if(h.touches.length===2){h.preventDefault();let v=h.touches[0],H=h.touches[1],F=Math.hypot(v.clientX-H.clientX,v.clientY-H.clientY),$=(v.clientX+H.clientX)/2,W=(v.clientY+H.clientY)/2,X=Math.max(m,Math.min(c,u*(F/150)));X!==t&&(t=X,x())}},{passive:!1}),e.addEventListener("touchend",()=>{d=!1,x()}),x()}},K=ot;K.sliderCounter=0;var nt=class extends y.PluginSettingTab{constructor(e,i){super(e,i);this.plugin=i}display(){let{containerEl:e}=this;e.empty(),new y.Setting(e).setName("Enable drawing annotation").setDesc("Toggle to enable drawing annotations on the slider. (default: off)").addToggle(i=>i.setValue(this.plugin.settings.enableDrawingAnnotation).onChange(async t=>{this.plugin.settings.enableDrawingAnnotation=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()})),new y.Setting(e).setName("Enable visualizer").setDesc("Toggle to enable wave-like visualization for audio/video playback.").addToggle(i=>i.setValue(this.plugin.settings.enableVisualizer).onChange(async t=>{this.plugin.settings.enableVisualizer=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()})),new y.Setting(e).setName("Visualizer color").setDesc("CSS color value for the visualizer wave.").addText(i=>i.setValue(this.plugin.settings.visualizerColor).onChange(async t=>{this.plugin.settings.visualizerColor=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()})),new y.Setting(e).setName("Visualizer height").setDesc("Height of the visualizer (e.g., '50px').").addText(i=>i.setValue(this.plugin.settings.visualizerHeight).onChange(async t=>{this.plugin.settings.visualizerHeight=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()})),new y.Setting(e).setName("Enable image compression").setDesc("Toggle to enable/disable image compression globally. Can be overridden per slider in YAML.").addToggle(i=>i.setValue(this.plugin.settings.enableCompression).onChange(async t=>{this.plugin.settings.enableCompression=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()})),new y.Setting(e).setName("Compression quality").setDesc("Set the image compression quality (0 to 1, e.g., 0.7 for 70% quality).").addText(i=>i.setPlaceholder("0.7").setValue(String(this.plugin.settings.compressionQuality)).onChange(async t=>{let a=parseFloat(t);!isNaN(a)&&a>=0&&a<=1?(this.plugin.settings.compressionQuality=a,await this.plugin.saveSettings(),this.plugin.refreshSliders()):console.warn("Please enter a number between 0 and 1.")})),new y.Setting(e).setName("Enable compare mode").setDesc("Toggle to enable image comparison feature globally. Can be configured per slider in YAML.").addToggle(i=>i.setValue(this.plugin.settings.enableCompareMode).onChange(async t=>{this.plugin.settings.enableCompareMode=t,await this.plugin.saveSettings(),this.plugin.refreshSliders()}))}}; /* nosourcemap */