165 lines
3.7 KiB
Stylus
165 lines
3.7 KiB
Stylus
_bem_context = {
|
|
_alias_map: {}
|
|
_alias_stacks: {
|
|
}
|
|
}
|
|
|
|
work_stack(stack, callback)
|
|
while length(stack) > 0
|
|
entry = pop(stack)
|
|
if entry != ()
|
|
callback(entry)
|
|
|
|
set_alias(alias, name)
|
|
if name != null && alias != null
|
|
_bem_context._alias_map[alias] = name
|
|
|
|
lookup_alias(name)
|
|
if name in _bem_context._alias_map
|
|
return _bem_context._alias_map[name]
|
|
else
|
|
return name
|
|
|
|
|
|
|
|
store_alias(alias)
|
|
level_name = called-from[1]
|
|
if not level_name in _bem_context._alias_stacks
|
|
_bem_context._alias_stacks[level_name] = () ()
|
|
|
|
if alias != null
|
|
push(_bem_context._alias_stacks[level_name], alias)
|
|
|
|
pop_last_alias()
|
|
level_name = called-from[1]
|
|
if not level_name in _bem_context._alias_stacks
|
|
return null
|
|
return pop(_bem_context._alias_stacks[level_name])
|
|
|
|
apply_alias_stack(name)
|
|
level_name = called-from[1]
|
|
if level_name in _bem_context._alias_stacks
|
|
work_stack(_bem_context._alias_stacks[level_name], @(element){
|
|
set_alias(element, name)
|
|
})
|
|
|
|
|
|
|
|
auto_name(delimiter)
|
|
if length(called-from) < 3
|
|
return null
|
|
block_name = called-from[2]
|
|
if delimiter == null
|
|
return block_name
|
|
name = split(delimiter, block_name)[-1]
|
|
if name in ('RV-Element' 'RV-Block' 'RV-Block--shorthand' 'RV-Element--modifier' 'RV-Block--modifier' 'RV-Generate')
|
|
return null
|
|
return name
|
|
|
|
is_nested(mixin_name=null)
|
|
_free_hits = 0
|
|
if mixin_name == null
|
|
shift(called-from)
|
|
mixin_name = shift(called-from)
|
|
else
|
|
_free_hits = 1
|
|
for parent in called-from
|
|
if parent == mixin_name
|
|
if _free_hits == 0
|
|
return true
|
|
else
|
|
_free_hits = _free_hits - 1
|
|
return false
|
|
|
|
is_nested_in(parent_name)
|
|
return parent_name in called-from
|
|
|
|
not_nested_in(parent_name)
|
|
return !(parent_name in called-from)
|
|
|
|
is_any_parent_nested()
|
|
//RV-Level RV-Element--modifier RV-Element RV-Block--modifier RV-BreakPoint--horizontal RV-Block--modifier RV-Fan--horizontal RV-Block
|
|
for i in (length(called-from)...0)
|
|
i = i - 1
|
|
if i != index(called-from, called-from[i])
|
|
return true
|
|
return false
|
|
|
|
RV-Level(name_delimiter, allowed_parent_levels=null, selector_callback, squash_if_parent_nested=false)
|
|
name = auto_name(name_delimiter)
|
|
p(called-from)
|
|
not_in_parent = true
|
|
for parent_level in allowed_parent_levels
|
|
not_in_parent = not_in_parent && not_nested_in(parent_level)
|
|
if not_in_parent //|| is_nested_in('RV-Squash')
|
|
{block}
|
|
else if is_nested()
|
|
store_alias(name)
|
|
{block}
|
|
else
|
|
if name == null
|
|
name = pop_last_alias()
|
|
name = lookup_alias(name)
|
|
apply_alias_stack(name)
|
|
|
|
if squash_if_parent_nested && is_any_parent_nested()
|
|
{block}
|
|
else
|
|
selector_name = selector_callback(name)
|
|
if name == ''
|
|
selector_name = split(name_delimiter, selector_name)[0]
|
|
{selector_name}
|
|
{block}
|
|
|
|
// RV-Fan--horizontal RV-Fan--horizontal __ Base -- wurst
|
|
// RV-BreakPoint__Item--outside RV-Fan--horizontal__Base RV-Fan--horizontal
|
|
|
|
|
|
|
|
|
|
RV-Block(name)
|
|
.{name}
|
|
{block}
|
|
|
|
_bem_context._alias_map = {}
|
|
_bem_context._alias_stacks = {}
|
|
|
|
RV-Generate()
|
|
{block}
|
|
|
|
_bem_context._alias_map = {}
|
|
_bem_context._alias_stacks = {}
|
|
|
|
RV-Block()
|
|
+RV-Level(null, ('RV-Generate'), @(name){
|
|
define('current_block', name, true)
|
|
return '.'+name
|
|
})
|
|
{block}
|
|
|
|
RV-Block--shorthand(name)
|
|
+RV-Block(name)
|
|
{block}
|
|
|
|
RV-Element()
|
|
+RV-Level('__', ('RV-Generate' 'RV-Block--modifier'), @(name){
|
|
return '& .' + current_block +'__' + name
|
|
})
|
|
{block}
|
|
|
|
|
|
RV-Element--modifier()
|
|
+RV-Level('--', ('RV-Element'), @(name){return '&--' + name}, true)
|
|
{block}
|
|
|
|
RV-Block--modifier()
|
|
+RV-Level('--', ('RV-Generate' 'RV-Block--shorthand'), @(name){
|
|
'.' + current_block +'--' + name
|
|
}, true)
|
|
if is_nested_in('RV-Block--shorthand') && length(called-from) > 0
|
|
mixin_name = split('--', called-from[0])[0]
|
|
convert(unquote(mixin_name)+'()')
|
|
{block}
|
|
|
|
RV-Squash()
|
|
{block} |