orz-slides-browser 0.8.5 → 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/README.md +41 -8
- package/docs/embedding.md +333 -0
- package/esm/orz-slides.browser.mjs +22547 -0
- package/index.d.ts +361 -0
- package/orz-slides.browser.js +22308 -140
- package/package.json +43 -4
- package/release.json +12 -0
- package/require.cjs +3 -0
package/README.md
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
# orz-slides-browser
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
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.4 and
|
|
9
|
+
[reveal.js](https://revealjs.com/) 5.2.1 (both bundled), with the 14 slide
|
|
10
|
+
themes inside.
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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, standalone, layout }` — `layout` holds the per-slide 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` | the same API as ES module exports, plus `OrzCarrier`, `THEMES`, `DEFAULT_THEME`, `TEMPLATES`, `TEMPLATE_IDS`, `DEFAULT_TEMPLATE`, `newDocument`, `editHeader`, `parseDeck` and the per-slide 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
|
-
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/orz-slides-browser@1.0.0/orz-slides.browser.js"></script>
|
|
30
|
+
<script>const editor = OrzCarrier.mountEditor(element, { text, hooks: { save } });</script>
|
|
12
31
|
```
|
|
13
32
|
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
`.slides.html` files carry the bundle inline (the CLI's default) or load it
|
|
34
|
+
from `https://cdn.jsdelivr.net/npm/orz-slides-browser@<version>/orz-slides.browser.js`
|
|
35
|
+
(`--cdn`); the slide themes are inside the bundle, so both style the same.
|
|
36
|
+
The bundle holds no `<script` / `</script`, no CR and only ASCII, so it can be
|
|
37
|
+
inlined byte for byte and checked against `release.json`.
|
|
38
|
+
`require('orz-slides-browser')` is not supported (it throws): use `import` or a
|
|
39
|
+
`<script>` tag.
|
|
40
|
+
|
|
41
|
+
Embedding guide (hooks, the two editing modes, the preview frame, CSP,
|
|
42
|
+
versions): `docs/embedding.md` in this package
|
|
43
|
+
([on GitHub](https://github.com/wangyu16/orz-slides/blob/main/docs/embedding.md)).
|
|
44
|
+
Versioned in lockstep with `orz-slides`; built by its `build/bundle.ts`.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
@@ -0,0 +1,333 @@
|
|
|
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.0.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
|
+
// preferences: your PreferenceStore (default: localStorage, namespaced by the header uid)
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Any number of editors per page: each has its own undo history, preview frame
|
|
68
|
+
and preferences namespace; nothing is global. The chrome renders in a shadow
|
|
69
|
+
root (your CSS cannot break it; it cannot restyle your page); the preview runs
|
|
70
|
+
in a sandboxed `srcdoc` frame (`sandbox="allow-scripts"`, an opaque origin:
|
|
71
|
+
document scripts cannot reach your page, storage or cookies). Give an editor
|
|
72
|
+
room: below 640 px of width the kit shows the text and the preview as
|
|
73
|
+
tabs instead of side by side.
|
|
74
|
+
|
|
75
|
+
The toolbar has the view modes, the slides settings — **Theme**, **Ratio**,
|
|
76
|
+
**Slide numbers**, **Progress bar**, **Section numbers** (they edit the header:
|
|
77
|
+
`theme`, `ratio`, `slide_numbers`, `progress`, `section_numbers`; one
|
|
78
|
+
undoable edit each) —, **Issues** (the deck's lints, each with its line and,
|
|
79
|
+
where one exists, a quick fix applied as one undoable edit), an **AI** menu
|
|
80
|
+
when `hooks.ai` offers operations, the save state and Save. Footer,
|
|
81
|
+
transition and metadata stay in the header text. `chrome: 'compact'` shows
|
|
82
|
+
the same tools as icons. Keyboard: Cmd/Ctrl+S saves, Cmd/Ctrl+\ cycles the
|
|
83
|
+
modes, Cmd/Ctrl+Shift+Enter enlarges the live slide card into single-slide
|
|
84
|
+
editing and back, Esc leaves the text for the toolbar.
|
|
85
|
+
|
|
86
|
+
### Two ways to edit
|
|
87
|
+
|
|
88
|
+
Both edit the one text, with one undo history; the text stays the single
|
|
89
|
+
source of truth (no hidden layout data).
|
|
90
|
+
|
|
91
|
+
- **The whole deck** (the default): the text on the left, the **flattened**
|
|
92
|
+
preview on the right — every slide's content in text order (in-slide layout,
|
|
93
|
+
fit and floats not drawn), a thin divider per slide with its number, title
|
|
94
|
+
and layout, each region labelled, notes and footers set apart; scroll sync
|
|
95
|
+
maps a line to its slide. In the preview's bottom-right corner the **live
|
|
96
|
+
slide card** shows the caret's slide as it presents — at its real size
|
|
97
|
+
(1280 × 720 for 16:9, 960 × 720 for 4:3), scaled to the card, every box
|
|
98
|
+
fitted, with a badge (*fits*, *shrunk to 80%*, *footer cut*, *cut on paper*). The card can be
|
|
99
|
+
folded to a small tab (a reader preference) so it never covers the text.
|
|
100
|
+
- **Single-slide editing**: the card's **Edit** (or Cmd/Ctrl+Shift+Enter)
|
|
101
|
+
enlarges it into the layout GUI over that slide — split a box into rows or
|
|
102
|
+
columns, delete a box (its content moves to the neighbour), drag a divider
|
|
103
|
+
(it snaps to simple ratios), choose a preset, rename or swap boxes, add,
|
|
104
|
+
move, resize and layer floats, choose a template's look (`v=`), set the
|
|
105
|
+
slide's options (fit, background, transition, step), notes and footer, and
|
|
106
|
+
a filmstrip to add, duplicate, delete and reorder slides. Every operation
|
|
107
|
+
writes the marker lines of the text — **one undoable edit** each, its lines
|
|
108
|
+
flashed in the text; clicking a box selects its Markdown in the editor. The
|
|
109
|
+
overlay lives in your page (the trusted side), over the sandboxed frame,
|
|
110
|
+
which only reports the boxes' geometry as data: no operation can come from
|
|
111
|
+
the document's scripts. The shrink icon (or the same key) goes back to the
|
|
112
|
+
whole deck; `?` lists the keys.
|
|
113
|
+
|
|
114
|
+
Your UI can drive both: `editor.slides.setPerSlide(true)` (the preview must
|
|
115
|
+
be showing: `setMode('split')` or `'preview'`), `editor.slides.isPerSlide()`,
|
|
116
|
+
`editor.slides.setLive(on)`, `editor.slides.caretSlide()`.
|
|
117
|
+
|
|
118
|
+
### The `Editor` (FC-19 §4)
|
|
119
|
+
|
|
120
|
+
`getText()` · `setText(text, { resetHistory? })` · `setHeader(changes)` (one
|
|
121
|
+
undoable edit, FC-18 §9 rules) · `applyEdits(edits, { label? })` (several
|
|
122
|
+
replacements as ONE undoable edit) · `select(from, to, { scroll? })` ·
|
|
123
|
+
`getSelection()` · `setFocusRange(from, to, { mode? })` (dim or fold the text
|
|
124
|
+
outside a slide) · `flash(ranges)` · `undo()` / `redo()` · `isDirty()` /
|
|
125
|
+
`markSaved()` · `save()` → `{ ok, via, error?, conflict? }` (`via`: `hook`,
|
|
126
|
+
`host`, `file`, `download`), never rejects · `setMode(m)` / `getMode()` ·
|
|
127
|
+
`focus()` · `on('change' | 'dirty' | 'selection' | 'save' | 'error' |
|
|
128
|
+
'print', fn)` → unsubscribe · `proposeAi(op, { selection? })` /
|
|
129
|
+
`applyAi(proposal, { proposed? })` (the review flow) · `requestAi(op, {
|
|
130
|
+
selection? })` (propose and apply at once) · `uploadAssets(files)` ·
|
|
131
|
+
`ensureUid()` · `setReadOnly(flag)` / `isReadOnly()` · `refreshPreview({
|
|
132
|
+
includes? })` · `ready` (a promise: the text engine is final, `{ engine:
|
|
133
|
+
'codemirror6' }` or `{ engine: 'textarea', error }`; the editor is usable
|
|
134
|
+
before) · `destroy()`.
|
|
135
|
+
|
|
136
|
+
**`editor.slides`** (orz-slides' tools): `caretSlide()` (0-based) ·
|
|
137
|
+
`lints()` / `refreshLints()` · `applyFix({ code, line })` · `isLive()` /
|
|
138
|
+
`setLive(on)` (the card open or folded) · `isPerSlide()` / `setPerSlide(on)`
|
|
139
|
+
(single-slide editing) · `lastFit()` (the live slide's fit report: per box
|
|
140
|
+
its `scale` — 1 unscaled, the floor 0.6 — and `clipped`; `footerCut`) ·
|
|
141
|
+
`fitCoverage()`.
|
|
142
|
+
|
|
143
|
+
### Layout operations of your own
|
|
144
|
+
|
|
145
|
+
The layout GUI's operations are pure functions of the text, exported for apps
|
|
146
|
+
and agents: `OrzCarrier.layout` on the IIFE's global (and on the ES module's
|
|
147
|
+
`OrzCarrier`), or by name from the ES module — `parseDeck`, `applyOp`,
|
|
148
|
+
`applyEdits`, `slideMap`, `LayoutOpError`, `PRESET_CHOICES`, `SLIDE_SIZE`.
|
|
149
|
+
`applyOp(text, slideIndex, op)` returns the minimal edits (marker lines only;
|
|
150
|
+
a deleted box's block moves to its neighbour) — apply them with
|
|
151
|
+
`editor.applyEdits`, one undo step:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const text = editor.getText();
|
|
155
|
+
const i = editor.slides.caretSlide();
|
|
156
|
+
const box = OrzCarrier.layout.slideMap(text, i)?.boxes[0]?.name; // null: no such slide
|
|
157
|
+
if (box) {
|
|
158
|
+
const r = OrzCarrier.layout.applyOp(text, i, { type: 'split', box, dir: 'col' }); // throws LayoutOpError when it cannot apply
|
|
159
|
+
editor.applyEdits(r.edits, { label: r.label }); // "Split body into columns"
|
|
160
|
+
editor.flash(r.changed);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Ops (`LayoutOp`): `split`, `delete-box`, `tracks`, `preset`, `rename`,
|
|
165
|
+
`swap`, `move-content`, `ensure-region`, `float-add`, `float-geom`,
|
|
166
|
+
`float-delete`, `float-z`, `variant`, `options`, `slide-add`,
|
|
167
|
+
`slide-duplicate`, `slide-delete`, `slide-move`. A marker whose tree equals a
|
|
168
|
+
preset is written as the preset; a marker that did not change is never
|
|
169
|
+
rewritten.
|
|
170
|
+
|
|
171
|
+
### AI with a review step
|
|
172
|
+
|
|
173
|
+
The toolbar's AI menu never changes the deck by itself. Choosing an
|
|
174
|
+
operation calls `proposeAi`: your `hooks.ai.request` runs and the editor gets
|
|
175
|
+
a **proposal** (`{ op, proposed, range, original, passage }`) without touching
|
|
176
|
+
the text. A review panel shows it — editable — with Apply and Cancel; Apply
|
|
177
|
+
calls `applyAi(proposal, { proposed })`, which writes it as **one undoable
|
|
178
|
+
edit**, and refuses (`{ ok: false }`) if the text changed since the proposal
|
|
179
|
+
was made. Your own UI can run the same flow:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const r = await editor.proposeAi('tighten', { selection: true });
|
|
183
|
+
if (r.ok && await myConfirm(r.proposal.original, r.proposal.proposed)) editor.applyAi(r.proposal);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Hooks (FC-19 §3)
|
|
187
|
+
|
|
188
|
+
| Hook | Called | Return |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `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 |
|
|
191
|
+
| `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 |
|
|
192
|
+
| `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 |
|
|
193
|
+
| `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 |
|
|
194
|
+
| `uploadAsset(file)` | a file pasted or dropped into the editor, `editor.uploadAssets` | the relative path to insert (`` for images) |
|
|
195
|
+
| `resolveLink(href)` | a link clicked in the preview (as written, e.g. `week2.md`) | the URL to open |
|
|
196
|
+
| `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) |
|
|
197
|
+
|
|
198
|
+
**Includes.** Every preview surface (the flattened preview, the live slide,
|
|
199
|
+
single-slide editing) resolves an include the same way (FC-19 §3): a file
|
|
200
|
+
include from the `includes` option first (target as written → text, like an
|
|
201
|
+
assembled file's `#orz-includes`), then from `hooks.fetchInclude` with the
|
|
202
|
+
path as written (`'parts/a.md'`: you read your own files); a URL include
|
|
203
|
+
from `hooks.fetchInclude` with the URL first (your trust policy, your current
|
|
204
|
+
copy), then from `includes`. Each answer is asked for once per editor. An
|
|
205
|
+
include neither answers shows a quiet "Included file not available:
|
|
206
|
+
parts/a.md" note in the preview (the directive is kept).
|
|
207
|
+
|
|
208
|
+
Without `hooks.save` the editor saves like a standalone file: an inline
|
|
209
|
+
`.slides.html` (holding the `includes` you passed) through the File System
|
|
210
|
+
Access picker, else a download. Your app's page is not a served file: such a
|
|
211
|
+
save never shows the "opened from a web address" notice, even over https. If
|
|
212
|
+
the picked file is another copy of this deck (same header `uid`) whose text
|
|
213
|
+
changed on disk since the editor opened it, nothing is written: `save()`
|
|
214
|
+
resolves `{ ok: false, via: 'file', error: 'conflict', conflict: true }` and
|
|
215
|
+
the editor asks the reader — **Replace it** writes the file, **Download a copy
|
|
216
|
+
instead** downloads one. (Mounted inside an assembled `.slides.html` page, it
|
|
217
|
+
is an editor of that file: it saves through the file's own saver, delivery,
|
|
218
|
+
includes and host — with the same conflict question.)
|
|
219
|
+
|
|
220
|
+
## The preview frame
|
|
221
|
+
|
|
222
|
+
The preview is a `srcdoc` frame (FC-19 §8.4 pluggable preview) written by
|
|
223
|
+
orz-slides: the kit's bridge, the deck structure and the header's slide theme
|
|
224
|
+
(the same stylesheets the deck presents in, inline and nonce-stamped; the
|
|
225
|
+
frame is rebuilt when the header's theme changes), the flattened deck in
|
|
226
|
+
`#orz-doc`, the kit's content libraries and the live slide's runtime (fit,
|
|
227
|
+
decoration, the card), all carried by the bundle — nothing is fetched for
|
|
228
|
+
them. The editor renders the text in your page (pure data, no DOM) and posts
|
|
229
|
+
it to the frame; the live card gets the caret's slide as HTML the trusted
|
|
230
|
+
page rendered from the text, and answers with its fit report as data (at
|
|
231
|
+
worst a wrong badge, never an edit, a save or a key). Fit runs only for the
|
|
232
|
+
visible slide, after the typing pause.
|
|
233
|
+
|
|
234
|
+
### Printing
|
|
235
|
+
|
|
236
|
+
Cmd/Ctrl+P in the editor or its preview is the editor's `print` event: with
|
|
237
|
+
a listener your app decides, without one the browser prints **your page**.
|
|
238
|
+
orz-slides-browser 1.0 has no app-side print of the slides: the deck's print
|
|
239
|
+
document — one slide per page at the slide's size, every fragment shown,
|
|
240
|
+
optionally with the speaker notes — is built by the read view of an
|
|
241
|
+
assembled `.slides.html` (its pencil's *Print* and *Print with notes*). An
|
|
242
|
+
app listens to `print` (so your page is not printed) and offers the file:
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
editor.on('print', () => showMessage('To print the slides, download the .slides.html and use Print in its menu.'));
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The document's own raw HTML runs only inside the frame (an opaque origin in
|
|
249
|
+
your page), never in your page.
|
|
250
|
+
|
|
251
|
+
## Content-Security-Policy (FC-19 §8.4)
|
|
252
|
+
|
|
253
|
+
The preview frame is a `srcdoc` frame: it inherits your page's policy. With a
|
|
254
|
+
nonce policy, pass the nonce as `nonce` (FC-19 §3): the component stamps it on
|
|
255
|
+
CodeMirror's `<script>` and `<style>` and on every script and style of the
|
|
256
|
+
preview frame — the bridge, the content libraries, the live slide's runtime,
|
|
257
|
+
the deck structure and the slide theme. Without it, a nonce or hash policy
|
|
258
|
+
blocks the preview frame's inline scripts and the editor reports it (`error`
|
|
259
|
+
event, source `render`). The example's policy:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
default-src 'none';
|
|
263
|
+
script-src 'nonce-RANDOM' 'strict-dynamic';
|
|
264
|
+
style-src 'self' 'nonce-RANDOM' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://fonts.googleapis.com;
|
|
265
|
+
style-src-attr 'unsafe-inline'; (fit, the single-slide overlay, KaTeX and the diagram libraries write style attributes)
|
|
266
|
+
font-src https://cdn.jsdelivr.net https://fonts.gstatic.com data:; (the slide themes' webfonts: Google Fonts; KaTeX's)
|
|
267
|
+
img-src 'self' data: blob: https:; (wherever resolveAsset points)
|
|
268
|
+
connect-src 'self' blob: https://cdn.jsdelivr.net; (blob: only if resolveAsset gives blob: URLs: the editor reads their bytes for the preview)
|
|
269
|
+
frame-src https://www.youtube.com; (only if your decks embed YouTube videos, `{{youtube …}}`: the player is a youtube.com/embed frame)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
What loads from where: CodeMirror 6 from
|
|
273
|
+
`cdn.jsdelivr.net/npm/orz-markdown@<version>/vendor/codemirror6.js` (pinned,
|
|
274
|
+
SRI-checked; a textarea until it arrives); the slide themes are inside the
|
|
275
|
+
bundle (no theme fetch), their webfonts from Google Fonts
|
|
276
|
+
(`fonts.googleapis.com` stylesheets, `fonts.gstatic.com` fonts); KaTeX CSS
|
|
277
|
+
from jsDelivr, highlight.js from cdnjs, Mermaid / Chart.js from jsDelivr,
|
|
278
|
+
SMILES from unpkg (the preview libraries; with `'strict-dynamic'` the nonce
|
|
279
|
+
covers them). Mermaid inserts `<style>` elements at run time that nobody
|
|
280
|
+
stamps: if your decks use diagrams, add
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
style-src-elem 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://fonts.googleapis.com;
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
A `style-src-elem` directive *replaces* `style-src` for `<style>` and
|
|
287
|
+
`<link rel=stylesheet>` elements, so it repeats the whole list (your own
|
|
288
|
+
stylesheets, KaTeX, highlight.js, the webfonts) — `style-src-elem
|
|
289
|
+
'unsafe-inline'` alone would block them all — and it carries no nonce (a
|
|
290
|
+
nonce switches `'unsafe-inline'` off). Offline, editing works without them: the text is edited in a textarea
|
|
291
|
+
until CodeMirror arrives, the themes fall back to system fonts, and
|
|
292
|
+
formulas, diagrams and charts wait for their libraries.
|
|
293
|
+
|
|
294
|
+
## Without an editor
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { assemble, extract, readDocument, renderPreview, newDocument, TEMPLATE_IDS, THEMES, parseDeck } from 'orz-slides-browser';
|
|
298
|
+
|
|
299
|
+
readDocument(text) // header + derived facts (title, author, uid, theme, settings, lint) — no rendering; index with it
|
|
300
|
+
parseDeck(text) // the deck: config, slides (kind, template, title, layout, regions, notes, footer), lint
|
|
301
|
+
await renderPreview(text, { includes, fetchInclude }) // the flattened deck's HTML (dividers, region labels), not the slides
|
|
302
|
+
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)
|
|
303
|
+
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
|
|
304
|
+
await assemble(text, { delivery: 'cdn' }) // a small .slides.html that loads the engine from jsDelivr
|
|
305
|
+
await assemble(text) // an inline .slides.html (the IIFE inlines itself; the ES module fetches this release's bundle once, or pass engineSource)
|
|
306
|
+
await assemble(text, { includes }) // with resolved includes in #orz-includes
|
|
307
|
+
extract(html) // { text, kind, format, shell, delivery, includes } | null
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The slides themselves need the engine's layout (reveal.js, fit) — in the
|
|
311
|
+
editor's live card and in an assembled file's read view — so
|
|
312
|
+
`renderPreview` gives the flattened deck: a styled, continuous view for
|
|
313
|
+
thumbnails and lists. It adds no script of its own, but it keeps the
|
|
314
|
+
document's raw HTML as written — a deck can hold `<script>` and event
|
|
315
|
+
handlers (documents come from trusted sources; orz-markdown does not filter
|
|
316
|
+
them). Show its output only in a sandboxed frame (`<iframe sandbox
|
|
317
|
+
srcdoc=…>`, without `allow-same-origin`), never with `innerHTML` in your page.
|
|
318
|
+
|
|
319
|
+
`assemble` writes the same bytes as the Node library (`orz-slides`), so an app
|
|
320
|
+
can publish, preview or download without a server. Store the text; regenerate
|
|
321
|
+
the HTML. `THEMES` lists the 14 slide themes (`id`, `name`, `scheme`
|
|
322
|
+
light/dark, `description`); `DEFAULT_THEME` is `orchard`.
|
|
323
|
+
|
|
324
|
+
## Assembled files in an iframe
|
|
325
|
+
|
|
326
|
+
To show **assembled files** (untrusted or third-party `.slides.html`) rather
|
|
327
|
+
than the component, embed them in a sandboxed iframe and speak the host
|
|
328
|
+
protocols (`orz-host-save@1`, `orz-host-ai@1`, `orz-host-include@1`;
|
|
329
|
+
orz-markdown `spec/host-protocols.md`, host side `embedCarrierFrame` in
|
|
330
|
+
`orz-markdown/carrier/shell`; see `PROTOCOL.md`). The file then saves to you,
|
|
331
|
+
takes AI operations and include resolution from you, and shows no update
|
|
332
|
+
indicator. Present, the speaker view (its own window) and Print run inside
|
|
333
|
+
the file.
|