lix-website/themes/lix/assets/bootstrap/node_modules/postcss-sass/parser.js

585 lines
55 KiB
JavaScript
Raw Normal View History

2024-04-27 03:39:10 +00:00
"use strict";
var postcss = require('postcss');
var gonzales = require('gonzales-pe');
var DEFAULT_RAWS_ROOT = {
before: ''
};
var DEFAULT_RAWS_RULE = {
before: '',
between: ''
};
var DEFAULT_RAWS_DECL = {
before: '',
between: '',
semicolon: false
};
var DEFAULT_COMMENT_DECL = {
before: ''
};
var SUPPORTED_AT_KEYWORDS = ['media'];
var SassParser =
/*#__PURE__*/
function () {
function SassParser(input) {
this.input = input;
}
var _proto = SassParser.prototype;
_proto.parse = function parse() {
try {
this.node = gonzales.parse(this.input.css, {
syntax: 'sass'
});
} catch (error) {
throw this.input.error(error.message, error.line, 1);
}
this.lines = this.input.css.match(/^.*(\r?\n|$)/gm);
this.root = this.stylesheet(this.node);
};
_proto.extractSource = function extractSource(start, end) {
var nodeLines = this.lines.slice(start.line - 1, end.line);
nodeLines[0] = nodeLines[0].substring(start.column - 1);
var last = nodeLines.length - 1;
nodeLines[last] = nodeLines[last].substring(0, end.column);
return nodeLines.join('');
};
_proto.stylesheet = function stylesheet(node) {
var _this = this;
// Create and set parameters for Root node
var root = postcss.root();
root.source = {
start: node.start,
end: node.end,
input: this.input // Raws for root node
};
root.raws = {
semicolon: DEFAULT_RAWS_ROOT.semicolon,
before: DEFAULT_RAWS_ROOT.before // Store spaces before root (if exist)
};
this.raws = {
before: ''
};
node.content.forEach(function (contentNode) {
return _this.process(contentNode, root);
});
return root;
};
_proto.process = function process(node, parent) {
if (this[node.type]) return this[node.type](node, parent) || null;
return null;
};
_proto.ruleset = function ruleset(node, parent) {
var _this2 = this;
// Loop to find the deepest ruleset node
this.raws.multiRuleProp = '';
node.content.forEach(function (contentNode) {
switch (contentNode.type) {
case 'block':
{
// Create Rule node
var rule = postcss.rule();
rule.selector = ''; // Object to store raws for Rule
var ruleRaws = {
before: _this2.raws.before || DEFAULT_RAWS_RULE.before,
between: DEFAULT_RAWS_RULE.between // Variable to store spaces and symbols before declaration property
};
_this2.raws.before = '';
_this2.raws.comment = false; // Look up throw all nodes in current ruleset node
node.content.filter(function (content) {
return content.type === 'block';
}).forEach(function (innerContentNode) {
return _this2.process(innerContentNode, rule);
});
if (rule.nodes.length) {
// Write selector to Rule
rule.selector = _this2.extractSource(node.start, contentNode.start).slice(0, -1).replace(/\s+$/, function (spaces) {
ruleRaws.between = spaces;
return '';
}); // Set parameters for Rule node
rule.parent = parent;
rule.source = {
start: node.start,
end: node.end,
input: _this2.input
};
rule.raws = ruleRaws;
parent.nodes.push(rule);
}
break;
}
default:
}
});
};
_proto.block = function block(node, parent) {
var _this3 = this;
// If nested rules exist, wrap current rule in new rule node
if (this.raws.multiRule) {
if (this.raws.multiRulePropVariable) {
this.raws.multiRuleProp = "$" + this.raws.multiRuleProp;
}
var multiRule = Object.assign(postcss.rule(), {
source: {
start: {
line: node.start.line - 1,
column: node.start.column
},
end: node.end,
input: this.input
},
raws: {
before: this.raws.before || DEFAULT_RAWS_RULE.before,
between: DEFAULT_RAWS_RULE.between
},
parent: parent,
selector: (this.raws.customProperty ? '--' : '') + this.raws.multiRuleProp
});
parent.push(multiRule);
parent = multiRule;
}
this.raws.before = ''; // Looking for declaration node in block node
node.content.forEach(function (contentNode) {
return _this3.process(contentNode, parent);
});
if (this.raws.multiRule) {
this.raws.beforeMulti = this.raws.before;
}
};
_proto.declaration = function declaration(node, parent) {
var _this4 = this;
var isBlockInside = false; // Create Declaration node
var declarationNode = postcss.decl();
declarationNode.prop = ''; // Object to store raws for Declaration
var declarationRaws = Object.assign(declarationNode.raws, {
before: this.raws.before || DEFAULT_RAWS_DECL.before,
between: DEFAULT_RAWS_DECL.between,
semicolon: DEFAULT_RAWS_DECL.semicolon
});
this.raws.property = false;
this.raws.betweenBefore = false;
this.raws.comment = false; // Looking for property and value node in declaration node
node.content.forEach(function (contentNode) {
switch (contentNode.type) {
case 'customProperty':
_this4.raws.customProperty = true;
// fall through
case 'property':
{
/* this.raws.property to detect is property is already defined in current object */
_this4.raws.property = true;
_this4.raws.multiRuleProp = contentNode.content[0].content;
_this4.raws.multiRulePropVariable = contentNode.content[0].type === 'variable';
_this4.process(contentNode, declarationNode);
break;
}
case 'propertyDelimiter':
{
if (_this4.raws.property && !_this4.raws.betweenBefore) {
/* If property is already defined and there's no ':' before it */
declarationRaws.between += contentNode.content;
_this4.raws.multiRuleProp += contentNode.content;
} else {
/* If ':' goes before property declaration, like :width 100px */
_this4.raws.betweenBefore = true;
declarationRaws.before += contentNode.content;
_this4.raws.multiRuleProp += contentNode.content;
}
break;
}
case 'space':
{
declarationRaws.between += contentNode.content;
break;
}
case 'value':
{
// Look up for a value for current property
switch (contentNode.content[0].type) {
case 'block':
{
isBlockInside = true; // If nested rules exist
if (Array.isArray(contentNode.content[0].content)) {
_this4.raws.multiRule = true;
}
_this4.process(contentNode.content[0], parent);
break;
}
case 'variable':
{
declarationNode.value = '$';
_this4.process(contentNode, declarationNode);
break;
}
case 'color':
{
declarationNode.value = '#';
_this4.process(contentNode, declarationNode);
break;
}
case 'number':
{
if (contentNode.content.length > 1) {
declarationNode.value = contentNode.content.join('');
} else {
_this4.process(contentNode, declarationNode);
}
break;
}
case 'parentheses':
{
declarationNode.value = '(';
_this4.process(contentNode, declarationNode);
break;
}
default:
{
_this4.process(contentNode, declarationNode);
}
}
break;
}
default:
}
});
if (!isBlockInside) {
// Set parameters for Declaration node
declarationNode.source = {
start: node.start,
end: node.end,
input: this.input
};
declarationNode.parent = parent;
parent.nodes.push(declarationNode);
}
this.raws.before = '';
this.raws.customProperty = false;
this.raws.multiRuleProp = '';
this.raws.property = false;
};
_proto.customProperty = function customProperty(node, parent) {
this.property(node, parent);
parent.prop = "--" + parent.prop;
};
_proto.property = function property(node, parent) {
// Set property for Declaration node
switch (node.content[0].type) {
case 'variable':
{
parent.prop += '$';
break;
}
case 'interpolation':
{
this.raws.interpolation = true;
parent.prop += '#{';
break;
}
default:
}
parent.prop += node.content[0].content;
if (this.raws.interpolation) {
parent.prop += '}';
this.raws.interpolation = false;
}
};
_proto.value = function value(node, parent) {
if (!parent.value) {
parent.value = '';
} // Set value for Declaration node
if (node.content.length) {
node.content.forEach(function (contentNode) {
switch (contentNode.type) {
case 'important':
{
parent.raws.important = contentNode.content;
parent.important = true;
var match = parent.value.match(/^(.*?)(\s*)$/);
if (match) {
parent.raws.important = match[2] + parent.raws.important;
parent.value = match[1];
}
break;
}
case 'parentheses':
{
parent.value += contentNode.content.join('') + ')';
break;
}
case 'percentage':
{
parent.value += contentNode.content.join('') + '%';
break;
}
default:
{
if (contentNode.content.constructor === Array) {
parent.value += contentNode.content.join('');
} else {
parent.value += contentNode.content;
}
}
}
});
}
};
_proto.singlelineComment = function singlelineComment(node, parent) {
return this.comment(node, parent, true);
};
_proto.multilineComment = function multilineComment(node, parent) {
return this.comment(node, parent, false);
};
_proto.comment = function comment(node, parent, inline) {
// https://github.com/nodesecurity/eslint-plugin-security#detect-unsafe-regex
// eslint-disable-next-line security/detect-unsafe-regex
var text = node.content.match(/^(\s*)((?:\S[\S\s]*?)?)(\s*)$/);
this.raws.comment = true;
var comment = Object.assign(postcss.comment(), {
text: text[2],
raws: {
before: this.raws.before || DEFAULT_COMMENT_DECL.before,
left: text[1],
right: text[3],
inline: inline
},
source: {
start: {
line: node.start.line,
column: node.start.column
},
end: node.end,
input: this.input
},
parent: parent
});
if (this.raws.beforeMulti) {
comment.raws.before += this.raws.beforeMulti;
this.raws.beforeMulti = undefined;
}
parent.nodes.push(comment);
this.raws.before = '';
};
_proto.space = function space(node, parent) {
// Spaces before root and rule
switch (parent.type) {
case 'root':
{
this.raws.before += node.content;
break;
}
case 'rule':
{
if (this.raws.comment) {
this.raws.before += node.content;
} else if (this.raws.loop) {
parent.selector += node.content;
} else {
this.raws.before = (this.raws.before || '\n') + node.content;
}
break;
}
default:
}
};
_proto.declarationDelimiter = function declarationDelimiter(node) {
this.raws.before += node.content;
};
_proto.loop = function loop(node, parent) {
var _this5 = this;
var loop = postcss.rule();
this.raws.comment = false;
this.raws.multiRule = false;
this.raws.loop = true;
loop.selector = '';
loop.raws = {
before: this.raws.before || DEFAULT_RAWS_RULE.before,
between: DEFAULT_RAWS_RULE.between
};
if (this.raws.beforeMulti) {
loop.raws.before += this.raws.beforeMulti;
this.raws.beforeMulti = undefined;
}
node.content.forEach(function (contentNode, i) {
if (node.content[i + 1] && node.content[i + 1].type === 'block') {
_this5.raws.loop = false;
}
_this5.process(contentNode, loop);
});
parent.nodes.push(loop);
this.raws.loop = false;
};
_proto.atrule = function atrule(node, parent) {
var _this6 = this;
// Skip unsupported @xxx rules
var supportedNode = node.content[0].content.some(function (contentNode) {
return SUPPORTED_AT_KEYWORDS.includes(contentNode.content);
});
if (!supportedNode) return;
var atrule = postcss.rule();
atrule.selector = '';
atrule.raws = {
before: this.raws.before || DEFAULT_RAWS_RULE.before,
between: DEFAULT_RAWS_RULE.between
};
node.content.forEach(function (contentNode, i) {
if (contentNode.type === 'space') {
var prevNodeType = node.content[i - 1].type;
switch (prevNodeType) {
case 'atkeyword':
case 'ident':
atrule.selector += contentNode.content;
break;
default:
}
return;
}
_this6.process(contentNode, atrule);
});
parent.nodes.push(atrule);
};
_proto.parentheses = function parentheses(node, parent) {
parent.selector += '(';
node.content.forEach(function (contentNode) {
if (typeof contentNode.content === 'string') {
parent.selector += contentNode.content;
}
if (typeof contentNode.content === 'object') {
contentNode.content.forEach(function (childrenContentNode) {
if (contentNode.type === 'variable') parent.selector += '$';
parent.selector += childrenContentNode.content;
});
}
});
parent.selector += ')';
};
_proto.interpolation = function interpolation(node, parent) {
var _this7 = this;
parent.selector += '#{';
node.content.forEach(function (contentNode) {
_this7.process(contentNode, parent);
});
parent.selector += '}';
};
_proto.atkeyword = function atkeyword(node, parent) {
parent.selector += "@" + node.content;
};
_proto.operator = function operator(node, parent) {
parent.selector += node.content;
};
_proto.variable = function variable(node, parent) {
if (this.raws.loop) {
parent.selector += "$" + node.content[0].content;
return;
}
parent.selector += "$" + node.content;
};
_proto.ident = function ident(node, parent) {
parent.selector += node.content;
};
return SassParser;
}();
module.exports = SassParser;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBhcnNlci5lczYiXSwibmFtZXMiOlsicG9zdGNzcyIsInJlcXVpcmUiLCJnb256YWxlcyIsIkRFRkFVTFRfUkFXU19ST09UIiwiYmVmb3JlIiwiREVGQVVMVF9SQVdTX1JVTEUiLCJiZXR3ZWVuIiwiREVGQVVMVF9SQVdTX0RFQ0wiLCJzZW1pY29sb24iLCJERUZBVUxUX0NPTU1FTlRfREVDTCIsIlNVUFBPUlRFRF9BVF9LRVlXT1JEUyIsIlNhc3NQYXJzZXIiLCJpbnB1dCIsInBhcnNlIiwibm9kZSIsImNzcyIsInN5bnRheCIsImVycm9yIiwibWVzc2FnZSIsImxpbmUiLCJsaW5lcyIsIm1hdGNoIiwicm9vdCIsInN0eWxlc2hlZXQiLCJleHRyYWN0U291cmNlIiwic3RhcnQiLCJlbmQiLCJub2RlTGluZXMiLCJzbGljZSIsInN1YnN0cmluZyIsImNvbHVtbiIsImxhc3QiLCJsZW5ndGgiLCJqb2luIiwic291cmNlIiwicmF3cyIsImNvbnRlbnQiLCJmb3JFYWNoIiwiY29udGVudE5vZGUiLCJwcm9jZXNzIiwicGFyZW50IiwidHlwZSIsInJ1bGVzZXQiLCJtdWx0aVJ1bGVQcm9wIiwicnVsZSIsInNlbGVjdG9yIiwicnVsZVJhd3MiLCJjb21tZW50IiwiZmlsdGVyIiwiaW5uZXJDb250ZW50Tm9kZSIsIm5vZGVzIiwicmVwbGFjZSIsInNwYWNlcyIsInB1c2giLCJibG9jayIsIm11bHRpUnVsZSIsIm11bHRpUnVsZVByb3BWYXJpYWJsZSIsIk9iamVjdCIsImFzc2lnbiIsImN1c3RvbVByb3BlcnR5IiwiYmVmb3JlTXVsdGkiLCJkZWNsYXJhdGlvbiIsImlzQmxvY2tJbnNpZGU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