material-icon-theme 4.16.0 → 4.17.0

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 (201) hide show
  1. package/.eslintrc.json +51 -51
  2. package/.github/FUNDING.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +34 -34
  4. package/.github/ISSUE_TEMPLATE/icon_request.md +27 -27
  5. package/.github/workflows/build.yml +45 -45
  6. package/.github/workflows/color-check.yml +22 -22
  7. package/.github/workflows/release.yml +73 -73
  8. package/.prettierrc +7 -7
  9. package/.vscode/extensions.json +3 -3
  10. package/.vscode/launch.json +43 -43
  11. package/.vscode/settings.json +14 -14
  12. package/.vscode/tasks.json +32 -32
  13. package/.vscodeignore +20 -20
  14. package/CHANGELOG.md +1152 -1135
  15. package/CONTRIBUTING.md +62 -62
  16. package/LICENSE.md +8 -8
  17. package/README.md +208 -209
  18. package/build/web-extension.webpack.config.js +62 -62
  19. package/build/webpack.config.js +39 -39
  20. package/changelog.config.json +4 -4
  21. package/icons/architecture.svg +5 -0
  22. package/icons/astyle.svg +4 -4
  23. package/icons/azure.svg +10 -1
  24. package/icons/blitz.svg +4 -4
  25. package/icons/buildkite.svg +9 -1
  26. package/icons/cypress.svg +4 -4
  27. package/icons/dart_generated.svg +9 -0
  28. package/icons/dependabot.svg +4 -4
  29. package/icons/dinophp.svg +16 -16
  30. package/icons/figma.svg +10 -10
  31. package/icons/folder-angular-open.svg +2 -2
  32. package/icons/folder-angular.svg +2 -2
  33. package/icons/folder-buildkite-open.svg +9 -0
  34. package/icons/folder-buildkite.svg +8 -0
  35. package/icons/folder-cypress-open.svg +5 -5
  36. package/icons/folder-cypress.svg +5 -5
  37. package/icons/folder-java-open.svg +2 -2
  38. package/icons/folder-java.svg +2 -2
  39. package/icons/folder-next-open.svg +2 -2
  40. package/icons/folder-next.svg +2 -2
  41. package/icons/folder-nuxt-open.svg +2 -1
  42. package/icons/folder-nuxt.svg +2 -1
  43. package/icons/folder-queue-open.svg +2 -2
  44. package/icons/folder-queue.svg +2 -2
  45. package/icons/folder-resolver-open.svg +2 -2
  46. package/icons/folder-resolver.svg +2 -2
  47. package/icons/folder-serverless-open.svg +5 -5
  48. package/icons/folder-serverless.svg +5 -5
  49. package/icons/folder-shader-open.svg +8 -0
  50. package/icons/folder-shader.svg +7 -0
  51. package/icons/folder-target-open.svg +2 -2
  52. package/icons/folder-target.svg +2 -2
  53. package/icons/folder-unity-open.svg +2 -2
  54. package/icons/folder-unity.svg +2 -2
  55. package/icons/folder-vercel-open.svg +4 -4
  56. package/icons/folder-vercel.svg +4 -4
  57. package/icons/folder-verdaccio-open.svg +8 -0
  58. package/icons/folder-verdaccio.svg +8 -0
  59. package/icons/gleam.svg +4 -4
  60. package/icons/gridsome.svg +4 -4
  61. package/icons/hardhat.svg +3 -3
  62. package/icons/lighthouse.svg +2 -2
  63. package/icons/ndst.svg +7 -7
  64. package/icons/next.svg +3 -3
  65. package/icons/next_light.svg +2 -2
  66. package/icons/nuxt.svg +5 -1
  67. package/icons/odin.svg +6 -6
  68. package/icons/otne.svg +16 -0
  69. package/icons/parcel.svg +4 -4
  70. package/icons/playwright.svg +7 -7
  71. package/icons/plop.svg +4 -0
  72. package/icons/pnpm.svg +9 -9
  73. package/icons/pnpm_light.svg +7 -7
  74. package/icons/poetry.svg +1 -1
  75. package/icons/processing.svg +10 -10
  76. package/icons/remix.svg +4 -4
  77. package/icons/remix_light.svg +4 -4
  78. package/icons/rome.svg +5 -5
  79. package/icons/serverless.svg +4 -4
  80. package/icons/shader.svg +4 -0
  81. package/icons/siyuan.svg +9 -9
  82. package/icons/steadybit.svg +1 -1
  83. package/icons/svgr.svg +4 -4
  84. package/icons/tauri.svg +9 -9
  85. package/icons/template.svg +4 -4
  86. package/icons/tobi.svg +4 -4
  87. package/icons/tobimake.svg +14 -14
  88. package/icons/turborepo.svg +12 -12
  89. package/icons/turborepo_light.svg +12 -12
  90. package/icons/verdaccio.svg +5 -0
  91. package/images/contributors.png +0 -0
  92. package/images/fileIcons.png +0 -0
  93. package/images/folderIcons.png +0 -0
  94. package/logo.svg +21 -21
  95. package/material-colors.yml +257 -257
  96. package/package.json +264 -264
  97. package/package.nls.de.json +35 -35
  98. package/package.nls.es.json +32 -32
  99. package/package.nls.fr.json +32 -32
  100. package/package.nls.ja.json +35 -35
  101. package/package.nls.json +35 -35
  102. package/package.nls.nl.json +35 -35
  103. package/package.nls.pl.json +35 -35
  104. package/package.nls.pt-BR.json +32 -32
  105. package/package.nls.pt-PT.json +32 -32
  106. package/package.nls.ru.json +32 -32
  107. package/package.nls.zh-CN.json +32 -32
  108. package/package.nls.zh-TW.json +32 -32
  109. package/src/commands/activate.ts +26 -26
  110. package/src/commands/explorerArrows.ts +55 -55
  111. package/src/commands/folderColor.ts +96 -96
  112. package/src/commands/folders.ts +55 -55
  113. package/src/commands/grayscale.ts +55 -55
  114. package/src/commands/iconPacks.ts +68 -68
  115. package/src/commands/index.ts +30 -30
  116. package/src/commands/opacity.ts +46 -46
  117. package/src/commands/restoreConfig.ts +14 -14
  118. package/src/commands/saturation.ts +46 -46
  119. package/src/extension.ts +35 -35
  120. package/src/helpers/changeDetection.ts +68 -68
  121. package/src/helpers/customIcons.ts +8 -8
  122. package/src/helpers/fileConfig.ts +37 -37
  123. package/src/helpers/index.ts +100 -100
  124. package/src/helpers/objects.ts +58 -58
  125. package/src/helpers/types.ts +7 -7
  126. package/src/helpers/versioning.ts +73 -73
  127. package/src/i18n/index.ts +78 -78
  128. package/src/i18n/lang-de.ts +54 -54
  129. package/src/i18n/lang-en.ts +53 -53
  130. package/src/i18n/lang-es.ts +53 -53
  131. package/src/i18n/lang-fr.ts +53 -53
  132. package/src/i18n/lang-ja.ts +54 -54
  133. package/src/i18n/lang-nl.ts +54 -54
  134. package/src/i18n/lang-pl.ts +52 -52
  135. package/src/i18n/lang-pt-br.ts +53 -53
  136. package/src/i18n/lang-pt-pt.ts +53 -53
  137. package/src/i18n/lang-ru.ts +52 -52
  138. package/src/i18n/lang-uk.ts +54 -54
  139. package/src/i18n/lang-zh-cn.ts +52 -52
  140. package/src/i18n/lang-zh-tw.ts +52 -52
  141. package/src/icons/fileIcons.ts +1909 -1854
  142. package/src/icons/folderIcons.ts +769 -754
  143. package/src/icons/generator/constants.ts +29 -29
  144. package/src/icons/generator/fileGenerator.ts +216 -216
  145. package/src/icons/generator/folderGenerator.ts +340 -340
  146. package/src/icons/generator/iconOpacity.ts +111 -111
  147. package/src/icons/generator/iconSaturation.ts +140 -140
  148. package/src/icons/generator/index.ts +7 -7
  149. package/src/icons/generator/jsonGenerator.ts +187 -187
  150. package/src/icons/generator/languageGenerator.ts +127 -127
  151. package/src/icons/index.ts +4 -4
  152. package/src/icons/languageIcons.ts +136 -134
  153. package/src/messages/outdated.ts +33 -33
  154. package/src/messages/reload.ts +32 -32
  155. package/src/messages/start.ts +12 -12
  156. package/src/messages/update.ts +48 -48
  157. package/src/messages/welcome.ts +47 -47
  158. package/src/models/helpers/index.ts +1 -1
  159. package/src/models/helpers/themeStatus.ts +5 -5
  160. package/src/models/i18n/index.ts +1 -1
  161. package/src/models/i18n/translation.ts +50 -50
  162. package/src/models/iconConfiguration.ts +37 -37
  163. package/src/models/icons/defaultIcon.ts +16 -16
  164. package/src/models/icons/files/fileIcon.ts +49 -49
  165. package/src/models/icons/files/fileTypes.ts +14 -14
  166. package/src/models/icons/files/index.ts +2 -2
  167. package/src/models/icons/folders/folderIcon.ts +34 -34
  168. package/src/models/icons/folders/folderTheme.ts +23 -23
  169. package/src/models/icons/folders/index.ts +2 -2
  170. package/src/models/icons/iconJsonOptions.ts +23 -23
  171. package/src/models/icons/iconPack.ts +12 -12
  172. package/src/models/icons/index.ts +6 -6
  173. package/src/models/icons/languages/index.ts +1 -1
  174. package/src/models/icons/languages/languageIdentifier.ts +26 -26
  175. package/src/models/index.ts +4 -4
  176. package/src/models/scripts/contributors/contributor.ts +22 -22
  177. package/src/models/scripts/contributors/contributorsConfig.ts +10 -10
  178. package/src/scripts/contributors/contributors.css +24 -24
  179. package/src/scripts/contributors/index.ts +138 -138
  180. package/src/scripts/helpers/painter.ts +5 -5
  181. package/src/scripts/helpers/screenshots.ts +32 -32
  182. package/src/scripts/helpers/similarity.ts +47 -47
  183. package/src/scripts/helpers/titleCase.ts +7 -7
  184. package/src/scripts/icons/checks/checkIconAvailability.ts +215 -215
  185. package/src/scripts/icons/checks/checkIconConflicts.ts +154 -154
  186. package/src/scripts/icons/checks/checkIconUsage.ts +141 -141
  187. package/src/scripts/icons/checks/index.ts +7 -7
  188. package/src/scripts/icons/generateJson.ts +11 -11
  189. package/src/scripts/preview/index.ts +40 -40
  190. package/src/scripts/preview/preview.ts +165 -165
  191. package/src/scripts/preview/style.css +48 -48
  192. package/src/test/runTest.ts +26 -26
  193. package/src/test/spec/i18n/i18n.spec.ts +61 -61
  194. package/src/test/spec/icons/fileIcons.spec.ts +250 -250
  195. package/src/test/spec/icons/folderIcons.spec.ts +418 -418
  196. package/src/test/spec/icons/languageIcons.spec.ts +184 -184
  197. package/src/test/spec/index.ts +36 -36
  198. package/src/web/extension.ts +10 -10
  199. package/svgo.config.js +11 -11
  200. package/tsconfig.json +23 -23
  201. package/icons/nuxt_light.svg +0 -1
@@ -1,111 +1,111 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { getCustomIconPaths } from '../../helpers/customIcons';
4
- import { IconJsonOptions } from '../../models';
5
-
6
- /**
7
- * Changes the opacity of all icons in the set.
8
- * @param options Icon JSON options which include the opacity value.
9
- * @param fileNames Only change the opacity of certain file names.
10
- */
11
- export const setIconOpacity = (
12
- options: IconJsonOptions,
13
- fileNames?: string[]
14
- ) => {
15
- if (!validateOpacityValue(options.opacity)) {
16
- return console.error(
17
- 'Invalid opacity value! Opacity must be a decimal number between 0 and 1!'
18
- );
19
- }
20
-
21
- let iconsPath = '';
22
- if (path.basename(__dirname) === 'dist') {
23
- iconsPath = path.join(__dirname, '..', 'icons');
24
- } else {
25
- // executed via script
26
- iconsPath = path.join(__dirname, '..', '..', '..', 'icons');
27
- }
28
-
29
- const customIconPaths = getCustomIconPaths(options);
30
- const iconFiles = fs.readdirSync(iconsPath);
31
-
32
- try {
33
- // read all icon files from the icons folder
34
- (fileNames || iconFiles).forEach(adjustOpacity(iconsPath, options));
35
-
36
- customIconPaths.forEach((iconPath) => {
37
- const customIcons = fs.readdirSync(iconPath);
38
- customIcons.forEach(adjustOpacity(iconPath, options));
39
- });
40
- } catch (error) {
41
- console.error(error);
42
- }
43
- };
44
-
45
- /**
46
- * Validate the opacity value.
47
- * @param opacity Opacity value
48
- */
49
- export const validateOpacityValue = (opacity: number | undefined) => {
50
- return opacity !== undefined && opacity <= 1 && opacity >= 0;
51
- };
52
-
53
- /**
54
- * Get the SVG root element.
55
- * @param svg SVG file as string.
56
- */
57
- const getSVGRootElement = (svg: string) => {
58
- const result = new RegExp(/<svg[^>]*>/).exec(svg);
59
- return result?.[0];
60
- };
61
-
62
- /**
63
- * Add an opacity attribute to the SVG icon to control the opacity of the icon.
64
- * @param svgRoot Root element of the SVG icon.
65
- * @param opacity Opacity value.
66
- */
67
- const addOpacityAttribute = (svgRoot: string, opacity: number) => {
68
- const pattern = new RegExp(/\sopacity="[\d.]+"/);
69
- // if the opacity attribute already exists
70
- if (pattern.test(svgRoot)) {
71
- return svgRoot.replace(pattern, ` opacity="${opacity}"`);
72
- } else {
73
- return svgRoot.replace(/^<svg/, `<svg opacity="${opacity}"`);
74
- }
75
- };
76
-
77
- /**
78
- * Remove the opacity attribute of the SVG icon.
79
- * @param svgRoot Root element of the SVG icon.
80
- */
81
- const removeOpacityAttribute = (svgRoot: string) => {
82
- const pattern = new RegExp(/\sopacity="[\d.]+"/);
83
- return svgRoot.replace(pattern, '');
84
- };
85
-
86
- const adjustOpacity = (
87
- iconPath: string,
88
- options: IconJsonOptions
89
- ): ((value: string, index: number, array: string[]) => void) => {
90
- return (iconFileName) => {
91
- const svgFilePath = path.join(iconPath, iconFileName);
92
-
93
- // Read SVG file
94
- const svg = fs.readFileSync(svgFilePath, 'utf-8');
95
-
96
- // Get the root element of the SVG file
97
- const svgRootElement = getSVGRootElement(svg);
98
- if (!svgRootElement) return;
99
-
100
- let updatedRootElement: string;
101
-
102
- if (options.opacity !== undefined && options.opacity < 1) {
103
- updatedRootElement = addOpacityAttribute(svgRootElement, options.opacity);
104
- } else {
105
- updatedRootElement = removeOpacityAttribute(svgRootElement);
106
- }
107
- const updatedSVG = svg.replace(/<svg[^>]*>/, updatedRootElement);
108
-
109
- fs.writeFileSync(svgFilePath, updatedSVG);
110
- };
111
- };
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { getCustomIconPaths } from '../../helpers/customIcons';
4
+ import { IconJsonOptions } from '../../models';
5
+
6
+ /**
7
+ * Changes the opacity of all icons in the set.
8
+ * @param options Icon JSON options which include the opacity value.
9
+ * @param fileNames Only change the opacity of certain file names.
10
+ */
11
+ export const setIconOpacity = (
12
+ options: IconJsonOptions,
13
+ fileNames?: string[]
14
+ ) => {
15
+ if (!validateOpacityValue(options.opacity)) {
16
+ return console.error(
17
+ 'Invalid opacity value! Opacity must be a decimal number between 0 and 1!'
18
+ );
19
+ }
20
+
21
+ let iconsPath = '';
22
+ if (path.basename(__dirname) === 'dist') {
23
+ iconsPath = path.join(__dirname, '..', 'icons');
24
+ } else {
25
+ // executed via script
26
+ iconsPath = path.join(__dirname, '..', '..', '..', 'icons');
27
+ }
28
+
29
+ const customIconPaths = getCustomIconPaths(options);
30
+ const iconFiles = fs.readdirSync(iconsPath);
31
+
32
+ try {
33
+ // read all icon files from the icons folder
34
+ (fileNames || iconFiles).forEach(adjustOpacity(iconsPath, options));
35
+
36
+ customIconPaths.forEach((iconPath) => {
37
+ const customIcons = fs.readdirSync(iconPath);
38
+ customIcons.forEach(adjustOpacity(iconPath, options));
39
+ });
40
+ } catch (error) {
41
+ console.error(error);
42
+ }
43
+ };
44
+
45
+ /**
46
+ * Validate the opacity value.
47
+ * @param opacity Opacity value
48
+ */
49
+ export const validateOpacityValue = (opacity: number | undefined) => {
50
+ return opacity !== undefined && opacity <= 1 && opacity >= 0;
51
+ };
52
+
53
+ /**
54
+ * Get the SVG root element.
55
+ * @param svg SVG file as string.
56
+ */
57
+ const getSVGRootElement = (svg: string) => {
58
+ const result = new RegExp(/<svg[^>]*>/).exec(svg);
59
+ return result?.[0];
60
+ };
61
+
62
+ /**
63
+ * Add an opacity attribute to the SVG icon to control the opacity of the icon.
64
+ * @param svgRoot Root element of the SVG icon.
65
+ * @param opacity Opacity value.
66
+ */
67
+ const addOpacityAttribute = (svgRoot: string, opacity: number) => {
68
+ const pattern = new RegExp(/\sopacity="[\d.]+"/);
69
+ // if the opacity attribute already exists
70
+ if (pattern.test(svgRoot)) {
71
+ return svgRoot.replace(pattern, ` opacity="${opacity}"`);
72
+ } else {
73
+ return svgRoot.replace(/^<svg/, `<svg opacity="${opacity}"`);
74
+ }
75
+ };
76
+
77
+ /**
78
+ * Remove the opacity attribute of the SVG icon.
79
+ * @param svgRoot Root element of the SVG icon.
80
+ */
81
+ const removeOpacityAttribute = (svgRoot: string) => {
82
+ const pattern = new RegExp(/\sopacity="[\d.]+"/);
83
+ return svgRoot.replace(pattern, '');
84
+ };
85
+
86
+ const adjustOpacity = (
87
+ iconPath: string,
88
+ options: IconJsonOptions
89
+ ): ((value: string, index: number, array: string[]) => void) => {
90
+ return (iconFileName) => {
91
+ const svgFilePath = path.join(iconPath, iconFileName);
92
+
93
+ // Read SVG file
94
+ const svg = fs.readFileSync(svgFilePath, 'utf-8');
95
+
96
+ // Get the root element of the SVG file
97
+ const svgRootElement = getSVGRootElement(svg);
98
+ if (!svgRootElement) return;
99
+
100
+ let updatedRootElement: string;
101
+
102
+ if (options.opacity !== undefined && options.opacity < 1) {
103
+ updatedRootElement = addOpacityAttribute(svgRootElement, options.opacity);
104
+ } else {
105
+ updatedRootElement = removeOpacityAttribute(svgRootElement);
106
+ }
107
+ const updatedSVG = svg.replace(/<svg[^>]*>/, updatedRootElement);
108
+
109
+ fs.writeFileSync(svgFilePath, updatedSVG);
110
+ };
111
+ };
@@ -1,140 +1,140 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { getCustomIconPaths } from '../../helpers/customIcons';
4
- import { IconJsonOptions } from '../../models';
5
-
6
- /**
7
- * Changes saturation of all icons in the set.
8
- * @param options Icon JSON options which include the saturation value.
9
- * @param fileNames Only change the saturation of certain file names.
10
- */
11
- export const setIconSaturation = (
12
- options: IconJsonOptions,
13
- fileNames?: string[]
14
- ) => {
15
- if (!validateSaturationValue(options.saturation)) {
16
- return console.error(
17
- 'Invalid saturation value! Saturation must be a decimal number between 0 and 1!'
18
- );
19
- }
20
-
21
- let iconsPath = '';
22
- if (path.basename(__dirname) === 'dist') {
23
- iconsPath = path.join(__dirname, '..', 'icons');
24
- } else {
25
- // executed via script
26
- iconsPath = path.join(__dirname, '..', '..', '..', 'icons');
27
- }
28
-
29
- const customIconPaths = getCustomIconPaths(options);
30
- const iconFiles = fs.readdirSync(iconsPath);
31
-
32
- // read all icon files from the icons folder
33
- try {
34
- (fileNames || iconFiles).forEach(adjustSaturation(iconsPath, options));
35
-
36
- customIconPaths.forEach((iconPath) => {
37
- const customIcons = fs.readdirSync(iconPath);
38
- customIcons.forEach(adjustSaturation(iconPath, options));
39
- });
40
- } catch (error) {
41
- console.error(error);
42
- }
43
- };
44
-
45
- /**
46
- * Get the SVG root element.
47
- * @param svg SVG file as string.
48
- */
49
- const getSVGRootElement = (svg: string) => {
50
- const result = new RegExp(/<svg[^>]*>/).exec(svg);
51
- return result?.[0];
52
- };
53
-
54
- /**
55
- * Add an filter attribute to the SVG icon.
56
- * @param svgRoot Root element of the SVG icon.
57
- */
58
- const addFilterAttribute = (svgRoot: string) => {
59
- const pattern = new RegExp(/\sfilter="[^"]+?"/);
60
- // if the filter attribute already exists
61
- if (pattern.test(svgRoot)) {
62
- return svgRoot.replace(pattern, ' filter="url(#saturation)"');
63
- } else {
64
- return svgRoot.replace(/^<svg/, '<svg filter="url(#saturation)"');
65
- }
66
- };
67
-
68
- /**
69
- * Remove the filter attribute of the SVG icon.
70
- * @param svgRoot Root element of the SVG icon.
71
- */
72
- const removeFilterAttribute = (svgRoot: string) => {
73
- const pattern = new RegExp(/\sfilter="[^"]+?"/);
74
- return svgRoot.replace(pattern, '');
75
- };
76
-
77
- /**
78
- * Add filter element to the SVG icon.
79
- * @param svg SVG file as string.
80
- */
81
- const addFilterElement = (svg: string, value: number) => {
82
- const pattern = new RegExp(/<filter id="saturation".+<\/filter>(.*<\/svg>)/);
83
- const filterElement = `<filter id="saturation"><feColorMatrix type="saturate" values="${value}"/></filter>`;
84
- if (pattern.test(svg)) {
85
- return svg.replace(pattern, `${filterElement}$1`);
86
- } else {
87
- return svg.replace(/<\/svg>/, `${filterElement}</svg>`);
88
- }
89
- };
90
-
91
- /**
92
- * Remove filter element from the SVG icon.
93
- * @param svg SVG file as string.
94
- */
95
- const removeFilterElement = (svg: string) => {
96
- const pattern = new RegExp(/<filter id="saturation".+<\/filter>(.*<\/svg>)/);
97
- return svg.replace(pattern, '$1');
98
- };
99
-
100
- /**
101
- * Validate the saturation value.
102
- * @param saturation Saturation value
103
- */
104
- export const validateSaturationValue = (saturation: number | undefined) => {
105
- return saturation !== undefined && saturation <= 1 && saturation >= 0;
106
- };
107
-
108
- const adjustSaturation = (
109
- iconsPath: any,
110
- options: IconJsonOptions
111
- ): ((value: string, index: number, array: string[]) => void) => {
112
- return (iconFileName) => {
113
- const svgFilePath = path.join(iconsPath, iconFileName);
114
-
115
- // Read SVG file
116
- const svg = fs.readFileSync(svgFilePath, 'utf-8');
117
-
118
- // Get the root element of the SVG file
119
- const svgRootElement = getSVGRootElement(svg);
120
- if (!svgRootElement) return;
121
-
122
- let updatedRootElement: string;
123
-
124
- if (options.saturation !== undefined && options.saturation < 1) {
125
- updatedRootElement = addFilterAttribute(svgRootElement);
126
- } else {
127
- updatedRootElement = removeFilterAttribute(svgRootElement);
128
- }
129
-
130
- let updatedSVG = svg.replace(/<svg[^>]*>/, updatedRootElement);
131
-
132
- if (options.saturation !== undefined && options.saturation < 1) {
133
- updatedSVG = addFilterElement(updatedSVG, options.saturation);
134
- } else {
135
- updatedSVG = removeFilterElement(updatedSVG);
136
- }
137
-
138
- fs.writeFileSync(svgFilePath, updatedSVG);
139
- };
140
- };
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { getCustomIconPaths } from '../../helpers/customIcons';
4
+ import { IconJsonOptions } from '../../models';
5
+
6
+ /**
7
+ * Changes saturation of all icons in the set.
8
+ * @param options Icon JSON options which include the saturation value.
9
+ * @param fileNames Only change the saturation of certain file names.
10
+ */
11
+ export const setIconSaturation = (
12
+ options: IconJsonOptions,
13
+ fileNames?: string[]
14
+ ) => {
15
+ if (!validateSaturationValue(options.saturation)) {
16
+ return console.error(
17
+ 'Invalid saturation value! Saturation must be a decimal number between 0 and 1!'
18
+ );
19
+ }
20
+
21
+ let iconsPath = '';
22
+ if (path.basename(__dirname) === 'dist') {
23
+ iconsPath = path.join(__dirname, '..', 'icons');
24
+ } else {
25
+ // executed via script
26
+ iconsPath = path.join(__dirname, '..', '..', '..', 'icons');
27
+ }
28
+
29
+ const customIconPaths = getCustomIconPaths(options);
30
+ const iconFiles = fs.readdirSync(iconsPath);
31
+
32
+ // read all icon files from the icons folder
33
+ try {
34
+ (fileNames || iconFiles).forEach(adjustSaturation(iconsPath, options));
35
+
36
+ customIconPaths.forEach((iconPath) => {
37
+ const customIcons = fs.readdirSync(iconPath);
38
+ customIcons.forEach(adjustSaturation(iconPath, options));
39
+ });
40
+ } catch (error) {
41
+ console.error(error);
42
+ }
43
+ };
44
+
45
+ /**
46
+ * Get the SVG root element.
47
+ * @param svg SVG file as string.
48
+ */
49
+ const getSVGRootElement = (svg: string) => {
50
+ const result = new RegExp(/<svg[^>]*>/).exec(svg);
51
+ return result?.[0];
52
+ };
53
+
54
+ /**
55
+ * Add an filter attribute to the SVG icon.
56
+ * @param svgRoot Root element of the SVG icon.
57
+ */
58
+ const addFilterAttribute = (svgRoot: string) => {
59
+ const pattern = new RegExp(/\sfilter="[^"]+?"/);
60
+ // if the filter attribute already exists
61
+ if (pattern.test(svgRoot)) {
62
+ return svgRoot.replace(pattern, ' filter="url(#saturation)"');
63
+ } else {
64
+ return svgRoot.replace(/^<svg/, '<svg filter="url(#saturation)"');
65
+ }
66
+ };
67
+
68
+ /**
69
+ * Remove the filter attribute of the SVG icon.
70
+ * @param svgRoot Root element of the SVG icon.
71
+ */
72
+ const removeFilterAttribute = (svgRoot: string) => {
73
+ const pattern = new RegExp(/\sfilter="[^"]+?"/);
74
+ return svgRoot.replace(pattern, '');
75
+ };
76
+
77
+ /**
78
+ * Add filter element to the SVG icon.
79
+ * @param svg SVG file as string.
80
+ */
81
+ const addFilterElement = (svg: string, value: number) => {
82
+ const pattern = new RegExp(/<filter id="saturation".+<\/filter>(.*<\/svg>)/);
83
+ const filterElement = `<filter id="saturation"><feColorMatrix type="saturate" values="${value}"/></filter>`;
84
+ if (pattern.test(svg)) {
85
+ return svg.replace(pattern, `${filterElement}$1`);
86
+ } else {
87
+ return svg.replace(/<\/svg>/, `${filterElement}</svg>`);
88
+ }
89
+ };
90
+
91
+ /**
92
+ * Remove filter element from the SVG icon.
93
+ * @param svg SVG file as string.
94
+ */
95
+ const removeFilterElement = (svg: string) => {
96
+ const pattern = new RegExp(/<filter id="saturation".+<\/filter>(.*<\/svg>)/);
97
+ return svg.replace(pattern, '$1');
98
+ };
99
+
100
+ /**
101
+ * Validate the saturation value.
102
+ * @param saturation Saturation value
103
+ */
104
+ export const validateSaturationValue = (saturation: number | undefined) => {
105
+ return saturation !== undefined && saturation <= 1 && saturation >= 0;
106
+ };
107
+
108
+ const adjustSaturation = (
109
+ iconsPath: any,
110
+ options: IconJsonOptions
111
+ ): ((value: string, index: number, array: string[]) => void) => {
112
+ return (iconFileName) => {
113
+ const svgFilePath = path.join(iconsPath, iconFileName);
114
+
115
+ // Read SVG file
116
+ const svg = fs.readFileSync(svgFilePath, 'utf-8');
117
+
118
+ // Get the root element of the SVG file
119
+ const svgRootElement = getSVGRootElement(svg);
120
+ if (!svgRootElement) return;
121
+
122
+ let updatedRootElement: string;
123
+
124
+ if (options.saturation !== undefined && options.saturation < 1) {
125
+ updatedRootElement = addFilterAttribute(svgRootElement);
126
+ } else {
127
+ updatedRootElement = removeFilterAttribute(svgRootElement);
128
+ }
129
+
130
+ let updatedSVG = svg.replace(/<svg[^>]*>/, updatedRootElement);
131
+
132
+ if (options.saturation !== undefined && options.saturation < 1) {
133
+ updatedSVG = addFilterElement(updatedSVG, options.saturation);
134
+ } else {
135
+ updatedSVG = removeFilterElement(updatedSVG);
136
+ }
137
+
138
+ fs.writeFileSync(svgFilePath, updatedSVG);
139
+ };
140
+ };
@@ -1,7 +1,7 @@
1
- export * from './fileGenerator';
2
- export * from './folderGenerator';
3
- export * from './languageGenerator';
4
- export * from './constants';
5
- export * from './jsonGenerator';
6
- export * from './iconOpacity';
7
- export * from './iconSaturation';
1
+ export * from './fileGenerator';
2
+ export * from './folderGenerator';
3
+ export * from './languageGenerator';
4
+ export * from './constants';
5
+ export * from './jsonGenerator';
6
+ export * from './iconOpacity';
7
+ export * from './iconSaturation';