@stll/folio-core 0.66.0 → 0.66.1

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.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The document fonts folio bundles: one table for every place that names them.
3
+ *
4
+ * `@stll/folio-fonts` ships the files, and its generator
5
+ * (`scripts/generate-folio-fonts.ts`) reads this table to decide which files
6
+ * to copy and which `@font-face` rules to write, so the published package and
7
+ * the resolver here cannot disagree about a family. The module imports nothing:
8
+ * the generator, the resolver and the editor's availability check all read it
9
+ * without pulling in the rest of the engine.
10
+ */
11
+ declare const PACKAGE_TABLE: {
12
+ readonly Arimo: "arimo";
13
+ readonly Caladea: "caladea";
14
+ readonly Carlito: "carlito";
15
+ readonly Cousine: "cousine";
16
+ readonly Lato: "lato";
17
+ readonly "Noto Sans Arabic": "noto-sans-arabic";
18
+ readonly "Source Sans 3": "source-sans-3";
19
+ readonly Tinos: "tinos";
20
+ };
21
+ export type FontsourcePackageTable = typeof PACKAGE_TABLE;
22
+ /** Each bundled family and the directory (an `@fontsource` package name) that ships it. */
23
+ export declare const FONTSOURCE_PACKAGES: FontsourcePackageTable;
24
+ export type BundledFamily = keyof FontsourcePackageTable;
25
+ /**
26
+ * What each bundled family stands in for, as prose for the package's notices.
27
+ * The resolver's own mapping lives in `utils/fontLoader.ts` and
28
+ * `utils/fontResolver.ts`.
29
+ */
30
+ export declare const BUNDLED_FAMILY_SUBSTITUTES: Readonly<Record<BundledFamily, string>>;
31
+ /**
32
+ * The subsets a headless measurer or the PDF writer reads, in resolution
33
+ * priority: a code point two subsets cover resolves to the earlier one.
34
+ * A browser is served every subset the family is cut into.
35
+ */
36
+ export declare const MEASURED_SUBSETS: readonly ["latin", "latin-ext", "arabic"];
37
+ export type MeasuredSubset = (typeof MEASURED_SUBSETS)[number];
38
+ /** Folio paints 400 and 700 only, as `DisplayFontFace` states. */
39
+ export declare const BUNDLED_WEIGHTS: readonly [400, 700];
40
+ export type BundledWeight = (typeof BUNDLED_WEIGHTS)[number];
41
+ /** The styles a family may be cut in; a family without italics ships `normal` only. */
42
+ export declare const BUNDLED_STYLES: readonly ["normal", "italic"];
43
+ export type BundledStyle = (typeof BUNDLED_STYLES)[number];
44
+ /** `files/<package>-<subset>-<weight>-<style>.<format>`: the path of one served binary. */
45
+ export declare const bundledFontFilePath: ({ packageName, subset, weight, style, format }: {
46
+ readonly packageName: string;
47
+ readonly subset: string;
48
+ readonly weight: number;
49
+ readonly style: BundledStyle;
50
+ readonly format: "woff" | "woff2";
51
+ }) => string;
52
+ /** Each family's directory carries the ranges its subsets were cut with. */
53
+ export declare const UNICODE_RANGE_FILE = "unicode.json";
54
+ export {};
@@ -0,0 +1,45 @@
1
+ /** Each bundled family and the directory (an `@fontsource` package name) that ships it. */
2
+ const FONTSOURCE_PACKAGES = {
3
+ Arimo: "arimo",
4
+ Caladea: "caladea",
5
+ Carlito: "carlito",
6
+ Cousine: "cousine",
7
+ Lato: "lato",
8
+ "Noto Sans Arabic": "noto-sans-arabic",
9
+ "Source Sans 3": "source-sans-3",
10
+ Tinos: "tinos"
11
+ };
12
+ /**
13
+ * What each bundled family stands in for, as prose for the package's notices.
14
+ * The resolver's own mapping lives in `utils/fontLoader.ts` and
15
+ * `utils/fontResolver.ts`.
16
+ */
17
+ const BUNDLED_FAMILY_SUBSTITUTES = {
18
+ Arimo: "Arial, and the generic sans-serif",
19
+ Caladea: "Cambria",
20
+ Carlito: "Calibri",
21
+ Cousine: "Courier New, and the generic monospace",
22
+ Lato: "Aptos and Aptos Display",
23
+ "Noto Sans Arabic": "Dubai, and Arabic script in every other family",
24
+ "Source Sans 3": "Segoe UI",
25
+ Tinos: "Times New Roman, and the generic serif"
26
+ };
27
+ /**
28
+ * The subsets a headless measurer or the PDF writer reads, in resolution
29
+ * priority: a code point two subsets cover resolves to the earlier one.
30
+ * A browser is served every subset the family is cut into.
31
+ */
32
+ const MEASURED_SUBSETS = [
33
+ "latin",
34
+ "latin-ext",
35
+ "arabic"
36
+ ];
37
+ /** Folio paints 400 and 700 only, as `DisplayFontFace` states. */
38
+ const BUNDLED_WEIGHTS = [400, 700];
39
+ /** The styles a family may be cut in; a family without italics ships `normal` only. */
40
+ const BUNDLED_STYLES = ["normal", "italic"];
41
+ /** `files/<package>-<subset>-<weight>-<style>.<format>`: the path of one served binary. */
42
+ const bundledFontFilePath = ({ packageName, subset, weight, style, format }) => `files/${packageName}-${subset}-${String(weight)}-${style}.${format}`;
43
+ /** Each family's directory carries the ranges its subsets were cut with. */
44
+ const UNICODE_RANGE_FILE = "unicode.json";
45
+ export { BUNDLED_FAMILY_SUBSTITUTES, BUNDLED_STYLES, BUNDLED_WEIGHTS, FONTSOURCE_PACKAGES, MEASURED_SUBSETS, UNICODE_RANGE_FILE, bundledFontFilePath };
@@ -1,20 +1,14 @@
1
1
  import { HeadlessFontSource } from "./headlessMeasure.js";
2
- /** Where `@fontsource` files come from: `null` when the package or file is absent. */
2
+ import { FONTSOURCE_PACKAGES } from "./bundledFonts.js";
3
+ /**
4
+ * Where the face files come from: `null` when the family or file is absent.
5
+ * Each family is a directory laid out like its `@fontsource` package;
6
+ * `@stll/folio-fonts/node` reads the copies that package ships.
7
+ */
3
8
  export type FontsourceFiles = {
4
- /** Bytes of `@fontsource/<packageName>/<relativePath>`. */
9
+ /** Bytes of `<relativePath>` in the family directory `<packageName>`. */
5
10
  readonly read: (packageName: string, relativePath: string) => Uint8Array | null;
6
11
  };
7
- /** Each bundled family and the `@fontsource` package that ships it. */
8
- export declare const FONTSOURCE_PACKAGES: {
9
- readonly Arimo: "arimo";
10
- readonly Caladea: "caladea";
11
- readonly Carlito: "carlito";
12
- readonly Cousine: "cousine";
13
- readonly Lato: "lato";
14
- readonly "Noto Sans Arabic": "noto-sans-arabic";
15
- readonly "Source Sans 3": "source-sans-3";
16
- readonly Tinos: "tinos";
17
- };
18
12
  /**
19
13
  * A CSS `<string>` token, quoted and escaped. A family name comes from an
20
14
  * authored document and is emitted into a `<style>` element, so the
@@ -41,4 +35,5 @@ export type FontsourceFaces = {
41
35
  readonly fontFaceCss: (options?: FontsourceFontFaceCssOptions) => string;
42
36
  };
43
37
  /** The `@fontsource` faces, read through `files` and cached per face. */
44
- export declare const createFontsourceFaces: (files: FontsourceFiles) => FontsourceFaces;
38
+ export declare const createFontsourceFaces: (files: FontsourceFiles) => FontsourceFaces;
39
+ export { FONTSOURCE_PACKAGES };
@@ -2,6 +2,7 @@ import { bytesToDataUrl } from "../utils/base64.js";
2
2
  import { FONT_MAPPING } from "../utils/fontLoader.js";
3
3
  import { parseFontFamilyList, resolveFontFamily } from "../utils/fontResolver.js";
4
4
  import { decodeText } from "../utils/textEncoding.js";
5
+ import { BUNDLED_WEIGHTS, FONTSOURCE_PACKAGES, MEASURED_SUBSETS, UNICODE_RANGE_FILE, bundledFontFilePath } from "./bundledFonts.js";
5
6
  // src/fonts/fontsourceFaces.ts
6
7
  /**
7
8
  * Faces from the `@fontsource` packages, for a caller that measures and paints
@@ -23,25 +24,8 @@ import { decodeText } from "../utils/textEncoding.js";
23
24
  * The subsets served, in resolution priority: a code point two subsets cover
24
25
  * resolves to the earlier one on both sides.
25
26
  */
26
- const SUBSET_PRIORITY = [
27
- "latin",
28
- "latin-ext",
29
- "arabic"
30
- ];
31
- /** Folio paints 400 and 700 only, as `DisplayFontFace` states. */
32
- const REGULAR_WEIGHT = 400;
33
- const BOLD_WEIGHT = 700;
34
- /** Each bundled family and the `@fontsource` package that ships it. */
35
- const FONTSOURCE_PACKAGES = {
36
- Arimo: "arimo",
37
- Caladea: "caladea",
38
- Carlito: "carlito",
39
- Cousine: "cousine",
40
- Lato: "lato",
41
- "Noto Sans Arabic": "noto-sans-arabic",
42
- "Source Sans 3": "source-sans-3",
43
- Tinos: "tinos"
44
- };
27
+ const SUBSET_PRIORITY = MEASURED_SUBSETS;
28
+ const [REGULAR_WEIGHT, BOLD_WEIGHT] = BUNDLED_WEIGHTS;
45
29
  /** A CSS stack ends in a generic, so a generic must resolve to a bundled family too. */
46
30
  const GENERIC_FAMILIES = {
47
31
  serif: "Tinos",
@@ -81,8 +65,6 @@ const resolveBundledFamily = (family) => {
81
65
  return null;
82
66
  };
83
67
  const weightOf = (bold) => bold ? BOLD_WEIGHT : REGULAR_WEIGHT;
84
- /** `@fontsource` ships the ranges it cut each subset with, beside the files. */
85
- const UNICODE_RANGE_FILE = "unicode.json";
86
68
  const RANGE_TOKEN_RE = /^U\+([0-9A-Fa-f]+)(?:-([0-9A-Fa-f]+))?$/u;
87
69
  const parseRangeToken = (token) => {
88
70
  const match = RANGE_TOKEN_RE.exec(token.trim());
@@ -172,7 +154,13 @@ const createFontsourceFaces = (files) => {
172
154
  const cached = faceCache.get(key);
173
155
  if (cached !== void 0) return cached;
174
156
  const binaries = SUBSET_PRIORITY.flatMap((subset) => {
175
- const bytes = files.read(packageName, `files/${packageName}-${subset}-${String(weight)}-${style}.woff`);
157
+ const bytes = files.read(packageName, bundledFontFilePath({
158
+ packageName,
159
+ subset,
160
+ weight,
161
+ style,
162
+ format: "woff"
163
+ }));
176
164
  return bytes === null ? [] : [{
177
165
  subset,
178
166
  bytes
@@ -2,7 +2,7 @@
2
2
  * Font Loader
3
3
  *
4
4
  * Manages font availability for the DOCX editor. Fonts are bundled via
5
- * fontsource packages (WOFF2, no external requests). This module
5
+ * `@stll/folio-fonts` (WOFF2, no external requests). This module
6
6
  * tracks which fonts are loaded and provides callbacks for re-rendering
7
7
  * when fonts become available.
8
8
  */
@@ -1,9 +1,10 @@
1
+ import { FONTSOURCE_PACKAGES } from "../fonts/bundledFonts.js";
1
2
  // src/utils/fontLoader.ts
2
3
  /**
3
4
  * Font Loader
4
5
  *
5
6
  * Manages font availability for the DOCX editor. Fonts are bundled via
6
- * fontsource packages (WOFF2, no external requests). This module
7
+ * `@stll/folio-fonts` (WOFF2, no external requests). This module
7
8
  * tracks which fonts are loaded and provides callbacks for re-rendering
8
9
  * when fonts become available.
9
10
  */
@@ -34,16 +35,7 @@ const FONT_MAPPING = {
34
35
  "Lucida Console": "monospace"
35
36
  };
36
37
  /** Bundled font families (available without network requests). */
37
- const BUNDLED_FONTS = /* @__PURE__ */ new Set([
38
- "Carlito",
39
- "Caladea",
40
- "Arimo",
41
- "Tinos",
42
- "Cousine",
43
- "Lato",
44
- "Source Sans 3",
45
- "Noto Sans Arabic"
46
- ]);
38
+ const BUNDLED_FONTS = new Set(Object.keys(FONTSOURCE_PACKAGES));
47
39
  /**
48
40
  * Mark a font as loaded. For bundled fonts this is immediate;
49
41
  * for others it checks CSS Font Loading API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.66.0",
3
+ "version": "0.66.1",
4
4
  "description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -29,7 +29,9 @@
29
29
  "skills",
30
30
  "README.md",
31
31
  "LICENSE",
32
- "NOTICE.md"
32
+ "NOTICE.md",
33
+ "licenses",
34
+ "THIRD_PARTY_NOTICES.md"
33
35
  ],
34
36
  "type": "module",
35
37
  "sideEffects": false,