@penguinharness/use-bento-slides 0.2.18 → 0.2.19
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/README.md +37 -0
- package/README.zh.md +37 -0
- package/THIRD-PARTY-NOTICES.md +30 -0
- package/ifaces.json +63 -0
- package/package.json +19 -21
- package/skills/bento-slides/SKILL.md +89 -29
- package/skills/bento-slides/references/bento-agents.md +511 -0
- package/workbenches/slides/index.ts +677 -0
- package/workbenches/slides/package.json +43 -0
- package/workbenches/slides/ui/app.js +1101 -0
- package/workbenches/slides/ui/bridge.js +190 -0
- package/workbenches/slides/ui/conversation-view.js +206 -0
- package/workbenches/slides/ui/conversation.css +95 -0
- package/workbenches/slides/ui/conversation.js +115 -0
- package/workbenches/slides/ui/deck-files.css +279 -0
- package/workbenches/slides/ui/deck-files.js +189 -0
- package/workbenches/slides/ui/file-menu.js +72 -0
- package/workbenches/slides/ui/icon.svg +9 -0
- package/workbenches/slides/ui/index.html +252 -0
- package/workbenches/slides/ui/model-choice.js +298 -0
- package/workbenches/slides/ui/model-control.tsx +90 -0
- package/workbenches/slides/ui/powerpoint.js +196 -0
- package/workbenches/slides/ui/sample.bento.json +33 -0
- package/workbenches/slides/ui/strings.js +184 -0
- package/workbenches/slides/ui/style.css +505 -0
- package/workbenches/slides/ui/sync.js +268 -0
- package/workbenches/slides/ui/template-picker.js +128 -0
- package/workbenches/slides/ui/templates.js +256 -0
- package/workbenches/slides/ui/vendor/LICENSE-bento.txt +21 -0
- package/workbenches/slides/ui/vendor/LICENSE-jszip.txt +25 -0
- package/workbenches/slides/ui/vendor/LICENSE-pptxgen.txt +21 -0
- package/workbenches/slides/ui/vendor/bento-slides-1.2.13.runtime.txt +310 -0
- package/workbenches/slides/ui/vendor/pptxgen-4.0.1.bundle.js +96 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// How two writers share one deck: the person in the editor and the Agent editing the file.
|
|
2
|
+
//
|
|
3
|
+
// The deck file is the truth. The editor holds a copy and two baselines: the document as the
|
|
4
|
+
// editor showed it when it was last in step with the file (`shown`), and whatever the person has
|
|
5
|
+
// done since. When the file changes under the editor, the person's work is not compared with the
|
|
6
|
+
// new file as text: it is read as a list of edits (`diff(shown, mine)`), and those edits are
|
|
7
|
+
// replayed on the new file (`rebase`). An edit to something the other side did not touch simply
|
|
8
|
+
// applies; where both sides set the same property the person's value wins and the pair is
|
|
9
|
+
// reported, so the page can say so. Slides and elements are told apart by their `id`, which is
|
|
10
|
+
// what Bento itself morphs and links by.
|
|
11
|
+
//
|
|
12
|
+
// Everything here is plain data in, plain data out: no DOM, no fetch.
|
|
13
|
+
|
|
14
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
15
|
+
|
|
16
|
+
const byId = (list) => new Map((list ?? []).map((item) => [item.id, item]));
|
|
17
|
+
|
|
18
|
+
/** Whether every item of the list has an id of its own: the only lists edits can be told apart in. */
|
|
19
|
+
const keyed = (list) => {
|
|
20
|
+
const ids = (list ?? []).map((item) => item?.id);
|
|
21
|
+
return ids.every((id) => typeof id === "string" && id !== "") && new Set(ids).size === ids.length;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The id of the item before `id` in `list`, or null at the front. */
|
|
25
|
+
const before = (list, id) => {
|
|
26
|
+
const at = list.findIndex((item) => item.id === id);
|
|
27
|
+
return at > 0 ? list[at - 1].id : null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Property edits between two objects, leaving `skip` keys to their own comparison. */
|
|
31
|
+
function propEdits(from, to, skip) {
|
|
32
|
+
const edits = [];
|
|
33
|
+
for (const key of new Set([...Object.keys(from), ...Object.keys(to)])) {
|
|
34
|
+
if (skip.includes(key)) continue;
|
|
35
|
+
if (!(key in to)) edits.push({ key, drop: true });
|
|
36
|
+
else if (!(key in from) || !same(from[key], to[key])) edits.push({ key, value: to[key] });
|
|
37
|
+
}
|
|
38
|
+
return edits;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Edits to a keyed list: what was added (and after what), removed, moved, and changed inside. */
|
|
42
|
+
function listEdits(from, to, inner) {
|
|
43
|
+
const edits = [];
|
|
44
|
+
const old = byId(from);
|
|
45
|
+
const now = byId(to);
|
|
46
|
+
for (const item of from) if (!now.has(item.id)) edits.push({ op: "remove", id: item.id });
|
|
47
|
+
for (const item of to) {
|
|
48
|
+
if (!old.has(item.id)) {
|
|
49
|
+
edits.push({ op: "add", item, after: before(to, item.id) });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const changes = inner(old.get(item.id), item);
|
|
53
|
+
if (changes.length > 0) edits.push({ op: "change", id: item.id, changes });
|
|
54
|
+
}
|
|
55
|
+
// Order: only when the items both sides have are in a different order than before.
|
|
56
|
+
const kept = (list, other) => list.filter((item) => other.has(item.id)).map((item) => item.id);
|
|
57
|
+
if (!same(kept(from, now), kept(to, old))) {
|
|
58
|
+
edits.push({ op: "order", ids: to.map((item) => item.id) });
|
|
59
|
+
}
|
|
60
|
+
return edits;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The person's edits: what turns `shown` into `mine`. Both are documents as the editor reads
|
|
65
|
+
* them, so what differs is what the person did.
|
|
66
|
+
*/
|
|
67
|
+
export function diff(shown, mine) {
|
|
68
|
+
const edits = { props: propEdits(shown, mine, ["slides", "assets"]), slides: [], assets: [] };
|
|
69
|
+
for (const [key, value] of Object.entries(mine.assets ?? {})) {
|
|
70
|
+
if ((shown.assets ?? {})[key] !== value) edits.assets.push({ key, value });
|
|
71
|
+
}
|
|
72
|
+
const from = shown.slides ?? [];
|
|
73
|
+
const to = mine.slides ?? [];
|
|
74
|
+
if (!keyed(from) || !keyed(to)) {
|
|
75
|
+
if (!same(from, to)) edits.slides.push({ op: "replace", slides: to });
|
|
76
|
+
return edits;
|
|
77
|
+
}
|
|
78
|
+
edits.slides = listEdits(from, to, (a, b) => {
|
|
79
|
+
const changes = propEdits(a, b, ["elements"]).map((edit) => ({ ...edit, of: "slide" }));
|
|
80
|
+
const elsA = a.elements ?? [];
|
|
81
|
+
const elsB = b.elements ?? [];
|
|
82
|
+
if (!keyed(elsA) || !keyed(elsB)) {
|
|
83
|
+
if (!same(elsA, elsB)) changes.push({ of: "elements", op: "replace", elements: elsB });
|
|
84
|
+
return changes;
|
|
85
|
+
}
|
|
86
|
+
for (const edit of listEdits(elsA, elsB, (x, y) => propEdits(x, y, []))) {
|
|
87
|
+
changes.push({ of: "elements", ...edit });
|
|
88
|
+
}
|
|
89
|
+
return changes;
|
|
90
|
+
});
|
|
91
|
+
return edits;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whether a set of edits changes nothing. */
|
|
95
|
+
export const isEmpty = (edits) =>
|
|
96
|
+
edits.props.length === 0 && edits.slides.length === 0 && edits.assets.length === 0;
|
|
97
|
+
|
|
98
|
+
/** Sets properties on `target`, noting each one `theirs` had also changed away from `base`. */
|
|
99
|
+
function setProps(target, edits, base, where, clashes) {
|
|
100
|
+
for (const edit of edits) {
|
|
101
|
+
const theirs = target[edit.key];
|
|
102
|
+
const was = base?.[edit.key];
|
|
103
|
+
const mineValue = edit.drop ? undefined : edit.value;
|
|
104
|
+
if (base !== undefined && !same(theirs, was) && !same(theirs, mineValue)) {
|
|
105
|
+
clashes.push({ ...where, key: edit.key, theirs, mine: mineValue });
|
|
106
|
+
}
|
|
107
|
+
if (edit.drop) delete target[edit.key];
|
|
108
|
+
else target[edit.key] = edit.value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Replays keyed-list edits on `list` (changed in place); `change` handles an item's own edits. */
|
|
113
|
+
function applyList(list, edits, baseList, change) {
|
|
114
|
+
const base = byId(baseList);
|
|
115
|
+
for (const edit of edits) {
|
|
116
|
+
if (edit.op === "remove") {
|
|
117
|
+
const at = list.findIndex((item) => item.id === edit.id);
|
|
118
|
+
// Removed here, but changed there since: their change keeps the item.
|
|
119
|
+
if (at >= 0 && same(list[at], base.get(edit.id))) list.splice(at, 1);
|
|
120
|
+
} else if (edit.op === "add") {
|
|
121
|
+
if (list.some((item) => item.id === edit.item.id)) continue;
|
|
122
|
+
const after = edit.after === null ? -1 : list.findIndex((item) => item.id === edit.after);
|
|
123
|
+
list.splice(edit.after !== null && after < 0 ? list.length : after + 1, 0, edit.item);
|
|
124
|
+
} else if (edit.op === "change") {
|
|
125
|
+
let item = list.find((entry) => entry.id === edit.id);
|
|
126
|
+
if (item === undefined) {
|
|
127
|
+
// Edited here, removed there: the edit keeps the item, as it was plus the edit.
|
|
128
|
+
const was = base.get(edit.id);
|
|
129
|
+
if (was === undefined) continue;
|
|
130
|
+
item = structuredClone(was);
|
|
131
|
+
list.push(item);
|
|
132
|
+
}
|
|
133
|
+
change(item, edit.changes, base.get(edit.id));
|
|
134
|
+
} else if (edit.op === "order") {
|
|
135
|
+
const rank = new Map(edit.ids.map((id, index) => [id, index]));
|
|
136
|
+
// Items the order names take that order; the rest keep their place among them.
|
|
137
|
+
const named = list.filter((item) => rank.has(item.id));
|
|
138
|
+
named.sort((a, b) => rank.get(a.id) - rank.get(b.id));
|
|
139
|
+
let next = 0;
|
|
140
|
+
for (let i = 0; i < list.length; i++) if (rank.has(list[i].id)) list[i] = named[next++];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The file's document with the person's edits replayed on it.
|
|
147
|
+
*
|
|
148
|
+
* `base` is the file's document the editor was last in step with (what `theirs` changed from);
|
|
149
|
+
* `edits` is `diff(shown, mine)`. Returns the merged document and the properties both sides set
|
|
150
|
+
* differently, where the person's value was kept: `{ slide?, element?, key, theirs, mine }`.
|
|
151
|
+
*/
|
|
152
|
+
export function rebase(theirs, edits, base) {
|
|
153
|
+
const doc = structuredClone(theirs);
|
|
154
|
+
const clashes = [];
|
|
155
|
+
setProps(doc, edits.props, base, {}, clashes);
|
|
156
|
+
if (edits.assets.length > 0) {
|
|
157
|
+
doc.assets = { ...(doc.assets ?? {}) };
|
|
158
|
+
for (const { key, value } of edits.assets) doc.assets[key] = value;
|
|
159
|
+
}
|
|
160
|
+
const replaced = edits.slides.find((edit) => edit.op === "replace");
|
|
161
|
+
if (replaced) {
|
|
162
|
+
doc.slides = structuredClone(replaced.slides);
|
|
163
|
+
return { doc, clashes };
|
|
164
|
+
}
|
|
165
|
+
doc.slides = doc.slides ?? [];
|
|
166
|
+
applyList(doc.slides, edits.slides, base?.slides ?? [], (slide, changes, was) => {
|
|
167
|
+
setProps(
|
|
168
|
+
slide,
|
|
169
|
+
changes.filter((c) => c.of === "slide"),
|
|
170
|
+
was,
|
|
171
|
+
{ slide: slide.id },
|
|
172
|
+
clashes,
|
|
173
|
+
);
|
|
174
|
+
const elementEdits = changes.filter((c) => c.of === "elements");
|
|
175
|
+
const whole = elementEdits.find((c) => c.op === "replace");
|
|
176
|
+
if (whole) {
|
|
177
|
+
slide.elements = structuredClone(whole.elements);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
slide.elements = slide.elements ?? [];
|
|
181
|
+
applyList(slide.elements, elementEdits, was?.elements ?? [], (element, props, elementWas) =>
|
|
182
|
+
setProps(element, props, elementWas, { slide: slide.id, element: element.id }, clashes),
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
return { doc, clashes };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A deck as the file holds it: valid JSON laid out one slide header, one element and one asset
|
|
190
|
+
* per line, so a text tool can find and replace a single element and a diff reads slide by
|
|
191
|
+
* slide. `collab` never reaches the file: it would be the keys to a live sharing room.
|
|
192
|
+
*/
|
|
193
|
+
export function formatDeck(doc) {
|
|
194
|
+
const { slides = [], assets, collab: _keys, ...head } = doc;
|
|
195
|
+
const line = (value) => JSON.stringify(value);
|
|
196
|
+
const out = [];
|
|
197
|
+
const headText = line(head);
|
|
198
|
+
out.push(`${headText.slice(0, -1)}${headText === "{}" ? "" : ","}"slides":[`);
|
|
199
|
+
slides.forEach((slide, s) => {
|
|
200
|
+
const { elements = [], ...props } = slide;
|
|
201
|
+
const propsText = line(props);
|
|
202
|
+
out.push(`${propsText.slice(0, -1)}${propsText === "{}" ? "" : ","}"elements":[`);
|
|
203
|
+
elements.forEach((element, e) => {
|
|
204
|
+
out.push(` ${line(element)}${e < elements.length - 1 ? "," : ""}`);
|
|
205
|
+
});
|
|
206
|
+
out.push(`]}${s < slides.length - 1 ? "," : ""}`);
|
|
207
|
+
});
|
|
208
|
+
const keys = Object.keys(assets ?? {});
|
|
209
|
+
if (keys.length === 0) {
|
|
210
|
+
out.push("]}");
|
|
211
|
+
} else {
|
|
212
|
+
out.push(`],"assets":{`);
|
|
213
|
+
keys.forEach((key, k) => {
|
|
214
|
+
out.push(`${line(key)}:${line(assets[key])}${k < keys.length - 1 ? "," : ""}`);
|
|
215
|
+
});
|
|
216
|
+
out.push("}}");
|
|
217
|
+
}
|
|
218
|
+
return `${out.join("\n")}\n`;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** A deck file's text as a document; throws with a short reason when it is not one. */
|
|
222
|
+
export function parseDeck(text) {
|
|
223
|
+
let doc;
|
|
224
|
+
try {
|
|
225
|
+
// The API returns the original UTF-8 text, including any leading byte order mark.
|
|
226
|
+
doc = JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
227
|
+
} catch (err) {
|
|
228
|
+
throw new Error(`not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
229
|
+
}
|
|
230
|
+
if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
|
|
231
|
+
throw new Error("not a JSON object");
|
|
232
|
+
}
|
|
233
|
+
if (doc.format !== "bento/slides") throw new Error('its "format" is not "bento/slides"');
|
|
234
|
+
if (!Array.isArray(doc.slides)) throw new Error('it has no "slides" list');
|
|
235
|
+
const { collab: _keys, ...rest } = doc;
|
|
236
|
+
return rest;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The `#bento-doc` block of a `.bento.html` file, as a document. */
|
|
240
|
+
export function deckFromHtml(html) {
|
|
241
|
+
// Older exporters re-order or single-quote these attributes. Read the JSON block as
|
|
242
|
+
// text; scripts and other contents of the imported page never run.
|
|
243
|
+
for (const match of html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)) {
|
|
244
|
+
const attrs = new Map();
|
|
245
|
+
for (const part of match[1].matchAll(
|
|
246
|
+
/(?:^|\s)([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g,
|
|
247
|
+
)) {
|
|
248
|
+
attrs.set(part[1].toLowerCase(), part[2] ?? part[3] ?? part[4]);
|
|
249
|
+
}
|
|
250
|
+
if (
|
|
251
|
+
attrs.get("id") === "bento-doc" &&
|
|
252
|
+
["application/bento+json", "application/json"].includes(attrs.get("type")?.toLowerCase()) &&
|
|
253
|
+
match[2].trim()
|
|
254
|
+
)
|
|
255
|
+
return parseDeck(match[2]);
|
|
256
|
+
}
|
|
257
|
+
throw new Error("the file holds no Bento document");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** A Bento runtime file with `doc` written into its `#bento-doc` block. */
|
|
261
|
+
export function htmlWithDeck(runtime, doc) {
|
|
262
|
+
const json = JSON.stringify(doc).replace(/</g, "\\u003c");
|
|
263
|
+
const open = '<script type="application/bento+json" id="bento-doc">';
|
|
264
|
+
const start = runtime.indexOf(open);
|
|
265
|
+
const end = start < 0 ? -1 : runtime.indexOf("</script>", start);
|
|
266
|
+
if (start < 0 || end < 0) throw new Error("the Bento runtime has no document block");
|
|
267
|
+
return runtime.slice(0, start + open.length) + json + runtime.slice(end);
|
|
268
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { deckTemplates, templateDeck } from "./templates.js";
|
|
2
|
+
import { S, locale } from "./strings.js";
|
|
3
|
+
|
|
4
|
+
const $ = (id) => document.getElementById(id);
|
|
5
|
+
|
|
6
|
+
// Starters contain native rects and plain text. Both the gallery and the preview read the
|
|
7
|
+
// actual slide positions, colors and copy; creating the file uses the same slide objects.
|
|
8
|
+
function paint(sheet, page) {
|
|
9
|
+
sheet.style.backgroundColor = page.background;
|
|
10
|
+
sheet.replaceChildren(
|
|
11
|
+
...page.elements.map((item) => {
|
|
12
|
+
const node = document.createElement("span");
|
|
13
|
+
Object.assign(node.style, {
|
|
14
|
+
left: item.x / 12.8 + "%",
|
|
15
|
+
top: item.y / 7.2 + "%",
|
|
16
|
+
width: item.w / 12.8 + "%",
|
|
17
|
+
height: item.h / 7.2 + "%",
|
|
18
|
+
});
|
|
19
|
+
if (item.type === "shape") {
|
|
20
|
+
node.style.backgroundColor = item.fill;
|
|
21
|
+
} else {
|
|
22
|
+
node.textContent = item.html
|
|
23
|
+
.replaceAll("<", "<")
|
|
24
|
+
.replaceAll(">", ">")
|
|
25
|
+
.replaceAll("&", "&");
|
|
26
|
+
Object.assign(node.style, {
|
|
27
|
+
color: item.color,
|
|
28
|
+
fontSize: item.fontSize / 12.8 + "cqw",
|
|
29
|
+
fontWeight: item.fontWeight,
|
|
30
|
+
lineHeight: item.lineHeight,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function setupTemplatePicker({ blankDeck, createDeck }) {
|
|
39
|
+
const templates = deckTemplates(locale);
|
|
40
|
+
const layout = $("create-layout"),
|
|
41
|
+
name = $("create-name"),
|
|
42
|
+
dialog = $("create-dialog");
|
|
43
|
+
const form = $("create-form"),
|
|
44
|
+
submit = form.querySelector('[type="submit"]');
|
|
45
|
+
let page = 0;
|
|
46
|
+
let previousDefault = "";
|
|
47
|
+
const selection = () => templates.find((item) => item.id === layout.value);
|
|
48
|
+
const build = () => {
|
|
49
|
+
const item = selection(),
|
|
50
|
+
title = name.value.trim() || item?.title || S.untitled;
|
|
51
|
+
return item ? templateDeck(locale, item.id, title) : blankDeck(title);
|
|
52
|
+
};
|
|
53
|
+
function preview() {
|
|
54
|
+
const current = selection();
|
|
55
|
+
$("template-preview").hidden = !current;
|
|
56
|
+
if (!current) return;
|
|
57
|
+
const { slides } = build(),
|
|
58
|
+
selected = slides[page];
|
|
59
|
+
paint($("preview-sheet"), selected);
|
|
60
|
+
const heading = selected.elements.find((item) => item.role === "title");
|
|
61
|
+
const slideTitle = page === 0 ? name.value.trim() || current.title : heading.html;
|
|
62
|
+
$("preview-caption").textContent = S.contextSlide(page + 1, slides.length) + " · " + slideTitle;
|
|
63
|
+
$("preview-prev").disabled = page === 0;
|
|
64
|
+
$("preview-next").disabled = page === slides.length - 1;
|
|
65
|
+
}
|
|
66
|
+
function select() {
|
|
67
|
+
const nextDefault = selection()?.title ?? S.untitled;
|
|
68
|
+
if (!name.value.trim() || name.value === previousDefault) name.value = nextDefault;
|
|
69
|
+
previousDefault = nextDefault;
|
|
70
|
+
page = 0;
|
|
71
|
+
preview();
|
|
72
|
+
}
|
|
73
|
+
function open(key) {
|
|
74
|
+
name.value = "";
|
|
75
|
+
layout.value = key;
|
|
76
|
+
$("create-error").textContent = "";
|
|
77
|
+
select();
|
|
78
|
+
dialog.showModal();
|
|
79
|
+
name.select();
|
|
80
|
+
}
|
|
81
|
+
for (const item of templates) {
|
|
82
|
+
layout.add(new Option(item.label, item.id));
|
|
83
|
+
const button = document.createElement("button");
|
|
84
|
+
button.type = "button";
|
|
85
|
+
button.dataset.template = item.id;
|
|
86
|
+
const sheet = document.createElement("span");
|
|
87
|
+
sheet.className = "template-sheet slide-preview";
|
|
88
|
+
sheet.setAttribute("aria-hidden", "true");
|
|
89
|
+
const { slides } = templateDeck(locale, item.id, item.title);
|
|
90
|
+
paint(sheet, slides[0]);
|
|
91
|
+
const label = document.createElement("span");
|
|
92
|
+
label.textContent = item.label;
|
|
93
|
+
button.append(sheet, label);
|
|
94
|
+
button.onclick = () => open(item.id);
|
|
95
|
+
$("templates").append(button);
|
|
96
|
+
}
|
|
97
|
+
$("start-blank").onclick = $("new").onclick = () => open("blank");
|
|
98
|
+
layout.onchange = select;
|
|
99
|
+
name.oninput = preview;
|
|
100
|
+
$("preview-prev").onclick = () => {
|
|
101
|
+
page--;
|
|
102
|
+
preview();
|
|
103
|
+
};
|
|
104
|
+
$("preview-next").onclick = () => {
|
|
105
|
+
page++;
|
|
106
|
+
preview();
|
|
107
|
+
};
|
|
108
|
+
$("create-cancel").onclick = () => dialog.close();
|
|
109
|
+
dialog.addEventListener("cancel", (event) => {
|
|
110
|
+
if (submit.disabled) event.preventDefault();
|
|
111
|
+
});
|
|
112
|
+
form.onsubmit = async (event) => {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
if (submit.disabled) return;
|
|
115
|
+
if (!name.value.trim()) return name.focus();
|
|
116
|
+
const doc = build();
|
|
117
|
+
$("create-error").textContent = "";
|
|
118
|
+
for (const control of [submit, name, layout, $("create-cancel")]) control.disabled = true;
|
|
119
|
+
try {
|
|
120
|
+
await createDeck(doc.title, doc);
|
|
121
|
+
dialog.close();
|
|
122
|
+
} catch {
|
|
123
|
+
$("create-error").textContent = S.createFailed;
|
|
124
|
+
} finally {
|
|
125
|
+
for (const control of [submit, name, layout, $("create-cancel")]) control.disabled = false;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// These starters use the same editable text and shapes as a document drawn in Bento.
|
|
2
|
+
const copy = {
|
|
3
|
+
en: {
|
|
4
|
+
brief: {
|
|
5
|
+
label: "Project brief",
|
|
6
|
+
title: "A new onboarding guide",
|
|
7
|
+
audience: "Project proposal",
|
|
8
|
+
subtitle: "One starting point for a new hire’s first week.",
|
|
9
|
+
coverNote: "Introduce the project and the decision you need from the room.",
|
|
10
|
+
scope: "Where the guide starts and ends",
|
|
11
|
+
scopeItems: [
|
|
12
|
+
[
|
|
13
|
+
"In scope",
|
|
14
|
+
"A first-week checklist, links to essential tools and a named contact for each step.",
|
|
15
|
+
],
|
|
16
|
+
["For a later release", "Role-specific training and the full employee handbook."],
|
|
17
|
+
],
|
|
18
|
+
scopeNote:
|
|
19
|
+
"Replace these boundaries with the work your team can deliver in the first release.",
|
|
20
|
+
stages: "From draft to rollout",
|
|
21
|
+
stageItems: [
|
|
22
|
+
["Draft", "Map the first week with recent hires."],
|
|
23
|
+
["Pilot", "Try the guide with one incoming group."],
|
|
24
|
+
["Release", "Revise the checklist and assign an owner."],
|
|
25
|
+
],
|
|
26
|
+
stagesNote: "Add a date and owner to each milestone before sharing the plan.",
|
|
27
|
+
decision: "Decision requested",
|
|
28
|
+
question: "Can we pilot the guide with the next group of new hires?",
|
|
29
|
+
action: "Next step",
|
|
30
|
+
actionBody: "People Operations selects the pilot group and schedules a feedback session.",
|
|
31
|
+
decisionNote: "Confirm who will make the decision, and record the agreed next step.",
|
|
32
|
+
},
|
|
33
|
+
retro: {
|
|
34
|
+
label: "Team retrospective",
|
|
35
|
+
title: "First-week pilot retrospective",
|
|
36
|
+
audience: "Team retrospective",
|
|
37
|
+
subtitle: "What happened during the pilot, and what to change for the next group.",
|
|
38
|
+
coverNote: "Introduce the pilot and the period covered.",
|
|
39
|
+
scope: "What the pilot tested",
|
|
40
|
+
scopeItems: [
|
|
41
|
+
["Starting point", "Essential links were spread across individual welcome messages."],
|
|
42
|
+
["What we tried", "Each new hire received one checklist and a named point of contact."],
|
|
43
|
+
],
|
|
44
|
+
scopeNote: "Replace the example with a short account of your own pilot and its participants.",
|
|
45
|
+
stages: "Keep, change, try",
|
|
46
|
+
stageItems: [
|
|
47
|
+
["Keep", "A single place to find the tasks for day one."],
|
|
48
|
+
["Change", "Make account access requests before the start date."],
|
|
49
|
+
["Try", "Ask which instruction was hardest to follow."],
|
|
50
|
+
],
|
|
51
|
+
stagesNote: "Add one observation from the team for each change you propose.",
|
|
52
|
+
decision: "Next experiment",
|
|
53
|
+
question: "Does requesting access earlier help the next group start on time?",
|
|
54
|
+
action: "Review point",
|
|
55
|
+
actionBody:
|
|
56
|
+
"The onboarding lead checks access on day one and reviews feedback at the end of the week.",
|
|
57
|
+
decisionNote:
|
|
58
|
+
"Agree on the owner, what evidence to collect and when the team will review it.",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
zh: {
|
|
62
|
+
brief: {
|
|
63
|
+
label: "项目简报",
|
|
64
|
+
title: "新人入职指南改版",
|
|
65
|
+
audience: "项目提案",
|
|
66
|
+
subtitle: "给新同事一份入职第一周就能用的指南。",
|
|
67
|
+
coverNote: "介绍这个项目,以及今天希望大家决定的事情。",
|
|
68
|
+
scope: "这次改版做哪些事",
|
|
69
|
+
scopeItems: [
|
|
70
|
+
["本期交付", "第一周的任务清单、常用工具入口,以及每项任务的对接人。"],
|
|
71
|
+
["留待下期", "各岗位的专项培训,以及完整的员工手册。"],
|
|
72
|
+
],
|
|
73
|
+
scopeNote: "把这两个范围换成本次项目实际约定的交付边界。",
|
|
74
|
+
stages: "从初稿到上线",
|
|
75
|
+
stageItems: [
|
|
76
|
+
["起草", "和刚入职的同事一起梳理第一周的安排。"],
|
|
77
|
+
["试用", "请下一批新同事按指南走一遍。"],
|
|
78
|
+
["发布", "根据试用反馈修订清单,明确维护人。"],
|
|
79
|
+
],
|
|
80
|
+
stagesNote: "分享前,给每个阶段补上日期和负责人。",
|
|
81
|
+
decision: "本次需要确认",
|
|
82
|
+
question: "下一批新同事入职时,要不要先试用这份指南?",
|
|
83
|
+
action: "下一步",
|
|
84
|
+
actionBody: "由人力团队确定试用人员,约好收集反馈的时间。",
|
|
85
|
+
decisionNote: "确认由谁拍板,并记录讨论后的下一步。",
|
|
86
|
+
},
|
|
87
|
+
retro: {
|
|
88
|
+
label: "团队复盘",
|
|
89
|
+
title: "入职指南试用复盘",
|
|
90
|
+
audience: "团队复盘",
|
|
91
|
+
subtitle: "回顾这轮试用的变化,决定下批新同事入职前要改什么。",
|
|
92
|
+
coverNote: "介绍这次试用的时间、参与人和回顾范围。",
|
|
93
|
+
scope: "这次试用了什么",
|
|
94
|
+
scopeItems: [
|
|
95
|
+
["原先的做法", "常用链接分散在不同同事发来的欢迎消息里。"],
|
|
96
|
+
["这次的尝试", "每位新人收到同一份任务清单,每个环节都有对接人。"],
|
|
97
|
+
],
|
|
98
|
+
scopeNote: "把示例换成团队实际尝试过的做法和参与对象。",
|
|
99
|
+
stages: "保留、调整、尝试",
|
|
100
|
+
stageItems: [
|
|
101
|
+
["保留", "第一天要做的事都能在同一个地方找到。"],
|
|
102
|
+
["调整", "把账号申请提前到报到之前。"],
|
|
103
|
+
["尝试", "请新同事指出最难理解的一条说明。"],
|
|
104
|
+
],
|
|
105
|
+
stagesNote: "为每项改进补上一条来自团队的具体观察。",
|
|
106
|
+
decision: "下一轮试验",
|
|
107
|
+
question: "提前申请账号,能否让下一批新同事第一天就开始工作?",
|
|
108
|
+
action: "回访安排",
|
|
109
|
+
actionBody: "由入职负责人在报到日检查账号,周末汇总使用反馈。",
|
|
110
|
+
decisionNote: "约好负责人、要观察的现象,以及下一次回顾的时间。",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
const palettes = {
|
|
115
|
+
brief: {
|
|
116
|
+
paper: "#FAF9F5",
|
|
117
|
+
ink: "#242540",
|
|
118
|
+
accent: "#5143A3",
|
|
119
|
+
tint: "#E5E1F4",
|
|
120
|
+
cover: "#302A59",
|
|
121
|
+
coverInk: "#FFFFFF",
|
|
122
|
+
coverAccent: "#C9C1F2",
|
|
123
|
+
},
|
|
124
|
+
retro: {
|
|
125
|
+
paper: "#FFFCF2",
|
|
126
|
+
ink: "#173D35",
|
|
127
|
+
accent: "#246350",
|
|
128
|
+
tint: "#DBE9DC",
|
|
129
|
+
cover: "#F3EACB",
|
|
130
|
+
coverInk: "#173D35",
|
|
131
|
+
coverAccent: "#246350",
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
function text(id, value, x, y, w, h, fontSize, color, fontWeight = 400) {
|
|
136
|
+
return {
|
|
137
|
+
id,
|
|
138
|
+
type: "text",
|
|
139
|
+
...(id === "title" ? { role: "title" } : {}),
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
w,
|
|
143
|
+
h,
|
|
144
|
+
html: value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"),
|
|
145
|
+
fontSize,
|
|
146
|
+
fontWeight,
|
|
147
|
+
fontFamily: "system-ui, sans-serif",
|
|
148
|
+
color,
|
|
149
|
+
align: "left",
|
|
150
|
+
valign: "top",
|
|
151
|
+
lineHeight: 1.16,
|
|
152
|
+
rotation: 0,
|
|
153
|
+
opacity: 1,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function rect(id, x, y, w, h, fill) {
|
|
157
|
+
return {
|
|
158
|
+
id,
|
|
159
|
+
type: "shape",
|
|
160
|
+
shape: "rect",
|
|
161
|
+
x,
|
|
162
|
+
y,
|
|
163
|
+
w,
|
|
164
|
+
h,
|
|
165
|
+
fill,
|
|
166
|
+
stroke: "none",
|
|
167
|
+
strokeWidth: 0,
|
|
168
|
+
rotation: 0,
|
|
169
|
+
opacity: 1,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const slide = (id, background, notes, elements) => ({
|
|
173
|
+
id,
|
|
174
|
+
background,
|
|
175
|
+
notes,
|
|
176
|
+
transition: "none",
|
|
177
|
+
elements,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
export function deckTemplates(locale) {
|
|
181
|
+
return Object.entries(copy[locale]).map(([id, entry]) => ({
|
|
182
|
+
id,
|
|
183
|
+
label: entry.label,
|
|
184
|
+
title: entry.title,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
export function templateDeck(locale, key, title) {
|
|
188
|
+
const c = copy[locale][key],
|
|
189
|
+
p = palettes[key];
|
|
190
|
+
// A long user-entered title stays inside the editable cover in either language.
|
|
191
|
+
const ems = Array.from(title).reduce(
|
|
192
|
+
(sum, char) => sum + (char.codePointAt(0) < 256 ? 0.64 : 1),
|
|
193
|
+
0,
|
|
194
|
+
);
|
|
195
|
+
const titleSize = Math.min(
|
|
196
|
+
84,
|
|
197
|
+
Math.floor(Math.sqrt((0.74 * 1112 * 260) / (1.16 * Math.max(1, ems)))),
|
|
198
|
+
);
|
|
199
|
+
const cover = slide("cover", p.cover, c.coverNote, [
|
|
200
|
+
rect("marker", 84, 88, 90, 10, p.coverAccent),
|
|
201
|
+
text("kind", c.audience, 84, 126, 1080, 58, 34, p.coverAccent, 650),
|
|
202
|
+
text("title", title, 84, 224, 1112, 276, titleSize, p.coverInk, 750),
|
|
203
|
+
rect("rule", 84, 536, 1112, 3, p.coverAccent),
|
|
204
|
+
text("summary", c.subtitle, 84, 575, 1112, 104, 32, p.coverInk),
|
|
205
|
+
]);
|
|
206
|
+
const scope = slide("scope", p.paper, c.scopeNote, [
|
|
207
|
+
text("title", c.scope, 80, 65, 1120, 135, 60, p.ink, 730),
|
|
208
|
+
...c.scopeItems.flatMap(([label, body], i) => {
|
|
209
|
+
const x = 80 + i * 578;
|
|
210
|
+
return [
|
|
211
|
+
rect("line-" + i, x, 251, 522, 7, p.accent),
|
|
212
|
+
text("label-" + i, label, x, 287, 522, 105, 42, p.accent, 700),
|
|
213
|
+
text("body-" + i, body, x, 402, 506, 225, 34, p.ink),
|
|
214
|
+
];
|
|
215
|
+
}),
|
|
216
|
+
]);
|
|
217
|
+
const stages = slide("stages", p.paper, c.stagesNote, [
|
|
218
|
+
text("title", c.stages, 80, 65, 1120, 132, 60, p.ink, 730),
|
|
219
|
+
...c.stageItems.flatMap(([label, body], i) => {
|
|
220
|
+
if (key === "retro") {
|
|
221
|
+
const x = 80 + i * 380;
|
|
222
|
+
return [
|
|
223
|
+
rect("panel-" + i, x, 230, 352, 370, p.tint),
|
|
224
|
+
text("label-" + i, label, x + 28, 276, 296, 78, 44, p.accent, 700),
|
|
225
|
+
text("body-" + i, body, x + 28, 385, 296, 185, 30, p.ink),
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
const y = 218 + i * 140;
|
|
229
|
+
return [
|
|
230
|
+
rect("band-" + i, 80, y, 1120, 2, p.accent),
|
|
231
|
+
text("label-" + i, label, 80, y + 25, 302, 92, 39, p.accent, 700),
|
|
232
|
+
text("body-" + i, body, 398, y + 29, 776, 92, 32, p.ink),
|
|
233
|
+
];
|
|
234
|
+
}),
|
|
235
|
+
]);
|
|
236
|
+
const decision = slide("decision", p.tint, c.decisionNote, [
|
|
237
|
+
text("kind", c.decision, 84, 75, 1100, 66, 32, p.accent, 650),
|
|
238
|
+
text("title", c.question, 84, 177, 1096, 240, 66, p.ink, 730),
|
|
239
|
+
rect("rule", 84, 462, 1112, 4, p.accent),
|
|
240
|
+
text("action", c.action, 84, 513, 260, 100, 38, p.accent, 700),
|
|
241
|
+
text("body", c.actionBody, 370, 515, 820, 155, 31, p.ink),
|
|
242
|
+
]);
|
|
243
|
+
return {
|
|
244
|
+
format: "bento/slides",
|
|
245
|
+
version: 1,
|
|
246
|
+
title,
|
|
247
|
+
size: { width: 1280, height: 720 },
|
|
248
|
+
theme: {
|
|
249
|
+
background: p.paper,
|
|
250
|
+
color: p.ink,
|
|
251
|
+
accent: p.accent,
|
|
252
|
+
fontFamily: "system-ui, sans-serif",
|
|
253
|
+
},
|
|
254
|
+
slides: [cover, scope, stages, decision],
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Bento authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|