@fastkit/icon-font-gen 0.14.13 → 0.16.0-next.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.
- package/README.md +3 -0
- package/dist/cli.d.mts +5 -0
- package/dist/cli.mjs +28 -126
- package/dist/cli.mjs.map +1 -1
- package/dist/generator-qQDqZGRh.mjs +295 -0
- package/dist/generator-qQDqZGRh.mjs.map +1 -0
- package/dist/icon-font-gen.d.mts +94 -0
- package/dist/icon-font-gen.mjs +3 -3
- package/package.json +15 -15
- package/dist/chunk-4DBIOMOL.mjs +0 -328
- package/dist/chunk-4DBIOMOL.mjs.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/icon-font-gen.d.ts +0 -91
- package/dist/icon-font-gen.mjs.map +0 -1
package/README.md
CHANGED
package/dist/cli.d.mts
ADDED
package/dist/cli.mjs
CHANGED
|
@@ -1,107 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { c as IconFontGenError, i as generate, l as DEFAULT_CONFIG_FILENAME, u as DEFAULT_DEST_DIRNAME } from "./generator-qQDqZGRh.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { esbuildRequire, findPackageDir } from "@fastkit/node-util";
|
|
4
|
+
import { cac } from "cac";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
name: "@fastkit/icon-font-gen",
|
|
9
|
-
version: "0.14.13",
|
|
10
|
-
description: "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
11
|
-
keywords: [
|
|
12
|
-
"fastkit",
|
|
13
|
-
"icon"
|
|
14
|
-
],
|
|
15
|
-
homepage: "https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen#readme",
|
|
16
|
-
bugs: {
|
|
17
|
-
url: "https://github.com/dadajam4/fastkit/issues"
|
|
18
|
-
},
|
|
19
|
-
repository: {
|
|
20
|
-
type: "git",
|
|
21
|
-
url: "git+https://github.com/dadajam4/fastkit.git"
|
|
22
|
-
},
|
|
23
|
-
license: "MIT",
|
|
24
|
-
author: "dadajam4",
|
|
25
|
-
type: "module",
|
|
26
|
-
exports: {
|
|
27
|
-
"./package.json": "./package.json",
|
|
28
|
-
".": {
|
|
29
|
-
types: "./dist/icon-font-gen.d.ts",
|
|
30
|
-
import: {
|
|
31
|
-
default: "./dist/icon-font-gen.mjs"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"./cli": {
|
|
35
|
-
types: "./dist/cli.d.ts",
|
|
36
|
-
import: {
|
|
37
|
-
default: "./dist/cli.mjs"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"./*": "./dist/*"
|
|
41
|
-
},
|
|
42
|
-
main: "./dist/icon-font-gen.mjs",
|
|
43
|
-
types: "./dist/icon-font-gen.d.ts",
|
|
44
|
-
typesVersions: {
|
|
45
|
-
"*": {
|
|
46
|
-
".": [
|
|
47
|
-
"./dist/icon-font-gen.d.ts"
|
|
48
|
-
],
|
|
49
|
-
cli: [
|
|
50
|
-
"./dist/cli.d.ts"
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
bin: {
|
|
55
|
-
"icon-font": "./bin/cli.mjs"
|
|
56
|
-
},
|
|
57
|
-
files: [
|
|
58
|
-
"./cli.mjs",
|
|
59
|
-
"dist"
|
|
60
|
-
],
|
|
61
|
-
scripts: {
|
|
62
|
-
build: "plugboy build",
|
|
63
|
-
clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
64
|
-
eslint: "eslint . --ext ts,tsx,js,vue,html,yaml",
|
|
65
|
-
"eslint:fix": "eslint . --ext ts,tsx,js,vue,html,yaml --fix",
|
|
66
|
-
format: "pnpm run eslint:fix",
|
|
67
|
-
lint: "pnpm run eslint",
|
|
68
|
-
stub: "plugboy stub",
|
|
69
|
-
test: "vitest run",
|
|
70
|
-
typecheck: "tsc --noEmit"
|
|
71
|
-
},
|
|
72
|
-
dependencies: {
|
|
73
|
-
"@fastkit/ev": "workspace:^",
|
|
74
|
-
"@fastkit/helpers": "workspace:^",
|
|
75
|
-
"@fastkit/icon-font": "workspace:^",
|
|
76
|
-
"@fastkit/node-util": "workspace:^",
|
|
77
|
-
"@fastkit/tiny-logger": "workspace:^",
|
|
78
|
-
cac: "^6.7.14",
|
|
79
|
-
chokidar: "^3.6.0",
|
|
80
|
-
"fs-extra": "^11.2.0",
|
|
81
|
-
webfont: "^11.2.26"
|
|
82
|
-
},
|
|
83
|
-
buildOptions: {
|
|
84
|
-
name: "IconFont"
|
|
85
|
-
},
|
|
86
|
-
_docs: {
|
|
87
|
-
scope: "",
|
|
88
|
-
feature: "icon",
|
|
89
|
-
description: {
|
|
90
|
-
en: "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
91
|
-
ja: "\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u306E\u305F\u3081\u306B\u30A2\u30A4\u30B3\u30F3Web\u30D5\u30A9\u30F3\u30C8\u3068\u305D\u306E\u5B9A\u7FA9\u3092Type\u30BB\u30FC\u30D5\u306B\u751F\u6210\u3059\u308B\u30C4\u30FC\u30EB\u3002"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
6
|
+
//#region package.json
|
|
7
|
+
var version = "0.16.0-next.0";
|
|
95
8
|
|
|
96
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/cli.ts
|
|
97
11
|
async function cli() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}).command(
|
|
102
|
-
"[config file path]",
|
|
103
|
-
`
|
|
104
|
-
Path of the configuration file. (default: [your package directory]${__plugboy_path.sep}${DEFAULT_CONFIG_FILENAME})
|
|
12
|
+
const _cli = cac("icon-font");
|
|
13
|
+
_cli.option("-d, --dest <string>", "Destination for generated fonts.", { default: path.join(process.cwd(), `${DEFAULT_DEST_DIRNAME}`) }).command("[config file path]", `
|
|
14
|
+
Path of the configuration file. (default: [your package directory]${path.sep}${DEFAULT_CONFIG_FILENAME})
|
|
105
15
|
You must export default <IconFontConfig>.
|
|
106
16
|
|
|
107
17
|
e.g.
|
|
@@ -110,33 +20,25 @@ Path of the configuration file. (default: [your package directory]${__plugboy_pa
|
|
|
110
20
|
|
|
111
21
|
export default createIconFontConfig({ ... });
|
|
112
22
|
\`\`\`
|
|
113
|
-
`.trim()
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
...config,
|
|
130
|
-
dest
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
_cli.help();
|
|
135
|
-
_cli.version(package_default.version);
|
|
136
|
-
_cli.parse();
|
|
23
|
+
`.trim()).action(async (configPath, options) => {
|
|
24
|
+
if (!configPath) {
|
|
25
|
+
const pkgDir = await findPackageDir();
|
|
26
|
+
if (!pkgDir) throw new IconFontGenError("missing package directory.");
|
|
27
|
+
configPath = path.join(pkgDir, DEFAULT_CONFIG_FILENAME);
|
|
28
|
+
}
|
|
29
|
+
const dest = path.resolve(options.dest);
|
|
30
|
+
const config = (await esbuildRequire(configPath)).exports.default;
|
|
31
|
+
await generate({
|
|
32
|
+
...config,
|
|
33
|
+
dest
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
_cli.help();
|
|
37
|
+
_cli.version(version);
|
|
38
|
+
_cli.parse();
|
|
137
39
|
}
|
|
138
40
|
cli();
|
|
139
41
|
|
|
42
|
+
//#endregion
|
|
140
43
|
export { cli };
|
|
141
|
-
//# sourceMappingURL=cli.mjs.map
|
|
142
44
|
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["pkg.version"],"sources":["../package.json","../src/cli.ts"],"sourcesContent":["","import { cac } from 'cac';\nimport path from 'node:path';\nimport { findPackageDir, esbuildRequire } from '@fastkit/node-util';\nimport {\n DEFAULT_DEST_DIRNAME,\n DEFAULT_CONFIG_FILENAME,\n IconFontConfig,\n} from './schemes';\nimport { generate } from './generator';\nimport { IconFontGenError } from './logger';\nimport pkg from '../package.json';\n\nexport async function cli() {\n const _cli = cac('icon-font');\n\n _cli\n .option('-d, --dest <string>', 'Destination for generated fonts.', {\n default: path.join(process.cwd(), `${DEFAULT_DEST_DIRNAME}`),\n })\n .command(\n '[config file path]',\n `\nPath of the configuration file. (default: [your package directory]${path.sep}${DEFAULT_CONFIG_FILENAME})\n You must export default <IconFontConfig>.\n\n e.g.\n \\`\\`\\`\n import { createIconFontConfig } from '@fastkit/icon-font-gen';\n\n export default createIconFontConfig({ ... });\n \\`\\`\\`\n `.trim(),\n )\n .action(\n async (configPath: string | undefined, options: { dest: string }) => {\n if (!configPath) {\n const pkgDir = await findPackageDir();\n if (!pkgDir) {\n throw new IconFontGenError('missing package directory.');\n }\n configPath = path.join(pkgDir, DEFAULT_CONFIG_FILENAME);\n }\n\n const dest = path.resolve(options.dest);\n const mod = await esbuildRequire<{ default: IconFontConfig }>(\n configPath,\n );\n const config = mod.exports.default;\n\n await generate({\n ...config,\n dest,\n });\n },\n );\n\n _cli.help();\n\n _cli.version(pkg.version);\n\n _cli.parse();\n}\n\ncli();\n"],"mappings":";;;;;;;;;;ACYA,eAAsB,MAAM;CAC1B,MAAM,OAAO,IAAI,YAAY;AAE7B,MACG,OAAO,uBAAuB,oCAAoC,EACjE,SAAS,KAAK,KAAK,QAAQ,KAAK,EAAE,GAAG,uBAAuB,EAC7D,CAAC,CACD,QACC,sBACA;oEAC8D,KAAK,MAAM,wBAAwB;;;;;;;;;QAS/F,MAAM,CACT,CACA,OACC,OAAO,YAAgC,YAA8B;AACnE,MAAI,CAAC,YAAY;GACf,MAAM,SAAS,MAAM,gBAAgB;AACrC,OAAI,CAAC,OACH,OAAM,IAAI,iBAAiB,6BAA6B;AAE1D,gBAAa,KAAK,KAAK,QAAQ,wBAAwB;;EAGzD,MAAM,OAAO,KAAK,QAAQ,QAAQ,KAAK;EAIvC,MAAM,UAHM,MAAM,eAChB,WACD,EACkB,QAAQ;AAE3B,QAAM,SAAS;GACb,GAAG;GACH;GACD,CAAC;GAEL;AAEH,MAAK,MAAM;AAEX,MAAK,QAAQA,QAAY;AAEzB,MAAK,OAAO;;AAGd,KAAK"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { HashComparator, installPackage } from "@fastkit/node-util";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import chokidar from "chokidar";
|
|
5
|
+
import { EV } from "@fastkit/ev";
|
|
6
|
+
import { TinyLogger, createTinyError } from "@fastkit/tiny-logger";
|
|
7
|
+
|
|
8
|
+
//#region src/schemes.ts
|
|
9
|
+
const ICON_FONT_FORMATS = [
|
|
10
|
+
"eot",
|
|
11
|
+
"woff",
|
|
12
|
+
"woff2",
|
|
13
|
+
"svg",
|
|
14
|
+
"ttf"
|
|
15
|
+
];
|
|
16
|
+
const ICON_FONT_FORMAT_MAP = {
|
|
17
|
+
eot: "embedded-opentype",
|
|
18
|
+
woff2: "woff2",
|
|
19
|
+
woff: "woff",
|
|
20
|
+
ttf: "truetype",
|
|
21
|
+
svg: "svg"
|
|
22
|
+
};
|
|
23
|
+
async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
24
|
+
const entry = { ...rawEntry };
|
|
25
|
+
if (entry.src === "@mdi") {
|
|
26
|
+
const installedDir = await findOrInstallMDI();
|
|
27
|
+
entry.src = path.join(installedDir, "svg");
|
|
28
|
+
if (entry.fontHeight == null) entry.fontHeight = 512;
|
|
29
|
+
if (entry.descent == null) entry.descent = 64;
|
|
30
|
+
if (entry.name == null) entry.name = "mdi";
|
|
31
|
+
}
|
|
32
|
+
const name = entry.name || path.basename(entry.src);
|
|
33
|
+
const fontName = entry.fontName || `${name}-icon`;
|
|
34
|
+
const dest = path.join(rootDir, name);
|
|
35
|
+
const prefix = entry.disablePrefix ? "" : `${name}-`;
|
|
36
|
+
const display = entry.display || "block";
|
|
37
|
+
return {
|
|
38
|
+
...entry,
|
|
39
|
+
name,
|
|
40
|
+
fontName,
|
|
41
|
+
prefix,
|
|
42
|
+
dest,
|
|
43
|
+
display
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function findOrInstallMDI() {
|
|
47
|
+
return installPackage("@mdi/svg", { dev: true });
|
|
48
|
+
}
|
|
49
|
+
const DEFAULT_CONFIG_FILENAME = "icon-font.config";
|
|
50
|
+
const DEFAULT_DEST_DIRNAME = ".icon-font";
|
|
51
|
+
function ceateIconFontConfig(options) {
|
|
52
|
+
return options;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/logger.ts
|
|
57
|
+
const name = "icon-font-gen";
|
|
58
|
+
const logger = new TinyLogger(name);
|
|
59
|
+
const IconFontGenError = createTinyError(name);
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/generator.ts
|
|
63
|
+
const DEFAULT_OPTIONS = {
|
|
64
|
+
formats: ["woff2"],
|
|
65
|
+
fixedWidth: true,
|
|
66
|
+
normalize: true
|
|
67
|
+
};
|
|
68
|
+
const BANNER = `
|
|
69
|
+
/**
|
|
70
|
+
* This is auto generated file.
|
|
71
|
+
* Do not edit !!!
|
|
72
|
+
*
|
|
73
|
+
* @see: https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen
|
|
74
|
+
*/
|
|
75
|
+
`.trim();
|
|
76
|
+
function mergeDefaults(entry) {
|
|
77
|
+
return {
|
|
78
|
+
...DEFAULT_OPTIONS,
|
|
79
|
+
...entry
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async function generateTS(entry, ids) {
|
|
83
|
+
const code = `
|
|
84
|
+
/* eslint-disable */
|
|
85
|
+
// @ts-nocheck
|
|
86
|
+
${BANNER}
|
|
87
|
+
import type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
88
|
+
import { registerIconNames } from '@fastkit/icon-font';
|
|
89
|
+
declare module "@fastkit/icon-font" {
|
|
90
|
+
export interface IconNameMap {
|
|
91
|
+
${ids.map((id) => ` '${id}': true,`).join("\n")}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export const ICON_NAMES = registerIconNames([
|
|
95
|
+
${ids.map((id) => `'${id}'`).join(",\n ")}
|
|
96
|
+
]);
|
|
97
|
+
export type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
98
|
+
`.trim();
|
|
99
|
+
const fileName = `${entry.name || "icons"}.ts`;
|
|
100
|
+
const dest = path.resolve(entry.dest, fileName);
|
|
101
|
+
await fs.writeFile(dest, code);
|
|
102
|
+
return {
|
|
103
|
+
fileName,
|
|
104
|
+
dest,
|
|
105
|
+
code
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function generateEntry(entry) {
|
|
109
|
+
const options = mergeDefaults(entry);
|
|
110
|
+
const cssPrefix = `icon-${options.prefix}`;
|
|
111
|
+
const hash = new HashComparator(options.src, options.dest);
|
|
112
|
+
const srcHash = await hash.hasChanged();
|
|
113
|
+
if (!srcHash) {
|
|
114
|
+
logger.info(`Has not changed files. Skip process. >>> ${options.src}`);
|
|
115
|
+
return { entry };
|
|
116
|
+
}
|
|
117
|
+
await fs.ensureDir(options.dest);
|
|
118
|
+
const { webfont } = await import("webfont");
|
|
119
|
+
const { startUnicode = 47617 } = options;
|
|
120
|
+
let i = startUnicode;
|
|
121
|
+
const result = await webfont({
|
|
122
|
+
files: options.src,
|
|
123
|
+
fontName: options.fontName,
|
|
124
|
+
formats: options.formats,
|
|
125
|
+
fixedWidth: options.fixedWidth,
|
|
126
|
+
centerHorizontally: options.centerHorizontally,
|
|
127
|
+
normalize: options.normalize,
|
|
128
|
+
fontHeight: options.fontHeight,
|
|
129
|
+
round: options.round,
|
|
130
|
+
descent: options.descent,
|
|
131
|
+
addHashInFontUrl: options.addHashInFontUrl,
|
|
132
|
+
glyphTransformFn: (obj) => {
|
|
133
|
+
obj.unicode = [String.fromCodePoint(i)];
|
|
134
|
+
i++;
|
|
135
|
+
return obj;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const buildedFormats = [];
|
|
139
|
+
ICON_FONT_FORMATS.forEach((format) => {
|
|
140
|
+
const code = result[format];
|
|
141
|
+
if (code) buildedFormats.push({
|
|
142
|
+
format,
|
|
143
|
+
code
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
await Promise.all(buildedFormats.map(({ format, code }) => fs.writeFile(path.join(options.dest, `${options.name}.${format}`), code)));
|
|
147
|
+
const glyphs = [];
|
|
148
|
+
result.glyphsData.forEach(({ metadata }) => {
|
|
149
|
+
if (!metadata) return;
|
|
150
|
+
const { name, unicode } = metadata;
|
|
151
|
+
if (!unicode) return;
|
|
152
|
+
const code = unicode[0].charCodeAt(0).toString(16);
|
|
153
|
+
glyphs.push({
|
|
154
|
+
name,
|
|
155
|
+
code
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
const urlPath = options.absolutePath ? options.dest : ".";
|
|
159
|
+
const hashSuffix = options.addHashInFontUrl ? `?${Date.now()}` : "";
|
|
160
|
+
const src = buildedFormats.map(({ format }) => `url("${urlPath}/${options.name}.${format}${hashSuffix}") format("${ICON_FONT_FORMAT_MAP[format]}")`).join(",");
|
|
161
|
+
const cssCode = `/* stylelint-disable */
|
|
162
|
+
@font-face {
|
|
163
|
+
font-family: "${options.fontName}";
|
|
164
|
+
font-display: ${options.display};
|
|
165
|
+
font-style: normal;
|
|
166
|
+
font-weight: 400;
|
|
167
|
+
src: ${src};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
i[class^="${cssPrefix}"]:before, i[class*=" ${cssPrefix}"]:before {
|
|
171
|
+
font-family: ${options.fontName} !important;
|
|
172
|
+
font-style: normal;
|
|
173
|
+
font-weight: normal !important;
|
|
174
|
+
font-variant: normal;
|
|
175
|
+
text-transform: none;
|
|
176
|
+
text-rendering: auto;
|
|
177
|
+
line-height: 1;
|
|
178
|
+
-webkit-font-smoothing: antialiased;
|
|
179
|
+
-moz-osx-font-smoothing: grayscale;
|
|
180
|
+
}
|
|
181
|
+
${glyphs.map(({ name, code }) => `
|
|
182
|
+
.${cssPrefix}${name}:before { content: "\\${code}"; }
|
|
183
|
+
`).join("\n")}
|
|
184
|
+
`;
|
|
185
|
+
await fs.writeFile(path.join(options.dest, `${options.name}.css`), cssCode);
|
|
186
|
+
await generateTS(options, glyphs.map(({ name }) => `${options.prefix}${name}`));
|
|
187
|
+
await hash.commit(srcHash);
|
|
188
|
+
return {
|
|
189
|
+
entry,
|
|
190
|
+
result
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function generateIndex(dest, entries) {
|
|
194
|
+
const names = entries.map(({ name }) => name);
|
|
195
|
+
const tsCode = `
|
|
196
|
+
/* eslint-disable */
|
|
197
|
+
// @ts-nocheck
|
|
198
|
+
import './index.css';
|
|
199
|
+
${BANNER}
|
|
200
|
+
${names.map((name, index) => `import './${name}/${name}';`).join("\n")}
|
|
201
|
+
export type { IconName } from '@fastkit/icon-font';
|
|
202
|
+
export { ICON_NAMES } from '@fastkit/icon-font';
|
|
203
|
+
`.trim();
|
|
204
|
+
const tsDest = path.join(dest, "index.ts");
|
|
205
|
+
await fs.writeFile(tsDest, tsCode);
|
|
206
|
+
const cssCode = `
|
|
207
|
+
/* stylelint-disable */
|
|
208
|
+
${BANNER}
|
|
209
|
+
${names.map((name) => `@import './${name}/${name}.css';`).join("\n")}
|
|
210
|
+
`.trim();
|
|
211
|
+
const cssDest = path.join(dest, "index.css");
|
|
212
|
+
await fs.writeFile(cssDest, cssCode);
|
|
213
|
+
}
|
|
214
|
+
async function generate(opts) {
|
|
215
|
+
await fs.emptyDir(opts.dest);
|
|
216
|
+
const entries = (await Promise.all(opts.entries.map((entry) => resolveRawIconFontEntry(opts.dest, entry).then((_entry) => generateEntry(_entry))))).map(({ entry }) => entry);
|
|
217
|
+
await generateIndex(opts.dest, entries);
|
|
218
|
+
}
|
|
219
|
+
var IconFontRunnerItem = class extends EV {
|
|
220
|
+
entry;
|
|
221
|
+
ctx;
|
|
222
|
+
_resolveEntryPromise;
|
|
223
|
+
_watcher = null;
|
|
224
|
+
watchMode;
|
|
225
|
+
constructor(ctx, entry, watch = false) {
|
|
226
|
+
super();
|
|
227
|
+
this.ctx = ctx;
|
|
228
|
+
this.entry = entry;
|
|
229
|
+
this.watchMode = watch;
|
|
230
|
+
this.build = this.build.bind(this);
|
|
231
|
+
}
|
|
232
|
+
async run() {
|
|
233
|
+
const result = await this.build();
|
|
234
|
+
if (this.watchMode && !this._watcher) {
|
|
235
|
+
const watchDir = path.resolve(this.entry.src);
|
|
236
|
+
this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });
|
|
237
|
+
this._watcher.on("all", this.build);
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
resolveEntry() {
|
|
242
|
+
if (!this._resolveEntryPromise) this._resolveEntryPromise = resolveRawIconFontEntry(this.ctx.dest, this.entry);
|
|
243
|
+
return this._resolveEntryPromise;
|
|
244
|
+
}
|
|
245
|
+
async build() {
|
|
246
|
+
const entry = await this.resolveEntry();
|
|
247
|
+
const result = await generateEntry(entry);
|
|
248
|
+
this.emit("build", result);
|
|
249
|
+
return { entry };
|
|
250
|
+
}
|
|
251
|
+
destroy() {
|
|
252
|
+
if (this._watcher) {
|
|
253
|
+
this._watcher.close();
|
|
254
|
+
this._watcher = null;
|
|
255
|
+
}
|
|
256
|
+
this.offAll();
|
|
257
|
+
if (this.ctx) delete this.ctx;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
var IconFontRunner = class extends EV {
|
|
261
|
+
items = [];
|
|
262
|
+
dest;
|
|
263
|
+
constructor(opts, watch) {
|
|
264
|
+
super();
|
|
265
|
+
this.dest = opts.dest;
|
|
266
|
+
opts.entries.forEach((entry) => {
|
|
267
|
+
const item = new IconFontRunnerItem(this, entry, watch);
|
|
268
|
+
item.on("build", (result) => {
|
|
269
|
+
this.emit("build", {
|
|
270
|
+
item,
|
|
271
|
+
result
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
this.items.push(item);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
async buildIndex() {
|
|
278
|
+
const entries = await Promise.all(this.items.map((item) => item.resolveEntry()));
|
|
279
|
+
return generateIndex(this.dest, entries);
|
|
280
|
+
}
|
|
281
|
+
async run() {
|
|
282
|
+
await fs.ensureDir(this.dest);
|
|
283
|
+
await Promise.all([this.buildIndex(), Promise.all(this.items.map((item) => item.run()))]);
|
|
284
|
+
}
|
|
285
|
+
destroy() {
|
|
286
|
+
this.items.forEach((item) => item.destroy());
|
|
287
|
+
this.items.length = 0;
|
|
288
|
+
this.offAll();
|
|
289
|
+
delete this._opts;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
export { generateEntry as a, IconFontGenError as c, ICON_FONT_FORMATS as d, ICON_FONT_FORMAT_MAP as f, generate as i, DEFAULT_CONFIG_FILENAME as l, resolveRawIconFontEntry as m, IconFontRunner as n, generateIndex as o, ceateIconFontConfig as p, IconFontRunnerItem as r, mergeDefaults as s, DEFAULT_OPTIONS as t, DEFAULT_DEST_DIRNAME as u };
|
|
295
|
+
//# sourceMappingURL=generator-qQDqZGRh.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-qQDqZGRh.mjs","names":[],"sources":["../src/schemes.ts","../src/logger.ts","../src/generator.ts"],"sourcesContent":["import type { OptionsBase } from 'webfont/dist/src/types/OptionsBase';\nimport path from 'node:path';\nimport { installPackage } from '@fastkit/node-util';\n\nexport type IconFontFormat = NonNullable<OptionsBase['formats']>[number];\n\nexport const ICON_FONT_FORMATS: IconFontFormat[] = [\n 'eot',\n 'woff',\n 'woff2',\n 'svg',\n 'ttf',\n];\n\nexport const ICON_FONT_FORMAT_MAP: Record<IconFontFormat, string> = {\n eot: 'embedded-opentype',\n woff2: 'woff2',\n woff: 'woff',\n ttf: 'truetype',\n svg: 'svg',\n};\n\nexport interface IconFontSettings {\n fixedWidth?: boolean;\n centerHorizontally?: boolean;\n normalize?: boolean;\n fontHeight?: number;\n round?: number;\n descent?: number;\n disablePrefix?: boolean;\n absolutePath?: boolean;\n addHashInFontUrl?: boolean;\n}\n\nexport interface IconFontEntry extends IconFontSettings {\n name: string;\n fontName: string;\n formats?: IconFontFormat[];\n startUnicode?: number;\n prefix: string;\n src: string;\n dest: string;\n display: 'block' | 'swap';\n}\n\nexport interface RawIconFontEntry\n extends Omit<\n IconFontEntry,\n 'name' | 'fontName' | 'prefix' | 'dest' | 'display'\n > {\n name?: string;\n fontName?: string;\n /**\n * @default block\n */\n display?: 'block' | 'swap';\n}\n\n// export type RawIconFontOptions = IconFontEntry | IconFontEntry[];\n\nexport interface IconFontOptions {\n entries: RawIconFontEntry[];\n dest: string;\n}\n\nexport async function resolveRawIconFontEntry(\n rootDir: string,\n rawEntry: RawIconFontEntry,\n): Promise<IconFontEntry> {\n const entry = {\n ...rawEntry,\n };\n\n // mdi support\n if (entry.src === '@mdi') {\n const installedDir = await findOrInstallMDI();\n entry.src = path.join(installedDir, 'svg');\n if (entry.fontHeight == null) {\n entry.fontHeight = 512;\n }\n if (entry.descent == null) {\n entry.descent = 64;\n }\n if (entry.name == null) {\n entry.name = 'mdi';\n }\n }\n\n const name = entry.name || path.basename(entry.src);\n const fontName = entry.fontName || `${name}-icon`;\n const dest = path.join(rootDir, name);\n const prefix = entry.disablePrefix ? '' : `${name}-`;\n const display = entry.display || 'block';\n return {\n ...entry,\n name,\n fontName,\n prefix,\n dest,\n display,\n };\n}\n\nfunction findOrInstallMDI() {\n return installPackage('@mdi/svg', { dev: true });\n}\n\nexport const DEFAULT_CONFIG_FILENAME = 'icon-font.config';\n\nexport const DEFAULT_DEST_DIRNAME = '.icon-font';\n\nexport interface IconFontConfig extends Omit<IconFontOptions, 'dest'> {\n dest?: string;\n}\n\nexport function ceateIconFontConfig(options: IconFontConfig) {\n return options;\n}\n","import { TinyLogger, createTinyError } from '@fastkit/tiny-logger';\n\nconst name = 'icon-font-gen';\n\nexport const logger = new TinyLogger(name);\n\nexport const IconFontGenError = createTinyError(name);\n","import fs from 'fs-extra';\nimport path from 'node:path';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport { EV } from '@fastkit/ev';\nimport { HashComparator } from '@fastkit/node-util';\nimport { UnPromisify } from '@fastkit/helpers';\nimport type webfont from 'webfont';\nimport { logger } from './logger';\nimport {\n IconFontOptions,\n IconFontEntry,\n RawIconFontEntry,\n resolveRawIconFontEntry,\n ICON_FONT_FORMATS,\n IconFontFormat,\n ICON_FONT_FORMAT_MAP,\n} from './schemes';\n\nexport type IconFontEntryResult = {\n entry: IconFontEntry;\n result?: UnPromisify<ReturnType<typeof webfont>>;\n};\n\nexport const DEFAULT_OPTIONS: Partial<IconFontEntry> = {\n formats: ['woff2'],\n fixedWidth: true,\n normalize: true,\n};\n\nconst BANNER = `\n/**\n * This is auto generated file.\n * Do not edit !!!\n *\n * @see: https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen\n */\n`.trim();\n\nexport function mergeDefaults(entry: IconFontEntry): IconFontEntry {\n return {\n ...DEFAULT_OPTIONS,\n ...entry,\n };\n}\n\nasync function generateTS(entry: IconFontEntry, ids: string[]) {\n const code = `\n/* eslint-disable */\n// @ts-nocheck\n${BANNER}\nimport type { IconName, IconNameMap } from '@fastkit/icon-font';\nimport { registerIconNames } from '@fastkit/icon-font';\ndeclare module \"@fastkit/icon-font\" {\n export interface IconNameMap {\n${ids.map((id) => ` '${id}': true,`).join('\\n')}\n }\n}\nexport const ICON_NAMES = registerIconNames([\n ${ids.map((id) => `'${id}'`).join(',\\n ')}\n]);\nexport type { IconName, IconNameMap } from '@fastkit/icon-font';\n `.trim();\n const fileName = `${entry.name || 'icons'}.ts`;\n const dest = path.resolve(entry.dest, fileName);\n await fs.writeFile(dest, code);\n return {\n fileName,\n dest,\n code,\n };\n}\n\nexport async function generateEntry(\n entry: IconFontEntry,\n): Promise<IconFontEntryResult> {\n const options = mergeDefaults(entry);\n\n // @TODO support empty prefix\n // const namePrefix = options.name;\n const cssPrefix = `icon-${options.prefix}`;\n\n const hash = new HashComparator(options.src, options.dest);\n const srcHash = await hash.hasChanged();\n if (!srcHash) {\n logger.info(`Has not changed files. Skip process. >>> ${options.src}`);\n return { entry };\n }\n\n await fs.ensureDir(options.dest);\n\n const { webfont } = await import('webfont');\n\n // const { startUnicode = 0xea01 } = options;\n const { startUnicode = 0xba01 } = options;\n\n let i = startUnicode;\n\n const result = await webfont({\n files: options.src,\n fontName: options.fontName,\n formats: options.formats,\n fixedWidth: options.fixedWidth,\n centerHorizontally: options.centerHorizontally,\n normalize: options.normalize,\n fontHeight: options.fontHeight,\n round: options.round,\n descent: options.descent,\n addHashInFontUrl: options.addHashInFontUrl,\n glyphTransformFn: (obj) => {\n const char = String.fromCodePoint(i);\n obj.unicode = [char];\n i++;\n return obj;\n },\n });\n\n const buildedFormats: { format: IconFontFormat; code: string | Buffer }[] =\n [];\n ICON_FONT_FORMATS.forEach((format) => {\n const code = result[format];\n if (code) {\n buildedFormats.push({ format, code });\n }\n });\n\n await Promise.all(\n buildedFormats.map(({ format, code }) =>\n fs.writeFile(\n path.join(options.dest, `${options.name}.${format}`),\n code as string | Uint8Array,\n ),\n ),\n );\n\n const glyphs: { name: string; code: string }[] = [];\n\n result.glyphsData!.forEach(({ metadata }) => {\n if (!metadata) return;\n const { name, unicode } = metadata;\n if (!unicode) {\n return;\n }\n\n const code = unicode[0].charCodeAt(0).toString(16);\n glyphs.push({ name, code });\n });\n\n const urlPath = options.absolutePath ? options.dest : '.';\n const hashSuffix = options.addHashInFontUrl ? `?${Date.now()}` : '';\n const src = buildedFormats\n .map(\n ({ format }) =>\n `url(\"${urlPath}/${options.name}.${format}${hashSuffix}\") format(\"${ICON_FONT_FORMAT_MAP[format]}\")`,\n )\n .join(',');\n\n const cssCode = `/* stylelint-disable */\n@font-face {\n font-family: \"${options.fontName}\";\n font-display: ${options.display};\n font-style: normal;\n font-weight: 400;\n src: ${src};\n}\n\ni[class^=\"${cssPrefix}\"]:before, i[class*=\" ${cssPrefix}\"]:before {\n font-family: ${options.fontName} !important;\n font-style: normal;\n font-weight: normal !important;\n font-variant: normal;\n text-transform: none;\n text-rendering: auto;\n line-height: 1;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n${glyphs\n .map(\n ({ name, code }) => `\n.${cssPrefix}${name}:before { content: \"\\\\${code}\"; }\n `,\n )\n .join('\\n')}\n `;\n await fs.writeFile(path.join(options.dest, `${options.name}.css`), cssCode);\n\n // const prefix = options.prefix ? `${options.prefix}-` : '';\n const ids = glyphs.map(({ name }) => `${options.prefix}${name}`);\n await generateTS(options, ids);\n await hash.commit(srcHash);\n return {\n entry,\n result,\n };\n}\n\nexport async function generateIndex(dest: string, entries: IconFontEntry[]) {\n const names = entries.map(({ name }) => name);\n const tsCode = `\n/* eslint-disable */\n// @ts-nocheck\nimport './index.css';\n${BANNER}\n${names\n .map(\n (name, index) =>\n // `import { IconName as IconName_${index}, IconNameMap as IconNameMap_${index} } from './${name}/${name}';`,\n `import './${name}/${name}';`,\n )\n .join('\\n')}\nexport type { IconName } from '@fastkit/icon-font';\nexport { ICON_NAMES } from '@fastkit/icon-font';\n `.trim();\n const tsDest = path.join(dest, 'index.ts');\n await fs.writeFile(tsDest, tsCode);\n\n const cssCode = `\n/* stylelint-disable */\n${BANNER}\n${names.map((name) => `@import './${name}/${name}.css';`).join('\\n')}\n `.trim();\n const cssDest = path.join(dest, 'index.css');\n await fs.writeFile(cssDest, cssCode);\n}\n\nexport async function generate(opts: IconFontOptions) {\n await fs.emptyDir(opts.dest);\n const results = await Promise.all(\n opts.entries.map((entry) =>\n resolveRawIconFontEntry(opts.dest, entry).then((_entry) =>\n generateEntry(_entry),\n ),\n ),\n );\n const entries = results.map(({ entry }) => entry);\n await generateIndex(opts.dest, entries);\n}\n\nexport class IconFontRunnerItem extends EV<{\n build: IconFontEntryResult;\n}> {\n readonly entry: RawIconFontEntry;\n\n readonly ctx: IconFontRunner;\n\n private _resolveEntryPromise?: Promise<IconFontEntry>;\n\n private _watcher: FSWatcher | null = null;\n\n watchMode: boolean;\n\n // get name() {\n // return this.entry.name;\n // }\n\n constructor(ctx: IconFontRunner, entry: RawIconFontEntry, watch = false) {\n super();\n this.ctx = ctx;\n this.entry = entry;\n this.watchMode = watch;\n this.build = this.build.bind(this);\n }\n\n async run() {\n const result = await this.build();\n if (this.watchMode && !this._watcher) {\n const watchDir = path.resolve(this.entry.src);\n this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });\n this._watcher.on('all', this.build);\n }\n return result;\n }\n\n resolveEntry() {\n if (!this._resolveEntryPromise) {\n this._resolveEntryPromise = resolveRawIconFontEntry(\n this.ctx.dest,\n this.entry,\n );\n }\n return this._resolveEntryPromise;\n }\n\n async build() {\n const entry = await this.resolveEntry();\n const result = await generateEntry(entry);\n this.emit('build', result);\n return { entry };\n }\n\n destroy() {\n if (this._watcher) {\n this._watcher.close();\n this._watcher = null;\n }\n this.offAll();\n if (this.ctx) {\n delete (this as any).ctx;\n }\n }\n}\n\nexport class IconFontRunner extends EV<{\n build: {\n item: IconFontRunnerItem;\n result: IconFontEntryResult;\n };\n}> {\n readonly items: IconFontRunnerItem[] = [];\n\n readonly dest: string;\n\n constructor(opts: IconFontOptions, watch?: boolean) {\n super();\n\n this.dest = opts.dest;\n\n opts.entries.forEach((entry) => {\n const item = new IconFontRunnerItem(this, entry, watch);\n item.on('build', (result) => {\n this.emit('build', { item, result });\n });\n this.items.push(item);\n });\n }\n\n async buildIndex() {\n const entries = await Promise.all(\n this.items.map((item) => item.resolveEntry()),\n );\n return generateIndex(this.dest, entries);\n }\n\n async run() {\n await fs.ensureDir(this.dest);\n await Promise.all([\n this.buildIndex(),\n Promise.all(this.items.map((item) => item.run())),\n ]);\n }\n\n destroy() {\n this.items.forEach((item) => item.destroy());\n this.items.length = 0;\n this.offAll();\n delete (this as any)._opts;\n }\n}\n"],"mappings":";;;;;;;;AAMA,MAAa,oBAAsC;CACjD;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,uBAAuD;CAClE,KAAK;CACL,OAAO;CACP,MAAM;CACN,KAAK;CACL,KAAK;CACN;AA6CD,eAAsB,wBACpB,SACA,UACwB;CACxB,MAAM,QAAQ,EACZ,GAAG,UACJ;AAGD,KAAI,MAAM,QAAQ,QAAQ;EACxB,MAAM,eAAe,MAAM,kBAAkB;AAC7C,QAAM,MAAM,KAAK,KAAK,cAAc,MAAM;AAC1C,MAAI,MAAM,cAAc,KACtB,OAAM,aAAa;AAErB,MAAI,MAAM,WAAW,KACnB,OAAM,UAAU;AAElB,MAAI,MAAM,QAAQ,KAChB,OAAM,OAAO;;CAIjB,MAAM,OAAO,MAAM,QAAQ,KAAK,SAAS,MAAM,IAAI;CACnD,MAAM,WAAW,MAAM,YAAY,GAAG,KAAK;CAC3C,MAAM,OAAO,KAAK,KAAK,SAAS,KAAK;CACrC,MAAM,SAAS,MAAM,gBAAgB,KAAK,GAAG,KAAK;CAClD,MAAM,UAAU,MAAM,WAAW;AACjC,QAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACA;EACD;;AAGH,SAAS,mBAAmB;AAC1B,QAAO,eAAe,YAAY,EAAE,KAAK,MAAM,CAAC;;AAGlD,MAAa,0BAA0B;AAEvC,MAAa,uBAAuB;AAMpC,SAAgB,oBAAoB,SAAyB;AAC3D,QAAO;;;;;AClHT,MAAM,OAAO;AAEb,MAAa,SAAS,IAAI,WAAW,KAAK;AAE1C,MAAa,mBAAmB,gBAAgB,KAAK;;;;ACiBr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C,OAAK,MAAM,SAAS;AACpB,OAAK,QAAQ;AACb,SAAQ,KAAa"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { EV } from "@fastkit/ev";
|
|
2
|
+
import webfont from "webfont";
|
|
3
|
+
import { OptionsBase } from "webfont/dist/src/types/OptionsBase";
|
|
4
|
+
import { UnPromisify } from "@fastkit/helpers";
|
|
5
|
+
|
|
6
|
+
//#region src/schemes.d.ts
|
|
7
|
+
type IconFontFormat = NonNullable<OptionsBase['formats']>[number];
|
|
8
|
+
declare const ICON_FONT_FORMATS: IconFontFormat[];
|
|
9
|
+
declare const ICON_FONT_FORMAT_MAP: Record<IconFontFormat, string>;
|
|
10
|
+
interface IconFontSettings {
|
|
11
|
+
fixedWidth?: boolean;
|
|
12
|
+
centerHorizontally?: boolean;
|
|
13
|
+
normalize?: boolean;
|
|
14
|
+
fontHeight?: number;
|
|
15
|
+
round?: number;
|
|
16
|
+
descent?: number;
|
|
17
|
+
disablePrefix?: boolean;
|
|
18
|
+
absolutePath?: boolean;
|
|
19
|
+
addHashInFontUrl?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface IconFontEntry extends IconFontSettings {
|
|
22
|
+
name: string;
|
|
23
|
+
fontName: string;
|
|
24
|
+
formats?: IconFontFormat[];
|
|
25
|
+
startUnicode?: number;
|
|
26
|
+
prefix: string;
|
|
27
|
+
src: string;
|
|
28
|
+
dest: string;
|
|
29
|
+
display: 'block' | 'swap';
|
|
30
|
+
}
|
|
31
|
+
interface RawIconFontEntry extends Omit<IconFontEntry, 'name' | 'fontName' | 'prefix' | 'dest' | 'display'> {
|
|
32
|
+
name?: string;
|
|
33
|
+
fontName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* @default block
|
|
36
|
+
*/
|
|
37
|
+
display?: 'block' | 'swap';
|
|
38
|
+
}
|
|
39
|
+
interface IconFontOptions {
|
|
40
|
+
entries: RawIconFontEntry[];
|
|
41
|
+
dest: string;
|
|
42
|
+
}
|
|
43
|
+
declare function resolveRawIconFontEntry(rootDir: string, rawEntry: RawIconFontEntry): Promise<IconFontEntry>;
|
|
44
|
+
declare const DEFAULT_CONFIG_FILENAME = "icon-font.config";
|
|
45
|
+
declare const DEFAULT_DEST_DIRNAME = ".icon-font";
|
|
46
|
+
interface IconFontConfig extends Omit<IconFontOptions, 'dest'> {
|
|
47
|
+
dest?: string;
|
|
48
|
+
}
|
|
49
|
+
declare function ceateIconFontConfig(options: IconFontConfig): IconFontConfig;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/generator.d.ts
|
|
52
|
+
type IconFontEntryResult = {
|
|
53
|
+
entry: IconFontEntry;
|
|
54
|
+
result?: UnPromisify<ReturnType<typeof webfont>>;
|
|
55
|
+
};
|
|
56
|
+
declare const DEFAULT_OPTIONS: Partial<IconFontEntry>;
|
|
57
|
+
declare function mergeDefaults(entry: IconFontEntry): IconFontEntry;
|
|
58
|
+
declare function generateEntry(entry: IconFontEntry): Promise<IconFontEntryResult>;
|
|
59
|
+
declare function generateIndex(dest: string, entries: IconFontEntry[]): Promise<void>;
|
|
60
|
+
declare function generate(opts: IconFontOptions): Promise<void>;
|
|
61
|
+
declare class IconFontRunnerItem extends EV<{
|
|
62
|
+
build: IconFontEntryResult;
|
|
63
|
+
}> {
|
|
64
|
+
readonly entry: RawIconFontEntry;
|
|
65
|
+
readonly ctx: IconFontRunner;
|
|
66
|
+
private _resolveEntryPromise?;
|
|
67
|
+
private _watcher;
|
|
68
|
+
watchMode: boolean;
|
|
69
|
+
constructor(ctx: IconFontRunner, entry: RawIconFontEntry, watch?: boolean);
|
|
70
|
+
run(): Promise<{
|
|
71
|
+
entry: IconFontEntry;
|
|
72
|
+
}>;
|
|
73
|
+
resolveEntry(): Promise<IconFontEntry>;
|
|
74
|
+
build(): Promise<{
|
|
75
|
+
entry: IconFontEntry;
|
|
76
|
+
}>;
|
|
77
|
+
destroy(): void;
|
|
78
|
+
}
|
|
79
|
+
declare class IconFontRunner extends EV<{
|
|
80
|
+
build: {
|
|
81
|
+
item: IconFontRunnerItem;
|
|
82
|
+
result: IconFontEntryResult;
|
|
83
|
+
};
|
|
84
|
+
}> {
|
|
85
|
+
readonly items: IconFontRunnerItem[];
|
|
86
|
+
readonly dest: string;
|
|
87
|
+
constructor(opts: IconFontOptions, watch?: boolean);
|
|
88
|
+
buildIndex(): Promise<void>;
|
|
89
|
+
run(): Promise<void>;
|
|
90
|
+
destroy(): void;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { DEFAULT_CONFIG_FILENAME, DEFAULT_DEST_DIRNAME, DEFAULT_OPTIONS, ICON_FONT_FORMATS, ICON_FONT_FORMAT_MAP, IconFontConfig, IconFontEntry, IconFontEntryResult, IconFontFormat, IconFontOptions, IconFontRunner, IconFontRunnerItem, IconFontSettings, RawIconFontEntry, ceateIconFontConfig, generate, generateEntry, generateIndex, mergeDefaults, resolveRawIconFontEntry };
|
|
94
|
+
//# sourceMappingURL=icon-font-gen.d.mts.map
|
package/dist/icon-font-gen.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { a as generateEntry, d as ICON_FONT_FORMATS, f as ICON_FONT_FORMAT_MAP, i as generate, l as DEFAULT_CONFIG_FILENAME, m as resolveRawIconFontEntry, n as IconFontRunner, o as generateIndex, p as ceateIconFontConfig, r as IconFontRunnerItem, s as mergeDefaults, t as DEFAULT_OPTIONS, u as DEFAULT_DEST_DIRNAME } from "./generator-qQDqZGRh.mjs";
|
|
2
|
+
|
|
3
|
+
export { DEFAULT_CONFIG_FILENAME, DEFAULT_DEST_DIRNAME, DEFAULT_OPTIONS, ICON_FONT_FORMATS, ICON_FONT_FORMAT_MAP, IconFontRunner, IconFontRunnerItem, ceateIconFontConfig, generate, generateEntry, generateIndex, mergeDefaults, resolveRawIconFontEntry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/icon-font-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-next.0",
|
|
4
4
|
"description": "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fastkit",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
"./package.json": "./package.json",
|
|
22
22
|
".": {
|
|
23
|
-
"types": "./dist/icon-font-gen.d.
|
|
23
|
+
"types": "./dist/icon-font-gen.d.mts",
|
|
24
24
|
"import": {
|
|
25
25
|
"default": "./dist/icon-font-gen.mjs"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"./cli": {
|
|
29
|
-
"types": "./dist/cli.d.
|
|
29
|
+
"types": "./dist/cli.d.mts",
|
|
30
30
|
"import": {
|
|
31
31
|
"default": "./dist/cli.mjs"
|
|
32
32
|
}
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"./*": "./dist/*"
|
|
35
35
|
},
|
|
36
36
|
"main": "./dist/icon-font-gen.mjs",
|
|
37
|
-
"types": "./dist/icon-font-gen.d.
|
|
37
|
+
"types": "./dist/icon-font-gen.d.mts",
|
|
38
38
|
"typesVersions": {
|
|
39
39
|
"*": {
|
|
40
40
|
".": [
|
|
41
|
-
"./dist/icon-font-gen.d.
|
|
41
|
+
"./dist/icon-font-gen.d.mts"
|
|
42
42
|
],
|
|
43
43
|
"cli": [
|
|
44
|
-
"./dist/cli.d.
|
|
44
|
+
"./dist/cli.d.mts"
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"cac": "^6.7.14",
|
|
57
|
-
"chokidar": "^
|
|
58
|
-
"fs-extra": "^11.2
|
|
57
|
+
"chokidar": "^4.0.3",
|
|
58
|
+
"fs-extra": "^11.3.2",
|
|
59
59
|
"webfont": "^11.2.26",
|
|
60
|
-
"@fastkit/
|
|
61
|
-
"@fastkit/
|
|
62
|
-
"@fastkit/tiny-logger": "^0.
|
|
63
|
-
"@fastkit/
|
|
64
|
-
"@fastkit/
|
|
60
|
+
"@fastkit/ev": "^0.15.0-next.0",
|
|
61
|
+
"@fastkit/helpers": "^0.16.0-next.0",
|
|
62
|
+
"@fastkit/tiny-logger": "^0.16.0-next.0",
|
|
63
|
+
"@fastkit/node-util": "^0.16.0-next.0",
|
|
64
|
+
"@fastkit/icon-font": "^2.2.0-next.0"
|
|
65
65
|
},
|
|
66
66
|
"buildOptions": {
|
|
67
67
|
"name": "IconFont"
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "plugboy build",
|
|
79
79
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
80
|
-
"eslint": "eslint .
|
|
81
|
-
"eslint:fix": "eslint . --
|
|
80
|
+
"eslint": "eslint .",
|
|
81
|
+
"eslint:fix": "eslint . --fix",
|
|
82
82
|
"format": "pnpm run eslint:fix",
|
|
83
83
|
"lint": "pnpm run eslint",
|
|
84
84
|
"stub": "plugboy stub",
|
package/dist/chunk-4DBIOMOL.mjs
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import path2 from 'node:path';
|
|
2
|
-
import { installPackage, HashComparator } from '@fastkit/node-util';
|
|
3
|
-
import { TinyLogger, createTinyError } from '@fastkit/tiny-logger';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
import chokidar from 'chokidar';
|
|
6
|
-
import { EV } from '@fastkit/ev';
|
|
7
|
-
|
|
8
|
-
var ICON_FONT_FORMATS = [
|
|
9
|
-
"eot",
|
|
10
|
-
"woff",
|
|
11
|
-
"woff2",
|
|
12
|
-
"svg",
|
|
13
|
-
"ttf"
|
|
14
|
-
];
|
|
15
|
-
var ICON_FONT_FORMAT_MAP = {
|
|
16
|
-
eot: "embedded-opentype",
|
|
17
|
-
woff2: "woff2",
|
|
18
|
-
woff: "woff",
|
|
19
|
-
ttf: "truetype",
|
|
20
|
-
svg: "svg"
|
|
21
|
-
};
|
|
22
|
-
async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
23
|
-
const entry = {
|
|
24
|
-
...rawEntry
|
|
25
|
-
};
|
|
26
|
-
if (entry.src === "@mdi") {
|
|
27
|
-
const installedDir = await findOrInstallMDI();
|
|
28
|
-
entry.src = path2.join(installedDir, "svg");
|
|
29
|
-
if (entry.fontHeight == null) {
|
|
30
|
-
entry.fontHeight = 512;
|
|
31
|
-
}
|
|
32
|
-
if (entry.descent == null) {
|
|
33
|
-
entry.descent = 64;
|
|
34
|
-
}
|
|
35
|
-
if (entry.name == null) {
|
|
36
|
-
entry.name = "mdi";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const name2 = entry.name || path2.basename(entry.src);
|
|
40
|
-
const fontName = entry.fontName || `${name2}-icon`;
|
|
41
|
-
const dest = path2.join(rootDir, name2);
|
|
42
|
-
const prefix = entry.disablePrefix ? "" : `${name2}-`;
|
|
43
|
-
const display = entry.display || "block";
|
|
44
|
-
return {
|
|
45
|
-
...entry,
|
|
46
|
-
name: name2,
|
|
47
|
-
fontName,
|
|
48
|
-
prefix,
|
|
49
|
-
dest,
|
|
50
|
-
display
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function findOrInstallMDI() {
|
|
54
|
-
return installPackage("@mdi/svg", { dev: true });
|
|
55
|
-
}
|
|
56
|
-
var DEFAULT_CONFIG_FILENAME = "icon-font.config";
|
|
57
|
-
var DEFAULT_DEST_DIRNAME = ".icon-font";
|
|
58
|
-
function ceateIconFontConfig(options) {
|
|
59
|
-
return options;
|
|
60
|
-
}
|
|
61
|
-
var name = "icon-font-gen";
|
|
62
|
-
var logger = new TinyLogger(name);
|
|
63
|
-
var IconFontGenError = createTinyError(name);
|
|
64
|
-
var DEFAULT_OPTIONS = {
|
|
65
|
-
formats: ["woff2"],
|
|
66
|
-
fixedWidth: true,
|
|
67
|
-
normalize: true
|
|
68
|
-
};
|
|
69
|
-
var BANNER = `
|
|
70
|
-
/**
|
|
71
|
-
* This is auto generated file.
|
|
72
|
-
* Do not edit !!!
|
|
73
|
-
*
|
|
74
|
-
* @see: https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen
|
|
75
|
-
*/
|
|
76
|
-
`.trim();
|
|
77
|
-
function mergeDefaults(entry) {
|
|
78
|
-
return {
|
|
79
|
-
...DEFAULT_OPTIONS,
|
|
80
|
-
...entry
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
async function generateTS(entry, ids) {
|
|
84
|
-
const code = `
|
|
85
|
-
/* eslint-disable */
|
|
86
|
-
// @ts-nocheck
|
|
87
|
-
${BANNER}
|
|
88
|
-
import type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
89
|
-
import { registerIconNames } from '@fastkit/icon-font';
|
|
90
|
-
declare module "@fastkit/icon-font" {
|
|
91
|
-
export interface IconNameMap {
|
|
92
|
-
${ids.map((id) => ` '${id}': true,`).join("\n")}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export const ICON_NAMES = registerIconNames([
|
|
96
|
-
${ids.map((id) => `'${id}'`).join(",\n ")}
|
|
97
|
-
]);
|
|
98
|
-
export type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
99
|
-
`.trim();
|
|
100
|
-
const fileName = `${entry.name || "icons"}.ts`;
|
|
101
|
-
const dest = path2.resolve(entry.dest, fileName);
|
|
102
|
-
await fs.writeFile(dest, code);
|
|
103
|
-
return {
|
|
104
|
-
fileName,
|
|
105
|
-
dest,
|
|
106
|
-
code
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
async function generateEntry(entry) {
|
|
110
|
-
const options = mergeDefaults(entry);
|
|
111
|
-
const cssPrefix = `icon-${options.prefix}`;
|
|
112
|
-
const hash = new HashComparator(options.src, options.dest);
|
|
113
|
-
const srcHash = await hash.hasChanged();
|
|
114
|
-
if (!srcHash) {
|
|
115
|
-
logger.info(`Has not changed files. Skip process. >>> ${options.src}`);
|
|
116
|
-
return { entry };
|
|
117
|
-
}
|
|
118
|
-
await fs.ensureDir(options.dest);
|
|
119
|
-
const { webfont } = await import('webfont');
|
|
120
|
-
const { startUnicode = 47617 } = options;
|
|
121
|
-
let i = startUnicode;
|
|
122
|
-
const result = await webfont({
|
|
123
|
-
files: options.src,
|
|
124
|
-
fontName: options.fontName,
|
|
125
|
-
formats: options.formats,
|
|
126
|
-
fixedWidth: options.fixedWidth,
|
|
127
|
-
centerHorizontally: options.centerHorizontally,
|
|
128
|
-
normalize: options.normalize,
|
|
129
|
-
fontHeight: options.fontHeight,
|
|
130
|
-
round: options.round,
|
|
131
|
-
descent: options.descent,
|
|
132
|
-
addHashInFontUrl: options.addHashInFontUrl,
|
|
133
|
-
glyphTransformFn: (obj) => {
|
|
134
|
-
const char = String.fromCodePoint(i);
|
|
135
|
-
obj.unicode = [char];
|
|
136
|
-
i++;
|
|
137
|
-
return obj;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const buildedFormats = [];
|
|
141
|
-
ICON_FONT_FORMATS.forEach((format) => {
|
|
142
|
-
const code = result[format];
|
|
143
|
-
if (code) {
|
|
144
|
-
buildedFormats.push({ format, code });
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
await Promise.all(
|
|
148
|
-
buildedFormats.map(
|
|
149
|
-
({ format, code }) => fs.writeFile(path2.join(options.dest, `${options.name}.${format}`), code)
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
const glyphs = [];
|
|
153
|
-
result.glyphsData.forEach(({ metadata }) => {
|
|
154
|
-
if (!metadata) return;
|
|
155
|
-
const { name: name2, unicode } = metadata;
|
|
156
|
-
if (!unicode) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const code = unicode[0].charCodeAt(0).toString(16);
|
|
160
|
-
glyphs.push({ name: name2, code });
|
|
161
|
-
});
|
|
162
|
-
const urlPath = options.absolutePath ? options.dest : ".";
|
|
163
|
-
const hashSuffix = options.addHashInFontUrl ? `?${Date.now()}` : "";
|
|
164
|
-
const src = buildedFormats.map(
|
|
165
|
-
({ format }) => `url("${urlPath}/${options.name}.${format}${hashSuffix}") format("${ICON_FONT_FORMAT_MAP[format]}")`
|
|
166
|
-
).join(",");
|
|
167
|
-
const cssCode = `/* stylelint-disable */
|
|
168
|
-
@font-face {
|
|
169
|
-
font-family: "${options.fontName}";
|
|
170
|
-
font-display: ${options.display};
|
|
171
|
-
font-style: normal;
|
|
172
|
-
font-weight: 400;
|
|
173
|
-
src: ${src};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
i[class^="${cssPrefix}"]:before, i[class*=" ${cssPrefix}"]:before {
|
|
177
|
-
font-family: ${options.fontName} !important;
|
|
178
|
-
font-style: normal;
|
|
179
|
-
font-weight: normal !important;
|
|
180
|
-
font-variant: normal;
|
|
181
|
-
text-transform: none;
|
|
182
|
-
text-rendering: auto;
|
|
183
|
-
line-height: 1;
|
|
184
|
-
-webkit-font-smoothing: antialiased;
|
|
185
|
-
-moz-osx-font-smoothing: grayscale;
|
|
186
|
-
}
|
|
187
|
-
${glyphs.map(
|
|
188
|
-
({ name: name2, code }) => `
|
|
189
|
-
.${cssPrefix}${name2}:before { content: "\\${code}"; }
|
|
190
|
-
`
|
|
191
|
-
).join("\n")}
|
|
192
|
-
`;
|
|
193
|
-
await fs.writeFile(path2.join(options.dest, `${options.name}.css`), cssCode);
|
|
194
|
-
const ids = glyphs.map(({ name: name2 }) => `${options.prefix}${name2}`);
|
|
195
|
-
await generateTS(options, ids);
|
|
196
|
-
await hash.commit(srcHash);
|
|
197
|
-
return {
|
|
198
|
-
entry,
|
|
199
|
-
result
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
async function generateIndex(dest, entries) {
|
|
203
|
-
const names = entries.map(({ name: name2 }) => name2);
|
|
204
|
-
const tsCode = `
|
|
205
|
-
/* eslint-disable */
|
|
206
|
-
// @ts-nocheck
|
|
207
|
-
import './index.css';
|
|
208
|
-
${BANNER}
|
|
209
|
-
${names.map(
|
|
210
|
-
(name2, index) => (
|
|
211
|
-
// `import { IconName as IconName_${index}, IconNameMap as IconNameMap_${index} } from './${name}/${name}';`,
|
|
212
|
-
`import './${name2}/${name2}';`
|
|
213
|
-
)
|
|
214
|
-
).join("\n")}
|
|
215
|
-
export type { IconName } from '@fastkit/icon-font';
|
|
216
|
-
export { ICON_NAMES } from '@fastkit/icon-font';
|
|
217
|
-
`.trim();
|
|
218
|
-
const tsDest = path2.join(dest, "index.ts");
|
|
219
|
-
await fs.writeFile(tsDest, tsCode);
|
|
220
|
-
const cssCode = `
|
|
221
|
-
/* stylelint-disable */
|
|
222
|
-
${BANNER}
|
|
223
|
-
${names.map((name2) => `@import './${name2}/${name2}.css';`).join("\n")}
|
|
224
|
-
`.trim();
|
|
225
|
-
const cssDest = path2.join(dest, "index.css");
|
|
226
|
-
await fs.writeFile(cssDest, cssCode);
|
|
227
|
-
}
|
|
228
|
-
async function generate(opts) {
|
|
229
|
-
await fs.emptyDir(opts.dest);
|
|
230
|
-
const results = await Promise.all(
|
|
231
|
-
opts.entries.map(
|
|
232
|
-
(entry) => resolveRawIconFontEntry(opts.dest, entry).then(
|
|
233
|
-
(_entry) => generateEntry(_entry)
|
|
234
|
-
)
|
|
235
|
-
)
|
|
236
|
-
);
|
|
237
|
-
const entries = results.map(({ entry }) => entry);
|
|
238
|
-
await generateIndex(opts.dest, entries);
|
|
239
|
-
}
|
|
240
|
-
var IconFontRunnerItem = class extends EV {
|
|
241
|
-
entry;
|
|
242
|
-
ctx;
|
|
243
|
-
_resolveEntryPromise;
|
|
244
|
-
_watcher = null;
|
|
245
|
-
watchMode;
|
|
246
|
-
// get name() {
|
|
247
|
-
// return this.entry.name;
|
|
248
|
-
// }
|
|
249
|
-
constructor(ctx, entry, watch = false) {
|
|
250
|
-
super();
|
|
251
|
-
this.ctx = ctx;
|
|
252
|
-
this.entry = entry;
|
|
253
|
-
this.watchMode = watch;
|
|
254
|
-
this.build = this.build.bind(this);
|
|
255
|
-
}
|
|
256
|
-
async run() {
|
|
257
|
-
const result = await this.build();
|
|
258
|
-
if (this.watchMode && !this._watcher) {
|
|
259
|
-
const watchDir = path2.resolve(this.entry.src);
|
|
260
|
-
this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });
|
|
261
|
-
this._watcher.on("all", this.build);
|
|
262
|
-
}
|
|
263
|
-
return result;
|
|
264
|
-
}
|
|
265
|
-
resolveEntry() {
|
|
266
|
-
if (!this._resolveEntryPromise) {
|
|
267
|
-
this._resolveEntryPromise = resolveRawIconFontEntry(
|
|
268
|
-
this.ctx.dest,
|
|
269
|
-
this.entry
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
return this._resolveEntryPromise;
|
|
273
|
-
}
|
|
274
|
-
async build() {
|
|
275
|
-
const entry = await this.resolveEntry();
|
|
276
|
-
const result = await generateEntry(entry);
|
|
277
|
-
this.emit("build", result);
|
|
278
|
-
return { entry };
|
|
279
|
-
}
|
|
280
|
-
destroy() {
|
|
281
|
-
if (this._watcher) {
|
|
282
|
-
this._watcher.close();
|
|
283
|
-
this._watcher = null;
|
|
284
|
-
}
|
|
285
|
-
this.offAll();
|
|
286
|
-
if (this.ctx) {
|
|
287
|
-
delete this.ctx;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
var IconFontRunner = class extends EV {
|
|
292
|
-
items = [];
|
|
293
|
-
dest;
|
|
294
|
-
constructor(opts, watch) {
|
|
295
|
-
super();
|
|
296
|
-
this.dest = opts.dest;
|
|
297
|
-
opts.entries.forEach((entry) => {
|
|
298
|
-
const item = new IconFontRunnerItem(this, entry, watch);
|
|
299
|
-
item.on("build", (result) => {
|
|
300
|
-
this.emit("build", { item, result });
|
|
301
|
-
});
|
|
302
|
-
this.items.push(item);
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
async buildIndex() {
|
|
306
|
-
const entries = await Promise.all(
|
|
307
|
-
this.items.map((item) => item.resolveEntry())
|
|
308
|
-
);
|
|
309
|
-
return generateIndex(this.dest, entries);
|
|
310
|
-
}
|
|
311
|
-
async run() {
|
|
312
|
-
await fs.ensureDir(this.dest);
|
|
313
|
-
await Promise.all([
|
|
314
|
-
this.buildIndex(),
|
|
315
|
-
Promise.all(this.items.map((item) => item.run()))
|
|
316
|
-
]);
|
|
317
|
-
}
|
|
318
|
-
destroy() {
|
|
319
|
-
this.items.forEach((item) => item.destroy());
|
|
320
|
-
this.items.length = 0;
|
|
321
|
-
this.offAll();
|
|
322
|
-
delete this._opts;
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
export { DEFAULT_CONFIG_FILENAME, DEFAULT_DEST_DIRNAME, DEFAULT_OPTIONS, ICON_FONT_FORMATS, ICON_FONT_FORMAT_MAP, IconFontGenError, IconFontRunner, IconFontRunnerItem, ceateIconFontConfig, generate, generateEntry, generateIndex, mergeDefaults, resolveRawIconFontEntry };
|
|
327
|
-
//# sourceMappingURL=chunk-4DBIOMOL.mjs.map
|
|
328
|
-
//# sourceMappingURL=chunk-4DBIOMOL.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemes.ts","../src/logger.ts","../src/generator.ts"],"names":["path","name"],"mappings":";;;;;;;;AAMO,IAAM,iBAAsC,GAAA;AAAA,EACjD,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AACF,EAAA;AAEO,IAAM,oBAAuD,GAAA;AAAA,EAClE,GAAK,EAAA,mBAAA;AAAA,EACL,KAAO,EAAA,OAAA;AAAA,EACP,IAAM,EAAA,MAAA;AAAA,EACN,GAAK,EAAA,UAAA;AAAA,EACL,GAAK,EAAA,KAAA;AACP,EAAA;AA6CA,eAAsB,uBAAA,CACpB,SACA,QACwB,EAAA;AACxB,EAAA,MAAM,KAAQ,GAAA;AAAA,IACZ,GAAG,QAAA;AAA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AA,CAAA;AAAA,OACpC,CAAA,CAAA;AACD,MAAK,IAAA,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA,CAAA;AAAA,KACrB,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,UAAa,GAAA;AACjB,IAAM,MAAA,OAAA,GAAU,MAAM,OAAQ,CAAA,GAAA;AAAA,MAC5B,KAAK,KAAM,CAAA,GAAA,CAAI,CAAC,IAAS,KAAA,IAAA,CAAK,cAAc,CAAA;AAAA,KAC9C,CAAA;AACA,IAAO,OAAA,aAAA,CAAc,IAAK,CAAA,IAAA,EAAM,OAAO,CAAA,CAAA;AAAA,GACzC;AAAA,EAEA,MAAM,GAAM,GAAA;AACV,IAAM,MAAA,EAAA,CAAG,SAAU,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC5B,IAAA,MAAM,QAAQ,GAAI,CAAA;AAAA,MAChB,KAAK,UAAW,EAAA;AAAA,MAChB,OAAA,CAAQ,GAAI,CAAA,IAAA,CAAK,KAAM,CAAA,GAAA,CAAI,CAAC,IAAS,KAAA,IAAA,CAAK,GAAI,EAAC,CAAC,CAAA;AAAA,KACjD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,OAAU,GAAA;AACR,IAAA,IAAA,CAAK,MAAM,OAAQ,CAAA,CAAC,IAAS,KAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAC3C,IAAA,IAAA,CAAK,MAAM,MAAS,GAAA,CAAA,CAAA;AACpB,IAAA,IAAA,CAAK,MAAO,EAAA,CAAA;AACZ,IAAA,OAAQ,IAAa,CAAA,KAAA,CAAA;AAAA,GACvB;AACF","file":"chunk-4DBIOMOL.mjs","sourcesContent":["import type { OptionsBase } from 'webfont/dist/src/types/OptionsBase';\nimport path from 'node:path';\nimport { installPackage } from '@fastkit/node-util';\n\nexport type IconFontFormat = NonNullable<OptionsBase['formats']>[number];\n\nexport const ICON_FONT_FORMATS: IconFontFormat[] = [\n 'eot',\n 'woff',\n 'woff2',\n 'svg',\n 'ttf',\n];\n\nexport const ICON_FONT_FORMAT_MAP: Record<IconFontFormat, string> = {\n eot: 'embedded-opentype',\n woff2: 'woff2',\n woff: 'woff',\n ttf: 'truetype',\n svg: 'svg',\n};\n\nexport interface IconFontSettings {\n fixedWidth?: boolean;\n centerHorizontally?: boolean;\n normalize?: boolean;\n fontHeight?: number;\n round?: number;\n descent?: number;\n disablePrefix?: boolean;\n absolutePath?: boolean;\n addHashInFontUrl?: boolean;\n}\n\nexport interface IconFontEntry extends IconFontSettings {\n name: string;\n fontName: string;\n formats?: IconFontFormat[];\n startUnicode?: number;\n prefix: string;\n src: string;\n dest: string;\n display: 'block' | 'swap';\n}\n\nexport interface RawIconFontEntry\n extends Omit<\n IconFontEntry,\n 'name' | 'fontName' | 'prefix' | 'dest' | 'display'\n > {\n name?: string;\n fontName?: string;\n /**\n * @default block\n */\n display?: 'block' | 'swap';\n}\n\n// export type RawIconFontOptions = IconFontEntry | IconFontEntry[];\n\nexport interface IconFontOptions {\n entries: RawIconFontEntry[];\n dest: string;\n}\n\nexport async function resolveRawIconFontEntry(\n rootDir: string,\n rawEntry: RawIconFontEntry,\n): Promise<IconFontEntry> {\n const entry = {\n ...rawEntry,\n };\n\n // mdi support\n if (entry.src === '@mdi') {\n const installedDir = await findOrInstallMDI();\n entry.src = path.join(installedDir, 'svg');\n if (entry.fontHeight == null) {\n entry.fontHeight = 512;\n }\n if (entry.descent == null) {\n entry.descent = 64;\n }\n if (entry.name == null) {\n entry.name = 'mdi';\n }\n }\n\n const name = entry.name || path.basename(entry.src);\n const fontName = entry.fontName || `${name}-icon`;\n const dest = path.join(rootDir, name);\n const prefix = entry.disablePrefix ? '' : `${name}-`;\n const display = entry.display || 'block';\n return {\n ...entry,\n name,\n fontName,\n prefix,\n dest,\n display,\n };\n}\n\nfunction findOrInstallMDI() {\n return installPackage('@mdi/svg', { dev: true });\n}\n\nexport const DEFAULT_CONFIG_FILENAME = 'icon-font.config';\n\nexport const DEFAULT_DEST_DIRNAME = '.icon-font';\n\nexport interface IconFontConfig extends Omit<IconFontOptions, 'dest'> {\n dest?: string;\n}\n\nexport function ceateIconFontConfig(options: IconFontConfig) {\n return options;\n}\n","import { TinyLogger, createTinyError } from '@fastkit/tiny-logger';\n\nconst name = 'icon-font-gen';\n\nexport const logger = new TinyLogger(name);\n\nexport const IconFontGenError = createTinyError(name);\n","import fs from 'fs-extra';\nimport path from 'node:path';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport { EV } from '@fastkit/ev';\nimport { HashComparator } from '@fastkit/node-util';\nimport { UnPromisify } from '@fastkit/helpers';\nimport type webfont from 'webfont';\nimport { logger } from './logger';\nimport {\n IconFontOptions,\n IconFontEntry,\n RawIconFontEntry,\n resolveRawIconFontEntry,\n ICON_FONT_FORMATS,\n IconFontFormat,\n ICON_FONT_FORMAT_MAP,\n} from './schemes';\n\nexport type IconFontEntryResult = {\n entry: IconFontEntry;\n result?: UnPromisify<ReturnType<typeof webfont>>;\n};\n\nexport const DEFAULT_OPTIONS: Partial<IconFontEntry> = {\n formats: ['woff2'],\n fixedWidth: true,\n normalize: true,\n};\n\nconst BANNER = `\n/**\n * This is auto generated file.\n * Do not edit !!!\n *\n * @see: https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen\n */\n`.trim();\n\nexport function mergeDefaults(entry: IconFontEntry): IconFontEntry {\n return {\n ...DEFAULT_OPTIONS,\n ...entry,\n };\n}\n\nasync function generateTS(entry: IconFontEntry, ids: string[]) {\n const code = `\n/* eslint-disable */\n// @ts-nocheck\n${BANNER}\nimport type { IconName, IconNameMap } from '@fastkit/icon-font';\nimport { registerIconNames } from '@fastkit/icon-font';\ndeclare module \"@fastkit/icon-font\" {\n export interface IconNameMap {\n${ids.map((id) => ` '${id}': true,`).join('\\n')}\n }\n}\nexport const ICON_NAMES = registerIconNames([\n ${ids.map((id) => `'${id}'`).join(',\\n ')}\n]);\nexport type { IconName, IconNameMap } from '@fastkit/icon-font';\n `.trim();\n const fileName = `${entry.name || 'icons'}.ts`;\n const dest = path.resolve(entry.dest, fileName);\n await fs.writeFile(dest, code);\n return {\n fileName,\n dest,\n code,\n };\n}\n\nexport async function generateEntry(\n entry: IconFontEntry,\n): Promise<IconFontEntryResult> {\n const options = mergeDefaults(entry);\n\n // @TODO support empty prefix\n // const namePrefix = options.name;\n const cssPrefix = `icon-${options.prefix}`;\n\n const hash = new HashComparator(options.src, options.dest);\n const srcHash = await hash.hasChanged();\n if (!srcHash) {\n logger.info(`Has not changed files. Skip process. >>> ${options.src}`);\n return { entry };\n }\n\n await fs.ensureDir(options.dest);\n\n // eslint-disable-next-line no-shadow\n const { webfont } = await import('webfont');\n\n // const { startUnicode = 0xea01 } = options;\n const { startUnicode = 0xba01 } = options;\n\n let i = startUnicode;\n\n const result = await webfont({\n files: options.src,\n fontName: options.fontName,\n formats: options.formats,\n fixedWidth: options.fixedWidth,\n centerHorizontally: options.centerHorizontally,\n normalize: options.normalize,\n fontHeight: options.fontHeight,\n round: options.round,\n descent: options.descent,\n addHashInFontUrl: options.addHashInFontUrl,\n glyphTransformFn: (obj) => {\n const char = String.fromCodePoint(i);\n obj.unicode = [char];\n i++;\n return obj;\n },\n });\n\n const buildedFormats: { format: IconFontFormat; code: string | Buffer }[] =\n [];\n ICON_FONT_FORMATS.forEach((format) => {\n const code = result[format];\n if (code) {\n buildedFormats.push({ format, code });\n }\n });\n\n await Promise.all(\n buildedFormats.map(({ format, code }) =>\n fs.writeFile(path.join(options.dest, `${options.name}.${format}`), code),\n ),\n );\n\n const glyphs: { name: string; code: string }[] = [];\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n result.glyphsData!.forEach(({ metadata }) => {\n if (!metadata) return;\n const { name, unicode } = metadata;\n if (!unicode) {\n return;\n }\n\n const code = unicode[0].charCodeAt(0).toString(16);\n glyphs.push({ name, code });\n });\n\n const urlPath = options.absolutePath ? options.dest : '.';\n const hashSuffix = options.addHashInFontUrl ? `?${Date.now()}` : '';\n const src = buildedFormats\n .map(\n ({ format }) =>\n `url(\"${urlPath}/${options.name}.${format}${hashSuffix}\") format(\"${ICON_FONT_FORMAT_MAP[format]}\")`,\n )\n .join(',');\n\n const cssCode = `/* stylelint-disable */\n@font-face {\n font-family: \"${options.fontName}\";\n font-display: ${options.display};\n font-style: normal;\n font-weight: 400;\n src: ${src};\n}\n\ni[class^=\"${cssPrefix}\"]:before, i[class*=\" ${cssPrefix}\"]:before {\n font-family: ${options.fontName} !important;\n font-style: normal;\n font-weight: normal !important;\n font-variant: normal;\n text-transform: none;\n text-rendering: auto;\n line-height: 1;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n${glyphs\n .map(\n ({ name, code }) => `\n.${cssPrefix}${name}:before { content: \"\\\\${code}\"; }\n `,\n )\n .join('\\n')}\n `;\n await fs.writeFile(path.join(options.dest, `${options.name}.css`), cssCode);\n\n // const prefix = options.prefix ? `${options.prefix}-` : '';\n const ids = glyphs.map(({ name }) => `${options.prefix}${name}`);\n await generateTS(options, ids);\n await hash.commit(srcHash);\n return {\n entry,\n result,\n };\n}\n\nexport async function generateIndex(dest: string, entries: IconFontEntry[]) {\n const names = entries.map(({ name }) => name);\n const tsCode = `\n/* eslint-disable */\n// @ts-nocheck\nimport './index.css';\n${BANNER}\n${names\n .map(\n (name, index) =>\n // `import { IconName as IconName_${index}, IconNameMap as IconNameMap_${index} } from './${name}/${name}';`,\n `import './${name}/${name}';`,\n )\n .join('\\n')}\nexport type { IconName } from '@fastkit/icon-font';\nexport { ICON_NAMES } from '@fastkit/icon-font';\n `.trim();\n const tsDest = path.join(dest, 'index.ts');\n await fs.writeFile(tsDest, tsCode);\n\n const cssCode = `\n/* stylelint-disable */\n${BANNER}\n${names.map((name) => `@import './${name}/${name}.css';`).join('\\n')}\n `.trim();\n const cssDest = path.join(dest, 'index.css');\n await fs.writeFile(cssDest, cssCode);\n}\n\nexport async function generate(opts: IconFontOptions) {\n await fs.emptyDir(opts.dest);\n const results = await Promise.all(\n opts.entries.map((entry) =>\n resolveRawIconFontEntry(opts.dest, entry).then((_entry) =>\n generateEntry(_entry),\n ),\n ),\n );\n const entries = results.map(({ entry }) => entry);\n await generateIndex(opts.dest, entries);\n}\n\nexport class IconFontRunnerItem extends EV<{\n build: IconFontEntryResult;\n}> {\n readonly entry: RawIconFontEntry;\n\n readonly ctx: IconFontRunner;\n\n private _resolveEntryPromise?: Promise<IconFontEntry>;\n\n private _watcher: FSWatcher | null = null;\n\n watchMode: boolean;\n\n // get name() {\n // return this.entry.name;\n // }\n\n constructor(ctx: IconFontRunner, entry: RawIconFontEntry, watch = false) {\n super();\n this.ctx = ctx;\n this.entry = entry;\n this.watchMode = watch;\n this.build = this.build.bind(this);\n }\n\n async run() {\n const result = await this.build();\n if (this.watchMode && !this._watcher) {\n const watchDir = path.resolve(this.entry.src);\n this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });\n this._watcher.on('all', this.build);\n }\n return result;\n }\n\n resolveEntry() {\n if (!this._resolveEntryPromise) {\n this._resolveEntryPromise = resolveRawIconFontEntry(\n this.ctx.dest,\n this.entry,\n );\n }\n return this._resolveEntryPromise;\n }\n\n async build() {\n const entry = await this.resolveEntry();\n const result = await generateEntry(entry);\n this.emit('build', result);\n return { entry };\n }\n\n destroy() {\n if (this._watcher) {\n this._watcher.close();\n this._watcher = null;\n }\n this.offAll();\n if (this.ctx) {\n delete (this as any).ctx;\n }\n }\n}\n\nexport class IconFontRunner extends EV<{\n build: {\n item: IconFontRunnerItem;\n result: IconFontEntryResult;\n };\n}> {\n readonly items: IconFontRunnerItem[] = [];\n\n readonly dest: string;\n\n constructor(opts: IconFontOptions, watch?: boolean) {\n super();\n\n this.dest = opts.dest;\n\n opts.entries.forEach((entry) => {\n const item = new IconFontRunnerItem(this, entry, watch);\n item.on('build', (result) => {\n this.emit('build', { item, result });\n });\n this.items.push(item);\n });\n }\n\n async buildIndex() {\n const entries = await Promise.all(\n this.items.map((item) => item.resolveEntry()),\n );\n return generateIndex(this.dest, entries);\n }\n\n async run() {\n await fs.ensureDir(this.dest);\n await Promise.all([\n this.buildIndex(),\n Promise.all(this.items.map((item) => item.run())),\n ]);\n }\n\n destroy() {\n this.items.forEach((item) => item.destroy());\n this.items.length = 0;\n this.offAll();\n delete (this as any)._opts;\n }\n}\n"]}
|
package/dist/cli.d.ts
DELETED
package/dist/icon-font-gen.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { OptionsBase } from 'webfont/dist/src/types/OptionsBase';
|
|
2
|
-
import { EV } from '@fastkit/ev';
|
|
3
|
-
import { UnPromisify } from '@fastkit/helpers';
|
|
4
|
-
import webfont from 'webfont';
|
|
5
|
-
|
|
6
|
-
type IconFontFormat = NonNullable<OptionsBase['formats']>[number];
|
|
7
|
-
declare const ICON_FONT_FORMATS: IconFontFormat[];
|
|
8
|
-
declare const ICON_FONT_FORMAT_MAP: Record<IconFontFormat, string>;
|
|
9
|
-
interface IconFontSettings {
|
|
10
|
-
fixedWidth?: boolean;
|
|
11
|
-
centerHorizontally?: boolean;
|
|
12
|
-
normalize?: boolean;
|
|
13
|
-
fontHeight?: number;
|
|
14
|
-
round?: number;
|
|
15
|
-
descent?: number;
|
|
16
|
-
disablePrefix?: boolean;
|
|
17
|
-
absolutePath?: boolean;
|
|
18
|
-
addHashInFontUrl?: boolean;
|
|
19
|
-
}
|
|
20
|
-
interface IconFontEntry extends IconFontSettings {
|
|
21
|
-
name: string;
|
|
22
|
-
fontName: string;
|
|
23
|
-
formats?: IconFontFormat[];
|
|
24
|
-
startUnicode?: number;
|
|
25
|
-
prefix: string;
|
|
26
|
-
src: string;
|
|
27
|
-
dest: string;
|
|
28
|
-
display: 'block' | 'swap';
|
|
29
|
-
}
|
|
30
|
-
interface RawIconFontEntry extends Omit<IconFontEntry, 'name' | 'fontName' | 'prefix' | 'dest' | 'display'> {
|
|
31
|
-
name?: string;
|
|
32
|
-
fontName?: string;
|
|
33
|
-
/**
|
|
34
|
-
* @default block
|
|
35
|
-
*/
|
|
36
|
-
display?: 'block' | 'swap';
|
|
37
|
-
}
|
|
38
|
-
interface IconFontOptions {
|
|
39
|
-
entries: RawIconFontEntry[];
|
|
40
|
-
dest: string;
|
|
41
|
-
}
|
|
42
|
-
declare function resolveRawIconFontEntry(rootDir: string, rawEntry: RawIconFontEntry): Promise<IconFontEntry>;
|
|
43
|
-
declare const DEFAULT_CONFIG_FILENAME = "icon-font.config";
|
|
44
|
-
declare const DEFAULT_DEST_DIRNAME = ".icon-font";
|
|
45
|
-
interface IconFontConfig extends Omit<IconFontOptions, 'dest'> {
|
|
46
|
-
dest?: string;
|
|
47
|
-
}
|
|
48
|
-
declare function ceateIconFontConfig(options: IconFontConfig): IconFontConfig;
|
|
49
|
-
|
|
50
|
-
type IconFontEntryResult = {
|
|
51
|
-
entry: IconFontEntry;
|
|
52
|
-
result?: UnPromisify<ReturnType<typeof webfont>>;
|
|
53
|
-
};
|
|
54
|
-
declare const DEFAULT_OPTIONS: Partial<IconFontEntry>;
|
|
55
|
-
declare function mergeDefaults(entry: IconFontEntry): IconFontEntry;
|
|
56
|
-
declare function generateEntry(entry: IconFontEntry): Promise<IconFontEntryResult>;
|
|
57
|
-
declare function generateIndex(dest: string, entries: IconFontEntry[]): Promise<void>;
|
|
58
|
-
declare function generate(opts: IconFontOptions): Promise<void>;
|
|
59
|
-
declare class IconFontRunnerItem extends EV<{
|
|
60
|
-
build: IconFontEntryResult;
|
|
61
|
-
}> {
|
|
62
|
-
readonly entry: RawIconFontEntry;
|
|
63
|
-
readonly ctx: IconFontRunner;
|
|
64
|
-
private _resolveEntryPromise?;
|
|
65
|
-
private _watcher;
|
|
66
|
-
watchMode: boolean;
|
|
67
|
-
constructor(ctx: IconFontRunner, entry: RawIconFontEntry, watch?: boolean);
|
|
68
|
-
run(): Promise<{
|
|
69
|
-
entry: IconFontEntry;
|
|
70
|
-
}>;
|
|
71
|
-
resolveEntry(): Promise<IconFontEntry>;
|
|
72
|
-
build(): Promise<{
|
|
73
|
-
entry: IconFontEntry;
|
|
74
|
-
}>;
|
|
75
|
-
destroy(): void;
|
|
76
|
-
}
|
|
77
|
-
declare class IconFontRunner extends EV<{
|
|
78
|
-
build: {
|
|
79
|
-
item: IconFontRunnerItem;
|
|
80
|
-
result: IconFontEntryResult;
|
|
81
|
-
};
|
|
82
|
-
}> {
|
|
83
|
-
readonly items: IconFontRunnerItem[];
|
|
84
|
-
readonly dest: string;
|
|
85
|
-
constructor(opts: IconFontOptions, watch?: boolean);
|
|
86
|
-
buildIndex(): Promise<void>;
|
|
87
|
-
run(): Promise<void>;
|
|
88
|
-
destroy(): void;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { DEFAULT_CONFIG_FILENAME, DEFAULT_DEST_DIRNAME, DEFAULT_OPTIONS, ICON_FONT_FORMATS, ICON_FONT_FORMAT_MAP, type IconFontConfig, type IconFontEntry, type IconFontEntryResult, type IconFontFormat, type IconFontOptions, IconFontRunner, IconFontRunnerItem, type IconFontSettings, type RawIconFontEntry, ceateIconFontConfig, generate, generateEntry, generateIndex, mergeDefaults, resolveRawIconFontEntry };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"icon-font-gen.mjs"}
|