| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- (function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.Karibsen={}))})(this,function(r){"use strict";var k=Object.defineProperty;var b=(r,o,d)=>o in r?k(r,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[o]=d;var l=(r,o,d)=>b(r,typeof o!="symbol"?o+"":o,d);/*
- * * @module fr.ts
- * * @project Karibsen Studio
- * * @description Module utilitaire pour Karibsen Studio
- * * @author Corentin / Karibsen
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */const o={validate:"Valider",back:"Retour",preview:"Prévisualiser",close:"Fermer",root:"Racine"};/*
- * * @module en.ts
- * * @project Karibsen Studio
- * * @description Language module for Karibsen Studio – English
- * * @author Corentin / Karibsen
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */const d={validate:"Validate",back:"Back",preview:"Preview",close:"Close",root:"Root"};/*
- * * @module es.ts
- * * @project Karibsen Studio
- * * @description Módulo de idioma para Karibsen Studio – Español
- * * @author Corentin / Karibsen
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */const f={preview:"Vista previa",validate:"Confirmar",back:"Atrás",close:"Cerrar",root:"Raíz"};/*
- * * @module de.ts
- * * @project Karibsen Studio
- * * @description Sprachmodul für Karibsen Studio – Deutsch
- * * @author Corentin / Karibsen
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */const v={preview:"Vorschau",validate:"Bestätigen",back:"Zurück",close:"Schließen",root:"Wurzel"};/*
- * * @module index.ts
- * * @project Karibsen Studio
- * * @description Point d'entrée pour tous les modules de langue
- * * @author Corentin / Karibsen
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */const p={fr:o,en:d,es:f,de:v};/*
- * * @module KServerBrowser
- * * @project Karibsen Studio
- * * @description
- * * @author Corentin NELHOMME, ShadowV,
- * * @copyright Copyright (c) 2023-2025 Karibsen Studio
- * * @license MIT
- * * @website https://karibsen.fr
- *
- */class y{constructor(e){l(this,"config");l(this,"container");l(this,"selectedFile",null);l(this,"icons");l(this,"fileType");l(this,"navigationHistory",[]);l(this,"initialData",[]);l(this,"lang");l(this,"validateButton");l(this,"previewButton");l(this,"acceptedExtensions",[]);l(this,"autoHideEmptyFolders");var n,a;if(this.config=e,this.container=typeof e.containerId=="string"?document.getElementById(e.containerId):e.containerId,!this.container)throw new Error("[KServerBrowser] - Container not found.");this.icons={folder:"📁",folderOpen:"📂",file:"📄",image:"🖼️",video:"🎥",pdf:"📑",...e.icons},this.fileType={images:!0,videos:!0,...e.fileTypes};const t=((n=e.lang)==null?void 0:n.toLowerCase())??"en",i=p[t]?t:"en";this.lang={...p[i],...e.langModule},this.acceptedExtensions=((a=e.acceptedTypeFiles)==null?void 0:a.map(s=>s.toLowerCase()))??[],this.autoHideEmptyFolders=e.autoHideEmptyFolders??!1,this.applyTheme(e.theme)}async open(){const e=await this.loadData();this.initialData=e,this.renderExplorer(e)}async loadData(){if(typeof this.config.dataSource=="string")try{let t=await(await fetch(this.config.dataSource)).json();return Array.isArray(t.data[0].folder)?t.data[0].folder:[t.data[0].folder]}catch{throw new Error("Unable to load data from URL.")}else{if(Array.isArray(this.config.dataSource))return this.config.dataSource;throw new Error("Your datasource is invalid.")}}renderExplorer(e){this.container.innerHTML="";const t=document.createElement("div");t.classList.add("kcontainer");const i=document.createElement("div");i.classList.add("kheader"),i.appendChild(this.buildBreadcrumbs());const n=document.createElement("ul");n.classList.add("kfile-tree"),this.buildTree(e,n);const a=document.createElement("div");if(a.classList.add("kfooter"),this.validateButton=document.createElement("button"),this.validateButton.textContent=this.lang.validate,this.validateButton.disabled=!0,this.validateButton.className="k-validate-btn",this.validateButton.onclick=()=>this.validateSelectedFile(),this.previewButton=document.createElement("button"),this.previewButton.textContent=this.lang.preview,this.previewButton.className="k-preview-btn",this.previewButton.style.display="none",this.previewButton.onclick=()=>this.previewSelectedImage(),this.navigationHistory.length>0){const s=document.createElement("button");s.textContent=this.lang.back,s.className="k-back-btn",s.onclick=()=>this.goBack(),t.appendChild(s)}else{const s=document.createElement("button");s.textContent=this.lang.close,s.className="k-back-btn",s.onclick=()=>this.destroy(),t.appendChild(s)}t.appendChild(i),t.appendChild(n),a.appendChild(this.previewButton),a.appendChild(this.validateButton),t.appendChild(a),this.container.appendChild(t),n.addEventListener("click",this.handleClick.bind(this))}buildTree(e,t){const i=document.createDocumentFragment();for(const n of e){if(!this.shouldDisplayItem(n)||n.type==="folder"&&this.autoHideEmptyFolders&&!this.folderHasDisplayableChildren(n))continue;const a=this.createListItem(n);i.appendChild(a),n.type==="folder"&&this.attachFolderChildren(n,a)}t.appendChild(i)}buildBreadcrumbs(){const e=document.createElement("div");e.className="k-breadcrumb";const t=[...this.navigationHistory];if(t.length===0)return e.textContent=this.lang.root,e;if(t.length>2){const n=document.createElement("span");n.textContent="...",e.appendChild(n)}const i=t.slice(-2);return i.forEach((n,a)=>{const s=document.createElement("span");if(s.textContent=n.name,s.className="k-breadcrumb-item",s.onclick=()=>{const c=this.navigationHistory.indexOf(n);this.navigationHistory=this.navigationHistory.slice(0,c+1),this.renderExplorer(n.children??[])},e.appendChild(s),a<i.length-1){const c=document.createElement("span");c.textContent=" / ",e.appendChild(c)}}),e}shouldDisplayItem(e){var n;if(e.type!=="file")return!0;const t=((n=e.name.split(".").pop())==null?void 0:n.toLowerCase())??"",i=this.acceptedExtensions.includes(t);return this.acceptedExtensions.length===0?!0:i}createListItem(e){const t=document.createElement("li");t.dataset.type=e.type,t.classList.add("k"+e.type),t._fileData=e,e.disabled&&(t.classList.add("k-disabled"),t.setAttribute("aria-disabled","true"));const i=document.createElement("span");if(e.type==="folder")i.textContent=this.icons.folder;else{const a=this.getIconForFile(e.name);if(a===null&&e.url){const s=document.createElement("img");s.src=e.previewURL,s.alt=e.name,s.className="kfile-thumb",i.appendChild(s)}else i.textContent=a??this.icons.file}t.prepend(i);const n=document.createElement("p");return n.className="k-name",n.textContent=e.type==="folder"?e.name+"/":e.name,t.appendChild(n),t}attachFolderChildren(e,t){if(t.classList.add("kfolder"),e.children&&e.children.length>0){const i=document.createElement("ul");this.buildTree(e.children,i),t.appendChild(i)}else t.dataset.lazy="true"}getIconForFile(e){var i;const t=(i=e.split(".").pop())==null?void 0:i.toLowerCase();return t?["jpg","jpeg","png","webp","gif"].includes(t)?null:["mp4","webm","mov"].includes(t)?this.icons.video:["pdf","txt"].includes(t)?this.icons.pdf:this.icons.file:this.icons.file}applyTheme(e){if(e)if(e.endsWith(".css")||e.startsWith("http")){const t=document.createElement("link");t.rel="stylesheet",t.href=e,document.head.appendChild(t)}else{const t=`k-theme-${e}`;this.container.classList.add(t)}}previewSelectedImage(){var e;(e=this.selectedFile)!=null&&e.url&&this.isImageFile(this.selectedFile.name)&&this.openImageModal(this.selectedFile.previewURL)}openImageModal(e){const t=this.container.querySelector(".kcontainer");if(!t)return;const i=t.querySelector(".k-modal");i&&i.remove();const n=document.createElement("div");n.className="k-modal";const a=document.createElement("div");a.className="k-modal-overlay",a.onclick=()=>n.remove();const s=document.createElement("div");s.className="k-modal-content";const c=document.createElement("img");c.src=e,c.alt="Preview",c.className="k-modal-img";const h=document.createElement("button");h.textContent=this.lang.close,h.className="k-modal-close",h.onclick=()=>m(),s.appendChild(h),s.appendChild(c),n.appendChild(a),n.appendChild(s),t.appendChild(n);const u=g=>{g.key==="Escape"&&m()};document.addEventListener("keydown",u);function m(){n.remove(),document.removeEventListener("keydown",u)}}handleClick(e){const i=e.target.closest("li");if(!i||!this.container.contains(i))return;const n=i._fileData;n&&(n.disabled||(n.type==="folder"&&(this.navigationHistory.push(n),this.renderExplorer(n.children??[])),n.type==="file"&&(this.validateButton.disabled=!1,this.container.querySelectorAll("li.kfile.selected").forEach(s=>s.classList.remove("selected")),i.classList.add("selected"),this.selectedFile=n,this.isImageFile(n.name)&&this.previewButton?this.previewButton.style.display="inline-block":this.previewButton&&(this.previewButton.style.display="none"),this.config.onFileClick&&this.config.onFileClick(n))))}goBack(){this.navigationHistory.pop();const e=this.navigationHistory[this.navigationHistory.length-1],t=(e==null?void 0:e.children)??this.initialData;this.renderExplorer(t)}getSelectedFiles(){return this.selectedFile}validateSelectedFile(){if(!this.selectedFile)return;const e=this.selectedFile;if(typeof this.config.onValidate=="function"){const t=this.navigationHistory.map(i=>i.name).join("/");this.config.onValidate({folder:t,file:e})}else console.warn("[KServerBrowser] No callback onValidate was define.")}destroy(){this.container.innerHTML="",this.selectedFile=null,this.validateButton=void 0,this.navigationHistory=[],this.initialData=[];const e=new CustomEvent("kserverbrowser:closed",{detail:{containerId:this.config.containerId}});document.dispatchEvent(e),console.log("[KServerBrowser] was destroy.")}isImageFile(e){var i;const t=(i=e.split(".").pop())==null?void 0:i.toLowerCase();return["jpg","jpeg","png","webp"].includes(t??"")}folderHasDisplayableChildren(e){return!e.children||e.children.length===0?!1:e.children.some(t=>t.type==="file"?this.shouldDisplayItem(t):t.type==="folder"?this.folderHasDisplayableChildren(t):!1)}}r.ServerBrowser=y,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|