generate-atomic-css
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,11 @@ # Change Log | ||
## 1.2.0 (2019-07-15) | ||
### Features | ||
- Complete extractFromToSource with unit tests ([4ac3634](https://gitlab.com/codsen/codsen/commit/4ac3634)) | ||
- Improvements to multiple CSS rule generation and recognition in config ([b780889](https://gitlab.com/codsen/codsen/commit/b780889)) | ||
- Improvements to the padding algorithm ([21ac50f](https://gitlab.com/codsen/codsen/commit/21ac50f)) | ||
- Separate extractFromToSource() into a standalone, exported function ([af27f89](https://gitlab.com/codsen/codsen/commit/af27f89)) | ||
## 1.1.0 (2019-07-06) | ||
@@ -12,3 +21,3 @@ | ||
- Don't close the comment blocks above, it's not fully safe ([5ce6230](https://gitlab.com/codsen/codsen/commit/5ce6230)) | ||
- Fix cases when there is no $$$ in the input and there are heads/tails ([09ceccd](https://gitlab.com/codsen/codsen/commit/09ceccd)) | ||
- Fix cases when there is no \$\$\$ in the input and there are heads/tails ([09ceccd](https://gitlab.com/codsen/codsen/commit/09ceccd)) | ||
- Fix the case when the only non-whitespace string is at zero index (falsey value) ([76fd296](https://gitlab.com/codsen/codsen/commit/76fd296)) | ||
@@ -26,3 +35,3 @@ - More tests and more improvements to edge case recognition ([4721b20](https://gitlab.com/codsen/codsen/commit/4721b20)) | ||
- Output the log ([c729689](https://gitlab.com/codsen/codsen/commit/c729689)) | ||
- Tackle input without any $$$ ([1dcaee4](https://gitlab.com/codsen/codsen/commit/1dcaee4)) | ||
- Tackle input without any \$\$\$ ([1dcaee4](https://gitlab.com/codsen/codsen/commit/1dcaee4)) | ||
@@ -29,0 +38,0 @@ ## 1.0.0 (2018-06-28) |
/** | ||
* generate-atomic-css | ||
* Generate Atomic CSS | ||
* Version: 1.1.0 | ||
* Version: 1.2.0 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -33,89 +33,46 @@ * License: MIT | ||
var version = "1.1.0"; | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
} | ||
var isArr = Array.isArray; | ||
function isStr(something) { | ||
return typeof something === "string"; | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function trimBlankLinesFromLinesArray(lineArr) { | ||
var trim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
if (!trim) { | ||
return lineArr; | ||
} | ||
var copyArr = Array.from(lineArr); | ||
if (copyArr.length && isStr(copyArr[0]) && !copyArr[0].trim().length) { | ||
do { | ||
copyArr.shift(); | ||
} while (!copyArr[0].trim().length); | ||
} | ||
if (copyArr.length && isStr(copyArr[copyArr.length - 1]) && !copyArr[copyArr.length - 1].trim().length) { | ||
do { | ||
copyArr.pop(); | ||
} while (!copyArr[copyArr.length - 1].trim().length); | ||
} | ||
return copyArr; | ||
} | ||
function prepLine(str, progressFn, subsetFrom, subsetTo, generatedCount, pad) { | ||
var currentPercentageDone; | ||
var lastPercentage = 0; | ||
var split = str.split("|").filter(function (val) { | ||
return val.length; | ||
}); | ||
var from = 0; | ||
var to = 500; | ||
if (split[1]) { | ||
if (split[2]) { | ||
from = Number.parseInt(split[1].trim()); | ||
to = Number.parseInt(split[2].trim()); | ||
} else { | ||
to = Number.parseInt(split[1].trim()); | ||
function _iterableToArrayLimit(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} | ||
var res = ""; | ||
var subsetRange = subsetTo - subsetFrom; | ||
var _loop = function _loop(i) { | ||
generatedCount.count++; | ||
var newStr = split[0]; | ||
var threeDollarRegexWithUnits = /(\$\$\$(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax))/g; | ||
var unitsOnly = /(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax)/g; | ||
var threeDollarFollowedByWhitespaceRegex = /\$\$\$(?=[{ ])/g; | ||
var threeDollarRegex = /\$\$\$/g; | ||
if (pad) { | ||
var findingsThreeDollarWithUnits = newStr.match(threeDollarRegexWithUnits); | ||
if (isArr(findingsThreeDollarWithUnits) && findingsThreeDollarWithUnits.length | ||
) { | ||
findingsThreeDollarWithUnits.forEach(function (valFound) { | ||
newStr = newStr.replace(valFound, "".concat(i).concat(i === 0 ? "" : unitsOnly.exec(valFound)[0]).padStart(valFound.length - 3 + String(to).length)); | ||
}); | ||
} | ||
res += "".concat(i === from ? "" : "\n").concat(newStr.replace(threeDollarFollowedByWhitespaceRegex, "".concat(i).padEnd(String(to).length)).replace(threeDollarRegex, i)).trimEnd(); | ||
} else { | ||
if (i === 0) { | ||
res += "".concat(i === from ? "" : "\n").concat(newStr.replace(threeDollarRegexWithUnits, i).replace(threeDollarRegex, i).trimEnd()); | ||
} else { | ||
res += "".concat(i === from ? "" : "\n").concat(newStr.replace(threeDollarRegex, i).trimEnd()); | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
if (typeof progressFn === "function") { | ||
currentPercentageDone = Math.floor(subsetFrom + i / (to - from) * subsetRange); | ||
if (currentPercentageDone !== lastPercentage) { | ||
lastPercentage = currentPercentageDone; | ||
progressFn(currentPercentageDone); | ||
} | ||
} | ||
}; | ||
for (var i = from; i <= to; i++) { | ||
_loop(i); | ||
} | ||
return res; | ||
return _arr; | ||
} | ||
function prepConfig(str, progressFn, progressFrom, progressTo) { | ||
var trim = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
var generatedCount = arguments.length > 5 ? arguments[5] : undefined; | ||
var pad = arguments.length > 6 ? arguments[6] : undefined; | ||
return trimBlankLinesFromLinesArray(split(str).map(function (rowStr, i, arr) { | ||
return rowStr.includes("$$$") ? prepLine(rowStr, progressFn, progressFrom + (progressTo - progressFrom) / arr.length * i, progressFrom + (progressTo - progressFrom) / arr.length * (i + 1), generatedCount, pad) : rowStr; | ||
}), trim).join("\n"); | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
var version = "1.2.0"; | ||
var isArr = Array.isArray; | ||
function isStr(something) { | ||
return typeof something === "string"; | ||
} | ||
var headsAndTails = { | ||
@@ -127,48 +84,13 @@ CONFIGHEAD: "GENERATE-ATOMIC-CSS-CONFIG-STARTS", | ||
}; | ||
function genAtomic(str, originalOpts) { | ||
function trimIfNeeded(str) { | ||
if (!opts.includeConfig && !opts.includeHeadsAndTails) { | ||
return str; | ||
} | ||
return str.trim(); | ||
} | ||
if (typeof str !== "string") { | ||
throw new Error("generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as \"".concat(JSON.stringify(str, null, 4), "\" (type ").concat(_typeof(str), ")")); | ||
} | ||
var CONFIGHEAD = headsAndTails.CONFIGHEAD, | ||
CONFIGTAIL = headsAndTails.CONFIGTAIL, | ||
CONTENTHEAD = headsAndTails.CONTENTHEAD, | ||
CONTENTTAIL = headsAndTails.CONTENTTAIL; | ||
var defaults = { | ||
includeConfig: true, | ||
includeHeadsAndTails: true, | ||
pad: true, | ||
configOverride: null, | ||
reportProgressFunc: null, | ||
reportProgressFuncFrom: 0, | ||
reportProgressFuncTo: 100 | ||
}; | ||
var generatedCount = { | ||
count: 0 | ||
}; | ||
var opts = Object.assign({}, defaults, originalOpts); | ||
if (opts.includeConfig && !opts.includeHeadsAndTails) { | ||
opts.includeHeadsAndTails = true; | ||
} | ||
if (!opts.configOverride && !str.includes("$$$") && !str.includes(CONFIGHEAD) && !str.includes(CONFIGTAIL) && !str.includes(CONTENTHEAD) && !str.includes(CONTENTTAIL) || isStr(opts.configOverride) && !opts.configOverride.includes("$$$") && !opts.configOverride.includes(CONFIGHEAD) && !opts.configOverride.includes(CONFIGTAIL) && !opts.configOverride.includes(CONTENTHEAD) && !opts.configOverride.includes(CONTENTTAIL)) { | ||
return { | ||
log: { | ||
count: 0 | ||
}, | ||
result: str | ||
}; | ||
} | ||
var frontPart = ""; | ||
var endPart = ""; | ||
var units = ["px", "em", "%", "rem", "cm", "mm", "in", "pt", "pc", "ex", "ch", "vw", "vmin", "vmax"]; | ||
var CONFIGHEAD = headsAndTails.CONFIGHEAD, | ||
CONFIGTAIL = headsAndTails.CONFIGTAIL, | ||
CONTENTHEAD = headsAndTails.CONTENTHEAD, | ||
CONTENTTAIL = headsAndTails.CONTENTTAIL; | ||
var padLeftIfTheresOnTheLeft = [":"]; | ||
function extractConfig(str) { | ||
var extractedConfig = str; | ||
var rawContentAbove = ""; | ||
var rawContentBelow = ""; | ||
var extractedConfig; | ||
if (opts.configOverride) { | ||
extractedConfig = opts.configOverride; | ||
} else if (str.includes(CONFIGHEAD) && str.includes(CONFIGTAIL)) { | ||
if (str.includes(CONFIGHEAD) && str.includes(CONFIGTAIL)) { | ||
if (str.indexOf(CONFIGTAIL) !== -1 && str.indexOf(CONTENTHEAD) !== -1 && str.indexOf(CONFIGTAIL) > str.indexOf(CONTENTHEAD)) { | ||
@@ -278,3 +200,3 @@ throw new Error("generate-atomic-css: [THROW_ID_02] Config heads are after config tails!"); | ||
} | ||
if (!rowStr.includes("$$$")) { | ||
if (!rowStr.includes("$$$") && !rowStr.includes("{") && !rowStr.includes(":")) { | ||
gatheredLinesAboveTopmostConfigLine.push(rowStr); | ||
@@ -287,3 +209,3 @@ return false; | ||
for (var i = configLines.length; i--;) { | ||
if (!configLines[i].includes("$$$")) { | ||
if (!configLines[i].includes("$$$") && !configLines[i].includes("{") && !configLines[i].includes(":")) { | ||
gatheredLinesBelowLastConfigLine.unshift(configLines.pop()); | ||
@@ -302,2 +224,260 @@ } else { | ||
} | ||
return [extractedConfig, rawContentAbove, rawContentBelow]; | ||
} | ||
function trimBlankLinesFromLinesArray(lineArr) { | ||
var trim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
if (!trim) { | ||
return lineArr; | ||
} | ||
var copyArr = Array.from(lineArr); | ||
if (copyArr.length && isStr(copyArr[0]) && !copyArr[0].trim().length) { | ||
do { | ||
copyArr.shift(); | ||
} while (isStr(copyArr[0]) && !copyArr[0].trim().length); | ||
} | ||
if (copyArr.length && isStr(copyArr[copyArr.length - 1]) && !copyArr[copyArr.length - 1].trim().length) { | ||
do { | ||
copyArr.pop(); | ||
} while (copyArr && copyArr[copyArr.length - 1] && !copyArr[copyArr.length - 1].trim().length); | ||
} | ||
return copyArr; | ||
} | ||
function extractFromToSource(str) { | ||
var fromDefault = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var toDefault = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 500; | ||
var from = fromDefault; | ||
var to = toDefault; | ||
var source = str; | ||
var tempArr; | ||
if (str.lastIndexOf("}") > 0 && str.slice(str.lastIndexOf("}") + 1).includes("|")) { | ||
tempArr = str.slice(str.lastIndexOf("}") + 1).split("|").filter(function (val) { | ||
return val.trim().length; | ||
}).map(function (val) { | ||
return val.trim(); | ||
}).filter(function (val) { | ||
return String(val).split("").every(function (_char) { | ||
return /\d/g.test(_char); | ||
}); | ||
}); | ||
} else if (str.includes("|")) { | ||
tempArr = str.split("|").filter(function (val) { | ||
return val.trim().length; | ||
}).map(function (val) { | ||
return val.trim(); | ||
}).filter(function (val) { | ||
return String(val).split("").every(function (_char2) { | ||
return /\d/g.test(_char2); | ||
}); | ||
}); | ||
} | ||
if (isArr(tempArr)) { | ||
if (tempArr.length === 1) { | ||
to = Number.parseInt(tempArr[0], 10); | ||
} else if (tempArr.length > 1) { | ||
from = Number.parseInt(tempArr[0], 10); | ||
to = Number.parseInt(tempArr[1], 10); | ||
} | ||
} | ||
if (str.lastIndexOf("}") > 0 && str.slice(str.lastIndexOf("}") + 1).includes("|")) { | ||
source = str.slice(0, str.indexOf("|", str.lastIndexOf("}") + 1)).trimEnd(); | ||
if (source.trim().startsWith("|")) { | ||
while (source.trim().startsWith("|")) { | ||
source = source.trimStart().slice(1); | ||
} | ||
} | ||
} else { | ||
var lastPipeWasAt = null; | ||
var firstNonPipeNonWhitespaceCharMet = false; | ||
var startFrom = 0; | ||
var endTo = str.length; | ||
var onlyDigitsAndWhitespaceBeenMet = null; | ||
for (var i = 0, len = str.length; i < len; i++) { | ||
if ("0123456789".includes(str[i])) { | ||
if (onlyDigitsAndWhitespaceBeenMet === null && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = true; | ||
} | ||
} else { | ||
if (str[i] !== "|" && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = false; | ||
} | ||
} | ||
if (!str[i + 1] && onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
} | ||
if (str[i] === "|") { | ||
if (onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
break; | ||
} | ||
lastPipeWasAt = i; | ||
onlyDigitsAndWhitespaceBeenMet = null; | ||
} else if (!firstNonPipeNonWhitespaceCharMet && str[i].trim().length) { | ||
firstNonPipeNonWhitespaceCharMet = true; | ||
if (lastPipeWasAt !== null) { | ||
startFrom = lastPipeWasAt + 1; | ||
} | ||
} | ||
} | ||
source = str.slice(startFrom, endTo).trimEnd(); | ||
} | ||
return [from, to, source]; | ||
} | ||
function prepLine(str, progressFn, subsetFrom, subsetTo, generatedCount, pad) { | ||
var currentPercentageDone; | ||
var lastPercentage = 0; | ||
var _extractFromToSource = extractFromToSource(str, 0, 500), | ||
_extractFromToSource2 = _slicedToArray(_extractFromToSource, 3), | ||
from = _extractFromToSource2[0], | ||
to = _extractFromToSource2[1], | ||
source = _extractFromToSource2[2]; | ||
var subsetRange = subsetTo - subsetFrom; | ||
var res = ""; | ||
var _loop = function _loop(i) { | ||
var debtPaddingLen = 0; | ||
var startPoint = 0; | ||
var _loop2 = function _loop2(y, len) { | ||
var charcode = source[y].charCodeAt(0); | ||
if (source[y] === "$" && source[y - 1] === "$" && source[y - 2] === "$") { | ||
var restOfStr = source.slice(y + 1); | ||
var unitFound; | ||
if (i === 0 && units.some(function (unit) { | ||
if (restOfStr.startsWith(unit)) { | ||
unitFound = unit; | ||
return true; | ||
} | ||
}) && (source[stringLeftRight.right(source, y + unitFound.length)] === "{" || !source[y + unitFound.length + 1].trim().length)) { | ||
res += "".concat(source.slice(startPoint, y - 2)).concat(pad ? String(i).padStart(String(to).length - String(i).length + unitFound.length + 1) : i); | ||
startPoint = y + 1 + (unitFound ? unitFound.length : 0); | ||
} else { | ||
var unitThatFollow; | ||
units.some(function (unit) { | ||
if (source.slice(y + 1).startsWith(unit)) { | ||
unitThatFollow = unit; | ||
return true; | ||
} | ||
}); | ||
if (!source[y - 3].trim().length || padLeftIfTheresOnTheLeft.some(function (val) { | ||
return source.slice(startPoint, y - 2).trim().endsWith(val); | ||
})) { | ||
var temp = 0; | ||
if (i === 0) { | ||
units.some(function (unit) { | ||
if ("".concat(source.slice(startPoint, y - 2)).startsWith(unit)) { | ||
temp = unit.length; | ||
} | ||
return true; | ||
}); | ||
} | ||
res += "".concat(source.slice(startPoint + temp, y - 2)).concat(pad ? String(i).padStart(String(to).length + (i === 0 && unitThatFollow ? unitThatFollow.length : 0)) : i); | ||
} else if (!source[y + 1].trim().length || source[stringLeftRight.right(source, y)] === "{") { | ||
res += "".concat(source.slice(startPoint, y - 2)).concat(pad ? String(i).padEnd(String(to).length + (i === 0 && unitThatFollow ? unitThatFollow.length : 0)) : i); | ||
} else { | ||
res += "".concat(source.slice(startPoint, y - 2)).concat(i); | ||
if (pad) { | ||
debtPaddingLen = String(to).length - String(i).length; | ||
} | ||
} | ||
startPoint = y + 1; | ||
} | ||
} | ||
if (source[y] === "{" && pad) { | ||
if (debtPaddingLen) { | ||
res += "".concat(source.slice(startPoint, y)).concat(" ".repeat(debtPaddingLen)); | ||
startPoint = y; | ||
debtPaddingLen = 0; | ||
} | ||
} | ||
if (!source[y + 1]) { | ||
var _unitFound; | ||
var _restOfStr = source.slice(startPoint); | ||
if (i === 0 && units.some(function (unit) { | ||
if (_restOfStr.startsWith(unit)) { | ||
_unitFound = unit; | ||
return true; | ||
} | ||
})) { | ||
res += "".concat(source.slice(startPoint + _unitFound.length)); | ||
} else { | ||
res += "".concat(source.slice(startPoint)); | ||
} | ||
res += "".concat(i !== to ? "\n" : ""); | ||
} | ||
}; | ||
for (var y = 0, len = source.length; y < len; y++) { | ||
_loop2(y); | ||
} | ||
generatedCount.count++; | ||
if (typeof progressFn === "function") { | ||
currentPercentageDone = Math.floor(subsetFrom + i / (to - from) * subsetRange); | ||
if (currentPercentageDone !== lastPercentage) { | ||
lastPercentage = currentPercentageDone; | ||
progressFn(currentPercentageDone); | ||
} | ||
} | ||
}; | ||
for (var i = from; i <= to; i++) { | ||
_loop(i); | ||
} | ||
return res; | ||
} | ||
function bump(str, thingToBump) { | ||
if (/\.\w/g.test(str)) { | ||
thingToBump.count++; | ||
} | ||
return str; | ||
} | ||
function prepConfig(str, progressFn, progressFrom, progressTo) { | ||
var trim = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true; | ||
var generatedCount = arguments.length > 5 ? arguments[5] : undefined; | ||
var pad = arguments.length > 6 ? arguments[6] : undefined; | ||
return trimBlankLinesFromLinesArray(split(str).map(function (rowStr, i, arr) { | ||
return rowStr.includes("$$$") ? prepLine(rowStr, progressFn, progressFrom + (progressTo - progressFrom) / arr.length * i, progressFrom + (progressTo - progressFrom) / arr.length * (i + 1), generatedCount, pad) : bump(rowStr, generatedCount); | ||
}), trim).join("\n"); | ||
} | ||
function genAtomic(str, originalOpts) { | ||
function trimIfNeeded(str) { | ||
if (!opts.includeConfig && !opts.includeHeadsAndTails) { | ||
return str; | ||
} | ||
return str.trim(); | ||
} | ||
if (typeof str !== "string") { | ||
throw new Error("generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as \"".concat(JSON.stringify(str, null, 4), "\" (type ").concat(_typeof(str), ")")); | ||
} | ||
var CONFIGHEAD = headsAndTails.CONFIGHEAD, | ||
CONFIGTAIL = headsAndTails.CONFIGTAIL, | ||
CONTENTHEAD = headsAndTails.CONTENTHEAD, | ||
CONTENTTAIL = headsAndTails.CONTENTTAIL; | ||
var defaults = { | ||
includeConfig: true, | ||
includeHeadsAndTails: true, | ||
pad: true, | ||
configOverride: null, | ||
reportProgressFunc: null, | ||
reportProgressFuncFrom: 0, | ||
reportProgressFuncTo: 100 | ||
}; | ||
var generatedCount = { | ||
count: 0 | ||
}; | ||
var opts = Object.assign({}, defaults, originalOpts); | ||
if (opts.includeConfig && !opts.includeHeadsAndTails) { | ||
opts.includeHeadsAndTails = true; | ||
} | ||
if (!opts.configOverride && !str.includes("$$$") && !str.includes(CONFIGHEAD) && !str.includes(CONFIGTAIL) && !str.includes(CONTENTHEAD) && !str.includes(CONTENTTAIL) || isStr(opts.configOverride) && !opts.configOverride.includes("$$$") && !opts.configOverride.includes(CONFIGHEAD) && !opts.configOverride.includes(CONFIGTAIL) && !opts.configOverride.includes(CONTENTHEAD) && !opts.configOverride.includes(CONTENTTAIL)) { | ||
return { | ||
log: { | ||
count: 0 | ||
}, | ||
result: str | ||
}; | ||
} | ||
var frontPart = ""; | ||
var endPart = ""; | ||
var _extractConfig = extractConfig(opts.configOverride ? opts.configOverride : str), | ||
_extractConfig2 = _slicedToArray(_extractConfig, 3), | ||
extractedConfig = _extractConfig2[0], | ||
rawContentAbove = _extractConfig2[1], | ||
rawContentBelow = _extractConfig2[2]; | ||
if (!isStr(extractedConfig) || !extractedConfig.trim().length) { | ||
@@ -322,3 +502,3 @@ return { | ||
if (str.includes(CONFIGHEAD)) { | ||
if (stringLeftRight.left(str, str.indexOf(CONFIGHEAD))) { | ||
if (stringLeftRight.left(str, str.indexOf(CONFIGHEAD)) != null) { | ||
var sliceUpTo = str.indexOf(CONFIGHEAD); | ||
@@ -328,24 +508,35 @@ if (str[stringLeftRight.left(str, sliceUpTo)] === "*" && str[stringLeftRight.left(str, stringLeftRight.left(str, sliceUpTo))] === "/") { | ||
} | ||
frontPart = "".concat(str.slice(0, sliceUpTo)).concat(str[stringLeftRight.right(str, sliceUpTo - 1)] === "/" && str[stringLeftRight.right(str, stringLeftRight.right(str, sliceUpTo - 1))] === "*" ? "" : "/* ").concat(frontPart); | ||
var putInFront = "/* "; | ||
if (str[stringLeftRight.right(str, sliceUpTo - 1)] === "/" && str[stringLeftRight.right(str, stringLeftRight.right(str, sliceUpTo - 1))] === "*" || frontPart.trim().startsWith("/*")) { | ||
putInFront = ""; | ||
} | ||
frontPart = "".concat(str.slice(0, sliceUpTo)).concat(putInFront).concat(frontPart); | ||
} | ||
} | ||
if (str.includes(CONFIGTAIL) && stringLeftRight.right(str, str.indexOf(CONFIGTAIL) + CONFIGTAIL.length)) { | ||
var _sliceFrom2 = str.indexOf(CONFIGTAIL) + CONFIGTAIL.length; | ||
var sliceFrom = str.indexOf(CONFIGTAIL) + CONFIGTAIL.length; | ||
if (str[stringLeftRight.right(str, str.indexOf(CONFIGTAIL) + CONFIGTAIL.length)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, str.indexOf(CONFIGTAIL) + CONFIGTAIL.length))] === "/") { | ||
_sliceFrom2 = stringLeftRight.right(str, stringLeftRight.right(str, str.indexOf(CONFIGTAIL) + CONFIGTAIL.length)) + 1; | ||
sliceFrom = stringLeftRight.right(str, stringLeftRight.right(str, str.indexOf(CONFIGTAIL) + CONFIGTAIL.length)) + 1; | ||
} | ||
if (str.slice(stringLeftRight.right(str, _sliceFrom2 - 1)).startsWith(CONTENTHEAD)) { | ||
var contentHeadsStartAt = stringLeftRight.right(str, _sliceFrom2); | ||
_sliceFrom2 = contentHeadsStartAt + CONTENTHEAD.length; | ||
if (str[stringLeftRight.right(str, _sliceFrom2 - 1)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, _sliceFrom2 - 1))] === "/") { | ||
_sliceFrom2 = stringLeftRight.right(str, stringLeftRight.right(str, _sliceFrom2 - 1)) + 1; | ||
if (str.slice(stringLeftRight.right(str, sliceFrom - 1)).startsWith(CONTENTHEAD)) { | ||
var contentHeadsStartAt = stringLeftRight.right(str, sliceFrom); | ||
sliceFrom = contentHeadsStartAt + CONTENTHEAD.length; | ||
if (str[stringLeftRight.right(str, sliceFrom - 1)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom - 1))] === "/") { | ||
sliceFrom = stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom - 1)) + 1; | ||
} | ||
if (str.includes(CONTENTTAIL)) { | ||
_sliceFrom2 = str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if (str[stringLeftRight.right(str, _sliceFrom2)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, _sliceFrom2))] === "/") { | ||
_sliceFrom2 = stringLeftRight.right(str, stringLeftRight.right(str, _sliceFrom2)) + 1; | ||
sliceFrom = str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if (str[stringLeftRight.right(str, sliceFrom)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom))] === "/") { | ||
sliceFrom = stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom)) + 1; | ||
} | ||
} | ||
} | ||
endPart = "".concat(endPart).concat(str[_sliceFrom2] && stringLeftRight.right(str, _sliceFrom2 - 1) ? str.slice(_sliceFrom2) : ""); | ||
var slicedFrom = str.slice(sliceFrom); | ||
if (slicedFrom.length && slicedFrom.includes(CONTENTTAIL)) { | ||
sliceFrom = str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if (str[stringLeftRight.right(str, sliceFrom)] === "*" && str[stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom))] === "/") { | ||
sliceFrom = stringLeftRight.right(str, stringLeftRight.right(str, sliceFrom)) + 1; | ||
} | ||
} | ||
endPart = "".concat(endPart).concat(str[sliceFrom] && stringLeftRight.right(str, sliceFrom - 1) ? str.slice(sliceFrom) : ""); | ||
} | ||
@@ -375,4 +566,5 @@ if (isStr(rawContentAbove)) { | ||
exports.extractFromToSource = extractFromToSource; | ||
exports.genAtomic = genAtomic; | ||
exports.headsAndTails = headsAndTails; | ||
exports.version = version; |
/** | ||
* generate-atomic-css | ||
* Generate Atomic CSS | ||
* Version: 1.1.0 | ||
* Version: 1.2.0 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -13,3 +13,3 @@ * License: MIT | ||
var version = "1.1.0"; | ||
var version = "1.2.0"; | ||
@@ -20,119 +20,2 @@ const isArr = Array.isArray; | ||
} | ||
function trimBlankLinesFromLinesArray(lineArr, trim = true) { | ||
if (!trim) { | ||
return lineArr; | ||
} | ||
const copyArr = Array.from(lineArr); | ||
if (copyArr.length && isStr(copyArr[0]) && !copyArr[0].trim().length) { | ||
do { | ||
copyArr.shift(); | ||
} while (!copyArr[0].trim().length); | ||
} | ||
if ( | ||
copyArr.length && | ||
isStr(copyArr[copyArr.length - 1]) && | ||
!copyArr[copyArr.length - 1].trim().length | ||
) { | ||
do { | ||
copyArr.pop(); | ||
} while (!copyArr[copyArr.length - 1].trim().length); | ||
} | ||
return copyArr; | ||
} | ||
function prepLine(str, progressFn, subsetFrom, subsetTo, generatedCount, pad) { | ||
let currentPercentageDone; | ||
let lastPercentage = 0; | ||
const split = str.split("|").filter(val => val.length); | ||
let from = 0; | ||
let to = 500; | ||
if (split[1]) { | ||
if (split[2]) { | ||
from = Number.parseInt(split[1].trim()); | ||
to = Number.parseInt(split[2].trim()); | ||
} else { | ||
to = Number.parseInt(split[1].trim()); | ||
} | ||
} | ||
let res = ""; | ||
const subsetRange = subsetTo - subsetFrom; | ||
for (let i = from; i <= to; i++) { | ||
generatedCount.count++; | ||
let newStr = split[0]; | ||
const threeDollarRegexWithUnits = /(\$\$\$(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax))/g; | ||
const unitsOnly = /(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax)/g; | ||
const threeDollarFollowedByWhitespaceRegex = /\$\$\$(?=[{ ])/g; | ||
const threeDollarRegex = /\$\$\$/g; | ||
if (pad) { | ||
const findingsThreeDollarWithUnits = newStr.match( | ||
threeDollarRegexWithUnits | ||
); | ||
if ( | ||
isArr(findingsThreeDollarWithUnits) && | ||
findingsThreeDollarWithUnits.length | ||
) { | ||
findingsThreeDollarWithUnits.forEach(valFound => { | ||
newStr = newStr.replace( | ||
valFound, | ||
`${i}${i === 0 ? "" : unitsOnly.exec(valFound)[0]}`.padStart( | ||
valFound.length - 3 + String(to).length | ||
) | ||
); | ||
}); | ||
} | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace( | ||
threeDollarFollowedByWhitespaceRegex, | ||
`${i}`.padEnd(String(to).length) | ||
) | ||
.replace(threeDollarRegex, i)}`.trimEnd(); | ||
} else { | ||
if (i === 0) { | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace(threeDollarRegexWithUnits, i) | ||
.replace(threeDollarRegex, i) | ||
.trimEnd()}`; | ||
} else { | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace(threeDollarRegex, i) | ||
.trimEnd()}`; | ||
} | ||
} | ||
if (typeof progressFn === "function") { | ||
currentPercentageDone = Math.floor( | ||
subsetFrom + (i / (to - from)) * subsetRange | ||
); | ||
if (currentPercentageDone !== lastPercentage) { | ||
lastPercentage = currentPercentageDone; | ||
progressFn(currentPercentageDone); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
function prepConfig( | ||
str, | ||
progressFn, | ||
progressFrom, | ||
progressTo, | ||
trim = true, | ||
generatedCount, | ||
pad | ||
) { | ||
return trimBlankLinesFromLinesArray( | ||
split(str).map((rowStr, i, arr) => | ||
rowStr.includes("$$$") | ||
? prepLine( | ||
rowStr, | ||
progressFn, | ||
progressFrom + ((progressTo - progressFrom) / arr.length) * i, | ||
progressFrom + ((progressTo - progressFrom) / arr.length) * (i + 1), | ||
generatedCount, | ||
pad | ||
) | ||
: rowStr | ||
), | ||
trim | ||
).join("\n"); | ||
} | ||
const headsAndTails = { | ||
@@ -144,64 +27,25 @@ CONFIGHEAD: "GENERATE-ATOMIC-CSS-CONFIG-STARTS", | ||
}; | ||
function genAtomic(str, originalOpts) { | ||
function trimIfNeeded(str) { | ||
if (!opts.includeConfig && !opts.includeHeadsAndTails) { | ||
return str; | ||
} | ||
return str.trim(); | ||
} | ||
if (typeof str !== "string") { | ||
throw new Error( | ||
`generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as "${JSON.stringify( | ||
str, | ||
null, | ||
4 | ||
)}" (type ${typeof str})` | ||
); | ||
} | ||
const { CONFIGHEAD, CONFIGTAIL, CONTENTHEAD, CONTENTTAIL } = headsAndTails; | ||
const defaults = { | ||
includeConfig: true, | ||
includeHeadsAndTails: true, | ||
pad: true, | ||
configOverride: null, | ||
reportProgressFunc: null, | ||
reportProgressFuncFrom: 0, | ||
reportProgressFuncTo: 100 | ||
}; | ||
const generatedCount = { | ||
count: 0 | ||
}; | ||
const opts = Object.assign({}, defaults, originalOpts); | ||
if (opts.includeConfig && !opts.includeHeadsAndTails) { | ||
opts.includeHeadsAndTails = true; | ||
} | ||
if ( | ||
(!opts.configOverride && | ||
!str.includes("$$$") && | ||
!str.includes(CONFIGHEAD) && | ||
!str.includes(CONFIGTAIL) && | ||
!str.includes(CONTENTHEAD) && | ||
!str.includes(CONTENTTAIL)) || | ||
(isStr(opts.configOverride) && | ||
!opts.configOverride.includes("$$$") && | ||
!opts.configOverride.includes(CONFIGHEAD) && | ||
!opts.configOverride.includes(CONFIGTAIL) && | ||
!opts.configOverride.includes(CONTENTHEAD) && | ||
!opts.configOverride.includes(CONTENTTAIL)) | ||
) { | ||
return { | ||
log: { | ||
count: 0 | ||
}, | ||
result: str | ||
}; | ||
} | ||
let frontPart = ""; | ||
let endPart = ""; | ||
const units = [ | ||
"px", | ||
"em", | ||
"%", | ||
"rem", | ||
"cm", | ||
"mm", | ||
"in", | ||
"pt", | ||
"pc", | ||
"ex", | ||
"ch", | ||
"vw", | ||
"vmin", | ||
"vmax" | ||
]; | ||
const { CONFIGHEAD, CONFIGTAIL, CONTENTHEAD, CONTENTTAIL } = headsAndTails; | ||
const padLeftIfTheresOnTheLeft = [":"]; | ||
function extractConfig(str) { | ||
let extractedConfig = str; | ||
let rawContentAbove = ""; | ||
let rawContentBelow = ""; | ||
let extractedConfig; | ||
if (opts.configOverride) { | ||
extractedConfig = opts.configOverride; | ||
} else if (str.includes(CONFIGHEAD) && str.includes(CONFIGTAIL)) { | ||
if (str.includes(CONFIGHEAD) && str.includes(CONFIGTAIL)) { | ||
if ( | ||
@@ -356,3 +200,7 @@ str.indexOf(CONFIGTAIL) !== -1 && | ||
} | ||
if (!rowStr.includes("$$$")) { | ||
if ( | ||
!rowStr.includes("$$$") && | ||
!rowStr.includes("{") && | ||
!rowStr.includes(":") | ||
) { | ||
gatheredLinesAboveTopmostConfigLine.push(rowStr); | ||
@@ -365,3 +213,7 @@ return false; | ||
for (let i = configLines.length; i--; ) { | ||
if (!configLines[i].includes("$$$")) { | ||
if ( | ||
!configLines[i].includes("$$$") && | ||
!configLines[i].includes("{") && | ||
!configLines[i].includes(":") | ||
) { | ||
gatheredLinesBelowLastConfigLine.unshift(configLines.pop()); | ||
@@ -383,2 +235,332 @@ } else { | ||
} | ||
return [extractedConfig, rawContentAbove, rawContentBelow]; | ||
} | ||
function trimBlankLinesFromLinesArray(lineArr, trim = true) { | ||
if (!trim) { | ||
return lineArr; | ||
} | ||
const copyArr = Array.from(lineArr); | ||
if (copyArr.length && isStr(copyArr[0]) && !copyArr[0].trim().length) { | ||
do { | ||
copyArr.shift(); | ||
} while (isStr(copyArr[0]) && !copyArr[0].trim().length); | ||
} | ||
if ( | ||
copyArr.length && | ||
isStr(copyArr[copyArr.length - 1]) && | ||
!copyArr[copyArr.length - 1].trim().length | ||
) { | ||
do { | ||
copyArr.pop(); | ||
} while ( | ||
copyArr && | ||
copyArr[copyArr.length - 1] && | ||
!copyArr[copyArr.length - 1].trim().length | ||
); | ||
} | ||
return copyArr; | ||
} | ||
function extractFromToSource(str, fromDefault = 0, toDefault = 500) { | ||
let from = fromDefault; | ||
let to = toDefault; | ||
let source = str; | ||
let tempArr; | ||
if ( | ||
str.lastIndexOf("}") > 0 && | ||
str.slice(str.lastIndexOf("}") + 1).includes("|") | ||
) { | ||
tempArr = str | ||
.slice(str.lastIndexOf("}") + 1) | ||
.split("|") | ||
.filter(val => val.trim().length) | ||
.map(val => val.trim()) | ||
.filter(val => | ||
String(val) | ||
.split("") | ||
.every(char => /\d/g.test(char)) | ||
); | ||
} else if (str.includes("|")) { | ||
tempArr = str | ||
.split("|") | ||
.filter(val => val.trim().length) | ||
.map(val => val.trim()) | ||
.filter(val => | ||
String(val) | ||
.split("") | ||
.every(char => /\d/g.test(char)) | ||
); | ||
} | ||
if (isArr(tempArr)) { | ||
if (tempArr.length === 1) { | ||
to = Number.parseInt(tempArr[0], 10); | ||
} else if (tempArr.length > 1) { | ||
from = Number.parseInt(tempArr[0], 10); | ||
to = Number.parseInt(tempArr[1], 10); | ||
} | ||
} | ||
if ( | ||
str.lastIndexOf("}") > 0 && | ||
str.slice(str.lastIndexOf("}") + 1).includes("|") | ||
) { | ||
source = str.slice(0, str.indexOf("|", str.lastIndexOf("}") + 1)).trimEnd(); | ||
if (source.trim().startsWith("|")) { | ||
while (source.trim().startsWith("|")) { | ||
source = source.trimStart().slice(1); | ||
} | ||
} | ||
} else { | ||
let lastPipeWasAt = null; | ||
let firstNonPipeNonWhitespaceCharMet = false; | ||
let startFrom = 0; | ||
let endTo = str.length; | ||
let onlyDigitsAndWhitespaceBeenMet = null; | ||
for (let i = 0, len = str.length; i < len; i++) { | ||
if ("0123456789".includes(str[i])) { | ||
if (onlyDigitsAndWhitespaceBeenMet === null && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = true; | ||
} | ||
} else { | ||
if (str[i] !== "|" && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = false; | ||
} | ||
} | ||
if (!str[i + 1] && onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
} | ||
if (str[i] === "|") { | ||
if (onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
break; | ||
} | ||
lastPipeWasAt = i; | ||
onlyDigitsAndWhitespaceBeenMet = null; | ||
} else if (!firstNonPipeNonWhitespaceCharMet && str[i].trim().length) { | ||
firstNonPipeNonWhitespaceCharMet = true; | ||
if (lastPipeWasAt !== null) { | ||
startFrom = lastPipeWasAt + 1; | ||
} | ||
} | ||
} | ||
source = str.slice(startFrom, endTo).trimEnd(); | ||
} | ||
return [from, to, source]; | ||
} | ||
function prepLine(str, progressFn, subsetFrom, subsetTo, generatedCount, pad) { | ||
let currentPercentageDone; | ||
let lastPercentage = 0; | ||
const [from, to, source] = extractFromToSource(str, 0, 500); | ||
const subsetRange = subsetTo - subsetFrom; | ||
let res = ""; | ||
for (let i = from; i <= to; i++) { | ||
let debtPaddingLen = 0; | ||
let startPoint = 0; | ||
for (let y = 0, len = source.length; y < len; y++) { | ||
const charcode = source[y].charCodeAt(0); | ||
if (source[y] === "$" && source[y - 1] === "$" && source[y - 2] === "$") { | ||
const restOfStr = source.slice(y + 1); | ||
let unitFound; | ||
if ( | ||
i === 0 && | ||
units.some(unit => { | ||
if (restOfStr.startsWith(unit)) { | ||
unitFound = unit; | ||
return true; | ||
} | ||
}) && | ||
(source[right(source, y + unitFound.length)] === "{" || | ||
!source[y + unitFound.length + 1].trim().length) | ||
) { | ||
res += `${source.slice(startPoint, y - 2)}${ | ||
pad | ||
? String(i).padStart( | ||
String(to).length - String(i).length + unitFound.length + 1 | ||
) | ||
: i | ||
}`; | ||
startPoint = y + 1 + (unitFound ? unitFound.length : 0); | ||
} else { | ||
let unitThatFollow; | ||
units.some(unit => { | ||
if (source.slice(y + 1).startsWith(unit)) { | ||
unitThatFollow = unit; | ||
return true; | ||
} | ||
}); | ||
if ( | ||
!source[y - 3].trim().length || | ||
padLeftIfTheresOnTheLeft.some(val => | ||
source | ||
.slice(startPoint, y - 2) | ||
.trim() | ||
.endsWith(val) | ||
) | ||
) { | ||
let temp = 0; | ||
if (i === 0) { | ||
units.some(unit => { | ||
if (`${source.slice(startPoint, y - 2)}`.startsWith(unit)) { | ||
temp = unit.length; | ||
} | ||
return true; | ||
}); | ||
} | ||
res += `${source.slice(startPoint + temp, y - 2)}${ | ||
pad | ||
? String(i).padStart( | ||
String(to).length + | ||
(i === 0 && unitThatFollow ? unitThatFollow.length : 0) | ||
) | ||
: i | ||
}`; | ||
} else if ( | ||
!source[y + 1].trim().length || | ||
source[right(source, y)] === "{" | ||
) { | ||
res += `${source.slice(startPoint, y - 2)}${ | ||
pad | ||
? String(i).padEnd( | ||
String(to).length + | ||
(i === 0 && unitThatFollow ? unitThatFollow.length : 0) | ||
) | ||
: i | ||
}`; | ||
} else { | ||
res += `${source.slice(startPoint, y - 2)}${i}`; | ||
if (pad) { | ||
debtPaddingLen = String(to).length - String(i).length; | ||
} | ||
} | ||
startPoint = y + 1; | ||
} | ||
} | ||
if (source[y] === "{" && pad) { | ||
if (debtPaddingLen) { | ||
res += `${source.slice(startPoint, y)}${` `.repeat(debtPaddingLen)}`; | ||
startPoint = y; | ||
debtPaddingLen = 0; | ||
} | ||
} | ||
if (!source[y + 1]) { | ||
let unitFound; | ||
const restOfStr = source.slice(startPoint); | ||
if ( | ||
i === 0 && | ||
units.some(unit => { | ||
if (restOfStr.startsWith(unit)) { | ||
unitFound = unit; | ||
return true; | ||
} | ||
}) | ||
) { | ||
res += `${source.slice(startPoint + unitFound.length)}`; | ||
} else { | ||
res += `${source.slice(startPoint)}`; | ||
} | ||
res += `${i !== to ? "\n" : ""}`; | ||
} | ||
} | ||
generatedCount.count++; | ||
if (typeof progressFn === "function") { | ||
currentPercentageDone = Math.floor( | ||
subsetFrom + (i / (to - from)) * subsetRange | ||
); | ||
if (currentPercentageDone !== lastPercentage) { | ||
lastPercentage = currentPercentageDone; | ||
progressFn(currentPercentageDone); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
function bump(str, thingToBump) { | ||
if (/\.\w/g.test(str)) { | ||
thingToBump.count++; | ||
} | ||
return str; | ||
} | ||
function prepConfig( | ||
str, | ||
progressFn, | ||
progressFrom, | ||
progressTo, | ||
trim = true, | ||
generatedCount, | ||
pad | ||
) { | ||
return trimBlankLinesFromLinesArray( | ||
split(str).map((rowStr, i, arr) => | ||
rowStr.includes("$$$") | ||
? prepLine( | ||
rowStr, | ||
progressFn, | ||
progressFrom + ((progressTo - progressFrom) / arr.length) * i, | ||
progressFrom + ((progressTo - progressFrom) / arr.length) * (i + 1), | ||
generatedCount, | ||
pad | ||
) | ||
: bump(rowStr, generatedCount) | ||
), | ||
trim | ||
).join("\n"); | ||
} | ||
function genAtomic(str, originalOpts) { | ||
function trimIfNeeded(str) { | ||
if (!opts.includeConfig && !opts.includeHeadsAndTails) { | ||
return str; | ||
} | ||
return str.trim(); | ||
} | ||
if (typeof str !== "string") { | ||
throw new Error( | ||
`generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as "${JSON.stringify( | ||
str, | ||
null, | ||
4 | ||
)}" (type ${typeof str})` | ||
); | ||
} | ||
const { CONFIGHEAD, CONFIGTAIL, CONTENTHEAD, CONTENTTAIL } = headsAndTails; | ||
const defaults = { | ||
includeConfig: true, | ||
includeHeadsAndTails: true, | ||
pad: true, | ||
configOverride: null, | ||
reportProgressFunc: null, | ||
reportProgressFuncFrom: 0, | ||
reportProgressFuncTo: 100 | ||
}; | ||
const generatedCount = { | ||
count: 0 | ||
}; | ||
const opts = Object.assign({}, defaults, originalOpts); | ||
if (opts.includeConfig && !opts.includeHeadsAndTails) { | ||
opts.includeHeadsAndTails = true; | ||
} | ||
if ( | ||
(!opts.configOverride && | ||
!str.includes("$$$") && | ||
!str.includes(CONFIGHEAD) && | ||
!str.includes(CONFIGTAIL) && | ||
!str.includes(CONTENTHEAD) && | ||
!str.includes(CONTENTTAIL)) || | ||
(isStr(opts.configOverride) && | ||
!opts.configOverride.includes("$$$") && | ||
!opts.configOverride.includes(CONFIGHEAD) && | ||
!opts.configOverride.includes(CONFIGTAIL) && | ||
!opts.configOverride.includes(CONTENTHEAD) && | ||
!opts.configOverride.includes(CONTENTTAIL)) | ||
) { | ||
return { | ||
log: { | ||
count: 0 | ||
}, | ||
result: str | ||
}; | ||
} | ||
let frontPart = ""; | ||
let endPart = ""; | ||
let [extractedConfig, rawContentAbove, rawContentBelow] = extractConfig( | ||
opts.configOverride ? opts.configOverride : str | ||
); | ||
if (!isStr(extractedConfig) || !extractedConfig.trim().length) { | ||
@@ -403,3 +585,3 @@ return { | ||
if (str.includes(CONFIGHEAD)) { | ||
if (left(str, str.indexOf(CONFIGHEAD))) { | ||
if (left(str, str.indexOf(CONFIGHEAD)) != null) { | ||
let sliceUpTo = str.indexOf(CONFIGHEAD); | ||
@@ -412,8 +594,11 @@ if ( | ||
} | ||
frontPart = `${str.slice(0, sliceUpTo)}${ | ||
str[right(str, sliceUpTo - 1)] === "/" && | ||
str[right(str, right(str, sliceUpTo - 1))] === "*" | ||
? "" | ||
: "/* " | ||
}${frontPart}`; | ||
let putInFront = "/* "; | ||
if ( | ||
(str[right(str, sliceUpTo - 1)] === "/" && | ||
str[right(str, right(str, sliceUpTo - 1))] === "*") || | ||
frontPart.trim().startsWith("/*") | ||
) { | ||
putInFront = ""; | ||
} | ||
frontPart = `${str.slice(0, sliceUpTo)}${putInFront}${frontPart}`; | ||
} | ||
@@ -454,2 +639,12 @@ } | ||
} | ||
const slicedFrom = str.slice(sliceFrom); | ||
if (slicedFrom.length && slicedFrom.includes(CONTENTTAIL)) { | ||
sliceFrom = str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if ( | ||
str[right(str, sliceFrom)] === "*" && | ||
str[right(str, right(str, sliceFrom))] === "/" | ||
) { | ||
sliceFrom = right(str, right(str, sliceFrom)) + 1; | ||
} | ||
} | ||
endPart = `${endPart}${ | ||
@@ -496,2 +691,2 @@ str[sliceFrom] && right(str, sliceFrom - 1) ? str.slice(sliceFrom) : "" | ||
export { genAtomic, headsAndTails, version }; | ||
export { extractFromToSource, genAtomic, headsAndTails, version }; |
/** | ||
* generate-atomic-css | ||
* Generate Atomic CSS | ||
* Version: 1.1.0 | ||
* Version: 1.2.0 | ||
* Author: Roy Revelt, Codsen Ltd | ||
@@ -10,2 +10,2 @@ * License: MIT | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).generateAtomicCss={})}(this,function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n="[object Object]";var r,o,i=Function.prototype,c=Object.prototype,u=i.toString,a=c.hasOwnProperty,l=u.call(Object),f=c.toString,s=(r=Object.getPrototypeOf,o=Object,function(t){return r(o(t))});var h=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||f.call(t)!=n||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=s(t);if(null===e)return!0;var r=a.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&u.call(r)==l},d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(t,e){t(e={exports:{}},e.exports)}(function(t,e){var n=200,r="__lodash_hash_undefined__",o=9007199254740991,i="[object Arguments]",c="[object Boolean]",u="[object Date]",a="[object Function]",l="[object GeneratorFunction]",f="[object Map]",s="[object Number]",h="[object Object]",p="[object RegExp]",g="[object Set]",v="[object String]",y="[object Symbol]",_="[object ArrayBuffer]",b="[object DataView]",O="[object Float32Array]",m="[object Float64Array]",j="[object Int8Array]",w="[object Int16Array]",x="[object Int32Array]",A="[object Uint8Array]",T="[object Uint8ClampedArray]",E="[object Uint16Array]",C="[object Uint32Array]",S=/\w*$/,$=/^\[object .+?Constructor\]$/,N=/^(?:0|[1-9]\d*)$/,I={};I[i]=I["[object Array]"]=I[_]=I[b]=I[c]=I[u]=I[O]=I[m]=I[j]=I[w]=I[x]=I[f]=I[s]=I[h]=I[p]=I[g]=I[v]=I[y]=I[A]=I[T]=I[E]=I[C]=!0,I["[object Error]"]=I[a]=I["[object WeakMap]"]=!1;var F="object"==typeof d&&d&&d.Object===Object&&d,P="object"==typeof self&&self&&self.Object===Object&&self,R=F||P||Function("return this")(),W=e&&!e.nodeType&&e,D=W&&t&&!t.nodeType&&t,H=D&&D.exports===W;function M(t,e){return t.set(e[0],e[1]),t}function G(t,e){return t.add(e),t}function L(t,e,n,r){var o=-1,i=t?t.length:0;for(r&&i&&(n=t[++o]);++o<i;)n=e(n,t[o],o,t);return n}function k(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function B(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function U(t,e){return function(n){return t(e(n))}}function z(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var V,J=Array.prototype,q=Function.prototype,K=Object.prototype,Q=R["__core-js_shared__"],X=(V=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+V:"",Y=q.toString,Z=K.hasOwnProperty,tt=K.toString,et=RegExp("^"+Y.call(Z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),nt=H?R.Buffer:void 0,rt=R.Symbol,ot=R.Uint8Array,it=U(Object.getPrototypeOf,Object),ct=Object.create,ut=K.propertyIsEnumerable,at=J.splice,lt=Object.getOwnPropertySymbols,ft=nt?nt.isBuffer:void 0,st=U(Object.keys,Object),ht=Dt(R,"DataView"),dt=Dt(R,"Map"),pt=Dt(R,"Promise"),gt=Dt(R,"Set"),vt=Dt(R,"WeakMap"),yt=Dt(Object,"create"),_t=kt(ht),bt=kt(dt),Ot=kt(pt),mt=kt(gt),jt=kt(vt),wt=rt?rt.prototype:void 0,xt=wt?wt.valueOf:void 0;function At(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Tt(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Et(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Ct(t){this.__data__=new Tt(t)}function St(t,e){var n=Ut(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&zt(t)}(t)&&Z.call(t,"callee")&&(!ut.call(t,"callee")||tt.call(t)==i)}(t)?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],r=n.length,o=!!r;for(var c in t)!e&&!Z.call(t,c)||o&&("length"==c||Gt(c,r))||n.push(c);return n}function $t(t,e,n){var r=t[e];Z.call(t,e)&&Bt(r,n)&&(void 0!==n||e in t)||(t[e]=n)}function Nt(t,e){for(var n=t.length;n--;)if(Bt(t[n][0],e))return n;return-1}function It(t,e,n,r,o,d,$){var N;if(r&&(N=d?r(t,o,d,$):r(t)),void 0!==N)return N;if(!qt(t))return t;var F=Ut(t);if(F){if(N=function(t){var e=t.length,n=t.constructor(e);e&&"string"==typeof t[0]&&Z.call(t,"index")&&(n.index=t.index,n.input=t.input);return n}(t),!e)return function(t,e){var n=-1,r=t.length;e||(e=Array(r));for(;++n<r;)e[n]=t[n];return e}(t,N)}else{var P=Mt(t),R=P==a||P==l;if(Vt(t))return function(t,e){if(e)return t.slice();var n=new t.constructor(t.length);return t.copy(n),n}(t,e);if(P==h||P==i||R&&!d){if(k(t))return d?t:{};if(N=function(t){return"function"!=typeof t.constructor||Lt(t)?{}:(e=it(t),qt(e)?ct(e):{});var e}(R?{}:t),!e)return function(t,e){return Rt(t,Ht(t),e)}(t,function(t,e){return t&&Rt(e,Kt(e),t)}(N,t))}else{if(!I[P])return d?t:{};N=function(t,e,n,r){var o=t.constructor;switch(e){case _:return Pt(t);case c:case u:return new o(+t);case b:return function(t,e){var n=e?Pt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,r);case O:case m:case j:case w:case x:case A:case T:case E:case C:return function(t,e){var n=e?Pt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}(t,r);case f:return function(t,e,n){return L(e?n(B(t),!0):B(t),M,new t.constructor)}(t,r,n);case s:case v:return new o(t);case p:return(l=new(a=t).constructor(a.source,S.exec(a))).lastIndex=a.lastIndex,l;case g:return function(t,e,n){return L(e?n(z(t),!0):z(t),G,new t.constructor)}(t,r,n);case y:return i=t,xt?Object(xt.call(i)):{}}var i;var a,l}(t,P,It,e)}}$||($=new Ct);var W=$.get(t);if(W)return W;if($.set(t,N),!F)var D=n?function(t){return function(t,e,n){var r=e(t);return Ut(t)?r:function(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}(r,n(t))}(t,Kt,Ht)}(t):Kt(t);return function(t,e){for(var n=-1,r=t?t.length:0;++n<r&&!1!==e(t[n],n,t););}(D||t,function(o,i){D&&(o=t[i=o]),$t(N,i,It(o,e,n,r,i,t,$))}),N}function Ft(t){return!(!qt(t)||function(t){return!!X&&X in t}(t))&&(Jt(t)||k(t)?et:$).test(kt(t))}function Pt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Rt(t,e,n,r){n||(n={});for(var o=-1,i=e.length;++o<i;){var c=e[o],u=r?r(n[c],t[c],c,n,t):void 0;$t(n,c,void 0===u?t[c]:u)}return n}function Wt(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function Dt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Ft(n)?n:void 0}At.prototype.clear=function(){this.__data__=yt?yt(null):{}},At.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},At.prototype.get=function(t){var e=this.__data__;if(yt){var n=e[t];return n===r?void 0:n}return Z.call(e,t)?e[t]:void 0},At.prototype.has=function(t){var e=this.__data__;return yt?void 0!==e[t]:Z.call(e,t)},At.prototype.set=function(t,e){return this.__data__[t]=yt&&void 0===e?r:e,this},Tt.prototype.clear=function(){this.__data__=[]},Tt.prototype.delete=function(t){var e=this.__data__,n=Nt(e,t);return!(n<0||(n==e.length-1?e.pop():at.call(e,n,1),0))},Tt.prototype.get=function(t){var e=this.__data__,n=Nt(e,t);return n<0?void 0:e[n][1]},Tt.prototype.has=function(t){return Nt(this.__data__,t)>-1},Tt.prototype.set=function(t,e){var n=this.__data__,r=Nt(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},Et.prototype.clear=function(){this.__data__={hash:new At,map:new(dt||Tt),string:new At}},Et.prototype.delete=function(t){return Wt(this,t).delete(t)},Et.prototype.get=function(t){return Wt(this,t).get(t)},Et.prototype.has=function(t){return Wt(this,t).has(t)},Et.prototype.set=function(t,e){return Wt(this,t).set(t,e),this},Ct.prototype.clear=function(){this.__data__=new Tt},Ct.prototype.delete=function(t){return this.__data__.delete(t)},Ct.prototype.get=function(t){return this.__data__.get(t)},Ct.prototype.has=function(t){return this.__data__.has(t)},Ct.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Tt){var o=r.__data__;if(!dt||o.length<n-1)return o.push([t,e]),this;r=this.__data__=new Et(o)}return r.set(t,e),this};var Ht=lt?U(lt,Object):function(){return[]},Mt=function(t){return tt.call(t)};function Gt(t,e){return!!(e=null==e?o:e)&&("number"==typeof t||N.test(t))&&t>-1&&t%1==0&&t<e}function Lt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||K)}function kt(t){if(null!=t){try{return Y.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Bt(t,e){return t===e||t!=t&&e!=e}(ht&&Mt(new ht(new ArrayBuffer(1)))!=b||dt&&Mt(new dt)!=f||pt&&"[object Promise]"!=Mt(pt.resolve())||gt&&Mt(new gt)!=g||vt&&"[object WeakMap]"!=Mt(new vt))&&(Mt=function(t){var e=tt.call(t),n=e==h?t.constructor:void 0,r=n?kt(n):void 0;if(r)switch(r){case _t:return b;case bt:return f;case Ot:return"[object Promise]";case mt:return g;case jt:return"[object WeakMap]"}return e});var Ut=Array.isArray;function zt(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=o}(t.length)&&!Jt(t)}var Vt=ft||function(){return!1};function Jt(t){var e=qt(t)?tt.call(t):"";return e==a||e==l}function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Kt(t){return zt(t)?St(t):function(t){if(!Lt(t))return st(t);var e=[];for(var n in Object(t))Z.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}t.exports=function(t){return It(t,!0,!0)}});function p(t){const e={value:t,hungry:!1,optional:!1};return(e.value.endsWith("?*")||e.value.endsWith("*?"))&&e.value.length>2?(e.value=e.value.slice(0,e.value.length-2),e.optional=!0,e.hungry=!0):e.value.endsWith("?")&&e.value.length>1?(e.value=e.value.slice(0,e.value.length-1),e.optional=!0):e.value.endsWith("*")&&e.value.length>1&&(e.value=e.value.slice(0,e.value.length-1),e.hungry=!0),e}function g(t,e){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),!t[e+1])return null;if(t[e+1]&&t[e+1].trim().length)return e+1;if(t[e+2]&&t[e+2].trim().length)return e+2;for(let n=e+1,r=t.length;n<r;n++)if(t[n].trim().length)return n;return null}function v(t,e){if("string"!=typeof t||!t.length)return null;if(e&&"number"==typeof e||(e=0),e<1)return null;if(t[e-1]&&t[e-1].trim().length)return e-1;if(t[e-2]&&t[e-2].trim().length)return e-2;for(let n=e;n--;)if(t[n]&&t[n].trim().length)return n;return null}function y(t,e,n,r,o){if("string"!=typeof e||!e.length)return null;if(n&&"number"==typeof n||(n=0),"right"===t&&!e[n+1]||"left"===t&&!e[n-1])return null;let i=n;const c=[];let u,a,l,f=0;for(;f<o.length;){if("string"!=typeof o[f]||!o[f].length){f++;continue}const{value:n,optional:s,hungry:h}=p(o[f]),d="right"===t?g(e,i):v(e,i);if(!(r.i&&e[d].toLowerCase()===n.toLowerCase()||!r.i&&e[d]===n)){if(s){f++;continue}if(l){f++,l=void 0;continue}return null}{const o="right"===t?g(e,d):v(e,d);h&&(r.i&&e[o].toLowerCase()===n.toLowerCase()||!r.i&&e[o]===n)?l=!0:f++,"right"===t&&d>i+1?c.push([i+1,d]):"left"===t&&d<i-1&&c.unshift([d+1,i]),i=d,"right"===t?(void 0===u&&(u=d),a=d):(void 0===a&&(a=d),u=d)}}return void 0===u?null:{gaps:c,leftmostChar:u,rightmostChar:a}}function _(t,e,...n){if(!n.length)return v(t,e);const r={i:!1};let o;return y("left",t,e,o=h(n[0])?Object.assign({},r,n.shift()):r,Array.from(n).reverse())}function b(t,e,...n){if(!n.length)return g(t,e);const r={i:!1};let o;return y("right",t,e,o=h(n[0])?Object.assign({},r,n.shift()):r,n)}var O=(t,e)=>{if(e=Object.assign({preserveNewLines:!1},e),"string"!=typeof t)throw new TypeError(`Expected input to be of type \`string\`, got \`${typeof t}\``);if(!e.preserveNewlines)return t.split(/\r?\n/);const n=t.split(/(\r?\n)/),r=[];for(let t=0;t<n.length;t+=2)r.push(n[t]+(n[t+1]||""));return r},m=Array.isArray;function j(t){return"string"==typeof t}function w(t,e,n,r){var o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],i=arguments.length>5?arguments[5]:void 0,c=arguments.length>6?arguments[6]:void 0;return function(t){if(arguments.length>1&&void 0!==arguments[1]&&!arguments[1])return t;var e=Array.from(t);if(e.length&&j(e[0])&&!e[0].trim().length)do{e.shift()}while(!e[0].trim().length);if(e.length&&j(e[e.length-1])&&!e[e.length-1].trim().length)do{e.pop()}while(!e[e.length-1].trim().length);return e}(O(t).map(function(t,o,u){return t.includes("$$$")?function(t,e,n,r,o,i){var c,u=0,a=t.split("|").filter(function(t){return t.length}),l=0,f=500;a[1]&&(a[2]?(l=Number.parseInt(a[1].trim()),f=Number.parseInt(a[2].trim())):f=Number.parseInt(a[1].trim()));for(var s="",h=r-n,d=function(t){o.count++;var r=a[0],d=/(\$\$\$(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax))/g,p=/(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax)/g,g=/\$\$\$/g;if(i){var v=r.match(d);m(v)&&v.length&&v.forEach(function(e){r=r.replace(e,"".concat(t).concat(0===t?"":p.exec(e)[0]).padStart(e.length-3+String(f).length))}),s+="".concat(t===l?"":"\n").concat(r.replace(/\$\$\$(?=[{ ])/g,"".concat(t).padEnd(String(f).length)).replace(g,t)).trimEnd()}else s+=0===t?"".concat(t===l?"":"\n").concat(r.replace(d,t).replace(g,t).trimEnd()):"".concat(t===l?"":"\n").concat(r.replace(g,t).trimEnd());"function"==typeof e&&(c=Math.floor(n+t/(f-l)*h))!==u&&(u=c,e(c))},p=l;p<=f;p++)d(p);return s}(t,e,n+(r-n)/u.length*o,n+(r-n)/u.length*(o+1),i,c):t}),o).join("\n")}var x={CONFIGHEAD:"GENERATE-ATOMIC-CSS-CONFIG-STARTS",CONFIGTAIL:"GENERATE-ATOMIC-CSS-CONFIG-ENDS",CONTENTHEAD:"GENERATE-ATOMIC-CSS-CONTENT-STARTS",CONTENTTAIL:"GENERATE-ATOMIC-CSS-CONTENT-ENDS"};t.genAtomic=function(t,n){if("string"!=typeof t)throw new Error('generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as "'.concat(JSON.stringify(t,null,4),'" (type ').concat(e(t),")"));var r=x.CONFIGHEAD,o=x.CONFIGTAIL,i=x.CONTENTHEAD,c=x.CONTENTTAIL,u={count:0},a=Object.assign({},{includeConfig:!0,includeHeadsAndTails:!0,pad:!0,configOverride:null,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100},n);if(a.includeConfig&&!a.includeHeadsAndTails&&(a.includeHeadsAndTails=!0),!a.configOverride&&!t.includes("$$$")&&!t.includes(r)&&!t.includes(o)&&!t.includes(i)&&!t.includes(c)||j(a.configOverride)&&!a.configOverride.includes("$$$")&&!a.configOverride.includes(r)&&!a.configOverride.includes(o)&&!a.configOverride.includes(i)&&!a.configOverride.includes(c))return{log:{count:0},result:t};var l,f="",s="",h="",d="";if(a.configOverride)l=a.configOverride;else if(t.includes(r)&&t.includes(o)){if(-1!==t.indexOf(o)&&-1!==t.indexOf(i)&&t.indexOf(o)>t.indexOf(i))throw new Error("generate-atomic-css: [THROW_ID_02] Config heads are after config tails!");var p=t.indexOf(r)+r.length,y=t.indexOf(o);if("*"===t[g(t,p)]&&"/"===t[g(t,g(t,p))]&&(p=g(t,g(t,p))+1),"*"===t[v(t,y)]&&"/"===t[v(t,v(t,y))]&&(y=v(t,v(t,y))),!j(l=t.slice(p,y).trim())||!l.trim().length)return{log:{count:0},result:""}}else if(t.includes(r)&&!t.includes(o)&&t.includes(i)){if(t.indexOf(r)>t.indexOf(i))throw new Error("generate-atomic-css: [THROW_ID_03] Config heads are after content heads!");l=t.slice(t.indexOf(r)+r.length,t.indexOf(i))}else if(t.includes(r)||t.includes(o)||!t.includes(i)&&!t.includes(c)){for(var O=new RegExp("(\\/\\s*\\*\\s*)*".concat(i,"(\\s*\\*\\s*\\/)*")),m=new RegExp("(\\/\\s*\\*\\s*)*".concat(c,"(\\s*\\*\\s*\\/)*")),A=!1,T=[],E=[],C=t.split("\n").filter(function(t){return!!A||(t.includes("$$$")?(A=!0,!0):(T.push(t),!1))}),S=C.length;S--&&!C[S].includes("$$$");)E.unshift(C.pop());l=C.join("\n").replace(O,"").replace(m,""),T.length&&(h="".concat(T.join("\n"),"\n")),E.length&&(d="\n".concat(E.join("\n")))}else if((l=t).includes(i)){if(v(t,l.indexOf(i))){var $=l.indexOf(i);_(t,$,"/","*")&&($=_(t,$,"/","*").leftmostChar),h=0===$?"":t.slice(0,$)}var N=l.indexOf(i)+i.length;b(l,N-1,"*","/")&&(N=b(l,N-1,"*","/").rightmostChar+1);var I=null;if(t.includes(c)){I=t.indexOf(c),"*"===t[v(t,I)]&&"/"===t[v(t,v(t,I))]&&(I=v(t,v(t,I)));var F=t.indexOf(c)+c.length;"*"===t[g(t,F-1)]&&"/"===t[g(t,g(t,F-1))]&&(F=g(t,g(t,F-1))+1),g(t,F)&&(d=t.slice(F))}l=I?l.slice(N,I).trim():l.slice(N).trim()}else if(l.includes(c)){var P,R=[],W=!1,D=(l=l.split("\n").filter(function(t){return t.includes("$$$")||W?!!W||(W=!0,!0):(W||R.push(t),!1)}).join("\n")).indexOf(c);_(l,D,"/","*")&&(D=_(l,D,"/","*").leftmostChar),l=l.slice(0,D).trim(),R.length&&(h="".concat(R.join("\n"),"\n")),g(t,t.indexOf(c)+c.length)&&(P=t.indexOf(c)+c.length,"*"===t[g(t,P)]&&"/"===t[g(t,g(t,P))]&&(P=g(t,g(t,P))+1,g(t,P)&&(d=t.slice(P))))}if(!j(l)||!l.trim().length)return{log:{count:0},result:""};if((a.includeConfig||a.includeHeadsAndTails)&&(f="".concat(i," */\n"),a.includeConfig||(f="/* ".concat(f)),s="\n/* ".concat(c," */")),a.includeConfig&&(f="/* ".concat(r,"\n").concat(l.trim(),"\n").concat(o,"\n").concat(f)),t.includes(r)&&v(t,t.indexOf(r))){var H=t.indexOf(r);"*"===t[v(t,H)]&&"/"===t[v(t,v(t,H))]&&(H=v(t,v(t,H))),f="".concat(t.slice(0,H)).concat("/"===t[g(t,H-1)]&&"*"===t[g(t,g(t,H-1))]?"":"/* ").concat(f)}if(t.includes(o)&&g(t,t.indexOf(o)+o.length)){var M=t.indexOf(o)+o.length;if("*"===t[g(t,t.indexOf(o)+o.length)]&&"/"===t[g(t,g(t,t.indexOf(o)+o.length))]&&(M=g(t,g(t,t.indexOf(o)+o.length))+1),t.slice(g(t,M-1)).startsWith(i)){var G=g(t,M);"*"===t[g(t,(M=G+i.length)-1)]&&"/"===t[g(t,g(t,M-1))]&&(M=g(t,g(t,M-1))+1),t.includes(c)&&(M=t.indexOf(c)+c.length,"*"===t[g(t,M)]&&"/"===t[g(t,g(t,M))]&&(M=g(t,g(t,M))+1))}s="".concat(s).concat(t[M]&&g(t,M-1)?t.slice(M):"")}if(j(h)&&(f="".concat(h).concat(f)),j(d)){if(d.trim().endsWith("/*")&&!d.trim().startsWith("*/")){var L="";j(d)&&d[0]&&!d[0].trim().length&&(L=d.slice(0,g(d,0))),d="".concat(L,"/* ").concat(d.trim())}s="".concat(s).concat(d)}var k="".concat(function(t){return a.includeConfig||a.includeHeadsAndTails?t.trim():t}("".concat(f).concat(w(l,a.reportProgressFunc,a.reportProgressFuncFrom,a.reportProgressFuncTo,!0,u,a.pad)).concat(s)),"\n");return{log:{count:u.count},result:k}},t.headsAndTails=x,t.version="1.1.0",Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).generateAtomicCss={})}(this,function(t){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function e(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var e=[],r=!0,i=!1,o=void 0;try{for(var c,u=t[Symbol.iterator]();!(r=(c=u.next()).done)&&(e.push(c.value),!n||e.length!==n);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return e}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r="[object Object]";var i,o,c=Function.prototype,u=Object.prototype,l=c.toString,a=u.hasOwnProperty,s=l.call(Object),f=u.toString,h=(i=Object.getPrototypeOf,o=Object,function(t){return i(o(t))});var g=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||f.call(t)!=r||function(t){var n=!1;if(null!=t&&"function"!=typeof t.toString)try{n=!!(t+"")}catch(t){}return n}(t))return!1;var n=h(t);if(null===n)return!0;var e=a.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&l.call(e)==s},d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(t,n){t(n={exports:{}},n.exports)}(function(t,n){var e=200,r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",c="[object Boolean]",u="[object Date]",l="[object Function]",a="[object GeneratorFunction]",s="[object Map]",f="[object Number]",h="[object Object]",g="[object RegExp]",p="[object Set]",v="[object String]",y="[object Symbol]",b="[object ArrayBuffer]",m="[object DataView]",O="[object Float32Array]",_="[object Float64Array]",j="[object Int8Array]",w="[object Int16Array]",x="[object Int32Array]",A="[object Uint8Array]",T="[object Uint8ClampedArray]",S="[object Uint16Array]",E="[object Uint32Array]",C=/\w*$/,I=/^\[object .+?Constructor\]$/,N=/^(?:0|[1-9]\d*)$/,$={};$[o]=$["[object Array]"]=$[b]=$[m]=$[c]=$[u]=$[O]=$[_]=$[j]=$[w]=$[x]=$[s]=$[f]=$[h]=$[g]=$[p]=$[v]=$[y]=$[A]=$[T]=$[S]=$[E]=!0,$["[object Error]"]=$[l]=$["[object WeakMap]"]=!1;var F="object"==typeof d&&d&&d.Object===Object&&d,W="object"==typeof self&&self&&self.Object===Object&&self,P=F||W||Function("return this")(),D=n&&!n.nodeType&&n,H=D&&t&&!t.nodeType&&t,R=H&&H.exports===D;function G(t,n){return t.set(n[0],n[1]),t}function L(t,n){return t.add(n),t}function M(t,n,e,r){var i=-1,o=t?t.length:0;for(r&&o&&(e=t[++i]);++i<o;)e=n(e,t[i],i,t);return e}function k(t){var n=!1;if(null!=t&&"function"!=typeof t.toString)try{n=!!(t+"")}catch(t){}return n}function B(t){var n=-1,e=Array(t.size);return t.forEach(function(t,r){e[++n]=[r,t]}),e}function U(t,n){return function(e){return t(n(e))}}function z(t){var n=-1,e=Array(t.size);return t.forEach(function(t){e[++n]=t}),e}var V,J=Array.prototype,q=Function.prototype,K=Object.prototype,Q=P["__core-js_shared__"],X=(V=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+V:"",Y=q.toString,Z=K.hasOwnProperty,tt=K.toString,nt=RegExp("^"+Y.call(Z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),et=R?P.Buffer:void 0,rt=P.Symbol,it=P.Uint8Array,ot=U(Object.getPrototypeOf,Object),ct=Object.create,ut=K.propertyIsEnumerable,lt=J.splice,at=Object.getOwnPropertySymbols,st=et?et.isBuffer:void 0,ft=U(Object.keys,Object),ht=Ht(P,"DataView"),gt=Ht(P,"Map"),dt=Ht(P,"Promise"),pt=Ht(P,"Set"),vt=Ht(P,"WeakMap"),yt=Ht(Object,"create"),bt=kt(ht),mt=kt(gt),Ot=kt(dt),_t=kt(pt),jt=kt(vt),wt=rt?rt.prototype:void 0,xt=wt?wt.valueOf:void 0;function At(t){var n=-1,e=t?t.length:0;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Tt(t){var n=-1,e=t?t.length:0;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function St(t){var n=-1,e=t?t.length:0;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Et(t){this.__data__=new Tt(t)}function Ct(t,n){var e=Ut(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&zt(t)}(t)&&Z.call(t,"callee")&&(!ut.call(t,"callee")||tt.call(t)==o)}(t)?function(t,n){for(var e=-1,r=Array(t);++e<t;)r[e]=n(e);return r}(t.length,String):[],r=e.length,i=!!r;for(var c in t)!n&&!Z.call(t,c)||i&&("length"==c||Lt(c,r))||e.push(c);return e}function It(t,n,e){var r=t[n];Z.call(t,n)&&Bt(r,e)&&(void 0!==e||n in t)||(t[n]=e)}function Nt(t,n){for(var e=t.length;e--;)if(Bt(t[e][0],n))return e;return-1}function $t(t,n,e,r,i,d,I){var N;if(r&&(N=d?r(t,i,d,I):r(t)),void 0!==N)return N;if(!qt(t))return t;var F=Ut(t);if(F){if(N=function(t){var n=t.length,e=t.constructor(n);n&&"string"==typeof t[0]&&Z.call(t,"index")&&(e.index=t.index,e.input=t.input);return e}(t),!n)return function(t,n){var e=-1,r=t.length;n||(n=Array(r));for(;++e<r;)n[e]=t[e];return n}(t,N)}else{var W=Gt(t),P=W==l||W==a;if(Vt(t))return function(t,n){if(n)return t.slice();var e=new t.constructor(t.length);return t.copy(e),e}(t,n);if(W==h||W==o||P&&!d){if(k(t))return d?t:{};if(N=function(t){return"function"!=typeof t.constructor||Mt(t)?{}:(n=ot(t),qt(n)?ct(n):{});var n}(P?{}:t),!n)return function(t,n){return Pt(t,Rt(t),n)}(t,function(t,n){return t&&Pt(n,Kt(n),t)}(N,t))}else{if(!$[W])return d?t:{};N=function(t,n,e,r){var i=t.constructor;switch(n){case b:return Wt(t);case c:case u:return new i(+t);case m:return function(t,n){var e=n?Wt(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}(t,r);case O:case _:case j:case w:case x:case A:case T:case S:case E:return function(t,n){var e=n?Wt(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}(t,r);case s:return function(t,n,e){return M(n?e(B(t),!0):B(t),G,new t.constructor)}(t,r,e);case f:case v:return new i(t);case g:return(a=new(l=t).constructor(l.source,C.exec(l))).lastIndex=l.lastIndex,a;case p:return function(t,n,e){return M(n?e(z(t),!0):z(t),L,new t.constructor)}(t,r,e);case y:return o=t,xt?Object(xt.call(o)):{}}var o;var l,a}(t,W,$t,n)}}I||(I=new Et);var D=I.get(t);if(D)return D;if(I.set(t,N),!F)var H=e?function(t){return function(t,n,e){var r=n(t);return Ut(t)?r:function(t,n){for(var e=-1,r=n.length,i=t.length;++e<r;)t[i+e]=n[e];return t}(r,e(t))}(t,Kt,Rt)}(t):Kt(t);return function(t,n){for(var e=-1,r=t?t.length:0;++e<r&&!1!==n(t[e],e,t););}(H||t,function(i,o){H&&(i=t[o=i]),It(N,o,$t(i,n,e,r,o,t,I))}),N}function Ft(t){return!(!qt(t)||function(t){return!!X&&X in t}(t))&&(Jt(t)||k(t)?nt:I).test(kt(t))}function Wt(t){var n=new t.constructor(t.byteLength);return new it(n).set(new it(t)),n}function Pt(t,n,e,r){e||(e={});for(var i=-1,o=n.length;++i<o;){var c=n[i],u=r?r(e[c],t[c],c,e,t):void 0;It(e,c,void 0===u?t[c]:u)}return e}function Dt(t,n){var e,r,i=t.__data__;return("string"==(r=typeof(e=n))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==e:null===e)?i["string"==typeof n?"string":"hash"]:i.map}function Ht(t,n){var e=function(t,n){return null==t?void 0:t[n]}(t,n);return Ft(e)?e:void 0}At.prototype.clear=function(){this.__data__=yt?yt(null):{}},At.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},At.prototype.get=function(t){var n=this.__data__;if(yt){var e=n[t];return e===r?void 0:e}return Z.call(n,t)?n[t]:void 0},At.prototype.has=function(t){var n=this.__data__;return yt?void 0!==n[t]:Z.call(n,t)},At.prototype.set=function(t,n){return this.__data__[t]=yt&&void 0===n?r:n,this},Tt.prototype.clear=function(){this.__data__=[]},Tt.prototype.delete=function(t){var n=this.__data__,e=Nt(n,t);return!(e<0||(e==n.length-1?n.pop():lt.call(n,e,1),0))},Tt.prototype.get=function(t){var n=this.__data__,e=Nt(n,t);return e<0?void 0:n[e][1]},Tt.prototype.has=function(t){return Nt(this.__data__,t)>-1},Tt.prototype.set=function(t,n){var e=this.__data__,r=Nt(e,t);return r<0?e.push([t,n]):e[r][1]=n,this},St.prototype.clear=function(){this.__data__={hash:new At,map:new(gt||Tt),string:new At}},St.prototype.delete=function(t){return Dt(this,t).delete(t)},St.prototype.get=function(t){return Dt(this,t).get(t)},St.prototype.has=function(t){return Dt(this,t).has(t)},St.prototype.set=function(t,n){return Dt(this,t).set(t,n),this},Et.prototype.clear=function(){this.__data__=new Tt},Et.prototype.delete=function(t){return this.__data__.delete(t)},Et.prototype.get=function(t){return this.__data__.get(t)},Et.prototype.has=function(t){return this.__data__.has(t)},Et.prototype.set=function(t,n){var r=this.__data__;if(r instanceof Tt){var i=r.__data__;if(!gt||i.length<e-1)return i.push([t,n]),this;r=this.__data__=new St(i)}return r.set(t,n),this};var Rt=at?U(at,Object):function(){return[]},Gt=function(t){return tt.call(t)};function Lt(t,n){return!!(n=null==n?i:n)&&("number"==typeof t||N.test(t))&&t>-1&&t%1==0&&t<n}function Mt(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||K)}function kt(t){if(null!=t){try{return Y.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Bt(t,n){return t===n||t!=t&&n!=n}(ht&&Gt(new ht(new ArrayBuffer(1)))!=m||gt&&Gt(new gt)!=s||dt&&"[object Promise]"!=Gt(dt.resolve())||pt&&Gt(new pt)!=p||vt&&"[object WeakMap]"!=Gt(new vt))&&(Gt=function(t){var n=tt.call(t),e=n==h?t.constructor:void 0,r=e?kt(e):void 0;if(r)switch(r){case bt:return m;case mt:return s;case Ot:return"[object Promise]";case _t:return p;case jt:return"[object WeakMap]"}return n});var Ut=Array.isArray;function zt(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=i}(t.length)&&!Jt(t)}var Vt=st||function(){return!1};function Jt(t){var n=qt(t)?tt.call(t):"";return n==l||n==a}function qt(t){var n=typeof t;return!!t&&("object"==n||"function"==n)}function Kt(t){return zt(t)?Ct(t):function(t){if(!Mt(t))return ft(t);var n=[];for(var e in Object(t))Z.call(t,e)&&"constructor"!=e&&n.push(e);return n}(t)}t.exports=function(t){return $t(t,!0,!0)}});function p(t){const n={value:t,hungry:!1,optional:!1};return(n.value.endsWith("?*")||n.value.endsWith("*?"))&&n.value.length>2?(n.value=n.value.slice(0,n.value.length-2),n.optional=!0,n.hungry=!0):n.value.endsWith("?")&&n.value.length>1?(n.value=n.value.slice(0,n.value.length-1),n.optional=!0):n.value.endsWith("*")&&n.value.length>1&&(n.value=n.value.slice(0,n.value.length-1),n.hungry=!0),n}function v(t,n){if("string"!=typeof t||!t.length)return null;if(n&&"number"==typeof n||(n=0),!t[n+1])return null;if(t[n+1]&&t[n+1].trim().length)return n+1;if(t[n+2]&&t[n+2].trim().length)return n+2;for(let e=n+1,r=t.length;e<r;e++)if(t[e].trim().length)return e;return null}function y(t,n){if("string"!=typeof t||!t.length)return null;if(n&&"number"==typeof n||(n=0),n<1)return null;if(t[n-1]&&t[n-1].trim().length)return n-1;if(t[n-2]&&t[n-2].trim().length)return n-2;for(let e=n;e--;)if(t[e]&&t[e].trim().length)return e;return null}function b(t,n,e,r,i){if("string"!=typeof n||!n.length)return null;if(e&&"number"==typeof e||(e=0),"right"===t&&!n[e+1]||"left"===t&&!n[e-1])return null;let o=e;const c=[];let u,l,a,s=0;for(;s<i.length;){if("string"!=typeof i[s]||!i[s].length){s++;continue}const{value:e,optional:f,hungry:h}=p(i[s]),g="right"===t?v(n,o):y(n,o);if(!(r.i&&n[g].toLowerCase()===e.toLowerCase()||!r.i&&n[g]===e)){if(f){s++;continue}if(a){s++,a=void 0;continue}return null}{const i="right"===t?v(n,g):y(n,g);h&&(r.i&&n[i].toLowerCase()===e.toLowerCase()||!r.i&&n[i]===e)?a=!0:s++,"right"===t&&g>o+1?c.push([o+1,g]):"left"===t&&g<o-1&&c.unshift([g+1,o]),o=g,"right"===t?(void 0===u&&(u=g),l=g):(void 0===l&&(l=g),u=g)}}return void 0===u?null:{gaps:c,leftmostChar:u,rightmostChar:l}}function m(t,n,...e){if(!e.length)return y(t,n);const r={i:!1};let i;return b("left",t,n,i=g(e[0])?Object.assign({},r,e.shift()):r,Array.from(e).reverse())}function O(t,n,...e){if(!e.length)return v(t,n);const r={i:!1};let i;return b("right",t,n,i=g(e[0])?Object.assign({},r,e.shift()):r,e)}var _=(t,n)=>{if(n=Object.assign({preserveNewLines:!1},n),"string"!=typeof t)throw new TypeError(`Expected input to be of type \`string\`, got \`${typeof t}\``);if(!n.preserveNewlines)return t.split(/\r?\n/);const e=t.split(/(\r?\n)/),r=[];for(let t=0;t<e.length;t+=2)r.push(e[t]+(e[t+1]||""));return r},j=Array.isArray;function w(t){return"string"==typeof t}var x={CONFIGHEAD:"GENERATE-ATOMIC-CSS-CONFIG-STARTS",CONFIGTAIL:"GENERATE-ATOMIC-CSS-CONFIG-ENDS",CONTENTHEAD:"GENERATE-ATOMIC-CSS-CONTENT-STARTS",CONTENTTAIL:"GENERATE-ATOMIC-CSS-CONTENT-ENDS"},A=["px","em","%","rem","cm","mm","in","pt","pc","ex","ch","vw","vmin","vmax"],T=x.CONFIGHEAD,S=x.CONFIGTAIL,E=x.CONTENTHEAD,C=x.CONTENTTAIL,I=[":"];function N(t){var n=t,e="",r="";if(t.includes(T)&&t.includes(S)){if(-1!==t.indexOf(S)&&-1!==t.indexOf(E)&&t.indexOf(S)>t.indexOf(E))throw new Error("generate-atomic-css: [THROW_ID_02] Config heads are after config tails!");var i=t.indexOf(T)+T.length,o=t.indexOf(S);if("*"===t[v(t,i)]&&"/"===t[v(t,v(t,i))]&&(i=v(t,v(t,i))+1),"*"===t[y(t,o)]&&"/"===t[y(t,y(t,o))]&&(o=y(t,y(t,o))),!w(n=t.slice(i,o).trim())||!n.trim().length)return{log:{count:0},result:""}}else if(t.includes(T)&&!t.includes(S)&&t.includes(E)){if(t.indexOf(T)>t.indexOf(E))throw new Error("generate-atomic-css: [THROW_ID_03] Config heads are after content heads!");n=t.slice(t.indexOf(T)+T.length,t.indexOf(E))}else if(t.includes(T)||t.includes(S)||!t.includes(E)&&!t.includes(C)){for(var c=new RegExp("(\\/\\s*\\*\\s*)*".concat(E,"(\\s*\\*\\s*\\/)*")),u=new RegExp("(\\/\\s*\\*\\s*)*".concat(C,"(\\s*\\*\\s*\\/)*")),l=!1,a=[],s=[],f=t.split("\n").filter(function(t){return!!l||(t.includes("$$$")||t.includes("{")||t.includes(":")?(l=!0,!0):(a.push(t),!1))}),h=f.length;h--&&!(f[h].includes("$$$")||f[h].includes("{")||f[h].includes(":"));)s.unshift(f.pop());n=f.join("\n").replace(c,"").replace(u,""),a.length&&(e="".concat(a.join("\n"),"\n")),s.length&&(r="\n".concat(s.join("\n")))}else if((n=t).includes(E)){if(y(t,n.indexOf(E))){var g=n.indexOf(E);m(t,g,"/","*")&&(g=m(t,g,"/","*").leftmostChar),e=0===g?"":t.slice(0,g)}var d=n.indexOf(E)+E.length;O(n,d-1,"*","/")&&(d=O(n,d-1,"*","/").rightmostChar+1);var p=null;if(t.includes(C)){p=t.indexOf(C),"*"===t[y(t,p)]&&"/"===t[y(t,y(t,p))]&&(p=y(t,y(t,p)));var b=t.indexOf(C)+C.length;"*"===t[v(t,b-1)]&&"/"===t[v(t,v(t,b-1))]&&(b=v(t,v(t,b-1))+1),v(t,b)&&(r=t.slice(b))}n=p?n.slice(d,p).trim():n.slice(d).trim()}else if(n.includes(C)){var _,j=[],x=!1,A=(n=n.split("\n").filter(function(t){return t.includes("$$$")||x?!!x||(x=!0,!0):(x||j.push(t),!1)}).join("\n")).indexOf(C);m(n,A,"/","*")&&(A=m(n,A,"/","*").leftmostChar),n=n.slice(0,A).trim(),j.length&&(e="".concat(j.join("\n"),"\n")),v(t,t.indexOf(C)+C.length)&&(_=t.indexOf(C)+C.length,"*"===t[v(t,_)]&&"/"===t[v(t,v(t,_))]&&(_=v(t,v(t,_))+1,v(t,_)&&(r=t.slice(_))))}return[n,e,r]}function $(t){var n,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:500,i=t;if(t.lastIndexOf("}")>0&&t.slice(t.lastIndexOf("}")+1).includes("|")?n=t.slice(t.lastIndexOf("}")+1).split("|").filter(function(t){return t.trim().length}).map(function(t){return t.trim()}).filter(function(t){return String(t).split("").every(function(t){return/\d/g.test(t)})}):t.includes("|")&&(n=t.split("|").filter(function(t){return t.trim().length}).map(function(t){return t.trim()}).filter(function(t){return String(t).split("").every(function(t){return/\d/g.test(t)})})),j(n)&&(1===n.length?r=Number.parseInt(n[0],10):n.length>1&&(e=Number.parseInt(n[0],10),r=Number.parseInt(n[1],10))),t.lastIndexOf("}")>0&&t.slice(t.lastIndexOf("}")+1).includes("|")){if((i=t.slice(0,t.indexOf("|",t.lastIndexOf("}")+1)).trimEnd()).trim().startsWith("|"))for(;i.trim().startsWith("|");)i=i.trimStart().slice(1)}else{for(var o=null,c=!1,u=0,l=t.length,a=null,s=0,f=t.length;s<f;s++)if("0123456789".includes(t[s])?null===a&&t[s].trim().length&&(a=!0):"|"!==t[s]&&t[s].trim().length&&(a=!1),!t[s+1]&&a&&(l=o),"|"===t[s]){if(a){l=o;break}o=s,a=null}else!c&&t[s].trim().length&&(c=!0,null!==o&&(u=o+1));i=t.slice(u,l).trimEnd()}return[e,r,i]}function F(t,n,r,i){var o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],c=arguments.length>5?arguments[5]:void 0,u=arguments.length>6?arguments[6]:void 0;return function(t){if(arguments.length>1&&void 0!==arguments[1]&&!arguments[1])return t;var n=Array.from(t);if(n.length&&w(n[0])&&!n[0].trim().length)do{n.shift()}while(w(n[0])&&!n[0].trim().length);if(n.length&&w(n[n.length-1])&&!n[n.length-1].trim().length)do{n.pop()}while(n&&n[n.length-1]&&!n[n.length-1].trim().length);return n}(_(t).map(function(t,o,l){return t.includes("$$$")?function(t,n,r,i,o,c){for(var u,l=0,a=e($(t,0,500),3),s=a[0],f=a[1],h=a[2],g=i-r,d="",p=function(t){for(var e=0,i=0,a=function(n,r){if(h[n].charCodeAt(0),"$"===h[n]&&"$"===h[n-1]&&"$"===h[n-2]){var o,u=h.slice(n+1);if(0!==t||!A.some(function(t){if(u.startsWith(t))return o=t,!0})||"{"!==h[v(h,n+o.length)]&&h[n+o.length+1].trim().length){var l;if(A.some(function(t){if(h.slice(n+1).startsWith(t))return l=t,!0}),!h[n-3].trim().length||I.some(function(t){return h.slice(i,n-2).trim().endsWith(t)})){var a=0;0===t&&A.some(function(t){return"".concat(h.slice(i,n-2)).startsWith(t)&&(a=t.length),!0}),d+="".concat(h.slice(i+a,n-2)).concat(c?String(t).padStart(String(f).length+(0===t&&l?l.length:0)):t)}else h[n+1].trim().length&&"{"!==h[v(h,n)]?(d+="".concat(h.slice(i,n-2)).concat(t),c&&(e=String(f).length-String(t).length)):d+="".concat(h.slice(i,n-2)).concat(c?String(t).padEnd(String(f).length+(0===t&&l?l.length:0)):t);i=n+1}else d+="".concat(h.slice(i,n-2)).concat(c?String(t).padStart(String(f).length-String(t).length+o.length+1):t),i=n+1+(o?o.length:0)}if("{"===h[n]&&c&&e&&(d+="".concat(h.slice(i,n)).concat(" ".repeat(e)),i=n,e=0),!h[n+1]){var s,g=h.slice(i);0===t&&A.some(function(t){if(g.startsWith(t))return s=t,!0})?d+="".concat(h.slice(i+s.length)):d+="".concat(h.slice(i)),d+="".concat(t!==f?"\n":"")}},p=0,y=h.length;p<y;p++)a(p);o.count++,"function"==typeof n&&(u=Math.floor(r+t/(f-s)*g))!==l&&(l=u,n(u))},y=s;y<=f;y++)p(y);return d}(t,n,r+(i-r)/l.length*o,r+(i-r)/l.length*(o+1),c,u):function(t,n){return/\.\w/g.test(t)&&n.count++,t}(t,c)}),o).join("\n")}t.extractFromToSource=$,t.genAtomic=function(t,r){if("string"!=typeof t)throw new Error('generate-atomic-css: [THROW_ID_01] First input argument must be a string! It was given as "'.concat(JSON.stringify(t,null,4),'" (type ').concat(n(t),")"));var i=x.CONFIGHEAD,o=x.CONFIGTAIL,c=x.CONTENTHEAD,u=x.CONTENTTAIL,l={count:0},a=Object.assign({},{includeConfig:!0,includeHeadsAndTails:!0,pad:!0,configOverride:null,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100},r);if(a.includeConfig&&!a.includeHeadsAndTails&&(a.includeHeadsAndTails=!0),!a.configOverride&&!t.includes("$$$")&&!t.includes(i)&&!t.includes(o)&&!t.includes(c)&&!t.includes(u)||w(a.configOverride)&&!a.configOverride.includes("$$$")&&!a.configOverride.includes(i)&&!a.configOverride.includes(o)&&!a.configOverride.includes(c)&&!a.configOverride.includes(u))return{log:{count:0},result:t};var s="",f="",h=e(N(a.configOverride?a.configOverride:t),3),g=h[0],d=h[1],p=h[2];if(!w(g)||!g.trim().length)return{log:{count:0},result:""};if((a.includeConfig||a.includeHeadsAndTails)&&(s="".concat(c," */\n"),a.includeConfig||(s="/* ".concat(s)),f="\n/* ".concat(u," */")),a.includeConfig&&(s="/* ".concat(i,"\n").concat(g.trim(),"\n").concat(o,"\n").concat(s)),t.includes(i)&&null!=y(t,t.indexOf(i))){var b=t.indexOf(i);"*"===t[y(t,b)]&&"/"===t[y(t,y(t,b))]&&(b=y(t,y(t,b)));var m="/* ";("/"===t[v(t,b-1)]&&"*"===t[v(t,v(t,b-1))]||s.trim().startsWith("/*"))&&(m=""),s="".concat(t.slice(0,b)).concat(m).concat(s)}if(t.includes(o)&&v(t,t.indexOf(o)+o.length)){var O=t.indexOf(o)+o.length;if("*"===t[v(t,t.indexOf(o)+o.length)]&&"/"===t[v(t,v(t,t.indexOf(o)+o.length))]&&(O=v(t,v(t,t.indexOf(o)+o.length))+1),t.slice(v(t,O-1)).startsWith(c)){var _=v(t,O);"*"===t[v(t,(O=_+c.length)-1)]&&"/"===t[v(t,v(t,O-1))]&&(O=v(t,v(t,O-1))+1),t.includes(u)&&(O=t.indexOf(u)+u.length,"*"===t[v(t,O)]&&"/"===t[v(t,v(t,O))]&&(O=v(t,v(t,O))+1))}var j=t.slice(O);j.length&&j.includes(u)&&(O=t.indexOf(u)+u.length,"*"===t[v(t,O)]&&"/"===t[v(t,v(t,O))]&&(O=v(t,v(t,O))+1)),f="".concat(f).concat(t[O]&&v(t,O-1)?t.slice(O):"")}if(w(d)&&(s="".concat(d).concat(s)),w(p)){if(p.trim().endsWith("/*")&&!p.trim().startsWith("*/")){var A="";w(p)&&p[0]&&!p[0].trim().length&&(A=p.slice(0,v(p,0))),p="".concat(A,"/* ").concat(p.trim())}f="".concat(f).concat(p)}var T="".concat(function(t){return a.includeConfig||a.includeHeadsAndTails?t.trim():t}("".concat(s).concat(F(g,a.reportProgressFunc,a.reportProgressFuncFrom,a.reportProgressFuncTo,!0,l,a.pad)).concat(f)),"\n");return{log:{count:l.count},result:T}},t.headsAndTails=x,t.version="1.2.0",Object.defineProperty(t,"__esModule",{value:!0})}); |
import split from 'split-lines'; | ||
import { right, left, leftSeq, rightSeq } from 'string-left-right'; | ||
@@ -7,2 +8,215 @@ const isArr = Array.isArray; | ||
} | ||
const headsAndTails = { | ||
CONFIGHEAD: "GENERATE-ATOMIC-CSS-CONFIG-STARTS", | ||
CONFIGTAIL: "GENERATE-ATOMIC-CSS-CONFIG-ENDS", | ||
CONTENTHEAD: "GENERATE-ATOMIC-CSS-CONTENT-STARTS", | ||
CONTENTTAIL: "GENERATE-ATOMIC-CSS-CONTENT-ENDS" | ||
}; | ||
const units = [ | ||
"px", | ||
"em", | ||
"%", | ||
"rem", | ||
"cm", | ||
"mm", | ||
"in", | ||
"pt", | ||
"pc", | ||
"ex", | ||
"ch", | ||
"vw", | ||
"vmin", | ||
"vmax" | ||
]; | ||
const { CONFIGHEAD, CONFIGTAIL, CONTENTHEAD, CONTENTTAIL } = headsAndTails; | ||
const padLeftIfTheresOnTheLeft = [":"]; | ||
function extractConfig(str) { | ||
let extractedConfig = str; | ||
let rawContentAbove = ""; | ||
let rawContentBelow = ""; | ||
if (str.includes(CONFIGHEAD) && str.includes(CONFIGTAIL)) { | ||
if ( | ||
str.indexOf(CONFIGTAIL) !== -1 && | ||
str.indexOf(CONTENTHEAD) !== -1 && | ||
str.indexOf(CONFIGTAIL) > str.indexOf(CONTENTHEAD) | ||
) { | ||
throw new Error( | ||
`generate-atomic-css: [THROW_ID_02] Config heads are after config tails!` | ||
); | ||
} | ||
let sliceFrom = str.indexOf(CONFIGHEAD) + CONFIGHEAD.length; | ||
let sliceTo = str.indexOf(CONFIGTAIL); | ||
if ( | ||
str[right(str, sliceFrom)] === "*" && | ||
str[right(str, right(str, sliceFrom))] === "/" | ||
) { | ||
sliceFrom = right(str, right(str, sliceFrom)) + 1; | ||
} | ||
if ( | ||
str[left(str, sliceTo)] === "*" && | ||
str[left(str, left(str, sliceTo))] === "/" | ||
) { | ||
sliceTo = left(str, left(str, sliceTo)); | ||
} | ||
extractedConfig = str.slice(sliceFrom, sliceTo).trim(); | ||
if (!isStr(extractedConfig) || !extractedConfig.trim().length) { | ||
return { | ||
log: { | ||
count: 0 | ||
}, | ||
result: "" | ||
}; | ||
} | ||
} else if ( | ||
str.includes(CONFIGHEAD) && | ||
!str.includes(CONFIGTAIL) && | ||
str.includes(CONTENTHEAD) | ||
) { | ||
if (str.indexOf(CONFIGHEAD) > str.indexOf(CONTENTHEAD)) { | ||
throw new Error( | ||
`generate-atomic-css: [THROW_ID_03] Config heads are after content heads!` | ||
); | ||
} | ||
extractedConfig = str.slice( | ||
str.indexOf(CONFIGHEAD) + CONFIGHEAD.length, | ||
str.indexOf(CONTENTHEAD) | ||
); | ||
} else if ( | ||
!str.includes(CONFIGHEAD) && | ||
!str.includes(CONFIGTAIL) && | ||
(str.includes(CONTENTHEAD) || str.includes(CONTENTTAIL)) | ||
) { | ||
extractedConfig = str; | ||
if (extractedConfig.includes(CONTENTHEAD)) { | ||
if (left(str, extractedConfig.indexOf(CONTENTHEAD))) { | ||
let sliceTo = extractedConfig.indexOf(CONTENTHEAD); | ||
if (leftSeq(str, sliceTo, "/", "*")) { | ||
sliceTo = leftSeq(str, sliceTo, "/", "*").leftmostChar; | ||
} | ||
rawContentAbove = sliceTo === 0 ? "" : str.slice(0, sliceTo); | ||
} | ||
let sliceFrom = extractedConfig.indexOf(CONTENTHEAD) + CONTENTHEAD.length; | ||
if (rightSeq(extractedConfig, sliceFrom - 1, "*", "/")) { | ||
sliceFrom = | ||
rightSeq(extractedConfig, sliceFrom - 1, "*", "/").rightmostChar + 1; | ||
} | ||
let sliceTo = null; | ||
if (str.includes(CONTENTTAIL)) { | ||
sliceTo = str.indexOf(CONTENTTAIL); | ||
if ( | ||
str[left(str, sliceTo)] === "*" && | ||
str[left(str, left(str, sliceTo))] === "/" | ||
) { | ||
sliceTo = left(str, left(str, sliceTo)); | ||
} | ||
let contentAfterStartsAt = | ||
str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if ( | ||
str[right(str, contentAfterStartsAt - 1)] === "*" && | ||
str[right(str, right(str, contentAfterStartsAt - 1))] === "/" | ||
) { | ||
contentAfterStartsAt = | ||
right(str, right(str, contentAfterStartsAt - 1)) + 1; | ||
} | ||
if (right(str, contentAfterStartsAt)) { | ||
rawContentBelow = str.slice(contentAfterStartsAt); | ||
} | ||
} | ||
if (sliceTo) { | ||
extractedConfig = extractedConfig.slice(sliceFrom, sliceTo).trim(); | ||
} else { | ||
extractedConfig = extractedConfig.slice(sliceFrom).trim(); | ||
} | ||
} | ||
else if (extractedConfig.includes(CONTENTTAIL)) { | ||
const contentInFront = []; | ||
let stopFilteringAndPassAllLines = false; | ||
extractedConfig = extractedConfig | ||
.split("\n") | ||
.filter(rowStr => { | ||
if (!rowStr.includes("$$$") && !stopFilteringAndPassAllLines) { | ||
if (!stopFilteringAndPassAllLines) { | ||
contentInFront.push(rowStr); | ||
} | ||
return false; | ||
} | ||
if (!stopFilteringAndPassAllLines) { | ||
stopFilteringAndPassAllLines = true; | ||
return true; | ||
} | ||
return true; | ||
}) | ||
.join("\n"); | ||
let sliceTo = extractedConfig.indexOf(CONTENTTAIL); | ||
if (leftSeq(extractedConfig, sliceTo, "/", "*")) { | ||
sliceTo = leftSeq(extractedConfig, sliceTo, "/", "*").leftmostChar; | ||
} | ||
extractedConfig = extractedConfig.slice(0, sliceTo).trim(); | ||
if (contentInFront.length) { | ||
rawContentAbove = `${contentInFront.join("\n")}\n`; | ||
} | ||
let contentAfterStartsAt; | ||
if (right(str, str.indexOf(CONTENTTAIL) + CONTENTTAIL.length)) { | ||
contentAfterStartsAt = str.indexOf(CONTENTTAIL) + CONTENTTAIL.length; | ||
if ( | ||
str[right(str, contentAfterStartsAt)] === "*" && | ||
str[right(str, right(str, contentAfterStartsAt))] === "/" | ||
) { | ||
contentAfterStartsAt = | ||
right(str, right(str, contentAfterStartsAt)) + 1; | ||
if (right(str, contentAfterStartsAt)) { | ||
rawContentBelow = str.slice(contentAfterStartsAt); | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
const contentHeadsRegex = new RegExp( | ||
`(\\/\\s*\\*\\s*)*${CONTENTHEAD}(\\s*\\*\\s*\\/)*` | ||
); | ||
const contentTailsRegex = new RegExp( | ||
`(\\/\\s*\\*\\s*)*${CONTENTTAIL}(\\s*\\*\\s*\\/)*` | ||
); | ||
let stopFiltering = false; | ||
const gatheredLinesAboveTopmostConfigLine = []; | ||
const gatheredLinesBelowLastConfigLine = []; | ||
const configLines = str.split("\n").filter(rowStr => { | ||
if (stopFiltering) { | ||
return true; | ||
} | ||
if ( | ||
!rowStr.includes("$$$") && | ||
!rowStr.includes("{") && | ||
!rowStr.includes(":") | ||
) { | ||
gatheredLinesAboveTopmostConfigLine.push(rowStr); | ||
return false; | ||
} | ||
stopFiltering = true; | ||
return true; | ||
}); | ||
for (let i = configLines.length; i--; ) { | ||
if ( | ||
!configLines[i].includes("$$$") && | ||
!configLines[i].includes("{") && | ||
!configLines[i].includes(":") | ||
) { | ||
gatheredLinesBelowLastConfigLine.unshift(configLines.pop()); | ||
} else { | ||
break; | ||
} | ||
} | ||
extractedConfig = configLines | ||
.join("\n") | ||
.replace(contentHeadsRegex, "") | ||
.replace(contentTailsRegex, ""); | ||
if (gatheredLinesAboveTopmostConfigLine.length) { | ||
rawContentAbove = `${gatheredLinesAboveTopmostConfigLine.join("\n")}\n`; | ||
} | ||
if (gatheredLinesBelowLastConfigLine.length) { | ||
rawContentBelow = `\n${gatheredLinesBelowLastConfigLine.join("\n")}`; | ||
} | ||
} | ||
return [extractedConfig, rawContentAbove, rawContentBelow]; | ||
} | ||
function trimBlankLinesFromLinesArray(lineArr, trim = true) { | ||
@@ -16,3 +230,3 @@ if (!trim) { | ||
copyArr.shift(); | ||
} while (!copyArr[0].trim().length); | ||
} while (isStr(copyArr[0]) && !copyArr[0].trim().length); | ||
} | ||
@@ -26,64 +240,210 @@ if ( | ||
copyArr.pop(); | ||
} while (!copyArr[copyArr.length - 1].trim().length); | ||
} while ( | ||
copyArr && | ||
copyArr[copyArr.length - 1] && | ||
!copyArr[copyArr.length - 1].trim().length | ||
); | ||
} | ||
return copyArr; | ||
} | ||
function extractFromToSource(str, fromDefault = 0, toDefault = 500) { | ||
let from = fromDefault; | ||
let to = toDefault; | ||
let source = str; | ||
let tempArr; | ||
if ( | ||
str.lastIndexOf("}") > 0 && | ||
str.slice(str.lastIndexOf("}") + 1).includes("|") | ||
) { | ||
tempArr = str | ||
.slice(str.lastIndexOf("}") + 1) | ||
.split("|") | ||
.filter(val => val.trim().length) | ||
.map(val => val.trim()) | ||
.filter(val => | ||
String(val) | ||
.split("") | ||
.every(char => /\d/g.test(char)) | ||
); | ||
} else if (str.includes("|")) { | ||
tempArr = str | ||
.split("|") | ||
.filter(val => val.trim().length) | ||
.map(val => val.trim()) | ||
.filter(val => | ||
String(val) | ||
.split("") | ||
.every(char => /\d/g.test(char)) | ||
); | ||
} | ||
if (isArr(tempArr)) { | ||
if (tempArr.length === 1) { | ||
to = Number.parseInt(tempArr[0], 10); | ||
} else if (tempArr.length > 1) { | ||
from = Number.parseInt(tempArr[0], 10); | ||
to = Number.parseInt(tempArr[1], 10); | ||
} | ||
} | ||
if ( | ||
str.lastIndexOf("}") > 0 && | ||
str.slice(str.lastIndexOf("}") + 1).includes("|") | ||
) { | ||
source = str.slice(0, str.indexOf("|", str.lastIndexOf("}") + 1)).trimEnd(); | ||
if (source.trim().startsWith("|")) { | ||
while (source.trim().startsWith("|")) { | ||
source = source.trimStart().slice(1); | ||
} | ||
} | ||
} else { | ||
let lastPipeWasAt = null; | ||
let firstNonPipeNonWhitespaceCharMet = false; | ||
let startFrom = 0; | ||
let endTo = str.length; | ||
let onlyDigitsAndWhitespaceBeenMet = null; | ||
for (let i = 0, len = str.length; i < len; i++) { | ||
if ("0123456789".includes(str[i])) { | ||
if (onlyDigitsAndWhitespaceBeenMet === null && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = true; | ||
} | ||
} else { | ||
if (str[i] !== "|" && str[i].trim().length) { | ||
onlyDigitsAndWhitespaceBeenMet = false; | ||
} | ||
} | ||
if (!str[i + 1] && onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
} | ||
if (str[i] === "|") { | ||
if (onlyDigitsAndWhitespaceBeenMet) { | ||
endTo = lastPipeWasAt; | ||
break; | ||
} | ||
lastPipeWasAt = i; | ||
onlyDigitsAndWhitespaceBeenMet = null; | ||
} else if (!firstNonPipeNonWhitespaceCharMet && str[i].trim().length) { | ||
firstNonPipeNonWhitespaceCharMet = true; | ||
if (lastPipeWasAt !== null) { | ||
startFrom = lastPipeWasAt + 1; | ||
} | ||
} | ||
} | ||
source = str.slice(startFrom, endTo).trimEnd(); | ||
} | ||
return [from, to, source]; | ||
} | ||
function prepLine(str, progressFn, subsetFrom, subsetTo, generatedCount, pad) { | ||
let currentPercentageDone; | ||
let lastPercentage = 0; | ||
const split = str.split("|").filter(val => val.length); | ||
let from = 0; | ||
let to = 500; | ||
if (split[1]) { | ||
if (split[2]) { | ||
from = Number.parseInt(split[1].trim()); | ||
to = Number.parseInt(split[2].trim()); | ||
} else { | ||
to = Number.parseInt(split[1].trim()); | ||
} | ||
} | ||
const [from, to, source] = extractFromToSource(str, 0, 500); | ||
const subsetRange = subsetTo - subsetFrom; | ||
let res = ""; | ||
const subsetRange = subsetTo - subsetFrom; | ||
for (let i = from; i <= to; i++) { | ||
generatedCount.count++; | ||
let newStr = split[0]; | ||
const threeDollarRegexWithUnits = /(\$\$\$(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax))/g; | ||
const unitsOnly = /(px|em|%|rem|cm|mm|in|pt|pc|ex|ch|vw|vmin|vmax)/g; | ||
const threeDollarFollowedByWhitespaceRegex = /\$\$\$(?=[{ ])/g; | ||
const threeDollarRegex = /\$\$\$/g; | ||
if (pad) { | ||
const findingsThreeDollarWithUnits = newStr.match( | ||
threeDollarRegexWithUnits | ||
); | ||
if ( | ||
isArr(findingsThreeDollarWithUnits) && | ||
findingsThreeDollarWithUnits.length | ||
) { | ||
findingsThreeDollarWithUnits.forEach(valFound => { | ||
newStr = newStr.replace( | ||
valFound, | ||
`${i}${i === 0 ? "" : unitsOnly.exec(valFound)[0]}`.padStart( | ||
valFound.length - 3 + String(to).length | ||
let debtPaddingLen = 0; | ||
let startPoint = 0; | ||
for (let y = 0, len = source.length; y < len; y++) { | ||
const charcode = source[y].charCodeAt(0); | ||
if (source[y] === "$" && source[y - 1] === "$" && source[y - 2] === "$") { | ||
const restOfStr = source.slice(y + 1); | ||
let unitFound; | ||
if ( | ||
i === 0 && | ||
units.some(unit => { | ||
if (restOfStr.startsWith(unit)) { | ||
unitFound = unit; | ||
return true; | ||
} | ||
}) && | ||
(source[right(source, y + unitFound.length)] === "{" || | ||
!source[y + unitFound.length + 1].trim().length) | ||
) { | ||
res += `${source.slice(startPoint, y - 2)}${ | ||
pad | ||
? String(i).padStart( | ||
String(to).length - String(i).length + unitFound.length + 1 | ||
) | ||
: i | ||
}`; | ||
startPoint = y + 1 + (unitFound ? unitFound.length : 0); | ||
} else { | ||
let unitThatFollow; | ||
units.some(unit => { | ||
if (source.slice(y + 1).startsWith(unit)) { | ||
unitThatFollow = unit; | ||
return true; | ||
} | ||
}); | ||
if ( | ||
!source[y - 3].trim().length || | ||
padLeftIfTheresOnTheLeft.some(val => | ||
source | ||
.slice(startPoint, y - 2) | ||
.trim() | ||
.endsWith(val) | ||
) | ||
); | ||
}); | ||
) { | ||
let temp = 0; | ||
if (i === 0) { | ||
units.some(unit => { | ||
if (`${source.slice(startPoint, y - 2)}`.startsWith(unit)) { | ||
temp = unit.length; | ||
} | ||
return true; | ||
}); | ||
} | ||
res += `${source.slice(startPoint + temp, y - 2)}${ | ||
pad | ||
? String(i).padStart( | ||
String(to).length + | ||
(i === 0 && unitThatFollow ? unitThatFollow.length : 0) | ||
) | ||
: i | ||
}`; | ||
} else if ( | ||
!source[y + 1].trim().length || | ||
source[right(source, y)] === "{" | ||
) { | ||
res += `${source.slice(startPoint, y - 2)}${ | ||
pad | ||
? String(i).padEnd( | ||
String(to).length + | ||
(i === 0 && unitThatFollow ? unitThatFollow.length : 0) | ||
) | ||
: i | ||
}`; | ||
} else { | ||
res += `${source.slice(startPoint, y - 2)}${i}`; | ||
if (pad) { | ||
debtPaddingLen = String(to).length - String(i).length; | ||
} | ||
} | ||
startPoint = y + 1; | ||
} | ||
} | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace( | ||
threeDollarFollowedByWhitespaceRegex, | ||
`${i}`.padEnd(String(to).length) | ||
) | ||
.replace(threeDollarRegex, i)}`.trimEnd(); | ||
} else { | ||
if (i === 0) { | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace(threeDollarRegexWithUnits, i) | ||
.replace(threeDollarRegex, i) | ||
.trimEnd()}`; | ||
} else { | ||
res += `${i === from ? "" : "\n"}${newStr | ||
.replace(threeDollarRegex, i) | ||
.trimEnd()}`; | ||
if (source[y] === "{" && pad) { | ||
if (debtPaddingLen) { | ||
res += `${source.slice(startPoint, y)}${` `.repeat(debtPaddingLen)}`; | ||
startPoint = y; | ||
debtPaddingLen = 0; | ||
} | ||
} | ||
if (!source[y + 1]) { | ||
let unitFound; | ||
const restOfStr = source.slice(startPoint); | ||
if ( | ||
i === 0 && | ||
units.some(unit => { | ||
if (restOfStr.startsWith(unit)) { | ||
unitFound = unit; | ||
return true; | ||
} | ||
}) | ||
) { | ||
res += `${source.slice(startPoint + unitFound.length)}`; | ||
} else { | ||
res += `${source.slice(startPoint)}`; | ||
} | ||
res += `${i !== to ? "\n" : ""}`; | ||
} | ||
} | ||
generatedCount.count++; | ||
if (typeof progressFn === "function") { | ||
@@ -101,2 +461,8 @@ currentPercentageDone = Math.floor( | ||
} | ||
function bump(str, thingToBump) { | ||
if (/\.\w/g.test(str)) { | ||
thingToBump.count++; | ||
} | ||
return str; | ||
} | ||
function prepConfig( | ||
@@ -122,3 +488,3 @@ str, | ||
) | ||
: rowStr | ||
: bump(rowStr, generatedCount) | ||
), | ||
@@ -129,2 +495,2 @@ trim | ||
export { isArr, isStr, prepConfig, prepLine }; | ||
export { extractConfig, extractFromToSource, headsAndTails, isArr, isStr, prepConfig, prepLine }; |
{ | ||
"name": "generate-atomic-css", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Generate Atomic CSS", | ||
@@ -166,10 +166,11 @@ "license": "MIT", | ||
"dependencies": { | ||
"ranges-apply": "^3.0.20", | ||
"split-lines": "^2.0.0", | ||
"string-left-right": "^2.2.9" | ||
"string-left-right": "^2.2.10" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.5.0", | ||
"@babel/preset-env": "^7.5.0", | ||
"@babel/core": "^7.5.4", | ||
"@babel/preset-env": "^7.5.4", | ||
"@babel/register": "^7.4.4", | ||
"ava": "^2.1.0", | ||
"ava": "^2.2.0", | ||
"babel-plugin-istanbul": "^5.1.4", | ||
@@ -184,7 +185,7 @@ "benchmark": "^2.1.4", | ||
"esm": "^3.2.25", | ||
"js-row-num-cli": "^1.5.29", | ||
"lect": "^0.7.6", | ||
"js-row-num-cli": "^1.5.30", | ||
"lect": "^0.7.7", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.18.2", | ||
"rollup": "^1.16.6", | ||
"rollup": "^1.17.0", | ||
"rollup-plugin-ascii": "^0.0.3", | ||
@@ -198,4 +199,4 @@ "rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-strip": "^1.2.1", | ||
"rollup-plugin-terser": "^5.1.0" | ||
"rollup-plugin-terser": "^5.1.1" | ||
} | ||
} |
128
README.md
@@ -22,2 +22,3 @@ # generate-atomic-css | ||
- [headsAndTails](#headsandtails) | ||
- [extractFromToSource()](#extractfromtosource) | ||
- [Idea](#idea) | ||
@@ -36,5 +37,15 @@ - [Config](#config) | ||
// consume via a CommonJS require: | ||
const { genAtomic, version, headsAndTails } = require("generate-atomic-css"); | ||
const { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} = require("generate-atomic-css"); | ||
// or as an ES Module: | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
``` | ||
@@ -46,5 +57,5 @@ | ||
| ------------------------------------------------------------------------------------------------------- | --------------------- | --------------------------------- | ----- | | ||
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/generate-atomic-css.cjs.js` | 16 KB | | ||
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/generate-atomic-css.esm.js` | 15 KB | | ||
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/generate-atomic-css.umd.js` | 18 KB | | ||
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/generate-atomic-css.cjs.js` | 19 KB | | ||
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/generate-atomic-css.esm.js` | 17 KB | | ||
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/generate-atomic-css.umd.js` | 19 KB | | ||
@@ -58,12 +69,23 @@ **[⬆ back to top](#)** | ||
```js | ||
const { genAtomic, version, headsAndTails } = require("generate-atomic-css"); | ||
const { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} = require("generate-atomic-css"); | ||
// or | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
``` | ||
| Name | What it does | | ||
| ------------- | -------------------------------------------------------------- | | ||
| genAtomic | It's the main function which generates CSS | | ||
| version | Exports version from package.json, for example, string `1.0.1` | | ||
| headsAndTails | Exports a plain object with all heads and tails | | ||
| Name | What it does | | ||
| ------------------- | ---------------------------------------------------------------- | | ||
| genAtomic | It's the main function which generates CSS | | ||
| version | Exports version from package.json, for example, string `1.0.1` | | ||
| headsAndTails | Exports a plain object with all heads and tails | | ||
| extractFromToSource | Extracts "from" and "to" from source in rows, separated by pipes | | ||
@@ -81,3 +103,8 @@ **[⬆ back to top](#)** | ||
```js | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
const source = `a | ||
@@ -171,3 +198,8 @@ | ||
```js | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
const source = `.mt$$$ { margin-top: $$$px; }|3`; | ||
@@ -190,3 +222,8 @@ const { log, result } = genAtomic(source, { | ||
```js | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
console.log(`version = v${version}`); | ||
@@ -200,3 +237,3 @@ // => version = v1.0.1 | ||
It's a plain object, its main purpose is to serve as a single source of truth for head and tails names: | ||
It's a plain object, its main purpose is to serve as a single source of truth for heads and tails names: | ||
@@ -215,3 +252,8 @@ ```js | ||
```js | ||
import { genAtomic, version, headsAndTails } from "generate-atomic-css"; | ||
import { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} from "generate-atomic-css"; | ||
console.log(`headsAndTails.CONTENTTAIL = ${headsAndTails.CONTENTTAIL}`); | ||
@@ -223,5 +265,53 @@ // => headsAndTails.CONTENTTAIL = GENERATE-ATOMIC-CSS-CONTENT-ENDS | ||
## extractFromToSource() | ||
It's an internal function which reads the source line, for example: | ||
```js | ||
.pb$$$ { padding-bottom: $$$px !important; } | 5 | 10 | ||
``` | ||
and separates "from" (`5` above) and "to" (`10` above) values from the rest of the string (`.pb$$$ { padding-bottom: $$$px !important; }`). | ||
The challenging part is that pipes can be wrapping the line from outside, plus, if there is only one number at the end of the line, it is "to" value. | ||
``` | ||
| .mt$$$ { margin-top: $$$px !important; } | 1 | | ||
``` | ||
Here's an example how to use `extractFromToSource()`: | ||
```js | ||
const { | ||
genAtomic, | ||
version, | ||
headsAndTails, | ||
extractFromToSource | ||
} = require("generate-atomic-css"); | ||
const input1 = `.pb$$$ { padding-bottom: $$$px !important; } | 5 | 10`; | ||
const input2 = `.mt$$$ { margin-top: $$$px !important; } | 1`; | ||
// second and third input argument are default "from" and default "to" values: | ||
const [from1, to1, source1] = extractFromToSource(input1, 0, 500); | ||
console.log(`from = ${from1}`); | ||
// from = 5 | ||
console.log(`to = ${to1}`); | ||
// from = 10 | ||
console.log(`source = "${source1}"`); | ||
// source = ".pb$$$ { padding-bottom: $$$px !important; }" | ||
const [from2, to2, source2] = extractFromToSource(input2, 0, 100); | ||
console.log(`from = ${from2}`); | ||
// from = 0 <--- default | ||
console.log(`to = ${to2}`); | ||
// from = 1 <--- comes from pipe, "} | 1`;" | ||
console.log(`source = "${source2}"`); | ||
// source = ".mt$$$ { margin-top: $$$px !important; }" | ||
``` | ||
**[⬆ back to top](#)** | ||
## Idea | ||
At the simplest operation, you can turn off heads/tails (set `opts.includeHeadsAndTails` to `false`) and config (set `opts.includeConfig` to `false`). | ||
On a basic level, you can turn off heads/tails (set `opts.includeHeadsAndTails` to `false`) and config (set `opts.includeConfig` to `false`). | ||
@@ -365,3 +455,3 @@ Each line which contains `$$$` will be repeated, from default `0` to `500` or within the range you set: | ||
[gitlab-url]: https://gitlab.com/codsen/codsen/tree/master/packages/generate-atomic-css | ||
[cov-img]: https://img.shields.io/badge/coverage-92.27%25-brightgreen.svg?style=flat-square | ||
[cov-img]: https://img.shields.io/badge/coverage-93.56%25-brightgreen.svg?style=flat-square | ||
[cov-url]: https://gitlab.com/codsen/codsen/tree/master/packages/generate-atomic-css | ||
@@ -368,0 +458,0 @@ [deps2d-img]: https://img.shields.io/badge/deps%20in%202D-see_here-08f0fd.svg?style=flat-square |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
103135
1799
457
3
+ Addedranges-apply@^3.0.20
+ Addedranges-apply@3.2.4(transitive)
+ Addedranges-merge@5.0.4(transitive)
+ Addedranges-sort@3.14.0(transitive)
Updatedstring-left-right@^2.2.10