orz-slides-browser 1.0.0 → 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
@@ -5,9 +5,9 @@ The browser engine and editor component of
5
5
  Markdown that present, edit and save themselves: the very bundle every
6
6
  `.slides.html` file carries, and the same editor for web apps (orz family
7
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.
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.
11
11
 
12
12
  ```sh
13
13
  npm i orz-slides-browser@1
@@ -15,8 +15,8 @@ npm i orz-slides-browser@1
15
15
 
16
16
  | File | What |
17
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. |
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
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
21
  | `index.d.ts` | types (`Editor`, `EditorOptions`, `EditorHooks`, `SlidesTools`, `LayoutOp`, …). |
22
22
 
@@ -26,10 +26,14 @@ const editor = mountEditor(element, { text, nonce, hooks: { async save(text) { /
26
26
  ```
27
27
 
28
28
  ```html
29
- <script src="https://cdn.jsdelivr.net/npm/orz-slides-browser@1.0.0/orz-slides.browser.js"></script>
29
+ <script src="https://cdn.jsdelivr.net/npm/orz-slides-browser@1.1.0/orz-slides.browser.js"></script>
30
30
  <script>const editor = OrzCarrier.mountEditor(element, { text, hooks: { save } });</script>
31
31
  ```
32
32
 
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
+
33
37
  `.slides.html` files carry the bundle inline (the CLI's default) or load it
34
38
  from `https://cdn.jsdelivr.net/npm/orz-slides-browser@<version>/orz-slides.browser.js`
35
39
  (`--cdn`); the slide themes are inside the bundle, so both style the same.
@@ -38,6 +42,33 @@ inlined byte for byte and checked against `release.json`.
38
42
  `require('orz-slides-browser')` is not supported (it throws): use `import` or a
39
43
  `<script>` tag.
40
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
+
41
72
  Embedding guide (hooks, the two editing modes, the preview frame, CSP,
42
73
  versions): `docs/embedding.md` in this package
43
74
  ([on GitHub](https://github.com/wangyu16/orz-slides/blob/main/docs/embedding.md)).
package/docs/embedding.md CHANGED
@@ -29,7 +29,7 @@ npm install orz-slides-browser@1 # or: npm i orz-slides-browser@1
29
29
  | a bundler (Vite, esbuild, webpack) | `import { mountEditor } from 'orz-slides-browser'` | `esm/orz-slides.browser.mjs` (`exports` → `import`) |
30
30
  | a plain `<script>` | `<script src=".../orz-slides.browser.js">` → `globalThis.OrzCarrier` | `orz-slides.browser.js` (`exports` → `default`) |
31
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 |
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
33
 
34
34
  Types: `orz-slides-browser/index.d.ts` (`Editor`, `EditorOptions`,
35
35
  `EditorHooks`, `SlidesTools`, `LayoutOp`, …). The ES module sets no global
@@ -60,6 +60,7 @@ const editor = mountEditor(element, {
60
60
  includes, // resolved includes for the preview: { 'parts/a.md': text, 'https://…': text } (FC-19 §3)
61
61
  fileName: 'talk.slides.html', // the suggested name of saves without hooks.save (picker, download); default document.slides.html
62
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)
63
64
  // preferences: your PreferenceStore (default: localStorage, namespaced by the header uid)
64
65
  });
65
66
  ```
@@ -83,6 +84,18 @@ the same tools as icons. Keyboard: Cmd/Ctrl+S saves, Cmd/Ctrl+\ cycles the
83
84
  modes, Cmd/Ctrl+Shift+Enter enlarges the live slide card into single-slide
84
85
  editing and back, Esc leaves the text for the toolbar.
85
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
+
86
99
  ### Two ways to edit
87
100
 
88
101
  Both edit the one text, with one undo history; the text stays the single
@@ -98,7 +111,7 @@ source of truth (no hidden layout data).
98
111
  fitted, with a badge (*fits*, *shrunk to 80%*, *footer cut*, *cut on paper*). The card can be
99
112
  folded to a small tab (a reader preference) so it never covers the text.
100
113
  - **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
114
+ enlarges it into the layout editor over that slide — split a box into rows or
102
115
  columns, delete a box (its content moves to the neighbour), drag a divider
103
116
  (it snaps to simple ratios), choose a preset, rename or swap boxes, add,
104
117
  move, resize and layer floats, choose a template's look (`v=`), set the
@@ -142,7 +155,7 @@ its `scale` — 1 unscaled, the floor 0.6 — and `clipped`; `footerCut`) ·
142
155
 
143
156
  ### Layout operations of your own
144
157
 
145
- The layout GUI's operations are pure functions of the text, exported for apps
158
+ The layout editor's operations are pure functions of the text, exported for apps
146
159
  and agents: `OrzCarrier.layout` on the IIFE's global (and on the ES module's
147
160
  `OrzCarrier`), or by name from the ES module — `parseDeck`, `applyOp`,
148
161
  `applyEdits`, `slideMap`, `LayoutOpError`, `PRESET_CHOICES`, `SLIDE_SIZE`.
@@ -162,7 +175,7 @@ editor.flash(r.changed);
162
175
  ```
163
176
 
164
177
  Ops (`LayoutOp`): `split`, `delete-box`, `tracks`, `preset`, `rename`,
165
- `swap`, `move-content`, `ensure-region`, `float-add`, `float-geom`,
178
+ `swap`, `move-content`, `ensure-region`, `open`, `open-float`, `float-add`, `float-geom`,
166
179
  `float-delete`, `float-z`, `variant`, `options`, `slide-add`,
167
180
  `slide-duplicate`, `slide-delete`, `slide-move`. A marker whose tree equals a
168
181
  preset is written as the preset; a marker that did not change is never
@@ -235,16 +248,31 @@ visible slide, after the typing pause.
235
248
 
236
249
  Cmd/Ctrl+P in the editor or its preview is the editor's `print` event: with
237
250
  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:
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.
243
261
 
244
262
  ```js
245
- editor.on('print', () => showMessage('To print the slides, download the .slides.html and use Print in its menu.'));
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
+ }));
246
270
  ```
247
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
+
248
276
  The document's own raw HTML runs only inside the frame (an opaque origin in
249
277
  your page), never in your page.
250
278
 
@@ -256,19 +284,42 @@ CodeMirror's `<script>` and `<style>` and on every script and style of the
256
284
  preview frame — the bridge, the content libraries, the live slide's runtime,
257
285
  the deck structure and the slide theme. Without it, a nonce or hash policy
258
286
  blocks the preview frame's inline scripts and the editor reports it (`error`
259
- event, source `render`). The example's policy:
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):
260
292
 
261
293
  ```
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)
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
270
295
  ```
271
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
+
272
323
  What loads from where: CodeMirror 6 from
273
324
  `cdn.jsdelivr.net/npm/orz-markdown@<version>/vendor/codemirror6.js` (pinned,
274
325
  SRI-checked; a textarea until it arrives); the slide themes are inside the
@@ -277,7 +328,8 @@ bundle (no theme fetch), their webfonts from Google Fonts
277
328
  from jsDelivr, highlight.js from cdnjs, Mermaid / Chart.js from jsDelivr,
278
329
  SMILES from unpkg (the preview libraries; with `'strict-dynamic'` the nonce
279
330
  covers them). Mermaid inserts `<style>` elements at run time that nobody
280
- stamps: if your decks use diagrams, add
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
281
333
 
282
334
  ```
283
335
  style-src-elem 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://fonts.googleapis.com;
@@ -294,17 +346,21 @@ formulas, diagrams and charts wait for their libraries.
294
346
  ## Without an editor
295
347
 
296
348
  ```ts
297
- import { assemble, extract, readDocument, renderPreview, newDocument, TEMPLATE_IDS, THEMES, parseDeck } from 'orz-slides-browser';
349
+ import { assemble, extract, readDocument, renderPreview, newDocument, TEMPLATE_IDS, THEMES, parseDeck, includeTargets, linkTargets, themeSwatch } from 'orz-slides-browser';
298
350
 
299
351
  readDocument(text) // header + derived facts (title, author, uid, theme, settings, lint) — no rendering; index with it
300
352
  parseDeck(text) // the deck: config, slides (kind, template, title, layout, regions, notes, footer), lint
301
353
  await renderPreview(text, { includes, fetchInclude }) // the flattened deck's HTML (dividers, region labels), not the slides
302
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
303
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
304
358
  await assemble(text, { delivery: 'cdn' }) // a small .slides.html that loads the engine from jsDelivr
305
359
  await assemble(text) // an inline .slides.html (the IIFE inlines itself; the ES module fetches this release's bundle once, or pass engineSource)
306
360
  await assemble(text, { includes }) // with resolved includes in #orz-includes
307
- extract(html) // { text, kind, format, shell, delivery, includes } | null
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 }
308
364
  ```
309
365
 
310
366
  The slides themselves need the engine's layout (reveal.js, fit) — in the
@@ -319,7 +375,9 @@ srcdoc=…>`, without `allow-same-origin`), never with `innerHTML` in your page.
319
375
  `assemble` writes the same bytes as the Node library (`orz-slides`), so an app
320
376
  can publish, preview or download without a server. Store the text; regenerate
321
377
  the HTML. `THEMES` lists the 14 slide themes (`id`, `name`, `scheme`
322
- light/dark, `description`); `DEFAULT_THEME` is `orchard`.
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`.
323
381
 
324
382
  ## Assembled files in an iframe
325
383