@navaramap/font 0.2.0 → 0.3.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/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
- import { ConcurrencyManager } from '@navaramap/worker';
2
1
  import { DataTexture } from 'three';
3
2
 
3
+ /**
4
+ * Pixels of distance field a quality's glyph rect keeps around the outline.
5
+ * The text shader grows a glyph's quad past it for wider outlines.
6
+ *
7
+ * SDF: `SDF_BUFFER` (12) in `crates/navara_wasm_font_worker/src/atlas.rs`.
8
+ * MSDF: `MSDF_PADDING_PX` (8) in `crates/navara_wasm_font_worker/src/msdf.rs`.
9
+ */
10
+ export declare const atlasPaddingPx: (highQuality: boolean) => number;
11
+
4
12
  /**
5
13
  * Pixel range over which a quality's atlas distance field ramps from
6
14
  * "outside" to "inside" (i.e. the value covered by `d - 0.5` in the shader).
@@ -141,9 +149,10 @@ export declare class FontManager {
141
149
  private _workerUrl;
142
150
  private _client;
143
151
  private _clientPromise;
144
- private _concurrencyManager;
145
152
  /** Worker cache budget, delivered when the (lazy) client is created. */
146
153
  private _fontBudgetBytes;
154
+ /** Delivered when the (lazy) client is created; see `setWorkerCoreReservation`. */
155
+ private _reserveWorkerCore;
147
156
  /** Tracks in-flight fetch promises to avoid duplicate requests. */
148
157
  private _pending;
149
158
  /** Tracks fonts that have been successfully loaded. */
@@ -202,7 +211,6 @@ export declare class FontManager {
202
211
  /** Whether a retain/release flush is already scheduled. */
203
212
  private _refFlushScheduled;
204
213
  constructor(workerUrl: string | URL);
205
- setConcurrencyManager(concurrencyManager: ConcurrencyManager): void;
206
214
  /**
207
215
  * Register a font family with multiple faces.
208
216
  * No font files are loaded until text is prepared.
@@ -236,6 +244,13 @@ export declare class FontManager {
236
244
  * the budget is delivered with its init message.
237
245
  */
238
246
  setMemoryBudget(bytes: number | undefined): void;
247
+ /**
248
+ * Lets the font worker hold a core of the view's worker pool while it
249
+ * loads fonts or shapes text (see `reserveWorkerCore` in
250
+ * `@navaramap/worker`). Must be called before the first font loads, like
251
+ * {@link setMemoryBudget}.
252
+ */
253
+ setWorkerCoreReservation(reserve: () => () => void): void;
239
254
  /**
240
255
  * Snapshot of the font worker's memory usage, or `undefined` while no
241
256
  * worker has been spawned (no fonts in use = zero cost).
@@ -369,11 +384,15 @@ export declare class FontManager {
369
384
  */
370
385
  export declare class FontWorkerClient {
371
386
  private _worker;
372
- private _concurrencyManager;
373
387
  private _nextId;
374
388
  private _pending;
375
389
  private _ready;
376
- constructor(workerUrl: string | URL, concurrencyManager: ConcurrencyManager, options?: FontWorkerClientOptions);
390
+ /** Heavy requests (init, font loads, text shaping) still in flight. */
391
+ private _heavyRequests;
392
+ private _releaseCore;
393
+ private _releaseCoreTimer;
394
+ private _reserveWorkerCore;
395
+ constructor(workerUrl: string | URL, options?: FontWorkerClientOptions);
377
396
  /** Wait for the WASM module to be initialized in the worker. */
378
397
  ready(): Promise<void>;
379
398
  /** Load a font file into the worker's FontCache. Transfers the ArrayBuffer.
@@ -405,6 +424,11 @@ export declare class FontWorkerClient {
405
424
  /** Snapshot of the worker's WASM heap and font-cache memory usage. */
406
425
  getMemoryStats(): Promise<FontWorkerMemoryStats>;
407
426
  dispose(): void;
427
+ /**
428
+ * Hold a worker-pool core while `request` keeps the font worker busy, so
429
+ * the pool leaves the worker a core of its own (see `reserveWorkerCore`).
430
+ */
431
+ private _holdCore;
408
432
  private _send;
409
433
  }
410
434
 
@@ -412,6 +436,12 @@ declare type FontWorkerClientOptions = {
412
436
  /** Memory budget for the worker's font caches (font data + atlas pixels).
413
437
  * Caps further atlas growth; the WASM heap itself never shrinks. */
414
438
  fontBudgetBytes?: number;
439
+ /** Holds a worker-pool core while the font worker is busy and returns
440
+ * its release (`reserveWorkerCore` of the view's worker pool). Passed in
441
+ * rather than imported: this package bundles its own copy of
442
+ * `@navaramap/worker`, which would hold a core on a pool that does not
443
+ * exist. */
444
+ reserveWorkerCore?: () => () => void;
415
445
  };
416
446
 
417
447
  /** Snapshot of the font worker's WASM heap and font-cache memory usage. */
@@ -446,6 +476,21 @@ export declare const GlyphCharClass: {
446
476
  readonly Ideographic: 3;
447
477
  };
448
478
 
479
+ /**
480
+ * Direction of the `\n`-separated segment a glyph was shaped in. Must match
481
+ * the `DIRECTION_*` constants in
482
+ * `crates/navara_wasm_font_worker/src/shaping.rs`.
483
+ */
484
+ export declare const GlyphDirection: {
485
+ /** No character with a script of its own (digits, punctuation, spaces).
486
+ * Font-family fallback shapes such runs apart from the letters around
487
+ * them, so a line's direction is its first non-neutral glyph's. */
488
+ readonly Neutral: 0;
489
+ readonly Ltr: 1;
490
+ /** The segment's glyphs arrive in visual order (reversed logical order). */
491
+ readonly Rtl: 2;
492
+ };
493
+
449
494
  /** Glyph metrics from either the SDF or the color atlas. */
450
495
  export declare type GlyphMetrics = {
451
496
  glyphId: number;
@@ -539,6 +584,11 @@ export declare type ShapedGlyph = {
539
584
  yOffset: number;
540
585
  /** One of `GlyphCharClass` (line-break info). */
541
586
  charClass: number;
587
+ /** Same shaping cluster as the previous glyph (combining marks, pre-base
588
+ * vowels). Letter spacing is inserted only before cluster starts. */
589
+ continuesCluster?: boolean;
590
+ /** One of `GlyphDirection`; absent means neutral. */
591
+ direction?: number;
542
592
  };
543
593
 
544
594
  /** Result from shaping text: glyph positions + atlas metrics. */
@@ -553,6 +603,10 @@ export declare type ShapeTextResult = {
553
603
  descender: number;
554
604
  /** Extra line gap in font units (hhea). */
555
605
  lineGap: number;
606
+ /** False when letter spacing must not be applied: tracking pulls apart the
607
+ * joined letterforms of cursive Arabic, so (like MapLibre) any Arabic
608
+ * character disables it for the whole label. */
609
+ allowsLetterSpacing: boolean;
556
610
  /** FontManager-internal: the atlas generation these metrics were built
557
611
  * under. When the atlas evicts glyphs its generation bumps, marking older
558
612
  * cached results stale so they are re-shaped on next use. Unset on results