@docx-editor.dev/fonts-cjk/browser
The packaged CJK face for the editor in a browser: a font resolver that composes next to packagedFonts() and googleFonts() from @docx-editor.dev/fonts.
```ts import { packagedFonts } from '@docx-editor.dev/fonts'; import { googleFonts } from '@docx-editor.dev/fonts/google'; import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
const fonts = [packagedFonts(), googleFonts(), cjkFonts()]; ```
Functions (1)
cjkFontsfunctionSource ↗
The packaged CJK face, served ON DEMAND: a font resolver that fetches the face only when a document names one of the [CJK_SUBSTITUTED_FAMILIES](CJK_SUBSTITUTED_FAMILIES), in English or in a localized name ([LOCALIZED_CJK_FAMILIES](LOCALIZED_CJK_FAMILIES)), or names [NOTO_SANS_CJK_JP_FAMILY](NOTO_SANS_CJK_JP_FAMILY) itself. A document without one never downloads the 16 MB face.
The face has one weight and one style, so every face of a named family points at it. Put it after the origins whose faces you prefer: a family an earlier origin already paints is left to that origin.
The face is the file inside this package, fetched from where your bundler emits it. Nothing comes from a third party. A failed fetch reports through onFailure and the document opens without the face; cancellation rejects with signal.reason.
declare function cjkFonts(options?: CjkFontsOptions): CjkFontsResolver;Interfaces (8)
CjkFontFaceRequestinterfaceSource ↗
A face request, structurally the editor contract's FontFaceRequest.
interface CjkFontFaceRequest| Member | Type | Summary |
|---|---|---|
| family | string | The family name. |
| style | 'normal' | 'italic' | Whether this is the upright or the italic face. |
| weight | number | CSS numeric weight. |
CjkFontLoadFailureinterfaceSource ↗
A fetch of the packaged face that failed for a reason other than cancellation.
interface CjkFontLoadFailure| Member | Type | Summary |
|---|---|---|
| diagnostic | string | Why the fetch failed. |
| family | string | Always [NOTO_SANS_CJK_JP_FAMILY](NOTO_SANS_CJK_JP_FAMILY). |
| url | string | The URL the resolver fetched, or an empty string when it could not build one. |
CjkFontResolverMarkinterfaceSource ↗
The marker the editor reads to call a function per document.
interface CjkFontResolverMark| Member | Type | Summary |
|---|---|---|
| "docx-editor.dev/font-resolver" | true | Always `true`. Set non-enumerably. |
CjkFontsFragmentinterfaceSource ↗
What one resolver call produced, structurally the editor contract's FontConfigurationFragment.
interface CjkFontsFragment| Member | Type | Summary |
|---|---|---|
| sources | readonly CjkFontSource[] | The packaged face, when the document names a family it stands in for. |
| substitutions | readonly {
readonly from: CjkFontFaceRequest;
readonly to: CjkFontFaceRequest;
}[] | Every face of each named East Asian family, pointed at the packaged face. |
CjkFontsOptionsinterfaceSource ↗
Options for [cjkFonts](cjkFonts).
interface CjkFontsOptions| Member | Type | Summary |
|---|---|---|
| fetcher? | typeof fetch | Injectable for tests; defaults to the global `fetch`. |
| onFailure? | (failure: CjkFontLoadFailure) => void | Fetch failures. Defaults to a console warning. The document then opens without the face. |
CjkFontSourceinterfaceSource ↗
The packaged face as a font source, structurally the editor contract's FontSource.
interface CjkFontSource| Member | Type | Summary |
|---|---|---|
| bytes | Uint8Array | The font file. |
| faceIndex | number | Always 0: the file holds one face. |
| hash | string | `sha256:` and the hexadecimal SHA-256 of `bytes`. The editor checks it on admission. |
| id | string | A stable identifier for the source. |
| request | CjkFontFaceRequest | The face this source supplies: [NOTO_SANS_CJK_JP_FAMILY](NOTO_SANS_CJK_JP_FAMILY), 400, normal. |
CjkFontsRequestinterfaceSource ↗
The request the resolver takes, structurally the editor contract's FontResolutionRequest.
interface CjkFontsRequest| Member | Type | Summary |
|---|---|---|
| defaultFamily | string | The face a run naming no font resolves to. |
| families | readonly string[] | Families the document declares, already name-validated and capped by the engine. |
| resolvedFaces? | readonly CjkResolvedFontFace[] | Faces an earlier origin in the same composition can already paint. |
| signal? | AbortSignal | Cancels the request. The resolver rejects with `signal.reason`. |
CjkResolvedFontFaceinterfaceSource ↗
One face an earlier origin in the same composition can already paint, structurally the editor contract's FontFaceRequest.
interface CjkResolvedFontFace| Member | Type | Summary |
|---|---|---|
| family | string | The family name, matched case-insensitively. |
| style | 'normal' | 'italic' | Whether this is the upright or the italic face. |
| weight | number | CSS numeric weight. |
Type aliases (1)
CjkFontsResolvertypeSource ↗
What [cjkFonts](cjkFonts) returns: a marked resolver over the packaged CJK face.
type CjkFontsResolver = ((request: CjkFontsRequest) => Promise<CjkFontsFragment>) & CjkFontResolverMark;Variables (3)
CJK_SUBSTITUTED_FAMILIESconstSource ↗
East Asian families the packaged face stands in for when the family itself is missing.
The face covers their text, not their metrics: substituting it can change glyph forms, line breaks, and page counts.
CJK_SUBSTITUTED_FAMILIES: readonly string[]LOCALIZED_CJK_FAMILIESconstSource ↗
Localized names that documents write for the families in [CJK_SUBSTITUTED_FAMILIES](CJK_SUBSTITUTED_FAMILIES), each mapped to its English name. A document saved in a Chinese, Japanese, or Korean locale names its East Asian font this way.
A Map, not an object: the key is file-derived, and a name such as constructor must not find a prototype member.
LOCALIZED_CJK_FAMILIES: ReadonlyMap<string, string>NOTO_SANS_CJK_JP_FAMILYconstSource ↗
Family name of the packaged face.
NOTO_SANS_CJK_JP_FAMILY = "Noto Sans CJK JP"