@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
MemberTypeSummary
familystringThe family name.
style'normal' | 'italic'Whether this is the upright or the italic face.
weightnumberCSS numeric weight.

CjkFontLoadFailureinterfaceSource ↗

A fetch of the packaged face that failed for a reason other than cancellation.

interface CjkFontLoadFailure
MemberTypeSummary
diagnosticstringWhy the fetch failed.
familystringAlways [NOTO_SANS_CJK_JP_FAMILY](NOTO_SANS_CJK_JP_FAMILY).
urlstringThe 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
MemberTypeSummary
"docx-editor.dev/font-resolver"trueAlways `true`. Set non-enumerably.

CjkFontsFragmentinterfaceSource ↗

What one resolver call produced, structurally the editor contract's FontConfigurationFragment.

interface CjkFontsFragment
MemberTypeSummary
sourcesreadonly CjkFontSource[]The packaged face, when the document names a family it stands in for.
substitutionsreadonly { 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
MemberTypeSummary
fetcher?typeof fetchInjectable for tests; defaults to the global `fetch`.
onFailure?(failure: CjkFontLoadFailure) => voidFetch 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
MemberTypeSummary
bytesUint8ArrayThe font file.
faceIndexnumberAlways 0: the file holds one face.
hashstring`sha256:` and the hexadecimal SHA-256 of `bytes`. The editor checks it on admission.
idstringA stable identifier for the source.
requestCjkFontFaceRequestThe 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
MemberTypeSummary
defaultFamilystringThe face a run naming no font resolves to.
familiesreadonly 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?AbortSignalCancels 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
MemberTypeSummary
familystringThe family name, matched case-insensitively.
style'normal' | 'italic'Whether this is the upright or the italic face.
weightnumberCSS 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"