@vedivad/typst-web-service 0.14.4 → 0.15.1

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
@@ -476,6 +476,12 @@ declare class TypstProject {
476
476
  }
477
477
 
478
478
  interface TypstRendererOptions {
479
+ /**
480
+ * Explicit Worker instance. When omitted, an inlined blob worker is created
481
+ * automatically. Use this for Vite apps to get proper source maps:
482
+ * `TypstRenderer.create({ worker: new Worker(new URL('typst-web-service/renderer-worker', import.meta.url)) })`
483
+ */
484
+ worker?: Worker;
479
485
  /** URL to the typst-ts-renderer WASM binary. Defaults to jsDelivr CDN. */
480
486
  wasmUrl?: string;
481
487
  }
@@ -490,30 +496,35 @@ interface RenderedSvgPage {
490
496
  svg: string;
491
497
  }
492
498
  /**
493
- * Converts Typst vector artifacts to SVG strings.
499
+ * Converts Typst vector artifacts to SVG strings, off the main thread.
494
500
  *
495
- * Thin wrapper around `@myriaddreamin/typst.ts`'s renderer: we own the public
496
- * API surface and WASM-URL convention; typst.ts owns the WASM session,
497
- * sub-page rendering, and lifecycle. See `renderer.mts` in that package for
498
- * the inner mechanics.
501
+ * Wraps `@myriaddreamin/typst.ts`'s renderer hosted in a Web Worker — the
502
+ * WASM init, vector SVG conversion, and base64 image-embedding all happen
503
+ * off-thread. Returned SVG strings cross via Comlink; page splitting runs on
504
+ * the main thread (Workers don't have `DOMParser`).
499
505
  *
500
506
  * const renderer = TypstRenderer.create();
501
507
  * const svg = await renderer.renderSvg(vector);
502
508
  */
503
509
  declare class TypstRenderer {
504
510
  #private;
505
- private readonly wasmUrl;
506
- private inner;
507
511
  private constructor();
508
512
  static create(options?: TypstRendererOptions): TypstRenderer;
509
- private getInner;
513
+ /** Terminate the worker. The instance is unusable afterwards. */
514
+ destroy(): void;
510
515
  /**
511
- * Drop the reference to the inner renderer. The upstream wrapper doesn't
512
- * expose an explicit free(); the WASM module is reclaimed when the page
513
- * unloads. Consumers may still call this to release the JS-side handle.
516
+ * Render a Typst vector artifact to a single merged SVG string.
517
+ *
518
+ * Ownership of `vector.buffer` transfers to the worker (zero-copy).
519
+ * Don't reuse the vector after passing it in — accessing its bytes from
520
+ * the main thread after this call is undefined behavior.
521
+ *
522
+ * Concurrent calls are serialized in the worker: while a render is in
523
+ * flight, the most recent `vector` becomes the next render and any
524
+ * intermediate calls are dropped. All overlapping callers share one
525
+ * returned promise that resolves with the LAST rendered SVG — your
526
+ * specific vector may have been superseded.
514
527
  */
515
- destroy(): void;
516
- /** Render a Typst vector artifact to a single merged SVG string. */
517
528
  renderSvg(vector: Uint8Array): Promise<string>;
518
529
  /**
519
530
  * Render a Typst vector artifact into one self-contained SVG string per
@@ -524,43 +535,6 @@ declare class TypstRenderer {
524
535
  * the document has no page groups.
525
536
  */
526
537
  renderSvgPages(vector: Uint8Array): Promise<RenderedSvgPage[]>;
527
- /**
528
- * Mount an incremental canvas renderer into `root`. Each `update(vector)`
529
- * call repaints the canvases in place. The win for image-heavy docs comes
530
- * from the persistent WASM session: decoded image bitmaps are cached in
531
- * the renderer, so subsequent paints skip the decode step. Canvas elements
532
- * are recreated each update (typst.ts manages the DOM inside `root`), but
533
- * canvas creation is cheap — the bottleneck the SVG path was solving was
534
- * `<image>` data-URL decode, not DOM construction.
535
- *
536
- * Call `reset()` when switching to an unrelated document (next `update`
537
- * starts fresh from the session). Call `dispose()` to free the session.
538
- *
539
- * Trade-off vs the SVG paths: output is rasterized — text in the rendered
540
- * canvas isn't selectable, and zoom past `pixelPerPt` needs a re-render to
541
- * stay crisp. typst.ts builds a `<canvas>` per page inside `root` and adds
542
- * a text-semantic layer alongside it for screen readers / a11y.
543
- */
544
- createIncrementalCanvasRenderer(root: HTMLElement, options?: IncrementalCanvasOptions): IncrementalCanvasRenderer;
545
- }
546
- interface IncrementalCanvasOptions {
547
- pixelPerPt?: number;
548
- backgroundColor?: string;
549
- }
550
- interface IncrementalCanvasRenderer {
551
- /**
552
- * Apply a new vector and repaint. First call seeds the session.
553
- *
554
- * Concurrent calls are serialized: while a repaint is in flight, the most
555
- * recent `update` becomes the next paint and intermediates are dropped.
556
- * All overlapping callers share one returned promise that resolves when
557
- * the chain catches up — your specific vector may have been superseded.
558
- */
559
- update(vector: Uint8Array): Promise<void>;
560
- /** Force the next `update` to re-seed (use when the doc identity changes). */
561
- reset(): void;
562
- /** Free the WASM session. */
563
- dispose(): void;
564
538
  }
565
539
 
566
- export { type AnalyzerUri, type CompileResult, type DiagnosticMessage, type DiagnosticRange, type FormatConfig, type FormatRangeResult, type IncrementalCanvasOptions, type IncrementalCanvasRenderer, type LspCompletionItem, type LspCompletionList, type LspCompletionResponse, type LspDiagnostic, type LspHover, type LspHoverContents, type LspMarkupContent, type LspPosition, type LspRange, type Path, type RenderedSvgPage, TypstAnalyzer, type TypstAnalyzerOptions, TypstCompiler, type TypstCompilerOptions, TypstFormatter, TypstProject, type TypstProjectOptions, TypstRenderer, type TypstRendererOptions, normalizePath, normalizeRoot, pathToAnalyzerUri };
540
+ export { type AnalyzerUri, type CompileResult, type DiagnosticMessage, type DiagnosticRange, type FormatConfig, type FormatRangeResult, type LspCompletionItem, type LspCompletionList, type LspCompletionResponse, type LspDiagnostic, type LspHover, type LspHoverContents, type LspMarkupContent, type LspPosition, type LspRange, type Path, type RenderedSvgPage, TypstAnalyzer, type TypstAnalyzerOptions, TypstCompiler, type TypstCompilerOptions, TypstFormatter, TypstProject, type TypstProjectOptions, TypstRenderer, type TypstRendererOptions, normalizePath, normalizeRoot, pathToAnalyzerUri };