flexacore-ui-dev
Version:
Universal UI Framework for CDN, React, Angular, Vue, Svelte with TypeScript support
1 lines • 3.84 kB
JavaScript
!function(e,t){"use strict";if("undefined"==typeof FlexaCoreEngine)return void console.error("FlexaCore Engine not loaded");class o{constructor(){this.version="2.0.0",this.engine=e.flexacore,this.initialized=!1,this.config={autoInit:!0,debug:!1,theme:"default",rtl:!1,locale:"en",components:{modal:!0,dropdown:!0,tooltip:!0,toast:!0,tabs:!0,switch:!0,progress:!0,skeleton:!0,stepper:!0,form:!0},plugins:{"theme-manager":!0,"component-manager":!0}}}init(e={}){return this.initialized?(this.log("FlexaCore Framework already initialized"),this):(this.config=this.deepMerge(this.config,e),this.engine.init(this.config),this.loadPlugins(),this.setupGlobalAPI(),t.body.classList.add("flexacore-framework"),this.initialized=!0,this.log("FlexaCore Framework initialized successfully"),this)}loadPlugins(){this.config.plugins["theme-manager"]&&this.loadPlugin("theme-manager"),this.config.plugins["component-manager"]&&this.loadPlugin("component-manager")}loadPlugin(o){let s=t.createElement("script");"localhost"===e.location.hostname||"127.0.0.1"===e.location.hostname?s.src=`../dist/plugins/${o}.min.js`:s.src=`https://cdn.flexacore.dev/plugins/${o}.min.js`,s.onload=()=>{this.log(`Plugin "${o}" loaded`)},s.onerror=()=>{this.error(`Failed to load plugin "${o}"`)},t.head.appendChild(s)}setupGlobalAPI(){e.FlexaCore={version:this.version,init:this.init.bind(this),config:this.config,engine:this.engine,theme:{apply:e=>this.engine.emit("theme-change",{theme:e}),toggle:()=>this.engine.emit("theme-toggle"),get:()=>this.engine.getState("theme")},components:{modal:{show:e=>this.showModal(e),hide:e=>this.hideModal(e)},toast:{show:(e,t,o)=>this.showToast(e,t,o)},tabs:{show:(e,t)=>this.showTab(e,t)}},utils:{addClass:(e,t)=>e.classList.add(t),removeClass:(e,t)=>e.classList.remove(t),toggleClass:(e,t)=>e.classList.toggle(t),hasClass:(e,t)=>e.classList.contains(t),create:(e,o,s)=>{const i=t.createElement(e);return o&&(i.className=o),s&&(i.innerHTML=s),i}}},e.FC={init:this.init.bind(this),theme:e.FlexaCore.theme,components:e.FlexaCore.components,utils:e.FlexaCore.utils,version:this.version}}showModal(e){const o=t.getElementById(e);o&&(o.classList.add("fc-modal-active"),t.body.classList.add("fc-modal-open"))}hideModal(e){const o=t.getElementById(e);o&&(o.classList.remove("fc-modal-active"),t.body.classList.remove("fc-modal-open"))}showToast(e,t="info",o=3e3){const s=this.getToastContainer(),i=this.createToast(e,t);s.appendChild(i),setTimeout(()=>{i.classList.add("fc-toast-active")},100),setTimeout(()=>{this.hideToast(i)},o)}getToastContainer(){let e=t.getElementById("fc-toast-container");return e||(e=t.createElement("div"),e.id="fc-toast-container",e.className="fc-toast-container",t.body.appendChild(e)),e}createToast(e,o){const s=t.createElement("div");return s.className=`fc-toast fc-toast-${o}`,s.textContent=e,s}hideToast(e){e.classList.remove("fc-toast-active"),setTimeout(()=>{e.parentNode&&e.parentNode.removeChild(e)},300)}showTab(e,o){const s="string"==typeof e?t.querySelector(e):e;if(s){const e=s.querySelectorAll("[data-fc-tab]"),t=s.querySelectorAll("[data-fc-tab-content]");e.forEach(e=>e.classList.remove("fc-tab-active")),t.forEach(e=>e.classList.remove("fc-tab-content-active"));const i=s.querySelector(`[data-fc-tab="${o}"]`),a=s.querySelector(`[data-fc-tab-content="${o}"]`);i&&i.classList.add("fc-tab-active"),a&&a.classList.add("fc-tab-content-active")}}deepMerge(e,t){const o={...e};for(const e in t)t[e]&&"object"==typeof t[e]&&!Array.isArray(t[e])?o[e]=this.deepMerge(o[e]||{},t[e]):o[e]=t[e];return o}log(...e){this.config.debug&&console.log("[FlexaCore Framework]",...e)}error(...e){console.error("[FlexaCore Framework]",...e)}}const s=new o;"loading"===t.readyState?t.addEventListener("DOMContentLoaded",()=>{s.config.autoInit&&s.init()}):s.config.autoInit&&s.init(),e.FlexaCoreFramework=o}(window,document);