@docx-editor.dev/fonts-cjk 2.33.0 → 2.34.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/dist/browser.cjs +27 -13
- package/dist/browser.js +27 -13
- package/package.json +1 -1
package/dist/browser.cjs
CHANGED
|
@@ -161,27 +161,42 @@ function loadFace(fetcher, url, signal) {
|
|
|
161
161
|
}
|
|
162
162
|
function cjkFonts(options = {}) {
|
|
163
163
|
async function resolveCjkFonts(request) {
|
|
164
|
-
const
|
|
165
|
-
(request.resolvedFaces ?? []).
|
|
164
|
+
const faces = new Set(
|
|
165
|
+
(request.resolvedFaces ?? []).map(
|
|
166
|
+
(face) => `${face.family.trim().toLowerCase()}/${face.weight}/${face.style}`
|
|
167
|
+
)
|
|
166
168
|
);
|
|
169
|
+
const isPainted = (family, weight = 400, style = "normal") => faces.has(`${family.trim().toLowerCase()}/${weight}/${style}`);
|
|
170
|
+
const aliases = [];
|
|
167
171
|
const planned = request.families.filter((family) => {
|
|
168
172
|
const key = family.trim().toLowerCase();
|
|
169
|
-
|
|
173
|
+
if (!SUBSTITUTED.has(key) || isPainted(family)) return false;
|
|
174
|
+
const english = LOCALIZED_CJK_FAMILIES.get(family.trim());
|
|
175
|
+
if (english === void 0 || !isPainted(english)) return true;
|
|
176
|
+
for (const [weight, style] of FACES)
|
|
177
|
+
aliases.push({
|
|
178
|
+
from: { family, weight, style },
|
|
179
|
+
to: isPainted(english, weight, style) ? { family: english, weight, style } : { family: english, weight: 400, style: "normal" }
|
|
180
|
+
});
|
|
181
|
+
return false;
|
|
170
182
|
});
|
|
171
183
|
const named = request.families.some(
|
|
172
184
|
(family) => family.trim().toLowerCase() === NOTO_SANS_CJK_JP_FAMILY.toLowerCase()
|
|
173
185
|
);
|
|
174
|
-
if (planned.length === 0 && !named) return { sources: [], substitutions:
|
|
175
|
-
if (
|
|
176
|
-
return { sources: [], substitutions: substitutionsFor(planned) };
|
|
186
|
+
if (planned.length === 0 && !named) return { sources: [], substitutions: aliases };
|
|
187
|
+
if (isPainted(NOTO_SANS_CJK_JP_FAMILY)) {
|
|
188
|
+
return { sources: [], substitutions: [...aliases, ...substitutionsFor(planned)] };
|
|
177
189
|
}
|
|
178
190
|
if ((options.loading ?? "background") === "background") {
|
|
179
|
-
const deferred = downloadFace(planned, request).catch(() =>
|
|
180
|
-
|
|
191
|
+
const deferred = downloadFace(planned, request, aliases).catch(() => ({
|
|
192
|
+
sources: [],
|
|
193
|
+
substitutions: aliases
|
|
194
|
+
}));
|
|
195
|
+
return { sources: [], substitutions: aliases, deferred };
|
|
181
196
|
}
|
|
182
|
-
return downloadFace(planned, request);
|
|
197
|
+
return downloadFace(planned, request, aliases);
|
|
183
198
|
}
|
|
184
|
-
async function downloadFace(planned, request) {
|
|
199
|
+
async function downloadFace(planned, request, aliases) {
|
|
185
200
|
const fetcher = options.fetcher ?? defaultFetch;
|
|
186
201
|
let url = "";
|
|
187
202
|
let bytes;
|
|
@@ -198,7 +213,7 @@ function cjkFonts(options = {}) {
|
|
|
198
213
|
};
|
|
199
214
|
if (options.onFailure) options.onFailure(failure);
|
|
200
215
|
else console.warn(`[fonts-cjk] ${failure.family} (${failure.url}): ${failure.diagnostic}`);
|
|
201
|
-
return { sources: [], substitutions:
|
|
216
|
+
return { sources: [], substitutions: aliases };
|
|
202
217
|
}
|
|
203
218
|
if (request.signal?.aborted) throw request.signal.reason;
|
|
204
219
|
return {
|
|
@@ -211,7 +226,7 @@ function cjkFonts(options = {}) {
|
|
|
211
226
|
faceIndex: 0
|
|
212
227
|
}
|
|
213
228
|
],
|
|
214
|
-
substitutions: substitutionsFor(planned)
|
|
229
|
+
substitutions: [...aliases, ...substitutionsFor(planned)]
|
|
215
230
|
};
|
|
216
231
|
}
|
|
217
232
|
const descriptor = { value: true, enumerable: false, configurable: true };
|
|
@@ -219,7 +234,6 @@ function cjkFonts(options = {}) {
|
|
|
219
234
|
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_MARK_KEY, descriptor);
|
|
220
235
|
return resolveCjkFonts;
|
|
221
236
|
}
|
|
222
|
-
var EMPTY = Object.freeze({ sources: [], substitutions: [] });
|
|
223
237
|
function substitutionsFor(families) {
|
|
224
238
|
return families.flatMap(
|
|
225
239
|
(family) => FACES.map(([weight, style]) => ({ from: { family, weight, style }, to: PACKAGED_FACE }))
|
package/dist/browser.js
CHANGED
|
@@ -86,27 +86,42 @@ function loadFace(fetcher, url, signal) {
|
|
|
86
86
|
}
|
|
87
87
|
function cjkFonts(options = {}) {
|
|
88
88
|
async function resolveCjkFonts(request) {
|
|
89
|
-
const
|
|
90
|
-
(request.resolvedFaces ?? []).
|
|
89
|
+
const faces = new Set(
|
|
90
|
+
(request.resolvedFaces ?? []).map(
|
|
91
|
+
(face) => `${face.family.trim().toLowerCase()}/${face.weight}/${face.style}`
|
|
92
|
+
)
|
|
91
93
|
);
|
|
94
|
+
const isPainted = (family, weight = 400, style = "normal") => faces.has(`${family.trim().toLowerCase()}/${weight}/${style}`);
|
|
95
|
+
const aliases = [];
|
|
92
96
|
const planned = request.families.filter((family) => {
|
|
93
97
|
const key = family.trim().toLowerCase();
|
|
94
|
-
|
|
98
|
+
if (!SUBSTITUTED.has(key) || isPainted(family)) return false;
|
|
99
|
+
const english = LOCALIZED_CJK_FAMILIES.get(family.trim());
|
|
100
|
+
if (english === void 0 || !isPainted(english)) return true;
|
|
101
|
+
for (const [weight, style] of FACES)
|
|
102
|
+
aliases.push({
|
|
103
|
+
from: { family, weight, style },
|
|
104
|
+
to: isPainted(english, weight, style) ? { family: english, weight, style } : { family: english, weight: 400, style: "normal" }
|
|
105
|
+
});
|
|
106
|
+
return false;
|
|
95
107
|
});
|
|
96
108
|
const named = request.families.some(
|
|
97
109
|
(family) => family.trim().toLowerCase() === NOTO_SANS_CJK_JP_FAMILY.toLowerCase()
|
|
98
110
|
);
|
|
99
|
-
if (planned.length === 0 && !named) return { sources: [], substitutions:
|
|
100
|
-
if (
|
|
101
|
-
return { sources: [], substitutions: substitutionsFor(planned) };
|
|
111
|
+
if (planned.length === 0 && !named) return { sources: [], substitutions: aliases };
|
|
112
|
+
if (isPainted(NOTO_SANS_CJK_JP_FAMILY)) {
|
|
113
|
+
return { sources: [], substitutions: [...aliases, ...substitutionsFor(planned)] };
|
|
102
114
|
}
|
|
103
115
|
if ((options.loading ?? "background") === "background") {
|
|
104
|
-
const deferred = downloadFace(planned, request).catch(() =>
|
|
105
|
-
|
|
116
|
+
const deferred = downloadFace(planned, request, aliases).catch(() => ({
|
|
117
|
+
sources: [],
|
|
118
|
+
substitutions: aliases
|
|
119
|
+
}));
|
|
120
|
+
return { sources: [], substitutions: aliases, deferred };
|
|
106
121
|
}
|
|
107
|
-
return downloadFace(planned, request);
|
|
122
|
+
return downloadFace(planned, request, aliases);
|
|
108
123
|
}
|
|
109
|
-
async function downloadFace(planned, request) {
|
|
124
|
+
async function downloadFace(planned, request, aliases) {
|
|
110
125
|
const fetcher = options.fetcher ?? defaultFetch;
|
|
111
126
|
let url = "";
|
|
112
127
|
let bytes;
|
|
@@ -123,7 +138,7 @@ function cjkFonts(options = {}) {
|
|
|
123
138
|
};
|
|
124
139
|
if (options.onFailure) options.onFailure(failure);
|
|
125
140
|
else console.warn(`[fonts-cjk] ${failure.family} (${failure.url}): ${failure.diagnostic}`);
|
|
126
|
-
return { sources: [], substitutions:
|
|
141
|
+
return { sources: [], substitutions: aliases };
|
|
127
142
|
}
|
|
128
143
|
if (request.signal?.aborted) throw request.signal.reason;
|
|
129
144
|
return {
|
|
@@ -136,7 +151,7 @@ function cjkFonts(options = {}) {
|
|
|
136
151
|
faceIndex: 0
|
|
137
152
|
}
|
|
138
153
|
],
|
|
139
|
-
substitutions: substitutionsFor(planned)
|
|
154
|
+
substitutions: [...aliases, ...substitutionsFor(planned)]
|
|
140
155
|
};
|
|
141
156
|
}
|
|
142
157
|
const descriptor = { value: true, enumerable: false, configurable: true };
|
|
@@ -144,7 +159,6 @@ function cjkFonts(options = {}) {
|
|
|
144
159
|
Object.defineProperty(resolveCjkFonts, FONT_RESOLVER_MARK_KEY, descriptor);
|
|
145
160
|
return resolveCjkFonts;
|
|
146
161
|
}
|
|
147
|
-
var EMPTY = Object.freeze({ sources: [], substitutions: [] });
|
|
148
162
|
function substitutionsFor(families) {
|
|
149
163
|
return families.flatMap(
|
|
150
164
|
(family) => FACES.map(([weight, style]) => ({ from: { family, weight, style }, to: PACKAGED_FACE }))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docx-editor.dev/fonts-cjk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.0",
|
|
4
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",
|