@esri/calcite-ui-icons 4.3.0-next.4 → 4.3.0-next.5

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.
@@ -1,13 +1,12 @@
1
+ "use strict";
1
2
  import fsExtra from "fs-extra";
2
3
  import path from "node:path";
3
- "use strict";
4
- const { readdir, mkdir, writeFile, readFile, lstatSync } = fsExtra;
4
+ const { readdir, mkdir, writeFile, readFile } = fsExtra;
5
5
  const ICONS = path.resolve(path.dirname(process.argv[1]), "../icons");
6
6
  const NAME = "generated";
7
7
  const SIZES = [16, 24, 32];
8
8
  const OUTLINE = "outline";
9
9
  const FILL = "fill";
10
- const isDir = (file) => lstatSync(`${ICONS}/${file}`).isDirectory();
11
10
  const readSVG = (icon) => readFile(`${ICONS}/${icon.fileName}`, { encoding: "utf-8" });
12
11
  const has = (haystack, needle) => haystack.indexOf(needle) > -1;
13
12
  /**
@@ -79,12 +78,12 @@ const has = (haystack, needle) => haystack.indexOf(needle) > -1;
79
78
  * @return {ThenPromise<T>} - Promise that resolves when directory creation is ensured.
80
79
  */
81
80
  function ensureDir(dir) {
82
- return mkdir(dir).catch((error) => {
83
- const triedToCreateExisting = error.code === "EEXIST";
84
- if (!triedToCreateExisting) {
85
- throw error;
86
- }
87
- });
81
+ return mkdir(dir).catch((error) => {
82
+ const triedToCreateExisting = error.code === "EEXIST";
83
+ if (!triedToCreateExisting) {
84
+ throw error;
85
+ }
86
+ });
88
87
  }
89
88
  /**
90
89
  * Builds map of requested icons.
@@ -94,19 +93,19 @@ function ensureDir(dir) {
94
93
  * @return {ExportInfo} - Key-value pair where keys correspond to icon size and values are @link{IconRequest[] requested icons}.
95
94
  */
96
95
  function getRequestedIcons(input) {
97
- const iconsPerSize = {};
98
- SIZES.forEach((size) => (iconsPerSize[size] = []));
99
- input.forEach((icon) => {
100
- const { name, sizes = SIZES[0], style = OUTLINE } = icon;
101
- sizes
102
- .filter((size) => has(SIZES, size))
103
- .forEach((size) => {
104
- const fillPart = style === FILL ? "-f" : "";
105
- const fileName = `${name}-${size}${fillPart}.svg`;
106
- iconsPerSize[size].push({ name, size, style, fileName });
107
- });
108
- });
109
- return iconsPerSize;
96
+ const iconsPerSize = {};
97
+ SIZES.forEach((size) => (iconsPerSize[size] = []));
98
+ input.forEach((icon) => {
99
+ const { name, sizes = SIZES[0], style = OUTLINE } = icon;
100
+ sizes
101
+ .filter((size) => has(SIZES, size))
102
+ .forEach((size) => {
103
+ const fillPart = style === FILL ? "-f" : "";
104
+ const fileName = `${name}-${size}${fillPart}.svg`;
105
+ iconsPerSize[size].push({ name, size, style, fileName });
106
+ });
107
+ });
108
+ return iconsPerSize;
110
109
  }
111
110
  /**
112
111
  * Creates spritesheet export details.
@@ -116,51 +115,51 @@ function getRequestedIcons(input) {
116
115
  * @return {ThenPromise<ExportInfo>} - Promise that resolves with export info.
117
116
  */
118
117
  function generateExportInfo(requested) {
119
- const processRequested = (icons) => {
120
- SIZES.forEach((size) => {
121
- requested[size].forEach((icon) => {
122
- if (!has(icons, icon.fileName)) {
123
- return;
124
- }
125
- exportInfo[size].push({
126
- name: icon.name,
127
- style: icon.style,
128
- size,
129
- fileName: icon.fileName,
130
- });
131
- });
132
- });
133
- };
134
- const processAll = (icons) => {
135
- icons.forEach((icon) => {
136
- SIZES.forEach((size) => {
137
- const fileMatchesSize = icon.indexOf(`-${size}`) > -1;
138
- if (!fileMatchesSize) {
139
- return;
140
- }
141
- const parserPattern = /(.+)-\d\d(-f)?\.svg/;
142
- const [, name, filled] = parserPattern.exec(icon);
143
- exportInfo[size].push({
144
- name,
145
- style: filled ? FILL : OUTLINE,
146
- size,
147
- fileName: icon,
148
- });
149
- });
118
+ const processRequested = (icons) => {
119
+ SIZES.forEach((size) => {
120
+ requested[size].forEach((icon) => {
121
+ if (!has(icons, icon.fileName)) {
122
+ return;
123
+ }
124
+ exportInfo[size].push({
125
+ name: icon.name,
126
+ style: icon.style,
127
+ size,
128
+ fileName: icon.fileName,
150
129
  });
151
- };
152
- const includeAll = SIZES.every((size) => requested[size].length === 0);
153
- const exportInfo = {};
154
- SIZES.forEach((size) => (exportInfo[size] = []));
155
- return readdir(ICONS)
156
- .then((icons) => {
157
- if (includeAll) {
158
- processAll(icons);
159
- return;
130
+ });
131
+ });
132
+ };
133
+ const processAll = (icons) => {
134
+ icons.forEach((icon) => {
135
+ SIZES.forEach((size) => {
136
+ const fileMatchesSize = icon.indexOf(`-${size}`) > -1;
137
+ if (!fileMatchesSize) {
138
+ return;
160
139
  }
161
- processRequested(icons);
140
+ const parserPattern = /(.+)-\d\d(-f)?\.svg/;
141
+ const [, name, filled] = parserPattern.exec(icon);
142
+ exportInfo[size].push({
143
+ name,
144
+ style: filled ? FILL : OUTLINE,
145
+ size,
146
+ fileName: icon,
147
+ });
148
+ });
149
+ });
150
+ };
151
+ const includeAll = SIZES.every((size) => requested[size].length === 0);
152
+ const exportInfo = {};
153
+ SIZES.forEach((size) => (exportInfo[size] = []));
154
+ return readdir(ICONS)
155
+ .then((icons) => {
156
+ if (includeAll) {
157
+ processAll(icons);
158
+ return;
159
+ }
160
+ processRequested(icons);
162
161
  })
163
- .then(() => exportInfo);
162
+ .then(() => exportInfo);
164
163
  }
165
164
  /**
166
165
  * Converts an SVG into a Symbol element.
@@ -170,12 +169,12 @@ function generateExportInfo(requested) {
170
169
  * @return {ThenPromise<string>} - Promise that resolves with symbol element text content.
171
170
  */
172
171
  function svgToSymbol(icon) {
173
- return readSVG(icon).then((svgContent) => {
174
- const svgContentCapturingPattern = /^\s*\<svg[^>]*>(.+)\<\/svg>\s*$/;
175
- const [, innerContent] = svgContentCapturingPattern.exec(svgContent);
176
- const { size } = icon;
177
- return `<symbol id="${icon.name}-${size}" viewbox="0 0 ${size} ${size}">${innerContent}</symbol>`;
178
- });
172
+ return readSVG(icon).then((svgContent) => {
173
+ const svgContentCapturingPattern = /^\s*<svg[^>]*>(.+)<\/svg>\s*$/;
174
+ const [, innerContent] = svgContentCapturingPattern.exec(svgContent);
175
+ const { size } = icon;
176
+ return `<symbol id="${icon.name}-${size}" viewbox="0 0 ${size} ${size}">${innerContent}</symbol>`;
177
+ });
179
178
  }
180
179
  /**
181
180
  * Creates spritesheet content.
@@ -188,9 +187,9 @@ function svgToSymbol(icon) {
188
187
  * @return {ThenPromise<T>} - Promise that resolves when spritesheet is created
189
188
  */
190
189
  function createSpritesheet({ icons, output, size }) {
191
- return Promise.all(icons.map(svgToSymbol))
192
- .then((symbols) => `<svg xmlns="http://www.w3.org/2000/svg">${symbols.join("")}</svg>`)
193
- .then((content) => writeFile(`${output}/${`${NAME}-${size}.svg`}`, content));
190
+ return Promise.all(icons.map(svgToSymbol))
191
+ .then((symbols) => `<svg xmlns="http://www.w3.org/2000/svg">${symbols.join("")}</svg>`)
192
+ .then((content) => writeFile(`${output}/${`${NAME}-${size}.svg`}`, content));
194
193
  }
195
194
  /**
196
195
  * Creates icon spritesheet from config.
@@ -200,28 +199,32 @@ function createSpritesheet({ icons, output, size }) {
200
199
  * @return {ThenPromise<ExportSummary>} - Promise that resolves with export summary.
201
200
  */
202
201
  function spriter(config) {
203
- const startTime = process.hrtime();
204
- const { input = [], output = "./output" } = config;
205
- return ensureDir(output)
206
- .then(() => generateExportInfo(getRequestedIcons(input)))
207
- .then((exportInfo) => Promise.all(SIZES.map((size) => {
208
- const icons = exportInfo[size];
209
- if (icons.length === 0) {
202
+ const startTime = process.hrtime();
203
+ const { input = [], output = "./output" } = config;
204
+ return ensureDir(output)
205
+ .then(() => generateExportInfo(getRequestedIcons(input)))
206
+ .then((exportInfo) =>
207
+ Promise.all(
208
+ SIZES.map((size) => {
209
+ const icons = exportInfo[size];
210
+ if (icons.length === 0) {
210
211
  return;
211
- }
212
- return createSpritesheet({ icons, output, size });
213
- })).then(() => exportInfo))
214
- .then((exportInfo) => {
215
- const endTime = process.hrtime(startTime);
216
- const nanoToMillis = 1000000;
217
- const ellapsed = endTime[1] / nanoToMillis;
218
- const spritesheets = Object.keys(exportInfo).map((size) => {
219
- return {
220
- output: `${output}/${NAME}-${size}.svg`,
221
- icons: exportInfo[size],
222
- };
223
- });
224
- return { ellapsed, spritesheets };
212
+ }
213
+ return createSpritesheet({ icons, output, size });
214
+ }),
215
+ ).then(() => exportInfo),
216
+ )
217
+ .then((exportInfo) => {
218
+ const endTime = process.hrtime(startTime);
219
+ const nanoToMillis = 1000000;
220
+ const ellapsed = endTime[1] / nanoToMillis;
221
+ const spritesheets = Object.keys(exportInfo).map((size) => {
222
+ return {
223
+ output: `${output}/${NAME}-${size}.svg`,
224
+ icons: exportInfo[size],
225
+ };
226
+ });
227
+ return { ellapsed, spritesheets };
225
228
  });
226
229
  }
227
230
  export default spriter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/calcite-ui-icons",
3
- "version": "4.3.0-next.4",
3
+ "version": "4.3.0-next.5",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "A collection of UI SVG icons created by Esri for applications.",
@@ -80,5 +80,5 @@
80
80
  "volta": {
81
81
  "extends": "../../package.json"
82
82
  },
83
- "gitHead": "5b32819b21ed13d93e8092430e5e570fae34e25d"
83
+ "gitHead": "33323c39ed4806d5134759109184b3963131c56c"
84
84
  }