@nowline/export-core 0.2.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 +131 -0
- package/assets/fonts/DejaVuSans.ttf +0 -0
- package/assets/fonts/DejaVuSansMono.ttf +0 -0
- package/assets/fonts/LICENSE-DejaVu.txt +187 -0
- package/dist/ast-helpers.d.ts +16 -0
- package/dist/ast-helpers.d.ts.map +1 -0
- package/dist/ast-helpers.js +44 -0
- package/dist/ast-helpers.js.map +1 -0
- package/dist/fonts/bundled.d.ts +7 -0
- package/dist/fonts/bundled.d.ts.map +1 -0
- package/dist/fonts/bundled.js +52 -0
- package/dist/fonts/bundled.js.map +1 -0
- package/dist/fonts/index.d.ts +6 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +5 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/probe-list.d.ts +29 -0
- package/dist/fonts/probe-list.d.ts.map +1 -0
- package/dist/fonts/probe-list.js +119 -0
- package/dist/fonts/probe-list.js.map +1 -0
- package/dist/fonts/resolve.d.ts +35 -0
- package/dist/fonts/resolve.d.ts.map +1 -0
- package/dist/fonts/resolve.js +159 -0
- package/dist/fonts/resolve.js.map +1 -0
- package/dist/fonts/sfns.d.ts +6 -0
- package/dist/fonts/sfns.d.ts.map +1 -0
- package/dist/fonts/sfns.js +37 -0
- package/dist/fonts/sfns.js.map +1 -0
- package/dist/generated/bundled-fonts.d.ts +3 -0
- package/dist/generated/bundled-fonts.d.ts.map +1 -0
- package/dist/generated/bundled-fonts.js +9 -0
- package/dist/generated/bundled-fonts.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/pdf-page.d.ts +66 -0
- package/dist/pdf-page.d.ts.map +1 -0
- package/dist/pdf-page.js +170 -0
- package/dist/pdf-page.js.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +16 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +56 -0
- package/dist/units.js.map +1 -0
- package/package.json +50 -0
- package/src/ast-helpers.ts +47 -0
- package/src/fonts/bundled.ts +59 -0
- package/src/fonts/index.ts +18 -0
- package/src/fonts/probe-list.ts +143 -0
- package/src/fonts/resolve.ts +228 -0
- package/src/fonts/sfns.ts +34 -0
- package/src/generated/bundled-fonts.ts +10 -0
- package/src/index.ts +62 -0
- package/src/pdf-page.ts +224 -0
- package/src/types.ts +88 -0
- package/src/units.ts +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @nowline/export-core
|
|
2
|
+
|
|
3
|
+
Shared types, helpers, and font infrastructure used by every Nowline export
|
|
4
|
+
package. Intentionally small: zero heavy dependencies, browser-safe types,
|
|
5
|
+
and a single Node-only side (the platform font probe) that's lazy-loaded.
|
|
6
|
+
|
|
7
|
+
**License:** Apache 2.0
|
|
8
|
+
**Part of:** [`lolay/nowline`](../../) monorepo
|
|
9
|
+
**Spec:** [`specs/handoffs/m2c.md`](../../specs/handoffs/m2c.md) § 1, § 10
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @nowline/export-core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@nowline/export-core` is a peer of every `@nowline/export-*` package —
|
|
18
|
+
install it once and the format packages will use the same types and font
|
|
19
|
+
resolution as the CLI.
|
|
20
|
+
|
|
21
|
+
## What lives here
|
|
22
|
+
|
|
23
|
+
### Shared types
|
|
24
|
+
|
|
25
|
+
- `ExportInputs` — the bundle every format exporter consumes: parsed AST,
|
|
26
|
+
resolved-include result, positioned model, source path, and `today`. This
|
|
27
|
+
is the single shape `cli/src/commands/render.ts` builds once and hands to
|
|
28
|
+
each `export*()` function.
|
|
29
|
+
- `PdfPageSize`, `PdfPresetName`, `PdfOrientation`, `PdfLength`,
|
|
30
|
+
`PdfLengthUnit` — used by both `@nowline/export-pdf` and the CLI argument
|
|
31
|
+
parser.
|
|
32
|
+
- `FontSource`, `FontRole`, `ResolvedFont`, `ResolvedFontPair` — see
|
|
33
|
+
*Font resolution* below.
|
|
34
|
+
|
|
35
|
+
### Unit conversion
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { parseLength, lengthToPoints } from '@nowline/export-core';
|
|
39
|
+
|
|
40
|
+
parseLength('0.5in'); // { value: 0.5, unit: 'in' }
|
|
41
|
+
lengthToPoints({ value: 0.5, unit: 'in' }); // 36
|
|
42
|
+
lengthToPoints({ value: 12, unit: 'pt' }); // 12
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Supported units: `pt`, `in`, `mm`, `cm`. Bare numbers parse as points.
|
|
46
|
+
|
|
47
|
+
### PDF page sizing
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { parsePageSize, resolvePage, fitContent } from '@nowline/export-core';
|
|
51
|
+
|
|
52
|
+
parsePageSize('letter'); // { kind: 'preset', name: 'letter' }
|
|
53
|
+
parsePageSize('8.5x11in'); // { kind: 'custom', wPt: 612, hPt: 792 }
|
|
54
|
+
parsePageSize('content'); // { kind: 'content' }
|
|
55
|
+
|
|
56
|
+
const page = resolvePage(pageSize, orientation, marginPt, contentBox);
|
|
57
|
+
const scale = fitContent(page, contentBox);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`resolvePage()` flips dimensions when `orientation: 'auto'` chooses
|
|
61
|
+
landscape over portrait based on the model's aspect ratio. `fitContent()`
|
|
62
|
+
returns the scale factor that fits the content inside `(page − 2 ×
|
|
63
|
+
margin)` without exceeding 1:1 (a small roadmap doesn't bloat to fill the
|
|
64
|
+
page).
|
|
65
|
+
|
|
66
|
+
### Font resolution
|
|
67
|
+
|
|
68
|
+
`resolveFonts()` is the single entry point for picking a sans/mono pair for
|
|
69
|
+
a render. The five-step precedence chain is documented in
|
|
70
|
+
`specs/handoffs/m2c.md` § 10:
|
|
71
|
+
|
|
72
|
+
1. **Explicit flag** — `fontSans: '/path/to/Foo.ttf'` (or alias `'sf'`,
|
|
73
|
+
`'helvetica'`, `'dejavu'`).
|
|
74
|
+
2. **Environment** — `NOWLINE_FONT_SANS`, `NOWLINE_FONT_MONO`.
|
|
75
|
+
3. **Headless** — `headless: true` skips the platform probe and uses the
|
|
76
|
+
bundled DejaVu pair. Also automatically selected when running inside a
|
|
77
|
+
container with no fontconfig.
|
|
78
|
+
4. **Platform probe** — macOS: SF Pro → Helvetica → Geneva. Windows:
|
|
79
|
+
Segoe UI → Arial → Tahoma. Linux: DejaVu Sans (Debian, Fedora, Arch
|
|
80
|
+
paths) → Liberation Sans → bundled DejaVu fallback.
|
|
81
|
+
5. **Bundled** — DejaVu Sans + DejaVu Sans Mono ship with this package.
|
|
82
|
+
Always succeeds; ensures the resolver is total.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { resolveFonts } from '@nowline/export-core';
|
|
86
|
+
|
|
87
|
+
const result = await resolveFonts({
|
|
88
|
+
fontSans: undefined, // null/undefined = use precedence chain
|
|
89
|
+
fontMono: undefined,
|
|
90
|
+
headless: false,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
result.sans; // { source: 'probe', name: 'SF Pro', bytes: Uint8Array(...) }
|
|
94
|
+
result.mono; // { source: 'probe', name: 'SF Mono', bytes: Uint8Array(...) }
|
|
95
|
+
result.sansFellBackToBundled; // boolean — true if step 5 fired
|
|
96
|
+
result.monoFellBackToBundled;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Variable fonts (e.g., SF Pro on macOS Ventura+) are detected by inspecting
|
|
100
|
+
the OpenType `fvar` table and instanced at `wght: 400` to produce
|
|
101
|
+
deterministic, single-instance bytes — `fontkit` is *not* a runtime
|
|
102
|
+
dependency.
|
|
103
|
+
|
|
104
|
+
### Bundled font assets
|
|
105
|
+
|
|
106
|
+
DejaVu Sans (`assets/fonts/DejaVuSans.ttf`) and DejaVu Sans Mono
|
|
107
|
+
(`assets/fonts/DejaVuSansMono.ttf`) ship with this package. They're used as
|
|
108
|
+
the always-available fallback in step 5 of the resolver.
|
|
109
|
+
|
|
110
|
+
The DejaVu license (Bitstream Vera + public-domain additions) is
|
|
111
|
+
`assets/fonts/LICENSE-DejaVu.txt`. It is MIT-compatible; redistribution is
|
|
112
|
+
permitted with notice retained in the package files. SF Pro / SF Mono are
|
|
113
|
+
*not* shipped — they're picked up at render time on macOS only and embedded
|
|
114
|
+
into the output (PDF subset, PNG raster). See
|
|
115
|
+
`specs/handoffs/m2c.md` § 10 for the full font licensing notes.
|
|
116
|
+
|
|
117
|
+
## Determinism
|
|
118
|
+
|
|
119
|
+
Every helper in this package is deterministic given identical inputs:
|
|
120
|
+
|
|
121
|
+
- `parsePageSize`, `parseLength`, `resolvePage`, `fitContent`, `validateMargin`
|
|
122
|
+
are pure functions of their arguments.
|
|
123
|
+
- `resolveFonts` returns byte-identical font bytes across calls (variable
|
|
124
|
+
fonts are instanced before being returned).
|
|
125
|
+
- The bundled DejaVu cache is process-global; `clearBundledCache()` resets
|
|
126
|
+
it for tests.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
Apache-2.0. Shipped with bundled DejaVu fonts (Bitstream Vera license,
|
|
131
|
+
`assets/fonts/LICENSE-DejaVu.txt`).
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
|
|
2
|
+
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Bitstream Vera Fonts Copyright
|
|
6
|
+
------------------------------
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
|
|
9
|
+
a trademark of Bitstream, Inc.
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of the fonts accompanying this license ("Fonts") and associated
|
|
13
|
+
documentation files (the "Font Software"), to reproduce and distribute the
|
|
14
|
+
Font Software, including without limitation the rights to use, copy, merge,
|
|
15
|
+
publish, distribute, and/or sell copies of the Font Software, and to permit
|
|
16
|
+
persons to whom the Font Software is furnished to do so, subject to the
|
|
17
|
+
following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright and trademark notices and this permission notice shall
|
|
20
|
+
be included in all copies of one or more of the Font Software typefaces.
|
|
21
|
+
|
|
22
|
+
The Font Software may be modified, altered, or added to, and in particular
|
|
23
|
+
the designs of glyphs or characters in the Fonts may be modified and
|
|
24
|
+
additional glyphs or characters may be added to the Fonts, only if the fonts
|
|
25
|
+
are renamed to names not containing either the words "Bitstream" or the word
|
|
26
|
+
"Vera".
|
|
27
|
+
|
|
28
|
+
This License becomes null and void to the extent applicable to Fonts or Font
|
|
29
|
+
Software that has been modified and is distributed under the "Bitstream
|
|
30
|
+
Vera" names.
|
|
31
|
+
|
|
32
|
+
The Font Software may be sold as part of a larger software package but no
|
|
33
|
+
copy of one or more of the Font Software typefaces may be sold by itself.
|
|
34
|
+
|
|
35
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
36
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
|
38
|
+
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
|
39
|
+
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
|
|
40
|
+
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
|
41
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
|
42
|
+
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
|
|
43
|
+
FONT SOFTWARE.
|
|
44
|
+
|
|
45
|
+
Except as contained in this notice, the names of Gnome, the Gnome
|
|
46
|
+
Foundation, and Bitstream Inc., shall not be used in advertising or
|
|
47
|
+
otherwise to promote the sale, use or other dealings in this Font Software
|
|
48
|
+
without prior written authorization from the Gnome Foundation or Bitstream
|
|
49
|
+
Inc., respectively. For further information, contact: fonts at gnome dot
|
|
50
|
+
org.
|
|
51
|
+
|
|
52
|
+
Arev Fonts Copyright
|
|
53
|
+
------------------------------
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
|
|
56
|
+
|
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
58
|
+
a copy of the fonts accompanying this license ("Fonts") and
|
|
59
|
+
associated documentation files (the "Font Software"), to reproduce
|
|
60
|
+
and distribute the modifications to the Bitstream Vera Font Software,
|
|
61
|
+
including without limitation the rights to use, copy, merge, publish,
|
|
62
|
+
distribute, and/or sell copies of the Font Software, and to permit
|
|
63
|
+
persons to whom the Font Software is furnished to do so, subject to
|
|
64
|
+
the following conditions:
|
|
65
|
+
|
|
66
|
+
The above copyright and trademark notices and this permission notice
|
|
67
|
+
shall be included in all copies of one or more of the Font Software
|
|
68
|
+
typefaces.
|
|
69
|
+
|
|
70
|
+
The Font Software may be modified, altered, or added to, and in
|
|
71
|
+
particular the designs of glyphs or characters in the Fonts may be
|
|
72
|
+
modified and additional glyphs or characters may be added to the
|
|
73
|
+
Fonts, only if the fonts are renamed to names not containing either
|
|
74
|
+
the words "Tavmjong Bah" or the word "Arev".
|
|
75
|
+
|
|
76
|
+
This License becomes null and void to the extent applicable to Fonts
|
|
77
|
+
or Font Software that has been modified and is distributed under the
|
|
78
|
+
"Tavmjong Bah Arev" names.
|
|
79
|
+
|
|
80
|
+
The Font Software may be sold as part of a larger software package but
|
|
81
|
+
no copy of one or more of the Font Software typefaces may be sold by
|
|
82
|
+
itself.
|
|
83
|
+
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
|
|
88
|
+
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
93
|
+
|
|
94
|
+
Except as contained in this notice, the name of Tavmjong Bah shall not
|
|
95
|
+
be used in advertising or otherwise to promote the sale, use or other
|
|
96
|
+
dealings in this Font Software without prior written authorization
|
|
97
|
+
from Tavmjong Bah. For further information, contact: tavmjong @ free
|
|
98
|
+
. fr.
|
|
99
|
+
|
|
100
|
+
TeX Gyre DJV Math
|
|
101
|
+
-----------------
|
|
102
|
+
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
|
|
103
|
+
|
|
104
|
+
Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
|
|
105
|
+
(on behalf of TeX users groups) are in public domain.
|
|
106
|
+
|
|
107
|
+
Letters imported from Euler Fraktur from AMSfonts are (c) American
|
|
108
|
+
Mathematical Society (see below).
|
|
109
|
+
Bitstream Vera Fonts Copyright
|
|
110
|
+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
|
|
111
|
+
is a trademark of Bitstream, Inc.
|
|
112
|
+
|
|
113
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
114
|
+
of the fonts accompanying this license (“Fonts”) and associated
|
|
115
|
+
documentation
|
|
116
|
+
files (the “Font Software”), to reproduce and distribute the Font Software,
|
|
117
|
+
including without limitation the rights to use, copy, merge, publish,
|
|
118
|
+
distribute,
|
|
119
|
+
and/or sell copies of the Font Software, and to permit persons to whom
|
|
120
|
+
the Font Software is furnished to do so, subject to the following
|
|
121
|
+
conditions:
|
|
122
|
+
|
|
123
|
+
The above copyright and trademark notices and this permission notice
|
|
124
|
+
shall be
|
|
125
|
+
included in all copies of one or more of the Font Software typefaces.
|
|
126
|
+
|
|
127
|
+
The Font Software may be modified, altered, or added to, and in particular
|
|
128
|
+
the designs of glyphs or characters in the Fonts may be modified and
|
|
129
|
+
additional
|
|
130
|
+
glyphs or characters may be added to the Fonts, only if the fonts are
|
|
131
|
+
renamed
|
|
132
|
+
to names not containing either the words “Bitstream” or the word “Vera”.
|
|
133
|
+
|
|
134
|
+
This License becomes null and void to the extent applicable to Fonts or
|
|
135
|
+
Font Software
|
|
136
|
+
that has been modified and is distributed under the “Bitstream Vera”
|
|
137
|
+
names.
|
|
138
|
+
|
|
139
|
+
The Font Software may be sold as part of a larger software package but
|
|
140
|
+
no copy
|
|
141
|
+
of one or more of the Font Software typefaces may be sold by itself.
|
|
142
|
+
|
|
143
|
+
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
144
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
|
145
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
|
146
|
+
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
|
147
|
+
FOUNDATION
|
|
148
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
|
|
149
|
+
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
|
|
150
|
+
ACTION
|
|
151
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
|
|
152
|
+
INABILITY TO USE
|
|
153
|
+
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
154
|
+
Except as contained in this notice, the names of GNOME, the GNOME
|
|
155
|
+
Foundation,
|
|
156
|
+
and Bitstream Inc., shall not be used in advertising or otherwise to promote
|
|
157
|
+
the sale, use or other dealings in this Font Software without prior written
|
|
158
|
+
authorization from the GNOME Foundation or Bitstream Inc., respectively.
|
|
159
|
+
For further information, contact: fonts at gnome dot org.
|
|
160
|
+
|
|
161
|
+
AMSFonts (v. 2.2) copyright
|
|
162
|
+
|
|
163
|
+
The PostScript Type 1 implementation of the AMSFonts produced by and
|
|
164
|
+
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
|
|
165
|
+
available for general use. This has been accomplished through the
|
|
166
|
+
cooperation
|
|
167
|
+
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
|
|
168
|
+
Members of this consortium include:
|
|
169
|
+
|
|
170
|
+
Elsevier Science IBM Corporation Society for Industrial and Applied
|
|
171
|
+
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
|
|
172
|
+
|
|
173
|
+
In order to assure the authenticity of these fonts, copyright will be
|
|
174
|
+
held by
|
|
175
|
+
the American Mathematical Society. This is not meant to restrict in any way
|
|
176
|
+
the legitimate use of the fonts, such as (but not limited to) electronic
|
|
177
|
+
distribution of documents containing these fonts, inclusion of these fonts
|
|
178
|
+
into other public domain or commercial font collections or computer
|
|
179
|
+
applications, use of the outline data to create derivative fonts and/or
|
|
180
|
+
faces, etc. However, the AMS does require that the AMS copyright notice be
|
|
181
|
+
removed from any derivative versions of the fonts which have been altered in
|
|
182
|
+
any way. In addition, to ensure the fidelity of TeX documents using Computer
|
|
183
|
+
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
|
|
184
|
+
has requested that any alterations which yield different font metrics be
|
|
185
|
+
given a different name.
|
|
186
|
+
|
|
187
|
+
$Id$
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EntityProperty, RoadmapDeclaration } from '@nowline/core';
|
|
2
|
+
export type PropertyHost = {
|
|
3
|
+
properties?: EntityProperty[];
|
|
4
|
+
title?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
};
|
|
7
|
+
/** Return the single-value `value` for `key`, or undefined. */
|
|
8
|
+
export declare function getProp(host: PropertyHost, key: string): string | undefined;
|
|
9
|
+
/** Return the multi-value list for `key` (e.g. `after:[a, b]`), or empty. */
|
|
10
|
+
export declare function getProps(host: PropertyHost, key: string): readonly string[];
|
|
11
|
+
export declare function hasProp(host: PropertyHost, key: string): boolean;
|
|
12
|
+
/** Display label: title if present, otherwise name (id), otherwise '<unnamed>'. */
|
|
13
|
+
export declare function displayLabel(host: PropertyHost): string;
|
|
14
|
+
/** Roadmap title falls back to declaration name. */
|
|
15
|
+
export declare function roadmapTitle(decl: RoadmapDeclaration | undefined): string;
|
|
16
|
+
//# sourceMappingURL=ast-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-helpers.d.ts","sourceRoot":"","sources":["../src/ast-helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,MAAM,YAAY,GAAG;IACvB,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM3E;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAM3E;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAIvD;AAED,oDAAoD;AACpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB,GAAG,SAAS,GAAG,MAAM,CAGzE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Tiny AST property helpers shared by lossy exporters (Mermaid, MS Project,
|
|
2
|
+
// XLSX). The Langium-generated AST stores DSL properties as
|
|
3
|
+
// `EntityProperty[]` with `{ key, value?, values[] }`. Walking that shape
|
|
4
|
+
// directly is verbose; these helpers keep the exporters readable.
|
|
5
|
+
/** Return the single-value `value` for `key`, or undefined. */
|
|
6
|
+
export function getProp(host, key) {
|
|
7
|
+
const prop = host.properties?.find((p) => p.key === key);
|
|
8
|
+
if (!prop)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (prop.value !== undefined)
|
|
11
|
+
return prop.value;
|
|
12
|
+
if (prop.values && prop.values.length > 0)
|
|
13
|
+
return prop.values[0];
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Return the multi-value list for `key` (e.g. `after:[a, b]`), or empty. */
|
|
17
|
+
export function getProps(host, key) {
|
|
18
|
+
const prop = host.properties?.find((p) => p.key === key);
|
|
19
|
+
if (!prop)
|
|
20
|
+
return [];
|
|
21
|
+
if (prop.values && prop.values.length > 0)
|
|
22
|
+
return prop.values;
|
|
23
|
+
if (prop.value !== undefined)
|
|
24
|
+
return [prop.value];
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
export function hasProp(host, key) {
|
|
28
|
+
return host.properties?.some((p) => p.key === key) ?? false;
|
|
29
|
+
}
|
|
30
|
+
/** Display label: title if present, otherwise name (id), otherwise '<unnamed>'. */
|
|
31
|
+
export function displayLabel(host) {
|
|
32
|
+
if (host.title?.trim())
|
|
33
|
+
return host.title;
|
|
34
|
+
if (host.name?.trim())
|
|
35
|
+
return host.name;
|
|
36
|
+
return '<unnamed>';
|
|
37
|
+
}
|
|
38
|
+
/** Roadmap title falls back to declaration name. */
|
|
39
|
+
export function roadmapTitle(decl) {
|
|
40
|
+
if (!decl)
|
|
41
|
+
return 'Roadmap';
|
|
42
|
+
return decl.title?.trim() || decl.name?.trim() || 'Roadmap';
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ast-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["../src/ast-helpers.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4DAA4D;AAC5D,0EAA0E;AAC1E,kEAAkE;AAUlE,+DAA+D;AAC/D,MAAM,UAAU,OAAO,CAAC,IAAkB,EAAE,GAAW;IACnD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjE,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,QAAQ,CAAC,IAAkB,EAAE,GAAW;IACpD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC;IAC9D,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAkB,EAAE,GAAW;IACnD,OAAO,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC;AAChE,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,IAAkB;IAC3C,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IAC1C,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC;IACxC,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,YAAY,CAAC,IAAoC;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const BUNDLED_SANS_PATH: string;
|
|
2
|
+
export declare const BUNDLED_MONO_PATH: string;
|
|
3
|
+
export declare function loadBundledSans(): Promise<Uint8Array>;
|
|
4
|
+
export declare function loadBundledMono(): Promise<Uint8Array>;
|
|
5
|
+
/** Test seam: drop cached bytes so platform-mocked tests start fresh. */
|
|
6
|
+
export declare function clearBundledCache(): void;
|
|
7
|
+
//# sourceMappingURL=bundled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled.d.ts","sourceRoot":"","sources":["../../src/fonts/bundled.ts"],"names":[],"mappings":"AA+BA,eAAO,MAAM,iBAAiB,QAA0C,CAAC;AACzE,eAAO,MAAM,iBAAiB,QAA8C,CAAC;AAU7E,wBAAsB,eAAe,IAAI,OAAO,CAAC,UAAU,CAAC,CAI3D;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,UAAU,CAAC,CAI3D;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Bundled-fallback font loader.
|
|
2
|
+
//
|
|
3
|
+
// Spec: specs/handoffs/m2c.md § 10 "Bundled fallback".
|
|
4
|
+
//
|
|
5
|
+
// Ships exactly two TTFs under `assets/fonts/`: DejaVuSans.ttf (~740 KB) and
|
|
6
|
+
// DejaVuSansMono.ttf (~330 KB). Bold / italic are synthesized by PDFKit's
|
|
7
|
+
// faux-bold and skew transforms. License: see LICENSE-DejaVu.txt next to the
|
|
8
|
+
// fonts.
|
|
9
|
+
//
|
|
10
|
+
// The TTF bytes are embedded as base64 string literals via
|
|
11
|
+
// `scripts/bundle-fonts.mjs` (run as `prebuild` / `pretest`) so the loader
|
|
12
|
+
// works under both Node and a bun --compile binary. `bun --compile` does not
|
|
13
|
+
// virtualize fs.readFile of import.meta.url paths, so the on-disk asset is
|
|
14
|
+
// invisible inside the compiled binary; the embedded strings are the
|
|
15
|
+
// runtime source of truth.
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { MONO_BASE64, SANS_BASE64 } from '../generated/bundled-fonts.js';
|
|
19
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
// dist/fonts/bundled.js → ../../assets/fonts/
|
|
21
|
+
// src/fonts/bundled.ts → ../../assets/fonts/
|
|
22
|
+
const ASSETS_DIR = path.resolve(HERE, '..', '..', 'assets', 'fonts');
|
|
23
|
+
// Informational: where the source-of-truth TTFs live on disk for users
|
|
24
|
+
// running under Node. Not the runtime load source — `loadBundledSans` and
|
|
25
|
+
// `loadBundledMono` decode from the embedded base64 instead. Inside a bun
|
|
26
|
+
// --compile binary these paths are phantom (the assets are not on disk).
|
|
27
|
+
export const BUNDLED_SANS_PATH = path.join(ASSETS_DIR, 'DejaVuSans.ttf');
|
|
28
|
+
export const BUNDLED_MONO_PATH = path.join(ASSETS_DIR, 'DejaVuSansMono.ttf');
|
|
29
|
+
let cachedSans;
|
|
30
|
+
let cachedMono;
|
|
31
|
+
function decodeBase64(b64) {
|
|
32
|
+
const buf = Buffer.from(b64, 'base64');
|
|
33
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
34
|
+
}
|
|
35
|
+
export async function loadBundledSans() {
|
|
36
|
+
if (cachedSans)
|
|
37
|
+
return cachedSans;
|
|
38
|
+
cachedSans = decodeBase64(SANS_BASE64);
|
|
39
|
+
return cachedSans;
|
|
40
|
+
}
|
|
41
|
+
export async function loadBundledMono() {
|
|
42
|
+
if (cachedMono)
|
|
43
|
+
return cachedMono;
|
|
44
|
+
cachedMono = decodeBase64(MONO_BASE64);
|
|
45
|
+
return cachedMono;
|
|
46
|
+
}
|
|
47
|
+
/** Test seam: drop cached bytes so platform-mocked tests start fresh. */
|
|
48
|
+
export function clearBundledCache() {
|
|
49
|
+
cachedSans = undefined;
|
|
50
|
+
cachedMono = undefined;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=bundled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled.js","sourceRoot":"","sources":["../../src/fonts/bundled.ts"],"names":[],"mappings":"AAAA,gCAA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AU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IACvC,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe;IACjC,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAClC,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IACvC,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB;IAC7B,UAAU,GAAG,SAAS,CAAC;IACvB,UAAU,GAAG,SAAS,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BUNDLED_MONO_PATH, BUNDLED_SANS_PATH, clearBundledCache, loadBundledMono, loadBundledSans, } from './bundled.js';
|
|
2
|
+
export { ALIASES, aliasCandidate, type FontCandidate, isAlias, type PlatformProbe, probeListFor, } from './probe-list.js';
|
|
3
|
+
export type { ResolveOptions, ResolveResult } from './resolve.js';
|
|
4
|
+
export { FontResolveError, resolveFonts } from './resolve.js';
|
|
5
|
+
export { isVariableFontBytes } from './sfns.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,OAAO,EACP,cAAc,EACd,KAAK,aAAa,EAClB,OAAO,EACP,KAAK,aAAa,EAClB,YAAY,GACf,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BUNDLED_MONO_PATH, BUNDLED_SANS_PATH, clearBundledCache, loadBundledMono, loadBundledSans, } from './bundled.js';
|
|
2
|
+
export { ALIASES, aliasCandidate, isAlias, probeListFor, } from './probe-list.js';
|
|
3
|
+
export { FontResolveError, resolveFonts } from './resolve.js';
|
|
4
|
+
export { isVariableFontBytes } from './sfns.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,OAAO,EACP,cAAc,EAEd,OAAO,EAEP,YAAY,GACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface FontCandidate {
|
|
2
|
+
path: string;
|
|
3
|
+
face?: string;
|
|
4
|
+
/** Friendly family name surfaced in `ResolvedFont.name`. */
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PlatformProbe {
|
|
8
|
+
sans: readonly FontCandidate[];
|
|
9
|
+
mono: readonly FontCandidate[];
|
|
10
|
+
}
|
|
11
|
+
export declare function probeListFor(platform: NodeJS.Platform, env?: NodeJS.ProcessEnv): PlatformProbe;
|
|
12
|
+
/**
|
|
13
|
+
* Aliases for `--font-sans` / `--font-mono`. Resolves to the platform-default
|
|
14
|
+
* candidate for that family. `dejavu` always resolves to the bundled fallback
|
|
15
|
+
* regardless of platform — handled in resolver.ts.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ALIASES: Readonly<Record<string, {
|
|
18
|
+
sans?: string;
|
|
19
|
+
mono?: string;
|
|
20
|
+
}>>;
|
|
21
|
+
export declare function isAlias(value: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Look up the candidate corresponding to an alias for the given role.
|
|
24
|
+
*
|
|
25
|
+
* Returns `undefined` if the alias doesn't have an entry for that role
|
|
26
|
+
* (e.g. `--font-sans menlo` makes no sense — menlo is a mono family).
|
|
27
|
+
*/
|
|
28
|
+
export declare function aliasCandidate(alias: string, role: 'sans' | 'mono', probe: PlatformProbe): FontCandidate | undefined;
|
|
29
|
+
//# sourceMappingURL=probe-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe-list.d.ts","sourceRoot":"","sources":["../../src/fonts/probe-list.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,SAAS,aAAa,EAAE,CAAC;IAC/B,IAAI,EAAE,SAAS,aAAa,EAAE,CAAC;CAClC;AA8DD,wBAAgB,YAAY,CACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACrC,aAAa,CAOf;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB9E,CAAC;AAEF,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,KAAK,EAAE,aAAa,GACrB,aAAa,GAAG,SAAS,CAO3B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Per-platform candidate-font tables walked by `resolveFonts()`.
|
|
2
|
+
//
|
|
3
|
+
// Spec: specs/handoffs/m2c.md § 10 "Platform probe list".
|
|
4
|
+
//
|
|
5
|
+
// `path` segments use forward slashes; the resolver normalizes via
|
|
6
|
+
// `path.normalize()` at lookup time so Windows paths work correctly.
|
|
7
|
+
// `face` is set for `.ttc` collections — the resolver loads the TTC and
|
|
8
|
+
// hands the face PostScript name to PDFKit / resvg via `ResolvedFont.face`.
|
|
9
|
+
// Use platform-specific path joiners so Windows paths render with backslashes
|
|
10
|
+
// even when the resolver runs on a non-Windows host (e.g. test mocks on macOS
|
|
11
|
+
// CI exercising the win32 probe list).
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
const MACOS = {
|
|
14
|
+
sans: [
|
|
15
|
+
{ path: '/System/Library/Fonts/SFNS.ttf', name: 'SF Pro' },
|
|
16
|
+
{ path: '/System/Library/Fonts/Helvetica.ttc', face: 'Helvetica', name: 'Helvetica' },
|
|
17
|
+
{ path: '/System/Library/Fonts/Supplemental/Arial.ttf', name: 'Arial' },
|
|
18
|
+
],
|
|
19
|
+
mono: [
|
|
20
|
+
{ path: '/System/Library/Fonts/SFNSMono.ttf', name: 'SF Mono' },
|
|
21
|
+
{ path: '/System/Library/Fonts/Menlo.ttc', face: 'Menlo-Regular', name: 'Menlo' },
|
|
22
|
+
{ path: '/System/Library/Fonts/Monaco.ttf', name: 'Monaco' },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
function windowsCandidate(fontsDir, file, name) {
|
|
26
|
+
return { path: path.win32.join(fontsDir, file), name };
|
|
27
|
+
}
|
|
28
|
+
function windowsProbe(fontsDir) {
|
|
29
|
+
return {
|
|
30
|
+
sans: [
|
|
31
|
+
windowsCandidate(fontsDir, 'segoeui.ttf', 'Segoe UI'),
|
|
32
|
+
windowsCandidate(fontsDir, 'arial.ttf', 'Arial'),
|
|
33
|
+
windowsCandidate(fontsDir, 'tahoma.ttf', 'Tahoma'),
|
|
34
|
+
windowsCandidate(fontsDir, 'verdana.ttf', 'Verdana'),
|
|
35
|
+
],
|
|
36
|
+
mono: [
|
|
37
|
+
windowsCandidate(fontsDir, 'consola.ttf', 'Consolas'),
|
|
38
|
+
windowsCandidate(fontsDir, 'cour.ttf', 'Courier New'),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const LINUX = {
|
|
43
|
+
sans: [
|
|
44
|
+
{ path: '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', name: 'DejaVu Sans' },
|
|
45
|
+
{ path: '/usr/share/fonts/dejavu/DejaVuSans.ttf', name: 'DejaVu Sans' },
|
|
46
|
+
{ path: '/usr/share/fonts/TTF/DejaVuSans.ttf', name: 'DejaVu Sans' },
|
|
47
|
+
{ path: '/usr/share/fonts/liberation/LiberationSans-Regular.ttf', name: 'Liberation Sans' },
|
|
48
|
+
{
|
|
49
|
+
path: '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf',
|
|
50
|
+
name: 'Liberation Sans',
|
|
51
|
+
},
|
|
52
|
+
{ path: '/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf', name: 'Noto Sans' },
|
|
53
|
+
{ path: '/usr/share/fonts/ubuntu/Ubuntu-R.ttf', name: 'Ubuntu' },
|
|
54
|
+
{ path: '/usr/share/fonts/cantarell/Cantarell-Regular.otf', name: 'Cantarell' },
|
|
55
|
+
],
|
|
56
|
+
mono: [
|
|
57
|
+
{ path: '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', name: 'DejaVu Sans Mono' },
|
|
58
|
+
{ path: '/usr/share/fonts/dejavu/DejaVuSansMono.ttf', name: 'DejaVu Sans Mono' },
|
|
59
|
+
{ path: '/usr/share/fonts/TTF/DejaVuSansMono.ttf', name: 'DejaVu Sans Mono' },
|
|
60
|
+
{ path: '/usr/share/fonts/liberation/LiberationMono-Regular.ttf', name: 'Liberation Mono' },
|
|
61
|
+
{
|
|
62
|
+
path: '/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf',
|
|
63
|
+
name: 'Liberation Mono',
|
|
64
|
+
},
|
|
65
|
+
{ path: '/usr/share/fonts/ubuntu/UbuntuMono-R.ttf', name: 'Ubuntu Mono' },
|
|
66
|
+
{ path: '/usr/share/fonts/truetype/noto/NotoSansMono-Regular.ttf', name: 'Noto Sans Mono' },
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
export function probeListFor(platform, env = process.env) {
|
|
70
|
+
if (platform === 'darwin')
|
|
71
|
+
return MACOS;
|
|
72
|
+
if (platform === 'win32') {
|
|
73
|
+
const fontsDir = path.win32.join(env.WINDIR ?? 'C:\\Windows', 'Fonts');
|
|
74
|
+
return windowsProbe(fontsDir);
|
|
75
|
+
}
|
|
76
|
+
return LINUX;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Aliases for `--font-sans` / `--font-mono`. Resolves to the platform-default
|
|
80
|
+
* candidate for that family. `dejavu` always resolves to the bundled fallback
|
|
81
|
+
* regardless of platform — handled in resolver.ts.
|
|
82
|
+
*/
|
|
83
|
+
export const ALIASES = {
|
|
84
|
+
sf: { sans: 'SF Pro', mono: 'SF Mono' },
|
|
85
|
+
segoe: { sans: 'Segoe UI', mono: 'Consolas' },
|
|
86
|
+
dejavu: { sans: 'DejaVu Sans', mono: 'DejaVu Sans Mono' },
|
|
87
|
+
helvetica: { sans: 'Helvetica' },
|
|
88
|
+
arial: { sans: 'Arial' },
|
|
89
|
+
tahoma: { sans: 'Tahoma' },
|
|
90
|
+
verdana: { sans: 'Verdana' },
|
|
91
|
+
liberation: { sans: 'Liberation Sans', mono: 'Liberation Mono' },
|
|
92
|
+
noto: { sans: 'Noto Sans', mono: 'Noto Sans Mono' },
|
|
93
|
+
ubuntu: { sans: 'Ubuntu', mono: 'Ubuntu Mono' },
|
|
94
|
+
cantarell: { sans: 'Cantarell' },
|
|
95
|
+
menlo: { mono: 'Menlo' },
|
|
96
|
+
consolas: { mono: 'Consolas' },
|
|
97
|
+
monaco: { mono: 'Monaco' },
|
|
98
|
+
courier: { mono: 'Courier New' },
|
|
99
|
+
};
|
|
100
|
+
export function isAlias(value) {
|
|
101
|
+
return Object.hasOwn(ALIASES, value.toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Look up the candidate corresponding to an alias for the given role.
|
|
105
|
+
*
|
|
106
|
+
* Returns `undefined` if the alias doesn't have an entry for that role
|
|
107
|
+
* (e.g. `--font-sans menlo` makes no sense — menlo is a mono family).
|
|
108
|
+
*/
|
|
109
|
+
export function aliasCandidate(alias, role, probe) {
|
|
110
|
+
const entry = ALIASES[alias.toLowerCase()];
|
|
111
|
+
if (!entry)
|
|
112
|
+
return undefined;
|
|
113
|
+
const target = entry[role];
|
|
114
|
+
if (!target)
|
|
115
|
+
return undefined;
|
|
116
|
+
const list = probe[role];
|
|
117
|
+
return list.find((c) => c.name === target);
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=probe-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe-list.js","sourceRoot":"","sources":["../../src/fonts/probe-list.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,0DAA0D;AAC1D,EAAE;AACF,mEAAmE;AACnE,qEAAqE;AACrE,wEAAwE;AACxE,4EAA4E;AAE5E,8EAA8E;AAC9E,8EAA8E;AAC9E,uCAAuC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,MAAM,KAAK,GAAkB;IACzB,IAAI,EAAE;QACF,EAAE,IAAI,EAAE,gCAAgC,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1D,EAAE,IAAI,EAAE,qCAAqC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE;QACrF,EAAE,IAAI,EAAE,8CAA8C,EAAE,IAAI,EAAE,OAAO,EAAE;KAC1E;IACD,IAAI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