@eliceio/cdk-cli 1.3.0 → 1.3.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.
@@ -7,6 +7,11 @@ export declare const LAZY_MIN_BYTES: number;
7
7
  export type ChunkGraph = Map<string, {
8
8
  imports: string[];
9
9
  dynamicImports: string[];
10
+ /**
11
+ * 화면을 열자마자 `import()`로 부르는 chunk (키트 start가 부르는 SDK). 나중에 받는 파일로 내면
12
+ * HTML 머리에 `<link rel="preload" as="script">`를 넣어 CSS와 같이 받게 한다
13
+ */
14
+ startup?: boolean;
10
15
  }>;
11
16
  /** 화면(HTML)마다 열 때 받는 크기와 나중에 받는 파일 */
12
17
  export interface SandboxScreen {
@@ -26,6 +26,9 @@ import { screenSizes, LAZY_FILE_MARK } from '../rules/size.js';
26
26
  * 받아 실행하는 함수(`__ecdk_load`)로 바뀐다. 그래서 문서 화면은 쓰는 쪽(PDF · PPTX)의 라이브러리만 받는다.
27
27
  * - 나중에 받는 chunk는 iife로 묶고, 다른 chunk를 부르는 import는 페이지의 모듈 목록(`__ecdk_lazy`)에서 꺼낸다:
28
28
  * 같은 chunk가 두 번 실행되지 않는다 (화면에 넣은 chunk도 목록에 올려 같은 것을 씀).
29
+ * - 화면을 열자마자 부르는 chunk(`startup`, SDK)는 첫 모듈 스크립트 자리에 `<link rel="preload" as="script">`를 넣는다.
30
+ * 모듈 스크립트는 앞의 CSS를 다 받은 뒤에 실행되므로, 넣지 않으면 CSS → 실행 → SDK 파일 받기가 차례로 걸린다.
31
+ * preload는 crossorigin 없이(no-cors) 넣어 `__ecdk_load`의 `<script src>` 요청과 같은 것으로 쓰인다 (출처 null에서도 됨)
29
32
  * - 안 되는 경우는 나누지 않고 지금처럼 HTML에 다 넣는다 (`SandboxScreen.lazySkipped`): 나중에 받는 chunk에
30
33
  * top-level await가 있음(일반 스크립트로 못 냄) · chunk끼리 서로 부름(순환) · 묶기 실패.
31
34
  */
@@ -302,6 +305,20 @@ function planLazy(entry, graph, byPath) {
302
305
  shared: [...shared].sort()
303
306
  };
304
307
  }
308
+ /**
309
+ * 화면을 열자마자 부르는 나중에 받는 chunk(`startup`)와 그것이 정적 import하는 나중에 받는 chunk를 미리 받는 태그
310
+ * @param page HTML 경로 (하위 폴더면 그만큼 ../)
311
+ */
312
+ function preloadTags(page, plan, graph) {
313
+ const files = new Set();
314
+ const visit = p => {
315
+ if (files.has(p) || !plan.lazy.has(p)) return;
316
+ files.add(p);
317
+ for (const q of graph.get(p)?.imports ?? []) visit(q);
318
+ };
319
+ for (const p of [...plan.lazy].sort()) if (graph.get(p)?.startup) visit(p);
320
+ return [...files].map(p => `<link rel="preload" as="script" href="${upFrom(page) || './'}${p}">\n`).join('');
321
+ }
305
322
  /** HTML의 모듈 스크립트(src)를 묶어 본문으로 넣는다. 바뀐 파일만 새로 만들어 돌려준다 */
306
323
  async function inlineModuleScripts(files, opts = {}) {
307
324
  const byPath = new Map(files.map(f => [f.path, f]));
@@ -361,6 +378,7 @@ async function inlineModuleScripts(files, opts = {}) {
361
378
  }
362
379
  const code = await bundle(entry, f.path, byPath, opts, plan);
363
380
  next += html.slice(last, m.index);
381
+ if (plan && opts.chunks) next += preloadTags(f.path, plan, opts.chunks);
364
382
  if (i === 0) next += jsonPrelude(files, f.path);
365
383
  if (plan) {
366
384
  for (const p of plan.lazy) {
@@ -22,6 +22,8 @@ const ECDK_PLUGIN_NAME = 'ecdk';
22
22
  const MOCK_SDK_FLAG = '__ECDK_MOCK_SDK__';
23
23
  const encoder = new TextEncoder();
24
24
  const decoder = new TextDecoder();
25
+ /** SDK(@eliceio/cdk) 모듈 경로 (npm 설치 · pnpm .pnpm 폴더 · tgz 모두 node_modules/@eliceio/cdk/ 아래) */
26
+ const SDK_MODULE = /[\\/]node_modules[\\/]@eliceio[\\/]cdk[\\/]/;
25
27
  /**
26
28
  * Adds values to metadata.json `build` (also an authored one). Legacy completion-policy fields are dropped from the zip
27
29
  * (completion policy is an LXP setting, ADR 0012; leftovers are reported by manifest.completion-policies-ignored).
@@ -198,7 +200,11 @@ function ecdk(options = {}) {
198
200
  const graph = new Map();
199
201
  for (const item of Object.values(bundle)) if (item.type === 'chunk') graph.set(item.fileName, {
200
202
  imports: item.imports,
201
- dynamicImports: item.dynamicImports
203
+ dynamicImports: item.dynamicImports,
204
+ // 키트 start가 화면을 열자마자 import()하는 SDK: HTML 머리에서 CSS와 같이 미리 받는다 (core/sandbox.ts)
205
+ ...(item.moduleIds.some(id => SDK_MODULE.test(id)) ? {
206
+ startup: true
207
+ } : {})
202
208
  });
203
209
  const sandboxed = await inlineModuleScripts(output, {
204
210
  minify: config.minify !== false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eliceio/cdk-cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "교육자용 Custom HTML 콘텐츠 CLI",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -46,7 +46,7 @@
46
46
  "rollup": "^4.0.0",
47
47
  "tslib": "^2.6.1",
48
48
  "typescript": "~5.9.3",
49
- "@eliceio/cdk": "^1.3.0"
49
+ "@eliceio/cdk": "^1.3.1"
50
50
  },
51
51
  "scripts": {
52
52
  "prebuild": "del-cli \"buildcache/*\" \"es/*\"",
@@ -2,15 +2,15 @@
2
2
 
3
3
  Run `ecdk create --list` first: it prints each template with its own version (`quiz@1.5.0`), what it is for and its screens. Pick the template from that list. `ecdk create` records the template and version in `package.json` `"ecdk"` (`template`), `ecdk build` copies it to `metadata.json` `build.template`, and `ecdk doctor` says when the installed ecdk ships a newer version of that template (nothing changes on its own).
4
4
 
5
- | Case | Start with |
6
- | ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7
- | A quiz (up to 20 questions per quiz material) | `ecdk create <folder>` (quiz template: starts with no question; the edit screen adds questions of any of the five types with "+ 문제 추가"; answers set on the edit screen; `pattern` or `partial_pattern` grading, `on_graded` picked in LXP) |
8
- | Any other material | `ecdk create <folder> --template blank` (three screens with a small example to replace, "예측하고 확인하기", and the kit content editor on the edit screen: see 5) |
9
- | A material in several steps (intro → experiment → summary, slides) | `ecdk create <folder> --template steps` (kit stepper `app.useStepper` and a different content layout per step, example "진자의 주기", content editor on the edit screen: see [14](14-layouts.md)) |
10
- | One document to read (PDF or PPTX, completion on opening) | `ecdk create <folder> --template document` (the edit screen uploads a `.pdf` or `.pptx` and edits PPTX slide text in place; the student screen pages through it; `on_access` picked in LXP; `.ppt` · `.pps` · `.ppsx` must be saved as `.pptx` or `.pdf` first; uploads work in `ecdk dev` only until the server upload API ships) |
11
- | A dark screen | Add `--theme dark` to the above |
12
- | A problem description | Create with blank, set `metadata.json` to `{ "kind": "description", "screens": { "learn": { "enabled": true, "entry": "index.html" } }, "commentary": "commentary.txt" }`, delete the other screen files |
13
- | An existing HTML page | [7. Move existing HTML](07-move-existing-html.md) |
5
+ | Case | Start with |
6
+ | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7
+ | A quiz (up to 20 questions per quiz material) | `ecdk create <folder>` (quiz template: starts with no question; the edit screen adds questions of any of the five types with "+ 문제 추가"; answers set on the edit screen; `pattern` or `partial_pattern` grading, `on_graded` picked in LXP) |
8
+ | Any other material | `ecdk create <folder> --template blank` (three screens with a small example to replace, "예측하고 확인하기", and the kit content editor on the edit screen: see 5) |
9
+ | A material in several steps (intro → experiment → summary, slides) | `ecdk create <folder> --template steps` (kit stepper `app.useStepper` and a different content layout per step, example "진자의 주기", content editor on the edit screen: see [14](14-layouts.md)) |
10
+ | One document to read (PDF or PPTX, completion on opening) | `ecdk create <folder> --template document` (the edit screen uploads a `.pdf` or `.pptx` and edits PPTX slide text in place; the student screen pages through it; `on_access` picked in LXP; `.ppt` · `.pps` · `.ppsx` must be saved as `.pptx` or `.pdf` first; in `ecdk dev` the file stays in `.ecdk/assets/`; for a page on LXP upload it with the MCP `create_asset_upload`, [12](12-upload-with-the-material-mcp.md) "Images and documents") |
11
+ | A dark screen | Add `--theme dark` to the above |
12
+ | A problem description | Create with blank, set `metadata.json` to `{ "kind": "description", "screens": { "learn": { "enabled": true, "entry": "index.html" } }, "commentary": "commentary.txt" }`, delete the other screen files |
13
+ | An existing HTML page | [7. Move existing HTML](07-move-existing-html.md) |
14
14
 
15
15
  `create` refuses a folder that is not empty. Use a new subfolder. It then runs `npm install` in the project (the SDK `@eliceio/cdk` comes from npm through `package.json`; `--no-install` skips it). When the install fails, the project stays: run `npm install` in it (network or proxy problem; tell the user).
16
16
 
@@ -16,13 +16,16 @@
16
16
 
17
17
  - **Writing `.ecdk/settings.json` by hand (answer format tags, ADR 0013)**: put `"answerFormat": 2` and `"requires": { "quiz": "1.10.0" }` at the top level and `"answerMode": "list"` (or `"regex"`) on every text question, and write text answers in the regex **as typed** (escape regex characters, `%` → `%25`, `;` → `%3B`), e.g. `q4=(?:weight|가중치|50%25)`. A regex-mode question stores the author's regex wrapped in `(?:…)`, e.g. `q4=(?:[Aa]pples?|사과)`. Without `answerFormat` the student screen sends `encodeURIComponent` answers, so the regex must use that form instead (`q4=(?:%EA%B0%80%EC%A4%91%EC%B9%98)`); never mix the two. Then save once in the edit view so the edit screen checks and rewrites everything. If a material goes back to a 1.9.x zip, the answers must be saved again on that edit screen (the old screen ignores the tag).
18
18
 
19
- **Adding images** (a picture in a question's `description` or in `explanation.text`, both Markdown). There are two ways:
19
+ **Adding images** (a picture in a question's `description` or in `explanation.text`, both Markdown; the question `title` is plain text, so an image there shows as the raw `![…](…)`). There are two ways:
20
20
 
21
- - **An image in the zip (you can do this).** Save the file as `public/img/<name>` (letters, digits, `-`, `_` and `.` only: the quiz reads only such `img/` paths) and write `![alt](img/<name>)` in the text, with alt text that says what the picture shows. `ecdk build` copies it into the zip **as is** (it does not shrink or convert it); `file.large-image` warns above 1MB (a warning only). Never put an image into the settings as a `data:` address (the old `![…](image:id)` + `images` form is only kept for old quizzes).
22
- - **Prepare the file first, the way the editor's image button does**, so both kinds look the same: longest side 2048px or less, WebP quality about 85 (keep PNG when transparency matters, GIF as is), no EXIF · GPS, well under 1MB. Use the first tool that exists: `cwebp -q 85 -resize <w> 0 -metadata none in.png -o out.webp` (`-resize` only when a side is over 2048) → macOS `sips` (`sips -Z 2048`, then `-s format jpeg` or keep PNG) → ImageMagick `magick in.png -resize '2048x2048>' -strip -quality 85 out.webp` → none of them: ask the person to shrink it, do not add a large original.
23
- - **An image added with the editor's image button (`asset:`).** On the LXP edit screen of a **saved** material only, the image button shrinks the picture in the browser (`app.assets.uploadImage` → `optimizeImage`: longest side 2048px, WebP 0.85, JPEG fallback, PNG kept when it may be transparent, EXIF · GPS dropped, GIF as is, up to 10MB) and stores `![alt](asset:assets/{material id}/{id}.webp)` in the settings. It is refused on the learn and instructor screens (`ScreenNotSupported`), on the edit screen of an upload that is not saved yet (`#edit=1`) and in previews or a `versionId` (`DraftNotSaved`). **You cannot do this**: there is no edit token and the `elice-material` MCP has no image upload tool. Keep every `asset:` reference you find exactly as it is. When the person wants an image added or replaced this way, tell them: open the page's editor → click the question or explanation box → the image button → '초안으로 저장' → '수업 자료에 반영'.
21
+ - **An image uploaded to the page (`asset:`, preferred for a quiz that is on LXP).** It is stored on the server for the page and the text holds `![alt](asset:assets/{material id}/{id}.webp)`: the same as the editor's image button, so the person can replace it in the LXP editor, and it does not grow the zip.
22
+ - **You do it with the `elice-material` MCP** when it lists `create_asset_upload` ([12](12-upload-with-the-material-mcp.md) "Images and documents (`asset:` files)"): prepare the file (below; this path does not shrink it for you), upload it to the confirmed page, and write `![alt](asset:<key>)` with the returned `key` (never the URL), with alt text that says what the picture shows. Merge the page's current settings first and save only after the person's yes.
23
+ - **The person does it with the editor's image button.** On the LXP edit screen of a **saved** material only, the button shrinks the picture in the browser (`app.assets.uploadImage` → `optimizeImage`: longest side 2048px, WebP 0.85, JPEG fallback, PNG kept when it may be transparent, EXIF · GPS dropped, GIF as is, up to 10MB) and stores the `asset:` reference. It is refused on the learn and instructor screens (`ScreenNotSupported`), on the edit screen of an upload that is not saved yet (`#edit=1`) and in previews or a `versionId` (`DraftNotSaved`). Tell them: open the page's editor → click the question or explanation box → the image button → '초안으로 저장' → '수업 자료에 반영'.
24
+ - Keep every `asset:` reference you find exactly as it is. `ecdk dev` cannot show a server image.
25
+ - **An image in the zip (`img/`).** For a project not uploaded yet (no LXP page), or when the MCP has no `create_asset_upload` (tell the person). Save the file as `public/img/<name>` (letters, digits, `-`, `_` and `.` only: the quiz reads only such `img/` paths) and write `![alt](img/<name>)` in the text, with alt text that says what the picture shows. `ecdk build` copies it into the zip **as is** (it does not shrink or convert it); `file.large-image` warns above 1MB (a warning only). Never put an image into the settings as a `data:` address (the old `![…](image:id)` + `images` form is only kept for old quizzes).
26
+ - **Prepare the file first, the way the editor's image button does** (both ways above), so every image looks the same: longest side 2048px or less, WebP quality about 85 (keep PNG when transparency matters, GIF as is), no EXIF · GPS, well under 1MB. Use the first tool that exists: `cwebp -q 85 -resize <w> 0 -metadata none in.png -o out.webp` (`-resize` only when a side is over 2048) → macOS `sips` (`sips -Z 2048`, then `-s format jpeg` or keep PNG) → ImageMagick `magick in.png -resize '2048x2048>' -strip -quality 85 out.webp` → none of them: ask the person to shrink it, do not add a large original.
24
27
  - **Display size**: there is no setting for it today. An image fills the card width (`.qz-image`, `max-width: 100%`). Say so; never add CSS for one file path in `styles.css` (it breaks when the image changes). The only way now is to crop or resize the source file.
25
- - **A quiz that is already on LXP**: before adding a zip image, merge the page's current settings into `.ecdk/settings.json` ([12](12-upload-with-the-material-mcp.md) "Content and answers (settings)", item 8), so the upload does not wipe what was edited in LXP.
28
+ - **A quiz that is already on LXP**: before adding an image either way, merge the page's current settings into `.ecdk/settings.json` ([12](12-upload-with-the-material-mcp.md) "Content and answers (settings)", item 8), so the upload does not wipe what was edited in LXP.
26
29
 
27
30
  - File split: **`ui/` is the look** (edit freely), **`screens/` is the layout** (which blocks in which order), **`core/` is behavior and the grading contract** (do not edit).
28
31
  - Colors, spacing, corners, choice cards: the `--qz-*` variables in `ui/theme.css` (they point at EDS tokens, so `--theme dark` also fits)
@@ -26,7 +26,7 @@ Read `check.issues[]` (`id` · `level` · `path` · `line` · `message`) from `e
26
26
  | `project.quiz` (doctor, quiz template) | The saved questions, answers or points do not pass the quiz edit screen's own checks (run with the project's `core/model.js`): answers or scores left in the old question order, `points` ≠ `scores`, an answer pointing at a deleted option, a missing `gradingType`, a regex the edit screen cannot read (a text answer in the wrong shape for the project's template version), quiz 1.10.0+: a regex answer not in the stored shape or with a blocked syntax, an answer regex over 500 characters, `answerFormat` · `requires` · `answerMode` the project's template does not know, text answers that look as typed (or a regex question) but `answerFormat` is missing, `answerFormat` 2 with URL-encoded text answers (saved again by a 1.9.x edit screen) - for these two, students typing 한글, spaces or `%` are marked wrong: have the person press "초안으로 저장" once in the edit view and the answers are saved again in the right shape. A warning (`warn`): tags written in snake_case (`answer_format` · `answer_mode`). Fix as [15](15-edit-settings-by-hand.md) says, run `ecdk doctor` again, then have the person save once in the edit view ("초안으로 저장") |
27
27
  | `build.template-unknown` (warn) | The material was made with a template or template version this ecdk does not know. Update ecdk (`npm i -g @eliceio/cdk-cli`) or check `template` in `package.json` `"ecdk"` |
28
28
  | `manifest.*` · `entry.*` | Check `screens` and `kind` in `metadata.json` |
29
- | `limit.*` · `file.large-image` | Shrink images and video, drop unused files (build output: "files not referenced anywhere") |
29
+ | `limit.*` · `file.large-image` | Shrink images (longest side 2048px, WebP 85, [6](06-using-the-quiz-template.md) "Adding images") and video, drop unused files (build output: "files not referenced anywhere") |
30
30
  | `sdk.lib-copy` (error, project only) | An SDK copy `lib/cdk.js` in the project (never put in the zip): `ecdk doctor --fix`, `npm install`, replace the kit `lib/elice-content.js` with a new `ecdk create` one, delete `lib/cdk.js` |
31
31
 
32
32
  Use `ecdk-ignore`, which turns a rule off, only for legitimate code a regular expression cannot tell apart, and **always with the reason**. Do not scatter it to silence errors.
@@ -18,6 +18,7 @@ The `elice-material` MCP server (elice-material backend) uploads a built zip to
18
18
  | Upload URL | `create_package_upload` (`size_bytes`) | At most 20 MB. Returns `key` and `curl_command` |
19
19
  | Upload | the `curl_command`, `package.zip` replaced by the zip path | From a desktop app, run it through a login shell (see Always) |
20
20
  | Draft | `submit_package` (`key`) → `get_draft` every 2–3 s | `ready`: shows `preview_urls`, `warnings`, the package metadata. `failed`: report `failure` with `ecdk validate dist/content.zip` and stop |
21
+ | Files (optional) | `create_asset_upload` (`extension`, `size_bytes`) → its `curl_command`, per file | Images for quiz text, the PDF/PPTX of the document template. Only after the draft is `ready`. Put the returned `key` (never the URL) into the settings. See "Images and documents (`asset:` files)" below |
21
22
  | Approve | — | Show page, title, whether content and answers go with it (the summary, no answer values), the completion policy to set (below), `preview_urls`. Saving is visible to learners at once when the page is open |
22
23
  | Save | `save_draft` (`material_draft_id`, `expected_current_version_id`, `payload`) | One save carries everything, so no extra version is made. `payload` holds only the keys to set, each only when the tool's schema lists it: `settings` and `completion_policy` when the person said yes (below; `on_graded` only together with `settings` that include `grading`), and `title` · `icon` when the page has none (a new page). `MATERIAL_CHANGED`: someone saved after your `get_material`; do not retry blindly, tell the person |
23
24
  | Check | `get_material` (or `get_draft` before saving) | When settings were sent: the saved settings have the same top-level keys and item count and `grading.type` as the summary. When a policy was sent: it shows that policy. Show any `warnings` in the result to the person. If not as sent, tell the person and use the fallback |
@@ -42,7 +43,20 @@ Next time, read it, confirm the page with the person as above (기관 · 과목
42
43
  5. **Summary and an explicit yes.** Before the upload, show what goes with it: the title, the number of questions or items, and whether answers are included (`grading.type`, `pattern`, `partial_pattern` or `rubric`; for `partial_pattern` also the number of questions and the scores), but never the answer values (`answer_key`, `rubric`). **Settings reach every viewer, students included: never send settings that hold a learner's personal data** (names, contact details, student numbers …; 2 "Personal data"). The answers must be ones the person confirmed (Always: ask before you settle correct answers). Send it only after an explicit yes; a no means the fallback.
43
44
  6. **Send** it as `payload.settings` with the save (`save_draft` above), with the completion policy the person agreed to (below). Then check it with `get_material` (or `get_draft` when the draft shows it before saving) as in the table.
44
45
  7. **No settings file?** Suggest filling the edit view in `ecdk dev` first and saving, so the upload carries it, or skip it (the person enters the content in the LXP edit screen later).
45
- 8. **Adding images to a page that already has a version.** Read the page's current settings first (`get_material`, or `get_draft` for a draft not saved yet) and merge them into the local `.ecdk/settings.json` before you change anything: `settings` replaces the whole object, so skipping this overwrites what was edited in the LXP editor, including `asset:` images people added there (keep those references exactly as they are). Then add the zip image (6 "Adding images"), `ecdk build`, and upload as usual: `create_package_upload` → the `curl_command` → `submit_package` → `get_draft` until ready → show the person → `save_draft` with the merged settings only after their yes (items 3–6 still apply).
46
+ 8. **Adding images to a page that already has a version.** Read the page's current settings first (`get_material`, or `get_draft` for a draft not saved yet) and merge them into the local `.ecdk/settings.json` before you change anything: `settings` replaces the whole object, so skipping this overwrites what was edited in the LXP editor, including `asset:` images people added there (keep those references exactly as they are). Then, when the MCP lists `create_asset_upload`, upload the image as an `asset:` file ("Images and documents" below; no new zip needed: `update_material` with the merged settings after the person's yes). Only when it does not: add a zip image (6 "Adding images"), `ecdk build`, and upload as usual: `create_package_upload` → the `curl_command` → `submit_package` → `get_draft` until ready → show the person → `save_draft` with the merged settings only after their yes (items 3–6 still apply).
47
+
48
+ **Images and documents (`asset:` files)**
49
+
50
+ `create_asset_upload` gives a signed upload URL for one file stored on the server for this page, the same place the LXP editor's image and file buttons use. The settings then point at the file by its `key`, so it stays editable in the LXP editor and does not grow the zip.
51
+
52
+ - **When.** Images in quiz text (a question's `description`, `explanation.text`: `![alt](asset:<key>)`, never `title`, which is plain text; 6 "Adding images"), and the PDF or PPTX of the document template (`settings.document`). Files the screen code loads itself still go in the zip.
53
+ - **Is the tool there?** Use it only when the MCP lists `create_asset_upload`. If not (an older server), tell the person and fall back: a quiz image goes in the zip as `img/` (6 "Adding images"); a document is uploaded by the person on the LXP edit screen (the file button, then '수업 자료에 반영').
54
+ - **Types and limits.** `extension`: `png` · `jpg` · `jpeg` · `webp` · `gif` (at most 10 MB) or `pdf` · `pptx` (at most 95 MB); no SVG, no `.ppt` (save as `.pptx` or `.pdf` first). `size_bytes` is the exact file size (`wc -c < file`). Above the limit the tool answers `MATERIAL_PACKAGE_TOO_LARGE` with the limit. **Shrink an image first** (6 "Adding images": longest side 2048px or less, WebP about 85, EXIF · GPS stripped): this path does not run the editor's in-browser `optimizeImage`.
55
+ - **Order.** Confirm the target page first (above). With a new zip: build → `create_package_upload` → the `curl_command` → `submit_package` → `get_draft` until `ready` → then, per file, `create_asset_upload` → its `curl_command` (replace `asset.<extension>` with the file's path; from a desktop app through a login shell) → put the key into the settings → show the person → `save_draft` with the merged settings after their yes. Never call it before the new draft is ready: the file's folder follows the ready draft's package (a copied page uses its source's folder until then), so an earlier key can point where the new version does not read. Without a new zip (the page already has a version): `get_material` → `create_asset_upload` → the `curl_command` → `update_material` with the merged settings after the person's yes.
56
+ - **The key, not the URL.** Put the returned `key` (`assets/{material id}/{id}.{ext}`) into the settings exactly as returned; never the upload URL or any signed address (it expires and carries a signature). Quiz: `![alt](asset:<key>)` in the Markdown, with alt text that says what the picture shows. Document template: `settings.document = { "asset_key": <key>, "name": <file name>, "size": <bytes>, "type": "pdf" | "pptx", "pages": <page count, or 0 if unknown> }` (`templates/document/core/settings.js`).
57
+ - **Files uploaded in `ecdk dev` are local.** A key under `assets/00000000-0000-4000-8000-0000000000e1/` in `.ecdk/settings.json` (quiz `asset:` images, `settings.document.asset_key`) points to `.ecdk/assets/<same file name>` on this PC and does not exist on LXP. Before sending such settings, upload each of those files with `create_asset_upload` (after the draft is `ready`) and replace the local key with the returned one everywhere it appears. Never send a local key; if the tool is missing, tell the person the files must be added again in the LXP edit screen.
58
+ - **Merge, then show.** `settings` replaces the whole object: start from the page's current settings (`get_material`, or `get_draft` before the first save), keep every `asset:` reference already there exactly as it is, add the new keys, and write the result to `.ecdk/settings.json` as well. Before saving, show the person which file goes where (question number or the document, file name, size after shrinking, alt text) and wait for a yes. The draft preview does not show these settings before the save, and `ecdk dev` cannot show a server file: check on the LXP page after saving.
59
+ - **Nothing changes until a save.** An uploaded file that no saved settings point at is unused; there is no MCP tool to delete it. If the person says no, do not save.
46
60
 
47
61
  **Fallback (the server has no `settings`, the person said no, or there is no file)**: upload the zip only, without content or `grading`, and without `on_graded` (see "Completion policy"). After saving, tell the person to open the LXP edit page, enter the content and answers on the edit screen (`settings`, with `settings.grading` for `on_graded`) and save with the edit screen's own button (the quiz template: "초안으로 저장"). That saves to the draft; learners see it only after '수업 자료에 반영' at the top of the LXP edit page.
48
62
 
@@ -77,6 +91,7 @@ The completion policy is not in the project or the zip (ADR 0012): it is a setti
77
91
  | `MATERIAL_CHANGED` | Someone saved after your `get_material`. Do not retry blindly; tell the person |
78
92
  | `MATERIAL_GRADING_REQUIRED` | `on_graded` without `grading`. Stop and tell the person |
79
93
  | `MATERIAL_DRAFT_PENDING` (`update_material`) | Someone uploaded a package to this page and did not save it: a ready draft holds a package different from the current version. Nothing changed. Stop, explain it, and ask whether to save that draft (`save_draft`, which publishes their upload) or discard it (`discard_draft`). Never pick for the person |
94
+ | `MATERIAL_PACKAGE_TOO_LARGE` (`create_asset_upload`) | The file is above its limit (images 10 MB, PDF · PPTX 95 MB). Shrink the image (6 "Adding images") or ask the person for a smaller document |
80
95
  | `PACKAGE_TOO_LARGE` | Over 20 MB |
81
96
  | An error about `settings` (for example `INVALID_INPUT`, a bad `settings.grading` pattern or rubric, `partial_pattern` scores summing to less than 100) | Nothing was saved: report it, and save without settings (the fallback) only after the person agrees |
82
97
  | `warnings` in a tool result | Show them to the person close to word for word (for example `settings.grading` sent while the policy is not `on_graded`). No `warnings` key means none |
@@ -16,7 +16,7 @@ Reference files are in `references/` in this skill's folder (see Always). For th
16
16
  2. **Sort the request.**
17
17
  - Content, answers, points or grading → `.ecdk/settings.json`, keeping every id.
18
18
  - Wording or look of the screens → `ui/` (quiz: `ui/texts.js`, `ui/theme.css`, `ui/templates/`) and `screens/`.
19
- - An image in a question or explanation → `references/06-using-the-quiz-template.md` "Adding images": a zip image in `public/img/` you prepare, `asset:` images only the person adds in the LXP editor, no size setting.
19
+ - An image in a question or explanation → `references/06-using-the-quiz-template.md` "Adding images": for a quiz on LXP an `asset:` image you upload with the MCP `create_asset_upload` (or the person adds with the editor's image button), otherwise a zip image in `public/img/`; prepare it first, no size setting.
20
20
  - Something the template does not do (for example a text answer that ignores upper case or spaces, a new question type, a new grading rule) → never edit `core/` or `lib/` to add it (Always). Offer what works now (for a text answer: list each spelling the person wants to accept as its own accepted answer; with quiz 1.10.0 or later also a regex answer, `answerMode: "regex"`, if the person picks it) and, if that is not enough, tell the person it is a feature request for the template.
21
21
  3. **Ask first** about any value the person decides that the request does not spell out (Always): points or their split, correct or accepted answers (also when translating: the translated answers), a question's title or wording beyond what was asked. Say what you would set and wait for a yes; change only what the request names.
22
22
  4. **Change it** as `references/15-edit-settings-by-hand.md` says: keep question, option and group ids; when you delete or reorder questions, `grading.answer_key` and `grading.scores` move with them; build answer regexes with the project's `core/model.js` (its script), never by hand. The text answer shape follows the project's quiz template version: from 1.10.0 the edit screen writes `answerFormat: 2` · `requires`, keeps text answers as typed and may have regex questions (`answerMode`) with their own rules (reference 15, "Regex answers"); older projects keep URL-encoded text answers and must not get `answerFormat`, `requires` or `answerMode`.
@@ -16,7 +16,7 @@ Reference files are in `references/` in this skill's folder (see Always). Read `
16
16
  3. **Content and answers.** Check whether the input schema of `save_draft` (or `update_material`) lists `settings` as a key of `payload` (on an older server, a top-level parameter). If it does and this project has `.ecdk/settings.json`: make sure the edit screen saved it (the person saves the edit view in `ecdk dev`; a file you wrote by hand must go through that save), run `ecdk doctor` and send no `settings` while its `project.grading` or `project.quiz` check fails (tell the person why, never the answer values; they fix it in the edit view), show a short summary (title, number of questions or items, answers included or not and `grading.type`, never the answer values) and ask for an explicit yes to send it with the upload. `settings` replaces the page's settings as a whole: on a page that already has a version, compare `get_material`'s settings with the file first, and if keys would disappear or the LXP content differs (an instructor edited it in LXP), show the difference briefly and ask before overwriting (a new page needs no comparison). Adding images to a page that already has a version: merge its current settings (`get_material` or `get_draft`) into `.ecdk/settings.json` first, keeping `asset:` images as they are (`references/12-upload-with-the-material-mcp.md` item 8). No file: suggest filling the edit view in `ecdk dev` first, or skip it. No `settings` key, or the person says no: zip only (the fallback). Details: `references/12-upload-with-the-material-mcp.md` "Content and answers (settings)".
17
17
  4. **Completion policy.** If `save_draft` (or `update_material`) lists `completion_policy` in its input schema (in `payload`), propose one (`references/12-upload-with-the-material-mcp.md` "Completion policy"): graded (the quiz template, or settings with `grading`) → `on_graded`, submits without grading → `on_submit`, no submission → `on_access`. `on_graded` only when the same save carries `settings` with `grading` (or the page already has grading); otherwise no policy at the first save, or `on_submit` if the person wants it (ask). Tell the person that only `on_graded` grades: `on_submit` completes on any submission without grading ("제출했어요."), `on_access` completes on open. The policy is a page setting and applies at once.
18
18
  5. **Pick the page and confirm it.** Candidates: `.ecdk/link.json`, the LXP edit URL the person gives (`https://{org}.…/lecturepages/{id}/edit`), or the person's choice from `list_my_organizations` → `list_courses` → `list_lectures` → `list_custom_pages`. Never pick a page yourself (not the first in a list, not a guess by title, not a page from another project); if the answer is ambiguous, ask again. Before any upload call (`create_package_upload`, `submit_package`), show the full target, 기관 · 과목 · 수업 · 페이지 with names and ids, its LXP edit URL, whether content and answers go with it and the completion policy to set (the page's current one too), then wait for an explicit yes. Do this every time: also for `.ecdk/link.json` (and compare its `version_id` with `get_material`) and for a URL the person gave (confirm the names it resolves to). `.ecdk/link.json` and an edit URL give only the org's `name_short`: get the 기관 name from `list_my_organizations` and the 과목 · 수업 · 페이지 names from `get_material`. A new page (`create_custom_page`) needs its own yes that names the 수업 it goes into. If the page already has content or answers saved in LXP, say that sending settings replaces them and ask again.
19
- 6. **Upload.** `get_material` (keep `current_version.id`) → `create_package_upload` with `size_bytes = zipBytes` → run its `curl_command` with `package.zip` replaced by the zip path → `submit_package` → poll `get_draft` until ready or failed. On failure, report the server's reason with `ecdk validate dist/content.zip` and stop.
19
+ 6. **Upload.** `get_material` (keep `current_version.id`) → `create_package_upload` with `size_bytes = zipBytes` → run its `curl_command` with `package.zip` replaced by the zip path → `submit_package` → poll `get_draft` until ready or failed. On failure, report the server's reason with `ecdk validate dist/content.zip` and stop. Images or a PDF/PPTX for the settings: only now (draft ready), `create_asset_upload` per file → its `curl_command`, and put the returned `key`, never the URL, into the merged settings (`references/12-upload-with-the-material-mcp.md` "Images and documents"); no such tool: zip images, and tell the person.
20
20
  7. **Approve.** Show what changes (page, title, whether the content and answers go with it or are entered on the LXP edit screen after saving, the completion policy) and the draft `preview_urls`. Saving is visible to learners at once if the page is open. Wait for an explicit yes.
21
21
  8. **Save.** One `save_draft` with `material_draft_id`, `expected_current_version_id` and `payload` holding only keys its schema lists: `settings` (the content of `.ecdk/settings.json`) only when step 3 got a yes, `completion_policy` only when step 4 got a yes, and `title` · `icon` when the page has none (a new page; icon: `references/12-upload-with-the-material-mcp.md` "Icon"), all in this one save so no extra version is made. On `MATERIAL_CHANGED` or `MATERIAL_GRADING_REQUIRED`, stop and tell the person (`references/12-upload-with-the-material-mcp.md` "Errors and warnings").
22
22
  9. **Check.** Show any `warnings` in the result to the person close to word for word. `get_material` must show what was sent: the settings (same keys, item count and `grading.type` as the summary), the completion policy, the title. If not, tell the person and use the fallback. Without settings: tell the person to enter the content and answers in the LXP edit screen, save with its own button, then press '수업 자료에 반영' at the top of the LXP edit page (`references/12-upload-with-the-material-mcp.md` "Fallback"); for a graded material, then pick 답안 확인 후 완료 in the '설정' panel at the top of the LXP edit page, or offer to set `on_graded` with `update_material` (when it takes `completion_policy`) once `get_material` shows the grading. No `completion_policy` key: tell the person which policy to pick in that '설정' panel. `update_material` stopping with `MATERIAL_DRAFT_PENDING`: someone's upload is not saved; explain and ask whether to save it (`save_draft`) or discard it (`discard_draft`), never pick for them.
@@ -6,6 +6,7 @@ export declare class FetchError extends Error {
6
6
  constructor(message: string, status: number);
7
7
  }
8
8
  export declare function fetchBytes(url: string, fetchImpl?: typeof fetch): Promise<Uint8Array>;
9
+ export declare function preloadViewer(kind: 'pdf' | 'pptx'): void;
9
10
  export declare function openDocument(
10
11
  kind: 'pdf' | 'pptx',
11
12
  source: Uint8Array | string,
@@ -1,5 +1,6 @@
1
1
  // 문서 불러오기 (고치지 않습니다): 저장된 주소에서 파일 바이트를 받고, 종류에 맞는 그리기 모듈로 엽니다.
2
2
  // PDF · PPTX 모듈은 필요할 때만 불러온다 (import()): 둘 다 묶여 들어가지만 쓰지 않는 쪽은 실행하지 않는다.
3
+ // 화면은 문서 종류를 알면 preloadViewer로 미리 부르고, openDocument는 PPTX 파일 받기와 모듈 불러오기를 같이 한다 (차례로 기다리지 않게).
3
4
 
4
5
  /** 파일을 받지 못함 (주소 · 권한 · 콘텐츠 CSP connect-src) */
5
6
  export class FetchError extends Error {
@@ -28,13 +29,39 @@ export async function fetchBytes(url, fetchImpl = globalThis.fetch) {
28
29
  return new Uint8Array(await res.arrayBuffer());
29
30
  }
30
31
 
32
+ /** @type {Partial<Record<'pdf' | 'pptx', Promise<any>>>} 불러오는 중이거나 불러온 그리기 모듈 (실패하면 지워 다음에 다시 시도) */
33
+ const viewers = {};
34
+
35
+ /** @param {'pdf' | 'pptx'} kind */
36
+ function viewerModule(kind) {
37
+ viewers[kind] ??= (kind === 'pdf' ? import('./pdf.js') : import('./pptx-view.js')).catch((e) => {
38
+ delete viewers[kind];
39
+ throw e;
40
+ });
41
+ return viewers[kind];
42
+ }
43
+
44
+ /**
45
+ * 그리기 모듈을 미리 불러 둔다 (문서 종류를 안 순간, 주소를 받기 전에). PDF는 pdf.js 작업자도 미리 띄운다.
46
+ * 실패는 여기서 삼킨다: openDocument가 다시 불러 그 오류를 낸다. 문서가 없으면 부르지 않는다 (그리기 코드를 받지 않게)
47
+ * @param {'pdf' | 'pptx'} kind
48
+ */
49
+ export function preloadViewer(kind) {
50
+ viewerModule(kind)
51
+ .then((m) => m.preparePdf?.())
52
+ .catch(() => undefined);
53
+ }
54
+
31
55
  /**
32
56
  * @param {'pdf' | 'pptx'} kind
33
57
  * @param {Uint8Array | string} source 바이트, 또는 주소 (PDF는 pdf.js가 Range로 필요한 부분만 받음, PPTX는 전체를 받음)
34
58
  * @param {{ prefetch?: boolean }} [opts] PDF 주소: 첫 쪽 뒤 나머지를 미리 받기 (편집 화면, core/pdf-options.js)
35
59
  */
36
60
  export async function openDocument(kind, source, opts) {
37
- if (kind === 'pdf') return (await import('./pdf.js')).openPdf(source, opts);
61
+ const viewer = viewerModule(kind);
62
+ if (kind === 'pdf') return (await viewer).openPdf(source, opts);
63
+ // PPTX: 파일 받기와 그리기 모듈 불러오기를 같이 한다. 둘 다 실패하면 받기 오류(FetchError)를 먼저 낸다
64
+ viewer.catch(() => undefined);
38
65
  const bytes = typeof source === 'string' ? await fetchBytes(source) : source;
39
- return (await import('./pptx-view.js')).openPptx(bytes);
66
+ return (await viewer).openPptx(bytes);
40
67
  }
@@ -10,3 +10,4 @@ export declare function openPdf(
10
10
  source: Uint8Array | string,
11
11
  opts?: { prefetch?: boolean }
12
12
  ): Promise<OpenedDocument>;
13
+ export declare function preparePdf(): Promise<void>;
@@ -71,6 +71,11 @@ function ensureWorker() {
71
71
  return worker;
72
72
  }
73
73
 
74
+ /** 작업자를 미리 띄운다 (core/load.js preloadViewer). 실패해도 openPdf가 다시 시도하고 그 오류를 낸다 */
75
+ export function preparePdf() {
76
+ return ensureWorker().catch(() => undefined);
77
+ }
78
+
74
79
  /** PDF를 여는(첫 응답 · 쪽 크기) 데 이 시간보다 오래 걸리면 멈춘 것으로 보고 오류 */
75
80
  const OPEN_TIMEOUT_MS = 30000;
76
81
 
@@ -17,7 +17,7 @@ import {
17
17
  DOCUMENT_MIME,
18
18
  SNIFF_BYTES,
19
19
  } from '../core/file-type.js';
20
- import { fetchBytes, openDocument } from '../core/load.js';
20
+ import { fetchBytes, openDocument, preloadViewer } from '../core/load.js';
21
21
  import {
22
22
  formatBytes,
23
23
  MAX_DOCUMENT_BYTES,
@@ -371,8 +371,9 @@ function showDocument(doc, startAt) {
371
371
  state.refit = () => {
372
372
  if (state.view === view && pageMaxHeight(view) !== fit) void state.viewer.refresh();
373
373
  };
374
- // 쪽 목록은 큰 쪽을 그린 뒤 브라우저가 한가할 때 (긴 문서에서 첫 화면이 늦지 않게)
375
- afterIdle(() => doc.thumbnails(120))
374
+ // 쪽 목록은 큰 쪽(첫 쪽)을 다 그린 뒤 브라우저가 한가할 때 (긴 문서에서 첫 화면이 늦지 않게)
375
+ state.viewer.ready
376
+ .then(() => afterIdle(() => doc.thumbnails(120)))
376
377
  .then(images => {
377
378
  if (state.doc !== doc) return;
378
379
  state.thumbs = images;
@@ -534,6 +535,8 @@ async function getContent() {
534
535
  // ---------- 처음 그리기: 저장된 문서가 있으면 받아서 연다 ----------
535
536
  // 함수 안에서 연다: 모듈 맨 위(top-level await)에서 받은 바이트 · 문서는 다른 파일로 바꾼 뒤에도 놓이지 않았다
536
537
  async function openSaved() {
538
+ // 그리기 모듈은 주소 · 파일을 받는 동안 미리 불러 둔다
539
+ preloadViewer(draft.document.type);
537
540
  // 문서를 받는 동안: 글 없이 16:9 미리보기 자리만 (문구는 화면 읽기 프로그램에만)
538
541
  previewArea.replaceChildren(loading('edit', { label: tv.loading, parts: ['media'] }));
539
542
  // 받는 동안 다른 파일을 골라 보이면 그 파일을 둔다 (늦게 끝난 이 문서는 버림). 고른 파일을 열지 못했으면 이 문서를 보인다
@@ -2,7 +2,7 @@
2
2
  // 완료 정책은 LXP 설정 '열람 시 학습 완료'(on_access)라 이 화면은 제출하지 않습니다 (LXP가 열면 완료로 기록).
3
3
  // 모양은 ui/(templates · texts · theme.css), 동작은 core/에 있습니다.
4
4
  import { start } from '../lib/elice-content.js';
5
- import { FetchError, openDocument } from '../core/load.js';
5
+ import { FetchError, openDocument, preloadViewer } from '../core/load.js';
6
6
  import { isExpiredSource } from '../core/pdf-options.js';
7
7
  import { normalizeSettings } from '../core/settings.js';
8
8
  import { part } from '../core/dom.js';
@@ -32,6 +32,8 @@ function isLoadError(e) {
32
32
  }
33
33
 
34
34
  async function show(file) {
35
+ // 그리기 모듈(PPTX 1.4MB · pdf.js)은 주소를 받는 동안 미리 불러 둔다
36
+ preloadViewer(file.type);
35
37
  // 문서를 받는 동안: 글 없이 화면 가득 빛이 지나가는 자리 (문구는 화면 읽기 프로그램에만)
36
38
  root.replaceChildren(loading('learn', { label: t.loading }));
37
39
  // 서명된 asset 주소 = 버전의 asset_base_url + 파일 키 asset_key(assets/{자료 id}/…) (SDK assets.get이 만듦). PDF는 pdf.js가 Range로 필요한 부분만 받는다
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "title": "문서 (PDF · PPT)",
5
5
  "description": "PDF, PPT 문서를 올립니다",
6
6
  "catalog": {