slidetake 0.2.3 → 0.3.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
@@ -4,13 +4,31 @@ Markdown in, a spatial deck and a finished video out.
4
4
 
5
5
  Slidetake turns a markdown file into a deck you move through like a map, and, when you are recording, drives the camera and OBS from the deck itself: every slide is a take, a slide spoken badly is retaken on the spot, and at the end you get a frame-exact ffmpeg cut, chapters and a YouTube publish pack.
6
6
 
7
- The built app is a single HTML file, [`dist/index.html`](dist/index.html): open it, copy it or host it anywhere.
7
+ The built app is a single HTML file, [`dist/index.html`](dist/index.html): open it, copy it or host it anywhere. Every feature: [slidetake.com/features](https://slidetake.com/features); step by step: [slidetake.com/docs](https://slidetake.com/docs).
8
+
9
+ ## Three places to use it
10
+
11
+ | Where | What it's for |
12
+ |---|---|
13
+ | **slidetake.com** | write in the editor, view a deck from a GitHub file, gist or URL, and share a link with the deck inside it |
14
+ | **Your computer** | the same with `npx slidetake deck.md`: your files and the images beside them, offline, reloading as you save, so an AI agent can write `deck.md` while you watch ([llms.txt](https://slidetake.com/llms.txt) tells it how) |
15
+ | **Your website** | `slidetake.js` on your pages ([below](#embed-in-a-site)): users view, and `?obs` makes the page your recorder; the hugo-continuum theme does it for `engine: slidetake` |
16
+
17
+ ### On your computer
18
+
19
+ ```sh
20
+ npx slidetake deck.md # or a folder: its index.md, deck.md, slides.md or README.md
21
+ ```
22
+
23
+ Opens on `http://localhost:4300` (`--port` to change, `--open` to open the browser). Files next to the deck are served beside it, so `![](diagram.png)` works. Saving the file reloads the deck where you are; typing in the browser's editor saves to the file. Over plain http, so OBS on another machine works too. Node 20+.
8
24
 
9
25
  ## Examples
10
26
 
11
- [`examples/`](examples) holds the decks to look at and start from: [`showcase.md`](examples/showcase.md) has everything a card can hold (steps, Graphviz, D2, SVG, ECharts, images, galleries, YouTube, camera) and is what [slidetake.com/examples](https://slidetake.com/examples) shows; the starter templates sit beside it.
27
+ [`examples/`](examples) holds the decks to look at and start from: [`showcase.md`](examples/showcase.md) has everything a card can hold (steps, Graphviz, D2, SVG, ECharts, images, galleries, YouTube, camera) and is what [slidetake.com/showcase](https://slidetake.com/showcase) shows; the starter templates sit beside it.
28
+
29
+ ## Develop Slidetake
12
30
 
13
- ## Run it
31
+ `npm run dev` builds, rebuilds on change and serves the site at `http://localhost:8787` (Cloudflare's local runtime, with slidetake.com's routes). Or serve the repo statically:
14
32
 
15
33
  ```sh
16
34
  python3 -m http.server 8765
@@ -20,7 +38,7 @@ Then open:
20
38
 
21
39
  - `http://localhost:8765/dist/` for the sample deck and the editor
22
40
  - `http://localhost:8765/dist/?src=https://…/deck.md` for a deck on the web, including GitHub raw URLs (relative images load from next to it)
23
- - `?edit=0` hides the editor, `?layout=tree|radial|path|focus` picks the layout, `?mode=light` the light theme
41
+ - `?edit=0` hides the editor, `?layout=focus|path|radial|tree` picks the layout, `?mode=light` the light theme
24
42
 
25
43
  ## Open a deck from a link
26
44
 
@@ -37,7 +55,7 @@ https://slidetake.com/?src=https://…/deck.md anything else
37
55
 
38
56
  Every deck you open is read-only. Typing in one makes **your copy** at `/edit`, kept in this browser and marked *edited* until you **Save** (a .md file) or **Share** it. A changed deck is shared inside the link itself, like edotor.net: `https://slidetake.com/share#deflate:<compressed markdown>`, never sent to a server. **Reset to original** goes back to the deck you started from, and `/new` starts from a template.
39
57
 
40
- For AI tools: the guide is plain markdown at [slidetake.com/help.md](https://slidetake.com/help.md), indexed by [llms.txt](https://slidetake.com/llms.txt).
58
+ For AI tools: the guide is plain markdown at [slidetake.com/docs.md](https://slidetake.com/docs.md), indexed by [llms.txt](https://slidetake.com/llms.txt).
41
59
 
42
60
  ## Recording
43
61
 
@@ -52,11 +70,11 @@ The bottom bar always has **Camera** (C), **● Record** (R) and **Fullscreen**
52
70
 
53
71
  **Recording needs [OBS Studio](https://obsproject.com)** (free) with its WebSocket server on; OBS records and Slidetake drives it. The Record dialog checks the screen: if it isn't 16:9, present on a screen that is, physical or virtual (say 1920×1080), so the video fits YouTube without bars.
54
72
 
55
- From https://slidetake.com, OBS must run on the same computer (`localhost`): browsers block secure pages from plain `ws://` connections to other machines. To record with OBS on another machine, serve `dist/index.html` locally over http.
73
+ From https://slidetake.com, OBS must run on the same computer (`localhost`): browsers block secure pages from plain `ws://` connections to other machines. To record with OBS on another machine, use `npx slidetake`, which serves over http.
56
74
 
57
75
  ## Decks
58
76
 
59
- Plain markdown (each heading is a card), the older `+++` format, and reveal.js decks (`---` and `--` separators) all open as they are. The full guide is itself a deck: [slidetake.com/help](https://slidetake.com/help) ([src/help.md](src/help.md)). In the app, `?` shows the keys.
77
+ Plain markdown (each heading is a card), the older `+++` format, and reveal.js decks (`---` and `--` separators) all open as they are. The docs are themselves a deck: [slidetake.com/docs](https://slidetake.com/docs) ([src/docs.md](src/docs.md)). In the app, `K` or `?` shows the keys.
60
78
 
61
79
  ## Embed in a site
62
80
 
@@ -78,7 +96,7 @@ window.SLIDETAKE = {
78
96
  // recording: true // optional: always show Camera and Record
79
97
  };
80
98
  </script>
81
- <script src="https://cdn.jsdelivr.net/npm/slidetake@0.2.0/dist/slidetake.js"></script>
99
+ <script src="https://cdn.jsdelivr.net/npm/slidetake@0.3.0/dist/slidetake.js"></script>
82
100
  ```
83
101
 
84
102
  `colors` takes any CSS colour per token, for both modes or under `light` / `dark`: `accent` (text and the current slide), `accentSoft` (smaller headings), `line` (borders and the active path), `ring` (the current slide's outline), `header` and `headerText` (a band of colour behind the header). A deck can also set its own with `accent:` in its top block.
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ // npx slidetake [deck.md | folder] [--port 4300] [--open]
3
+ //
4
+ // Slidetake on your own machine: serves the app and the deck's folder on localhost, so images next to the
5
+ // markdown load as they are, and the deck reloads whenever a file in the folder changes. Typing in the
6
+ // browser's editor writes back to the file, so your editor, an AI writing the file, and the browser all
7
+ // work on the same deck.md. Nothing leaves the machine, and it needs no install beyond Node.
8
+ import {createServer} from 'node:http';
9
+ import {readFileSync, statSync, existsSync, readdirSync, watch, createReadStream} from 'node:fs';
10
+ import {writeFile} from 'node:fs/promises';
11
+ import {resolve, dirname, basename, extname, join, relative, sep} from 'node:path';
12
+ import {fileURLToPath} from 'node:url';
13
+ import {spawn} from 'node:child_process';
14
+
15
+ const PKG = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
16
+ const APP = fileURLToPath(new URL('../dist/index.html', import.meta.url));
17
+
18
+ const args = process.argv.slice(2);
19
+ if (args.includes('-h') || args.includes('--help')){
20
+ console.log(`Slidetake ${PKG.version}: present and record a markdown deck from this machine.
21
+
22
+ npx slidetake [deck.md | folder] [--port 4300] [--open]
23
+
24
+ deck.md the deck to open; a folder opens its index.md, deck.md, slides.md, README.md or only .md file (default: .)
25
+ --port the port to try first (default 4300; the next free one is used if it's taken)
26
+ --open open the deck in the browser
27
+
28
+ Files next to the deck (images, video) are served beside it, so relative paths work. Saving the
29
+ file reloads the deck; typing in the browser's editor saves to the file.`);
30
+ process.exit(0);
31
+ }
32
+ const opt = name=>{ const i = args.indexOf(name); return i >= 0 ? args.splice(i, 2)[1] : undefined; };
33
+ const flag = name=>{ const i = args.indexOf(name); if (i >= 0) args.splice(i, 1); return i >= 0; };
34
+ const port0 = parseInt(opt('--port') || '4300', 10);
35
+ const open = flag('--open');
36
+
37
+ // the deck: a file, or the markdown file a folder holds
38
+ let target = resolve(args[0] || '.');
39
+ if (!existsSync(target)){ console.error('No such file or folder: ' + target); process.exit(1); }
40
+ if (statSync(target).isDirectory()){
41
+ const mds = readdirSync(target).filter(f=>/\.(md|markdown)$/i.test(f));
42
+ const pick = ['index.md', 'deck.md', 'slides.md', 'README.md'].find(f=>mds.includes(f)) || (mds.length === 1 ? mds[0] : null);
43
+ if (!pick){
44
+ console.error(mds.length ? 'Several markdown files here; name one: ' + mds.join(', ') : 'No markdown file in ' + target);
45
+ process.exit(1);
46
+ }
47
+ target = join(target, pick);
48
+ }
49
+ const ROOT = dirname(target), DECK = '/' + encodeURIComponent(basename(target));
50
+
51
+ const TYPES = {'.md': 'text/markdown; charset=utf-8', '.markdown': 'text/markdown; charset=utf-8', '.txt': 'text/plain; charset=utf-8',
52
+ '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': 'text/javascript', '.json': 'application/json',
53
+ '.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
54
+ '.webp': 'image/webp', '.avif': 'image/avif', '.ico': 'image/x-icon', '.mp4': 'video/mp4', '.webm': 'video/webm',
55
+ '.mov': 'video/quicktime', '.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.pdf': 'application/pdf',
56
+ '.woff': 'font/woff', '.woff2': 'font/woff2'};
57
+
58
+ // the app page, told which deck to open and where to hear about changes
59
+ const page = ()=>readFileSync(APP, 'utf8').replace('<head>',
60
+ '<head><script>window.SLIDETAKE_LOCAL=' + JSON.stringify({deck: DECK, file: basename(target), events: '/__slidetake/events', save: '/__slidetake/save'}) + '</script>');
61
+
62
+ // a file inside the deck's folder, or null for anything outside it
63
+ function inRoot(urlPath){
64
+ let p;
65
+ try { p = decodeURIComponent(urlPath.split('?')[0]); } catch(e){ return null; }
66
+ const file = resolve(ROOT, '.' + p);
67
+ return file === ROOT || file.startsWith(ROOT + sep) ? file : null;
68
+ }
69
+
70
+ const clients = new Set();
71
+ let lastSaved = null; // what the browser last wrote, so its own save doesn't bounce back as a change
72
+
73
+ const server = createServer(async (req, res)=>{
74
+ const url = req.url || '/';
75
+ if (url.startsWith('/__slidetake/events')){
76
+ res.writeHead(200, {'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive'});
77
+ res.write('retry: 1000\n\n');
78
+ clients.add(res);
79
+ req.on('close', ()=>clients.delete(res));
80
+ return;
81
+ }
82
+ if (url.startsWith('/__slidetake/save') && req.method === 'PUT'){
83
+ let body = '';
84
+ req.setEncoding('utf8');
85
+ for await (const chunk of req) body += chunk;
86
+ lastSaved = body;
87
+ await writeFile(target, body);
88
+ res.writeHead(204); res.end();
89
+ return;
90
+ }
91
+ const file = inRoot(url);
92
+ if (file && existsSync(file) && statSync(file).isFile()){
93
+ res.writeHead(200, {'Content-Type': TYPES[extname(file).toLowerCase()] || 'application/octet-stream', 'Cache-Control': 'no-store'});
94
+ createReadStream(file).pipe(res);
95
+ return;
96
+ }
97
+ // every other path is the app: /, /docs, /examples, /edit and the rest
98
+ res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store'});
99
+ res.end(page());
100
+ });
101
+
102
+ // any change in the folder reloads the deck (an image redrawn counts too); bursts from one save are merged
103
+ let timer = null;
104
+ watch(ROOT, {recursive: true}, (event, name)=>{
105
+ if (!name || /(^|[/\\])(\.|node_modules)/.test(name)) return;
106
+ clearTimeout(timer);
107
+ timer = setTimeout(()=>{
108
+ if (name === basename(target) && lastSaved !== null){
109
+ try { if (readFileSync(target, 'utf8') === lastSaved) return; } catch(e){}
110
+ }
111
+ for (const c of clients) c.write('data: ' + JSON.stringify({file: name}) + '\n\n');
112
+ }, 80);
113
+ });
114
+
115
+ function listen(port){
116
+ server.once('error', e=>{
117
+ if (e.code === 'EADDRINUSE' && port < port0 + 20) listen(port + 1);
118
+ else { console.error(e.message); process.exit(1); }
119
+ });
120
+ server.listen(port, '127.0.0.1', ()=>{
121
+ const link = 'http://localhost:' + port + '/';
122
+ console.log(`\n Slidetake ${PKG.version} · ${link}\n ${relative(process.cwd(), target) || basename(target)} · saves reload the deck; Ctrl+C stops\n`);
123
+ if (open){
124
+ const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
125
+ spawn(cmd, [link], {stdio: 'ignore', detached: true, shell: process.platform === 'win32'}).unref();
126
+ }
127
+ });
128
+ }
129
+ listen(port0);