1 | "use strict";
|
2 | exports.__esModule = true;
|
3 | exports.isKeyframePointAndSetIndentation = exports.convertLine = exports.replaceSpacesOrTabs = exports.getIndentationOffset = exports.replaceWithOffset = exports.getBlockHeaderOffset = void 0;
|
4 | var suf_regex_1 = require("suf-regex");
|
5 |
|
6 | function getBlockHeaderOffset(distance, tabSize, current, ignoreCurrent) {
|
7 | if (distance === 0) {
|
8 | return 0;
|
9 | }
|
10 | if (tabSize * Math.round(distance / tabSize - 0.1) > current && !ignoreCurrent) {
|
11 | return current - distance;
|
12 | }
|
13 | return tabSize * Math.round(distance / tabSize - 0.1) - distance;
|
14 | }
|
15 | exports.getBlockHeaderOffset = getBlockHeaderOffset;
|
16 |
|
17 |
|
18 |
|
19 | function replaceWithOffset(text, offset, STATE) {
|
20 | if (offset < 0) {
|
21 | text = text
|
22 | .replace(/\t/g, ' '.repeat(STATE.CONFIG.tabSize))
|
23 | .replace(new RegExp("^ {" + Math.abs(offset) + "}"), '');
|
24 | if (!STATE.CONFIG.insertSpaces) {
|
25 | text = replaceSpacesOrTabs(text, STATE, false);
|
26 | }
|
27 | }
|
28 | else {
|
29 | text = text.replace(/^/, STATE.CONFIG.insertSpaces ? ' '.repeat(offset) : '\t'.repeat(offset / STATE.CONFIG.tabSize));
|
30 | }
|
31 | return text;
|
32 | }
|
33 | exports.replaceWithOffset = replaceWithOffset;
|
34 |
|
35 | function getIndentationOffset(text, indentation, tabSize) {
|
36 | var distance = suf_regex_1.getDistance(text, tabSize);
|
37 | return { offset: indentation - distance, distance: distance };
|
38 | }
|
39 | exports.getIndentationOffset = getIndentationOffset;
|
40 | function isKeyframePoint(text, isAtKeyframe) {
|
41 | if (isAtKeyframe === false) {
|
42 | return false;
|
43 | }
|
44 | return /^[\t ]*\d+%/.test(text) || /^[\t ]*from[\t ]*$|^[\t ]*to[\t ]*$/.test(text);
|
45 | }
|
46 | function replaceSpacesOrTabs(text, STATE, insertSpaces) {
|
47 | if (insertSpaces !== undefined ? insertSpaces : STATE.CONFIG.insertSpaces) {
|
48 | return text.replace(/\t/g, ' '.repeat(STATE.CONFIG.tabSize));
|
49 | }
|
50 | else {
|
51 | return text.replace(new RegExp(' '.repeat(STATE.CONFIG.tabSize), 'g'), '\t');
|
52 | }
|
53 | }
|
54 | exports.replaceSpacesOrTabs = replaceSpacesOrTabs;
|
55 | function convertLine(line, STATE) {
|
56 | return (STATE.CONFIG.convert &&
|
57 | suf_regex_1.isScssOrCss(line.get(), STATE.CONTEXT.convert.wasLastLineCss) &&
|
58 | !suf_regex_1.isComment(line.get()));
|
59 | }
|
60 | exports.convertLine = convertLine;
|
61 | function isKeyframePointAndSetIndentation(line, STATE) {
|
62 | var isAtKeyframesPoint = isKeyframePoint(line.get(), STATE.CONTEXT.keyframes.isIn);
|
63 | if (STATE.CONTEXT.keyframes.isIn && isAtKeyframesPoint) {
|
64 | STATE.CONTEXT.indentation = Math.max(0, STATE.CONTEXT.keyframes.indentation);
|
65 | }
|
66 | return isAtKeyframesPoint;
|
67 | }
|
68 | exports.isKeyframePointAndSetIndentation = isKeyframePointAndSetIndentation;
|