@junejs/pdf-font-noto-sans-jp 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 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 NotoSansJPOptions, r as NotoSansJPWeight } from "./provider-BQunweLO.js";
2
+ //#region src/node.d.ts
3
+ export declare function notoSansJP(opts?: NotoSansJPOptions): import("@junejs/pdf-typst-wasm").FontProvider;
4
+ //#endregion
5
+ export type { NotoSansJPOptions, NotoSansJPWeight };
package/dist/node.js ADDED
@@ -0,0 +1,14 @@
1
+ import { i as createNotoSansJP, n as MISSING, t as FILES } from "./provider-DXfXGRsb.js";
2
+ import { readFile } from "node:fs/promises";
3
+ //#region src/node.ts
4
+ function notoSansJP(opts = {}) {
5
+ return createNotoSansJP(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 { notoSansJP };
@@ -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 NotoSansJPWeight = 400 | 700;
14
+ type NotoSansJPOptions = {
15
+ weights?: NotoSansJPWeight[];
16
+ };
17
+ declare const NOTO_SANS_JP: Record<NotoSansJPWeight, AssetRef>;
18
+ //#endregion
19
+ export { AssetRef as a, AssetLoader as i, NotoSansJPOptions as n, loadVerified as o, NotoSansJPWeight as r, NOTO_SANS_JP as t };
@@ -0,0 +1,28 @@
1
+ //#region src/provider.ts
2
+ function createNotoSansJP(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(`notoSansJP: no weight ${w} (this package ships 400 and 700)`);
5
+ return {
6
+ name: "noto-sans-jp",
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/JP/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/JP/${name}`]
17
+ });
18
+ const NOTO_SANS_JP = {
19
+ 400: ref("NotoSansJP-Regular.otf", "dff723ba59d57d136764a04b9b2d03205544f7cd785a711442d6d2d085ac5073", 4533028),
20
+ 700: ref("NotoSansJP-Bold.otf", "1b0edfb500b73a4fa8a4fcaae1bbbd403994e08e73e3e0da37e70d3853f42c5f", 4656448)
21
+ };
22
+ const FILES = {
23
+ 400: NOTO_SANS_JP[400].name,
24
+ 700: NOTO_SANS_JP[700].name
25
+ };
26
+ const MISSING = "@junejs/pdf-font-noto-sans-jp: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-jp";
27
+ //#endregion
28
+ export { createNotoSansJP as i, MISSING as n, NOTO_SANS_JP as r, FILES as t };
@@ -0,0 +1,10 @@
1
+ import { a as AssetRef, i as AssetLoader, n as NotoSansJPOptions, o as loadVerified, r as NotoSansJPWeight, t as NOTO_SANS_JP } from "./provider-BQunweLO.js";
2
+ import { FontEgress } from "@junejs/pdf-typst-wasm";
3
+ //#region src/unbundled.d.ts
4
+ export type UnbundledNotoSansJPOptions = NotoSansJPOptions & {
5
+ load: AssetLoader;
6
+ egress?: FontEgress[];
7
+ };
8
+ export declare function notoSansJP(opts: UnbundledNotoSansJPOptions): import("@junejs/pdf-typst-wasm").FontProvider;
9
+ //#endregion
10
+ export { type AssetLoader, type AssetRef, NOTO_SANS_JP, type NotoSansJPOptions, type NotoSansJPWeight, loadVerified };
@@ -0,0 +1,23 @@
1
+ import { i as createNotoSansJP, r as NOTO_SANS_JP } from "./provider-DXfXGRsb.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_JP).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({
15
+ host,
16
+ sends: "nothing"
17
+ }));
18
+ function notoSansJP(opts) {
19
+ const { load, egress, ...rest } = opts;
20
+ return createNotoSansJP((weight) => loadVerified(NOTO_SANS_JP[weight], load), rest, egress ?? HOSTS);
21
+ }
22
+ //#endregion
23
+ export { NOTO_SANS_JP, loadVerified, notoSansJP };
@@ -0,0 +1,5 @@
1
+ import { n as NotoSansJPOptions, r as NotoSansJPWeight } from "./provider-BQunweLO.js";
2
+ //#region src/workerd.d.ts
3
+ export declare function notoSansJP(opts?: NotoSansJPOptions): import("@junejs/pdf-typst-wasm").FontProvider;
4
+ //#endregion
5
+ export type { NotoSansJPOptions, NotoSansJPWeight };
@@ -0,0 +1,9 @@
1
+ import { i as createNotoSansJP } from "./provider-DXfXGRsb.js";
2
+ import bold from "../fonts/NotoSansJP-Bold.otf";
3
+ import regular from "../fonts/NotoSansJP-Regular.otf";
4
+ //#region src/workerd.ts
5
+ function notoSansJP(opts = {}) {
6
+ return createNotoSansJP(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
7
+ }
8
+ //#endregion
9
+ export { notoSansJP };
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@junejs/pdf-font-noto-sans-jp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "June — Noto Sans JP (Japanese, 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
+ "japanese"
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-jp"
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-jp 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 { createNotoSansJP, MISSING, type NotoSansJPOptions, type NotoSansJPWeight } from "./provider";
9
+
10
+ export type { NotoSansJPOptions, NotoSansJPWeight } 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<NotoSansJPWeight, () => FileImport> = {
15
+ 400: () => import("../fonts/NotoSansJP-Regular.otf", { with: { type: "file" } }),
16
+ 700: () => import("../fonts/NotoSansJP-Bold.otf", { with: { type: "file" } }),
17
+ };
18
+
19
+ export function notoSansJP(opts: NotoSansJPOptions = {}) {
20
+ return createNotoSansJP(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-jp 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 { notoSansJP } from "@junejs/pdf-font-noto-sans-jp";
6
+ // typstWasmRenderer({ fonts: [notoSansJP()] });
7
+
8
+ import { readFile } from "node:fs/promises";
9
+
10
+ import { createNotoSansJP, FILES, MISSING, type NotoSansJPOptions } from "./provider";
11
+
12
+ export type { NotoSansJPOptions, NotoSansJPWeight } from "./provider";
13
+
14
+ export function notoSansJP(opts: NotoSansJPOptions = {}) {
15
+ return createNotoSansJP(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,61 @@
1
+ // notoSansJP — a FontProvider (@junejs/pdf-typst-wasm) for Japanese that needs no
2
+ // network: Noto Sans CJK's Japan 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.4 MiB per weight, registered
5
+ // once per renderer.
6
+ //
7
+ // The subset is not every CJK ideograph. Measured with fontTools: 16,732 code points, 13,742
8
+ // of them Han; with Typst's embedded fonts, every JIS X 0213 character (the subset alone lacks
9
+ // 162 of them, none Han, all covered by the embedded fonts).
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 NotoSansJPWeight = 400 | 700;
21
+
22
+ export type NotoSansJPOptions = {
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?: NotoSansJPWeight[];
27
+ };
28
+
29
+ export type WeightLoader = (weight: NotoSansJPWeight) => Promise<Uint8Array>;
30
+
31
+ // `egress`: what `load` contacts. The bundled entries read files the package ships: none.
32
+ export function createNotoSansJP(load: WeightLoader, opts: NotoSansJPOptions = {}, egress: FontEgress[] = []): FontProvider {
33
+ const weights = [...new Set<NotoSansJPWeight>(opts.weights ?? [400, 700])];
34
+ for (const w of weights) if (w !== 400 && w !== 700) throw new Error(`notoSansJP: no weight ${w as number} (this package ships 400 and 700)`);
35
+ return {
36
+ name: "noto-sans-jp",
37
+ egress,
38
+ persistent: () => Promise.all(weights.map(load)),
39
+ };
40
+ }
41
+
42
+ // The upstream release the files come from: Noto Sans CJK's Japan 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/JP/${name}`, `https://cdn.jsdelivr.net/gh/notofonts/noto-cjk@${TAG}/Sans/SubsetOTF/JP/${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_JP: Record<NotoSansJPWeight, AssetRef> = {
55
+ 400: ref("NotoSansJP-Regular.otf", "dff723ba59d57d136764a04b9b2d03205544f7cd785a711442d6d2d085ac5073", 4533028),
56
+ 700: ref("NotoSansJP-Bold.otf", "1b0edfb500b73a4fa8a4fcaae1bbbd403994e08e73e3e0da37e70d3853f42c5f", 4656448),
57
+ };
58
+
59
+ export const FILES: Record<NotoSansJPWeight, string> = { 400: NOTO_SANS_JP[400].name, 700: NOTO_SANS_JP[700].name };
60
+
61
+ export const MISSING = "@junejs/pdf-font-noto-sans-jp: its font files are missing — in the June repo, run `bun scripts/fetch-fonts.ts` in packages/pdf-font-noto-sans-jp";
@@ -0,0 +1,32 @@
1
+ // @junejs/pdf-font-noto-sans-jp/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 Japanese. 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 { notoSansJP } from "@junejs/pdf-font-noto-sans-jp/unbundled";
8
+ // typstWasmRenderer({ load, fonts: [notoSansJP({ 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 { createNotoSansJP, NOTO_SANS_JP, type NotoSansJPOptions } from "./provider";
15
+
16
+ export { loadVerified, type AssetLoader, type AssetRef } from "./assets";
17
+ export { NOTO_SANS_JP, type NotoSansJPOptions, type NotoSansJPWeight } from "./provider";
18
+
19
+ export type UnbundledNotoSansJPOptions = NotoSansJPOptions & {
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_JP).flatMap((r) => r.urls.map((u) => new URL(u).host)))].map((host) => ({ host, sends: "nothing" }));
28
+
29
+ export function notoSansJP(opts: UnbundledNotoSansJPOptions) {
30
+ const { load, egress, ...rest } = opts;
31
+ return createNotoSansJP((weight) => loadVerified(NOTO_SANS_JP[weight], load), rest, egress ?? HOSTS);
32
+ }
package/src/workerd.ts ADDED
@@ -0,0 +1,17 @@
1
+ // @junejs/pdf-font-noto-sans-jp 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/NotoSansJP-Bold.otf";
10
+ import regular from "../fonts/NotoSansJP-Regular.otf";
11
+ import { createNotoSansJP, type NotoSansJPOptions } from "./provider";
12
+
13
+ export type { NotoSansJPOptions, NotoSansJPWeight } from "./provider";
14
+
15
+ export function notoSansJP(opts: NotoSansJPOptions = {}) {
16
+ return createNotoSansJP(async (weight) => new Uint8Array(weight === 700 ? bold : regular), opts);
17
+ }
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.