@blueprintjs/icons 4.6.1 → 4.6.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blueprintjs/icons",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.2",
|
|
4
4
|
"description": "Components, fonts, icons, and css files for creating and displaying icons.",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist:bundle": "cross-env NODE_ENV=production webpack",
|
|
26
26
|
"dist:css": "css-dist lib/css/*.css",
|
|
27
27
|
"dist:verify": "assert-package-layout",
|
|
28
|
-
"generate-icon-src": "node scripts/generate-icon-fonts.
|
|
28
|
+
"generate-icon-src": "node scripts/generate-icon-fonts.mjs && node scripts/generate-icon-paths.mjs",
|
|
29
29
|
"lint": "run-p lint:scss lint:es",
|
|
30
30
|
"lint:scss": "sass-lint",
|
|
31
31
|
"lint:es": "es-lint",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@blueprintjs/node-build-scripts": "^6.0.0",
|
|
45
45
|
"@blueprintjs/test-commons": "^1.1.0",
|
|
46
|
+
"@types/svgo": "~1.3.6",
|
|
46
47
|
"enzyme": "^3.11.0",
|
|
47
48
|
"fantasticon": "^1.2.3",
|
|
48
49
|
"mocha": "^10.0.0",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// @ts-check
|
|
17
|
+
|
|
18
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { join, resolve } from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
|
|
22
|
+
export const scriptsDir = fileURLToPath(new URL(".", import.meta.url));
|
|
23
|
+
export const iconResourcesDir = resolve(scriptsDir, "../../../resources/icons");
|
|
24
|
+
export const generatedSrcDir = resolve(scriptsDir, "../src/generated");
|
|
25
|
+
export const NS = "bp4";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} IconMetadata
|
|
29
|
+
* @property {string} displayName - "Icon name" for display
|
|
30
|
+
* @property {string} iconName - `icon-name` for IconName and CSS class
|
|
31
|
+
* @property {string} tags - comma separated list of tags describing this icon
|
|
32
|
+
* @property {string} group - group to which this icon belongs
|
|
33
|
+
* @property {string} content - unicode character for icon glyph in font
|
|
34
|
+
* @property {number} codepoint - icon font codepoint
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// TODO(adahiya): replace this with `await import("../icons.json", { assert: { type: "json" } })` in Node 17.5+
|
|
38
|
+
/** @type {IconMetadata[]} */
|
|
39
|
+
export const iconsMetadata = JSON.parse(readFileSync(resolve(scriptsDir, "../icons.json"), { encoding: "utf8" })).sort(
|
|
40
|
+
(a, b) => a.iconName.localeCompare(b.iconName),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Writes lines to given filename in GENERATED_SRC_DIR.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} filename
|
|
47
|
+
* @param {Array<string>} lines
|
|
48
|
+
*/
|
|
49
|
+
export function writeLinesToFile(filename, ...lines) {
|
|
50
|
+
const outputPath = join(generatedSrcDir, filename);
|
|
51
|
+
const contents = [...lines, ""].join("\n");
|
|
52
|
+
writeFileSync(outputPath, contents);
|
|
53
|
+
}
|
|
@@ -17,40 +17,45 @@
|
|
|
17
17
|
* @fileoverview Generates icon fonts and codepoints from SVG sources
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
const { getLogger } = require("fantasticon/lib/cli/logger");
|
|
22
|
-
const fs = require("fs");
|
|
23
|
-
const path = require("path");
|
|
20
|
+
// @ts-check
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
import { FontAssetType, OtherAssetType, generateFonts as runFantasticon } from "fantasticon";
|
|
23
|
+
import { getLogger } from "fantasticon/lib/cli/logger.js";
|
|
24
|
+
import { mkdirSync } from "node:fs";
|
|
25
|
+
import { join, resolve } from "node:path";
|
|
26
|
+
|
|
27
|
+
import { generatedSrcDir, iconResourcesDir, iconsMetadata, NS, scriptsDir } from "./common.mjs";
|
|
27
28
|
|
|
28
29
|
const logger = getLogger();
|
|
30
|
+
|
|
31
|
+
/** @type {import("fantasticon/lib/utils/codepoints").CodepointsMap} */
|
|
29
32
|
const codepoints = {};
|
|
30
33
|
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
codepoints[icon.iconName] = icon.codepoint;
|
|
34
|
+
for (const icon of iconsMetadata) {
|
|
35
|
+
if (Object.values(codepoints).indexOf(icon.codepoint) !== -1) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`[generate-icon-fonts] Invalid metadata entry in icons.json: icon "${icon.iconName}" cannot have codepoint ${icon.codepoint}, it is already in use.`,
|
|
38
|
+
);
|
|
39
39
|
}
|
|
40
|
+
codepoints[icon.iconName] = icon.codepoint;
|
|
41
|
+
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})();
|
|
43
|
+
logger.start();
|
|
44
|
+
await Promise.all([
|
|
45
|
+
connectToLogger(generateFonts(16, `${NS}-icon-standard`)),
|
|
46
|
+
connectToLogger(generateFonts(20, `${NS}-icon-large`)),
|
|
47
|
+
]);
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {number} size
|
|
51
|
+
* @param {string} prefix
|
|
52
|
+
*/
|
|
48
53
|
async function generateFonts(size, prefix) {
|
|
49
|
-
|
|
54
|
+
mkdirSync(join(generatedSrcDir, `${size}px/paths`), { recursive: true });
|
|
50
55
|
return runFantasticon({
|
|
51
56
|
name: `blueprint-icons-${size}`,
|
|
52
|
-
inputDir:
|
|
53
|
-
outputDir:
|
|
57
|
+
inputDir: join(iconResourcesDir, `${size}px`),
|
|
58
|
+
outputDir: join(generatedSrcDir, `${size}px`),
|
|
54
59
|
normalize: true,
|
|
55
60
|
descent: 0,
|
|
56
61
|
// N.B. Important: we need to scale up the font height so that the icons do not get visually degraded
|
|
@@ -62,11 +67,11 @@ async function generateFonts(size, prefix) {
|
|
|
62
67
|
assetTypes: [OtherAssetType.CSS, OtherAssetType.SCSS, OtherAssetType.TS],
|
|
63
68
|
templates: {
|
|
64
69
|
// N.B. in icons-20, we don't generate CSS or the codepoints since we expect them to be the same as icons-16
|
|
65
|
-
scss:
|
|
66
|
-
css:
|
|
70
|
+
scss: resolve(scriptsDir, `./icons-${size}.scss.hbs`),
|
|
71
|
+
css: resolve(scriptsDir, "./icons.css.hbs"),
|
|
67
72
|
},
|
|
68
73
|
pathOptions: {
|
|
69
|
-
scss:
|
|
74
|
+
scss: join(generatedSrcDir, `${size}px`, "_icon-variables.scss"),
|
|
70
75
|
},
|
|
71
76
|
codepoints,
|
|
72
77
|
tag: "i",
|
|
@@ -74,6 +79,10 @@ async function generateFonts(size, prefix) {
|
|
|
74
79
|
});
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
/**
|
|
83
|
+
* @param {Promise<import("fantasticon/lib/core/runner").RunnerResults>} runner
|
|
84
|
+
* @returns {Promise<void>}
|
|
85
|
+
*/
|
|
77
86
|
function connectToLogger(runner) {
|
|
78
87
|
return runner.then(results => logger.results(results)).catch(error => logger.error(error));
|
|
79
88
|
}
|
|
@@ -15,55 +15,49 @@
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @fileoverview Generates SVG paths used in <Icon> React components
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* Important: we expect ../src/generated/ to contain SVG definitions of all the icons already before this script runs.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// @ts-check
|
|
23
|
+
|
|
24
|
+
import { pascalCase } from "change-case";
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
24
27
|
// Note: we had issues with this approach using svgo v2.x, so for now we stick with v1.x
|
|
25
28
|
// With v2.x, some shapes within the icon SVGs would not get converted to paths correctly,
|
|
26
29
|
// resulting in invalid d="..." attributes rendered by the <Icon> component.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {Object} IconMetadata
|
|
31
|
-
* @property {string} displayName - "Icon name" for display
|
|
32
|
-
* @property {string} iconName - `icon-name` for IconName and CSS class
|
|
33
|
-
* @property {string} tags - comma separated list of tags describing this icon
|
|
34
|
-
* @property {string} group - group to which this icon belongs
|
|
35
|
-
* @property {string} content - unicode character for icon glyph in font
|
|
36
|
-
*/
|
|
30
|
+
import SVGO from "svgo";
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
const ICONS_METADATA = require("../icons.json").sort((a, b) => a.iconName.localeCompare(b.iconName));
|
|
40
|
-
const { RESOURCES_DIR, writeLinesToFile } = require("./common");
|
|
32
|
+
import { iconResourcesDir, iconsMetadata, writeLinesToFile } from "./common.mjs";
|
|
41
33
|
|
|
42
34
|
const svgo = new SVGO({ plugins: [{ convertShapeToPath: { convertArcs: true } }] });
|
|
43
|
-
const ICON_NAMES = ICONS_METADATA.map(icon => icon.iconName);
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
const ICON_NAMES = iconsMetadata.map(icon => icon.iconName);
|
|
37
|
+
|
|
38
|
+
/** @type {[16, 20]} */
|
|
39
|
+
const ICON_SIZES = [16, 20];
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
pathStrings.length > 0
|
|
52
|
-
? `export default [${pathStrings.join(", ")}];`
|
|
53
|
-
: // special case for "blank" icon - we need an explicit typedef
|
|
54
|
-
`const p: string[] = []; export default p;`;
|
|
41
|
+
for (const iconSize of ICON_SIZES) {
|
|
42
|
+
const iconPaths = await getIconPaths(iconSize);
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
for (const [iconName, pathStrings] of Object.entries(iconPaths)) {
|
|
45
|
+
const line =
|
|
46
|
+
pathStrings.length > 0
|
|
47
|
+
? `export default [${pathStrings.join(", ")}];`
|
|
48
|
+
: // special case for "blank" icon - we need an explicit typedef
|
|
49
|
+
`const p: string[] = []; export default p;`;
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
writeLinesToFile(
|
|
61
|
-
`${iconSize}px/paths/index.ts`,
|
|
62
|
-
...ICON_NAMES.map(iconName => `export { default as ${pascalCase(iconName)} } from "./${iconName}";`),
|
|
63
|
-
);
|
|
64
|
-
console.info("Done.");
|
|
51
|
+
writeLinesToFile(`${iconSize}px/paths/${iconName}.ts`, line);
|
|
65
52
|
}
|
|
66
|
-
|
|
53
|
+
|
|
54
|
+
console.info(`Writing index file for ${iconSize}px icon kit paths...`);
|
|
55
|
+
writeLinesToFile(
|
|
56
|
+
`${iconSize}px/paths/index.ts`,
|
|
57
|
+
...ICON_NAMES.map(iconName => `export { default as ${pascalCase(iconName)} } from "./${iconName}";`),
|
|
58
|
+
);
|
|
59
|
+
console.info("Done.");
|
|
60
|
+
}
|
|
67
61
|
|
|
68
62
|
/**
|
|
69
63
|
* Loads SVG file for each icon, extracts path strings `d="path-string"`,
|
|
@@ -75,8 +69,8 @@ async function getIconPaths(iconSize) {
|
|
|
75
69
|
/** @type Record<string, string[]> */
|
|
76
70
|
const iconPaths = {};
|
|
77
71
|
for (const iconName of ICON_NAMES) {
|
|
78
|
-
const filepath =
|
|
79
|
-
const svg =
|
|
72
|
+
const filepath = join(iconResourcesDir, `${iconSize}px/${iconName}.svg`);
|
|
73
|
+
const svg = readFileSync(filepath, "utf-8");
|
|
80
74
|
const optimizedSvg = await svgo.optimize(svg, { path: filepath });
|
|
81
75
|
const pathStrings = (optimizedSvg.data.match(/ d="[^"]+"/g) || [])
|
|
82
76
|
// strip off leading 'd="'
|
package/scripts/common.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2021 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const fs = require("fs");
|
|
17
|
-
const path = require("path");
|
|
18
|
-
|
|
19
|
-
const RESOURCES_DIR = path.resolve(__dirname, "../../../resources/icons");
|
|
20
|
-
const GENERATED_SRC_DIR = path.resolve(__dirname, "../src/generated");
|
|
21
|
-
const NS = "bp4";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Writes lines to given filename in GENERATED_SRC_DIR.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} filename
|
|
27
|
-
* @param {Array<string>} lines
|
|
28
|
-
*/
|
|
29
|
-
function writeLinesToFile(filename, ...lines) {
|
|
30
|
-
const outputPath = path.join(GENERATED_SRC_DIR, filename);
|
|
31
|
-
const contents = [...lines, ""].join("\n");
|
|
32
|
-
fs.writeFileSync(outputPath, contents);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = {
|
|
36
|
-
RESOURCES_DIR,
|
|
37
|
-
GENERATED_SRC_DIR,
|
|
38
|
-
NS,
|
|
39
|
-
writeLinesToFile,
|
|
40
|
-
};
|