@kition/kit-editor 0.3.0 → 0.5.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.
@@ -151,6 +151,8 @@ export type KitEngineRequest = {
151
151
  revision?: number;
152
152
  } | {
153
153
  method: 'info';
154
+ } | {
155
+ method: 'fonts';
154
156
  } | {
155
157
  method: 'invoke';
156
158
  name: string;
@@ -227,6 +229,13 @@ export type KitEngineResponse = {
227
229
  data?: ModelErrorData;
228
230
  errors?: KitParamError[];
229
231
  };
232
+ /**
233
+ * What the worker tells the page unasked: `fonts`, how many of the manifest's `lazyFonts` the
234
+ * engine has not been given yet, when the document opens and after each one is in.
235
+ */
236
+ export type KitEngineEvent = {
237
+ fonts: number;
238
+ };
230
239
  /**
231
240
  * The page's handle on one document open in a kit engine worker. Every call
232
241
  * is asynchronous and answered in order; `info` is current after each change.
@@ -238,6 +247,9 @@ export declare class KitEngine {
238
247
  private readonly pending;
239
248
  private nextId;
240
249
  private failure;
250
+ private readonly fontListeners;
251
+ /** How many of the manifest's `lazyFonts` the engine has not been given yet. */
252
+ fontsPending: number;
241
253
  private constructor();
242
254
  /**
243
255
  * Starts a worker and opens the file's bytes in it with the kit's SDK; the bytes move to the
@@ -349,6 +361,14 @@ export declare class KitEngine {
349
361
  * changed since, so an edit that reached the engine after the bytes were taken stays unsaved.
350
362
  */
351
363
  markSaved(revision?: number): Promise<void>;
364
+ /**
365
+ * Calls `listener` each time the engine was given one of the manifest's `lazyFonts`: what it
366
+ * draws may have changed (text it drew as missing glyphs), so the page draws again. Answers how
367
+ * to stop.
368
+ */
369
+ onFonts(listener: () => void): () => void;
370
+ /** Gives the engine every one of the manifest's `lazyFonts` now; resolves once each is in (or skipped). */
371
+ loadFonts(): Promise<void>;
352
372
  /** Brings `info` up to date after changes it does not follow (an `invoke` that edits, such as a merge of the file). */
353
373
  refreshInfo(): Promise<KitEngineInfo>;
354
374
  /**
@@ -3,6 +3,7 @@
3
3
  * WebAssembly or written in TypeScript (`ts-worker`), is loaded and opened. Every kit exposes the same document class shape, so one
4
4
  * worker, one client, and one document hook serve every kit.
5
5
  */
6
+ import { LazyFonts } from './lazyFonts.js';
6
7
  /** One engine command, as the editor's menus and shortcuts show it. */
7
8
  export type KitCommand = {
8
9
  id: string;
@@ -55,11 +56,20 @@ export type KitModuleManifest = {
55
56
  args: unknown[];
56
57
  }>;
57
58
  /**
58
- * Font files (URLs) given to the engine's `addFont(bytes)` once it loads, before any document
59
- * opens: faces for scripts the engine does not embed (a CJK font in a web build). One that does
60
- * not load is skipped; text in it shows in the engine's own faces.
59
+ * Font files (URLs) given to the engine's `addFont(bytes)` once it loads, in order, before any
60
+ * document opens: the faces the first frame needs (the primary face). One that does not load is
61
+ * skipped; text in it shows in the engine's own faces.
61
62
  */
62
63
  fonts?: string[];
64
+ /**
65
+ * Font files (URLs) given to `addFont` after the document opened, in order (engine contract E9):
66
+ * faces for scripts the engine does not embed and few documents use (a CJK or emoji font in a
67
+ * web build), so the first frame does not wait for them. They load once the engine's
68
+ * `wantsFonts()` says text needed a face it does not have, or right after the document opens
69
+ * when the engine has no `wantsFonts`. `KitEngine.onFonts` tells the page when each one is in,
70
+ * since what the engine draws may then change.
71
+ */
72
+ lazyFonts?: string[];
63
73
  /**
64
74
  * The commands that write only comment threads (KitModel rule M23): the kit's
65
75
  * `kit.json` `collaboration.comments.commands`. A commenter's read-only session runs them (the
@@ -162,6 +172,8 @@ type KitModuleExports = {
162
172
  } | unknown>;
163
173
  /** Loads and starts a kit's SDK once per page or worker. */
164
174
  export declare function loadKitModule(manifest: KitModuleManifest): Promise<KitModuleExports>;
175
+ /** The lazy fonts of a kit's loaded SDK (its manifest's `lazyFonts`); null before `loadKitModule` answered. */
176
+ export declare function kitModuleLazyFonts(manifest: KitModuleManifest): LazyFonts | null;
165
177
  /** Opens file bytes with a loaded SDK's document class, with their stored replica when given and the SDK takes one. */
166
178
  export declare function openKitModuleDocument(module: KitModuleExports, manifest: KitModuleManifest, name: string, bytes: Uint8Array, replica?: KitModuleReplica | null): KitModuleDocument;
167
179
  /** A new, empty document of the SDK's own making (New image, New video project). */
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A kit engine's lazy fonts (engine contract E9, kit-editor's manifest `lazyFonts`): faces the
3
+ * engine is given after its document opens, so the first frame waits only for the manifest's
4
+ * `fonts` (the primary face). They load in the order the manifest lists them, once the engine says
5
+ * it wants a face it does not have (the optional module function `wantsFonts()`), or right after
6
+ * the document opens when the engine cannot say. One file failing to load is skipped.
7
+ */
8
+ /** A font file's bytes given to the engine (`addFont`); answers how many faces it added, or their family. */
9
+ export type AddFont = (bytes: Uint8Array) => unknown;
10
+ /** Fetches a font file's bytes; null when it cannot be read. */
11
+ export type FetchFont = (url: string) => Promise<Uint8Array | null>;
12
+ export declare class LazyFonts {
13
+ private readonly addFont;
14
+ private readonly wantsFonts;
15
+ private readonly read;
16
+ private readonly left;
17
+ private loading;
18
+ private readonly listeners;
19
+ /** `addFont` null: the engine takes no fonts, so there is nothing to load. */
20
+ constructor(urls: readonly string[], addFont: AddFont | null, wantsFonts: (() => boolean) | null, read?: FetchFont);
21
+ /** How many of the lazy fonts the engine has not been given yet (still to load, or loading). */
22
+ get pending(): number;
23
+ /** Calls `listener` with `pending` after each font was given to the engine (or skipped); answers how to stop. */
24
+ onSettled(listener: (pending: number) => void): () => void;
25
+ /**
26
+ * Starts loading when fonts are left, none is loading, and the engine wants a face (or cannot
27
+ * say). Call it after every request the engine answered: it asks the engine at most once per
28
+ * call, and not at all once loading started.
29
+ */
30
+ check(): void;
31
+ /** Gives the engine every lazy font now, in order; resolves once each was given or skipped. */
32
+ loadAll(): Promise<void>;
33
+ private load;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kition/kit-editor",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Build a kit's embedded editor: host connection, document session, engine canvas and tools, and shared components styled by the host's theme (Kit UI protocol).",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,12 +19,12 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@kition/kit-engine": "^0.3.0",
22
+ "@kition/kit-engine": "^0.5.0",
23
23
  "@kition/tessera-ui": "^0.1.0",
24
24
  "@kition/tessera-icons": "^0.1.0",
25
25
  "@kition/tessera-tokens": "^0.1.0",
26
- "@kition/kit-ui-protocol": "0.3.0",
27
- "@kition/kdm": "0.3.0"
26
+ "@kition/kdm": "0.5.0",
27
+ "@kition/kit-ui-protocol": "0.5.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": ">=19",