orz-slides-browser 0.8.4 → 1.0.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/index.d.ts ADDED
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Types of `orz-slides-browser` (FC-19 §2–4): the IIFE's `globalThis.OrzCarrier`
3
+ * and the ES module's named exports have this shape. Self-contained (no
4
+ * dependency on orz-markdown's types); the full definitions live in
5
+ * orz-markdown `carrier/editor` (FC-19 §8) and in orz-slides' sources
6
+ * (`src/types.ts`, `src/layout-ops.ts`).
7
+ */
8
+
9
+ export type Kind = 'md' | 'slides' | 'paged';
10
+ export type EditorMode = 'split' | 'editor' | 'preview';
11
+ export type HeaderChange = string | null | { multiline: string };
12
+ export type Ratio = '16:9' | '4:3';
13
+
14
+ export interface AssembleOptions {
15
+ /** `inline` (default) inlines the engine; `cdn` loads it from jsDelivr. */
16
+ delivery?: 'inline' | 'cdn';
17
+ /** The exact text of `orz-slides.browser.js` for an inline file (default: this bundle's own text; the ES module fetches it from jsDelivr). */
18
+ engineSource?: string;
19
+ /** Resolved includes stored in `#orz-includes` exactly as given. */
20
+ includes?: Record<string, string>;
21
+ }
22
+
23
+ export interface Extracted {
24
+ text: string;
25
+ kind: Kind;
26
+ format: number;
27
+ shell: string;
28
+ delivery: string;
29
+ includes?: Record<string, string>;
30
+ }
31
+
32
+ export interface Lint { level: 'error' | 'warning' | 'info'; code: string; message: string; line?: number; from?: number; to?: number; next?: string }
33
+
34
+ export interface DocumentInfo {
35
+ kind: Kind;
36
+ format: number;
37
+ header: { start: number; end: number; fields: Record<string, string>; keys: string[] } | null;
38
+ meta: Record<string, unknown> & { title?: string; author?: string; uid?: string; keywords?: string[] };
39
+ theme?: string;
40
+ lang: string;
41
+ /** The slides settings: `ratio`, `footer`, `transition`, `slide_numbers`, `progress`, `section_numbers` (as written; `slide_numbers` / `progress` default `yes`). */
42
+ settings: Record<string, string>;
43
+ hostKeys: Record<string, string>;
44
+ title: string;
45
+ /** The header's lints and the deck's (slide markers, regions, options, headings), with lines. */
46
+ lint: Lint[];
47
+ }
48
+
49
+ export interface TextRange { from: number; to: number }
50
+ export interface AiOperation { id: string; title: string; selection: boolean }
51
+
52
+ export interface EditorHooks {
53
+ /** App host: persist the text (absent: the standalone save). */
54
+ save?(text: string): Promise<void>;
55
+ ai?: { operations: AiOperation[]; request(op: string, ctx: { text: string; selection?: TextRange }): Promise<{ proposed: string }> };
56
+ /** An include `includes` lacks: a URL, or a file include's path as written (your trust policy); null = not available. */
57
+ fetchInclude?(target: string): Promise<string | null>;
58
+ /** A relative `src` in the preview and the live slide, synchronously: the URL to load. */
59
+ resolveAsset?(path: string): string;
60
+ uploadAsset?(file: File): Promise<string>;
61
+ resolveLink?(href: string): string;
62
+ mintUid?(): Promise<string>;
63
+ }
64
+
65
+ export interface PreferenceStore {
66
+ get(key: string): unknown;
67
+ set(key: string, value: unknown): boolean;
68
+ remove(key: string): void;
69
+ all(): Record<string, unknown>;
70
+ }
71
+
72
+ export interface EditorOptions {
73
+ text: string;
74
+ kind?: 'slides';
75
+ readOnly?: boolean;
76
+ mode?: EditorMode;
77
+ chrome?: 'full' | 'compact' | 'none';
78
+ hooks?: EditorHooks;
79
+ preferences?: PreferenceStore;
80
+ /** FC-19 §3 `nonce`: your CSP nonce, stamped on the preview frame's and CodeMirror's scripts and styles (FC-19 §8.4). */
81
+ nonce?: string;
82
+ /** FC-19 §3 `includes`: resolved includes for the preview (target as written → text), read before `hooks.fetchInclude`; without `hooks.save` also stored in a saved file. */
83
+ includes?: Record<string, string>;
84
+ /** FC-19 §3 `fileName`: the suggested file name of saves without `hooks.save` (picker and download), e.g. `talk.slides.html`; default `document.slides.html`. */
85
+ fileName?: string;
86
+ }
87
+
88
+ export type SaveVia = 'hook' | 'host' | 'file' | 'download';
89
+ export type SaveOutcome = { ok: true; via: SaveVia } | { ok: false; via?: SaveVia | 'served-notice'; error: string; cancelled?: boolean; conflict?: boolean };
90
+ export type AiOutcome = { ok: true; op: string } | { ok: false; error: string };
91
+ /** An AI proposal awaiting the reader's review (`proposeAi`); only the editor that made it can apply it (`applyAi`). */
92
+ export interface AiProposal {
93
+ readonly op: string;
94
+ readonly proposed: string;
95
+ readonly range: Readonly<TextRange>;
96
+ readonly original: string;
97
+ readonly passage: boolean;
98
+ }
99
+ export type AiProposalOutcome = { ok: true; op: string; proposal: AiProposal } | { ok: false; error: string };
100
+ export type UploadOutcome = { ok: true; inserted: string[] } | { ok: false; inserted: string[]; error: string };
101
+
102
+ export interface EditorEvents {
103
+ /** `label`: the undo step's name of an `applyEdits` edit (a layout op). */
104
+ change: { text: string; label?: string };
105
+ dirty: { dirty: boolean };
106
+ selection: { from: number; to: number };
107
+ save: { text: string; via: SaveVia };
108
+ error: { source: 'save' | 'render' | 'adapter' | 'format' | 'hook'; message: string; error: unknown };
109
+ /** The reader's Cmd/Ctrl+P in the editor or its preview: with a listener the browser's print is prevented and the listener decides. */
110
+ print: { source: 'preview' | 'editor' };
111
+ }
112
+
113
+ /** A lint of the deck as the editor shows it (with its quick fix, when it has one). */
114
+ export interface SlideLint extends Lint { fix?: { from: number; to: number; insert: string; label: string } }
115
+
116
+ /** The live slide's fit report: per box its scale (1 = unscaled, floor 0.6) and whether its content is cut. */
117
+ export interface FitReport {
118
+ index: number;
119
+ boxes: Array<{ kind: string; name: string; scale: number; clipped: boolean; x: number; y: number; w: number; h: number }>;
120
+ footerCut: boolean;
121
+ scrolls: boolean;
122
+ }
123
+
124
+ /** orz-slides' tools of a mounted editor (`editor.slides`). */
125
+ export interface SlidesTools {
126
+ /** The caret's slide (0-based). */
127
+ caretSlide(): number;
128
+ /** The deck's lints as last computed (after a typing pause). */
129
+ lints(): readonly SlideLint[];
130
+ /** Compute the lints now. */
131
+ refreshLints(): readonly SlideLint[];
132
+ /** Apply a lint's quick fix (one undoable edit); false when there is none any more. */
133
+ applyFix(lint: { code: string; line?: number }): boolean;
134
+ /** The live slide card in the preview's corner: open, or folded to a small tab (a reader preference). */
135
+ isLive(): boolean;
136
+ setLive(on: boolean): void;
137
+ /** Single-slide editing (the card enlarged into the layout GUI over the slide), or the flattened preview. */
138
+ isPerSlide(): boolean;
139
+ setPerSlide(on: boolean): void;
140
+ /** The live slide's last fit report, or null before one. */
141
+ lastFit(): FitReport | null;
142
+ /** How many slides have a fit report for their current text. */
143
+ fitCoverage(): { checked: number; total: number };
144
+ }
145
+
146
+ export interface Editor {
147
+ getText(): string;
148
+ setText(text: string, options?: { resetHistory?: boolean }): void;
149
+ setHeader(changes: Record<string, HeaderChange>): void;
150
+ /** Apply several replacements (exact offsets, sorted, not overlapping) as ONE undoable edit — e.g. an `applyOp` result's `edits`. */
151
+ applyEdits(edits: ReadonlyArray<{ from: number; to: number; insert: string }>, options?: { label?: string }): boolean;
152
+ /** Select a range of the text (`scroll`: bring it into view). */
153
+ select(from: number, to: number, options?: { scroll?: boolean }): void;
154
+ /** The selection in exact offsets, or null. */
155
+ getSelection(): { from: number; to: number } | null;
156
+ /** Dim (or fold) the text outside a range (a slide); `null` shows everything again. */
157
+ setFocusRange(from: number | null, to?: number, options?: { mode?: 'dim' | 'fold' }): void;
158
+ /** Light the lines the ranges touch for a moment (what a tool just changed). */
159
+ flash(ranges: ReadonlyArray<{ from: number; to: number }>, options?: { ms?: number }): void;
160
+ undo(): boolean;
161
+ redo(): boolean;
162
+ isDirty(): boolean;
163
+ markSaved(): void;
164
+ save(): Promise<SaveOutcome>;
165
+ setMode(mode: EditorMode): void;
166
+ getMode(): EditorMode;
167
+ focus(): void;
168
+ on<E extends keyof EditorEvents>(event: E, fn: (e: EditorEvents[E]) => void): () => void;
169
+ destroy(): void;
170
+ requestAi(op: string, options?: { selection?: boolean }): Promise<AiOutcome>;
171
+ proposeAi(op: string, options?: { selection?: boolean }): Promise<AiProposalOutcome>;
172
+ applyAi(proposal: AiProposal, options?: { proposed?: string }): AiOutcome;
173
+ uploadAssets(files: ArrayLike<File>): Promise<UploadOutcome>;
174
+ ensureUid(): Promise<string>;
175
+ setReadOnly(readOnly: boolean): void;
176
+ isReadOnly(): boolean;
177
+ refreshPreview(options?: { includes?: Record<string, string> | null }): Promise<void>;
178
+ readonly ready: Promise<{ engine: string; error?: unknown }>;
179
+ /** orz-slides' own tools: the caret's slide, lints and quick fixes, the live card, single-slide editing. */
180
+ readonly slides: SlidesTools;
181
+ }
182
+
183
+ export interface RenderPreviewOptions {
184
+ fetchInclude?(target: string): Promise<string | null>;
185
+ includes?: Readonly<Record<string, string>>;
186
+ twinLinks?: boolean;
187
+ /**
188
+ * A whole HTML document (the header's slide theme and the flattened
189
+ * preview's styles inline, KaTeX and highlight.js stylesheets linked, the
190
+ * deck flattened into one flow with a divider per slide; no engine script)
191
+ * instead of the flattened deck's HTML. Either way the document's own raw HTML is
192
+ * kept as written — show it in a sandboxed frame.
193
+ */
194
+ document?: boolean;
195
+ /**
196
+ * With `document: true`: a CSP nonce stamped on the document's `<style>`
197
+ * elements (a `srcdoc` frame inherits the app's policy). The engine adds no
198
+ * script; the document's own raw HTML is not stamped.
199
+ */
200
+ nonce?: string;
201
+ }
202
+
203
+ /** A slide theme (`THEMES`). */
204
+ export interface SlideTheme {
205
+ id: string;
206
+ name: string;
207
+ scheme: 'light' | 'dark';
208
+ /** The orz-markdown theme it is derived from, or null (an updated 0.x theme). */
209
+ derivedFrom: string | null;
210
+ sectionNumbers: 'plain' | 'roman' | '01' | 'none';
211
+ description: string;
212
+ }
213
+
214
+ /** A deck template (`TEMPLATES`, `newDocument({ template })`). */
215
+ export interface TemplateInfo { id: string; label: string; description: string }
216
+
217
+ /** A layout op of the per-slide editor (orz-slides `src/layout-ops.ts`); boxes are region names, floats are counted in slide order. */
218
+ export type LayoutOp =
219
+ | { type: 'split'; box: string; dir: 'row' | 'col' }
220
+ | { type: 'delete-box'; box: string }
221
+ | { type: 'tracks'; path: number[]; tracks: string[] }
222
+ | { type: 'preset'; preset: 'single' | '2col' | '3col' | '2row' | 'main-side' | 'quad' }
223
+ | { type: 'rename'; box: string; to: string }
224
+ | { type: 'swap'; a: string; b: string }
225
+ | { type: 'move-content'; from: string; to: string }
226
+ | { type: 'ensure-region'; name: string }
227
+ | { type: 'float-add'; box?: { left: number; top: number; w: number; h: number }; covers?: boolean }
228
+ | { type: 'float-geom'; index: number; box: Partial<{ left: number; top: number; w: number; h: number }>; from?: { left: number; top: number; w: number; h: number } }
229
+ | { type: 'float-delete'; index: number }
230
+ | { type: 'float-z'; index: number; dir: 'forward' | 'backward' }
231
+ | { type: 'variant'; v: number }
232
+ | { type: 'options'; set: { fit?: 'fit' | 'scroll' | 'off' | null; bg?: string | null; transition?: string | null; step?: boolean } }
233
+ | { type: 'slide-add'; after?: boolean }
234
+ | { type: 'slide-duplicate' }
235
+ | { type: 'slide-delete' }
236
+ | { type: 'slide-move'; to: number };
237
+
238
+ export interface TextEdit { from: number; to: number; insert: string }
239
+
240
+ /** What a layout op does to the text: minimal edits on marker lines (a deleted box's block moves to its neighbour). */
241
+ export interface OpResult {
242
+ edits: TextEdit[];
243
+ text: string;
244
+ label: string;
245
+ slide: number;
246
+ select?: TextRange;
247
+ changed: TextRange[];
248
+ }
249
+
250
+ /** Where each part of a slide is in the text. */
251
+ export interface SlideMap {
252
+ index: number;
253
+ kind: 'normal' | 'template';
254
+ boxes: Array<{ name: string; range: TextRange | null; marker: TextRange | null; empty: boolean }>;
255
+ title: TextRange | null;
256
+ floats: Array<{ range: TextRange; marker: TextRange; box: { left: number; top: number; w: number; h: number }; z: number | undefined; empty: boolean; exact: boolean }>;
257
+ notes: TextRange | null;
258
+ footer: TextRange | null;
259
+ marker: TextRange;
260
+ span: TextRange;
261
+ }
262
+
263
+ /** The parsed deck (format 1, FC-18 §7.2); the full type is orz-slides' `Deck` (`src/types.ts`). */
264
+ export interface Deck {
265
+ config: { title?: string; theme: string; themeAsWritten?: string; ratio: Ratio; author?: string; footer?: string; transition?: string; slideNumbers: boolean; progress: boolean; sectionNumbers: 'plain' | 'roman' | '01' | 'none' | null };
266
+ slides: Array<{ index: number; kind: 'normal' | 'template'; template?: 'title' | 'section' | 'outline' | 'closing'; title?: string; layoutSpec: string; regions: Array<{ name: string; markdown: string }>; notes?: string; footer?: string; span: TextRange } & Record<string, unknown>>;
267
+ preamble: TextRange | null;
268
+ lint: SlideLint[];
269
+ }
270
+
271
+ export declare const kind: 'slides';
272
+ export declare const version: string;
273
+ export declare const formats: number[];
274
+ export declare function assemble(text: string, options?: AssembleOptions): Promise<string>;
275
+ export declare function extract(html: string): Extracted | null;
276
+ export declare function readDocument(text: string): DocumentInfo;
277
+ export declare function renderPreview(text: string, options?: RenderPreviewOptions): Promise<string>;
278
+ export declare function mountEditor(element: HTMLElement, options: EditorOptions): Editor;
279
+ export declare function editHeader(text: string, changes: Readonly<Record<string, HeaderChange>>): string;
280
+ /** The 14 slide themes a header `theme` may name. */
281
+ export declare const THEMES: readonly SlideTheme[];
282
+ export declare const DEFAULT_THEME: string;
283
+ /** The deck templates (`starter`, `talk`, `minimal`). */
284
+ export declare const TEMPLATES: readonly TemplateInfo[];
285
+ export declare const TEMPLATE_IDS: readonly string[];
286
+ export declare const DEFAULT_TEMPLATE: string;
287
+ /** A new format-1 slides text from a deck template (`carrier: slides`, a fresh `uid` unless given). Throws for an unknown template, theme or ratio. */
288
+ export declare function newDocument(options?: { template?: string; title?: string; theme?: string; ratio?: Ratio; uid?: string }): string;
289
+ /** Parse a slides text (format 1): the deck, its slides and lints. */
290
+ export declare function parseDeck(text: string): Deck;
291
+ /** One layout op on slide `index` (0-based) → the minimal text edits; throws `LayoutOpError` when the op cannot apply (the text unchanged). */
292
+ export declare function applyOp(text: string, index: number, op: LayoutOp): OpResult;
293
+ /** Apply sorted, non-overlapping edits to a text. */
294
+ export declare function applyEdits(text: string, edits: readonly TextEdit[]): string;
295
+ /** Where each part of slide `index` is in the text, or null. */
296
+ export declare function slideMap(text: string, index: number): SlideMap | null;
297
+ export declare class LayoutOpError extends Error { readonly code: 'no-slide' | 'no-box' | 'only-box' | 'bad-name' | 'template' | 'normal' | 'blocked' | 'no-float' | 'no-change' | 'bad-value' | 'only-slide' | 'unsafe' }
298
+ /** The layout choices of the per-slide editor (`single` and the presets). */
299
+ export declare const PRESET_CHOICES: readonly string[];
300
+ /** The logical slide size per ratio (16:9 → 1280 × 720, 4:3 → 960 × 720). */
301
+ export declare const SLIDE_SIZE: Readonly<Record<Ratio, { width: number; height: number }>>;
302
+
303
+ /** How a save from an assembled file's page went. */
304
+ export interface StandaloneSaveOutcome { ok: boolean; via?: string; error?: string; cancelled?: boolean }
305
+
306
+ /**
307
+ * The page-side handle of an assembled `.slides.html` that booted (orz-markdown
308
+ * `carrier/app` `CarrierApp`; `OrzCarrier.standalone`). Not part of FC-19:
309
+ * tests, the conformance driver and scripts in a file's own page use it.
310
+ */
311
+ export interface StandaloneFile {
312
+ getText(): string;
313
+ isDirty(): boolean;
314
+ edit(): Editor;
315
+ leave(): Promise<void>;
316
+ editor(): Editor | null;
317
+ setSetting(changes: Record<string, HeaderChange>): void;
318
+ undo(): boolean;
319
+ redo(): boolean;
320
+ save(): Promise<StandaloneSaveOutcome>;
321
+ download(): Promise<StandaloneSaveOutcome>;
322
+ newDocument(options?: { text?: string; name?: string }): Promise<StandaloneSaveOutcome>;
323
+ saveAsCopy(): Promise<StandaloneSaveOutcome>;
324
+ toast(message: string, tone?: 'info' | 'success' | 'warning' | 'error'): void;
325
+ readonly updating: boolean;
326
+ readonly ready: Promise<void>;
327
+ /** The handle's list of operations (the pencil's: Edit, Present, Print, Print with notes, Speaker view, Overview, Save, …, the settings). */
328
+ readonly menu: { open(): void; close(): void; isOpen(): boolean };
329
+ }
330
+
331
+ /** `OrzCarrier.layout`: the format-1 parser and the per-slide editor's pure layout ops (also exported by name from the ES module). */
332
+ export interface LayoutApi {
333
+ parseDeck: typeof parseDeck;
334
+ applyOp: typeof applyOp;
335
+ applyEdits: typeof applyEdits;
336
+ slideMap: typeof slideMap;
337
+ LayoutOpError: typeof LayoutOpError;
338
+ PRESET_CHOICES: typeof PRESET_CHOICES;
339
+ SLIDE_SIZE: typeof SLIDE_SIZE;
340
+ }
341
+
342
+ export interface OrzCarrierApi {
343
+ kind: 'slides';
344
+ version: string;
345
+ formats: number[];
346
+ assemble: typeof assemble;
347
+ extract: typeof extract;
348
+ readDocument: typeof readDocument;
349
+ mountEditor: typeof mountEditor;
350
+ renderPreview: typeof renderPreview;
351
+ /** orz-slides' extension: the parser and the layout ops. */
352
+ layout: LayoutApi;
353
+ /** The booted file's handle in an assembled `.slides.html` (the IIFE only); null elsewhere. Not in the ES module's `OrzCarrier`. */
354
+ readonly standalone?: StandaloneFile | null;
355
+ }
356
+ export declare const OrzCarrier: OrzCarrierApi;
357
+
358
+ declare global {
359
+ // eslint-disable-next-line no-var
360
+ var OrzCarrier: OrzCarrierApi | undefined;
361
+ }