@docx-editor.dev/fonts-cjk 2.29.0 → 2.31.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/README.md +21 -3
- package/dist/browser.cjs +226 -0
- package/dist/browser.d.cts +166 -0
- package/dist/browser.d.ts +166 -0
- package/dist/browser.js +150 -0
- package/dist/chunk-C6F6KNLC.js +58 -0
- package/dist/families-DKqfn8DD.d.cts +28 -0
- package/dist/families-DKqfn8DD.d.ts +28 -0
- package/dist/index.cjs +60 -4
- package/dist/index.d.cts +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.js +8 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
# @docx-editor.dev/fonts-cjk
|
|
12
12
|
|
|
13
|
-
This package supplies Noto Sans CJK JP for Chinese, Japanese, and Korean text. The [`@docx-editor.dev/docx-to-pdf`](https://www.npmjs.com/package/@docx-editor.dev/docx-to-pdf) package uses it as an optional fallback. The font file is about 16 MB, so it ships separately.
|
|
13
|
+
This package supplies Noto Sans CJK JP for Chinese, Japanese, and Korean text. The [`@docx-editor.dev/docx-to-pdf`](https://www.npmjs.com/package/@docx-editor.dev/docx-to-pdf) package uses it as an optional fallback, and the editor uses it through the `cjkFonts()` resolver. The font file is about 16 MB, so it ships separately.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -38,14 +38,32 @@ An installed package with missing or unreadable font assets reports `font-origin
|
|
|
38
38
|
|
|
39
39
|
For deployment examples, see [Integrate PDF conversion](../docx-to-pdf/docs/integrations.md).
|
|
40
40
|
|
|
41
|
+
## Use the font in the editor
|
|
42
|
+
|
|
43
|
+
The `@docx-editor.dev/fonts-cjk/browser` entry exports `cjkFonts()`, a font resolver with the same shape as `packagedFonts()` and `googleFonts()` from `@docx-editor.dev/fonts`. Put it after the origins whose fonts you prefer:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { packagedFonts } from '@docx-editor.dev/fonts';
|
|
47
|
+
import { googleFonts } from '@docx-editor.dev/fonts/google';
|
|
48
|
+
import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
|
|
49
|
+
|
|
50
|
+
const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The resolver downloads the font only when a document names one of the `CJK_SUBSTITUTED_FAMILIES`, or one of their localized names in `LOCALIZED_CJK_FAMILIES`. Your bundler emits the font file as an asset, and the resolver fetches it from there. No request goes to a third party. The browser entry is ECMAScript modules only, because it finds the file through `import.meta.url`.
|
|
54
|
+
|
|
55
|
+
A failed download calls the `onFailure` option, or writes a console warning. The document then opens without the font.
|
|
56
|
+
|
|
41
57
|
## Use the font directly
|
|
42
58
|
|
|
43
|
-
The
|
|
59
|
+
The Node.js entry has these public exports:
|
|
44
60
|
|
|
45
61
|
| Export | Type | Value |
|
|
46
62
|
| --- | --- | --- |
|
|
47
63
|
| `NOTO_SANS_CJK_JP_FAMILY` | String literal | `'Noto Sans CJK JP'` |
|
|
48
64
|
| `NOTO_SANS_CJK_JP_URL` | `URL` | A `file:` URL for `assets/NotoSansCJKjp-Regular.otf`. |
|
|
65
|
+
| `CJK_SUBSTITUTED_FAMILIES` | `readonly string[]` | The East Asian families the font stands in for. |
|
|
66
|
+
| `LOCALIZED_CJK_FAMILIES` | `ReadonlyMap<string, string>` | Localized family names, mapped to their English names. |
|
|
49
67
|
|
|
50
68
|
Use the exported URL to read the font without constructing a package path:
|
|
51
69
|
|
|
@@ -60,7 +78,7 @@ const bytes = await readFile(NOTO_SANS_CJK_JP_URL);
|
|
|
60
78
|
console.log(NOTO_SANS_CJK_JP_FAMILY, bytes.byteLength);
|
|
61
79
|
```
|
|
62
80
|
|
|
63
|
-
The
|
|
81
|
+
The Node.js entry does not bundle the font into JavaScript or install a browser font.
|
|
64
82
|
|
|
65
83
|
## Coverage and limits
|
|
66
84
|
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/browser.ts
|
|
21
|
+
var browser_exports = {};
|
|
22
|
+
__export(browser_exports, {
|
|
23
|
+
CJK_SUBSTITUTED_FAMILIES: () => CJK_SUBSTITUTED_FAMILIES,
|
|
24
|
+
LOCALIZED_CJK_FAMILIES: () => LOCALIZED_CJK_FAMILIES,
|
|
25
|
+
NOTO_SANS_CJK_JP_FAMILY: () => NOTO_SANS_CJK_JP_FAMILY,
|
|
26
|
+
cjkFonts: () => cjkFonts
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(browser_exports);
|
|
29
|
+
|
|
30
|
+
// src/families.ts
|
|
31
|
+
var NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
32
|
+
var NOTO_SANS_CJK_JP_SHA256 = "68a3fc98800b2a27b371f2fb79991daf3633bd89309d4ffaa6946fd587f375b5";
|
|
33
|
+
var CJK_SUBSTITUTED_FAMILIES = Object.freeze([
|
|
34
|
+
"MS Gothic",
|
|
35
|
+
"MS PGothic",
|
|
36
|
+
"MS UI Gothic",
|
|
37
|
+
"MS Mincho",
|
|
38
|
+
"MS PMincho",
|
|
39
|
+
"Meiryo",
|
|
40
|
+
"Yu Gothic",
|
|
41
|
+
"Yu Mincho",
|
|
42
|
+
"SimSun",
|
|
43
|
+
"NSimSun",
|
|
44
|
+
"SimHei",
|
|
45
|
+
"FangSong",
|
|
46
|
+
"KaiTi",
|
|
47
|
+
"DengXian",
|
|
48
|
+
"Microsoft YaHei",
|
|
49
|
+
"Microsoft JhengHei",
|
|
50
|
+
"MingLiU",
|
|
51
|
+
"PMingLiU",
|
|
52
|
+
"Batang",
|
|
53
|
+
"Gulim",
|
|
54
|
+
"Dotum",
|
|
55
|
+
"Malgun Gothic"
|
|
56
|
+
]);
|
|
57
|
+
var LOCALIZED_CJK_FAMILIES = /* @__PURE__ */ new Map([
|
|
58
|
+
["\u5B8B\u4F53", "SimSun"],
|
|
59
|
+
["\u65B0\u5B8B\u4F53", "NSimSun"],
|
|
60
|
+
["\u9ED1\u4F53", "SimHei"],
|
|
61
|
+
["\u4EFF\u5B8B", "FangSong"],
|
|
62
|
+
["\u6977\u4F53", "KaiTi"],
|
|
63
|
+
["\u7B49\u7EBF", "DengXian"],
|
|
64
|
+
["\u5FAE\u8F6F\u96C5\u9ED1", "Microsoft YaHei"],
|
|
65
|
+
["\u5FAE\u8EDF\u6B63\u9ED1\u9AD4", "Microsoft JhengHei"],
|
|
66
|
+
["\u65B0\u7D30\u660E\u9AD4", "PMingLiU"],
|
|
67
|
+
["\u7D30\u660E\u9AD4", "MingLiU"],
|
|
68
|
+
["\uFF2D\uFF33 \u660E\u671D", "MS Mincho"],
|
|
69
|
+
["\uFF2D\uFF33 \uFF30\u660E\u671D", "MS PMincho"],
|
|
70
|
+
["\uFF2D\uFF33 \u30B4\u30B7\u30C3\u30AF", "MS Gothic"],
|
|
71
|
+
["\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", "MS PGothic"],
|
|
72
|
+
["\uFF2D\uFF33 \uFF35\uFF29 \uFF27\uFF4F\uFF54\uFF48\uFF49\uFF43", "MS UI Gothic"],
|
|
73
|
+
["\u30E1\u30A4\u30EA\u30AA", "Meiryo"],
|
|
74
|
+
["\u6E38\u30B4\u30B7\u30C3\u30AF", "Yu Gothic"],
|
|
75
|
+
["\u6E38\u660E\u671D", "Yu Mincho"],
|
|
76
|
+
["\uB9D1\uC740 \uACE0\uB515", "Malgun Gothic"],
|
|
77
|
+
["\uBC14\uD0D5", "Batang"],
|
|
78
|
+
["\uAD74\uB9BC", "Gulim"],
|
|
79
|
+
["\uB3CB\uC6C0", "Dotum"]
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
// src/browser.ts
|
|
83
|
+
var import_meta = {};
|
|
84
|
+
var faceLocation = () => new URL("../assets/NotoSansCJKjp-Regular.otf", import_meta.url);
|
|
85
|
+
var FONT_RESOLVER_BRAND = /* @__PURE__ */ Symbol.for("docx-editor.dev/font-resolver");
|
|
86
|
+
var FONT_RESOLVER_MARK_KEY = "docx-editor.dev/font-resolver";
|
|
87
|
+
var SUBSTITUTED = new Map([
|
|
88
|
+
...CJK_SUBSTITUTED_FAMILIES.map((family) => [family.toLowerCase(), family]),
|
|
89
|
+
...[...LOCALIZED_CJK_FAMILIES.keys()].map(
|
|
90
|
+
(localized) => [localized.toLowerCase(), localized]
|
|
91
|
+
)
|
|
92
|
+
]);
|
|
93
|
+
var FACES = [
|
|
94
|
+
[400, "normal"],
|
|
95
|
+
[700, "normal"],
|
|
96
|
+
[400, "italic"],
|
|
97
|
+
[700, "italic"]
|
|
98
|
+
];
|
|
99
|
+
var PACKAGED_FACE = {
|
|
100
|
+
family: NOTO_SANS_CJK_JP_FAMILY,
|
|
101
|
+
weight: 400,
|
|
102
|
+
style: "normal"
|
|
103
|
+
};
|
|
104
|
+
var defaultFetch = ((input, init) => globalThis.fetch(input, init));
|
|
105
|
+
var loadsByFetcher = /* @__PURE__ */ new WeakMap();
|
|
106
|
+
function startLoad(fetcher, url) {
|
|
107
|
+
const controller = new AbortController();
|
|
108
|
+
const load = {
|
|
109
|
+
controller,
|
|
110
|
+
waiters: 0,
|
|
111
|
+
settled: false,
|
|
112
|
+
bytes: fetcher(url, { signal: controller.signal }).then((response) => {
|
|
113
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
114
|
+
return response.arrayBuffer();
|
|
115
|
+
}).then((buffer) => new Uint8Array(buffer))
|
|
116
|
+
};
|
|
117
|
+
load.bytes.then(
|
|
118
|
+
() => {
|
|
119
|
+
load.settled = true;
|
|
120
|
+
},
|
|
121
|
+
() => {
|
|
122
|
+
load.settled = true;
|
|
123
|
+
if (loadsByFetcher.get(fetcher) === load) loadsByFetcher.delete(fetcher);
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
loadsByFetcher.set(fetcher, load);
|
|
127
|
+
return load;
|
|
128
|
+
}
|
|
129
|
+
function loadFace(fetcher, url, signal) {
|
|
130
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
131
|
+
const load = loadsByFetcher.get(fetcher) ?? startLoad(fetcher, url);
|
|
132
|
+
load.waiters += 1;
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
let left = false;
|
|
135
|
+
const leave = () => {
|
|
136
|
+
if (left) return;
|
|
137
|
+
left = true;
|
|
138
|
+
signal?.removeEventListener("abort", onAbort);
|
|
139
|
+
load.waiters -= 1;
|
|
140
|
+
};
|
|
141
|
+
const onAbort = () => {
|
|
142
|
+
leave();
|
|
143
|
+
if (load.waiters === 0 && !load.settled) {
|
|
144
|
+
if (loadsByFetcher.get(fetcher) === load) loadsByFetcher.delete(fetcher);
|
|
145
|
+
load.controller.abort(signal.reason);
|
|
146
|
+
}
|
|
147
|
+
reject(signal.reason);
|
|
148
|
+
};
|
|
149
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
150
|
+
load.bytes.then(
|
|
151
|
+
(bytes) => {
|
|
152
|
+
leave();
|
|
153
|
+
resolve(bytes);
|
|
154
|
+
},
|
|
155
|
+
(error) => {
|
|
156
|
+
leave();
|
|
157
|
+
reject(error);
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function cjkFonts(options = {}) {
|
|
163
|
+
async function resolveCjkFonts(request) {
|
|
164
|
+
const painted = new Set(
|
|
165
|
+
(request.resolvedFaces ?? []).filter((face) => face.weight === 400 && face.style === "normal").map((face) => face.family.trim().toLowerCase())
|
|
166
|
+
);
|
|
167
|
+
const planned = request.families.filter((family) => {
|
|
168
|
+
const key = family.trim().toLowerCase();
|
|
169
|
+
return SUBSTITUTED.has(key) && !painted.has(key);
|
|
170
|
+
});
|
|
171
|
+
const named = request.families.some(
|
|
172
|
+
(family) => family.trim().toLowerCase() === NOTO_SANS_CJK_JP_FAMILY.toLowerCase()
|
|
173
|
+
);
|
|
174
|
+
if (planned.length === 0 && !named) return { sources: [], substitutions: [] };
|
|
175
|
+
if (painted.has(NOTO_SANS_CJK_JP_FAMILY.toLowerCase())) {
|
|
176
|
+
return { sources: [], substitutions: substitutionsFor(planned) };
|
|
177
|
+
}
|
|
178
|
+
const fetcher = options.fetcher ?? defaultFetch;
|
|
179
|
+
let url = "";
|
|
180
|
+
let bytes;
|
|
181
|
+
try {
|
|
182
|
+
const location = faceLocation();
|
|
183
|
+
url = typeof location === "string" ? location : location.href;
|
|
184
|
+
bytes = await loadFace(fetcher, url, request.signal);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
187
|
+
const failure = {
|
|
188
|
+
family: NOTO_SANS_CJK_JP_FAMILY,
|
|
189
|
+
url,
|
|
190
|
+
diagnostic: error instanceof Error ? error.message : String(error)
|
|
191
|
+
};
|
|
192
|
+
if (options.onFailure) options.onFailure(failure);
|
|
193
|
+
else console.warn(`[fonts-cjk] ${failure.family} (${failure.url}): ${failure.diagnostic}`);
|
|
194
|
+
return { sources: [], substitutions: [] };
|
|
195
|
+
}
|
|
196
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
197
|
+
return {
|
|
198
|
+
sources: [
|
|
199
|
+
{
|
|
200
|
+
request: PACKAGED_FACE,
|
|
201
|
+
id: "fonts-cjk:noto-sans-cjk-jp#400#normal",
|
|
202
|
+
bytes,
|
|
203
|
+
hash: `sha256:${NOTO_SANS_CJK_JP_SHA256}`,
|
|
204
|
+
faceIndex: 0
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
substitutions: substitutionsFor(planned)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const descriptor = { value: true, enumerable: false, configurable: true };
|
|
211
|
+
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_BRAND, descriptor);
|
|
212
|
+
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_MARK_KEY, descriptor);
|
|
213
|
+
return resolveCjkFonts;
|
|
214
|
+
}
|
|
215
|
+
function substitutionsFor(families) {
|
|
216
|
+
return families.flatMap(
|
|
217
|
+
(family) => FACES.map(([weight, style]) => ({ from: { family, weight, style }, to: PACKAGED_FACE }))
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
222
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
223
|
+
LOCALIZED_CJK_FAMILIES,
|
|
224
|
+
NOTO_SANS_CJK_JP_FAMILY,
|
|
225
|
+
cjkFonts
|
|
226
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The packaged CJK face for the editor in a browser: a font resolver that composes next to
|
|
3
|
+
* `packagedFonts()` and `googleFonts()` from `@docx-editor.dev/fonts`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { packagedFonts } from '@docx-editor.dev/fonts';
|
|
7
|
+
* import { googleFonts } from '@docx-editor.dev/fonts/google';
|
|
8
|
+
* import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
|
|
9
|
+
*
|
|
10
|
+
* const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export { C as CJK_SUBSTITUTED_FAMILIES, L as LOCALIZED_CJK_FAMILIES, N as NOTO_SANS_CJK_JP_FAMILY } from './families-DKqfn8DD.cjs';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The packaged CJK face for the editor in a browser: a font resolver that composes next to
|
|
20
|
+
* `packagedFonts()` and `googleFonts()` from `@docx-editor.dev/fonts`.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { packagedFonts } from '@docx-editor.dev/fonts';
|
|
24
|
+
* import { googleFonts } from '@docx-editor.dev/fonts/google';
|
|
25
|
+
* import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
|
|
26
|
+
*
|
|
27
|
+
* const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @packageDocumentation
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One face an earlier origin in the same composition can already paint, structurally the
|
|
36
|
+
* editor contract's `FontFaceRequest`.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
interface CjkResolvedFontFace {
|
|
41
|
+
/** The family name, matched case-insensitively. */
|
|
42
|
+
readonly family: string;
|
|
43
|
+
/** CSS numeric weight. */
|
|
44
|
+
readonly weight: number;
|
|
45
|
+
/** Whether this is the upright or the italic face. */
|
|
46
|
+
readonly style: 'normal' | 'italic';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The request the resolver takes, structurally the editor contract's `FontResolutionRequest`.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface CjkFontsRequest {
|
|
54
|
+
/** Families the document declares, already name-validated and capped by the engine. */
|
|
55
|
+
readonly families: readonly string[];
|
|
56
|
+
/** The face a run naming no font resolves to. */
|
|
57
|
+
readonly defaultFamily: string;
|
|
58
|
+
/** Cancels the request. The resolver rejects with `signal.reason`. */
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
/** Faces an earlier origin in the same composition can already paint. */
|
|
61
|
+
readonly resolvedFaces?: readonly CjkResolvedFontFace[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A face request, structurally the editor contract's `FontFaceRequest`.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
interface CjkFontFaceRequest {
|
|
69
|
+
/** The family name. */
|
|
70
|
+
readonly family: string;
|
|
71
|
+
/** CSS numeric weight. */
|
|
72
|
+
readonly weight: number;
|
|
73
|
+
/** Whether this is the upright or the italic face. */
|
|
74
|
+
readonly style: 'normal' | 'italic';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The packaged face as a font source, structurally the editor contract's `FontSource`.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface CjkFontSource {
|
|
82
|
+
/** The face this source supplies: {@link NOTO_SANS_CJK_JP_FAMILY}, 400, normal. */
|
|
83
|
+
readonly request: CjkFontFaceRequest;
|
|
84
|
+
/** A stable identifier for the source. */
|
|
85
|
+
readonly id: string;
|
|
86
|
+
/** The font file. */
|
|
87
|
+
readonly bytes: Uint8Array;
|
|
88
|
+
/** `sha256:` and the hexadecimal SHA-256 of `bytes`. The editor checks it on admission. */
|
|
89
|
+
readonly hash: string;
|
|
90
|
+
/** Always 0: the file holds one face. */
|
|
91
|
+
readonly faceIndex: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What one resolver call produced, structurally the editor contract's
|
|
95
|
+
* `FontConfigurationFragment`.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
interface CjkFontsFragment {
|
|
100
|
+
/** The packaged face, when the document names a family it stands in for. */
|
|
101
|
+
readonly sources: readonly CjkFontSource[];
|
|
102
|
+
/** Every face of each named East Asian family, pointed at the packaged face. */
|
|
103
|
+
readonly substitutions: readonly {
|
|
104
|
+
readonly from: CjkFontFaceRequest;
|
|
105
|
+
readonly to: CjkFontFaceRequest;
|
|
106
|
+
}[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A fetch of the packaged face that failed for a reason other than cancellation.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
interface CjkFontLoadFailure {
|
|
114
|
+
/** Always {@link NOTO_SANS_CJK_JP_FAMILY}. */
|
|
115
|
+
readonly family: string;
|
|
116
|
+
/** The URL the resolver fetched, or an empty string when it could not build one. */
|
|
117
|
+
readonly url: string;
|
|
118
|
+
/** Why the fetch failed. */
|
|
119
|
+
readonly diagnostic: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for {@link cjkFonts}.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
interface CjkFontsOptions {
|
|
127
|
+
/** Injectable for tests; defaults to the global `fetch`. */
|
|
128
|
+
readonly fetcher?: typeof fetch;
|
|
129
|
+
/** Fetch failures. Defaults to a console warning. The document then opens without the face. */
|
|
130
|
+
readonly onFailure?: (failure: CjkFontLoadFailure) => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The marker the editor reads to call a function per document.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
interface CjkFontResolverMark {
|
|
138
|
+
/** Always `true`. Set non-enumerably. */
|
|
139
|
+
readonly 'docx-editor.dev/font-resolver': true;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* What {@link cjkFonts} returns: a marked resolver over the packaged CJK face.
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
type CjkFontsResolver = ((request: CjkFontsRequest) => Promise<CjkFontsFragment>) & CjkFontResolverMark;
|
|
147
|
+
/**
|
|
148
|
+
* The packaged CJK face, served ON DEMAND: a font resolver that fetches the face only when a
|
|
149
|
+
* document names one of the {@link CJK_SUBSTITUTED_FAMILIES}, in English or in a localized
|
|
150
|
+
* name ({@link LOCALIZED_CJK_FAMILIES}), or names {@link NOTO_SANS_CJK_JP_FAMILY} itself.
|
|
151
|
+
* A document without one never downloads the 16 MB face.
|
|
152
|
+
*
|
|
153
|
+
* The face has one weight and one style, so every face of a named family points at it. Put
|
|
154
|
+
* it after the origins whose faces you prefer: a family an earlier origin already paints is
|
|
155
|
+
* left to that origin.
|
|
156
|
+
*
|
|
157
|
+
* The face is the file inside this package, fetched from where your bundler emits it. Nothing
|
|
158
|
+
* comes from a third party. A failed fetch reports through `onFailure` and the document opens
|
|
159
|
+
* without the face; cancellation rejects with `signal.reason`.
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
declare function cjkFonts(options?: CjkFontsOptions): CjkFontsResolver;
|
|
164
|
+
|
|
165
|
+
export { cjkFonts };
|
|
166
|
+
export type { CjkFontFaceRequest, CjkFontLoadFailure, CjkFontResolverMark, CjkFontSource, CjkFontsFragment, CjkFontsOptions, CjkFontsRequest, CjkFontsResolver, CjkResolvedFontFace };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The packaged CJK face for the editor in a browser: a font resolver that composes next to
|
|
3
|
+
* `packagedFonts()` and `googleFonts()` from `@docx-editor.dev/fonts`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { packagedFonts } from '@docx-editor.dev/fonts';
|
|
7
|
+
* import { googleFonts } from '@docx-editor.dev/fonts/google';
|
|
8
|
+
* import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
|
|
9
|
+
*
|
|
10
|
+
* const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export { C as CJK_SUBSTITUTED_FAMILIES, L as LOCALIZED_CJK_FAMILIES, N as NOTO_SANS_CJK_JP_FAMILY } from './families-DKqfn8DD.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The packaged CJK face for the editor in a browser: a font resolver that composes next to
|
|
20
|
+
* `packagedFonts()` and `googleFonts()` from `@docx-editor.dev/fonts`.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { packagedFonts } from '@docx-editor.dev/fonts';
|
|
24
|
+
* import { googleFonts } from '@docx-editor.dev/fonts/google';
|
|
25
|
+
* import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
|
|
26
|
+
*
|
|
27
|
+
* const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @packageDocumentation
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One face an earlier origin in the same composition can already paint, structurally the
|
|
36
|
+
* editor contract's `FontFaceRequest`.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
interface CjkResolvedFontFace {
|
|
41
|
+
/** The family name, matched case-insensitively. */
|
|
42
|
+
readonly family: string;
|
|
43
|
+
/** CSS numeric weight. */
|
|
44
|
+
readonly weight: number;
|
|
45
|
+
/** Whether this is the upright or the italic face. */
|
|
46
|
+
readonly style: 'normal' | 'italic';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The request the resolver takes, structurally the editor contract's `FontResolutionRequest`.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface CjkFontsRequest {
|
|
54
|
+
/** Families the document declares, already name-validated and capped by the engine. */
|
|
55
|
+
readonly families: readonly string[];
|
|
56
|
+
/** The face a run naming no font resolves to. */
|
|
57
|
+
readonly defaultFamily: string;
|
|
58
|
+
/** Cancels the request. The resolver rejects with `signal.reason`. */
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
/** Faces an earlier origin in the same composition can already paint. */
|
|
61
|
+
readonly resolvedFaces?: readonly CjkResolvedFontFace[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A face request, structurally the editor contract's `FontFaceRequest`.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
interface CjkFontFaceRequest {
|
|
69
|
+
/** The family name. */
|
|
70
|
+
readonly family: string;
|
|
71
|
+
/** CSS numeric weight. */
|
|
72
|
+
readonly weight: number;
|
|
73
|
+
/** Whether this is the upright or the italic face. */
|
|
74
|
+
readonly style: 'normal' | 'italic';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The packaged face as a font source, structurally the editor contract's `FontSource`.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface CjkFontSource {
|
|
82
|
+
/** The face this source supplies: {@link NOTO_SANS_CJK_JP_FAMILY}, 400, normal. */
|
|
83
|
+
readonly request: CjkFontFaceRequest;
|
|
84
|
+
/** A stable identifier for the source. */
|
|
85
|
+
readonly id: string;
|
|
86
|
+
/** The font file. */
|
|
87
|
+
readonly bytes: Uint8Array;
|
|
88
|
+
/** `sha256:` and the hexadecimal SHA-256 of `bytes`. The editor checks it on admission. */
|
|
89
|
+
readonly hash: string;
|
|
90
|
+
/** Always 0: the file holds one face. */
|
|
91
|
+
readonly faceIndex: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What one resolver call produced, structurally the editor contract's
|
|
95
|
+
* `FontConfigurationFragment`.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
interface CjkFontsFragment {
|
|
100
|
+
/** The packaged face, when the document names a family it stands in for. */
|
|
101
|
+
readonly sources: readonly CjkFontSource[];
|
|
102
|
+
/** Every face of each named East Asian family, pointed at the packaged face. */
|
|
103
|
+
readonly substitutions: readonly {
|
|
104
|
+
readonly from: CjkFontFaceRequest;
|
|
105
|
+
readonly to: CjkFontFaceRequest;
|
|
106
|
+
}[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A fetch of the packaged face that failed for a reason other than cancellation.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
interface CjkFontLoadFailure {
|
|
114
|
+
/** Always {@link NOTO_SANS_CJK_JP_FAMILY}. */
|
|
115
|
+
readonly family: string;
|
|
116
|
+
/** The URL the resolver fetched, or an empty string when it could not build one. */
|
|
117
|
+
readonly url: string;
|
|
118
|
+
/** Why the fetch failed. */
|
|
119
|
+
readonly diagnostic: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for {@link cjkFonts}.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
interface CjkFontsOptions {
|
|
127
|
+
/** Injectable for tests; defaults to the global `fetch`. */
|
|
128
|
+
readonly fetcher?: typeof fetch;
|
|
129
|
+
/** Fetch failures. Defaults to a console warning. The document then opens without the face. */
|
|
130
|
+
readonly onFailure?: (failure: CjkFontLoadFailure) => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The marker the editor reads to call a function per document.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
interface CjkFontResolverMark {
|
|
138
|
+
/** Always `true`. Set non-enumerably. */
|
|
139
|
+
readonly 'docx-editor.dev/font-resolver': true;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* What {@link cjkFonts} returns: a marked resolver over the packaged CJK face.
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
type CjkFontsResolver = ((request: CjkFontsRequest) => Promise<CjkFontsFragment>) & CjkFontResolverMark;
|
|
147
|
+
/**
|
|
148
|
+
* The packaged CJK face, served ON DEMAND: a font resolver that fetches the face only when a
|
|
149
|
+
* document names one of the {@link CJK_SUBSTITUTED_FAMILIES}, in English or in a localized
|
|
150
|
+
* name ({@link LOCALIZED_CJK_FAMILIES}), or names {@link NOTO_SANS_CJK_JP_FAMILY} itself.
|
|
151
|
+
* A document without one never downloads the 16 MB face.
|
|
152
|
+
*
|
|
153
|
+
* The face has one weight and one style, so every face of a named family points at it. Put
|
|
154
|
+
* it after the origins whose faces you prefer: a family an earlier origin already paints is
|
|
155
|
+
* left to that origin.
|
|
156
|
+
*
|
|
157
|
+
* The face is the file inside this package, fetched from where your bundler emits it. Nothing
|
|
158
|
+
* comes from a third party. A failed fetch reports through `onFailure` and the document opens
|
|
159
|
+
* without the face; cancellation rejects with `signal.reason`.
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
declare function cjkFonts(options?: CjkFontsOptions): CjkFontsResolver;
|
|
164
|
+
|
|
165
|
+
export { cjkFonts };
|
|
166
|
+
export type { CjkFontFaceRequest, CjkFontLoadFailure, CjkFontResolverMark, CjkFontSource, CjkFontsFragment, CjkFontsOptions, CjkFontsRequest, CjkFontsResolver, CjkResolvedFontFace };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
3
|
+
LOCALIZED_CJK_FAMILIES,
|
|
4
|
+
NOTO_SANS_CJK_JP_FAMILY,
|
|
5
|
+
NOTO_SANS_CJK_JP_SHA256
|
|
6
|
+
} from "./chunk-C6F6KNLC.js";
|
|
7
|
+
|
|
8
|
+
// src/browser.ts
|
|
9
|
+
var faceLocation = () => new URL("../assets/NotoSansCJKjp-Regular.otf", import.meta.url);
|
|
10
|
+
var FONT_RESOLVER_BRAND = /* @__PURE__ */ Symbol.for("docx-editor.dev/font-resolver");
|
|
11
|
+
var FONT_RESOLVER_MARK_KEY = "docx-editor.dev/font-resolver";
|
|
12
|
+
var SUBSTITUTED = new Map([
|
|
13
|
+
...CJK_SUBSTITUTED_FAMILIES.map((family) => [family.toLowerCase(), family]),
|
|
14
|
+
...[...LOCALIZED_CJK_FAMILIES.keys()].map(
|
|
15
|
+
(localized) => [localized.toLowerCase(), localized]
|
|
16
|
+
)
|
|
17
|
+
]);
|
|
18
|
+
var FACES = [
|
|
19
|
+
[400, "normal"],
|
|
20
|
+
[700, "normal"],
|
|
21
|
+
[400, "italic"],
|
|
22
|
+
[700, "italic"]
|
|
23
|
+
];
|
|
24
|
+
var PACKAGED_FACE = {
|
|
25
|
+
family: NOTO_SANS_CJK_JP_FAMILY,
|
|
26
|
+
weight: 400,
|
|
27
|
+
style: "normal"
|
|
28
|
+
};
|
|
29
|
+
var defaultFetch = ((input, init) => globalThis.fetch(input, init));
|
|
30
|
+
var loadsByFetcher = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
function startLoad(fetcher, url) {
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const load = {
|
|
34
|
+
controller,
|
|
35
|
+
waiters: 0,
|
|
36
|
+
settled: false,
|
|
37
|
+
bytes: fetcher(url, { signal: controller.signal }).then((response) => {
|
|
38
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
39
|
+
return response.arrayBuffer();
|
|
40
|
+
}).then((buffer) => new Uint8Array(buffer))
|
|
41
|
+
};
|
|
42
|
+
load.bytes.then(
|
|
43
|
+
() => {
|
|
44
|
+
load.settled = true;
|
|
45
|
+
},
|
|
46
|
+
() => {
|
|
47
|
+
load.settled = true;
|
|
48
|
+
if (loadsByFetcher.get(fetcher) === load) loadsByFetcher.delete(fetcher);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
loadsByFetcher.set(fetcher, load);
|
|
52
|
+
return load;
|
|
53
|
+
}
|
|
54
|
+
function loadFace(fetcher, url, signal) {
|
|
55
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
56
|
+
const load = loadsByFetcher.get(fetcher) ?? startLoad(fetcher, url);
|
|
57
|
+
load.waiters += 1;
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
let left = false;
|
|
60
|
+
const leave = () => {
|
|
61
|
+
if (left) return;
|
|
62
|
+
left = true;
|
|
63
|
+
signal?.removeEventListener("abort", onAbort);
|
|
64
|
+
load.waiters -= 1;
|
|
65
|
+
};
|
|
66
|
+
const onAbort = () => {
|
|
67
|
+
leave();
|
|
68
|
+
if (load.waiters === 0 && !load.settled) {
|
|
69
|
+
if (loadsByFetcher.get(fetcher) === load) loadsByFetcher.delete(fetcher);
|
|
70
|
+
load.controller.abort(signal.reason);
|
|
71
|
+
}
|
|
72
|
+
reject(signal.reason);
|
|
73
|
+
};
|
|
74
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
75
|
+
load.bytes.then(
|
|
76
|
+
(bytes) => {
|
|
77
|
+
leave();
|
|
78
|
+
resolve(bytes);
|
|
79
|
+
},
|
|
80
|
+
(error) => {
|
|
81
|
+
leave();
|
|
82
|
+
reject(error);
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function cjkFonts(options = {}) {
|
|
88
|
+
async function resolveCjkFonts(request) {
|
|
89
|
+
const painted = new Set(
|
|
90
|
+
(request.resolvedFaces ?? []).filter((face) => face.weight === 400 && face.style === "normal").map((face) => face.family.trim().toLowerCase())
|
|
91
|
+
);
|
|
92
|
+
const planned = request.families.filter((family) => {
|
|
93
|
+
const key = family.trim().toLowerCase();
|
|
94
|
+
return SUBSTITUTED.has(key) && !painted.has(key);
|
|
95
|
+
});
|
|
96
|
+
const named = request.families.some(
|
|
97
|
+
(family) => family.trim().toLowerCase() === NOTO_SANS_CJK_JP_FAMILY.toLowerCase()
|
|
98
|
+
);
|
|
99
|
+
if (planned.length === 0 && !named) return { sources: [], substitutions: [] };
|
|
100
|
+
if (painted.has(NOTO_SANS_CJK_JP_FAMILY.toLowerCase())) {
|
|
101
|
+
return { sources: [], substitutions: substitutionsFor(planned) };
|
|
102
|
+
}
|
|
103
|
+
const fetcher = options.fetcher ?? defaultFetch;
|
|
104
|
+
let url = "";
|
|
105
|
+
let bytes;
|
|
106
|
+
try {
|
|
107
|
+
const location = faceLocation();
|
|
108
|
+
url = typeof location === "string" ? location : location.href;
|
|
109
|
+
bytes = await loadFace(fetcher, url, request.signal);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
112
|
+
const failure = {
|
|
113
|
+
family: NOTO_SANS_CJK_JP_FAMILY,
|
|
114
|
+
url,
|
|
115
|
+
diagnostic: error instanceof Error ? error.message : String(error)
|
|
116
|
+
};
|
|
117
|
+
if (options.onFailure) options.onFailure(failure);
|
|
118
|
+
else console.warn(`[fonts-cjk] ${failure.family} (${failure.url}): ${failure.diagnostic}`);
|
|
119
|
+
return { sources: [], substitutions: [] };
|
|
120
|
+
}
|
|
121
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
122
|
+
return {
|
|
123
|
+
sources: [
|
|
124
|
+
{
|
|
125
|
+
request: PACKAGED_FACE,
|
|
126
|
+
id: "fonts-cjk:noto-sans-cjk-jp#400#normal",
|
|
127
|
+
bytes,
|
|
128
|
+
hash: `sha256:${NOTO_SANS_CJK_JP_SHA256}`,
|
|
129
|
+
faceIndex: 0
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
substitutions: substitutionsFor(planned)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const descriptor = { value: true, enumerable: false, configurable: true };
|
|
136
|
+
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_BRAND, descriptor);
|
|
137
|
+
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_MARK_KEY, descriptor);
|
|
138
|
+
return resolveCjkFonts;
|
|
139
|
+
}
|
|
140
|
+
function substitutionsFor(families) {
|
|
141
|
+
return families.flatMap(
|
|
142
|
+
(family) => FACES.map(([weight, style]) => ({ from: { family, weight, style }, to: PACKAGED_FACE }))
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
147
|
+
LOCALIZED_CJK_FAMILIES,
|
|
148
|
+
NOTO_SANS_CJK_JP_FAMILY,
|
|
149
|
+
cjkFonts
|
|
150
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/families.ts
|
|
2
|
+
var NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
3
|
+
var NOTO_SANS_CJK_JP_SHA256 = "68a3fc98800b2a27b371f2fb79991daf3633bd89309d4ffaa6946fd587f375b5";
|
|
4
|
+
var CJK_SUBSTITUTED_FAMILIES = Object.freeze([
|
|
5
|
+
"MS Gothic",
|
|
6
|
+
"MS PGothic",
|
|
7
|
+
"MS UI Gothic",
|
|
8
|
+
"MS Mincho",
|
|
9
|
+
"MS PMincho",
|
|
10
|
+
"Meiryo",
|
|
11
|
+
"Yu Gothic",
|
|
12
|
+
"Yu Mincho",
|
|
13
|
+
"SimSun",
|
|
14
|
+
"NSimSun",
|
|
15
|
+
"SimHei",
|
|
16
|
+
"FangSong",
|
|
17
|
+
"KaiTi",
|
|
18
|
+
"DengXian",
|
|
19
|
+
"Microsoft YaHei",
|
|
20
|
+
"Microsoft JhengHei",
|
|
21
|
+
"MingLiU",
|
|
22
|
+
"PMingLiU",
|
|
23
|
+
"Batang",
|
|
24
|
+
"Gulim",
|
|
25
|
+
"Dotum",
|
|
26
|
+
"Malgun Gothic"
|
|
27
|
+
]);
|
|
28
|
+
var LOCALIZED_CJK_FAMILIES = /* @__PURE__ */ new Map([
|
|
29
|
+
["\u5B8B\u4F53", "SimSun"],
|
|
30
|
+
["\u65B0\u5B8B\u4F53", "NSimSun"],
|
|
31
|
+
["\u9ED1\u4F53", "SimHei"],
|
|
32
|
+
["\u4EFF\u5B8B", "FangSong"],
|
|
33
|
+
["\u6977\u4F53", "KaiTi"],
|
|
34
|
+
["\u7B49\u7EBF", "DengXian"],
|
|
35
|
+
["\u5FAE\u8F6F\u96C5\u9ED1", "Microsoft YaHei"],
|
|
36
|
+
["\u5FAE\u8EDF\u6B63\u9ED1\u9AD4", "Microsoft JhengHei"],
|
|
37
|
+
["\u65B0\u7D30\u660E\u9AD4", "PMingLiU"],
|
|
38
|
+
["\u7D30\u660E\u9AD4", "MingLiU"],
|
|
39
|
+
["\uFF2D\uFF33 \u660E\u671D", "MS Mincho"],
|
|
40
|
+
["\uFF2D\uFF33 \uFF30\u660E\u671D", "MS PMincho"],
|
|
41
|
+
["\uFF2D\uFF33 \u30B4\u30B7\u30C3\u30AF", "MS Gothic"],
|
|
42
|
+
["\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", "MS PGothic"],
|
|
43
|
+
["\uFF2D\uFF33 \uFF35\uFF29 \uFF27\uFF4F\uFF54\uFF48\uFF49\uFF43", "MS UI Gothic"],
|
|
44
|
+
["\u30E1\u30A4\u30EA\u30AA", "Meiryo"],
|
|
45
|
+
["\u6E38\u30B4\u30B7\u30C3\u30AF", "Yu Gothic"],
|
|
46
|
+
["\u6E38\u660E\u671D", "Yu Mincho"],
|
|
47
|
+
["\uB9D1\uC740 \uACE0\uB515", "Malgun Gothic"],
|
|
48
|
+
["\uBC14\uD0D5", "Batang"],
|
|
49
|
+
["\uAD74\uB9BC", "Gulim"],
|
|
50
|
+
["\uB3CB\uC6C0", "Dotum"]
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
NOTO_SANS_CJK_JP_FAMILY,
|
|
55
|
+
NOTO_SANS_CJK_JP_SHA256,
|
|
56
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
57
|
+
LOCALIZED_CJK_FAMILIES
|
|
58
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Family name of the packaged face.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
7
|
+
/**
|
|
8
|
+
* East Asian families the packaged face stands in for when the family itself is missing.
|
|
9
|
+
*
|
|
10
|
+
* The face covers their text, not their metrics: substituting it can change glyph forms,
|
|
11
|
+
* line breaks, and page counts.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare const CJK_SUBSTITUTED_FAMILIES: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Localized names that documents write for the families in {@link CJK_SUBSTITUTED_FAMILIES},
|
|
18
|
+
* each mapped to its English name. A document saved in a Chinese, Japanese, or Korean locale
|
|
19
|
+
* names its East Asian font this way.
|
|
20
|
+
*
|
|
21
|
+
* A `Map`, not an object: the key is file-derived, and a name such as `constructor` must not
|
|
22
|
+
* find a prototype member.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare const LOCALIZED_CJK_FAMILIES: ReadonlyMap<string, string>;
|
|
27
|
+
|
|
28
|
+
export { CJK_SUBSTITUTED_FAMILIES as C, LOCALIZED_CJK_FAMILIES as L, NOTO_SANS_CJK_JP_FAMILY as N };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Family name of the packaged face.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
7
|
+
/**
|
|
8
|
+
* East Asian families the packaged face stands in for when the family itself is missing.
|
|
9
|
+
*
|
|
10
|
+
* The face covers their text, not their metrics: substituting it can change glyph forms,
|
|
11
|
+
* line breaks, and page counts.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare const CJK_SUBSTITUTED_FAMILIES: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Localized names that documents write for the families in {@link CJK_SUBSTITUTED_FAMILIES},
|
|
18
|
+
* each mapped to its English name. A document saved in a Chinese, Japanese, or Korean locale
|
|
19
|
+
* names its East Asian font this way.
|
|
20
|
+
*
|
|
21
|
+
* A `Map`, not an object: the key is file-derived, and a name such as `constructor` must not
|
|
22
|
+
* find a prototype member.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare const LOCALIZED_CJK_FAMILIES: ReadonlyMap<string, string>;
|
|
27
|
+
|
|
28
|
+
export { CJK_SUBSTITUTED_FAMILIES as C, LOCALIZED_CJK_FAMILIES as L, NOTO_SANS_CJK_JP_FAMILY as N };
|
package/dist/index.cjs
CHANGED
|
@@ -18,15 +18,69 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
CJK_SUBSTITUTED_FAMILIES: () => CJK_SUBSTITUTED_FAMILIES,
|
|
24
|
+
LOCALIZED_CJK_FAMILIES: () => LOCALIZED_CJK_FAMILIES,
|
|
23
25
|
NOTO_SANS_CJK_JP_FAMILY: () => NOTO_SANS_CJK_JP_FAMILY,
|
|
24
26
|
NOTO_SANS_CJK_JP_URL: () => NOTO_SANS_CJK_JP_URL
|
|
25
27
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
29
|
var import_node_url = require("url");
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
// src/families.ts
|
|
29
32
|
var NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
33
|
+
var CJK_SUBSTITUTED_FAMILIES = Object.freeze([
|
|
34
|
+
"MS Gothic",
|
|
35
|
+
"MS PGothic",
|
|
36
|
+
"MS UI Gothic",
|
|
37
|
+
"MS Mincho",
|
|
38
|
+
"MS PMincho",
|
|
39
|
+
"Meiryo",
|
|
40
|
+
"Yu Gothic",
|
|
41
|
+
"Yu Mincho",
|
|
42
|
+
"SimSun",
|
|
43
|
+
"NSimSun",
|
|
44
|
+
"SimHei",
|
|
45
|
+
"FangSong",
|
|
46
|
+
"KaiTi",
|
|
47
|
+
"DengXian",
|
|
48
|
+
"Microsoft YaHei",
|
|
49
|
+
"Microsoft JhengHei",
|
|
50
|
+
"MingLiU",
|
|
51
|
+
"PMingLiU",
|
|
52
|
+
"Batang",
|
|
53
|
+
"Gulim",
|
|
54
|
+
"Dotum",
|
|
55
|
+
"Malgun Gothic"
|
|
56
|
+
]);
|
|
57
|
+
var LOCALIZED_CJK_FAMILIES = /* @__PURE__ */ new Map([
|
|
58
|
+
["\u5B8B\u4F53", "SimSun"],
|
|
59
|
+
["\u65B0\u5B8B\u4F53", "NSimSun"],
|
|
60
|
+
["\u9ED1\u4F53", "SimHei"],
|
|
61
|
+
["\u4EFF\u5B8B", "FangSong"],
|
|
62
|
+
["\u6977\u4F53", "KaiTi"],
|
|
63
|
+
["\u7B49\u7EBF", "DengXian"],
|
|
64
|
+
["\u5FAE\u8F6F\u96C5\u9ED1", "Microsoft YaHei"],
|
|
65
|
+
["\u5FAE\u8EDF\u6B63\u9ED1\u9AD4", "Microsoft JhengHei"],
|
|
66
|
+
["\u65B0\u7D30\u660E\u9AD4", "PMingLiU"],
|
|
67
|
+
["\u7D30\u660E\u9AD4", "MingLiU"],
|
|
68
|
+
["\uFF2D\uFF33 \u660E\u671D", "MS Mincho"],
|
|
69
|
+
["\uFF2D\uFF33 \uFF30\u660E\u671D", "MS PMincho"],
|
|
70
|
+
["\uFF2D\uFF33 \u30B4\u30B7\u30C3\u30AF", "MS Gothic"],
|
|
71
|
+
["\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", "MS PGothic"],
|
|
72
|
+
["\uFF2D\uFF33 \uFF35\uFF29 \uFF27\uFF4F\uFF54\uFF48\uFF49\uFF43", "MS UI Gothic"],
|
|
73
|
+
["\u30E1\u30A4\u30EA\u30AA", "Meiryo"],
|
|
74
|
+
["\u6E38\u30B4\u30B7\u30C3\u30AF", "Yu Gothic"],
|
|
75
|
+
["\u6E38\u660E\u671D", "Yu Mincho"],
|
|
76
|
+
["\uB9D1\uC740 \uACE0\uB515", "Malgun Gothic"],
|
|
77
|
+
["\uBC14\uD0D5", "Batang"],
|
|
78
|
+
["\uAD74\uB9BC", "Gulim"],
|
|
79
|
+
["\uB3CB\uC6C0", "Dotum"]
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
// src/index.ts
|
|
83
|
+
var import_meta = {};
|
|
30
84
|
var NOTO_SANS_CJK_JP_URL = new URL(
|
|
31
85
|
"../assets/NotoSansCJKjp-Regular.otf",
|
|
32
86
|
// The CommonJS build has no `import.meta`, and its `__dirname` is the same `dist/`.
|
|
@@ -34,6 +88,8 @@ var NOTO_SANS_CJK_JP_URL = new URL(
|
|
|
34
88
|
);
|
|
35
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
90
|
0 && (module.exports = {
|
|
91
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
92
|
+
LOCALIZED_CJK_FAMILIES,
|
|
37
93
|
NOTO_SANS_CJK_JP_FAMILY,
|
|
38
94
|
NOTO_SANS_CJK_JP_URL
|
|
39
95
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -5,17 +5,14 @@
|
|
|
5
5
|
* The face is about 16 MB, so it ships in its own package. When this package is installed
|
|
6
6
|
* next to `@docx-editor.dev/docx-to-pdf`, PDF export finds it without configuration.
|
|
7
7
|
*
|
|
8
|
-
* Node.js only: the face is a file beside this module, not a bundled asset.
|
|
8
|
+
* Node.js only: the face is a file beside this module, not a bundled asset. For the editor in
|
|
9
|
+
* a browser, use `cjkFonts()` from `@docx-editor.dev/fonts-cjk/browser`.
|
|
9
10
|
*
|
|
10
11
|
* @packageDocumentation
|
|
11
12
|
* @public
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
14
|
+
export { C as CJK_SUBSTITUTED_FAMILIES, L as LOCALIZED_CJK_FAMILIES, N as NOTO_SANS_CJK_JP_FAMILY } from './families-DKqfn8DD.cjs';
|
|
15
|
+
|
|
19
16
|
/**
|
|
20
17
|
* `file:` URL of the packaged face, `NotoSansCJKjp-Regular.otf`: one weight (400), one style
|
|
21
18
|
* (normal), OpenType with CFF outlines.
|
|
@@ -24,4 +21,4 @@ declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
|
24
21
|
*/
|
|
25
22
|
declare const NOTO_SANS_CJK_JP_URL: URL;
|
|
26
23
|
|
|
27
|
-
export {
|
|
24
|
+
export { NOTO_SANS_CJK_JP_URL };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,17 +5,14 @@
|
|
|
5
5
|
* The face is about 16 MB, so it ships in its own package. When this package is installed
|
|
6
6
|
* next to `@docx-editor.dev/docx-to-pdf`, PDF export finds it without configuration.
|
|
7
7
|
*
|
|
8
|
-
* Node.js only: the face is a file beside this module, not a bundled asset.
|
|
8
|
+
* Node.js only: the face is a file beside this module, not a bundled asset. For the editor in
|
|
9
|
+
* a browser, use `cjkFonts()` from `@docx-editor.dev/fonts-cjk/browser`.
|
|
9
10
|
*
|
|
10
11
|
* @packageDocumentation
|
|
11
12
|
* @public
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
14
|
+
export { C as CJK_SUBSTITUTED_FAMILIES, L as LOCALIZED_CJK_FAMILIES, N as NOTO_SANS_CJK_JP_FAMILY } from './families-DKqfn8DD.js';
|
|
15
|
+
|
|
19
16
|
/**
|
|
20
17
|
* `file:` URL of the packaged face, `NotoSansCJKjp-Regular.otf`: one weight (400), one style
|
|
21
18
|
* (normal), OpenType with CFF outlines.
|
|
@@ -24,4 +21,4 @@ declare const NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
|
24
21
|
*/
|
|
25
22
|
declare const NOTO_SANS_CJK_JP_URL: URL;
|
|
26
23
|
|
|
27
|
-
export {
|
|
24
|
+
export { NOTO_SANS_CJK_JP_URL };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
3
|
+
LOCALIZED_CJK_FAMILIES,
|
|
4
|
+
NOTO_SANS_CJK_JP_FAMILY
|
|
5
|
+
} from "./chunk-C6F6KNLC.js";
|
|
6
|
+
|
|
1
7
|
// src/index.ts
|
|
2
8
|
import { pathToFileURL } from "url";
|
|
3
|
-
var NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP";
|
|
4
9
|
var NOTO_SANS_CJK_JP_URL = new URL(
|
|
5
10
|
"../assets/NotoSansCJKjp-Regular.otf",
|
|
6
11
|
// The CommonJS build has no `import.meta`, and its `__dirname` is the same `dist/`.
|
|
7
12
|
typeof __dirname === "string" ? pathToFileURL(__dirname + "/").href : import.meta.url
|
|
8
13
|
);
|
|
9
14
|
export {
|
|
15
|
+
CJK_SUBSTITUTED_FAMILIES,
|
|
16
|
+
LOCALIZED_CJK_FAMILIES,
|
|
10
17
|
NOTO_SANS_CJK_JP_FAMILY,
|
|
11
18
|
NOTO_SANS_CJK_JP_URL
|
|
12
19
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docx-editor.dev/fonts-cjk",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Noto Sans CJK JP fallback font for Chinese, Japanese, and Korean text in @docx-editor.dev/docx-to-pdf.",
|
|
3
|
+
"version": "2.31.0",
|
|
4
|
+
"description": "Noto Sans CJK JP fallback font for Chinese, Japanese, and Korean text in @docx-editor.dev/docx-to-pdf and the editor.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"import": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
+
"./browser": {
|
|
20
|
+
"types": "./dist/browser.d.ts",
|
|
21
|
+
"import": "./dist/browser.js"
|
|
22
|
+
},
|
|
19
23
|
"./package.json": "./package.json"
|
|
20
24
|
},
|
|
21
25
|
"files": [
|