@junejs/pdf-font-noto-sans-kr 0.0.0-stage → 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/LICENSE +92 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +14 -0
- package/dist/provider-BhoN_t0i.js +28 -0
- package/dist/provider-BiqtA6ZU.d.ts +19 -0
- package/dist/unbundled.d.ts +10 -0
- package/dist/unbundled.js +23 -0
- package/dist/workerd.d.ts +5 -0
- package/dist/workerd.js +9 -0
- package/fonts/NotoSansKR-Bold.otf +0 -0
- package/fonts/NotoSansKR-Regular.otf +0 -0
- package/package.json +68 -4
- package/src/assets.ts +20 -0
- package/src/bun.ts +29 -0
- package/src/fonts.d.ts +5 -0
- package/src/node.ts +22 -0
- package/src/provider.ts +61 -0
- package/src/unbundled.ts +32 -0
- package/src/workerd.ts +17 -0
- package/README.md +0 -3
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 NotoSansKROptions, r as NotoSansKRWeight } from "./provider-BiqtA6ZU.js";
|
|
2
|
+
//#region src/node.d.ts
|
|
3
|
+
export declare function notoSansKR(opts?: NotoSansKROptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
4
|
+
//#endregion
|
|
5
|
+
export type { NotoSansKROptions, NotoSansKRWeight };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i as createNotoSansKR, n as MISSING, t as FILES } from "./provider-BhoN_t0i.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
//#region src/node.ts
|
|
4
|
+
function notoSansKR(opts = {}) {
|
|
5
|
+
return createNotoSansKR(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 { notoSansKR };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/provider.ts
|
|
2
|
+
function createNotoSansKR(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(`notoSansKR: no weight ${w} (this package ships 400 and 700)`);
|
|
5
|
+
return {
|
|
6
|
+
name: "noto-sans-kr",
|
|
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/KR/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/KR/${name}`]
|
|
17
|
+
});
|
|
18
|
+
const NOTO_SANS_KR = {
|
|
19
|
+
400: ref("NotoSansKR-Regular.otf", "69975a0ac8472717870aefeab0a4d52739308d90856b9955313b2ad5e0148d68", 4644748),
|
|
20
|
+
700: ref("NotoSansKR-Bold.otf", "5a6ceb287ed2fc6cfc6213144ebea68cbd94b20fc9eb873d8486493bf02d9bda", 4816044)
|
|
21
|
+
};
|
|
22
|
+
const FILES = {
|
|
23
|
+
400: NOTO_SANS_KR[400].name,
|
|
24
|
+
700: NOTO_SANS_KR[700].name
|
|
25
|
+
};
|
|
26
|
+
const MISSING = "@junejs/pdf-font-noto-sans-kr: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-kr";
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createNotoSansKR as i, MISSING as n, NOTO_SANS_KR as r, FILES as t };
|
|
@@ -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 NotoSansKRWeight = 400 | 700;
|
|
14
|
+
type NotoSansKROptions = {
|
|
15
|
+
weights?: NotoSansKRWeight[];
|
|
16
|
+
};
|
|
17
|
+
declare const NOTO_SANS_KR: Record<NotoSansKRWeight, AssetRef>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { AssetRef as a, AssetLoader as i, NotoSansKROptions as n, loadVerified as o, NotoSansKRWeight as r, NOTO_SANS_KR as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { a as AssetRef, i as AssetLoader, n as NotoSansKROptions, o as loadVerified, r as NotoSansKRWeight, t as NOTO_SANS_KR } from "./provider-BiqtA6ZU.js";
|
|
2
|
+
import { FontEgress } from "@junejs/pdf-typst-wasm";
|
|
3
|
+
//#region src/unbundled.d.ts
|
|
4
|
+
export type UnbundledNotoSansKROptions = NotoSansKROptions & {
|
|
5
|
+
load: AssetLoader;
|
|
6
|
+
egress?: FontEgress[];
|
|
7
|
+
};
|
|
8
|
+
export declare function notoSansKR(opts: UnbundledNotoSansKROptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type AssetLoader, type AssetRef, NOTO_SANS_KR, type NotoSansKROptions, type NotoSansKRWeight, loadVerified };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { i as createNotoSansKR, r as NOTO_SANS_KR } from "./provider-BhoN_t0i.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_KR).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({
|
|
15
|
+
host,
|
|
16
|
+
sends: "nothing"
|
|
17
|
+
}));
|
|
18
|
+
function notoSansKR(opts) {
|
|
19
|
+
const { load, egress, ...rest } = opts;
|
|
20
|
+
return createNotoSansKR((weight) => loadVerified(NOTO_SANS_KR[weight], load), rest, egress ?? HOSTS);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NOTO_SANS_KR, loadVerified, notoSansKR };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { n as NotoSansKROptions, r as NotoSansKRWeight } from "./provider-BiqtA6ZU.js";
|
|
2
|
+
//#region src/workerd.d.ts
|
|
3
|
+
export declare function notoSansKR(opts?: NotoSansKROptions): import("@junejs/pdf-typst-wasm").FontProvider;
|
|
4
|
+
//#endregion
|
|
5
|
+
export type { NotoSansKROptions, NotoSansKRWeight };
|
package/dist/workerd.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { i as createNotoSansKR } from "./provider-BhoN_t0i.js";
|
|
2
|
+
import bold from "../fonts/NotoSansKR-Bold.otf";
|
|
3
|
+
import regular from "../fonts/NotoSansKR-Regular.otf";
|
|
4
|
+
//#region src/workerd.ts
|
|
5
|
+
function notoSansKR(opts = {}) {
|
|
6
|
+
return createNotoSansKR(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { notoSansKR };
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junejs/pdf-font-noto-sans-kr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "June — Noto Sans KR (Korean, 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
|
+
"./unbundled": {
|
|
29
|
+
"source": "./src/unbundled.ts",
|
|
30
|
+
"bun": "./src/unbundled.ts",
|
|
31
|
+
"types": "./dist/unbundled.d.ts",
|
|
32
|
+
"default": "./dist/unbundled.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"src/*.ts",
|
|
38
|
+
"fonts/*.otf",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"fetch-fonts": "bun scripts/fetch-fonts.ts",
|
|
43
|
+
"build": "bun scripts/fetch-fonts.ts && tsdown",
|
|
44
|
+
"test": "bun test"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@junejs/pdf-typst-wasm": "^0.2.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@junejs/pdf": "^0.2.1",
|
|
51
|
+
"@junejs/pdf-typst-wasm": "^0.2.1",
|
|
52
|
+
"@junejs/server": "^0.2.1"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"june",
|
|
56
|
+
"pdf",
|
|
57
|
+
"typst",
|
|
58
|
+
"font",
|
|
59
|
+
"noto",
|
|
60
|
+
"korean"
|
|
61
|
+
],
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "git+https://github.com/junebuild/june.git",
|
|
68
|
+
"directory": "packages/pdf-font-noto-sans-kr"
|
|
69
|
+
}
|
|
70
|
+
}
|
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/bun.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @junejs/pdf-font-noto-sans-kr 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 { createNotoSansKR, MISSING, type NotoSansKROptions, type NotoSansKRWeight } from "./provider";
|
|
9
|
+
|
|
10
|
+
export type { NotoSansKROptions, NotoSansKRWeight } 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<NotoSansKRWeight, () => FileImport> = {
|
|
15
|
+
400: () => import("../fonts/NotoSansKR-Regular.otf", { with: { type: "file" } }),
|
|
16
|
+
700: () => import("../fonts/NotoSansKR-Bold.otf", { with: { type: "file" } }),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function notoSansKR(opts: NotoSansKROptions = {}) {
|
|
20
|
+
return createNotoSansKR(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
package/src/node.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @junejs/pdf-font-noto-sans-kr 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 { notoSansKR } from "@junejs/pdf-font-noto-sans-kr";
|
|
6
|
+
// typstWasmRenderer({ fonts: [notoSansKR()] });
|
|
7
|
+
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
|
|
10
|
+
import { createNotoSansKR, FILES, MISSING, type NotoSansKROptions } from "./provider";
|
|
11
|
+
|
|
12
|
+
export type { NotoSansKROptions, NotoSansKRWeight } from "./provider";
|
|
13
|
+
|
|
14
|
+
export function notoSansKR(opts: NotoSansKROptions = {}) {
|
|
15
|
+
return createNotoSansKR(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
|
+
}
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// notoSansKR — a FontProvider (@junejs/pdf-typst-wasm) for Korean that needs no
|
|
2
|
+
// network: Noto Sans CJK's Korea 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, ~4.5 MiB per weight, registered
|
|
5
|
+
// once per renderer.
|
|
6
|
+
//
|
|
7
|
+
// Measured with fontTools: 23,174 code points, among them all 11,172 Hangul syllables and
|
|
8
|
+
// 8,653 Han; with Typst's embedded fonts, every KS X 1001 character except three hanja
|
|
9
|
+
// (U+9699 and the compatibility ideographs U+F95F, U+F9AA).
|
|
10
|
+
// A rare character outside it (隙) is reported by the renderer's missing glyphs check
|
|
11
|
+
// like any other.
|
|
12
|
+
//
|
|
13
|
+
// Each runtime finds the files its own way (node.ts, bun.ts, workerd.ts); this module only
|
|
14
|
+
// turns weights into a provider.
|
|
15
|
+
|
|
16
|
+
import type { FontEgress, FontProvider } from "@junejs/pdf-typst-wasm";
|
|
17
|
+
import type { AssetRef } from "./assets";
|
|
18
|
+
|
|
19
|
+
// The weights Markdown needs: body text, and bold for **strong** and headings.
|
|
20
|
+
export type NotoSansKRWeight = 400 | 700;
|
|
21
|
+
|
|
22
|
+
export type NotoSansKROptions = {
|
|
23
|
+
// Default [400, 700]. Only the listed weights are read and registered, so [400] halves the
|
|
24
|
+
// font memory per renderer; Typst synthesizes bold from the regular. It doesn't shrink a
|
|
25
|
+
// deploy: a Worker upload or a compiled binary carries both files either way.
|
|
26
|
+
weights?: NotoSansKRWeight[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type WeightLoader = (weight: NotoSansKRWeight) => Promise<Uint8Array>;
|
|
30
|
+
|
|
31
|
+
// `egress`: what `load` contacts. The bundled entries read files the package ships: none.
|
|
32
|
+
export function createNotoSansKR(load: WeightLoader, opts: NotoSansKROptions = {}, egress: FontEgress[] = []): FontProvider {
|
|
33
|
+
const weights = [...new Set<NotoSansKRWeight>(opts.weights ?? [400, 700])];
|
|
34
|
+
for (const w of weights) if (w !== 400 && w !== 700) throw new Error(`notoSansKR: no weight ${w as number} (this package ships 400 and 700)`);
|
|
35
|
+
return {
|
|
36
|
+
name: "noto-sans-kr",
|
|
37
|
+
egress,
|
|
38
|
+
persistent: () => Promise.all(weights.map(load)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The upstream release the files come from: Noto Sans CJK's Korea subset OTFs.
|
|
43
|
+
export const TAG = "Sans2.004";
|
|
44
|
+
|
|
45
|
+
const ref = (name: string, sha256: string, size: number): AssetRef => ({
|
|
46
|
+
name,
|
|
47
|
+
sha256,
|
|
48
|
+
size,
|
|
49
|
+
urls: [`https://raw.githubusercontent.com/notofonts/noto-cjk/${TAG}/Sans/SubsetOTF/KR/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/KR/${name}`],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Each weight's file, pinned: scripts/fetch-fonts.ts fetches and checks these, and the
|
|
53
|
+
// unbundled entry checks an app's loader against them (#383).
|
|
54
|
+
export const NOTO_SANS_KR: Record<NotoSansKRWeight, AssetRef> = {
|
|
55
|
+
400: ref("NotoSansKR-Regular.otf", "69975a0ac8472717870aefeab0a4d52739308d90856b9955313b2ad5e0148d68", 4644748),
|
|
56
|
+
700: ref("NotoSansKR-Bold.otf", "5a6ceb287ed2fc6cfc6213144ebea68cbd94b20fc9eb873d8486493bf02d9bda", 4816044),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const FILES: Record<NotoSansKRWeight, string> = { 400: NOTO_SANS_KR[400].name, 700: NOTO_SANS_KR[700].name };
|
|
60
|
+
|
|
61
|
+
export const MISSING = "@junejs/pdf-font-noto-sans-kr: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-kr";
|
package/src/unbundled.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @junejs/pdf-font-noto-sans-kr/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 ~9 MiB whether or not it renders Korean. 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 { notoSansKR } from "@junejs/pdf-font-noto-sans-kr/unbundled";
|
|
8
|
+
// typstWasmRenderer({ load, fonts: [notoSansKR({ 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 { createNotoSansKR, NOTO_SANS_KR, type NotoSansKROptions } from "./provider";
|
|
15
|
+
|
|
16
|
+
export { loadVerified, type AssetLoader, type AssetRef } from "./assets";
|
|
17
|
+
export { NOTO_SANS_KR, type NotoSansKROptions, type NotoSansKRWeight } from "./provider";
|
|
18
|
+
|
|
19
|
+
export type UnbundledNotoSansKROptions = NotoSansKROptions & {
|
|
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_KR).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({ host, sends: "nothing" }));
|
|
28
|
+
|
|
29
|
+
export function notoSansKR(opts: UnbundledNotoSansKROptions) {
|
|
30
|
+
const { load, egress, ...rest } = opts;
|
|
31
|
+
return createNotoSansKR((weight) => loadVerified(NOTO_SANS_KR[weight], load), rest, egress ?? HOSTS);
|
|
32
|
+
}
|
package/src/workerd.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @junejs/pdf-font-noto-sans-kr 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 ~9 MiB to the Worker, next to the engine's 29 MiB, under the 64 MiB limit. Wrangler
|
|
4
|
+
// needs a rule for the extension; `june build` emits it (#379), and an app running wrangler
|
|
5
|
+
// on its own config adds it:
|
|
6
|
+
//
|
|
7
|
+
// "rules": [{ "type": "Data", "globs": ["**/*.otf"], "fallthrough": true }]
|
|
8
|
+
|
|
9
|
+
import bold from "../fonts/NotoSansKR-Bold.otf";
|
|
10
|
+
import regular from "../fonts/NotoSansKR-Regular.otf";
|
|
11
|
+
import { createNotoSansKR, type NotoSansKROptions } from "./provider";
|
|
12
|
+
|
|
13
|
+
export type { NotoSansKROptions, NotoSansKRWeight } from "./provider";
|
|
14
|
+
|
|
15
|
+
export function notoSansKR(opts: NotoSansKROptions = {}) {
|
|
16
|
+
return createNotoSansKR(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
|
|
17
|
+
}
|
package/README.md
DELETED