@junejs/pdf-font-noto-sans-tc 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,92 @@
1
+ This Font Software is licensed under the SIL Open Font License,
2
+ Version 1.1.
3
+
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font
14
+ creation efforts of academic and linguistic communities, and to
15
+ provide a free and open framework in which fonts may be shared and
16
+ improved in partnership with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply to
25
+ any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software
36
+ components as distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to,
39
+ deleting, or substituting -- in part or in whole -- any of the
40
+ components of the Original Version, by changing formats or by porting
41
+ the Font Software to a new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION & CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed,
49
+ modify, redistribute, and sell modified and unmodified copies of the
50
+ Font Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components, in
53
+ Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the
64
+ corresponding Copyright Holder. This restriction only applies to the
65
+ primary font name as presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created using
77
+ the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
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 THE
88
+ COPYRIGHT HOLDER 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.
package/dist/node.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { n as NotoSansTCWeight, t as NotoSansTCOptions } from "./provider-CzTbdFzv.js";
2
+ //#region src/node.d.ts
3
+ export declare function notoSansTC(opts?: NotoSansTCOptions): import("@junejs/pdf-typst-wasm").FontProvider;
4
+ //#endregion
5
+ export type { NotoSansTCOptions, NotoSansTCWeight };
package/dist/node.js ADDED
@@ -0,0 +1,14 @@
1
+ import { n as MISSING, r as createNotoSansTC, t as FILES } from "./provider-DOCYT0sP.js";
2
+ import { readFile } from "node:fs/promises";
3
+ //#region src/node.ts
4
+ function notoSansTC(opts = {}) {
5
+ return createNotoSansTC(async (weight) => {
6
+ try {
7
+ return new Uint8Array(await readFile(new URL(`../fonts/${FILES[weight]}`, import.meta.url)));
8
+ } catch (err) {
9
+ throw new Error(MISSING, { cause: err });
10
+ }
11
+ }, opts);
12
+ }
13
+ //#endregion
14
+ export { notoSansTC };
@@ -0,0 +1,8 @@
1
+ import "@junejs/pdf-typst-wasm";
2
+ //#region src/provider.d.ts
3
+ type NotoSansTCWeight = 400 | 700;
4
+ type NotoSansTCOptions = {
5
+ weights?: NotoSansTCWeight[];
6
+ };
7
+ //#endregion
8
+ export { NotoSansTCWeight as n, NotoSansTCOptions as t };
@@ -0,0 +1,17 @@
1
+ //#region src/provider.ts
2
+ function createNotoSansTC(load, opts = {}) {
3
+ const weights = [...new Set(opts.weights ?? [400, 700])];
4
+ for (const w of weights) if (w !== 400 && w !== 700) throw new Error(`notoSansTC: no weight ${w} (this package ships 400 and 700)`);
5
+ return {
6
+ name: "noto-sans-tc",
7
+ egress: [],
8
+ persistent: () => Promise.all(weights.map(load))
9
+ };
10
+ }
11
+ const FILES = {
12
+ 400: "NotoSansTC-Regular.otf",
13
+ 700: "NotoSansTC-Bold.otf"
14
+ };
15
+ const MISSING = "@junejs/pdf-font-noto-sans-tc: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-tc";
16
+ //#endregion
17
+ export { MISSING as n, createNotoSansTC as r, FILES as t };
@@ -0,0 +1,5 @@
1
+ import { n as NotoSansTCWeight, t as NotoSansTCOptions } from "./provider-CzTbdFzv.js";
2
+ //#region src/workerd.d.ts
3
+ export declare function notoSansTC(opts?: NotoSansTCOptions): import("@junejs/pdf-typst-wasm").FontProvider;
4
+ //#endregion
5
+ export type { NotoSansTCOptions, NotoSansTCWeight };
@@ -0,0 +1,9 @@
1
+ import { r as createNotoSansTC } from "./provider-DOCYT0sP.js";
2
+ import bold from "../fonts/NotoSansTC-Bold.otf";
3
+ import regular from "../fonts/NotoSansTC-Regular.otf";
4
+ //#region src/workerd.ts
5
+ function notoSansTC(opts = {}) {
6
+ return createNotoSansTC(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
7
+ }
8
+ //#endregion
9
+ export { notoSansTC };
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@junejs/pdf-font-noto-sans-tc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "June — Noto Sans TC (Traditional Chinese, regular and bold) as an offline font provider for @junejs/pdf-typst-wasm: no network call, on Node, Bun, Deno and Cloudflare Workers.",
5
+ "type": "module",
6
+ "license": "MIT AND OFL-1.1",
7
+ "homepage": "https://june.build",
8
+ "exports": {
9
+ ".": {
10
+ "source": {
11
+ "workerd": "./src/workerd.ts",
12
+ "bun": "./src/bun.ts",
13
+ "default": "./src/node.ts"
14
+ },
15
+ "bun": {
16
+ "workerd": "./src/workerd.ts",
17
+ "default": "./src/bun.ts"
18
+ },
19
+ "workerd": {
20
+ "types": "./dist/workerd.d.ts",
21
+ "default": "./dist/workerd.js"
22
+ },
23
+ "default": {
24
+ "types": "./dist/node.d.ts",
25
+ "default": "./dist/node.js"
26
+ }
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src/*.ts",
32
+ "fonts/*.otf",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "fetch-fonts": "bun scripts/fetch-fonts.ts",
37
+ "build": "bun scripts/fetch-fonts.ts && tsdown",
38
+ "test": "bun test"
39
+ },
40
+ "peerDependencies": {
41
+ "@junejs/pdf-typst-wasm": "^0.2.0"
42
+ },
43
+ "devDependencies": {
44
+ "@junejs/pdf": "^0.2.0",
45
+ "@junejs/pdf-typst-wasm": "^0.2.0"
46
+ },
47
+ "keywords": [
48
+ "june",
49
+ "pdf",
50
+ "typst",
51
+ "font",
52
+ "noto",
53
+ "traditional-chinese"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/junebuild/june.git",
61
+ "directory": "packages/pdf-font-noto-sans-tc"
62
+ }
63
+ }
package/src/bun.ts ADDED
@@ -0,0 +1,29 @@
1
+ // @junejs/pdf-font-noto-sans-tc on Bun: each file is imported `with { type: "file" }`, so
2
+ // `bun build --compile` embeds it and the import yields its path inside the binary, the way
3
+ // @junejs/pdf-typst-wasm loads its engine (#367). Dynamic, with literal paths the bundler can
4
+ // see: read on the first render, never at import.
5
+
6
+ import { readFile } from "node:fs/promises";
7
+
8
+ import { createNotoSansTC, MISSING, type NotoSansTCOptions, type NotoSansTCWeight } from "./provider";
9
+
10
+ export type { NotoSansTCOptions, NotoSansTCWeight } from "./provider";
11
+
12
+ // fonts.d.ts types a .otf import as bytes (workerd's Data module); with type "file" it is a path.
13
+ type FileImport = Promise<unknown>;
14
+ const IMPORTS: Record<NotoSansTCWeight, () => FileImport> = {
15
+ 400: () => import("../fonts/NotoSansTC-Regular.otf", { with: { type: "file" } }),
16
+ 700: () => import("../fonts/NotoSansTC-Bold.otf", { with: { type: "file" } }),
17
+ };
18
+
19
+ export function notoSansTC(opts: NotoSansTCOptions = {}) {
20
+ return createNotoSansTC(async (weight) => {
21
+ let path: string;
22
+ try {
23
+ path = ((await IMPORTS[weight]()) as { default: string }).default;
24
+ } catch (err) {
25
+ throw new Error(MISSING, { cause: err });
26
+ }
27
+ return new Uint8Array(await readFile(path));
28
+ }, opts);
29
+ }
package/src/fonts.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ // An .otf import is a Data module on workerd (wrangler's Data rule): the file's bytes.
2
+ declare module "*.otf" {
3
+ const data: ArrayBuffer;
4
+ export default data;
5
+ }
package/src/node.ts ADDED
@@ -0,0 +1,22 @@
1
+ // @junejs/pdf-font-noto-sans-tc on Node and Deno: the font files are read from fonts/ next to
2
+ // this file's directory (the same path from src/ in the repo and dist/ in the package), on the
3
+ // renderer's first render.
4
+ //
5
+ // import { notoSansTC } from "@junejs/pdf-font-noto-sans-tc";
6
+ // typstWasmRenderer({ fonts: [notoSansTC()] });
7
+
8
+ import { readFile } from "node:fs/promises";
9
+
10
+ import { createNotoSansTC, FILES, MISSING, type NotoSansTCOptions } from "./provider";
11
+
12
+ export type { NotoSansTCOptions, NotoSansTCWeight } from "./provider";
13
+
14
+ export function notoSansTC(opts: NotoSansTCOptions = {}) {
15
+ return createNotoSansTC(async (weight) => {
16
+ try {
17
+ return new Uint8Array(await readFile(new URL(`../fonts/${FILES[weight]}`, import.meta.url)));
18
+ } catch (err) {
19
+ throw new Error(MISSING, { cause: err });
20
+ }
21
+ }, opts);
22
+ }
@@ -0,0 +1,41 @@
1
+ // notoSansTC — a FontProvider (@junejs/pdf-typst-wasm) for Traditional Chinese that needs no
2
+ // network: Noto Sans CJK's Taiwan subset, regular and bold, shipped in this package (#371).
3
+ // The offline alternative to googleFontSubsets, which sends each document's characters to
4
+ // Google: here egress is empty and the cost is size instead, ~5.5 MB per weight, registered
5
+ // once per renderer.
6
+ //
7
+ // The subset is not every CJK ideograph. Measured with fontTools: 20,745 code points, 17,755
8
+ // of them Han, and every Big5 character except four symbols (U+02CD, U+203E, U+223C, U+2252).
9
+ // A rare character outside it (靐) is reported by the renderer's missing glyphs check like any
10
+ // other.
11
+ //
12
+ // Each runtime finds the files its own way (node.ts, bun.ts, workerd.ts); this module only
13
+ // turns weights into a provider.
14
+
15
+ import type { FontProvider } from "@junejs/pdf-typst-wasm";
16
+
17
+ // The weights Markdown needs: body text, and bold for **strong** and headings.
18
+ export type NotoSansTCWeight = 400 | 700;
19
+
20
+ export type NotoSansTCOptions = {
21
+ // Default [400, 700]. Only the listed weights are read and registered, so [400] halves the
22
+ // font memory per renderer; Typst synthesizes bold from the regular. It doesn't shrink a
23
+ // deploy: a Worker upload or a compiled binary carries both files either way.
24
+ weights?: NotoSansTCWeight[];
25
+ };
26
+
27
+ export type WeightLoader = (weight: NotoSansTCWeight) => Promise<Uint8Array>;
28
+
29
+ export function createNotoSansTC(load: WeightLoader, opts: NotoSansTCOptions = {}): FontProvider {
30
+ const weights = [...new Set<NotoSansTCWeight>(opts.weights ?? [400, 700])];
31
+ for (const w of weights) if (w !== 400 && w !== 700) throw new Error(`notoSansTC: no weight ${w as number} (this package ships 400 and 700)`);
32
+ return {
33
+ name: "noto-sans-tc",
34
+ egress: [],
35
+ persistent: () => Promise.all(weights.map(load)),
36
+ };
37
+ }
38
+
39
+ export const FILES: Record<NotoSansTCWeight, string> = { 400: "NotoSansTC-Regular.otf", 700: "NotoSansTC-Bold.otf" };
40
+
41
+ export const MISSING = "@junejs/pdf-font-noto-sans-tc: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-tc";
package/src/workerd.ts ADDED
@@ -0,0 +1,16 @@
1
+ // @junejs/pdf-font-noto-sans-tc on Cloudflare Workers (the `workerd` export condition): the
2
+ // files are imported as Data modules, so wrangler uploads them with the Worker. The two weights
3
+ // add ~11 MiB to the Worker, next to the engine's 29 MiB, under the 64 MiB limit. Wrangler
4
+ // needs a rule for the extension in the app's wrangler config:
5
+ //
6
+ // "rules": [{ "type": "Data", "globs": ["**/*.otf"] }]
7
+
8
+ import bold from "../fonts/NotoSansTC-Bold.otf";
9
+ import regular from "../fonts/NotoSansTC-Regular.otf";
10
+ import { createNotoSansTC, type NotoSansTCOptions } from "./provider";
11
+
12
+ export type { NotoSansTCOptions, NotoSansTCWeight } from "./provider";
13
+
14
+ export function notoSansTC(opts: NotoSansTCOptions = {}) {
15
+ return createNotoSansTC(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
16
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.