@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/schema.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Deck, channel and slide ids: lowercase slugs, so they are safe as folder names on every OS. */
|
|
3
|
+
export const ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
4
|
+
export const idSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.regex(ID_PATTERN, "use lowercase letters, digits and dashes (max 64), starting with a letter or digit")
|
|
7
|
+
.refine((s) => !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(s), "that name is reserved on Windows");
|
|
8
|
+
export const SIZES = {
|
|
9
|
+
"4:5": { width: 1080, height: 1350 },
|
|
10
|
+
"1:1": { width: 1080, height: 1080 },
|
|
11
|
+
"9:16": { width: 1080, height: 1920 },
|
|
12
|
+
};
|
|
13
|
+
export const sizeSchema = z.enum(["4:5", "1:1", "9:16"]);
|
|
14
|
+
export const textStyleSchema = z.enum(["outline", "shadow", "plain", "box"]);
|
|
15
|
+
export const hexColor = z.string().regex(/^#[0-9a-fA-F]{6}$/, "use a 6-digit hex colour like #1a2b3c");
|
|
16
|
+
export const colorsSchema = z
|
|
17
|
+
.object({ bg: hexColor, fg: hexColor, accent: hexColor, muted: hexColor.optional(), card: hexColor.optional() })
|
|
18
|
+
.strict();
|
|
19
|
+
export const slideKindSchema = z.enum(["cover", "tip", "list", "quote", "bridge", "app", "text"]);
|
|
20
|
+
export const slideSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
kind: slideKindSchema,
|
|
23
|
+
title: z.string().max(400).optional(),
|
|
24
|
+
body: z.string().max(1200).optional(),
|
|
25
|
+
items: z.array(z.string().min(1).max(200)).max(8).optional(),
|
|
26
|
+
list_style: z.enum(["bullet", "check", "number"]).optional(),
|
|
27
|
+
number: z.number().int().min(0).max(99).optional(),
|
|
28
|
+
image: z.string().min(1).max(300).optional(),
|
|
29
|
+
focus: z.object({ x: z.number().min(0).max(100), y: z.number().min(0).max(100) }).strict().optional(),
|
|
30
|
+
author: z.string().max(120).optional(),
|
|
31
|
+
text_style: textStyleSchema.optional(),
|
|
32
|
+
text_position: z.number().min(0).max(100).optional(),
|
|
33
|
+
})
|
|
34
|
+
.strict();
|
|
35
|
+
export const hashtagSchema = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^#?[\p{L}\p{N}_]{1,100}$/u, "a hashtag is letters, digits or _ (no spaces)")
|
|
38
|
+
.transform((h) => h.replace(/^#/, ""));
|
|
39
|
+
export const tiktokOptionsSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
privacy: z.enum(["public", "friends", "followers", "only_me"]).optional(),
|
|
42
|
+
disclosure: z.enum(["none", "own_brand", "paid_partnership"]).optional(),
|
|
43
|
+
inbox_draft: z.boolean().optional(),
|
|
44
|
+
auto_music: z.boolean().optional(),
|
|
45
|
+
comments: z.boolean().optional(),
|
|
46
|
+
cover_index: z.number().int().min(0).max(34).optional(),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
export const publishRecordSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
provider: z.enum(["export", "appeeky", "postiz", "spec-draft"]),
|
|
52
|
+
at: z.string(),
|
|
53
|
+
render_hash: z.string(),
|
|
54
|
+
post_id: z.string().optional(),
|
|
55
|
+
draft_file: z.string().optional(),
|
|
56
|
+
scheduled_for: z.string().optional(),
|
|
57
|
+
/** Uploads done so far, by render file name, so a retry after a failure goes on where it stopped. */
|
|
58
|
+
media: z.record(z.string()).optional(),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
export const deckSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
version: z.literal(1).default(1),
|
|
64
|
+
id: idSchema,
|
|
65
|
+
channel: idSchema.optional(),
|
|
66
|
+
language: z.string().regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})?$/, "use a language code like en or pt-BR").default("en"),
|
|
67
|
+
size: sizeSchema.default("4:5"),
|
|
68
|
+
theme: z.string().min(1).max(64).default("tiktok-classic"),
|
|
69
|
+
/** Brand colours instead of the theme's own. */
|
|
70
|
+
colors: colorsSchema.optional(),
|
|
71
|
+
full_cover: z.boolean().default(true),
|
|
72
|
+
text_style: textStyleSchema.optional(),
|
|
73
|
+
show_handle: z.boolean().default(false),
|
|
74
|
+
slides: z.array(slideSchema).min(1).max(35),
|
|
75
|
+
caption: z.string().max(4000).default(""),
|
|
76
|
+
hashtags: z.array(hashtagSchema).max(30).default([]),
|
|
77
|
+
accounts: z.array(z.string().min(1)).default([]),
|
|
78
|
+
when: z.string().optional(),
|
|
79
|
+
tiktok: tiktokOptionsSchema.optional(),
|
|
80
|
+
topic: z.string().max(200).optional(),
|
|
81
|
+
/** The shape the deck follows (templates_list), checked by lint. */
|
|
82
|
+
template: idSchema.optional(),
|
|
83
|
+
status: z.enum(["draft", "rendered", "published"]).default("draft"),
|
|
84
|
+
published: z.array(publishRecordSchema).default([]),
|
|
85
|
+
})
|
|
86
|
+
.strict();
|
|
87
|
+
const timeOfDay = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "use 24-hour HH:MM");
|
|
88
|
+
export const DAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
89
|
+
export const scheduleSchema = z
|
|
90
|
+
.object({
|
|
91
|
+
mode: z.enum(["window", "fixed"]).default("window"),
|
|
92
|
+
days: z.array(z.enum(DAYS)).default([...DAYS]),
|
|
93
|
+
per_day: z.number().int().min(1).max(12).default(1),
|
|
94
|
+
window: z.object({ start: timeOfDay, end: timeOfDay }).strict().default({ start: "17:00", end: "21:00" }),
|
|
95
|
+
times: z.array(timeOfDay).default([]),
|
|
96
|
+
timezone: z.string().default("UTC"),
|
|
97
|
+
prepare: z
|
|
98
|
+
.union([z.literal("day_before"), z.literal("at_post_time"), z.object({ hours_before: z.number().min(0).max(168) }).strict()])
|
|
99
|
+
.default("day_before"),
|
|
100
|
+
min_gap: z.number().int().min(0).max(24 * 60).default(45),
|
|
101
|
+
})
|
|
102
|
+
.strict();
|
|
103
|
+
export const channelSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
version: z.literal(1).default(1),
|
|
106
|
+
id: idSchema,
|
|
107
|
+
name: z.string().min(1).max(120),
|
|
108
|
+
enabled: z.boolean().default(false),
|
|
109
|
+
accounts: z.array(z.string().min(1)).default([]),
|
|
110
|
+
schedule: scheduleSchema.default({}),
|
|
111
|
+
content: z
|
|
112
|
+
.object({
|
|
113
|
+
audience: z.array(z.string().min(1).max(80)).default([]),
|
|
114
|
+
language: z.string().default("en"),
|
|
115
|
+
slide_count: z.number().int().min(2).max(20).default(6),
|
|
116
|
+
full_cover: z.boolean().default(true),
|
|
117
|
+
bridge: z.boolean().default(false),
|
|
118
|
+
brand: z.boolean().default(true),
|
|
119
|
+
topics: z.array(z.string().min(1).max(200)).default([]),
|
|
120
|
+
/** Templates to rotate through for this channel's posts; empty means any. */
|
|
121
|
+
templates: z.array(z.string().min(1).max(64)).default([]),
|
|
122
|
+
never: z.array(z.string().min(1).max(200)).default([]),
|
|
123
|
+
notes: z.string().max(2000).default(""),
|
|
124
|
+
})
|
|
125
|
+
.strict()
|
|
126
|
+
.default({}),
|
|
127
|
+
design: z
|
|
128
|
+
.object({ size: sizeSchema.default("4:5"), theme: z.string().default("tiktok-classic"), colors: colorsSchema.optional() })
|
|
129
|
+
.strict()
|
|
130
|
+
.default({}),
|
|
131
|
+
hashtags: z.array(hashtagSchema).max(30).default([]),
|
|
132
|
+
tiktok: tiktokOptionsSchema.optional(),
|
|
133
|
+
})
|
|
134
|
+
.strict();
|
|
135
|
+
export const brandSchema = z
|
|
136
|
+
.object({
|
|
137
|
+
name: z.string().min(1).max(120).optional(),
|
|
138
|
+
handle: z.string().max(60).optional(),
|
|
139
|
+
one_liner: z.string().max(300).optional(),
|
|
140
|
+
audience: z.string().max(600).optional(),
|
|
141
|
+
tone: z.array(z.string().min(1).max(60)).max(10).default([]),
|
|
142
|
+
voice_examples: z.array(z.string().min(1).max(300)).max(10).default([]),
|
|
143
|
+
words_to_use: z.array(z.string().min(1).max(60)).max(40).default([]),
|
|
144
|
+
words_to_avoid: z.array(z.string().min(1).max(60)).max(40).default([]),
|
|
145
|
+
claims_allowed: z.array(z.string().min(1).max(200)).max(20).default([]),
|
|
146
|
+
claims_never: z.array(z.string().min(1).max(200)).max(20).default([]),
|
|
147
|
+
cta: z.string().max(200).optional(),
|
|
148
|
+
colors: colorsSchema.optional(),
|
|
149
|
+
icon: z.string().max(300).optional(),
|
|
150
|
+
notes: z.string().max(4000).optional(),
|
|
151
|
+
})
|
|
152
|
+
.strict();
|
|
153
|
+
export const settingsSchema = z
|
|
154
|
+
.object({
|
|
155
|
+
version: z.literal(1).default(1),
|
|
156
|
+
app: z
|
|
157
|
+
.object({
|
|
158
|
+
name: z.string().min(1).max(120).optional(),
|
|
159
|
+
app_store_id: z.string().regex(/^\d{5,12}$/, "the numeric App Store id").optional(),
|
|
160
|
+
play_package: z.string().regex(/^[a-zA-Z][\w]*(\.[a-zA-Z][\w]*)+$/, "a package name like com.example.app").optional(),
|
|
161
|
+
country: z.string().regex(/^[a-z]{2}$/).default("us"),
|
|
162
|
+
})
|
|
163
|
+
.strict()
|
|
164
|
+
.default({}),
|
|
165
|
+
brand: brandSchema.default({}),
|
|
166
|
+
defaults: z
|
|
167
|
+
.object({ size: sizeSchema.default("4:5"), theme: z.string().default("tiktok-classic"), language: z.string().default("en") })
|
|
168
|
+
.strict()
|
|
169
|
+
.default({}),
|
|
170
|
+
banned_phrases: z.object({ add: z.array(z.string()).default([]), remove: z.array(z.string()).default([]) }).strict().default({}),
|
|
171
|
+
/** Turn the built-in banned-phrase warning into an error. */
|
|
172
|
+
strict_phrases: z.boolean().default(false),
|
|
173
|
+
})
|
|
174
|
+
.strict();
|
package/dist/shape.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FontRole } from "./themes.js";
|
|
2
|
+
/** Text that needs shaping: Arabic, Hebrew, Thai or Devanagari. */
|
|
3
|
+
export declare const COMPLEX: RegExp;
|
|
4
|
+
export declare function initShaper(): Promise<void>;
|
|
5
|
+
export declare const shaperReady: () => boolean;
|
|
6
|
+
/** WOFF 1.0 → plain OpenType: HarfBuzz reads only uncompressed fonts. */
|
|
7
|
+
export declare function woffToSfnt(w: Buffer): Buffer;
|
|
8
|
+
export interface ShapedGlyph {
|
|
9
|
+
/** SVG path in font units; draw with translate(x, baseline) scale(scale, -scale). */
|
|
10
|
+
d: string;
|
|
11
|
+
x: number;
|
|
12
|
+
dy: number;
|
|
13
|
+
scale: number;
|
|
14
|
+
accent: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ShapedLine {
|
|
17
|
+
glyphs: ShapedGlyph[];
|
|
18
|
+
width: number;
|
|
19
|
+
rtl: boolean;
|
|
20
|
+
/** Visual x ranges of the accent words, for highlight boxes and underlines. */
|
|
21
|
+
accentSpans: {
|
|
22
|
+
x0: number;
|
|
23
|
+
x1: number;
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
/** Shapes one line of runs (accent or not), in visual order. */
|
|
27
|
+
export declare function shapeLine(role: FontRole, runs: {
|
|
28
|
+
text: string;
|
|
29
|
+
accent: boolean;
|
|
30
|
+
}[], size: number, locale?: string): ShapedLine;
|
|
31
|
+
export declare function shapedWidth(role: FontRole, text: string, size: number, locale?: string): number;
|
package/dist/shape.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lines in Arabic, Hebrew, Thai and Devanagari are shaped with HarfBuzz and drawn as SVG paths.
|
|
3
|
+
* The slide renderer cannot join Arabic letters, place their marks, or order
|
|
4
|
+
* right-to-left words, so those lines never go through it as text.
|
|
5
|
+
*/
|
|
6
|
+
import { inflateSync } from "node:zlib";
|
|
7
|
+
import bidiFactory from "bidi-js";
|
|
8
|
+
import { pickFont, fontBytes, isEmoji } from "./fonts.js";
|
|
9
|
+
let hb = null;
|
|
10
|
+
const bidi = bidiFactory();
|
|
11
|
+
/** Text that needs shaping: Arabic, Hebrew, Thai or Devanagari. */
|
|
12
|
+
export const COMPLEX = /[\p{Script=Arabic}\p{Script=Hebrew}\p{Script=Thai}\p{Script=Devanagari}]/u;
|
|
13
|
+
export async function initShaper() {
|
|
14
|
+
hb ??= await import("harfbuzzjs");
|
|
15
|
+
}
|
|
16
|
+
export const shaperReady = () => hb !== null;
|
|
17
|
+
/** WOFF 1.0 → plain OpenType: HarfBuzz reads only uncompressed fonts. */
|
|
18
|
+
export function woffToSfnt(w) {
|
|
19
|
+
if (w.toString("latin1", 0, 4) !== "wOFF")
|
|
20
|
+
return w;
|
|
21
|
+
const flavor = w.readUInt32BE(4);
|
|
22
|
+
const n = w.readUInt16BE(12);
|
|
23
|
+
const head = Buffer.alloc(12 + 16 * n);
|
|
24
|
+
head.writeUInt32BE(flavor, 0);
|
|
25
|
+
head.writeUInt16BE(n, 4);
|
|
26
|
+
let es = 0;
|
|
27
|
+
while (1 << (es + 1) <= n)
|
|
28
|
+
es++;
|
|
29
|
+
head.writeUInt16BE((1 << es) * 16, 6);
|
|
30
|
+
head.writeUInt16BE(es, 8);
|
|
31
|
+
head.writeUInt16BE(n * 16 - (1 << es) * 16, 10);
|
|
32
|
+
const bodies = [];
|
|
33
|
+
let offset = head.length;
|
|
34
|
+
for (let i = 0; i < n; i++) {
|
|
35
|
+
const p = 44 + i * 20;
|
|
36
|
+
const tag = w.readUInt32BE(p);
|
|
37
|
+
const off = w.readUInt32BE(p + 4);
|
|
38
|
+
const comp = w.readUInt32BE(p + 8);
|
|
39
|
+
const orig = w.readUInt32BE(p + 12);
|
|
40
|
+
const sum = w.readUInt32BE(p + 16);
|
|
41
|
+
const raw = w.subarray(off, off + comp);
|
|
42
|
+
const data = comp < orig ? inflateSync(raw) : raw;
|
|
43
|
+
const q = 12 + i * 16;
|
|
44
|
+
head.writeUInt32BE(tag, q);
|
|
45
|
+
head.writeUInt32BE(sum, q + 4);
|
|
46
|
+
head.writeUInt32BE(offset, q + 8);
|
|
47
|
+
head.writeUInt32BE(orig, q + 12);
|
|
48
|
+
const pad = (4 - (data.length % 4)) % 4;
|
|
49
|
+
bodies.push(data, Buffer.alloc(pad));
|
|
50
|
+
offset += data.length + pad;
|
|
51
|
+
}
|
|
52
|
+
return Buffer.concat([head, ...bodies]);
|
|
53
|
+
}
|
|
54
|
+
const hbFonts = new Map();
|
|
55
|
+
function hbFont(f) {
|
|
56
|
+
const bytes = fontBytes(f);
|
|
57
|
+
if (!bytes || !hb)
|
|
58
|
+
return null;
|
|
59
|
+
let h = hbFonts.get(bytes.key);
|
|
60
|
+
if (!h) {
|
|
61
|
+
const face = new hb.Face(new hb.Blob(woffToSfnt(bytes.data)));
|
|
62
|
+
h = { font: new hb.Font(face), upem: face.upem };
|
|
63
|
+
hbFonts.set(bytes.key, h);
|
|
64
|
+
}
|
|
65
|
+
return h;
|
|
66
|
+
}
|
|
67
|
+
const paths = new Map();
|
|
68
|
+
function glyphPath(key, h, gid) {
|
|
69
|
+
const k = `${key}|${gid}`;
|
|
70
|
+
let d = paths.get(k);
|
|
71
|
+
if (d === undefined) {
|
|
72
|
+
d = h.font.glyphToPath(gid);
|
|
73
|
+
paths.set(k, d);
|
|
74
|
+
}
|
|
75
|
+
return d;
|
|
76
|
+
}
|
|
77
|
+
const inherits = (ch) => /[\p{M}\p{Cf}\s]/u.test(ch);
|
|
78
|
+
/** Shapes one line of runs (accent or not), in visual order. */
|
|
79
|
+
export function shapeLine(role, runs, size, locale) {
|
|
80
|
+
const text = runs.map((r) => r.text).join("");
|
|
81
|
+
const accentAt = [];
|
|
82
|
+
for (const r of runs)
|
|
83
|
+
for (let i = 0; i < r.text.length; i++)
|
|
84
|
+
accentAt.push(r.accent);
|
|
85
|
+
const { levels, paragraphs } = bidi.getEmbeddingLevels(text);
|
|
86
|
+
const baseLevel = paragraphs[0]?.level ?? 0;
|
|
87
|
+
// Split into segments of one bidi level, one accent state and one font.
|
|
88
|
+
const segs = [];
|
|
89
|
+
for (let i = 0; i < text.length;) {
|
|
90
|
+
const cp = text.codePointAt(i);
|
|
91
|
+
const ch = String.fromCodePoint(cp);
|
|
92
|
+
const len = ch.length;
|
|
93
|
+
const prev = segs[segs.length - 1];
|
|
94
|
+
const level = levels[i];
|
|
95
|
+
const accent = accentAt[i];
|
|
96
|
+
let font;
|
|
97
|
+
if (isEmoji(ch))
|
|
98
|
+
font = null;
|
|
99
|
+
else if (prev && prev.font && inherits(ch) && prev.font.charToGlyphIndex(ch) > 0)
|
|
100
|
+
font = prev.font;
|
|
101
|
+
else
|
|
102
|
+
font = pickFont(role, ch, locale);
|
|
103
|
+
if (prev && prev.level === level && prev.accent === accent && prev.font === font)
|
|
104
|
+
prev.end = i + len;
|
|
105
|
+
else
|
|
106
|
+
segs.push({ start: i, end: i + len, level, accent, font });
|
|
107
|
+
i += len;
|
|
108
|
+
}
|
|
109
|
+
// Unicode rule L2: from the highest level down to the lowest odd one, reverse runs at that level or above.
|
|
110
|
+
const order = segs.map((_, i) => i);
|
|
111
|
+
const max = Math.max(baseLevel, ...segs.map((s) => s.level));
|
|
112
|
+
const minOdd = Math.min(...segs.map((s) => s.level).filter((l) => l % 2 === 1), max + 1);
|
|
113
|
+
for (let lvl = max; lvl >= minOdd && lvl > 0; lvl--) {
|
|
114
|
+
for (let i = 0; i < order.length;) {
|
|
115
|
+
if (segs[order[i]].level >= lvl) {
|
|
116
|
+
let j = i;
|
|
117
|
+
while (j + 1 < order.length && segs[order[j + 1]].level >= lvl)
|
|
118
|
+
j++;
|
|
119
|
+
order.splice(i, j - i + 1, ...order.slice(i, j + 1).reverse());
|
|
120
|
+
i = j + 1;
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const glyphs = [];
|
|
127
|
+
const accentSpans = [];
|
|
128
|
+
let x = 0;
|
|
129
|
+
for (const idx of order) {
|
|
130
|
+
const seg = segs[idx];
|
|
131
|
+
const x0 = x;
|
|
132
|
+
const chunk = text.slice(seg.start, seg.end);
|
|
133
|
+
const h = seg.font && hb ? hbFont(seg.font) : null;
|
|
134
|
+
if (!h || !hb) {
|
|
135
|
+
// Emoji, or a letter no font has: keep its room so the line keeps its width.
|
|
136
|
+
for (const ch of chunk)
|
|
137
|
+
if (!inherits(ch))
|
|
138
|
+
x += size * (isEmoji(ch) ? 1.15 : 0.6);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const key = fontBytes(seg.font).key;
|
|
142
|
+
const buf = new hb.Buffer();
|
|
143
|
+
buf.addText(chunk);
|
|
144
|
+
buf.guessSegmentProperties();
|
|
145
|
+
buf.setDirection(seg.level % 2 ? hb.Direction.RTL : hb.Direction.LTR);
|
|
146
|
+
if (locale)
|
|
147
|
+
buf.setLanguage(locale);
|
|
148
|
+
hb.shape(h.font, buf);
|
|
149
|
+
const k = size / h.upem;
|
|
150
|
+
for (const g of buf.getGlyphInfosAndPositions()) {
|
|
151
|
+
const d = glyphPath(key, h, g.codepoint);
|
|
152
|
+
if (d)
|
|
153
|
+
glyphs.push({ d, x: x + (g.xOffset ?? 0) * k, dy: -(g.yOffset ?? 0) * k, scale: k, accent: seg.accent });
|
|
154
|
+
x += (g.xAdvance ?? 0) * k;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (seg.accent) {
|
|
158
|
+
const last = accentSpans[accentSpans.length - 1];
|
|
159
|
+
if (last && Math.abs(last.x1 - x0) < 0.5)
|
|
160
|
+
last.x1 = x;
|
|
161
|
+
else
|
|
162
|
+
accentSpans.push({ x0, x1: x });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { glyphs, width: x, rtl: baseLevel % 2 === 1, accentSpans };
|
|
166
|
+
}
|
|
167
|
+
export function shapedWidth(role, text, size, locale) {
|
|
168
|
+
return shapeLine(role, [{ text, accent: false }], size, locale).width;
|
|
169
|
+
}
|
package/dist/skill.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** skills/open-slideshow in the package: next to src/ when developing, next to dist/ when installed. */
|
|
2
|
+
export declare const SKILL_DIR: string;
|
|
3
|
+
/** The instructions every agent gets: Claude Code as a skill, Codex in AGENTS.md, Cursor as a rule. */
|
|
4
|
+
export declare const SKILL: string;
|
|
5
|
+
/** The detailed guides in skills/open-slideshow/references, by topic (file name without .md). */
|
|
6
|
+
export declare function guideTopics(): string[];
|
|
7
|
+
export declare function guideText(topic: string): string | null;
|
package/dist/skill.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/** skills/open-slideshow in the package: next to src/ when developing, next to dist/ when installed. */
|
|
5
|
+
export const SKILL_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "skills", "open-slideshow");
|
|
6
|
+
/** The instructions every agent gets: Claude Code as a skill, Codex in AGENTS.md, Cursor as a rule. */
|
|
7
|
+
export const SKILL = readFileSync(join(SKILL_DIR, "SKILL.md"), "utf8");
|
|
8
|
+
/** The detailed guides in skills/open-slideshow/references, by topic (file name without .md). */
|
|
9
|
+
export function guideTopics() {
|
|
10
|
+
const dir = join(SKILL_DIR, "references");
|
|
11
|
+
return existsSync(dir) ? readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => f.slice(0, -3)).sort() : [];
|
|
12
|
+
}
|
|
13
|
+
export function guideText(topic) {
|
|
14
|
+
if (!guideTopics().includes(topic))
|
|
15
|
+
return null;
|
|
16
|
+
return readFileSync(join(SKILL_DIR, "references", `${topic}.md`), "utf8");
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Slide } from "./schema.js";
|
|
2
|
+
type Kind = Slide["kind"];
|
|
3
|
+
/** One step of a template: which slide kinds fit, and how many of them. */
|
|
4
|
+
export interface TemplateSlot {
|
|
5
|
+
kinds: Kind[];
|
|
6
|
+
label: string;
|
|
7
|
+
/** What to write here. */
|
|
8
|
+
hint: string;
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Template {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
/** When this shape works best. */
|
|
17
|
+
when: string;
|
|
18
|
+
slots: TemplateSlot[];
|
|
19
|
+
/** A filled-in example, for the preview and for the agent to see the shape. */
|
|
20
|
+
example: (app: string) => Slide[];
|
|
21
|
+
}
|
|
22
|
+
export declare const TEMPLATES: Template[];
|
|
23
|
+
export declare function getTemplate(id: string): Template | undefined;
|
|
24
|
+
/** The shape in one line, e.g. "cover (hook) → tip ×3–7 → bridge? → app?". */
|
|
25
|
+
export declare function shapeText(t: Template): string;
|
|
26
|
+
/** Which slot each slide fills when the kinds follow the template in order; null when they do not. */
|
|
27
|
+
export declare function assignSlots(t: Template, kinds: Kind[]): number[] | null;
|
|
28
|
+
/** Whether a deck's slide kinds follow the template, in order. */
|
|
29
|
+
export declare function followsTemplate(t: Template, kinds: Kind[]): boolean;
|
|
30
|
+
/** What the agent gets from templates_list. */
|
|
31
|
+
export declare function templateGuide(t: Template): {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
when: string;
|
|
36
|
+
shape: string;
|
|
37
|
+
slots: {
|
|
38
|
+
kinds: ("cover" | "tip" | "list" | "quote" | "bridge" | "app" | "text")[];
|
|
39
|
+
label: string;
|
|
40
|
+
count: string | number;
|
|
41
|
+
hint: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const cover = (hint) => ({ kinds: ["cover"], label: "hook", hint, min: 1, max: 1 });
|
|
2
|
+
const appEnd = [
|
|
3
|
+
{ kinds: ["bridge"], label: "bridge", hint: "One line that turns to the app, only if it follows from the slides before.", min: 0, max: 1 },
|
|
4
|
+
{ kinds: ["app"], label: "app", hint: "The app's name and what it does for this; a short call to action in the body.", min: 0, max: 1 },
|
|
5
|
+
];
|
|
6
|
+
export const TEMPLATES = [
|
|
7
|
+
{
|
|
8
|
+
id: "tips",
|
|
9
|
+
name: "Tips",
|
|
10
|
+
description: "A hook that promises a number of tips, one tip per slide, then the app.",
|
|
11
|
+
when: "Teaching something useful. The easiest shape to save and share.",
|
|
12
|
+
slots: [cover("Promise a number and a result: '5 small habits that fixed my *sleep*'."), { kinds: ["tip"], label: "tips", hint: "One tip each: the tip as the title, why or how in the body.", min: 3, max: 7 }, ...appEnd],
|
|
13
|
+
example: (app) => [
|
|
14
|
+
{ kind: "cover", title: "3 tiny habits that fixed my *sleep*" },
|
|
15
|
+
{ kind: "tip", title: "Same wake-up time, *every* day", body: "Even on weekends. Your body clock loves boring." },
|
|
16
|
+
{ kind: "tip", title: "No screens *30 minutes* before bed", body: "Put the phone in another room. Really." },
|
|
17
|
+
{ kind: "tip", title: "Write tomorrow's list *before* bed", body: "Your brain stops rehearsing it at 2am." },
|
|
18
|
+
{ kind: "bridge", title: "I keep all of it in *one place*" },
|
|
19
|
+
{ kind: "app", title: `*${app}* reminds me every night`, body: "Free on the App Store." },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "mistakes",
|
|
24
|
+
name: "Mistakes",
|
|
25
|
+
description: "Things people get wrong, each with the fix, then the app.",
|
|
26
|
+
when: "Your audience already tries to do the thing and it does not work for them. Strong hooks, lots of comments.",
|
|
27
|
+
slots: [
|
|
28
|
+
cover("Call out the mistakes: '4 sleep mistakes you make *every night*'."),
|
|
29
|
+
{ kinds: ["tip"], label: "mistakes", hint: "The mistake as the title, the fix in the body.", min: 3, max: 5 },
|
|
30
|
+
...appEnd,
|
|
31
|
+
],
|
|
32
|
+
example: (app) => [
|
|
33
|
+
{ kind: "cover", title: "3 sleep mistakes you make *every night*" },
|
|
34
|
+
{ kind: "tip", title: "Scrolling *in bed*", body: "Your brain reads it as daytime. Leave the phone outside the room." },
|
|
35
|
+
{ kind: "tip", title: "Sleeping in on *weekends*", body: "It is jet lag you give yourself every Monday." },
|
|
36
|
+
{ kind: "tip", title: "Coffee *after 2pm*", body: "Half of it is still in you at midnight." },
|
|
37
|
+
{ kind: "bridge", title: "Fixing them is easier with a *nudge*" },
|
|
38
|
+
{ kind: "app", title: `That's what *${app}* is for`, body: "Free on the App Store." },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "story",
|
|
43
|
+
name: "Story",
|
|
44
|
+
description: "A personal story: the problem, what did not work, what did, then the app.",
|
|
45
|
+
when: "Founder or user stories. Feels like a person, not an ad. Works best with real photos.",
|
|
46
|
+
slots: [
|
|
47
|
+
cover("A personal, specific opening: 'I slept 5 hours a night for *two years*'."),
|
|
48
|
+
{ kinds: ["text", "quote"], label: "problem", hint: "What it was like. Concrete details, first person.", min: 1, max: 2 },
|
|
49
|
+
{ kinds: ["list", "text"], label: "what I tried", hint: "What did not work; a list is fine.", min: 1, max: 2 },
|
|
50
|
+
{ kinds: ["text", "tip"], label: "what worked", hint: "The turn: what finally worked and why.", min: 1, max: 2 },
|
|
51
|
+
...appEnd,
|
|
52
|
+
],
|
|
53
|
+
example: (app) => [
|
|
54
|
+
{ kind: "cover", title: "I slept 5 hours a night for *two years*" },
|
|
55
|
+
{ kind: "text", body: "Every morning felt like *jet lag*. Three alarms, two coffees, no focus by noon." },
|
|
56
|
+
{ kind: "list", title: "What I tried first", items: ["Melatonin", "Blackout curtains", "Going to bed at 9 (lol)"] },
|
|
57
|
+
{ kind: "text", body: "What worked was *boring*: same bedtime, phone out of the room, every single night." },
|
|
58
|
+
{ kind: "app", title: `I tracked it with *${app}*`, body: "Free on the App Store." },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "before-after",
|
|
63
|
+
name: "Before / after",
|
|
64
|
+
description: "How it was, how it is now, and what changed in between.",
|
|
65
|
+
when: "A clear change you can show: a routine, a result, a screen. Good with two contrasting photos.",
|
|
66
|
+
slots: [
|
|
67
|
+
cover("The change in one line: 'My nights, *before and after* 30 days'."),
|
|
68
|
+
{ kinds: ["text", "tip"], label: "before", hint: "Start with *Before:* and the honest picture.", min: 1, max: 1 },
|
|
69
|
+
{ kinds: ["text", "tip"], label: "after", hint: "Start with *After:* and the same details, changed.", min: 1, max: 1 },
|
|
70
|
+
{ kinds: ["list"], label: "what changed", hint: "The 3–5 things that made the difference.", min: 1, max: 1 },
|
|
71
|
+
...appEnd,
|
|
72
|
+
],
|
|
73
|
+
example: (app) => [
|
|
74
|
+
{ kind: "cover", title: "My nights, *before and after* 30 days" },
|
|
75
|
+
{ kind: "text", body: "*Before:* in bed at 1am, awake at 3, asleep again at 5." },
|
|
76
|
+
{ kind: "text", body: "*After:* in bed at 11, asleep by 11:20, up at 7 without an alarm." },
|
|
77
|
+
{ kind: "list", title: "What changed", items: ["Same bedtime, every night", "Phone charging in the kitchen", "No coffee after 2pm"] },
|
|
78
|
+
{ kind: "app", title: `*${app}* kept me on track`, body: "Free on the App Store." },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "ranking",
|
|
83
|
+
name: "Ranking",
|
|
84
|
+
description: "Options ranked, counting down to the best one.",
|
|
85
|
+
when: "Comparisons and opinions. People comment to argue with the order, which helps reach.",
|
|
86
|
+
slots: [
|
|
87
|
+
cover("What is ranked and in which direction: 'Bedtime habits, ranked from *worst to best*'."),
|
|
88
|
+
{ kinds: ["tip"], label: "ranked items", hint: "One item each, counting down with `number` (5, 4, 3…); one line why.", min: 3, max: 10 },
|
|
89
|
+
...appEnd,
|
|
90
|
+
],
|
|
91
|
+
example: (app) => [
|
|
92
|
+
{ kind: "cover", title: "Bedtime habits, ranked from *worst to best*" },
|
|
93
|
+
{ kind: "tip", number: 4, title: "Scrolling until you *pass out*", body: "The fastest way to wake up tired." },
|
|
94
|
+
{ kind: "tip", number: 3, title: "*One more* episode", body: "It is never one." },
|
|
95
|
+
{ kind: "tip", number: 2, title: "Reading a *paper* book", body: "Ten pages and you are gone." },
|
|
96
|
+
{ kind: "tip", number: 1, title: "Same time, *every night*", body: "Boring wins. Nothing beats it." },
|
|
97
|
+
{ kind: "app", title: `*${app}* makes #1 easy`, body: "Free on the App Store." },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "quotes",
|
|
102
|
+
name: "Quotes",
|
|
103
|
+
description: "Lines worth saving, one per slide, then the app.",
|
|
104
|
+
when: "Motivation and mindset content. Only real quotes: the user's own words, or a person who really said it.",
|
|
105
|
+
slots: [
|
|
106
|
+
cover("Why these lines matter: 'Things my sleep coach said that *stuck*'."),
|
|
107
|
+
{ kinds: ["quote"], label: "quotes", hint: "The quote as the title, who said it as author. Never invent a quote or put words in a real person's mouth.", min: 3, max: 6 },
|
|
108
|
+
...appEnd,
|
|
109
|
+
],
|
|
110
|
+
example: (app) => [
|
|
111
|
+
{ kind: "cover", title: "Things my sleep coach said that *stuck*" },
|
|
112
|
+
{ kind: "quote", title: "Your bed is for sleep. *Not* for worrying.", author: "my sleep coach" },
|
|
113
|
+
{ kind: "quote", title: "You can't catch up on sleep *on Sunday*.", author: "my sleep coach" },
|
|
114
|
+
{ kind: "quote", title: "Tired is a *schedule* problem first.", author: "my sleep coach" },
|
|
115
|
+
{ kind: "app", title: `Now I follow it with *${app}*`, body: "Free on the App Store." },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "checklist",
|
|
120
|
+
name: "Checklist",
|
|
121
|
+
description: "A short checklist people save and come back to.",
|
|
122
|
+
when: "Routines and step-by-step things. High saves.",
|
|
123
|
+
slots: [
|
|
124
|
+
cover("Tell people to save it: 'Save this *bedtime checklist*'."),
|
|
125
|
+
{ kinds: ["list"], label: "checklists", hint: "One group per slide (e.g. '1 hour before', 'In bed'), 3–5 short items.", min: 1, max: 4 },
|
|
126
|
+
...appEnd,
|
|
127
|
+
],
|
|
128
|
+
example: (app) => [
|
|
129
|
+
{ kind: "cover", title: "Save this *bedtime checklist*" },
|
|
130
|
+
{ kind: "list", title: "1 hour before", items: ["Lights down", "Last coffee was before 2pm", "Tomorrow's list written"] },
|
|
131
|
+
{ kind: "list", title: "In bed", items: ["Phone in *another* room", "Same playlist", "Same time as yesterday"] },
|
|
132
|
+
{ kind: "app", title: `*${app}* ticks it off with me`, body: "Free on the App Store." },
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
export function getTemplate(id) {
|
|
137
|
+
return TEMPLATES.find((t) => t.id === id);
|
|
138
|
+
}
|
|
139
|
+
/** The shape in one line, e.g. "cover (hook) → tip ×3–7 → bridge? → app?". */
|
|
140
|
+
export function shapeText(t) {
|
|
141
|
+
return t.slots
|
|
142
|
+
.map((s) => {
|
|
143
|
+
const k = s.kinds.join("/");
|
|
144
|
+
const n = s.min === 1 && s.max === 1 ? "" : s.min === 0 && s.max === 1 ? "?" : ` ×${s.min}${s.max > s.min ? `–${s.max}` : ""}`;
|
|
145
|
+
return `${k}${n} (${s.label})`;
|
|
146
|
+
})
|
|
147
|
+
.join(" → ");
|
|
148
|
+
}
|
|
149
|
+
/** Which slot each slide fills when the kinds follow the template in order; null when they do not. */
|
|
150
|
+
export function assignSlots(t, kinds) {
|
|
151
|
+
const out = [];
|
|
152
|
+
const go = (slot, i) => {
|
|
153
|
+
if (slot === t.slots.length)
|
|
154
|
+
return i === kinds.length;
|
|
155
|
+
const s = t.slots[slot];
|
|
156
|
+
let n = 0;
|
|
157
|
+
while (n < s.max && i + n < kinds.length && s.kinds.includes(kinds[i + n]))
|
|
158
|
+
n++;
|
|
159
|
+
// Take fewer first, so a later slot that also fits gets its slides.
|
|
160
|
+
for (let m = s.min; m <= n; m++) {
|
|
161
|
+
out.length = i;
|
|
162
|
+
for (let j = 0; j < m; j++)
|
|
163
|
+
out.push(slot);
|
|
164
|
+
if (go(slot + 1, i + m))
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
};
|
|
169
|
+
return go(0, 0) ? out : null;
|
|
170
|
+
}
|
|
171
|
+
/** Whether a deck's slide kinds follow the template, in order. */
|
|
172
|
+
export function followsTemplate(t, kinds) {
|
|
173
|
+
return assignSlots(t, kinds) !== null;
|
|
174
|
+
}
|
|
175
|
+
/** What the agent gets from templates_list. */
|
|
176
|
+
export function templateGuide(t) {
|
|
177
|
+
return {
|
|
178
|
+
id: t.id,
|
|
179
|
+
name: t.name,
|
|
180
|
+
description: t.description,
|
|
181
|
+
when: t.when,
|
|
182
|
+
shape: shapeText(t),
|
|
183
|
+
slots: t.slots.map((s) => ({ kinds: s.kinds, label: s.label, count: s.min === s.max ? s.min : `${s.min}–${s.max}`, hint: s.hint })),
|
|
184
|
+
};
|
|
185
|
+
}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FontRole } from "./themes.js";
|
|
2
|
+
export interface Run {
|
|
3
|
+
text: string;
|
|
4
|
+
accent: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type Line = Run[];
|
|
7
|
+
/** `*word*` marks words for the accent; `\*` is a literal star. Throws on an unclosed star. */
|
|
8
|
+
export declare function parseMarkup(input: string): Run[];
|
|
9
|
+
export declare function plainText(input: string): string;
|
|
10
|
+
export declare function markupError(input: string | undefined): string | null;
|
|
11
|
+
export interface Wrapped {
|
|
12
|
+
lines: Line[];
|
|
13
|
+
/** True when a single word had to be cut to fit. */
|
|
14
|
+
broke_word: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function wrap(role: FontRole, markup: string, size: number, width: number, locale?: string): Wrapped;
|
|
17
|
+
export interface Fitted {
|
|
18
|
+
size: number;
|
|
19
|
+
lines: Line[];
|
|
20
|
+
height: number;
|
|
21
|
+
/** The text does not fit even at the smallest size. */
|
|
22
|
+
overflow: boolean;
|
|
23
|
+
broke_word: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface FitOptions {
|
|
26
|
+
max: number;
|
|
27
|
+
min: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
line_height: number;
|
|
31
|
+
max_lines?: number;
|
|
32
|
+
/** The deck's language, for upper-casing (Turkish i → İ). */
|
|
33
|
+
locale?: string;
|
|
34
|
+
}
|
|
35
|
+
/** The largest size at which the text fits the box without cutting a word. */
|
|
36
|
+
export declare function fit(role: FontRole, markup: string, o: FitOptions): Fitted;
|
|
37
|
+
/** Upper-cases in the deck's language; an unknown language code falls back to plain rules. */
|
|
38
|
+
export declare function upperCase(text: string, locale?: string): string;
|
|
39
|
+
/** Whether a line reads right to left (its first strong letter is Arabic or Hebrew). */
|
|
40
|
+
export declare function isRtl(text: string): boolean;
|