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,1241 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title data-t="text">HTML Design</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
--bg: #f5f5f2; --panel: #ffffff; --text: #1f2328; --muted: #5f6771; --line: #dcdfe3; --soft: #f0f1f3;
|
|
11
|
+
--accent: #1f6a8c; --accent-text: #ffffff; --del: #a8321f; --del-bg: #fae6e2; --add: #1d7a46; --add-bg: #e3f4e9;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-color-scheme: dark) {
|
|
14
|
+
:root {
|
|
15
|
+
--bg: #191b1e; --panel: #22252a; --text: #e6e8eb; --muted: #a0a8b2; --line: #383d44; --soft: #2b2f35;
|
|
16
|
+
--accent: #7cc0dd; --accent-text: #10222b; --del: #f1a597; --del-bg: #472420; --add: #7bd6a0; --add-bg: #17392a;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
* { box-sizing: border-box; }
|
|
20
|
+
html, body { height: 100%; }
|
|
21
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 system-ui, "Malgun Gothic", sans-serif; }
|
|
22
|
+
button { font: inherit; color: inherit; cursor: pointer; }
|
|
23
|
+
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
24
|
+
.btn { white-space: nowrap; background: transparent; border: 1px solid var(--line); border-radius: 5px; padding: 2px 9px; font-size: 13px; }
|
|
25
|
+
.btn:hover { background: var(--soft); }
|
|
26
|
+
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
|
27
|
+
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
|
28
|
+
.btn[disabled] { opacity: .5; cursor: default; }
|
|
29
|
+
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: 13px; }
|
|
30
|
+
|
|
31
|
+
#bar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
|
|
32
|
+
.group { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
|
|
33
|
+
.spacer { flex: 1; }
|
|
34
|
+
.meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
|
|
35
|
+
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; width: 28px; height: 28px; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--muted); }
|
|
36
|
+
.icon-btn:hover { background: var(--soft); color: var(--text); }
|
|
37
|
+
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--soft); border-color: var(--line); color: var(--accent); }
|
|
38
|
+
.icon-btn[disabled] { opacity: .4; cursor: default; }
|
|
39
|
+
.ic, .ic svg { display: block; width: 16px; height: 16px; }
|
|
40
|
+
.ic svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
|
|
41
|
+
.icon-btn .dot { position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
|
|
42
|
+
details > summary { cursor: pointer; }
|
|
43
|
+
details.menu { position: relative; }
|
|
44
|
+
details.menu > summary { list-style: none; border: 1px solid var(--line); border-radius: 5px; padding: 2px 9px; font-size: 13px; white-space: nowrap; }
|
|
45
|
+
details.menu > summary::-webkit-details-marker { display: none; }
|
|
46
|
+
details.menu > summary::after { content: " ▾"; color: var(--muted); }
|
|
47
|
+
details.menu > .pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 10; display: grid; gap: 2px; min-width: 200px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .15); }
|
|
48
|
+
details.menu > .pop .btn { text-align: left; border-color: transparent; }
|
|
49
|
+
#stage { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; padding: 12px; align-items: start; }
|
|
50
|
+
#stage.closed { grid-template-columns: minmax(0, 1fr); }
|
|
51
|
+
#canvas { overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-height: 300px; }
|
|
52
|
+
#frameBox { transform-origin: 0 0; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .12); margin: 0 auto; }
|
|
53
|
+
#frame { display: block; border: 0; background: #fff; }
|
|
54
|
+
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
|
|
55
|
+
aside section, aside details.fold { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
|
|
56
|
+
aside h2, aside details.fold > summary { font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
|
|
57
|
+
aside details.fold:not([open]) > summary { margin: 0; }
|
|
58
|
+
details.sub > summary { color: var(--muted); font-size: 12px; margin-top: 6px; }
|
|
59
|
+
aside p { margin: 4px 0; }
|
|
60
|
+
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 13px; }
|
|
61
|
+
.kv dt { color: var(--muted); }
|
|
62
|
+
.kv dd { margin: 0; overflow-wrap: anywhere; }
|
|
63
|
+
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; margin: 4px 0; }
|
|
64
|
+
.chip { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 0 8px; font-size: 12px; }
|
|
65
|
+
.chip[aria-current="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
|
|
66
|
+
.compare { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
|
|
67
|
+
.compare th, .compare td { border-top: 1px solid var(--line); padding: 2px 4px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
|
|
68
|
+
.compare th { color: var(--muted); font-weight: 600; }
|
|
69
|
+
.form { display: grid; gap: 6px; margin-top: 6px; }
|
|
70
|
+
.form label > span { display: block; color: var(--muted); font-size: 12px; }
|
|
71
|
+
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
|
|
72
|
+
textarea, input[type=text], select { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; width: 100%; }
|
|
73
|
+
textarea { resize: vertical; min-height: 3.2em; }
|
|
74
|
+
.outline { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
|
|
75
|
+
.outline button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 4px; padding: 1px 4px; font-size: 13px; }
|
|
76
|
+
.outline button:hover { background: var(--soft); }
|
|
77
|
+
.outline button[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
|
|
78
|
+
.outline .id { color: var(--muted); font-size: 11px; margin-left: 4px; }
|
|
79
|
+
.outline button[aria-current="true"] .id { color: inherit; }
|
|
80
|
+
.changed { color: var(--add); font-size: 11px; margin-left: 4px; }
|
|
81
|
+
.warn { color: var(--del); font-size: 12px; }
|
|
82
|
+
html { scroll-padding-top: calc(var(--bar-h, 41px) + var(--talk-h, 0px) + 8px); }
|
|
83
|
+
#talkBar { position: sticky; top: var(--bar-h, 41px); z-index: 4; margin: 8px 12px 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .08); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
|
|
84
|
+
#talkBar.unsent { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
|
85
|
+
#talkBar .state { margin: 0 0 6px; font-size: 13px; overflow-wrap: anywhere; }
|
|
86
|
+
#talkBar .state b { font-weight: 600; }
|
|
87
|
+
#talkBar .steps { margin: 0 0 6px; padding-left: 20px; font-size: 13px; }
|
|
88
|
+
#talkBar .steps li { margin: 1px 0; }
|
|
89
|
+
#talkBar .hint { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
|
|
90
|
+
#talkBar .state .wait { color: var(--del); font-weight: 600; }
|
|
91
|
+
#talkBar .state .done { color: var(--add); font-weight: 600; }
|
|
92
|
+
#talkBar .line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
93
|
+
#talkBar .line select { width: auto; flex: none; }
|
|
94
|
+
#talkBar .line input[type=text] { flex: 1; min-width: 160px; padding: 5px 8px; }
|
|
95
|
+
#talkBar .line .btn { flex: none; padding: 5px 14px; font-size: 14px; }
|
|
96
|
+
#talkBar .state .link { margin-left: 6px; }
|
|
97
|
+
#talkBar .help { position: relative; flex: none; }
|
|
98
|
+
#talkBar .help > summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: 13px; }
|
|
99
|
+
#talkBar .help > summary::-webkit-details-marker { display: none; }
|
|
100
|
+
#talkBar .help > .pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: min(380px, 80vw); padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .15); }
|
|
101
|
+
#talkBar .help .hint { margin: 0; }
|
|
102
|
+
#toast { position: fixed; z-index: 50; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 5px 12px; border-radius: 6px; font-size: 14px; max-width: min(90vw, 640px); }
|
|
103
|
+
#toast.bad { background: var(--del); color: #fff; }
|
|
104
|
+
#error { color: var(--del); padding: 16px; }
|
|
105
|
+
[hidden] { display: none !important; }
|
|
106
|
+
@media (max-width: 900px) { #stage { grid-template-columns: minmax(0, 1fr); } }
|
|
107
|
+
</style>
|
|
108
|
+
</head>
|
|
109
|
+
<body>
|
|
110
|
+
<div id="error" role="alert" hidden></div>
|
|
111
|
+
<header id="bar"><span class="meta" id="frameNote"></span></header>
|
|
112
|
+
<div id="talkBar" role="group" aria-label="Send what you picked to the AI" data-t="aria-label" hidden></div>
|
|
113
|
+
<main id="stage">
|
|
114
|
+
<div id="canvas">
|
|
115
|
+
<div id="frameBox"></div>
|
|
116
|
+
</div>
|
|
117
|
+
<aside id="side"></aside>
|
|
118
|
+
</main>
|
|
119
|
+
<div id="toast" role="status" hidden></div>
|
|
120
|
+
<script>
|
|
121
|
+
// HTML 디자인의 화면(plugin-design/html-design.md). 호스트 연결로만 코어와 이야기한다. 글은 모두 textContent 로 넣는다.
|
|
122
|
+
// 샘플은 안쪽 srcdoc iframe 에 그린다. 플러그인 문서에 직접 넣으면 미디어 쿼리, vh, position: fixed 가 플러그인 iframe 을
|
|
123
|
+
// 기준으로 잡혀 모바일 시안이 되지 않기 때문이다(6절 확인 결과). 안쪽 문서는 다른 opaque origin 이라 DOM 을 직접 읽지
|
|
124
|
+
// 못하므로, 클릭, 드래그, 측정은 이 화면이 srcdoc 에 함께 넣는 스크립트(agentMain)가 안쪽에서 하고 postMessage 로 알린다.
|
|
125
|
+
// 사람이 화면에서 고치는 것도 모두 조작으로 바뀌어 AI 와 같은 경로로 저장된다. 보는 샘플, 폭, 모드, 선택은 화면 상태다.
|
|
126
|
+
'use strict';
|
|
127
|
+
const PLUGIN_VERSION = '0.1.5';
|
|
128
|
+
const SELECTION_FORMAT = 'aic.html-design/selection-1';
|
|
129
|
+
const RENDERER = 'aic.html-design 0.1.5, srcdoc iframe';
|
|
130
|
+
// 이름은 화면의 언어를 정한 뒤 부를 때마다 t() 로 낸다
|
|
131
|
+
const WIDTHS = { mobile: { width: 390, height: 760, label: () => t('Mobile 390') }, desktop: { width: 1280, height: 800, label: () => t('Desktop 1280') } };
|
|
132
|
+
const PROPERTIES = ['margin-top', 'margin-bottom', 'padding-top', 'padding-bottom', 'gap', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'color', 'background-color', 'border-radius', 'text-align', 'width', 'max-width', 'height'];
|
|
133
|
+
const MEDIA_LABEL = () => ({ all: t('All widths'), mobile: t('Mobile only'), desktop: t('Desktop only') });
|
|
134
|
+
const STATE_LABEL = () => ({ none: t('Normal'), hover: t('On hover'), focus: t('Keyboard focus'), active: t('While pressed'), open: t('When open') });
|
|
135
|
+
|
|
136
|
+
// ---- 화면의 언어 ----
|
|
137
|
+
// 호스트가 capabilities 의 language 로 AIC 화면의 언어("ko" 나 "en")를 알린다(plugin-guide.md 4.4절, rawdev 2026-11-25). 영어가 원문이고,
|
|
138
|
+
// "ko" 일 때만 아래 사전에서 한국어를 찾는다. 사전에 없거나 다른 값이거나 값이 없으면(옛 호스트) 영어를 보인다. 사람이 언어를 바꾸면
|
|
139
|
+
// 호스트가 화면을 다시 열므로 처음 한 번만 읽는다. 화면 글만 바꾼다. 샘플과 작업본(안쪽 문서), 저장 파일, 논리가 낸 문장(요약, 거절)은
|
|
140
|
+
// 작업 내용이거나 AI 가 읽는 글이라 그대로 둔다. t() 에는 글자 그대로의 문자열만 준다(src/lang.test.ts 가 소스에서 원문을 찾는다).
|
|
141
|
+
// index.html 의 고정 글은 data-t 를 단 요소에 있다. 값은 바꿀 것이고 text 는 글, 그 밖은 같은 이름의 속성이다.
|
|
142
|
+
let lang = 'en';
|
|
143
|
+
const KO = {
|
|
144
|
+
'HTML Design': 'HTML 디자인',
|
|
145
|
+
'Send what you picked to the AI': '고른 것을 AI 에게 보내기',
|
|
146
|
+
'Mobile 390': '모바일 390',
|
|
147
|
+
'Desktop 1280': '데스크톱 1280',
|
|
148
|
+
'All widths': '모든 폭',
|
|
149
|
+
'Mobile only': '모바일만',
|
|
150
|
+
'Desktop only': '데스크톱만',
|
|
151
|
+
'Normal': '보통',
|
|
152
|
+
'On hover': '가리킬 때',
|
|
153
|
+
'Keyboard focus': '키보드 초점',
|
|
154
|
+
'While pressed': '누르는 중',
|
|
155
|
+
'When open': '펼쳤을 때',
|
|
156
|
+
'Design screen': '디자인 화면',
|
|
157
|
+
'{label}×{height} CSS px, shown at {percent}%': '{label}×{height} CSS px, {percent}% 로 줄여 보임',
|
|
158
|
+
'Reference: {name}': '참고: {name}',
|
|
159
|
+
'Could not send the new measurements: {message}': '다시 잰 값을 보내지 못했습니다: {message}',
|
|
160
|
+
'Working copy': '작업본',
|
|
161
|
+
'Sample: {name}': '샘플: {name}',
|
|
162
|
+
'View': '보는 화면',
|
|
163
|
+
'Choose what to view': '보는 화면 고르기',
|
|
164
|
+
'Screen width': '화면 폭',
|
|
165
|
+
'Mode': '모드',
|
|
166
|
+
'Pick': '고르기',
|
|
167
|
+
'Click the screen to pick an element, or drag to pick an area. Then write a message in the send bar at the top and send it to the AI': '화면을 누르면 요소를, 끌면 영역을 고릅니다. 그런 다음 위쪽 보내는 칸에 말을 적어 AI 에게 보냅니다',
|
|
168
|
+
'Preview': '미리보기',
|
|
169
|
+
'Links and menus work as in the sample': '링크와 메뉴가 샘플의 원래대로 움직입니다',
|
|
170
|
+
'Save as HTML file': 'HTML 파일로 저장',
|
|
171
|
+
'Save as HTML file: saves the working copy as a single HTML file': 'HTML 파일로 저장: 지금 작업본을 HTML 파일 하나로 저장합니다',
|
|
172
|
+
'Save as HTML file: start a working copy first': 'HTML 파일로 저장: 작업본을 시작한 뒤 저장합니다',
|
|
173
|
+
'Save as HTML file: this host cannot save HTML yet': 'HTML 파일로 저장: 이 호스트는 아직 HTML 저장을 지원하지 않습니다',
|
|
174
|
+
'Edit panel': '편집 칸',
|
|
175
|
+
'Edit panel (click to open): measurements of what you picked, text and style changes, elements': '편집 칸 열기: 고른 것의 잰 값, 문구와 스타일 고치기, 요소 목록',
|
|
176
|
+
'Edit panel (click to close): measurements of what you picked, text and style changes, elements': '편집 칸 닫기: 고른 것의 잰 값, 문구와 스타일 고치기, 요소 목록',
|
|
177
|
+
'. New measurements are in': '. 다시 잰 값이 있습니다',
|
|
178
|
+
'Saved: {file}': '저장했습니다: {file}',
|
|
179
|
+
'Could not save': '저장하지 못했습니다',
|
|
180
|
+
'none': '없음',
|
|
181
|
+
'{n} line': '{n}줄',
|
|
182
|
+
'{n} lines': '{n}줄',
|
|
183
|
+
'When picked {rev}': '선택 당시 {rev}',
|
|
184
|
+
'Redrawn {rev}': '다시 그린 값 {rev}',
|
|
185
|
+
'Redrawn': '다시 그린 값',
|
|
186
|
+
'Width': '폭',
|
|
187
|
+
'Gap': '간격',
|
|
188
|
+
'gone': '없음',
|
|
189
|
+
'Nothing has changed yet, so the values are the same as when picked.': '아직 바꾼 것이 없어 당시 값과 같습니다.',
|
|
190
|
+
'Waiting for measurement: the screen measures again after it draws the new revision.': '측정 대기: 바뀐 내용을 다시 그리면 다시 잽니다.',
|
|
191
|
+
'The width is different, so the two values cannot be compared directly.': '폭이 달라 두 값을 바로 견줄 수 없습니다.',
|
|
192
|
+
'Measurements: when picked and redrawn {rev}': '잰 값: 당시와 다시 그린 {rev}',
|
|
193
|
+
'Measurements': '잰 값',
|
|
194
|
+
'Picked': '고른 것',
|
|
195
|
+
'Nothing is picked yet. Click or drag on the screen to pick. With a keyboard, pick from the elements list below.': '아직 고른 것이 없습니다. 화면에서 누르거나 끌어 고르고, 키보드로는 아래 요소 목록에서 고릅니다.',
|
|
196
|
+
'Picked element': '고른 요소',
|
|
197
|
+
'Picked area': '고른 영역',
|
|
198
|
+
'Element': '요소',
|
|
199
|
+
'Text': '문구',
|
|
200
|
+
'Pick a wrapping section': '감싼 구역 고르기',
|
|
201
|
+
'Area': '영역',
|
|
202
|
+
'Elements in area': '걸친 요소',
|
|
203
|
+
'vertical {px}px between {a} and {b}': '{a}, {b} 사이 세로 {px}px',
|
|
204
|
+
'horizontal {px}px between {a} and {b}': '{a}, {b} 사이 가로 {px}px',
|
|
205
|
+
'Several elements are in the area. Click one to pick only that element.': '걸친 요소가 여럿입니다. 하나를 누르면 그 요소만 고릅니다.',
|
|
206
|
+
'area between {a} and {b}': '{a}, {b} 사이 영역',
|
|
207
|
+
'empty area': '빈 영역',
|
|
208
|
+
'area ({names})': '영역({names})',
|
|
209
|
+
'area ({names} and {more} more)': '영역({names} 외 {more}개)',
|
|
210
|
+
'The gap was {was}px and is now {now}px.': '간격은 {was}px 에서 지금 {now}px 입니다.',
|
|
211
|
+
'Message to the AI about what you picked': '고른 곳에 대해 AI 에게 할 말',
|
|
212
|
+
'For example: this gap is too wide. You can also send it empty': '예: 여기 간격이 너무 넓어. 비워 두고 보내도 됩니다',
|
|
213
|
+
'First click or drag on the screen above to pick what to change, then write your message here and send it': '먼저 위 화면에서 고칠 곳을 누르거나 끌어 고른 뒤, 여기에 할 말을 적어 보냅니다',
|
|
214
|
+
'Role of what you picked': '고른 곳의 역할',
|
|
215
|
+
'Change this': '바꿀 곳',
|
|
216
|
+
'Use as reference': '참고할 곳',
|
|
217
|
+
'Edit directly': '직접 고치기',
|
|
218
|
+
'Open the edit panel and change text and styles yourself': '편집 칸을 열어 문구와 스타일을 직접 고칩니다',
|
|
219
|
+
'A view-only screen does not send to the AI.': '보기만 하는 화면에서는 AI 에게 보내지 않습니다.',
|
|
220
|
+
'This host cannot send what you picked to the AI yet.': '이 호스트는 아직 고른 것을 AI 에게 보내지 못합니다.',
|
|
221
|
+
'Sent to the AI (selection {id}).': 'AI 에게 보냈습니다(선택 {id}).',
|
|
222
|
+
', message "{said}"': ', 말 "{said}"',
|
|
223
|
+
', no message': ', 말 없음',
|
|
224
|
+
'Picked: {what}.': '고른 것: {what}.',
|
|
225
|
+
'Not sent to the AI yet.': '아직 AI 에게 보내지 않았습니다.',
|
|
226
|
+
'Click what you want to change on the screen above. Drag across several elements to pick an area.': '위 화면에서 고칠 곳을 누릅니다. 여러 요소에 걸쳐 끌면 영역을 고릅니다.',
|
|
227
|
+
'Write your message in this bar and click [Send to AI] or press Enter. The message can be empty.': '이 칸에 할 말을 적고 [AI 에게 보내기] 를 누르거나 Enter 를 누릅니다. 말은 비워도 됩니다.',
|
|
228
|
+
'The AI can read what you picked, but picking does not wake the AI. To give it work, write a message and click [Send to AI].': '고른 것은 AI 가 읽을 수 있지만 AI 를 깨우지는 않습니다. 일을 시키려면 말을 적고 [AI 에게 보내기] 를 누릅니다.',
|
|
229
|
+
'Picking alone does not tell the AI. The AI reads the place and your message only after you send them.': '고르기만 해서는 AI 가 알지 못합니다. 보내야 AI 가 고른 곳과 말을 함께 읽습니다.',
|
|
230
|
+
'Help for the send bar': '보내는 칸 도움말',
|
|
231
|
+
'Send to AI': 'AI 에게 보내기',
|
|
232
|
+
'This screen does not send': '이 화면에서는 보내지 않습니다',
|
|
233
|
+
'Sends what you picked and your message to the AI. The message can be empty': '고른 것과 적은 말을 AI 에게 보냅니다. 말은 비워도 됩니다',
|
|
234
|
+
'First pick what to change on the screen above': '먼저 위 화면에서 고칠 곳을 고릅니다',
|
|
235
|
+
'Could not send the selection': '선택을 보내지 못했습니다',
|
|
236
|
+
'Sent the earlier pick as {id}. What you picked now is not sent yet': '앞의 선택을 {id} 로 보냈습니다. 지금 고른 것은 아직 보내지 않았습니다',
|
|
237
|
+
'Sent selection {id}': '선택을 보냈습니다({id})',
|
|
238
|
+
'Edit: {label} ({id})': '고치기: {label} ({id})',
|
|
239
|
+
'New text': '새 문구',
|
|
240
|
+
'Text (original: {original})': '문구 (원래: {original})',
|
|
241
|
+
'Change text': '문구 바꾸기',
|
|
242
|
+
'The text has not changed': '바뀐 문구가 없습니다',
|
|
243
|
+
'Property': '속성',
|
|
244
|
+
'Value': '값',
|
|
245
|
+
'For example: 16px. Leave empty to remove this change': '예: 16px. 비우면 이 변경을 지웁니다',
|
|
246
|
+
'State': '상태',
|
|
247
|
+
'Reference: {name} ({sample}@{version})': '참고: {name} ({sample}@{version})',
|
|
248
|
+
'Change style': '스타일 바꾸기',
|
|
249
|
+
'Styles changed on this element': '이 요소에 바꾼 스타일',
|
|
250
|
+
'Elements ({n})': '요소 목록 ({n})',
|
|
251
|
+
'Elements ({n}, changed {changed})': '요소 목록 ({n}, 바뀜 {changed})',
|
|
252
|
+
'changed': '바뀜',
|
|
253
|
+
'Reason for the choice': '고른 이유',
|
|
254
|
+
'For example: the photo catches the eye first': '예: 사진이 먼저 눈에 들어와서',
|
|
255
|
+
'Version {version}. Open another sample from the menu at the left end of the top bar.': '버전 {version}. 위쪽 줄 맨 왼쪽 메뉴에서 다른 샘플을 펼쳐 봅니다.',
|
|
256
|
+
'Start with this sample': '이 샘플로 시작',
|
|
257
|
+
'Start a working copy from this sample': '이 샘플로 작업본 시작',
|
|
258
|
+
'Write the reason for your choice': '고른 이유를 적어 주세요',
|
|
259
|
+
'Click an element here to attach it as the reference for your next style change.': '여기서 요소를 누르면 다음 스타일 수정에 참고한 예시로 붙습니다.',
|
|
260
|
+
'Picked example: {label} ({key})': '고른 예시: {label} ({key})',
|
|
261
|
+
'Back to the working copy': '작업본으로 돌아가기',
|
|
262
|
+
'Working copy: {title}': '작업본: {title}',
|
|
263
|
+
'Sample': '샘플',
|
|
264
|
+
'{title} ({id}) version {version}': '{title} ({id}) 버전 {version}',
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/** 지금 언어의 글. 사전에 없으면 영어 원문이다. */
|
|
268
|
+
function lookup(text) {
|
|
269
|
+
return lang === 'ko' && Object.prototype.hasOwnProperty.call(KO, text) ? KO[text] : text;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** 화면 글. {name} 자리에 values 의 값을 넣는다. 값 안의 {name} 은 다시 채우지 않는다. */
|
|
273
|
+
function t(text, values) {
|
|
274
|
+
const s = lookup(text);
|
|
275
|
+
if (!values) return s;
|
|
276
|
+
return s.replace(/\{(\w+)\}/g, (m, k) => (Object.prototype.hasOwnProperty.call(values, k) ? String(values[k]) : m));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** capabilities 의 language 로 언어를 정한다. 한국어면 index.html 의 고정 글(data-t)을 바꾸고 문서의 lang 을 맞춘다. */
|
|
280
|
+
function setLanguage(value) {
|
|
281
|
+
lang = value === 'ko' ? 'ko' : 'en';
|
|
282
|
+
if (lang !== 'ko') return;
|
|
283
|
+
document.documentElement.lang = 'ko';
|
|
284
|
+
for (const n of document.querySelectorAll('[data-t]')) {
|
|
285
|
+
for (const what of n.getAttribute('data-t').split(/\s+/).filter(Boolean)) {
|
|
286
|
+
if (what === 'text') n.textContent = lookup(n.textContent);
|
|
287
|
+
else n.setAttribute(what, lookup(n.getAttribute(what) ?? ''));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// ---- 화면의 언어 끝 ----
|
|
292
|
+
|
|
293
|
+
const errorEl = document.getElementById('error');
|
|
294
|
+
const toastEl = document.getElementById('toast');
|
|
295
|
+
const barEl = document.getElementById('bar');
|
|
296
|
+
const sideEl = document.getElementById('side');
|
|
297
|
+
const frameBox = document.getElementById('frameBox');
|
|
298
|
+
const frameNote = document.getElementById('frameNote');
|
|
299
|
+
const talkEl = document.getElementById('talkBar');
|
|
300
|
+
// 보내는 칸은 위쪽 아이콘 줄 바로 아래에 붙어 있다(rawdev 2026-11-25 "ai에게 보내기 창이 화면 하단에 있어서 잘 안보여. 가능하면 상단에 둬").
|
|
301
|
+
// 아이콘 줄은 폭에 따라 두 줄이 되기도 하므로 그 높이를 따라 붙는 위치를 맞춘다. 스크롤해 무엇을 보이게 할 때(scrollIntoView)는
|
|
302
|
+
// 두 줄의 높이만큼 비워 두어, 작업 내용의 윗부분이 붙어 있는 두 줄 아래에 가려지지 않게 한다
|
|
303
|
+
if (typeof ResizeObserver === 'function') {
|
|
304
|
+
const fit = () => { const st = document.documentElement.style; st.setProperty('--bar-h', `${barEl.offsetHeight}px`); st.setProperty('--talk-h', `${talkEl.offsetHeight}px`); };
|
|
305
|
+
const ro = new ResizeObserver(fit); ro.observe(barEl); ro.observe(talkEl);
|
|
306
|
+
}
|
|
307
|
+
const stageEl = document.getElementById('stage');
|
|
308
|
+
// 아이콘은 이 파일에 적은 고정 svg 글자만 innerHTML 로 넣는다. 사람이나 AI 가 쓴 글은 넣지 않는다(코어 화면의 아이콘과 같은 모양)
|
|
309
|
+
const ICONS = {
|
|
310
|
+
mobile: '<rect x="5" y="1.5" width="6" height="13" rx="1.2"/><path d="M7.3 12.3h1.4"/>',
|
|
311
|
+
desktop: '<rect x="1.5" y="2.5" width="13" height="8.5" rx="1"/><path d="M6 14h4M8 11v3"/>',
|
|
312
|
+
save: '<path d="M8 2v8M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 11v2.5h11V11"/>',
|
|
313
|
+
side: '<rect x="2" y="2.5" width="12" height="11" rx="1.5"/><path d="M10 2.5v11"/>',
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
let nextId = 1;
|
|
317
|
+
const waiting = new Map();
|
|
318
|
+
let concept = null; // 호스트의 읽기 응답. body 가 플러그인 project 의 json 이다
|
|
319
|
+
let caps = { edit: true }; // capabilities(). conceptSelection, conceptPick, output 이 있으면 선택 보내기, 고른 것 알리기, 저장을 쓴다
|
|
320
|
+
let view = null; // 'work' 이거나 샘플 id. 한 번에 하나만 펼친다
|
|
321
|
+
let widthKey = 'mobile';
|
|
322
|
+
let mode = 'select'; // select: 고르기(누르거나 끌어 고르고 위쪽 보내는 칸에서 AI 에게 보낸다), preview: 샘플의 원래 동작(링크, 메뉴 펼침, hover)
|
|
323
|
+
// 지금 고른 것. { gen, payload, shared, redrawn, shareSeq, measureSeq } 이고 payload 는 SELECTION_FORMAT 이다.
|
|
324
|
+
// shared 는 대화로 보낸 선택 { id, role, said }, redrawn 은 수정된 revision 을 그린 뒤 같은 대상을 다시 잰 값이다.
|
|
325
|
+
// 둘을 선택 객체 안에 두는 것은, 보내기나 재기를 기다리는 사이 사람이 다른 것을 고르면 늦게 온 응답이 새 선택에
|
|
326
|
+
// 붙지 않게 하려는 것이다(sol 리뷰 F1). 비동기 작업은 시작할 때의 선택 객체를 잡고, 끝난 뒤 그 객체가 아직 지금
|
|
327
|
+
// 선택인지와 자기가 그 선택의 가장 최근 작업인지를 확인한다.
|
|
328
|
+
let selection = null;
|
|
329
|
+
let selectionGen = 0;
|
|
330
|
+
let reference = null; // 참고 샘플에서 고른 요소. { sample, version, key, label }
|
|
331
|
+
let drawn = { srcdoc: null, nonce: null, ready: false, token: null, base: null };
|
|
332
|
+
let measureSeq = 0;
|
|
333
|
+
const measureWaits = new Map();
|
|
334
|
+
let committing = false;
|
|
335
|
+
|
|
336
|
+
function call(method, params) {
|
|
337
|
+
return new Promise((resolve, reject) => {
|
|
338
|
+
const id = nextId++;
|
|
339
|
+
waiting.set(id, { resolve, reject });
|
|
340
|
+
parent.postMessage({ aic: 1, id, method, params }, '*');
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ---- 안쪽 문서에서 도는 스크립트 ----
|
|
345
|
+
// 이 두 함수는 문자열로 srcdoc 에 들어간다. 바깥 변수를 쓰지 않는다.
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* 끈 영역에서 걸친 요소와 인접한 두 요소의 간격을 낸다(3절). items 는 [{ key, x, y, width, height }] 이고 rect 는 같은 좌표다.
|
|
349
|
+
* 영역을 통째로 감싼 요소(구역)는 후보에서 뺀다. 간격은 영역 가운데 줄 위아래(또는 좌우)에서 가장 가까운 두 요소 사이다.
|
|
350
|
+
*/
|
|
351
|
+
function computeGap(rect, items) {
|
|
352
|
+
const right = (b) => b.x + b.width;
|
|
353
|
+
const bottom = (b) => b.y + b.height;
|
|
354
|
+
const contains = (b) => b.x <= rect.x && b.y <= rect.y && right(b) >= rect.x + rect.width && bottom(b) >= rect.y + rect.height;
|
|
355
|
+
const overlaps = (b) => b.width > 0 && b.height > 0 && b.x < rect.x + rect.width && right(b) > rect.x && b.y < rect.y + rect.height && bottom(b) > rect.y;
|
|
356
|
+
const free = items.filter((b) => b.width > 0 && b.height > 0 && !contains(b));
|
|
357
|
+
const candidates = free.filter(overlaps).map((b) => b.key);
|
|
358
|
+
const area = (b) => b.width * b.height;
|
|
359
|
+
const pick = (list, score) => list.sort((p, q) => score(p) - score(q) || area(p) - area(q))[0];
|
|
360
|
+
const vertical = () => {
|
|
361
|
+
const cy = rect.y + rect.height / 2;
|
|
362
|
+
const xs = free.filter((b) => b.x < rect.x + rect.width && right(b) > rect.x);
|
|
363
|
+
const a = pick(xs.filter((b) => bottom(b) <= cy + 0.5), (b) => -bottom(b));
|
|
364
|
+
const b = pick(xs.filter((b) => b.y >= cy - 0.5), (b) => b.y);
|
|
365
|
+
return a && b && b.y >= bottom(a) ? { a: a.key, b: b.key, direction: 'vertical', px: Math.round((b.y - bottom(a)) * 10) / 10 } : null;
|
|
366
|
+
};
|
|
367
|
+
const horizontal = () => {
|
|
368
|
+
const cx = rect.x + rect.width / 2;
|
|
369
|
+
const ys = free.filter((b) => b.y < rect.y + rect.height && bottom(b) > rect.y);
|
|
370
|
+
const a = pick(ys.filter((b) => right(b) <= cx + 0.5), (b) => -right(b));
|
|
371
|
+
const b = pick(ys.filter((b) => b.x >= cx - 0.5), (b) => b.x);
|
|
372
|
+
return a && b && b.x >= right(a) ? { a: a.key, b: b.key, direction: 'horizontal', px: Math.round((b.x - right(a)) * 10) / 10 } : null;
|
|
373
|
+
};
|
|
374
|
+
const gap = rect.width >= rect.height ? vertical() || horizontal() : horizontal() || vertical();
|
|
375
|
+
return { candidates, gap };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function agentMain(cfg, computeGap) {
|
|
379
|
+
let mode = cfg.mode;
|
|
380
|
+
const post = (m) => parent.postMessage(Object.assign({ aicAgent: 1, nonce: cfg.nonce }, m), '*');
|
|
381
|
+
// 선택 표시는 shadow root 에 그려 샘플 CSS 와 섞이지 않게 한다. 저장하는 파일에는 이 스크립트가 들어가지 않는다
|
|
382
|
+
const host = document.createElement('div');
|
|
383
|
+
host.setAttribute('data-aic-overlay', '');
|
|
384
|
+
host.style.cssText = 'position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:2147483647';
|
|
385
|
+
const shadow = host.attachShadow({ mode: 'closed' });
|
|
386
|
+
shadow.innerHTML = '<style>.b{position:fixed;border:2px solid #1f6a8c;background:rgba(31,106,140,.08);pointer-events:none;box-sizing:border-box}.d{border-style:dashed}.g{position:fixed;background:rgba(224,122,139,.45);pointer-events:none}.t{position:fixed;font:12px/1.4 system-ui,sans-serif;background:#1f6a8c;color:#fff;padding:0 4px;border-radius:3px;white-space:nowrap}</style><div id="l"></div>';
|
|
387
|
+
const layer = shadow.getElementById('l');
|
|
388
|
+
document.documentElement.appendChild(host);
|
|
389
|
+
let marks = null;
|
|
390
|
+
const byKey = (k) => document.querySelector('[data-aic-key="' + CSS.escape(k) + '"]');
|
|
391
|
+
const keyed = (n) => {
|
|
392
|
+
const e = n && (n.nodeType === 1 ? n : n.parentElement);
|
|
393
|
+
return e ? e.closest('[data-aic-key]') : null;
|
|
394
|
+
};
|
|
395
|
+
const pathOf = (n) => { const out = []; for (let x = keyed(n); x; x = x.parentElement ? x.parentElement.closest('[data-aic-key]') : null) out.push(x.getAttribute('data-aic-key')); return out; };
|
|
396
|
+
const textOf = (e) => (e.children.length === 0 ? e.textContent.replace(/\s+/g, ' ').trim() : null);
|
|
397
|
+
function linesOf(e) {
|
|
398
|
+
const r = document.createRange();
|
|
399
|
+
r.selectNodeContents(e);
|
|
400
|
+
const tops = new Set();
|
|
401
|
+
for (const b of r.getClientRects()) if (b.width > 0 && b.height > 0) tops.add(Math.round(b.top));
|
|
402
|
+
return tops.size;
|
|
403
|
+
}
|
|
404
|
+
const round = (n) => Math.round(n * 10) / 10;
|
|
405
|
+
function boxOf(e) {
|
|
406
|
+
const b = e.getBoundingClientRect();
|
|
407
|
+
const out = { x: round(b.left), y: round(b.top), width: round(b.width), height: round(b.height) };
|
|
408
|
+
if (textOf(e)) { out.lines = linesOf(e); out.fontSize = getComputedStyle(e).fontSize; }
|
|
409
|
+
return out;
|
|
410
|
+
}
|
|
411
|
+
const viewport = () => ({ width: cfg.width, height: cfg.height, innerWidth: innerWidth, innerHeight: innerHeight, clientWidth: document.documentElement.clientWidth, scrollY: Math.round(scrollY) });
|
|
412
|
+
const openState = () => Array.from(document.querySelectorAll('details[open][data-aic-key]')).map((d) => d.getAttribute('data-aic-key'));
|
|
413
|
+
const allBoxes = () => Array.from(document.querySelectorAll('[data-aic-key]')).map((e) => Object.assign({ key: e.getAttribute('data-aic-key') }, boxOf(e)));
|
|
414
|
+
function measure(keys) {
|
|
415
|
+
const measured = {}, missing = [], texts = {};
|
|
416
|
+
for (const k of keys) {
|
|
417
|
+
const e = byKey(k);
|
|
418
|
+
if (!e) { missing.push(k); continue; }
|
|
419
|
+
measured[k] = boxOf(e);
|
|
420
|
+
const t = textOf(e);
|
|
421
|
+
if (t !== null) texts[k] = t;
|
|
422
|
+
}
|
|
423
|
+
return { measured, missing, texts, viewport: viewport(), open: openState() };
|
|
424
|
+
}
|
|
425
|
+
function draw() {
|
|
426
|
+
layer.textContent = '';
|
|
427
|
+
if (!marks) return;
|
|
428
|
+
const add = (cls, b, text) => {
|
|
429
|
+
const d = document.createElement('div');
|
|
430
|
+
d.className = cls;
|
|
431
|
+
d.style.cssText = 'left:' + b.x + 'px;top:' + b.y + 'px;width:' + b.width + 'px;height:' + b.height + 'px';
|
|
432
|
+
if (text) { d.className = 't'; d.textContent = text; d.style.cssText = 'left:' + b.x + 'px;top:' + Math.max(0, b.y - 18) + 'px'; }
|
|
433
|
+
layer.appendChild(d);
|
|
434
|
+
};
|
|
435
|
+
for (const k of marks.keys || []) { const e = byKey(k); if (e) { const b = boxOf(e); add('b', b); add('t', b, marks.labels && marks.labels[k] || k); } }
|
|
436
|
+
if (marks.rect) add('b d', marks.rect);
|
|
437
|
+
if (marks.gap) {
|
|
438
|
+
const a = byKey(marks.gap.a), b = byKey(marks.gap.b);
|
|
439
|
+
if (a && b) {
|
|
440
|
+
const p = a.getBoundingClientRect(), q = b.getBoundingClientRect();
|
|
441
|
+
const g = marks.gap.direction === 'vertical'
|
|
442
|
+
? { x: Math.max(p.left, q.left), y: p.bottom, width: Math.max(8, Math.min(p.right, q.right) - Math.max(p.left, q.left)), height: Math.max(0, q.top - p.bottom) }
|
|
443
|
+
: { x: p.right, y: Math.max(p.top, q.top), width: Math.max(0, q.left - p.right), height: Math.max(8, Math.min(p.bottom, q.bottom) - Math.max(p.top, q.top)) };
|
|
444
|
+
add('g', g);
|
|
445
|
+
add('t', g, round(marks.gap.direction === 'vertical' ? q.top - p.bottom : q.left - p.right) + 'px');
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
addEventListener('scroll', draw, { passive: true });
|
|
450
|
+
addEventListener('resize', draw);
|
|
451
|
+
// 고르기 모드에서는 샘플의 원래 동작(링크 이동, 메뉴 펼침)을 막고 고른 것만 알린다
|
|
452
|
+
let start = null, dragging = false;
|
|
453
|
+
addEventListener('pointerdown', (e) => {
|
|
454
|
+
if (mode !== 'select' || e.button !== 0) return;
|
|
455
|
+
start = { x: e.clientX, y: e.clientY };
|
|
456
|
+
dragging = false;
|
|
457
|
+
e.preventDefault();
|
|
458
|
+
}, true);
|
|
459
|
+
addEventListener('pointermove', (e) => {
|
|
460
|
+
if (!start) return;
|
|
461
|
+
const w = e.clientX - start.x, h = e.clientY - start.y;
|
|
462
|
+
if (!dragging && Math.abs(w) + Math.abs(h) < 6) return;
|
|
463
|
+
dragging = true;
|
|
464
|
+
marks = { rect: { x: Math.min(start.x, e.clientX), y: Math.min(start.y, e.clientY), width: Math.abs(w), height: Math.abs(h) } };
|
|
465
|
+
draw();
|
|
466
|
+
}, true);
|
|
467
|
+
addEventListener('pointerup', (e) => {
|
|
468
|
+
if (!start) return;
|
|
469
|
+
const s = start;
|
|
470
|
+
start = null;
|
|
471
|
+
if (dragging) {
|
|
472
|
+
const rect = { x: round(Math.min(s.x, e.clientX)), y: round(Math.min(s.y, e.clientY)), width: round(Math.abs(e.clientX - s.x)), height: round(Math.abs(e.clientY - s.y)) };
|
|
473
|
+
const found = computeGap(rect, allBoxes());
|
|
474
|
+
const keys = found.candidates.concat(found.gap ? [found.gap.a, found.gap.b] : []);
|
|
475
|
+
post({ type: 'area', rect: rect, candidates: found.candidates, gap: found.gap, m: measure(Array.from(new Set(keys))) });
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const target = document.elementFromPoint(e.clientX, e.clientY);
|
|
479
|
+
const path = pathOf(target);
|
|
480
|
+
post({ type: 'pick', path: path, m: measure(path) });
|
|
481
|
+
}, true);
|
|
482
|
+
addEventListener('click', (e) => {
|
|
483
|
+
if (mode === 'select') { e.preventDefault(); e.stopPropagation(); return; }
|
|
484
|
+
// srcdoc 문서의 링크는 바깥 플러그인 문서의 주소를 기준으로 풀려, #about 도 같은 문서 안의 이동이 아니라 플러그인 주소로의
|
|
485
|
+
// 새 이동이 되고 frame-src 에 막힌다(실제 코어로 돌려 보며 찾음). <base> 는 base-uri 'none' 에 막힌다.
|
|
486
|
+
// 그래서 링크는 여기서 직접 같은 문서 안의 위치로 옮긴다. 정제가 # 아닌 링크를 # 로 바꿔 두었다
|
|
487
|
+
const a = e.target && e.target.closest ? e.target.closest('a[href]') : null;
|
|
488
|
+
if (!a) return;
|
|
489
|
+
e.preventDefault();
|
|
490
|
+
const href = a.getAttribute('href') || '';
|
|
491
|
+
const target = href.length > 1 && href[0] === '#' ? document.getElementById(href.slice(1)) : null;
|
|
492
|
+
if (target) target.scrollIntoView({ block: 'start' });
|
|
493
|
+
else window.scrollTo(0, 0);
|
|
494
|
+
}, true);
|
|
495
|
+
document.addEventListener('toggle', () => { post({ type: 'state', open: openState() }); draw(); }, true);
|
|
496
|
+
addEventListener('message', (e) => {
|
|
497
|
+
if (e.source !== parent || !e.data || e.data.aicHost !== 1 || e.data.nonce !== cfg.nonce) return;
|
|
498
|
+
const d = e.data;
|
|
499
|
+
if (d.type === 'mode') { mode = d.mode; if (mode !== 'select') { start = null; } }
|
|
500
|
+
else if (d.type === 'marks') { marks = d.marks; draw(); }
|
|
501
|
+
else if (d.type === 'measure') post({ type: 'measured', req: d.req, m: measure(d.keys || []) });
|
|
502
|
+
else if (d.type === 'show') { const t = byKey(d.key); if (t && t.scrollIntoView) t.scrollIntoView({ block: 'center' }); draw(); }
|
|
503
|
+
});
|
|
504
|
+
const ready = () => post({ type: 'ready', m: measure([]) });
|
|
505
|
+
if (document.readyState === 'complete') ready(); else addEventListener('load', ready);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// ---- 그리기 ----
|
|
509
|
+
|
|
510
|
+
/** 샘플 HTML 을 그리기 전에 한 번 더 거른다(2절). 원본은 논리가 이미 검사했고, 이것은 겹쳐 두는 검사다. */
|
|
511
|
+
function sanitizeHtml(html) {
|
|
512
|
+
if (typeof DOMParser === 'undefined') return html.replace(/<\s*script[\s\S]*?<\s*\/\s*script\s*>/gi, '').replace(/\son[a-z]+\s*=\s*"[^"]*"/gi, '');
|
|
513
|
+
const doc = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
|
|
514
|
+
for (const n of doc.body.querySelectorAll('script,iframe,object,embed,link,meta,base,form,frame,frameset,template,style')) n.remove();
|
|
515
|
+
for (const n of doc.body.querySelectorAll('*')) {
|
|
516
|
+
for (const a of Array.from(n.attributes)) {
|
|
517
|
+
const name = a.name.toLowerCase();
|
|
518
|
+
if (name.startsWith('on') || name === 'style' || name === 'srcset' || name === 'formaction' || name === 'action') n.removeAttribute(a.name);
|
|
519
|
+
else if (name === 'href' && !/^#[\w-]*$/.test(a.value)) n.setAttribute('href', '#');
|
|
520
|
+
else if ((name === 'src' || name === 'poster') && !/^data:image\//.test(a.value)) n.removeAttribute(a.name);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return doc.body.innerHTML;
|
|
524
|
+
}
|
|
525
|
+
const sanitizeCss = (css) => css.replace(/<\/style/gi, '').replace(/@import[^;]*;?/gi, '').replace(/url\(\s*(["']?)(?!data:)[^)]*\)/gi, 'none');
|
|
526
|
+
|
|
527
|
+
function srcdocFor(doc, nonce) {
|
|
528
|
+
const size = WIDTHS[widthKey];
|
|
529
|
+
const cfg = { nonce, mode, width: size.width, height: size.height };
|
|
530
|
+
const agent = `(${agentMain.toString()})(${JSON.stringify(cfg)}, ${computeGap.toString()});`.replace(/<\//g, '<\\/');
|
|
531
|
+
return `<!doctype html><html lang="ko"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><style>${sanitizeCss(doc.css)}</style></head><body>${sanitizeHtml(doc.html)}<script>${agent}<\/script></body></html>`;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function currentDoc() {
|
|
535
|
+
const b = concept?.body;
|
|
536
|
+
if (!b) return null;
|
|
537
|
+
if (view === 'work') return b.current;
|
|
538
|
+
return b.catalog.find((c) => c.id === view)?.doc ?? null;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
let frame = null;
|
|
542
|
+
function ensureFrame() {
|
|
543
|
+
if (frame) return frame;
|
|
544
|
+
frame = document.createElement('iframe');
|
|
545
|
+
frame.setAttribute('id', 'frame');
|
|
546
|
+
frame.setAttribute('title', t('Design screen'));
|
|
547
|
+
// sandbox 를 따로 달지 않는다. 플러그인 iframe 의 sandbox(allow-scripts)와 화면 정책을 그대로 물려받는다(6절)
|
|
548
|
+
frameBox.append(frame);
|
|
549
|
+
return frame;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function sizeFrame() {
|
|
553
|
+
const size = WIDTHS[widthKey];
|
|
554
|
+
const f = ensureFrame();
|
|
555
|
+
f.setAttribute('width', String(size.width));
|
|
556
|
+
f.setAttribute('height', String(size.height));
|
|
557
|
+
f.style.width = `${size.width}px`;
|
|
558
|
+
f.style.height = `${size.height}px`;
|
|
559
|
+
// 좁은 칸에서는 줄여서 보인다. 안쪽 viewport 는 그대로라 측정값은 CSS px 그대로다
|
|
560
|
+
const avail = Math.max(320, (document.getElementById('canvas')?.clientWidth ?? size.width) - 26);
|
|
561
|
+
const scale = Math.min(1, avail / size.width);
|
|
562
|
+
frameBox.style.width = `${size.width * scale}px`;
|
|
563
|
+
frameBox.style.height = `${size.height * scale}px`;
|
|
564
|
+
f.style.transform = scale < 1 ? `scale(${scale})` : '';
|
|
565
|
+
f.style.transformOrigin = '0 0';
|
|
566
|
+
// 위쪽 줄에 짧게 적는다. 줄여 보이면 그 비율도 적는다(측정값은 줄이기 전의 CSS px 다)
|
|
567
|
+
frameNote.textContent = `${size.width}×${size.height}${scale < 1 ? `, ${Math.round(scale * 100)}%` : ''}`;
|
|
568
|
+
frameNote.setAttribute('title', scale < 1 ? t('{label}×{height} CSS px, shown at {percent}%', { label: size.label(), height: size.height, percent: Math.round(scale * 100) }) : `${size.label()}×${size.height} CSS px`);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** 지금 보는 문서를 그린다. 같은 문서면 다시 그리지 않아 스크롤과 펼친 상태를 지킨다. */
|
|
572
|
+
function drawFrame() {
|
|
573
|
+
const doc = currentDoc();
|
|
574
|
+
sizeFrame();
|
|
575
|
+
if (!doc) return false;
|
|
576
|
+
const key = `${view}|${widthKey}|${doc.css}|${doc.html}`;
|
|
577
|
+
if (drawn.key === key) return true;
|
|
578
|
+
const nonce = `n${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
579
|
+
drawn = { key, nonce, ready: false, token: drawn.token, base: drawn.base };
|
|
580
|
+
ensureFrame().srcdoc = srcdocFor(doc, nonce);
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function toAgent(msg) {
|
|
585
|
+
if (!frame?.contentWindow || !drawn.nonce) return;
|
|
586
|
+
frame.contentWindow.postMessage({ aicHost: 1, nonce: drawn.nonce, ...msg }, '*');
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function measureKeys(keys) {
|
|
590
|
+
return new Promise((resolve) => {
|
|
591
|
+
if (!drawn.ready) { resolve(null); return; }
|
|
592
|
+
const req = (measureSeq += 1);
|
|
593
|
+
measureWaits.set(req, resolve);
|
|
594
|
+
toAgent({ type: 'measure', req, keys });
|
|
595
|
+
setTimeout(() => { if (measureWaits.delete(req)) resolve(null); }, 3000);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// ---- 호스트 ----
|
|
600
|
+
|
|
601
|
+
window.addEventListener('message', (e) => {
|
|
602
|
+
const d = e.data;
|
|
603
|
+
if (frame && e.source === frame.contentWindow) {
|
|
604
|
+
if (typeof d === 'object' && d !== null && d.aicAgent === 1 && d.nonce === drawn.nonce) onAgent(d);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (e.source !== parent) return;
|
|
608
|
+
if (typeof d !== 'object' || d === null || d.aic !== 1) return;
|
|
609
|
+
if (d.event === 'change') { refresh(); return; }
|
|
610
|
+
const w = waiting.get(d.id);
|
|
611
|
+
if (!w) return;
|
|
612
|
+
waiting.delete(d.id);
|
|
613
|
+
if (d.error) w.reject(new Error(d.error));
|
|
614
|
+
else w.resolve(d.result);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
function onAgent(d) {
|
|
618
|
+
if (d.type === 'ready') {
|
|
619
|
+
drawn.ready = true;
|
|
620
|
+
toAgent({ type: 'mode', mode });
|
|
621
|
+
pushMarks();
|
|
622
|
+
afterDraw();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (d.type === 'measured') {
|
|
626
|
+
const w = measureWaits.get(d.req);
|
|
627
|
+
if (w) { measureWaits.delete(d.req); w(d.m); }
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (d.type === 'state') return;
|
|
631
|
+
if (d.type === 'pick') { if (Array.isArray(d.path) && d.path.length) onPick(d.path, d.m); return; }
|
|
632
|
+
if (d.type === 'area' && d.rect) onArea(d);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const els = () => concept?.body?.elements ?? [];
|
|
636
|
+
const idOfKey = (k) => els().find((e) => e.key === k)?.id ?? null;
|
|
637
|
+
const elById = (id) => els().find((e) => e.id === id) ?? null;
|
|
638
|
+
const catalogOf = (id) => concept?.body?.catalog?.find((c) => c.id === id) ?? null;
|
|
639
|
+
|
|
640
|
+
/** 화면이 잰 키 단위 값을 record id 단위로 바꾼다. */
|
|
641
|
+
function byIds(map) {
|
|
642
|
+
const out = {};
|
|
643
|
+
for (const [k, v] of Object.entries(map ?? {})) { const id = idOfKey(k); if (id) out[id] = v; }
|
|
644
|
+
return out;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function basePayload(m) {
|
|
648
|
+
const page = concept.body.page;
|
|
649
|
+
return {
|
|
650
|
+
format: SELECTION_FORMAT,
|
|
651
|
+
page: page.id,
|
|
652
|
+
sample: { id: page.sample.id, version: page.sample.version },
|
|
653
|
+
plugin: PLUGIN_VERSION,
|
|
654
|
+
renderer: RENDERER,
|
|
655
|
+
rev: drawn.base ?? concept.base,
|
|
656
|
+
viewport: m.viewport,
|
|
657
|
+
state: { open: (m.open ?? []).map(idOfKey).filter(Boolean) },
|
|
658
|
+
labels: {},
|
|
659
|
+
texts: byIds(m.texts),
|
|
660
|
+
measured: byIds(m.measured),
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function withLabels(p, ids) {
|
|
665
|
+
for (const id of ids) { const e = elById(id); if (e) p.labels[id] = e.label; }
|
|
666
|
+
return p;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function onPick(pathKeys, m) {
|
|
670
|
+
if (view !== 'work') {
|
|
671
|
+
// 참고 샘플에서 고른 것은 다음 스타일 수정의 출처로 붙인다(2절의 수정 범위)
|
|
672
|
+
const c = catalogOf(view);
|
|
673
|
+
const k = pathKeys[0];
|
|
674
|
+
const e = c?.elements.find((x) => x.key === k);
|
|
675
|
+
reference = c && e ? { sample: c.id, version: c.version, key: k, label: e.label } : null;
|
|
676
|
+
pushMarks();
|
|
677
|
+
render();
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const path = pathKeys.map(idOfKey).filter(Boolean);
|
|
681
|
+
if (!path.length) return;
|
|
682
|
+
const p = withLabels({ ...basePayload(m), kind: 'element', element: path[0], path }, path);
|
|
683
|
+
setSelection(p, true);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function onArea(d) {
|
|
687
|
+
if (view !== 'work') return;
|
|
688
|
+
const candidates = (d.candidates ?? []).map(idOfKey).filter(Boolean);
|
|
689
|
+
const gap = d.gap && idOfKey(d.gap.a) && idOfKey(d.gap.b) ? { ...d.gap, a: idOfKey(d.gap.a), b: idOfKey(d.gap.b) } : null;
|
|
690
|
+
const p = withLabels({ ...basePayload(d.m), kind: 'area', area: d.rect, candidates, gap }, [...candidates, ...(gap ? [gap.a, gap.b] : [])]);
|
|
691
|
+
setSelection(p, true);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** 화면에서 누르거나 끌어 고르면(toTalk) 바로 말을 적도록 보내는 칸에 초점을 옮긴다. 목록에서 고를 때는 옮기지 않는다. */
|
|
695
|
+
function setSelection(payload, toTalk = false) {
|
|
696
|
+
selection = { gen: (selectionGen += 1), payload, shared: null, redrawn: null, shareSeq: 0, measureSeq: 0 };
|
|
697
|
+
pushMarks();
|
|
698
|
+
render();
|
|
699
|
+
notifyPick();
|
|
700
|
+
if (toTalk) focusTalk();
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** 선택이 가리키는 record. 보낼 때와 고른 것을 알릴 때 같다. */
|
|
704
|
+
function selectionRecords(p) {
|
|
705
|
+
return [...new Set([...(p.kind === 'element' ? [p.element] : p.candidates), ...(p.gap ? [p.gap.a, p.gap.b] : [])])];
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/** 고른 것을 호스트에 알린다(032 30절 11번, rawdev 2026-11-18). 코어는 기록하지 않고 선택 id 를 만들지 않으며 AI 를 깨우지 않는다.
|
|
709
|
+
* AI 는 read_selection 에서 "화면에서 지금 고른 것(보내지 않음)" 으로 읽는다. 모양은 shareSelection 에서 role 과 said 를 뺀 것이고
|
|
710
|
+
* 답은 기다리지 않는다. 보낸 뒤에는 코어가 지우므로 null 을 보내지 않고, 화면이 바뀌거나 닫히면 호스트가 지운다. */
|
|
711
|
+
function notifyPick() {
|
|
712
|
+
if (!caps.conceptPick || caps.edit === false) return;
|
|
713
|
+
const p = selection?.payload ?? null;
|
|
714
|
+
call('setPick', p ? { base: p.rev, payload: p, records: selectionRecords(p) } : null).catch(() => {});
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** 고른 뒤 말 칸으로 초점을 옮긴다. 초점을 줄 때의 스크롤은 막고, 보내는 칸이 화면 밖에 있을 때만 보일 만큼 움직인다(위에 붙어 있어 보통은 움직이지 않는다).
|
|
718
|
+
* 그래야 방금 고른 곳이 화면에서 크게 밀려나지 않는다. */
|
|
719
|
+
function focusTalk() {
|
|
720
|
+
if (typeof talkInput?.focus !== 'function') return;
|
|
721
|
+
try { talkInput.focus({ preventScroll: true }); } catch { talkInput.focus(); }
|
|
722
|
+
if (typeof talkEl.getBoundingClientRect !== 'function') return;
|
|
723
|
+
const r = talkEl.getBoundingClientRect();
|
|
724
|
+
if (r.bottom > window.innerHeight || r.top < 0) talkEl.scrollIntoView({ block: 'nearest' });
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** 고른 요소를 다시 고른다(가장 안쪽에서 감싼 구역으로, 또는 요소 목록에서). 측정값은 다시 잰다. */
|
|
728
|
+
async function selectElement(id) {
|
|
729
|
+
const e = elById(id);
|
|
730
|
+
if (!e) return;
|
|
731
|
+
const keys = [];
|
|
732
|
+
for (let x = e; x; x = x.parent ? elById(x.parent) : null) keys.push(x.key);
|
|
733
|
+
const gen = selectionGen;
|
|
734
|
+
const m = (await measureKeys(keys)) ?? { measured: {}, texts: {}, viewport: { width: WIDTHS[widthKey].width, height: WIDTHS[widthKey].height }, open: [] };
|
|
735
|
+
// 재는 사이 사람이 다른 것을 골랐으면 그쪽을 둔다
|
|
736
|
+
if (gen !== selectionGen) return;
|
|
737
|
+
const path = keys.map(idOfKey).filter(Boolean);
|
|
738
|
+
setSelection(withLabels({ ...basePayload(m), kind: 'element', element: id, path }, path));
|
|
739
|
+
toAgent({ type: 'show', key: e.key });
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function selectionKeys(p) {
|
|
743
|
+
const ids = p.kind === 'element' ? [p.element] : [...(p.candidates ?? []), ...(p.gap ? [p.gap.a, p.gap.b] : [])];
|
|
744
|
+
return [...new Set(ids)].map((id) => elById(id)?.key ?? null).filter(Boolean);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function pushMarks() {
|
|
748
|
+
if (!drawn.ready) return;
|
|
749
|
+
if (view !== 'work') {
|
|
750
|
+
toAgent({ type: 'marks', marks: reference && reference.sample === view ? { keys: [reference.key], labels: { [reference.key]: t('Reference: {name}', { name: reference.label }) } } : null });
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const p = selection?.payload;
|
|
754
|
+
if (!p) { toAgent({ type: 'marks', marks: null }); return; }
|
|
755
|
+
const labels = {};
|
|
756
|
+
for (const id of Object.keys(p.labels)) { const e = elById(id); if (e) labels[e.key] = `${e.label} ${id}`; }
|
|
757
|
+
const gap = p.gap ? { ...p.gap, a: elById(p.gap.a)?.key, b: elById(p.gap.b)?.key } : null;
|
|
758
|
+
// 끈 사각형은 그때 그린 화면의 좌표다. 다시 그린 뒤에는 숨기고 같은 두 요소 사이의 간격만 표시한다
|
|
759
|
+
const rect = p.rev === (drawn.base ?? concept.base) ? p.area : null;
|
|
760
|
+
toAgent({ type: 'marks', marks: p.kind === 'element' ? { keys: [elById(p.element)?.key].filter(Boolean), labels } : { rect, gap: gap && gap.a && gap.b ? gap : null, keys: [], labels } });
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** 그린 뒤에 할 일: 그린 기준을 호스트에 알리고, 선택이 있으면 같은 대상을 다시 잰다(4절). */
|
|
764
|
+
async function afterDraw() {
|
|
765
|
+
if (drawPending && concept && typeof concept.renderToken === 'string') {
|
|
766
|
+
drawPending = false;
|
|
767
|
+
drawn.base = concept.base;
|
|
768
|
+
parent.postMessage({ aic: 1, event: 'rendered', token: concept.renderToken }, '*');
|
|
769
|
+
}
|
|
770
|
+
await remeasure();
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
async function remeasure() {
|
|
774
|
+
const sel = selection;
|
|
775
|
+
const p = sel?.payload;
|
|
776
|
+
if (!p || view !== 'work' || !concept) return;
|
|
777
|
+
if (p.rev === concept.base && !sel.redrawn) return; // 선택한 revision 그대로면 당시 값과 같다
|
|
778
|
+
if (sel.redrawn && sel.redrawn.rev === concept.base && sel.redrawn.viewport.width === WIDTHS[widthKey].width) return;
|
|
779
|
+
// 이 재기가 시작할 때의 선택, 그린 문서, 기준을 잡는다. 끝난 뒤 하나라도 바뀌었으면 버린다
|
|
780
|
+
const seq = (sel.measureSeq += 1);
|
|
781
|
+
const base = concept.base;
|
|
782
|
+
const nonce = drawn.nonce;
|
|
783
|
+
const keys = selectionKeys(p);
|
|
784
|
+
const m = await measureKeys(keys);
|
|
785
|
+
if (!m || selection !== sel || sel.measureSeq !== seq || drawn.nonce !== nonce || concept.base !== base || view !== 'work') return;
|
|
786
|
+
const measured = byIds(m.measured);
|
|
787
|
+
let gap = null;
|
|
788
|
+
if (p.gap) {
|
|
789
|
+
const a = measured[p.gap.a], b = measured[p.gap.b];
|
|
790
|
+
if (a && b) gap = { ...p.gap, px: Math.round((p.gap.direction === 'vertical' ? b.y - (a.y + a.height) : b.x - (a.x + a.width)) * 10) / 10 };
|
|
791
|
+
}
|
|
792
|
+
const redrawn = {
|
|
793
|
+
rev: base,
|
|
794
|
+
viewport: m.viewport,
|
|
795
|
+
state: { open: (m.open ?? []).map(idOfKey).filter(Boolean) },
|
|
796
|
+
renderer: RENDERER,
|
|
797
|
+
measured,
|
|
798
|
+
gap,
|
|
799
|
+
missing: (m.missing ?? []).map(idOfKey).filter(Boolean),
|
|
800
|
+
};
|
|
801
|
+
sel.redrawn = redrawn;
|
|
802
|
+
// 보내는 선택 id 는 이 측정과 같은 선택 객체에 붙은 것이다. 나중에 바뀐 지금 선택의 id 를 읽지 않는다
|
|
803
|
+
if (sel.shared && caps.conceptSelection) {
|
|
804
|
+
try {
|
|
805
|
+
await call('reportMeasurement', { selection: sel.shared.id, payload: redrawn });
|
|
806
|
+
} catch (err) {
|
|
807
|
+
toast(t('Could not send the new measurements: {message}', { message: err.message }), true);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
pushMarks();
|
|
811
|
+
render();
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
let drawPending = false;
|
|
815
|
+
let inflight = null;
|
|
816
|
+
let again = false;
|
|
817
|
+
function refresh() {
|
|
818
|
+
if (inflight) { again = true; return inflight; }
|
|
819
|
+
inflight = (async () => {
|
|
820
|
+
try {
|
|
821
|
+
const c = await call('readConcept');
|
|
822
|
+
errorEl.hidden = true;
|
|
823
|
+
// 다른 참여자(AI)의 아직 합쳐지지 않은 변경까지 얹은 상태를 그린다(트리 화면과 같다). 코어도 선택의 record 와
|
|
824
|
+
// 저장할 파일을 이 상태로 본다. 이것을 빼면 AI 가 고친 것이 합쳐지기 전까지 화면에 보이지 않는다
|
|
825
|
+
concept = { ...c, body: c.withOthers ?? c.body };
|
|
826
|
+
const b = concept.body ?? {};
|
|
827
|
+
if (view === null || (view === 'work' && !b.page)) view = b.page ? 'work' : b.catalog?.[0]?.id ?? null;
|
|
828
|
+
if (selection && b.page && selection.payload.page !== b.page.id) { selection = null; selectionGen += 1; notifyPick(); }
|
|
829
|
+
drawPending = typeof c.renderToken === 'string';
|
|
830
|
+
render();
|
|
831
|
+
// 문서가 그대로면 다시 그리지 않으므로 여기서 그린 기준을 알린다. 바뀌었으면 안쪽 문서가 ready 를 알릴 때 알린다
|
|
832
|
+
if (drawFrame() && drawn.ready) await afterDraw();
|
|
833
|
+
} catch (err) {
|
|
834
|
+
errorEl.textContent = err.message;
|
|
835
|
+
errorEl.hidden = false;
|
|
836
|
+
}
|
|
837
|
+
})().finally(() => {
|
|
838
|
+
inflight = null;
|
|
839
|
+
if (again) { again = false; refresh(); }
|
|
840
|
+
});
|
|
841
|
+
return inflight;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
let toastTimer = null;
|
|
845
|
+
function toast(text, bad = false) {
|
|
846
|
+
toastEl.textContent = text;
|
|
847
|
+
toastEl.classList.toggle('bad', bad);
|
|
848
|
+
toastEl.hidden = false;
|
|
849
|
+
clearTimeout(toastTimer);
|
|
850
|
+
toastTimer = setTimeout(() => { toastEl.hidden = true; }, bad ? 7000 : 3500);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
async function send(steps) {
|
|
854
|
+
if (committing) return null;
|
|
855
|
+
committing = true;
|
|
856
|
+
try {
|
|
857
|
+
const res = await call('applyOperation', { base: concept.base, steps });
|
|
858
|
+
if (!res.ok) { toast(res.summary ?? res.error, true); await refresh(); return null; }
|
|
859
|
+
toast(res.summary);
|
|
860
|
+
await refresh();
|
|
861
|
+
return res;
|
|
862
|
+
} catch (err) {
|
|
863
|
+
toast(err.message, true);
|
|
864
|
+
return null;
|
|
865
|
+
} finally {
|
|
866
|
+
committing = false;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// ---- 화면 ----
|
|
871
|
+
|
|
872
|
+
function el(tag, props, ...children) {
|
|
873
|
+
const n = document.createElement(tag);
|
|
874
|
+
for (const [k, v] of Object.entries(props ?? {})) {
|
|
875
|
+
if (k === 'class') n.className = v;
|
|
876
|
+
else if (k === 'on') for (const [ev, fn] of Object.entries(v)) n.addEventListener(ev, fn);
|
|
877
|
+
else if (k === 'value') n.value = v;
|
|
878
|
+
else if (v !== false && v !== null && v !== undefined) n.setAttribute(k, v === true ? '' : v);
|
|
879
|
+
}
|
|
880
|
+
for (const c of children.flat(Infinity)) {
|
|
881
|
+
if (c === null || c === undefined || c === false) continue;
|
|
882
|
+
n.append(c instanceof Node ? c : String(c));
|
|
883
|
+
}
|
|
884
|
+
return n;
|
|
885
|
+
}
|
|
886
|
+
const btn = (label, onClick, extra = {}) => el('button', { type: 'button', class: 'btn', on: { click: onClick }, ...extra }, label);
|
|
887
|
+
const pressed = (on) => (on ? 'true' : 'false');
|
|
888
|
+
function icon(name) {
|
|
889
|
+
const s = el('span', { class: 'ic', 'aria-hidden': 'true' });
|
|
890
|
+
s.innerHTML = `<svg viewBox="0 0 16 16">${ICONS[name]}</svg>`;
|
|
891
|
+
return s;
|
|
892
|
+
}
|
|
893
|
+
/** 아이콘 버튼. 이름은 aria-label 과 title 에 둔다. title 을 따로 주면 그것을 보인다. */
|
|
894
|
+
const iconBtn = (name, label, onClick, extra = {}, ...more) => el('button', { type: 'button', class: 'icon-btn', 'aria-label': label, title: label, on: { click: onClick }, ...extra }, icon(name), ...more);
|
|
895
|
+
|
|
896
|
+
// 접는 칸의 열림은 다시 그려도 지킨다. 화면을 다시 그릴 때마다 닫히지 않게 사람이 연 것을 기억한다
|
|
897
|
+
const folds = {};
|
|
898
|
+
function fold(key, open, summary, children, extra = {}, summaryProps = {}) {
|
|
899
|
+
return el('details', { ...extra, open: folds[key] ?? open, on: { toggle: (e) => { folds[key] = e.target.open; } } }, el('summary', summaryProps, summary), children);
|
|
900
|
+
}
|
|
901
|
+
// 펼친 메뉴는 바깥을 누르면 닫는다
|
|
902
|
+
document.addEventListener?.('click', (e) => {
|
|
903
|
+
for (const d of document.querySelectorAll('details.menu[open]')) if (!d.contains(e.target)) { d.open = false; folds[d.dataset.fold] = false; }
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
// 오른쪽 편집 칸(고른 것의 잰 값, 문구와 스타일 고치기, 요소 목록). 작업본 화면에서는 닫힌 채 시작하고 위쪽 줄 오른쪽 버튼으로 연다.
|
|
907
|
+
// 샘플 고르기와 참고 샘플 화면에서는 그 칸이 그 화면의 할 일(시작하기, 돌아가기)이라 늘 보인다(rawdev 2026-11-24, 코어 화면 032 34절과 같은 방향)
|
|
908
|
+
let sideOpen = false;
|
|
909
|
+
const sideShown = () => !concept?.body?.page || view !== 'work' || sideOpen;
|
|
910
|
+
function toggleSide() { sideOpen = !sideOpen; render(); }
|
|
911
|
+
|
|
912
|
+
function renderBar() {
|
|
913
|
+
const b = concept.body;
|
|
914
|
+
// 보는 화면은 메뉴 하나로 고른다. 메뉴 이름이 지금 보는 화면이라 펼치지 않아도 안다
|
|
915
|
+
const name = (id) => (b.page ? (id === 'work' ? t('Working copy') : t('Reference: {name}', { name: catalogOf(id)?.title ?? id })) : t('Sample: {name}', { name: catalogOf(id)?.title ?? id }));
|
|
916
|
+
const choose = (id) => { folds.view = false; switchView(id); };
|
|
917
|
+
const items = [...(b.page ? [btn(t('Working copy'), () => choose('work'), { 'aria-pressed': pressed(view === 'work') })] : []),
|
|
918
|
+
...b.catalog.map((c) => btn(b.page ? t('Reference: {name}', { name: c.title }) : c.title, () => choose(c.id), { 'aria-pressed': pressed(view === c.id) }))];
|
|
919
|
+
const views = fold('view', false, name(view), el('div', { class: 'pop', role: 'group', 'aria-label': t('View') }, items),
|
|
920
|
+
{ class: 'menu', 'data-fold': 'view' }, { title: t('Choose what to view') });
|
|
921
|
+
const widths = el('div', { class: 'group', role: 'group', 'aria-label': t('Screen width') },
|
|
922
|
+
Object.entries(WIDTHS).map(([k, v]) => iconBtn(k, v.label(), () => { widthKey = k; drawFrame(); render(); }, { 'aria-pressed': pressed(widthKey === k) })), frameNote);
|
|
923
|
+
const modes = el('div', { class: 'group', role: 'group', 'aria-label': t('Mode') },
|
|
924
|
+
btn(t('Pick'), () => setMode('select'), { 'aria-pressed': pressed(mode === 'select'), title: t('Click the screen to pick an element, or drag to pick an area. Then write a message in the send bar at the top and send it to the AI') }),
|
|
925
|
+
btn(t('Preview'), () => setMode('preview'), { 'aria-pressed': pressed(mode === 'preview'), title: t('Links and menus work as in the sample') }));
|
|
926
|
+
const canSave = Boolean(b.page) && Array.isArray(caps.output) && caps.output.includes('html');
|
|
927
|
+
const save = iconBtn('save', t('Save as HTML file'), saveHtml, { disabled: !canSave, title: canSave ? t('Save as HTML file: saves the working copy as a single HTML file') : !b.page ? t('Save as HTML file: start a working copy first') : t('Save as HTML file: this host cannot save HTML yet') });
|
|
928
|
+
// 닫힌 편집 칸에 새로 다시 잰 값이 오면 버튼에 점을 찍는다. 열면 지운다
|
|
929
|
+
const fresh = !sideOpen && Boolean(selection?.redrawn) && selection.seen !== selection.redrawn;
|
|
930
|
+
const side = b.page && view === 'work'
|
|
931
|
+
? iconBtn('side', t('Edit panel'), toggleSide, { 'aria-pressed': pressed(sideOpen), 'aria-controls': 'side',
|
|
932
|
+
title: `${sideOpen ? t('Edit panel (click to close): measurements of what you picked, text and style changes, elements') : t('Edit panel (click to open): measurements of what you picked, text and style changes, elements')}${fresh ? t('. New measurements are in') : ''}` }, fresh ? el('span', { class: 'dot' }) : null)
|
|
933
|
+
: null;
|
|
934
|
+
barEl.replaceChildren(...[views, widths, modes, el('span', { class: 'spacer' }), save, side].filter(Boolean));
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function switchView(v) {
|
|
938
|
+
view = v;
|
|
939
|
+
drawFrame();
|
|
940
|
+
render();
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function setMode(m) {
|
|
944
|
+
mode = m;
|
|
945
|
+
toAgent({ type: 'mode', mode });
|
|
946
|
+
sizeFrame();
|
|
947
|
+
render();
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
async function saveHtml() {
|
|
951
|
+
try {
|
|
952
|
+
const res = await call('saveOutput', { base: concept.base, format: 'html' });
|
|
953
|
+
if (res?.ok) toast(t('Saved: {file}', { file: res.fileName ?? res.artifact }));
|
|
954
|
+
else toast(res?.summary ?? res?.error ?? t('Could not save'), true);
|
|
955
|
+
} catch (err) {
|
|
956
|
+
toast(err.message, true);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function boxText(b) {
|
|
961
|
+
if (!b) return t('none');
|
|
962
|
+
return `${b.x}, ${b.y} / ${b.width}×${b.height}${b.lines ? `, ${b.lines === 1 ? t('{n} line', { n: b.lines }) : t('{n} lines', { n: b.lines })}` : ''}`;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function compareTable(p) {
|
|
966
|
+
const redrawn = selection?.redrawn ?? null;
|
|
967
|
+
const rows = [];
|
|
968
|
+
const head = el('tr', {}, el('th', {}, ''), el('th', {}, t('When picked {rev}', { rev: p.rev })), el('th', {}, redrawn ? t('Redrawn {rev}', { rev: redrawn.rev }) : t('Redrawn')));
|
|
969
|
+
rows.push(el('tr', {}, el('th', {}, t('Width')), el('td', {}, `${p.viewport.width}×${p.viewport.height}`), el('td', {}, redrawn ? `${redrawn.viewport.width}×${redrawn.viewport.height}` : '-')));
|
|
970
|
+
if (p.gap) rows.push(el('tr', {}, el('th', {}, t('Gap')), el('td', {}, `${p.gap.px}px`), el('td', {}, redrawn?.gap ? `${redrawn.gap.px}px` : '-')));
|
|
971
|
+
for (const id of Object.keys(p.measured)) {
|
|
972
|
+
rows.push(el('tr', {}, el('th', {}, `${p.labels[id] ?? id}`), el('td', {}, boxText(p.measured[id])), el('td', {}, redrawn ? (redrawn.missing?.includes(id) ? t('gone') : boxText(redrawn.measured[id])) : '-')));
|
|
973
|
+
}
|
|
974
|
+
const note = !redrawn ? el('p', { class: 'note' }, p.rev === concept.base ? t('Nothing has changed yet, so the values are the same as when picked.') : t('Waiting for measurement: the screen measures again after it draws the new revision.')) : null;
|
|
975
|
+
// 폭이 달라 견줄 수 없다는 알림은 접힌 표 밖에 둔다
|
|
976
|
+
const warn = redrawn && redrawn.viewport.width !== p.viewport.width ? el('p', { class: 'warn' }, t('The width is different, so the two values cannot be compared directly.')) : null;
|
|
977
|
+
return [warn, fold('measure', false, redrawn ? t('Measurements: when picked and redrawn {rev}', { rev: redrawn.rev }) : t('Measurements'), [el('table', { class: 'compare' }, el('thead', {}, head), el('tbody', {}, rows)), note], { class: 'sub' })];
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function selectionSection() {
|
|
981
|
+
const p = selection?.payload;
|
|
982
|
+
if (!p) {
|
|
983
|
+
return el('section', {}, el('h2', {}, t('Picked')),
|
|
984
|
+
el('p', { class: 'note' }, t('Nothing is picked yet. Click or drag on the screen to pick. With a keyboard, pick from the elements list below.')));
|
|
985
|
+
}
|
|
986
|
+
const parts = [el('h2', {}, p.kind === 'element' ? t('Picked element') : t('Picked area'))];
|
|
987
|
+
if (p.kind === 'element') {
|
|
988
|
+
const e = elById(p.element);
|
|
989
|
+
parts.push(el('dl', { class: 'kv' },
|
|
990
|
+
el('dt', {}, t('Element')), el('dd', {}, `${e?.label ?? p.labels[p.element]} (${p.element})`),
|
|
991
|
+
p.texts[p.element] !== undefined ? [el('dt', {}, t('Text')), el('dd', {}, p.texts[p.element])] : null));
|
|
992
|
+
if (p.path && p.path.length > 1) {
|
|
993
|
+
parts.push(el('div', { class: 'crumbs' }, el('span', { class: 'note' }, t('Pick a wrapping section')),
|
|
994
|
+
p.path.map((id) => el('button', { type: 'button', class: 'chip', 'aria-current': id === p.element ? 'true' : 'false', on: { click: () => selectElement(id) } }, elById(id)?.label ?? id))));
|
|
995
|
+
}
|
|
996
|
+
} else {
|
|
997
|
+
parts.push(el('dl', { class: 'kv' },
|
|
998
|
+
el('dt', {}, t('Area')), el('dd', {}, `${p.area.x}, ${p.area.y} / ${p.area.width}×${p.area.height}`),
|
|
999
|
+
el('dt', {}, t('Elements in area')), el('dd', {}, p.candidates.length ? '' : t('none')),
|
|
1000
|
+
p.gap ? [el('dt', {}, t('Gap')), el('dd', {}, p.gap.direction === 'vertical'
|
|
1001
|
+
? t('vertical {px}px between {a} and {b}', { px: p.gap.px, a: p.labels[p.gap.a], b: p.labels[p.gap.b] })
|
|
1002
|
+
: t('horizontal {px}px between {a} and {b}', { px: p.gap.px, a: p.labels[p.gap.a], b: p.labels[p.gap.b] }))] : null));
|
|
1003
|
+
if (p.candidates.length) {
|
|
1004
|
+
parts.push(el('div', { class: 'crumbs' }, p.candidates.map((id) => el('button', { type: 'button', class: 'chip', on: { click: () => selectElement(id) } }, elById(id)?.label ?? id))));
|
|
1005
|
+
if (p.candidates.length > 1) parts.push(el('p', { class: 'note' }, t('Several elements are in the area. Click one to pick only that element.')));
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
parts.push(...compareTable(p));
|
|
1009
|
+
return el('section', {}, parts);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
let talk = { role: 'change', said: '' };
|
|
1013
|
+
let talkInput = null;
|
|
1014
|
+
const MAX_TALK_NAMES = 3;
|
|
1015
|
+
|
|
1016
|
+
/** 보내는 칸에 적는 고른 것의 한 줄. 무엇을 골랐는지 사람이 바로 알아보게 쓴다. */
|
|
1017
|
+
function selText(p) {
|
|
1018
|
+
const label = (id) => elById(id)?.label ?? p.labels[id] ?? id;
|
|
1019
|
+
if (p.kind === 'element') {
|
|
1020
|
+
const words = p.texts[p.element];
|
|
1021
|
+
return `${label(p.element)}${words ? ` "${words.length > 30 ? `${words.slice(0, 30)}…` : words}"` : ''}`;
|
|
1022
|
+
}
|
|
1023
|
+
if (p.gap) return t('area between {a} and {b}', { a: label(p.gap.a), b: label(p.gap.b) });
|
|
1024
|
+
if (!p.candidates.length) return t('empty area');
|
|
1025
|
+
const names = p.candidates.slice(0, MAX_TALK_NAMES).map(label).join(', ');
|
|
1026
|
+
return p.candidates.length > MAX_TALK_NAMES
|
|
1027
|
+
? t('area ({names} and {more} more)', { names, more: p.candidates.length - MAX_TALK_NAMES })
|
|
1028
|
+
: t('area ({names})', { names });
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/** 고른 뒤 다시 그린 값이 오면 한눈에 보이게 보내는 칸의 줄에 간격의 변화를 적는다. */
|
|
1032
|
+
function gapChange(p) {
|
|
1033
|
+
const r = selection?.redrawn;
|
|
1034
|
+
return p.gap && r?.gap && r.viewport.width === p.viewport.width ? ` ${t('The gap was {was}px and is now {now}px.', { was: p.gap.px, now: r.gap.px })}` : '';
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// 고른 것을 AI 에게 보내는 칸(svg 플러그인의 보내는 칸과 같은 이유, rawdev 2026-11-18). 위쪽 아이콘 줄 바로 아래에 붙여 늘 보이게 둔다(처음에는 화면 아래였다, rawdev 2026-11-25 위로 옮김).
|
|
1038
|
+
// 한 줄로 줄였다(rawdev 2026-11-24): 고르기 전에는 말 칸의 안내 글이 할 일을 말하고, 차례와 AI 가 읽는 방식은 [?] 를 눌러 본다.
|
|
1039
|
+
// 고른 뒤에는 고른 것, 보냈는지, 다시 잰 간격처럼 한눈에 보여야 하는 것만 한 줄로 적는다.
|
|
1040
|
+
// 말은 비워도 보내고(코어는 말 없는 선택을 받는다) Enter 로도 보낸다. Esc 는 초점을 화면으로 돌린다
|
|
1041
|
+
function renderTalk() {
|
|
1042
|
+
const show = Boolean(concept?.body?.page) && view === 'work';
|
|
1043
|
+
talkEl.hidden = !show;
|
|
1044
|
+
if (!show) { talkInput = null; talkEl.replaceChildren(); return; }
|
|
1045
|
+
const p = selection?.payload ?? null;
|
|
1046
|
+
const can = Boolean(caps.conceptSelection) && caps.edit !== false;
|
|
1047
|
+
const said = el('input', { type: 'text', 'data-keep': 'said', 'aria-label': t('Message to the AI about what you picked'), value: talk.said, disabled: !can,
|
|
1048
|
+
placeholder: p ? t('For example: this gap is too wide. You can also send it empty') : t('First click or drag on the screen above to pick what to change, then write your message here and send it'),
|
|
1049
|
+
on: {
|
|
1050
|
+
input: (e) => { talk.said = e.target.value; },
|
|
1051
|
+
keydown: (e) => {
|
|
1052
|
+
if (e.key === 'Enter' && !e.isComposing && selection && can) { e.preventDefault(); shareSelection(); }
|
|
1053
|
+
if (e.key === 'Escape') { e.target.blur(); frame?.focus(); }
|
|
1054
|
+
},
|
|
1055
|
+
} });
|
|
1056
|
+
talkInput = said;
|
|
1057
|
+
const role = el('select', { 'aria-label': t('Role of what you picked'), disabled: !can, on: { change: (e) => { talk.role = e.target.value; } } },
|
|
1058
|
+
el('option', { value: 'change', ...(talk.role === 'change' ? { selected: true } : {}) }, t('Change this')),
|
|
1059
|
+
el('option', { value: 'reference', ...(talk.role === 'reference' ? { selected: true } : {}) }, t('Use as reference')));
|
|
1060
|
+
// 편집 칸이 닫혀 있으면 고른 요소를 직접 고칠 수 있다는 것을 줄 끝에 알린다
|
|
1061
|
+
const direct = p && p.kind === 'element' && caps.edit !== false && !sideOpen ? btn(t('Edit directly'), toggleSide, { class: 'link', title: t('Open the edit panel and change text and styles yourself') }) : null;
|
|
1062
|
+
let head = null;
|
|
1063
|
+
if (!can) {
|
|
1064
|
+
head = el('p', { class: 'state' }, caps.edit === false ? t('A view-only screen does not send to the AI.') : t('This host cannot send what you picked to the AI yet.'));
|
|
1065
|
+
} else if (p && selection.shared) {
|
|
1066
|
+
head = el('p', { class: 'state' }, el('span', { class: 'done' }, t('Sent to the AI (selection {id}).', { id: selection.shared.id })),
|
|
1067
|
+
` ${selText(p)}${selection.shared.said ? t(', message "{said}"', { said: selection.shared.said }) : t(', no message')}.${gapChange(p)}`, direct);
|
|
1068
|
+
} else if (p) {
|
|
1069
|
+
head = el('p', { class: 'state' }, el('b', {}, t('Picked: {what}.', { what: selText(p) })), ' ', el('span', { class: 'wait' }, t('Not sent to the AI yet.')), gapChange(p), direct);
|
|
1070
|
+
}
|
|
1071
|
+
const help = fold('help', false, '?', el('div', { class: 'pop' },
|
|
1072
|
+
el('ol', { class: 'steps' },
|
|
1073
|
+
el('li', {}, t('Click what you want to change on the screen above. Drag across several elements to pick an area.')),
|
|
1074
|
+
el('li', {}, t('Write your message in this bar and click [Send to AI] or press Enter. The message can be empty.'))),
|
|
1075
|
+
el('p', { class: 'hint' }, caps.conceptPick
|
|
1076
|
+
? t('The AI can read what you picked, but picking does not wake the AI. To give it work, write a message and click [Send to AI].')
|
|
1077
|
+
: t('Picking alone does not tell the AI. The AI reads the place and your message only after you send them.'))), { class: 'help' }, { 'aria-label': t('Help for the send bar'), title: t('Help for the send bar') });
|
|
1078
|
+
talkEl.classList.toggle('unsent', Boolean(p) && can && !selection.shared);
|
|
1079
|
+
talkEl.replaceChildren(...[head, el('div', { class: 'line' }, role, said,
|
|
1080
|
+
btn(t('Send to AI'), shareSelection, { class: 'btn primary', disabled: !can || !p, title: !can ? t('This screen does not send') : p ? t('Sends what you picked and your message to the AI. The message can be empty') : t('First pick what to change on the screen above') }), help)].filter(Boolean));
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
/** 다시 그릴 때 쓰던 칸(data-keep)의 초점과 커서를 지킨다(svg 플러그인의 keepFocus 와 같다). */
|
|
1084
|
+
function keepFocus(fn) {
|
|
1085
|
+
const a = document.activeElement;
|
|
1086
|
+
const key = a && typeof a.getAttribute === 'function' ? a.getAttribute('data-keep') : null;
|
|
1087
|
+
const range = key && typeof a.selectionStart === 'number' ? [a.selectionStart, a.selectionEnd] : null;
|
|
1088
|
+
fn();
|
|
1089
|
+
if (!key) return;
|
|
1090
|
+
const b = document.querySelector(`[data-keep="${key}"]`);
|
|
1091
|
+
if (!b || b === a) return;
|
|
1092
|
+
b.focus();
|
|
1093
|
+
if (range && b.setSelectionRange) try { b.setSelectionRange(range[0], range[1]); } catch {}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
async function shareSelection() {
|
|
1097
|
+
const sel = selection;
|
|
1098
|
+
const p = sel?.payload;
|
|
1099
|
+
if (!p) return;
|
|
1100
|
+
const records = selectionRecords(p);
|
|
1101
|
+
// 보낼 때의 역할과 말을 잡아 둔다. 기다리는 사이 새로 쓴 말은 지우지 않는다
|
|
1102
|
+
const role = talk.role;
|
|
1103
|
+
const said = talk.said;
|
|
1104
|
+
const seq = (sel.shareSeq += 1);
|
|
1105
|
+
try {
|
|
1106
|
+
const res = await call('shareSelection', { base: p.rev, role, said: said.trim(), payload: p, records });
|
|
1107
|
+
if (!res?.ok) { toast(res?.summary ?? res?.error ?? t('Could not send the selection'), true); return; }
|
|
1108
|
+
// 응답은 보낸 선택에 붙인다. 그 사이 다른 것을 골랐으면 지금 선택에는 붙이지 않는다
|
|
1109
|
+
if (sel.shareSeq === seq) sel.shared = { id: res.selection, role, said: said.trim() };
|
|
1110
|
+
if (selection !== sel) { toast(t('Sent the earlier pick as {id}. What you picked now is not sent yet', { id: res.selection })); return; }
|
|
1111
|
+
if (talk.said === said) talk = { role: talk.role, said: '' };
|
|
1112
|
+
toast(t('Sent selection {id}', { id: res.selection }));
|
|
1113
|
+
render();
|
|
1114
|
+
// 보내기 전에 이미 다시 잰 값이 있으면 이 선택 id 로 보낸다
|
|
1115
|
+
if (sel.shared?.id === res.selection && sel.redrawn && caps.conceptSelection) await call('reportMeasurement', { selection: res.selection, payload: sel.redrawn });
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
toast(err.message, true);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
let form = { text: null, property: 'margin-bottom', value: '', media: 'all', state: 'none', useRef: true, for: null };
|
|
1122
|
+
function editSection() {
|
|
1123
|
+
const p = selection?.payload;
|
|
1124
|
+
if (!p || p.kind !== 'element' || caps.edit === false) return null;
|
|
1125
|
+
const e = elById(p.element);
|
|
1126
|
+
if (!e) return null;
|
|
1127
|
+
if (form.for !== e.id) form = { ...form, text: e.text ?? e.original, value: '', for: e.id };
|
|
1128
|
+
const parts = [el('h2', {}, t('Edit: {label} ({id})', { label: e.label, id: e.id }))];
|
|
1129
|
+
if (e.original !== null) {
|
|
1130
|
+
const input = el('input', { type: 'text', 'aria-label': t('New text'), value: form.text ?? '', on: { input: (ev) => { form.text = ev.target.value; } } });
|
|
1131
|
+
parts.push(el('div', { class: 'form' }, el('label', {}, el('span', {}, e.text !== null ? t('Text (original: {original})', { original: e.original }) : t('Text')), input),
|
|
1132
|
+
btn(t('Change text'), () => {
|
|
1133
|
+
const next = (form.text ?? '').trim();
|
|
1134
|
+
if (next === '' || next === (e.text ?? e.original)) { toast(t('The text has not changed'), true); return; }
|
|
1135
|
+
send([{ op: 'text.set', input: { element: e.id, text: next } }]);
|
|
1136
|
+
})));
|
|
1137
|
+
}
|
|
1138
|
+
const prop = el('select', { 'aria-label': t('Property'), on: { change: (ev) => { form.property = ev.target.value; } } },
|
|
1139
|
+
PROPERTIES.map((x) => el('option', { value: x, ...(x === form.property ? { selected: true } : {}) }, x)));
|
|
1140
|
+
const value = el('input', { type: 'text', 'aria-label': t('Value'), placeholder: t('For example: 16px. Leave empty to remove this change'), value: form.value, on: { input: (ev) => { form.value = ev.target.value; } } });
|
|
1141
|
+
const mediaLabel = MEDIA_LABEL();
|
|
1142
|
+
const stateLabel = STATE_LABEL();
|
|
1143
|
+
const media = el('select', { 'aria-label': t('Width'), on: { change: (ev) => { form.media = ev.target.value; } } },
|
|
1144
|
+
Object.entries(mediaLabel).map(([k, v]) => el('option', { value: k, ...(k === form.media ? { selected: true } : {}) }, v)));
|
|
1145
|
+
const state = el('select', { 'aria-label': t('State'), on: { change: (ev) => { form.state = ev.target.value; } } },
|
|
1146
|
+
Object.entries(stateLabel).map(([k, v]) => el('option', { value: k, ...(k === form.state ? { selected: true } : {}) }, v)));
|
|
1147
|
+
const ref = reference ? el('label', {}, el('input', { type: 'checkbox', ...(form.useRef ? { checked: true } : {}), on: { change: (ev) => { form.useRef = ev.target.checked; } } }), ` ${t('Reference: {name} ({sample}@{version})', { name: reference.label, sample: reference.sample, version: reference.version })}`) : null;
|
|
1148
|
+
const styles = [];
|
|
1149
|
+
for (const [cond, decl] of Object.entries(e.styles ?? {})) {
|
|
1150
|
+
const [m, s] = cond.split('/');
|
|
1151
|
+
for (const [k, v] of Object.entries(decl)) styles.push(el('li', {}, `${mediaLabel[m] ?? m}${s !== 'none' ? `, ${stateLabel[s] ?? s}` : ''}: ${k} ${v}`));
|
|
1152
|
+
}
|
|
1153
|
+
parts.push(el('div', { class: 'form' }, el('div', { class: 'row2' }, prop, value), el('div', { class: 'row2' }, media, state), ref,
|
|
1154
|
+
btn(t('Change style'), () => {
|
|
1155
|
+
const input = { element: e.id, property: form.property, value: form.value.trim(), media: form.media, state: form.state };
|
|
1156
|
+
if (reference && form.useRef && input.value !== '') input.source = { sample: reference.sample, key: reference.key };
|
|
1157
|
+
send([{ op: 'style.set', input }]);
|
|
1158
|
+
})));
|
|
1159
|
+
if (styles.length) parts.push(el('p', { class: 'note' }, t('Styles changed on this element')), el('ul', {}, styles));
|
|
1160
|
+
return el('section', {}, parts);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function outlineSection() {
|
|
1164
|
+
const list = els();
|
|
1165
|
+
if (!list.length) return null;
|
|
1166
|
+
const depth = (e) => { let d = 0; for (let x = e.parent; x && d < 20; x = elById(x)?.parent) d += 1; return d; };
|
|
1167
|
+
const current = selection?.payload?.kind === 'element' ? selection.payload.element : null;
|
|
1168
|
+
const isChanged = (e) => e.text !== null || Object.keys(e.styles ?? {}).length > 0;
|
|
1169
|
+
const changed = list.filter(isChanged).length;
|
|
1170
|
+
// 접어 두되, 몇 개가 바뀌었는지는 접은 이름에 적는다
|
|
1171
|
+
return fold('outline', false, changed ? t('Elements ({n}, changed {changed})', { n: list.length, changed }) : t('Elements ({n})', { n: list.length }),
|
|
1172
|
+
el('ul', { class: 'outline' }, list.map((e) => el('li', {},
|
|
1173
|
+
el('button', { type: 'button', style: `padding-left:${4 + depth(e) * 12}px`, 'aria-current': e.id === current ? 'true' : 'false', on: { click: () => selectElement(e.id) } },
|
|
1174
|
+
e.label, el('span', { class: 'id' }, e.id), isChanged(e) ? el('span', { class: 'changed' }, t('changed')) : null)))), { class: 'fold' });
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
let startReason = '';
|
|
1178
|
+
function pickerSide() {
|
|
1179
|
+
const c = catalogOf(view);
|
|
1180
|
+
if (!c) return [];
|
|
1181
|
+
const can = caps.edit !== false;
|
|
1182
|
+
const reason = el('textarea', { 'aria-label': t('Reason for the choice'), placeholder: t('For example: the photo catches the eye first'), value: startReason, on: { input: (e) => { startReason = e.target.value; } } });
|
|
1183
|
+
return [
|
|
1184
|
+
el('section', {}, el('h2', {}, t('Sample: {name}', { name: c.title })), el('p', {}, c.about), el('p', { class: 'note' }, t('Version {version}. Open another sample from the menu at the left end of the top bar.', { version: c.version }))),
|
|
1185
|
+
can ? el('section', {}, el('h2', {}, t('Start with this sample')), el('div', { class: 'form' }, reason,
|
|
1186
|
+
btn(t('Start a working copy from this sample'), () => {
|
|
1187
|
+
const r = startReason.trim();
|
|
1188
|
+
if (!r) { toast(t('Write the reason for your choice'), true); return; }
|
|
1189
|
+
send([{ op: 'page.start', input: { sample: c.id, reason: r } }]).then((res) => { if (res) { startReason = ''; view = 'work'; drawFrame(); render(); } });
|
|
1190
|
+
}, { class: 'btn primary' }))) : null,
|
|
1191
|
+
];
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function referenceSide() {
|
|
1195
|
+
const c = catalogOf(view);
|
|
1196
|
+
return [el('section', {}, el('h2', {}, t('Reference: {name}', { name: c.title })), el('p', {}, c.about),
|
|
1197
|
+
el('p', { class: 'note' }, t('Click an element here to attach it as the reference for your next style change.')),
|
|
1198
|
+
reference && reference.sample === c.id ? el('p', {}, t('Picked example: {label} ({key})', { label: reference.label, key: reference.key })) : null,
|
|
1199
|
+
btn(t('Back to the working copy'), () => switchView('work')))];
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
let sideWas = null;
|
|
1203
|
+
function render() {
|
|
1204
|
+
if (!concept) return;
|
|
1205
|
+
// 편집 칸이 열려 있으면 다시 잰 값을 본 것으로 친다(위쪽 줄 버튼의 점을 지운다)
|
|
1206
|
+
const shown = sideShown();
|
|
1207
|
+
if (shown && view === 'work' && selection?.redrawn) selection.seen = selection.redrawn;
|
|
1208
|
+
renderBar();
|
|
1209
|
+
keepFocus(() => {
|
|
1210
|
+
renderTalk();
|
|
1211
|
+
const b = concept.body;
|
|
1212
|
+
if (!b.page) { sideEl.replaceChildren(...pickerSide()); return; }
|
|
1213
|
+
if (view !== 'work') { sideEl.replaceChildren(...referenceSide()); return; }
|
|
1214
|
+
const info = fold('info', false, t('Working copy: {title}', { title: b.page.sample.title }),
|
|
1215
|
+
el('dl', { class: 'kv' }, el('dt', {}, t('Sample')), el('dd', {}, t('{title} ({id}) version {version}', { title: b.page.sample.title, id: b.page.sample.id, version: b.page.sample.version })),
|
|
1216
|
+
el('dt', {}, t('Reason for the choice')), el('dd', {}, b.page.reason)), { class: 'fold' });
|
|
1217
|
+
sideEl.replaceChildren(...[info, selectionSection(), editSection(), outlineSection()].filter(Boolean));
|
|
1218
|
+
});
|
|
1219
|
+
sideEl.hidden = !shown;
|
|
1220
|
+
stageEl.classList.toggle('closed', !shown);
|
|
1221
|
+
// 칸을 열거나 닫으면 화면이 쓸 수 있는 폭이 바뀌므로 크기를 다시 맞춘다
|
|
1222
|
+
if (sideWas !== null && sideWas !== shown) sizeFrame();
|
|
1223
|
+
sideWas = shown;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
window.addEventListener('resize', () => { if (concept) sizeFrame(); });
|
|
1227
|
+
|
|
1228
|
+
parent.postMessage({ aic: 1, event: 'ready', rendered: true }, '*');
|
|
1229
|
+
// 언어를 정한 뒤 처음 그린다. 호스트가 capabilities 에 답하지 않거나 늦으면 영어로 먼저 그리고, 답이 오면 다시 그린다
|
|
1230
|
+
let started = false;
|
|
1231
|
+
const start = () => { if (!started) { started = true; refresh(); } };
|
|
1232
|
+
call('capabilities', {}).then((cap) => {
|
|
1233
|
+
caps = { ...caps, ...(cap ?? {}) };
|
|
1234
|
+
setLanguage(cap?.language);
|
|
1235
|
+
if (frame) frame.setAttribute('title', t('Design screen'));
|
|
1236
|
+
if (concept) { sizeFrame(); render(); }
|
|
1237
|
+
}, () => {}).finally(start);
|
|
1238
|
+
setTimeout(start, 1500);
|
|
1239
|
+
</script>
|
|
1240
|
+
</body>
|
|
1241
|
+
</html>
|