@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/schema.js ADDED
@@ -0,0 +1,211 @@
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
+ /** `screenshot` shows a screenshot of the app (its image) inside a phone, with an optional title above. */
20
+ export const slideKindSchema = z.enum(["cover", "tip", "list", "quote", "bridge", "app", "text", "screenshot"]);
21
+ export const slideSchema = z
22
+ .object({
23
+ kind: slideKindSchema,
24
+ title: z.string().max(400).optional(),
25
+ body: z.string().max(1200).optional(),
26
+ items: z.array(z.string().min(1).max(200)).max(8).optional(),
27
+ list_style: z.enum(["bullet", "check", "number"]).optional(),
28
+ number: z.number().int().min(0).max(99).optional(),
29
+ image: z.string().min(1).max(300).optional(),
30
+ focus: z.object({ x: z.number().min(0).max(100), y: z.number().min(0).max(100) }).strict().optional(),
31
+ author: z.string().max(120).optional(),
32
+ text_style: textStyleSchema.optional(),
33
+ text_position: z.number().min(0).max(100).optional(),
34
+ })
35
+ .strict();
36
+ export const hashtagSchema = z
37
+ .string()
38
+ .regex(/^#?[\p{L}\p{N}_]{1,100}$/u, "a hashtag is letters, digits or _ (no spaces)")
39
+ .transform((h) => h.replace(/^#/, ""));
40
+ export const tiktokOptionsSchema = z
41
+ .object({
42
+ privacy: z.enum(["public", "friends", "followers", "only_me"]).optional(),
43
+ disclosure: z.enum(["none", "own_brand", "paid_partnership"]).optional(),
44
+ inbox_draft: z.boolean().optional(),
45
+ auto_music: z.boolean().optional(),
46
+ comments: z.boolean().optional(),
47
+ cover_index: z.number().int().min(0).max(34).optional(),
48
+ })
49
+ .strict();
50
+ export const publishRecordSchema = z
51
+ .object({
52
+ provider: z.enum(["export", "appeeky", "postiz", "spec-draft"]),
53
+ at: z.string(),
54
+ render_hash: z.string(),
55
+ post_id: z.string().optional(),
56
+ draft_file: z.string().optional(),
57
+ scheduled_for: z.string().optional(),
58
+ /** Uploads done so far, by render file name, so a retry after a failure goes on where it stopped. */
59
+ media: z.record(z.string()).optional(),
60
+ })
61
+ .strict();
62
+ /** How a published post did, from Appeeky, a Spec repo or typed in by hand. */
63
+ export const resultSchema = z
64
+ .object({
65
+ at: z.string(),
66
+ source: z.enum(["appeeky", "spec", "manual"]),
67
+ platform: z.string().max(40).optional(),
68
+ views: z.number().int().min(0).optional(),
69
+ likes: z.number().int().min(0).optional(),
70
+ comments: z.number().int().min(0).optional(),
71
+ shares: z.number().int().min(0).optional(),
72
+ saves: z.number().int().min(0).optional(),
73
+ reach: z.number().int().min(0).optional(),
74
+ })
75
+ .strict();
76
+ export const seriesSchema = z
77
+ .object({
78
+ id: idSchema,
79
+ part: z.number().int().min(1).max(99),
80
+ of: z.number().int().min(1).max(99).optional(),
81
+ /** The label on the cover, e.g. "Bölüm {part}"; {part} and {of} are filled in. Default "Part {part}". */
82
+ label: z.string().min(1).max(40).optional(),
83
+ })
84
+ .strict();
85
+ export const deckSchema = z
86
+ .object({
87
+ version: z.literal(1).default(1),
88
+ id: idSchema,
89
+ channel: idSchema.optional(),
90
+ 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"),
91
+ size: sizeSchema.default("4:5"),
92
+ theme: z.string().min(1).max(64).default("tiktok-classic"),
93
+ /** Brand colours instead of the theme's own. */
94
+ colors: colorsSchema.optional(),
95
+ full_cover: z.boolean().default(true),
96
+ text_style: textStyleSchema.optional(),
97
+ show_handle: z.boolean().default(false),
98
+ slides: z.array(slideSchema).min(1).max(35),
99
+ caption: z.string().max(4000).default(""),
100
+ hashtags: z.array(hashtagSchema).max(30).default([]),
101
+ accounts: z.array(z.string().min(1)).default([]),
102
+ when: z.string().optional(),
103
+ tiktok: tiktokOptionsSchema.optional(),
104
+ topic: z.string().max(200).optional(),
105
+ /** The shape the deck follows (templates_list), checked by lint. */
106
+ template: idSchema.optional(),
107
+ status: z.enum(["draft", "rendered", "published"]).default("draft"),
108
+ published: z.array(publishRecordSchema).default([]),
109
+ /** How the post did, newest last (results_sync or results_record). */
110
+ results: z.array(resultSchema).default([]),
111
+ /** A hook test: decks with the same experiment differ only in the cover; variant is a, b, c… */
112
+ experiment: idSchema.optional(),
113
+ variant: z.string().regex(/^[a-e]$/, "a variant is one letter, a to e").optional(),
114
+ /** One part of a series of linked decks. */
115
+ series: seriesSchema.optional(),
116
+ /** The deck this one translates (deck_translate). */
117
+ translation_of: idSchema.optional(),
118
+ /** The deck this one posts again with a new hook (deck_repost). */
119
+ repost_of: idSchema.optional(),
120
+ /** The idea from the idea queue this deck was made from. */
121
+ idea: z.string().max(64).optional(),
122
+ })
123
+ .strict();
124
+ const timeOfDay = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "use 24-hour HH:MM");
125
+ export const DAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
126
+ export const scheduleSchema = z
127
+ .object({
128
+ mode: z.enum(["window", "fixed"]).default("window"),
129
+ days: z.array(z.enum(DAYS)).default([...DAYS]),
130
+ per_day: z.number().int().min(1).max(12).default(1),
131
+ window: z.object({ start: timeOfDay, end: timeOfDay }).strict().default({ start: "17:00", end: "21:00" }),
132
+ times: z.array(timeOfDay).default([]),
133
+ timezone: z.string().default("UTC"),
134
+ prepare: z
135
+ .union([z.literal("day_before"), z.literal("at_post_time"), z.object({ hours_before: z.number().min(0).max(168) }).strict()])
136
+ .default("day_before"),
137
+ min_gap: z.number().int().min(0).max(24 * 60).default(45),
138
+ })
139
+ .strict();
140
+ export const channelSchema = z
141
+ .object({
142
+ version: z.literal(1).default(1),
143
+ id: idSchema,
144
+ name: z.string().min(1).max(120),
145
+ enabled: z.boolean().default(false),
146
+ accounts: z.array(z.string().min(1)).default([]),
147
+ schedule: scheduleSchema.default({}),
148
+ content: z
149
+ .object({
150
+ audience: z.array(z.string().min(1).max(80)).default([]),
151
+ language: z.string().default("en"),
152
+ slide_count: z.number().int().min(2).max(20).default(6),
153
+ full_cover: z.boolean().default(true),
154
+ bridge: z.boolean().default(false),
155
+ brand: z.boolean().default(true),
156
+ topics: z.array(z.string().min(1).max(200)).default([]),
157
+ /** Templates to rotate through for this channel's posts; empty means any. */
158
+ templates: z.array(z.string().min(1).max(64)).default([]),
159
+ never: z.array(z.string().min(1).max(200)).default([]),
160
+ notes: z.string().max(2000).default(""),
161
+ })
162
+ .strict()
163
+ .default({}),
164
+ design: z
165
+ .object({ size: sizeSchema.default("4:5"), theme: z.string().default("tiktok-classic"), colors: colorsSchema.optional() })
166
+ .strict()
167
+ .default({}),
168
+ hashtags: z.array(hashtagSchema).max(30).default([]),
169
+ tiktok: tiktokOptionsSchema.optional(),
170
+ })
171
+ .strict();
172
+ export const brandSchema = z
173
+ .object({
174
+ name: z.string().min(1).max(120).optional(),
175
+ handle: z.string().max(60).optional(),
176
+ one_liner: z.string().max(300).optional(),
177
+ audience: z.string().max(600).optional(),
178
+ tone: z.array(z.string().min(1).max(60)).max(10).default([]),
179
+ voice_examples: z.array(z.string().min(1).max(300)).max(10).default([]),
180
+ words_to_use: z.array(z.string().min(1).max(60)).max(40).default([]),
181
+ words_to_avoid: z.array(z.string().min(1).max(60)).max(40).default([]),
182
+ claims_allowed: z.array(z.string().min(1).max(200)).max(20).default([]),
183
+ claims_never: z.array(z.string().min(1).max(200)).max(20).default([]),
184
+ cta: z.string().max(200).optional(),
185
+ colors: colorsSchema.optional(),
186
+ icon: z.string().max(300).optional(),
187
+ notes: z.string().max(4000).optional(),
188
+ })
189
+ .strict();
190
+ export const settingsSchema = z
191
+ .object({
192
+ version: z.literal(1).default(1),
193
+ app: z
194
+ .object({
195
+ name: z.string().min(1).max(120).optional(),
196
+ app_store_id: z.string().regex(/^\d{5,12}$/, "the numeric App Store id").optional(),
197
+ play_package: z.string().regex(/^[a-zA-Z][\w]*(\.[a-zA-Z][\w]*)+$/, "a package name like com.example.app").optional(),
198
+ country: z.string().regex(/^[a-z]{2}$/).default("us"),
199
+ })
200
+ .strict()
201
+ .default({}),
202
+ brand: brandSchema.default({}),
203
+ defaults: z
204
+ .object({ size: sizeSchema.default("4:5"), theme: z.string().default("tiktok-classic"), language: z.string().default("en") })
205
+ .strict()
206
+ .default({}),
207
+ banned_phrases: z.object({ add: z.array(z.string()).default([]), remove: z.array(z.string()).default([]) }).strict().default({}),
208
+ /** Turn the built-in banned-phrase warning into an error. */
209
+ strict_phrases: z.boolean().default(false),
210
+ })
211
+ .strict();
@@ -0,0 +1,18 @@
1
+ import { type ImageMeta } from "./images.js";
2
+ import { type Workspace } from "./workspace.js";
3
+ /** The app's screenshots in a Spec repo: appeeky/screenshots/<store>/<locale>/<device>/*.png|jpg. */
4
+ export declare function specScreenshotFiles(ws: Workspace, locale?: string): string[];
5
+ export declare const fullSize: (u: string) => string;
6
+ /** iPhone screenshots from the App Store listing (Apple's public lookup). */
7
+ export declare function appStoreScreenshotUrls(id: string, country?: string): Promise<string[]>;
8
+ /**
9
+ * The app's own screenshots, imported as images to put in a `screenshot` slide. In a Spec repo
10
+ * they come from the repo; otherwise from the App Store listing.
11
+ */
12
+ export declare function appScreenshots(ws: Workspace, opts?: {
13
+ limit?: number;
14
+ locale?: string;
15
+ }): Promise<{
16
+ source: string;
17
+ images: ImageMeta[];
18
+ }>;
@@ -0,0 +1,69 @@
1
+ import { existsSync, readdirSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { importImageFromFile, importImageFromUrl } from "./images.js";
4
+ import { UserError } from "./workspace.js";
5
+ /** Phone screenshot folders Spec writes, best first (the largest iPhone, then any phone). */
6
+ const SPEC_TYPES = ["APP_IPHONE_69", "APP_IPHONE_67", "APP_IPHONE_65", "APP_IPHONE_61", "APP_IPHONE_58", "APP_IPHONE_55", "phone"];
7
+ /** The app's screenshots in a Spec repo: appeeky/screenshots/<store>/<locale>/<device>/*.png|jpg. */
8
+ export function specScreenshotFiles(ws, locale) {
9
+ const root = ws.spec?.screenshots_dir;
10
+ if (!root || !existsSync(root))
11
+ return [];
12
+ const locales = [locale, ...(ws.spec?.locales ?? [])].filter((l) => !!l);
13
+ for (const store of ["app-store", "google-play"]) {
14
+ const sd = join(root, store);
15
+ if (!existsSync(sd))
16
+ continue;
17
+ const available = readdirSync(sd).filter((d) => statSync(join(sd, d)).isDirectory());
18
+ for (const loc of [...locales, ...available]) {
19
+ const ld = join(sd, loc);
20
+ if (!existsSync(ld))
21
+ continue;
22
+ const types = readdirSync(ld).filter((d) => statSync(join(ld, d)).isDirectory());
23
+ const type = SPEC_TYPES.find((t) => types.includes(t)) ?? types.find((t) => /iphone|phone/i.test(t));
24
+ if (!type)
25
+ continue;
26
+ const files = readdirSync(join(ld, type))
27
+ .filter((f) => /\.(png|jpe?g)$/i.test(f))
28
+ .sort()
29
+ .map((f) => join(ld, type, f));
30
+ if (files.length)
31
+ return files;
32
+ }
33
+ }
34
+ return [];
35
+ }
36
+ export const fullSize = (u) => u.replace(/\/\d+x\d+bb\.(jpg|png|webp)$/, "/1290x2796bb.$1");
37
+ /** iPhone screenshots from the App Store listing (Apple's public lookup). */
38
+ export async function appStoreScreenshotUrls(id, country = "us") {
39
+ const res = await fetch(`https://itunes.apple.com/lookup?id=${encodeURIComponent(id)}&country=${encodeURIComponent(country)}&entity=software`, { signal: AbortSignal.timeout(10_000) });
40
+ if (!res.ok)
41
+ throw new UserError(`App Store lookup: HTTP ${res.status}`);
42
+ const data = (await res.json());
43
+ // The lookup gives small thumbnails; the same path with a larger size returns the original (capped at its real size).
44
+ return (data.results?.[0]?.screenshotUrls ?? []).map(fullSize);
45
+ }
46
+ /**
47
+ * The app's own screenshots, imported as images to put in a `screenshot` slide. In a Spec repo
48
+ * they come from the repo; otherwise from the App Store listing.
49
+ */
50
+ export async function appScreenshots(ws, opts = {}) {
51
+ const limit = Math.min(Math.max(opts.limit ?? 6, 1), 10);
52
+ const local = specScreenshotFiles(ws, opts.locale).slice(0, limit);
53
+ if (local.length) {
54
+ const images = [];
55
+ for (const f of local)
56
+ images.push(await importImageFromFile(ws, f, { source: "spec", license: "own", note: `app screenshot ${f.split("/").slice(-3).join("/")}` }));
57
+ return { source: "appeeky/screenshots", images };
58
+ }
59
+ const id = ws.settings.app.app_store_id;
60
+ if (!id)
61
+ throw new UserError("no screenshots in this repo and no App Store id; import a screenshot with image_import (path), or set the App Store id with brand_set");
62
+ const urls = (await appStoreScreenshotUrls(id, ws.settings.app.country)).slice(0, limit);
63
+ if (!urls.length)
64
+ throw new UserError("the App Store listing has no iPhone screenshots; import one with image_import");
65
+ const images = [];
66
+ for (const u of urls)
67
+ images.push(await importImageFromUrl(ws, u, { source: "app-store", license: "own", note: "app screenshot" }));
68
+ return { source: "App Store", images };
69
+ }
@@ -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
+ }
@@ -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,47 @@
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
+ /** Hook patterns that fit this shape; fill them with the app's own topic, never copy them as they are. */
19
+ hooks: string[];
20
+ slots: TemplateSlot[];
21
+ /** A filled-in example, for the preview and for the agent to see the shape. */
22
+ example: (app: string) => Slide[];
23
+ }
24
+ export declare const TEMPLATES: Template[];
25
+ export declare function getTemplate(id: string): Template | undefined;
26
+ /** The shape in one line, e.g. "cover (hook) → tip ×3–7 → bridge? → app?". */
27
+ export declare function shapeText(t: Template): string;
28
+ /** Which slot each slide fills when the kinds follow the template in order; null when they do not. */
29
+ export declare function assignSlots(t: Template, kinds: Kind[]): number[] | null;
30
+ /** Whether a deck's slide kinds follow the template, in order. */
31
+ export declare function followsTemplate(t: Template, kinds: Kind[]): boolean;
32
+ /** What the agent gets from templates_list. */
33
+ export declare function templateGuide(t: Template): {
34
+ id: string;
35
+ name: string;
36
+ description: string;
37
+ when: string;
38
+ hooks: string[];
39
+ shape: string;
40
+ slots: {
41
+ kinds: ("cover" | "tip" | "list" | "quote" | "bridge" | "app" | "text" | "screenshot")[];
42
+ label: string;
43
+ count: string | number;
44
+ hint: string;
45
+ }[];
46
+ };
47
+ export {};