@eliceio/cdk-cli 1.3.0-contenttypes.0 → 1.3.0-contenttypes.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -23
- package/es/cli.js +1 -1
- package/es/commands/create/index.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/doctor/index.js +6 -2
- package/es/core/config.d.ts +22 -0
- package/es/core/config.js +165 -1
- package/es/dev/assets.d.ts +80 -0
- package/es/dev/assets.js +240 -0
- package/es/dev/grading.d.ts +42 -26
- package/es/dev/grading.js +88 -39
- package/es/dev/host-page.js +26 -2
- package/es/dev/inject.d.ts +2 -1
- package/es/dev/inject.js +10 -2
- package/es/dev/mock-api.d.ts +23 -2
- package/es/dev/mock-api.js +210 -40
- package/es/dev/server.d.ts +12 -1
- package/es/dev/server.js +115 -9
- package/es/rules.json.js +1 -1
- package/package.json +2 -2
- package/rules.json +3 -3
- package/skills/_shared/references/02-design-the-material.md +1 -1
- package/skills/_shared/references/03-create-the-project.md +9 -8
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/05-screen-code.md +22 -20
- package/skills/_shared/references/06-using-the-quiz-template.md +6 -4
- package/skills/_shared/references/08-fix-check-errors.md +1 -1
- package/skills/_shared/references/09-check.md +1 -0
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +17 -0
- package/templates/_shared/lib/cdk-mock.js +212 -7
- package/templates/_shared/lib/elice-content.d.ts +61 -1
- package/templates/_shared/lib/elice-content.js +317 -10
- package/templates/blank/README.md +1 -1
- package/templates/blank/screens/instructor.js +8 -2
- package/templates/blank/screens/learn.js +1 -1
- package/templates/blank/template.json +1 -1
- package/templates/document/README.md +92 -0
- package/templates/document/commentary.txt +2 -0
- package/templates/document/core/dom.d.ts +13 -0
- package/templates/document/core/dom.js +83 -0
- package/templates/document/core/file-type.d.ts +21 -0
- package/templates/document/core/file-type.js +85 -0
- package/templates/document/core/group-3d.d.ts +20 -0
- package/templates/document/core/group-3d.js +256 -0
- package/templates/document/core/inline-edit.d.ts +15 -0
- package/templates/document/core/inline-edit.js +377 -0
- package/templates/document/core/load.d.ts +13 -0
- package/templates/document/core/load.js +40 -0
- package/templates/document/core/pdf-options.d.ts +9 -0
- package/templates/document/core/pdf-options.js +36 -0
- package/templates/document/core/pdf-worker.d.ts +24 -0
- package/templates/document/core/pdf-worker.js +122 -0
- package/templates/document/core/pdf.d.ts +12 -0
- package/templates/document/core/pdf.js +190 -0
- package/templates/document/core/pptx-edit.d.ts +14 -0
- package/templates/document/core/pptx-edit.js +137 -0
- package/templates/document/core/pptx-fonts.d.ts +5 -0
- package/templates/document/core/pptx-fonts.js +115 -0
- package/templates/document/core/pptx-media.d.ts +18 -0
- package/templates/document/core/pptx-media.js +83 -0
- package/templates/document/core/pptx-view.d.ts +5 -0
- package/templates/document/core/pptx-view.js +185 -0
- package/templates/document/core/settings.d.ts +25 -0
- package/templates/document/core/settings.js +86 -0
- package/templates/document/core/slide-edges.d.ts +3 -0
- package/templates/document/core/slide-edges.js +82 -0
- package/templates/document/core/viewer.d.ts +28 -0
- package/templates/document/core/viewer.js +159 -0
- package/templates/document/edit.html +17 -0
- package/templates/document/gitignore +4 -0
- package/templates/document/index.html +18 -0
- package/templates/document/metadata.json +9 -0
- package/templates/document/package.json +17 -0
- package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
- package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
- package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
- package/templates/document/screens/edit.js +574 -0
- package/templates/document/screens/learn.js +61 -0
- package/templates/document/styles.css +644 -0
- package/templates/document/template.json +13 -0
- package/templates/document/ui/templates/edit.js +82 -0
- package/templates/document/ui/templates/page.js +11 -0
- package/templates/document/ui/templates/viewer.js +41 -0
- package/templates/document/ui/texts.d.ts +3 -0
- package/templates/document/ui/texts.js +62 -0
- package/templates/document/ui/theme.css +69 -0
- package/templates/quiz/README.md +16 -12
- package/templates/quiz/core/behaviors.d.ts +4 -0
- package/templates/quiz/core/behaviors.js +4 -2
- package/templates/quiz/core/editor.d.ts +17 -2
- package/templates/quiz/core/editor.js +85 -10
- package/templates/quiz/core/markdown.d.ts +15 -0
- package/templates/quiz/core/markdown.js +164 -4
- package/templates/quiz/core/model.d.ts +53 -9
- package/templates/quiz/core/model.js +384 -41
- package/templates/quiz/core/rich-text.d.ts +1 -2
- package/templates/quiz/core/rich-text.js +7 -59
- package/templates/quiz/public/img/mascot-half.webp +0 -0
- package/templates/quiz/screens/edit.js +403 -126
- package/templates/quiz/screens/learn.js +106 -40
- package/templates/quiz/styles.css +584 -4
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/edit.d.ts +3 -0
- package/templates/quiz/ui/templates/edit.js +113 -11
- package/templates/quiz/ui/templates/page.js +14 -0
- package/templates/quiz/ui/templates/question.js +5 -3
- package/templates/quiz/ui/texts.js +89 -26
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// 작은 DOM 도우미 (퀴즈 템플릿 core/dom.js와 같음). ui/templates/*는 html`…`로 마크업을 쓰고, 동작은 data-role로 그 안의 요소를 찾습니다.
|
|
2
|
+
|
|
3
|
+
/** 조건부로 넣은 null · undefined · false 빼기 */
|
|
4
|
+
export const present = (nodes) => nodes.filter((c) => c !== null && c !== undefined && c !== false);
|
|
5
|
+
|
|
6
|
+
export function el(tag, props = {}, ...children) {
|
|
7
|
+
const node = Object.assign(document.createElement(tag), props);
|
|
8
|
+
node.append(...present(children));
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const escape = (s) =>
|
|
13
|
+
s
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
|
|
20
|
+
const MARK = 'dc-node:';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HTML 조각 템플릿. 끼워 넣는 값은
|
|
24
|
+
* 글자 · 숫자 → 이스케이프해서 글자로 (교육자 · 학생이 쓴 내용도 안전)
|
|
25
|
+
* 요소(Node) · 배열 → 그 자리에 그대로 (태그 사이에만, 속성 값에는 글자만)
|
|
26
|
+
* null · undefined · false → 아무것도 넣지 않음 (`${cond && '…'}`)
|
|
27
|
+
* 줄바꿈이 든 앞뒤 공백은 지우므로 들여쓰기를 자유롭게 해도 됩니다 (한 줄 안의 공백은 그대로).
|
|
28
|
+
* 최상위 요소가 하나면 그 요소를, 아니면 DocumentFragment를 돌려준다.
|
|
29
|
+
*/
|
|
30
|
+
export function html(strings, ...values) {
|
|
31
|
+
const nodes = [];
|
|
32
|
+
const part = (v) => {
|
|
33
|
+
if (v === null || v === undefined || v === false) return '';
|
|
34
|
+
if (Array.isArray(v)) return v.map(part).join('');
|
|
35
|
+
if (typeof Node !== 'undefined' && v instanceof Node) {
|
|
36
|
+
nodes.push(v);
|
|
37
|
+
return `<!--${MARK}${nodes.length - 1}-->`;
|
|
38
|
+
}
|
|
39
|
+
return escape(String(v));
|
|
40
|
+
};
|
|
41
|
+
const markup = strings.reduce((out, s, i) => out + part(values[i - 1]) + s);
|
|
42
|
+
const template = document.createElement('template');
|
|
43
|
+
// 끼워 넣는 값은 모두 위에서 이스케이프하거나 주석 자리표로 바꾼다 (퀴즈 quiz.test.ts 'html 템플릿'에서 확인)
|
|
44
|
+
// ecdk-ignore-next-line sec.html-injection
|
|
45
|
+
template.innerHTML = markup.trim();
|
|
46
|
+
const walker = document.createTreeWalker(
|
|
47
|
+
template.content,
|
|
48
|
+
NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,
|
|
49
|
+
);
|
|
50
|
+
const swap = [];
|
|
51
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) swap.push(n);
|
|
52
|
+
for (const n of swap) {
|
|
53
|
+
if (n.nodeType === Node.COMMENT_NODE && n.data.startsWith(MARK))
|
|
54
|
+
n.replaceWith(nodes[Number(n.data.slice(MARK.length))]);
|
|
55
|
+
else if (n.nodeType === Node.TEXT_NODE) {
|
|
56
|
+
// 들여쓰기: 줄바꿈이 든 앞뒤 공백은 지우고, 그것만 있는 글자 노드는 뺀다 (JSX와 같은 규칙)
|
|
57
|
+
const data = n.data.replace(/^\s*\n\s*/, '').replace(/\s*\n\s*$/, '');
|
|
58
|
+
if (data === '') n.remove();
|
|
59
|
+
else if (data !== n.data) n.data = data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const fragment = template.content;
|
|
63
|
+
return fragment.childNodes.length === 1 && fragment.firstChild instanceof Element
|
|
64
|
+
? fragment.firstChild
|
|
65
|
+
: fragment;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** root 자신이나 그 안에서 data-role="name"인 첫 요소 */
|
|
69
|
+
export function part(root, name) {
|
|
70
|
+
const selector = `[data-role="${name}"]`;
|
|
71
|
+
return root.matches?.(selector) ? root : root.querySelector(selector);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** root 안의 data-role="name"인 모든 요소 */
|
|
75
|
+
export const parts = (root, name) => [...root.querySelectorAll(`[data-role="${name}"]`)];
|
|
76
|
+
|
|
77
|
+
/** 읽기 전용(교육자 · 튜터링)일 때 root와 그 안의 입력 · 버튼을 모두 막는다 */
|
|
78
|
+
export function lock(root) {
|
|
79
|
+
if ('disabled' in root) root.disabled = true;
|
|
80
|
+
for (const c of root.querySelectorAll('input, textarea, select, button, fieldset'))
|
|
81
|
+
c.disabled = true;
|
|
82
|
+
return root;
|
|
83
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// core/file-type.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export type DocumentKind = 'pdf' | 'pptx';
|
|
3
|
+
export declare const DOCUMENT_KINDS: Readonly<Record<string, DocumentKind>>;
|
|
4
|
+
export declare const ACCEPTED_EXTENSIONS: readonly string[];
|
|
5
|
+
export declare const CONVERT_EXTENSIONS: readonly string[];
|
|
6
|
+
export declare const DOCUMENT_MIME: Readonly<Record<DocumentKind, string>>;
|
|
7
|
+
export declare const SNIFF_BYTES: number;
|
|
8
|
+
export declare function extensionOf(name: string): string;
|
|
9
|
+
export declare function sniff(head: Uint8Array): 'pdf' | 'zip-pptx' | 'zip' | 'ole' | 'unknown';
|
|
10
|
+
export type FileCheck =
|
|
11
|
+
| { ok: true; kind: DocumentKind; type: string }
|
|
12
|
+
| {
|
|
13
|
+
ok: false;
|
|
14
|
+
reason: 'empty' | 'too-large' | 'convert' | 'unsupported' | 'mismatch';
|
|
15
|
+
ext: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function checkDocumentFile(
|
|
18
|
+
file: { name: string; size: number; head: Uint8Array },
|
|
19
|
+
limits: { maxBytes: number }
|
|
20
|
+
): FileCheck;
|
|
21
|
+
export declare function kindOf(doc?: { type?: string; name?: string }): DocumentKind | null;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// 문서 파일 형식 알아보기 (고치지 않습니다). 편집 화면이 고른 파일을 올리기 전에 이름(확장자)과 첫 바이트로 확인합니다.
|
|
2
|
+
//
|
|
3
|
+
// 이번 버전은 .pdf · .pptx만 받습니다. 옛 형식(.ppt · .pps)과 쇼 형식(.ppsx)은 브라우저에서 읽지 못하거나
|
|
4
|
+
// 편집 · 저장 경로가 달라 받지 않고, .pptx · .pdf로 바꿔 올리라고 안내합니다 (서버 변환은 다음 단계).
|
|
5
|
+
|
|
6
|
+
/** 받는 형식: 확장자 → 종류 */
|
|
7
|
+
export const DOCUMENT_KINDS = Object.freeze({ pdf: 'pdf', pptx: 'pptx' });
|
|
8
|
+
|
|
9
|
+
/** 받는 확장자 (파일 고르기 accept · 안내 문구) */
|
|
10
|
+
export const ACCEPTED_EXTENSIONS = Object.freeze(Object.keys(DOCUMENT_KINDS));
|
|
11
|
+
|
|
12
|
+
/** 알아보지만 받지 않는 발표 자료 형식 (바꿔 올리라는 안내) */
|
|
13
|
+
export const CONVERT_EXTENSIONS = Object.freeze(['ppt', 'pps', 'ppsx']);
|
|
14
|
+
|
|
15
|
+
/** 종류 → 올릴 때 Content-Type */
|
|
16
|
+
export const DOCUMENT_MIME = Object.freeze({
|
|
17
|
+
pdf: 'application/pdf',
|
|
18
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** 형식 확인에 읽는 앞부분 길이 (바이트) */
|
|
22
|
+
export const SNIFF_BYTES = 4096;
|
|
23
|
+
|
|
24
|
+
/** 파일 이름의 확장자 (소문자, 점 없이). 없으면 '' */
|
|
25
|
+
export function extensionOf(name) {
|
|
26
|
+
const m = /\.([A-Za-z0-9]+)$/.exec(String(name ?? '').trim());
|
|
27
|
+
return m ? m[1].toLowerCase() : '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const startsWith = (bytes, sig) => sig.every((b, i) => bytes[i] === b);
|
|
31
|
+
const PDF_SIG = [0x25, 0x50, 0x44, 0x46, 0x2d]; // %PDF-
|
|
32
|
+
const ZIP_SIG = [0x50, 0x4b, 0x03, 0x04]; // PK\3\4
|
|
33
|
+
const OLE_SIG = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]; // 옛 Office(.ppt · .pps)
|
|
34
|
+
|
|
35
|
+
/** 바이트 안에 글자(ASCII)가 있는지 */
|
|
36
|
+
function hasAscii(bytes, text) {
|
|
37
|
+
const codes = [...text].map(c => c.charCodeAt(0));
|
|
38
|
+
outer: for (let i = 0; i + codes.length <= bytes.length; i += 1) {
|
|
39
|
+
for (let j = 0; j < codes.length; j += 1) if (bytes[i + j] !== codes[j]) continue outer;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 첫 바이트로 본 실제 형식: 'pdf' · 'zip-pptx'(zip이고 ppt/ 항목 이름이 보임) · 'zip' · 'ole' · 'unknown'.
|
|
47
|
+
* PDF는 앞 1KB 안 어디서든 %PDF-로 시작할 수 있어(앞에 쓰레기 바이트) 그 안을 찾는다
|
|
48
|
+
* @param {Uint8Array} head 파일 앞부분 (SNIFF_BYTES 정도)
|
|
49
|
+
*/
|
|
50
|
+
export function sniff(head) {
|
|
51
|
+
if (!(head instanceof Uint8Array) || head.length === 0) return 'unknown';
|
|
52
|
+
if (startsWith(head, ZIP_SIG)) return hasAscii(head, 'ppt/') ? 'zip-pptx' : 'zip';
|
|
53
|
+
if (startsWith(head, OLE_SIG)) return 'ole';
|
|
54
|
+
if (hasAscii(head.subarray(0, 1024), '%PDF-')) return 'pdf';
|
|
55
|
+
return 'unknown';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 고른 파일을 받을지 정한다. 크기 · 이름 · 앞부분 바이트만 본다 (파일 전체를 열어 보는 것은 편집 화면이 따로).
|
|
60
|
+
* @param {{ name: string, size: number, head: Uint8Array }} file
|
|
61
|
+
* @param {{ maxBytes: number }} limits
|
|
62
|
+
* @returns {{ ok: true, kind: 'pdf' | 'pptx', type: string }
|
|
63
|
+
* | { ok: false, reason: 'empty' | 'too-large' | 'convert' | 'unsupported' | 'mismatch', ext: string }}
|
|
64
|
+
*/
|
|
65
|
+
export function checkDocumentFile({ name, size, head }, { maxBytes }) {
|
|
66
|
+
const ext = extensionOf(name);
|
|
67
|
+
if (CONVERT_EXTENSIONS.includes(ext)) return { ok: false, reason: 'convert', ext };
|
|
68
|
+
const kind = DOCUMENT_KINDS[ext];
|
|
69
|
+
if (!kind) return { ok: false, reason: 'unsupported', ext };
|
|
70
|
+
if (!(size > 0)) return { ok: false, reason: 'empty', ext };
|
|
71
|
+
if (size > maxBytes) return { ok: false, reason: 'too-large', ext };
|
|
72
|
+
const real = sniff(head);
|
|
73
|
+
// 이름만 .pptx로 바꾼 옛 .ppt(OLE)는 바꿔 올리라고 안내
|
|
74
|
+
if (kind === 'pptx' && real === 'ole') return { ok: false, reason: 'convert', ext };
|
|
75
|
+
const matches = kind === 'pdf' ? real === 'pdf' : real === 'zip-pptx' || real === 'zip';
|
|
76
|
+
if (!matches) return { ok: false, reason: 'mismatch', ext };
|
|
77
|
+
return { ok: true, kind, type: DOCUMENT_MIME[kind] };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 저장된 종류 · 이름 · MIME에서 종류 ('pdf' · 'pptx'). 모르면 null */
|
|
81
|
+
export function kindOf({ type = '', name = '' } = {}) {
|
|
82
|
+
if (type === 'pdf' || type === DOCUMENT_MIME.pdf) return 'pdf';
|
|
83
|
+
if (type === 'pptx' || type === DOCUMENT_MIME.pptx) return 'pptx';
|
|
84
|
+
return DOCUMENT_KINDS[extensionOf(name)] ?? null;
|
|
85
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// core/group-3d.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare const MATCH_PX: number;
|
|
3
|
+
export declare const ISOMETRIC_CAMERAS: Record<string, [number, number, number]>;
|
|
4
|
+
export declare function cameraMatrix(lat: number, lon: number, rev: number): [number, number, number, number];
|
|
5
|
+
export interface CameraGroup {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
w: number;
|
|
9
|
+
h: number;
|
|
10
|
+
matrix: [number, number, number, number];
|
|
11
|
+
}
|
|
12
|
+
export declare function findCameraGroups(xml: string): CameraGroup[];
|
|
13
|
+
export declare function applyGroupCameras(slide: HTMLElement, groups: CameraGroup[]): number;
|
|
14
|
+
export declare function createGroupCameras(files: {
|
|
15
|
+
slides?: Map<string, string>;
|
|
16
|
+
slideRels?: Map<string, string>;
|
|
17
|
+
slideLayouts?: Map<string, string>;
|
|
18
|
+
slideLayoutRels?: Map<string, string>;
|
|
19
|
+
slideMasters?: Map<string, string>;
|
|
20
|
+
}): { apply(slide: HTMLElement, slidePath: string | undefined): number };
|
|
@@ -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 };
|