axentix
Version:
Axentix is a framework mixing fully customizable components & utility-first classes, leaving the design choice to the developer.
3 lines (2 loc) • 1.91 kB
JavaScript
(function(s,n){typeof exports=="object"&&typeof module!="undefined"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(s=typeof globalThis!="undefined"?globalThis:s||self,n(s.Component={}))})(this,function(s){"use strict";var f=Object.defineProperty;var h=(s,n,i)=>n in s?f(s,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[n]=i;var c=(s,n,i)=>h(s,typeof n!="symbol"?n+"":n,i);const n=[],i={components:[],plugins:[],prefix:"ax",mode:""},d=o=>i.components.find(t=>t.name===o).class,l=()=>{const o=i.components.filter(e=>e.dataDetection),t=i.plugins.filter(e=>e.dataDetection);return[...o,...t].map(e=>e.name)},p=()=>{document.querySelectorAll("[data-ax]").forEach(t=>{let e=t.dataset.ax;if(e=e[0].toUpperCase()+e.slice(1).toLowerCase(),!l().includes(e)){console.error(`[Axentix] Error: ${e} component doesn't exist.
Did you forget to register him ?`,t);return}try{const r=d(e);new r(`#${t.id}`)}catch(r){console.error("[Axentix] Data: Unable to load "+e,r)}})},u=()=>{try{new Axentix.Axentix("all")}catch(o){console.error("[Axentix] Unable to auto init.",o)}};document.addEventListener("DOMContentLoaded",()=>{document.documentElement.dataset.axentix&&u(),p()});const a=(o,t,e)=>{const r=new CustomEvent("ax."+t,{detail:{},bubbles:!0});o.dispatchEvent(r)},m=o=>{const t=n.find(e=>e.type!=="Toast"&&"#"+e.instance.el.id===o);return t?t.instance:!1};class x{constructor(){c(this,"el")}removeListeners(){}setupListeners(){}setup(){}preventDbInstance(t){if(t&&m(t))throw new Error(`Instance already exist on ${t}`)}sync(){a(this.el,"component.sync"),this.removeListeners(),this.setupListeners()}reset(){a(this.el,"component.reset"),this.removeListeners(),this.setup()}destroy(){a(this.el,"component.destroy"),this.removeListeners();const t=n.findIndex(e=>e.instance.el.id===this.el.id);n.splice(t,1)}}s.AxentixComponent=x,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});