@eliceio/cdk-cli 1.3.0-contenttypes.0 → 1.3.0-contenttypes.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +24 -23
  2. package/es/cli.js +1 -1
  3. package/es/commands/create/index.js +1 -0
  4. package/es/commands/create/scaffold.d.ts +1 -1
  5. package/es/commands/create/scaffold.js +1 -1
  6. package/es/commands/doctor/index.js +6 -2
  7. package/es/core/config.d.ts +22 -0
  8. package/es/core/config.js +165 -1
  9. package/es/dev/assets.d.ts +80 -0
  10. package/es/dev/assets.js +240 -0
  11. package/es/dev/grading.d.ts +42 -26
  12. package/es/dev/grading.js +88 -39
  13. package/es/dev/host-page.js +26 -2
  14. package/es/dev/inject.d.ts +2 -1
  15. package/es/dev/inject.js +10 -2
  16. package/es/dev/mock-api.d.ts +23 -2
  17. package/es/dev/mock-api.js +210 -40
  18. package/es/dev/server.d.ts +12 -1
  19. package/es/dev/server.js +115 -9
  20. package/es/rules.json.js +1 -1
  21. package/package.json +2 -2
  22. package/rules.json +3 -3
  23. package/skills/_shared/references/02-design-the-material.md +1 -1
  24. package/skills/_shared/references/03-create-the-project.md +9 -8
  25. package/skills/_shared/references/04-rules.md +1 -1
  26. package/skills/_shared/references/05-screen-code.md +22 -20
  27. package/skills/_shared/references/06-using-the-quiz-template.md +6 -4
  28. package/skills/_shared/references/08-fix-check-errors.md +1 -1
  29. package/skills/_shared/references/09-check.md +1 -0
  30. package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
  31. package/skills/elice-content-publish/SKILL.md +1 -1
  32. package/templates/_shared/lib/cdk-mock.d.ts +17 -0
  33. package/templates/_shared/lib/cdk-mock.js +212 -7
  34. package/templates/_shared/lib/elice-content.d.ts +61 -1
  35. package/templates/_shared/lib/elice-content.js +317 -10
  36. package/templates/blank/README.md +1 -1
  37. package/templates/blank/screens/instructor.js +8 -2
  38. package/templates/blank/screens/learn.js +1 -1
  39. package/templates/blank/template.json +1 -1
  40. package/templates/document/README.md +92 -0
  41. package/templates/document/commentary.txt +2 -0
  42. package/templates/document/core/dom.d.ts +13 -0
  43. package/templates/document/core/dom.js +83 -0
  44. package/templates/document/core/file-type.d.ts +21 -0
  45. package/templates/document/core/file-type.js +85 -0
  46. package/templates/document/core/group-3d.d.ts +20 -0
  47. package/templates/document/core/group-3d.js +256 -0
  48. package/templates/document/core/inline-edit.d.ts +15 -0
  49. package/templates/document/core/inline-edit.js +377 -0
  50. package/templates/document/core/load.d.ts +13 -0
  51. package/templates/document/core/load.js +40 -0
  52. package/templates/document/core/pdf-options.d.ts +9 -0
  53. package/templates/document/core/pdf-options.js +36 -0
  54. package/templates/document/core/pdf-worker.d.ts +24 -0
  55. package/templates/document/core/pdf-worker.js +122 -0
  56. package/templates/document/core/pdf.d.ts +12 -0
  57. package/templates/document/core/pdf.js +190 -0
  58. package/templates/document/core/pptx-edit.d.ts +14 -0
  59. package/templates/document/core/pptx-edit.js +137 -0
  60. package/templates/document/core/pptx-fonts.d.ts +5 -0
  61. package/templates/document/core/pptx-fonts.js +115 -0
  62. package/templates/document/core/pptx-media.d.ts +18 -0
  63. package/templates/document/core/pptx-media.js +83 -0
  64. package/templates/document/core/pptx-view.d.ts +5 -0
  65. package/templates/document/core/pptx-view.js +185 -0
  66. package/templates/document/core/settings.d.ts +25 -0
  67. package/templates/document/core/settings.js +86 -0
  68. package/templates/document/core/slide-edges.d.ts +3 -0
  69. package/templates/document/core/slide-edges.js +82 -0
  70. package/templates/document/core/viewer.d.ts +28 -0
  71. package/templates/document/core/viewer.js +159 -0
  72. package/templates/document/edit.html +17 -0
  73. package/templates/document/gitignore +4 -0
  74. package/templates/document/index.html +18 -0
  75. package/templates/document/metadata.json +9 -0
  76. package/templates/document/package.json +17 -0
  77. package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
  78. package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
  79. package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
  80. package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
  81. package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
  82. package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
  83. package/templates/document/screens/edit.js +574 -0
  84. package/templates/document/screens/learn.js +61 -0
  85. package/templates/document/styles.css +644 -0
  86. package/templates/document/template.json +13 -0
  87. package/templates/document/ui/templates/edit.js +82 -0
  88. package/templates/document/ui/templates/page.js +11 -0
  89. package/templates/document/ui/templates/viewer.js +41 -0
  90. package/templates/document/ui/texts.d.ts +3 -0
  91. package/templates/document/ui/texts.js +62 -0
  92. package/templates/document/ui/theme.css +69 -0
  93. package/templates/quiz/README.md +16 -12
  94. package/templates/quiz/core/behaviors.d.ts +4 -0
  95. package/templates/quiz/core/behaviors.js +4 -2
  96. package/templates/quiz/core/editor.d.ts +17 -2
  97. package/templates/quiz/core/editor.js +85 -10
  98. package/templates/quiz/core/markdown.d.ts +15 -0
  99. package/templates/quiz/core/markdown.js +164 -4
  100. package/templates/quiz/core/model.d.ts +53 -9
  101. package/templates/quiz/core/model.js +384 -41
  102. package/templates/quiz/core/rich-text.d.ts +1 -2
  103. package/templates/quiz/core/rich-text.js +7 -59
  104. package/templates/quiz/public/img/mascot-half.webp +0 -0
  105. package/templates/quiz/screens/edit.js +403 -126
  106. package/templates/quiz/screens/learn.js +106 -40
  107. package/templates/quiz/styles.css +584 -4
  108. package/templates/quiz/template.json +1 -1
  109. package/templates/quiz/ui/templates/edit.d.ts +3 -0
  110. package/templates/quiz/ui/templates/edit.js +113 -11
  111. package/templates/quiz/ui/templates/page.js +14 -0
  112. package/templates/quiz/ui/templates/question.js +5 -3
  113. package/templates/quiz/ui/texts.js +89 -26
@@ -14,8 +14,15 @@
14
14
  * 실제 SDK처럼 account · result는 null (edit 토큰은 /me를 부르지 않음)
15
15
  * 편집 화면이 넣은 settings.grading은 학생 화면의 material.settings에서 서버처럼 빼고 준다
16
16
  * - 수업 페이지 이동: 아무 데도 가지 않고, 이전·다음 페이지는 없음(false)
17
- * - Files (assets) and the video player: nothing is uploaded. assets.post rejects with request_failed,
18
- * assets.get returns null, videoPlayerUrl and accessToken are null (try them in ecdk dev or LXP)
17
+ * - 자료 파일 (assets.post · get, 실제 SDK와 같은 모양 · 검사 · 오류 코드):
18
+ * ecdk dev 콘텐츠 주소를 직접 열었으면(window.__ECDK_DEV__.assets) 실제 SDK처럼 흉내 서버에 올리고(upload-url → PUT)
19
+ * 서버 모양 키 `assets/{자료 id}/{이름}`을 주며, get은 흉내 API asset_base_url + 키라 다른 화면에서도 열린다.
20
+ * 그 밖(서버 없음)은 이 페이지 메모리에만 둔다 (blob: 주소, 새로고침 · 다른 화면에서는 없음)
21
+ * - 동영상 플레이어: videoPlayerUrl · accessToken은 null (ecdk dev나 LXP에서 시험)
22
+ * - kvstore: settings처럼 이 브라우저에 보는 사람의 값을 최상위 key별로 둔다.
23
+ * 튜터는 쓸 수 없다(read_only_mode). 크기 · 쓰기 횟수 제한은 없음
24
+ * - mlapi (mlapi.fetch): mlapi를 부르지 않고, ecdk dev처럼 서버 오류 모양의 503 SERVICE_UNAVAILABLE
25
+ * (reason ai_not_configured)로 답한다 (AI 호출은 LXP에서 시험)
19
26
  * - 시나리오: 주소에 ?mock=session_expired | rate_limited | request_failed | external_service_error
20
27
  * | slow | content_not_ready | unauthorized | draft_not_ready
21
28
  *
@@ -43,6 +50,7 @@ export const ErrorCode = Object.freeze({
43
50
  FileInvalidSize: 'file_invalid_size',
44
51
  ScriptLoadFailed: 'script_load_failed',
45
52
  ScriptNamespaceNotFound: 'script_namespace_not_found',
53
+ StorageLimitExceeded: 'storage_limit_exceeded',
46
54
  });
47
55
 
48
56
  export class EliceCDKError extends Error {
@@ -54,6 +62,75 @@ export class EliceCDKError extends Error {
54
62
  }
55
63
 
56
64
  const VIEWERS = Object.freeze(['student', 'instructor', 'tutor']);
65
+ /** 자료 파일 한도 (실제 SDK와 같음): 문서 1바이트~95MB, 이미지 1바이트~10MB */
66
+ const MB = 1024 * 1024;
67
+ /** 실제 SDK처럼 파일 형식(MIME), 없으면 확장자로 종류를 정한다. SVG는 받지 않는다 */
68
+ const ASSET_KINDS = Object.freeze([
69
+ { extension: 'pdf', aliases: [], contentType: 'application/pdf', maxBytes: 95 * MB },
70
+ {
71
+ extension: 'pptx',
72
+ aliases: [],
73
+ contentType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
74
+ maxBytes: 95 * MB,
75
+ },
76
+ { extension: 'png', aliases: [], contentType: 'image/png', maxBytes: 10 * MB },
77
+ { extension: 'jpg', aliases: ['jpeg'], contentType: 'image/jpeg', maxBytes: 10 * MB },
78
+ { extension: 'webp', aliases: [], contentType: 'image/webp', maxBytes: 10 * MB },
79
+ { extension: 'gif', aliases: [], contentType: 'image/gif', maxBytes: 10 * MB },
80
+ ]);
81
+ /** mock이 올린 파일: 키 → blob: 주소 (이 페이지 메모리에만) */
82
+ const MOCK_ASSETS = new Map();
83
+ /** 서버 파일 키 모양: `assets/{자료 id}/{이름}.{확장자}` */
84
+ const FILE_KEY = /^assets\/[\w-]+\/[\w-]+\.(pdf|pptx|png|jpe?g|webp|gif)$/i;
85
+
86
+ /**
87
+ * ecdk dev가 알려 준 자료 파일 흉내 주소 (콘텐츠 주소를 직접 열어 mock으로 돌 때). 없으면 null.
88
+ * uploadUrl: 토큰 없이 쓰는 dev 전용 upload-url, baseUrl: 흉내 API의 asset_base_url (서명 경로까지)
89
+ * @returns {{ uploadUrl: string, baseUrl: string } | null}
90
+ */
91
+ function devAssets() {
92
+ const d = globalThis.__ECDK_DEV__?.assets;
93
+ return d && typeof d.uploadUrl === 'string' && typeof d.baseUrl === 'string' ? d : null;
94
+ }
95
+
96
+ /** ecdk dev 흉내 서버에 실제 SDK와 같은 흐름으로 올린다 (upload-url → PUT). 서버 파일 키를 돌려줌 */
97
+ async function uploadToDev(dev, file, kind, onProgress, signal) {
98
+ let target;
99
+ try {
100
+ const res = await fetch(dev.uploadUrl, {
101
+ method: 'POST',
102
+ headers: { 'Content-Type': 'application/json' },
103
+ body: JSON.stringify({
104
+ key: `asset.${kind.extension}`,
105
+ content_length: file.size,
106
+ content_type: kind.contentType,
107
+ }),
108
+ signal,
109
+ });
110
+ if (!res.ok) throw new Error(`upload-url ${res.status}`);
111
+ target = (await res.json())?.data;
112
+ const put = await fetch(target.upload_url, {
113
+ method: 'PUT',
114
+ headers: { 'Content-Type': kind.contentType, 'x-ms-blob-type': 'BlockBlob' },
115
+ body: file,
116
+ signal,
117
+ });
118
+ if (!put.ok) throw new Error(`PUT ${put.status}`);
119
+ } catch (e) {
120
+ if (signal?.aborted) throw signal.reason;
121
+ throw new EliceCDKError(ErrorCode.RequestFailed, 'Failed to upload the file (mock · ecdk dev).', e);
122
+ }
123
+ onProgress?.({ loaded: file.size, total: file.size });
124
+ return target.key;
125
+ }
126
+
127
+ /** 키의 주소: 이 페이지에서 올린 것(blob:), 아니면 ecdk dev 흉내 API asset_base_url + 키. 모르면 null */
128
+ function mockAssetUrl(id) {
129
+ const local = MOCK_ASSETS.get(id);
130
+ if (local) return local;
131
+ const dev = devAssets();
132
+ return dev && typeof id === 'string' && FILE_KEY.test(id) ? `${dev.baseUrl}${id}` : null;
133
+ }
57
134
  const MAX_ANSWER_BYTES = 64 * 1024;
58
135
  const STORE_PREFIX = 'elice-content-mock:';
59
136
  const MESSAGE_SOURCE = 'eliceio-content-sdk';
@@ -64,6 +141,9 @@ const DEFAULT_ENTRIES = Object.freeze({
64
141
  instructor: 'instructor.html',
65
142
  edit: 'edit.html',
66
143
  });
144
+ /** kvstore key: dot path of letters, digits, `_` or Korean, at most 256 characters (get also takes '' for every top-level key) */
145
+ const KV_KEY_PATTERN = /^[0-9A-Za-z_가-힣]+(?:\.[0-9A-Za-z_가-힣]+)*$/;
146
+ const KV_KEY_MAX_LENGTH = 256;
67
147
  /** rubric(AI) 채점 흉내 점수 */
68
148
  const RUBRIC_MOCK_SCORE = 80;
69
149
 
@@ -192,6 +272,36 @@ export function gradeLocally(grading, answer) {
192
272
 
193
273
  const sleep = ms => new Promise(r => setTimeout(r, ms));
194
274
 
275
+ function assertKvKey(key) {
276
+ if (typeof key !== 'string' || key.length > KV_KEY_MAX_LENGTH || !KV_KEY_PATTERN.test(key))
277
+ throw new EliceCDKError(ErrorCode.InvalidParam, `Invalid key "${key}".`);
278
+ }
279
+
280
+ /** Value at the dot path ('' = every top-level key as { key: value }), null when missing */
281
+ function kvRead(doc, key) {
282
+ let value = doc;
283
+ for (const part of key ? key.split('.') : [])
284
+ value = value && typeof value === 'object' && !Array.isArray(value) ? value[part] : undefined;
285
+ return value ?? null;
286
+ }
287
+
288
+ /** New document with the value at the dot path. Like the server, a value on the path that is not an object (null included) is invalid_input */
289
+ function kvWrite(doc, key, value) {
290
+ const stored = JSON.parse(JSON.stringify(value ?? null));
291
+ const next = structuredClone(doc ?? {});
292
+ const parts = key.split('.');
293
+ const last = parts.pop();
294
+ let parent = next;
295
+ for (const part of parts) {
296
+ parent[part] ??= {};
297
+ if (!parent[part] || typeof parent[part] !== 'object' || Array.isArray(parent[part]))
298
+ throw new EliceCDKError(ErrorCode.InvalidInput, `"${part}" on the key path is not an object (mock).`);
299
+ parent = parent[part];
300
+ }
301
+ parent[last] = stored;
302
+ return next;
303
+ }
304
+
195
305
  /**
196
306
  * @typedef {object} MockOptions
197
307
  * @property {() => void} [onSessionExpired]
@@ -222,6 +332,8 @@ export class MockEliceCDK {
222
332
  #draftSubmissions = [];
223
333
  #navigation;
224
334
  #assets;
335
+ #kvstore;
336
+ #mlapi;
225
337
 
226
338
  /** @param {MockOptions} [options] */
227
339
  constructor(options = {}) {
@@ -251,13 +363,97 @@ export class MockEliceCDK {
251
363
  },
252
364
  });
253
365
  this.#assets = Object.freeze({
254
- // There is no storage locally, so nothing is uploaded.
255
- post: async (_file, _options) => {
366
+ post: async (file, { onProgress, signal } = {}) => {
256
367
  this.#assertReady();
257
368
  this.#assertScreen('edit');
258
- throw new EliceCDKError(ErrorCode.RequestFailed, 'Uploads are not available in the mock.');
369
+ if (this.#isDraft)
370
+ throw new EliceCDKError(
371
+ ErrorCode.DraftNotSaved,
372
+ 'Files cannot be uploaded to an unsaved upload (mock).'
373
+ );
374
+ const extension = String(file?.name ?? '').split('.').pop()?.toLowerCase();
375
+ const kind =
376
+ ASSET_KINDS.find((k) => k.contentType === file?.type) ??
377
+ ASSET_KINDS.find((k) => k.extension === extension || k.aliases.includes(extension));
378
+ if (!kind)
379
+ throw new EliceCDKError(
380
+ ErrorCode.FileInvalidType,
381
+ 'Only PDF, PPTX, PNG, JPEG, WebP and GIF files can be uploaded (mock).'
382
+ );
383
+ if (!(file.size >= 1) || file.size > kind.maxBytes)
384
+ throw new EliceCDKError(
385
+ ErrorCode.FileInvalidSize,
386
+ `The file must be between 1 byte and ${kind.maxBytes / MB}MB (mock).`
387
+ );
388
+ if (signal?.aborted) throw signal.reason;
389
+ await this.#delay();
390
+ if (signal?.aborted) throw signal.reason;
391
+ const dev = devAssets();
392
+ let id;
393
+ if (dev) id = await uploadToDev(dev, file, kind, onProgress, signal);
394
+ else {
395
+ // 실제 서버처럼 파일 키 `assets/{자료 id}/{이름}`
396
+ id = `assets/mock/mock-${(MOCK_ASSETS.size + 1).toString(36)}-${Date.now().toString(36)}.${kind.extension}`;
397
+ MOCK_ASSETS.set(id, URL.createObjectURL(file));
398
+ onProgress?.({ loaded: file.size, total: file.size });
399
+ }
400
+ return { id, name: file.name, size: file.size, mime: kind.contentType, url: mockAssetUrl(id) ?? '' };
401
+ },
402
+ get: async (id) => {
403
+ const url = this.initialized ? mockAssetUrl(id) : null;
404
+ return url == null ? null : { id, url };
405
+ },
406
+ });
407
+ // The viewer's values in this material, kept in the browser store ('kv': { key: value })
408
+ this.#kvstore = Object.freeze({
409
+ get: async ({ key }) => {
410
+ this.#assertReady();
411
+ if (key !== '') assertKvKey(key);
412
+ await this.#delay();
413
+ return kvRead(this.#store.get('kv', null) ?? {}, key);
414
+ },
415
+ post: async ({ key, value }) => {
416
+ this.#assertReady();
417
+ assertKvKey(key);
418
+ if (this.#viewer === 'tutor')
419
+ throw new EliceCDKError(ErrorCode.ReadOnlyMode, 'A tutor cannot save values (mock).');
420
+ await this.#delay();
421
+ this.#store.set('kv', kvWrite(this.#store.get('kv', null), key, value));
422
+ },
423
+ delete: async key => {
424
+ this.#assertReady();
425
+ assertKvKey(key);
426
+ if (this.#viewer === 'tutor')
427
+ throw new EliceCDKError(ErrorCode.ReadOnlyMode, 'A tutor cannot delete values (mock).');
428
+ await this.#delay();
429
+ const parts = key.split('.');
430
+ const last = parts.pop();
431
+ const next = structuredClone(this.#store.get('kv', null) ?? {});
432
+ const parent = kvRead(next, parts.join('.'));
433
+ if (parent && typeof parent === 'object' && !Array.isArray(parent)) delete parent[last];
434
+ this.#store.set('kv', next);
435
+ },
436
+ });
437
+
438
+ this.#mlapi = Object.freeze({
439
+ // There is no mlapi locally: answer like a server without AI (503 ai_not_configured).
440
+ fetch: async (_input, _init) => {
441
+ this.#assertReady();
442
+ const message = 'AI calls are not available in the mock. Try them in LXP.';
443
+ return new Response(
444
+ JSON.stringify({
445
+ data: null,
446
+ meta: {
447
+ error: {
448
+ code: 'SERVICE_UNAVAILABLE',
449
+ message,
450
+ details: [{ type: 'app_exception_detail', msg: message, ctx: { reason: 'ai_not_configured' } }],
451
+ },
452
+ },
453
+ }),
454
+ { status: 503, headers: { 'Content-Type': 'application/json' } }
455
+ );
259
456
  },
260
- get: async (_id) => null,
261
457
  });
262
458
  }
263
459
 
@@ -289,10 +485,18 @@ export class MockEliceCDK {
289
485
  get navigation() {
290
486
  return this.#navigation;
291
487
  }
292
- /** Uploads and reads files. The mock uploads nothing and has no files to read. */
488
+ /** 자료 파일 올리기 · 읽기 (위 머리말: ecdk dev 흉내 서버, 아니면 이 페이지 메모리) */
293
489
  get assets() {
294
490
  return this.#assets;
295
491
  }
492
+ /** The viewer's values in this material (get · post · delete), kept in this browser */
493
+ get kvstore() {
494
+ return this.#kvstore;
495
+ }
496
+ /** Calls mlapi. The mock calls nothing and answers 503 ai_not_configured. */
497
+ get mlapi() {
498
+ return this.#mlapi;
499
+ }
296
500
  get accessToken() {
297
501
  return null;
298
502
  }
@@ -485,6 +689,7 @@ export class MockEliceCDK {
485
689
  this.#store.set('settings', {});
486
690
  this.#store.set('submissions', []);
487
691
  this.#store.set('result', null);
692
+ this.#store.set('kv', null);
488
693
  this.#draftSubmissions = [];
489
694
  }
490
695
 
@@ -51,12 +51,61 @@ export interface SubmitOptions<A = unknown> {
51
51
  resultText?: (result: SubmitResult) => string | undefined;
52
52
  /** true면 같은 답도 다시 제출 (기본: 제출한 답 그대로면 버튼을 끄고 "답을 고치면 다시 제출할 수 있어요.") */
53
53
  allowUnchanged?: boolean;
54
+ /**
55
+ * 제출 뒤 스크롤. 'result'(기본): 성공하면 결과 줄을 화면 안으로. 'bottom': 서버 응답(성공 · 실패) 뒤 화면 맨 아래로
56
+ * (다음 프레임, 늦게 들어온 그림이 있으면 한 번 더, 움직임 줄이기 설정이면 바로)
57
+ */
58
+ scrollOnResult?: 'result' | 'bottom';
54
59
  root?: Element;
55
60
  label?: string;
56
61
  }
57
62
 
63
+ export interface UploadFileOptions {
64
+ /** 올린 바이트 / 전체 바이트 */
65
+ onProgress?: (progress: { loaded: number; total: number }) => void;
66
+ /** 취소하면 uploadFile이 AbortError(signal.reason)로 끝난다 */
67
+ signal?: AbortSignal;
68
+ }
69
+
70
+ /** app.assets.uploadImage 결과 */
71
+ export interface UploadedImage {
72
+ /** settings에 넣을 서버 파일 키 */
73
+ asset_key: string;
74
+ /** 올린 파일 크기 (바이트, 줄인 뒤) */
75
+ size: number;
76
+ /** 고른 원본 크기 (바이트) */
77
+ original_size: number;
78
+ /** 올린 그림의 폭 · 높이 (px, GIF는 null) */
79
+ width: number | null;
80
+ height: number | null;
81
+ /** 올린 파일 형식 (image/webp 등) */
82
+ type: string;
83
+ }
84
+
85
+ /** 이미지 올리기 규칙: 서버 한도 10MB, 긴 변 2048px, WebP 품질 0.85, 받는 형식 (SVG 없음) */
86
+ export declare const IMAGE_RULES: Readonly<{
87
+ maxBytes: number;
88
+ maxSide: number;
89
+ quality: number;
90
+ types: ReadonlyArray<string>;
91
+ }>;
92
+
93
+ /**
94
+ * 올리기 전 이미지 줄이기 (uploadImage가 부름): 긴 변 maxSide까지 · WebP(못 만들면 JPEG, 투명할 수 있으면 PNG)로 다시 저장해
95
+ * EXIF · GPS를 뺀다. 더 커지면 원본 (줄여야 하거나 메타데이터가 있으면 제외). GIF는 그대로.
96
+ * 오류 ContentError: upload_bad_type · upload_bad_file · image_unreadable
97
+ */
98
+ export declare function optimizeImage(
99
+ file: File,
100
+ options?: { maxSide?: number; quality?: number },
101
+ ): Promise<{ file: File; width: number | null; height: number | null; optimized: boolean }>;
102
+
58
103
  export interface SaveOptions<C> {
59
- getContent: () => C;
104
+ /**
105
+ * 저장할 내용. 저장 직전에 파일을 올려야 하면(예: 고친 문서) Promise를 돌려준다:
106
+ * 끝날 때까지 버튼을 막고, 던진 오류는 저장 문구("저장하지 못했어요: …")로 보인다
107
+ */
108
+ getContent: () => C | Promise<C>;
60
109
  /**
61
110
  * 같이 저장할 채점 설정 (settings.grading, 학생에게 안 감). 문장이면 저장을 막고 보여 줌,
62
111
  * undefined면 채점 설정은 그대로
@@ -228,6 +277,17 @@ export interface ContentApp<C = Record<string, unknown>> {
228
277
  useStepper(options?: StepperOptions): Stepper;
229
278
  /** useStepper의 옛 이름 (같은 동작) */
230
279
  usePaging(options: StepperOptions): Stepper;
280
+ /**
281
+ * 자료 파일 (PDF · PPTX · 이미지, SDK assets.post · assets.get). uploadFile은 편집 화면에서 올리고 settings에 넣을
282
+ * `{ asset_key }`(SDK가 준 id = 서버 파일 키 `assets/{자료 id}/{이름}` 그대로)를,
283
+ * uploadImage는 이미지(PNG · JPEG · WebP · GIF, 10MB까지)를 optimizeImage로 줄인 뒤 올려 asset_key와 크기를,
284
+ * url은 asset_key의 주소(서명된 asset 경로, 모르면 null)를 Promise로 준다
285
+ */
286
+ assets: {
287
+ uploadFile(file: File, options?: UploadFileOptions): Promise<{ asset_key: string }>;
288
+ uploadImage(file: File, options?: UploadFileOptions): Promise<UploadedImage>;
289
+ url(assetKey: string): Promise<string | null>;
290
+ };
231
291
  /** 편집 화면 저장 영역 */
232
292
  useSave(options: SaveOptions<C>): {
233
293
  element: Element;