@junejs/pdf-font-noto-sans-tc 0.2.0 → 0.2.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.
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/provider-DIaL_q7p.d.ts +19 -0
- package/dist/provider-g4uaDoUt.js +28 -0
- package/dist/unbundled.d.ts +10 -0
- package/dist/unbundled.js +23 -0
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +1 -1
- package/package.json +11 -4
- package/src/assets.ts +20 -0
- package/src/provider.ts +26 -7
- package/src/unbundled.ts +32 -0
- package/src/workerd.ts +3 -2
- package/dist/provider-CzTbdFzv.d.ts +0 -8
- package/dist/provider-DOCYT0sP.js +0 -17
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as NotoSansTCOptions, r as NotoSansTCWeight } from "./provider-DIaL_q7p.js";
|
|
2
2
|
//#region src/node.d.ts
|
|
3
3
|
export declare function notoSansTC(opts?: NotoSansTCOptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
4
4
|
//#endregion
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as createNotoSansTC, n as MISSING, t as FILES } from "./provider-g4uaDoUt.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
//#region src/node.ts
|
|
4
4
|
function notoSansTC(opts = {}) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FontEgress } from "@junejs/pdf-typst-wasm";
|
|
2
|
+
//#region src/assets.d.ts
|
|
3
|
+
type AssetRef = {
|
|
4
|
+
name: string;
|
|
5
|
+
sha256: string;
|
|
6
|
+
size: number;
|
|
7
|
+
urls: string[];
|
|
8
|
+
};
|
|
9
|
+
type AssetLoader = (ref: AssetRef) => Promise<Uint8Array | ArrayBuffer>;
|
|
10
|
+
declare function loadVerified(ref: AssetRef, load: AssetLoader): Promise<Uint8Array>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/provider.d.ts
|
|
13
|
+
type NotoSansTCWeight = 400 | 700;
|
|
14
|
+
type NotoSansTCOptions = {
|
|
15
|
+
weights?: NotoSansTCWeight[];
|
|
16
|
+
};
|
|
17
|
+
declare const NOTO_SANS_TC: Record<NotoSansTCWeight, AssetRef>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { AssetRef as a, AssetLoader as i, NotoSansTCOptions as n, loadVerified as o, NotoSansTCWeight as r, NOTO_SANS_TC as t };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/provider.ts
|
|
2
|
+
function createNotoSansTC(load, opts = {}, egress = []) {
|
|
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 TAG = "Sans2.004";
|
|
12
|
+
const ref = (name, sha256, size) => ({
|
|
13
|
+
name,
|
|
14
|
+
sha256,
|
|
15
|
+
size,
|
|
16
|
+
urls: [`https://raw.githubusercontent.com/notofonts/noto-cjk/${TAG}/Sans/SubsetOTF/TC/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/TC/${name}`]
|
|
17
|
+
});
|
|
18
|
+
const NOTO_SANS_TC = {
|
|
19
|
+
400: ref("NotoSansTC-Regular.otf", "5bab0cb3c1cf89dde07c4a95a4054b195afbcfe784d69d75c340780712237537", 5683368),
|
|
20
|
+
700: ref("NotoSansTC-Bold.otf", "55420b259eb119bf5f2a0aadba10cf9d736c12d64ab93e78546d69ef5f43558b", 5839972)
|
|
21
|
+
};
|
|
22
|
+
const FILES = {
|
|
23
|
+
400: NOTO_SANS_TC[400].name,
|
|
24
|
+
700: NOTO_SANS_TC[700].name
|
|
25
|
+
};
|
|
26
|
+
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";
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createNotoSansTC as i, MISSING as n, NOTO_SANS_TC as r, FILES as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { a as AssetRef, i as AssetLoader, n as NotoSansTCOptions, o as loadVerified, r as NotoSansTCWeight, t as NOTO_SANS_TC } from "./provider-DIaL_q7p.js";
|
|
2
|
+
import { FontEgress } from "@junejs/pdf-typst-wasm";
|
|
3
|
+
//#region src/unbundled.d.ts
|
|
4
|
+
export type UnbundledNotoSansTCOptions = NotoSansTCOptions & {
|
|
5
|
+
load: AssetLoader;
|
|
6
|
+
egress?: FontEgress[];
|
|
7
|
+
};
|
|
8
|
+
export declare function notoSansTC(opts: UnbundledNotoSansTCOptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type AssetLoader, type AssetRef, NOTO_SANS_TC, type NotoSansTCOptions, type NotoSansTCWeight, loadVerified };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { i as createNotoSansTC, r as NOTO_SANS_TC } from "./provider-g4uaDoUt.js";
|
|
2
|
+
//#region src/assets.ts
|
|
3
|
+
async function loadVerified(ref, load) {
|
|
4
|
+
const got = await load(ref);
|
|
5
|
+
const bytes = got instanceof Uint8Array ? got.buffer instanceof SharedArrayBuffer ? got.slice() : got : new Uint8Array(got);
|
|
6
|
+
if (bytes.byteLength !== ref.size) throw new Error(`${ref.name}: the loader returned ${bytes.byteLength} bytes, expected ${ref.size} (sha256 ${ref.sha256})`);
|
|
7
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
8
|
+
const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
9
|
+
if (hex !== ref.sha256) throw new Error(`${ref.name}: the loader returned bytes with sha256 ${hex}, expected ${ref.sha256}`);
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/unbundled.ts
|
|
14
|
+
const HOSTS = [...new Set(Object.values(NOTO_SANS_TC).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({
|
|
15
|
+
host,
|
|
16
|
+
sends: "nothing"
|
|
17
|
+
}));
|
|
18
|
+
function notoSansTC(opts) {
|
|
19
|
+
const { load, egress, ...rest } = opts;
|
|
20
|
+
return createNotoSansTC((weight) => loadVerified(NOTO_SANS_TC[weight], load), rest, egress ?? HOSTS);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NOTO_SANS_TC, loadVerified, notoSansTC };
|
package/dist/workerd.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as NotoSansTCOptions, r as NotoSansTCWeight } from "./provider-DIaL_q7p.js";
|
|
2
2
|
//#region src/workerd.d.ts
|
|
3
3
|
export declare function notoSansTC(opts?: NotoSansTCOptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
4
4
|
//#endregion
|
package/dist/workerd.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junejs/pdf-font-noto-sans-tc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"license": "MIT AND OFL-1.1",
|
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
"types": "./dist/node.d.ts",
|
|
25
25
|
"default": "./dist/node.js"
|
|
26
26
|
}
|
|
27
|
+
},
|
|
28
|
+
"./unbundled": {
|
|
29
|
+
"source": "./src/unbundled.ts",
|
|
30
|
+
"bun": "./src/unbundled.ts",
|
|
31
|
+
"types": "./dist/unbundled.d.ts",
|
|
32
|
+
"default": "./dist/unbundled.js"
|
|
27
33
|
}
|
|
28
34
|
},
|
|
29
35
|
"files": [
|
|
@@ -38,11 +44,12 @@
|
|
|
38
44
|
"test": "bun test"
|
|
39
45
|
},
|
|
40
46
|
"peerDependencies": {
|
|
41
|
-
"@junejs/pdf-typst-wasm": "^0.2.
|
|
47
|
+
"@junejs/pdf-typst-wasm": "^0.2.1"
|
|
42
48
|
},
|
|
43
49
|
"devDependencies": {
|
|
44
|
-
"@junejs/pdf": "^0.2.
|
|
45
|
-
"@junejs/pdf-typst-wasm": "^0.2.
|
|
50
|
+
"@junejs/pdf": "^0.2.1",
|
|
51
|
+
"@junejs/pdf-typst-wasm": "^0.2.1",
|
|
52
|
+
"@junejs/server": "^0.2.1"
|
|
46
53
|
},
|
|
47
54
|
"keywords": [
|
|
48
55
|
"june",
|
package/src/assets.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The asset types and check @junejs/pdf-typst-wasm/unbundled defines (its src/assets.ts),
|
|
2
|
+
// repeated here on purpose: the peer range is ^0.2.0, and 0.2.0 has no ./unbundled, so this
|
|
3
|
+
// package must not import it — at run time or in its published types. The shapes are the
|
|
4
|
+
// same, so a loader written for one serves both.
|
|
5
|
+
|
|
6
|
+
export type AssetRef = { name: string; sha256: string; size: number; urls: string[] };
|
|
7
|
+
|
|
8
|
+
export type AssetLoader = (ref: AssetRef) => Promise<Uint8Array | ArrayBuffer>;
|
|
9
|
+
|
|
10
|
+
// The loader's bytes, checked against the ref's size and SHA-256 before they are used.
|
|
11
|
+
export async function loadVerified(ref: AssetRef, load: AssetLoader): Promise<Uint8Array> {
|
|
12
|
+
const got = await load(ref);
|
|
13
|
+
// WebCrypto refuses a view on a SharedArrayBuffer: copy one into a plain buffer first.
|
|
14
|
+
const bytes = got instanceof Uint8Array ? (got.buffer instanceof SharedArrayBuffer ? got.slice() : got) : new Uint8Array(got);
|
|
15
|
+
if (bytes.byteLength !== ref.size) throw new Error(`${ref.name}: the loader returned ${bytes.byteLength} bytes, expected ${ref.size} (sha256 ${ref.sha256})`);
|
|
16
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes as Uint8Array<ArrayBuffer>);
|
|
17
|
+
const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
18
|
+
if (hex !== ref.sha256) throw new Error(`${ref.name}: the loader returned bytes with sha256 ${hex}, expected ${ref.sha256}`);
|
|
19
|
+
return bytes;
|
|
20
|
+
}
|
package/src/provider.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// notoSansTC — a FontProvider (@junejs/pdf-typst-wasm) for Traditional Chinese that needs no
|
|
2
2
|
// network: Noto Sans CJK's Taiwan subset, regular and bold, shipped in this package (#371).
|
|
3
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
|
|
4
|
+
// Google: here egress is empty and the cost is size instead, ~5.5 MiB per weight, registered
|
|
5
5
|
// once per renderer.
|
|
6
6
|
//
|
|
7
7
|
// The subset is not every CJK ideograph. Measured with fontTools: 20,745 code points, 17,755
|
|
8
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
|
|
10
|
-
// other.
|
|
9
|
+
// A rare character outside it (靐) is reported by the renderer's missing glyphs check
|
|
10
|
+
// like any other.
|
|
11
11
|
//
|
|
12
12
|
// Each runtime finds the files its own way (node.ts, bun.ts, workerd.ts); this module only
|
|
13
13
|
// turns weights into a provider.
|
|
14
14
|
|
|
15
|
-
import type { FontProvider } from "@junejs/pdf-typst-wasm";
|
|
15
|
+
import type { FontEgress, FontProvider } from "@junejs/pdf-typst-wasm";
|
|
16
|
+
import type { AssetRef } from "./assets";
|
|
16
17
|
|
|
17
18
|
// The weights Markdown needs: body text, and bold for **strong** and headings.
|
|
18
19
|
export type NotoSansTCWeight = 400 | 700;
|
|
@@ -26,16 +27,34 @@ export type NotoSansTCOptions = {
|
|
|
26
27
|
|
|
27
28
|
export type WeightLoader = (weight: NotoSansTCWeight) => Promise<Uint8Array>;
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
// `egress`: what `load` contacts. The bundled entries read files the package ships: none.
|
|
31
|
+
export function createNotoSansTC(load: WeightLoader, opts: NotoSansTCOptions = {}, egress: FontEgress[] = []): FontProvider {
|
|
30
32
|
const weights = [...new Set<NotoSansTCWeight>(opts.weights ?? [400, 700])];
|
|
31
33
|
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
34
|
return {
|
|
33
35
|
name: "noto-sans-tc",
|
|
34
|
-
egress
|
|
36
|
+
egress,
|
|
35
37
|
persistent: () => Promise.all(weights.map(load)),
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
// The upstream release the files come from: Noto Sans CJK's Taiwan subset OTFs.
|
|
42
|
+
export const TAG = "Sans2.004";
|
|
43
|
+
|
|
44
|
+
const ref = (name: string, sha256: string, size: number): AssetRef => ({
|
|
45
|
+
name,
|
|
46
|
+
sha256,
|
|
47
|
+
size,
|
|
48
|
+
urls: [`https://raw.githubusercontent.com/notofonts/noto-cjk/${TAG}/Sans/SubsetOTF/TC/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/TC/${name}`],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Each weight's file, pinned: scripts/fetch-fonts.ts fetches and checks these, and the
|
|
52
|
+
// unbundled entry checks an app's loader against them (#383).
|
|
53
|
+
export const NOTO_SANS_TC: Record<NotoSansTCWeight, AssetRef> = {
|
|
54
|
+
400: ref("NotoSansTC-Regular.otf", "5bab0cb3c1cf89dde07c4a95a4054b195afbcfe784d69d75c340780712237537", 5683368),
|
|
55
|
+
700: ref("NotoSansTC-Bold.otf", "55420b259eb119bf5f2a0aadba10cf9d736c12d64ab93e78546d69ef5f43558b", 5839972),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const FILES: Record<NotoSansTCWeight, string> = { 400: NOTO_SANS_TC[400].name, 700: NOTO_SANS_TC[700].name };
|
|
40
59
|
|
|
41
60
|
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/unbundled.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @junejs/pdf-font-noto-sans-tc/unbundled — the provider without its font files (#383). The
|
|
2
|
+
// default entries embed them (bun.ts as files, workerd.ts as Data modules), so a
|
|
3
|
+
// `bun build --compile` binary carries ~11 MiB whether or not it renders Chinese. This entry
|
|
4
|
+
// never references them: the app passes `load`, called on the first render with each weight's
|
|
5
|
+
// ref, and its bytes are checked against the ref's size and sha256 before they are used.
|
|
6
|
+
//
|
|
7
|
+
// import { notoSansTC } from "@junejs/pdf-font-noto-sans-tc/unbundled";
|
|
8
|
+
// typstWasmRenderer({ load, fonts: [notoSansTC({ load })] });
|
|
9
|
+
//
|
|
10
|
+
// Runtime-neutral: no host imports.
|
|
11
|
+
|
|
12
|
+
import type { FontEgress } from "@junejs/pdf-typst-wasm";
|
|
13
|
+
import { loadVerified, type AssetLoader } from "./assets";
|
|
14
|
+
import { createNotoSansTC, NOTO_SANS_TC, type NotoSansTCOptions } from "./provider";
|
|
15
|
+
|
|
16
|
+
export { loadVerified, type AssetLoader, type AssetRef } from "./assets";
|
|
17
|
+
export { NOTO_SANS_TC, type NotoSansTCOptions, type NotoSansTCWeight } from "./provider";
|
|
18
|
+
|
|
19
|
+
export type UnbundledNotoSansTCOptions = NotoSansTCOptions & {
|
|
20
|
+
// Gets a weight's file for its ref. Checked against the ref before the font is registered.
|
|
21
|
+
load: AssetLoader;
|
|
22
|
+
// What `load` contacts, for renderer.egress. Default: the refs' URL hosts, sending nothing
|
|
23
|
+
// (the files may be downloaded). [] when the app pre-seeds them and never fetches.
|
|
24
|
+
egress?: FontEgress[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const HOSTS: FontEgress[] = [...new Set(Object.values(NOTO_SANS_TC).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({ host, sends: "nothing" }));
|
|
28
|
+
|
|
29
|
+
export function notoSansTC(opts: UnbundledNotoSansTCOptions) {
|
|
30
|
+
const { load, egress, ...rest } = opts;
|
|
31
|
+
return createNotoSansTC((weight) => loadVerified(NOTO_SANS_TC[weight], load), rest, egress ?? HOSTS);
|
|
32
|
+
}
|
package/src/workerd.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// @junejs/pdf-font-noto-sans-tc on Cloudflare Workers (the `workerd` export condition): the
|
|
2
2
|
// files are imported as Data modules, so wrangler uploads them with the Worker. The two weights
|
|
3
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
|
|
4
|
+
// needs a rule for the extension; `june build` emits it (#379), and an app running wrangler
|
|
5
|
+
// on its own config adds it:
|
|
5
6
|
//
|
|
6
|
-
// "rules": [{ "type": "Data", "globs": ["**/*.otf"] }]
|
|
7
|
+
// "rules": [{ "type": "Data", "globs": ["**/*.otf"], "fallthrough": true }]
|
|
7
8
|
|
|
8
9
|
import bold from "../fonts/NotoSansTC-Bold.otf";
|
|
9
10
|
import regular from "../fonts/NotoSansTC-Regular.otf";
|
|
@@ -1,17 +0,0 @@
|
|
|
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 };
|