@eliceio/cdk-cli 1.3.0-contenttypes.0 → 1.3.0-contenttypes.1
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 +21 -20
- package/es/cli.js +1 -1
- package/es/commands/create/index.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/doctor/index.js +6 -2
- package/es/core/config.d.ts +22 -0
- package/es/core/config.js +165 -1
- package/es/dev/assets.d.ts +80 -0
- package/es/dev/assets.js +240 -0
- package/es/dev/grading.d.ts +42 -26
- package/es/dev/grading.js +88 -39
- package/es/dev/host-page.js +26 -2
- package/es/dev/inject.d.ts +2 -1
- package/es/dev/inject.js +10 -2
- package/es/dev/mock-api.d.ts +23 -2
- package/es/dev/mock-api.js +210 -40
- package/es/dev/server.d.ts +12 -1
- package/es/dev/server.js +115 -9
- package/es/rules.json.js +1 -1
- package/package.json +2 -2
- package/rules.json +3 -3
- package/skills/_shared/references/02-design-the-material.md +1 -1
- package/skills/_shared/references/03-create-the-project.md +9 -8
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/05-screen-code.md +22 -20
- package/skills/_shared/references/06-using-the-quiz-template.md +2 -2
- package/skills/_shared/references/08-fix-check-errors.md +1 -1
- package/skills/_shared/references/09-check.md +1 -0
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +17 -0
- package/templates/_shared/lib/cdk-mock.js +212 -7
- package/templates/_shared/lib/elice-content.d.ts +61 -1
- package/templates/_shared/lib/elice-content.js +317 -10
- package/templates/blank/README.md +1 -1
- package/templates/blank/screens/instructor.js +8 -2
- package/templates/blank/screens/learn.js +1 -1
- package/templates/blank/template.json +1 -1
- package/templates/document/README.md +92 -0
- package/templates/document/commentary.txt +2 -0
- package/templates/document/core/dom.d.ts +13 -0
- package/templates/document/core/dom.js +83 -0
- package/templates/document/core/file-type.d.ts +21 -0
- package/templates/document/core/file-type.js +85 -0
- package/templates/document/core/group-3d.d.ts +20 -0
- package/templates/document/core/group-3d.js +256 -0
- package/templates/document/core/inline-edit.d.ts +15 -0
- package/templates/document/core/inline-edit.js +377 -0
- package/templates/document/core/load.d.ts +13 -0
- package/templates/document/core/load.js +40 -0
- package/templates/document/core/pdf-options.d.ts +9 -0
- package/templates/document/core/pdf-options.js +36 -0
- package/templates/document/core/pdf-worker.d.ts +24 -0
- package/templates/document/core/pdf-worker.js +122 -0
- package/templates/document/core/pdf.d.ts +12 -0
- package/templates/document/core/pdf.js +190 -0
- package/templates/document/core/pptx-edit.d.ts +14 -0
- package/templates/document/core/pptx-edit.js +137 -0
- package/templates/document/core/pptx-fonts.d.ts +5 -0
- package/templates/document/core/pptx-fonts.js +115 -0
- package/templates/document/core/pptx-media.d.ts +18 -0
- package/templates/document/core/pptx-media.js +83 -0
- package/templates/document/core/pptx-view.d.ts +5 -0
- package/templates/document/core/pptx-view.js +185 -0
- package/templates/document/core/settings.d.ts +25 -0
- package/templates/document/core/settings.js +86 -0
- package/templates/document/core/slide-edges.d.ts +3 -0
- package/templates/document/core/slide-edges.js +82 -0
- package/templates/document/core/viewer.d.ts +28 -0
- package/templates/document/core/viewer.js +159 -0
- package/templates/document/edit.html +17 -0
- package/templates/document/gitignore +4 -0
- package/templates/document/index.html +18 -0
- package/templates/document/metadata.json +9 -0
- package/templates/document/package.json +17 -0
- package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
- package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
- package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
- package/templates/document/screens/edit.js +574 -0
- package/templates/document/screens/learn.js +61 -0
- package/templates/document/styles.css +644 -0
- package/templates/document/template.json +6 -0
- package/templates/document/ui/templates/edit.js +82 -0
- package/templates/document/ui/templates/page.js +11 -0
- package/templates/document/ui/templates/viewer.js +41 -0
- package/templates/document/ui/texts.d.ts +3 -0
- package/templates/document/ui/texts.js +62 -0
- package/templates/document/ui/theme.css +69 -0
- package/templates/quiz/README.md +11 -9
- package/templates/quiz/core/behaviors.d.ts +4 -0
- package/templates/quiz/core/behaviors.js +4 -2
- package/templates/quiz/core/editor.d.ts +17 -2
- package/templates/quiz/core/editor.js +85 -10
- package/templates/quiz/core/markdown.d.ts +15 -0
- package/templates/quiz/core/markdown.js +164 -4
- package/templates/quiz/core/model.d.ts +6 -2
- package/templates/quiz/core/model.js +30 -4
- package/templates/quiz/core/rich-text.d.ts +1 -2
- package/templates/quiz/core/rich-text.js +7 -59
- package/templates/quiz/public/img/mascot-half.webp +0 -0
- package/templates/quiz/screens/edit.js +165 -52
- package/templates/quiz/screens/learn.js +94 -38
- package/templates/quiz/styles.css +464 -4
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/edit.d.ts +1 -0
- package/templates/quiz/ui/templates/edit.js +65 -9
- package/templates/quiz/ui/templates/page.js +14 -0
- package/templates/quiz/ui/templates/question.js +5 -3
- package/templates/quiz/ui/texts.js +38 -20
|
@@ -1,22 +1,165 @@
|
|
|
1
1
|
// 지문 · 해설용 작은 마크다운 (외부 라이브러리 없이). 먼저 HTML을 모두 이스케이프하므로 교육자가 쓴 태그는 그대로 글자로 보인다.
|
|
2
2
|
// 지원: 문단 · 줄바꿈 · # 제목 · **굵게** · *기울임* · ~~취소선~~ · `코드` · ```코드 블록```(3줄부터 줄 번호) · - 목록 · 1. 목록 ·
|
|
3
|
-
// [링크](https://…) · 그림  · 그림 (편집 화면에서 서버에 올린 그림) · (zip 안 그림) ·
|
|
4
|
+
// 옛 (1.9.0 전 편집 화면이 내용 images에 data: 주소로 둔 그림) ·
|
|
4
5
|
// \* 처럼 앞에 \를 붙이면 서식 기호가 아니라 글자
|
|
5
6
|
|
|
6
7
|
const escape = (s) =>
|
|
7
8
|
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
8
9
|
|
|
9
|
-
/** 내용 images에 둔 그림 (아이디 → data: 주소). 화면이 내용을 받으면 setImages로 넣는다 */
|
|
10
|
+
/** 옛 그림: 내용 images에 둔 그림 (아이디 → data: 주소). 화면이 내용을 받으면 setImages로 넣는다 */
|
|
10
11
|
let images = {};
|
|
11
12
|
/** @param {Record<string, string> | undefined} next */
|
|
12
13
|
export const setImages = (next) => {
|
|
13
14
|
images = next ?? {};
|
|
14
15
|
};
|
|
15
|
-
/** 그림으로 받는 data: 주소 (편집 화면이 줄여 만든 webp · jpeg, 옛 png) */
|
|
16
|
+
/** 옛 그림으로 받는 data: 주소 (1.9.0 전 편집 화면이 줄여 만든 webp · jpeg, 옛 png) */
|
|
16
17
|
export const IMAGE_DATA = /^data:image\/(webp|jpeg|png);base64,[A-Za-z0-9+/=]+$/;
|
|
17
|
-
/** 아이디의 그림 주소 (없거나 모양이 다르면 null) */
|
|
18
|
+
/** 아이디의 옛 그림 주소 (없거나 모양이 다르면 null) */
|
|
18
19
|
export const imageSrc = (id) => (IMAGE_DATA.test(images[id] ?? '') ? images[id] : null);
|
|
19
20
|
|
|
21
|
+
/** 서버에 올린 그림의 파일 키 `assets/{자료 id}/{이름}.{확장자}` (SDK assets.post가 준 id 그대로) */
|
|
22
|
+
export const ASSET_KEY = /^assets\/[\w-]+\/[\w-]+\.(?:png|jpe?g|webp|gif)$/i;
|
|
23
|
+
const ASSET_REF = /asset:(assets\/[\w-]+\/[\w-]+\.(?:png|jpe?g|webp|gif))(?=\))/gi;
|
|
24
|
+
/**
|
|
25
|
+
* 올린 그림 (파일 키 → 받은 결과: 화면에 넣을 blob: 주소, 받지 못했으면 null). settings에는 키만 둔다.
|
|
26
|
+
* 서명 주소를 <img>에 바로 넣지 않고 fetch로 받아 blob:으로 넣는다: 콘텐츠 CSP 초안의 img-src는 콘텐츠 출처 · data: · blob:뿐이고
|
|
27
|
+
* 파일 출처(자료 API)는 connect-src에만 있다. 받아 둔 그림은 서명 주소가 만료돼도 그대로 보인다.
|
|
28
|
+
* 화면은 그림을 기다리지 않고 먼저 그린다: 아직 받지 못한 그림 자리는 설명 글(data-asset-pending)이고, 받으면 그 자리만 <img>로
|
|
29
|
+
* (못 받으면 안내로) 바꾼다. 다시 그려도 받은 그림은 바로 <img>, 받는 중이면 다시 자리를 두었다가 끝나면 바꾼다
|
|
30
|
+
*/
|
|
31
|
+
const assetUrls = new Map();
|
|
32
|
+
/** 받는 중인 그림 (파일 키 → Promise). 같은 그림을 두 번 받지 않는다 */
|
|
33
|
+
const assetLoads = new Map();
|
|
34
|
+
/** 그림 하나를 받는 시간 한도 (주소 묻기 + 내려받기 합쳐서). 넘으면 못 받은 것으로 */
|
|
35
|
+
export const ASSET_TIMEOUT_MS = 10_000;
|
|
36
|
+
/** 받지 못했던 자리를 받은 결과로 바꾼 뒤 document에 보내는 이벤트 (detail: { key, element }) */
|
|
37
|
+
export const ASSET_FILLED_EVENT = 'qz-asset-filled';
|
|
38
|
+
/** 처음 보는 키를 그릴 때 받으러 갈 함수 (resolveAssets · loadAsset이 넣음, 키트 app.assets.url) */
|
|
39
|
+
let assetLoader = null;
|
|
40
|
+
/** 받지 못한 그림 자리에 보일 글 (화면이 문구를 넣음, 없으면 설명 글) */
|
|
41
|
+
let assetFailedText = '';
|
|
42
|
+
/** @param {string} text */
|
|
43
|
+
export const setAssetFailedText = (text) => {
|
|
44
|
+
assetFailedText = text ?? '';
|
|
45
|
+
};
|
|
46
|
+
/** 그림을 받을 주소: 서명 주소(https) · 로컬 흉내(http · blob:) */
|
|
47
|
+
const ASSET_URL = /^(https?:\/\/|blob:)[^\s"'<>]+$/;
|
|
48
|
+
const ASSET_TYPES = /^image\/(png|jpeg|webp|gif)$/;
|
|
49
|
+
|
|
50
|
+
/** 주소를 묻고 받아 blob: 주소로 (signal로 멈춤) */
|
|
51
|
+
async function fetchAsset(key, urlOf, signal) {
|
|
52
|
+
const url = await urlOf(key);
|
|
53
|
+
if (typeof url !== 'string' || !ASSET_URL.test(url)) return null;
|
|
54
|
+
if (url.startsWith('blob:')) return url;
|
|
55
|
+
const res = await fetch(url, { signal });
|
|
56
|
+
if (!res.ok) return null;
|
|
57
|
+
const blob = await res.blob();
|
|
58
|
+
return ASSET_TYPES.test(blob.type) || blob.type === '' ? URL.createObjectURL(blob) : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 그림 자리 (아직 받지 못함 · 못 받음) */
|
|
62
|
+
function placeholder(key, alt) {
|
|
63
|
+
const failed = assetUrls.has(key);
|
|
64
|
+
const el = document.createElement('span');
|
|
65
|
+
el.className = 'qz-image-missing';
|
|
66
|
+
if (failed && assetFailedText) {
|
|
67
|
+
el.setAttribute('role', 'alert');
|
|
68
|
+
el.textContent = assetFailedText;
|
|
69
|
+
} else el.textContent = alt;
|
|
70
|
+
if (!failed) el.dataset.assetPending = key;
|
|
71
|
+
el.dataset.alt = alt;
|
|
72
|
+
return el;
|
|
73
|
+
}
|
|
74
|
+
/** 받은 그림 */
|
|
75
|
+
function assetImage(key, src, alt) {
|
|
76
|
+
const img = document.createElement('img');
|
|
77
|
+
img.className = 'qz-image';
|
|
78
|
+
img.src = src;
|
|
79
|
+
img.alt = alt;
|
|
80
|
+
img.dataset.asset = key;
|
|
81
|
+
return img;
|
|
82
|
+
}
|
|
83
|
+
/** 문서에 놓인 그 키의 자리를 받은 결과로 바꾼다 (자리만 바꾸고 나머지는 건드리지 않음) */
|
|
84
|
+
function fillAsset(key) {
|
|
85
|
+
if (typeof document === 'undefined') return;
|
|
86
|
+
for (const el of document.querySelectorAll('[data-asset-pending]')) {
|
|
87
|
+
if (el.dataset.assetPending !== key) continue;
|
|
88
|
+
const alt = el.dataset.alt ?? el.textContent ?? '';
|
|
89
|
+
const src = assetUrls.get(key);
|
|
90
|
+
const next = src ? assetImage(key, src, alt) : placeholder(key, alt);
|
|
91
|
+
el.replaceWith(next);
|
|
92
|
+
// 화면이 늦게 들어온 그림에 맞출 수 있게 (학생 화면: 제출 뒤 맨 아래로 한 번 더)
|
|
93
|
+
document.dispatchEvent(new CustomEvent(ASSET_FILLED_EVENT, { detail: { key, element: next } }));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 파일 키의 그림을 받는다 (주소 묻기 + 내려받기 합쳐서 ASSET_TIMEOUT_MS까지). 끝나면 화면의 그 자리를 바꾼다.
|
|
99
|
+
* 이미 받았거나 받는 중이면 그것을 기다린다. urlOf는 키트 app.assets.url
|
|
100
|
+
* @param {string} key
|
|
101
|
+
* @param {(key: string) => Promise<string | null>} urlOf
|
|
102
|
+
*/
|
|
103
|
+
export function loadAsset(key, urlOf) {
|
|
104
|
+
if (!ASSET_KEY.test(key)) return Promise.resolve();
|
|
105
|
+
assetLoader ??= urlOf;
|
|
106
|
+
if (assetUrls.get(key)) return Promise.resolve();
|
|
107
|
+
const running = assetLoads.get(key);
|
|
108
|
+
if (running) return running;
|
|
109
|
+
const controller = new AbortController();
|
|
110
|
+
let timer;
|
|
111
|
+
const deadline = new Promise((resolve) => {
|
|
112
|
+
timer = setTimeout(() => {
|
|
113
|
+
controller.abort();
|
|
114
|
+
resolve(null);
|
|
115
|
+
}, ASSET_TIMEOUT_MS);
|
|
116
|
+
});
|
|
117
|
+
const load = Promise.race([
|
|
118
|
+
fetchAsset(key, urlOf, controller.signal).catch(() => null),
|
|
119
|
+
deadline,
|
|
120
|
+
]).then((src) => {
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
assetLoads.delete(key);
|
|
123
|
+
assetUrls.set(key, src);
|
|
124
|
+
fillAsset(key);
|
|
125
|
+
});
|
|
126
|
+
assetLoads.set(key, load);
|
|
127
|
+
return load;
|
|
128
|
+
}
|
|
129
|
+
/** 글에 든 올린 그림 파일 키들 */
|
|
130
|
+
export const assetKeysIn = (source) => [...String(source ?? '').matchAll(ASSET_REF)].map((m) => m[1]);
|
|
131
|
+
/**
|
|
132
|
+
* 글들에 든 올린 그림을 받기 시작한다. 화면은 기다리지 않고 먼저 그려도 된다 (받으면 자리를 바꿈).
|
|
133
|
+
* 돌려준 Promise는 모두 끝났을 때 (테스트용)
|
|
134
|
+
* @param {(string | undefined)[]} sources
|
|
135
|
+
* @param {(key: string) => Promise<string | null>} urlOf
|
|
136
|
+
*/
|
|
137
|
+
export function resolveAssets(sources, urlOf) {
|
|
138
|
+
assetLoader = urlOf;
|
|
139
|
+
const keys = [...new Set(sources.flatMap(assetKeysIn))];
|
|
140
|
+
return Promise.all(keys.map((key) => loadAsset(key, urlOf))).then(() => undefined);
|
|
141
|
+
}
|
|
142
|
+
/** 그림 칸 참조(image:아이디 · asset:파일키)의 주소 (모르면 null) */
|
|
143
|
+
export const refSrc = (ref) => {
|
|
144
|
+
const [, kind, value] = /^(image|asset):(.+)$/.exec(ref ?? '') ?? [];
|
|
145
|
+
if (kind === 'image') return imageSrc(value);
|
|
146
|
+
if (kind === 'asset') return assetUrls.get(value) ?? null;
|
|
147
|
+
return null;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* 그림 칸(편집 화면)에 놓을 asset 그림: 받았으면 <img>, 아직이면 자리(받으면 바뀜), 못 받았으면 안내. asset이 아니면 null
|
|
151
|
+
* @param {string} ref
|
|
152
|
+
* @param {string} [alt]
|
|
153
|
+
*/
|
|
154
|
+
export function assetBlock(ref, alt = '') {
|
|
155
|
+
const key = /^asset:(.+)$/.exec(ref ?? '')?.[1];
|
|
156
|
+
if (!key || !ASSET_KEY.test(key)) return null;
|
|
157
|
+
const src = assetUrls.get(key);
|
|
158
|
+
if (src) return assetImage(key, src, alt);
|
|
159
|
+
if (!assetUrls.has(key) && !assetLoads.has(key) && assetLoader) void loadAsset(key, assetLoader);
|
|
160
|
+
return placeholder(key, alt);
|
|
161
|
+
}
|
|
162
|
+
|
|
20
163
|
// \로 막은 서식 기호는 잠시 쓰지 않는 글자로 바꿔 두었다가 마지막에 되돌린다
|
|
21
164
|
const ESCAPED = {
|
|
22
165
|
'\\': '',
|
|
@@ -45,6 +188,23 @@ function inline(s) {
|
|
|
45
188
|
? `<img class="qz-image" src="${src}" alt="${alt}">`
|
|
46
189
|
: `<span class="qz-image-missing">${alt}</span>`;
|
|
47
190
|
})
|
|
191
|
+
.replace(
|
|
192
|
+
/!\[([^\]]*)\]\(asset:(assets\/[\w-]+\/[\w-]+\.(?:png|jpe?g|webp|gif))\)/gi,
|
|
193
|
+
(_, alt, key) => {
|
|
194
|
+
const src = assetUrls.get(key);
|
|
195
|
+
if (src) return `<img class="qz-image" src="${escape(src)}" alt="${alt}" data-asset="${key}">`;
|
|
196
|
+
// 받지 못했으면(주소 만료 · 시간 초과 등) 화면이 준 안내
|
|
197
|
+
if (assetUrls.has(key) && assetFailedText)
|
|
198
|
+
return `<span class="qz-image-missing" role="alert" data-alt="${alt}">${escape(assetFailedText)}</span>`;
|
|
199
|
+
// 아직이면 설명 글 자리를 두고 받으러 간다 (받으면 fillAsset이 이 자리를 바꿈)
|
|
200
|
+
if (!assetUrls.has(key) && !assetLoads.has(key) && assetLoader) {
|
|
201
|
+
const loader = assetLoader;
|
|
202
|
+
queueMicrotask(() => void loadAsset(key, loader));
|
|
203
|
+
}
|
|
204
|
+
const pending = assetUrls.has(key) ? '' : ` data-asset-pending="${key}"`;
|
|
205
|
+
return `<span class="qz-image-missing"${pending} data-alt="${alt}">${alt}</span>`;
|
|
206
|
+
},
|
|
207
|
+
)
|
|
48
208
|
.replace(
|
|
49
209
|
/!\[([^\]]*)\]\((img\/[\w./-]+)\)/g,
|
|
50
210
|
'<img class="qz-image" src="$2" alt="$1" loading="lazy">',
|
|
@@ -10,11 +10,15 @@ export declare function canAddQuestion(questions: unknown[] | undefined): boolea
|
|
|
10
10
|
export declare function nextId(used: string[], prefix?: string): string;
|
|
11
11
|
export declare function newQuestion(type: string, usedIds: string[], names: DefaultNames): any;
|
|
12
12
|
export declare function convertType(q: any, type: string, names: DefaultNames): any;
|
|
13
|
-
/** messages: 검증 문구 (ui/texts.js의 validation) */
|
|
13
|
+
/** messages: 검증 문구 (ui/texts.js의 validation). field: 'points'면 부분 채점 배점 문제 (questionIndex -1은 합계) */
|
|
14
14
|
export declare function validateQuiz(
|
|
15
15
|
content: any,
|
|
16
16
|
messages: Record<string, any>
|
|
17
|
-
): { questionIndex: number; message: string } | null;
|
|
17
|
+
): { questionIndex: number; message: string; field?: 'points' } | null;
|
|
18
|
+
/** 자동 배점: 문제마다 ceil(100 / 문제 수) (3문제 34 · 34 · 34) */
|
|
19
|
+
export declare function equalPoints(n: number): number[];
|
|
20
|
+
/** 문제별 배점(points) 합. 정수가 아닌 배점은 0 */
|
|
21
|
+
export declare function totalPoints(questions: { points?: unknown }[]): number;
|
|
18
22
|
export declare function encodeAnswer(q: any, value: any): string;
|
|
19
23
|
export declare function decodeAnswer(q: any, text: string | undefined): any;
|
|
20
24
|
export declare function isAnswered(q: any, value: any): boolean;
|
|
@@ -25,9 +25,9 @@ export const LIMITS = {
|
|
|
25
25
|
groupsMax: 6,
|
|
26
26
|
// 여러 문항 퀴즈: 문항 20개까지. pattern은 모든 문항을 맞혀야 100점, partial_pattern은 맞은 문항 점수의 합
|
|
27
27
|
questionsMax: 20,
|
|
28
|
-
// 편집 화면에서 올린 그림 (지문 · 해설):
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// 편집 화면에서 올린 그림 (지문 · 해설): 퀴즈 전체에 50개까지. 그림은 서버 파일로 올리고 글에는 파일 키(약 90자)만 두어
|
|
29
|
+
// settings(서버 한도 약 64KB)에는 50개를 넣어도 약 5KB
|
|
30
|
+
imagesMax: 50,
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/** 편집 화면에서 문항을 더 넣을 수 있는지. 이미 여러 문항으로 저장된 퀴즈도 그대로 보이고 저장되며, 더 넣는 것만 막는다 */
|
|
@@ -120,9 +120,35 @@ export function validateQuiz(content, v) {
|
|
|
120
120
|
return at(v.placeholderMax(LIMITS.placeholderMax));
|
|
121
121
|
if (q.explanation?.enabled && !q.explanation.text?.trim()) return at(v.explanation);
|
|
122
122
|
}
|
|
123
|
+
// 부분 채점(문제 2개 이상): 문제별 배점은 0~100 정수, 합은 100 이상 (100보다 작으면 다 맞혀도 완료되지 않음)
|
|
124
|
+
if (content.gradingType === PARTIAL && content.questions.length > 1) {
|
|
125
|
+
const bad = content.questions.findIndex(
|
|
126
|
+
(q) => !Number.isInteger(q.points) || q.points < 0 || q.points > 100,
|
|
127
|
+
);
|
|
128
|
+
if (bad >= 0) return { questionIndex: bad, message: v.at(bad + 1, v.pointsInt), field: 'points' };
|
|
129
|
+
if (totalPoints(content.questions) < 100)
|
|
130
|
+
return { questionIndex: -1, message: v.pointsTotal, field: 'points' };
|
|
131
|
+
}
|
|
123
132
|
return null;
|
|
124
133
|
}
|
|
125
134
|
|
|
135
|
+
/**
|
|
136
|
+
* 자동 배점: 문제마다 같은 점수 ceil(100 / 문제 수) (연주님 부분 채점 UI, 2026-11-18 결정). 3문제면 34 · 34 · 34(합 102)이고
|
|
137
|
+
* 서버가 학생 점수를 100에서 자르므로 다 맞히면 100점. 100으로 나눠떨어지면 합 100 (4문제 25 · 25 · 25 · 25)
|
|
138
|
+
* @param {number} n 문제 수
|
|
139
|
+
* @returns {number[]}
|
|
140
|
+
*/
|
|
141
|
+
export function equalPoints(n) {
|
|
142
|
+
const count = Math.floor(n);
|
|
143
|
+
if (!(count >= 1)) return [];
|
|
144
|
+
return Array.from({ length: count }, () => Math.ceil(100 / count));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 문제별 배점 합 (정수가 아닌 배점은 0으로) */
|
|
148
|
+
export function totalPoints(questions) {
|
|
149
|
+
return questions.reduce((sum, q) => sum + (Number.isInteger(q.points) ? q.points : 0), 0);
|
|
150
|
+
}
|
|
151
|
+
|
|
126
152
|
// ---------- 답 문자열 (편집 화면이 같은 모양으로 정답 정규식을 만든다) ----------
|
|
127
153
|
|
|
128
154
|
/**
|
|
@@ -316,7 +342,7 @@ export function checkAnswerKeys(questions, key, keys, v) {
|
|
|
316
342
|
|
|
317
343
|
/**
|
|
318
344
|
* 저장할 문항별 점수. 저장된 점수는 같은 자리 정규식(answer_key[i] = "^문제id=…")의 문제 것이라, 문제 id로 맞춰 지금 문제 순서로 다시 놓는다
|
|
319
|
-
* (순서를 바꿔도 점수가 제 문제를 따라감). 저장된 문제 id와 지금 문제 id가 하나라도 다르면(더함 · 지움) 똑같이 나눈 점수 (split
|
|
345
|
+
* (순서를 바꿔도 점수가 제 문제를 따라감). 저장된 문제 id와 지금 문제 id가 하나라도 다르면(더함 · 지움) 똑같이 나눈 점수 (split: 퀴즈 편집 화면은 equalPoints).
|
|
320
346
|
* resplit: 저장된 점수가 있었는데 맞추지 못해 다시 나눴는지 (화면이 짧게 알림)
|
|
321
347
|
* @param {{ answer_key?: unknown, scores?: unknown } | undefined} saved 저장된 partial_pattern 채점 설정
|
|
322
348
|
* @returns {{ scores: number[], resplit: boolean }}
|
|
@@ -11,9 +11,8 @@ export interface RichText {
|
|
|
11
11
|
list(tag?: 'ul' | 'ol'): void;
|
|
12
12
|
code(sample: string): void;
|
|
13
13
|
}
|
|
14
|
-
export type Block = { type: 'text'; text: string } | { type: 'image'; alt: string;
|
|
14
|
+
export type Block = { type: 'text'; text: string } | { type: 'image'; alt: string; ref: string };
|
|
15
15
|
export declare function toMarkdown(root: Node): string;
|
|
16
16
|
export declare function richText(el: HTMLElement, opts: { onChange: (markdown: string) => void }): RichText;
|
|
17
17
|
export declare function splitBlocks(source: string): Block[];
|
|
18
18
|
export declare function joinBlocks(items: Block[]): string;
|
|
19
|
-
export declare function compressImage(file: File, maxChars: number): Promise<string>;
|
|
@@ -436,10 +436,12 @@ export function richText(el, { onChange }) {
|
|
|
436
436
|
return editor;
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
|
|
439
|
+
/** 한 줄을 차지하는 그림: 올린 그림 asset:파일키 · 옛 그림 image:아이디 */
|
|
440
|
+
const IMAGE_LINE =
|
|
441
|
+
/^!\[([^\]]*)\]\((image:[\w-]+|asset:assets\/[\w-]+\/[\w-]+\.(?:png|jpe?g|webp|gif))\)$/i;
|
|
440
442
|
/**
|
|
441
|
-
* 마크다운을 글 칸 · 그림 칸 차례로 나눈다 (한 줄을 차지하는 올린 그림 만 그림 칸)
|
|
442
|
-
* @returns {({ type: 'text', text: string } | { type: 'image', alt: string,
|
|
443
|
+
* 마크다운을 글 칸 · 그림 칸 차례로 나눈다 (한 줄을 차지하는 올린 그림  · 옛 만 그림 칸)
|
|
444
|
+
* @returns {({ type: 'text', text: string } | { type: 'image', alt: string, ref: string })[]}
|
|
443
445
|
*/
|
|
444
446
|
export function splitBlocks(source) {
|
|
445
447
|
const out = [];
|
|
@@ -452,7 +454,7 @@ export function splitBlocks(source) {
|
|
|
452
454
|
const image = IMAGE_LINE.exec(line.trim());
|
|
453
455
|
if (image) {
|
|
454
456
|
flush();
|
|
455
|
-
out.push({ type: 'image', alt: image[1],
|
|
457
|
+
out.push({ type: 'image', alt: image[1], ref: image[2] });
|
|
456
458
|
} else lines.push(line);
|
|
457
459
|
}
|
|
458
460
|
flush();
|
|
@@ -462,60 +464,6 @@ export function splitBlocks(source) {
|
|
|
462
464
|
/** splitBlocks의 반대 (빈 글 칸은 뺀다) */
|
|
463
465
|
export const joinBlocks = (items) =>
|
|
464
466
|
items
|
|
465
|
-
.map((b) =>
|
|
466
|
-
b.type === 'image' ? `` : b.text.replace(/^\n+|\n+$/g, ''),
|
|
467
|
-
)
|
|
467
|
+
.map((b) => (b.type === 'image' ? `` : b.text.replace(/^\n+|\n+$/g, '')))
|
|
468
468
|
.filter((s) => s !== '')
|
|
469
469
|
.join('\n\n');
|
|
470
|
-
|
|
471
|
-
const SIZES = [
|
|
472
|
-
[1280, 0.85],
|
|
473
|
-
[1280, 0.7],
|
|
474
|
-
[960, 0.7],
|
|
475
|
-
[800, 0.6],
|
|
476
|
-
[640, 0.55],
|
|
477
|
-
];
|
|
478
|
-
const fail = (code) => Object.assign(new Error(code), { code });
|
|
479
|
-
/**
|
|
480
|
-
* 올린 그림 파일을 maxChars 글자 이하의 data: 주소로 (webp, 못 만들면 jpeg). 크기 · 품질을 차례로 줄여 맞춘다
|
|
481
|
-
* 실패하면 code가 'not-image' | 'unreadable' | 'too-big'인 오류
|
|
482
|
-
*/
|
|
483
|
-
export async function compressImage(file, maxChars) {
|
|
484
|
-
if (!file.type.startsWith('image/')) throw fail('not-image');
|
|
485
|
-
let bitmap;
|
|
486
|
-
try {
|
|
487
|
-
bitmap = await createImageBitmap(file);
|
|
488
|
-
} catch {
|
|
489
|
-
throw fail('unreadable');
|
|
490
|
-
}
|
|
491
|
-
const canvas = document.createElement('canvas');
|
|
492
|
-
const ctx = canvas.getContext('2d');
|
|
493
|
-
let type = 'image/webp';
|
|
494
|
-
const draw = () => {
|
|
495
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
496
|
-
// jpeg는 투명한 곳이 검게 되지 않게 흰 바탕
|
|
497
|
-
if (type === 'image/jpeg') {
|
|
498
|
-
ctx.fillStyle = '#fff';
|
|
499
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
500
|
-
}
|
|
501
|
-
ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
502
|
-
};
|
|
503
|
-
for (const [side, quality] of SIZES) {
|
|
504
|
-
const scale = Math.min(1, side / Math.max(bitmap.width, bitmap.height));
|
|
505
|
-
canvas.width = Math.max(1, Math.round(bitmap.width * scale));
|
|
506
|
-
canvas.height = Math.max(1, Math.round(bitmap.height * scale));
|
|
507
|
-
draw();
|
|
508
|
-
let url = canvas.toDataURL(type, quality);
|
|
509
|
-
if (type === 'image/webp' && !url.startsWith('data:image/webp')) {
|
|
510
|
-
type = 'image/jpeg';
|
|
511
|
-
draw();
|
|
512
|
-
url = canvas.toDataURL(type, quality);
|
|
513
|
-
}
|
|
514
|
-
if (url.length <= maxChars) {
|
|
515
|
-
bitmap.close?.();
|
|
516
|
-
return url;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
bitmap.close?.();
|
|
520
|
-
throw fail('too-big');
|
|
521
|
-
}
|
|
Binary file
|