@appeeky/open-slideshow 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +227 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/brand.d.ts +55 -0
- package/dist/brand.js +246 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +261 -0
- package/dist/decks.d.ts +44 -0
- package/dist/decks.js +90 -0
- package/dist/fonts.d.ts +45 -0
- package/dist/fonts.js +243 -0
- package/dist/gallery.d.ts +35 -0
- package/dist/gallery.js +109 -0
- package/dist/images.d.ts +49 -0
- package/dist/images.js +223 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/lint.d.ts +33 -0
- package/dist/lint.js +181 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +233 -0
- package/dist/publish.d.ts +100 -0
- package/dist/publish.js +401 -0
- package/dist/render.d.ts +73 -0
- package/dist/render.js +515 -0
- package/dist/schedule.d.ts +19 -0
- package/dist/schedule.js +114 -0
- package/dist/schema.d.ts +1004 -0
- package/dist/schema.js +174 -0
- package/dist/shape.d.ts +31 -0
- package/dist/shape.js +169 -0
- package/dist/skill.d.ts +7 -0
- package/dist/skill.js +17 -0
- package/dist/templates.d.ts +44 -0
- package/dist/templates.js +185 -0
- package/dist/text.d.ts +40 -0
- package/dist/text.js +230 -0
- package/dist/themes.d.ts +43 -0
- package/dist/themes.js +202 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/viral.d.ts +12 -0
- package/dist/viral.js +35 -0
- package/dist/workspace.d.ts +80 -0
- package/dist/workspace.js +306 -0
- package/package.json +65 -4
- package/skills/open-slideshow/SKILL.md +52 -0
- package/skills/open-slideshow/references/brand.md +54 -0
- package/skills/open-slideshow/references/channels.md +63 -0
- package/skills/open-slideshow/references/images.md +53 -0
- package/skills/open-slideshow/references/languages.md +41 -0
- package/skills/open-slideshow/references/publishing.md +70 -0
- package/skills/open-slideshow/references/review.md +74 -0
- package/skills/open-slideshow/references/templates.md +59 -0
- package/skills/open-slideshow/references/troubleshooting.md +82 -0
- package/skills/open-slideshow/references/writing.md +76 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { existsSync, readFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import YAML from "yaml";
|
|
5
|
+
import { brandContext } from "./brand.js";
|
|
6
|
+
import { newDeck, renderDeckById } from "./decks.js";
|
|
7
|
+
import { templateGallery, themeGallery } from "./gallery.js";
|
|
8
|
+
import { importImageFromFile, importImageFromUrl, searchImages } from "./images.js";
|
|
9
|
+
import { lintDeck } from "./lint.js";
|
|
10
|
+
import { publishDeck } from "./publish.js";
|
|
11
|
+
import { viralLines, viralSearch } from "./viral.js";
|
|
12
|
+
import { dueSlots, planSlots, savePlan } from "./schedule.js";
|
|
13
|
+
import { SKILL, guideText, guideTopics } from "./skill.js";
|
|
14
|
+
import { THEMES } from "./themes.js";
|
|
15
|
+
import { TEMPLATES, shapeText } from "./templates.js";
|
|
16
|
+
import { initWorkspace, listChannels, listDecks, loadDeck, openWorkspace, UserError, writeAtomic } from "./workspace.js";
|
|
17
|
+
import { VERSION } from "./version.js";
|
|
18
|
+
const HELP = `open-slideshow ${VERSION}: TikTok slideshows and Instagram carousels, written by your own agent, rendered here.
|
|
19
|
+
|
|
20
|
+
Usage: open-slideshow <command> [options]
|
|
21
|
+
|
|
22
|
+
init [--name N] [--app-store-id ID] set up this folder (not needed in an Appeeky Spec repo)
|
|
23
|
+
agent <claude|codex|cursor> connect your coding agent (skill + MCP)
|
|
24
|
+
info where open-slideshow works and what is here
|
|
25
|
+
brand [--json] [--offline] what your agent knows about the app and brand
|
|
26
|
+
themes [--deck ID] a picture of all 10 themes to pick from
|
|
27
|
+
templates [--theme ID] a picture of the slideshow shapes (tips, story, ranking…)
|
|
28
|
+
new <deck.yaml|deck.json> add a deck from a file
|
|
29
|
+
list decks and their status
|
|
30
|
+
lint <deck> check a deck
|
|
31
|
+
render <deck> render to JPEGs (decks/<deck>/renders)
|
|
32
|
+
image search <query> [--provider P] find photos (openverse, unsplash, pexels)
|
|
33
|
+
image import <path|url> bring an image in
|
|
34
|
+
viral <topic> [--kind K] [--since S] the most liked TikTok slideshows on a topic (Appeeky, $0.01)
|
|
35
|
+
plan [--days N] next post times for enabled channels
|
|
36
|
+
due slots that need a deck now
|
|
37
|
+
publish <deck> --to export|photos|appeeky|postiz|spec-draft [--yes] [--again] [--out DIR] [--when ISO]
|
|
38
|
+
publish --scheduled --to appeeky|postiz|spec-draft [--yes]
|
|
39
|
+
every rendered deck with a time still ahead (for CI)
|
|
40
|
+
mcp run the MCP server (stdio) for your agent
|
|
41
|
+
|
|
42
|
+
Env: APPEEKY_API_KEY (posting through Appeeky, viral search), UNSPLASH_ACCESS_KEY, PEXELS_API_KEY, OPEN_SLIDESHOW_DIR.`;
|
|
43
|
+
const out = (v) => process.stdout.write(`${typeof v === "string" ? v : JSON.stringify(v, null, 2)}\n`);
|
|
44
|
+
function mcpCommand() {
|
|
45
|
+
return { command: "npx", args: ["-y", "@appeeky/open-slideshow", "mcp"] };
|
|
46
|
+
}
|
|
47
|
+
/** Codex and Cursor get the guides through the guide tool, not files next to the skill. */
|
|
48
|
+
function forOtherAgents(skill) {
|
|
49
|
+
return skill
|
|
50
|
+
.replace(/^---[\s\S]*?---\n/, "")
|
|
51
|
+
.replace("Detailed guides live next to this file in `references/`. Read the one you need, or call the `guide` tool with its topic.", "Detailed guides: call the `guide` tool with a topic.");
|
|
52
|
+
}
|
|
53
|
+
function installAgent(agent, root) {
|
|
54
|
+
const mcp = mcpCommand();
|
|
55
|
+
if (agent === "claude") {
|
|
56
|
+
const dir = join(root, ".claude", "skills", "open-slideshow");
|
|
57
|
+
writeAtomic(join(dir, "SKILL.md"), SKILL);
|
|
58
|
+
for (const t of guideTopics())
|
|
59
|
+
writeAtomic(join(dir, "references", `${t}.md`), guideText(t));
|
|
60
|
+
out(`Wrote .claude/skills/open-slideshow (SKILL.md and ${guideTopics().length} guides)\nNow run:\n claude mcp add open-slideshow -- ${mcp.command} ${mcp.args.join(" ")}`);
|
|
61
|
+
}
|
|
62
|
+
else if (agent === "codex") {
|
|
63
|
+
const file = join(root, "AGENTS.md");
|
|
64
|
+
const marker = "<!-- open-slideshow -->";
|
|
65
|
+
const body = forOtherAgents(SKILL);
|
|
66
|
+
const existing = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
67
|
+
const next = existing.includes(marker) ? existing.replace(new RegExp(`${marker}[\\s\\S]*?${marker}`), `${marker}\n${body}\n${marker}`) : `${existing}${existing ? "\n\n" : ""}${marker}\n${body}\n${marker}\n`;
|
|
68
|
+
writeAtomic(file, next);
|
|
69
|
+
out(`Wrote the open-slideshow section in AGENTS.md\nAdd to ~/.codex/config.toml:\n\n[mcp_servers.open-slideshow]\ncommand = "${mcp.command}"\nargs = [${mcp.args.map((a) => `"${a}"`).join(", ")}]`);
|
|
70
|
+
}
|
|
71
|
+
else if (agent === "cursor") {
|
|
72
|
+
writeAtomic(join(root, ".cursor", "rules", "open-slideshow.mdc"), `---\ndescription: open-slideshow slideshows\nalwaysApply: false\n---\n${forOtherAgents(SKILL)}`);
|
|
73
|
+
const file = join(root, ".cursor", "mcp.json");
|
|
74
|
+
const cfg = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
|
75
|
+
cfg.mcpServers = { ...(cfg.mcpServers ?? {}), "open-slideshow": mcp };
|
|
76
|
+
writeAtomic(file, `${JSON.stringify(cfg, null, 2)}\n`);
|
|
77
|
+
out("Wrote .cursor/rules/open-slideshow.mdc and .cursor/mcp.json");
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
throw new UserError("agent: claude, codex or cursor");
|
|
81
|
+
}
|
|
82
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
83
|
+
const [cmd, ...rest] = argv;
|
|
84
|
+
if (!cmd || cmd === "help" || cmd === "--help" || cmd === "-h") {
|
|
85
|
+
out(HELP);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
if (cmd === "--version" || cmd === "-v") {
|
|
89
|
+
out(VERSION);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
if (cmd === "mcp") {
|
|
93
|
+
const { startMcp } = await import("./mcp.js");
|
|
94
|
+
await startMcp();
|
|
95
|
+
return -1; // keep running
|
|
96
|
+
}
|
|
97
|
+
const { values: o, positionals: p } = parseArgs({
|
|
98
|
+
args: rest,
|
|
99
|
+
allowPositionals: true,
|
|
100
|
+
options: {
|
|
101
|
+
json: { type: "boolean" },
|
|
102
|
+
offline: { type: "boolean" },
|
|
103
|
+
name: { type: "string" },
|
|
104
|
+
"app-store-id": { type: "string" },
|
|
105
|
+
deck: { type: "string" },
|
|
106
|
+
theme: { type: "string" },
|
|
107
|
+
provider: { type: "string" },
|
|
108
|
+
to: { type: "string" },
|
|
109
|
+
yes: { type: "boolean" },
|
|
110
|
+
again: { type: "boolean" },
|
|
111
|
+
out: { type: "string" },
|
|
112
|
+
when: { type: "string" },
|
|
113
|
+
kind: { type: "string" },
|
|
114
|
+
since: { type: "string" },
|
|
115
|
+
days: { type: "string" },
|
|
116
|
+
scheduled: { type: "boolean" },
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const dir = process.env.OPEN_SLIDESHOW_DIR ?? process.cwd();
|
|
120
|
+
try {
|
|
121
|
+
switch (cmd) {
|
|
122
|
+
case "init": {
|
|
123
|
+
const ws = initWorkspace(dir, { app: { name: o.name, app_store_id: o["app-store-id"], country: "us" } });
|
|
124
|
+
out(`open-slideshow is ready in ${ws.dir} (${ws.mode === "spec" ? "Appeeky Spec repo" : "standalone"}).\nNext: open-slideshow agent claude|codex|cursor, then ask your agent for a slideshow.`);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
case "agent":
|
|
128
|
+
installAgent(p[0] ?? "", openWorkspace(dir).root);
|
|
129
|
+
return 0;
|
|
130
|
+
case "info": {
|
|
131
|
+
const ws = openWorkspace(dir);
|
|
132
|
+
out({ mode: ws.mode, root: ws.root, dir: ws.dir, initialized: ws.initialized, app: ws.settings.app, warnings: ws.warnings, decks: listDecks(ws).length, channels: listChannels(ws).length });
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
case "brand": {
|
|
136
|
+
const ctx = await brandContext(openWorkspace(dir), { offline: o.offline });
|
|
137
|
+
out(o.json ? ctx : ctx.markdown);
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
case "themes": {
|
|
141
|
+
const g = await themeGallery(openWorkspace(dir), { deck: o.deck });
|
|
142
|
+
out(THEMES.map((t) => `${t.id.padEnd(16)} ${t.description}`).join("\n"));
|
|
143
|
+
out(`\nPicture: ${g.sheet}`);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
case "templates": {
|
|
147
|
+
const g = await templateGallery(openWorkspace(dir), { theme: o.theme });
|
|
148
|
+
out(TEMPLATES.map((t) => `${t.id.padEnd(14)} ${t.description}\n${"".padEnd(14)} ${shapeText(t)}`).join("\n"));
|
|
149
|
+
out(`\nPicture: ${g.sheet}`);
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
case "new": {
|
|
153
|
+
const file = p[0];
|
|
154
|
+
if (!file || !existsSync(file))
|
|
155
|
+
throw new UserError("new <deck.yaml|deck.json>");
|
|
156
|
+
const raw = readFileSync(file, "utf8");
|
|
157
|
+
const deck = newDeck(openWorkspace(dir), file.endsWith(".json") ? JSON.parse(raw) : YAML.parse(raw));
|
|
158
|
+
out(`created deck ${deck.id}`);
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
case "list":
|
|
162
|
+
out(listDecks(openWorkspace(dir)).map((d) => `${d.id.padEnd(40)} ${d.error ? `ERROR ${d.error.split("\n")[0]}` : `${d.deck.status.padEnd(9)} ${d.deck.theme}`}`).join("\n") || "no decks yet");
|
|
163
|
+
return 0;
|
|
164
|
+
case "lint": {
|
|
165
|
+
const ws = openWorkspace(dir);
|
|
166
|
+
const r = await lintDeck(ws, loadDeck(ws, p[0] ?? ""));
|
|
167
|
+
for (const e of r.errors)
|
|
168
|
+
out(`error ${e.message}`);
|
|
169
|
+
for (const w of r.warnings)
|
|
170
|
+
out(`warning ${w.message}`);
|
|
171
|
+
out(r.ok ? "ok" : `${r.errors.length} error(s)`);
|
|
172
|
+
return r.ok ? 0 : 1;
|
|
173
|
+
}
|
|
174
|
+
case "render": {
|
|
175
|
+
const r = await renderDeckById(openWorkspace(dir), p[0] ?? "");
|
|
176
|
+
for (const e of r.lint.errors)
|
|
177
|
+
out(`error ${e.message}`);
|
|
178
|
+
for (const w of r.lint.warnings)
|
|
179
|
+
out(`warning ${w.message}`);
|
|
180
|
+
out(`rendered ${r.files.length} slides to ${r.dir} (sheet: ${join(r.dir, r.sheet)})`);
|
|
181
|
+
return r.lint.ok ? 0 : 1;
|
|
182
|
+
}
|
|
183
|
+
case "image": {
|
|
184
|
+
const ws = openWorkspace(dir);
|
|
185
|
+
if (p[0] === "search") {
|
|
186
|
+
const hits = await searchImages(p.slice(1).join(" "), { provider: o.provider, orientation: "portrait" });
|
|
187
|
+
out(hits.map((h, i) => `${i + 1}. ${h.url} (${h.license}${h.author ? `, ${h.author}` : ""})`).join("\n") || "nothing found");
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
if (p[0] === "import" && p[1]) {
|
|
191
|
+
mkdirSync(join(ws.dir, "images"), { recursive: true });
|
|
192
|
+
const m = /^https:\/\//.test(p[1]) ? await importImageFromUrl(ws, p[1]) : await importImageFromFile(ws, resolve(p[1]));
|
|
193
|
+
out(`imported as ${m.ref} (${m.width}×${m.height})`);
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
throw new UserError("image search <query> | image import <path|url>");
|
|
197
|
+
}
|
|
198
|
+
case "viral": {
|
|
199
|
+
if (!p.length)
|
|
200
|
+
throw new UserError("viral <topic> [--kind slideshow|video|any] [--since week|month|quarter|half|any]");
|
|
201
|
+
const posts = await viralSearch(p.join(" "), { kind: o.kind ?? "slideshow", since: o.since ?? "quarter" });
|
|
202
|
+
out(viralLines(posts).join("\n") || "nothing found");
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
case "plan": {
|
|
206
|
+
const ws = openWorkspace(dir);
|
|
207
|
+
const chans = listChannels(ws).filter((c) => c.channel?.enabled);
|
|
208
|
+
if (!chans.length)
|
|
209
|
+
throw new UserError("no enabled channels");
|
|
210
|
+
const slots = savePlan(ws, chans.flatMap((c) => planSlots(c.channel, new Date(), Number(o.days ?? 7))));
|
|
211
|
+
out(slots.map((s) => `${s.at} ${s.channel.padEnd(20)} ${s.deck ?? "(needs a deck)"}${s.note ? ` ${s.note}` : ""}`).join("\n"));
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
case "due": {
|
|
215
|
+
const due = dueSlots(openWorkspace(dir));
|
|
216
|
+
out(due.length ? due.map((s) => `${s.at} ${s.channel}`).join("\n") : "nothing due");
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
case "publish": {
|
|
220
|
+
const provider = (o.to ?? o.provider);
|
|
221
|
+
if (!provider || !["export", "photos", "appeeky", "postiz", "spec-draft"].includes(provider))
|
|
222
|
+
throw new UserError("publish <deck> --to export|photos|appeeky|postiz|spec-draft");
|
|
223
|
+
if (o.scheduled) {
|
|
224
|
+
// For CI: the decks a person already approved (merged) with a time still ahead. Never "post now".
|
|
225
|
+
if (p[0])
|
|
226
|
+
throw new UserError("publish --scheduled takes no deck; it publishes every rendered deck with a time");
|
|
227
|
+
if (!["appeeky", "postiz", "spec-draft"].includes(provider))
|
|
228
|
+
throw new UserError("publish --scheduled works with --to appeeky, postiz or spec-draft");
|
|
229
|
+
const ws = openWorkspace(dir);
|
|
230
|
+
const soon = Date.now() + 2 * 60_000;
|
|
231
|
+
const ready = listDecks(ws).filter((d) => d.deck && d.deck.status === "rendered" && d.deck.when && Date.parse(d.deck.when) > soon);
|
|
232
|
+
if (!ready.length) {
|
|
233
|
+
out("nothing to schedule");
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
let failed = 0;
|
|
237
|
+
for (const d of ready) {
|
|
238
|
+
try {
|
|
239
|
+
const r = await publishDeck(ws, d.id, { provider, confirm: o.yes });
|
|
240
|
+
out(`${d.id}: ${r.done ? r.message : `would schedule for ${d.deck.when} (add --yes)`}`);
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
failed++;
|
|
244
|
+
process.stderr.write(`${d.id}: ${e.message}\n`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return failed ? 1 : 0;
|
|
248
|
+
}
|
|
249
|
+
const r = await publishDeck(openWorkspace(dir), p[0] ?? "", { provider, confirm: o.yes, again: o.again, out: o.out ? resolve(o.out) : undefined, when: o.when });
|
|
250
|
+
out(r.done ? r.message : `${JSON.stringify(r.preview, null, 2)}\n${r.message.replace("call again with confirm", "add --yes")}`);
|
|
251
|
+
return 0;
|
|
252
|
+
}
|
|
253
|
+
default:
|
|
254
|
+
throw new UserError(`unknown command "${cmd}"\n\n${HELP}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
process.stderr.write(`${e instanceof UserError ? e.message : e.stack ?? String(e)}\n`);
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
package/dist/decks.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Deck, type DeckInput, type Slide } from "./schema.js";
|
|
2
|
+
import { type RenderResult } from "./render.js";
|
|
3
|
+
import { type LintResult } from "./lint.js";
|
|
4
|
+
import { type Workspace } from "./workspace.js";
|
|
5
|
+
export interface Manifest {
|
|
6
|
+
deck: string;
|
|
7
|
+
hash: string;
|
|
8
|
+
files: string[];
|
|
9
|
+
size: Deck["size"];
|
|
10
|
+
theme: string;
|
|
11
|
+
rendered_at: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const manifestFile: (ws: Workspace, id: string) => string;
|
|
14
|
+
export declare const readManifest: (ws: Workspace, id: string) => Manifest | null;
|
|
15
|
+
export declare function newDeck(ws: Workspace, input: Omit<DeckInput, "id"> & {
|
|
16
|
+
id?: string;
|
|
17
|
+
}, opts?: {
|
|
18
|
+
overwrite?: boolean;
|
|
19
|
+
}): Deck;
|
|
20
|
+
export interface DeckPatch extends Partial<Omit<Deck, "id" | "version" | "published" | "status" | "slides">> {
|
|
21
|
+
slides?: Slide[];
|
|
22
|
+
/** Changes to single slides by index (0-based), merged into the slide. */
|
|
23
|
+
slide_edits?: {
|
|
24
|
+
index: number;
|
|
25
|
+
set: Partial<Slide>;
|
|
26
|
+
}[];
|
|
27
|
+
insert?: {
|
|
28
|
+
index: number;
|
|
29
|
+
slide: Slide;
|
|
30
|
+
}[];
|
|
31
|
+
remove?: number[];
|
|
32
|
+
move?: {
|
|
33
|
+
from: number;
|
|
34
|
+
to: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare function updateDeck(ws: Workspace, id: string, patch: DeckPatch): Deck;
|
|
38
|
+
export interface RenderOutcome extends RenderResult {
|
|
39
|
+
dir: string;
|
|
40
|
+
lint: LintResult;
|
|
41
|
+
}
|
|
42
|
+
export declare function renderDeckById(ws: Workspace, id: string): Promise<RenderOutcome>;
|
|
43
|
+
/** The renders on disk, only if they match the deck as it is now. */
|
|
44
|
+
export declare function freshRenders(ws: Workspace, deck: Deck): Manifest;
|
package/dist/decks.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { deckSchema, slideSchema } from "./schema.js";
|
|
4
|
+
import { renderDeck, renderHash } from "./render.js";
|
|
5
|
+
import { lintDeck, renderContext } from "./lint.js";
|
|
6
|
+
import { getTheme } from "./themes.js";
|
|
7
|
+
import { deckExists, loadDeck, parseWith, readJson, rendersDir, saveDeck, uniqueDeckId, UserError, writeAtomic } from "./workspace.js";
|
|
8
|
+
import { plainText } from "./text.js";
|
|
9
|
+
export const manifestFile = (ws, id) => join(rendersDir(ws, id), "manifest.json");
|
|
10
|
+
export const readManifest = (ws, id) => readJson(manifestFile(ws, id), null);
|
|
11
|
+
export function newDeck(ws, input, opts = {}) {
|
|
12
|
+
const s = ws.settings;
|
|
13
|
+
const firstTitle = input.slides?.find((x) => x.title)?.title;
|
|
14
|
+
const id = input.id ?? uniqueDeckId(ws, input.topic ?? (firstTitle ? plainText(firstTitle) : "deck"));
|
|
15
|
+
if (deckExists(ws, id) && !opts.overwrite)
|
|
16
|
+
throw new UserError(`deck "${id}" already exists; use deck_update to change it`);
|
|
17
|
+
const deck = parseWith(deckSchema, {
|
|
18
|
+
size: s.defaults.size,
|
|
19
|
+
theme: s.defaults.theme,
|
|
20
|
+
language: s.defaults.language,
|
|
21
|
+
...input,
|
|
22
|
+
id,
|
|
23
|
+
}, `deck ${id}`);
|
|
24
|
+
if (!getTheme(deck.theme))
|
|
25
|
+
throw new UserError(`unknown theme "${deck.theme}"; themes_list shows the 10 themes`);
|
|
26
|
+
return saveDeck(ws, deck);
|
|
27
|
+
}
|
|
28
|
+
export function updateDeck(ws, id, patch) {
|
|
29
|
+
const deck = loadDeck(ws, id);
|
|
30
|
+
if (deck.status === "published")
|
|
31
|
+
throw new UserError(`deck ${id} is already published; make a new deck (deck_create) instead of changing a posted one`);
|
|
32
|
+
const { slides, slide_edits, insert, remove, move, ...rest } = patch;
|
|
33
|
+
let next = slides ? slides.map((s) => parseWith(slideSchema, s, "slide")) : [...deck.slides];
|
|
34
|
+
for (const e of slide_edits ?? []) {
|
|
35
|
+
if (!next[e.index])
|
|
36
|
+
throw new UserError(`no slide ${e.index} (deck has ${next.length}, counted from 0)`);
|
|
37
|
+
const merged = { ...next[e.index], ...e.set };
|
|
38
|
+
for (const [k, v] of Object.entries(e.set))
|
|
39
|
+
if (v === null)
|
|
40
|
+
delete merged[k];
|
|
41
|
+
next[e.index] = parseWith(slideSchema, merged, `slide ${e.index}`);
|
|
42
|
+
}
|
|
43
|
+
if (remove?.length) {
|
|
44
|
+
const drop = new Set(remove);
|
|
45
|
+
for (const r of drop)
|
|
46
|
+
if (!next[r])
|
|
47
|
+
throw new UserError(`no slide ${r} to remove`);
|
|
48
|
+
next = next.filter((_, i) => !drop.has(i));
|
|
49
|
+
}
|
|
50
|
+
for (const ins of [...(insert ?? [])].sort((a, b) => a.index - b.index)) {
|
|
51
|
+
if (ins.index < 0 || ins.index > next.length)
|
|
52
|
+
throw new UserError(`cannot insert at ${ins.index}`);
|
|
53
|
+
next.splice(ins.index, 0, parseWith(slideSchema, ins.slide, "slide"));
|
|
54
|
+
}
|
|
55
|
+
if (move) {
|
|
56
|
+
if (!next[move.from] || move.to < 0 || move.to >= next.length)
|
|
57
|
+
throw new UserError("move: index out of range");
|
|
58
|
+
const [s] = next.splice(move.from, 1);
|
|
59
|
+
next.splice(move.to, 0, s);
|
|
60
|
+
}
|
|
61
|
+
const updated = { ...deck, ...rest, slides: next, status: "draft" };
|
|
62
|
+
if (rest.theme && !getTheme(rest.theme))
|
|
63
|
+
throw new UserError(`unknown theme "${rest.theme}"`);
|
|
64
|
+
return saveDeck(ws, parseWith(deckSchema, updated, `deck ${id}`));
|
|
65
|
+
}
|
|
66
|
+
export async function renderDeckById(ws, id) {
|
|
67
|
+
const deck = loadDeck(ws, id);
|
|
68
|
+
const lint = await lintDeck(ws, deck);
|
|
69
|
+
const ctx = renderContext(ws, deck);
|
|
70
|
+
const dir = rendersDir(ws, id);
|
|
71
|
+
const result = await renderDeck(deck, ctx, dir);
|
|
72
|
+
const manifest = { deck: id, hash: result.hash, files: result.files, size: deck.size, theme: deck.theme, rendered_at: new Date().toISOString() };
|
|
73
|
+
writeAtomic(manifestFile(ws, id), JSON.stringify(manifest, null, 2));
|
|
74
|
+
if (deck.status === "draft")
|
|
75
|
+
saveDeck(ws, { ...deck, status: "rendered" });
|
|
76
|
+
return { ...result, dir, lint };
|
|
77
|
+
}
|
|
78
|
+
/** The renders on disk, only if they match the deck as it is now. */
|
|
79
|
+
export function freshRenders(ws, deck) {
|
|
80
|
+
const m = readManifest(ws, deck.id);
|
|
81
|
+
if (!m)
|
|
82
|
+
throw new UserError(`deck ${deck.id} is not rendered yet; run deck_render`);
|
|
83
|
+
const now = renderHash(deck, renderContext(ws, deck));
|
|
84
|
+
if (m.hash !== now)
|
|
85
|
+
throw new UserError(`deck ${deck.id} changed since it was rendered; run deck_render again and look at it before publishing`);
|
|
86
|
+
for (const f of m.files)
|
|
87
|
+
if (!existsSync(join(rendersDir(ws, deck.id), f)))
|
|
88
|
+
throw new UserError(`render ${f} is missing; run deck_render again`);
|
|
89
|
+
return m;
|
|
90
|
+
}
|
package/dist/fonts.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import opentype from "opentype.js";
|
|
2
|
+
import type { FontFamily, FontRole } from "./themes.js";
|
|
3
|
+
export interface SatoriFont {
|
|
4
|
+
name: string;
|
|
5
|
+
data: Buffer;
|
|
6
|
+
weight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
7
|
+
style: "normal" | "italic";
|
|
8
|
+
}
|
|
9
|
+
/** The file bytes behind a parsed font, for the shaper. */
|
|
10
|
+
export declare const fontBytes: (f: opentype.Font) => {
|
|
11
|
+
key: string;
|
|
12
|
+
data: Buffer;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/** All faces, for satori. Satori does not fall back between faces of one name, so every subset gets its own name. The same array is kept between calls so satori can cache the parsed fonts. */
|
|
15
|
+
export declare function satoriFonts(): SatoriFont[];
|
|
16
|
+
/** The CSS font-family list: the family's subsets, Inter's for letters it lacks, then any loaded script fonts (in the deck language's order). */
|
|
17
|
+
export declare function fontStack(family: FontFamily, locale?: string): string;
|
|
18
|
+
export type Pack = "jp" | "sc" | "tc" | "kr" | "ar" | "he" | "th" | "hi";
|
|
19
|
+
export declare const SCRIPTS: Record<Pack, {
|
|
20
|
+
pkg: string;
|
|
21
|
+
version: string;
|
|
22
|
+
subset: string;
|
|
23
|
+
name: string;
|
|
24
|
+
label: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function orderedPacks(locale?: string): Pack[];
|
|
27
|
+
/** The script fonts a text needs. */
|
|
28
|
+
export declare function packsFor(text: string, locale?: string): Pack[];
|
|
29
|
+
/**
|
|
30
|
+
* Loads (downloading once, then from the cache) the fonts a text needs.
|
|
31
|
+
* Returns the scripts that could not be loaded, e.g. offline on first use.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureScriptFonts(text: string, locale?: string): Promise<Pack[]>;
|
|
34
|
+
/** The font that draws `ch` for a role: the role's own, Inter, then the script fonts. */
|
|
35
|
+
export declare function pickFont(role: FontRole, ch: string, locale?: string): opentype.Font | null;
|
|
36
|
+
/** Characters no font here can draw. Whitespace and emoji are not counted: emoji are drawn as images. */
|
|
37
|
+
export declare function missingChars(role: FontRole, text: string, locale?: string): string[];
|
|
38
|
+
/** `fallback`: drawn in Inter because the theme's font lacks them. `missing`: no font here can draw them. */
|
|
39
|
+
export declare function glyphReport(role: FontRole, text: string, locale?: string): {
|
|
40
|
+
fallback: string[];
|
|
41
|
+
missing: string[];
|
|
42
|
+
};
|
|
43
|
+
export declare function isEmoji(ch: string): boolean;
|
|
44
|
+
/** Width of `text` in px at `size`, the way satori lays it out (advances plus letter spacing). */
|
|
45
|
+
export declare function measure(role: FontRole, text: string, size: number, locale?: string): number;
|