@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,256 @@
1
+ // 그룹 3D 카메라 우회 (고치지 않습니다). PowerPoint는 그룹 도형의 grpSpPr/a:scene3d/a:camera 프리셋으로 묶음 전체를
2
+ // 비스듬히 눕혀 그리는데(예: isometricTopUp, 바닥에 놓인 S자 길), @aiden0z/pptx-renderer 1.4.0은 그룹 3D를
3
+ // "그림 2개 + perspectiveLeft"일 때만 투영하고 나머지는 평면으로 그린 뒤 data-pptx-shape3d-fallback만 붙인다.
4
+ // 이 파일은 원본 XML에서 그 그룹의 카메라를 읽어, 평면으로 그려진 그룹 div에 같은 정사영(평행 투영)을 CSS transform으로 씌운다.
5
+ // - 정사영 프리셋(isometric*)만: 3D 회전을 화면 평면에 비춘 2x2 행렬 하나로 정확히 맞는다. 원근(perspective*) ·
6
+ // 빗각(oblique*) · 조명 · 돌출 · 그림자는 하지 않는다
7
+ // - 짝짓기: 그룹 div의 슬라이드 기준 위치 · 크기(style left · top · width · height를 조상까지 더함)가 XML 그룹 위치와
8
+ // 0.5px 안으로 하나만 맞을 때만. 확실하지 않으면 아무것도 하지 않는다 (틀린 변환보다 평면이 낫다)
9
+ // - 렌더러가 이미 투영한 그룹(fallback 표시가 없거나 transform이 있음)은 건드리지 않는다 (이중 변환 방지)
10
+ // 렌더러가 그룹 정사영 카메라를 직접 그리게 되면(upstream) 이 파일과 pptx-view.js의 호출을 걷어낸다.
11
+
12
+ /** 1px = 9525 EMU (96dpi, 렌더러와 같음) */
13
+ const EMU_PER_PX = 9525;
14
+ /** 그룹 div 위치와 XML 그룹 위치가 이만큼(px) 안이면 같은 그룹 */
15
+ export const MATCH_PX = 0.5;
16
+
17
+ /**
18
+ * 정사영 카메라 프리셋의 회전 (lat · lon · rev, 1/60000도). 값은 LibreOffice oox/source/drawingml/scene3dhelper.cxx의
19
+ * aPrstCameraValuesArray (MS Office에서 잰 값, tdf#70039)에서 mbIsParallel이고 기울임(skew)이 없는 isometric* 프리셋만 옮김.
20
+ * ECMA-376은 프리셋 이름만 정하고 각도는 정하지 않는다
21
+ */
22
+ export const ISOMETRIC_CAMERAS = {
23
+ isometricTopUp: [19476000, 18882000, 3612000],
24
+ isometricTopDown: [19476000, 2718000, 17988000],
25
+ isometricBottomUp: [2124000, 2718000, 3612000],
26
+ isometricBottomDown: [2124000, 18882000, 17988000],
27
+ isometricLeftUp: [19500000, 2700000, 0],
28
+ isometricLeftDown: [2100000, 2700000, 0],
29
+ isometricRightUp: [2100000, 18900000, 0],
30
+ isometricRightDown: [19500000, 18900000, 0],
31
+ isometricOffAxis1Left: [1080000, 3840000, 0],
32
+ isometricOffAxis1Right: [1080000, 20040000, 0],
33
+ isometricOffAxis1Top: [18078000, 18390000, 3456000],
34
+ isometricOffAxis2Left: [1080000, 1560000, 0],
35
+ isometricOffAxis2Right: [1080000, 17760000, 0],
36
+ isometricOffAxis2Top: [18078000, 3210000, 18144000],
37
+ isometricOffAxis3Bottom: [3522000, 18390000, 18144000],
38
+ isometricOffAxis3Left: [20520000, 3840000, 0],
39
+ isometricOffAxis3Right: [20520000, 20040000, 0],
40
+ isometricOffAxis4Bottom: [3522000, 3210000, 3456000],
41
+ isometricOffAxis4Left: [20520000, 1560000, 0],
42
+ isometricOffAxis4Right: [20520000, 17760000, 0],
43
+ };
44
+
45
+ const mul = (A, B) =>
46
+ A.map(row =>
47
+ B[0].map((_, j) =>
48
+ row.reduce(
49
+ (s, v, k) => s + v * B[k][j],
50
+ 0
51
+ )
52
+ )
53
+ );
54
+
55
+ /**
56
+ * 카메라 회전(1/60000도) → 그룹 평면을 화면에 비춘 CSS matrix(a, b, c, d). y축은 아래.
57
+ * MS Office는 y축(lon) → x축(lat) → z축(rev) 순서로 돌린다: 전체 = Z · X · Y (LibreOffice
58
+ * Scene3DHelper::getAPIAnglesFromOOXAngle과 같은 부호). 정사영이라 화면 좌표는 전체 행렬의 왼쪽 위 2x2.
59
+ * isometricTopUp ≈ matrix(0.7069, -0.4058, 0.7073, 0.4051)
60
+ * @param {number} lat @param {number} lon @param {number} rev
61
+ * @returns {[number, number, number, number]}
62
+ */
63
+ export function cameraMatrix(lat, lon, rev) {
64
+ const rad = v => (v / 60000) * (Math.PI / 180);
65
+ const [a, b, c] = [rad(lat), rad(lon), rad(rev)];
66
+ const X = [
67
+ [1, 0, 0],
68
+ [0, Math.cos(a), Math.sin(a)],
69
+ [0, -Math.sin(a), Math.cos(a)],
70
+ ];
71
+ const Y = [
72
+ [Math.cos(b), 0, -Math.sin(b)],
73
+ [0, 1, 0],
74
+ [Math.sin(b), 0, Math.cos(b)],
75
+ ];
76
+ const Z = [
77
+ [Math.cos(c), Math.sin(c), 0],
78
+ [-Math.sin(c), Math.cos(c), 0],
79
+ [0, 0, 1],
80
+ ];
81
+ const T = mul(Z, mul(X, Y));
82
+ return [T[0][0], T[1][0], T[0][1], T[1][1]];
83
+ }
84
+
85
+ const kids = (el, name) => [...el.children].filter(c => c.localName === name);
86
+ const kid = (el, name) => kids(el, name)[0];
87
+ const num = (el, attr) => {
88
+ const n = Number(el?.getAttribute(attr));
89
+ return Number.isFinite(n) ? n : 0;
90
+ };
91
+
92
+ /**
93
+ * 그룹 grpSpPr의 카메라가 정사영 프리셋이면 [lat, lon, rev]. a:rot가 있으면 프리셋 대신 그 값 (LibreOffice와 같음)
94
+ * @param {Element | undefined} grpSpPr
95
+ */
96
+ function groupCamera(grpSpPr) {
97
+ const scene = grpSpPr && kid(grpSpPr, 'scene3d');
98
+ const camera = scene && kid(scene, 'camera');
99
+ if (!camera) return null;
100
+ const preset = ISOMETRIC_CAMERAS[camera.getAttribute('prst') ?? ''];
101
+ if (!preset) return null;
102
+ const rot = kid(camera, 'rot');
103
+ return rot ? [num(rot, 'lat'), num(rot, 'lon'), num(rot, 'rev')] : preset;
104
+ }
105
+
106
+ /**
107
+ * 슬라이드 · 레이아웃 · 마스터 XML 하나에서 정사영 카메라가 있는 그룹을 찾는다 (슬라이드 기준 px 위치와 CSS 행렬).
108
+ * 그룹 · 조상 그룹이 돌거나 뒤집혔거나, 조상 그룹에도 카메라가 있으면 뺀다 (렌더러가 transform을 붙여 위치로 짝지을 수 없음)
109
+ * @param {string} xml
110
+ * @returns {Array<{ x: number, y: number, w: number, h: number, matrix: [number, number, number, number] }>}
111
+ */
112
+ export function findCameraGroups(xml) {
113
+ if (!xml || !xml.includes('scene3d') || !xml.includes('isometric')) return [];
114
+ const doc = new DOMParser().parseFromString(xml, 'application/xml');
115
+ // cSld > spTree (이름공간 접두어와 상관없이 localName으로)
116
+ const tree = kid(kid(doc.documentElement, 'cSld') ?? doc.documentElement, 'spTree');
117
+ if (!tree) return [];
118
+ const found = [];
119
+ const identity = { ox: 0, oy: 0, sx: 1, sy: 1 };
120
+ /** @param {Element} group @param {typeof identity} map @param {boolean} blocked */
121
+ const walk = (group, map, blocked) => {
122
+ for (const g of kids(group, 'grpSp')) {
123
+ const pr = kid(g, 'grpSpPr');
124
+ const xfrm = pr && kid(pr, 'xfrm');
125
+ if (!xfrm) continue;
126
+ const off = kid(xfrm, 'off');
127
+ const ext = kid(xfrm, 'ext');
128
+ const chOff = kid(xfrm, 'chOff');
129
+ const chExt = kid(xfrm, 'chExt');
130
+ const turned =
131
+ num(xfrm, 'rot') !== 0 ||
132
+ xfrm.getAttribute('flipH') === '1' ||
133
+ xfrm.getAttribute('flipV') === '1';
134
+ const x = map.ox + num(off, 'x') * map.sx;
135
+ const y = map.oy + num(off, 'y') * map.sy;
136
+ const w = num(ext, 'cx') * map.sx;
137
+ const h = num(ext, 'cy') * map.sy;
138
+ const camera = groupCamera(pr);
139
+ if (camera && !blocked && !turned) {
140
+ found.push({
141
+ x: x / EMU_PER_PX,
142
+ y: y / EMU_PER_PX,
143
+ w: w / EMU_PER_PX,
144
+ h: h / EMU_PER_PX,
145
+ matrix: cameraMatrix(...camera),
146
+ });
147
+ }
148
+ const cw = num(chExt, 'cx');
149
+ const ch = num(chExt, 'cy');
150
+ const sx = cw > 0 ? w / cw : map.sx;
151
+ const sy = ch > 0 ? h / ch : map.sy;
152
+ walk(
153
+ g,
154
+ { ox: x - num(chOff, 'x') * sx, oy: y - num(chOff, 'y') * sy, sx, sy },
155
+ blocked || turned || Boolean(camera) || Boolean(pr && kid(pr, 'scene3d'))
156
+ );
157
+ }
158
+ };
159
+ walk(tree, identity, false);
160
+ return found;
161
+ }
162
+
163
+ const px = (el, prop) => Number.parseFloat(el.style[prop]) || 0;
164
+
165
+ /** 요소의 슬라이드 기준 위치 (조상 div의 left · top을 더함). 조상에 transform이 있으면 null */
166
+ function slideRect(el, slide) {
167
+ let x = px(el, 'left');
168
+ let y = px(el, 'top');
169
+ for (let g = el.parentElement; g && g !== slide; g = g.parentElement) {
170
+ if (g.style.transform && g.style.transform !== 'none') return null;
171
+ x += px(g, 'left');
172
+ y += px(g, 'top');
173
+ }
174
+ return { x, y, w: px(el, 'width'), h: px(el, 'height') };
175
+ }
176
+
177
+ const near = (a, b) => Math.abs(a - b) <= MATCH_PX;
178
+ const same = (r, c) => near(r.x, c.x) && near(r.y, c.y) && near(r.w, c.w) && near(r.h, c.h);
179
+
180
+ /**
181
+ * 그린 슬라이드에서 평면으로 그려진 3D 그룹(data-pptx-shape3d-fallback)에 카메라 투영을 씌운다. 씌운 그룹 수를 돌려준다.
182
+ * 짝이 하나로 정해질 때만 (그룹 후보 하나에 div 하나)
183
+ * @param {HTMLElement} slide 렌더러의 슬라이드 맨 위 요소
184
+ * @param {ReturnType<typeof findCameraGroups>} groups 이 슬라이드 · 레이아웃 · 마스터의 카메라 그룹
185
+ */
186
+ export function applyGroupCameras(slide, groups) {
187
+ if (!groups.length) return 0;
188
+ const flat = [...slide.querySelectorAll('[data-pptx-shape3d-fallback]')]
189
+ .filter(
190
+ el => el instanceof HTMLElement && !(el.style.transform && el.style.transform !== 'none')
191
+ )
192
+ .map(el => ({ el, rect: slideRect(/** @type {HTMLElement} */ (el), slide) }))
193
+ .filter(c => c.rect);
194
+ let applied = 0;
195
+ for (const group of groups) {
196
+ const hits = flat.filter(c => same(c.rect, group));
197
+ if (hits.length !== 1 || groups.filter(g => same(hits[0].rect, g)).length !== 1) continue;
198
+ const el = /** @type {HTMLElement} */ (hits[0].el);
199
+ const [a, b, c, d] = group.matrix.map(v => Number(v.toFixed(6)));
200
+ el.style.transformOrigin = '50% 50%';
201
+ el.style.transform = `matrix(${a}, ${b}, ${c}, ${d}, 0, 0)`;
202
+ el.dataset.dcGroupCamera = '';
203
+ applied += 1;
204
+ }
205
+ return applied;
206
+ }
207
+
208
+ /**
209
+ * 렌더러가 연 zip 파일(parseZipLazyMedia 결과)에서 슬라이드 경로마다 카메라 그룹을 찾는다 (슬라이드 · 레이아웃 · 마스터,
210
+ * XML 파일마다 한 번만 읽고 기억함)
211
+ * @param {{ slides?: Map<string, string>, slideRels?: Map<string, string>, slideLayouts?: Map<string, string>,
212
+ * slideLayoutRels?: Map<string, string>, slideMasters?: Map<string, string> }} files
213
+ */
214
+ export function createGroupCameras(files) {
215
+ /** @type {Map<string, ReturnType<typeof findCameraGroups>>} */
216
+ const byXml = new Map();
217
+ const groupsIn = (map, path) => {
218
+ if (!byXml.has(path)) byXml.set(path, findCameraGroups(map?.get(path) ?? ''));
219
+ return /** @type {ReturnType<typeof findCameraGroups>} */ (byXml.get(path));
220
+ };
221
+ /** rels에서 type이 …/{type}인 대상 경로 (from 파일 기준 상대 경로를 풂) */
222
+ const target = (relsXml, from, type) => {
223
+ const m = [...(relsXml ?? '').matchAll(/<Relationship\b[^>]*>/g)]
224
+ .map(r => r[0])
225
+ .find(r => new RegExp(`Type="[^"]*/${type}"`).test(r));
226
+ const t = m?.match(/Target="([^"]+)"/)?.[1];
227
+ if (!t) return null;
228
+ const parts = from.split('/').slice(0, -1);
229
+ for (const seg of t.split('/')) {
230
+ if (seg === '..') parts.pop();
231
+ else if (seg !== '.') parts.push(seg);
232
+ }
233
+ return parts.join('/');
234
+ };
235
+ const relsOf = path => path.replace(/([^/]+)$/, '_rels/$1.rels');
236
+ const hasAny = [files.slides, files.slideLayouts, files.slideMasters].some(m =>
237
+ [...(m?.values() ?? [])].some(x => typeof x === 'string' && x.includes('isometric'))
238
+ );
239
+ return {
240
+ /**
241
+ * @param {HTMLElement} slide 그린 슬라이드
242
+ * @param {string | undefined} slidePath 예: ppt/slides/slide1.xml
243
+ */
244
+ apply(slide, slidePath) {
245
+ if (!hasAny || !slidePath) return 0;
246
+ const groups = [...groupsIn(files.slides, slidePath)];
247
+ const layout = target(files.slideRels?.get(relsOf(slidePath)), slidePath, 'slideLayout');
248
+ if (layout) {
249
+ groups.push(...groupsIn(files.slideLayouts, layout));
250
+ const master = target(files.slideLayoutRels?.get(relsOf(layout)), layout, 'slideMaster');
251
+ if (master) groups.push(...groupsIn(files.slideMasters, master));
252
+ }
253
+ return applyGroupCameras(slide, groups);
254
+ },
255
+ };
256
+ }
@@ -0,0 +1,15 @@
1
+ // core/inline-edit.js 타입 (편집기 자동완성 · 테스트용)
2
+ export declare function findTextBoxes<
3
+ S extends {
4
+ text?: string;
5
+ box: { x: number; y: number; w: number; h: number };
6
+ cell?: { row: number; index: number };
7
+ },
8
+ >(root: Element, shapes: S[], textOf?: (shape: S) => string): Array<{ shape: S; element: HTMLElement }>;
9
+ export declare function routeTextClicks(page: HTMLElement): void;
10
+ export declare function readBoxText(box: Element): string;
11
+ export declare function outlineBox(box: HTMLElement): void;
12
+ export declare function makeEditable(
13
+ box: HTMLElement,
14
+ opts: { label: string; onCommit: (text: string) => void }
15
+ ): { before: string };
@@ -0,0 +1,377 @@
1
+ // 슬라이드 글자 제자리 고치기 (편집 화면, 고치지 않습니다).
2
+ // @aiden0z/pptx-renderer가 그린 글자 상자를 그대로 contenteditable로 바꿔, 글꼴 · 크기 · 색 · 굵기 · 정렬 · 줄 간격 ·
3
+ // 위치 · 줄바꿈이 슬라이드와 같은 채로 고친다. 고친 글자는 화면 코드가 @office-kit headless로 파일에 넣는다.
4
+ // 쓰는 것은 DOM뿐이라 happy-dom 테스트로 확인한다. 렌더러 마크업에는 class가 없어 모양으로 찾는다:
5
+ // 슬라이드(core/pptx-view.js가 data-dc-slide를 붙임) 안 도형은 left · top · width · height(px, 파일 좌표)를 가진 div,
6
+ // 그 안 글자 상자는 display: flex; flex-direction: column인 div, 문단마다 div > span, 글머리 기호는 문단 첫 span(position: absolute).
7
+ // 그룹은 자식 도형을 담은 div (자식 위치는 그룹 기준). 표는 도형 div > table > tbody > tr > td이고, 병합으로 가려진 칸은 td가 없다.
8
+
9
+ /** 그린 도형 위치(px)와 @office-kit 도형 위치가 이만큼 안이면 같은 도형으로 본다 */
10
+ const MATCH_PX = 2;
11
+
12
+ const px = (el, prop) => Number.parseFloat(el.style[prop]) || 0;
13
+
14
+ /** 렌더러의 글자 상자 (도형 div 바로 안, 문단 div를 세로로 쌓는 flex) */
15
+ const isTextBox = el =>
16
+ el.tagName === 'DIV' && el.style.display === 'flex' && el.style.flexDirection === 'column';
17
+
18
+ /** 도형 div의 슬라이드 기준 위치: 그룹 안 도형은 그룹 기준으로 그려지므로 슬라이드까지 조상들의 위치를 더한다 */
19
+ function slidePosition(el, slide) {
20
+ let left = px(el, 'left');
21
+ let top = px(el, 'top');
22
+ for (let g = el.parentElement; g && g !== slide; g = g.parentElement) {
23
+ left += px(g, 'left');
24
+ top += px(g, 'top');
25
+ }
26
+ return { left, top, width: px(el, 'width') };
27
+ }
28
+
29
+ const squash = t => t.replace(/\s+/g, ' ').trim();
30
+
31
+ /**
32
+ * 그려진 슬라이드에서 글자 도형마다 글자 상자를 찾는다 (위치 · 크기로 짝지음, 좌표는 파일 크기 px).
33
+ * 같은 자리에 도형(바탕 · 동그라미)과 그 위 글자 상자가 겹칠 수 있다 (렌더러는 글자가 없는 도형에는 글자 상자를 그리지 않지만,
34
+ * 빈 문단만 있는 도형 등 빈 상자가 생길 수 있음): 같은 자리 후보 중 글자가 같은 것 → 글자가 있는 것 순으로 고르고,
35
+ * 도형에 글자가 있는데 빈 상자뿐이면 짝짓지 않는다.
36
+ * 그룹 안 도형 위치는 core/pptx-edit.js가 슬라이드 좌표로 옮겨 준다. 그래도 위치로 못 찾으면(그룹 회전 등)
37
+ * 글자 · 폭이 같은 상자가 하나뿐일 때만 그것으로.
38
+ * 표 칸(shape.cell)은 위치가 같은 표에서 cell.row번째 줄의 cell.index번째 td를 글자 상자로 쓴다 (빈 칸도)
39
+ * @param {Element} root 슬라이드를 그린 곳 ([data-dc-slide]가 안에 있음)
40
+ * @param {Array<{ text?: string, box: { x: number, y: number, w: number, h: number }, cell?: { row: number, index: number } }>} shapes 슬라이드 크기에 대한 비율
41
+ * @param {(shape: object) => string} [textOf] 지금 보이는 글자 (고친 뒤 다시 그렸으면 고친 글자, 기본 shape.text)
42
+ * @returns {Array<{ shape: object, element: HTMLElement }>}
43
+ */
44
+ export function findTextBoxes(root, shapes, textOf = shape => shape.text ?? '') {
45
+ const slide = root.querySelector('[data-dc-slide]');
46
+ if (!slide) return [];
47
+ const width = px(slide, 'width');
48
+ const height = px(slide, 'height');
49
+ const boxes = [...slide.querySelectorAll('div')]
50
+ .filter(el => isTextBox(el) && el.parentElement && el.parentElement !== slide)
51
+ .map(el => ({ el, pos: slidePosition(el.parentElement, slide), text: squash(readBoxText(el)) }));
52
+ const tables = [...slide.querySelectorAll('table')]
53
+ .filter(el => el.parentElement && el.parentElement !== slide)
54
+ .map(el => ({ el, pos: slidePosition(el.parentElement, slide) }));
55
+ const near = (pos, { x, y, w }) =>
56
+ Math.abs(pos.left - x * width) <= MATCH_PX &&
57
+ Math.abs(pos.top - y * height) <= MATCH_PX &&
58
+ Math.abs(pos.width - w * width) <= MATCH_PX;
59
+ const used = new Set();
60
+ const found = [];
61
+ for (const shape of shapes) {
62
+ if (shape.cell) {
63
+ const table = tables.find(t => near(t.pos, shape.box));
64
+ // 줄 · 칸은 요소로 센다 (tBodies · rows · cells가 없는 DOM도 있음)
65
+ const rows = table ? [...table.el.querySelectorAll('tr')] : [];
66
+ const tr = rows.filter(r => r.closest('table') === table.el)[shape.cell.row];
67
+ const td = tr && [...tr.children].filter(c => c.tagName === 'TD')[shape.cell.index];
68
+ if (td && !used.has(td)) {
69
+ used.add(td);
70
+ found.push({ shape, element: td });
71
+ }
72
+ continue;
73
+ }
74
+ const { w } = shape.box;
75
+ const want = squash(textOf(shape));
76
+ let best = null;
77
+ let bestScore = -1;
78
+ for (const c of boxes) {
79
+ if (used.has(c.el) || !near(c.pos, shape.box)) continue;
80
+ // 글자가 같음 2, 글자가 있음 1, 빈 상자 0 (같은 점수면 앞에 그린 것)
81
+ const score = c.text === want ? 2 : c.text ? 1 : 0;
82
+ if (score > bestScore) {
83
+ best = c;
84
+ bestScore = score;
85
+ }
86
+ }
87
+ if (!best || (want && bestScore === 0)) {
88
+ const same = want
89
+ ? boxes.filter(
90
+ c => !used.has(c.el) && c.text === want && Math.abs(c.pos.width - w * width) <= MATCH_PX
91
+ )
92
+ : [];
93
+ if (same.length !== 1) continue;
94
+ best = same[0];
95
+ }
96
+ used.add(best.el);
97
+ found.push({ shape, element: best.el });
98
+ }
99
+ return found;
100
+ }
101
+
102
+ /**
103
+ * 누른 곳의 글자가 다른 글자 상자에 가려 있으면 그 글자의 상자로 보낸다. 도형 글자 상자는 도형 크기만큼 투명하게 깔려,
104
+ * 뒤에 그린 넓은 상자(같은 그룹의 긴 줄, 바탕 도형 등)가 앞 상자의 글자를 덮는다 (PowerPoint는 채우기 없는 도형을 글자로 고름).
105
+ * 누른 곳 맨 위가 글자가 아니고(빈 자리) 그 아래 고칠 수 있는 상자의 글자가 있을 때만 바꾸고, 커서는 누른 글자 자리에 둔다
106
+ * @param {HTMLElement} page 슬라이드를 그리는 곳 (쪽을 넘겨도 같은 요소, 한 번만 붙임)
107
+ */
108
+ export function routeTextClicks(page) {
109
+ if (page.dataset.dcRoute !== undefined) return;
110
+ page.dataset.dcRoute = '';
111
+ const doc = page.ownerDocument;
112
+ page.addEventListener(
113
+ 'mousedown',
114
+ e => {
115
+ if (e.button !== 0 || typeof doc.elementsFromPoint !== 'function') return;
116
+ const stack = doc.elementsFromPoint(e.clientX, e.clientY);
117
+ const top = stack[0];
118
+ const owner = top?.closest('.dc-editable');
119
+ // 맨 위가 고칠 수 있는 상자의 글자이거나 고치는 중인 상자면 그대로
120
+ if (!top || (owner && (top.tagName === 'SPAN' || owner === doc.activeElement))) return;
121
+ const span = stack.find(
122
+ el =>
123
+ el.tagName === 'SPAN' && el.dataset.dcBullet === undefined && el.closest('.dc-editable')
124
+ );
125
+ const box = span?.closest('.dc-editable');
126
+ if (!box || box === owner || !page.contains(box)) return;
127
+ e.preventDefault();
128
+ box.focus();
129
+ placeCaret(span, e.clientX);
130
+ },
131
+ true
132
+ );
133
+ }
134
+
135
+ /** span 글자 중 x(화면 좌표)에 가장 가까운 자리에 커서 */
136
+ function placeCaret(span, x) {
137
+ const doc = span.ownerDocument;
138
+ const sel = doc.getSelection();
139
+ const text = [...span.childNodes].find(n => n.nodeType === 3);
140
+ if (!sel || !text) return;
141
+ const range = doc.createRange();
142
+ let offset = text.data.length;
143
+ for (let i = 0; i < text.data.length; i += 1) {
144
+ range.setStart(text, i);
145
+ range.setEnd(text, i + 1);
146
+ const r = range.getBoundingClientRect();
147
+ if (x < r.left + r.width / 2) {
148
+ offset = i;
149
+ break;
150
+ }
151
+ }
152
+ range.setStart(text, offset);
153
+ range.collapse(true);
154
+ sel.removeAllRanges();
155
+ sel.addRange(range);
156
+ }
157
+
158
+ /** 글자 상자 안 문단 (렌더러는 div, 붙여넣기 · 브라우저가 p를 만들 수 있음) */
159
+ const isParagraph = el => el.tagName === 'DIV' || el.tagName === 'P';
160
+
161
+ /** 문단 첫 span이 글머리 기호(따로 띄워 둠, 뒤에 글자가 이어짐)인지 */
162
+ const isBullet = span =>
163
+ span.tagName === 'SPAN' &&
164
+ !span.previousElementSibling &&
165
+ Boolean(span.nextElementSibling) &&
166
+ span.style.position === 'absolute';
167
+
168
+ /** 글머리 기호는 고칠 수 없게 (글자로 읽지 않음) */
169
+ function lockBullets(box) {
170
+ for (const p of box.children) {
171
+ const first = p.firstElementChild;
172
+ if (first && isBullet(first)) {
173
+ first.contentEditable = 'false';
174
+ first.dataset.dcBullet = '';
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * 글자 상자의 글자: 문단(p · div)마다 한 줄, 줄바꿈(<br>)도 줄. 글머리 기호는 뺀다. @office-kit setShapeText와 같은 모양(\n)
181
+ * @param {Element} box 글자 상자
182
+ */
183
+ export function readBoxText(box) {
184
+ const lines = [];
185
+ let line = null;
186
+ const walk = node => {
187
+ for (const c of node.childNodes) {
188
+ if (c.nodeType === 3) {
189
+ line = (line ?? '') + c.data;
190
+ } else if (c.nodeType === 1) {
191
+ if (c.dataset?.dcBullet !== undefined || isBullet(c)) continue;
192
+ if (c.tagName === 'BR') {
193
+ lines.push(line ?? '');
194
+ line = null;
195
+ continue;
196
+ }
197
+ const block = c.tagName === 'P' || c.tagName === 'DIV';
198
+ if (block && line !== null) {
199
+ lines.push(line);
200
+ line = null;
201
+ }
202
+ walk(c);
203
+ if (block && line !== null) {
204
+ lines.push(line);
205
+ line = null;
206
+ }
207
+ }
208
+ }
209
+ };
210
+ walk(box);
211
+ if (line !== null) lines.push(line);
212
+ // 문단을 감싼 div · p가 겹쳐 생긴 빈 줄은 빼지 않는다 (사용자가 만든 빈 문단일 수 있음). 끝의 빈 줄만 정리
213
+ while (lines.length > 1 && lines[lines.length - 1] === '') lines.pop();
214
+ return lines.join('\n');
215
+ }
216
+
217
+ /**
218
+ * 편집 테두리 범위를 잰다 (styles.css div.dc-editable::before가 그림). 도형 글자 상자는 도형 크기라 글자보다 넓어
219
+ * 문단을 글자 폭으로 줄여 두었다: 테두리는 상자마다 하나로, 상자 안 문단(직속 자식) 전체를 감싼다.
220
+ * 좌표는 상자 안 좌표(offsetLeft · offsetTop · offsetWidth · offsetHeight, 상자는 position: absolute라 문단의 offsetParent)라
221
+ * 쪽 맞춤(transform: scale) · 회전 · 그룹과 상관없이 같고, 테두리도 상자와 같이 기운다. 화면 좌표(getBoundingClientRect)는 쓰지 않는다.
222
+ * 문단이 아닌 직속 자식(span · br, flex 항목이라 블록)도 같이 잰다. 상자에 바로 들어간 글자(텍스트 노드)는 자리를 잴 수 없어
223
+ * 상자 전체로 둔다. 표 칸(td)은 칸 전체 테두리 그대로라 재지 않는다.
224
+ * 상자 style에 CSS 변수만 쓰므로 자식 노드(저장 글자 · Esc 되돌리기 · 변경 감지 childList)는 바뀌지 않는다
225
+ * @param {HTMLElement} box 글자 상자
226
+ */
227
+ export function outlineBox(box) {
228
+ if (box.tagName !== 'DIV') return;
229
+ let left = Infinity;
230
+ let top = Infinity;
231
+ let right = -Infinity;
232
+ let bottom = -Infinity;
233
+ let loose = false;
234
+ for (const node of box.childNodes) {
235
+ if (node.nodeType === 3) {
236
+ if (node.data.trim()) loose = true;
237
+ continue;
238
+ }
239
+ if (node.nodeType !== 1 || node.offsetParent !== box) continue;
240
+ const { offsetLeft: x, offsetTop: y, offsetWidth: w, offsetHeight: h } = node;
241
+ if (!w && !h) continue;
242
+ left = Math.min(left, x);
243
+ top = Math.min(top, y);
244
+ right = Math.max(right, x + w);
245
+ bottom = Math.max(bottom, y + h);
246
+ }
247
+ const style = box.style;
248
+ if (loose || left === Infinity) {
249
+ for (const k of ['left', 'top', 'width', 'height']) style.removeProperty(`--dc-edit-${k}`);
250
+ return;
251
+ }
252
+ style.setProperty('--dc-edit-left', `${left}px`);
253
+ style.setProperty('--dc-edit-top', `${top}px`);
254
+ style.setProperty('--dc-edit-width', `${right - left}px`);
255
+ style.setProperty('--dc-edit-height', `${bottom - top}px`);
256
+ }
257
+
258
+ /**
259
+ * 글자 상자를 제자리에서 고칠 수 있게 한다. Enter는 새 문단, Esc는 취소, 바깥을 누르면(blur) 적용,
260
+ * Ctrl/⌘+Enter도 적용. 붙여넣기는 글자만, 굵게 · 기울임 같은 서식 단축키는 막는다 (글자만 고침). 한글 조합 중 키는 건드리지 않는다
261
+ * @param {HTMLElement} box 글자 상자 (findTextBoxes)
262
+ * @param {{ label: string, onCommit: (text: string) => void }} opts
263
+ */
264
+ export function makeEditable(box, { label, onCommit }) {
265
+ // 쪽을 다시 맞출 때(크기 바뀜) 같은 상자에 또 붙이지 않는다 (고치는 중 글자를 원래 글자로 잘못 기억함)
266
+ if (box.dataset.dcEditable !== undefined) {
267
+ outlineBox(box);
268
+ return { before: readBoxText(box) };
269
+ }
270
+ box.dataset.dcEditable = '';
271
+ lockBullets(box);
272
+ // 고친 뒤에도 같은 상자를 계속 쓴다 (화면 코드가 다시 그리지 않음): 적용할 때마다 기준(before · Esc로 되돌릴 모양)을 바꾼다
273
+ let original = [...box.childNodes].map(n => n.cloneNode(true));
274
+ let before = readBoxText(box);
275
+ box.contentEditable = 'true';
276
+ box.spellcheck = false;
277
+ box.tabIndex = 0;
278
+ box.classList.add('dc-editable');
279
+ box.setAttribute('role', 'textbox');
280
+ box.setAttribute('aria-multiline', 'true');
281
+ box.setAttribute('aria-label', label);
282
+ let cancelled = false;
283
+ // 문단 정렬 · 줄 간격 · 글자 크기는 문단 div에 있다. 글자를 다 지운 뒤 Backspace를 더 누르면 브라우저가 마지막 문단 div까지
284
+ // 지워, 새로 쓴 글자가 상자에 바로 들어가 왼쪽 정렬 · 기본 크기가 된다 (filled-template 24쪽 '일반 처리'). 문단을 지키고,
285
+ // 그래도 문단이 없어지면(전체 잘라내기 등) 처음 문단 모양으로 다시 감싼다
286
+ const paragraph = [...box.children].find(isParagraph)?.cloneNode(false) ?? null;
287
+ const keepParagraph = () => {
288
+ if (!paragraph || [...box.children].some(isParagraph)) return;
289
+ const p = paragraph.cloneNode(false);
290
+ p.append(...box.childNodes);
291
+ if (!p.firstChild) p.append(box.ownerDocument.createElement('br'));
292
+ box.append(p);
293
+ const sel = box.ownerDocument.getSelection();
294
+ if (sel && box.ownerDocument.activeElement === box) {
295
+ const range = box.ownerDocument.createRange();
296
+ range.selectNodeContents(p);
297
+ range.collapse(false);
298
+ sel.removeAllRanges();
299
+ sel.addRange(range);
300
+ }
301
+ };
302
+ // 입력하는 동안은 저장 전 변경으로 보지 않는다 (적용하면 화면 코드가 markDirty). 한글 조합 중에는 DOM을 건드리지 않는다.
303
+ // 테두리 범위는 글자가 바뀔 때(입력 · 붙여넣기 · 조합 끝)와 보일 때(가리킴 · focus) 다시 잰다. 조합 중 글자 폭도 따라가게
304
+ // 조합 중 input에서도 잰다 (DOM은 건드리지 않고 읽기만)
305
+ box.addEventListener('input', e => {
306
+ e.stopPropagation();
307
+ if (!e.isComposing) keepParagraph();
308
+ outlineBox(box);
309
+ });
310
+ box.addEventListener('compositionend', () => {
311
+ keepParagraph();
312
+ outlineBox(box);
313
+ });
314
+ // 상자는 누를 수 없어(pointer-events: none) 문단에서 올라온 것. 쪽 맞춤 · 글꼴이 늦게 들어와 바뀐 크기도 여기서 맞춘다
315
+ box.addEventListener('pointerover', () => outlineBox(box));
316
+ box.addEventListener('keydown', e => {
317
+ if (e.isComposing) return;
318
+ if (
319
+ (e.key === 'Backspace' || e.key === 'Delete') &&
320
+ readBoxText(box) === '' &&
321
+ [...box.children].filter(isParagraph).length <= 1
322
+ ) {
323
+ // 지울 글자가 없다: 남은 빈 문단(정렬 · 크기)을 지우지 않게
324
+ e.preventDefault();
325
+ } else if (e.key === 'Escape') {
326
+ e.preventDefault();
327
+ cancelled = true;
328
+ box.blur();
329
+ // 되돌리기는 다음 차례에: 고치는 동안 생긴 변화 알림(MutationObserver, 키트 useSave)이 먼저 처리되게.
330
+ // 바로 바꾸면 알림이 늦게 와 떼어 낸 노드를 보고 "저장하지 않은 변경"으로 잘못 센다
331
+ setTimeout(
332
+ () => {
333
+ box.replaceChildren(...original.map(n => n.cloneNode(true)));
334
+ lockBullets(box);
335
+ outlineBox(box);
336
+ },
337
+ 0
338
+ );
339
+ } else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
340
+ e.preventDefault();
341
+ box.blur();
342
+ } else if ((e.ctrlKey || e.metaKey) && ['b', 'i', 'u'].includes(e.key.toLowerCase())) {
343
+ e.preventDefault();
344
+ }
345
+ });
346
+ box.addEventListener('paste', e => {
347
+ e.preventDefault();
348
+ const text = e.clipboardData?.getData('text/plain') ?? '';
349
+ const sel = box.ownerDocument.getSelection();
350
+ if (!sel || sel.rangeCount === 0) return;
351
+ const range = sel.getRangeAt(0);
352
+ range.deleteContents();
353
+ const node = box.ownerDocument.createTextNode(text);
354
+ range.insertNode(node);
355
+ range.setStartAfter(node);
356
+ range.collapse(true);
357
+ sel.removeAllRanges();
358
+ sel.addRange(range);
359
+ // 막은 붙여넣기는 input이 오지 않는다: 전체를 골라 붙이면 문단이 지워져 글자가 상자에 바로 들어가므로 여기서도 감싼다
360
+ keepParagraph();
361
+ outlineBox(box);
362
+ });
363
+ box.addEventListener('focus', () => {
364
+ cancelled = false;
365
+ outlineBox(box);
366
+ });
367
+ box.addEventListener('blur', () => {
368
+ if (cancelled) return;
369
+ const after = readBoxText(box);
370
+ if (after === before) return;
371
+ before = after;
372
+ original = [...box.childNodes].map(n => n.cloneNode(true));
373
+ onCommit(after);
374
+ });
375
+ outlineBox(box);
376
+ return { before };
377
+ }
@@ -0,0 +1,13 @@
1
+ // core/load.js 타입 (편집기 자동완성 · 테스트용)
2
+ import type { OpenedDocument } from './pdf.js';
3
+
4
+ export declare class FetchError extends Error {
5
+ status: number;
6
+ constructor(message: string, status: number);
7
+ }
8
+ export declare function fetchBytes(url: string, fetchImpl?: typeof fetch): Promise<Uint8Array>;
9
+ export declare function openDocument(
10
+ kind: 'pdf' | 'pptx',
11
+ source: Uint8Array | string,
12
+ opts?: { prefetch?: boolean }
13
+ ): Promise<OpenedDocument>;