@eliceio/cdk-cli 1.2.1 → 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.
Files changed (169) hide show
  1. package/README.md +63 -53
  2. package/es/cli.js +11 -2
  3. package/es/commands/build/index.js +12 -0
  4. package/es/commands/create/index.js +2 -0
  5. package/es/commands/create/scaffold.d.ts +2 -2
  6. package/es/commands/create/scaffold.js +3 -3
  7. package/es/commands/dev/index.d.ts +10 -1
  8. package/es/commands/dev/index.js +47 -7
  9. package/es/commands/doctor/index.js +6 -2
  10. package/es/core/config.d.ts +42 -9
  11. package/es/core/config.js +217 -12
  12. package/es/core/project-check.d.ts +3 -2
  13. package/es/core/project-check.js +14 -3
  14. package/es/core/regex.d.ts +11 -0
  15. package/es/core/regex.js +41 -0
  16. package/es/core/sandbox.d.ts +26 -0
  17. package/es/core/sandbox.js +240 -30
  18. package/es/dev/assets.d.ts +80 -0
  19. package/es/dev/assets.js +240 -0
  20. package/es/dev/check.d.ts +30 -0
  21. package/es/dev/check.js +224 -34
  22. package/es/dev/grading.d.ts +49 -14
  23. package/es/dev/grading.js +109 -29
  24. package/es/dev/host-page.js +27 -3
  25. package/es/dev/inject.d.ts +2 -1
  26. package/es/dev/inject.js +10 -2
  27. package/es/dev/mock-api.d.ts +26 -3
  28. package/es/dev/mock-api.js +219 -40
  29. package/es/dev/server.d.ts +12 -1
  30. package/es/dev/server.js +115 -9
  31. package/es/engines/vite/index.js +1 -1
  32. package/es/engines/vite/plugin.d.ts +2 -0
  33. package/es/engines/vite/plugin.js +33 -5
  34. package/es/rules/answers.d.ts +13 -0
  35. package/es/rules/answers.js +94 -0
  36. package/es/rules/check.js +70 -1
  37. package/es/rules/index.d.ts +1 -0
  38. package/es/rules/index.js +1 -0
  39. package/es/rules/size.d.ts +31 -0
  40. package/es/rules/size.js +58 -0
  41. package/es/rules/types.d.ts +12 -0
  42. package/es/rules.json.js +2 -2
  43. package/package.json +2 -2
  44. package/rules.json +34 -5
  45. package/skills/_shared/always.md +3 -3
  46. package/skills/_shared/references/00-what-the-person-decides.md +1 -1
  47. package/skills/_shared/references/02-design-the-material.md +10 -7
  48. package/skills/_shared/references/03-create-the-project.md +10 -8
  49. package/skills/_shared/references/04-rules.md +1 -1
  50. package/skills/_shared/references/05-screen-code.md +52 -23
  51. package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
  52. package/skills/_shared/references/08-fix-check-errors.md +23 -22
  53. package/skills/_shared/references/09-check.md +8 -6
  54. package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
  55. package/skills/_shared/references/13-edit-screen-design.md +122 -0
  56. package/skills/_shared/references/14-layouts.md +96 -0
  57. package/skills/elice-content-check/SKILL.md +2 -2
  58. package/skills/elice-content-create/SKILL.md +1 -1
  59. package/skills/elice-content-migrate/SKILL.md +1 -1
  60. package/skills/elice-content-publish/SKILL.md +1 -1
  61. package/templates/_shared/lib/cdk-mock.d.ts +47 -3
  62. package/templates/_shared/lib/cdk-mock.js +293 -15
  63. package/templates/_shared/lib/elice-content-editor.js +89 -58
  64. package/templates/_shared/lib/elice-content.css +1313 -126
  65. package/templates/_shared/lib/elice-content.d.ts +222 -23
  66. package/templates/_shared/lib/elice-content.js +1176 -88
  67. package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
  68. package/templates/_shared/lib/icons/empty-content.js +11 -0
  69. package/templates/_shared/lib/icons/file-video.d.ts +2 -0
  70. package/templates/_shared/lib/icons/file-video.js +11 -0
  71. package/templates/_shared/lib/icons/file.d.ts +2 -0
  72. package/templates/_shared/lib/icons/file.js +11 -0
  73. package/templates/blank/README.md +6 -4
  74. package/templates/blank/edit.html +8 -2
  75. package/templates/blank/index.html +6 -1
  76. package/templates/blank/instructor.html +6 -1
  77. package/templates/blank/screens/instructor.js +8 -2
  78. package/templates/blank/screens/learn.js +1 -1
  79. package/templates/blank/template.json +1 -1
  80. package/templates/document/README.md +92 -0
  81. package/templates/document/commentary.txt +2 -0
  82. package/templates/document/core/dom.d.ts +13 -0
  83. package/templates/document/core/dom.js +83 -0
  84. package/templates/document/core/file-type.d.ts +21 -0
  85. package/templates/document/core/file-type.js +85 -0
  86. package/templates/document/core/group-3d.d.ts +20 -0
  87. package/templates/document/core/group-3d.js +256 -0
  88. package/templates/document/core/inline-edit.d.ts +15 -0
  89. package/templates/document/core/inline-edit.js +377 -0
  90. package/templates/document/core/load.d.ts +13 -0
  91. package/templates/document/core/load.js +40 -0
  92. package/templates/document/core/pdf-options.d.ts +9 -0
  93. package/templates/document/core/pdf-options.js +36 -0
  94. package/templates/document/core/pdf-worker.d.ts +24 -0
  95. package/templates/document/core/pdf-worker.js +122 -0
  96. package/templates/document/core/pdf.d.ts +12 -0
  97. package/templates/document/core/pdf.js +190 -0
  98. package/templates/document/core/pptx-edit.d.ts +14 -0
  99. package/templates/document/core/pptx-edit.js +137 -0
  100. package/templates/document/core/pptx-fonts.d.ts +5 -0
  101. package/templates/document/core/pptx-fonts.js +115 -0
  102. package/templates/document/core/pptx-media.d.ts +18 -0
  103. package/templates/document/core/pptx-media.js +83 -0
  104. package/templates/document/core/pptx-view.d.ts +5 -0
  105. package/templates/document/core/pptx-view.js +185 -0
  106. package/templates/document/core/settings.d.ts +25 -0
  107. package/templates/document/core/settings.js +86 -0
  108. package/templates/document/core/slide-edges.d.ts +3 -0
  109. package/templates/document/core/slide-edges.js +82 -0
  110. package/templates/document/core/viewer.d.ts +28 -0
  111. package/templates/document/core/viewer.js +159 -0
  112. package/templates/document/edit.html +17 -0
  113. package/templates/document/gitignore +4 -0
  114. package/templates/document/index.html +18 -0
  115. package/templates/document/metadata.json +9 -0
  116. package/templates/document/package.json +17 -0
  117. package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
  118. package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
  119. package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
  120. package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
  121. package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
  122. package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
  123. package/templates/document/screens/edit.js +574 -0
  124. package/templates/document/screens/learn.js +61 -0
  125. package/templates/document/styles.css +644 -0
  126. package/templates/document/template.json +6 -0
  127. package/templates/document/ui/templates/edit.js +82 -0
  128. package/templates/document/ui/templates/page.js +11 -0
  129. package/templates/document/ui/templates/viewer.js +41 -0
  130. package/templates/document/ui/texts.d.ts +3 -0
  131. package/templates/document/ui/texts.js +62 -0
  132. package/templates/document/ui/theme.css +69 -0
  133. package/templates/quiz/README.md +32 -14
  134. package/templates/quiz/core/behaviors.d.ts +17 -7
  135. package/templates/quiz/core/behaviors.js +40 -53
  136. package/templates/quiz/core/editor.d.ts +27 -2
  137. package/templates/quiz/core/editor.js +412 -11
  138. package/templates/quiz/core/markdown.d.ts +19 -0
  139. package/templates/quiz/core/markdown.js +225 -11
  140. package/templates/quiz/core/model.d.ts +40 -3
  141. package/templates/quiz/core/model.js +112 -5
  142. package/templates/quiz/core/rich-text.d.ts +18 -0
  143. package/templates/quiz/core/rich-text.js +469 -0
  144. package/templates/quiz/edit.html +12 -3
  145. package/templates/quiz/index.html +12 -3
  146. package/templates/quiz/public/img/mascot-half.webp +0 -0
  147. package/templates/quiz/screens/edit.js +331 -49
  148. package/templates/quiz/screens/learn.js +147 -15
  149. package/templates/quiz/styles.css +1244 -622
  150. package/templates/quiz/template.json +9 -2
  151. package/templates/quiz/ui/templates/edit.d.ts +19 -5
  152. package/templates/quiz/ui/templates/edit.js +371 -77
  153. package/templates/quiz/ui/templates/group.js +19 -8
  154. package/templates/quiz/ui/templates/order.js +25 -24
  155. package/templates/quiz/ui/templates/page.js +33 -8
  156. package/templates/quiz/ui/templates/question.js +6 -4
  157. package/templates/quiz/ui/texts.js +91 -26
  158. package/templates/quiz/ui/theme.css +8 -9
  159. package/templates/steps/README.md +77 -0
  160. package/templates/steps/commentary.txt +7 -0
  161. package/templates/steps/edit.html +21 -0
  162. package/templates/steps/gitignore +4 -0
  163. package/templates/steps/index.html +69 -0
  164. package/templates/steps/metadata.json +9 -0
  165. package/templates/steps/package.json +13 -0
  166. package/templates/steps/screens/edit.js +32 -0
  167. package/templates/steps/screens/learn.js +108 -0
  168. package/templates/steps/styles.css +54 -0
  169. package/templates/steps/template.json +6 -0
@@ -0,0 +1,115 @@
1
+ /*! 슬라이드 글꼴 (zip의 fonts/, SIL Open Font License 1.1, 원본 파일 그대로):
2
+ Carlito 5.3.0 (npm @fontsource/carlito, fonts/OFL-Carlito.txt), Caladea 5.3.0 (npm @fontsource/caladea, fonts/OFL-Caladea.txt) */
3
+ // PPTX 슬라이드 글꼴 (고치지 않습니다). 슬라이드가 쓰는 글꼴이 이 PC에 없을 때 비슷한 글꼴로 그린다:
4
+ // - Calibri → Carlito, Cambria → Caladea (글자 폭이 같은 대체 글꼴: 줄바꿈 · 위치가 PowerPoint와 같게).
5
+ // 넣은 것은 보통 · 굵게의 latin 범위뿐 (기울임은 브라우저가 기울여 그리고, 그 밖 글자는 이 PC 글꼴로)
6
+ // - 한글은 넣지 않고 이 PC 글꼴로: 고딕은 맑은 고딕 · Apple SD Gothic Neo · Noto Sans KR, 명조 글꼴(Cambria 등) 안 한글은
7
+ // 바탕 · AppleMyungjo · Noto Serif KR (한글 글꼴은 용량이 커서 넣지 않음)
8
+ // 렌더러는 run마다 글꼴 목록을 적는데(예: "Calibri, Aptos, …, system-ui, 等线, …"), 한글이 목록 중간의 system-ui나
9
+ // 중국어 글꼴로 먼저 가므로 첫 글꼴 바로 뒤에 대체 글꼴과 한글 글꼴 이름을 넣는다 (slideFontFamily).
10
+ // 이 PC에 진짜 Calibri가 있으면 목록 앞이라 그것을 쓴다. @font-face는 쓰일 때만 받는다 (렌더러 fontFaces 옵션은 바로 받음).
11
+
12
+ /** Carlito · Caladea latin 범위 (fontsource unicode.json) */
13
+ const LATIN_RANGE =
14
+ 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD';
15
+ /** [family, 파일, weight] */
16
+ const LATIN_FACES = [
17
+ ['Carlito', 'carlito-latin-400-normal.woff2', 400],
18
+ ['Carlito', 'carlito-latin-700-normal.woff2', 700],
19
+ ['Caladea', 'caladea-latin-400-normal.woff2', 400],
20
+ ['Caladea', 'caladea-latin-700-normal.woff2', 700],
21
+ ];
22
+
23
+ /** 글자 폭이 같은 대체 글꼴 */
24
+ const SUBSTITUTES = { calibri: 'Carlito', cambria: 'Caladea' };
25
+ /** 명조 계열 글꼴 (그 run 안 한글을 명조로) */
26
+ const SERIF = new Set([
27
+ 'cambria',
28
+ 'georgia',
29
+ 'times new roman',
30
+ 'times',
31
+ 'garamond',
32
+ 'book antiqua',
33
+ 'palatino linotype',
34
+ 'palatino',
35
+ 'constantia',
36
+ 'century',
37
+ 'century schoolbook',
38
+ 'baskerville old face',
39
+ 'bodoni mt',
40
+ 'batang',
41
+ '바탕',
42
+ '바탕체',
43
+ 'batangche',
44
+ 'gungsuh',
45
+ '궁서',
46
+ 'serif',
47
+ ]);
48
+ /** 이 PC의 한글 글꼴 (이름만, 넣지 않음) */
49
+ const SANS_KO = ['맑은 고딕', 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR'];
50
+ const SERIF_KO = ['바탕', 'Batang', 'AppleMyungjo', 'Noto Serif KR'];
51
+
52
+ /** font-family 값을 글꼴 이름 목록으로 (따옴표 · 쉼표) */
53
+ function splitFamilies(value) {
54
+ const out = [];
55
+ for (const m of value.matchAll(
56
+ /\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^,]+))\s*(?:,|$)/g
57
+ )) {
58
+ const name = (m[1] ?? m[2] ?? m[3] ?? '').trim();
59
+ if (name) out.push(name);
60
+ }
61
+ return out;
62
+ }
63
+ const quote = name => (/^[a-z-]+$/i.test(name) ? name : `"${name.replace(/"/g, '\\"')}"`);
64
+
65
+ /**
66
+ * 렌더러가 적은 글꼴 목록에 대체 · 한글 글꼴을 넣은 목록. 첫 글꼴(파일의 글꼴) 바로 뒤에 넣는다 (두 번 해도 같음)
67
+ * @param {string} value CSS font-family
68
+ */
69
+ export function slideFontFamily(value) {
70
+ const names = splitFamilies(value);
71
+ if (names.length === 0) return value;
72
+ const first = names[0];
73
+ const key = first.toLowerCase();
74
+ const sub = SUBSTITUTES[key];
75
+ const added = [...(sub ? [sub] : []), ...(SERIF.has(key) ? SERIF_KO : SANS_KO)].filter(
76
+ n => n.toLowerCase() !== key
77
+ );
78
+ const lower = new Set(added.map(n => n.toLowerCase()));
79
+ const rest = names.slice(1).filter(n => !lower.has(n.toLowerCase()));
80
+ return [first, ...added, ...rest].map(quote).join(', ');
81
+ }
82
+
83
+ /**
84
+ * 그린 슬라이드의 글자 요소마다 글꼴 목록을 바꾼다 (렌더러가 쓰는 style · SVG font-family 속성)
85
+ * @param {Element} root
86
+ */
87
+ export function applySlideFonts(root) {
88
+ const els = [root, ...root.querySelectorAll('[style*="font-family"], [font-family]')];
89
+ for (const el of els) {
90
+ const style = /** @type {HTMLElement} */ (el).style;
91
+ if (style?.fontFamily) style.fontFamily = slideFontFamily(style.fontFamily);
92
+ const attr = el.getAttribute('font-family');
93
+ if (attr) el.setAttribute('font-family', slideFontFamily(attr));
94
+ }
95
+ }
96
+
97
+ /** @font-face 규칙 (글꼴 파일은 문서 기준 fonts/: zip 최상위, 원본 public/fonts/) */
98
+ export function fontFaceCss(base = 'fonts/') {
99
+ return LATIN_FACES.map(
100
+ ([family, file, weight]) =>
101
+ `@font-face{font-family:${family};font-style:normal;font-weight:${weight};font-display:swap;` +
102
+ `src:url(${base}${file}) format("woff2");unicode-range:${LATIN_RANGE}}`
103
+ ).join('\n');
104
+ }
105
+
106
+ let installed = false;
107
+ /** 글꼴 규칙을 문서에 한 번 넣는다 (PPTX를 열 때만: PDF · 다른 화면은 받지 않음) */
108
+ export function installSlideFonts(doc = document) {
109
+ if (installed || !doc?.head) return;
110
+ installed = true;
111
+ const style = doc.createElement('style');
112
+ style.dataset.dcPptxFonts = '';
113
+ style.textContent = fontFaceCss();
114
+ doc.head.append(style);
115
+ }
@@ -0,0 +1,18 @@
1
+ // core/pptx-media.js 타입 (편집기 자동완성 · 테스트용)
2
+ export declare function shapeFillRelIds(xml: string): string[];
3
+ export declare function shapeFillTargets(
4
+ files: { slides: Map<string, string>; slideLayouts: Map<string, string>; slideMasters: Map<string, string> },
5
+ pres: {
6
+ slides: Array<{
7
+ slidePath: string;
8
+ layoutIndex: string;
9
+ rels: Map<string, { target: string; targetMode?: string }>;
10
+ showMasterSp?: boolean;
11
+ }>;
12
+ layouts: Map<string, { rels: Map<string, { target: string; targetMode?: string }>; showMasterSp?: boolean }>;
13
+ masters: Map<string, { rels: Map<string, { target: string; targetMode?: string }> }>;
14
+ layoutToMaster: Map<string, string>;
15
+ },
16
+ i: number,
17
+ cache: Map<string, string[]>
18
+ ): string[];
@@ -0,0 +1,83 @@
1
+ // 슬라이드를 그리기 전에 미리 읽어 둘 그림 (고치지 않습니다). core/pptx-view.js가 부릅니다.
2
+ //
3
+ // 그림은 그 슬라이드를 그릴 때 읽는다(parseZipLazyMedia). 그런데 @aiden0z/pptx-renderer 1.4.0은 도형 그림 채우기
4
+ // (p:spPr의 a:blipFill)를 그릴 때 그림을 이미 읽었는지만 보고(동기), 아직이면 그림을 나중에 기본 채우기(p:style fillRef) 밑에
5
+ // 넣어 그림이 가려진다. 그래서 그 슬라이드 · 레이아웃 · 마스터의 도형 그림 채우기가 가리키는 그림만 그리기 전에 읽어 둔다.
6
+ // 배경 · 글자 그림 채우기 · 그림(p:pic)은 렌더러가 읽은 뒤 제자리에 넣으므로 미리 읽지 않는다 (첫 쪽이 늦지 않게).
7
+
8
+ /**
9
+ * 슬라이드 XML에서 도형 그림 채우기(spPr > blipFill > blip)의 관계 id (r:embed · r:link)
10
+ * @param {string} xml slide · slideLayout · slideMaster XML
11
+ * @returns {string[]}
12
+ */
13
+ export function shapeFillRelIds(xml) {
14
+ // 빠른 확인: blipFill이 없으면 XML을 읽지 않는다
15
+ if (!xml || !xml.includes('blipFill')) return [];
16
+ const doc = new DOMParser().parseFromString(xml, 'application/xml');
17
+ const ids = new Set();
18
+ // 접두어(a: · r:)는 파일마다 다를 수 있어 이름 끝(localName)으로 찾는다
19
+ for (const fill of doc.getElementsByTagName('*')) {
20
+ if (fill.localName !== 'blipFill' || fill.parentElement?.localName !== 'spPr') continue;
21
+ const blip = [...fill.children].find(c => c.localName === 'blip');
22
+ const attrs = blip ? [...blip.attributes] : [];
23
+ const ref = name => attrs.find(a => a.name.split(':').pop() === name)?.value;
24
+ const id = ref('embed') || ref('link');
25
+ if (id) ids.add(id);
26
+ }
27
+ return [...ids];
28
+ }
29
+
30
+ /**
31
+ * i번째 슬라이드를 그리기 전에 읽어 둘 그림 주소 (관계 target, 파일 안의 것만). 슬라이드 · 레이아웃 · 마스터 순.
32
+ * 레이아웃 · 마스터 결과는 cache에 둔다 (여러 슬라이드가 같이 씀)
33
+ * @param {{ slides: Map<string, string>, slideLayouts: Map<string, string>, slideMasters: Map<string, string> }} files parseZipLazyMedia 결과
34
+ * @param {{ slides: Array<{ slidePath: string, layoutIndex: string, rels: Map<string, { target: string, targetMode?: string }>, showMasterSp?: boolean }>, layouts: Map<string, { rels: Map<string, { target: string, targetMode?: string }>, showMasterSp?: boolean }>, masters: Map<string, { rels: Map<string, { target: string, targetMode?: string }> }>, layoutToMaster: Map<string, string> }} pres
35
+ * @param {number} i
36
+ * @param {Map<string, string[]>} cache
37
+ * @returns {string[]}
38
+ */
39
+ export function shapeFillTargets(files, pres, i, cache) {
40
+ const slide = pres.slides[i];
41
+ if (!slide) return [];
42
+ const parts = [
43
+ {
44
+ path: slide.slidePath,
45
+ xml: files.slides.get(slide.slidePath),
46
+ rels: slide.rels,
47
+ shared: false,
48
+ },
49
+ ];
50
+ const layout = pres.layouts.get(slide.layoutIndex);
51
+ if (layout) {
52
+ parts.push({
53
+ path: slide.layoutIndex,
54
+ xml: files.slideLayouts.get(slide.layoutIndex),
55
+ rels: layout.rels,
56
+ shared: true,
57
+ });
58
+ const masterPath = pres.layoutToMaster.get(slide.layoutIndex);
59
+ const master = masterPath ? pres.masters.get(masterPath) : undefined;
60
+ // 마스터 도형을 감춘 슬라이드 · 레이아웃이면 마스터 그림은 읽지 않는다
61
+ if (master && slide.showMasterSp !== false && layout.showMasterSp !== false)
62
+ parts.push({
63
+ path: masterPath,
64
+ xml: files.slideMasters.get(masterPath),
65
+ rels: master.rels,
66
+ shared: true,
67
+ });
68
+ }
69
+ const targets = new Set();
70
+ for (const part of parts) {
71
+ let list = part.shared ? cache.get(part.path) : undefined;
72
+ if (!list) {
73
+ list = [];
74
+ for (const id of shapeFillRelIds(part.xml ?? '')) {
75
+ const rel = part.rels?.get(id);
76
+ if (rel?.target && rel.targetMode?.trim().toLowerCase() !== 'external') list.push(rel.target);
77
+ }
78
+ if (part.shared) cache.set(part.path, list);
79
+ }
80
+ for (const t of list) targets.add(t);
81
+ }
82
+ return [...targets];
83
+ }
@@ -0,0 +1,5 @@
1
+ // core/pptx-view.js 타입 (편집기 자동완성 · 테스트용)
2
+ import type { OpenedDocument } from './pdf.js';
3
+
4
+ export declare const BASE_WIDTH: number;
5
+ export declare function openPptx(bytes: Uint8Array): Promise<OpenedDocument>;
@@ -0,0 +1,185 @@
1
+ // PPTX 그리기 (고치지 않습니다). @aiden0z/pptx-renderer로 슬라이드를 HTML로 그립니다 (학생 · 편집 화면 공통).
2
+ //
3
+ // 슬라이드는 파일의 크기(px, 10인치 = 960px)로 한 번 그리고, 화면 맞춤은 바깥에서 CSS transform으로 줄이고 늘린다
4
+ // (다시 그리지 않음). 뷰어에 알리는 쪽 크기는 기준 폭(BASE_WIDTH) 기준. 편집 화면은 슬라이드 위 글자 상자를 파일 좌표로 찾는다
5
+ // (core/inline-edit.js, 그린 슬라이드 맨 위 요소에 data-dc-slide). 키트 글꼴 설정이 슬라이드 글자에 스며들지 않게
6
+ // styles.css .dc-pptx가 글꼴 · 굵기 · 자간 · 줄 간격을 되돌리고, 없는 글꼴은 core/pptx-fonts.js가 대체 글꼴로 잇는다.
7
+ import {
8
+ buildPresentation,
9
+ parseZipLazyMedia,
10
+ renderSlide,
11
+ RECOMMENDED_ZIP_LIMITS,
12
+ } from '@aiden0z/pptx-renderer';
13
+
14
+ import { createGroupCameras } from './group-3d.js';
15
+ import { applySlideFonts, installSlideFonts } from './pptx-fonts.js';
16
+ import { shapeFillTargets } from './pptx-media.js';
17
+ import { snapSlideEdges } from './slide-edges.js';
18
+
19
+ /** 뷰어에 알리는 쪽 폭 (px). 슬라이드 크기와 상관없이 같은 값이라 화면 맞춤 배율이 파일마다 같다 */
20
+ export const BASE_WIDTH = 960;
21
+
22
+ /**
23
+ * 압축 풀기 한도. 권장값(RECOMMENDED_ZIP_LIMITS)은 파일 하나 32MB까지라, 올릴 수 있는 크기(95MB) 안의 큰 그림 · 동영상이
24
+ * 든 자료를 열지 못한다. 한 파일 · 전체 한도만 올리고 압축 폭탄 막기는 그대로 둔다
25
+ */
26
+ const ZIP_LIMITS = {
27
+ ...RECOMMENDED_ZIP_LIMITS,
28
+ maxEntryUncompressedBytes: 128 * 1024 * 1024,
29
+ maxTotalUncompressedBytes: 512 * 1024 * 1024,
30
+ maxMediaBytes: 384 * 1024 * 1024,
31
+ };
32
+
33
+ /**
34
+ * 파일 크기(px)의 슬라이드를 담을 틀. transform으로 줄이고 늘린다
35
+ * @param {{ width: number, height: number }} pres
36
+ */
37
+ function slideHost(pres) {
38
+ const host = document.createElement('div');
39
+ host.className = 'dc-pptx';
40
+ host.style.width = `${pres.width}px`;
41
+ host.style.height = `${pres.height}px`;
42
+ return host;
43
+ }
44
+
45
+ /**
46
+ * PPTX 바이트를 연다. 문서 뷰어(core/viewer.js)가 쓰는 모양으로 돌려준다
47
+ * @param {Uint8Array} bytes
48
+ */
49
+ export async function openPptx(bytes) {
50
+ // 바이트가 버퍼 전체면 복사하지 않고 그대로 (큰 파일에서 같은 크기를 또 들고 있지 않게).
51
+ // 그림 · 슬라이드 내용은 그 슬라이드를 그릴 때 읽는다 (첫 쪽이 빨리 뜨고, 학생 화면은 본 쪽만 읽음)
52
+ const whole = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength;
53
+ const files = await parseZipLazyMedia(
54
+ whole
55
+ ? bytes.buffer
56
+ : bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),
57
+ ZIP_LIMITS
58
+ );
59
+ let pres = buildPresentation(files, { lazySlides: true });
60
+ const count = pres.slides.length;
61
+ if (!count || !(pres.width > 0) || !(pres.height > 0))
62
+ throw new Error('슬라이드를 읽지 못했습니다.');
63
+ const size = { width: BASE_WIDTH, height: Math.round((BASE_WIDTH * pres.height) / pres.width) };
64
+ // 그림 주소(blob:)는 큰 쪽 · 쪽 목록이 같이 쓴다. 닫을 때(destroy) 모두 놓는다
65
+ const media = new Map();
66
+ /** 레이아웃 · 마스터마다 미리 읽을 그림 주소 (core/pptx-media.js) */
67
+ const fillTargets = new Map();
68
+ /**
69
+ * i번째 슬라이드 · 레이아웃 · 마스터의 도형 그림 채우기 그림을 읽어 둔다. 렌더러는 도형 그림 채우기를 그릴 때 읽은 그림만 보고,
70
+ * 아직이면 기본 채우기 밑에 그림을 넣어 가린다 (@aiden0z/pptx-renderer 1.4.0). 읽은 그림은 pres.media에 남아 다음에는 바로 끝난다
71
+ */
72
+ const preload = async i => {
73
+ const resolver = pres?.mediaResolver;
74
+ if (!resolver) return;
75
+ const targets = shapeFillTargets(files, pres, i, fillTargets);
76
+ // 못 읽은 그림은 렌더러가 그릴 때처럼 빈 채로 둔다
77
+ await Promise.all(targets.map(t => resolver.resolve(t).catch(() => undefined)));
78
+ };
79
+ const options = {
80
+ mediaUrlCache: media,
81
+ // 콘텐츠 CSP가 바깥 주소를 막는다: 요청하지 않는다. PDF 미리보기가 든 EMF 그림은 그리지 않음 (pdf.js 작업자를 따로 띄우지 않게)
82
+ externalMedia: 'block',
83
+ pdfjs: false,
84
+ onNodeError: (id, e) => console.warn('[document] 슬라이드 요소를 그리지 못했습니다', id, e),
85
+ };
86
+ // 이 PC에 없는 글꼴은 넣어 둔 대체 글꼴로 (core/pptx-fonts.js, 쓰인 글자 조각만 받음)
87
+ installSlideFonts();
88
+ // 렌더러가 평면으로 그린 3D 카메라 그룹(isometric*)을 원본 XML의 카메라로 눕힌다 (core/group-3d.js)
89
+ const cameras = createGroupCameras(files);
90
+ /** 슬라이드 하나를 그린다. 맨 위 요소에 data-dc-slide (글자 상자 찾기 기준). 글꼴 목록은 렌더러가 글자를 재기 전에 바꾼다 */
91
+ const draw = i => {
92
+ const handle = renderSlide(pres, pres.slides[i], options);
93
+ handle.element.dataset.dcSlide = String(i);
94
+ // 슬라이드보다 1px 미만 작은 배경 도형을 가장자리까지 (오른쪽 · 아래 끝에 흰 줄이 비치지 않게)
95
+ snapSlideEdges(handle.element);
96
+ cameras.apply(handle.element, pres.slides[i].slidePath);
97
+ applySlideFonts(handle.element);
98
+ return handle;
99
+ };
100
+ const host = slideHost(pres);
101
+ let shown = -1;
102
+ let current = null;
103
+ /** 마지막으로 부른 render 차례. 그림을 읽는 사이 다른 쪽을 부르면 앞 차례는 그리지 않는다 */
104
+ let turn = 0;
105
+ const thumbs = new Set();
106
+ return {
107
+ kind: 'pptx',
108
+ count,
109
+ /** 배율 1의 크기 (기준 폭) */
110
+ pageSize: () => size,
111
+ /**
112
+ * i번째 슬라이드를 target에 그린다. 같은 쪽이면 다시 그리지 않고 배율만 (편집 화면이 고친 글자가 그대로 남음)
113
+ * @param {number} i
114
+ * @param {HTMLElement} target
115
+ * @param {number} scale
116
+ */
117
+ async render(i, target, scale) {
118
+ if (!pres) return false;
119
+ const mine = ++turn;
120
+ if (i !== shown) {
121
+ await preload(i);
122
+ if (!pres || mine !== turn) return false;
123
+ }
124
+ const frame = target.firstElementChild?.classList.contains('dc-pptx-frame')
125
+ ? target.firstElementChild
126
+ : Object.assign(document.createElement('div'), { className: 'dc-pptx-frame' });
127
+ frame.style.width = `${size.width * scale}px`;
128
+ frame.style.height = `${size.height * scale}px`;
129
+ host.style.transform = `scale(${(scale * BASE_WIDTH) / pres.width})`;
130
+ // 차트는 다음 화면 그리기(requestAnimationFrame) 때 문서에 붙어 있어야 그려진다: 그린 차례에 바로 붙인다
131
+ if (host.parentElement !== frame) frame.replaceChildren(host);
132
+ if (frame.parentElement !== target) target.replaceChildren(frame);
133
+ if (i !== shown) {
134
+ const next = draw(i);
135
+ current?.dispose();
136
+ current = next;
137
+ host.replaceChildren(next.element);
138
+ shown = i;
139
+ }
140
+ return true;
141
+ },
142
+ /**
143
+ * 모든 슬라이드를 작게 그린 것 (편집 화면 왼쪽 목록). 폭 width(px). 파일 크기로 그리고 transform으로 줄인다
144
+ * (작은 크기로 그리면 글자 줄바꿈이 달라짐). 큰 쪽과 같은 좌표라 고친 글자를 그대로 옮긴다.
145
+ * 모두 한 번에 그린다: 차트는 다음 화면 그리기 전에 화면 코드가 목록에 붙여야 그려진다
146
+ * @param {number} width
147
+ * @returns {Promise<HTMLElement[]>}
148
+ */
149
+ async thumbnails(width) {
150
+ if (!pres) return [];
151
+ const k = width / pres.width;
152
+ const images = [];
153
+ // 도형 그림 채우기 그림을 먼저 모두 읽고, 그리기는 기다리지 않고 한 번에 (차트 때문에)
154
+ for (let i = 0; i < count; i += 1) await preload(i);
155
+ if (!pres) return [];
156
+ for (let i = 0; i < count; i += 1) {
157
+ const handle = draw(i);
158
+ thumbs.add(handle);
159
+ const box = document.createElement('div');
160
+ box.className = 'dc-pptx-thumb';
161
+ box.style.width = `${width}px`;
162
+ box.style.height = `${pres.height * k}px`;
163
+ const inner = slideHost(pres);
164
+ inner.style.transform = `scale(${k})`;
165
+ inner.append(handle.element);
166
+ box.append(inner);
167
+ images.push(box);
168
+ }
169
+ return images;
170
+ },
171
+ /** 닫기: 그린 슬라이드 · 차트를 비우고 그림 주소(blob:)와 읽은 내용을 놓는다 (큰 파일이 메모리에 남지 않게) */
172
+ destroy() {
173
+ current?.dispose();
174
+ current = null;
175
+ for (const handle of thumbs) handle.dispose();
176
+ thumbs.clear();
177
+ for (const url of media.values()) URL.revokeObjectURL(url);
178
+ media.clear();
179
+ fillTargets.clear();
180
+ pres = null;
181
+ host.replaceChildren();
182
+ host.remove();
183
+ },
184
+ };
185
+ }
@@ -0,0 +1,25 @@
1
+ // core/settings.js 타입 (편집기 자동완성 · 테스트용)
2
+ import type { DocumentKind } from './file-type.js';
3
+
4
+ export interface DocumentFile {
5
+ /** 서버가 준 파일 키 `assets/{자료 id}/{id}.{ext}` (예전 SDK는 이름 `{id}.{ext}`만, 지금 SDK는 열지 않음). 주소는 SDK assets.get이 만듦 (키트 app.assets.url) */
6
+ asset_key: string;
7
+ name: string;
8
+ size: number;
9
+ type: DocumentKind;
10
+ /** 쪽(PDF) · 슬라이드(PPTX) 수 */
11
+ pages: number;
12
+ }
13
+ export interface Draft {
14
+ title: string;
15
+ document: DocumentFile | null;
16
+ }
17
+ export declare const MAX_DOCUMENT_BYTES: number;
18
+ export declare function normalizeSettings(raw: unknown): Draft;
19
+ export declare function toSettings(draft: Draft): { title?: string; document?: DocumentFile };
20
+ export declare function validateSettings(
21
+ draft: Draft,
22
+ messages: { noDocument: string; uploading: string },
23
+ state?: { uploading?: boolean }
24
+ ): true | string;
25
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,86 @@
1
+ // 저장 내용(settings)의 모양 · 기본값 · 검증 (고치지 않습니다). 학생 · 편집 화면이 모두 여기를 거칩니다.
2
+ //
3
+ // settings = {
4
+ // title?: string,
5
+ // document: { asset_key, name, size, type, pages }, // app.assets.uploadFile 결과 + 보일 정보(이름 · 크기 · 종류 · 쪽 수)
6
+ // }
7
+ //
8
+ // 서버 스펙: 편집 화면이 POST /storage/upload-url로 받은 주소에 파일을 PUT하고, settings에는 asset_key만 있으면 된다.
9
+ // asset_key는 서버가 준 파일 키(assets/{자료 id}/{id}.{ext}) 그대로. 보기는 await app.assets.url(asset_key) (버전의 asset_base_url + 파일 키). name · size · pages는 편집 화면 파일 줄에 보이려고 둔다.
10
+ // type은 MIME이 아니라 종류('pdf' · 'pptx')입니다 (화면이 고를 뷰어). PPTX를 편집 화면에서 고치면 고친 파일을
11
+ // 같은 흐름으로 새로 올려 asset_key를 바꿉니다 (글자 차이를 settings에 따로 두지 않음).
12
+ // SDK는 서버 응답 키를 camelCase로 바꿔 주므로 읽을 때는 assetKey도 받는다 (저장할 때는 asset_key).
13
+ // settings는 학생에게도 내려가므로 비밀 값을 넣지 않습니다. 채점 설정(grading)은 없습니다: 완료 정책은
14
+ // LXP 설정 '열람 시 학습 완료'(on_access)라 학생 화면은 제출하지 않습니다.
15
+ import { kindOf } from './file-type.js';
16
+
17
+ /** 문서 파일 최대 크기 (바이트). 서버 업로드 한도 asset.pdf · asset.pptx 95MB와 같다 */
18
+ export const MAX_DOCUMENT_BYTES = 95 * 1024 ** 2;
19
+
20
+ const str = v => (typeof v === 'string' ? v : '');
21
+ const num = v => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : 0);
22
+
23
+ /**
24
+ * asset_key 모양: 서버가 준 파일 키 `assets/{자료 id}/{파일 이름}` 그대로, 또는 예전 SDK가 저장한 이름 하나
25
+ * (어느 자료의 것인지는 SDK assets.get이 확인. 이름 하나뿐인 예전 키는 SDK가 열지 않음)
26
+ */
27
+ const ASSET_KEY = /^(assets\/[\w-]+\/)?[\w-][\w.-]*$/;
28
+
29
+ /**
30
+ * 저장된 settings(없거나 옛 모양이어도)를 늘 같은 모양으로. 문서가 없거나 종류를 모르면 document는 null
31
+ * @returns {{ title: string, document: null | { asset_key: string, name: string, size: number, type: 'pdf' | 'pptx', pages: number } }}
32
+ */
33
+ export function normalizeSettings(raw) {
34
+ const s = raw && typeof raw === 'object' ? raw : {};
35
+ const d = s.document && typeof s.document === 'object' ? s.document : null;
36
+ const key = d ? str(d.asset_key) || str(d.assetKey) : '';
37
+ const type = d ? kindOf({ type: str(d.type), name: str(d.name) || key }) : null;
38
+ const document =
39
+ d && ASSET_KEY.test(key) && type
40
+ ? {
41
+ asset_key: key,
42
+ name: str(d.name),
43
+ size: num(d.size),
44
+ type,
45
+ pages: Math.floor(num(d.pages)),
46
+ }
47
+ : null;
48
+ return { title: str(s.title), document };
49
+ }
50
+
51
+ /**
52
+ * 편집 화면 값 → 저장할 settings. 빈 제목은 넣지 않는다
53
+ * @param {ReturnType<typeof normalizeSettings>} draft
54
+ */
55
+ export function toSettings(draft) {
56
+ const out = {};
57
+ if (draft.title.trim()) out.title = draft.title.trim();
58
+ if (draft.document) out.document = { ...draft.document };
59
+ return out;
60
+ }
61
+
62
+ /**
63
+ * 저장 전 검증. 통과하면 true, 아니면 보여 줄 문장
64
+ * @param {ReturnType<typeof normalizeSettings>} draft
65
+ * @param {{ noDocument: string, uploading: string }} messages
66
+ * @param {{ uploading?: boolean }} [state]
67
+ */
68
+ export function validateSettings(draft, messages, state = {}) {
69
+ if (state.uploading) return messages.uploading;
70
+ if (!draft.document) return messages.noDocument;
71
+ return true;
72
+ }
73
+
74
+ /** 1.4MB · 820KB · 12B (소수 한 자리, 1024 단위) */
75
+ export function formatBytes(bytes) {
76
+ const n = num(bytes);
77
+ if (n < 1024) return `${n}B`;
78
+ const units = ['KB', 'MB', 'GB'];
79
+ let v = n / 1024;
80
+ let i = 0;
81
+ while (v >= 1024 && i < units.length - 1) {
82
+ v /= 1024;
83
+ i += 1;
84
+ }
85
+ return `${Math.round(v * 10) / 10}${units[i]}`;
86
+ }
@@ -0,0 +1,3 @@
1
+ // core/slide-edges.js 타입 (편집기 자동완성 · 테스트용)
2
+ export declare const EDGE_SNAP_PX: number;
3
+ export declare function snapSlideEdges(slide: HTMLElement): number;
@@ -0,0 +1,82 @@
1
+ // 슬라이드 가장자리 맞추기 (고치지 않습니다). 슬라이드 크기보다 아주 조금(1px 미만) 작은 도형을 가장자리까지 늘린다.
2
+ // 예: 배경을 도형으로 깐 레이아웃의 도형 폭이 12188952 EMU(슬라이드 12192000보다 3048 작음)면 렌더러가 1279.68px로 그려,
3
+ // 늘려 보일 때 오른쪽 끝에 슬라이드 바탕(흰색) 세로선이 비친다. PowerPoint는 픽셀에 맞춰 그려 이 틈이 보이지 않는다.
4
+ // 일부러 가장자리를 비운 도형(1px 이상 떨어짐)과 회전한 도형은 그대로 둔다.
5
+ // 슬라이드 전체를 덮는 불투명 배경 도형이 있으면 슬라이드에 data-dc-full-bleed를 붙인다: 늘려 보일 때 가장자리 픽셀이 반쯤 걸치면
6
+ // 그 픽셀에서 쪽 틀(흰 종이) · 슬라이드 바탕(흰색) 위에 배경 도형이 겹쳐 섞여 밝은 줄이 생기므로, styles.css가 이때만
7
+ // 쪽 틀을 투명하게 하고 슬라이드 바탕을 가장자리 1px 안쪽에만 칠한다 (덮여서 보이지 않는 바탕).
8
+
9
+ /** 이만큼(슬라이드 좌표 px) 안으로 못 미치면 가장자리까지 늘린다 */
10
+ export const EDGE_SNAP_PX = 1;
11
+
12
+ const num = v => {
13
+ const n = Number.parseFloat(v);
14
+ return Number.isFinite(n) ? n : null;
15
+ };
16
+ const near = gap => gap > 0 && gap < EDGE_SNAP_PX;
17
+
18
+ const transparent = el => {
19
+ const o = el.getAttribute('opacity') ?? el.getAttribute('fill-opacity') ?? el.style?.opacity;
20
+ return o !== null && o !== undefined && o !== '' && Number.parseFloat(o) < 1;
21
+ };
22
+ /** 층이 불투명하게 칠한 도형인지 (svg 안 칠한 path · rect 등, 투명도 없음) */
23
+ function opaqueShape(el) {
24
+ if (transparent(el)) return false;
25
+ const svg = [...el.children].find(c => c.tagName.toLowerCase() === 'svg');
26
+ if (!svg || transparent(svg)) return false;
27
+ return [...svg.querySelectorAll('path, rect, polygon, ellipse, circle')].some(shape => {
28
+ const fill = shape.getAttribute('fill');
29
+ return fill !== null && fill !== 'none' && fill !== 'transparent' && !transparent(shape);
30
+ });
31
+ }
32
+
33
+ /**
34
+ * 슬라이드 맨 위 요소(렌더러의 슬라이드, style width · height) 바로 아래 층들을 가장자리에 맞춘다. 바꾼 층 수를 돌려준다.
35
+ * 슬라이드 전체를 덮는 불투명 도형이 있으면 data-dc-full-bleed
36
+ * @param {HTMLElement} slide
37
+ */
38
+ export function snapSlideEdges(slide) {
39
+ const width = num(slide.style.width);
40
+ const height = num(slide.style.height);
41
+ if (!width || !height) return 0;
42
+ let changed = 0;
43
+ let fullBleed = false;
44
+ for (const el of slide.children) {
45
+ const s = /** @type {HTMLElement} */ (el).style;
46
+ if (!s || s.position !== 'absolute' || (s.transform && s.transform !== 'none')) continue;
47
+ let left = num(s.left);
48
+ let top = num(s.top);
49
+ const w0 = num(s.width);
50
+ const h0 = num(s.height);
51
+ if (left === null || top === null || w0 === null || h0 === null) continue;
52
+ let w = w0;
53
+ let h = h0;
54
+ if (near(left)) {
55
+ w += left;
56
+ left = 0;
57
+ }
58
+ if (near(top)) {
59
+ h += top;
60
+ top = 0;
61
+ }
62
+ if (near(width - (left + w))) w = width - left;
63
+ if (near(height - (top + h))) h = height - top;
64
+ if (left === 0 && top === 0 && w >= width && h >= height && opaqueShape(el)) fullBleed = true;
65
+ if (w === w0 && h === h0) continue;
66
+ s.left = `${left}px`;
67
+ s.top = `${top}px`;
68
+ s.width = `${w}px`;
69
+ s.height = `${h}px`;
70
+ // 도형 모양(svg)도 같이 늘린다: viewBox는 그대로 두고 비율을 맞추지 않게
71
+ for (const svg of el.children) {
72
+ if (svg.tagName.toLowerCase() !== 'svg') continue;
73
+ if (!svg.getAttribute('viewBox')) svg.setAttribute('viewBox', `0 0 ${w0} ${h0}`);
74
+ svg.setAttribute('width', String(w));
75
+ svg.setAttribute('height', String(h));
76
+ svg.setAttribute('preserveAspectRatio', 'none');
77
+ }
78
+ changed += 1;
79
+ }
80
+ if (fullBleed) slide.dataset.dcFullBleed = '';
81
+ return changed;
82
+ }
@@ -0,0 +1,28 @@
1
+ // core/viewer.js 타입 (편집기 자동완성 · 테스트용)
2
+ export interface PageSize {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export interface ViewerDoc {
7
+ count: number;
8
+ pageSize(i: number): PageSize;
9
+ render(i: number, target: HTMLElement, scale: number): Promise<boolean>;
10
+ }
11
+ export declare function fitScale(page: PageSize, stage: PageSize): number;
12
+ export declare function mountViewer(
13
+ root: HTMLElement,
14
+ doc: ViewerDoc,
15
+ opts?: {
16
+ start?: number;
17
+ maxHeight?: () => number;
18
+ onPage?: (i: number, info: { scale: number; size: PageSize }) => void;
19
+ /** 쪽을 그리지 못했을 때 alert 자리에 보일 글 (null이면 보이지 않음) */
20
+ errorText?: (e: unknown) => string | null;
21
+ }
22
+ ): {
23
+ go(i: number): Promise<void>;
24
+ readonly page: number;
25
+ refresh(): Promise<void>;
26
+ readonly ready: Promise<void>;
27
+ destroy(): void;
28
+ };