@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
16 lines (14 loc) • 1.3 kB
JavaScript
;const o=require("vue"),S=require("../../../common/utils/NeonResponsiveUtils.cjs.js"),u="neon-grid-styles-",h=o.defineComponent({name:"NeonGrid",props:{layouts:{type:Array,required:!0},id:{type:String,required:!0}},setup(i){const c=o.ref(new Set(i.layouts.map(t=>t.grid.flat()).flat())),p=t=>{let e=` .neon-grid {
grid-template-areas: `;e=e+t.map(r=>`"${r.join(" ")}"`).join(`
`)+";",e=e+`
}
`;const n=[];e=e+t.map(r=>r.map(s=>n.indexOf(s)>=0?"":(n.push(s),`
.${s} {
grid-area: ${s};
}`)).join(`
`)).join("");const l=new Set(t.flat().flat()),g=Array.from(c.value).filter(r=>!l.has(r));return e=e+g.map(r=>`
.${r} { display: none!important; }`),e},m=t=>{const e=t.grid,n=S.NeonResponsiveUtils.breakpoints[t.breakpoint];return`@media screen${n.length>0?` and ${n}`:""} {
`+p(e)+`
}`},y=()=>i.layouts.map(t=>m(t)).join(`
`),f=t=>{const e=u+i.id;let n=document.getElementById(e);n===null&&(n=document.createElement("style"),n.id=e,document.head.appendChild(n)),n.innerHTML=t},a=()=>{const t=y();f(t)},d=()=>{const t=u+i.id,e=document.getElementById(t);e!=null&&e.parentNode&&e.parentNode.removeChild(e)};o.onMounted(()=>a()),o.onUnmounted(()=>d()),o.watch(()=>i.layouts,()=>{d(),a()},{deep:!0,immediate:!0})}});module.exports=h;
//# sourceMappingURL=NeonGrid.cjs.js.map