@eliceio/cdk-cli 1.7.1 → 1.8.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/README.md +18 -15
- package/es/commands/create/index.js +6 -3
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/doctor/index.js +34 -1
- package/es/core/lesson-check.d.ts +7 -0
- package/es/core/lesson-check.js +87 -0
- package/es/core/templates.d.ts +2 -0
- package/es/core/templates.js +4 -1
- package/es/dev/host-page.js +5 -2
- package/es/dev/learner-files.d.ts +1 -1
- package/es/dev/learner-files.js +7 -4
- package/es/dev/learner-shares.d.ts +90 -0
- package/es/dev/learner-shares.js +282 -0
- package/es/dev/mock-api.d.ts +28 -0
- package/es/dev/mock-api.js +32 -1
- package/es/dev/server.d.ts +3 -0
- package/es/dev/server.js +22 -1
- package/package.json +2 -2
- package/skills/_shared/always.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +10 -9
- package/skills/_shared/references/03-create-the-project.md +12 -11
- package/skills/_shared/references/05-screen-code.md +1 -0
- package/skills/_shared/references/08-fix-check-errors.md +1 -0
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +2 -2
- package/skills/_shared/references/17-using-the-entry-template.md +44 -5
- package/skills/_shared/references/18-using-the-lesson-template.md +207 -0
- package/skills/_shared/references/19-lesson-layouts.md +2132 -0
- package/skills/elice-content-create/SKILL.md +4 -3
- package/skills/elice-content-publish/SKILL.md +3 -3
- package/templates/_shared/lib/cdk-mock.d.ts +16 -0
- package/templates/_shared/lib/cdk-mock.js +49 -0
- package/templates/blank/template.json +1 -1
- package/templates/board/README.md +15 -7
- package/templates/board/core/board.d.ts +13 -0
- package/templates/board/core/board.js +11 -1
- package/templates/board/core/files.d.ts +40 -0
- package/templates/board/core/files.js +176 -0
- package/templates/board/core/model.d.ts +5 -0
- package/templates/board/core/model.js +24 -7
- package/templates/board/core/settings.d.ts +2 -0
- package/templates/board/core/settings.js +12 -1
- package/templates/board/package.json +1 -1
- package/templates/board/screens/board.js +58 -0
- package/templates/board/screens/edit.js +36 -1
- package/templates/board/template.json +1 -1
- package/templates/board/ui/board.css +176 -0
- package/templates/board/ui/card.js +74 -1
- package/templates/board/ui/composer.js +169 -20
- package/templates/board/ui/icons.js +2 -0
- package/templates/board/ui/texts.js +30 -2
- package/templates/lesson/README.md +71 -0
- package/templates/lesson/commentary.txt +7 -0
- package/templates/lesson/core/dom.d.ts +4 -0
- package/templates/lesson/core/dom.js +22 -0
- package/templates/lesson/core/engine.d.ts +23 -0
- package/templates/lesson/core/engine.js +169 -0
- package/templates/lesson/core/interact.d.ts +2 -0
- package/templates/lesson/core/interact.js +429 -0
- package/templates/lesson/core/layout-files.d.ts +4 -0
- package/templates/lesson/core/layout-files.js +9 -0
- package/templates/lesson/core/lesson.d.ts +95 -0
- package/templates/lesson/core/lesson.js +609 -0
- package/templates/lesson/core/sample.d.ts +4 -0
- package/templates/lesson/core/sample.js +128 -0
- package/templates/lesson/edit.html +21 -0
- package/templates/lesson/gitignore +4 -0
- package/templates/lesson/index.html +22 -0
- package/templates/lesson/layouts/_actions.html +1 -0
- package/templates/lesson/layouts/_cmp.html +1 -0
- package/templates/lesson/layouts/_deco-corner.html +1 -0
- package/templates/lesson/layouts/_deco-cover.html +1 -0
- package/templates/lesson/layouts/_deco-section.html +1 -0
- package/templates/lesson/layouts/_foot.html +1 -0
- package/templates/lesson/layouts/_head.html +1 -0
- package/templates/lesson/layouts/_media.html +1 -0
- package/templates/lesson/layouts/agenda.html +13 -0
- package/templates/lesson/layouts/bar-chart.html +14 -0
- package/templates/lesson/layouts/cards.html +12 -0
- package/templates/lesson/layouts/checklist.html +12 -0
- package/templates/lesson/layouts/choice-list.html +13 -0
- package/templates/lesson/layouts/closing.html +13 -0
- package/templates/lesson/layouts/compare.html +12 -0
- package/templates/lesson/layouts/cover-dark.html +13 -0
- package/templates/lesson/layouts/cover.html +15 -0
- package/templates/lesson/layouts/figures.html +12 -0
- package/templates/lesson/layouts/flow.html +13 -0
- package/templates/lesson/layouts/how-to.html +15 -0
- package/templates/lesson/layouts/image-bg.html +12 -0
- package/templates/lesson/layouts/image-pair.html +15 -0
- package/templates/lesson/layouts/image-split.html +12 -0
- package/templates/lesson/layouts/layers.html +12 -0
- package/templates/lesson/layouts/objectives.html +12 -0
- package/templates/lesson/layouts/ox-card.html +24 -0
- package/templates/lesson/layouts/ox-list.html +21 -0
- package/templates/lesson/layouts/process.html +14 -0
- package/templates/lesson/layouts/profile.html +13 -0
- package/templates/lesson/layouts/prompt-builder.html +18 -0
- package/templates/lesson/layouts/quiz.html +14 -0
- package/templates/lesson/layouts/quote.html +12 -0
- package/templates/lesson/layouts/scenario-rows.html +12 -0
- package/templates/lesson/layouts/section.html +14 -0
- package/templates/lesson/layouts/simulation.html +18 -0
- package/templates/lesson/layouts/stat.html +14 -0
- package/templates/lesson/layouts/statement.html +13 -0
- package/templates/lesson/layouts/stats.html +12 -0
- package/templates/lesson/layouts/stepper.html +13 -0
- package/templates/lesson/layouts/table.html +12 -0
- package/templates/lesson/layouts/tabs.html +13 -0
- package/templates/lesson/layouts/text-visual.html +16 -0
- package/templates/lesson/layouts/timeline.html +12 -0
- package/templates/lesson/layouts/toggle.html +16 -0
- package/templates/lesson/layouts/variables.html +14 -0
- package/templates/lesson/layouts/venn.html +15 -0
- package/templates/lesson/layouts/versus.html +12 -0
- package/templates/lesson/metadata.json +9 -0
- package/templates/lesson/package.json +15 -0
- package/templates/lesson/public/img/sample-chat.svg +21 -0
- package/templates/lesson/screens/edit.js +79 -0
- package/templates/lesson/screens/learn.js +56 -0
- package/templates/lesson/styles.css +27 -0
- package/templates/lesson/template.json +7 -0
- package/templates/lesson/ui/design.css +1103 -0
- package/templates/lesson/ui/fonts/PretendardVariable.woff2 +0 -0
- package/templates/lesson/ui/learn.css +64 -0
- package/templates/lesson/ui/mobile.css +492 -0
- package/templates/lesson/ui/reset.css +6 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
// 학습 자료 내용(meta + slides[{ layout, data }])을 검사하고 슬라이드 HTML로 조립한다 (디자이너 deck-kit build.py를 옮긴 것).
|
|
2
|
+
// 브라우저(학생 화면 · 편집 화면 저장 전 검사)와 Node(ecdk doctor project.lesson) 모두에서 돈다. DOM · 파일을 쓰지 않는다:
|
|
3
|
+
// 레이아웃 틀(layouts/*.html)은 부르는 쪽이 읽어 parseLayouts로 넘긴다 (화면: core/layout-files.js, doctor: 파일을 직접 읽음).
|
|
4
|
+
// 학생 화면에 보이는 HTML은 모두 core/engine.js가 값을 이스케이프해 만든다.
|
|
5
|
+
import { escapeHtml, parse, render, truthy } from './engine.js';
|
|
6
|
+
|
|
7
|
+
/** 레이아웃 순서 (원본 build.py ORDER): 장표 → 실습 → 퀴즈. 여기 없는 레이아웃은 뒤에 이름순 */
|
|
8
|
+
export const ORDER = [
|
|
9
|
+
'cover',
|
|
10
|
+
'cover-dark',
|
|
11
|
+
'agenda',
|
|
12
|
+
'objectives',
|
|
13
|
+
'section',
|
|
14
|
+
'statement',
|
|
15
|
+
'text-visual',
|
|
16
|
+
'cards',
|
|
17
|
+
'compare',
|
|
18
|
+
'versus',
|
|
19
|
+
'process',
|
|
20
|
+
'scenario-rows',
|
|
21
|
+
'flow',
|
|
22
|
+
'timeline',
|
|
23
|
+
'stat',
|
|
24
|
+
'stats',
|
|
25
|
+
'bar-chart',
|
|
26
|
+
'table',
|
|
27
|
+
'layers',
|
|
28
|
+
'venn',
|
|
29
|
+
'quote',
|
|
30
|
+
'profile',
|
|
31
|
+
'image-split',
|
|
32
|
+
'image-bg',
|
|
33
|
+
'figures',
|
|
34
|
+
'image-pair',
|
|
35
|
+
'closing',
|
|
36
|
+
'variables',
|
|
37
|
+
'how-to',
|
|
38
|
+
'prompt-builder',
|
|
39
|
+
'tabs',
|
|
40
|
+
'toggle',
|
|
41
|
+
'stepper',
|
|
42
|
+
'checklist',
|
|
43
|
+
'simulation',
|
|
44
|
+
'quiz',
|
|
45
|
+
'choice-list',
|
|
46
|
+
'ox-list',
|
|
47
|
+
'ox-card',
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const SCHEMA_RE = /^\s*<!--SCHEMA\s*([\s\S]*?)-->\s*/;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 레이아웃 틀 파일 → { ids, layouts: { id: { schema, template } }, partials }. files: { 경로: 파일 내용 } (경로는 이름만 봄).
|
|
54
|
+
* 틀 맨 위 <!--SCHEMA {...}--> 주석이 슬롯 규칙(필수 · 글자 수 · 항목 수 · 고르기 · 문체)이고 그 아래가 틀이다.
|
|
55
|
+
* `_`로 시작하는 파일은 부분 틀({{>head}} 등). 형식이 틀리면 던진다 (템플릿을 고친 사람에게 바로 보이게)
|
|
56
|
+
*/
|
|
57
|
+
export function parseLayouts(files) {
|
|
58
|
+
const layouts = {};
|
|
59
|
+
const partials = {};
|
|
60
|
+
for (const [path, src] of Object.entries(files)) {
|
|
61
|
+
const file = path.slice(path.lastIndexOf('/') + 1);
|
|
62
|
+
if (!file.endsWith('.html')) continue;
|
|
63
|
+
const id = file.slice(0, -5);
|
|
64
|
+
if (id.startsWith('_')) {
|
|
65
|
+
partials[id.slice(1)] = src;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const m = SCHEMA_RE.exec(src);
|
|
69
|
+
if (!m) throw new Error(`layouts/${file}: SCHEMA 주석이 없습니다`);
|
|
70
|
+
const schema = JSON.parse(m[1]);
|
|
71
|
+
if (schema.id !== id) throw new Error(`layouts/${file}: SCHEMA id(${schema.id})가 파일 이름과 다릅니다`);
|
|
72
|
+
layouts[id] = { schema, template: src.slice(m[0].length) };
|
|
73
|
+
}
|
|
74
|
+
const found = Object.keys(layouts);
|
|
75
|
+
const ids = [...ORDER.filter(id => found.includes(id)), ...found.filter(id => !ORDER.includes(id)).sort()];
|
|
76
|
+
return { ids, layouts, partials };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 모든 레이아웃에서 쓰는 슬롯 */
|
|
80
|
+
export const UNIVERSAL = {
|
|
81
|
+
tag: {
|
|
82
|
+
max: 24,
|
|
83
|
+
style: 'label',
|
|
84
|
+
hint: '제목 줄 오른쪽 보조 정보(선택. 자료명, 목표, 소요 시간 등)',
|
|
85
|
+
},
|
|
86
|
+
notes: {
|
|
87
|
+
style: 'notes',
|
|
88
|
+
hint: "강의 노트. 합니다체(질문은 '~일까요?', 권유는 '~해 보세요'), 문장당 공백 제외 60자 이내",
|
|
89
|
+
},
|
|
90
|
+
image_alt: { max: 60, style: 'label', hint: '이미지 대체 텍스트' },
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** meta에서 고르는 값 (첫 값이 기본, style이 slide면 일부 기본이 바뀜) */
|
|
94
|
+
const META_ENUMS = {
|
|
95
|
+
style: ['document', 'slide'],
|
|
96
|
+
title_mode: ['fixed', 'free'],
|
|
97
|
+
header: ['hide', 'show'],
|
|
98
|
+
background: ['decor', 'plain'],
|
|
99
|
+
header_right: ['none', 'title'],
|
|
100
|
+
title_label: ['chapter', 'title', 'none'],
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** 머리글 · 쪽 번호 규칙이 다른 장표 */
|
|
104
|
+
const COVERS = ['cover', 'cover-dark'];
|
|
105
|
+
const NO_EYEBROW = ['cover', 'cover-dark', 'section', 'closing', 'image-bg', 'quote'];
|
|
106
|
+
|
|
107
|
+
const compiled = new WeakMap();
|
|
108
|
+
/** 레이아웃 묶음(parseLayouts 결과)의 틀은 처음 쓸 때 한 번만 읽는다 */
|
|
109
|
+
function templates(set) {
|
|
110
|
+
let tpl = compiled.get(set);
|
|
111
|
+
if (!tpl) {
|
|
112
|
+
tpl = {
|
|
113
|
+
partials: Object.fromEntries(Object.entries(set.partials).map(([k, v]) => [k, parse(v)])),
|
|
114
|
+
layouts: Object.fromEntries(Object.entries(set.layouts).map(([k, v]) => [k, parse(v.template)])),
|
|
115
|
+
};
|
|
116
|
+
compiled.set(set, tpl);
|
|
117
|
+
}
|
|
118
|
+
return tpl;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** options.layouts (parseLayouts 결과). 없으면 부르는 쪽 실수라 던진다 */
|
|
122
|
+
function layoutSet(options) {
|
|
123
|
+
const set = options?.layouts;
|
|
124
|
+
if (!set || !isObj(set.layouts) || !Array.isArray(set.ids))
|
|
125
|
+
throw new Error('options.layouts가 없습니다 (parseLayouts 결과, 화면은 core/layout-files.js의 LAYOUTS)');
|
|
126
|
+
return set;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const clone = v => JSON.parse(JSON.stringify(v ?? {}));
|
|
130
|
+
const isObj = v => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
131
|
+
const str = v => (v === null || v === undefined ? '' : String(v));
|
|
132
|
+
|
|
133
|
+
/** 스키마의 default를 채우고, 모든 목록에 <key>_n(개수)을 더한다 */
|
|
134
|
+
function applyDefaults(value, slots) {
|
|
135
|
+
if (!isObj(value)) return;
|
|
136
|
+
for (const [key, spec] of Object.entries(slots)) {
|
|
137
|
+
if ('default' in spec && !truthy(value[key])) value[key] = spec.default;
|
|
138
|
+
const v = value[key];
|
|
139
|
+
if (Array.isArray(v)) {
|
|
140
|
+
value[`${key}_n`] = v.length;
|
|
141
|
+
if (spec.fields) for (const it of v) applyDefaults(it, spec.fields);
|
|
142
|
+
} else if (isObj(v) && spec.fields) applyDefaults(v, spec.fields);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const EMOJI = /[\u{1F300}-\u{1FAFF}☀-⛿⭐⭕✅❌✨]/u;
|
|
147
|
+
const POLITE_BAD = /(해요|예요|에요|어요|아요|네요|죠|거든요|세요)[.?!]*$/;
|
|
148
|
+
/** 강의 노트에서 해요체로 끝나도 되는 문장: 질문 '~일까요?' · 권유 '~해 보세요' (문체 기준 표) */
|
|
149
|
+
const NOTES_ALLOWED_END = /(?:일까요|할까요|인가요)\??$|보세요[.]?$/;
|
|
150
|
+
const MARKUP = /\*\*|`/g;
|
|
151
|
+
|
|
152
|
+
/** 화면에 보이는 글자 수 (서식 기호 · 줄바꿈 제외) */
|
|
153
|
+
export function visibleLength(s) {
|
|
154
|
+
return [...str(s).replace(MARKUP, '').replace(/\n/g, '')].length;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const short = (s, n = 30) => [...s].slice(0, n).join('');
|
|
158
|
+
const tail = (s, n = 24) => [...s].slice(-n).join('');
|
|
159
|
+
|
|
160
|
+
/** 문체 검사 (경고만). style: 슬롯의 문체 코드 */
|
|
161
|
+
function checkText(text, style, where, out) {
|
|
162
|
+
const plain = str(text).replace(MARKUP, '');
|
|
163
|
+
if (style === 'quote') return;
|
|
164
|
+
const warn = m => out.push({ level: 'warn', message: `${where}: ${m}` });
|
|
165
|
+
if (/[·—–]/.test(plain))
|
|
166
|
+
warn(
|
|
167
|
+
`가운뎃점(·)이나 긴 대시는 쓰지 않는다. 쉼표, 슬래시, 문장 분리로 바꾼다 -> "${short(plain)}"`
|
|
168
|
+
);
|
|
169
|
+
if (EMOJI.test(plain)) warn(`이모지는 화면에 쓰지 않는다 -> "${short(plain)}"`);
|
|
170
|
+
if (plain.includes('!')) warn(`감탄 표현은 쓰지 않는다 -> "${short(plain)}"`);
|
|
171
|
+
const flat = plain.replace(/\n/g, ' ').trim();
|
|
172
|
+
const lines = plain.split('\n').map(l => l.trim());
|
|
173
|
+
if (lines.length > 1 && lines.some(l => l.length > 0 && [...l].length <= 2))
|
|
174
|
+
warn(`줄바꿈(\\n)으로 한두 글자만 남는 줄이 생김. 의미 단위로 나눈다 -> "${short(plain)}"`);
|
|
175
|
+
if (style === 'title' || style === 'label') {
|
|
176
|
+
if (flat.endsWith('.')) warn(`제목과 라벨은 마침표 없이 끝낸다 -> "${short(flat)}"`);
|
|
177
|
+
if (/(?:하|되|있|없|이)(?:음|함|임)$/.test(flat))
|
|
178
|
+
warn(`'~함, ~음, ~임' 종결은 쓰지 않는다. 체언이나 '~하기'로 끝낸다 -> "${short(flat)}"`);
|
|
179
|
+
}
|
|
180
|
+
if (style === 'title' && /(합니다|입니다|습니다|해요|예요|에요)[.]?$/.test(flat))
|
|
181
|
+
warn(`페이지 제목은 개조식(체언 종결)으로 쓴다 -> "${short(flat)}"`);
|
|
182
|
+
if (style === 'question' && !/(가|까)\?$/.test(flat))
|
|
183
|
+
warn(`문항은 '~인가?', '~는가?'로 끝낸다 -> "${tail(flat)}"`);
|
|
184
|
+
if (style === 'explain' && flat.startsWith('정답은'))
|
|
185
|
+
warn("해설은 '정답은'으로 시작하지 않고 풀이 근거를 설명한다");
|
|
186
|
+
if (style === 'goal' && !/할 수 있다$/.test(flat))
|
|
187
|
+
warn(`학습 목표는 '~할 수 있다'로 끝낸다 -> "${short(flat)}"`);
|
|
188
|
+
if (
|
|
189
|
+
(style === 'sentence' || style === 'practice' || style === 'explain') &&
|
|
190
|
+
POLITE_BAD.test(flat)
|
|
191
|
+
)
|
|
192
|
+
warn(`설명 문장은 합니다체로 쓴다 -> "${tail(flat)}"`);
|
|
193
|
+
if (style === 'notes') {
|
|
194
|
+
for (const sent of flat.split(/(?<=[.?!])\s+/)) {
|
|
195
|
+
if (sent.replace(/\s/g, '').length > 60)
|
|
196
|
+
warn(`강의 노트는 문장당 공백 제외 60자 이내 -> "${short(sent)}"`);
|
|
197
|
+
// 원본 build.py는 노트 전체의 끝만 보고 '~해 보세요'도 경고했다. 문체 기준 표대로 문장마다 보고 권유는 허용
|
|
198
|
+
if (POLITE_BAD.test(sent) && !NOTES_ALLOWED_END.test(sent))
|
|
199
|
+
warn(
|
|
200
|
+
`강의 노트에 해요체 문장이 있음. 합니다체로 쓰고 해요체는 질문 '~일까요?', 권유 '~해 보세요'만 쓴다 -> "${tail(sent)}"`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 슬롯 하나 검사. ctx: { vars: 정의한 변수 key 집합, local: 이 페이지에서만 쓰는 key(프롬프트 빌더 항목), out }
|
|
208
|
+
*/
|
|
209
|
+
function validateSlot(value, spec, where, ctx) {
|
|
210
|
+
const { t } = spec;
|
|
211
|
+
if (t === 'image' || t === 'bool') return;
|
|
212
|
+
if (t === 'enum') {
|
|
213
|
+
if (truthy(value) && !spec.opts.map(String).includes(String(value)))
|
|
214
|
+
ctx.out.push({
|
|
215
|
+
level: 'error',
|
|
216
|
+
message: `${where}: 허용값 ${spec.opts.map(o => JSON.stringify(o)).join(', ')} 중 하나여야 함 -> ${JSON.stringify(value)}`,
|
|
217
|
+
});
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (spec.fields && isObj(value)) {
|
|
221
|
+
validateDict(value, spec.fields, where, ctx);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (Array.isArray(value) || spec.n) {
|
|
225
|
+
const list = Array.isArray(value) ? value : [];
|
|
226
|
+
const [lo, hi] = spec.n ?? [0, 999];
|
|
227
|
+
if (list.length < lo || list.length > hi)
|
|
228
|
+
ctx.out.push({
|
|
229
|
+
level: 'error',
|
|
230
|
+
message: `${where}: 항목 수는 ${lo}~${hi}개여야 함 (현재 ${list.length}개)`,
|
|
231
|
+
});
|
|
232
|
+
list.forEach((it, i) => {
|
|
233
|
+
const w = `${where}[${i + 1}]`;
|
|
234
|
+
if (spec.fields) {
|
|
235
|
+
if (!isObj(it)) ctx.out.push({ level: 'error', message: `${w}: 객체여야 함` });
|
|
236
|
+
else validateDict(it, spec.fields, w, ctx);
|
|
237
|
+
} else {
|
|
238
|
+
const item = spec.item ?? {};
|
|
239
|
+
const cells = Array.isArray(it) ? it : [it];
|
|
240
|
+
cells.forEach((c, j) =>
|
|
241
|
+
checkScalar(c, item, Array.isArray(it) ? `${w}[${j + 1}]` : w, ctx)
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
checkScalar(value, spec, where, ctx);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function checkScalar(v, spec, where, ctx) {
|
|
251
|
+
if (!truthy(v)) return;
|
|
252
|
+
if (typeof v === 'object') {
|
|
253
|
+
ctx.out.push({ level: 'error', message: `${where}: 글이어야 함 (객체 · 목록이 아님)` });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
for (const m of str(v).matchAll(/\[\[([a-z0-9_-]+)\]\]/g))
|
|
257
|
+
if (!ctx.vars.has(m[1]) && !ctx.local.has(m[1]))
|
|
258
|
+
ctx.out.push({
|
|
259
|
+
level: 'warn',
|
|
260
|
+
message: `${where}: 정의되지 않은 변수 [[${m[1]}]] (meta.variables에 추가)`,
|
|
261
|
+
});
|
|
262
|
+
if (spec.max && visibleLength(v) > spec.max)
|
|
263
|
+
ctx.out.push({
|
|
264
|
+
level: 'warn',
|
|
265
|
+
message: `${where}: 글자 수 초과 ${visibleLength(v)}/${spec.max} -> "${short(str(v).replace(/\n/g, ' '), 24)}"`,
|
|
266
|
+
});
|
|
267
|
+
if (spec.style) checkText(v, spec.style, where, ctx.out);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 레이아웃이 계산해 넣는 키 (오타 경고에서 뺀다) */
|
|
271
|
+
const DERIVED = new Set(['ratio_c', 'ratio_px', 'focus_css']);
|
|
272
|
+
|
|
273
|
+
function validateDict(data, slots, where, ctx) {
|
|
274
|
+
for (const [key, spec] of Object.entries(slots)) {
|
|
275
|
+
const v = data[key];
|
|
276
|
+
if (spec.req && !truthy(v)) {
|
|
277
|
+
ctx.out.push({ level: 'error', message: `${where}.${key}: 필수 슬롯이 비어 있음` });
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (truthy(v) || spec.n) {
|
|
281
|
+
if ((v === undefined || v === null) && spec.n) {
|
|
282
|
+
if (spec.n[0] === 0) continue;
|
|
283
|
+
ctx.out.push({ level: 'error', message: `${where}.${key}: 필수 목록이 비어 있음` });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
validateSlot(v, spec, `${where}.${key}`, ctx);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const key of Object.keys(data))
|
|
290
|
+
if (!(key in slots) && !key.endsWith('_n') && !key.startsWith('is_') && !DERIVED.has(key))
|
|
291
|
+
ctx.out.push({
|
|
292
|
+
level: 'warn',
|
|
293
|
+
message: `${where}.${key}: 이 레이아웃에 없는 슬롯 (오타 확인)`,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const RATIO_PX = {
|
|
298
|
+
'16:10': '1600x1000',
|
|
299
|
+
'16:9': '1600x900',
|
|
300
|
+
'2:1': '1600x800',
|
|
301
|
+
'4:3': '1600x1200',
|
|
302
|
+
'1:1': '1200x1200',
|
|
303
|
+
'3:4': '1200x1600',
|
|
304
|
+
'9:16': '1080x1920',
|
|
305
|
+
};
|
|
306
|
+
const FOCUS_CSS = {
|
|
307
|
+
center: 'center',
|
|
308
|
+
top: 'center top',
|
|
309
|
+
bottom: 'center bottom',
|
|
310
|
+
left: 'left center',
|
|
311
|
+
right: 'right center',
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/** 이미지 틀 파생값 (틀 플래그, 비율 클래스, 권장 픽셀, 초점) */
|
|
315
|
+
function postDefaults(data, lid) {
|
|
316
|
+
let px = '';
|
|
317
|
+
if (lid === 'image-bg') {
|
|
318
|
+
data.frame = 'bleed';
|
|
319
|
+
data.ratio = '16:9';
|
|
320
|
+
px = '1920x1080 이상';
|
|
321
|
+
}
|
|
322
|
+
const frame = str(data.frame);
|
|
323
|
+
if (frame) data[`is_${frame}`] = true;
|
|
324
|
+
const ratio = str(data.ratio);
|
|
325
|
+
data.ratio = ratio;
|
|
326
|
+
data.ratio_c = ratio.replace(':', '-');
|
|
327
|
+
data.ratio_px = px || RATIO_PX[ratio] || '';
|
|
328
|
+
data.focus_css = FOCUS_CSS[str(data.focus || 'center')] ?? 'center';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const stripMarkup = s => str(s).replace(MARKUP, '').replace(/\n/g, ' ').trim();
|
|
332
|
+
|
|
333
|
+
/** 이미지 경로 검사: 외부 주소는 콘텐츠 CSP가 막는다. 파일이 있는지는 options.imageExists가 있을 때만 (Node) */
|
|
334
|
+
function checkImages(data, where, out, imageExists) {
|
|
335
|
+
const walk = (v, path) => {
|
|
336
|
+
if (Array.isArray(v)) v.forEach((x, i) => walk(x, `${path}[${i + 1}]`));
|
|
337
|
+
else if (isObj(v))
|
|
338
|
+
for (const [k, x] of Object.entries(v)) {
|
|
339
|
+
if (k === 'image' && typeof x === 'string' && x) {
|
|
340
|
+
if (/^(?:https?:)?\/\//i.test(x))
|
|
341
|
+
out.push({
|
|
342
|
+
level: 'error',
|
|
343
|
+
message: `${path}.image: 외부 이미지 주소는 콘텐츠 CSP가 막아 보이지 않음. 이미지 파일을 프로젝트 public/에 넣고 상대 경로로 -> ${x}`,
|
|
344
|
+
});
|
|
345
|
+
else if (!/^data:image\//i.test(x) && imageExists && !imageExists(x))
|
|
346
|
+
out.push({ level: 'error', message: `${path}.image: 이미지 파일 없음: ${x}` });
|
|
347
|
+
} else walk(x, `${path}.${k}`);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
walk(data, where);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 내용 검사 + 조립. 결과: { slides, report, attrs, vars, title }
|
|
355
|
+
* - slides: [{ html, layout, title, notes }] (html은 <section class="slide" …>)
|
|
356
|
+
* - report: [{ level: 'error' | 'warn', message }] (원본 build.py의 ERROR · WARN)
|
|
357
|
+
* - attrs: 자료 틀 속성 { title, header, hright, bg, key, single }
|
|
358
|
+
* options.layouts: 레이아웃 묶음 (parseLayouts 결과, 필수)
|
|
359
|
+
* options.imageExists(path): 이미지 파일이 있는지 (doctor). 없으면 파일 검사를 하지 않는다
|
|
360
|
+
*/
|
|
361
|
+
export function buildLesson(content, options = {}) {
|
|
362
|
+
const set = layoutSet(options);
|
|
363
|
+
const report = [];
|
|
364
|
+
const error = message => report.push({ level: 'error', message });
|
|
365
|
+
const warn = message => report.push({ level: 'warn', message });
|
|
366
|
+
if (!isObj(content)) {
|
|
367
|
+
error('내용은 { meta, slides } 객체여야 함');
|
|
368
|
+
return { slides: [], report, attrs: lessonAttrs({}, 0, report), vars: {}, title: '' };
|
|
369
|
+
}
|
|
370
|
+
const meta = isObj(content.meta) ? content.meta : {};
|
|
371
|
+
const slides = Array.isArray(content.slides) ? content.slides : [];
|
|
372
|
+
if (content.meta !== undefined && !isObj(content.meta)) error('meta는 객체여야 함');
|
|
373
|
+
if (!Array.isArray(content.slides)) error('slides는 슬라이드 목록이어야 함');
|
|
374
|
+
else if (slides.length === 0) error('slides가 비어 있음 (슬라이드 1장 이상)');
|
|
375
|
+
|
|
376
|
+
/** 변수 key → 입력 전에 보일 값 */
|
|
377
|
+
const vars = {};
|
|
378
|
+
const variables = Array.isArray(meta.variables) ? meta.variables.filter(isObj) : [];
|
|
379
|
+
for (const v of variables) {
|
|
380
|
+
if (!/^[a-z0-9_-]+$/.test(str(v.key))) {
|
|
381
|
+
error(
|
|
382
|
+
`meta.variables: key는 영문 소문자, 숫자, 하이픈, 밑줄만 가능 -> ${JSON.stringify(v.key)}`
|
|
383
|
+
);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
vars[v.key] = str(v.default) || str(v.placeholder) || str(v.label) || v.key;
|
|
387
|
+
}
|
|
388
|
+
const varList = variables
|
|
389
|
+
.filter(v => Object.hasOwn(vars, str(v.key)))
|
|
390
|
+
.map(v => ({ ...v, placeholder: v.placeholder ?? v.label ?? v.key }));
|
|
391
|
+
|
|
392
|
+
const glob = {
|
|
393
|
+
variables: varList,
|
|
394
|
+
variables_n: varList.length,
|
|
395
|
+
brand: str(meta.brand),
|
|
396
|
+
lesson_title: str(meta.title),
|
|
397
|
+
total: slides.length,
|
|
398
|
+
};
|
|
399
|
+
const style = str(meta.style || 'document');
|
|
400
|
+
const doc = style === 'document';
|
|
401
|
+
const titleMode = str(meta.title_mode || (doc ? 'fixed' : 'free'));
|
|
402
|
+
const titleLabel = str(meta.title_label || (titleMode === 'fixed' ? 'chapter' : 'none'));
|
|
403
|
+
const tpl = templates(set);
|
|
404
|
+
const env = { partials: tpl.partials, vars };
|
|
405
|
+
const out = [];
|
|
406
|
+
let section = '';
|
|
407
|
+
let placeholders = 0;
|
|
408
|
+
let streak = ['', 0];
|
|
409
|
+
|
|
410
|
+
slides.forEach((s, idx) => {
|
|
411
|
+
const i = idx + 1;
|
|
412
|
+
const lid = str(isObj(s) ? s.layout : '');
|
|
413
|
+
const where = `페이지 ${i} (${lid})`;
|
|
414
|
+
const layout = Object.hasOwn(set.layouts, lid) ? set.layouts[lid] : undefined;
|
|
415
|
+
if (!isObj(s) || !layout) {
|
|
416
|
+
error(`${where}: 없는 레이아웃. 사용 가능: ${set.ids.join(', ')}`);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (s.data !== undefined && !isObj(s.data)) error(`${where}: data는 객체여야 함`);
|
|
420
|
+
const schema = layout.schema;
|
|
421
|
+
const data = clone(isObj(s.data) ? s.data : {});
|
|
422
|
+
const slots = { ...schema.slots };
|
|
423
|
+
for (const [k, v] of Object.entries(UNIVERSAL)) if (!(k in slots)) slots[k] = v;
|
|
424
|
+
applyDefaults(data, slots);
|
|
425
|
+
const local = new Set(
|
|
426
|
+
(Array.isArray(data.groups) ? data.groups : []).filter(isObj).map(g => str(g.key))
|
|
427
|
+
);
|
|
428
|
+
validateDict(data, slots, where, { vars: new Set(Object.keys(vars)), local, out: report });
|
|
429
|
+
checkImages(s.data, where, report, options.imageExists);
|
|
430
|
+
if ('frame' in schema.slots || lid === 'image-bg') postDefaults(data, lid);
|
|
431
|
+
if (lid === 'variables' && Object.keys(vars).length === 0)
|
|
432
|
+
error(`${where}: meta.variables가 비어 있음. 입력받을 변수를 meta에 정의`);
|
|
433
|
+
if (lid === 'cards') {
|
|
434
|
+
const ni = Array.isArray(data.items) ? data.items.length : 0;
|
|
435
|
+
const nc = Number.parseInt(data.cols || 3, 10) || 3;
|
|
436
|
+
if (ni > nc && !(nc === 2 && ni === 4))
|
|
437
|
+
warn(
|
|
438
|
+
`${where}: 카드 ${ni}개가 ${nc}열보다 많아 두 줄이 됨. 넘칠 수 있으므로 열 수와 같은 개수로 맞춘다`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
const answerOk = (answer, options) => {
|
|
442
|
+
const n = Number(answer);
|
|
443
|
+
return Number.isInteger(n) && n >= 1 && n <= (Array.isArray(options) ? options.length : 0);
|
|
444
|
+
};
|
|
445
|
+
if (lid === 'quiz' && !answerOk(data.answer, data.options))
|
|
446
|
+
error(`${where}.answer: 1~보기 수 사이의 번호여야 함`);
|
|
447
|
+
if (lid === 'choice-list')
|
|
448
|
+
(Array.isArray(data.items) ? data.items : []).forEach((it, k) => {
|
|
449
|
+
if (!isObj(it) || !answerOk(it.answer, it.options))
|
|
450
|
+
error(`${where}.items[${k + 1}].answer: 1~보기 수 사이의 번호여야 함`);
|
|
451
|
+
});
|
|
452
|
+
if (lid === 'ox-list')
|
|
453
|
+
(Array.isArray(data.items) ? data.items : []).forEach((it, k) => {
|
|
454
|
+
if (isObj(it) && !['O', 'X'].includes(str(it.answer)))
|
|
455
|
+
error(`${where}.items[${k + 1}].answer: "O" 또는 "X"여야 함`);
|
|
456
|
+
});
|
|
457
|
+
if (lid === 'ox-card' && !['O', 'X'].includes(str(data.answer)))
|
|
458
|
+
error(`${where}.answer: "O" 또는 "X"여야 함`);
|
|
459
|
+
const emojiList = { simulation: 'scenes', tabs: 'tabs', toggle: 'options' }[lid];
|
|
460
|
+
if (emojiList) {
|
|
461
|
+
const em = (Array.isArray(data[emojiList]) ? data[emojiList] : [])
|
|
462
|
+
.filter(isObj)
|
|
463
|
+
.map(x => truthy(x.emoji));
|
|
464
|
+
if (em.some(Boolean) && !em.every(Boolean))
|
|
465
|
+
warn(`${where}.${emojiList}: 이모지는 목록의 모든 항목에 넣거나 모두 비운다`);
|
|
466
|
+
}
|
|
467
|
+
if (lid === 'simulation') {
|
|
468
|
+
const ctl = new Map(
|
|
469
|
+
(Array.isArray(data.controls) ? data.controls : [])
|
|
470
|
+
.filter(isObj)
|
|
471
|
+
.map(c => [str(c.key), (Array.isArray(c.values) ? c.values : []).map(str)])
|
|
472
|
+
);
|
|
473
|
+
const names = (Array.isArray(data.scenes) ? data.scenes : [])
|
|
474
|
+
.filter(isObj)
|
|
475
|
+
.map(x => str(x.name));
|
|
476
|
+
(Array.isArray(data.missions) ? data.missions : []).filter(isObj).forEach((m, k) => {
|
|
477
|
+
const w = `${where}.missions[${k + 1}]`;
|
|
478
|
+
if (m.scene && !names.includes(str(m.scene)))
|
|
479
|
+
error(`${w}.scene: scenes에 없는 장면 이름 -> ${JSON.stringify(m.scene)}`);
|
|
480
|
+
for (const part of str(m.when).split(';')) {
|
|
481
|
+
if (!part.trim()) continue;
|
|
482
|
+
const at = part.indexOf('=');
|
|
483
|
+
const key = (at < 0 ? part : part.slice(0, at)).trim();
|
|
484
|
+
const values = at < 0 ? [] : part.slice(at + 1).split('|');
|
|
485
|
+
if (!ctl.has(key)) {
|
|
486
|
+
error(`${w}.when: controls에 없는 key -> ${JSON.stringify(key)}`);
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
for (const v of values)
|
|
490
|
+
if (!ctl.get(key).includes(v.trim()))
|
|
491
|
+
error(`${w}.when: ${key}의 values에 없는 값 -> ${JSON.stringify(v.trim())}`);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
if (lid === 'section') section = stripMarkup(data.chapter || data.title);
|
|
496
|
+
const ctx = { ...glob };
|
|
497
|
+
const headLeft = ['cover', 'cover-dark', 'section'].includes(lid)
|
|
498
|
+
? glob.brand
|
|
499
|
+
: section || glob.brand;
|
|
500
|
+
Object.assign(ctx, {
|
|
501
|
+
section: COVERS.includes(lid) ? '' : section,
|
|
502
|
+
page: i,
|
|
503
|
+
head_left: headLeft,
|
|
504
|
+
});
|
|
505
|
+
if (!NO_EYEBROW.includes(lid) && !data.eyebrow) {
|
|
506
|
+
if (titleLabel === 'chapter' && section) data.eyebrow = section;
|
|
507
|
+
else if (titleLabel === 'title' && meta.title) data.eyebrow = str(meta.title);
|
|
508
|
+
}
|
|
509
|
+
Object.assign(ctx, data);
|
|
510
|
+
let body;
|
|
511
|
+
try {
|
|
512
|
+
body = render(tpl.layouts[lid], ctx, env).trim();
|
|
513
|
+
} catch (e) {
|
|
514
|
+
error(`${where}: 그리지 못함 (${e.message})`);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const title = stripMarkup(data.title || data.text || schema.name);
|
|
518
|
+
placeholders += body.split('class="ph"').length - 1;
|
|
519
|
+
// 키트 스테퍼가 단계로 쓰는 표시(data-ec-step)와 원본의 쪽 정보
|
|
520
|
+
body = body.replace(
|
|
521
|
+
/^<section /,
|
|
522
|
+
`<section data-ec-step id="s${i}" data-page="${i}" data-section="${escapeHtml(section, true)}" data-title="${escapeHtml(title, true)}" `
|
|
523
|
+
);
|
|
524
|
+
const notes = truthy(data.notes)
|
|
525
|
+
? `<aside class="notes">${escapeHtml(str(data.notes))}</aside>`
|
|
526
|
+
: '';
|
|
527
|
+
const end = body.lastIndexOf('</section>');
|
|
528
|
+
body = `${body.slice(0, end)}${notes}</section>`;
|
|
529
|
+
out.push({ html: body, layout: lid, title, notes: str(data.notes) });
|
|
530
|
+
streak = streak[0] === lid ? [lid, streak[1] + 1] : [lid, 1];
|
|
531
|
+
if (streak[1] === 3 && lid !== 'cards')
|
|
532
|
+
warn(`페이지 ${i}: 같은 레이아웃(${lid})이 3장 연속. 다른 레이아웃으로 리듬을 바꾼다`);
|
|
533
|
+
});
|
|
534
|
+
if (slides.length > 0 && !COVERS.includes(str(isObj(slides[0]) ? slides[0].layout : '')))
|
|
535
|
+
warn('첫 페이지가 표지가 아님');
|
|
536
|
+
if (placeholders > 0)
|
|
537
|
+
warn(
|
|
538
|
+
`이미지 자리 ${placeholders}곳이 비어 있음(점선 상자로 표시됨). 이미지를 채우거나 의도한 자리인지 확인`
|
|
539
|
+
);
|
|
540
|
+
if (!meta.title) warn('meta.title이 비어 있음');
|
|
541
|
+
return {
|
|
542
|
+
slides: out,
|
|
543
|
+
report,
|
|
544
|
+
attrs: lessonAttrs(meta, slides.length, report),
|
|
545
|
+
vars,
|
|
546
|
+
title: str(meta.title),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** 자료 틀(#lesson)의 속성. 틀린 값은 오류로 알리고 기본값을 쓴다 */
|
|
551
|
+
function lessonAttrs(meta, total, report) {
|
|
552
|
+
const style = pick(meta, 'style', 'document', report);
|
|
553
|
+
const doc = style === 'document';
|
|
554
|
+
const attrs = {
|
|
555
|
+
title: pick(meta, 'title_mode', doc ? 'fixed' : 'free', report),
|
|
556
|
+
header: pick(meta, 'header', doc ? 'hide' : 'show', report),
|
|
557
|
+
bg: pick(meta, 'background', doc ? 'decor' : 'plain', report),
|
|
558
|
+
hright: pick(meta, 'header_right', 'none', report),
|
|
559
|
+
key: '',
|
|
560
|
+
single: total === 1,
|
|
561
|
+
};
|
|
562
|
+
pick(meta, 'title_label', 'chapter', report);
|
|
563
|
+
const kc = str(meta.key_color);
|
|
564
|
+
if (kc && !/^#[0-9a-fA-F]{6}$/.test(kc))
|
|
565
|
+
report.push({
|
|
566
|
+
level: 'error',
|
|
567
|
+
message: `meta.key_color는 #rrggbb 형식 -> ${JSON.stringify(kc)}`,
|
|
568
|
+
});
|
|
569
|
+
else attrs.key = kc;
|
|
570
|
+
return attrs;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function pick(meta, key, fallback, report) {
|
|
574
|
+
const v = meta[key];
|
|
575
|
+
if (v === undefined || v === null || v === '') return fallback;
|
|
576
|
+
if (!META_ENUMS[key].includes(String(v))) {
|
|
577
|
+
report.push({
|
|
578
|
+
level: 'error',
|
|
579
|
+
message: `meta.${key}는 ${META_ENUMS[key].join(' 또는 ')} -> ${JSON.stringify(v)}`,
|
|
580
|
+
});
|
|
581
|
+
return key === 'style' ? 'document' : fallback;
|
|
582
|
+
}
|
|
583
|
+
return String(v);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** 검사만 (조립 결과는 버림): [{ level, message }] */
|
|
587
|
+
export function validateLesson(content, options = {}) {
|
|
588
|
+
return buildLesson(content, options).report;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* 슬라이드 data에서 그 레이아웃에 없는 빈 칸('' · null · [] · {})을 뺀 사본. 편집기 폼 보기가 다른 슬라이드의 칸 모양을
|
|
593
|
+
* 빈 값으로 더했을 때 저장 전에 지운다. 값이 있는 모르는 칸은 남겨 검사가 오타로 알리게 한다
|
|
594
|
+
*/
|
|
595
|
+
export function cleanLesson(content, options = {}) {
|
|
596
|
+
const set = layoutSet(options);
|
|
597
|
+
if (!isObj(content) || !Array.isArray(content.slides)) return content;
|
|
598
|
+
return {
|
|
599
|
+
...content,
|
|
600
|
+
slides: content.slides.map(s => {
|
|
601
|
+
if (!isObj(s) || !isObj(s.data) || !Object.hasOwn(set.layouts, s.layout)) return s;
|
|
602
|
+
const slots = set.layouts[s.layout].schema.slots;
|
|
603
|
+
const data = Object.fromEntries(
|
|
604
|
+
Object.entries(s.data).filter(([k, v]) => k in slots || k in UNIVERSAL || truthy(v))
|
|
605
|
+
);
|
|
606
|
+
return { ...s, data };
|
|
607
|
+
}),
|
|
608
|
+
};
|
|
609
|
+
}
|