@fontmin-rs/wasm 0.1.0-beta.1 → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/dist/index.d.mts CHANGED
@@ -9,6 +9,19 @@ declare function initWasm(input?: InitInput): Promise<void>;
9
9
  type FontFormat = 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'svg' | 'css' | 'unknown';
10
10
  type OutputFormat = 'ttf' | 'woff' | 'woff2' | 'eot' | 'svg' | 'css';
11
11
  type LayoutSubsetMode = 'drop' | 'conservative' | 'preserve';
12
+ type MissingGlyphPolicy = 'ignore' | 'warn' | 'error';
13
+ interface CoverageOptions {
14
+ basicText?: boolean;
15
+ text?: string;
16
+ unicodeRanges?: string[];
17
+ unicodes?: number[];
18
+ }
19
+ interface CoverageReport {
20
+ coveragePercent: number;
21
+ missing: number[];
22
+ requested: number[];
23
+ supported: number[];
24
+ }
12
25
  interface FontMetadata {
13
26
  ascender: number;
14
27
  descender: number;
@@ -25,15 +38,12 @@ interface FontInfo {
25
38
  metadata: FontMetadata;
26
39
  size: number;
27
40
  }
28
- interface SubsetOptions {
29
- basicText?: boolean;
41
+ interface SubsetOptions extends CoverageOptions {
30
42
  keepNotdef?: boolean;
31
43
  layout?: LayoutSubsetMode;
44
+ missingGlyphs?: MissingGlyphPolicy;
32
45
  preserveHinting?: boolean;
33
- text?: string;
34
46
  trim?: boolean;
35
- unicodeRanges?: string[];
36
- unicodes?: number[];
37
47
  }
38
48
  interface WoffOptions {
39
49
  compressionLevel?: number;
@@ -96,6 +106,7 @@ interface CssOptions {
96
106
  //#endregion
97
107
  //#region src/native.d.ts
98
108
  declare function subsetTtf(input: Uint8Array, options?: SubsetOptions): Promise<Uint8Array>;
109
+ declare function analyzeCoverage(input: Uint8Array, options?: CoverageOptions): Promise<CoverageReport>;
99
110
  declare function ttfToWoff(input: Uint8Array, options?: WoffOptions): Promise<Uint8Array>;
100
111
  declare function woffToTtf(input: Uint8Array): Promise<Uint8Array>;
101
112
  declare function ttfToWoff2(input: Uint8Array, options?: Ttf2Woff2Options): Promise<Uint8Array>;
@@ -193,4 +204,4 @@ interface BrowserOptimizeConfig {
193
204
  }
194
205
  declare function optimizeBrowser(config: BrowserOptimizeConfig): Promise<BrowserAsset[]>;
195
206
  //#endregion
196
- export { type BrowserAsset, type BrowserOptimizeConfig, type BrowserPlugin, type BrowserPluginContext, type CssFontSource, type CssGlyph, type CssOptions, type DeliverySlice, type DeliverySlicesOptions, type FontFormat, type FontInfo, type FontMetadata, type FontminCompatPresetOptions, type GlyphOptions, type LayoutSubsetMode, type MaybePromise, type ModernWebOptions, type Otf2TtfOptions, type Otf2TtfPluginOptions, type OutputFormat, type SubsetOptions, type Svg2TtfOptions, type Svg2TtfPluginOptions, type SvgIcon, type Svgs2TtfOptions, type Svgs2TtfPluginOptions, type Ttf2EotOptions, type Ttf2EotPluginOptions, type Ttf2SvgOptions, type Ttf2SvgPluginOptions, type Ttf2Woff2Options, type Ttf2Woff2PluginOptions, type Ttf2WoffPluginOptions, type WoffOptions, css, deliverySlices, eotToTtf, fontminCompatPreset, generateFontFaceCss, glyph, initWasm, inspect, isWasmInitialized, modernWeb, optimizeBrowser, otf2ttf, otfToTtf, subsetTtf, svg2ttf, svgFontToTtf, svgs2ttf, svgsToTtf, ttf2eot, ttf2svg, ttf2woff, ttf2woff2, ttfToEot, ttfToSvg, ttfToWoff, ttfToWoff2, validateWoff2, woff2ToTtf, woffToTtf };
207
+ export { type BrowserAsset, type BrowserOptimizeConfig, type BrowserPlugin, type BrowserPluginContext, type CoverageOptions, type CoverageReport, type CssFontSource, type CssGlyph, type CssOptions, type DeliverySlice, type DeliverySlicesOptions, type FontFormat, type FontInfo, type FontMetadata, type FontminCompatPresetOptions, type GlyphOptions, type LayoutSubsetMode, type MaybePromise, type MissingGlyphPolicy, type ModernWebOptions, type Otf2TtfOptions, type Otf2TtfPluginOptions, type OutputFormat, type SubsetOptions, type Svg2TtfOptions, type Svg2TtfPluginOptions, type SvgIcon, type Svgs2TtfOptions, type Svgs2TtfPluginOptions, type Ttf2EotOptions, type Ttf2EotPluginOptions, type Ttf2SvgOptions, type Ttf2SvgPluginOptions, type Ttf2Woff2Options, type Ttf2Woff2PluginOptions, type Ttf2WoffPluginOptions, type WoffOptions, analyzeCoverage, css, deliverySlices, eotToTtf, fontminCompatPreset, generateFontFaceCss, glyph, initWasm, inspect, isWasmInitialized, modernWeb, optimizeBrowser, otf2ttf, otfToTtf, subsetTtf, svg2ttf, svgFontToTtf, svgs2ttf, svgsToTtf, ttf2eot, ttf2svg, ttf2woff, ttf2woff2, ttfToEot, ttfToSvg, ttfToWoff, ttfToWoff2, validateWoff2, woff2ToTtf, woffToTtf };
package/dist/index.mjs CHANGED
@@ -29,8 +29,15 @@ async function binary(operation, input, options = {}) {
29
29
  return bytes((await getWasmModule()).transform(operation, input, options));
30
30
  }
31
31
  async function subsetTtf(input, options = {}) {
32
+ if ((options.missingGlyphs ?? "warn") === "warn") {
33
+ const warning = missingGlyphWarning(await analyzeCoverage(input, coverageOptions(options)));
34
+ if (warning !== void 0) console.warn(warning);
35
+ }
32
36
  return binary("subsetTtf", input, options);
33
37
  }
38
+ async function analyzeCoverage(input, options = {}) {
39
+ return (await getWasmModule()).transform("analyzeCoverage", input, options);
40
+ }
34
41
  async function ttfToWoff(input, options = {}) {
35
42
  return binary("ttfToWoff", input, options);
36
43
  }
@@ -70,6 +77,20 @@ async function inspect(input) {
70
77
  async function generateFontFaceCss(sources, options = {}) {
71
78
  return (await getWasmModule()).generate_css(sources, options);
72
79
  }
80
+ function coverageOptions(options) {
81
+ const coverage = {};
82
+ if (options.basicText !== void 0) coverage.basicText = options.basicText;
83
+ if (options.text !== void 0) coverage.text = options.text;
84
+ if (options.unicodeRanges !== void 0) coverage.unicodeRanges = options.unicodeRanges;
85
+ if (options.unicodes !== void 0) coverage.unicodes = options.unicodes;
86
+ return coverage;
87
+ }
88
+ function missingGlyphWarning(report) {
89
+ if (report.missing.length === 0) return;
90
+ const visible = report.missing.slice(0, 16).map((codepoint) => `U+${codepoint.toString(16).toUpperCase().padStart(4, "0")}`).join(", ");
91
+ const remaining = report.missing.length - 16;
92
+ return `missing glyphs for requested Unicode code points: ${visible}${remaining > 0 ? `, and ${remaining} more` : ""}`;
93
+ }
73
94
  //#endregion
74
95
  //#region src/plugins.ts
75
96
  function plugin(name, options) {
@@ -83,6 +104,7 @@ function glyph(options = {}) {
83
104
  basicText: false,
84
105
  keepNotdef: true,
85
106
  layout: "conservative",
107
+ missingGlyphs: "warn",
86
108
  preserveHinting: false,
87
109
  trim: true,
88
110
  unicodes: [],
@@ -204,7 +226,10 @@ async function optimizeBrowser(config) {
204
226
  }
205
227
  for (const slice of slices) slicedAssets.push({
206
228
  ...asset,
207
- contents: await subsetTtf(asset.contents, { unicodeRanges: slice.unicodeRanges }),
229
+ contents: await subsetTtf(asset.contents, {
230
+ missingGlyphs: "ignore",
231
+ unicodeRanges: slice.unicodeRanges
232
+ }),
208
233
  fileName: appendFileNameSuffix(asset.fileName, slice.name),
209
234
  unicodeRanges: slice.unicodeRanges
210
235
  });
@@ -330,4 +355,4 @@ function toKebabCase(value) {
330
355
  return value.trim().replaceAll(/([a-z])([A-Z])/gu, "$1-$2").replaceAll(/\s+/gu, "-").toLowerCase();
331
356
  }
332
357
  //#endregion
333
- export { css, deliverySlices, eotToTtf, fontminCompatPreset, generateFontFaceCss, glyph, initWasm, inspect, isWasmInitialized, modernWeb, optimizeBrowser, otf2ttf, otfToTtf, subsetTtf, svg2ttf, svgFontToTtf, svgs2ttf, svgsToTtf, ttf2eot, ttf2svg, ttf2woff, ttf2woff2, ttfToEot, ttfToSvg, ttfToWoff, ttfToWoff2, validateWoff2, woff2ToTtf, woffToTtf };
358
+ export { analyzeCoverage, css, deliverySlices, eotToTtf, fontminCompatPreset, generateFontFaceCss, glyph, initWasm, inspect, isWasmInitialized, modernWeb, optimizeBrowser, otf2ttf, otfToTtf, subsetTtf, svg2ttf, svgFontToTtf, svgs2ttf, svgsToTtf, ttf2eot, ttf2svg, ttf2woff, ttf2woff2, ttfToEot, ttfToSvg, ttfToWoff, ttfToWoff2, validateWoff2, woff2ToTtf, woffToTtf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fontmin-rs/wasm",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "Browser WASM runtime for fontmin-rs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "@ntnyq/tsconfig": "^3.1.0",
28
28
  "playwright": "^1.61.1",
29
- "tsdown": "^0.22.8",
29
+ "tsdown": "^0.22.12",
30
30
  "typescript": "^7.0.2",
31
31
  "vitest": "^4.1.10"
32
32
  },