@iconify/tools 2.0.14 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/colors/attribs.cjs +30 -0
- package/lib/colors/attribs.d.ts +13 -10
- package/lib/colors/attribs.mjs +7 -13
- package/lib/colors/parse.cjs +269 -0
- package/lib/colors/parse.d.ts +15 -11
- package/lib/colors/parse.mjs +27 -31
- package/lib/colors/validate.cjs +52 -0
- package/lib/colors/validate.d.ts +11 -4
- package/lib/colors/validate.mjs +19 -6
- package/lib/css/parse.cjs +26 -0
- package/lib/css/parse.d.ts +3 -1
- package/lib/css/parse.mjs +8 -6
- package/lib/css/parser/error.cjs +25 -0
- package/lib/css/parser/error.d.ts +4 -2
- package/lib/css/parser/error.mjs +2 -4
- package/lib/css/parser/export.cjs +48 -0
- package/lib/css/parser/export.d.ts +5 -2
- package/lib/css/parser/export.mjs +4 -6
- package/lib/css/parser/strings.cjs +77 -0
- package/lib/css/parser/strings.d.ts +6 -3
- package/lib/css/parser/strings.mjs +4 -6
- package/lib/css/parser/text.cjs +135 -0
- package/lib/css/parser/text.d.ts +8 -5
- package/lib/css/parser/text.mjs +3 -8
- package/lib/css/parser/tokens.cjs +184 -0
- package/lib/css/parser/tokens.d.ts +6 -3
- package/lib/css/parser/tokens.mjs +7 -13
- package/lib/css/parser/tree.cjs +42 -0
- package/lib/css/parser/tree.d.ts +5 -2
- package/lib/css/parser/tree.mjs +2 -4
- package/lib/css/parser/types.cjs +2 -0
- package/lib/css/parser/types.d.ts +13 -11
- package/lib/css/parser/types.mjs +1 -0
- package/lib/download/api/cache.cjs +86 -0
- package/lib/download/api/cache.d.ts +8 -5
- package/lib/download/api/cache.mjs +14 -19
- package/lib/download/api/download.cjs +28 -0
- package/lib/download/api/download.d.ts +5 -2
- package/lib/download/api/download.mjs +8 -9
- package/lib/download/api/index.cjs +51 -0
- package/lib/download/api/index.d.ts +5 -2
- package/lib/download/api/index.mjs +8 -6
- package/lib/download/api/types.cjs +2 -0
- package/lib/download/api/types.d.ts +4 -2
- package/lib/download/api/types.mjs +1 -0
- package/lib/download/git/branch.cjs +22 -0
- package/lib/download/git/branch.d.ts +5 -2
- package/lib/download/git/branch.mjs +5 -5
- package/lib/download/git/hash.cjs +15 -0
- package/lib/download/git/hash.d.ts +5 -2
- package/lib/download/git/hash.mjs +5 -5
- package/lib/download/git/index.cjs +76 -0
- package/lib/download/git/index.d.ts +10 -8
- package/lib/download/git/index.mjs +41 -26
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +3 -1
- package/lib/download/git/reset.mjs +29 -5
- package/lib/download/github/hash.cjs +32 -0
- package/lib/download/github/hash.d.ts +5 -2
- package/lib/download/github/hash.mjs +10 -7
- package/lib/download/github/index.cjs +98 -0
- package/lib/download/github/index.d.ts +11 -9
- package/lib/download/github/index.mjs +23 -17
- package/lib/download/github/types.cjs +2 -0
- package/lib/download/github/types.d.ts +3 -1
- package/lib/download/github/types.mjs +1 -0
- package/lib/download/gitlab/hash.cjs +32 -0
- package/lib/download/gitlab/hash.d.ts +5 -2
- package/lib/download/gitlab/hash.mjs +10 -6
- package/lib/download/gitlab/index.cjs +98 -0
- package/lib/download/gitlab/index.d.ts +11 -9
- package/lib/download/gitlab/index.mjs +24 -18
- package/lib/download/gitlab/types.cjs +7 -0
- package/lib/download/gitlab/types.d.ts +4 -2
- package/lib/download/gitlab/types.mjs +3 -5
- package/lib/download/helpers/untar.cjs +14 -0
- package/lib/download/helpers/untar.d.ts +3 -1
- package/lib/download/helpers/untar.mjs +4 -5
- package/lib/download/helpers/unzip.cjs +19 -0
- package/lib/download/helpers/unzip.d.ts +3 -1
- package/lib/download/helpers/unzip.mjs +6 -7
- package/lib/download/index.cjs +64 -0
- package/lib/download/index.d.ts +18 -13
- package/lib/download/index.mjs +46 -19
- package/lib/download/npm/index.cjs +82 -0
- package/lib/download/npm/index.d.ts +10 -8
- package/lib/download/npm/index.mjs +16 -13
- package/lib/download/npm/types.cjs +2 -0
- package/lib/download/npm/types.d.ts +3 -1
- package/lib/download/npm/types.mjs +1 -0
- package/lib/download/npm/version.cjs +23 -0
- package/lib/download/npm/version.d.ts +7 -4
- package/lib/download/npm/version.mjs +8 -10
- package/lib/download/types/modified.cjs +2 -0
- package/lib/download/types/modified.d.ts +3 -1
- package/lib/download/types/modified.mjs +1 -0
- package/lib/download/types/sources.cjs +2 -0
- package/lib/download/types/sources.d.ts +4 -2
- package/lib/download/types/sources.mjs +1 -0
- package/lib/export/directory.cjs +45 -0
- package/lib/export/directory.d.ts +11 -4
- package/lib/export/directory.mjs +8 -8
- package/lib/export/helpers/custom-files.cjs +28 -0
- package/lib/export/helpers/custom-files.d.ts +4 -2
- package/lib/export/helpers/custom-files.mjs +8 -9
- package/lib/export/helpers/prepare.cjs +36 -0
- package/lib/export/helpers/prepare.d.ts +5 -3
- package/lib/export/helpers/prepare.mjs +7 -9
- package/lib/export/helpers/types-version.cjs +22 -0
- package/lib/export/helpers/types-version.d.ts +3 -1
- package/lib/export/helpers/types-version.mjs +15 -37
- package/lib/export/icon-package.cjs +59 -0
- package/lib/export/icon-package.d.ts +12 -5
- package/lib/export/icon-package.mjs +15 -16
- package/lib/export/json-package.cjs +133 -0
- package/lib/export/json-package.d.ts +12 -5
- package/lib/export/json-package.mjs +20 -21
- package/lib/icon-set/index.cjs +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +40 -53
- package/lib/icon-set/match.cjs +58 -0
- package/lib/icon-set/match.d.ts +10 -3
- package/lib/icon-set/match.mjs +5 -6
- package/lib/icon-set/merge.cjs +83 -0
- package/lib/icon-set/merge.d.ts +9 -2
- package/lib/icon-set/merge.mjs +15 -10
- package/lib/icon-set/props.cjs +28 -0
- package/lib/icon-set/props.d.ts +8 -4
- package/lib/icon-set/props.mjs +7 -10
- package/lib/icon-set/types.cjs +2 -0
- package/lib/icon-set/types.d.ts +19 -17
- package/lib/icon-set/types.mjs +1 -0
- package/lib/import/directory.cjs +76 -0
- package/lib/import/directory.d.ts +11 -5
- package/lib/import/directory.mjs +36 -11
- package/lib/import/figma/index.cjs +105 -0
- package/lib/import/figma/index.d.ts +15 -5
- package/lib/import/figma/index.mjs +40 -13
- package/lib/import/figma/nodes.cjs +86 -0
- package/lib/import/figma/nodes.d.ts +13 -4
- package/lib/import/figma/nodes.mjs +3 -11
- package/lib/import/figma/query.cjs +218 -0
- package/lib/import/figma/query.d.ts +18 -9
- package/lib/import/figma/query.mjs +9 -12
- package/lib/import/figma/types/api.cjs +2 -0
- package/lib/import/figma/types/api.d.ts +8 -7
- package/lib/import/figma/types/api.mjs +1 -0
- package/lib/import/figma/types/nodes.cjs +2 -0
- package/lib/import/figma/types/nodes.d.ts +16 -9
- package/lib/import/figma/types/nodes.mjs +1 -0
- package/lib/import/figma/types/options.cjs +2 -0
- package/lib/import/figma/types/options.d.ts +17 -10
- package/lib/import/figma/types/options.mjs +1 -0
- package/lib/import/figma/types/result.cjs +2 -0
- package/lib/import/figma/types/result.d.ts +12 -5
- package/lib/import/figma/types/result.mjs +1 -0
- package/lib/index.cjs +137 -0
- package/lib/index.d.ts +65 -44
- package/lib/index.mjs +83 -94
- package/lib/misc/bump-version.cjs +17 -0
- package/lib/misc/bump-version.d.ts +3 -1
- package/lib/misc/bump-version.mjs +2 -4
- package/lib/misc/compare-dirs.cjs +75 -0
- package/lib/misc/compare-dirs.d.ts +4 -2
- package/lib/misc/compare-dirs.mjs +12 -12
- package/lib/misc/exec.cjs +25 -0
- package/lib/misc/exec.d.ts +6 -4
- package/lib/misc/exec.mjs +4 -5
- package/lib/misc/keyword.cjs +19 -0
- package/lib/misc/keyword.d.ts +3 -1
- package/lib/misc/keyword.mjs +2 -4
- package/lib/misc/scan.cjs +51 -0
- package/lib/misc/scan.d.ts +7 -6
- package/lib/misc/scan.mjs +6 -7
- package/lib/misc/write-json.cjs +11 -0
- package/lib/misc/write-json.d.ts +3 -1
- package/lib/misc/write-json.mjs +5 -6
- package/lib/optimise/flags.cjs +252 -0
- package/lib/optimise/flags.d.ts +7 -2
- package/lib/optimise/flags.mjs +18 -19
- package/lib/optimise/global-style.cjs +154 -0
- package/lib/optimise/global-style.d.ts +7 -2
- package/lib/optimise/global-style.mjs +18 -15
- package/lib/optimise/scale.cjs +26 -0
- package/lib/optimise/scale.d.ts +7 -2
- package/lib/optimise/scale.mjs +5 -5
- package/lib/optimise/svgo.cjs +83 -0
- package/lib/optimise/svgo.d.ts +10 -6
- package/lib/optimise/svgo.mjs +6 -9
- package/lib/svg/analyse/error.cjs +18 -0
- package/lib/svg/analyse/error.d.ts +5 -2
- package/lib/svg/analyse/error.mjs +2 -4
- package/lib/svg/analyse/types.cjs +2 -0
- package/lib/svg/analyse/types.d.ts +11 -11
- package/lib/svg/analyse/types.mjs +1 -0
- package/lib/svg/analyse.cjs +291 -0
- package/lib/svg/analyse.d.ts +8 -3
- package/lib/svg/analyse.mjs +15 -30
- package/lib/svg/cleanup/attribs.cjs +41 -0
- package/lib/svg/cleanup/attribs.d.ts +7 -2
- package/lib/svg/cleanup/attribs.mjs +6 -12
- package/lib/svg/cleanup/bad-tags.cjs +51 -0
- package/lib/svg/cleanup/bad-tags.d.ts +7 -2
- package/lib/svg/cleanup/bad-tags.mjs +10 -25
- package/lib/svg/cleanup/inline-style.cjs +64 -0
- package/lib/svg/cleanup/inline-style.d.ts +7 -2
- package/lib/svg/cleanup/inline-style.mjs +14 -19
- package/lib/svg/cleanup/root-svg.cjs +81 -0
- package/lib/svg/cleanup/root-svg.d.ts +7 -2
- package/lib/svg/cleanup/root-svg.mjs +7 -18
- package/lib/svg/cleanup/svgo-style.cjs +38 -0
- package/lib/svg/cleanup/svgo-style.d.ts +7 -2
- package/lib/svg/cleanup/svgo-style.mjs +16 -11
- package/lib/svg/cleanup.cjs +32 -0
- package/lib/svg/cleanup.d.ts +7 -2
- package/lib/svg/cleanup.mjs +21 -9
- package/lib/svg/data/attributes.cjs +355 -0
- package/lib/svg/data/attributes.d.ts +27 -25
- package/lib/svg/data/attributes.mjs +90 -115
- package/lib/svg/data/tags.cjs +137 -0
- package/lib/svg/data/tags.d.ts +25 -23
- package/lib/svg/data/tags.mjs +25 -49
- package/lib/svg/index.cjs +130 -0
- package/lib/svg/index.d.ts +16 -5
- package/lib/svg/index.mjs +48 -14
- package/lib/svg/parse-style.cjs +134 -0
- package/lib/svg/parse-style.d.ts +12 -8
- package/lib/svg/parse-style.mjs +11 -9
- package/lib/svg/parse.cjs +42 -0
- package/lib/svg/parse.d.ts +11 -7
- package/lib/svg/parse.mjs +2 -4
- package/package.json +99 -94
- package/lib/colors/attribs.js +0 -26
- package/lib/colors/parse.js +0 -341
- package/lib/colors/validate.js +0 -48
- package/lib/css/parse.js +0 -23
- package/lib/css/parser/error.js +0 -27
- package/lib/css/parser/export.js +0 -69
- package/lib/css/parser/strings.js +0 -93
- package/lib/css/parser/text.js +0 -171
- package/lib/css/parser/tokens.js +0 -200
- package/lib/css/parser/tree.js +0 -44
- package/lib/css/parser/types.js +0 -2
- package/lib/download/api/cache.js +0 -108
- package/lib/download/api/download.js +0 -27
- package/lib/download/api/index.js +0 -52
- package/lib/download/api/types.js +0 -2
- package/lib/download/git/branch.js +0 -22
- package/lib/download/git/hash.js +0 -14
- package/lib/download/git/index.js +0 -75
- package/lib/download/git/reset.js +0 -16
- package/lib/download/github/hash.js +0 -28
- package/lib/download/github/index.js +0 -116
- package/lib/download/github/types.js +0 -2
- package/lib/download/gitlab/hash.js +0 -27
- package/lib/download/gitlab/index.js +0 -115
- package/lib/download/gitlab/types.js +0 -7
- package/lib/download/helpers/untar.js +0 -14
- package/lib/download/helpers/unzip.js +0 -18
- package/lib/download/index.js +0 -27
- package/lib/download/npm/index.js +0 -91
- package/lib/download/npm/types.js +0 -2
- package/lib/download/npm/version.js +0 -27
- package/lib/download/types/modified.js +0 -2
- package/lib/download/types/sources.js +0 -2
- package/lib/export/directory.js +0 -52
- package/lib/export/helpers/custom-files.js +0 -32
- package/lib/export/helpers/prepare.js +0 -49
- package/lib/export/helpers/types-version.js +0 -12
- package/lib/export/icon-package.js +0 -77
- package/lib/export/json-package.js +0 -156
- package/lib/icon-set/index.js +0 -749
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -34
- package/lib/icon-set/types.js +0 -2
- package/lib/import/directory.js +0 -59
- package/lib/import/figma/index.js +0 -90
- package/lib/import/figma/nodes.js +0 -106
- package/lib/import/figma/query.js +0 -244
- package/lib/import/figma/types/api.js +0 -12
- package/lib/import/figma/types/nodes.js +0 -2
- package/lib/import/figma/types/options.js +0 -2
- package/lib/import/figma/types/result.js +0 -2
- package/lib/index.js +0 -103
- package/lib/misc/bump-version.js +0 -19
- package/lib/misc/compare-dirs.js +0 -84
- package/lib/misc/exec.js +0 -26
- package/lib/misc/keyword.js +0 -31
- package/lib/misc/scan.js +0 -55
- package/lib/misc/write-json.js +0 -11
- package/lib/optimise/flags.js +0 -312
- package/lib/optimise/global-style.js +0 -185
- package/lib/optimise/scale.js +0 -42
- package/lib/optimise/svgo.js +0 -99
- package/lib/svg/analyse/error.js +0 -22
- package/lib/svg/analyse/types.js +0 -2
- package/lib/svg/analyse.js +0 -352
- package/lib/svg/cleanup/attribs.js +0 -51
- package/lib/svg/cleanup/bad-tags.js +0 -65
- package/lib/svg/cleanup/inline-style.js +0 -77
- package/lib/svg/cleanup/root-svg.js +0 -107
- package/lib/svg/cleanup/svgo-style.js +0 -35
- package/lib/svg/cleanup.js +0 -24
- package/lib/svg/data/attributes.js +0 -403
- package/lib/svg/data/tags.js +0 -188
- package/lib/svg/index.js +0 -134
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
package/lib/css/parse.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { getTokens } from './parser/tokens.mjs';
|
|
2
|
+
import './parser/error.mjs';
|
|
3
|
+
import './parser/strings.mjs';
|
|
4
|
+
import './parser/text.mjs';
|
|
5
|
+
|
|
3
6
|
function parseInlineStyle(style) {
|
|
4
7
|
const tokens = getTokens(style);
|
|
5
8
|
if (!(tokens instanceof Array)) {
|
|
6
9
|
return null;
|
|
7
10
|
}
|
|
8
|
-
const results = Object.create(null);
|
|
11
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
9
12
|
for (let i = 0; i < tokens.length; i++) {
|
|
10
13
|
const token = tokens[i];
|
|
11
14
|
if (token.type !== "rule") {
|
|
@@ -15,6 +18,5 @@ function parseInlineStyle(style) {
|
|
|
15
18
|
}
|
|
16
19
|
return results;
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
+
|
|
22
|
+
export { parseInlineStyle };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function styleParseError(message, code, index) {
|
|
6
|
+
let fullMessage = message;
|
|
7
|
+
if (typeof index === "number" && index !== -1) {
|
|
8
|
+
const start = index;
|
|
9
|
+
const remaining = code.slice(index) + "!";
|
|
10
|
+
const trimmed = remaining.trim();
|
|
11
|
+
const end = start + remaining.length - trimmed.length;
|
|
12
|
+
const code2 = code.slice(0, end);
|
|
13
|
+
const line = code2.length - code2.replace(/\n/g, "").length + 1;
|
|
14
|
+
fullMessage = message + " on line " + line;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
type: "style-parse-error",
|
|
18
|
+
message,
|
|
19
|
+
code,
|
|
20
|
+
index,
|
|
21
|
+
fullMessage
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.styleParseError = styleParseError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface StyleParseError {
|
|
2
2
|
type: 'style-parse-error';
|
|
3
3
|
message: string;
|
|
4
4
|
code: string;
|
|
@@ -8,4 +8,6 @@ export interface StyleParseError {
|
|
|
8
8
|
/**
|
|
9
9
|
* Create error message
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
declare function styleParseError(message: string, code: string, index?: number): StyleParseError;
|
|
12
|
+
|
|
13
|
+
export { StyleParseError, styleParseError };
|
package/lib/css/parser/error.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/css/parser/error.ts
|
|
2
1
|
function styleParseError(message, code, index) {
|
|
3
2
|
let fullMessage = message;
|
|
4
3
|
if (typeof index === "number" && index !== -1) {
|
|
@@ -18,6 +17,5 @@ function styleParseError(message, code, index) {
|
|
|
18
17
|
fullMessage
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
20
|
+
|
|
21
|
+
export { styleParseError };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const tab = " ";
|
|
6
|
+
const nl = "\n";
|
|
7
|
+
function tokensToString(tree) {
|
|
8
|
+
let compact = true;
|
|
9
|
+
for (let i = 0; i < tree.length; i++) {
|
|
10
|
+
if (tree[i].type !== "rule") {
|
|
11
|
+
compact = false;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return tree.map((token) => {
|
|
16
|
+
return parseToken(token, compact, 0);
|
|
17
|
+
}).join("");
|
|
18
|
+
}
|
|
19
|
+
function parseToken(token, compact, depth) {
|
|
20
|
+
let content;
|
|
21
|
+
switch (token.type) {
|
|
22
|
+
case "rule": {
|
|
23
|
+
return (compact ? "" : tab.repeat(depth)) + token.prop + (compact ? ":" : ": ") + token.value + ";" + (compact ? "" : nl);
|
|
24
|
+
}
|
|
25
|
+
case "at-rule": {
|
|
26
|
+
content = "@" + token.atRule + joinAtValues(token.atValues, compact);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "selector": {
|
|
30
|
+
content = token.selectors.join(compact ? "," : ", ");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const children = token.children.map((item) => {
|
|
34
|
+
return parseToken(item, compact, depth + 1);
|
|
35
|
+
});
|
|
36
|
+
return (compact ? "" : tab.repeat(depth)) + content + (compact ? "{" : " {" + nl) + children.join("") + (compact ? "}" : tab.repeat(depth) + "}" + nl);
|
|
37
|
+
}
|
|
38
|
+
function joinAtValues(values, compact) {
|
|
39
|
+
return values.map((item) => {
|
|
40
|
+
const value = typeof item === "string" ? item : joinAtValues(item, compact);
|
|
41
|
+
if (value.slice(0, 1) === "(" || value.slice(-1) === ")") {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
return "(" + value + ")";
|
|
45
|
+
}).join(compact ? "," : ", ");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.tokensToString = tokensToString;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CSSTreeToken } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Convert tokens tree to string
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function tokensToString(tree: CSSTreeToken[]): string;
|
|
7
|
+
|
|
8
|
+
export { tokensToString };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var nl = "\n";
|
|
1
|
+
const tab = " ";
|
|
2
|
+
const nl = "\n";
|
|
4
3
|
function tokensToString(tree) {
|
|
5
4
|
let compact = true;
|
|
6
5
|
for (let i = 0; i < tree.length; i++) {
|
|
@@ -41,6 +40,5 @@ function joinAtValues(values, compact) {
|
|
|
41
40
|
return "(" + value + ")";
|
|
42
41
|
}).join(compact ? "," : ", ");
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
43
|
+
|
|
44
|
+
export { tokensToString };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const css_parser_error = require('./error.cjs');
|
|
6
|
+
|
|
7
|
+
function findEndOfQuotedString(code, quote, start) {
|
|
8
|
+
let nextEscape = code.indexOf("\\", start + 1);
|
|
9
|
+
let end = code.indexOf(quote, start + 1);
|
|
10
|
+
if (end === -1) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
while (nextEscape !== -1 && nextEscape < end) {
|
|
14
|
+
if (end === nextEscape + 1) {
|
|
15
|
+
end = code.indexOf(quote, end + 1);
|
|
16
|
+
if (end === -1) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
nextEscape = code.indexOf("\\", nextEscape + 2);
|
|
21
|
+
}
|
|
22
|
+
return end + 1;
|
|
23
|
+
}
|
|
24
|
+
function findEndOfURL(code, start) {
|
|
25
|
+
let index = (start || 0) + 4;
|
|
26
|
+
const length = code.length;
|
|
27
|
+
while (true) {
|
|
28
|
+
if (index >= length) {
|
|
29
|
+
return css_parser_error.styleParseError("Cannot find end of URL", code, start);
|
|
30
|
+
}
|
|
31
|
+
let next = code.charAt(index);
|
|
32
|
+
switch (next) {
|
|
33
|
+
case '"':
|
|
34
|
+
case "'": {
|
|
35
|
+
let end = findEndOfQuotedString(code, next, index);
|
|
36
|
+
if (end === null) {
|
|
37
|
+
return css_parser_error.styleParseError("Incomplete string", code, index);
|
|
38
|
+
}
|
|
39
|
+
end = code.indexOf(")", end);
|
|
40
|
+
return end === -1 ? css_parser_error.styleParseError("Cannot find end of URL", code, start) : end + 1;
|
|
41
|
+
}
|
|
42
|
+
case " ":
|
|
43
|
+
case " ":
|
|
44
|
+
case "\r":
|
|
45
|
+
case "\n":
|
|
46
|
+
index++;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
while (true) {
|
|
50
|
+
switch (next) {
|
|
51
|
+
case ")":
|
|
52
|
+
return index + 1;
|
|
53
|
+
case '"':
|
|
54
|
+
case "'":
|
|
55
|
+
case "(":
|
|
56
|
+
case " ":
|
|
57
|
+
case " ":
|
|
58
|
+
case "\r":
|
|
59
|
+
case "\n":
|
|
60
|
+
return css_parser_error.styleParseError("Invalid URL", code, start);
|
|
61
|
+
default:
|
|
62
|
+
if (code.charCodeAt(index) < 32) {
|
|
63
|
+
return css_parser_error.styleParseError("Invalid URL", code, start);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
index++;
|
|
67
|
+
if (index >= length) {
|
|
68
|
+
return css_parser_error.styleParseError("Cannot find end of URL", code, start);
|
|
69
|
+
}
|
|
70
|
+
next = code.charAt(index);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.findEndOfQuotedString = findEndOfQuotedString;
|
|
77
|
+
exports.findEndOfURL = findEndOfURL;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { StyleParseError } from './error';
|
|
1
|
+
import { StyleParseError } from './error.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Find end of quoted string
|
|
4
5
|
*
|
|
5
6
|
* Returns index of character after quote
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
declare function findEndOfQuotedString(code: string, quote: string, start: number): number | null;
|
|
8
9
|
/**
|
|
9
10
|
* Find end of url
|
|
10
11
|
*
|
|
11
12
|
* Returns index of character after end of URL
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
declare function findEndOfURL(code: string, start: number): number | StyleParseError;
|
|
15
|
+
|
|
16
|
+
export { findEndOfQuotedString, findEndOfURL };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { styleParseError } from './error.mjs';
|
|
2
|
+
|
|
3
3
|
function findEndOfQuotedString(code, quote, start) {
|
|
4
4
|
let nextEscape = code.indexOf("\\", start + 1);
|
|
5
5
|
let end = code.indexOf(quote, start + 1);
|
|
@@ -68,7 +68,5 @@ function findEndOfURL(code, start) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
findEndOfURL
|
|
74
|
-
};
|
|
71
|
+
|
|
72
|
+
export { findEndOfQuotedString, findEndOfURL };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function mergeTextTokens(tokens) {
|
|
6
|
+
return tokens.map((token) => token.text).join("").trim();
|
|
7
|
+
}
|
|
8
|
+
function getSelectors(tokens) {
|
|
9
|
+
const selectors = [];
|
|
10
|
+
let selector = "";
|
|
11
|
+
tokens.forEach((token) => {
|
|
12
|
+
if (token.type !== "chunk") {
|
|
13
|
+
selector += token.text;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const list = token.text.split(",");
|
|
17
|
+
selector += list.shift();
|
|
18
|
+
while (list.length > 0) {
|
|
19
|
+
selectors.push(selector.trim());
|
|
20
|
+
selector = list.shift();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
selectors.push(selector.trim());
|
|
24
|
+
return selectors.filter((item) => item.length > 0);
|
|
25
|
+
}
|
|
26
|
+
function textTokensToRule(tokens) {
|
|
27
|
+
let prop = "";
|
|
28
|
+
let value = "";
|
|
29
|
+
let isProp = true;
|
|
30
|
+
let error = false;
|
|
31
|
+
tokens.forEach((token) => {
|
|
32
|
+
if (error) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (token.type !== "chunk") {
|
|
36
|
+
if (isProp) {
|
|
37
|
+
error = true;
|
|
38
|
+
} else {
|
|
39
|
+
value += token.text;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const pairs = token.text.split(":");
|
|
44
|
+
if (pairs.length > 2) {
|
|
45
|
+
error = true;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (pairs.length === 2) {
|
|
49
|
+
if (!isProp) {
|
|
50
|
+
error = true;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
prop += pairs[0];
|
|
54
|
+
value = pairs[1];
|
|
55
|
+
isProp = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (isProp) {
|
|
59
|
+
prop += token.text;
|
|
60
|
+
} else {
|
|
61
|
+
value += token.text;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (error || isProp) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
prop = prop.trim();
|
|
68
|
+
value = value.trim();
|
|
69
|
+
if (!prop.length || !value.length) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const result = {
|
|
73
|
+
type: "rule",
|
|
74
|
+
prop: prop.toLowerCase(),
|
|
75
|
+
value,
|
|
76
|
+
index: tokens[0].index
|
|
77
|
+
};
|
|
78
|
+
["important"].forEach((word) => {
|
|
79
|
+
if (result.value.slice(-1 - word.length).toLowerCase() === "!" + word) {
|
|
80
|
+
result[word] = true;
|
|
81
|
+
result.value = result.value.slice(0, -1 - word.length).trim();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return result.value.length ? result : null;
|
|
85
|
+
}
|
|
86
|
+
const nestableAtRules = ["media", "supports"];
|
|
87
|
+
function textTokensToSelector(tokens) {
|
|
88
|
+
const selectors = getSelectors(tokens);
|
|
89
|
+
const code = mergeTextTokens(tokens);
|
|
90
|
+
const index = tokens[0].index;
|
|
91
|
+
if (!selectors.length) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (selectors[0].charAt(0) === "@") {
|
|
95
|
+
const atRule = selectors[0].split(/\s+/, 1)[0].slice(1).toLowerCase();
|
|
96
|
+
selectors[0] = selectors[0].slice(1 + atRule.length).trim();
|
|
97
|
+
const atValues = selectors;
|
|
98
|
+
if (nestableAtRules.indexOf(atRule) !== -1) {
|
|
99
|
+
atValues.forEach((item, index2) => {
|
|
100
|
+
if (typeof item !== "string" || item.charAt(0) !== "(" || item.charAt(item.length - 1) !== ")") {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const list = item.slice(1, -1).split(/\)\s?and\s?\(/i).map((item2) => item2.trim());
|
|
104
|
+
let match = true;
|
|
105
|
+
list.forEach((item2) => {
|
|
106
|
+
if (item2.indexOf("(") !== -1 || item2.indexOf(")") !== -1) {
|
|
107
|
+
match = false;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (match) {
|
|
111
|
+
atValues[index2] = list;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type: "at-rule",
|
|
117
|
+
code,
|
|
118
|
+
index,
|
|
119
|
+
atRule,
|
|
120
|
+
atValues
|
|
121
|
+
};
|
|
122
|
+
} else {
|
|
123
|
+
return {
|
|
124
|
+
type: "selector",
|
|
125
|
+
code,
|
|
126
|
+
index,
|
|
127
|
+
selectors
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
exports.getSelectors = getSelectors;
|
|
133
|
+
exports.mergeTextTokens = mergeTextTokens;
|
|
134
|
+
exports.textTokensToRule = textTokensToRule;
|
|
135
|
+
exports.textTokensToSelector = textTokensToSelector;
|
package/lib/css/parser/text.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TextToken, CSSRuleToken, CSSTokenWithSelector } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Merge text tokens to string
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function mergeTextTokens(tokens: TextToken[]): string;
|
|
6
7
|
/**
|
|
7
8
|
* Get list of selectors from list of words
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function getSelectors(tokens: TextToken[]): string[];
|
|
10
11
|
/**
|
|
11
12
|
* Convert text token to rule
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
declare function textTokensToRule(tokens: TextToken[]): CSSRuleToken | null;
|
|
14
15
|
/**
|
|
15
16
|
* Create at-rule or selector token from text tokens
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
declare function textTokensToSelector(tokens: TextToken[]): CSSTokenWithSelector | null;
|
|
19
|
+
|
|
20
|
+
export { getSelectors, mergeTextTokens, textTokensToRule, textTokensToSelector };
|
package/lib/css/parser/text.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/css/parser/text.ts
|
|
2
1
|
function mergeTextTokens(tokens) {
|
|
3
2
|
return tokens.map((token) => token.text).join("").trim();
|
|
4
3
|
}
|
|
@@ -80,7 +79,7 @@ function textTokensToRule(tokens) {
|
|
|
80
79
|
});
|
|
81
80
|
return result.value.length ? result : null;
|
|
82
81
|
}
|
|
83
|
-
|
|
82
|
+
const nestableAtRules = ["media", "supports"];
|
|
84
83
|
function textTokensToSelector(tokens) {
|
|
85
84
|
const selectors = getSelectors(tokens);
|
|
86
85
|
const code = mergeTextTokens(tokens);
|
|
@@ -125,9 +124,5 @@ function textTokensToSelector(tokens) {
|
|
|
125
124
|
};
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
mergeTextTokens,
|
|
131
|
-
textTokensToRule,
|
|
132
|
-
textTokensToSelector
|
|
133
|
-
};
|
|
127
|
+
|
|
128
|
+
export { getSelectors, mergeTextTokens, textTokensToRule, textTokensToSelector };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const css_parser_error = require('./error.cjs');
|
|
6
|
+
const css_parser_strings = require('./strings.cjs');
|
|
7
|
+
const css_parser_text = require('./text.cjs');
|
|
8
|
+
|
|
9
|
+
function findTokens(code, tokens) {
|
|
10
|
+
const list = [];
|
|
11
|
+
const lc = code.toLowerCase();
|
|
12
|
+
tokens.forEach((token) => {
|
|
13
|
+
let index = 0;
|
|
14
|
+
while (true) {
|
|
15
|
+
index = lc.indexOf(token, index);
|
|
16
|
+
if (index === -1) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
list.push({
|
|
20
|
+
token,
|
|
21
|
+
index
|
|
22
|
+
});
|
|
23
|
+
index++;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
list.sort((a, b) => a.index - b.index);
|
|
27
|
+
return list;
|
|
28
|
+
}
|
|
29
|
+
function getTokens(css) {
|
|
30
|
+
const items = [];
|
|
31
|
+
let textQueue = [];
|
|
32
|
+
let start = 0;
|
|
33
|
+
let depth = 0;
|
|
34
|
+
try {
|
|
35
|
+
const checkRule = (text) => {
|
|
36
|
+
if (!textQueue.length) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const item = css_parser_text.textTokensToRule(textQueue);
|
|
40
|
+
if (item) {
|
|
41
|
+
items.push(item);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const value = css_parser_text.mergeTextTokens(textQueue) + text;
|
|
45
|
+
if (!value.length) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw css_parser_error.styleParseError("Invalid css rule", css, textQueue[0]?.index);
|
|
49
|
+
};
|
|
50
|
+
findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach((token) => {
|
|
51
|
+
if (token.index < start) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (token.token) {
|
|
55
|
+
case "/*": {
|
|
56
|
+
textQueue.push({
|
|
57
|
+
type: "chunk",
|
|
58
|
+
text: css.slice(start, token.index),
|
|
59
|
+
index: start
|
|
60
|
+
});
|
|
61
|
+
start = token.index;
|
|
62
|
+
const end = css.indexOf("*/", start + 2);
|
|
63
|
+
if (end === -1) {
|
|
64
|
+
throw css_parser_error.styleParseError("Missing comment closing statement", css, start);
|
|
65
|
+
}
|
|
66
|
+
start = end + 2;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "\\":
|
|
70
|
+
textQueue.push({
|
|
71
|
+
type: "chunk",
|
|
72
|
+
text: css.slice(start, token.index + 2),
|
|
73
|
+
index: start
|
|
74
|
+
});
|
|
75
|
+
start = token.index + 2;
|
|
76
|
+
break;
|
|
77
|
+
case "url(": {
|
|
78
|
+
textQueue.push({
|
|
79
|
+
type: "chunk",
|
|
80
|
+
text: css.slice(start, token.index),
|
|
81
|
+
index: start
|
|
82
|
+
});
|
|
83
|
+
start = token.index;
|
|
84
|
+
const end = css_parser_strings.findEndOfURL(css, start);
|
|
85
|
+
if (typeof end !== "number") {
|
|
86
|
+
throw end;
|
|
87
|
+
}
|
|
88
|
+
textQueue.push({
|
|
89
|
+
type: "url",
|
|
90
|
+
text: css.slice(start, end),
|
|
91
|
+
index: start
|
|
92
|
+
});
|
|
93
|
+
start = end;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case '"':
|
|
97
|
+
case "'": {
|
|
98
|
+
textQueue.push({
|
|
99
|
+
type: "chunk",
|
|
100
|
+
text: css.slice(start, token.index),
|
|
101
|
+
index: start
|
|
102
|
+
});
|
|
103
|
+
start = token.index;
|
|
104
|
+
const end = css_parser_strings.findEndOfQuotedString(css, token.token, start);
|
|
105
|
+
if (end === null) {
|
|
106
|
+
throw css_parser_error.styleParseError("Missing closing " + token.token, css, start);
|
|
107
|
+
}
|
|
108
|
+
textQueue.push({
|
|
109
|
+
type: "quoted-string",
|
|
110
|
+
text: css.slice(start, end),
|
|
111
|
+
index: start
|
|
112
|
+
});
|
|
113
|
+
start = end;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case ";": {
|
|
117
|
+
textQueue.push({
|
|
118
|
+
type: "chunk",
|
|
119
|
+
text: css.slice(start, token.index),
|
|
120
|
+
index: start
|
|
121
|
+
});
|
|
122
|
+
checkRule(token.token);
|
|
123
|
+
start = token.index + 1;
|
|
124
|
+
textQueue = [];
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case "{": {
|
|
128
|
+
textQueue.push({
|
|
129
|
+
type: "chunk",
|
|
130
|
+
text: css.slice(start, token.index),
|
|
131
|
+
index: start
|
|
132
|
+
});
|
|
133
|
+
const item = css_parser_text.textTokensToSelector(textQueue);
|
|
134
|
+
if (!item) {
|
|
135
|
+
throw css_parser_error.styleParseError("Invalid css rule", css, start);
|
|
136
|
+
}
|
|
137
|
+
items.push(item);
|
|
138
|
+
start = token.index + 1;
|
|
139
|
+
textQueue = [];
|
|
140
|
+
depth++;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "}": {
|
|
144
|
+
textQueue.push({
|
|
145
|
+
type: "chunk",
|
|
146
|
+
text: css.slice(start, token.index),
|
|
147
|
+
index: start
|
|
148
|
+
});
|
|
149
|
+
checkRule("");
|
|
150
|
+
items.push({
|
|
151
|
+
type: "close",
|
|
152
|
+
index: token.index
|
|
153
|
+
});
|
|
154
|
+
if (!depth) {
|
|
155
|
+
throw css_parser_error.styleParseError("Unexpected }", css, token.index);
|
|
156
|
+
}
|
|
157
|
+
depth--;
|
|
158
|
+
start = token.index + 1;
|
|
159
|
+
textQueue = [];
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default:
|
|
163
|
+
throw new Error(`Forgot to parse token: ${token.token}`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
if (depth) {
|
|
167
|
+
return css_parser_error.styleParseError("Missing }", css);
|
|
168
|
+
}
|
|
169
|
+
textQueue.push({
|
|
170
|
+
type: "chunk",
|
|
171
|
+
text: css.slice(start),
|
|
172
|
+
index: start
|
|
173
|
+
});
|
|
174
|
+
checkRule("");
|
|
175
|
+
} catch (err) {
|
|
176
|
+
if (typeof err === "object" && err.type === "style-parse-error") {
|
|
177
|
+
return err;
|
|
178
|
+
}
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
return items;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
exports.getTokens = getTokens;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { StyleParseError } from './error';
|
|
2
|
-
import
|
|
1
|
+
import { StyleParseError } from './error.js';
|
|
2
|
+
import { CSSToken } from './types.js';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Get tokens
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
declare function getTokens(css: string): CSSToken[] | StyleParseError;
|
|
8
|
+
|
|
9
|
+
export { getTokens };
|