Skip to content

Commit be48721

Browse files
committed
delete comments #94
1 parent baeb780 commit be48721

30 files changed

+86
-1928
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,32 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
299299

300300
```
301301

302+
### Convert colors
303+
304+
```javascript
305+
import {transform} from '@tbela99/css-parser';
306+
307+
308+
const css = `
309+
.hsl { color: #b3222280; }
310+
`;
311+
const result: TransformResult = await transform(css, {
312+
beautify: true,
313+
convertColor: ColorType.SRGB
314+
});
315+
316+
console.log(result.css);
317+
318+
```
319+
320+
result
321+
322+
```css
323+
.hsl {
324+
color: color(srgb .7019607843137254 .13333333333333333 .13333333333333333/50%)
325+
}
326+
```
327+
302328
### Merge similar rules
303329

304330
CSS

dist/index-umd-web.js

Lines changed: 5 additions & 395 deletions
Large diffs are not rendered by default.

dist/index.cjs

Lines changed: 5 additions & 395 deletions
Large diffs are not rendered by default.

dist/lib/fs/resolve.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,7 @@ function resolve(url, currentDirectory, cwd) {
7878
else if (currentDirectory.charAt(0) == '/') {
7979
result = dirname(currentDirectory) + '/' + url;
8080
}
81-
// else if (currentDirectory === '' || dirname(currentDirectory) === '') {
82-
//
83-
// result = url;
84-
// } else {
85-
//
86-
// result = dirname(currentDirectory) + '/' + url;
87-
// }
8881
let { parts, i } = splitPath(result);
89-
// if (parts.length == 0) {
90-
//
91-
// const path = result.charAt(0) == '/' ? '/' : '';
92-
//
93-
// return {
94-
// absolute: path,
95-
// relative: path
96-
// }
97-
// }
9882
const absolute = parts.join('/');
9983
const { parts: dirs } = splitPath(cwd ?? currentDirectory);
10084
for (const p of dirs) {

dist/lib/parser/parse.js

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,54 +1000,6 @@ function parseSelector(tokens) {
10001000
// @ts-ignore
10011001
value.typ = EnumToken.ChildCombinatorTokenType;
10021002
}
1003-
// @ts-ignore
1004-
// else if (value.typ == EnumToken.WhitespaceTokenType) {
1005-
//
1006-
// if (nextValue != null && nextValue.typ == EnumToken.LiteralTokenType) {
1007-
//
1008-
// if (['>', '+', '~'].includes((<LiteralToken>nextValue).val)) {
1009-
//
1010-
// switch ((<LiteralToken>value).val) {
1011-
//
1012-
// case '>':
1013-
// // @ts-ignore
1014-
// nextValue.typ = EnumToken.ChildCombinatorTokenType;
1015-
// break;
1016-
//
1017-
// case '+':
1018-
// // @ts-ignore
1019-
// nextValue.typ = EnumToken.NextSiblingCombinatorTokenType;
1020-
// break;
1021-
//
1022-
// case '~':
1023-
// // @ts-ignore
1024-
// nextValue.typ = EnumToken.SubsequentSiblingCombinatorTokenType;
1025-
// break;
1026-
// }
1027-
//
1028-
// // @ts-ignore
1029-
// delete (<LiteralToken>nextValue).val;
1030-
//
1031-
// continue;
1032-
// }
1033-
// }
1034-
//
1035-
// if (previousValue != null && [
1036-
// EnumToken.ChildCombinatorTokenType,
1037-
// EnumToken.DescendantCombinatorTokenType,
1038-
// EnumToken.NextSiblingCombinatorTokenType,
1039-
// EnumToken.SubsequentSiblingCombinatorTokenType,
1040-
// EnumToken.ColumnCombinatorTokenType,
1041-
// EnumToken.NameSpaceAttributeTokenType,
1042-
// EnumToken.CommaTokenType
1043-
// ].includes(previousValue.typ)) {
1044-
//
1045-
// continue;
1046-
// }
1047-
//
1048-
// // @ts-ignore
1049-
// value.typ = EnumToken.DescendantCombinatorTokenType;
1050-
// }
10511003
else if (value.typ == EnumToken.LiteralTokenType) {
10521004
if (value.val.charAt(0) == '&') {
10531005
// @ts-ignore
@@ -1065,13 +1017,6 @@ function parseSelector(tokens) {
10651017
value.typ = EnumToken.ClassSelectorTokenType;
10661018
}
10671019
}
1068-
// @ts-ignore
1069-
// if ((<DelimToken>value).typ == EnumToken.DelimTokenType) {
1070-
//
1071-
// // @ts-ignore
1072-
// (<NextSiblingCombinatorToken>value).typ = EnumToken.NextSiblingCombinatorTokenType;
1073-
//
1074-
// } else
10751020
if (['*', '>', '+', '~'].includes(value.val)) {
10761021
switch (value.val) {
10771022
case '*':
@@ -1137,10 +1082,6 @@ function parseSelector(tokens) {
11371082
}
11381083
return tokens;
11391084
}
1140-
// export async function parseDeclarations(src: string, options: ParserOptions = {}): Promise<AstDeclaration[]> {
1141-
//
1142-
// return doParse(`.x{${src}`, options).then((result: ParseResult) => <AstDeclaration[]>(<AstRule>result.ast.chi[0]).chi.filter(t => t.typ == EnumToken.DeclarationNodeType));
1143-
// }
11441085
/**
11451086
* parse css string
11461087
* @param src
@@ -1609,33 +1550,7 @@ function parseTokens(tokens, options = {}) {
16091550
}
16101551
}
16111552
}
1612-
// continue;
16131553
}
1614-
// if (options.parseColor) {
1615-
//
1616-
// if (t.typ == EnumToken.IdenTokenType) {
1617-
// // named color
1618-
// const value: string = (t as IdentToken).val.toLowerCase();
1619-
//
1620-
// if (value in COLORS_NAMES) {
1621-
// Object.assign(t, {
1622-
// typ: EnumToken.ColorTokenType,
1623-
// val: COLORS_NAMES[value].length < value.length ? COLORS_NAMES[value] : value,
1624-
// kin: ColorKind.HEX
1625-
// });
1626-
// }
1627-
//
1628-
// continue;
1629-
// }
1630-
//
1631-
// if (t.typ == EnumToken.HashTokenType && isHexColor((t as HashToken).val)) {
1632-
// // hex color
1633-
// // @ts-ignore
1634-
// t.typ = EnumToken.ColorTokenType;
1635-
// // @ts-ignore
1636-
// (t as ColorToken).kin = ColorKind.HEX;
1637-
// }
1638-
// }
16391554
}
16401555
return tokens;
16411556
}

dist/lib/parser/tokenize.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ function* consumeString(quoteStr, buffer, parseInfo) {
9292
}
9393
break;
9494
}
95-
// if (i == 1) {
96-
//
97-
// buffer += value + sequence[i];
98-
// next(parseInfo, 2);
99-
// continue;
100-
// }
10195
if (escapeSequence.trimEnd().length > 0) {
10296
const codepoint = parseInt(escapeSequence, 16);
10397
if (codepoint == 0 ||
@@ -120,7 +114,6 @@ function* consumeString(quoteStr, buffer, parseInfo) {
120114
buffer += value;
121115
yield pushToken(buffer, parseInfo, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
122116
next(parseInfo);
123-
// i += value.length;
124117
buffer = '';
125118
return;
126119
}
@@ -162,17 +155,9 @@ function prev(parseInfo, count = 1) {
162155
function next(parseInfo, count = 1) {
163156
let char = '';
164157
let chr = '';
165-
// if (count < 0) {
166-
//
167-
// return '';
168-
// }
169158
while (count-- && (chr = parseInfo.stream.charAt(parseInfo.currentPosition.ind + 1))) {
170159
char += chr;
171160
const codepoint = parseInfo.stream.charCodeAt(++parseInfo.currentPosition.ind);
172-
// if (isNaN(codepoint)) {
173-
//
174-
// return char;
175-
// }
176161
if (isNewLine(codepoint)) {
177162
parseInfo.currentPosition.lin++;
178163
parseInfo.currentPosition.col = 0;

0 commit comments

Comments
 (0)