@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.
- package/README.md +63 -53
- package/es/cli.js +11 -2
- package/es/commands/build/index.js +12 -0
- package/es/commands/create/index.js +2 -0
- package/es/commands/create/scaffold.d.ts +2 -2
- package/es/commands/create/scaffold.js +3 -3
- package/es/commands/dev/index.d.ts +10 -1
- package/es/commands/dev/index.js +47 -7
- package/es/commands/doctor/index.js +6 -2
- package/es/core/config.d.ts +42 -9
- package/es/core/config.js +217 -12
- package/es/core/project-check.d.ts +3 -2
- package/es/core/project-check.js +14 -3
- package/es/core/regex.d.ts +11 -0
- package/es/core/regex.js +41 -0
- package/es/core/sandbox.d.ts +26 -0
- package/es/core/sandbox.js +240 -30
- package/es/dev/assets.d.ts +80 -0
- package/es/dev/assets.js +240 -0
- package/es/dev/check.d.ts +30 -0
- package/es/dev/check.js +224 -34
- package/es/dev/grading.d.ts +49 -14
- package/es/dev/grading.js +109 -29
- package/es/dev/host-page.js +27 -3
- package/es/dev/inject.d.ts +2 -1
- package/es/dev/inject.js +10 -2
- package/es/dev/mock-api.d.ts +26 -3
- package/es/dev/mock-api.js +219 -40
- package/es/dev/server.d.ts +12 -1
- package/es/dev/server.js +115 -9
- package/es/engines/vite/index.js +1 -1
- package/es/engines/vite/plugin.d.ts +2 -0
- package/es/engines/vite/plugin.js +33 -5
- package/es/rules/answers.d.ts +13 -0
- package/es/rules/answers.js +94 -0
- package/es/rules/check.js +70 -1
- package/es/rules/index.d.ts +1 -0
- package/es/rules/index.js +1 -0
- package/es/rules/size.d.ts +31 -0
- package/es/rules/size.js +58 -0
- package/es/rules/types.d.ts +12 -0
- package/es/rules.json.js +2 -2
- package/package.json +2 -2
- package/rules.json +34 -5
- package/skills/_shared/always.md +3 -3
- package/skills/_shared/references/00-what-the-person-decides.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +10 -7
- package/skills/_shared/references/03-create-the-project.md +10 -8
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/05-screen-code.md +52 -23
- package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
- package/skills/_shared/references/08-fix-check-errors.md +23 -22
- package/skills/_shared/references/09-check.md +8 -6
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
- package/skills/_shared/references/13-edit-screen-design.md +122 -0
- package/skills/_shared/references/14-layouts.md +96 -0
- package/skills/elice-content-check/SKILL.md +2 -2
- package/skills/elice-content-create/SKILL.md +1 -1
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +47 -3
- package/templates/_shared/lib/cdk-mock.js +293 -15
- package/templates/_shared/lib/elice-content-editor.js +89 -58
- package/templates/_shared/lib/elice-content.css +1313 -126
- package/templates/_shared/lib/elice-content.d.ts +222 -23
- package/templates/_shared/lib/elice-content.js +1176 -88
- package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
- package/templates/_shared/lib/icons/empty-content.js +11 -0
- package/templates/_shared/lib/icons/file-video.d.ts +2 -0
- package/templates/_shared/lib/icons/file-video.js +11 -0
- package/templates/_shared/lib/icons/file.d.ts +2 -0
- package/templates/_shared/lib/icons/file.js +11 -0
- package/templates/blank/README.md +6 -4
- package/templates/blank/edit.html +8 -2
- package/templates/blank/index.html +6 -1
- package/templates/blank/instructor.html +6 -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 +6 -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 +32 -14
- package/templates/quiz/core/behaviors.d.ts +17 -7
- package/templates/quiz/core/behaviors.js +40 -53
- package/templates/quiz/core/editor.d.ts +27 -2
- package/templates/quiz/core/editor.js +412 -11
- package/templates/quiz/core/markdown.d.ts +19 -0
- package/templates/quiz/core/markdown.js +225 -11
- package/templates/quiz/core/model.d.ts +40 -3
- package/templates/quiz/core/model.js +112 -5
- package/templates/quiz/core/rich-text.d.ts +18 -0
- package/templates/quiz/core/rich-text.js +469 -0
- package/templates/quiz/edit.html +12 -3
- package/templates/quiz/index.html +12 -3
- package/templates/quiz/public/img/mascot-half.webp +0 -0
- package/templates/quiz/screens/edit.js +331 -49
- package/templates/quiz/screens/learn.js +147 -15
- package/templates/quiz/styles.css +1244 -622
- package/templates/quiz/template.json +9 -2
- package/templates/quiz/ui/templates/edit.d.ts +19 -5
- package/templates/quiz/ui/templates/edit.js +371 -77
- package/templates/quiz/ui/templates/group.js +19 -8
- package/templates/quiz/ui/templates/order.js +25 -24
- package/templates/quiz/ui/templates/page.js +33 -8
- package/templates/quiz/ui/templates/question.js +6 -4
- package/templates/quiz/ui/texts.js +91 -26
- package/templates/quiz/ui/theme.css +8 -9
- package/templates/steps/README.md +77 -0
- package/templates/steps/commentary.txt +7 -0
- package/templates/steps/edit.html +21 -0
- package/templates/steps/gitignore +4 -0
- package/templates/steps/index.html +69 -0
- package/templates/steps/metadata.json +9 -0
- package/templates/steps/package.json +13 -0
- package/templates/steps/screens/edit.js +32 -0
- package/templates/steps/screens/learn.js +108 -0
- package/templates/steps/styles.css +54 -0
- package/templates/steps/template.json +6 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// 문서 불러오기 (고치지 않습니다): 저장된 주소에서 파일 바이트를 받고, 종류에 맞는 그리기 모듈로 엽니다.
|
|
2
|
+
// PDF · PPTX 모듈은 필요할 때만 불러온다 (import()): 둘 다 묶여 들어가지만 쓰지 않는 쪽은 실행하지 않는다.
|
|
3
|
+
|
|
4
|
+
/** 파일을 받지 못함 (주소 · 권한 · 콘텐츠 CSP connect-src) */
|
|
5
|
+
export class FetchError extends Error {
|
|
6
|
+
constructor(message, status) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'FetchError';
|
|
9
|
+
this.status = status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 올린 파일 바이트 (주소는 await app.assets.url(asset_key) = asset_base_url + assets/{자료 id}/{asset_key}, 자료 API 출처의 서명 경로).
|
|
15
|
+
* 운영 콘텐츠 CSP의 connect-src는 지금 material API뿐이라 콘텐츠 출처 fetch가 막힌다 (서버에 connect-src 추가 요청).
|
|
16
|
+
* ecdk dev는 그 경로만 dev CSP에 더해 둔다
|
|
17
|
+
* @param {string} url
|
|
18
|
+
* @param {typeof fetch} [fetchImpl] 테스트용
|
|
19
|
+
*/
|
|
20
|
+
export async function fetchBytes(url, fetchImpl = globalThis.fetch) {
|
|
21
|
+
let res;
|
|
22
|
+
try {
|
|
23
|
+
res = await fetchImpl(url);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new FetchError(String(e?.message ?? e), 0);
|
|
26
|
+
}
|
|
27
|
+
if (!res.ok) throw new FetchError(`HTTP ${res.status}`, res.status);
|
|
28
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {'pdf' | 'pptx'} kind
|
|
33
|
+
* @param {Uint8Array | string} source 바이트, 또는 주소 (PDF는 pdf.js가 Range로 필요한 부분만 받음, PPTX는 전체를 받음)
|
|
34
|
+
* @param {{ prefetch?: boolean }} [opts] PDF 주소: 첫 쪽 뒤 나머지를 미리 받기 (편집 화면, core/pdf-options.js)
|
|
35
|
+
*/
|
|
36
|
+
export async function openDocument(kind, source, opts) {
|
|
37
|
+
if (kind === 'pdf') return (await import('./pdf.js')).openPdf(source, opts);
|
|
38
|
+
const bytes = typeof source === 'string' ? await fetchBytes(source) : source;
|
|
39
|
+
return (await import('./pptx-view.js')).openPptx(bytes);
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// core/pdf-options.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare const RANGE_CHUNK_BYTES: number;
|
|
3
|
+
export declare function pdfSourceOptions(
|
|
4
|
+
source: Uint8Array | string,
|
|
5
|
+
opts?: { prefetch?: boolean }
|
|
6
|
+
):
|
|
7
|
+
| { data: Uint8Array }
|
|
8
|
+
| { url: string; rangeChunkSize: number; disableStream: true; disableAutoFetch: boolean };
|
|
9
|
+
export declare function isExpiredSource(e: unknown): boolean;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// pdf.js 여는 옵션 (고치지 않습니다). core/pdf.js가 씁니다 (테스트가 pdf.js 없이 확인하려고 따로 둠).
|
|
2
|
+
//
|
|
3
|
+
// 주소로 열 때 (서버가 Range 응답 헤더를 내보내면 pdf.js가 Range로 받는다):
|
|
4
|
+
// - disableStream: 첫 요청(Range 없음)은 크기 · Range 지원만 보고 끊는다. 켜 두면 그 응답으로 파일 전체를 받으면서
|
|
5
|
+
// Range 요청도 해서 같은 바이트를 두 번 받는다
|
|
6
|
+
// - 학생 화면(기본): 보는 쪽만 그때그때 받는다 (disableAutoFetch). 서명 주소는 6시간 유효(발행 버전)라 그 뒤 넘긴
|
|
7
|
+
// 쪽은 받지 못할 수 있다 → 화면이 "문서 주소가 만료됐어요"를 보인다 (screens/learn.js)
|
|
8
|
+
// - 편집 화면(prefetch): 첫 쪽을 보인 뒤 나머지를 뒤에서 모두 받는다. 초안 서명 주소는 1시간 유효라 그 안에 다 받아 둔다
|
|
9
|
+
|
|
10
|
+
/** 주소로 열 때 한 번에 받는 크기 (Range). 큰 PDF도 첫 쪽부터 빨리 보이게 */
|
|
11
|
+
export const RANGE_CHUNK_BYTES = 256 * 1024;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Uint8Array | string} source 바이트, 또는 주소
|
|
15
|
+
* @param {{ prefetch?: boolean }} [opts] prefetch: 첫 쪽 뒤 나머지를 미리 받기 (편집 화면)
|
|
16
|
+
*/
|
|
17
|
+
export function pdfSourceOptions(source, opts = {}) {
|
|
18
|
+
if (typeof source !== 'string')
|
|
19
|
+
// pdf.js가 바이트를 작업자로 넘기며 비우므로 사본을 준다 (편집 화면이 같은 바이트를 다시 쓸 수 있게)
|
|
20
|
+
return { data: source.slice() };
|
|
21
|
+
return {
|
|
22
|
+
url: source,
|
|
23
|
+
rangeChunkSize: RANGE_CHUNK_BYTES,
|
|
24
|
+
disableStream: true,
|
|
25
|
+
disableAutoFetch: !opts.prefetch,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 서명 주소가 만료되어 받지 못한 것인지 (pdf.js UnexpectedResponseException · 받기 오류의 HTTP 상태 401 · 403 · 410)
|
|
31
|
+
* @param {unknown} e
|
|
32
|
+
*/
|
|
33
|
+
export function isExpiredSource(e) {
|
|
34
|
+
const status = e?.status ?? Number(/\((\d{3})\)/.exec(String(e?.message ?? ''))?.[1]);
|
|
35
|
+
return status === 401 || status === 403 || status === 410;
|
|
36
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// core/pdf-worker.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare const WORKER_READY_MS: number;
|
|
3
|
+
export declare function toClassicWorker(code: string): string;
|
|
4
|
+
export declare function withTimeout<T>(
|
|
5
|
+
promise: Promise<T>,
|
|
6
|
+
ms: number,
|
|
7
|
+
message: string,
|
|
8
|
+
onTimeout?: () => void
|
|
9
|
+
): Promise<T>;
|
|
10
|
+
export declare function workerUrl(classicCode: string): string;
|
|
11
|
+
export declare function startClassicWorker(
|
|
12
|
+
classicCode: string,
|
|
13
|
+
env?: { Worker?: typeof Worker; timeoutMs?: number; url?: string }
|
|
14
|
+
): Promise<Worker | null>;
|
|
15
|
+
export declare function loadMainThreadWorker(classicCode: string): boolean;
|
|
16
|
+
export declare function preparePdfWorker(
|
|
17
|
+
code: string,
|
|
18
|
+
env?: {
|
|
19
|
+
Worker?: typeof Worker;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
url?: string;
|
|
22
|
+
loadMainThread?: (code: string) => boolean;
|
|
23
|
+
}
|
|
24
|
+
): Promise<{ port: Worker | null }>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// pdf.js 작업자(worker) 띄우기 (고치지 않습니다). core/pdf.js가 씁니다.
|
|
2
|
+
//
|
|
3
|
+
// LXP 콘텐츠는 출처가 null인 sandbox iframe에서 돕니다(서버 CSP `sandbox allow-scripts`). 그 안에서는
|
|
4
|
+
// new Worker(blob:, { type: 'module' })가 실패하고(error) 일반(classic) blob 작업자는 됩니다. 그래서:
|
|
5
|
+
// 1. pdf.js 작업자 코드(ES 모듈)를 일반 스크립트로 바꿔 blob 작업자로 띄운다 (toClassicWorker)
|
|
6
|
+
// 2. 작업자가 첫 메시지(ready)를 보내지 않고 실패하거나 시간 안에 답이 없으면, 작업자 없이 화면 스레드에서
|
|
7
|
+
// 돌린다 (pdf.js "fake worker": 같은 코드를 <script>로 실행하면 globalThis.pdfjsWorker가 생김)
|
|
8
|
+
// 3. 그래도 안 되면 오류를 던져 화면이 "열지 못했어요"를 보인다 (멈춰 있지 않게)
|
|
9
|
+
|
|
10
|
+
/** 작업자가 첫 메시지를 보낼 때까지 기다리는 시간 */
|
|
11
|
+
export const WORKER_READY_MS = 5000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* pdf.js 작업자 ES 모듈 코드 → 일반 스크립트 코드: 끝의 `export { … }`를 빼고, 모듈 주소(import 메타의 url)는
|
|
15
|
+
* 스크립트 주소(self.location.href)로 (wasm 디코더가 기준 주소로만 쓰고 실패해도 넘어감)
|
|
16
|
+
* @param {string} code
|
|
17
|
+
*/
|
|
18
|
+
export function toClassicWorker(code) {
|
|
19
|
+
return code
|
|
20
|
+
.replace(/export\s*\{[^}]*\}\s*;?\s*$/, '')
|
|
21
|
+
// 정규식으로 적는다: 글자 그대로 쓰면 빌드(Vite)가 그 글자를 파일 주소로 바꿔 버린다
|
|
22
|
+
.replace(/\bimport\.meta\.url\b/g, 'self.location.href');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* promise가 ms 안에 끝나지 않으면 onTimeout()을 부르고 오류로 끝낸다
|
|
27
|
+
* @template T
|
|
28
|
+
* @param {Promise<T>} promise
|
|
29
|
+
* @param {number} ms
|
|
30
|
+
* @param {string} message
|
|
31
|
+
* @param {() => void} [onTimeout]
|
|
32
|
+
* @returns {Promise<T>}
|
|
33
|
+
*/
|
|
34
|
+
export function withTimeout(promise, ms, message, onTimeout) {
|
|
35
|
+
let timer = 0;
|
|
36
|
+
const timeout = new Promise((_, reject) => {
|
|
37
|
+
timer = setTimeout(
|
|
38
|
+
() => {
|
|
39
|
+
onTimeout?.();
|
|
40
|
+
reject(new Error(message));
|
|
41
|
+
},
|
|
42
|
+
ms
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 일반 스크립트 작업자 코드의 blob: 주소. 페이지에서 한 번만 만든다 (core/pdf.js가 모듈을 읽을 때)
|
|
50
|
+
* @param {string} classicCode
|
|
51
|
+
*/
|
|
52
|
+
export const workerUrl = classicCode =>
|
|
53
|
+
URL.createObjectURL(new Blob([classicCode], { type: 'text/javascript' }));
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 일반 blob 작업자를 띄우고 첫 메시지를 기다린다. 되면 작업자, 아니면 null (만든 작업자는 닫음)
|
|
57
|
+
* @param {string} classicCode
|
|
58
|
+
* @param {{ Worker?: typeof Worker, timeoutMs?: number, url?: string }} [env] url: 미리 만든 blob: 주소 (없으면 만듦)
|
|
59
|
+
* @returns {Promise<Worker | null>}
|
|
60
|
+
*/
|
|
61
|
+
export async function startClassicWorker(classicCode, env = {}) {
|
|
62
|
+
const WorkerClass = env.Worker ?? globalThis.Worker;
|
|
63
|
+
if (typeof WorkerClass !== 'function') return null;
|
|
64
|
+
const url = env.url ?? workerUrl(classicCode);
|
|
65
|
+
let worker;
|
|
66
|
+
try {
|
|
67
|
+
worker = new WorkerClass(url);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.warn('[document] PDF 작업자를 띄우지 못해 작업자 없이 엽니다', e);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const ready = await new Promise(resolve => {
|
|
73
|
+
const done = ok => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
worker.removeEventListener('message', onMessage);
|
|
76
|
+
worker.removeEventListener('error', onError);
|
|
77
|
+
resolve(ok);
|
|
78
|
+
};
|
|
79
|
+
const onMessage = () => done(true);
|
|
80
|
+
const onError = e => {
|
|
81
|
+
e.preventDefault?.();
|
|
82
|
+
done(false);
|
|
83
|
+
};
|
|
84
|
+
const timer = setTimeout(
|
|
85
|
+
() => done(false),
|
|
86
|
+
env.timeoutMs ?? WORKER_READY_MS
|
|
87
|
+
);
|
|
88
|
+
worker.addEventListener('message', onMessage);
|
|
89
|
+
worker.addEventListener('error', onError);
|
|
90
|
+
});
|
|
91
|
+
if (ready) return worker;
|
|
92
|
+
console.warn('[document] PDF 작업자가 답하지 않아 작업자 없이 엽니다');
|
|
93
|
+
worker.terminate();
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 작업자 없이(화면 스레드) 돌릴 준비: 작업자 코드를 <script>로 실행해 globalThis.pdfjsWorker를 만든다.
|
|
99
|
+
* 되면 true
|
|
100
|
+
* @param {string} classicCode
|
|
101
|
+
*/
|
|
102
|
+
export function loadMainThreadWorker(classicCode) {
|
|
103
|
+
if (globalThis.pdfjsWorker?.WorkerMessageHandler) return true;
|
|
104
|
+
const script = document.createElement('script');
|
|
105
|
+
script.textContent = classicCode;
|
|
106
|
+
document.head.append(script);
|
|
107
|
+
script.remove();
|
|
108
|
+
return Boolean(globalThis.pdfjsWorker?.WorkerMessageHandler);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* pdf.js 작업자를 준비한다: 일반 blob 작업자 → 안 되면 작업자 없이. 둘 다 안 되면 오류
|
|
113
|
+
* @param {string} code 일반 스크립트로 바꾼 작업자 코드 (toClassicWorker)
|
|
114
|
+
* @param {{ Worker?: typeof Worker, timeoutMs?: number, url?: string, loadMainThread?: (code: string) => boolean }} [env]
|
|
115
|
+
* @returns {Promise<{ port: Worker | null }>} port가 null이면 pdf.js가 화면 스레드에서 돈다
|
|
116
|
+
*/
|
|
117
|
+
export async function preparePdfWorker(code, env = {}) {
|
|
118
|
+
const port = await startClassicWorker(code, env);
|
|
119
|
+
if (port) return { port };
|
|
120
|
+
if ((env.loadMainThread ?? loadMainThreadWorker)(code)) return { port: null };
|
|
121
|
+
throw new Error('PDF 작업자를 띄우지 못했습니다');
|
|
122
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// core/pdf.js · core/pptx-view.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
import type { ViewerDoc } from './viewer.js';
|
|
3
|
+
|
|
4
|
+
export interface OpenedDocument extends ViewerDoc {
|
|
5
|
+
kind: 'pdf' | 'pptx';
|
|
6
|
+
thumbnails(width: number): Promise<HTMLElement[]>;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function openPdf(
|
|
10
|
+
source: Uint8Array | string,
|
|
11
|
+
opts?: { prefetch?: boolean }
|
|
12
|
+
): Promise<OpenedDocument>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// PDF 그리기 (고치지 않습니다). pdf.js(pdfjs-dist) legacy 빌드로 쪽을 canvas에 그리고, 글자 층(text layer)을 얹어
|
|
2
|
+
// 글자를 고르고 복사할 수 있게 합니다.
|
|
3
|
+
//
|
|
4
|
+
// 콘텐츠 CSP 안에서 돌리려고 pdf.js가 스스로 파일을 받지 않게 했습니다:
|
|
5
|
+
// - legacy 빌드: 최신 빌드는 Firefox 142에서 아직 없는 API(getOrInsertComputed)를 써서 멈춘다
|
|
6
|
+
// - 작업자(worker): 콘텐츠 출처의 파일 작업자는 CSP(worker-src blob:)에 막히므로, 작업자 코드를 번들에 글로 넣고
|
|
7
|
+
// Blob 주소로 띄운다. LXP(출처 null)에서는 모듈 작업자가 실패해 일반(classic) 작업자로 띄우고, 그것도 안 되면
|
|
8
|
+
// 작업자 없이 화면 스레드에서 돌린다 (core/pdf-worker.js). 열기가 오래 멈추면 오류로 끝낸다 (OPEN_TIMEOUT_MS)
|
|
9
|
+
// - 글꼴 · CMap · wasm: connect-src가 material API뿐이라 fetch로 받지 못한다. 번들에 넣은 데이터(data: 주소)를
|
|
10
|
+
// BinaryDataFactory로 넘긴다. CMap은 한국어(Adobe-Korea1 · KSC · UniKS)만 넣어 크기를 줄였다 (Identity-H는 pdf.js 안에 있음).
|
|
11
|
+
// 글꼴을 넣지 않은 중국어 · 일본어 PDF는 글자가 빠질 수 있다
|
|
12
|
+
// - PDF 안 스크립트는 돌리지 않는다 (enableScripting: false, quickjs wasm을 넣지 않음)
|
|
13
|
+
import * as pdfjs from 'pdfjs-dist/legacy/build/pdf.min.mjs';
|
|
14
|
+
import workerCode from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs?raw';
|
|
15
|
+
import { pdfSourceOptions } from './pdf-options.js';
|
|
16
|
+
import { preparePdfWorker, toClassicWorker, withTimeout, workerUrl } from './pdf-worker.js';
|
|
17
|
+
|
|
18
|
+
// 키: pdf.js가 요청하는 데이터 종류. 값: [폴더, 파일 경로 → data: 주소를 주는 함수]
|
|
19
|
+
const BUNDLED = {
|
|
20
|
+
cMapUrl: [
|
|
21
|
+
'cmaps',
|
|
22
|
+
import.meta.glob('/node_modules/pdfjs-dist/cmaps/{Adobe-Korea1-*,KSC*,UniKS-*}.bcmap', {
|
|
23
|
+
query: '?url&inline',
|
|
24
|
+
import: 'default',
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
standardFontDataUrl: [
|
|
28
|
+
'standard_fonts',
|
|
29
|
+
import.meta.glob('/node_modules/pdfjs-dist/standard_fonts/*.{pfb,ttf}', {
|
|
30
|
+
query: '?url&inline',
|
|
31
|
+
import: 'default',
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
wasmUrl: [
|
|
35
|
+
'wasm',
|
|
36
|
+
import.meta.glob('/node_modules/pdfjs-dist/wasm/{openjpeg,jbig2,qcms_bg}.wasm', {
|
|
37
|
+
query: '?url&inline',
|
|
38
|
+
import: 'default',
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const fromDataUrl = (url) => Uint8Array.from(atob(url.slice(url.indexOf(',') + 1)), (c) => c.charCodeAt(0));
|
|
44
|
+
|
|
45
|
+
/** pdf.js가 글꼴 · CMap · wasm을 달라고 하면 번들에 넣은 것을 준다 (네트워크 없음) */
|
|
46
|
+
class BundledDataFactory {
|
|
47
|
+
async fetch({ kind, filename }) {
|
|
48
|
+
const [dir, files] = BUNDLED[kind] ?? [];
|
|
49
|
+
const load = files?.[`/node_modules/pdfjs-dist/${dir}/${filename}`];
|
|
50
|
+
if (!load) throw new Error(`번들에 없는 pdf.js 데이터: ${kind} ${filename}`);
|
|
51
|
+
return fromDataUrl(await load());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 작업자 코드 · blob: 주소는 이 모듈을 읽을 때 한 번만 만든다
|
|
56
|
+
const WORKER_CODE = toClassicWorker(workerCode);
|
|
57
|
+
const WORKER_URL = workerUrl(WORKER_CODE);
|
|
58
|
+
|
|
59
|
+
let worker = null;
|
|
60
|
+
/** 작업자는 페이지에 하나만 띄워 여러 문서가 같이 쓴다 (준비가 실패하면 다음에 다시 시도) */
|
|
61
|
+
function ensureWorker() {
|
|
62
|
+
worker ??= preparePdfWorker(WORKER_CODE, { url: WORKER_URL }).then(
|
|
63
|
+
({ port }) => {
|
|
64
|
+
pdfjs.GlobalWorkerOptions.workerPort = port;
|
|
65
|
+
},
|
|
66
|
+
(e) => {
|
|
67
|
+
worker = null;
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
return worker;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** PDF를 여는(첫 응답 · 쪽 크기) 데 이 시간보다 오래 걸리면 멈춘 것으로 보고 오류 */
|
|
75
|
+
const OPEN_TIMEOUT_MS = 30000;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* PDF를 연다. 문서 뷰어(core/viewer.js)가 쓰는 모양으로 돌려준다
|
|
79
|
+
* @param {Uint8Array | string} source 바이트, 또는 주소(pdf.js가 Range로 필요한 부분만 받음, core/pdf-options.js)
|
|
80
|
+
* @param {{ prefetch?: boolean }} [opts] prefetch: 첫 쪽 뒤 나머지를 미리 받기 (편집 화면)
|
|
81
|
+
*/
|
|
82
|
+
export async function openPdf(source, opts = {}) {
|
|
83
|
+
await ensureWorker();
|
|
84
|
+
const task = pdfjs.getDocument({
|
|
85
|
+
...pdfSourceOptions(source, opts),
|
|
86
|
+
BinaryDataFactory: BundledDataFactory,
|
|
87
|
+
enableScripting: false,
|
|
88
|
+
isEvalSupported: false,
|
|
89
|
+
});
|
|
90
|
+
const { doc, sizes } = await withTimeout(
|
|
91
|
+
(async () => {
|
|
92
|
+
const doc = await task.promise;
|
|
93
|
+
const sizes = [];
|
|
94
|
+
for (let i = 1; i <= doc.numPages; i += 1) {
|
|
95
|
+
const vp = (await doc.getPage(i)).getViewport({ scale: 1 });
|
|
96
|
+
sizes.push({ width: vp.width, height: vp.height });
|
|
97
|
+
}
|
|
98
|
+
return { doc, sizes };
|
|
99
|
+
})(),
|
|
100
|
+
OPEN_TIMEOUT_MS,
|
|
101
|
+
'PDF를 여는 데 너무 오래 걸립니다',
|
|
102
|
+
() => void task.destroy()
|
|
103
|
+
);
|
|
104
|
+
return {
|
|
105
|
+
kind: 'pdf',
|
|
106
|
+
count: doc.numPages,
|
|
107
|
+
/** 0부터. 배율 1의 크기 (CSS px) */
|
|
108
|
+
pageSize: (i) => sizes[i],
|
|
109
|
+
/**
|
|
110
|
+
* i쪽을 target에 그린다 (배율 scale, 화면 픽셀 밀도만큼 선명하게). 그리는 중에 다시 부르면 앞의 것은 취소
|
|
111
|
+
* @param {number} i
|
|
112
|
+
* @param {HTMLElement} target
|
|
113
|
+
* @param {number} scale
|
|
114
|
+
* @param {{ textLayer?: boolean }} [opts]
|
|
115
|
+
*/
|
|
116
|
+
async render(i, target, scale, opts = {}) {
|
|
117
|
+
const page = await doc.getPage(i + 1);
|
|
118
|
+
const viewport = page.getViewport({ scale });
|
|
119
|
+
const ratio = Math.min(globalThis.devicePixelRatio || 1, 3);
|
|
120
|
+
const canvas = document.createElement('canvas');
|
|
121
|
+
canvas.width = Math.floor(viewport.width * ratio);
|
|
122
|
+
canvas.height = Math.floor(viewport.height * ratio);
|
|
123
|
+
canvas.style.width = `${viewport.width}px`;
|
|
124
|
+
canvas.style.height = `${viewport.height}px`;
|
|
125
|
+
const box = document.createElement('div');
|
|
126
|
+
box.className = 'dc-pdf-page';
|
|
127
|
+
box.style.width = `${viewport.width}px`;
|
|
128
|
+
box.style.height = `${viewport.height}px`;
|
|
129
|
+
// pdf.js 글자 층이 읽는 CSS 변수
|
|
130
|
+
box.style.setProperty('--total-scale-factor', String(scale));
|
|
131
|
+
box.style.setProperty('--scale-round-x', '1px');
|
|
132
|
+
box.style.setProperty('--scale-round-y', '1px');
|
|
133
|
+
box.append(canvas);
|
|
134
|
+
target.__dcTask?.cancel();
|
|
135
|
+
const task = page.render({
|
|
136
|
+
canvas,
|
|
137
|
+
viewport,
|
|
138
|
+
transform: ratio === 1 ? undefined : [ratio, 0, 0, ratio, 0, 0],
|
|
139
|
+
});
|
|
140
|
+
target.__dcTask = task;
|
|
141
|
+
try {
|
|
142
|
+
await task.promise;
|
|
143
|
+
} catch (e) {
|
|
144
|
+
if (e?.name === 'RenderingCancelledException') return false;
|
|
145
|
+
throw e;
|
|
146
|
+
} finally {
|
|
147
|
+
if (target.__dcTask === task) target.__dcTask = null;
|
|
148
|
+
}
|
|
149
|
+
if (opts.textLayer !== false) {
|
|
150
|
+
const layer = document.createElement('div');
|
|
151
|
+
layer.className = 'textLayer';
|
|
152
|
+
box.append(layer);
|
|
153
|
+
await new pdfjs.TextLayer({
|
|
154
|
+
textContentSource: page.streamTextContent(),
|
|
155
|
+
container: layer,
|
|
156
|
+
viewport,
|
|
157
|
+
}).render();
|
|
158
|
+
}
|
|
159
|
+
target.replaceChildren(box);
|
|
160
|
+
return true;
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* 모든 쪽을 작게 그린 것 (편집 화면 왼쪽 목록). 폭 width(px). 쪽마다 빈 틀을 바로 주고 그림은 차례로 채운다
|
|
164
|
+
* @param {number} width
|
|
165
|
+
* @returns {Promise<HTMLElement[]>}
|
|
166
|
+
*/
|
|
167
|
+
async thumbnails(width) {
|
|
168
|
+
const boxes = sizes.map((s) => {
|
|
169
|
+
const box = document.createElement('div');
|
|
170
|
+
box.className = 'dc-pdf-thumb';
|
|
171
|
+
box.style.width = `${width}px`;
|
|
172
|
+
box.style.height = `${Math.round((width * s.height) / s.width)}px`;
|
|
173
|
+
return box;
|
|
174
|
+
});
|
|
175
|
+
void (async () => {
|
|
176
|
+
for (let i = 0; i < boxes.length; i += 1) {
|
|
177
|
+
const page = await doc.getPage(i + 1);
|
|
178
|
+
const viewport = page.getViewport({ scale: (width * 2) / sizes[i].width });
|
|
179
|
+
const canvas = document.createElement('canvas');
|
|
180
|
+
canvas.width = Math.floor(viewport.width);
|
|
181
|
+
canvas.height = Math.floor(viewport.height);
|
|
182
|
+
await page.render({ canvas, viewport }).promise.catch(() => undefined);
|
|
183
|
+
boxes[i].replaceChildren(canvas);
|
|
184
|
+
}
|
|
185
|
+
})();
|
|
186
|
+
return boxes;
|
|
187
|
+
},
|
|
188
|
+
destroy: () => void task.destroy(),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// core/pptx-edit.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export interface TextShape {
|
|
3
|
+
/** 도형 ref, 표 칸이면 표 ref + row · col */
|
|
4
|
+
ref: { shapeId: number; row?: number; col?: number };
|
|
5
|
+
text: string;
|
|
6
|
+
box: { x: number; y: number; w: number; h: number };
|
|
7
|
+
/** 표 칸: 줄 · 칸, index는 그 줄에서 그려지는 칸(병합으로 가려진 칸 뺌) 중 몇 번째 */
|
|
8
|
+
cell?: { row: number; col: number; index: number };
|
|
9
|
+
}
|
|
10
|
+
export declare function readTextShapes(bytes: Uint8Array): Promise<TextShape[][]>;
|
|
11
|
+
export declare function applyTextEdits(
|
|
12
|
+
bytes: Uint8Array,
|
|
13
|
+
edits: Array<{ ref: object; text: string }>
|
|
14
|
+
): Promise<Uint8Array>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// PPTX 글자 고치기 (편집 화면만, 고치지 않습니다). @office-kit/pptx로 파일을 읽고 쓰고,
|
|
2
|
+
// @office-kit/pptx-editor의 headless 편집(setShapeText · setTableCellText)으로 글자를 바꿉니다. 바꾸지 않은 글자의 서식은 그대로 두고,
|
|
3
|
+
// 글자 말고 다른 요소(그림 · 도형 · 표 틀 · 차트)는 원래 파일 그대로입니다.
|
|
4
|
+
//
|
|
5
|
+
// 에디터 화면 전체(mountEditor, 리본 · 메뉴가 있는 발표 자료 편집기)는 쓰지 않습니다: 시안은 "슬라이드의 글자를 눌러
|
|
6
|
+
// 바로 고침"만 보이고, 화면 전체 편집기는 번들이 수 MB 더 큽니다. 학생 화면은 이 파일을 부르지 않습니다.
|
|
7
|
+
import {
|
|
8
|
+
getGroupChildren,
|
|
9
|
+
getGroupTransform,
|
|
10
|
+
getShapeId,
|
|
11
|
+
getShapeKind,
|
|
12
|
+
getShapeXmlString,
|
|
13
|
+
getSlides,
|
|
14
|
+
getSlideShapes,
|
|
15
|
+
getSlideSize,
|
|
16
|
+
getTableCell,
|
|
17
|
+
getTableCellSpan,
|
|
18
|
+
loadPresentation,
|
|
19
|
+
savePresentation,
|
|
20
|
+
} from '@office-kit/pptx';
|
|
21
|
+
import { applyAgentEdits, decodeAgentEdits, readForAgent } from '@office-kit/pptx-editor/headless';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 그룹 안 도형의 위치를 슬라이드 좌표로 옮기는 함수 (도형 id마다).
|
|
25
|
+
* @office-kit 도형 위치는 그룹 안 좌표(chOff · chExt 기준)라, 그룹을 옮기거나 늘리면(off ≠ chOff, ext ≠ chExt) 그려진 위치와 다르다.
|
|
26
|
+
* 렌더러처럼 slide = outer + (child − inner) × outer / inner를 그룹마다 바깥으로 거듭 적용한다
|
|
27
|
+
* @param {object} slide
|
|
28
|
+
* @returns {Map<number, (b: { x: number, y: number, w: number, h: number }) => { x: number, y: number, w: number, h: number }>}
|
|
29
|
+
*/
|
|
30
|
+
function groupProjections(slide) {
|
|
31
|
+
const out = new Map();
|
|
32
|
+
const visit = (group, outer) => {
|
|
33
|
+
const t = getGroupTransform(group);
|
|
34
|
+
const sx = t && t.inner.w ? t.outer.w / t.inner.w : 1;
|
|
35
|
+
const sy = t && t.inner.h ? t.outer.h / t.inner.h : 1;
|
|
36
|
+
const project = b =>
|
|
37
|
+
outer(
|
|
38
|
+
t
|
|
39
|
+
? {
|
|
40
|
+
x: t.outer.x + (b.x - t.inner.x) * sx,
|
|
41
|
+
y: t.outer.y + (b.y - t.inner.y) * sy,
|
|
42
|
+
w: b.w * sx,
|
|
43
|
+
h: b.h * sy,
|
|
44
|
+
}
|
|
45
|
+
: b
|
|
46
|
+
);
|
|
47
|
+
for (const child of getGroupChildren(group)) {
|
|
48
|
+
out.set(getShapeId(child), project);
|
|
49
|
+
if (getShapeKind(child) === 'group') visit(child, project);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// 슬라이드 도형 목록에는 그룹 안 도형도 들어 있다: 맨 바깥 그룹에서만 시작
|
|
53
|
+
for (const shape of getSlideShapes(slide)) {
|
|
54
|
+
if (getShapeKind(shape) === 'group' && !out.has(getShapeId(shape))) visit(shape, b => b);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 글자가 필드(<a:fld>: 날짜 · 슬라이드 번호 등)뿐인 도형. PowerPoint가 열 때 채우는 글자라 고칠 것이 아니고,
|
|
61
|
+
* 고치면 필드가 평문이 되어 더는 바뀌지 않는다 (@office-kit setShapeText는 고친 곳이 필드에 걸치면 평문으로 씀).
|
|
62
|
+
* 글자와 필드가 섞인 도형은 고칠 수 있다 (필드를 건드리지 않으면 필드는 그대로)
|
|
63
|
+
* @param {object} shape
|
|
64
|
+
*/
|
|
65
|
+
function isFieldOnly(shape) {
|
|
66
|
+
const xml = getShapeXmlString(shape);
|
|
67
|
+
return /<a:fld\b/.test(xml) && !/<a:r>(?:(?!<\/a:r>)[\s\S])*?<a:t>[^<]*\S/.test(xml);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 슬라이드마다 고칠 수 있는 글자 (위치는 슬라이드 크기에 대한 비율 0~1): 글자가 있는 도형과 표 칸.
|
|
72
|
+
* 표 칸은 ref가 칸(표 ref + row · col)이고 box는 표 전체, cell.index는 그 줄에서 그려지는 칸 중 몇 번째인지
|
|
73
|
+
* (병합으로 가려진 칸 hMerge · vMerge는 렌더러가 그리지 않으므로 빼고 셈). 빈 칸도 넣는다 (글자를 새로 쓸 수 있게).
|
|
74
|
+
* 필드뿐인 도형(날짜 · 슬라이드 번호)은 뺀다
|
|
75
|
+
* @param {Uint8Array} bytes
|
|
76
|
+
* @returns {Promise<Array<Array<{ ref: object, text: string, box: { x: number, y: number, w: number, h: number }, cell?: { row: number, col: number, index: number } }>>>}
|
|
77
|
+
*/
|
|
78
|
+
export async function readTextShapes(bytes) {
|
|
79
|
+
const pres = await loadPresentation(bytes);
|
|
80
|
+
const { width, height } = getSlideSize(pres);
|
|
81
|
+
const { slides } = readForAgent(pres, null);
|
|
82
|
+
const models = getSlides(pres);
|
|
83
|
+
return slides.map((slide, i) => {
|
|
84
|
+
const model = models[slide.index ?? i];
|
|
85
|
+
const projections = groupProjections(model);
|
|
86
|
+
const byId = new Map(getSlideShapes(model).map(s => [getShapeId(s), s]));
|
|
87
|
+
const items = [];
|
|
88
|
+
for (const s of slide.shapes) {
|
|
89
|
+
if (!s.bounds || !s.shape) continue;
|
|
90
|
+
const b = projections.get(s.shape.shapeId)?.(s.bounds) ?? s.bounds;
|
|
91
|
+
const box = { x: b.x / width, y: b.y / height, w: b.w / width, h: b.h / height };
|
|
92
|
+
const shape = byId.get(s.shape.shapeId);
|
|
93
|
+
if (s.kind === 'table') {
|
|
94
|
+
if (!shape || !Array.isArray(s.cells)) continue;
|
|
95
|
+
s.cells.forEach((row, r) => {
|
|
96
|
+
let index = 0;
|
|
97
|
+
row.forEach((text, c) => {
|
|
98
|
+
const span = getTableCellSpan(getTableCell(shape, r, c));
|
|
99
|
+
if (span.hMerge || span.vMerge) return;
|
|
100
|
+
items.push({
|
|
101
|
+
ref: { ...s.shape, row: r, col: c },
|
|
102
|
+
text,
|
|
103
|
+
box,
|
|
104
|
+
cell: { row: r, col: c, index },
|
|
105
|
+
});
|
|
106
|
+
index += 1;
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
} else if (typeof s.text === 'string' && !(shape && isFieldOnly(shape))) {
|
|
110
|
+
items.push({ ref: s.shape, text: s.text, box });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return items;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 원래 파일에 글자 바꾸기를 모두 적용한 새 파일
|
|
119
|
+
* @param {Uint8Array} bytes 원래 파일
|
|
120
|
+
* @param {Array<{ ref: object, text: string }>} edits 도형 · 표 칸마다 바꾼 전체 글자 (줄은 \n). 표 칸은 ref에 row · col이 있다
|
|
121
|
+
* @returns {Promise<Uint8Array>}
|
|
122
|
+
*/
|
|
123
|
+
export async function applyTextEdits(bytes, edits) {
|
|
124
|
+
const pres = await loadPresentation(bytes);
|
|
125
|
+
// 한 번에 50개까지 받는다 (headless 편집 묶음 한도)
|
|
126
|
+
for (let i = 0; i < edits.length; i += 50) {
|
|
127
|
+
const batch = edits
|
|
128
|
+
.slice(i, i + 50)
|
|
129
|
+
.map(e =>
|
|
130
|
+
typeof e.ref.row === 'number'
|
|
131
|
+
? { tool: 'setTableCellText', input: { cell: e.ref, text: e.text } }
|
|
132
|
+
: { tool: 'setShapeText', input: { shape: e.ref, value: e.text } }
|
|
133
|
+
);
|
|
134
|
+
await applyAgentEdits(pres, decodeAgentEdits(batch).edits);
|
|
135
|
+
}
|
|
136
|
+
return savePresentation(pres);
|
|
137
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// core/pptx-fonts.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare function slideFontFamily(value: string): string;
|
|
3
|
+
export declare function applySlideFonts(root: Element): void;
|
|
4
|
+
export declare function fontFaceCss(base?: string): string;
|
|
5
|
+
export declare function installSlideFonts(doc?: Document): void;
|