UNPKG

@flexilla/utilities

Version:

Utilities package for flexilla library

2 lines (1 loc) 1.48 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=({newElement:e,existingElement:t})=>{if(!(e instanceof HTMLElement)||!(t instanceof HTMLElement))throw new Error("Both parameters must be valid HTML elements.");const n=t.parentElement;if(n)n.insertBefore(e,t);else throw new Error("Existing element must have a parent element.")},l=(e,t)=>{for(const[n,s]of Object.entries(t))e.setAttribute(n,s)},d=({element:e,callback:t,type:n,keysCheck:s})=>{const r=getComputedStyle(e),o=n==="transition"?r.transition:r.animation;if(o!=="none"&&o!==""&&!s.includes(o)){const i=n==="transition"?"transitionend":"animationend",a=()=>{e.removeEventListener(i,a),t()};e.addEventListener(i,a,{once:!0})}else t()},u=({element:e,callback:t})=>{d({element:e,callback:t,type:"transition",keysCheck:["all 0s ease 0s","all"]})},f=({element:e,callback:t})=>{d({element:e,callback:t,type:"animation",keysCheck:["none 0s ease 0s 1 normal none running"]})},h=(e,t,n)=>{const s=new CustomEvent(t,{detail:n});e.dispatchEvent(s)},v=({container:e,attributeToWatch:t,onChildAdded:n})=>{const s=new MutationObserver(r=>{for(const o of r)if(o.type==="childList"&&Array.from(o.addedNodes).some(c=>c instanceof HTMLElement&&c.hasAttribute(t))){n();break}});return s.observe(e,{childList:!0}),()=>{s.disconnect()}};exports.afterAnimation=f;exports.afterTransition=u;exports.appendBefore=m;exports.dispatchCustomEvent=h;exports.observeChildrenChanges=v;exports.setAttributes=l;