@appeeky/open-slideshow 0.0.0-stage → 0.2.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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +9 -0
  5. package/dist/brand.d.ts +57 -0
  6. package/dist/brand.js +263 -0
  7. package/dist/brandkit.d.ts +50 -0
  8. package/dist/brandkit.js +212 -0
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +355 -0
  11. package/dist/decks.d.ts +44 -0
  12. package/dist/decks.js +100 -0
  13. package/dist/fonts.d.ts +45 -0
  14. package/dist/fonts.js +243 -0
  15. package/dist/gallery.d.ts +35 -0
  16. package/dist/gallery.js +109 -0
  17. package/dist/ideas.d.ts +50 -0
  18. package/dist/ideas.js +146 -0
  19. package/dist/images.d.ts +62 -0
  20. package/dist/images.js +241 -0
  21. package/dist/index.d.ts +21 -0
  22. package/dist/index.js +22 -0
  23. package/dist/lint.d.ts +36 -0
  24. package/dist/lint.js +197 -0
  25. package/dist/mcp.d.ts +3 -0
  26. package/dist/mcp.js +303 -0
  27. package/dist/preview.d.ts +18 -0
  28. package/dist/preview.js +96 -0
  29. package/dist/publish.d.ts +105 -0
  30. package/dist/publish.js +406 -0
  31. package/dist/readability.d.ts +19 -0
  32. package/dist/readability.js +42 -0
  33. package/dist/render.d.ts +92 -0
  34. package/dist/render.js +647 -0
  35. package/dist/results.d.ts +89 -0
  36. package/dist/results.js +252 -0
  37. package/dist/schedule.d.ts +19 -0
  38. package/dist/schedule.js +114 -0
  39. package/dist/schema.d.ts +1159 -0
  40. package/dist/schema.js +211 -0
  41. package/dist/screenshots.d.ts +18 -0
  42. package/dist/screenshots.js +69 -0
  43. package/dist/shape.d.ts +31 -0
  44. package/dist/shape.js +169 -0
  45. package/dist/skill.d.ts +7 -0
  46. package/dist/skill.js +17 -0
  47. package/dist/templates.d.ts +47 -0
  48. package/dist/templates.js +330 -0
  49. package/dist/text.d.ts +40 -0
  50. package/dist/text.js +231 -0
  51. package/dist/themes.d.ts +43 -0
  52. package/dist/themes.js +202 -0
  53. package/dist/variants.d.ts +48 -0
  54. package/dist/variants.js +175 -0
  55. package/dist/version.d.ts +1 -0
  56. package/dist/version.js +1 -0
  57. package/dist/video.d.ts +22 -0
  58. package/dist/video.js +59 -0
  59. package/dist/viral.d.ts +12 -0
  60. package/dist/viral.js +35 -0
  61. package/dist/workspace.d.ts +85 -0
  62. package/dist/workspace.js +322 -0
  63. package/package.json +65 -4
  64. package/skills/open-slideshow/SKILL.md +65 -0
  65. package/skills/open-slideshow/references/brand.md +64 -0
  66. package/skills/open-slideshow/references/channels.md +63 -0
  67. package/skills/open-slideshow/references/ideas.md +23 -0
  68. package/skills/open-slideshow/references/images.md +61 -0
  69. package/skills/open-slideshow/references/languages.md +51 -0
  70. package/skills/open-slideshow/references/publishing.md +70 -0
  71. package/skills/open-slideshow/references/results.md +47 -0
  72. package/skills/open-slideshow/references/review.md +81 -0
  73. package/skills/open-slideshow/references/screenshots.md +26 -0
  74. package/skills/open-slideshow/references/series.md +20 -0
  75. package/skills/open-slideshow/references/templates.md +96 -0
  76. package/skills/open-slideshow/references/troubleshooting.md +92 -0
  77. package/skills/open-slideshow/references/video.md +18 -0
  78. package/skills/open-slideshow/references/writing.md +76 -0
package/dist/themes.js ADDED
@@ -0,0 +1,202 @@
1
+ export const THEMES = [
2
+ {
3
+ id: "tiktok-classic",
4
+ name: "TikTok classic",
5
+ description: "A phone photo with white words and a black outline, the way people caption on TikTok.",
6
+ design: "photo",
7
+ colors: { bg: "#111111", fg: "#ffffff", accent: "#ffe14d", muted: "#e6e6e6", card: "#ffffff" },
8
+ display: { family: "TikTok Sans", weight: 800 },
9
+ body: { family: "TikTok Sans", weight: 700 },
10
+ text_style: "outline",
11
+ accent_style: "color",
12
+ align: "center",
13
+ scrim: 0,
14
+ cover_position: 38,
15
+ tip_position: 30,
16
+ },
17
+ {
18
+ id: "soft-shadow",
19
+ name: "Soft shadow",
20
+ description: "Photo with white words on a soft shadow. Quiet, personal, diary-like.",
21
+ design: "photo",
22
+ colors: { bg: "#1a1a1a", fg: "#ffffff", accent: "#ffd4e0", muted: "#f2f2f2", card: "#ffffff" },
23
+ display: { family: "TikTok Sans", weight: 700 },
24
+ body: { family: "TikTok Sans", weight: 500 },
25
+ text_style: "shadow",
26
+ accent_style: "underline",
27
+ align: "center",
28
+ scrim: 0.18,
29
+ cover_position: 45,
30
+ tip_position: 40,
31
+ },
32
+ {
33
+ id: "highlight-box",
34
+ name: "Highlight box",
35
+ description: "Black words on white boxes over the photo, like TikTok's background text.",
36
+ design: "photo",
37
+ colors: { bg: "#111111", fg: "#111111", accent: "#ff3b5c", muted: "#333333", card: "#ffffff" },
38
+ display: { family: "TikTok Sans", weight: 700 },
39
+ body: { family: "TikTok Sans", weight: 600 },
40
+ text_style: "box",
41
+ accent_style: "color",
42
+ align: "center",
43
+ scrim: 0,
44
+ cover_position: 40,
45
+ tip_position: 32,
46
+ },
47
+ {
48
+ id: "bold-poster",
49
+ name: "Bold poster",
50
+ description: "Tall condensed capitals over a darkened photo, with one word on an accent block.",
51
+ design: "photo",
52
+ colors: { bg: "#0d0d0d", fg: "#ffffff", accent: "#ff4d2e", muted: "#d9d9d9", card: "#ffffff" },
53
+ display: { family: "Anton", weight: 400, uppercase: true, tracking: 0.01 },
54
+ body: { family: "Inter", weight: 600 },
55
+ text_style: "plain",
56
+ accent_style: "box",
57
+ align: "left",
58
+ scrim: 0.62,
59
+ cover_position: 68,
60
+ tip_position: 66,
61
+ },
62
+ {
63
+ id: "magazine-cream",
64
+ name: "Magazine cream",
65
+ description: "A cream page: a serif headline on top, the photo below. Calm and editorial.",
66
+ design: "magazine",
67
+ colors: { bg: "#f4eee3", fg: "#1d1b18", accent: "#c2552d", muted: "#6b645a", card: "#ebe3d4" },
68
+ display: { family: "Instrument Serif", weight: 400 },
69
+ body: { family: "Inter", weight: 400 },
70
+ text_style: "plain",
71
+ accent_style: "color",
72
+ align: "left",
73
+ scrim: 0,
74
+ cover_position: 70,
75
+ tip_position: 30,
76
+ },
77
+ {
78
+ id: "editorial-ink",
79
+ name: "Editorial ink",
80
+ description: "Near-black page, warm white serif and a gold accent. Feels premium.",
81
+ design: "magazine",
82
+ colors: { bg: "#121212", fg: "#f5f1ea", accent: "#e8c468", muted: "#a8a39a", card: "#1f1f1f" },
83
+ display: { family: "Instrument Serif", weight: 400 },
84
+ body: { family: "Inter", weight: 400 },
85
+ text_style: "plain",
86
+ accent_style: "color",
87
+ align: "left",
88
+ scrim: 0,
89
+ cover_position: 70,
90
+ tip_position: 30,
91
+ },
92
+ {
93
+ id: "clean-note",
94
+ name: "Clean note",
95
+ description: "No photos: big clean words on white under your name and handle, like a post.",
96
+ design: "plain",
97
+ colors: { bg: "#ffffff", fg: "#0f1419", accent: "#1d9bf0", muted: "#536471", card: "#f7f9f9" },
98
+ display: { family: "Inter", weight: 700 },
99
+ body: { family: "Inter", weight: 400 },
100
+ text_style: "plain",
101
+ accent_style: "color",
102
+ align: "left",
103
+ scrim: 0,
104
+ cover_position: 50,
105
+ tip_position: 50,
106
+ },
107
+ {
108
+ id: "pastel-pop",
109
+ name: "Pastel pop",
110
+ description: "Soft pink page, heavy words and a hot-pink highlight. Playful.",
111
+ design: "magazine",
112
+ colors: { bg: "#ffd6e3", fg: "#2b1b24", accent: "#ff2e7e", muted: "#6e4a5b", card: "#ffffff" },
113
+ display: { family: "TikTok Sans", weight: 800 },
114
+ body: { family: "TikTok Sans", weight: 500 },
115
+ text_style: "plain",
116
+ accent_style: "box",
117
+ align: "left",
118
+ scrim: 0,
119
+ cover_position: 70,
120
+ tip_position: 30,
121
+ },
122
+ {
123
+ id: "navy-study",
124
+ name: "Navy study",
125
+ description: "Deep navy page with a cyan highlight. Reads like good study notes.",
126
+ design: "magazine",
127
+ colors: { bg: "#0e1b3d", fg: "#ffffff", accent: "#5ce1e6", muted: "#aab4d0", card: "#18295a" },
128
+ display: { family: "TikTok Sans", weight: 800 },
129
+ body: { family: "Inter", weight: 400 },
130
+ text_style: "plain",
131
+ accent_style: "box",
132
+ align: "left",
133
+ scrim: 0,
134
+ cover_position: 70,
135
+ tip_position: 30,
136
+ },
137
+ {
138
+ id: "terracotta-warm",
139
+ name: "Terracotta warm",
140
+ description: "Warm clay page with cream words. Food, home and wellness.",
141
+ design: "magazine",
142
+ colors: { bg: "#a3482a", fg: "#fff4e8", accent: "#2a1a12", muted: "#f6d9c4", card: "#8f3d22" },
143
+ display: { family: "TikTok Sans", weight: 800 },
144
+ body: { family: "Inter", weight: 400 },
145
+ text_style: "plain",
146
+ accent_style: "box",
147
+ align: "left",
148
+ scrim: 0,
149
+ cover_position: 70,
150
+ tip_position: 30,
151
+ },
152
+ ];
153
+ export function getTheme(id) {
154
+ return THEMES.find((t) => t.id === id);
155
+ }
156
+ /** A theme with brand colours laid over it. Text on photos keeps the theme's own colours, so it stays readable. */
157
+ export function withColors(theme, colors) {
158
+ if (!colors)
159
+ return theme;
160
+ if (theme.design === "photo")
161
+ return { ...theme, colors: { ...theme.colors, accent: colors.accent } };
162
+ return {
163
+ ...theme,
164
+ colors: {
165
+ bg: colors.bg,
166
+ fg: colors.fg,
167
+ accent: colors.accent,
168
+ muted: colors.muted ?? mix(colors.fg, colors.bg, 0.35),
169
+ card: colors.card ?? mix(colors.bg, colors.fg, 0.08),
170
+ },
171
+ };
172
+ }
173
+ export function hexToRgb(hex) {
174
+ const n = Number.parseInt(hex.slice(1), 16);
175
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
176
+ }
177
+ export function rgbToHex([r, g, b]) {
178
+ return `#${[r, g, b].map((v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0")).join("")}`;
179
+ }
180
+ /** `a` moved toward `b` by `t`. */
181
+ export function mix(a, b, t) {
182
+ const x = hexToRgb(a);
183
+ const y = hexToRgb(b);
184
+ return rgbToHex([x[0] + (y[0] - x[0]) * t, x[1] + (y[1] - x[1]) * t, x[2] + (y[2] - x[2]) * t]);
185
+ }
186
+ export function luminance(hex) {
187
+ const [r, g, b] = hexToRgb(hex).map((v) => {
188
+ const c = v / 255;
189
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
190
+ });
191
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
192
+ }
193
+ /** WCAG contrast ratio, 1 to 21. */
194
+ export function contrast(a, b) {
195
+ const la = luminance(a);
196
+ const lb = luminance(b);
197
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
198
+ }
199
+ /** Black or white, whichever reads better on `bg`. */
200
+ export function readableOn(bg) {
201
+ return contrast("#000000", bg) >= contrast("#ffffff", bg) ? "#111111" : "#ffffff";
202
+ }
@@ -0,0 +1,48 @@
1
+ import { type Deck, type Slide } from "./schema.js";
2
+ import { type Workspace } from "./workspace.js";
3
+ /**
4
+ * A hook test: copies of a deck that differ only in the cover's hook. The first deck is variant a;
5
+ * each new hook becomes b, c… With spread_days, each copy is scheduled that many days after the one
6
+ * before, so the variants do not compete with each other on the same day.
7
+ */
8
+ export declare function hookTest(ws: Workspace, id: string, hooks: string[], opts?: {
9
+ spread_days?: number;
10
+ }): Deck[];
11
+ /** The next part of a series. The first deck becomes part 1 when it is not in a series yet. */
12
+ export declare function seriesNext(ws: Workspace, id: string, slides: Slide[], opts?: {
13
+ topic?: string;
14
+ of?: number;
15
+ label?: string;
16
+ when?: string;
17
+ }): Deck;
18
+ export declare function listSeries(ws: Workspace): {
19
+ id: string;
20
+ parts: {
21
+ deck: string;
22
+ part: number;
23
+ of: number | undefined;
24
+ status: "draft" | "rendered" | "published";
25
+ when: string | undefined;
26
+ hook: string | undefined;
27
+ }[];
28
+ }[];
29
+ /**
30
+ * The same deck in another language. The agent writes the translated slides; this keeps every
31
+ * image, crop and number from the original, and checks the slides line up one to one.
32
+ */
33
+ export declare function translateDeck(ws: Workspace, id: string, language: string, t: {
34
+ slides: Partial<Slide>[];
35
+ caption?: string;
36
+ hashtags?: string[];
37
+ accounts?: string[];
38
+ when?: string;
39
+ }): Deck;
40
+ /**
41
+ * A deck that did well, posted again with a new hook. Platforms push down copies of the same post,
42
+ * so the cover must change; the middle slides can be reordered too.
43
+ */
44
+ export declare function repostDeck(ws: Workspace, id: string, hook: string, opts?: {
45
+ order?: number[];
46
+ min_days?: number;
47
+ now?: Date;
48
+ }): Deck;
@@ -0,0 +1,175 @@
1
+ import { DateTime } from "luxon";
2
+ import { normalizeHook, usedHooks } from "./brand.js";
3
+ import { newDeck } from "./decks.js";
4
+ import { slideSchema } from "./schema.js";
5
+ import { listDecks, loadDeck, parseWith, saveDeck, uniqueDeckId, UserError } from "./workspace.js";
6
+ /** Everything about a deck's look and where it goes, without its history. */
7
+ function design(d) {
8
+ return {
9
+ channel: d.channel,
10
+ language: d.language,
11
+ size: d.size,
12
+ theme: d.theme,
13
+ colors: d.colors,
14
+ full_cover: d.full_cover,
15
+ text_style: d.text_style,
16
+ show_handle: d.show_handle,
17
+ caption: d.caption,
18
+ hashtags: d.hashtags,
19
+ accounts: d.accounts,
20
+ tiktok: d.tiktok,
21
+ topic: d.topic,
22
+ template: d.template,
23
+ };
24
+ }
25
+ const coverIndex = (slides) => {
26
+ const i = slides.findIndex((s) => s.kind === "cover");
27
+ return i === -1 ? 0 : i;
28
+ };
29
+ function withHook(slides, hook) {
30
+ const i = coverIndex(slides);
31
+ return slides.map((s, j) => (j === i ? parseWith(slideSchema, { ...s, title: hook }, `slide ${i}`) : s));
32
+ }
33
+ const shiftDays = (when, days) => (when && days ? DateTime.fromISO(when, { setZone: true }).plus({ days }).toISO({ suppressMilliseconds: true }) ?? undefined : when);
34
+ // ---------- hook tests ----------
35
+ const LETTERS = ["a", "b", "c", "d", "e"];
36
+ /**
37
+ * A hook test: copies of a deck that differ only in the cover's hook. The first deck is variant a;
38
+ * each new hook becomes b, c… With spread_days, each copy is scheduled that many days after the one
39
+ * before, so the variants do not compete with each other on the same day.
40
+ */
41
+ export function hookTest(ws, id, hooks, opts = {}) {
42
+ const base = loadDeck(ws, id);
43
+ if (base.status === "published")
44
+ throw new UserError(`deck ${id} is already published; test hooks on a new deck (or deck_repost for a second go)`);
45
+ if (base.variant && base.variant !== "a")
46
+ throw new UserError(`deck ${id} is variant ${base.variant} of ${base.experiment}; start from variant a`);
47
+ if (!hooks.length || hooks.length > 4)
48
+ throw new UserError("give 1 to 4 new hooks (variant a is the deck as it is)");
49
+ const seen = new Set([normalizeHook(base.slides[coverIndex(base.slides)]?.title ?? "")]);
50
+ for (const h of hooks) {
51
+ const k = normalizeHook(h);
52
+ if (!k || seen.has(k))
53
+ throw new UserError(`each hook must be different: "${h}"`);
54
+ seen.add(k);
55
+ }
56
+ const experiment = base.experiment ?? base.id;
57
+ const existing = listDecks(ws).filter((d) => d.deck?.experiment === experiment).length;
58
+ if (existing + hooks.length > LETTERS.length && existing)
59
+ throw new UserError(`an experiment has at most ${LETTERS.length} variants`);
60
+ const a = saveDeck(ws, { ...base, experiment, variant: "a" });
61
+ const out = [a];
62
+ hooks.forEach((hook, i) => {
63
+ const letter = LETTERS[Math.max(existing, 1) + i];
64
+ out.push(newDeck(ws, {
65
+ ...design(base),
66
+ id: uniqueDeckId(ws, `${base.id}-${letter}`),
67
+ slides: withHook(base.slides, hook),
68
+ when: shiftDays(base.when, (opts.spread_days ?? 0) * (i + 1)),
69
+ experiment,
70
+ variant: letter,
71
+ }));
72
+ });
73
+ return out;
74
+ }
75
+ // ---------- series ----------
76
+ /** The next part of a series. The first deck becomes part 1 when it is not in a series yet. */
77
+ export function seriesNext(ws, id, slides, opts = {}) {
78
+ const prev = loadDeck(ws, id);
79
+ let series = prev.series;
80
+ if (!series) {
81
+ series = { id: prev.id, part: 1, ...(opts.of ? { of: opts.of } : {}), ...(opts.label ? { label: opts.label } : {}) };
82
+ // A posted deck keeps its look; the series starts from it anyway.
83
+ if (prev.status !== "published")
84
+ saveDeck(ws, { ...prev, series, status: "draft" });
85
+ }
86
+ const part = Math.max(series.part, ...listDecks(ws).filter((d) => d.deck?.series?.id === series.id).map((d) => d.deck.series.part)) + 1;
87
+ const of = opts.of ?? series.of;
88
+ if (of && part > of)
89
+ throw new UserError(`the series has ${of} parts and part ${of} exists; raise "of" to add more`);
90
+ return newDeck(ws, {
91
+ ...design(prev),
92
+ id: uniqueDeckId(ws, `${series.id}-part-${part}`),
93
+ topic: opts.topic ?? prev.topic,
94
+ slides,
95
+ when: opts.when,
96
+ series: { id: series.id, part, ...(of ? { of } : {}), ...(opts.label ?? series.label ? { label: opts.label ?? series.label } : {}) },
97
+ });
98
+ }
99
+ export function listSeries(ws) {
100
+ const by = new Map();
101
+ for (const d of listDecks(ws))
102
+ if (d.deck?.series)
103
+ by.set(d.deck.series.id, [...(by.get(d.deck.series.id) ?? []), d.deck]);
104
+ return [...by.entries()].map(([id, ds]) => ({
105
+ id,
106
+ parts: ds
107
+ .sort((a, b) => a.series.part - b.series.part)
108
+ .map((d) => ({ deck: d.id, part: d.series.part, of: d.series.of, status: d.status, when: d.when, hook: d.slides[coverIndex(d.slides)]?.title })),
109
+ }));
110
+ }
111
+ // ---------- translations ----------
112
+ /**
113
+ * The same deck in another language. The agent writes the translated slides; this keeps every
114
+ * image, crop and number from the original, and checks the slides line up one to one.
115
+ */
116
+ export function translateDeck(ws, id, language, t) {
117
+ const src = loadDeck(ws, id);
118
+ if (src.translation_of)
119
+ throw new UserError(`deck ${id} is itself a translation of ${src.translation_of}; translate the original`);
120
+ if (language.toLowerCase() === src.language.toLowerCase())
121
+ throw new UserError(`deck ${id} is already in ${src.language}`);
122
+ if (t.slides.length !== src.slides.length)
123
+ throw new UserError(`the translation has ${t.slides.length} slides; the original has ${src.slides.length}. Translate every slide, in order`);
124
+ const slides = src.slides.map((s, i) => {
125
+ const tr = t.slides[i];
126
+ if (tr.kind && tr.kind !== s.kind)
127
+ throw new UserError(`slide ${i + 1} is a ${s.kind} in the original but ${tr.kind} in the translation`);
128
+ if (s.items?.length && tr.items && tr.items.length !== s.items.length)
129
+ throw new UserError(`slide ${i + 1}: the original list has ${s.items.length} items`);
130
+ // Words come from the translation; the picture and its crop stay.
131
+ return parseWith(slideSchema, { ...s, ...tr, kind: s.kind, image: s.image, focus: s.focus, number: s.number }, `slide ${i + 1}`);
132
+ });
133
+ return newDeck(ws, {
134
+ ...design(src),
135
+ id: uniqueDeckId(ws, `${src.id}-${language.toLowerCase()}`),
136
+ language,
137
+ slides,
138
+ caption: t.caption ?? "",
139
+ hashtags: t.hashtags ?? [],
140
+ accounts: t.accounts ?? src.accounts,
141
+ when: t.when,
142
+ translation_of: src.id,
143
+ });
144
+ }
145
+ // ---------- reposts ----------
146
+ /**
147
+ * A deck that did well, posted again with a new hook. Platforms push down copies of the same post,
148
+ * so the cover must change; the middle slides can be reordered too.
149
+ */
150
+ export function repostDeck(ws, id, hook, opts = {}) {
151
+ const src = loadDeck(ws, id);
152
+ const last = src.published.at(-1);
153
+ if (!last)
154
+ throw new UserError(`deck ${id} was never published; publish it instead`);
155
+ const days = opts.min_days ?? 30;
156
+ const posted = Date.parse(last.scheduled_for ?? last.at);
157
+ const age = ((opts.now ?? new Date()).getTime() - posted) / 86_400_000;
158
+ if (age < days)
159
+ throw new UserError(`deck ${id} went out ${Math.floor(age)} days ago; wait ${days} days before posting it again`);
160
+ const key = normalizeHook(hook);
161
+ const used = usedHooks(ws, 1000).find((h) => normalizeHook(h.hook) === key);
162
+ if (!key || used)
163
+ throw new UserError(`"${hook}" was used before${used?.deck ? ` (${used.deck})` : ""}; a repost needs a hook people have not seen`);
164
+ let slides = withHook(src.slides, hook);
165
+ if (opts.order) {
166
+ const n = slides.length;
167
+ const sorted = [...opts.order].sort((a, b) => a - b);
168
+ if (sorted.length !== n || sorted.some((v, i) => v !== i))
169
+ throw new UserError(`order must list every slide index 0–${n - 1} once`);
170
+ if (opts.order[0] !== coverIndex(slides))
171
+ throw new UserError("the cover stays first");
172
+ slides = opts.order.map((i) => slides[i]);
173
+ }
174
+ return newDeck(ws, { ...design(src), id: uniqueDeckId(ws, `${src.id}-again`), slides, repost_of: src.id });
175
+ }
@@ -0,0 +1 @@
1
+ export declare const VERSION = "0.2.0";
@@ -0,0 +1 @@
1
+ export const VERSION = "0.2.0";
@@ -0,0 +1,22 @@
1
+ import { type SizeId } from "./schema.js";
2
+ import { type Workspace } from "./workspace.js";
3
+ export interface VideoOptions {
4
+ /** Seconds each slide stays on screen. */
5
+ seconds?: number;
6
+ /** Seconds of crossfade between slides; 0 cuts. */
7
+ fade?: number;
8
+ /** The video frame; slides of another shape sit in the middle on the theme's background. */
9
+ size?: SizeId;
10
+ }
11
+ /** ffmpeg's arguments to turn the slides into one MP4, without sound (music is added in the app). */
12
+ export declare function videoArgs(files: string[], out: string, o: Required<VideoOptions> & {
13
+ background: string;
14
+ }): string[];
15
+ /**
16
+ * The rendered slides as a short MP4 for Reels, Shorts or a TikTok video post: each slide for a
17
+ * few seconds, with a soft fade. Needs ffmpeg on this machine (or FFMPEG_PATH).
18
+ */
19
+ export declare function renderVideo(ws: Workspace, id: string, opts?: VideoOptions): Promise<{
20
+ file: string;
21
+ seconds: number;
22
+ }>;
package/dist/video.js ADDED
@@ -0,0 +1,59 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { freshRenders } from "./decks.js";
6
+ import { SIZES } from "./schema.js";
7
+ import { themeFor } from "./render.js";
8
+ import { loadDeck, rendersDir, UserError } from "./workspace.js";
9
+ const run = promisify(execFile);
10
+ /** ffmpeg's arguments to turn the slides into one MP4, without sound (music is added in the app). */
11
+ export function videoArgs(files, out, o) {
12
+ const { width: W, height: H } = SIZES[o.size];
13
+ const args = ["-y"];
14
+ const hold = o.seconds + o.fade;
15
+ for (const f of files)
16
+ args.push("-loop", "1", "-t", hold.toFixed(2), "-i", f);
17
+ const bg = o.background.replace("#", "0x");
18
+ const parts = files.map((_, i) => `[${i}:v]scale=${W}:${H}:force_original_aspect_ratio=decrease:out_range=tv,pad=${W}:${H}:(ow-iw)/2:(oh-ih)/2:color=${bg},setsar=1,fps=30,format=yuv420p[s${i}]`);
19
+ let last = "s0";
20
+ if (files.length === 1)
21
+ parts.push("[s0]null[v]");
22
+ else if (o.fade > 0)
23
+ for (let i = 1; i < files.length; i++) {
24
+ const offset = (o.seconds * i).toFixed(2);
25
+ const label = i === files.length - 1 ? "v" : `x${i}`;
26
+ parts.push(`[${last}][s${i}]xfade=transition=fade:duration=${o.fade.toFixed(2)}:offset=${offset}[${label}]`);
27
+ last = label;
28
+ }
29
+ else
30
+ parts.push(`${files.map((_, i) => `[s${i}]`).join("")}concat=n=${files.length}:v=1:a=0[v]`);
31
+ args.push("-filter_complex", parts.join(";"), "-map", "[v]", "-c:v", "libx264", "-preset", "medium", "-crf", "20", "-pix_fmt", "yuv420p", "-movflags", "+faststart", "-an", out);
32
+ return args;
33
+ }
34
+ /**
35
+ * The rendered slides as a short MP4 for Reels, Shorts or a TikTok video post: each slide for a
36
+ * few seconds, with a soft fade. Needs ffmpeg on this machine (or FFMPEG_PATH).
37
+ */
38
+ export async function renderVideo(ws, id, opts = {}) {
39
+ const deck = loadDeck(ws, id);
40
+ const manifest = freshRenders(ws, deck);
41
+ const o = { seconds: Math.min(Math.max(opts.seconds ?? 2.5, 1), 10), fade: Math.min(Math.max(opts.fade ?? 0.35, 0), 1), size: opts.size ?? "9:16" };
42
+ if (o.fade >= o.seconds)
43
+ throw new UserError("fade must be shorter than seconds");
44
+ const files = manifest.files.map((f) => join(rendersDir(ws, id), f));
45
+ const out = join(rendersDir(ws, id), "video.mp4");
46
+ const ffmpeg = process.env.FFMPEG_PATH ?? "ffmpeg";
47
+ if (process.env.FFMPEG_PATH && !existsSync(process.env.FFMPEG_PATH))
48
+ throw new UserError(`FFMPEG_PATH points to ${process.env.FFMPEG_PATH}, which does not exist`);
49
+ try {
50
+ await run(ffmpeg, videoArgs(files, out, { ...o, background: themeFor(deck).colors.bg }), { timeout: 300_000, maxBuffer: 8 * 1024 * 1024 });
51
+ }
52
+ catch (e) {
53
+ const err = e;
54
+ if (err.code === "ENOENT")
55
+ throw new UserError("making a video needs ffmpeg: install it (macOS: brew install ffmpeg; Windows: winget install ffmpeg; Linux: your package manager) or set FFMPEG_PATH");
56
+ throw new UserError(`ffmpeg failed: ${String(err.stderr ?? err.message).trim().split("\n").slice(-3).join(" ")}`);
57
+ }
58
+ return { file: out, seconds: Math.round((o.seconds * files.length) * 10) / 10 };
59
+ }
@@ -0,0 +1,12 @@
1
+ import { type ViralPost } from "./publish.js";
2
+ export type ViralKind = "slideshow" | "video" | "any";
3
+ export type ViralSince = "week" | "month" | "quarter" | "half" | "any";
4
+ export declare function viralSearch(query: string, opts?: {
5
+ kind?: ViralKind;
6
+ since?: ViralSince;
7
+ limit?: number;
8
+ }): Promise<ViralPost[]>;
9
+ /** One line per post, for a terminal or a model: numbers, slide count, the caption. */
10
+ export declare function viralLines(posts: ViralPost[]): string[];
11
+ /** The covers side by side, numbered, so the agent can read the hooks written on them. */
12
+ export declare function viralSheet(posts: ViralPost[], max?: number): Promise<Buffer | null>;
package/dist/viral.js ADDED
@@ -0,0 +1,35 @@
1
+ import sharp from "sharp";
2
+ import { download } from "./images.js";
3
+ import { AppeekyClient } from "./publish.js";
4
+ import { UserError } from "./workspace.js";
5
+ export async function viralSearch(query, opts = {}) {
6
+ if (!process.env.APPEEKY_API_KEY)
7
+ throw new UserError("set APPEEKY_API_KEY (your key from appeeky.com) to search what works on TikTok; each search costs $0.01 from your Appeeky balance");
8
+ const { posts } = await new AppeekyClient().viral(query, opts);
9
+ return posts ?? [];
10
+ }
11
+ const compact = (n) => (n == null ? "?" : n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${Math.round(n / 1e3)}K` : String(n));
12
+ /** One line per post, for a terminal or a model: numbers, slide count, the caption. */
13
+ export function viralLines(posts) {
14
+ return posts.map((p, i) => `${i + 1}. ${compact(p.likes)} likes · ${compact(p.views)} views${p.slideCount ? ` · ${p.slideCount} slides` : ""} — ${p.caption.replace(/\s+/g, " ").slice(0, 140) || "(no caption)"} ${p.url}`);
15
+ }
16
+ /** The covers side by side, numbered, so the agent can read the hooks written on them. */
17
+ export async function viralSheet(posts, max = 12) {
18
+ const picked = posts.slice(0, max);
19
+ const thumbs = await Promise.all(picked.map(async (p) => {
20
+ const src = p.images[0];
21
+ if (!src)
22
+ return null;
23
+ try {
24
+ return await sharp(await download(src), { limitInputPixels: 40_000_000 }).rotate().resize(300, 533, { fit: "cover" }).jpeg().toBuffer();
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }));
30
+ const ok = thumbs.flatMap((t, i) => (t ? [{ t, i }] : []));
31
+ if (!ok.length)
32
+ return null;
33
+ const { contactSheet } = await import("./render.js");
34
+ return contactSheet(ok.map((x) => x.t), "9:16", Math.min(ok.length, 6), ok.map((x) => `${x.i + 1}. ${compact(picked[x.i].likes)} likes`));
35
+ }
@@ -0,0 +1,85 @@
1
+ import { z } from "zod";
2
+ import { type Channel, type Deck, type Settings } from "./schema.js";
3
+ export declare const SETTINGS_FILE = "open-slideshow.yaml";
4
+ export declare const SPEC_FILE = "appeeky.spec.yaml";
5
+ export interface SpecInfo {
6
+ file: string;
7
+ app: {
8
+ name: string;
9
+ app_store_id?: string;
10
+ play_package?: string;
11
+ locale: string;
12
+ };
13
+ playbook?: string;
14
+ store_dir: string;
15
+ accounts_file: string;
16
+ posts_file: string;
17
+ drafts_dir: string;
18
+ comments_file: string;
19
+ reviews_dir: string;
20
+ screenshots_dir: string;
21
+ /** Locales of the store listing (appeeky/store/<store>/<locale>.yaml), primary first. */
22
+ locales: string[];
23
+ }
24
+ export interface Workspace {
25
+ mode: "standalone" | "spec";
26
+ root: string;
27
+ /** Where decks, channels and images live. */
28
+ dir: string;
29
+ state: string;
30
+ settings_file: string;
31
+ settings: Settings;
32
+ /** Whether a settings file exists (standalone) or the Spec repo was found. */
33
+ initialized: boolean;
34
+ spec?: SpecInfo;
35
+ warnings: string[];
36
+ }
37
+ export declare class UserError extends Error {
38
+ }
39
+ export declare function parseWith<T extends z.ZodTypeAny>(schema: T, data: unknown, file: string): z.infer<T>;
40
+ /** Writes through a temp file so a crash never leaves half a file. */
41
+ export declare function writeAtomic(file: string, content: string | Buffer): void;
42
+ export declare function openWorkspace(cwd?: string): Workspace;
43
+ export declare function initWorkspace(cwd: string, settings?: Partial<Settings>): Workspace;
44
+ export declare function settingsYaml(s: Settings): string;
45
+ export declare function saveSettings(ws: Workspace, settings: Settings): void;
46
+ export declare function checkId(id: string, what?: string): string;
47
+ export declare function slugify(text: string): string;
48
+ export declare const deckDir: (ws: Workspace, id: string) => string;
49
+ export declare const deckFile: (ws: Workspace, id: string) => string;
50
+ export declare const rendersDir: (ws: Workspace, id: string) => string;
51
+ export declare const channelFile: (ws: Workspace, id: string) => string;
52
+ export declare const imagesDir: (ws: Workspace) => string;
53
+ export declare function isInside(parent: string, child: string): boolean;
54
+ /** A slide's image: a name in images/ or a path inside the workspace. Never outside it. */
55
+ export declare function resolveImage(ws: Workspace, ref: string): string | null;
56
+ export declare function deckExists(ws: Workspace, id: string): boolean;
57
+ export declare function loadDeck(ws: Workspace, id: string): Deck;
58
+ export declare function saveDeck(ws: Workspace, deck: Deck): Deck;
59
+ export declare function listDecks(ws: Workspace): {
60
+ id: string;
61
+ deck?: Deck;
62
+ error?: string;
63
+ }[];
64
+ export declare function uniqueDeckId(ws: Workspace, base: string): string;
65
+ export declare function loadChannel(ws: Workspace, id: string): Channel;
66
+ export declare function saveChannel(ws: Workspace, ch: Channel): Channel;
67
+ export declare function listChannels(ws: Workspace): {
68
+ id: string;
69
+ channel?: Channel;
70
+ error?: string;
71
+ }[];
72
+ export declare function readJson<T>(file: string, fallback: T): T;
73
+ export declare function readJsonl<T>(file: string): T[];
74
+ export interface HistoryEntry {
75
+ deck: string;
76
+ channel?: string;
77
+ hook: string;
78
+ topic?: string;
79
+ at: string;
80
+ provider: string;
81
+ post_id?: string;
82
+ scheduled_for?: string;
83
+ }
84
+ export declare function historyFile(ws: Workspace): string;
85
+ export declare function appendHistory(ws: Workspace, e: HistoryEntry): void;