lix-website/themes/lix/assets/bootstrap/node_modules/sugarss/preprocess.js

121 lines
12 KiB
JavaScript
Raw Normal View History

2024-04-27 03:39:10 +00:00
'use strict';
exports.__esModule = true;
exports.default = preprocess;
function indentError(input, l, p) {
throw input.error('Mixed tabs and spaces are not allowed', l, p + 1);
}
function preprocess(input, lines) {
var indentType = void 0;
var prevNumber = 0;
var parts = lines.map(function (line) {
var lastComma = false;
var comment = false;
var number = prevNumber + 1;
var atrule = false;
var indent = '';
var tokens = [];
var colon = false;
if (line.length > 0) {
if (line[0][0] === 'space') {
indent = line[0][1];
tokens = line.slice(1);
} else {
indent = '';
tokens = line;
}
if (!indentType && indent.length) {
indentType = indent[0] === ' ' ? 'space' : 'tab';
}
if (indentType === 'space') {
if (indent.indexOf('\t') !== -1) {
indentError(input, number, indent.indexOf('\t'));
}
} else if (indentType === 'tab') {
if (indent.indexOf(' ') !== -1) {
indentError(input, number, indent.indexOf(' '));
}
}
if (tokens.length) {
for (var i = tokens.length - 1; i >= 0; i--) {
var type = tokens[i][0];
if (type === ',') {
lastComma = true;
break;
} else if (type === 'space') {
continue;
} else if (type === 'comment') {
continue;
} else if (type === 'newline') {
continue;
} else {
break;
}
}
comment = tokens[0][0] === 'comment';
atrule = tokens[0][0] === 'at-word';
var brackets = 0;
for (var _i = 0; _i < tokens.length - 1; _i++) {
var _type = tokens[_i][0];
var next = tokens[_i + 1][0];
if (_type === '(') {
brackets += 1;
} else if (_type === ')') {
brackets -= 1;
} else if (_type === ':' && brackets === 0 && (next === 'space' || next === 'newline')) {
colon = true;
}
}
}
var last = tokens[tokens.length - 1];
if (last && last[0] === 'newline') prevNumber = last[2];
}
return {
number: number,
indent: indent,
colon: colon,
tokens: tokens,
atrule: atrule,
comment: comment,
lastComma: lastComma,
before: ''
};
});
parts = parts.reduceRight(function (all, i) {
if (!i.tokens.length || i.tokens.every(function (j) {
return j[0] === 'newline';
})) {
var prev = all[0];
var before = i.indent + i.tokens.map(function (j) {
return j[1];
}).join('');
prev.before = before + prev.before;
} else {
all.unshift(i);
}
return all;
}, [{ end: true, before: '' }]);
parts.forEach(function (part, i) {
if (i === 0) return;
var prev = parts[i - 1];
var last = prev.tokens[prev.tokens.length - 1];
if (last && last[0] === 'newline') {
part.before = last[1] + part.before;
prev.tokens.pop();
}
});
return parts;
}
module.exports = exports['default'];
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByZXByb2Nlc3MuZXM2Il0sIm5hbWVzIjpbInByZXByb2Nlc3MiLCJpbmRlbnRFcnJvciIsImlucHV0IiwibCIsInAiLCJlcnJvciIsImxpbmVzIiwiaW5kZW50VHlwZSIsInByZXZOdW1iZXIiLCJwYXJ0cyIsIm1hcCIsImxhc3RDb21tYSIsImNvbW1lbnQiLCJudW1iZXIiLCJhdHJ1bGUiLCJpbmRlbnQiLCJ0b2tlbnMiLCJjb2xvbiIsImxpbmUiLCJsZW5ndGgiLCJzbGljZSIsImluZGV4T2YiLCJpIiwidHlwZSIsImJyYWNrZXRzIiwibmV4dCIsImxhc3QiLCJiZWZvcmUiLCJyZWR1Y2VSaWdodCIsImFsbCIsImV2ZXJ5IiwiaiIsInByZXYiLCJqb2luIiwidW5zaGlmdCIsImVuZCIsImZvckVhY2giLCJwYXJ0IiwicG9wIl0sIm1hcHBpbmdzIjoiOzs7a0JBSXdCQSxVO0FBSnhCLFNBQVNDLFdBQVQsQ0FBc0JDLEtBQXRCLEVBQTZCQyxDQUE3QixFQUFnQ0MsQ0FBaEMsRUFBbUM7QUFDakMsUUFBTUYsTUFBTUcsS0FBTixDQUFZLHVDQUFaLEVBQXFERixDQUFyRCxFQUF3REMsSUFBSSxDQUE1RCxDQUFOO0FBQ0Q7O0FBRWMsU0FBU0osVUFBVCxDQUFxQkUsS0FBckIsRUFBNEJJLEtBQTVCLEVBQW1DO0FBQ2hELE1BQUlDLG1CQUFKO0FBQ0EsTUFBSUMsYUFBYSxDQUFqQjtBQUNBLE1BQUlD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