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.
- package/LICENSE +55 -0
- package/README.md +93 -2
- package/bin/aic.js +20427 -0
- package/host-ui/host.js +5151 -0
- package/host-ui/index.html +483 -0
- package/host-ui/lang-en.js +631 -0
- package/package.json +30 -4
- package/plugin-guide.md +997 -0
- package/plugins/plugin-animation/LICENSE +55 -0
- package/plugins/plugin-animation/dist/logic.js +2225 -0
- package/plugins/plugin-animation/docs/manual.md +217 -0
- package/plugins/plugin-animation/manifest.json +31 -0
- package/plugins/plugin-animation/ui/icon.svg +6 -0
- package/plugins/plugin-animation/ui/index.html +2266 -0
- package/plugins/plugin-html-design/LICENSE +55 -0
- package/plugins/plugin-html-design/dist/logic.js +972 -0
- package/plugins/plugin-html-design/docs/manual.md +100 -0
- package/plugins/plugin-html-design/manifest.json +39 -0
- package/plugins/plugin-html-design/samples/exhibition-page.json +570 -0
- package/plugins/plugin-html-design/ui/icon.svg +5 -0
- package/plugins/plugin-html-design/ui/index.html +1241 -0
- package/plugins/plugin-html-slides/LICENSE +55 -0
- package/plugins/plugin-html-slides/dist/logic.js +1323 -0
- package/plugins/plugin-html-slides/docs/manual.md +121 -0
- package/plugins/plugin-html-slides/manifest.json +39 -0
- package/plugins/plugin-html-slides/samples/first-week-lecture.json +1129 -0
- package/plugins/plugin-html-slides/ui/icon.svg +5 -0
- package/plugins/plugin-html-slides/ui/index.html +1349 -0
- package/plugins/plugin-mindmap/LICENSE +55 -0
- package/plugins/plugin-mindmap/dist/logic.js +966 -0
- package/plugins/plugin-mindmap/docs/manual.md +145 -0
- package/plugins/plugin-mindmap/manifest.json +39 -0
- package/plugins/plugin-mindmap/samples/book-club.json +480 -0
- package/plugins/plugin-mindmap/ui/icon.svg +5 -0
- package/plugins/plugin-mindmap/ui/index.html +1774 -0
- package/plugins/plugin-plan/LICENSE +55 -0
- package/plugins/plugin-plan/dist/logic.js +1029 -0
- package/plugins/plugin-plan/docs/manual.md +261 -0
- package/plugins/plugin-plan/manifest.json +51 -0
- package/plugins/plugin-plan/samples/kimchi-day.json +1514 -0
- package/plugins/plugin-plan/samples/meeting-outline.json +653 -0
- package/plugins/plugin-plan/samples/reading-class.json +1577 -0
- package/plugins/plugin-plan/ui/icon.svg +7 -0
- package/plugins/plugin-plan/ui/index.html +1523 -0
- package/plugins/plugin-png/LICENSE +55 -0
- package/plugins/plugin-png/dist/logic.js +1758 -0
- package/plugins/plugin-png/docs/manual.md +344 -0
- package/plugins/plugin-png/manifest.json +35 -0
- package/plugins/plugin-png/ui/icon.svg +5 -0
- package/plugins/plugin-png/ui/index.html +2885 -0
- package/plugins/plugin-process-log/LICENSE +55 -0
- package/plugins/plugin-process-log/dist/logic.js +406 -0
- package/plugins/plugin-process-log/docs/manual.md +131 -0
- package/plugins/plugin-process-log/manifest.json +43 -0
- package/plugins/plugin-process-log/samples/design-decisions.json +241 -0
- package/plugins/plugin-process-log/ui/icon.svg +7 -0
- package/plugins/plugin-process-log/ui/index.html +721 -0
- package/plugins/plugin-story/LICENSE +55 -0
- package/plugins/plugin-story/dist/logic.js +2201 -0
- package/plugins/plugin-story/docs/manual.md +428 -0
- package/plugins/plugin-story/manifest.json +49 -0
- package/plugins/plugin-story/samples/scene-body.json +758 -0
- package/plugins/plugin-story/samples/time-and-groups.json +989 -0
- package/plugins/plugin-story/ui/icon.svg +4 -0
- package/plugins/plugin-story/ui/index.html +2783 -0
- package/plugins/plugin-svg/LICENSE +55 -0
- package/plugins/plugin-svg/dist/logic.js +2150 -0
- package/plugins/plugin-svg/docs/manual.md +314 -0
- package/plugins/plugin-svg/manifest.json +45 -0
- package/plugins/plugin-svg/samples/rocket-icon.json +1305 -0
- package/plugins/plugin-svg/samples/yard-cat.json +7796 -0
- package/plugins/plugin-svg/ui/icon.svg +4 -0
- package/plugins/plugin-svg/ui/index.html +2017 -0
- package/plugins/plugin-tree/LICENSE +55 -0
- package/plugins/plugin-tree/dist/logic.js +505 -0
- package/plugins/plugin-tree/docs/manual.md +140 -0
- package/plugins/plugin-tree/manifest.json +45 -0
- package/plugins/plugin-tree/samples/book-club.json +473 -0
- package/plugins/plugin-tree/samples/sort-memos.json +604 -0
- package/plugins/plugin-tree/ui/icon.svg +7 -0
- package/plugins/plugin-tree/ui/index.html +1305 -0
- package/schema/aic_describe.input.json +11 -0
- package/schema/aic_describe.output.json +67 -0
- package/schema/aic_observe.input.json +14 -0
- package/schema/aic_observe.output.json +47 -0
- package/schema/aic_send.input.json +15 -0
- package/schema/aic_send.output.json +38 -0
- package/schema/aic_update.input.json +19 -0
- package/schema/aic_update.output.json +39 -0
- package/schema/common.json +127 -0
- package/template/plugin/LICENSE +55 -0
- package/template/plugin/README.md +27 -0
- package/template/plugin/docs/manual.md +31 -0
- package/template/plugin/logic.js +337 -0
- package/template/plugin/manifest.json +27 -0
- package/template/plugin/ui/icon.svg +4 -0
- package/template/plugin/ui/index.html +269 -0
|
@@ -0,0 +1,972 @@
|
|
|
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 MEDIA = ["all", "mobile", "desktop"];
|
|
207
|
+
var STATES = ["none", "hover", "focus", "active", "open"];
|
|
208
|
+
var condKey = (media, state) => `${media}/${state}`;
|
|
209
|
+
var PROPERTIES = /* @__PURE__ */ new Set([
|
|
210
|
+
"color",
|
|
211
|
+
"background-color",
|
|
212
|
+
"opacity",
|
|
213
|
+
"font-size",
|
|
214
|
+
"font-weight",
|
|
215
|
+
"font-style",
|
|
216
|
+
"line-height",
|
|
217
|
+
"letter-spacing",
|
|
218
|
+
"text-align",
|
|
219
|
+
"text-transform",
|
|
220
|
+
"text-decoration",
|
|
221
|
+
"margin",
|
|
222
|
+
"margin-top",
|
|
223
|
+
"margin-right",
|
|
224
|
+
"margin-bottom",
|
|
225
|
+
"margin-left",
|
|
226
|
+
"padding",
|
|
227
|
+
"padding-top",
|
|
228
|
+
"padding-right",
|
|
229
|
+
"padding-bottom",
|
|
230
|
+
"padding-left",
|
|
231
|
+
"gap",
|
|
232
|
+
"row-gap",
|
|
233
|
+
"column-gap",
|
|
234
|
+
"width",
|
|
235
|
+
"max-width",
|
|
236
|
+
"min-width",
|
|
237
|
+
"height",
|
|
238
|
+
"max-height",
|
|
239
|
+
"min-height",
|
|
240
|
+
"aspect-ratio",
|
|
241
|
+
"object-fit",
|
|
242
|
+
"border",
|
|
243
|
+
"border-width",
|
|
244
|
+
"border-style",
|
|
245
|
+
"border-color",
|
|
246
|
+
"border-radius",
|
|
247
|
+
"display",
|
|
248
|
+
"flex-direction",
|
|
249
|
+
"flex-wrap",
|
|
250
|
+
"justify-content",
|
|
251
|
+
"align-items",
|
|
252
|
+
"grid-template-columns",
|
|
253
|
+
"box-shadow",
|
|
254
|
+
"transform",
|
|
255
|
+
"transition"
|
|
256
|
+
]);
|
|
257
|
+
function valueProblem(property, value) {
|
|
258
|
+
if (!PROPERTIES.has(property)) return `${property} is not a property you can change in this version. Properties you can change: ${[...PROPERTIES].join(", ")}`;
|
|
259
|
+
if (value.length > 200) return "The value is longer than 200 characters";
|
|
260
|
+
if (/[;{}<>\\@"'`]|\/\*|url\s*\(|expression\s*\(|image-set|image\s*\(|!\s*important/i.test(value)) {
|
|
261
|
+
return `The value "${value}" has a character or function that is not allowed (semicolon, braces, quotes, url(), !important and so on)`;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
function sourceProblems(html, css) {
|
|
266
|
+
const out = [];
|
|
267
|
+
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");
|
|
268
|
+
if (/\son[a-z]+\s*=/i.test(html)) out.push("There is an inline event handler");
|
|
269
|
+
if (/\sstyle\s*=/i.test(html)) out.push("There is a style attribute. Put styles in the CSS");
|
|
270
|
+
for (const m of html.matchAll(/\s(src|href|srcset|action|formaction|poster|xlink:href)\s*=\s*"([^"]*)"/gi)) {
|
|
271
|
+
const v = m[2];
|
|
272
|
+
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`);
|
|
273
|
+
}
|
|
274
|
+
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");
|
|
275
|
+
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`);
|
|
276
|
+
if (/<\/style/i.test(css)) out.push("The CSS has a closing style tag");
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
280
|
+
var unescapeHtml = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
281
|
+
var KEY = /^[a-z0-9-]+$/;
|
|
282
|
+
var leafPattern = (key) => new RegExp(`(<([a-zA-Z][\\w-]*)\\b[^>]*\\sdata-aic-key="${key}"[^>]*>)([^<]*)(</\\2\\s*>)`);
|
|
283
|
+
function leafText(html, key) {
|
|
284
|
+
if (!KEY.test(key)) return null;
|
|
285
|
+
const m = leafPattern(key).exec(html);
|
|
286
|
+
return m ? unescapeHtml(m[3]).replace(/\s+/g, " ").trim() : null;
|
|
287
|
+
}
|
|
288
|
+
var VOID2 = /* @__PURE__ */ new Set(["area", "br", "col", "hr", "img", "input", "wbr", "source", "track"]);
|
|
289
|
+
function parentsIn(html) {
|
|
290
|
+
const out = {};
|
|
291
|
+
const stack = [];
|
|
292
|
+
for (const m of html.matchAll(/<(\/?)([a-zA-Z][\w-]*)\b([^>]*)>/g)) {
|
|
293
|
+
const tag = m[2].toLowerCase();
|
|
294
|
+
if (m[1] === "/") {
|
|
295
|
+
const at = stack.map((s) => s.tag).lastIndexOf(tag);
|
|
296
|
+
if (at >= 0) stack.length = at;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const key = /\sdata-aic-key="([^"]*)"/.exec(m[3])?.[1] ?? null;
|
|
300
|
+
if (key !== null) out[key] = [...stack].reverse().find((s) => s.key !== null)?.key ?? null;
|
|
301
|
+
if (!VOID2.has(tag) && !m[3].trim().endsWith("/")) stack.push({ tag, key });
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function applyText(html, key, text) {
|
|
306
|
+
return html.replace(leafPattern(key), (_all, open, _tag, _inner, close) => `${open}${escapeHtml(text)}${close}`);
|
|
307
|
+
}
|
|
308
|
+
function resolveAssets(src, assets, css) {
|
|
309
|
+
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] ?? "")}"`);
|
|
310
|
+
}
|
|
311
|
+
var stateSelector = (key) => `:is([data-aic-key="${key}"],#aic-none#aic-none#aic-none)`;
|
|
312
|
+
var STATE_SUFFIX = { none: "", hover: ":hover", focus: ":focus-visible", active: ":active", open: "[open]" };
|
|
313
|
+
function mediaQuery(media, mobileMax) {
|
|
314
|
+
if (media === "mobile") return `(max-width:${mobileMax}px)`;
|
|
315
|
+
if (media === "desktop") return `(min-width:${mobileMax + 1}px)`;
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
function overrideCss(elements, page) {
|
|
319
|
+
const blocks = { all: [], mobile: [], desktop: [] };
|
|
320
|
+
let info = null;
|
|
321
|
+
for (const { content: c } of elements) {
|
|
322
|
+
for (const media of MEDIA) {
|
|
323
|
+
for (const state of STATES) {
|
|
324
|
+
const decl = c.styles[condKey(media, state)];
|
|
325
|
+
if (!decl) continue;
|
|
326
|
+
const props = Object.keys(decl).sort();
|
|
327
|
+
if (props.length === 0) continue;
|
|
328
|
+
if (state !== "none") {
|
|
329
|
+
blocks[media].push(`${stateSelector(c.key)}${STATE_SUFFIX[state]}{${props.map((p) => `${p}:${decl[p]}`).join(";")}}`);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
info ??= analyze(page.html, page.css);
|
|
333
|
+
const groups = /* @__PURE__ */ new Map();
|
|
334
|
+
for (const p of props) {
|
|
335
|
+
const sel = selectorWithSpec(c.key, normalSpec(info, c.key, p, media, page.mobileMax).spec);
|
|
336
|
+
groups.set(sel, [...groups.get(sel) ?? [], `${p}:${decl[p]}`]);
|
|
337
|
+
}
|
|
338
|
+
for (const [sel, list] of groups) blocks[media].push(`${sel}{${list.join(";")}}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const out = [];
|
|
343
|
+
for (const media of MEDIA) {
|
|
344
|
+
if (blocks[media].length === 0) continue;
|
|
345
|
+
const q = mediaQuery(media, page.mobileMax);
|
|
346
|
+
out.push(q ? `@media ${q}{
|
|
347
|
+
${blocks[media].join("\n")}
|
|
348
|
+
}` : blocks[media].join("\n"));
|
|
349
|
+
}
|
|
350
|
+
return out.length ? `
|
|
351
|
+
/* aic.html-design: working copy changes */
|
|
352
|
+
${out.join("\n")}` : "";
|
|
353
|
+
}
|
|
354
|
+
function keepsOriginalState(page, key, property, media) {
|
|
355
|
+
return normalSpec(analyze(page.html, page.css), key, property, media, page.mobileMax).preserved;
|
|
356
|
+
}
|
|
357
|
+
function composePage(page, elements) {
|
|
358
|
+
let html = page.html;
|
|
359
|
+
for (const { content: c } of elements) if (c.text !== null) html = applyText(html, c.key, c.text);
|
|
360
|
+
const css = page.css + overrideCss(elements, page);
|
|
361
|
+
return { html: resolveAssets(html, page.assets, false), css: resolveAssets(css, page.assets, true) };
|
|
362
|
+
}
|
|
363
|
+
function composeSample(s) {
|
|
364
|
+
return { html: resolveAssets(s.html, s.assets, false), css: resolveAssets(s.css, s.assets, true) };
|
|
365
|
+
}
|
|
366
|
+
function documentHtml(title, body, meta) {
|
|
367
|
+
return `<!doctype html>
|
|
368
|
+
<html lang="ko">
|
|
369
|
+
<head>
|
|
370
|
+
<meta charset="utf-8">
|
|
371
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
372
|
+
<meta name="generator" content="${escapeHtml(meta)}">
|
|
373
|
+
<title>${escapeHtml(title)}</title>
|
|
374
|
+
<style>
|
|
375
|
+
${body.css}
|
|
376
|
+
</style>
|
|
377
|
+
</head>
|
|
378
|
+
<body>
|
|
379
|
+
${body.html}
|
|
380
|
+
</body>
|
|
381
|
+
</html>
|
|
382
|
+
`;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// packages/plugin-html-design/src/samples.ts
|
|
386
|
+
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)"/><path d="M0 600 C220 560 380 640 620 600 S1020 560 1200 600" stroke="#9cc3cf" stroke-width="6" fill="none" opacity=".6"/><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="#e07a8b"><circle cx="240" cy="485" r="12"/><circle cx="290" cy="492" r="10"/><circle cx="430" cy="482" r="9"/><circle cx="730" cy="492" r="12"/><circle cx="800" cy="496" r="10"/></g></svg>`;
|
|
387
|
+
var ARTWORK_URI = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ARTWORK)}`;
|
|
388
|
+
var SHARED_ELEMENTS = [
|
|
389
|
+
{ key: "header", label: "\uBA38\uB9AC\uB9D0", kind: "box" },
|
|
390
|
+
{ key: "logo", label: "\uB85C\uACE0", kind: "text" },
|
|
391
|
+
{ key: "menu", label: "\uBA54\uB274", kind: "box" },
|
|
392
|
+
{ key: "menu-toggle", label: "\uBA54\uB274 \uBC84\uD2BC", kind: "button" },
|
|
393
|
+
{ key: "nav-works", label: "\uBA54\uB274: \uC791\uD488", kind: "button" },
|
|
394
|
+
{ key: "nav-about", label: "\uBA54\uB274: \uC18C\uAC1C", kind: "button" },
|
|
395
|
+
{ key: "nav-contact", label: "\uBA54\uB274: \uBB38\uC758", kind: "button" },
|
|
396
|
+
{ key: "hero", label: "\uCCAB \uAD6C\uC5ED", kind: "box" },
|
|
397
|
+
{ key: "title", label: "\uC81C\uBAA9", kind: "text" },
|
|
398
|
+
{ key: "subtitle", label: "\uBD80\uC81C", kind: "text" },
|
|
399
|
+
{ key: "photo", label: "\uC791\uD488 \uC0AC\uC9C4", kind: "image" },
|
|
400
|
+
{ key: "caption", label: "\uC0AC\uC9C4 \uC124\uBA85", kind: "text" },
|
|
401
|
+
{ key: "cta", label: "\uCCAB \uAD6C\uC5ED\uC758 \uC790\uC138\uD788 \uBCF4\uAE30 \uBC84\uD2BC", kind: "button" },
|
|
402
|
+
{ key: "about", label: "\uC18C\uAC1C \uAD6C\uC5ED", kind: "box" },
|
|
403
|
+
{ key: "about-title", label: "\uC18C\uAC1C \uC81C\uBAA9", kind: "text" },
|
|
404
|
+
{ key: "about-body", label: "\uC18C\uAC1C \uAE00", kind: "text" },
|
|
405
|
+
{ key: "about-cta", label: "\uC18C\uAC1C \uAD6C\uC5ED\uC758 \uC790\uC138\uD788 \uBCF4\uAE30 \uBC84\uD2BC", kind: "button" },
|
|
406
|
+
{ key: "footer", label: "\uBC14\uB2E5\uAE00", kind: "box" },
|
|
407
|
+
{ key: "footer-text", label: "\uBC14\uB2E5\uAE00 \uBB38\uAD6C", kind: "text" }
|
|
408
|
+
];
|
|
409
|
+
var HEADER = `<header class="top" data-aic-key="header">
|
|
410
|
+
<a class="logo" href="#top" data-aic-key="logo">\uC724\uC2AC \uAC24\uB7EC\uB9AC</a>
|
|
411
|
+
<details class="menu" data-aic-key="menu">
|
|
412
|
+
<summary data-aic-key="menu-toggle">\uBA54\uB274</summary>
|
|
413
|
+
<nav>
|
|
414
|
+
<a href="#works" data-aic-key="nav-works">\uC791\uD488</a>
|
|
415
|
+
<a href="#about" data-aic-key="nav-about">\uC18C\uAC1C</a>
|
|
416
|
+
<a href="#contact" data-aic-key="nav-contact">\uBB38\uC758</a>
|
|
417
|
+
</nav>
|
|
418
|
+
</details>
|
|
419
|
+
</header>`;
|
|
420
|
+
var ABOUT = `<section class="about" id="about" data-aic-key="about">
|
|
421
|
+
<h2 data-aic-key="about-title">\uC791\uAC00 \uB178\uD2B8</h2>
|
|
422
|
+
<p data-aic-key="about-body">\uBB3C\uACB0\uC774 \uBE5B\uC744 \uBC1B\uC544 \uC798\uAC8C \uBD80\uC11C\uC9C0\uB294 \uC21C\uAC04\uC744 \uC815\uC6D0\uC758 \uAF43\uACFC \uACB9\uCCD0 \uADF8\uB838\uC2B5\uB2C8\uB2E4. \uAC00\uAE4C\uC774 \uBCF4\uBA74 \uBD93 \uC790\uAD6D\uC774, \uBA40\uB9AC\uC11C \uBCF4\uBA74 \uD558\uB098\uC758 \uC218\uBA74\uC774 \uBCF4\uC785\uB2C8\uB2E4.</p>
|
|
423
|
+
<a class="btn ghost" href="#works" data-aic-key="about-cta">\uC790\uC138\uD788 \uBCF4\uAE30</a>
|
|
424
|
+
</section>
|
|
425
|
+
<footer class="foot" id="contact" data-aic-key="footer">
|
|
426
|
+
<p data-aic-key="footer-text">\uC724\uC2AC \uAC24\uB7EC\uB9AC, \uD654\uC694\uC77C\uBD80\uD130 \uC77C\uC694\uC77C\uAE4C\uC9C0 11\uC2DC\uC5D0\uC11C 19\uC2DC</p>
|
|
427
|
+
</footer>`;
|
|
428
|
+
var BASE_CSS = `*{box-sizing:border-box}
|
|
429
|
+
html,body{margin:0}
|
|
430
|
+
body{font:16px/1.6 system-ui,"Apple SD Gothic Neo","Malgun Gothic",sans-serif;color:#1f2328;background:#fbfaf7}
|
|
431
|
+
a{color:inherit}
|
|
432
|
+
.top{position:fixed;top:0;left:0;right:0;z-index:10;display:flex;align-items:center;justify-content:space-between;height:60px;padding:0 24px;background:rgba(251,250,247,.92);border-bottom:1px solid #e6e1d8}
|
|
433
|
+
.logo{font-weight:700;text-decoration:none;letter-spacing:.02em}
|
|
434
|
+
.menu summary{list-style:none;cursor:pointer;padding:6px 12px;border:1px solid #cfc8bb;border-radius:999px;font-size:14px}
|
|
435
|
+
.menu summary::-webkit-details-marker{display:none}
|
|
436
|
+
.menu nav{position:absolute;right:24px;top:56px;display:flex;flex-direction:column;gap:4px;padding:10px 14px;background:#fff;border:1px solid #e6e1d8;border-radius:10px;box-shadow:0 8px 24px rgba(0,0,0,.08)}
|
|
437
|
+
.menu nav a{text-decoration:none;padding:4px 2px}
|
|
438
|
+
.btn{display:inline-block;padding:12px 22px;border-radius:999px;background:#1f2328;color:#fff;text-decoration:none;font-weight:600;transition:background .2s,transform .2s}
|
|
439
|
+
.btn:hover{background:#2f5d73;transform:translateY(-1px)}
|
|
440
|
+
.btn.ghost{background:transparent;color:#1f2328;border:1px solid #1f2328}
|
|
441
|
+
.btn.ghost:hover{background:#1f2328;color:#fff}
|
|
442
|
+
.about{max-width:760px;margin:0 auto;padding:72px 24px}
|
|
443
|
+
.about h2{font-size:26px;margin:0 0 12px}
|
|
444
|
+
.about p{margin:0 0 24px}
|
|
445
|
+
.foot{padding:28px 24px;border-top:1px solid #e6e1d8;color:#5f6771;font-size:14px;text-align:center}
|
|
446
|
+
.foot p{margin:0}
|
|
447
|
+
@media (min-width:601px){
|
|
448
|
+
.menu summary{display:none}
|
|
449
|
+
.menu nav{position:static;flex-direction:row;gap:20px;padding:0;background:none;border:0;box-shadow:none}
|
|
450
|
+
.menu:not([open]) nav{display:flex}
|
|
451
|
+
}`;
|
|
452
|
+
var PHOTO_FIRST = {
|
|
453
|
+
id: "photo-first",
|
|
454
|
+
version: "1",
|
|
455
|
+
title: "\uC0AC\uC9C4\uC774 \uBA3C\uC800",
|
|
456
|
+
about: "\uC791\uD488 \uC0AC\uC9C4\uC774 \uD654\uBA74\uC744 \uAC00\uB4DD \uCC44\uC6B0\uACE0, \uC81C\uBAA9\uACFC \uBC84\uD2BC\uC740 \uC0AC\uC9C4 \uC544\uB798\uC5D0 \uB193\uC778\uB2E4.",
|
|
457
|
+
mobileMax: 600,
|
|
458
|
+
html: `${HEADER}
|
|
459
|
+
<main id="top">
|
|
460
|
+
<section class="hero" id="works" data-aic-key="hero">
|
|
461
|
+
<figure class="shot">
|
|
462
|
+
<img src="asset:artwork" alt="\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0" data-aic-key="photo">
|
|
463
|
+
<figcaption data-aic-key="caption">\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0, 2026, \uCE94\uBC84\uC2A4\uC5D0 \uC720\uCC44</figcaption>
|
|
464
|
+
</figure>
|
|
465
|
+
<div class="intro">
|
|
466
|
+
<h1 data-aic-key="title">\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0</h1>
|
|
467
|
+
<p class="sub" data-aic-key="subtitle">\uBE5B\uC774 \uC218\uBA74\uC5D0 \uB2FF\uB294 \uC21C\uAC04\uC744 \uADF8\uB9B0 \uC5F4\uB450 \uC810\uC758 \uC5F0\uC791</p>
|
|
468
|
+
<a class="btn" href="#about" data-aic-key="cta">\uC790\uC138\uD788 \uBCF4\uAE30</a>
|
|
469
|
+
</div>
|
|
470
|
+
</section>
|
|
471
|
+
${ABOUT}
|
|
472
|
+
</main>`,
|
|
473
|
+
css: `${BASE_CSS}
|
|
474
|
+
.hero{min-height:100vh;padding-top:60px;display:flex;flex-direction:column}
|
|
475
|
+
.shot{margin:0;flex:1;display:flex;flex-direction:column}
|
|
476
|
+
.shot img{display:block;width:100%;height:62vh;object-fit:cover}
|
|
477
|
+
.shot figcaption{padding:8px 24px;font-size:13px;color:#5f6771}
|
|
478
|
+
.intro{padding:16px 24px 48px;max-width:960px}
|
|
479
|
+
.intro h1{font-size:48px;line-height:1.15;margin:0 0 12px;letter-spacing:-.01em}
|
|
480
|
+
.intro .sub{font-size:18px;color:#3d434a;margin:0 0 28px}
|
|
481
|
+
@media (max-width:600px){
|
|
482
|
+
.top{padding:0 16px}
|
|
483
|
+
.shot img{height:48vh}
|
|
484
|
+
.intro{padding:12px 16px 40px}
|
|
485
|
+
.intro h1{font-size:32px}
|
|
486
|
+
.intro .sub{font-size:16px}
|
|
487
|
+
}`,
|
|
488
|
+
assets: { artwork: ARTWORK_URI },
|
|
489
|
+
elements: SHARED_ELEMENTS
|
|
490
|
+
};
|
|
491
|
+
var TITLE_FIRST = {
|
|
492
|
+
id: "title-first",
|
|
493
|
+
version: "1",
|
|
494
|
+
title: "\uC81C\uBAA9\uC774 \uBA3C\uC800",
|
|
495
|
+
about: "\uD070 \uC81C\uBAA9\uACFC \uC18C\uAC1C\uAC00 \uBA3C\uC800 \uB098\uC624\uACE0, \uC791\uD488 \uC0AC\uC9C4\uC740 \uC561\uC790\uCC98\uB7FC \uADF8 \uC544\uB798\uC5D0 \uB193\uC778\uB2E4.",
|
|
496
|
+
mobileMax: 600,
|
|
497
|
+
html: `${HEADER}
|
|
498
|
+
<main id="top">
|
|
499
|
+
<section class="hero" id="works" data-aic-key="hero">
|
|
500
|
+
<div class="intro">
|
|
501
|
+
<h1 data-aic-key="title">\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0</h1>
|
|
502
|
+
<p class="sub" data-aic-key="subtitle">\uBE5B\uC774 \uC218\uBA74\uC5D0 \uB2FF\uB294 \uC21C\uAC04\uC744 \uADF8\uB9B0 \uC5F4\uB450 \uC810\uC758 \uC5F0\uC791</p>
|
|
503
|
+
<a class="btn" href="#about" data-aic-key="cta">\uC790\uC138\uD788 \uBCF4\uAE30</a>
|
|
504
|
+
</div>
|
|
505
|
+
<figure class="shot">
|
|
506
|
+
<img src="asset:artwork" alt="\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0" data-aic-key="photo">
|
|
507
|
+
<figcaption data-aic-key="caption">\uBB3C\uACB0 \uC704\uC758 \uC815\uC6D0, 2026, \uCE94\uBC84\uC2A4\uC5D0 \uC720\uCC44</figcaption>
|
|
508
|
+
</figure>
|
|
509
|
+
</section>
|
|
510
|
+
${ABOUT}
|
|
511
|
+
</main>`,
|
|
512
|
+
css: `${BASE_CSS}
|
|
513
|
+
.hero{min-height:100vh;padding:120px 24px 48px;max-width:1100px;margin:0 auto;display:grid;grid-template-columns:5fr 7fr;gap:48px;align-items:center}
|
|
514
|
+
.intro h1{font-size:64px;line-height:1.05;margin:0 0 20px;letter-spacing:-.02em}
|
|
515
|
+
.intro .sub{font-size:18px;color:#3d434a;margin:0 0 32px}
|
|
516
|
+
.shot{margin:0;padding:14px;background:#fff;border:1px solid #e6e1d8;box-shadow:0 12px 32px rgba(0,0,0,.08)}
|
|
517
|
+
.shot img{display:block;width:100%;aspect-ratio:3/2;object-fit:cover}
|
|
518
|
+
.shot figcaption{padding-top:10px;font-size:13px;color:#5f6771}
|
|
519
|
+
@media (max-width:600px){
|
|
520
|
+
.top{padding:0 16px}
|
|
521
|
+
.hero{grid-template-columns:1fr;padding:96px 16px 40px;gap:40px}
|
|
522
|
+
.intro h1{font-size:40px}
|
|
523
|
+
.intro .sub{font-size:16px}
|
|
524
|
+
}`,
|
|
525
|
+
assets: { artwork: ARTWORK_URI },
|
|
526
|
+
elements: SHARED_ELEMENTS
|
|
527
|
+
};
|
|
528
|
+
var SAMPLES = [
|
|
529
|
+
{ ...PHOTO_FIRST, digest: "" },
|
|
530
|
+
{ ...TITLE_FIRST, digest: "" }
|
|
531
|
+
];
|
|
532
|
+
var DIGESTS = {
|
|
533
|
+
"photo-first@1": "c8dba99dabaa1f0c068ac56c28c0a69a8022282b6b56519382a63211fce8c632",
|
|
534
|
+
"title-first@1": "d85a9fd8be2b1d23a013a750d982bea3450fe8bce72aecf55cfe6ace3a1c32bd"
|
|
535
|
+
};
|
|
536
|
+
for (const s of SAMPLES) s.digest = DIGESTS[`${s.id}@${s.version}`] ?? "";
|
|
537
|
+
var sampleById = (id) => SAMPLES.find((s) => s.id === id);
|
|
538
|
+
|
|
539
|
+
// packages/plugin-html-design/src/logic.ts
|
|
540
|
+
var PACKAGE_ID = "aic.html-design";
|
|
541
|
+
var VERSION = "0.1.5";
|
|
542
|
+
var SELECTION_FORMAT = "aic.html-design/selection-1";
|
|
543
|
+
var Reject = class extends Error {
|
|
544
|
+
constructor(code, message) {
|
|
545
|
+
super(message);
|
|
546
|
+
this.code = code;
|
|
547
|
+
}
|
|
548
|
+
code;
|
|
549
|
+
};
|
|
550
|
+
var all = (s, type) => Object.values(s.records).filter((r) => r.type === type);
|
|
551
|
+
var idNumber = (id) => Number(id.replace(/\D/g, ""));
|
|
552
|
+
var byIdNumber = (a, b) => idNumber(a.id) - idNumber(b.id) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
553
|
+
var pageOf = (s) => all(s, "page").sort(byIdNumber)[0];
|
|
554
|
+
var elementsOf = (s, page) => all(s, "element").filter((r) => r.content.page === page).sort(byIdNumber);
|
|
555
|
+
var el = (r) => r.content;
|
|
556
|
+
var MEDIA_WORD = { all: "All widths", mobile: "Mobile", desktop: "Desktop" };
|
|
557
|
+
var STATE_WORD = { none: "", hover: " (on hover)", focus: " (keyboard focus)", active: " (while pressed)", open: " (when open)" };
|
|
558
|
+
function need(s, id, type, what) {
|
|
559
|
+
if (typeof id !== "string" || id === "") throw new Reject("INVALID_INPUT", `${what}: an id is required`);
|
|
560
|
+
const r = s.records[id];
|
|
561
|
+
if (!r) throw new Reject("TARGET_NOT_FOUND", `${what} ${id} not found`);
|
|
562
|
+
if (r.type !== type) throw new Reject("INVALID_INPUT", `${id} is not of type ${type}`);
|
|
563
|
+
return r;
|
|
564
|
+
}
|
|
565
|
+
function textInput(v, what, ctx, max = 2e3) {
|
|
566
|
+
if (typeof v !== "string") throw new Reject("INVALID_INPUT", `${what} must be text`);
|
|
567
|
+
const t = v.replace(/\r\n?/g, "\n").trim();
|
|
568
|
+
if (t.length > max) throw new Reject("INVALID_INPUT", `${what} is longer than ${max} characters`);
|
|
569
|
+
if (ctx.tempNames.includes(t)) throw new Reject("INVALID_INPUT", `"${t}" is the same as a temporary name in this request, so it cannot be used as text`);
|
|
570
|
+
return t;
|
|
571
|
+
}
|
|
572
|
+
function oneOf(v, list, what, fallback) {
|
|
573
|
+
if (v === void 0 || v === null || v === "") return fallback;
|
|
574
|
+
if (typeof v !== "string" || !list.includes(v)) throw new Reject("INVALID_INPUT", `${what} must be one of ${list.join(", ")}`);
|
|
575
|
+
return v;
|
|
576
|
+
}
|
|
577
|
+
function sourceInput(v) {
|
|
578
|
+
if (v === void 0 || v === null) return void 0;
|
|
579
|
+
if (typeof v !== "object" || typeof v.sample !== "string" || typeof v.key !== "string") {
|
|
580
|
+
throw new Reject("INVALID_INPUT", "source is { sample: sample id, key: element key }");
|
|
581
|
+
}
|
|
582
|
+
const { sample, key } = v;
|
|
583
|
+
const found = sampleById(sample);
|
|
584
|
+
if (!found) throw new Reject("TARGET_NOT_FOUND", `There is no built-in sample ${sample}. Samples: ${SAMPLES.map((x) => x.id).join(", ")}`);
|
|
585
|
+
if (!found.elements.some((e) => e.key === key)) throw new Reject("TARGET_NOT_FOUND", `Sample ${sample} has no element key ${key}`);
|
|
586
|
+
return { sample, version: found.version, key };
|
|
587
|
+
}
|
|
588
|
+
function startChanges(sample, reason, id) {
|
|
589
|
+
const problems = sourceProblems(sample.html, sample.css);
|
|
590
|
+
if (problems.length) throw new Reject("INVALID_STATE", `The source of sample ${sample.id} did not pass the check: ${problems.join("; ")}`);
|
|
591
|
+
const page = {
|
|
592
|
+
sample: { id: sample.id, version: sample.version, digest: sample.digest, title: sample.title },
|
|
593
|
+
reason,
|
|
594
|
+
mobileMax: sample.mobileMax,
|
|
595
|
+
html: sample.html,
|
|
596
|
+
css: sample.css,
|
|
597
|
+
assets: { ...sample.assets }
|
|
598
|
+
};
|
|
599
|
+
const parents = parentsIn(sample.html);
|
|
600
|
+
const changes = [{ id: id(0), type: "page", prefix: "pg", after: page }];
|
|
601
|
+
sample.elements.forEach((e, i) => {
|
|
602
|
+
const content = {
|
|
603
|
+
page: id(0),
|
|
604
|
+
key: e.key,
|
|
605
|
+
label: e.label,
|
|
606
|
+
kind: e.kind,
|
|
607
|
+
parent: parents[e.key] ?? null,
|
|
608
|
+
original: e.kind === "text" || e.kind === "button" ? leafText(sample.html, e.key) : null,
|
|
609
|
+
text: null,
|
|
610
|
+
styles: {},
|
|
611
|
+
sources: {}
|
|
612
|
+
};
|
|
613
|
+
changes.push({ id: id(i + 1), type: "element", prefix: "we", after: content });
|
|
614
|
+
});
|
|
615
|
+
return changes;
|
|
616
|
+
}
|
|
617
|
+
var label = (r) => `${r.id}(${el(r).label})`;
|
|
618
|
+
var OPERATIONS = {
|
|
619
|
+
"page.start": (s, input, id, ctx) => {
|
|
620
|
+
const existing = pageOf(s);
|
|
621
|
+
if (existing) {
|
|
622
|
+
const p = existing.content;
|
|
623
|
+
throw new Reject("INVALID_STATE", `There is only one working copy. ${existing.id} already started from sample ${p.sample.id} version ${p.sample.version}`);
|
|
624
|
+
}
|
|
625
|
+
if (typeof input.sample !== "string") throw new Reject("INVALID_INPUT", `Give a built-in sample id in sample: ${SAMPLES.map((x) => x.id).join(", ")}`);
|
|
626
|
+
const sample = sampleById(input.sample);
|
|
627
|
+
if (!sample) throw new Reject("TARGET_NOT_FOUND", `There is no built-in sample ${input.sample}. Samples: ${SAMPLES.map((x) => x.id).join(", ")}`);
|
|
628
|
+
const reason = textInput(input.reason ?? "", "Reason (reason)", ctx, 1e3);
|
|
629
|
+
if (reason === "") throw new Reject("INVALID_INPUT", "Write the reason for the choice (reason). It shows why the work started from this sample when it is opened again");
|
|
630
|
+
return {
|
|
631
|
+
changes: startChanges(sample, reason, id),
|
|
632
|
+
summary: `Working copy started (${id(0)}): sample ${sample.id} (${sample.title}) version ${sample.version}, ${sample.elements.length} editable elements. Reason: ${reason}`
|
|
633
|
+
};
|
|
634
|
+
},
|
|
635
|
+
"text.set": (s, input, _id, ctx) => {
|
|
636
|
+
const r = need(s, input.element, "element", "Element");
|
|
637
|
+
const c = el(r);
|
|
638
|
+
if (c.original === null) throw new Reject("INVALID_INPUT", `${label(r)} is not an element with text (${c.kind})`);
|
|
639
|
+
const text = textInput(input.text, "Text (text)", ctx);
|
|
640
|
+
if (text === "") throw new Reject("INVALID_INPUT", "The text is empty. To go back to the original text, give that text as it is");
|
|
641
|
+
const next = text === c.original ? null : text;
|
|
642
|
+
const before = c.text ?? c.original;
|
|
643
|
+
const summary = before === text ? `${label(r)} text: no change` : `${label(r)} text "${before}" to "${text}"${next === null ? " (original text)" : ""}`;
|
|
644
|
+
return { changes: [{ id: r.id, type: "element", after: { ...c, text: next } }], summary };
|
|
645
|
+
},
|
|
646
|
+
"style.set": (s, input) => {
|
|
647
|
+
const r = need(s, input.element, "element", "Element");
|
|
648
|
+
const c = el(r);
|
|
649
|
+
if (typeof input.property !== "string") throw new Reject("INVALID_INPUT", "Give a CSS property name in property");
|
|
650
|
+
const property = input.property.trim().toLowerCase();
|
|
651
|
+
if (typeof input.value !== "string") throw new Reject("INVALID_INPUT", "value is text. To remove this change, give empty text");
|
|
652
|
+
const value = input.value.trim();
|
|
653
|
+
const media = oneOf(input.media, MEDIA, "media", "all");
|
|
654
|
+
const state = oneOf(input.state, STATES, "state", "none");
|
|
655
|
+
if (value !== "") {
|
|
656
|
+
const bad = valueProblem(property, value);
|
|
657
|
+
if (bad) throw new Reject("INVALID_INPUT", bad);
|
|
658
|
+
} else if (!PROPERTIES.has(property)) throw new Reject("INVALID_INPUT", `${property} is not a property you can change in this version`);
|
|
659
|
+
const source = sourceInput(input.source);
|
|
660
|
+
const cond = condKey(media, state);
|
|
661
|
+
const decl = { ...c.styles[cond] ?? {} };
|
|
662
|
+
const before = decl[property];
|
|
663
|
+
if (value === "") delete decl[property];
|
|
664
|
+
else decl[property] = value;
|
|
665
|
+
const styles = { ...c.styles };
|
|
666
|
+
if (Object.keys(decl).length) styles[cond] = decl;
|
|
667
|
+
else delete styles[cond];
|
|
668
|
+
const sources = { ...c.sources };
|
|
669
|
+
const sk = `${cond}|${property}`;
|
|
670
|
+
if (source && value !== "") sources[sk] = source;
|
|
671
|
+
else delete sources[sk];
|
|
672
|
+
const where = `${MEDIA_WORD[media]}${STATE_WORD[state]}`;
|
|
673
|
+
const summary = value === "" ? before === void 0 ? `${label(r)} ${where} ${property}: no change to remove` : `${label(r)} ${where} ${property}: change removed (back to the source CSS)` : `${label(r)} ${where} ${property}: ${before ?? "source value"} to ${value}${source ? ` (reference: ${source.sample}@${source.version} ${source.key})` : ""}${state === "none" && s.records[c.page]?.type === "page" && keepsOriginalState(s.records[c.page].content, c.key, property, media) ? ". State styles in the source, such as on hover, stay as they are" : ""}`;
|
|
674
|
+
return { changes: [{ id: r.id, type: "element", after: { ...c, styles, sources } }], summary };
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
function refsOf(r) {
|
|
678
|
+
if (r.type === "element") return [{ from: r.id, to: el(r).page, kind: "page" }];
|
|
679
|
+
return [];
|
|
680
|
+
}
|
|
681
|
+
function validate(candidate, changed) {
|
|
682
|
+
const out = [];
|
|
683
|
+
const err = (record, code, message) => out.push({ level: "error", code, record, message });
|
|
684
|
+
const pages = all(candidate, "page");
|
|
685
|
+
if (pages.length > 1) err(pages.map((p) => p.id).find((x) => changed.includes(x)) ?? pages[1].id, "second_page", `There is only one working copy: ${pages.map((p) => p.id).join(", ")}`);
|
|
686
|
+
const seen = /* @__PURE__ */ new Map();
|
|
687
|
+
for (const r of all(candidate, "element").sort(byIdNumber)) {
|
|
688
|
+
const c = el(r);
|
|
689
|
+
const k = `${c.page}|${c.key}`;
|
|
690
|
+
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)}`);
|
|
691
|
+
seen.set(k, r.id);
|
|
692
|
+
if (!changed.includes(r.id)) continue;
|
|
693
|
+
if (candidate.records[c.page]?.type !== "page") err(r.id, "dangling_ref", `The working copy ${c.page} that ${r.id} points to does not exist`);
|
|
694
|
+
}
|
|
695
|
+
return out;
|
|
696
|
+
}
|
|
697
|
+
function elementViews(s, page) {
|
|
698
|
+
const list = elementsOf(s, page);
|
|
699
|
+
const idByKey = new Map(list.map((r) => [el(r).key, r.id]));
|
|
700
|
+
return list.map((r) => {
|
|
701
|
+
const c = el(r);
|
|
702
|
+
return { id: r.id, key: c.key, label: c.label, kind: c.kind, parent: c.parent ? idByKey.get(c.parent) ?? null : null, original: c.original, text: c.text, styles: c.styles, sources: c.sources };
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
function styleLines(v) {
|
|
706
|
+
const out = [];
|
|
707
|
+
for (const media of MEDIA) {
|
|
708
|
+
for (const state of STATES) {
|
|
709
|
+
const cond = condKey(media, state);
|
|
710
|
+
const decl = v.styles[cond];
|
|
711
|
+
if (!decl) continue;
|
|
712
|
+
for (const p of Object.keys(decl).sort()) {
|
|
713
|
+
const src = v.sources[`${cond}|${p}`];
|
|
714
|
+
out.push(`${MEDIA_WORD[media]}${STATE_WORD[state]} ${p}: ${decl[p]}${src ? ` (reference: ${src.sample}@${src.version} ${src.key})` : ""}`);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return out;
|
|
719
|
+
}
|
|
720
|
+
function conceptText(s, ids, mine) {
|
|
721
|
+
const starred = new Set(mine.flatMap((m) => m.changes.filter((c) => c.after !== null).map((c) => c.record)));
|
|
722
|
+
const star = (id) => starred.has(id) ? " *" : "";
|
|
723
|
+
const catalog = SAMPLES.map((x) => `- ${x.id} (${x.title}) version ${x.version}: ${x.about}`);
|
|
724
|
+
const page = pageOf(s);
|
|
725
|
+
if (!page) {
|
|
726
|
+
return [
|
|
727
|
+
"There is no working copy yet. The person looks at the two built-in samples one after the other on the screen.",
|
|
728
|
+
...catalog,
|
|
729
|
+
"Record the sample the person picked and the reason with page.start. Before that, ask the person which one they like."
|
|
730
|
+
].join("\n");
|
|
731
|
+
}
|
|
732
|
+
const p = page.content;
|
|
733
|
+
const views = elementViews(s, page.id);
|
|
734
|
+
const shown = ids ? views.filter((v) => ids.includes(v.id)) : views;
|
|
735
|
+
const byId = new Map(views.map((v) => [v.id, v]));
|
|
736
|
+
const depth = (v) => {
|
|
737
|
+
let d = 0;
|
|
738
|
+
for (let x = v.parent; x && d < 20; x = byId.get(x)?.parent ?? null) d += 1;
|
|
739
|
+
return d;
|
|
740
|
+
};
|
|
741
|
+
const lines = [
|
|
742
|
+
`Working copy (${page.id})${star(page.id)}: sample ${p.sample.id} (${p.sample.title}) version ${p.sample.version}, digest ${p.sample.digest.slice(0, 12)}`,
|
|
743
|
+
`Reason for the choice: ${p.reason}`,
|
|
744
|
+
`Mobile means a width of ${p.mobileMax}px or less. Desktop means wider.`,
|
|
745
|
+
"",
|
|
746
|
+
ids ? `Elements read: ${ids.join(", ")}` : "Editable elements (indent shows the wrapping element)"
|
|
747
|
+
];
|
|
748
|
+
for (const v of shown) {
|
|
749
|
+
const pad = ids ? "" : " ".repeat(depth(v));
|
|
750
|
+
const now = v.text ?? v.original;
|
|
751
|
+
const words = now === null ? "" : v.text !== null ? ` "${now}" (original "${v.original}")` : ` "${now}"`;
|
|
752
|
+
lines.push(`${pad}- (${v.id})${star(v.id)} ${v.label} [${v.kind}]${words}`);
|
|
753
|
+
for (const st of styleLines(v)) lines.push(`${pad} style ${st}`);
|
|
754
|
+
}
|
|
755
|
+
lines.push(
|
|
756
|
+
"",
|
|
757
|
+
"Built-in samples you can use as a reference",
|
|
758
|
+
...catalog,
|
|
759
|
+
"",
|
|
760
|
+
"Element position, size, line count and spacing are known only after the screen draws them. What the person points to on the screen, with the measurements at that time, comes as a selection."
|
|
761
|
+
);
|
|
762
|
+
return lines.join("\n");
|
|
763
|
+
}
|
|
764
|
+
function scopeIds(s, scope) {
|
|
765
|
+
const ids = scope?.targets ?? (scope?.target !== void 0 ? [scope.target] : null);
|
|
766
|
+
if (ids === null) return null;
|
|
767
|
+
for (const id of ids) need(s, id, "element", "Scope element");
|
|
768
|
+
return ids;
|
|
769
|
+
}
|
|
770
|
+
function project(s, scope, mine) {
|
|
771
|
+
const ids = scopeIds(s, scope);
|
|
772
|
+
const page = pageOf(s);
|
|
773
|
+
const p = page?.content;
|
|
774
|
+
const elements = page ? elementsOf(s, page.id).map((r) => ({ id: r.id, content: el(r) })) : [];
|
|
775
|
+
return {
|
|
776
|
+
text: conceptText(s, ids, mine),
|
|
777
|
+
scopeLabel: ids ? `Read elements ${ids.join(", ")}` : "Read everything",
|
|
778
|
+
// 화면은 이것으로 그린다. current 는 저장하는 파일과 같은 함수(composePage)에서 나온다
|
|
779
|
+
json: {
|
|
780
|
+
package: { id: PACKAGE_ID, version: VERSION },
|
|
781
|
+
page: page && p ? { id: page.id, sample: p.sample, reason: p.reason, mobileMax: p.mobileMax } : null,
|
|
782
|
+
current: page && p ? composePage(p, elements) : null,
|
|
783
|
+
elements: page ? elementViews(s, page.id) : [],
|
|
784
|
+
catalog: SAMPLES.map((x) => ({ id: x.id, version: x.version, title: x.title, about: x.about, digest: x.digest, mobileMax: x.mobileMax, elements: x.elements, doc: composeSample(x) }))
|
|
785
|
+
},
|
|
786
|
+
...ids ? { records: ids } : {}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
var px = (n) => `${Math.round(n * 10) / 10}`;
|
|
790
|
+
var boxText = (b) => b ? `x ${px(b.x)}, y ${px(b.y)}, ${px(b.width)}\xD7${px(b.height)}${b.lines ? `, ${b.lines} line${b.lines === 1 ? "" : "s"}` : ""}${b.fontSize ? `, font ${b.fontSize}` : ""}` : "no measurement";
|
|
791
|
+
var vpText = (v, open, labels) => `width ${v.width}\xD7${v.height}${v.clientWidth !== void 0 && v.clientWidth !== v.width ? ` (document width ${v.clientWidth})` : ""}${open.length ? `, open: ${open.map(labels).join(", ")}` : ""}`;
|
|
792
|
+
var gapText = (g, labels) => `${g.direction === "vertical" ? "vertical" : "horizontal"} gap between ${labels(g.a)} and ${labels(g.b)}: ${px(g.px)} CSS px`;
|
|
793
|
+
function isSelection(v) {
|
|
794
|
+
const x = v;
|
|
795
|
+
return typeof x === "object" && x !== null && x.format === SELECTION_FORMAT && (x.kind === "element" || x.kind === "area") && typeof x.rev === "string" && typeof x.viewport === "object";
|
|
796
|
+
}
|
|
797
|
+
function describeSelection(s, input) {
|
|
798
|
+
if (!isSelection(input?.selection)) return { error: "INVALID_INPUT", summary: `The selection format is not ${SELECTION_FORMAT}` };
|
|
799
|
+
const sel = input.selection;
|
|
800
|
+
const page = pageOf(s);
|
|
801
|
+
const nowViews = page ? new Map(elementViews(s, page.id).map((v) => [v.id, v])) : /* @__PURE__ */ new Map();
|
|
802
|
+
const gone = /* @__PURE__ */ new Set();
|
|
803
|
+
const name = (id) => {
|
|
804
|
+
const v = nowViews.get(id);
|
|
805
|
+
if (v) return `(${id}) ${v.label}`;
|
|
806
|
+
gone.add(id);
|
|
807
|
+
return `(${id}) ${sel.labels[id] ?? "unknown name"} (gone now)`;
|
|
808
|
+
};
|
|
809
|
+
const lines = [];
|
|
810
|
+
const open = sel.state?.open ?? [];
|
|
811
|
+
lines.push(`At selection: base ${sel.rev}, ${vpText(sel.viewport, open, name)}, sample ${sel.sample.id}@${sel.sample.version}, ${sel.renderer}`);
|
|
812
|
+
const targets = [];
|
|
813
|
+
if (sel.kind === "element" && sel.element) {
|
|
814
|
+
const id = sel.element;
|
|
815
|
+
targets.push(id);
|
|
816
|
+
const was = sel.texts[id];
|
|
817
|
+
lines.push(`Pointed element: ${name(id)}${was !== void 0 ? `, text at that time "${was}"` : ""}. ${boxText(sel.measured[id])}`);
|
|
818
|
+
if (sel.path && sel.path.length > 1) lines.push(`Wrapping elements (inside to outside): ${sel.path.slice(1).map(name).join(", ")}`);
|
|
819
|
+
const v = nowViews.get(id);
|
|
820
|
+
if (v) {
|
|
821
|
+
const sibs = [...nowViews.values()].filter((x) => x.parent === v.parent);
|
|
822
|
+
const at = sibs.findIndex((x) => x.id === id);
|
|
823
|
+
const near = [sibs[at - 1], sibs[at + 1]].filter(Boolean).map((x) => name(x.id));
|
|
824
|
+
if (near.length) lines.push(`Neighbors: ${near.join(", ")}`);
|
|
825
|
+
const now = v.text ?? v.original;
|
|
826
|
+
if (now !== null && was !== void 0 && now !== was) lines.push(`Text now: "${now}"`);
|
|
827
|
+
if (now !== null) {
|
|
828
|
+
const twins = [...nowViews.values()].filter((x) => x.id !== id && (x.text ?? x.original) === now);
|
|
829
|
+
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`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
} else if (sel.area) {
|
|
833
|
+
const a = sel.area;
|
|
834
|
+
lines.push(`Pointed area: x ${px(a.x)}, y ${px(a.y)}, ${px(a.width)}\xD7${px(a.height)} (CSS px in the viewport)`);
|
|
835
|
+
const cands = sel.candidates ?? [];
|
|
836
|
+
targets.push(...cands);
|
|
837
|
+
lines.push(cands.length ? `${cands.length} elements in the area: ${cands.map(name).join(", ")}` : "No editable element is in the area");
|
|
838
|
+
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.");
|
|
839
|
+
if (sel.gap) {
|
|
840
|
+
lines.push(`Two adjacent elements: ${gapText(sel.gap, name)}`);
|
|
841
|
+
for (const k of [sel.gap.a, sel.gap.b]) if (!targets.includes(k)) targets.push(k);
|
|
842
|
+
for (const k of [sel.gap.a, sel.gap.b]) lines.push(` ${name(k)}: ${boxText(sel.measured[k])}`);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const r = input.redrawn;
|
|
846
|
+
if (!r) lines.push("No redrawn values: the screen is closed or has not drawn the new revision yet (waiting for measurement).");
|
|
847
|
+
else {
|
|
848
|
+
const rOpen = r.state?.open ?? [];
|
|
849
|
+
lines.push(`Redrawn values: base ${r.rev}, ${vpText(r.viewport, rOpen, name)}, ${r.renderer}`);
|
|
850
|
+
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 look.`);
|
|
851
|
+
const diffs = [];
|
|
852
|
+
if (r.viewport.width !== sel.viewport.width || r.viewport.height !== sel.viewport.height) diffs.push(`width ${sel.viewport.width}\xD7${sel.viewport.height} to ${r.viewport.width}\xD7${r.viewport.height}`);
|
|
853
|
+
if ([...open].sort().join() !== [...rOpen].sort().join()) diffs.push("open state is different");
|
|
854
|
+
if (diffs.length) lines.push(`The conditions changed: ${diffs.join(", ")}. Do not compare the two values directly.`);
|
|
855
|
+
if (sel.gap && r.gap) lines.push(` ${gapText(r.gap, name)} (was ${px(sel.gap.px)})`);
|
|
856
|
+
for (const k of Object.keys(r.measured)) lines.push(` ${name(k)}: ${boxText(r.measured[k])} (was ${boxText(sel.measured[k])})`);
|
|
857
|
+
for (const k of r.missing ?? []) lines.push(` ${name(k)}: not on the redrawn screen`);
|
|
858
|
+
}
|
|
859
|
+
return { text: lines.join("\n"), targets, gone: [...gone] };
|
|
860
|
+
}
|
|
861
|
+
function renderOutput(s, req) {
|
|
862
|
+
if ((req?.format ?? "html") !== "html") return { error: "UNSUPPORTED_CAPABILITY", summary: "The only output format in this version is html" };
|
|
863
|
+
const page = pageOf(s);
|
|
864
|
+
if (!page) return { error: "INVALID_STATE", summary: "There is no working copy. Start one with page.start first" };
|
|
865
|
+
const p = page.content;
|
|
866
|
+
const elements = elementsOf(s, page.id).map((r) => ({ id: r.id, content: el(r) }));
|
|
867
|
+
const body = composePage(p, elements);
|
|
868
|
+
const title = elements.find((e) => e.content.key === "title");
|
|
869
|
+
const meta = `${PACKAGE_ID} ${VERSION}; page ${page.id}; sample ${p.sample.id}@${p.sample.version} ${p.sample.digest}${req?.revision ? `; revision ${req.revision}` : ""}`;
|
|
870
|
+
const keys = [...new Set([...p.html.matchAll(/asset:([a-z0-9-]+)/g), ...p.css.matchAll(/asset:([a-z0-9-]+)/g)].map((m) => m[1]))].sort();
|
|
871
|
+
return {
|
|
872
|
+
ok: true,
|
|
873
|
+
mediaType: "text/html; charset=utf-8",
|
|
874
|
+
fileName: `${p.sample.id}.html`,
|
|
875
|
+
content: documentHtml(title ? title.content.text ?? title.content.original ?? "Design" : "Design", body, meta),
|
|
876
|
+
basis: { page: page.id, sample: p.sample, revision: req?.revision ?? null },
|
|
877
|
+
// 그림은 이미 data: 로 들어 있다. 호스트가 빠진 자료를 확인할 수 있게 쓰는 곳을 적는다
|
|
878
|
+
assets: keys.map((k) => ({ key: k, present: typeof p.assets[k] === "string" && p.assets[k].startsWith("data:"), bytes: (p.assets[k] ?? "").length }))
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
var AI_GUIDE = [
|
|
882
|
+
"This screen edits a design working copy, started from a built-in HTML sample, together with the person. The source is real HTML and CSS, and every editable element has a fixed id (we plus a number).",
|
|
883
|
+
"If there is no working copy, let the person look at the two samples one after the other on the screen, then record the sample the person picked and the reason with page.start.",
|
|
884
|
+
'Change text with text.set and styles with style.set. If the person says "only this button", send the operation to that element id only. Do not change other elements that use the same text.',
|
|
885
|
+
'For "only on mobile", give mobile in the media of style.set. For "only on desktop", give desktop. Without media, the change applies to all widths. Use state for the look on hover, on focus, while pressed and when open. A change without state (the usual case) keeps the state styles in the source, such as on hover. To change a state style too, send it again with that state.',
|
|
886
|
+
"The properties and values you can change are fixed. Values that load images or outside addresses (such as url()) are rejected. If you used another sample as a reference, give { sample, key } in source.",
|
|
887
|
+
"Element position, size and spacing are not in the concept text. What the person points to on the screen comes as a selection, with the measurements at that time and the values redrawn after the change. If there are no redrawn values, do not guess. Say that you are waiting for measurement.",
|
|
888
|
+
"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 a change the person made on the screen is not merged yet, the description says so, and it is merged when you send the next operation with the base revision from the response.",
|
|
889
|
+
"After a change, tell the person what you changed and also the side effects, such as other elements being pushed or a different line count. The person judges the overall look on the screen.",
|
|
890
|
+
"When you read a scope, use element ids in scope.",
|
|
891
|
+
"Write what you put into the work in the language the person uses."
|
|
892
|
+
].join(" ");
|
|
893
|
+
var DESCRIPTION = {
|
|
894
|
+
id: PACKAGE_ID,
|
|
895
|
+
version: VERSION,
|
|
896
|
+
title: "HTML Design",
|
|
897
|
+
aiGuide: AI_GUIDE,
|
|
898
|
+
markGuide: "Text is plain text. Do not use marks inside text.",
|
|
899
|
+
operations: [
|
|
900
|
+
{
|
|
901
|
+
op: "page.start",
|
|
902
|
+
input: { sample: `Built-in sample id (${SAMPLES.map((x) => x.id).join(", ")})`, reason: "Why the person picked this sample" },
|
|
903
|
+
summary: "Copies a built-in sample at a fixed version and starts the working copy. There is only one working copy",
|
|
904
|
+
example: [{ op: "page.start", input: { sample: "photo-first", reason: "The photo catches the eye first" } }]
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
op: "text.set",
|
|
908
|
+
input: { element: "Element id (we plus a number)", text: "New text. Giving the original text restores it" },
|
|
909
|
+
summary: "Changes the text of one text or button element",
|
|
910
|
+
example: [{ op: "text.set", input: { element: "we13", text: "See the works" } }]
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
op: "style.set",
|
|
914
|
+
input: {
|
|
915
|
+
element: "Element id",
|
|
916
|
+
property: "CSS property name (fixed list)",
|
|
917
|
+
value: "CSS value. Empty text removes the change to this property under this condition",
|
|
918
|
+
media: "all (default), mobile, desktop",
|
|
919
|
+
state: "none (default), hover, focus, active, open",
|
|
920
|
+
source: "The example used as a reference { sample, key }. Leave it out if there is none"
|
|
921
|
+
},
|
|
922
|
+
summary: "Changes the style of one element, limited to a width and state condition",
|
|
923
|
+
example: [{ op: "style.set", input: { element: "we9", property: "margin-bottom", value: "8px", media: "mobile" } }]
|
|
924
|
+
}
|
|
925
|
+
]
|
|
926
|
+
};
|
|
927
|
+
var run = (f) => {
|
|
928
|
+
try {
|
|
929
|
+
return f();
|
|
930
|
+
} catch (e) {
|
|
931
|
+
if (e instanceof Reject) return { error: e.code, summary: e.message };
|
|
932
|
+
throw e;
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
var logic = {
|
|
936
|
+
describe: () => DESCRIPTION,
|
|
937
|
+
initialize: () => [],
|
|
938
|
+
plan(state, op, ctx) {
|
|
939
|
+
const handler = OPERATIONS[op.op];
|
|
940
|
+
if (!handler) return { error: "INVALID_INPUT", summary: `Unknown operation ${op.op}. See the list of operations in describe_document` };
|
|
941
|
+
const id = (k) => k === 0 && op.as ? op.as : `$~${ctx.stepIndex}.${k}`;
|
|
942
|
+
return run(() => {
|
|
943
|
+
const out = handler(state, op.input ?? {}, id, ctx);
|
|
944
|
+
return { ...out, summary: /[.?!]$/.test(out.summary) ? out.summary : `${out.summary}.` };
|
|
945
|
+
});
|
|
946
|
+
},
|
|
947
|
+
validate,
|
|
948
|
+
project: (state, scope, mine) => run(() => project(state, scope, mine)),
|
|
949
|
+
extractRefs: refsOf,
|
|
950
|
+
prepareGeneration: () => ({ error: "UNSUPPORTED_CAPABILITY", summary: "HTML Design does not make output that the AI rewrites. The working copy is serialized and kept as it is (html-design.md section 5)" }),
|
|
951
|
+
interpretSelection(state, sel) {
|
|
952
|
+
const text = sel.text.trim();
|
|
953
|
+
const page = pageOf(state);
|
|
954
|
+
if (text === "" || !page) return { candidates: [] };
|
|
955
|
+
const candidates = elementViews(state, page.id).filter((v) => {
|
|
956
|
+
const now = v.text ?? v.original;
|
|
957
|
+
return now !== null && now !== "" && (text.includes(now) || now.includes(text)) || v.label === text;
|
|
958
|
+
}).map((v) => ({ id: v.id, label: `${v.label} (${v.id})`, why: "The selected text overlaps the element text" }));
|
|
959
|
+
return { candidates };
|
|
960
|
+
},
|
|
961
|
+
resolveTarget(state, target) {
|
|
962
|
+
const r = state.records[target.id];
|
|
963
|
+
if (!r) return { found: false };
|
|
964
|
+
if (r.type === "element") return { found: true, label: `Element ${r.id}: ${el(r).label}` };
|
|
965
|
+
if (r.type === "page") return { found: true, label: `Working copy ${r.id}: sample ${r.content.sample.id}` };
|
|
966
|
+
return { found: true, label: r.id };
|
|
967
|
+
},
|
|
968
|
+
describeSelection,
|
|
969
|
+
renderOutput
|
|
970
|
+
};
|
|
971
|
+
globalThis.__aicPlugin = logic;
|
|
972
|
+
})();
|