Skip to content

Adds @container support #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_Store
70 changes: 69 additions & 1 deletion lib/parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,72 @@ module.exports = function(css, options){
});
}


/**
* Parse layer.
*/

function atlayer() {
const pos = position()
const m = match(/^@layer *([^{;@]+)/)

if (!m) {
return
}
const layer = trim(m[1])

if (!open()) {
match(/^[;\s]*/)
return pos({
type: 'layer',
layer: layer
})
}

const style = comments().concat(rules())

if (!close()) {
return error("@layer missing '}'")
}

return pos({
type: 'layer',
layer: layer,
rules: style
})
}


/**
* Parse container.
*/

function atcontainer() {
const pos = position()
const m = match(/^@container *([^{]+)/)

if (!m) {
return
}
const container = trim(m[1])

if (!open()) {
return error("@container missing '{'")
}

const style = comments().concat(rules())

if (!close()) {
return error("@container missing '}'")
}

return pos({
type: 'container',
container: container,
rules: style
})
}

/**
* Parse import
*/
Expand Down Expand Up @@ -541,7 +607,9 @@ module.exports = function(css, options){
|| atdocument()
|| atpage()
|| athost()
|| atfontface();
|| atfontface()
|| atcontainer()
|| atlayer();
}

/**
Expand Down
27 changes: 27 additions & 0 deletions lib/stringify/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,30 @@ Compiler.prototype.declaration = function(node){
return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
};

/**
* Visit container node.
*/

Compiler.prototype.container = function(node) {
return (
this.emit('@container ' + node.container, node.position) +
this.emit('{') +
this.mapVisit(node.rules) +
this.emit('}')
)
}

/**
* Visit layer node.
*/

Compiler.prototype.layer = function(node) {
return (
this.emit('@layer ' + node.layer, node.position) +
(node.rules
? this.emit('{') +
this.mapVisit(node.rules) +
this.emit('}')
: ';')
);
};
28 changes: 28 additions & 0 deletions lib/stringify/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ Compiler.prototype['custom-media'] = function(node){
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
};

/**
* Visit container node.
*/

Compiler.prototype.container = function(node) {
return (
this.emit(this.indent() + '@container ' + node.container, node.position) +
this.emit(' {\n' + this.indent(1)) +
this.mapVisit(node.rules, '\n\n') +
this.emit('\n' + this.indent(-1) + this.indent() + '}')
)
}

/**
* Visit rule node.
*/
Expand Down Expand Up @@ -238,6 +251,21 @@ Compiler.prototype.declaration = function(node){
+ this.emit(';');
};

/**
* Visit layer node.
*/

Compiler.prototype.layer = function(node) {
return (
this.emit(this.indent() + '@layer ' + node.layer, node.position) +
(node.rules
? this.emit(' {\n' + this.indent(1)) +
this.mapVisit(node.rules, '\n\n') +
this.emit('\n' + this.indent(-1) + this.indent() + '}')
: ';')
);
};

/**
* Increase, decrease or return current indentation.
*/
Expand Down
Loading