Comparing version 1.0.0-beta-27 to 1.0.0-beta-28
{ | ||
"name": "alga-css", | ||
"version": "1.0.0-beta-27", | ||
"version": "1.0.0-beta-28", | ||
"description": "Alga CSS is a scope or component oriented CSS toolkit for quickly reuse CSS components and it can be stored in .alga format file as a custom CSS component and also it has many built-in customizable CSS properties that can be directly inserted to HTML Element class", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
135
src/index.js
@@ -135,2 +135,68 @@ const chokidar = require('chokidar') | ||
const pluginLoader = () => { | ||
let newPackNodes = [] | ||
const filterPackNodes = [] | ||
for(let rule of config.inits) { | ||
let param = rule.params.trim() | ||
let name = param | ||
if(param.includes('.')) { | ||
const prms = param.split('.') | ||
param = prms[0].trim() | ||
name = prms[1].trim() | ||
} | ||
if(!filterPackNodes.includes(param) && config.components[param]) { | ||
filterPackNodes.push(param) | ||
let newNodes = [] | ||
if(rule?.nodes) { | ||
for(let node of rule.nodes) { | ||
if(node.type === 'rule' && (rule?.nodes?.length || 0) >= 1) { | ||
const ruleNodeName = node.selector.replace(/\#|\./, '').trim() | ||
for(let ruleNode of node.nodes) { | ||
if(ruleNodeName === 'props') { | ||
if(ruleNode.prop in config.components[param][ruleNodeName]) { | ||
config.components[param][ruleNodeName][ruleNode.prop].value = ruleNode.value | ||
} | ||
} | ||
} | ||
} else { | ||
if(node.type === 'decl' && String(node?.prop) in config.components[param]['props']) { | ||
config.components[param]['props'][node.prop].value = node.value | ||
} | ||
} | ||
} | ||
} | ||
let newBodyVar = [] | ||
if(config.components[param]?.[name]?.['body']) { | ||
newBodyVar = config.components[param][name]['body'] | ||
} | ||
newNodes = [ | ||
...newNodes, | ||
...declaration(newBodyVar, | ||
{ | ||
refs: config.components[param]['refs'], | ||
props: config.components[param]['props'], | ||
provide: config.components[param]['provide'] | ||
}, | ||
{ | ||
screen: config.screen, | ||
state: config.state, | ||
prefers: config.prefers, | ||
color: config.color | ||
}) | ||
] | ||
const newRoot = config.components[param]['root'] | ||
newRoot.removeAll() | ||
if(config.important) { | ||
newRoot.append(...newNodes) | ||
} else { | ||
const newLayer = layer(newNodes, name, rule.source) | ||
newRoot.append(newLayer) | ||
} | ||
newPackNodes.push(newRoot) | ||
} | ||
} | ||
return newPackNodes.flat() | ||
} | ||
root.walkAtRules(config.directive, rule => { | ||
@@ -157,2 +223,4 @@ if(config.directive === 'layer') { | ||
} | ||
} else if(!rule.params.includes(',') && (name.includes('modules') || param.includes('modules'))) { | ||
rule.append(...pluginLoader()) | ||
} else { | ||
@@ -203,3 +271,5 @@ let fileName = param | ||
rule.remove() | ||
} else if(!rule.params.includes(',') && (name.includes('modules') || param.includes('modules'))) { | ||
rule.append(...pluginLoader()) | ||
rule.remove() | ||
} else { | ||
@@ -330,65 +400,2 @@ let fileName = param | ||
let newPackNodes = [] | ||
const filterPackNodes = [] | ||
for(let rule of config.inits) { | ||
let param = rule.params.trim() | ||
let name = param | ||
if(param.includes('.')) { | ||
const prms = param.split('.') | ||
param = prms[0].trim() | ||
name = prms[1].trim() | ||
} | ||
if(!filterPackNodes.includes(param) && config.components[param]) { | ||
filterPackNodes.push(param) | ||
let newNodes = [] | ||
if(rule?.nodes) { | ||
for(let node of rule.nodes) { | ||
if(node.type === 'rule' && (rule?.nodes?.length || 0) >= 1) { | ||
const ruleNodeName = node.selector.replace(/\#|\./, '').trim() | ||
for(let ruleNode of node.nodes) { | ||
if(ruleNodeName === 'props') { | ||
if(ruleNode.prop in config.components[param][ruleNodeName]) { | ||
config.components[param][ruleNodeName][ruleNode.prop].value = ruleNode.value | ||
} | ||
} | ||
} | ||
} else { | ||
if(node.type === 'decl' && String(node?.prop) in config.components[param]['props']) { | ||
config.components[param]['props'][node.prop].value = node.value | ||
} | ||
} | ||
} | ||
} | ||
let newBodyVar = [] | ||
if(config.components[param]?.[name]?.['body']) { | ||
newBodyVar = config.components[param][name]['body'] | ||
} | ||
newNodes = [ | ||
...newNodes, | ||
...declaration(newBodyVar, | ||
{ | ||
refs: config.components[param]['refs'], | ||
props: config.components[param]['props'], | ||
provide: config.components[param]['provide'] | ||
}, | ||
{ | ||
screen: config.screen, | ||
state: config.state, | ||
prefers: config.prefers, | ||
color: config.color | ||
}) | ||
] | ||
const newRoot = config.components[param]['root'] | ||
newRoot.removeAll() | ||
if(config.important) { | ||
newRoot.append(...newNodes) | ||
} else { | ||
const newLayer = layer(newNodes, name, rule.source) | ||
newRoot.append(newLayer) | ||
} | ||
newPackNodes.push(newRoot) | ||
} | ||
} | ||
root.append(...newPackNodes.flat()) | ||
} | ||
@@ -395,0 +402,0 @@ } |
264975
79
3736