@hibi_10000/grunt-webfont 2.0.1 → 2.1.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/Gruntfile.ts +370 -0
- package/{License.md → LICENSE.md} +1 -0
- package/bin/fontforge/generate.py +1 -1
- package/dist/engines/fontforge.js +10 -5
- package/dist/engines/fontforge.js.map +1 -1
- package/dist/engines/node.js +16 -13
- package/dist/engines/node.js.map +1 -1
- package/dist/package.js +3 -102
- package/dist/package.js.map +1 -1
- package/dist/types.d.ts +13 -13
- package/dist/util/util.js +15 -4
- package/dist/util/util.js.map +1 -1
- package/dist/webfont.d.ts +5 -5
- package/dist/webfont.js +76 -60
- package/dist/webfont.js.map +1 -1
- package/package.json +34 -22
- package/pnpm-workspace.yaml +4 -0
- package/tasks/engines/fontforge.ts +5 -5
- package/tasks/engines/node.ts +3 -4
- package/tasks/types.ts +14 -12
- package/tasks/util/util.ts +18 -12
- package/tasks/webfont.ts +63 -47
- package/templates/demo.html +1 -1
- package/tsconfig.json +3 -10
package/dist/package.js
CHANGED
|
@@ -1,105 +1,6 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var
|
|
3
|
-
var description = "Ultimate SVG to webfont converter for Grunt.";
|
|
4
|
-
var version = "2.0.1";
|
|
5
|
-
var homepage = "https://github.com/Hibi-10000/grunt-webfont";
|
|
6
|
-
var author = "Hibi_10000";
|
|
7
|
-
var contributors = [
|
|
8
|
-
"Artem Sapegin (http://sapegin.me/)",
|
|
9
|
-
"Maxime Thirouin (http://moox.io/)",
|
|
10
|
-
"Aaron Lampros (https://github.com/alampros)",
|
|
11
|
-
"Cyrille Meichel (https://github.com/landru29)"
|
|
12
|
-
];
|
|
13
|
-
var repository = {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/Hibi-10000/grunt-webfont.git"
|
|
16
|
-
};
|
|
17
|
-
var bugs = { "url": "https://github.com/Hibi-10000/grunt-webfont/issues" };
|
|
18
|
-
var keywords = [
|
|
19
|
-
"gruntplugin",
|
|
20
|
-
"font",
|
|
21
|
-
"webfont",
|
|
22
|
-
"fontforge",
|
|
23
|
-
"font-face",
|
|
24
|
-
"woff",
|
|
25
|
-
"woff2",
|
|
26
|
-
"ttf",
|
|
27
|
-
"svg",
|
|
28
|
-
"eot",
|
|
29
|
-
"truetype",
|
|
30
|
-
"css",
|
|
31
|
-
"icon"
|
|
32
|
-
];
|
|
33
|
-
var license = "MIT";
|
|
34
|
-
var main = "dist/webfont.js";
|
|
35
|
-
var type = "module";
|
|
36
|
-
var scripts = {
|
|
37
|
-
"build": "tsdown",
|
|
38
|
-
"test:node": "node --test ./test/webfont.test.ts",
|
|
39
|
-
"test:grunt": "pnpm build & grunt --stack"
|
|
40
|
-
};
|
|
41
|
-
var engines = {
|
|
42
|
-
"node": ">=22",
|
|
43
|
-
"pnpm": ">=10"
|
|
44
|
-
};
|
|
45
|
-
var dependencies = {
|
|
46
|
-
"chalk": "^5.6.2",
|
|
47
|
-
"consola": "^3.4.2",
|
|
48
|
-
"glob": "^11.0.3",
|
|
49
|
-
"lodash": "^4.17.21",
|
|
50
|
-
"temp": "^0.9.4",
|
|
51
|
-
"ttf2woff2": "^8.0.0"
|
|
52
|
-
};
|
|
53
|
-
var optionalDependencies = {
|
|
54
|
-
"svg2ttf": "^6.0.3",
|
|
55
|
-
"svgicons2svgfont": "~15.0.1",
|
|
56
|
-
"svgo": "^4.0.0",
|
|
57
|
-
"ttf2eot": "^3.1.0",
|
|
58
|
-
"ttf2woff": "^3.0.0",
|
|
59
|
-
"which": "^5.0.0"
|
|
60
|
-
};
|
|
61
|
-
var devDependencies = {
|
|
62
|
-
"@types/grunt": "^0.4.32",
|
|
63
|
-
"@types/lodash": "^4.17.20",
|
|
64
|
-
"@types/node": "^22.18.1",
|
|
65
|
-
"@types/nodeunit": "^0.0.36",
|
|
66
|
-
"@types/stylus": "^0.48.43",
|
|
67
|
-
"@types/svg2ttf": "^5.0.3",
|
|
68
|
-
"@types/temp": "^0.9.4",
|
|
69
|
-
"@types/which": "^3.0.4",
|
|
70
|
-
"@types/xml2js": "^0.4.14",
|
|
71
|
-
"grunt": "^1.6.1",
|
|
72
|
-
"grunt-cli": "^1.5.0",
|
|
73
|
-
"grunt-contrib-clean": "^2.0.1",
|
|
74
|
-
"grunt-contrib-nodeunit": "^5.0.0",
|
|
75
|
-
"load-grunt-tasks": "^5.1.0",
|
|
76
|
-
"stylus": "^0.64.0",
|
|
77
|
-
"tsdown": "^0.15.0",
|
|
78
|
-
"typescript": "^5.9.2",
|
|
79
|
-
"xml2js": "^0.6.2"
|
|
80
|
-
};
|
|
81
|
-
var peerDependencies = { "grunt": ">=0.4.0" };
|
|
82
|
-
var package_default = {
|
|
83
|
-
name,
|
|
84
|
-
description,
|
|
85
|
-
version,
|
|
86
|
-
homepage,
|
|
87
|
-
author,
|
|
88
|
-
contributors,
|
|
89
|
-
repository,
|
|
90
|
-
bugs,
|
|
91
|
-
keywords,
|
|
92
|
-
license,
|
|
93
|
-
main,
|
|
94
|
-
type,
|
|
95
|
-
scripts,
|
|
96
|
-
engines,
|
|
97
|
-
dependencies,
|
|
98
|
-
optionalDependencies,
|
|
99
|
-
devDependencies,
|
|
100
|
-
peerDependencies
|
|
101
|
-
};
|
|
102
|
-
|
|
2
|
+
var version = "2.1.0";
|
|
103
3
|
//#endregion
|
|
104
|
-
export {
|
|
4
|
+
export { version };
|
|
5
|
+
|
|
105
6
|
//# sourceMappingURL=package.js.map
|
package/dist/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
//#region tasks/types.d.ts
|
|
2
2
|
interface Logger {
|
|
3
|
-
log: {
|
|
4
|
-
error: (
|
|
5
|
-
warn: (
|
|
6
|
-
info: (
|
|
7
|
-
verbose: (
|
|
3
|
+
readonly log: {
|
|
4
|
+
readonly error: (args: string) => void;
|
|
5
|
+
readonly warn: (msg: string) => void;
|
|
6
|
+
readonly info: (msg: string) => void;
|
|
7
|
+
readonly verbose: (msg: string) => void;
|
|
8
8
|
};
|
|
9
|
-
fail: {
|
|
10
|
-
fatal: (
|
|
11
|
-
warn?: (...args: any[]) => void;
|
|
9
|
+
readonly fail: {
|
|
10
|
+
readonly fatal: (args: string) => void;
|
|
12
11
|
};
|
|
13
12
|
}
|
|
13
|
+
type FontFormat = "eot" | "woff2" | "woff" | "ttf" | "svg";
|
|
14
14
|
interface CustomOutput {
|
|
15
15
|
template: string;
|
|
16
16
|
dest: string;
|
|
@@ -100,9 +100,9 @@ interface OptionsInternal extends TemplateOptions {
|
|
|
100
100
|
htmlDemoTemplate: string;
|
|
101
101
|
htmlDemoFilename: string;
|
|
102
102
|
styles: string[] | string;
|
|
103
|
-
types:
|
|
104
|
-
order:
|
|
105
|
-
embed:
|
|
103
|
+
types: FontFormat[];
|
|
104
|
+
order: FontFormat[];
|
|
105
|
+
embed: FontFormat[];
|
|
106
106
|
rename: (path: string, suffix?: string) => string;
|
|
107
107
|
engine: "fontforge" | "node";
|
|
108
108
|
autoHint: boolean;
|
|
@@ -119,7 +119,7 @@ interface OptionsInternal extends TemplateOptions {
|
|
|
119
119
|
descent: number;
|
|
120
120
|
version: string | boolean;
|
|
121
121
|
cache: string;
|
|
122
|
-
callback: (filename: string, types:
|
|
122
|
+
callback: (filename: string, types: FontFormat[], glyphs: string[], hash: string) => void;
|
|
123
123
|
customOutputs: CustomOutput[];
|
|
124
124
|
execMaxBuffer: number;
|
|
125
125
|
fontName?: string;
|
|
@@ -154,5 +154,5 @@ interface Context extends OptionsInternal {
|
|
|
154
154
|
iconsStyles?: true;
|
|
155
155
|
}
|
|
156
156
|
//#endregion
|
|
157
|
-
export { Config, Logger, Options };
|
|
157
|
+
export { Config, Context, CustomOutput, FontFormat, Logger, Options, OptionsInternal, TemplateOptions };
|
|
158
158
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/util/util.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { globSync } from "glob";
|
|
3
3
|
import { consola } from "consola";
|
|
4
|
-
|
|
5
4
|
//#region tasks/util/util.ts
|
|
5
|
+
/**
|
|
6
|
+
* grunt-webfont: common stuff
|
|
7
|
+
*
|
|
8
|
+
* @author Artem Sapegin (http://sapegin.me), Hibi_10000
|
|
9
|
+
*/
|
|
10
|
+
consola.options.throttle = 300;
|
|
6
11
|
const consolaLogger = {
|
|
7
12
|
log: {
|
|
8
13
|
error: consola.error.raw,
|
|
9
14
|
warn: consola.warn.raw,
|
|
10
15
|
info: consola.info.raw,
|
|
11
|
-
verbose: consola.
|
|
16
|
+
verbose: consola.debug.raw
|
|
12
17
|
},
|
|
13
18
|
fail: { fatal: (...args) => {
|
|
14
19
|
consola.fatal.raw(...args);
|
|
@@ -81,7 +86,13 @@ const fontSrcSeparators = {
|
|
|
81
86
|
/**
|
|
82
87
|
* List of available font formats.
|
|
83
88
|
*/
|
|
84
|
-
const fontFormats =
|
|
89
|
+
const fontFormats = [
|
|
90
|
+
"eot",
|
|
91
|
+
"woff2",
|
|
92
|
+
"woff",
|
|
93
|
+
"ttf",
|
|
94
|
+
"svg"
|
|
95
|
+
];
|
|
85
96
|
/**
|
|
86
97
|
* Returns list of all generated font files.
|
|
87
98
|
*
|
|
@@ -99,7 +110,7 @@ const generatedFontFiles = (o) => {
|
|
|
99
110
|
const getFontPath = (o, type) => {
|
|
100
111
|
return path.join(o.dest, `${o.fontFilename}.${type}`);
|
|
101
112
|
};
|
|
102
|
-
|
|
103
113
|
//#endregion
|
|
104
114
|
export { UNICODE_PUA_START, consolaLogger, cssFilePrefixes, fontFormats, fontSrcSeparators, fontsSrcsMap, generatedFontFiles, getFontPath };
|
|
115
|
+
|
|
105
116
|
//# sourceMappingURL=util.js.map
|
package/dist/util/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","names":[
|
|
1
|
+
{"version":3,"file":"util.js","names":[],"sources":["../../tasks/util/util.ts"],"sourcesContent":["/**\n * grunt-webfont: common stuff\n *\n * @author Artem Sapegin (http://sapegin.me), Hibi_10000\n */\n\nimport path from 'node:path';\nimport { globSync } from 'glob';\nimport { consola } from 'consola';\n\nimport type { FontFormat, Logger, OptionsInternal } from '../types.ts';\n\nconsola.options.throttle = 300;\n\nexport const consolaLogger: Logger = {\n\tlog: {\n\t\terror: consola.error.raw,\n\t\twarn: consola.warn.raw,\n\t\tinfo: consola.info.raw,\n\t\tverbose: consola.debug.raw,\n\t},\n\tfail: {\n\t\tfatal: (...args) => {\n\t\t\tconsola.fatal.raw(...args);\n\t\t\tprocess.exit(1);\n\t\t},\n\t},\n} as const;\n\nexport const showConsolaVerbose = () => {\n\tconsola.level = 4; // debug\n};\n\n/**\n * Unicode Private Use Area start.\n * http://en.wikipedia.org/wiki/Private_Use_(Unicode)\n */\nexport const UNICODE_PUA_START = 0xF101;\n\n/**\n * @font-face’s src values generation rules.\n */\nexport const fontsSrcsMap = {\n\teot: {\n\t\t0: {\n\t\t\text: '.eot',\n\t\t},\n\t\t1: {\n\t\t\text: '.eot?#iefix',\n\t\t\tformat: 'embedded-opentype',\n\t\t},\n\t},\n\twoff: {\n\t\t0: false,\n\t\t1: {\n\t\t\text: '.woff',\n\t\t\tformat: 'woff',\n\t\t\tembeddable: true,\n\t\t},\n\t},\n\twoff2: {\n\t\t0: false,\n\t\t1: {\n\t\t\text: '.woff2',\n\t\t\tformat: 'woff2',\n\t\t\tembeddable: true,\n\t\t},\n\t},\n\tttf: {\n\t\t0: false,\n\t\t1: {\n\t\t\text: '.ttf',\n\t\t\tformat: 'truetype',\n\t\t\tembeddable: true,\n\t\t},\n\t},\n\tsvg: {\n\t\t0: false,\n\t\t1: {\n\t\t\text: '.svg#{fontBaseName}',\n\t\t\tformat: 'svg',\n\t\t},\n\t},\n} as const;\n\n/**\n * CSS fileaname prefixes: _icons.scss.\n */\nexport const cssFilePrefixes = {\n\t_default: '',\n\tsass: '_',\n\tscss: '_'\n} as const;\n\n/**\n * @font-face’s src parts seperators.\n */\nexport const fontSrcSeparators = {\n\t_default: ',\\n\\t\\t',\n\tstyl: ', '\n} as const;\n\n/**\n * List of available font formats.\n */\nexport const fontFormats: FontFormat[] = ['eot', 'woff2', 'woff', 'ttf', 'svg'];\n\n/**\n * Returns list of all generated font files.\n *\n * @param o Options.\n */\nexport const generatedFontFiles = (o: OptionsInternal): string[] => {\n\treturn globSync(path.posix.join(o.dest, `${o.fontFilename}*.{${o.types}}`));\n};\n\n/**\n * Returns path to font of specified format.\n *\n * @param o Options.\n * @param type Font type (see `wf.fontFormats`).\n */\nexport const getFontPath = (o: OptionsInternal, type: string): string => {\n\treturn path.join(o.dest, `${o.fontFilename}.${type}`);\n};\n"],"mappings":";;;;;;;;;AAYA,QAAQ,QAAQ,WAAW;AAE3B,MAAa,gBAAwB;CACpC,KAAK;EACJ,OAAO,QAAQ,MAAM;EACrB,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,SAAS,QAAQ,MAAM;CACxB;CACA,MAAM,EACL,QAAQ,GAAG,SAAS;EACnB,QAAQ,MAAM,IAAI,GAAG,IAAI;EACzB,QAAQ,KAAK,CAAC;CACf,EACD;AACD;;;;;AAUA,MAAa,oBAAoB;;;;AAKjC,MAAa,eAAe;CAC3B,KAAK;EACJ,GAAG,EACF,KAAK,OACN;EACA,GAAG;GACF,KAAK;GACL,QAAQ;EACT;CACD;CACA,MAAM;EACL,GAAG;EACH,GAAG;GACF,KAAK;GACL,QAAQ;GACR,YAAY;EACb;CACD;CACA,OAAO;EACN,GAAG;EACH,GAAG;GACF,KAAK;GACL,QAAQ;GACR,YAAY;EACb;CACD;CACA,KAAK;EACJ,GAAG;EACH,GAAG;GACF,KAAK;GACL,QAAQ;GACR,YAAY;EACb;CACD;CACA,KAAK;EACJ,GAAG;EACH,GAAG;GACF,KAAK;GACL,QAAQ;EACT;CACD;AACD;;;;AAKA,MAAa,kBAAkB;CAC9B,UAAU;CACV,MAAM;CACN,MAAM;AACP;;;;AAKA,MAAa,oBAAoB;CAChC,UAAU;CACV,MAAM;AACP;;;;AAKA,MAAa,cAA4B;CAAC;CAAO;CAAS;CAAQ;CAAO;AAAK;;;;;;AAO9E,MAAa,sBAAsB,MAAiC;CACnE,OAAO,SAAS,KAAK,MAAM,KAAK,EAAE,MAAM,GAAG,EAAE,aAAa,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3E;;;;;;;AAQA,MAAa,eAAe,GAAoB,SAAyB;CACxE,OAAO,KAAK,KAAK,EAAE,MAAM,GAAG,EAAE,aAAa,GAAG,MAAM;AACrD"}
|
package/dist/webfont.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Config
|
|
2
|
-
|
|
1
|
+
import { Config } from "./types.js";
|
|
3
2
|
//#region tasks/webfont.d.ts
|
|
4
|
-
declare const
|
|
5
|
-
declare const webfont: (
|
|
3
|
+
declare const webfontGrunt: (grunt: IGrunt) => void;
|
|
4
|
+
declare const webfont: (targetName: string, config: Config) => Promise<void>;
|
|
5
|
+
declare const webfontGruntCjs: (grunt: IGrunt) => void;
|
|
6
6
|
//#endregion
|
|
7
|
-
export {
|
|
7
|
+
export { webfontGrunt as default, webfontGrunt, webfontGruntCjs as "module.exports", webfont };
|
|
8
8
|
//# sourceMappingURL=webfont.d.ts.map
|
package/dist/webfont.js
CHANGED
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { consolaLogger, cssFilePrefixes, fontFormats, fontSrcSeparators, fontsSrcsMap, generatedFontFiles, getFontPath } from "./util/util.js";
|
|
2
2
|
import fontforge_default from "./engines/fontforge.js";
|
|
3
3
|
import node_default from "./engines/node.js";
|
|
4
|
-
import
|
|
4
|
+
import { version } from "./package.js";
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import crypto from "node:crypto";
|
|
8
8
|
import { globSync } from "glob";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
-
import
|
|
10
|
+
import { Eta } from "eta";
|
|
11
11
|
import ttf2woff2 from "ttf2woff2";
|
|
12
|
-
|
|
13
12
|
//#region tasks/webfont.ts
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* SVG to webfont converter for Grunt
|
|
15
|
+
*
|
|
16
|
+
* @requires ttfautohint
|
|
17
|
+
* @author Artem Sapegin (http://sapegin.me), Hibi_10000
|
|
18
|
+
*/
|
|
19
|
+
const webfontGrunt = (grunt) => {
|
|
15
20
|
grunt.registerMultiTask("webfont", "Compile separate SVG files to webfont", function() {
|
|
16
21
|
/**
|
|
17
22
|
* Consola to Grunt logger adapter.
|
|
18
23
|
*/
|
|
19
24
|
const logger = {
|
|
20
25
|
log: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
grunt.warn.apply(null, args);
|
|
26
|
-
},
|
|
27
|
-
info: (...args) => {
|
|
28
|
-
grunt.log.writeln.apply(null, args);
|
|
29
|
-
},
|
|
30
|
-
verbose: (...args) => {
|
|
31
|
-
grunt.log.verbose.writeln.apply(null, args);
|
|
32
|
-
}
|
|
26
|
+
error: grunt.warn,
|
|
27
|
+
warn: grunt.log.warn,
|
|
28
|
+
info: grunt.log.writeln,
|
|
29
|
+
verbose: grunt.log.verbose.writeln
|
|
33
30
|
},
|
|
34
|
-
fail: { fatal:
|
|
35
|
-
grunt.fail.fatal.apply(null, args);
|
|
36
|
-
} }
|
|
31
|
+
fail: { fatal: grunt.fail.fatal }
|
|
37
32
|
};
|
|
38
33
|
const allDone = this.async();
|
|
39
34
|
const params = this.data;
|
|
@@ -43,11 +38,19 @@ var webfont_default = (grunt) => {
|
|
|
43
38
|
this.target,
|
|
44
39
|
"src"
|
|
45
40
|
].join("."));
|
|
46
|
-
|
|
41
|
+
webfontMain(this.name, this.target, this.filesSrc, params, options, logger).finally(allDone);
|
|
47
42
|
});
|
|
48
43
|
};
|
|
49
|
-
const webfont = async (
|
|
50
|
-
|
|
44
|
+
const webfont = async (targetName, config) => {
|
|
45
|
+
const filesSrc = globSync(config.src, { posix: true });
|
|
46
|
+
await webfontMain("webfont", targetName, filesSrc, config);
|
|
47
|
+
};
|
|
48
|
+
const webfontGruntCjs = (grunt) => webfontGrunt(grunt);
|
|
49
|
+
Object.assign(webfontGruntCjs, {
|
|
50
|
+
default: webfontGrunt,
|
|
51
|
+
webfont
|
|
52
|
+
});
|
|
53
|
+
const webfontMain = async (name, target, filesSrc, params, options = params.options ?? {}, logger = consolaLogger) => {
|
|
51
54
|
const md5 = crypto.createHash("md5");
|
|
52
55
|
if (params.dest === void 0 && options.dest === void 0) logger.log.warn(`Required property ${name}.${target}.dest or ${name}.${target}.options.dest missing.`);
|
|
53
56
|
if (options.skip) {
|
|
@@ -81,8 +84,12 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
81
84
|
htmlDemo: options.htmlDemo !== false,
|
|
82
85
|
htmlDemoTemplate: options.htmlDemoTemplate,
|
|
83
86
|
htmlDemoFilename: options.htmlDemoFilename,
|
|
84
|
-
styles: optionToArray(options.styles, "font,icon"),
|
|
85
|
-
types: optionToArray(options.types,
|
|
87
|
+
styles: optionToArray(options.styles, ["font", "icon"]),
|
|
88
|
+
types: optionToArray(options.types, [
|
|
89
|
+
"eot",
|
|
90
|
+
"woff",
|
|
91
|
+
"ttf"
|
|
92
|
+
]),
|
|
86
93
|
order: optionToArray(options.order, fontFormats),
|
|
87
94
|
embed: options.embed === true ? ["woff"] : optionToArray(options.embed, false),
|
|
88
95
|
rename: options.rename || path.basename,
|
|
@@ -90,7 +97,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
90
97
|
autoHint: options.autoHint !== false,
|
|
91
98
|
codepoints: options.codepoints,
|
|
92
99
|
codepointsFile: options.codepointsFile,
|
|
93
|
-
startCodepoint: options.startCodepoint ||
|
|
100
|
+
startCodepoint: options.startCodepoint || 61697,
|
|
94
101
|
ie7: options.ie7 === true,
|
|
95
102
|
normalize: options.normalize === true,
|
|
96
103
|
optimize: options.optimize === false ? false : true,
|
|
@@ -101,7 +108,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
101
108
|
cache: options.cache || path.join(import.meta.dirname, "..", ".cache"),
|
|
102
109
|
callback: options.callback,
|
|
103
110
|
customOutputs: options.customOutputs,
|
|
104
|
-
execMaxBuffer: options.execMaxBuffer ||
|
|
111
|
+
execMaxBuffer: options.execMaxBuffer || 204800
|
|
105
112
|
};
|
|
106
113
|
o = Object.assign(o, {
|
|
107
114
|
fontName: o.fontBaseName,
|
|
@@ -129,12 +136,12 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
129
136
|
let currentCodepoint = o.startCodepoint;
|
|
130
137
|
if (!o.codepoints) o.codepoints = {};
|
|
131
138
|
if (o.codepointsFile) o.codepoints = readCodepointsFromFile();
|
|
132
|
-
o.glyphs.forEach((name
|
|
133
|
-
if (!o.codepoints[name
|
|
139
|
+
o.glyphs.forEach((name) => {
|
|
140
|
+
if (!o.codepoints[name]) o.codepoints[name] = getNextCodepoint();
|
|
134
141
|
});
|
|
135
142
|
if (o.codepointsFile) saveCodepointsToFile();
|
|
136
143
|
const previousHash = readHash(name, target);
|
|
137
|
-
logger.log.verbose(
|
|
144
|
+
logger.log.verbose(`New hash: ${o.hash} - previous hash: ${previousHash}`);
|
|
138
145
|
if (o.hash === previousHash) {
|
|
139
146
|
logger.log.verbose("Config and source files weren’t changed since last run, checking resulting files...");
|
|
140
147
|
let regenerationNeeded = false;
|
|
@@ -148,7 +155,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
148
155
|
regenerationNeeded = generatedFiles.some((filename) => {
|
|
149
156
|
if (!filename) return false;
|
|
150
157
|
if (!fs.existsSync(filename)) {
|
|
151
|
-
logger.log.verbose(
|
|
158
|
+
logger.log.verbose(`File ${filename} is missed.`);
|
|
152
159
|
return true;
|
|
153
160
|
}
|
|
154
161
|
return false;
|
|
@@ -188,7 +195,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
188
195
|
md5.update(fs.readFileSync(file, "utf8"));
|
|
189
196
|
});
|
|
190
197
|
md5.update(JSON.stringify(o));
|
|
191
|
-
md5.update(
|
|
198
|
+
md5.update(version);
|
|
192
199
|
if (o.template) md5.update(fs.readFileSync(o.template, "utf8"));
|
|
193
200
|
if (o.htmlDemoTemplate) md5.update(fs.readFileSync(o.htmlDemoTemplate, "utf8"));
|
|
194
201
|
return md5.digest("hex");
|
|
@@ -239,8 +246,8 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
239
246
|
*/
|
|
240
247
|
function generateStylesheets() {
|
|
241
248
|
const codepoints = [];
|
|
242
|
-
o.glyphs.forEach((name
|
|
243
|
-
codepoints.push(o.codepoints[name
|
|
249
|
+
o.glyphs.forEach((name) => {
|
|
250
|
+
codepoints.push(o.codepoints[name].toString(16));
|
|
244
251
|
});
|
|
245
252
|
o.codepoints = codepoints;
|
|
246
253
|
o.glyphs = o.glyphs.map(classnameize);
|
|
@@ -318,7 +325,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
318
325
|
function prepareHtmlTemplateContext() {
|
|
319
326
|
let context = prepareBaseTemplateContext();
|
|
320
327
|
let htmlStyles;
|
|
321
|
-
const relativeRe = new RegExp(
|
|
328
|
+
const relativeRe = new RegExp(o.relativeFontPath.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&").replace(/[=!:\/]/g, "\\$&"), "g");
|
|
322
329
|
const htmlRelativeFontPath = normalizePath(path.relative(o.destHtml, o.dest));
|
|
323
330
|
const _fontSrc1 = o.fontSrc1.replace(relativeRe, htmlRelativeFontPath);
|
|
324
331
|
const _fontSrc2 = o.fontSrc2.replace(relativeRe, htmlRelativeFontPath);
|
|
@@ -347,9 +354,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
347
354
|
context = Object.assign(context, outputConfig.context);
|
|
348
355
|
const templatePath = outputConfig.template;
|
|
349
356
|
const extension = path.extname(templatePath);
|
|
350
|
-
const
|
|
351
|
-
const template$1 = readTemplate(templatePath, syntax, extension);
|
|
352
|
-
const output = renderTemplate(template$1, context);
|
|
357
|
+
const output = renderTemplate(readTemplate(templatePath, outputConfig.syntax || "", extension), context);
|
|
353
358
|
const dest = outputConfig.dest || o.dest;
|
|
354
359
|
let filepath;
|
|
355
360
|
let destParent;
|
|
@@ -375,8 +380,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
375
380
|
async function generateDemoHtml() {
|
|
376
381
|
if (!o.htmlDemo) return;
|
|
377
382
|
const context = prepareHtmlTemplateContext();
|
|
378
|
-
const
|
|
379
|
-
const demo = renderTemplate(demoTemplate, context);
|
|
383
|
+
const demo = renderTemplate(readTemplate(o.htmlDemoTemplate, "demo", ".html"), context);
|
|
380
384
|
try {
|
|
381
385
|
await fs.promises.mkdir(getDemoPath(), { recursive: true });
|
|
382
386
|
} catch (err) {
|
|
@@ -403,7 +407,7 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
403
407
|
* @param defVal Default value
|
|
404
408
|
*/
|
|
405
409
|
function optionToArray(val, defVal) {
|
|
406
|
-
if (val === void 0)
|
|
410
|
+
if (val === void 0) return defVal || [];
|
|
407
411
|
if (!val) return [];
|
|
408
412
|
if (typeof val !== "string") return val;
|
|
409
413
|
return val.split(",").map((value) => value.trim());
|
|
@@ -489,12 +493,16 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
489
493
|
}
|
|
490
494
|
url = filename;
|
|
491
495
|
} else url = `${o.relativeFontPath}${filename}`;
|
|
492
|
-
if (o.addHashes)
|
|
493
|
-
|
|
496
|
+
if (o.addHashes) {
|
|
497
|
+
if (url.indexOf("#iefix") === -1) url = url.replace(/(#|$)/, `?${o.hash}$1`);
|
|
498
|
+
else url = url.replace(/(#|$)/, `${o.hash}$1`);
|
|
499
|
+
}
|
|
494
500
|
}
|
|
495
501
|
let src = `url("${url}")`;
|
|
496
|
-
if (o.fontPathVariables && stylesheet !== "css")
|
|
497
|
-
|
|
502
|
+
if (o.fontPathVariables && stylesheet !== "css") {
|
|
503
|
+
if (stylesheet === "less") src = `url("@{${fontPathVariableName.replace("@", "")}}${url}")`;
|
|
504
|
+
else src = `url(${fontPathVariableName} + "${url}")`;
|
|
505
|
+
}
|
|
498
506
|
if (font.format) src += ` format("${font.format}")`;
|
|
499
507
|
return src;
|
|
500
508
|
}
|
|
@@ -506,8 +514,8 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
506
514
|
* @param ext Extension of the template
|
|
507
515
|
* @return \{filename: 'Template filename', template: 'Template code'}
|
|
508
516
|
*/
|
|
509
|
-
function readTemplate(template
|
|
510
|
-
const filename = template
|
|
517
|
+
function readTemplate(template, syntax, ext, optional) {
|
|
518
|
+
const filename = template ? path.resolve(template.replace(path.extname(template), ext)) : path.join(import.meta.dirname, `../templates/${syntax}${ext}`);
|
|
511
519
|
if (fs.existsSync(filename)) return {
|
|
512
520
|
filename,
|
|
513
521
|
template: fs.readFileSync(filename, "utf8")
|
|
@@ -520,11 +528,19 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
520
528
|
* @param template {filename: 'Template filename', template: 'Template code'}
|
|
521
529
|
* @param context Template context
|
|
522
530
|
*/
|
|
523
|
-
function renderTemplate(template
|
|
531
|
+
function renderTemplate(template, context) {
|
|
524
532
|
try {
|
|
525
|
-
return
|
|
533
|
+
return new Eta({
|
|
534
|
+
autoTrim: ["nl", false],
|
|
535
|
+
parse: {
|
|
536
|
+
exec: "",
|
|
537
|
+
interpolate: "~",
|
|
538
|
+
raw: "="
|
|
539
|
+
},
|
|
540
|
+
useWith: true
|
|
541
|
+
}).renderString(template.template, context);
|
|
526
542
|
} catch (e) {
|
|
527
|
-
logger.fail.fatal(`Error while rendering template ${template
|
|
543
|
+
logger.fail.fatal(`Error while rendering template ${template.filename}: ${e.message}`);
|
|
528
544
|
}
|
|
529
545
|
}
|
|
530
546
|
/**
|
|
@@ -560,8 +576,8 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
560
576
|
*/
|
|
561
577
|
function getDemoFilePath() {
|
|
562
578
|
if (!o.htmlDemo) return null;
|
|
563
|
-
const name
|
|
564
|
-
return path.join(o.destHtml, `${name
|
|
579
|
+
const name = o.htmlDemoFilename || o.fontBaseName;
|
|
580
|
+
return path.join(o.destHtml, `${name}.html`);
|
|
565
581
|
}
|
|
566
582
|
/**
|
|
567
583
|
* Return path of HTML demo file or `null` if feature was disabled
|
|
@@ -577,8 +593,8 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
577
593
|
* @param target Task target name.
|
|
578
594
|
* @param hash Hash.
|
|
579
595
|
*/
|
|
580
|
-
function saveHash(name
|
|
581
|
-
const filepath = getHashPath(name
|
|
596
|
+
function saveHash(name, target, hash) {
|
|
597
|
+
const filepath = getHashPath(name, target);
|
|
582
598
|
fs.mkdirSync(path.dirname(filepath), { recursive: true });
|
|
583
599
|
fs.writeFileSync(filepath, hash);
|
|
584
600
|
}
|
|
@@ -588,8 +604,8 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
588
604
|
* @param name Task name (webfont).
|
|
589
605
|
* @param target Task target name.
|
|
590
606
|
*/
|
|
591
|
-
function readHash(name
|
|
592
|
-
const filepath = getHashPath(name
|
|
607
|
+
function readHash(name, target) {
|
|
608
|
+
const filepath = getHashPath(name, target);
|
|
593
609
|
if (fs.existsSync(filepath)) return fs.readFileSync(filepath, "utf8");
|
|
594
610
|
return null;
|
|
595
611
|
}
|
|
@@ -599,11 +615,11 @@ const webfont = async (name, target, filesSrc, params, options, logger) => {
|
|
|
599
615
|
* @param name Task name (webfont).
|
|
600
616
|
* @param target Task target name.
|
|
601
617
|
*/
|
|
602
|
-
function getHashPath(name
|
|
603
|
-
return path.join(o.cache, name
|
|
618
|
+
function getHashPath(name, target) {
|
|
619
|
+
return path.join(o.cache, name, target, "hash");
|
|
604
620
|
}
|
|
605
621
|
};
|
|
606
|
-
|
|
607
622
|
//#endregion
|
|
608
|
-
export {
|
|
623
|
+
export { webfontGrunt as default, webfontGrunt, webfontGruntCjs as "module.exports", webfont };
|
|
624
|
+
|
|
609
625
|
//# sourceMappingURL=webfont.js.map
|