@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.
Files changed (309) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +20 -21
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +40 -53
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +7 -10
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +3 -11
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +137 -0
  158. package/lib/index.d.ts +65 -44
  159. package/lib/index.mjs +83 -94
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +18 -15
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -14
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +99 -94
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.textTokensToSelector = exports.textTokensToRule = exports.getSelectors = exports.mergeTextTokens = void 0;
4
- /**
5
- * Merge text tokens to string
6
- */
7
- function mergeTextTokens(tokens) {
8
- return tokens
9
- .map((token) => token.text)
10
- .join('')
11
- .trim();
12
- }
13
- exports.mergeTextTokens = mergeTextTokens;
14
- /**
15
- * Get list of selectors from list of words
16
- */
17
- function getSelectors(tokens) {
18
- const selectors = [];
19
- let selector = '';
20
- tokens.forEach((token) => {
21
- if (token.type !== 'chunk') {
22
- // Add entire URL or quoted string
23
- selector += token.text;
24
- return;
25
- }
26
- // Split by comma
27
- const list = token.text.split(',');
28
- selector += list.shift();
29
- while (list.length > 0) {
30
- selectors.push(selector.trim());
31
- selector = list.shift();
32
- }
33
- });
34
- selectors.push(selector.trim());
35
- // Filter empty entries
36
- return selectors.filter((item) => item.length > 0);
37
- }
38
- exports.getSelectors = getSelectors;
39
- /**
40
- * Convert text token to rule
41
- */
42
- function textTokensToRule(tokens) {
43
- let prop = '';
44
- let value = '';
45
- let isProp = true;
46
- let error = false;
47
- // Merge all tokens into property and value
48
- tokens.forEach((token) => {
49
- if (error) {
50
- return;
51
- }
52
- if (token.type !== 'chunk') {
53
- // URL or quoted string
54
- if (isProp) {
55
- // Cannot have URL or quoted string in property
56
- error = true;
57
- }
58
- else {
59
- value += token.text;
60
- }
61
- return;
62
- }
63
- // Code token
64
- const pairs = token.text.split(':');
65
- if (pairs.length > 2) {
66
- // Too many ':' in code
67
- error = true;
68
- return;
69
- }
70
- if (pairs.length === 2) {
71
- if (!isProp) {
72
- // Double ':' in code
73
- error = true;
74
- return;
75
- }
76
- prop += pairs[0];
77
- value = pairs[1];
78
- isProp = false;
79
- return;
80
- }
81
- // Add content to property or value
82
- if (isProp) {
83
- prop += token.text;
84
- }
85
- else {
86
- value += token.text;
87
- }
88
- });
89
- if (error || isProp) {
90
- // Error or still assembling a property
91
- return null;
92
- }
93
- prop = prop.trim();
94
- value = value.trim();
95
- if (!prop.length || !value.length) {
96
- return null;
97
- }
98
- const result = {
99
- type: 'rule',
100
- prop: prop.toLowerCase(),
101
- value: value,
102
- index: tokens[0].index,
103
- };
104
- // Check for !important (with possibility to support other stuff like !default in future)
105
- ['important'].forEach((word) => {
106
- if (result.value.slice(-1 - word.length).toLowerCase() === '!' + word) {
107
- result[word] = true;
108
- result.value = result.value.slice(0, -1 - word.length).trim();
109
- }
110
- });
111
- // Value cannot be empty
112
- return result.value.length ? result : null;
113
- }
114
- exports.textTokensToRule = textTokensToRule;
115
- // Rules that needs extra parsing
116
- const nestableAtRules = ['media', 'supports'];
117
- /**
118
- * Create at-rule or selector token from text tokens
119
- */
120
- function textTokensToSelector(tokens) {
121
- const selectors = getSelectors(tokens);
122
- const code = mergeTextTokens(tokens);
123
- const index = tokens[0].index;
124
- if (!selectors.length) {
125
- return null;
126
- }
127
- if (selectors[0].charAt(0) === '@') {
128
- const atRule = selectors[0].split(/\s+/, 1)[0].slice(1).toLowerCase();
129
- selectors[0] = selectors[0].slice(1 + atRule.length).trim();
130
- const atValues = selectors;
131
- // Remove parenthesis for at-rules that can be nested, such as @media
132
- if (nestableAtRules.indexOf(atRule) !== -1) {
133
- atValues.forEach((item, index) => {
134
- if (typeof item !== 'string' ||
135
- item.charAt(0) !== '(' ||
136
- item.charAt(item.length - 1) !== ')') {
137
- return;
138
- }
139
- const list = item
140
- .slice(1, -1)
141
- .split(/\)\s?and\s?\(/i)
142
- .map((item) => item.trim());
143
- let match = true;
144
- list.forEach((item) => {
145
- if (item.indexOf('(') !== -1 || item.indexOf(')') !== -1) {
146
- match = false;
147
- }
148
- });
149
- if (match) {
150
- atValues[index] = list;
151
- }
152
- });
153
- }
154
- return {
155
- type: 'at-rule',
156
- code,
157
- index,
158
- atRule,
159
- atValues,
160
- };
161
- }
162
- else {
163
- return {
164
- type: 'selector',
165
- code,
166
- index,
167
- selectors,
168
- };
169
- }
170
- }
171
- exports.textTokensToSelector = textTokensToSelector;
@@ -1,200 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokens = void 0;
4
- const error_1 = require("./error");
5
- const strings_1 = require("./strings");
6
- const text_1 = require("./text");
7
- /**
8
- * Find all tokens in css, sort by index
9
- */
10
- function findTokens(code, tokens) {
11
- const list = [];
12
- const lc = code.toLowerCase();
13
- tokens.forEach((token) => {
14
- let index = 0;
15
- // eslint-disable-next-line no-constant-condition
16
- while (true) {
17
- index = lc.indexOf(token, index);
18
- if (index === -1) {
19
- return;
20
- }
21
- list.push({
22
- token: token,
23
- index: index,
24
- });
25
- index++;
26
- }
27
- });
28
- list.sort((a, b) => a.index - b.index);
29
- return list;
30
- }
31
- /**
32
- * Get tokens
33
- */
34
- function getTokens(css) {
35
- const items = [];
36
- let textQueue = [];
37
- let start = 0;
38
- let depth = 0;
39
- try {
40
- const checkRule = (text) => {
41
- var _a;
42
- if (!textQueue.length) {
43
- return;
44
- }
45
- const item = (0, text_1.textTokensToRule)(textQueue);
46
- if (item) {
47
- items.push(item);
48
- return;
49
- }
50
- const value = (0, text_1.mergeTextTokens)(textQueue) + text;
51
- if (!value.length) {
52
- return;
53
- }
54
- throw (0, error_1.styleParseError)('Invalid css rule', css, (_a = textQueue[0]) === null || _a === void 0 ? void 0 : _a.index);
55
- };
56
- findTokens(css, ['"', "'", '/*', '{', '}', ';', 'url(', '\\']).forEach((token) => {
57
- if (token.index < start) {
58
- return;
59
- }
60
- switch (token.token) {
61
- case '/*': {
62
- // Skip to end of comment
63
- textQueue.push({
64
- type: 'chunk',
65
- text: css.slice(start, token.index),
66
- index: start,
67
- });
68
- start = token.index;
69
- const end = css.indexOf('*/', start + 2);
70
- if (end === -1) {
71
- // Invalid string
72
- throw (0, error_1.styleParseError)('Missing comment closing statement', css, start);
73
- }
74
- start = end + 2;
75
- break;
76
- }
77
- case '\\':
78
- // Escaped character, skip next character
79
- textQueue.push({
80
- type: 'chunk',
81
- text: css.slice(start, token.index + 2),
82
- index: start,
83
- });
84
- start = token.index + 2;
85
- break;
86
- case 'url(': {
87
- textQueue.push({
88
- type: 'chunk',
89
- text: css.slice(start, token.index),
90
- index: start,
91
- });
92
- start = token.index;
93
- // Skip to end of URL
94
- const end = (0, strings_1.findEndOfURL)(css, start);
95
- if (typeof end !== 'number') {
96
- throw end;
97
- }
98
- textQueue.push({
99
- type: 'url',
100
- text: css.slice(start, end),
101
- index: start,
102
- });
103
- start = end;
104
- break;
105
- }
106
- case '"':
107
- case "'": {
108
- textQueue.push({
109
- type: 'chunk',
110
- text: css.slice(start, token.index),
111
- index: start,
112
- });
113
- start = token.index;
114
- // Skip to end of quoted string
115
- const end = (0, strings_1.findEndOfQuotedString)(css, token.token, start);
116
- if (end === null) {
117
- throw (0, error_1.styleParseError)('Missing closing ' + token.token, css, start);
118
- }
119
- textQueue.push({
120
- type: 'quoted-string',
121
- text: css.slice(start, end),
122
- index: start,
123
- });
124
- start = end;
125
- break;
126
- }
127
- case ';': {
128
- textQueue.push({
129
- type: 'chunk',
130
- text: css.slice(start, token.index),
131
- index: start,
132
- });
133
- checkRule(token.token);
134
- start = token.index + 1;
135
- textQueue = [];
136
- break;
137
- }
138
- case '{': {
139
- // Get selector
140
- textQueue.push({
141
- type: 'chunk',
142
- text: css.slice(start, token.index),
143
- index: start,
144
- });
145
- const item = (0, text_1.textTokensToSelector)(textQueue);
146
- if (!item) {
147
- throw (0, error_1.styleParseError)('Invalid css rule', css, start);
148
- }
149
- items.push(item);
150
- start = token.index + 1;
151
- textQueue = [];
152
- depth++;
153
- break;
154
- }
155
- case '}': {
156
- // End of block
157
- textQueue.push({
158
- type: 'chunk',
159
- text: css.slice(start, token.index),
160
- index: start,
161
- });
162
- checkRule('');
163
- items.push({
164
- type: 'close',
165
- index: token.index,
166
- });
167
- if (!depth) {
168
- throw (0, error_1.styleParseError)('Unexpected }', css, token.index);
169
- }
170
- depth--;
171
- start = token.index + 1;
172
- textQueue = [];
173
- break;
174
- }
175
- default:
176
- throw new Error(`Forgot to parse token: ${token.token}`);
177
- }
178
- });
179
- if (depth) {
180
- return (0, error_1.styleParseError)('Missing }', css);
181
- }
182
- // Add remaining code
183
- textQueue.push({
184
- type: 'chunk',
185
- text: css.slice(start),
186
- index: start,
187
- });
188
- checkRule('');
189
- }
190
- catch (err) {
191
- // Return error if it is StyleParseError object, re-throw if it is something else
192
- if (typeof err === 'object' &&
193
- err.type === 'style-parse-error') {
194
- return err;
195
- }
196
- throw err;
197
- }
198
- return items;
199
- }
200
- exports.getTokens = getTokens;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tokensTree = void 0;
4
- /**
5
- * Convert tokens list to tree
6
- */
7
- function tokensTree(tokens) {
8
- const result = [];
9
- let index = 0;
10
- function parse(target) {
11
- while (index < tokens.length) {
12
- const token = tokens[index];
13
- index++;
14
- switch (token.type) {
15
- case 'close':
16
- return;
17
- case 'selector':
18
- case 'at-rule': {
19
- const newItem = {
20
- ...token,
21
- children: [],
22
- };
23
- target.push(newItem);
24
- parse(newItem.children);
25
- // Remove token without children
26
- if (!newItem.children.length) {
27
- const index = target.indexOf(newItem);
28
- if (index !== -1) {
29
- target.splice(index, 1);
30
- }
31
- }
32
- break;
33
- }
34
- default:
35
- target.push(token);
36
- }
37
- }
38
- }
39
- while (index < tokens.length) {
40
- parse(result);
41
- }
42
- return result;
43
- }
44
- exports.tokensTree = tokensTree;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearAPICache = exports.getAPICache = exports.storeAPICache = exports.apiCacheKey = void 0;
4
- const fs_1 = require("fs");
5
- const crypto_1 = require("crypto");
6
- const scan_1 = require("../../misc/scan");
7
- const cacheVersion = 1;
8
- const storedFiles = Object.create(null);
9
- /**
10
- * Unique key
11
- */
12
- function apiCacheKey(query) {
13
- var _a;
14
- const item = JSON.stringify({
15
- uri: query.uri,
16
- params: (_a = query.params) === null || _a === void 0 ? void 0 : _a.toString(),
17
- headers: query.headers,
18
- });
19
- return (0, crypto_1.createHash)('md5').update(item).digest('hex');
20
- }
21
- exports.apiCacheKey = apiCacheKey;
22
- /**
23
- * Store cache
24
- */
25
- async function storeAPICache(options, key, data) {
26
- const expires = Date.now() + options.ttl * 1000;
27
- const filename = options.dir + '/' + key + '.' + expires + '.json';
28
- if (!storedFiles[options.dir]) {
29
- await getStoredFiles(options.dir);
30
- }
31
- await fs_1.promises.writeFile(filename, JSON.stringify({
32
- version: cacheVersion,
33
- expires,
34
- data,
35
- }, null, 4), 'utf8');
36
- storedFiles[options.dir][key] = {
37
- filename,
38
- expires,
39
- };
40
- }
41
- exports.storeAPICache = storeAPICache;
42
- /**
43
- * Get item from cache
44
- */
45
- async function getAPICache(dir, key) {
46
- if (!storedFiles[dir]) {
47
- await getStoredFiles(dir);
48
- }
49
- const item = storedFiles[dir][key];
50
- if (!item) {
51
- return null;
52
- }
53
- const time = Date.now();
54
- try {
55
- const content = JSON.parse(await fs_1.promises.readFile(item.filename, 'utf8'));
56
- return content.version === cacheVersion && content.expires > time
57
- ? content.data
58
- : null;
59
- }
60
- catch (err) {
61
- return null;
62
- }
63
- }
64
- exports.getAPICache = getAPICache;
65
- /**
66
- * Clear cache
67
- */
68
- function clearAPICache(dir) {
69
- return getStoredFiles(dir, true);
70
- }
71
- exports.clearAPICache = clearAPICache;
72
- /**
73
- * Find all stored files
74
- */
75
- async function getStoredFiles(dir, clear = false) {
76
- const storage = (!clear && storedFiles[dir]) || Object.create(null);
77
- const time = Date.now();
78
- storedFiles[dir] = storage;
79
- // Create directory if missing
80
- try {
81
- await fs_1.promises.mkdir(dir, {
82
- recursive: true,
83
- });
84
- }
85
- catch (err) {
86
- //
87
- }
88
- // Find all files
89
- await (0, scan_1.scanDirectory)(dir, async (ext, file, subdir, path) => {
90
- if (ext !== '.json') {
91
- return false;
92
- }
93
- const filename = path + subdir + file + ext;
94
- const parts = file.split('.');
95
- const expires = parseInt(parts.pop());
96
- if (clear || expires < time || parts.length !== 1) {
97
- // Expired or invalid or cleaning up cache
98
- await fs_1.promises.unlink(filename);
99
- return false;
100
- }
101
- // Valid
102
- const cacheKey = parts[0];
103
- storage[cacheKey] = {
104
- filename,
105
- expires,
106
- };
107
- }, false);
108
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadFile = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
8
- const util_1 = require("util");
9
- const stream_1 = require("stream");
10
- const fs_1 = require("fs");
11
- const streamPipeline = (0, util_1.promisify)(stream_1.pipeline);
12
- /**
13
- * Download file
14
- */
15
- async function downloadFile(query, target) {
16
- const params = query.params ? query.params.toString() : '';
17
- const url = query.uri + (params ? '?' + params : '');
18
- const headers = query.headers;
19
- const response = await (0, node_fetch_1.default)(url, {
20
- headers,
21
- });
22
- if (!response.ok || !response.body) {
23
- throw new Error(`Error downloading ${url}: ${response.status}`);
24
- }
25
- await streamPipeline(response.body, (0, fs_1.createWriteStream)(target));
26
- }
27
- exports.downloadFile = downloadFile;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendAPIQuery = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
8
- const cache_1 = require("./cache");
9
- /**
10
- * Send API query
11
- */
12
- async function sendAPIQuery(query, cache) {
13
- const cacheKey = cache ? (0, cache_1.apiCacheKey)(query) : '';
14
- if (cache) {
15
- const cached = await (0, cache_1.getAPICache)(cache.dir, cacheKey);
16
- if (cached) {
17
- return cached;
18
- }
19
- }
20
- const result = await sendQuery(query);
21
- if (cache && typeof result !== 'number') {
22
- try {
23
- await (0, cache_1.storeAPICache)(cache, cacheKey, result);
24
- }
25
- catch (err) {
26
- console.error('Error writing API cache');
27
- }
28
- }
29
- return result;
30
- }
31
- exports.sendAPIQuery = sendAPIQuery;
32
- /**
33
- * Send query
34
- */
35
- async function sendQuery(query) {
36
- const params = query.params ? query.params.toString() : '';
37
- const url = query.uri + (params ? '?' + params : '');
38
- console.log('Fetch:', url);
39
- const headers = query.headers;
40
- try {
41
- const response = await (0, node_fetch_1.default)(url, {
42
- headers,
43
- });
44
- if (response.status >= 400) {
45
- return response.status;
46
- }
47
- return await response.text();
48
- }
49
- catch (err) {
50
- return 404;
51
- }
52
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGitRepoBranch = void 0;
4
- const exec_1 = require("../../misc/exec");
5
- /**
6
- * Get current branch from cloned git repo
7
- */
8
- async function getGitRepoBranch(options, checkout) {
9
- const result = await (0, exec_1.execAsync)('git branch --show-current', {
10
- cwd: options.target,
11
- });
12
- const branch = result.stdout.trim();
13
- if (typeof checkout === 'string' && branch !== checkout) {
14
- // Checkout correct branch
15
- await (0, exec_1.execAsync)(`git checkout ${checkout}`, {
16
- cwd: options.target,
17
- });
18
- return await getGitRepoBranch(options);
19
- }
20
- return branch;
21
- }
22
- exports.getGitRepoBranch = getGitRepoBranch;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGitRepoHash = void 0;
4
- const exec_1 = require("../../misc/exec");
5
- /**
6
- * Get latest hash from cloned git repo
7
- */
8
- async function getGitRepoHash(options) {
9
- const result = await (0, exec_1.execAsync)('git rev-parse HEAD', {
10
- cwd: options.target,
11
- });
12
- return result.stdout.trim();
13
- }
14
- exports.getGitRepoHash = getGitRepoHash;