orz-slides-browser 0.8.5 → 1.1.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/README.md CHANGED
@@ -1,15 +1,79 @@
1
1
  # orz-slides-browser
2
2
 
3
- Prebuilt, single-file in-browser **presentation engine** for
4
- [`orz-slides`](https://www.npmjs.com/package/orz-slides) `.slides.html` decks.
3
+ The browser engine and editor component of
4
+ [orz-slides](https://github.com/wangyu16/orz-slides) — slide decks written in
5
+ Markdown that present, edit and save themselves: the very bundle every
6
+ `.slides.html` file carries, and the same editor for web apps (orz family
7
+ contract FC-19). Built on the carrier kit of
8
+ [orz-markdown](https://www.npmjs.com/package/orz-markdown) 2.5.0 and
9
+ [reveal.js](https://revealjs.com/) 5.2.1 (both bundled: this release embeds
10
+ orz-markdown 2.5.0), with the 14 slide themes inside.
5
11
 
6
- It is `esbuild(reveal.js + orz-markdown + the orz-slides parser / layout engine /
7
- assembler)` as one IIFE that exposes `window.orzslides`. Each generated
8
- `.slides.html` either inlines this bundle (`--inline`) or loads it from jsDelivr:
12
+ ```sh
13
+ npm i orz-slides-browser@1
14
+ ```
15
+
16
+ | File | What |
17
+ |---|---|
18
+ | `orz-slides.browser.js` | the IIFE. Sets `globalThis.OrzCarrier` = `{ kind: 'slides', version, formats, assemble, extract, readDocument, mountEditor, renderPreview, includeTargets, linkTargets, printDocument, printDeck, standalone, layout }` — `layout` holds the layout editor's pure layout ops (`parseDeck`, `applyOp`, `applyEdits`, `slideMap`, `LayoutOpError`, `PRESET_CHOICES`, `SLIDE_SIZE`). Inside an assembled `.slides.html` it also starts that file (orz-markdown `carrier/app`): the read view — the deck, at 1280 × 720 (16:9) or 960 × 720 (4:3), every box fitted —, Present, Print, Print with notes, Speaker view, Overview, Edit (the whole deck beside a flattened preview, with the live slide card that enlarges into single-slide editing), Save, Download a copy, New document, Save as new copy, the header settings (theme, ratio, slide numbers, progress, section numbers), host protocols and the quiet update; `OrzCarrier.standalone` is then the file's handle, `null` elsewhere. Anywhere else it only sets the global. |
19
+ | `esm/orz-slides.browser.mjs` | ES module exports: `kind`, `version`, `formats`, `assemble`, `extract`, `readDocument`, `renderPreview`, `mountEditor`, `OrzCarrier` (the same object without `standalone`), `includeTargets` / `linkTargets` (a text's include directives and links, orz-markdown 2.5.0), `printDeck` (print a deck from your page, one slide per page) and `printDocument` (the kit's), `THEMES`, `DEFAULT_THEME`, `themeSwatch`, `TEMPLATES`, `TEMPLATE_IDS`, `DEFAULT_TEMPLATE`, `newDocument`, `parseDeck`, `editHeader(text, changes)` — change header keys in a text the way the pencil's settings do (one line per key, the rest of the text untouched; `null` removes a key) — and the layout editor's pure layout ops (`applyOp`, `applyEdits`, `slideMap`, `LayoutOpError`, `PRESET_CHOICES`, `SLIDE_SIZE`). Sets no global and boots nothing. |
20
+ | `release.json` | the release manifest the quiet update reads: `kind`, `version`, `formats`, `notes`, and `bundle.path` / `bundle.integrity` (the SHA-384 of `orz-slides.browser.js`'s exact bytes). |
21
+ | `index.d.ts` | types (`Editor`, `EditorOptions`, `EditorHooks`, `SlidesTools`, `LayoutOp`, …). |
9
22
 
23
+ ```js
24
+ import { mountEditor } from 'orz-slides-browser'; // a bundler: the ES module
25
+ const editor = mountEditor(element, { text, nonce, hooks: { async save(text) { /* store the text */ } } });
10
26
  ```
11
- https://cdn.jsdelivr.net/npm/orz-slides-browser@<version>/orz-slides.browser.js
27
+
28
+ ```html
29
+ <script src="https://cdn.jsdelivr.net/npm/orz-slides-browser@1.1.0/orz-slides.browser.js"></script>
30
+ <script>const editor = OrzCarrier.mountEditor(element, { text, hooks: { save } });</script>
12
31
  ```
13
32
 
14
- The version is kept in **lockstep** with the `orz-slides` CLI package. Generated
15
- by `npm run bundle`; not edited by hand.
33
+ Since 1.1, `assemble`, `mountEditor` and `renderPreview` take `twinLinks` — your
34
+ site's names for linked decks and documents (`{ slides: '{stem}.html' }`):
35
+ links to text twins point at them, and a file keeps the naming in every save.
36
+
37
+ `.slides.html` files carry the bundle inline (the CLI's default) or load it
38
+ from `https://cdn.jsdelivr.net/npm/orz-slides-browser@<version>/orz-slides.browser.js`
39
+ (`--cdn`); the slide themes are inside the bundle, so both style the same.
40
+ The bundle holds no `<script` / `</script`, no CR and only ASCII, so it can be
41
+ inlined byte for byte and checked against `release.json`.
42
+ `require('orz-slides-browser')` is not supported (it throws): use `import` or a
43
+ `<script>` tag.
44
+
45
+ ## Browsers, delivery and limits
46
+
47
+ - **Presenting, printing and editing work in every modern browser.** **Save
48
+ in place** needs Chromium (Chrome, Edge, …: the File System Access API):
49
+ the first Save asks where the file is (a file picker), later saves write
50
+ it directly; elsewhere Save downloads the file. A page served over http(s)
51
+ never saves in place (*Download a copy*).
52
+ - **CDN dependence.** Even an inline file (the engine, reveal.js and the
53
+ themes inside) loads the themes' webfonts (Google Fonts), KaTeX's and
54
+ highlight.js's styles, Mermaid / SMILES / Chart.js and the CodeMirror
55
+ editor from CDNs; a `--cdn` file also loads the engine. **Offline**, a deck
56
+ still presents (system fonts; formulas unstyled, diagrams and charts not
57
+ drawn) and edits in a plain text area.
58
+ - **Content-Security-Policy.** Under a nonce policy pass your nonce as
59
+ `mountEditor(element, { nonce })`; the component stamps it on its scripts
60
+ and styles and on the preview frame's. The tested policy and what loads
61
+ from where: `docs/embedding.md`, "Content-Security-Policy".
62
+ - **No app-side print** (1.0): in an app, Cmd/Ctrl+P in the editor is its
63
+ `print` event; the slides' print document (one slide per page, with or
64
+ without notes) comes from an assembled `.slides.html`'s *Print*.
65
+ - **Deliberate limits**: floats are unnamed (told apart by their order).
66
+ (Copying from a slide, reading or presenting, gives Markdown, as in every
67
+ orz file.)
68
+ - **Files are programs.** A `.slides.html` runs the engine and any raw HTML
69
+ in its deck: open only trusted files; show `renderPreview` output only in a
70
+ sandboxed frame.
71
+
72
+ Embedding guide (hooks, the two editing modes, the preview frame, CSP,
73
+ versions): `docs/embedding.md` in this package
74
+ ([on GitHub](https://github.com/wangyu16/orz-slides/blob/main/docs/embedding.md)).
75
+ Versioned in lockstep with `orz-slides`; built by its `build/bundle.ts`.
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,391 @@
1
+ # Embedding the orz-slides editor in a web app
2
+
3
+ `orz-slides-browser` is the editor that every `.slides.html` file carries,
4
+ packaged for web apps (family decision FD-06; contract FC-19 in orz-markdown
5
+ `spec/FC-19-editor-component.md`). An app mounts it in its own page, keeps the
6
+ **text** (the canonical deck, FC-18 text format 1) wherever it likes, and
7
+ makes assembled `.slides.html` files only when someone needs one. The editor
8
+ is orz-mdhtml's (the kit's editor shell) with the slides additions: its
9
+ preview shows the deck **flattened** — every slide's content in text order
10
+ with a thin divider per slide — with a **live slide card** in the corner that
11
+ enlarges into **single-slide editing** (see [Two ways to edit](#two-ways-to-edit)).
12
+
13
+ This guide ships in both packages (`node_modules/orz-slides-browser/docs/embedding.md`,
14
+ `node_modules/orz-slides/docs/embedding.md`). A working example:
15
+ [`examples/webapp/`](https://github.com/wangyu16/orz-slides/tree/main/examples/webapp) — two editors on
16
+ one page with every hook, under a nonce Content-Security-Policy with
17
+ `'strict-dynamic'` (`index.html`, IIFE) and the ES module variant
18
+ (`esm.html`). The test suite runs both in real Chrome, offline
19
+ (`tests/webapp.test.ts`).
20
+
21
+ ## Install and load
22
+
23
+ ```sh
24
+ npm install orz-slides-browser@1 # or: npm i orz-slides-browser@1
25
+ ```
26
+
27
+ | You want | Use | Resolves to |
28
+ |---|---|---|
29
+ | a bundler (Vite, esbuild, webpack) | `import { mountEditor } from 'orz-slides-browser'` | `esm/orz-slides.browser.mjs` (`exports` → `import`) |
30
+ | a plain `<script>` | `<script src=".../orz-slides.browser.js">` → `globalThis.OrzCarrier` | `orz-slides.browser.js` (`exports` → `default`) |
31
+ | `require()` | not supported: it throws, pointing to `import` or `<script>` | `require.cjs` (`exports` → `require`) |
32
+ | the CDN | `https://cdn.jsdelivr.net/npm/orz-slides-browser@<version>/orz-slides.browser.js` (e.g. `@1.1.0`; pin an exact version) | the same IIFE |
33
+
34
+ Types: `orz-slides-browser/index.d.ts` (`Editor`, `EditorOptions`,
35
+ `EditorHooks`, `SlidesTools`, `LayoutOp`, …). The ES module sets no global
36
+ and boots nothing; the IIFE sets `globalThis.OrzCarrier` and — only inside an
37
+ assembled `.slides.html` — starts that file's own read view (the deck) and
38
+ chrome. Both bundle orz-markdown, reveal.js 5.2.1 and the 14 slide themes
39
+ (about 2.2 MB, 0.6 MB gzipped).
40
+
41
+ ## Versions
42
+
43
+ **An app pins the component version it wants; files carry their own shells.**
44
+ Upgrading the package changes your editor, not anyone's files. The text format
45
+ (FC-18 format 1) is the only contract between them: a deck written by any 1.x
46
+ editor opens in every other 1.x editor and assembles with any 1.x shell. The
47
+ quiet update indicator never appears in an app (FC-19 §5 invariant 6).
48
+
49
+ ## Mount an editor
50
+
51
+ ```ts
52
+ import { mountEditor } from 'orz-slides-browser';
53
+
54
+ const editor = mountEditor(element, {
55
+ text, // the deck, exact (BOM, line endings kept)
56
+ mode: 'split', // 'split' | 'editor' | 'preview' (else the reader's stored preference)
57
+ chrome: 'full', // 'full' (labels) | 'compact' (icons) | 'none' (your UI drives the API)
58
+ readOnly: false,
59
+ nonce, // your CSP nonce (FC-19 §3, see below)
60
+ includes, // resolved includes for the preview: { 'parts/a.md': text, 'https://…': text } (FC-19 §3)
61
+ fileName: 'talk.slides.html', // the suggested name of saves without hooks.save (picker, download); default document.slides.html
62
+ hooks: { save, ai, fetchInclude, resolveAsset, uploadAsset, resolveLink, mintUid },
63
+ twinLinks, // (1.1) your site's names for linked texts, e.g. { slides: '{stem}.html', md: '{stem}.html' } (below)
64
+ // preferences: your PreferenceStore (default: localStorage, namespaced by the header uid)
65
+ });
66
+ ```
67
+
68
+ Any number of editors per page: each has its own undo history, preview frame
69
+ and preferences namespace; nothing is global. The chrome renders in a shadow
70
+ root (your CSS cannot break it; it cannot restyle your page); the preview runs
71
+ in a sandboxed `srcdoc` frame (`sandbox="allow-scripts"`, an opaque origin:
72
+ document scripts cannot reach your page, storage or cookies). Give an editor
73
+ room: below 640 px of width the kit shows the text and the preview as
74
+ tabs instead of side by side.
75
+
76
+ The toolbar has the view modes, the slides settings — **Theme**, **Ratio**,
77
+ **Slide numbers**, **Progress bar**, **Section numbers** (they edit the header:
78
+ `theme`, `ratio`, `slide_numbers`, `progress`, `section_numbers`; one
79
+ undoable edit each) —, **Issues** (the deck's lints, each with its line and,
80
+ where one exists, a quick fix applied as one undoable edit), an **AI** menu
81
+ when `hooks.ai` offers operations, the save state and Save. Footer,
82
+ transition and metadata stay in the header text. `chrome: 'compact'` shows
83
+ the same tools as icons. Keyboard: Cmd/Ctrl+S saves, Cmd/Ctrl+\ cycles the
84
+ modes, Cmd/Ctrl+Shift+Enter enlarges the live slide card into single-slide
85
+ editing and back, Esc leaves the text for the toolbar.
86
+
87
+ **Your site's link names** (1.1, orz-markdown 2.5.0, FC-18 §8.2). A link to
88
+ another text — `[week 2](week2.slides.md)`, `[notes](notes.md)` — points at
89
+ its assembled twin: `week2.slides.html`, `notes.md.html`. A site that
90
+ publishes under other names passes a naming, per kind a file-name template
91
+ (`{stem}` once, then only `A-Z a-z 0-9 . _ -`, ending in `.html`, same
92
+ folder): `twinLinks: { slides: '{stem}.html', md: '{stem}.html' }`. The
93
+ flattened preview and the live card then link to `week2.html`;
94
+ `assemble(text, { twinLinks })` and `renderPreview(text, { twinLinks })`
95
+ take the same, and an assembled file keeps the naming in every save and the
96
+ update (`extract(html).twinLinks`). With `hooks.resolveLink` links stay as
97
+ written, so your hook gets the source href.
98
+
99
+ ### Two ways to edit
100
+
101
+ Both edit the one text, with one undo history; the text stays the single
102
+ source of truth (no hidden layout data).
103
+
104
+ - **The whole deck** (the default): the text on the left, the **flattened**
105
+ preview on the right — every slide's content in text order (in-slide layout,
106
+ fit and floats not drawn), a thin divider per slide with its number, title
107
+ and layout, each region labelled, notes and footers set apart; scroll sync
108
+ maps a line to its slide. In the preview's bottom-right corner the **live
109
+ slide card** shows the caret's slide as it presents — at its real size
110
+ (1280 × 720 for 16:9, 960 × 720 for 4:3), scaled to the card, every box
111
+ fitted, with a badge (*fits*, *shrunk to 80%*, *footer cut*, *cut on paper*). The card can be
112
+ folded to a small tab (a reader preference) so it never covers the text.
113
+ - **Single-slide editing**: the card's **Edit** (or Cmd/Ctrl+Shift+Enter)
114
+ enlarges it into the layout editor over that slide — split a box into rows or
115
+ columns, delete a box (its content moves to the neighbour), drag a divider
116
+ (it snaps to simple ratios), choose a preset, rename or swap boxes, add,
117
+ move, resize and layer floats, choose a template's look (`v=`), set the
118
+ slide's options (fit, background, transition, step), notes and footer, and
119
+ a filmstrip to add, duplicate, delete and reorder slides. Every operation
120
+ writes the marker lines of the text — **one undoable edit** each, its lines
121
+ flashed in the text; clicking a box selects its Markdown in the editor. The
122
+ overlay lives in your page (the trusted side), over the sandboxed frame,
123
+ which only reports the boxes' geometry as data: no operation can come from
124
+ the document's scripts. The shrink icon (or the same key) goes back to the
125
+ whole deck; `?` lists the keys.
126
+
127
+ Your UI can drive both: `editor.slides.setPerSlide(true)` (the preview must
128
+ be showing: `setMode('split')` or `'preview'`), `editor.slides.isPerSlide()`,
129
+ `editor.slides.setLive(on)`, `editor.slides.caretSlide()`.
130
+
131
+ ### The `Editor` (FC-19 §4)
132
+
133
+ `getText()` · `setText(text, { resetHistory? })` · `setHeader(changes)` (one
134
+ undoable edit, FC-18 §9 rules) · `applyEdits(edits, { label? })` (several
135
+ replacements as ONE undoable edit) · `select(from, to, { scroll? })` ·
136
+ `getSelection()` · `setFocusRange(from, to, { mode? })` (dim or fold the text
137
+ outside a slide) · `flash(ranges)` · `undo()` / `redo()` · `isDirty()` /
138
+ `markSaved()` · `save()` → `{ ok, via, error?, conflict? }` (`via`: `hook`,
139
+ `host`, `file`, `download`), never rejects · `setMode(m)` / `getMode()` ·
140
+ `focus()` · `on('change' | 'dirty' | 'selection' | 'save' | 'error' |
141
+ 'print', fn)` → unsubscribe · `proposeAi(op, { selection? })` /
142
+ `applyAi(proposal, { proposed? })` (the review flow) · `requestAi(op, {
143
+ selection? })` (propose and apply at once) · `uploadAssets(files)` ·
144
+ `ensureUid()` · `setReadOnly(flag)` / `isReadOnly()` · `refreshPreview({
145
+ includes? })` · `ready` (a promise: the text engine is final, `{ engine:
146
+ 'codemirror6' }` or `{ engine: 'textarea', error }`; the editor is usable
147
+ before) · `destroy()`.
148
+
149
+ **`editor.slides`** (orz-slides' tools): `caretSlide()` (0-based) ·
150
+ `lints()` / `refreshLints()` · `applyFix({ code, line })` · `isLive()` /
151
+ `setLive(on)` (the card open or folded) · `isPerSlide()` / `setPerSlide(on)`
152
+ (single-slide editing) · `lastFit()` (the live slide's fit report: per box
153
+ its `scale` — 1 unscaled, the floor 0.6 — and `clipped`; `footerCut`) ·
154
+ `fitCoverage()`.
155
+
156
+ ### Layout operations of your own
157
+
158
+ The layout editor's operations are pure functions of the text, exported for apps
159
+ and agents: `OrzCarrier.layout` on the IIFE's global (and on the ES module's
160
+ `OrzCarrier`), or by name from the ES module — `parseDeck`, `applyOp`,
161
+ `applyEdits`, `slideMap`, `LayoutOpError`, `PRESET_CHOICES`, `SLIDE_SIZE`.
162
+ `applyOp(text, slideIndex, op)` returns the minimal edits (marker lines only;
163
+ a deleted box's block moves to its neighbour) — apply them with
164
+ `editor.applyEdits`, one undo step:
165
+
166
+ ```js
167
+ const text = editor.getText();
168
+ const i = editor.slides.caretSlide();
169
+ const box = OrzCarrier.layout.slideMap(text, i)?.boxes[0]?.name; // null: no such slide
170
+ if (box) {
171
+ const r = OrzCarrier.layout.applyOp(text, i, { type: 'split', box, dir: 'col' }); // throws LayoutOpError when it cannot apply
172
+ editor.applyEdits(r.edits, { label: r.label }); // "Split body into columns"
173
+ editor.flash(r.changed);
174
+ }
175
+ ```
176
+
177
+ Ops (`LayoutOp`): `split`, `delete-box`, `tracks`, `preset`, `rename`,
178
+ `swap`, `move-content`, `ensure-region`, `open`, `open-float`, `float-add`, `float-geom`,
179
+ `float-delete`, `float-z`, `variant`, `options`, `slide-add`,
180
+ `slide-duplicate`, `slide-delete`, `slide-move`. A marker whose tree equals a
181
+ preset is written as the preset; a marker that did not change is never
182
+ rewritten.
183
+
184
+ ### AI with a review step
185
+
186
+ The toolbar's AI menu never changes the deck by itself. Choosing an
187
+ operation calls `proposeAi`: your `hooks.ai.request` runs and the editor gets
188
+ a **proposal** (`{ op, proposed, range, original, passage }`) without touching
189
+ the text. A review panel shows it — editable — with Apply and Cancel; Apply
190
+ calls `applyAi(proposal, { proposed })`, which writes it as **one undoable
191
+ edit**, and refuses (`{ ok: false }`) if the text changed since the proposal
192
+ was made. Your own UI can run the same flow:
193
+
194
+ ```ts
195
+ const r = await editor.proposeAi('tighten', { selection: true });
196
+ if (r.ok && await myConfirm(r.proposal.original, r.proposal.proposed)) editor.applyAi(r.proposal);
197
+ ```
198
+
199
+ ## Hooks (FC-19 §3)
200
+
201
+ | Hook | Called | Return |
202
+ |---|---|---|
203
+ | `save(text)` | on Save / Cmd+S / `editor.save()` | a promise; reject to report a failure (the editor stays dirty). **With `save`, you own persistence**: nothing is written to disk or downloaded |
204
+ | `ai.operations`, `ai.request(op, { text, selection? })` | the AI menu and `editor.proposeAi` (the proposal is reviewed before `applyAi` writes it), `editor.requestAi` | `{ proposed }` — the replacement of the selection (`selection: true` operations) or of the whole text |
205
+ | `fetchInclude(target)` | the preview meets an include `includes` lacks: a URL (`{{md https://…}}` / `{{markdown …}}` / `{{md-include …}}`), or a file include's path as written (`{{md parts/a.md}}` → `'parts/a.md'`; you read your own files) | the Markdown, or `null`. Your trust policy (allowlist) decides |
206
+ | `resolveAsset(path)` | every relative `src` / `srcset` / `poster` and every slide background (`bg=`) in the flattened preview, the live slide, single-slide editing and the fit checks, **synchronously** (the preview does not wait) | the URL to load, as a string — not a promise: a URL your app already knows (a public URL, a URL signed beforehand, a `data:` URL, or a `blob:` URL of a stored asset — the editor reads a `blob:` URL it got from you once and hands the sandboxed preview, which cannot load your page's object URLs, the Blob itself: allow `connect-src blob:` and `img-src blob:`). It is asked with the path exactly as `uploadAsset` returned it (`assets/Screen Shot 1.png`, `assets/图表.png`), on every surface, never the percent-encoded form the Markdown holds |
207
+ | `uploadAsset(file)` | a file pasted or dropped into the editor, `editor.uploadAssets` | the relative path to insert (`![name](path)` for images) |
208
+ | `resolveLink(href)` | a link clicked in the preview (as written, e.g. `week2.md`) | the URL to open |
209
+ | `mintUid()` | `editor.ensureUid()` when the header has no `uid` | a **promise** of a `doc-[0-9a-z]{10,32}` id from your registry (FC-18 §10) |
210
+
211
+ **Includes.** Every preview surface (the flattened preview, the live slide,
212
+ single-slide editing) resolves an include the same way (FC-19 §3): a file
213
+ include from the `includes` option first (target as written → text, like an
214
+ assembled file's `#orz-includes`), then from `hooks.fetchInclude` with the
215
+ path as written (`'parts/a.md'`: you read your own files); a URL include
216
+ from `hooks.fetchInclude` with the URL first (your trust policy, your current
217
+ copy), then from `includes`. Each answer is asked for once per editor. An
218
+ include neither answers shows a quiet "Included file not available:
219
+ parts/a.md" note in the preview (the directive is kept).
220
+
221
+ Without `hooks.save` the editor saves like a standalone file: an inline
222
+ `.slides.html` (holding the `includes` you passed) through the File System
223
+ Access picker, else a download. Your app's page is not a served file: such a
224
+ save never shows the "opened from a web address" notice, even over https. If
225
+ the picked file is another copy of this deck (same header `uid`) whose text
226
+ changed on disk since the editor opened it, nothing is written: `save()`
227
+ resolves `{ ok: false, via: 'file', error: 'conflict', conflict: true }` and
228
+ the editor asks the reader — **Replace it** writes the file, **Download a copy
229
+ instead** downloads one. (Mounted inside an assembled `.slides.html` page, it
230
+ is an editor of that file: it saves through the file's own saver, delivery,
231
+ includes and host — with the same conflict question.)
232
+
233
+ ## The preview frame
234
+
235
+ The preview is a `srcdoc` frame (FC-19 §8.4 pluggable preview) written by
236
+ orz-slides: the kit's bridge, the deck structure and the header's slide theme
237
+ (the same stylesheets the deck presents in, inline and nonce-stamped; the
238
+ frame is rebuilt when the header's theme changes), the flattened deck in
239
+ `#orz-doc`, the kit's content libraries and the live slide's runtime (fit,
240
+ decoration, the card), all carried by the bundle — nothing is fetched for
241
+ them. The editor renders the text in your page (pure data, no DOM) and posts
242
+ it to the frame; the live card gets the caret's slide as HTML the trusted
243
+ page rendered from the text, and answers with its fit report as data (at
244
+ worst a wrong badge, never an edit, a save or a key). Fit runs only for the
245
+ visible slide, after the typing pause.
246
+
247
+ ### Printing
248
+
249
+ Cmd/Ctrl+P in the editor or its preview is the editor's `print` event: with
250
+ a listener your app decides, without one the browser prints **your page**.
251
+ Since 1.1, `printDeck(text, options)` prints the deck as an assembled
252
+ `.slides.html` does from its pencil's *Print* and *Print with notes*: one
253
+ slide per page at the slide's size, every fragment shown, each slide fitted
254
+ as on screen, whatever print had to cut marked on its page — optionally with
255
+ the speaker notes. The deck is laid out in a hidden frame of your page that
256
+ carries the engine's stylesheets, and printed with orz-markdown's
257
+ `printDocument` in a hidden `srcdoc` frame sandboxed `allow-scripts
258
+ allow-modals` (an opaque origin; the document holds no script); your page is
259
+ never printed. It resolves `true` once printed, `false` when a print of this
260
+ page is still running.
261
+
262
+ ```js
263
+ editor.on('print', () => printDeck(editor.getText(), {
264
+ nonce, // your CSP nonce: stamped on the stylesheets and the print frame's script
265
+ includes, // resolved includes, as you gave the editor
266
+ fetchInclude, // URL includes the record lacks (your trust policy)
267
+ notes: false, // true: each page the slide over its speaker notes
268
+ onCut: (message) => showMessage(message), // e.g. "slide 4 is cut on paper …"
269
+ }));
270
+ ```
271
+
272
+ `printDocument(html, { nonce })` (the kit's) is exported too, for a whole
273
+ document of your own. 1.0 had no app-side print (STATUS D-114): an app then
274
+ offered the `.slides.html` to print from its menu.
275
+
276
+ The document's own raw HTML runs only inside the frame (an opaque origin in
277
+ your page), never in your page.
278
+
279
+ ## Content-Security-Policy (FC-19 §8.4)
280
+
281
+ The preview frame is a `srcdoc` frame: it inherits your page's policy. With a
282
+ nonce policy, pass the nonce as `nonce` (FC-19 §3): the component stamps it on
283
+ CodeMirror's `<script>` and `<style>` and on every script and style of the
284
+ preview frame — the bridge, the content libraries, the live slide's runtime,
285
+ the deck structure and the slide theme. Without it, a nonce or hash policy
286
+ blocks the preview frame's inline scripts and the editor reports it (`error`
287
+ event, source `render`; its message may name the kit's option
288
+ `preview.nonce` — here the option is `nonce` on `mountEditor`). A tested
289
+ policy (one header value; replace `RANDOM` with a fresh nonce per response;
290
+ `examples/webapp/` uses the same without `frame-src`, plus
291
+ `base-uri 'none'; form-action 'none'`, which you may add too):
292
+
293
+ ```
294
+ default-src 'none'; script-src 'nonce-RANDOM' 'strict-dynamic'; style-src 'self' 'nonce-RANDOM' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://fonts.googleapis.com; style-src-attr 'unsafe-inline'; font-src https://cdn.jsdelivr.net https://fonts.gstatic.com data:; img-src 'self' data: blob: https:; connect-src 'self' blob: https://cdn.jsdelivr.net; frame-src https://www.youtube.com
295
+ ```
296
+
297
+ Why each part:
298
+
299
+ - `script-src` with `'strict-dynamic'`: the nonce also covers the scripts the
300
+ component loads (CodeMirror, the preview libraries).
301
+ - `style-src-attr 'unsafe-inline'`: fit, the single-slide overlay, KaTeX and
302
+ the diagram libraries write style attributes.
303
+ - `font-src`: the slide themes' webfonts (Google Fonts) and KaTeX's.
304
+ - `img-src`: must cover wherever `hooks.resolveAsset` points.
305
+ - `connect-src`: `blob:` only if `resolveAsset` gives `blob:` URLs (the editor
306
+ reads their bytes for the preview).
307
+ - `frame-src https://www.youtube.com`: only if your decks embed YouTube
308
+ videos (`{{youtube …}}`: the player is a youtube.com/embed frame); drop it
309
+ otherwise.
310
+
311
+ The same value works in a `<meta http-equiv="Content-Security-Policy">` tag
312
+ (the example does that).
313
+
314
+ **Use a nonce, not hashes.** `mountEditor` takes no hash list. An app that
315
+ builds its own preview frame with the kit (`orz-markdown/carrier/editor`'s
316
+ `PREVIEW_BRIDGE_HASH`, `previewScriptHashes`) must take the hash from the
317
+ same orz-markdown version its frame runs: the bridge, and so its hash,
318
+ differs between kit versions (2.3.0 and 2.4.0 differ; orz-slides 1.0 embeds
319
+ 2.4.0, 1.1 embeds 2.5.0). Tested in Chrome: the editor (CodeMirror 6), math,
320
+ code highlighting, Mermaid, Chart.js and SMILES render in the preview with
321
+ no violation but one — Mermaid's run-time `<style>` (below).
322
+
323
+ What loads from where: CodeMirror 6 from
324
+ `cdn.jsdelivr.net/npm/orz-markdown@<version>/vendor/codemirror6.js` (pinned,
325
+ SRI-checked; a textarea until it arrives); the slide themes are inside the
326
+ bundle (no theme fetch), their webfonts from Google Fonts
327
+ (`fonts.googleapis.com` stylesheets, `fonts.gstatic.com` fonts); KaTeX CSS
328
+ from jsDelivr, highlight.js from cdnjs, Mermaid / Chart.js from jsDelivr,
329
+ SMILES from unpkg (the preview libraries; with `'strict-dynamic'` the nonce
330
+ covers them). Mermaid inserts `<style>` elements at run time that nobody
331
+ stamps; a nonce policy blocks them and the diagram is drawn unreadable
332
+ (black shapes, no theme styling). If your decks use diagrams, add
333
+
334
+ ```
335
+ style-src-elem 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://fonts.googleapis.com;
336
+ ```
337
+
338
+ A `style-src-elem` directive *replaces* `style-src` for `<style>` and
339
+ `<link rel=stylesheet>` elements, so it repeats the whole list (your own
340
+ stylesheets, KaTeX, highlight.js, the webfonts) — `style-src-elem
341
+ 'unsafe-inline'` alone would block them all — and it carries no nonce (a
342
+ nonce switches `'unsafe-inline'` off). Offline, editing works without them: the text is edited in a textarea
343
+ until CodeMirror arrives, the themes fall back to system fonts, and
344
+ formulas, diagrams and charts wait for their libraries.
345
+
346
+ ## Without an editor
347
+
348
+ ```ts
349
+ import { assemble, extract, readDocument, renderPreview, newDocument, TEMPLATE_IDS, THEMES, parseDeck, includeTargets, linkTargets, themeSwatch } from 'orz-slides-browser';
350
+
351
+ readDocument(text) // header + derived facts (title, author, uid, theme, settings, lint) — no rendering; index with it
352
+ parseDeck(text) // the deck: config, slides (kind, template, title, layout, regions, notes, footer), lint
353
+ await renderPreview(text, { includes, fetchInclude }) // the flattened deck's HTML (dividers, region labels), not the slides
354
+ await renderPreview(text, { document: true, nonce }) // a whole HTML document of it: the slide theme and the flattened styles inline (<style> stamped with your nonce), no script (iframe srcdoc, thumbnails)
355
+ includeTargets(text) // (1.1) the include directives' targets, as written (orz-markdown 2.5.0, browser-safe)
356
+ linkTargets(text) // (1.1) every link and image: { href, line, kind: 'twin' | 'asset' | 'other', image, raw } — a site builder's link check
357
+ newDocument({ template: 'talk', title, theme: 'nocturne', ratio: '4:3' }) // a new text from a deck template (TEMPLATE_IDS: starter, talk, minimal): carrier slides, a fresh uid
358
+ await assemble(text, { delivery: 'cdn' }) // a small .slides.html that loads the engine from jsDelivr
359
+ await assemble(text) // an inline .slides.html (the IIFE inlines itself; the ES module fetches this release's bundle once, or pass engineSource)
360
+ await assemble(text, { includes }) // with resolved includes in #orz-includes
361
+ await assemble(text, { twinLinks: { slides: '{stem}.html' } }) // (1.1) links to text twins named your site's way; kept by every save
362
+ extract(html) // { text, kind, format, shell, delivery, includes, twinLinks? } | null
363
+ // (1.1) an orz-slides 0.x file: the text `upgrade` writes, shell '', legacy: { version, notes }
364
+ ```
365
+
366
+ The slides themselves need the engine's layout (reveal.js, fit) — in the
367
+ editor's live card and in an assembled file's read view — so
368
+ `renderPreview` gives the flattened deck: a styled, continuous view for
369
+ thumbnails and lists. It adds no script of its own, but it keeps the
370
+ document's raw HTML as written — a deck can hold `<script>` and event
371
+ handlers (documents come from trusted sources; orz-markdown does not filter
372
+ them). Show its output only in a sandboxed frame (`<iframe sandbox
373
+ srcdoc=…>`, without `allow-same-origin`), never with `innerHTML` in your page.
374
+
375
+ `assemble` writes the same bytes as the Node library (`orz-slides`), so an app
376
+ can publish, preview or download without a server. Store the text; regenerate
377
+ the HTML. `THEMES` lists the 14 slide themes (`id`, `name`, `scheme`
378
+ light/dark, `description`, and since 1.1 `paper` / `accent`, the page and
379
+ signature colours); `themeSwatch(id)` is a theme picker's dot (a CSS
380
+ `background`); `DEFAULT_THEME` is `orchard`.
381
+
382
+ ## Assembled files in an iframe
383
+
384
+ To show **assembled files** (untrusted or third-party `.slides.html`) rather
385
+ than the component, embed them in a sandboxed iframe and speak the host
386
+ protocols (`orz-host-save@1`, `orz-host-ai@1`, `orz-host-include@1`;
387
+ orz-markdown `spec/host-protocols.md`, host side `embedCarrierFrame` in
388
+ `orz-markdown/carrier/shell`; see `PROTOCOL.md`). The file then saves to you,
389
+ takes AI operations and include resolution from you, and shows no update
390
+ indicator. Present, the speaker view (its own window) and Print run inside
391
+ the file.