@turntrout/subfont 1.7.0 → 1.8.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.
Files changed (151) hide show
  1. package/CLAUDE.md +39 -13
  2. package/README.md +24 -14
  3. package/lib/FontTracerPool.d.ts +38 -0
  4. package/lib/FontTracerPool.d.ts.map +1 -0
  5. package/lib/FontTracerPool.js +230 -217
  6. package/lib/FontTracerPool.js.map +1 -0
  7. package/lib/HeadlessBrowser.d.ts +18 -0
  8. package/lib/HeadlessBrowser.d.ts.map +1 -0
  9. package/lib/HeadlessBrowser.js +216 -210
  10. package/lib/HeadlessBrowser.js.map +1 -0
  11. package/lib/cli.d.ts +3 -0
  12. package/lib/cli.d.ts.map +1 -0
  13. package/lib/cli.js +15 -12
  14. package/lib/cli.js.map +1 -0
  15. package/lib/codepointMaps.d.ts +4 -0
  16. package/lib/codepointMaps.d.ts.map +1 -0
  17. package/lib/codepointMaps.js +99 -0
  18. package/lib/codepointMaps.js.map +1 -0
  19. package/lib/collectFeatureGlyphIds.d.ts +3 -0
  20. package/lib/collectFeatureGlyphIds.d.ts.map +1 -0
  21. package/lib/collectFeatureGlyphIds.js +124 -138
  22. package/lib/collectFeatureGlyphIds.js.map +1 -0
  23. package/lib/collectTextsByPage.d.ts +41 -0
  24. package/lib/collectTextsByPage.d.ts.map +1 -0
  25. package/lib/collectTextsByPage.js +726 -965
  26. package/lib/collectTextsByPage.js.map +1 -0
  27. package/lib/concurrencyLimit.d.ts +3 -0
  28. package/lib/concurrencyLimit.d.ts.map +1 -0
  29. package/lib/concurrencyLimit.js +12 -11
  30. package/lib/concurrencyLimit.js.map +1 -0
  31. package/lib/escapeJsStringLiteral.d.ts +3 -0
  32. package/lib/escapeJsStringLiteral.d.ts.map +1 -0
  33. package/lib/escapeJsStringLiteral.js +7 -6
  34. package/lib/escapeJsStringLiteral.js.map +1 -0
  35. package/lib/extractReferencedCustomPropertyNames.d.ts +3 -0
  36. package/lib/extractReferencedCustomPropertyNames.d.ts.map +1 -0
  37. package/lib/extractReferencedCustomPropertyNames.js +15 -16
  38. package/lib/extractReferencedCustomPropertyNames.js.map +1 -0
  39. package/lib/extractVisibleText.d.ts +7 -0
  40. package/lib/extractVisibleText.d.ts.map +1 -0
  41. package/lib/extractVisibleText.js +110 -119
  42. package/lib/extractVisibleText.js.map +1 -0
  43. package/lib/findCustomPropertyDefinitions.d.ts +8 -0
  44. package/lib/findCustomPropertyDefinitions.d.ts.map +1 -0
  45. package/lib/findCustomPropertyDefinitions.js +41 -48
  46. package/lib/findCustomPropertyDefinitions.js.map +1 -0
  47. package/lib/fontConverter.d.ts +2 -0
  48. package/lib/fontConverter.d.ts.map +1 -0
  49. package/lib/fontConverter.js +40 -21
  50. package/lib/fontConverter.js.map +1 -0
  51. package/lib/fontConverterWorker.d.ts +2 -0
  52. package/lib/fontConverterWorker.d.ts.map +1 -0
  53. package/lib/fontConverterWorker.js +52 -15
  54. package/lib/fontConverterWorker.js.map +1 -0
  55. package/lib/fontFaceHelpers.d.ts +64 -0
  56. package/lib/fontFaceHelpers.d.ts.map +1 -0
  57. package/lib/fontFaceHelpers.js +237 -249
  58. package/lib/fontFaceHelpers.js.map +1 -0
  59. package/lib/fontFeatureHelpers.d.ts +30 -0
  60. package/lib/fontFeatureHelpers.d.ts.map +1 -0
  61. package/lib/fontFeatureHelpers.js +277 -212
  62. package/lib/fontFeatureHelpers.js.map +1 -0
  63. package/lib/fontTracerWorker.d.ts +11 -0
  64. package/lib/fontTracerWorker.d.ts.map +1 -0
  65. package/lib/fontTracerWorker.js +94 -60
  66. package/lib/fontTracerWorker.js.map +1 -0
  67. package/lib/gatherStylesheetsWithPredicates.d.ts +26 -0
  68. package/lib/gatherStylesheetsWithPredicates.d.ts.map +1 -0
  69. package/lib/gatherStylesheetsWithPredicates.js +75 -84
  70. package/lib/gatherStylesheetsWithPredicates.js.map +1 -0
  71. package/lib/getCssRulesByProperty.d.ts +29 -0
  72. package/lib/getCssRulesByProperty.d.ts.map +1 -0
  73. package/lib/getCssRulesByProperty.js +316 -316
  74. package/lib/getCssRulesByProperty.js.map +1 -0
  75. package/lib/getFontInfo.d.ts +11 -0
  76. package/lib/getFontInfo.d.ts.map +1 -0
  77. package/lib/getFontInfo.js +31 -33
  78. package/lib/getFontInfo.js.map +1 -0
  79. package/lib/initialValueByProp.d.ts +3 -0
  80. package/lib/initialValueByProp.d.ts.map +1 -0
  81. package/lib/initialValueByProp.js +20 -17
  82. package/lib/initialValueByProp.js.map +1 -0
  83. package/lib/injectSubsetDefinitions.d.ts +3 -0
  84. package/lib/injectSubsetDefinitions.d.ts.map +1 -0
  85. package/lib/injectSubsetDefinitions.js +55 -59
  86. package/lib/injectSubsetDefinitions.js.map +1 -0
  87. package/lib/normalizeFontPropertyValue.d.ts +3 -0
  88. package/lib/normalizeFontPropertyValue.d.ts.map +1 -0
  89. package/lib/normalizeFontPropertyValue.js +59 -54
  90. package/lib/normalizeFontPropertyValue.js.map +1 -0
  91. package/lib/parseCommandLineOptions.d.ts +9 -0
  92. package/lib/parseCommandLineOptions.d.ts.map +1 -0
  93. package/lib/parseCommandLineOptions.js +145 -149
  94. package/lib/parseCommandLineOptions.js.map +1 -0
  95. package/lib/parseFontVariationSettings.d.ts +3 -0
  96. package/lib/parseFontVariationSettings.d.ts.map +1 -0
  97. package/lib/parseFontVariationSettings.js +38 -36
  98. package/lib/parseFontVariationSettings.js.map +1 -0
  99. package/lib/progress.d.ts +27 -0
  100. package/lib/progress.d.ts.map +1 -0
  101. package/lib/progress.js +51 -54
  102. package/lib/progress.js.map +1 -0
  103. package/lib/sfntCache.d.ts +4 -0
  104. package/lib/sfntCache.d.ts.map +1 -0
  105. package/lib/sfntCache.js +67 -25
  106. package/lib/sfntCache.js.map +1 -0
  107. package/lib/stripLocalTokens.d.ts +3 -0
  108. package/lib/stripLocalTokens.d.ts.map +1 -0
  109. package/lib/stripLocalTokens.js +23 -21
  110. package/lib/stripLocalTokens.js.map +1 -0
  111. package/lib/subfont.d.ts +54 -0
  112. package/lib/subfont.d.ts.map +1 -0
  113. package/lib/subfont.js +531 -629
  114. package/lib/subfont.js.map +1 -0
  115. package/lib/subsetFontWithGlyphs.d.ts +21 -0
  116. package/lib/subsetFontWithGlyphs.d.ts.map +1 -0
  117. package/lib/subsetFontWithGlyphs.js +285 -259
  118. package/lib/subsetFontWithGlyphs.js.map +1 -0
  119. package/lib/subsetFonts.d.ts +55 -0
  120. package/lib/subsetFonts.d.ts.map +1 -0
  121. package/lib/subsetFonts.js +899 -1200
  122. package/lib/subsetFonts.js.map +1 -0
  123. package/lib/subsetGeneration.d.ts +36 -0
  124. package/lib/subsetGeneration.d.ts.map +1 -0
  125. package/lib/subsetGeneration.js +328 -325
  126. package/lib/subsetGeneration.js.map +1 -0
  127. package/lib/types/shared.d.ts +11 -0
  128. package/lib/types/shared.d.ts.map +1 -0
  129. package/lib/types/shared.js +3 -0
  130. package/lib/types/shared.js.map +1 -0
  131. package/lib/unicodeRange.d.ts +3 -0
  132. package/lib/unicodeRange.d.ts.map +1 -0
  133. package/lib/unicodeRange.js +17 -30
  134. package/lib/unicodeRange.js.map +1 -0
  135. package/lib/unquote.d.ts +3 -0
  136. package/lib/unquote.d.ts.map +1 -0
  137. package/lib/unquote.js +18 -25
  138. package/lib/unquote.js.map +1 -0
  139. package/lib/variationAxes.d.ts +33 -0
  140. package/lib/variationAxes.d.ts.map +1 -0
  141. package/lib/variationAxes.js +127 -157
  142. package/lib/variationAxes.js.map +1 -0
  143. package/lib/warnAboutMissingGlyphs.d.ts +43 -0
  144. package/lib/warnAboutMissingGlyphs.d.ts.map +1 -0
  145. package/lib/warnAboutMissingGlyphs.js +139 -147
  146. package/lib/warnAboutMissingGlyphs.js.map +1 -0
  147. package/lib/wasmQueue.d.ts +3 -0
  148. package/lib/wasmQueue.d.ts.map +1 -0
  149. package/lib/wasmQueue.js +13 -10
  150. package/lib/wasmQueue.js.map +1 -0
  151. package/package.json +12 -2
@@ -1,226 +1,232 @@
1
- const urlTools = require('urltools');
2
- const puppeteer = require('puppeteer-core');
3
- const pathModule = require('path');
4
- const os = require('os');
5
- const {
6
- install,
7
- Browser,
8
- detectBrowserPlatform,
9
- Cache,
10
- } = require('@puppeteer/browsers');
11
-
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const urlTools = __importStar(require("urltools"));
36
+ const puppeteer = __importStar(require("puppeteer-core"));
37
+ const pathModule = require("path");
38
+ const os = require("os");
39
+ const browsers_1 = require("@puppeteer/browsers");
12
40
  async function transferResults(jsHandle) {
13
- const results = await jsHandle.jsonValue();
14
- for (const [i, result] of results.entries()) {
15
- const resultHandle = await jsHandle.getProperty(String(i));
16
- try {
17
- const elementHandle = await resultHandle.getProperty('node');
18
- result.node = elementHandle;
19
- } finally {
20
- await resultHandle.dispose();
41
+ const results = await jsHandle.jsonValue();
42
+ for (const [i, result] of results.entries()) {
43
+ const resultHandle = await jsHandle.getProperty(String(i));
44
+ try {
45
+ const elementHandle = await resultHandle.getProperty('node');
46
+ result.node = elementHandle;
47
+ }
48
+ finally {
49
+ await resultHandle.dispose();
50
+ }
21
51
  }
22
- }
23
- return results;
52
+ return results;
24
53
  }
25
-
26
- async function downloadOrLocatePreferredBrowserRevision(
27
- extraArgs = [],
28
- log = console
29
- ) {
30
- if (process.env.PUPPETEER_EXECUTABLE_PATH) {
54
+ async function downloadOrLocatePreferredBrowserRevision(extraArgs = [], log = console) {
55
+ if (process.env.PUPPETEER_EXECUTABLE_PATH) {
56
+ return puppeteer.launch({
57
+ executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
58
+ args: ['--no-sandbox', '--disable-setuid-sandbox', ...extraArgs],
59
+ });
60
+ }
61
+ const cacheDir = pathModule.resolve(__dirname, '..', 'puppeteer-browsers');
62
+ const platform = (0, browsers_1.detectBrowserPlatform)();
63
+ const cache = new browsers_1.Cache(cacheDir);
64
+ const installed = cache.getInstalledBrowsers();
65
+ let executablePath;
66
+ const chromeEntry = installed.find((b) => b.browser === browsers_1.Browser.CHROME);
67
+ if (chromeEntry) {
68
+ executablePath = chromeEntry.executablePath;
69
+ }
70
+ else {
71
+ // Check the default puppeteer cache (~/.cache/puppeteer) before downloading
72
+ const defaultCacheDir = pathModule.join(os.homedir(), '.cache', 'puppeteer');
73
+ const defaultCache = new browsers_1.Cache(defaultCacheDir);
74
+ const defaultInstalled = defaultCache.getInstalledBrowsers();
75
+ const defaultChromeEntry = defaultInstalled.find((b) => b.browser === browsers_1.Browser.CHROME);
76
+ if (defaultChromeEntry) {
77
+ executablePath = defaultChromeEntry.executablePath;
78
+ }
79
+ else {
80
+ log.log('Downloading Chrome');
81
+ const result = await (0, browsers_1.install)({
82
+ browser: browsers_1.Browser.CHROME,
83
+ buildId: 'stable',
84
+ cacheDir,
85
+ platform: platform,
86
+ });
87
+ executablePath = result.executablePath;
88
+ }
89
+ }
31
90
  return puppeteer.launch({
32
- executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
33
- args: ['--no-sandbox', '--disable-setuid-sandbox', ...extraArgs],
91
+ executablePath,
92
+ args: ['--no-sandbox', '--disable-setuid-sandbox', ...extraArgs],
34
93
  });
35
- }
36
- const cacheDir = pathModule.resolve(__dirname, '..', 'puppeteer-browsers');
37
- const platform = detectBrowserPlatform();
38
- const cache = new Cache(cacheDir);
39
- const installed = cache.getInstalledBrowsers();
40
- let executablePath;
41
- const chromeEntry = installed.find((b) => b.browser === Browser.CHROME);
42
- if (chromeEntry) {
43
- executablePath = chromeEntry.executablePath;
44
- } else {
45
- // Check the default puppeteer cache (~/.cache/puppeteer) before downloading
46
- const defaultCacheDir = pathModule.join(
47
- os.homedir(),
48
- '.cache',
49
- 'puppeteer'
50
- );
51
- const defaultCache = new Cache(defaultCacheDir);
52
- const defaultInstalled = defaultCache.getInstalledBrowsers();
53
- const defaultChromeEntry = defaultInstalled.find(
54
- (b) => b.browser === Browser.CHROME
55
- );
56
- if (defaultChromeEntry) {
57
- executablePath = defaultChromeEntry.executablePath;
58
- } else {
59
- log.log('Downloading Chrome');
60
- const result = await install({
61
- browser: Browser.CHROME,
62
- buildId: 'stable',
63
- cacheDir,
64
- platform,
65
- });
66
- executablePath = result.executablePath;
67
- }
68
- }
69
- return puppeteer.launch({
70
- executablePath,
71
- args: ['--no-sandbox', '--disable-setuid-sandbox', ...extraArgs],
72
- });
73
94
  }
74
-
75
95
  class HeadlessBrowser {
76
- constructor({ console, chromeArgs = [] }) {
77
- this.console = console;
78
- this._chromeArgs = chromeArgs;
79
- }
80
-
81
- _launchBrowserMemoized() {
82
- // Make sure we only download and launch one browser per HeadlessBrowser instance.
83
- // Clear the cached promise on failure so a subsequent call can retry.
84
- if (!this._launchPromise) {
85
- this._launchPromise = downloadOrLocatePreferredBrowserRevision(
86
- this._chromeArgs,
87
- this.console
88
- ).catch((err) => {
89
- this._launchPromise = undefined;
90
- throw err;
91
- });
96
+ console;
97
+ _chromeArgs;
98
+ _launchPromise;
99
+ _closed = false;
100
+ constructor({ console, chromeArgs = [] }) {
101
+ this.console = console;
102
+ this._chromeArgs = chromeArgs;
92
103
  }
93
- return this._launchPromise;
94
- }
95
-
96
- async tracePage(htmlAsset) {
97
- const assetGraph = htmlAsset.assetGraph;
98
- const browser = await this._launchBrowserMemoized();
99
- const page = await browser.newPage();
100
-
101
- try {
102
- // Make up a base url to map to the assetgraph root.
103
- // Use the canonical root if available, so that it'll be
104
- // easier to handle absolute and protocol-relative urls pointing
105
- // at it, as well as fall through to the actual domain if some
106
- // assets aren't found in the graph.
107
- const baseUrl = assetGraph.canonicalRoot
108
- ? assetGraph.canonicalRoot.replace(/\/?$/, '/')
109
- : 'https://example.com/';
110
-
111
- // Intercept all requests made by the headless browser, and
112
- // fake a response from the assetgraph instance if the corresponding
113
- // asset is found there:
114
- await page.setRequestInterception(true);
115
- page.on('request', (request) => {
116
- const url = request.url();
117
- if (url.startsWith(baseUrl)) {
118
- let agUrl = url.replace(baseUrl, assetGraph.root);
119
- if (/\/$/.test(agUrl)) {
120
- agUrl += 'index.html';
121
- }
122
- const asset = assetGraph.findAssets({
123
- isLoaded: true,
124
- url: agUrl,
125
- })[0];
126
- if (asset) {
127
- request.respond({
128
- status: 200,
129
- contentType: asset.contentType,
130
- body: asset.rawSrc,
131
- });
132
- } else {
133
- // Asset not in graph — return 404 instead of letting the
134
- // request hit the network (baseUrl is synthetic).
135
- request.respond({ status: 404, body: '' });
136
- }
137
- return;
104
+ _launchBrowserMemoized() {
105
+ if (this._closed) {
106
+ return Promise.reject(new Error('HeadlessBrowser is closed'));
138
107
  }
139
- if (url.startsWith('file:')) {
140
- request.continue();
141
- return;
108
+ if (!this._launchPromise) {
109
+ this._launchPromise = downloadOrLocatePreferredBrowserRevision(this._chromeArgs, this.console).catch((err) => {
110
+ this._launchPromise = undefined;
111
+ throw err;
112
+ });
142
113
  }
143
- // External request — abort to avoid hanging on DNS/network.
144
- // The requestfailed handler will log it.
145
- request.abort('failed');
146
- });
147
-
148
- page.on('requestfailed', (request) => {
149
- const response = request.response();
150
- if (response && response.status() > 400) {
151
- this.console.error(
152
- `${request.method()} ${request.url()} returned ${response.status()}`
153
- );
154
- } else {
155
- const failure = request.failure();
156
- const reason = failure ? failure.errorText : 'unknown error';
157
- this.console.error(
158
- `${request.method()} ${request.url()} failed: ${reason}`
159
- );
114
+ return this._launchPromise;
115
+ }
116
+ async tracePage(htmlAsset) {
117
+ const assetGraph = htmlAsset.assetGraph;
118
+ const browser = await this._launchBrowserMemoized();
119
+ const page = await browser.newPage();
120
+ try {
121
+ // Make up a base url to map to the assetgraph root.
122
+ const baseUrl = assetGraph.canonicalRoot
123
+ ? assetGraph.canonicalRoot.replace(/\/?$/, '/')
124
+ : 'https://example.com/';
125
+ // Intercept all requests made by the headless browser, and
126
+ // fake a response from the assetgraph instance if the corresponding
127
+ // asset is found there:
128
+ await page.setRequestInterception(true);
129
+ page.on('request', (request) => {
130
+ const url = request.url();
131
+ try {
132
+ if (url.startsWith(baseUrl)) {
133
+ let agUrl = url.replace(baseUrl, assetGraph.root);
134
+ if (/\/$/.test(agUrl)) {
135
+ agUrl += 'index.html';
136
+ }
137
+ const asset = assetGraph.findAssets({
138
+ isLoaded: true,
139
+ url: agUrl,
140
+ })[0];
141
+ if (asset) {
142
+ request.respond({
143
+ status: 200,
144
+ contentType: asset.contentType,
145
+ body: asset.rawSrc,
146
+ });
147
+ }
148
+ else {
149
+ request.respond({ status: 404, body: '' });
150
+ }
151
+ return;
152
+ }
153
+ if (url.startsWith('file:')) {
154
+ request.continue();
155
+ return;
156
+ }
157
+ // External request — abort to avoid hanging on DNS/network.
158
+ request.abort('failed');
159
+ }
160
+ catch {
161
+ // Request may already be handled or page may be closing — ignore.
162
+ }
163
+ });
164
+ page.on('requestfailed', (request) => {
165
+ const failure = request.failure();
166
+ const reason = failure ? failure.errorText : 'unknown error';
167
+ this.console.error(`${request.method()} ${request.url()} failed: ${reason}`);
168
+ });
169
+ page.on('pageerror', (err) => {
170
+ // Puppeteer v24+ passes Error objects; format stack to match v19 style
171
+ if (err instanceof Error && err.stack) {
172
+ // Normalize "at <anonymous> (url:line:col)" to "at url:line:col"
173
+ const normalized = err.stack.replace(/at <anonymous> \((.+)\)/g, 'at $1');
174
+ this.console.error(normalized);
175
+ }
176
+ else if (err instanceof Error) {
177
+ this.console.error(`${err.name}: ${err.message}`);
178
+ }
179
+ else {
180
+ this.console.error(err);
181
+ }
182
+ });
183
+ page.on('error', this.console.error);
184
+ // Prevent the CSP of the page from rejecting our injection of font-tracer
185
+ await page.setBypassCSP(true);
186
+ await page.goto(urlTools.resolveUrl(baseUrl, urlTools.buildRelativeUrl(assetGraph.root, htmlAsset.url)), { timeout: 30000 });
187
+ await page.addScriptTag({
188
+ path: require.resolve('font-tracer/dist/fontTracer.browser.js'),
189
+ });
190
+ // The injected font-tracer.browser.js script attaches a global
191
+ // `fontTracer`. The closure runs inside the browser, so the global
192
+ // is present at runtime even though TS can't know about it.
193
+ const jsHandle = await page.evaluateHandle(
194
+ /* istanbul ignore next */
195
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
196
+ () => globalThis.fontTracer(document));
197
+ try {
198
+ // puppeteer's evaluateHandle return type is generic over the page
199
+ // closure; bridge it to the local minimal shape.
200
+ // eslint-disable-next-line no-restricted-syntax
201
+ return await transferResults(jsHandle);
202
+ }
203
+ finally {
204
+ await jsHandle.dispose();
205
+ }
160
206
  }
161
- });
162
-
163
- page.on('pageerror', (err) => {
164
- // Puppeteer v24+ passes Error objects; format stack to match v19 style
165
- if (err instanceof Error && err.stack) {
166
- // Normalize "at <anonymous> (url:line:col)" to "at url:line:col"
167
- const normalized = err.stack.replace(
168
- /at <anonymous> \((.+)\)/g,
169
- 'at $1'
170
- );
171
- this.console.error(normalized);
172
- } else if (err instanceof Error) {
173
- this.console.error(`${err.name}: ${err.message}`);
174
- } else {
175
- this.console.error(err);
207
+ finally {
208
+ await page.close();
176
209
  }
177
- });
178
- page.on('error', this.console.error);
179
-
180
- // Prevent the CSP of the page from rejecting our injection of font-tracer
181
- await page.setBypassCSP(true);
182
-
183
- await page.goto(
184
- urlTools.resolveUrl(
185
- baseUrl,
186
- urlTools.buildRelativeUrl(assetGraph.root, htmlAsset.url)
187
- ),
188
- { timeout: 30000 }
189
- );
190
-
191
- await page.addScriptTag({
192
- path: require.resolve('font-tracer/dist/fontTracer.browser.js'),
193
- });
194
-
195
- const jsHandle = await page.evaluateHandle(
196
- /* global fontTracer */
197
- /* istanbul ignore next */
198
- () => fontTracer(document)
199
- );
200
- try {
201
- return await transferResults(jsHandle);
202
- } finally {
203
- await jsHandle.dispose();
204
- }
205
- } finally {
206
- await page.close();
207
210
  }
208
- }
209
-
210
- async close() {
211
- const launchPromise = this._launchPromise;
212
- if (launchPromise) {
213
- this._launchPromise = undefined;
214
- let browser;
215
- try {
216
- browser = await launchPromise;
217
- } catch {
218
- // Launch failed — nothing to close
219
- return;
220
- }
221
- await browser.close();
211
+ async close() {
212
+ // Set _closed *before* awaiting so any concurrent tracePage() that hasn't
213
+ // yet entered _launchBrowserMemoized fails fast instead of starting a
214
+ // second browser we won't clean up.
215
+ this._closed = true;
216
+ const launchPromise = this._launchPromise;
217
+ this._launchPromise = undefined;
218
+ if (launchPromise) {
219
+ let browser;
220
+ try {
221
+ browser = await launchPromise;
222
+ }
223
+ catch {
224
+ // Launch failed — nothing to close
225
+ return;
226
+ }
227
+ await browser.close();
228
+ }
222
229
  }
223
- }
224
230
  }
225
-
226
231
  module.exports = HeadlessBrowser;
232
+ //# sourceMappingURL=HeadlessBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HeadlessBrowser.js","sourceRoot":"","sources":["../src/HeadlessBrowser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,wCAAwC,CAAC;aAChE,CAAC,CAAC;YAEH,+DAA+D;YAC/D,mEAAmE;YACnE,4DAA4D;YAC5D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc;YACxC,0BAA0B;YAC1B,8DAA8D;YAC9D,GAAG,EAAE,CAAE,UAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAC/C,CAAC;YACF,IAAI,CAAC;gBACH,kEAAkE;gBAClE,iDAAiD;gBACjD,gDAAgD;gBAChD,OAAO,MAAM,eAAe,CAAC,QAAmC,CAAC,CAAC;YACpE,CAAC;oBAAS,CAAC;gBACT,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,0EAA0E;QAC1E,sEAAsE;QACtE,oCAAoC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,OAAyB,CAAC;YAC9B,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,aAAa,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,mCAAmC;gBACnC,OAAO;YACT,CAAC;YACD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAED,iBAAS,eAAe,CAAC"}
package/lib/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js CHANGED
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env node
2
-
3
- const { yargs, help, ...options } = require('./parseCommandLineOptions')();
4
-
5
- require('@gustavnikolaj/async-main-wrap')(require('./subfont'), {
6
- processError(err) {
7
- yargs.showHelp();
8
- if (err.name === 'UsageError') {
9
- // Avoid rendering a stack trace for the wrong usage errors
10
- err.customOutput = err.message;
11
- }
12
- return err;
13
- },
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const parseCommandLineOptions = require("./parseCommandLineOptions");
5
+ const asyncMainWrap = require("@gustavnikolaj/async-main-wrap");
6
+ const subfont = require("./subfont");
7
+ const { yargs, help: _help, ...options } = parseCommandLineOptions();
8
+ asyncMainWrap(subfont, {
9
+ processError(err) {
10
+ yargs.showHelp();
11
+ if (err.name === 'UsageError') {
12
+ err.customOutput = err.message;
13
+ }
14
+ return err;
15
+ },
14
16
  })(options, console);
17
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,qEAAsE;AACtE,gEAAiE;AACjE,qCAAsC;AAEtC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,uBAAuB,EAAE,CAAC;AAIrE,aAAa,CAAC,OAAO,EAAE;IACrB,YAAY,CAAC,GAA0B;QACrC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC9B,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function pageNeedsMathTable(text: string): boolean;
2
+ export declare function pageNeedsColorTables(text: string): boolean;
3
+ export declare function scriptsForText(text: string): string[];
4
+ //# sourceMappingURL=codepointMaps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codepointMaps.d.ts","sourceRoot":"","sources":["../src/codepointMaps.ts"],"names":[],"mappings":"AAgFA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAKD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAarD"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ // Codepoint range tables used to gate optional table dropping and to map
3
+ // codepoints to OpenType script tags. Ranges are deliberately a small
4
+ // hardcoded list, not a faithful transcription of every Unicode block —
5
+ // getting common cases right is enough; an unmapped codepoint just means
6
+ // we keep the table or skip the script.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.pageNeedsMathTable = pageNeedsMathTable;
9
+ exports.pageNeedsColorTables = pageNeedsColorTables;
10
+ exports.scriptsForText = scriptsForText;
11
+ const MATH_RANGES = [
12
+ { min: 0x2190, max: 0x21ff }, // Arrows (commonly used as math operators)
13
+ { min: 0x2200, max: 0x22ff }, // Mathematical Operators
14
+ { min: 0x27c0, max: 0x27ef }, // Misc Mathematical Symbols-A
15
+ { min: 0x2980, max: 0x29ff }, // Misc Mathematical Symbols-B
16
+ { min: 0x2a00, max: 0x2aff }, // Supplemental Mathematical Operators
17
+ { min: 0x1d400, max: 0x1d7ff }, // Mathematical Alphanumeric Symbols
18
+ ];
19
+ const EMOJI_RANGES = [
20
+ { min: 0x2600, max: 0x26ff }, // Misc Symbols (☀, ☂, ☎, …)
21
+ { min: 0x2700, max: 0x27bf }, // Dingbats
22
+ { min: 0x1f000, max: 0x1f02f }, // Mahjong Tiles
23
+ { min: 0x1f0a0, max: 0x1f0ff }, // Playing Cards
24
+ { min: 0x1f300, max: 0x1f5ff }, // Misc Symbols and Pictographs
25
+ { min: 0x1f600, max: 0x1f64f }, // Emoticons
26
+ { min: 0x1f680, max: 0x1f6ff }, // Transport and Map Symbols
27
+ { min: 0x1f700, max: 0x1f77f }, // Alchemical Symbols
28
+ { min: 0x1f900, max: 0x1f9ff }, // Supplemental Symbols and Pictographs
29
+ { min: 0x1fa70, max: 0x1faff }, // Symbols and Pictographs Extended-A
30
+ ];
31
+ // Latin ranges are intentionally omitted: scriptsForText() always seeds
32
+ // the result set with 'latn', so any Latin codepoint already counts.
33
+ const SCRIPT_RANGES = [
34
+ { min: 0x0370, max: 0x03ff, tag: 'grek' }, // Greek and Coptic
35
+ { min: 0x1f00, max: 0x1fff, tag: 'grek' }, // Greek Extended
36
+ { min: 0x0400, max: 0x052f, tag: 'cyrl' }, // Cyrillic + Supplement
37
+ { min: 0x2de0, max: 0x2dff, tag: 'cyrl' }, // Cyrillic Extended-A
38
+ { min: 0xa640, max: 0xa69f, tag: 'cyrl' }, // Cyrillic Extended-B
39
+ { min: 0x0590, max: 0x05ff, tag: 'hebr' }, // Hebrew
40
+ { min: 0x0600, max: 0x06ff, tag: 'arab' }, // Arabic
41
+ { min: 0x0750, max: 0x077f, tag: 'arab' }, // Arabic Supplement
42
+ { min: 0xfb50, max: 0xfdff, tag: 'arab' }, // Arabic Presentation Forms-A
43
+ { min: 0xfe70, max: 0xfeff, tag: 'arab' }, // Arabic Presentation Forms-B
44
+ { min: 0x0900, max: 0x097f, tag: 'deva' }, // Devanagari
45
+ { min: 0x0980, max: 0x09ff, tag: 'beng' }, // Bengali
46
+ { min: 0x0a00, max: 0x0a7f, tag: 'guru' }, // Gurmukhi (Punjabi)
47
+ { min: 0x0a80, max: 0x0aff, tag: 'gujr' }, // Gujarati
48
+ { min: 0x0b80, max: 0x0bff, tag: 'taml' }, // Tamil
49
+ { min: 0x0c00, max: 0x0c7f, tag: 'telu' }, // Telugu
50
+ { min: 0x0c80, max: 0x0cff, tag: 'knda' }, // Kannada
51
+ { min: 0x0d00, max: 0x0d7f, tag: 'mlym' }, // Malayalam
52
+ { min: 0x3040, max: 0x30ff, tag: 'kana' }, // Hiragana / Katakana
53
+ { min: 0x1100, max: 0x11ff, tag: 'hang' }, // Hangul Jamo
54
+ { min: 0x3130, max: 0x318f, tag: 'hang' }, // Hangul Compatibility Jamo
55
+ { min: 0xac00, max: 0xd7af, tag: 'hang' }, // Hangul Syllables
56
+ { min: 0x3400, max: 0x4dbf, tag: 'hani' }, // CJK Extension A
57
+ { min: 0x4e00, max: 0x9fff, tag: 'hani' }, // CJK Unified Ideographs
58
+ { min: 0xf900, max: 0xfaff, tag: 'hani' }, // CJK Compatibility Ideographs
59
+ { min: 0x20000, max: 0x2a6df, tag: 'hani' }, // CJK Extension B
60
+ ];
61
+ function inRange(cp, r) {
62
+ return cp >= r.min && cp <= r.max;
63
+ }
64
+ function textHitsRanges(text, ranges) {
65
+ for (const ch of text) {
66
+ const cp = ch.codePointAt(0);
67
+ if (cp === undefined)
68
+ continue;
69
+ for (const r of ranges)
70
+ if (inRange(cp, r))
71
+ return true;
72
+ }
73
+ return false;
74
+ }
75
+ function pageNeedsMathTable(text) {
76
+ return textHitsRanges(text, MATH_RANGES);
77
+ }
78
+ function pageNeedsColorTables(text) {
79
+ return textHitsRanges(text, EMOJI_RANGES);
80
+ }
81
+ // Returns the OpenType script tags exercised by `text`, plus the safety
82
+ // pair `DFLT` (default script) and `latn` (most fonts ship Latin fallback
83
+ // even when used for other scripts).
84
+ function scriptsForText(text) {
85
+ const tags = new Set(['DFLT', 'latn']);
86
+ for (const ch of text) {
87
+ const cp = ch.codePointAt(0);
88
+ if (cp === undefined)
89
+ continue;
90
+ for (const r of SCRIPT_RANGES) {
91
+ if (inRange(cp, r)) {
92
+ tags.add(r.tag);
93
+ break;
94
+ }
95
+ }
96
+ }
97
+ return [...tags];
98
+ }
99
+ //# sourceMappingURL=codepointMaps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codepointMaps.js","sourceRoot":"","sources":["../src/codepointMaps.ts"],"names":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,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,EAAE,KAAK,SAAS;YAAE,SAAS;QAC/B,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;YAC9B,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;gBACnB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBAChB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AACnB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare function collectFeatureGlyphIds(fontBuffer: Buffer | Uint8Array, text: string, cssFeatureTags: Iterable<string> | null | undefined): Promise<number[]>;
2
+ export = collectFeatureGlyphIds;
3
+ //# sourceMappingURL=collectFeatureGlyphIds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectFeatureGlyphIds.d.ts","sourceRoot":"","sources":["../src/collectFeatureGlyphIds.ts"],"names":[],"mappings":"AAiJA,iBAAS,sBAAsB,CAC7B,UAAU,EAAE,MAAM,GAAG,UAAU,EAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GAClD,OAAO,CAAC,MAAM,EAAE,CAAC,CAInB;AAED,SAAS,sBAAsB,CAAC"}