aicommunicator 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 (97) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +93 -2
  3. package/bin/aic.js +20427 -0
  4. package/host-ui/host.js +5151 -0
  5. package/host-ui/index.html +483 -0
  6. package/host-ui/lang-en.js +631 -0
  7. package/package.json +30 -4
  8. package/plugin-guide.md +997 -0
  9. package/plugins/plugin-animation/LICENSE +55 -0
  10. package/plugins/plugin-animation/dist/logic.js +2225 -0
  11. package/plugins/plugin-animation/docs/manual.md +217 -0
  12. package/plugins/plugin-animation/manifest.json +31 -0
  13. package/plugins/plugin-animation/ui/icon.svg +6 -0
  14. package/plugins/plugin-animation/ui/index.html +2266 -0
  15. package/plugins/plugin-html-design/LICENSE +55 -0
  16. package/plugins/plugin-html-design/dist/logic.js +972 -0
  17. package/plugins/plugin-html-design/docs/manual.md +100 -0
  18. package/plugins/plugin-html-design/manifest.json +39 -0
  19. package/plugins/plugin-html-design/samples/exhibition-page.json +570 -0
  20. package/plugins/plugin-html-design/ui/icon.svg +5 -0
  21. package/plugins/plugin-html-design/ui/index.html +1241 -0
  22. package/plugins/plugin-html-slides/LICENSE +55 -0
  23. package/plugins/plugin-html-slides/dist/logic.js +1323 -0
  24. package/plugins/plugin-html-slides/docs/manual.md +121 -0
  25. package/plugins/plugin-html-slides/manifest.json +39 -0
  26. package/plugins/plugin-html-slides/samples/first-week-lecture.json +1129 -0
  27. package/plugins/plugin-html-slides/ui/icon.svg +5 -0
  28. package/plugins/plugin-html-slides/ui/index.html +1349 -0
  29. package/plugins/plugin-mindmap/LICENSE +55 -0
  30. package/plugins/plugin-mindmap/dist/logic.js +966 -0
  31. package/plugins/plugin-mindmap/docs/manual.md +145 -0
  32. package/plugins/plugin-mindmap/manifest.json +39 -0
  33. package/plugins/plugin-mindmap/samples/book-club.json +480 -0
  34. package/plugins/plugin-mindmap/ui/icon.svg +5 -0
  35. package/plugins/plugin-mindmap/ui/index.html +1774 -0
  36. package/plugins/plugin-plan/LICENSE +55 -0
  37. package/plugins/plugin-plan/dist/logic.js +1029 -0
  38. package/plugins/plugin-plan/docs/manual.md +261 -0
  39. package/plugins/plugin-plan/manifest.json +51 -0
  40. package/plugins/plugin-plan/samples/kimchi-day.json +1514 -0
  41. package/plugins/plugin-plan/samples/meeting-outline.json +653 -0
  42. package/plugins/plugin-plan/samples/reading-class.json +1577 -0
  43. package/plugins/plugin-plan/ui/icon.svg +7 -0
  44. package/plugins/plugin-plan/ui/index.html +1523 -0
  45. package/plugins/plugin-png/LICENSE +55 -0
  46. package/plugins/plugin-png/dist/logic.js +1758 -0
  47. package/plugins/plugin-png/docs/manual.md +344 -0
  48. package/plugins/plugin-png/manifest.json +35 -0
  49. package/plugins/plugin-png/ui/icon.svg +5 -0
  50. package/plugins/plugin-png/ui/index.html +2885 -0
  51. package/plugins/plugin-process-log/LICENSE +55 -0
  52. package/plugins/plugin-process-log/dist/logic.js +406 -0
  53. package/plugins/plugin-process-log/docs/manual.md +131 -0
  54. package/plugins/plugin-process-log/manifest.json +43 -0
  55. package/plugins/plugin-process-log/samples/design-decisions.json +241 -0
  56. package/plugins/plugin-process-log/ui/icon.svg +7 -0
  57. package/plugins/plugin-process-log/ui/index.html +721 -0
  58. package/plugins/plugin-story/LICENSE +55 -0
  59. package/plugins/plugin-story/dist/logic.js +2201 -0
  60. package/plugins/plugin-story/docs/manual.md +428 -0
  61. package/plugins/plugin-story/manifest.json +49 -0
  62. package/plugins/plugin-story/samples/scene-body.json +758 -0
  63. package/plugins/plugin-story/samples/time-and-groups.json +989 -0
  64. package/plugins/plugin-story/ui/icon.svg +4 -0
  65. package/plugins/plugin-story/ui/index.html +2783 -0
  66. package/plugins/plugin-svg/LICENSE +55 -0
  67. package/plugins/plugin-svg/dist/logic.js +2150 -0
  68. package/plugins/plugin-svg/docs/manual.md +314 -0
  69. package/plugins/plugin-svg/manifest.json +45 -0
  70. package/plugins/plugin-svg/samples/rocket-icon.json +1305 -0
  71. package/plugins/plugin-svg/samples/yard-cat.json +7796 -0
  72. package/plugins/plugin-svg/ui/icon.svg +4 -0
  73. package/plugins/plugin-svg/ui/index.html +2017 -0
  74. package/plugins/plugin-tree/LICENSE +55 -0
  75. package/plugins/plugin-tree/dist/logic.js +505 -0
  76. package/plugins/plugin-tree/docs/manual.md +140 -0
  77. package/plugins/plugin-tree/manifest.json +45 -0
  78. package/plugins/plugin-tree/samples/book-club.json +473 -0
  79. package/plugins/plugin-tree/samples/sort-memos.json +604 -0
  80. package/plugins/plugin-tree/ui/icon.svg +7 -0
  81. package/plugins/plugin-tree/ui/index.html +1305 -0
  82. package/schema/aic_describe.input.json +11 -0
  83. package/schema/aic_describe.output.json +67 -0
  84. package/schema/aic_observe.input.json +14 -0
  85. package/schema/aic_observe.output.json +47 -0
  86. package/schema/aic_send.input.json +15 -0
  87. package/schema/aic_send.output.json +38 -0
  88. package/schema/aic_update.input.json +19 -0
  89. package/schema/aic_update.output.json +39 -0
  90. package/schema/common.json +127 -0
  91. package/template/plugin/LICENSE +55 -0
  92. package/template/plugin/README.md +27 -0
  93. package/template/plugin/docs/manual.md +31 -0
  94. package/template/plugin/logic.js +337 -0
  95. package/template/plugin/manifest.json +27 -0
  96. package/template/plugin/ui/icon.svg +4 -0
  97. package/template/plugin/ui/index.html +269 -0
@@ -0,0 +1,1323 @@
1
+ "use strict";
2
+ (() => {
3
+ // packages/plugin-html-design/src/cascade.ts
4
+ var cmp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
5
+ var maxSpec = (a, b) => a === null || cmp(b, a) > 0 ? b : a;
6
+ var VOID = /* @__PURE__ */ new Set(["area", "br", "col", "hr", "img", "input", "wbr", "source", "track"]);
7
+ function elementTree(html) {
8
+ const out = /* @__PURE__ */ new Map();
9
+ const stack = [];
10
+ for (const m of html.matchAll(/<(\/?)([a-zA-Z][\w-]*)\b([^>]*)>/g)) {
11
+ const tag = m[2].toLowerCase();
12
+ if (m[1] === "/") {
13
+ const at = stack.map((s) => s.tag).lastIndexOf(tag);
14
+ if (at >= 0) stack.length = at;
15
+ continue;
16
+ }
17
+ const attrs = {};
18
+ for (const a of m[3].matchAll(/([\w:-]+)(?:\s*=\s*"([^"]*)")?/g)) attrs[a[1].toLowerCase()] = a[2] ?? "";
19
+ const el2 = { tag, id: attrs.id ?? null, classes: (attrs.class ?? "").split(/\s+/).filter(Boolean), attrs, parent: stack[stack.length - 1] ?? null };
20
+ if (attrs["data-aic-key"]) out.set(attrs["data-aic-key"], el2);
21
+ if (!VOID.has(tag) && !m[3].trim().endsWith("/")) stack.push(el2);
22
+ }
23
+ return out;
24
+ }
25
+ function cssRules(css) {
26
+ const src = css.replace(/\/\*[\s\S]*?\*\//g, "");
27
+ const out = [];
28
+ const walk = (text, media) => {
29
+ let i = 0;
30
+ while (i < text.length) {
31
+ const open = text.indexOf("{", i);
32
+ if (open < 0) break;
33
+ const prelude = text.slice(i, open).trim();
34
+ let depth = 1;
35
+ let j = open + 1;
36
+ for (; j < text.length && depth > 0; j += 1) {
37
+ if (text[j] === "{") depth += 1;
38
+ else if (text[j] === "}") depth -= 1;
39
+ }
40
+ const inner = text.slice(open + 1, j - 1);
41
+ if (prelude.startsWith("@media")) walk(inner, prelude.slice(6).trim());
42
+ else if (!prelude.startsWith("@")) {
43
+ const props = inner.split(";").map((d) => d.split(":")[0].trim().toLowerCase()).filter(Boolean);
44
+ out.push({ selector: prelude, props, media });
45
+ }
46
+ i = j;
47
+ }
48
+ };
49
+ walk(src, null);
50
+ return out;
51
+ }
52
+ var splitTop = (s, sep) => {
53
+ const out = [];
54
+ let depth = 0;
55
+ let cur = "";
56
+ for (const ch of s) {
57
+ if (ch === "(" || ch === "[") depth += 1;
58
+ else if (ch === ")" || ch === "]") depth -= 1;
59
+ if (ch === sep && depth === 0) {
60
+ out.push(cur);
61
+ cur = "";
62
+ } else cur += ch;
63
+ }
64
+ out.push(cur);
65
+ return out.map((x) => x.trim()).filter(Boolean);
66
+ };
67
+ var STATE_PSEUDO = /* @__PURE__ */ new Set(["hover", "focus", "focus-visible", "focus-within", "active"]);
68
+ var LEGACY_ELEMENTS = /* @__PURE__ */ new Set(["before", "after", "first-line", "first-letter"]);
69
+ function compound(src) {
70
+ const spec = [0, 0, 0];
71
+ let state = false;
72
+ let pseudoElement = false;
73
+ const tests = [];
74
+ let rest = src;
75
+ const re = /^(?:(\*|[a-zA-Z][\w-]*)|#([\w-]+)|\.([\w-]+)|\[([^\]=\s]+)(?:\s*=\s*["']?([^"'\]]*)["']?)?\]|::([\w-]+)|:([\w-]+)(?:\(([^)]*)\))?)/;
76
+ while (rest.length) {
77
+ const m = re.exec(rest);
78
+ if (!m) return null;
79
+ rest = rest.slice(m[0].length);
80
+ if (m[1]) {
81
+ if (m[1] !== "*") {
82
+ spec[2] += 1;
83
+ const t = m[1].toLowerCase();
84
+ tests.push((el2) => el2.tag === t);
85
+ }
86
+ } else if (m[2]) {
87
+ spec[0] += 1;
88
+ const id = m[2];
89
+ tests.push((el2) => el2.id === id);
90
+ } else if (m[3]) {
91
+ spec[1] += 1;
92
+ const c = m[3];
93
+ tests.push((el2) => el2.classes.includes(c));
94
+ } else if (m[4]) {
95
+ spec[1] += 1;
96
+ const name = m[4].toLowerCase();
97
+ if (name === "open") state = true;
98
+ else {
99
+ const v = m[5];
100
+ tests.push((el2) => name in el2.attrs && (v === void 0 || el2.attrs[name] === v));
101
+ }
102
+ } else if (m[6]) {
103
+ spec[2] += 1;
104
+ pseudoElement = true;
105
+ } else if (m[7]) {
106
+ const name = m[7].toLowerCase();
107
+ if (LEGACY_ELEMENTS.has(name)) {
108
+ spec[2] += 1;
109
+ pseudoElement = true;
110
+ } else if (name === "not" && m[8] !== void 0) {
111
+ const arg = compound(m[8].trim());
112
+ if (!arg) return null;
113
+ spec[0] += arg.spec[0];
114
+ spec[1] += arg.spec[1];
115
+ spec[2] += arg.spec[2];
116
+ if (arg.state) state = true;
117
+ else tests.push((el2) => !arg.test(el2));
118
+ } else {
119
+ spec[1] += 1;
120
+ if (STATE_PSEUDO.has(name)) state = true;
121
+ }
122
+ }
123
+ }
124
+ return { spec, state, pseudoElement, test: (el2) => tests.every((t) => t(el2)) };
125
+ }
126
+ function complex(src) {
127
+ const parts = [];
128
+ const tokens = src.replace(/\s*>\s*/g, " > ").split(/\s+/).filter(Boolean);
129
+ let comb = " ";
130
+ for (const t of tokens) {
131
+ if (t === ">") {
132
+ comb = ">";
133
+ continue;
134
+ }
135
+ const c = compound(t);
136
+ if (!c) return null;
137
+ parts.push({ comb, c });
138
+ comb = " ";
139
+ }
140
+ if (!parts.length) return null;
141
+ const spec = [0, 0, 0];
142
+ for (const p of parts) for (let k = 0; k < 3; k += 1) spec[k] += p.c.spec[k];
143
+ const match = (el2, i) => {
144
+ if (!el2 || !parts[i].c.test(el2)) return false;
145
+ if (i === 0) return true;
146
+ if (parts[i].comb === ">") return match(el2.parent, i - 1);
147
+ for (let a = el2.parent; a; a = a.parent) if (match(a, i - 1)) return true;
148
+ return false;
149
+ };
150
+ return {
151
+ spec,
152
+ state: parts.some((p) => p.c.state),
153
+ pseudoElement: parts[parts.length - 1].c.pseudoElement,
154
+ matches: (el2) => match(el2, parts.length - 1)
155
+ };
156
+ }
157
+ function overlaps(a, b) {
158
+ if (a === b || b.startsWith(`${a}-`) || a.startsWith(`${b}-`)) return true;
159
+ const gap = (x, y) => x === "gap" && (y === "row-gap" || y === "column-gap");
160
+ return gap(a, b) || gap(b, a);
161
+ }
162
+ function mediaCompatible(ruleMedia, media, mobileMax) {
163
+ if (ruleMedia === null || media === "all") return true;
164
+ const q = ruleMedia.replace(/\s+/g, "");
165
+ const min = /^\(min-width:(\d+)px\)$/.exec(q);
166
+ const max = /^\(max-width:(\d+)px\)$/.exec(q);
167
+ if (media === "mobile" && min) return Number(min[1]) <= mobileMax;
168
+ if (media === "desktop" && max) return Number(max[1]) > mobileMax;
169
+ return true;
170
+ }
171
+ function analyze(html, css) {
172
+ const rules = [];
173
+ for (const r of cssRules(css)) {
174
+ for (const sel of splitTop(r.selector, ",")) {
175
+ const c = complex(sel);
176
+ rules.push({ c: c ?? { spec: [0, 1, 0], state: false, pseudoElement: false, matches: () => true }, props: r.props, media: r.media });
177
+ }
178
+ }
179
+ return { rules, tree: elementTree(html) };
180
+ }
181
+ function normalSpec(info, key, property, media, mobileMax) {
182
+ const HIGH = [2, 0, 0];
183
+ const el2 = info.tree.get(key);
184
+ if (!el2) return { spec: HIGH, preserved: false };
185
+ let base = null;
186
+ let state = null;
187
+ for (const r of info.rules) {
188
+ if (r.c.pseudoElement || !r.props.some((p) => overlaps(p, property)) || !mediaCompatible(r.media, media, mobileMax) || !r.c.matches(el2)) continue;
189
+ if (r.c.state) state = maxSpec(state, r.c.spec);
190
+ else base = maxSpec(base, r.c.spec);
191
+ }
192
+ const want = maxSpec(base, [0, 1, 0]);
193
+ if (state && cmp(state, want) > 0) return { spec: want, preserved: true };
194
+ return { spec: HIGH, preserved: false };
195
+ }
196
+ function selectorWithSpec(key, spec) {
197
+ const own = `[data-aic-key="${key}"]`;
198
+ if (cmp(spec, [0, 1, 0]) <= 0) return `:is(${own})`;
199
+ const [a, b, c] = spec;
200
+ const head = `${c > 0 ? "aic-none" : ""}${"#aic-none".repeat(a)}${".aic-none".repeat(b)}`;
201
+ const tail = c > 1 ? " aic-none".repeat(c - 1) : "";
202
+ return `:is(${own},${head}${tail})`;
203
+ }
204
+
205
+ // packages/plugin-html-design/src/compose.ts
206
+ var PROPERTIES = /* @__PURE__ */ new Set([
207
+ "color",
208
+ "background-color",
209
+ "opacity",
210
+ "font-size",
211
+ "font-weight",
212
+ "font-style",
213
+ "line-height",
214
+ "letter-spacing",
215
+ "text-align",
216
+ "text-transform",
217
+ "text-decoration",
218
+ "margin",
219
+ "margin-top",
220
+ "margin-right",
221
+ "margin-bottom",
222
+ "margin-left",
223
+ "padding",
224
+ "padding-top",
225
+ "padding-right",
226
+ "padding-bottom",
227
+ "padding-left",
228
+ "gap",
229
+ "row-gap",
230
+ "column-gap",
231
+ "width",
232
+ "max-width",
233
+ "min-width",
234
+ "height",
235
+ "max-height",
236
+ "min-height",
237
+ "aspect-ratio",
238
+ "object-fit",
239
+ "border",
240
+ "border-width",
241
+ "border-style",
242
+ "border-color",
243
+ "border-radius",
244
+ "display",
245
+ "flex-direction",
246
+ "flex-wrap",
247
+ "justify-content",
248
+ "align-items",
249
+ "grid-template-columns",
250
+ "box-shadow",
251
+ "transform",
252
+ "transition"
253
+ ]);
254
+ function valueProblem(property, value) {
255
+ if (!PROPERTIES.has(property)) return `${property} is not a property you can change in this version. Properties you can change: ${[...PROPERTIES].join(", ")}`;
256
+ if (value.length > 200) return "The value is longer than 200 characters";
257
+ if (/[;{}<>\\@"'`]|\/\*|url\s*\(|expression\s*\(|image-set|image\s*\(|!\s*important/i.test(value)) {
258
+ return `The value "${value}" has a character or function that is not allowed (semicolon, braces, quotes, url(), !important and so on)`;
259
+ }
260
+ return null;
261
+ }
262
+ function sourceProblems(html, css) {
263
+ const out = [];
264
+ if (/<\s*(script|iframe|object|embed|link|meta|base|form|frame|frameset|svg|math|template|style)\b/i.test(html)) out.push("There is a tag that is not allowed");
265
+ if (/\son[a-z]+\s*=/i.test(html)) out.push("There is an inline event handler");
266
+ if (/\sstyle\s*=/i.test(html)) out.push("There is a style attribute. Put styles in the CSS");
267
+ for (const m of html.matchAll(/\s(src|href|srcset|action|formaction|poster|xlink:href)\s*=\s*"([^"]*)"/gi)) {
268
+ const v = m[2];
269
+ if (m[1].toLowerCase() === "href" ? !/^#[\w-]*$/.test(v) : !/^asset:[a-z0-9-]+$/.test(v)) out.push(`${m[1]}="${v}" is not allowed. Links use #, images use asset:key`);
270
+ }
271
+ if (/@import|@font-face|javascript:|expression\s*\(|behavior\s*:|-moz-binding/i.test(css)) out.push("The CSS has a rule that is not allowed");
272
+ for (const m of css.matchAll(/url\s*\(\s*["']?([^"')]*)/gi)) if (!/^asset:[a-z0-9-]+$/.test(m[1])) out.push(`url(${m[1]}) in the CSS is not allowed`);
273
+ if (/<\/style/i.test(css)) out.push("The CSS has a closing style tag");
274
+ return out;
275
+ }
276
+ var escapeHtml = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
277
+ var VOID2 = /* @__PURE__ */ new Set(["area", "br", "col", "hr", "img", "input", "wbr", "source", "track"]);
278
+ function parentsIn(html) {
279
+ const out = {};
280
+ const stack = [];
281
+ for (const m of html.matchAll(/<(\/?)([a-zA-Z][\w-]*)\b([^>]*)>/g)) {
282
+ const tag = m[2].toLowerCase();
283
+ if (m[1] === "/") {
284
+ const at = stack.map((s) => s.tag).lastIndexOf(tag);
285
+ if (at >= 0) stack.length = at;
286
+ continue;
287
+ }
288
+ const key = /\sdata-aic-key="([^"]*)"/.exec(m[3])?.[1] ?? null;
289
+ if (key !== null) out[key] = [...stack].reverse().find((s) => s.key !== null)?.key ?? null;
290
+ if (!VOID2.has(tag) && !m[3].trim().endsWith("/")) stack.push({ tag, key });
291
+ }
292
+ return out;
293
+ }
294
+ var stateSelector = (key) => `:is([data-aic-key="${key}"],#aic-none#aic-none#aic-none)`;
295
+
296
+ // packages/plugin-html-slides/src/samples.ts
297
+ var LINK_WORDS = ["next", "prev", "first", "last"];
298
+ var ARTWORK = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800"><defs><linearGradient id="s" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#f3d9b1"/><stop offset="1" stop-color="#c98f6b"/></linearGradient><linearGradient id="w" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#2f5d73"/><stop offset="1" stop-color="#1b3442"/></linearGradient></defs><rect width="1200" height="800" fill="url(#s)"/><circle cx="880" cy="250" r="120" fill="#fff4dc" opacity=".85"/><path d="M0 520 C200 470 360 560 600 520 S1000 470 1200 520 V800 H0Z" fill="url(#w)"/><g fill="#355e3b"><ellipse cx="260" cy="500" rx="90" ry="40"/><ellipse cx="420" cy="490" rx="60" ry="28"/><ellipse cx="760" cy="505" rx="110" ry="36"/></g><g fill="#9fb8c9" opacity=".7"><ellipse cx="1000" cy="470" rx="160" ry="30"/></g></svg>`;
299
+ var ARTWORK_URI = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ARTWORK)}`;
300
+ var LAYOUTS = [
301
+ {
302
+ key: "cover",
303
+ title: "\uD45C\uC9C0",
304
+ html: `<div class="page cover" data-aic-key="page">
305
+ <p class="kicker" data-aic-key="kicker">2026 \uAC00\uC744 \uAC15\uC758</p>
306
+ <h1 class="title" data-aic-key="title">\uBE5B\uC73C\uB85C \uADF8\uB9AC\uB294 \uD48D\uACBD</h1>
307
+ <p class="subtitle" data-aic-key="subtitle">\uC0C9\uACFC \uAC70\uB9AC\uC758 \uAE30\uCD08</p>
308
+ <a class="go" href="#next" data-aic-key="start">\uC2DC\uC791\uD558\uAE30</a>
309
+ </div>`,
310
+ elements: [
311
+ { key: "page", label: "\uD398\uC774\uC9C0 \uBC14\uD0D5", kind: "block" },
312
+ { key: "kicker", label: "\uBA38\uB9AC \uAE00", kind: "text" },
313
+ { key: "title", label: "\uC81C\uBAA9", kind: "text" },
314
+ { key: "subtitle", label: "\uBD80\uC81C", kind: "text" },
315
+ { key: "start", label: "\uC2DC\uC791\uD558\uAE30 \uB9C1\uD06C", kind: "link" }
316
+ ]
317
+ },
318
+ {
319
+ key: "list",
320
+ title: "\uC81C\uBAA9\uACFC \uBAA9\uB85D",
321
+ html: `<div class="page list" data-aic-key="page">
322
+ <h2 class="heading" data-aic-key="heading">\uC624\uB298 \uB2E4\uB8F0 \uAC83</h2>
323
+ <ul class="points" data-aic-key="points">
324
+ <li data-aic-key="point-1">\uBE5B\uC758 \uBC29\uD5A5\uACFC \uADF8\uB9BC\uC790</li>
325
+ <li data-aic-key="point-2">\uAC00\uAE4C\uC6B4 \uC0C9\uACFC \uBA3C \uC0C9</li>
326
+ <li data-aic-key="point-3">\uD55C \uC7A5\uBA74\uC5D0 \uD55C \uAC00\uC9C0 \uC911\uC2EC</li>
327
+ </ul>
328
+ </div>`,
329
+ elements: [
330
+ { key: "page", label: "\uD398\uC774\uC9C0 \uBC14\uD0D5", kind: "block" },
331
+ { key: "heading", label: "\uC81C\uBAA9", kind: "text" },
332
+ { key: "points", label: "\uBAA9\uB85D", kind: "block" },
333
+ { key: "point-1", label: "\uBAA9\uB85D 1", kind: "text" },
334
+ { key: "point-2", label: "\uBAA9\uB85D 2", kind: "text" },
335
+ { key: "point-3", label: "\uBAA9\uB85D 3", kind: "text" }
336
+ ]
337
+ },
338
+ {
339
+ key: "picture",
340
+ title: "\uADF8\uB9BC\uACFC \uC124\uBA85",
341
+ html: `<div class="page picture" data-aic-key="page">
342
+ <img class="art" src="asset:artwork" alt="\uAC15\uACFC \uC5B8\uB355 \uADF8\uB9BC" data-aic-key="art">
343
+ <div class="words" data-aic-key="words">
344
+ <h2 class="heading" data-aic-key="heading">\uBA3C \uACF3\uC740 \uC605\uAC8C</h2>
345
+ <p class="caption" data-aic-key="caption">\uBA40\uB9AC \uC788\uB294 \uC5B8\uB355\uC77C\uC218\uB85D \uD558\uB298\uC0C9\uC5D0 \uAC00\uAE4C\uC6CC\uC9C4\uB2E4.</p>
346
+ </div>
347
+ </div>`,
348
+ elements: [
349
+ { key: "page", label: "\uD398\uC774\uC9C0 \uBC14\uD0D5", kind: "block" },
350
+ { key: "art", label: "\uADF8\uB9BC", kind: "image" },
351
+ { key: "words", label: "\uC124\uBA85 \uBB36\uC74C", kind: "block" },
352
+ { key: "heading", label: "\uC81C\uBAA9", kind: "text" },
353
+ { key: "caption", label: "\uC124\uBA85", kind: "text" }
354
+ ]
355
+ },
356
+ {
357
+ key: "closing",
358
+ title: "\uB9C8\uBB34\uB9AC",
359
+ html: `<div class="page closing" data-aic-key="page">
360
+ <h2 class="title" data-aic-key="title">\uACE0\uB9D9\uC2B5\uB2C8\uB2E4</h2>
361
+ <p class="contact" data-aic-key="contact">\uC9C8\uBB38\uC740 \uAC15\uC758 \uAC8C\uC2DC\uD310\uC5D0 \uB0A8\uACA8 \uC8FC\uC138\uC694</p>
362
+ <a class="go" href="#first" data-aic-key="again">\uCC98\uC74C\uC73C\uB85C</a>
363
+ </div>`,
364
+ elements: [
365
+ { key: "page", label: "\uD398\uC774\uC9C0 \uBC14\uD0D5", kind: "block" },
366
+ { key: "title", label: "\uC81C\uBAA9", kind: "text" },
367
+ { key: "contact", label: "\uC548\uB0B4 \uAE00", kind: "text" },
368
+ { key: "again", label: "\uCC98\uC74C\uC73C\uB85C \uB9C1\uD06C", kind: "link" }
369
+ ]
370
+ }
371
+ ];
372
+ var LIGHT_CSS = `.aic-slide{background:#fbfaf7;color:#22262b;font-family:"Pretendard","Malgun Gothic",system-ui,sans-serif}
373
+ .page{position:absolute;inset:0;padding:120px 160px;box-sizing:border-box;display:flex;flex-direction:column}
374
+ .cover{justify-content:center;gap:28px}
375
+ .kicker{margin:0;font-size:32px;letter-spacing:.08em;color:#8a6d4b}
376
+ .cover .title{margin:0;font-size:120px;line-height:1.1;font-weight:700}
377
+ .subtitle{margin:0;font-size:44px;color:#5b636c}
378
+ .go{align-self:flex-start;margin-top:40px;font-size:32px;color:#1f6a8c;text-decoration:none;border-bottom:3px solid currentColor;padding-bottom:4px}
379
+ .go:hover{color:#0f3d52}
380
+ .heading{margin:0 0 56px;font-size:72px;line-height:1.15;font-weight:700}
381
+ .points{margin:0;padding:0 0 0 48px;font-size:44px;line-height:1.5;display:flex;flex-direction:column;gap:24px}
382
+ .points li::marker{color:#c98f6b}
383
+ .picture{flex-direction:row;align-items:center;gap:80px}
384
+ .art{width:960px;height:640px;object-fit:cover;border-radius:12px}
385
+ .words{flex:1}
386
+ .picture .heading{margin-bottom:32px}
387
+ .caption{margin:0;font-size:40px;line-height:1.5;color:#4a525b}
388
+ .closing{justify-content:center;align-items:center;text-align:center;gap:32px}
389
+ .closing .title{margin:0;font-size:132px;font-weight:700}
390
+ .contact{margin:0;font-size:40px;color:#5b636c}
391
+ .closing .go{align-self:center}
392
+ .aic-nav{font:28px/1 "Malgun Gothic",system-ui,sans-serif;color:#7a828b}
393
+ .aic-nav a,.aic-nav button{color:#1f6a8c;text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;padding:8px 12px}
394
+ .aic-nav a:hover,.aic-nav button:hover{color:#0f3d52}`;
395
+ var DARK_CSS = `.aic-slide{background:#111316;color:#f2efe8;font-family:"Pretendard","Malgun Gothic",system-ui,sans-serif}
396
+ .page{position:absolute;inset:0;padding:140px 180px;box-sizing:border-box;display:flex;flex-direction:column}
397
+ .cover{justify-content:flex-end;gap:20px;background:linear-gradient(160deg,#111316 55%,#2b2219)}
398
+ .kicker{margin:0;font-size:30px;letter-spacing:.2em;text-transform:uppercase;color:#e0a96d}
399
+ .cover .title{margin:0;font-size:156px;line-height:1.02;font-weight:800;letter-spacing:-.02em}
400
+ .subtitle{margin:0;font-size:48px;color:#b9b3a8}
401
+ .go{align-self:flex-start;margin-top:56px;font-size:34px;color:#111316;background:#e0a96d;text-decoration:none;border-radius:999px;padding:14px 40px}
402
+ .go:hover{background:#f3c48d}
403
+ .heading{margin:0 0 64px;font-size:84px;line-height:1.1;font-weight:800}
404
+ .points{margin:0;padding:0;list-style:none;font-size:48px;line-height:1.4;display:flex;flex-direction:column;gap:36px;counter-reset:p}
405
+ .points li{counter-increment:p;padding-left:96px;position:relative}
406
+ .points li::before{content:counter(p,decimal-leading-zero);position:absolute;left:0;color:#e0a96d;font-weight:700}
407
+ .picture{flex-direction:row-reverse;align-items:stretch;gap:0;padding:0}
408
+ .art{width:1100px;height:1080px;object-fit:cover}
409
+ .words{flex:1;padding:140px 96px;display:flex;flex-direction:column;justify-content:center}
410
+ .picture .heading{margin-bottom:40px;font-size:72px}
411
+ .caption{margin:0;font-size:40px;line-height:1.55;color:#b9b3a8}
412
+ .closing{justify-content:center;gap:28px}
413
+ .closing .title{margin:0;font-size:168px;font-weight:800;letter-spacing:-.02em}
414
+ .contact{margin:0;font-size:44px;color:#b9b3a8}
415
+ .aic-nav{font:28px/1 "Malgun Gothic",system-ui,sans-serif;color:#8d877c}
416
+ .aic-nav a,.aic-nav button{color:#e0a96d;text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;padding:8px 12px}
417
+ .aic-nav a:hover,.aic-nav button:hover{color:#f3c48d}`;
418
+ var SAMPLES = [
419
+ {
420
+ id: "light-lecture",
421
+ version: "1",
422
+ title: "\uBC1D\uC740 \uAC15\uC758",
423
+ about: "\uBC1D\uC740 \uBC14\uD0D5\uC5D0 \uC67C\uCABD \uC815\uB82C, \uC81C\uBAA9\uC740 \uD06C\uAC8C \uB450\uACE0 \uB0B4\uC6A9\uC740 \uC870\uC6A9\uD788 \uB530\uB77C\uC628\uB2E4. \uAC15\uC758\uB098 \uC124\uBA85\uC774 \uAE34 \uBC1C\uD45C\uC5D0 \uB9DE\uB294\uB2E4.",
424
+ css: LIGHT_CSS,
425
+ assets: { artwork: ARTWORK_URI },
426
+ layouts: LAYOUTS,
427
+ start: ["cover", "list", "picture", "closing"],
428
+ digest: ""
429
+ },
430
+ {
431
+ id: "dark-keynote",
432
+ version: "1",
433
+ title: "\uC5B4\uB450\uC6B4 \uBC1C\uD45C",
434
+ about: "\uC5B4\uB450\uC6B4 \uBC14\uD0D5\uC5D0 \uC544\uC8FC \uD070 \uC81C\uBAA9\uACFC \uD55C \uAC00\uC9C0 \uAC15\uC870\uC0C9. \uADF8\uB9BC\uC740 \uD398\uC774\uC9C0 \uC808\uBC18\uC744 \uCC44\uC6B4\uB2E4. \uBB34\uB300 \uBC1C\uD45C\uB098 \uC9E7\uC740 \uC18C\uAC1C\uC5D0 \uB9DE\uB294\uB2E4.",
435
+ css: DARK_CSS,
436
+ assets: { artwork: ARTWORK_URI },
437
+ layouts: LAYOUTS,
438
+ start: ["cover", "list", "picture", "closing"],
439
+ digest: ""
440
+ }
441
+ ];
442
+ var DIGESTS = {
443
+ "light-lecture@1": "75b2a9540b2233ec7ee16193b057a800483ff0866aee8be90bb5eb891dc51a4b",
444
+ "dark-keynote@1": "0d83158031b98f67fd8d7a112b56fed9b6eab44a6c242dc2bc760ba70bec5507"
445
+ };
446
+ for (const s of SAMPLES) s.digest = DIGESTS[`${s.id}@${s.version}`] ?? "";
447
+ var sampleById = (id) => SAMPLES.find((s) => s.id === id);
448
+ var layoutOf = (s, key) => s.layouts.find((l) => l.key === key);
449
+
450
+ // packages/plugin-html-slides/src/deck.ts
451
+ var SLIDE_W = 1920;
452
+ var SLIDE_H = 1080;
453
+ var AIAKIV_MAX = 5e4;
454
+ var STATES = ["none", "hover", "focus", "active"];
455
+ var STATE_SUFFIX = { none: "", hover: ":hover", focus: ":focus-visible", active: ":active" };
456
+ var isLinkWord = (v) => LINK_WORDS.includes(v);
457
+ var BASE_CSS = `html,body{margin:0;height:100%;background:#000;overflow:hidden}
458
+ .aic-stage{position:absolute;left:50%;top:50%;width:${SLIDE_W}px;height:${SLIDE_H}px;transform:translate(-50%,-50%) scale(var(--aic-scale,.5));transform-origin:50% 50%}
459
+ .aic-slide{position:absolute;inset:0;overflow:hidden}
460
+ .aic-slide[hidden]{display:none}
461
+ .aic-nav{position:absolute;right:48px;bottom:36px;display:flex;gap:16px;align-items:center;z-index:10}
462
+ .aic-nav [aria-disabled="true"]{opacity:.3;cursor:default}
463
+ .aic-nav [hidden]{display:none}`;
464
+ var DECK_RUNTIME = `(function(){
465
+ var W=${SLIDE_W},H=${SLIDE_H},root=document.documentElement;
466
+ var slides=Array.prototype.slice.call(document.querySelectorAll('.aic-slide'));
467
+ var cur=-1;
468
+ function fit(){var s=Math.min(window.innerWidth/W,window.innerHeight/H);if(!(s>0))s=.5;root.style.setProperty('--aic-scale',String(s));}
469
+ function indexOf(id){for(var i=0;i<slides.length;i++)if(slides[i].id===id)return i;return -1;}
470
+ function show(i,fromHash){
471
+ if(!slides.length)return;
472
+ i=Math.max(0,Math.min(slides.length-1,i));
473
+ if(i===cur)return;
474
+ cur=i;
475
+ for(var k=0;k<slides.length;k++){if(k===i)slides[k].removeAttribute('hidden');else slides[k].setAttribute('hidden','');}
476
+ if(!fromHash){try{if(location.hash!=='#'+slides[i].id)history.replaceState(null,'','#'+slides[i].id);}catch(e){}}
477
+ try{document.dispatchEvent(new CustomEvent('aic-deck-show',{detail:{id:slides[i].id,index:i}}));}catch(e){}
478
+ }
479
+ function go(x){if(typeof x==='number')show(x);else{var i=indexOf(String(x));if(i>=0)show(i);}}
480
+ function fullscreen(){var d=document;if(d.fullscreenElement){if(d.exitFullscreen)d.exitFullscreen();return;}if(d.fullscreenEnabled&&root.requestFullscreen)root.requestFullscreen().catch(function(){});}
481
+ document.addEventListener('click',function(e){
482
+ if(e.defaultPrevented)return;
483
+ var t=e.target&&e.target.closest?e.target:null;
484
+ if(t&&t.closest('.aic-fs')){e.preventDefault();fullscreen();return;}
485
+ var a=t?t.closest('a[href]'):null;
486
+ if(a){var h=a.getAttribute('href')||'';if(h.charAt(0)==='#'){e.preventDefault();if(a.getAttribute('aria-disabled')==='true')return;var i=indexOf(h.slice(1));if(i>=0)show(i);}return;}
487
+ if(t&&t.closest('button,input,select,textarea,summary,label'))return;
488
+ if(e.button===0)show(cur+1);
489
+ });
490
+ document.addEventListener('keydown',function(e){
491
+ if(e.altKey||e.ctrlKey||e.metaKey)return;
492
+ var k=e.key;
493
+ if(k==='ArrowRight'||k==='PageDown'||k===' '||k==='Spacebar')show(cur+1);
494
+ else if(k==='ArrowLeft'||k==='PageUp')show(cur-1);
495
+ else if(k==='Home')show(0);
496
+ else if(k==='End')show(slides.length-1);
497
+ else if(k==='f'||k==='F')fullscreen();
498
+ else return;
499
+ e.preventDefault();
500
+ });
501
+ window.addEventListener('hashchange',function(){var i=indexOf(location.hash.slice(1));if(i>=0)show(i,true);});
502
+ window.addEventListener('resize',fit);
503
+ if(document.fullscreenEnabled){var b=document.querySelectorAll('.aic-fs');for(var j=0;j<b.length;j++)b[j].removeAttribute('hidden');}
504
+ fit();
505
+ var start=indexOf(location.hash.slice(1));
506
+ show(start>=0?start:0,true);
507
+ window.aicDeck={go:go,next:function(){show(cur+1);},prev:function(){show(cur-1);},index:function(){return cur;},count:slides.length};
508
+ })();`;
509
+ var unescapeHtml = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&");
510
+ var KEY = /^[a-z0-9-]+$/;
511
+ var leafPattern = (key) => new RegExp(`(<([a-zA-Z][\\w-]*)\\b[^>]*\\sdata-aic-key="${key}"[^>]*>)([^<]*)(</\\2\\s*>)`);
512
+ var openTag = (key) => new RegExp(`<[a-zA-Z][\\w-]*\\b[^>]*\\sdata-aic-key="${key}"[^>]*>`);
513
+ function leafText(html, key) {
514
+ if (!KEY.test(key)) return null;
515
+ const m = leafPattern(key).exec(html);
516
+ return m ? unescapeHtml(m[3]).replace(/\s+/g, " ").trim() : null;
517
+ }
518
+ function linkOf(html, key) {
519
+ if (!KEY.test(key)) return null;
520
+ const tag = openTag(key).exec(html)?.[0];
521
+ const href = tag ? /\shref="#([a-z]+)"/.exec(tag)?.[1] : void 0;
522
+ return href && isLinkWord(href) ? href : null;
523
+ }
524
+ function applyText(html, key, text) {
525
+ return html.replace(leafPattern(key), (_all, open, _tag, _inner, close) => `${open}${escapeHtml(text)}${close}`);
526
+ }
527
+ function resolveTarget(target, order, self) {
528
+ const at = order.indexOf(self);
529
+ if (target === "next") return order[Math.min(order.length - 1, at + 1)] ?? self;
530
+ if (target === "prev") return order[Math.max(0, at - 1)] ?? self;
531
+ if (target === "first") return order[0] ?? self;
532
+ if (target === "last") return order[order.length - 1] ?? self;
533
+ return order.includes(target) ? target : self;
534
+ }
535
+ function resolveAssets(src, assets, css) {
536
+ return css ? src.replace(/url\(\s*(["']?)asset:([a-z0-9-]+)\1\s*\)/g, (_m, _q, k) => assets[k] ? `url("${assets[k]}")` : "none") : src.replace(/"asset:([a-z0-9-]+)"/g, (_m, k) => `"${escapeHtml(assets[k] ?? "")}"`);
537
+ }
538
+ function slideInnerHtml(slide, order, assets) {
539
+ let html = slide.content.html;
540
+ for (const { content: c } of slide.elements) if (c.text !== null) html = applyText(html, c.key, c.text);
541
+ for (const { content: c } of slide.elements) {
542
+ if (!c.link) continue;
543
+ const to = resolveTarget(c.link.target ?? c.link.original, order, slide.id);
544
+ html = html.replace(openTag(c.key), (tag) => tag.replace(/\shref="[^"]*"/, ` href="#${to}"`));
545
+ }
546
+ html = html.replace(/\shref="#(next|prev|first|last)"/g, (_m, w) => ` href="#${resolveTarget(w, order, slide.id)}"`);
547
+ const idOf = new Map(slide.elements.map((e) => [e.content.key, e.id]));
548
+ html = html.replace(/\sdata-aic-key="([^"]*)"/g, (m, k) => idOf.has(k) ? ` data-aic-key="${idOf.get(k)}"` : m);
549
+ return resolveAssets(html, assets, false);
550
+ }
551
+ var analysisHtml = (html) => `<section class="aic-slide">${html}</section>`;
552
+ function overrideCss(slides, themeCss) {
553
+ const out = [];
554
+ const cache = /* @__PURE__ */ new Map();
555
+ for (const s of slides) {
556
+ for (const { id, content: c } of s.elements) {
557
+ for (const state of STATES) {
558
+ const decl = c.styles[state];
559
+ if (!decl) continue;
560
+ const props = Object.keys(decl).sort();
561
+ if (props.length === 0) continue;
562
+ if (state !== "none") {
563
+ out.push(`${stateSelector(id)}${STATE_SUFFIX[state]}{${props.map((p) => `${p}:${decl[p]}`).join(";")}}`);
564
+ continue;
565
+ }
566
+ let info = cache.get(s.content.html);
567
+ if (!info) {
568
+ info = analyze(analysisHtml(s.content.html), themeCss);
569
+ cache.set(s.content.html, info);
570
+ }
571
+ const groups = /* @__PURE__ */ new Map();
572
+ for (const p of props) {
573
+ const sel = selectorWithSpec(id, normalSpec(info, c.key, p, "all", 0).spec);
574
+ groups.set(sel, [...groups.get(sel) ?? [], `${p}:${decl[p]}`]);
575
+ }
576
+ for (const [sel, list] of groups) out.push(`${sel}{${list.join(";")}}`);
577
+ }
578
+ }
579
+ }
580
+ return out.length ? `
581
+ /* aic.html-slides: \uBC14\uAFBC \uC2A4\uD0C0\uC77C */
582
+ ${out.join("\n")}` : "";
583
+ }
584
+ function keepsOriginalState(layoutHtml, themeCss, key, property) {
585
+ return normalSpec(analyze(analysisHtml(layoutHtml), themeCss), key, property, "all", 0).preserved;
586
+ }
587
+ function navHtml(order, at) {
588
+ const prev = order[at - 1];
589
+ const next = order[at + 1];
590
+ const link = (cls, to, word) => `<a class="${cls}" href="#${to ?? order[at]}"${to ? "" : ' aria-disabled="true"'}>${word}</a>`;
591
+ return `<nav class="aic-nav" aria-label="\uD398\uC774\uC9C0 \uC774\uB3D9">${link("aic-prev", prev, "\uC774\uC804")}<span class="aic-num">${at + 1} / ${order.length}</span>${link("aic-next", next, "\uB2E4\uC74C")}<button type="button" class="aic-fs" hidden>\uC804\uCCB4\uD654\uBA74</button></nav>`;
592
+ }
593
+ function deckBody(deck, slides) {
594
+ const order = deck.order.filter((id) => slides.some((s) => s.id === id));
595
+ const byId = new Map(slides.map((s) => [s.id, s]));
596
+ const sections = order.map((id, i) => {
597
+ const s = byId.get(id);
598
+ return `<section class="aic-slide" id="${id}" data-aic-slide="${id}" aria-label="${i + 1}\uCABD"${i > 0 ? " hidden" : ""}>
599
+ ${slideInnerHtml(s, order, deck.assets)}
600
+ ${navHtml(order, i)}
601
+ </section>`;
602
+ });
603
+ const css = `${BASE_CSS}
604
+ ${resolveAssets(deck.css, deck.assets, true)}${overrideCss(order.map((id) => byId.get(id)), deck.css)}`;
605
+ return { html: `<div class="aic-stage">
606
+ ${sections.join("\n")}
607
+ </div>`, css };
608
+ }
609
+ function documentHtml(title, body, meta, script) {
610
+ return `<!doctype html>
611
+ <html lang="ko">
612
+ <head>
613
+ <meta charset="utf-8">
614
+ <meta name="viewport" content="width=device-width, initial-scale=1">
615
+ <meta name="generator" content="${escapeHtml(meta)}">
616
+ <title>${escapeHtml(title)}</title>
617
+ <style>
618
+ ${body.css}
619
+ </style>
620
+ </head>
621
+ <body>
622
+ ${body.html}
623
+ ${script === null ? "" : `<script>
624
+ ${script}
625
+ </script>
626
+ `}</body>
627
+ </html>
628
+ `;
629
+ }
630
+ function pageSource(deck, slide, title, meta) {
631
+ const css = `${BASE_CSS}
632
+ ${resolveAssets(deck.css, deck.assets, true)}${overrideCss([slide], deck.css)}`;
633
+ const html = `<div class="aic-stage">
634
+ <section class="aic-slide" id="${slide.id}" data-aic-slide="${slide.id}">
635
+ ${slideInnerHtml(slide, deck.order, deck.assets)}
636
+ </section>
637
+ </div>`;
638
+ return documentHtml(title, { html, css }, meta, null);
639
+ }
640
+
641
+ // packages/plugin-html-slides/src/logic.ts
642
+ var PACKAGE_ID = "aic.html-slides";
643
+ var VERSION = "0.1.5";
644
+ var SELECTION_FORMAT = "aic.html-slides/selection-1";
645
+ var Reject = class extends Error {
646
+ constructor(code, message) {
647
+ super(message);
648
+ this.code = code;
649
+ }
650
+ code;
651
+ };
652
+ var all = (s, type) => Object.values(s.records).filter((r) => r.type === type);
653
+ var idNumber = (id) => Number(id.replace(/\D/g, ""));
654
+ var byIdNumber = (a, b) => idNumber(a.id) - idNumber(b.id) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
655
+ var deckOf = (s) => all(s, "deck").sort(byIdNumber)[0];
656
+ var dk = (r) => r.content;
657
+ var sl = (r) => r.content;
658
+ var el = (r) => r.content;
659
+ var elementsOf = (s, slide) => all(s, "element").filter((r) => el(r).slide === slide).sort(byIdNumber);
660
+ var STATE_WORD = { none: "", hover: " (hover)", focus: " (keyboard focus)", active: " (while pressed)" };
661
+ var LINK_WORD = { next: "next page", prev: "previous page", first: "first page", last: "last page" };
662
+ function need(s, id, type, what) {
663
+ if (typeof id !== "string" || id === "") throw new Reject("INVALID_INPUT", `${what} needs an id`);
664
+ const r = s.records[id];
665
+ if (!r) throw new Reject("TARGET_NOT_FOUND", `Cannot find ${what} ${id}`);
666
+ if (r.type !== type) throw new Reject("INVALID_INPUT", `${id} is not a ${what}`);
667
+ return r;
668
+ }
669
+ function needDeck(s) {
670
+ const d = deckOf(s);
671
+ if (!d) throw new Reject("INVALID_STATE", "There is no deck yet. Start one with deck.start first");
672
+ return d;
673
+ }
674
+ function textInput(v, what, ctx, max = 2e3) {
675
+ if (typeof v !== "string") throw new Reject("INVALID_INPUT", `${what} must be text`);
676
+ const t = v.replace(/\r\n?/g, "\n").trim();
677
+ if (t.length > max) throw new Reject("INVALID_INPUT", `${what} is longer than ${max} characters`);
678
+ if (ctx.tempNames.includes(t)) throw new Reject("INVALID_INPUT", `"${t}" is a temporary name in this request, so it cannot be used as text`);
679
+ return t;
680
+ }
681
+ function oneOf(v, list, what, fallback) {
682
+ if (v === void 0 || v === null || v === "") return fallback;
683
+ if (typeof v !== "string" || !list.includes(v)) throw new Reject("INVALID_INPUT", `${what} must be one of ${list.join(", ")}`);
684
+ return v;
685
+ }
686
+ function sourceInput(v) {
687
+ if (v === void 0 || v === null) return void 0;
688
+ const x = v;
689
+ if (typeof v !== "object" || typeof x.sample !== "string" || typeof x.layout !== "string" || typeof x.key !== "string") {
690
+ throw new Reject("INVALID_INPUT", "source is { sample: sample id, layout: layout key, key: element key }");
691
+ }
692
+ const found = sampleById(x.sample);
693
+ if (!found) throw new Reject("TARGET_NOT_FOUND", `There is no built-in sample ${x.sample}. Available samples: ${SAMPLES.map((s) => s.id).join(", ")}`);
694
+ const layout = layoutOf(found, x.layout);
695
+ if (!layout) throw new Reject("TARGET_NOT_FOUND", `Sample ${x.sample} has no layout ${x.layout}`);
696
+ if (!layout.elements.some((e) => e.key === x.key)) throw new Reject("TARGET_NOT_FOUND", `Layout ${x.layout} has no element key ${x.key}`);
697
+ return { sample: x.sample, version: found.version, layout: x.layout, key: x.key };
698
+ }
699
+ function slideChanges(sample, layout, deck, id, first) {
700
+ const problems = sourceProblems(layout.html, sample.css);
701
+ if (problems.length) throw new Reject("INVALID_STATE", `Layout ${layout.key} of sample ${sample.id} did not pass the check: ${problems.join("; ")}`);
702
+ const slideId = id(first);
703
+ const content = { deck, layout: { sample: sample.id, version: sample.version, key: layout.key, title: layout.title }, html: layout.html };
704
+ const parents = parentsIn(layout.html);
705
+ const changes = [{ id: slideId, type: "slide", prefix: "sl", after: content }];
706
+ layout.elements.forEach((e, i) => {
707
+ const link = e.kind === "link" ? linkOf(layout.html, e.key) : null;
708
+ const c = {
709
+ slide: slideId,
710
+ key: e.key,
711
+ label: e.label,
712
+ kind: e.kind,
713
+ parent: parents[e.key] ?? null,
714
+ original: e.kind === "text" || e.kind === "link" ? leafText(layout.html, e.key) : null,
715
+ text: null,
716
+ styles: {},
717
+ sources: {},
718
+ link: link ? { original: link, target: null } : null
719
+ };
720
+ changes.push({ id: id(first + 1 + i), type: "element", prefix: "se", after: c });
721
+ });
722
+ return changes;
723
+ }
724
+ function sampleOfDeck(d) {
725
+ const sample = sampleById(d.sample.id);
726
+ if (!sample || sample.version !== d.sample.version) throw new Reject("INVALID_STATE", `Cannot find the layouts of sample ${d.sample.id} version ${d.sample.version} in this plugin version`);
727
+ return sample;
728
+ }
729
+ function insertAfter(order, item, after, s) {
730
+ const rest = order.filter((x) => x !== item);
731
+ if (after === void 0) return [...rest, item];
732
+ if (after === null || after === "") return [item, ...rest];
733
+ if (typeof after !== "string") throw new Reject("INVALID_INPUT", "after is a page id, or null for the front");
734
+ need(s, after, "slide", "page before it");
735
+ const at = rest.indexOf(after);
736
+ if (at < 0) throw new Reject("INVALID_INPUT", `${after} is not in the order of this deck`);
737
+ return [...rest.slice(0, at + 1), item, ...rest.slice(at + 1)];
738
+ }
739
+ function slideParts(s, slideId) {
740
+ const r = s.records[slideId];
741
+ return { id: slideId, content: sl(r), elements: elementsOf(s, slideId).map((e) => ({ id: e.id, content: el(e) })) };
742
+ }
743
+ function slideTitle(s, slideId) {
744
+ const els = elementsOf(s, slideId);
745
+ const t = els.find((e) => ["title", "heading"].includes(el(e).key));
746
+ return t ? el(t).text ?? el(t).original ?? "" : "";
747
+ }
748
+ var metaOf = (deckId, d, extra = "") => `${PACKAGE_ID} ${VERSION}; deck ${deckId}; sample ${d.sample.id}@${d.sample.version} ${d.sample.digest}${extra}`;
749
+ function pageLengths(s, deckRec) {
750
+ const d = dk(deckRec);
751
+ return d.order.filter((id) => s.records[id]?.type === "slide").map((id) => {
752
+ const length = pageSource(d, slideParts(s, id), slideTitle(s, id) || d.sample.title, metaOf(deckRec.id, d, `; slide ${id}`)).length;
753
+ return { id, length, aiakiv: length <= AIAKIV_MAX };
754
+ });
755
+ }
756
+ var label = (r) => `${r.id}(${el(r).label})`;
757
+ var pageNo = (s, slideId) => {
758
+ const d = deckOf(s);
759
+ const at = d ? dk(d).order.indexOf(slideId) : -1;
760
+ return at >= 0 ? `page ${at + 1}` : "not in the order";
761
+ };
762
+ var OPERATIONS = {
763
+ "deck.start": (s, input, id, ctx) => {
764
+ const existing = deckOf(s);
765
+ if (existing) throw new Reject("INVALID_STATE", `There is only one deck. ${existing.id} already started from sample ${dk(existing).sample.id} version ${dk(existing).sample.version}`);
766
+ if (typeof input.sample !== "string") throw new Reject("INVALID_INPUT", `Give a built-in sample id in sample: ${SAMPLES.map((x) => x.id).join(", ")}`);
767
+ const sample = sampleById(input.sample);
768
+ if (!sample) throw new Reject("TARGET_NOT_FOUND", `There is no built-in sample ${input.sample}. Available samples: ${SAMPLES.map((x) => x.id).join(", ")}`);
769
+ const reason = textInput(input.reason ?? "", "reason", ctx, 1e3);
770
+ if (reason === "") throw new Reject("INVALID_INPUT", "Write the reason. It shows later why the deck started from this sample");
771
+ const changes = [];
772
+ const order = [];
773
+ let k = 1;
774
+ for (const key of sample.start) {
775
+ const layout = layoutOf(sample, key);
776
+ order.push(id(k));
777
+ changes.push(...slideChanges(sample, layout, id(0), id, k));
778
+ k += 1 + layout.elements.length;
779
+ }
780
+ const deck = {
781
+ sample: { id: sample.id, version: sample.version, digest: sample.digest, title: sample.title },
782
+ reason,
783
+ css: sample.css,
784
+ assets: { ...sample.assets },
785
+ order
786
+ };
787
+ return {
788
+ changes: [{ id: id(0), type: "deck", prefix: "dk", after: deck }, ...changes],
789
+ summary: `Deck started (${id(0)}): sample ${sample.id} (${sample.title}) version ${sample.version}, ${order.length} pages (${sample.start.map((x) => layoutOf(sample, x).title).join(", ")}). Reason: ${reason}`
790
+ };
791
+ },
792
+ "slide.add": (s, input, id) => {
793
+ const deckRec = needDeck(s);
794
+ const d = dk(deckRec);
795
+ const sample = sampleOfDeck(d);
796
+ if (typeof input.layout !== "string") throw new Reject("INVALID_INPUT", `Give a layout key in layout: ${sample.layouts.map((l) => `${l.key}(${l.title})`).join(", ")}`);
797
+ const layout = layoutOf(sample, input.layout);
798
+ if (!layout) throw new Reject("TARGET_NOT_FOUND", `There is no layout ${input.layout}. Available layouts: ${sample.layouts.map((l) => `${l.key}(${l.title})`).join(", ")}`);
799
+ const order = insertAfter(d.order, id(0), input.after, s);
800
+ return {
801
+ changes: [...slideChanges(sample, layout, deckRec.id, id, 0), { id: deckRec.id, type: "deck", after: { ...d, order } }],
802
+ summary: `Page added (${id(0)}): ${layout.title} layout, page ${order.indexOf(id(0)) + 1} of ${order.length}`
803
+ };
804
+ },
805
+ "slide.remove": (s, input) => {
806
+ const deckRec = needDeck(s);
807
+ const d = dk(deckRec);
808
+ const r = need(s, input.slide, "slide", "page");
809
+ if (d.order.length <= 1) throw new Reject("INVALID_STATE", "The last remaining page cannot be removed");
810
+ const order = d.order.filter((x) => x !== r.id);
811
+ const changes = [{ id: r.id, type: "slide", after: null }];
812
+ for (const e of elementsOf(s, r.id)) changes.push({ id: e.id, type: "element", after: null });
813
+ const moved = [];
814
+ for (const e of all(s, "element").sort(byIdNumber)) {
815
+ const c = el(e);
816
+ if (c.slide === r.id || !c.link || c.link.target !== r.id) continue;
817
+ changes.push({ id: e.id, type: "element", after: { ...c, link: { ...c.link, target: c.link.original === "next" ? null : "next" } } });
818
+ moved.push(label(e));
819
+ }
820
+ changes.push({ id: deckRec.id, type: "deck", after: { ...d, order } });
821
+ return {
822
+ changes,
823
+ summary: `Page removed (${r.id}, ${sl(r).layout.title}, page ${d.order.indexOf(r.id) + 1}). ${order.length} pages left${moved.length ? `. Links ${moved.join(", ")} that pointed to this page now go to the next page` : ""}`
824
+ };
825
+ },
826
+ "slide.move": (s, input) => {
827
+ const deckRec = needDeck(s);
828
+ const d = dk(deckRec);
829
+ const r = need(s, input.slide, "slide", "page");
830
+ if (!("after" in input)) throw new Reject("INVALID_INPUT", "Give the id of the page that comes before it in after. Use null for the front");
831
+ if (input.after === r.id) throw new Reject("INVALID_INPUT", "A page cannot be moved after itself");
832
+ const order = insertAfter(d.order, r.id, input.after, s);
833
+ const from = d.order.indexOf(r.id) + 1;
834
+ const to = order.indexOf(r.id) + 1;
835
+ return {
836
+ changes: [{ id: deckRec.id, type: "deck", after: { ...d, order } }],
837
+ summary: from === to ? `Page ${r.id}: the order is unchanged (page ${to})` : `Moved page ${r.id} (${sl(r).layout.title}) from page ${from} to page ${to}`
838
+ };
839
+ },
840
+ "text.set": (s, input, _id, ctx) => {
841
+ const r = need(s, input.element, "element", "element");
842
+ const c = el(r);
843
+ if (c.original === null) throw new Reject("INVALID_INPUT", `${label(r)} is not an element with text (${c.kind})`);
844
+ const text = textInput(input.text, "text", ctx);
845
+ if (text === "") throw new Reject("INVALID_INPUT", "The text is empty. To go back to the original text, give that text as it is");
846
+ const next = text === c.original ? null : text;
847
+ const before = c.text ?? c.original;
848
+ const summary = before === text ? `${label(r)} text: no change` : `${pageNo(s, c.slide)} ${label(r)} text "${before}" to "${text}"${next === null ? " (original text)" : ""}`;
849
+ return { changes: [{ id: r.id, type: "element", after: { ...c, text: next } }], summary };
850
+ },
851
+ "style.set": (s, input) => {
852
+ const r = need(s, input.element, "element", "element");
853
+ const c = el(r);
854
+ if (typeof input.property !== "string") throw new Reject("INVALID_INPUT", "Give a CSS property name in property");
855
+ const property = input.property.trim().toLowerCase();
856
+ if (typeof input.value !== "string") throw new Reject("INVALID_INPUT", "value is text. To remove this change, give empty text");
857
+ if (input.media !== void 0 && input.media !== "all") throw new Reject("INVALID_INPUT", "Slide pages are fixed at 1920\xD71080, so there is no media");
858
+ const value = input.value.trim();
859
+ const state = oneOf(input.state, STATES, "state", "none");
860
+ if (value !== "") {
861
+ const bad = valueProblem(property, value);
862
+ if (bad) throw new Reject("INVALID_INPUT", bad);
863
+ } else if (!PROPERTIES.has(property)) throw new Reject("INVALID_INPUT", `${property} is not a property you can change in the first version`);
864
+ const source = sourceInput(input.source);
865
+ const decl = { ...c.styles[state] ?? {} };
866
+ const before = decl[property];
867
+ if (value === "") delete decl[property];
868
+ else decl[property] = value;
869
+ const styles = { ...c.styles };
870
+ if (Object.keys(decl).length) styles[state] = decl;
871
+ else delete styles[state];
872
+ const sources = { ...c.sources };
873
+ const sk = `${state}|${property}`;
874
+ if (source && value !== "") sources[sk] = source;
875
+ else delete sources[sk];
876
+ const slideRec = s.records[c.slide];
877
+ const deckRec = deckOf(s);
878
+ const keeps = state === "none" && slideRec?.type === "slide" && deckRec && keepsOriginalState(sl(slideRec).html, dk(deckRec).css, c.key, property);
879
+ const where = `${pageNo(s, c.slide)} ${label(r)}${STATE_WORD[state]}`;
880
+ const summary = value === "" ? before === void 0 ? `${where} ${property}: no change to remove` : `${where} ${property} change removed (back to the original CSS)` : `${where} ${property}: ${before ?? "original"} to ${value}${source ? ` (reference: ${source.sample}@${source.version} ${source.layout}/${source.key})` : ""}${keeps ? ". The original state styles, such as hover, stay as they are" : ""}`;
881
+ return { changes: [{ id: r.id, type: "element", after: { ...c, styles, sources } }], summary };
882
+ },
883
+ "link.set": (s, input) => {
884
+ const r = need(s, input.element, "element", "element");
885
+ const c = el(r);
886
+ if (!c.link) throw new Reject("INVALID_INPUT", `${label(r)} is not a link element (${c.kind})`);
887
+ if (typeof input.target !== "string" || input.target === "") throw new Reject("INVALID_INPUT", `target is ${LINK_WORDS.join(", ")} or a page id`);
888
+ const target = input.target;
889
+ if (!isLinkWord(target)) {
890
+ need(s, target, "slide", "link target page");
891
+ const d = deckOf(s);
892
+ if (!d || !dk(d).order.includes(target)) throw new Reject("INVALID_INPUT", `${target} is not in the order of this deck`);
893
+ }
894
+ const next = target === c.link.original ? null : target;
895
+ const word = (t) => LINK_WORD[t] ?? `${t}(${pageNo(s, t)})`;
896
+ const before = c.link.target ?? c.link.original;
897
+ return {
898
+ changes: [{ id: r.id, type: "element", after: { ...c, link: { ...c.link, target: next } } }],
899
+ summary: before === target ? `${label(r)} link: no change` : `${pageNo(s, c.slide)} ${label(r)} link target ${word(before)} to ${word(target)}${next === null ? " (original target)" : ""}`
900
+ };
901
+ }
902
+ };
903
+ function refsOf(r) {
904
+ if (r.type === "element") {
905
+ const c = el(r);
906
+ const out = [{ from: r.id, to: c.slide, kind: "slide" }];
907
+ if (c.link?.target && !isLinkWord(c.link.target)) out.push({ from: r.id, to: c.link.target, kind: "link" });
908
+ return out;
909
+ }
910
+ if (r.type === "slide") return [{ from: r.id, to: sl(r).deck, kind: "deck" }];
911
+ return [];
912
+ }
913
+ function validate(candidate, changed) {
914
+ const out = [];
915
+ const err = (record, code, message) => out.push({ level: "error", code, record, message });
916
+ const decks = all(candidate, "deck");
917
+ if (decks.length > 1) err(decks.map((p) => p.id).find((x) => changed.includes(x)) ?? decks[1].id, "second_deck", `There is only one deck: ${decks.map((p) => p.id).join(", ")}`);
918
+ const deck = decks.sort(byIdNumber)[0];
919
+ if (deck && changed.includes(deck.id)) {
920
+ const order = dk(deck).order;
921
+ if (new Set(order).size !== order.length) err(deck.id, "duplicate_slide", "The same page appears twice in the order");
922
+ for (const id of order) if (candidate.records[id]?.type !== "slide") err(deck.id, "dangling_ref", `${id} in the order is not a page`);
923
+ if (order.length === 0) err(deck.id, "empty_deck", "There are no pages");
924
+ }
925
+ for (const r of all(candidate, "slide")) {
926
+ if (!changed.includes(r.id)) continue;
927
+ if (candidate.records[sl(r).deck]?.type !== "deck") err(r.id, "dangling_ref", `The deck ${sl(r).deck} that ${r.id} points to does not exist`);
928
+ if (deck && !dk(deck).order.includes(r.id)) err(r.id, "orphan_slide", `${r.id} is not in the order`);
929
+ }
930
+ const seen = /* @__PURE__ */ new Map();
931
+ for (const r of all(candidate, "element").sort(byIdNumber)) {
932
+ const c = el(r);
933
+ const k = `${c.slide}|${c.key}`;
934
+ if (seen.has(k) && changed.includes(r.id)) err(r.id, "duplicate_key", `Element key ${c.key} is the same as in ${seen.get(k)}`);
935
+ seen.set(k, r.id);
936
+ if (c.link?.target && !isLinkWord(c.link.target) && candidate.records[c.link.target]?.type !== "slide") err(r.id, "dangling_link", `The link target ${c.link.target} of ${r.id} does not exist`);
937
+ if (!changed.includes(r.id)) continue;
938
+ if (candidate.records[c.slide]?.type !== "slide") err(r.id, "dangling_ref", `The page ${c.slide} that ${r.id} points to does not exist`);
939
+ }
940
+ return out;
941
+ }
942
+ function elementViews(s, slideId, order) {
943
+ const list = elementsOf(s, slideId);
944
+ const idByKey = new Map(list.map((r) => [el(r).key, r.id]));
945
+ return list.map((r) => {
946
+ const c = el(r);
947
+ return {
948
+ id: r.id,
949
+ key: c.key,
950
+ label: c.label,
951
+ kind: c.kind,
952
+ parent: c.parent ? idByKey.get(c.parent) ?? null : null,
953
+ original: c.original,
954
+ text: c.text,
955
+ styles: c.styles,
956
+ sources: c.sources,
957
+ link: c.link ? { ...c.link, resolved: resolveTarget(c.link.target ?? c.link.original, order, slideId) } : null
958
+ };
959
+ });
960
+ }
961
+ function styleLines(v) {
962
+ const out = [];
963
+ for (const state of STATES) {
964
+ const decl = v.styles[state];
965
+ if (!decl) continue;
966
+ for (const p of Object.keys(decl).sort()) {
967
+ const src = v.sources[`${state}|${p}`];
968
+ out.push(`${state === "none" ? "normal" : STATE_WORD[state].trim()} ${p}: ${decl[p]}${src ? ` (reference: ${src.sample}@${src.version} ${src.layout}/${src.key})` : ""}`);
969
+ }
970
+ }
971
+ return out;
972
+ }
973
+ function conceptText(s, slideIds, elementIds, mine) {
974
+ const starred = new Set(mine.flatMap((m) => m.changes.filter((c) => c.after !== null).map((c) => c.record)));
975
+ const star = (id) => starred.has(id) ? " *" : "";
976
+ const catalog = SAMPLES.map((x) => `- ${x.id} (${x.title}) version ${x.version}: ${x.about} Layouts: ${x.layouts.map((l) => `${l.key}(${l.title})`).join(", ")}`);
977
+ const deckRec = deckOf(s);
978
+ if (!deckRec) {
979
+ return [
980
+ "There is no deck yet. The person looks at the two built-in presentation samples one at a time on the screen.",
981
+ ...catalog,
982
+ "Record the sample the person picked and the reason with deck.start. Before that, ask the person which one they prefer."
983
+ ].join("\n");
984
+ }
985
+ const d = dk(deckRec);
986
+ const lengths = new Map(pageLengths(s, deckRec).map((x) => [x.id, x]));
987
+ const lines = [
988
+ `Deck (${deckRec.id})${star(deckRec.id)}: sample ${d.sample.id} (${d.sample.title}) version ${d.sample.version}, digest ${d.sample.digest.slice(0, 12)}`,
989
+ `Reason: ${d.reason}`,
990
+ `Pages are fixed at ${SLIDE_W}\xD7${SLIDE_H} CSS px and scale to fit the window. A navigation bar with previous, page number and next is added to every page automatically.`,
991
+ `${d.order.length} pages. A page whose source is ${AIAKIV_MAX} characters or fewer can be saved to AiAkiv.`
992
+ ];
993
+ const showIds = slideIds ?? d.order;
994
+ for (const id of d.order) {
995
+ const r = s.records[id];
996
+ if (!r || r.type !== "slide") continue;
997
+ const len = lengths.get(id);
998
+ const head = `Page ${d.order.indexOf(id) + 1} (${id})${star(id)} ${sl(r).layout.title}: "${slideTitle(s, id)}", source ${len?.length ?? 0} characters, ${len?.aiakiv ? "can be saved to AiAkiv" : "cannot use AiAkiv (over 50,000 characters)"}`;
999
+ lines.push("", head);
1000
+ if (!showIds.includes(id) && !elementIds) continue;
1001
+ const views = elementViews(s, id, d.order);
1002
+ const byId = new Map(views.map((v) => [v.id, v]));
1003
+ const depth = (v) => {
1004
+ let n = 0;
1005
+ for (let x = v.parent; x && n < 20; x = byId.get(x)?.parent ?? null) n += 1;
1006
+ return n;
1007
+ };
1008
+ for (const v of views) {
1009
+ if (elementIds && !elementIds.includes(v.id)) continue;
1010
+ const pad = elementIds ? " " : " ".repeat(depth(v) + 1);
1011
+ const now = v.text ?? v.original;
1012
+ const words = now === null ? "" : v.text !== null ? ` "${now}" (original "${v.original}")` : ` "${now}"`;
1013
+ const link = v.link ? ` link: ${LINK_WORD[v.link.target ?? v.link.original] ?? v.link.target}${v.link.target !== null ? ` (original ${LINK_WORD[v.link.original] ?? v.link.original})` : ""}, now goes to ${v.link.resolved} (page ${d.order.indexOf(v.link.resolved) + 1})` : "";
1014
+ lines.push(`${pad}- (${v.id})${star(v.id)} ${v.label} [${v.kind}]${words}${link}`);
1015
+ for (const st of styleLines(v)) lines.push(`${pad} style ${st}`);
1016
+ }
1017
+ }
1018
+ const sample = sampleById(d.sample.id);
1019
+ lines.push(
1020
+ "",
1021
+ `Layouts you can add: ${sample ? sample.layouts.map((l) => `${l.key}(${l.title})`).join(", ") : "sample not found"}`,
1022
+ "Built-in samples you can refer to",
1023
+ ...catalog,
1024
+ "",
1025
+ "The position, size, line count and spacing of elements are known only after the screen draws them. The place the person points at on the screen comes as a selection, with the measurements at that time (CSS px on the page)."
1026
+ );
1027
+ if (slideIds && slideIds.length === 1 && !elementIds) {
1028
+ const id = slideIds[0];
1029
+ lines.push("", `Source of ${id} (${lengths.get(id)?.length ?? 0} characters)`, "```html", pageSource(d, slideParts(s, id), slideTitle(s, id) || d.sample.title, metaOf(deckRec.id, d, `; slide ${id}`)), "```");
1030
+ }
1031
+ return lines.join("\n");
1032
+ }
1033
+ function scopeIds(s, scope) {
1034
+ const ids = scope?.targets ?? (scope?.target !== void 0 ? [scope.target] : null);
1035
+ if (ids === null) return { slides: null, elements: null };
1036
+ const slides = [];
1037
+ const elements = [];
1038
+ for (const id of ids) {
1039
+ const r = s.records[id];
1040
+ if (!r) throw new Reject("TARGET_NOT_FOUND", `Cannot find ${id} to narrow the read`);
1041
+ if (r.type === "slide") slides.push(id);
1042
+ else if (r.type === "element") elements.push(id);
1043
+ else throw new Reject("INVALID_INPUT", `To narrow the read, use a page (sl) or element (se) id. ${id} is a ${r.type}`);
1044
+ }
1045
+ if (slides.length && elements.length) throw new Reject("INVALID_INPUT", "Do not narrow to pages and elements at the same time");
1046
+ return { slides: slides.length ? slides : null, elements: elements.length ? elements : null };
1047
+ }
1048
+ function catalogDoc(sample) {
1049
+ const order = sample.start.map((k) => `${sample.id}-${k}`);
1050
+ const deck = { sample: { id: sample.id, version: sample.version, digest: sample.digest, title: sample.title }, reason: "", css: sample.css, assets: sample.assets, order };
1051
+ const slides = sample.start.map((k, i) => {
1052
+ const layout = layoutOf(sample, k);
1053
+ return {
1054
+ id: order[i],
1055
+ content: { deck: "", layout: { sample: sample.id, version: sample.version, key: k, title: layout.title }, html: layout.html },
1056
+ elements: layout.elements.map((e) => ({ id: `${k}.${e.key}`, content: { slide: order[i], key: e.key, label: e.label, kind: e.kind, parent: null, original: null, text: null, styles: {}, sources: {}, link: null } }))
1057
+ };
1058
+ });
1059
+ return deckBody(deck, slides);
1060
+ }
1061
+ function project(s, scope, mine) {
1062
+ const { slides: slideIds, elements: elementIds } = scopeIds(s, scope);
1063
+ const deckRec = deckOf(s);
1064
+ const d = deckRec ? dk(deckRec) : null;
1065
+ const order = d ? d.order.filter((id) => s.records[id]?.type === "slide") : [];
1066
+ const lengths = deckRec ? new Map(pageLengths(s, deckRec).map((x) => [x.id, x])) : /* @__PURE__ */ new Map();
1067
+ const narrowed = slideIds ?? elementIds;
1068
+ return {
1069
+ text: conceptText(s, slideIds, elementIds, mine),
1070
+ scopeLabel: narrowed ? `Read ${narrowed.join(", ")}` : "Read everything",
1071
+ // 화면은 이것으로 그린다. current 는 저장하는 파일과 같은 함수(deckBody)에서 나온다
1072
+ json: {
1073
+ package: { id: PACKAGE_ID, version: VERSION },
1074
+ size: { width: SLIDE_W, height: SLIDE_H },
1075
+ aiakivMax: AIAKIV_MAX,
1076
+ runtime: DECK_RUNTIME,
1077
+ deck: deckRec && d ? { id: deckRec.id, sample: d.sample, reason: d.reason, order } : null,
1078
+ current: deckRec && d ? deckBody(d, order.map((id) => slideParts(s, id))) : null,
1079
+ slides: order.map((id, i) => ({
1080
+ id,
1081
+ number: i + 1,
1082
+ layout: sl(s.records[id]).layout,
1083
+ title: slideTitle(s, id),
1084
+ length: lengths.get(id)?.length ?? 0,
1085
+ aiakiv: lengths.get(id)?.aiakiv ?? false,
1086
+ elements: elementViews(s, id, order)
1087
+ })),
1088
+ catalog: SAMPLES.map((x) => ({
1089
+ id: x.id,
1090
+ version: x.version,
1091
+ title: x.title,
1092
+ about: x.about,
1093
+ digest: x.digest,
1094
+ layouts: x.layouts.map((l) => ({ key: l.key, title: l.title, elements: l.elements })),
1095
+ start: x.start,
1096
+ doc: catalogDoc(x)
1097
+ }))
1098
+ },
1099
+ ...narrowed ? { records: narrowed } : {}
1100
+ };
1101
+ }
1102
+ var px = (n) => `${Math.round(n * 10) / 10}`;
1103
+ var boxText = (b) => b ? `x ${px(b.x)}, y ${px(b.y)}, ${px(b.width)}\xD7${px(b.height)}${b.lines ? `, ${b.lines} lines` : ""}${b.fontSize ? `, font ${b.fontSize}` : ""}` : "no measurements";
1104
+ var scaleText = (v) => typeof v.scale === "number" ? `, screen scale ${Math.round(v.scale * 1e3) / 10}%` : "";
1105
+ var gapText = (g, labels) => `${g.direction === "vertical" ? "vertical" : "horizontal"} gap between ${labels(g.a)} and ${labels(g.b)}: ${px(g.px)} CSS px`;
1106
+ function isSelection(v) {
1107
+ const x = v;
1108
+ return typeof x === "object" && x !== null && x.format === SELECTION_FORMAT && (x.kind === "element" || x.kind === "area") && typeof x.rev === "string" && typeof x.slide === "string" && typeof x.viewport === "object";
1109
+ }
1110
+ function describeSelection(s, input) {
1111
+ if (!isSelection(input?.selection)) return { error: "INVALID_INPUT", summary: `The selection format is not ${SELECTION_FORMAT}` };
1112
+ const sel = input.selection;
1113
+ const deckRec = deckOf(s);
1114
+ const order = deckRec ? dk(deckRec).order : [];
1115
+ const slideNow = s.records[sel.slide]?.type === "slide";
1116
+ const nowViews = slideNow ? new Map(elementViews(s, sel.slide, order).map((v) => [v.id, v])) : /* @__PURE__ */ new Map();
1117
+ const gone = /* @__PURE__ */ new Set();
1118
+ const name = (id) => {
1119
+ const v = nowViews.get(id);
1120
+ if (v) return `(${id}) ${v.label}`;
1121
+ gone.add(id);
1122
+ return `(${id}) ${sel.labels[id] ?? "unknown name"} (gone now)`;
1123
+ };
1124
+ const lines = [];
1125
+ const at = order.indexOf(sel.slide);
1126
+ const pageNow = !slideNow ? "a page that no longer exists" : at + 1 === sel.number ? `page ${sel.number}` : `page ${sel.number} then, page ${at + 1} now`;
1127
+ if (!slideNow) gone.add(sel.slide);
1128
+ lines.push(`At the time of selection: base ${sel.rev}, page ${sel.slide} (${pageNow}), page ${sel.viewport.width}\xD7${sel.viewport.height}${scaleText(sel.viewport)}, sample ${sel.sample.id}@${sel.sample.version}, ${sel.renderer}`);
1129
+ const targets = [];
1130
+ if (sel.kind === "element" && sel.element) {
1131
+ const id = sel.element;
1132
+ targets.push(id);
1133
+ const was = sel.texts[id];
1134
+ lines.push(`Pointed element: ${name(id)}${was !== void 0 ? `, text at the time "${was}"` : ""}. ${boxText(sel.measured[id])}`);
1135
+ if (sel.path && sel.path.length > 1) lines.push(`Enclosing elements (inside to outside): ${sel.path.slice(1).map(name).join(", ")}`);
1136
+ const v = nowViews.get(id);
1137
+ if (v) {
1138
+ const sibs = [...nowViews.values()].filter((x) => x.parent === v.parent);
1139
+ const i = sibs.findIndex((x) => x.id === id);
1140
+ const near = [sibs[i - 1], sibs[i + 1]].filter(Boolean).map((x) => name(x.id));
1141
+ if (near.length) lines.push(`Neighbors: ${near.join(", ")}`);
1142
+ const now = v.text ?? v.original;
1143
+ if (now !== null && was !== void 0 && now !== was) lines.push(`Current text: "${now}"`);
1144
+ if (v.link) lines.push(`Link: now goes to ${v.link.resolved} (page ${order.indexOf(v.link.resolved) + 1}). Change the target with link.set`);
1145
+ if (now !== null) {
1146
+ const twins = [...nowViews.values()].filter((x) => x.id !== id && (x.text ?? x.original) === now);
1147
+ if (twins.length) lines.push(`Other elements with the same text: ${twins.map((x) => name(x.id)).join(", ")}. To change only this element, send the operation to ${id} only`);
1148
+ }
1149
+ }
1150
+ } else if (sel.area) {
1151
+ const a = sel.area;
1152
+ lines.push(`Pointed area: x ${px(a.x)}, y ${px(a.y)}, ${px(a.width)}\xD7${px(a.height)} (CSS px on the page)`);
1153
+ const cands = sel.candidates ?? [];
1154
+ targets.push(...cands);
1155
+ lines.push(cands.length ? `${cands.length} elements in the area: ${cands.map(name).join(", ")}` : "No editable element is in the area");
1156
+ if (cands.length > 1) lines.push("Several elements are in the area. Decide which one to change from what the person said, or ask the person.");
1157
+ if (sel.gap) {
1158
+ lines.push(`Two adjacent elements: ${gapText(sel.gap, name)}`);
1159
+ for (const k of [sel.gap.a, sel.gap.b]) if (!targets.includes(k)) targets.push(k);
1160
+ for (const k of [sel.gap.a, sel.gap.b]) lines.push(` ${name(k)}: ${boxText(sel.measured[k])}`);
1161
+ }
1162
+ }
1163
+ const r = input.redrawn;
1164
+ if (!r) lines.push("No redrawn values: the screen is closed, it has not drawn the new revision yet, or the person is looking at another page (waiting for measurement).");
1165
+ else {
1166
+ lines.push(`Redrawn values: base ${r.rev}, page ${r.viewport.width}\xD7${r.viewport.height}${scaleText(r.viewport)}, ${r.renderer}`);
1167
+ if (typeof input.current === "string" && input.current !== r.rev) lines.push(`These values are for base ${r.rev}. The screen has not redrawn the current base ${input.current} yet (waiting for measurement). Do not read the values below as the current layout.`);
1168
+ if (sel.gap && r.gap) lines.push(` ${gapText(r.gap, name)} (at the time ${px(sel.gap.px)})`);
1169
+ for (const k of Object.keys(r.measured)) lines.push(` ${name(k)}: ${boxText(r.measured[k])} (at the time ${boxText(sel.measured[k])})`);
1170
+ for (const k of r.missing ?? []) lines.push(` ${name(k)}: not on the redrawn screen`);
1171
+ }
1172
+ return { text: lines.join("\n"), targets, gone: [...gone] };
1173
+ }
1174
+ function renderOutput(s, req) {
1175
+ if ((req?.format ?? "html") !== "html") return { error: "UNSUPPORTED_CAPABILITY", summary: "The first version outputs html only" };
1176
+ const deckRec = deckOf(s);
1177
+ if (!deckRec) return { error: "INVALID_STATE", summary: "There is no deck. Start one with deck.start first" };
1178
+ const d = dk(deckRec);
1179
+ const order = d.order.filter((id) => s.records[id]?.type === "slide");
1180
+ const body = deckBody(d, order.map((id) => slideParts(s, id)));
1181
+ const title = (order.length ? slideTitle(s, order[0]) : "") || d.sample.title;
1182
+ const meta = metaOf(deckRec.id, d, req?.revision ? `; revision ${req.revision}` : "");
1183
+ const keys = [...new Set([...order.flatMap((id) => [...sl(s.records[id]).html.matchAll(/asset:([a-z0-9-]+)/g)]), ...d.css.matchAll(/asset:([a-z0-9-]+)/g)].map((m) => m[1]))].sort();
1184
+ const lengths = pageLengths(s, deckRec);
1185
+ return {
1186
+ ok: true,
1187
+ mediaType: "text/html; charset=utf-8",
1188
+ fileName: `${d.sample.id}-slides.html`,
1189
+ content: documentHtml(title, body, meta, DECK_RUNTIME),
1190
+ basis: { deck: deckRec.id, sample: d.sample, revision: req?.revision ?? null, pages: lengths },
1191
+ assets: keys.map((k) => ({ key: k, present: typeof d.assets[k] === "string" && d.assets[k].startsWith("data:"), bytes: (d.assets[k] ?? "").length }))
1192
+ };
1193
+ }
1194
+ var AI_GUIDE = [
1195
+ "This screen is for editing a presentation deck with the person. The deck starts from a built-in HTML presentation sample. Pages are fixed at 1920\xD71080 CSS px. Each page (sl number) and each editable element (se number) has a fixed id.",
1196
+ "If there is no deck, have the person look at the two samples one at a time on the screen, then record the sample the person picked and the reason with deck.start.",
1197
+ "Add, remove and move pages with slide.add (copies one layout of the sample), slide.remove and slide.move. A navigation bar with previous, page number and next is added to every page automatically and follows the order when it changes.",
1198
+ "A link element inside a page can point to next, prev, first, last or a specific page id. Set it with link.set.",
1199
+ "Change text with text.set and styles with style.set. Write text in the language the person uses. Elements on other pages that use the same layout have different ids, so they do not change together. The look on hover, focus and while pressed is set with state. If you change a style without state, the original state styles stay as they are.",
1200
+ "The properties and values you can change are fixed. Values that load pictures or outside addresses (url() and the like) are rejected.",
1201
+ "A page whose source is 50,000 characters or fewer can be saved to AiAkiv. A longer page cannot use AiAkiv, but editing and saving the file are not blocked. When you narrow the read to one page id, the source of that page is attached.",
1202
+ "The position, size and spacing of elements are not in the concept text. The place the person points at on the screen comes as a selection, with the measurements at that time and the values redrawn after a change. If there are no redrawn values, do not guess. Say that you are waiting for measurement.",
1203
+ "You learn about a selection when aic watch wakes you or from the current selection in read_concept, and you read it with read_selection. The selection is described in the same state as the person's screen. If changes the person made on the screen are not merged yet, the description says so, and they are merged when you send the next operation with the base revision from the response.",
1204
+ "Full screen presenting happens in the saved HTML file. Inside the AIC screen, the presentation preview fills the plugin area."
1205
+ ].join(" ");
1206
+ var DESCRIPTION = {
1207
+ id: PACKAGE_ID,
1208
+ version: VERSION,
1209
+ title: "HTML Slides",
1210
+ aiGuide: AI_GUIDE,
1211
+ markGuide: "Text is plain text. Do not use marks inside the text.",
1212
+ operations: [
1213
+ {
1214
+ op: "deck.start",
1215
+ input: { sample: `Built-in sample id (${SAMPLES.map((x) => x.id).join(", ")})`, reason: "Why the person picked this sample" },
1216
+ summary: "Copies a built-in sample at a fixed version and starts the deck. The default pages of the sample are created. There is only one deck",
1217
+ example: [{ op: "deck.start", input: { sample: "light-lecture", reason: "The lecture has a lot of explanation, so the light one is easier to read" } }]
1218
+ },
1219
+ {
1220
+ op: "slide.add",
1221
+ input: { layout: "Layout key (cover, list, picture, closing)", after: "Id of the page that comes before it. Leave it out for the end, null for the front" },
1222
+ summary: "Copies one layout of the sample and adds a page",
1223
+ example: [{ op: "slide.add", input: { layout: "list", after: "sl2" } }]
1224
+ },
1225
+ {
1226
+ op: "slide.remove",
1227
+ input: { slide: "Page id" },
1228
+ summary: "Removes a page and its elements. Links that pointed to this page now go to the next page",
1229
+ example: [{ op: "slide.remove", input: { slide: "sl8" } }]
1230
+ },
1231
+ {
1232
+ op: "slide.move",
1233
+ input: { slide: "Page id", after: "Id of the page that comes before it. null for the front" },
1234
+ summary: "Moves a page in the order",
1235
+ example: [{ op: "slide.move", input: { slide: "sl8", after: null } }]
1236
+ },
1237
+ {
1238
+ op: "text.set",
1239
+ input: { element: "Element id (se number)", text: "New text. Giving the original text restores it" },
1240
+ summary: "Changes the text of one text or link element",
1241
+ example: [{ op: "text.set", input: { element: "se3", text: "Streets of light and color" } }]
1242
+ },
1243
+ {
1244
+ op: "style.set",
1245
+ input: {
1246
+ element: "Element id",
1247
+ property: "CSS property name (fixed list)",
1248
+ value: "CSS value. Empty text removes the change to this property in this state",
1249
+ state: "none (default), hover, focus, active",
1250
+ source: "Example you referred to { sample, layout, key }. Leave it out if there is none"
1251
+ },
1252
+ summary: "Changes the style of one element, limited to a state",
1253
+ example: [{ op: "style.set", input: { element: "se3", property: "font-size", value: "96px" } }]
1254
+ },
1255
+ {
1256
+ op: "link.set",
1257
+ input: { element: "Link element id", target: "next, prev, first, last or a page id. Giving the original target restores it" },
1258
+ summary: "Changes the page a link inside a page goes to",
1259
+ example: [{ op: "link.set", input: { element: "se5", target: "sl11" } }]
1260
+ }
1261
+ ]
1262
+ };
1263
+ var run = (f) => {
1264
+ try {
1265
+ return f();
1266
+ } catch (e) {
1267
+ if (e instanceof Reject) return { error: e.code, summary: e.message };
1268
+ throw e;
1269
+ }
1270
+ };
1271
+ function lengthNote(before, out) {
1272
+ const after = { ...before, records: { ...before.records } };
1273
+ for (const c of out.changes) {
1274
+ if (c.after === null) delete after.records[c.id];
1275
+ else after.records[c.id] = { id: c.id, type: c.type, owner: before.records[c.id]?.owner ?? null, content: c.after };
1276
+ }
1277
+ const deckRec = deckOf(after);
1278
+ if (!deckRec) return "";
1279
+ const was = deckOf(before) ? new Map(pageLengths(before, deckOf(before)).map((x) => [x.id, x.aiakiv])) : /* @__PURE__ */ new Map();
1280
+ const over = pageLengths(after, deckRec).filter((x) => !x.aiakiv && was.get(x.id) !== false);
1281
+ return over.length ? ` Pages ${over.map((x) => `${x.id} (${x.length} characters)`).join(", ")} are now over 50,000 characters and cannot use AiAkiv.` : "";
1282
+ }
1283
+ var logic = {
1284
+ describe: () => DESCRIPTION,
1285
+ initialize: () => [],
1286
+ plan(state, op, ctx) {
1287
+ const handler = OPERATIONS[op.op];
1288
+ if (!handler) return { error: "INVALID_INPUT", summary: `Unknown operation ${op.op}. See the operation list in describe_document` };
1289
+ const id = (k) => k === 0 && op.as ? op.as : `$~${ctx.stepIndex}.${k}`;
1290
+ return run(() => {
1291
+ const out = handler(state, op.input ?? {}, id, ctx);
1292
+ const summary = /[.?!]$/.test(out.summary) ? out.summary : `${out.summary}.`;
1293
+ return { ...out, summary: `${summary}${lengthNote(state, out)}` };
1294
+ });
1295
+ },
1296
+ validate,
1297
+ project: (state, scope, mine) => run(() => project(state, scope, mine)),
1298
+ extractRefs: refsOf,
1299
+ prepareGeneration: () => ({ error: "UNSUPPORTED_CAPABILITY", summary: "HTML Slides does not make an output that the AI rewrites. The deck is kept as it is, serialized (html-slides.md section 9)" }),
1300
+ interpretSelection(state, sel) {
1301
+ const text = sel.text.trim();
1302
+ const deckRec = deckOf(state);
1303
+ if (text === "" || !deckRec) return { candidates: [] };
1304
+ const order = dk(deckRec).order;
1305
+ const candidates = order.flatMap((sid) => elementViews(state, sid, order)).filter((v) => {
1306
+ const now = v.text ?? v.original;
1307
+ return now !== null && now !== "" && (text.includes(now) || now.includes(text)) || v.label === text;
1308
+ }).map((v) => ({ id: v.id, label: `${v.label} (${v.id})`, why: "The picked text overlaps the text of the element" }));
1309
+ return { candidates };
1310
+ },
1311
+ resolveTarget(state, target) {
1312
+ const r = state.records[target.id];
1313
+ if (!r) return { found: false };
1314
+ if (r.type === "element") return { found: true, label: `Element ${r.id}: ${el(r).label} (${pageNo(state, el(r).slide)})` };
1315
+ if (r.type === "slide") return { found: true, label: `Page ${r.id}: ${sl(r).layout.title} (${pageNo(state, r.id)})` };
1316
+ if (r.type === "deck") return { found: true, label: `Deck ${r.id}: sample ${dk(r).sample.id}` };
1317
+ return { found: true, label: r.id };
1318
+ },
1319
+ describeSelection,
1320
+ renderOutput
1321
+ };
1322
+ globalThis.__aicPlugin = logic;
1323
+ })();