@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/text.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { measure } from "./fonts.js";
|
|
2
|
+
/** `*word*` marks words for the accent; `\*` is a literal star. Throws on an unclosed star. */
|
|
3
|
+
export function parseMarkup(input) {
|
|
4
|
+
const runs = [];
|
|
5
|
+
let accent = false;
|
|
6
|
+
let buf = "";
|
|
7
|
+
for (let i = 0; i < input.length; i++) {
|
|
8
|
+
const ch = input[i];
|
|
9
|
+
if (ch === "\\" && input[i + 1] === "*") {
|
|
10
|
+
buf += "*";
|
|
11
|
+
i++;
|
|
12
|
+
}
|
|
13
|
+
else if (ch === "*") {
|
|
14
|
+
if (buf)
|
|
15
|
+
runs.push({ text: buf, accent });
|
|
16
|
+
buf = "";
|
|
17
|
+
accent = !accent;
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
buf += ch;
|
|
21
|
+
}
|
|
22
|
+
if (accent)
|
|
23
|
+
throw new Error(`unclosed * in "${input}"`);
|
|
24
|
+
if (buf)
|
|
25
|
+
runs.push({ text: buf, accent });
|
|
26
|
+
return runs;
|
|
27
|
+
}
|
|
28
|
+
export function plainText(input) {
|
|
29
|
+
try {
|
|
30
|
+
return parseMarkup(input)
|
|
31
|
+
.map((r) => r.text)
|
|
32
|
+
.join("");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return input.replace(/\*/g, "");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function markupError(input) {
|
|
39
|
+
if (!input)
|
|
40
|
+
return null;
|
|
41
|
+
try {
|
|
42
|
+
parseMarkup(input);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return e.message;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const CJK = /[-ヿ㐀-䶿一-鿿가-豈-]/u;
|
|
50
|
+
/** Words (or single CJK characters) with their accent runs. */
|
|
51
|
+
function pieces(runs, upper, locale) {
|
|
52
|
+
const out = [];
|
|
53
|
+
let cur = [];
|
|
54
|
+
let pendingSpace = false;
|
|
55
|
+
let pendingNewline = false;
|
|
56
|
+
const flush = () => {
|
|
57
|
+
if (cur.length)
|
|
58
|
+
out.push({ runs: cur, space: pendingSpace, newline: pendingNewline });
|
|
59
|
+
cur = [];
|
|
60
|
+
pendingSpace = false;
|
|
61
|
+
pendingNewline = false;
|
|
62
|
+
};
|
|
63
|
+
// A break with no space: ends the word being built; a space or new line already pending stays.
|
|
64
|
+
const breakHere = () => {
|
|
65
|
+
if (cur.length)
|
|
66
|
+
flush();
|
|
67
|
+
};
|
|
68
|
+
const push = (ch, accent) => {
|
|
69
|
+
const last = cur[cur.length - 1];
|
|
70
|
+
if (last && last.accent === accent)
|
|
71
|
+
last.text += ch;
|
|
72
|
+
else
|
|
73
|
+
cur.push({ text: ch, accent });
|
|
74
|
+
};
|
|
75
|
+
// Japanese breaks between phrases (a word and the particles after it), not between any two
|
|
76
|
+
// characters: the boundaries are found on the whole text, across accent runs.
|
|
77
|
+
const cased = runs.map((r) => (upper ? upperCase(r.text, locale) : r.text));
|
|
78
|
+
const bounds = KANA.test(cased.join("")) || /^ja\b/i.test(locale ?? "") ? jaPhraseBounds(cased.join("")) : null;
|
|
79
|
+
let at = 0;
|
|
80
|
+
for (const [ri, run] of runs.entries()) {
|
|
81
|
+
const text = /\p{Script=Thai}/u.test(cased[ri]) ? thaiBreaks(cased[ri]) : cased[ri];
|
|
82
|
+
for (const ch of text) {
|
|
83
|
+
if (bounds && ch !== "\u200b") {
|
|
84
|
+
if (bounds.has(at))
|
|
85
|
+
breakHere();
|
|
86
|
+
at += ch.length;
|
|
87
|
+
}
|
|
88
|
+
if (ch === "\u200b") {
|
|
89
|
+
// A break that adds no space (Thai word boundaries, or typed by the writer).
|
|
90
|
+
breakHere();
|
|
91
|
+
}
|
|
92
|
+
else if (ch === "\n") {
|
|
93
|
+
flush();
|
|
94
|
+
pendingNewline = true;
|
|
95
|
+
}
|
|
96
|
+
else if (/\s/u.test(ch)) {
|
|
97
|
+
const nl = pendingNewline;
|
|
98
|
+
flush();
|
|
99
|
+
pendingNewline = nl;
|
|
100
|
+
pendingSpace = !nl;
|
|
101
|
+
}
|
|
102
|
+
else if (CJK.test(ch) && !bounds) {
|
|
103
|
+
breakHere();
|
|
104
|
+
push(ch, run.accent);
|
|
105
|
+
flush();
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
push(ch, run.accent);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
flush();
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
const runsWidth = (role, runs, size, locale) => runs.reduce((w, r) => w + measure(role, r.text, size, locale), 0);
|
|
115
|
+
function appendRuns(line, runs, space) {
|
|
116
|
+
const add = (r) => {
|
|
117
|
+
const last = line[line.length - 1];
|
|
118
|
+
if (last && last.accent === r.accent)
|
|
119
|
+
last.text += r.text;
|
|
120
|
+
else
|
|
121
|
+
line.push({ ...r });
|
|
122
|
+
};
|
|
123
|
+
if (space && line.length)
|
|
124
|
+
add({ text: " ", accent: line[line.length - 1].accent && runs[0].accent });
|
|
125
|
+
for (const r of runs)
|
|
126
|
+
add(r);
|
|
127
|
+
}
|
|
128
|
+
/** Splits a piece wider than the line into character chunks. */
|
|
129
|
+
function splitWide(role, piece, size, width, locale) {
|
|
130
|
+
const out = [];
|
|
131
|
+
let cur = [];
|
|
132
|
+
for (const run of piece.runs)
|
|
133
|
+
for (const { segment: ch } of graphemes.segment(run.text)) {
|
|
134
|
+
const next = [...cur.map((r) => ({ ...r }))];
|
|
135
|
+
appendRuns(next, [{ text: ch, accent: run.accent }], false);
|
|
136
|
+
if (cur.length && runsWidth(role, next, size, locale) > width) {
|
|
137
|
+
out.push({ runs: cur, space: out.length === 0 ? piece.space : false, newline: out.length === 0 ? piece.newline : false });
|
|
138
|
+
cur = [{ text: ch, accent: run.accent }];
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
cur = next;
|
|
142
|
+
}
|
|
143
|
+
if (cur.length)
|
|
144
|
+
out.push({ runs: cur, space: out.length === 0 ? piece.space : false, newline: out.length === 0 ? piece.newline : false });
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
export function wrap(role, markup, size, width, locale) {
|
|
148
|
+
const lines = [];
|
|
149
|
+
let line = [];
|
|
150
|
+
let brokeWord = false;
|
|
151
|
+
for (const p0 of pieces(parseMarkup(markup), !!role.uppercase, locale)) {
|
|
152
|
+
const parts = runsWidth(role, p0.runs, size, locale) > width ? ((brokeWord = true), splitWide(role, p0, size, width, locale)) : [p0];
|
|
153
|
+
for (const p of parts) {
|
|
154
|
+
if (p.newline && line.length) {
|
|
155
|
+
lines.push(line);
|
|
156
|
+
line = [];
|
|
157
|
+
}
|
|
158
|
+
const candidate = line.map((r) => ({ ...r }));
|
|
159
|
+
appendRuns(candidate, p.runs, p.space);
|
|
160
|
+
if (line.length && runsWidth(role, candidate, size, locale) > width) {
|
|
161
|
+
lines.push(line);
|
|
162
|
+
line = [];
|
|
163
|
+
appendRuns(line, p.runs, false);
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
line = candidate;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (line.length)
|
|
170
|
+
lines.push(line);
|
|
171
|
+
return { lines, broke_word: brokeWord };
|
|
172
|
+
}
|
|
173
|
+
/** The largest size at which the text fits the box without cutting a word. */
|
|
174
|
+
export function fit(role, markup, o) {
|
|
175
|
+
let last = null;
|
|
176
|
+
for (let size = o.max; size >= o.min; size -= 2) {
|
|
177
|
+
const w = wrap(role, markup, size, o.width, o.locale);
|
|
178
|
+
const height = w.lines.length * size * o.line_height;
|
|
179
|
+
last = { size, lines: w.lines, height, overflow: false, broke_word: w.broke_word };
|
|
180
|
+
if (height <= o.height && !w.broke_word && (!o.max_lines || w.lines.length <= o.max_lines))
|
|
181
|
+
return last;
|
|
182
|
+
}
|
|
183
|
+
const w = wrap(role, markup, o.min, o.width, o.locale);
|
|
184
|
+
return { size: o.min, lines: w.lines, height: w.lines.length * o.min * o.line_height, overflow: true, broke_word: w.broke_word || !!last?.broke_word };
|
|
185
|
+
}
|
|
186
|
+
/** Upper-cases in the deck's language; an unknown language code falls back to plain rules. */
|
|
187
|
+
export function upperCase(text, locale) {
|
|
188
|
+
try {
|
|
189
|
+
return text.toLocaleUpperCase(locale ?? "en");
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return text.toUpperCase();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Whether a line reads right to left (its first strong letter is Arabic or Hebrew). */
|
|
196
|
+
export function isRtl(text) {
|
|
197
|
+
const m = /[\p{Script=Arabic}\p{Script=Hebrew}]|[\p{L}]/u.exec(text);
|
|
198
|
+
return !!m && /[\p{Script=Arabic}\p{Script=Hebrew}]/u.test(m[0]);
|
|
199
|
+
}
|
|
200
|
+
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
201
|
+
const thaiWords = new Intl.Segmenter("th", { granularity: "word" });
|
|
202
|
+
const KANA = /[\p{Script=Hiragana}\p{Script=Katakana}]/u;
|
|
203
|
+
const jaWords = new Intl.Segmenter("ja", { granularity: "word" });
|
|
204
|
+
/** Marks that may not start a line, or end one (Japanese line-breaking rules). */
|
|
205
|
+
const NO_START = /^[、。,.・:;?!ー〜…‥」』)】〕〉》”’ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ]/u;
|
|
206
|
+
const NO_END = /[「『(【〔〈《“‘]$/u;
|
|
207
|
+
/** Where a Japanese line may break: after each phrase (a word with the particles after it), as offsets. */
|
|
208
|
+
function jaPhraseBounds(text) {
|
|
209
|
+
const phrases = [];
|
|
210
|
+
for (const { segment } of jaWords.segment(text)) {
|
|
211
|
+
const prev = phrases[phrases.length - 1];
|
|
212
|
+
const join = prev !== undefined && !/\s/u.test(segment) && !/\s$/u.test(prev) && (/^\p{Script=Hiragana}+$/u.test(segment) || NO_START.test(segment) || NO_END.test(prev) || /\p{Nd}$/u.test(prev));
|
|
213
|
+
if (join)
|
|
214
|
+
phrases[phrases.length - 1] += segment;
|
|
215
|
+
else
|
|
216
|
+
phrases.push(segment);
|
|
217
|
+
}
|
|
218
|
+
const out = new Set();
|
|
219
|
+
let at = 0;
|
|
220
|
+
for (const p of phrases) {
|
|
221
|
+
if (at > 0)
|
|
222
|
+
out.add(at);
|
|
223
|
+
at += p.length;
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
/** Thai has no spaces between words: mark the word boundaries so lines can break there. */
|
|
228
|
+
function thaiBreaks(text) {
|
|
229
|
+
return [...thaiWords.segment(text)].map((s) => s.segment).join("\u200b");
|
|
230
|
+
}
|
package/dist/themes.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Colors, TextStyle } from "./schema.js";
|
|
2
|
+
export type FontFamily = "TikTok Sans" | "Inter" | "Anton" | "Instrument Serif";
|
|
3
|
+
export type Design = "photo" | "magazine" | "plain";
|
|
4
|
+
export interface FontRole {
|
|
5
|
+
family: FontFamily;
|
|
6
|
+
weight: number;
|
|
7
|
+
uppercase?: boolean;
|
|
8
|
+
italic?: boolean;
|
|
9
|
+
/** Extra space between letters, in em. */
|
|
10
|
+
tracking?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Theme {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
design: Design;
|
|
17
|
+
colors: Required<Colors>;
|
|
18
|
+
display: FontRole;
|
|
19
|
+
body: FontRole;
|
|
20
|
+
/** How words sit on a photo (photo design only). */
|
|
21
|
+
text_style: TextStyle;
|
|
22
|
+
/** How `*words*` stand out: in the accent colour, on an accent box, or underlined in the accent. */
|
|
23
|
+
accent_style: "color" | "box" | "underline";
|
|
24
|
+
align: "center" | "left";
|
|
25
|
+
/** How dark the photo gets under the words, 0 to 1. */
|
|
26
|
+
scrim: number;
|
|
27
|
+
/** Where the words sit on a photo slide, as % of the height (the middle of the block). */
|
|
28
|
+
cover_position: number;
|
|
29
|
+
tip_position: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const THEMES: Theme[];
|
|
32
|
+
export declare function getTheme(id: string): Theme | undefined;
|
|
33
|
+
/** A theme with brand colours laid over it. Text on photos keeps the theme's own colours, so it stays readable. */
|
|
34
|
+
export declare function withColors(theme: Theme, colors: Colors | undefined): Theme;
|
|
35
|
+
export declare function hexToRgb(hex: string): [number, number, number];
|
|
36
|
+
export declare function rgbToHex([r, g, b]: [number, number, number]): string;
|
|
37
|
+
/** `a` moved toward `b` by `t`. */
|
|
38
|
+
export declare function mix(a: string, b: string, t: number): string;
|
|
39
|
+
export declare function luminance(hex: string): number;
|
|
40
|
+
/** WCAG contrast ratio, 1 to 21. */
|
|
41
|
+
export declare function contrast(a: string, b: string): number;
|
|
42
|
+
/** Black or white, whichever reads better on `bg`. */
|
|
43
|
+
export declare function readableOn(bg: string): string;
|
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 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.1.0";
|
package/dist/viral.d.ts
ADDED
|
@@ -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,80 @@
|
|
|
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
|
+
}
|
|
19
|
+
export interface Workspace {
|
|
20
|
+
mode: "standalone" | "spec";
|
|
21
|
+
root: string;
|
|
22
|
+
/** Where decks, channels and images live. */
|
|
23
|
+
dir: string;
|
|
24
|
+
state: string;
|
|
25
|
+
settings_file: string;
|
|
26
|
+
settings: Settings;
|
|
27
|
+
/** Whether a settings file exists (standalone) or the Spec repo was found. */
|
|
28
|
+
initialized: boolean;
|
|
29
|
+
spec?: SpecInfo;
|
|
30
|
+
warnings: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare class UserError extends Error {
|
|
33
|
+
}
|
|
34
|
+
export declare function parseWith<T extends z.ZodTypeAny>(schema: T, data: unknown, file: string): z.infer<T>;
|
|
35
|
+
/** Writes through a temp file so a crash never leaves half a file. */
|
|
36
|
+
export declare function writeAtomic(file: string, content: string | Buffer): void;
|
|
37
|
+
export declare function openWorkspace(cwd?: string): Workspace;
|
|
38
|
+
export declare function initWorkspace(cwd: string, settings?: Partial<Settings>): Workspace;
|
|
39
|
+
export declare function settingsYaml(s: Settings): string;
|
|
40
|
+
export declare function saveSettings(ws: Workspace, settings: Settings): void;
|
|
41
|
+
export declare function checkId(id: string, what?: string): string;
|
|
42
|
+
export declare function slugify(text: string): string;
|
|
43
|
+
export declare const deckDir: (ws: Workspace, id: string) => string;
|
|
44
|
+
export declare const deckFile: (ws: Workspace, id: string) => string;
|
|
45
|
+
export declare const rendersDir: (ws: Workspace, id: string) => string;
|
|
46
|
+
export declare const channelFile: (ws: Workspace, id: string) => string;
|
|
47
|
+
export declare const imagesDir: (ws: Workspace) => string;
|
|
48
|
+
export declare function isInside(parent: string, child: string): boolean;
|
|
49
|
+
/** A slide's image: a name in images/ or a path inside the workspace. Never outside it. */
|
|
50
|
+
export declare function resolveImage(ws: Workspace, ref: string): string | null;
|
|
51
|
+
export declare function deckExists(ws: Workspace, id: string): boolean;
|
|
52
|
+
export declare function loadDeck(ws: Workspace, id: string): Deck;
|
|
53
|
+
export declare function saveDeck(ws: Workspace, deck: Deck): Deck;
|
|
54
|
+
export declare function listDecks(ws: Workspace): {
|
|
55
|
+
id: string;
|
|
56
|
+
deck?: Deck;
|
|
57
|
+
error?: string;
|
|
58
|
+
}[];
|
|
59
|
+
export declare function uniqueDeckId(ws: Workspace, base: string): string;
|
|
60
|
+
export declare function loadChannel(ws: Workspace, id: string): Channel;
|
|
61
|
+
export declare function saveChannel(ws: Workspace, ch: Channel): Channel;
|
|
62
|
+
export declare function listChannels(ws: Workspace): {
|
|
63
|
+
id: string;
|
|
64
|
+
channel?: Channel;
|
|
65
|
+
error?: string;
|
|
66
|
+
}[];
|
|
67
|
+
export declare function readJson<T>(file: string, fallback: T): T;
|
|
68
|
+
export declare function readJsonl<T>(file: string): T[];
|
|
69
|
+
export interface HistoryEntry {
|
|
70
|
+
deck: string;
|
|
71
|
+
channel?: string;
|
|
72
|
+
hook: string;
|
|
73
|
+
topic?: string;
|
|
74
|
+
at: string;
|
|
75
|
+
provider: string;
|
|
76
|
+
post_id?: string;
|
|
77
|
+
scheduled_for?: string;
|
|
78
|
+
}
|
|
79
|
+
export declare function historyFile(ws: Workspace): string;
|
|
80
|
+
export declare function appendHistory(ws: Workspace, e: HistoryEntry): void;
|