Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

slide-protocol.ts

47 lines2.0 KB

1// Adapted from opencode (MIT). Copyright (c) 2025 opencode. See LICENSE.opencode.
2import type { Method } from "./worker-rpc";
3​
4/** The longest side a decoded picture keeps: enough for a full-width slide on a high-density screen. */
5export const maxImageSide = 2560;
6​
7/** What the window shows of one slide besides its bitmap. */
8export type SlideSummary = {
9 /** In CSS pixels. */
10 readonly width: number;
11 readonly height: number;
12 readonly hidden: boolean;
13 readonly notes: string | undefined;
14};
15​
16/** An SVG picture the worker cannot decode, which the window rasterizes at `size`, or at its own size when absent. */
17export type VectorRequest = {
18 readonly asset: string;
19 readonly blob: Blob;
20 readonly size: { readonly width: number; readonly height: number } | undefined;
21};
22​
23/** A rasterized SVG picture, or none when the window could not decode it either. */
24export type VectorBitmap = { readonly asset: string; readonly bitmap: ImageBitmap | undefined };
25​
26export type SlidePainted =
27 | {
28 readonly kind: "painted";
29 /** The slide at the requested density, or less when that would exceed the bitmap caps. */
30 readonly bitmap: ImageBitmap;
31 /** SVG pictures the slide drew without, or too coarse: paint again once the worker has them. */
32 readonly vectors: readonly VectorRequest[];
33 }
34 /** The slide does not lay out, or does not paint even without shadows. */
35 | { readonly kind: "failed" }
36 /** The caller aborted the paint while it ran. */
37 | { readonly kind: "cancelled" };
38​
39/** The PowerPoint worker's methods. */
40export type SlideMethods = {
41 /** Opens the deck once per worker, its fonts included. Rejects when the engine cannot read it. */
42 readonly open: Method<{ readonly bytes: ArrayBuffer }, readonly SlideSummary[]>;
43 /** Paints one slide at `density` device pixels per CSS pixel. */
44 readonly paint: Method<{ readonly index: number; readonly density: number }, SlidePainted>;
45 /** Hands over SVG pictures rasterized for `VectorRequest`s. */
46 readonly vectors: Method<readonly VectorBitmap[], void>;
47};