UNPKG

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.87 kB
(function(a,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis!="undefined"?globalThis:a||self,r(a.Data={}))})(this,function(a){"use strict";const r={components:[],plugins:[],prefix:"ax",mode:""},u=t=>r.components.find(e=>e.name===t).class,d=()=>{const t=r.components.filter(o=>o.dataDetection),e=r.plugins.filter(o=>o.dataDetection);return[...t,...e].map(o=>o.name)},p=t=>t.replace(/[\w]([A-Z])/g,e=>e[0]+"-"+e[1]).toLowerCase(),g=(t,e="")=>{const o=p(t);return e?e+"-"+o:o},x=(t,e,o,s,i="")=>{const n=e[0].toUpperCase()+e.slice(1).toLowerCase();d().includes(n)&&o!=="Collapsible"&&n!=="Sidenav"&&(t[e]=u(n).getDefaultOptions());const c=i?i+"-"+e:e,l=f(t[e],o,s,c);if(!(Object.keys(l).length===0&&t.constructor===Object))return l},f=(t,e,o,s="")=>Object.keys(t).reduce((i,n)=>{if(typeof t[n]=="object"&&t[n]!==null){const c=x(t,n,e,o,s);c&&(i[n]=c)}else if(t[n]!==null){const c="data-"+e.toLowerCase()+"-"+g(n,s);if(o.hasAttribute(c)){const l=o.getAttribute(c);i[n]=typeof t[n]=="number"?Number(l):l,typeof t[n]=="boolean"&&(i[n]=l==="true")}}return i},{}),O=(t,e)=>{const o=Object.assign({},u(t).getDefaultOptions());return f(o,t,e)},m=()=>{document.querySelectorAll("[data-ax]").forEach(e=>{let o=e.dataset.ax;if(o=o[0].toUpperCase()+o.slice(1).toLowerCase(),!d().includes(o)){console.error(`[Axentix] Error: ${o} component doesn't exist. Did you forget to register him ?`,e);return}try{const s=u(o);new s(`#${e.id}`)}catch(s){console.error("[Axentix] Data: Unable to load "+o,s)}})},y=()=>{try{new Axentix.Axentix("all")}catch(t){console.error("[Axentix] Unable to auto init.",t)}};document.addEventListener("DOMContentLoaded",()=>{document.documentElement.dataset.axentix&&y(),m()}),a.formatOptions=O,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});