@eliceio/cdk-cli 1.8.1-documentqa.0 → 1.9.0-youtubeqa.0
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 +19 -19
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +1 -1
- package/es/dev/host-page.js +1 -1
- package/es/dev/server.d.ts +1 -1
- package/es/dev/server.js +1 -1
- package/es/rules/check.js +3 -3
- package/es/rules/csp.d.ts +3 -3
- package/es/rules/csp.js +32 -7
- 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 +1 -0
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
- package/skills/_shared/references/18-using-the-lesson-template.md +1 -1
- package/skills/elice-content-create/SKILL.md +1 -1
- package/templates/document/README.md +3 -5
- package/templates/document/core/viewer.js +1 -4
- package/templates/document/screens/learn.js +2 -47
- package/templates/document/styles.css +0 -73
- package/templates/document/template.json +1 -1
- package/templates/document/ui/templates/viewer.js +3 -8
- package/templates/document/ui/texts.js +0 -2
- package/templates/document/ui/theme.css +0 -2
- package/templates/youtube/README.md +66 -0
- package/templates/youtube/commentary.txt +2 -0
- package/templates/youtube/core/dom.d.ts +13 -0
- package/templates/youtube/core/dom.js +83 -0
- package/templates/youtube/core/settings.d.ts +21 -0
- package/templates/youtube/core/settings.js +71 -0
- package/templates/youtube/core/youtube.d.ts +9 -0
- package/templates/youtube/core/youtube.js +111 -0
- package/templates/youtube/edit.html +17 -0
- package/templates/youtube/gitignore +4 -0
- package/templates/youtube/index.html +17 -0
- package/templates/youtube/metadata.json +9 -0
- package/templates/youtube/package.json +13 -0
- package/templates/youtube/screens/edit.js +69 -0
- package/templates/youtube/screens/learn.js +18 -0
- package/templates/youtube/styles.css +101 -0
- package/templates/youtube/template.json +14 -0
- package/templates/youtube/ui/templates/edit.js +60 -0
- package/templates/youtube/ui/templates/player.js +61 -0
- package/templates/youtube/ui/texts.d.ts +3 -0
- package/templates/youtube/ui/texts.js +50 -0
- package/templates/youtube/ui/theme.css +14 -0
|
@@ -16,7 +16,7 @@ Write the progress line `[n/N] …` before and after every step below (Always
|
|
|
16
16
|
1. **Design before code.** Read `references/00-what-the-person-decides.md` and `references/02-design-the-material.md`. Decide ① what the student does, ② whether the student submits and the grading (`type` `pattern` or `rubric`, set on the edit screen; the quiz template uses `pattern`, so do not ask for a quiz; AI grading is `rubric` saved by the edit screen's `getGrading` and the student submits only the answer, never a score computed with `mlapi`, `references/05-screen-code.md` "AI grading") and which completion policy fits (the publish skill sets it after the person agrees; only `on_graded` grades, `on_submit` completes on any submission without grading), ③ the instructor screen (seen only in the LXP editor preview; instructors on the learning page see the student screen), ④ the content edit screen, ⑤ the purpose. Decide what the request leaves out and tell the person briefly; ask only when the learning goal is unclear. Then show the numbered plan.
|
|
17
17
|
2. **Environment and project.** `ecdk --version && ecdk doctor --json` (`references/01-check-the-environment.md`, also for `cli.latest`), then `ecdk create --list` to pick a template and `ecdk create <folder> --template <name>` (`references/03-create-the-project.md`; it runs `npm install` for the SDK, so when that fails run `npm install` in the project). Start `ecdk dev <folder>` in the background now and give the person the URL.
|
|
18
18
|
3. **Write the screens.** Start from the template's example code and the kit API table at the top of `references/05-screen-code.md`; do not open `lib/` to learn the API (the table is the API). Follow its UI patterns (kit icon buttons, list rows, drop zones; the quiz template: `references/06-using-the-quiz-template.md`; a survey (opinions, feedback, self-assessment, no right answers): the survey template and `references/16-using-the-survey-template.md` for the settings shape, question-writing rules, personal data and where the answers are; block coding in Entry: the Entry template and `references/17-using-the-entry-template.md`, where the person builds the start and answer projects on the edit screen and you never write project JSON); an edit screen you write by hand follows `references/13-edit-screen-design.md` (kit classes, layout, microcopy); when a student or instructor screen has nothing to show, always use `app.emptyState()`, never your own empty-state markup, illustration or text (`references/05-screen-code.md`, "Nothing to show"), and write `commentary.txt` (key concepts and intent, no answers). There is no default content file: the content and answers are what the edit screen saves (`ecdk dev` writes `.ecdk/settings.json`, local by default; the elice-content-publish skill can send it with the upload after the person agrees, otherwise the person enters it in the LXP edit screen).
|
|
19
|
-
- **A learning material the person did not give a screen layout for** (explanations, guided practice, self-check, "학습 자료 만들어줘") and that is not a quiz, survey, PDF/PPT document, video, Entry or board request: use the lesson template and `references/18-using-the-lesson-template.md`. You write only the content (`.ecdk/settings.json`, the lesson content object with layouts from `references/19-lesson-layouts.md`), never screen code; `ecdk doctor` (`project.lesson`) checks it. Lesson quizzes are self-check only. In a run without a person, skip the edit-view save and report how the content reaches LXP (`references/18-using-the-lesson-template.md` step 8).
|
|
19
|
+
- **A learning material the person did not give a screen layout for** (explanations, guided practice, self-check, "학습 자료 만들어줘") and that is not a quiz, survey, PDF/PPT document, video, YouTube video, Entry or board request: use the lesson template and `references/18-using-the-lesson-template.md`. You write only the content (`.ecdk/settings.json`, the lesson content object with layouts from `references/19-lesson-layouts.md`), never screen code; `ecdk doctor` (`project.lesson`) checks it. Lesson quizzes are self-check only. In a run without a person, skip the edit-view save and report how the content reaches LXP (`references/18-using-the-lesson-template.md` step 8).
|
|
20
20
|
- When the person wants to design the screens themselves, or the activity needs an interaction the lesson layouts cannot do (a live simulation, a game, a custom visualization), start from the blank template and its content editor: design the content JSON shape and its schema first (`references/02-design-the-material.md` ④-1), put them in `screens/edit.js` (`useContentEditor(app, { initial, schema })`), then write the student screen against that shape. Replace the template's example everywhere it says `이 자료에 맞게 바꿀 곳`.
|
|
21
21
|
- If the person describes the content (for example "5 questions about perceptrons"), fill it in so the upload can carry it: write `.ecdk/settings.json` in the shape `references/09-check.md` describes (the edit screen's content object at the top level, `grading` when graded), then have the person open the edit view in `ecdk dev`, check it and save with the edit screen's button, so the edit screen's own validation runs. Draft the answers, but the person confirms them before any upload (Always). One quiz material holds up to 20 questions (`references/06-using-the-quiz-template.md`): put them all in one material; only more than 20 means several quiz materials (pages). If the person prefers, give the content as draft text (the content editor: one JSON block for 코드 보기) to enter in the LXP edit screen instead. Not for the Entry template: its settings are Entry projects the person builds on the edit screen, never written by you, also in a run without a person (`references/17-using-the-entry-template.md` "Who makes what").
|
|
22
22
|
4. **Check each screen** with `ecdk dev <folder> --check --screens <screen>` after you write it (`references/09-check.md`), fix what it reports (error ids: `references/08-fix-check-errors.md`). The person looks at the screens too.
|
|
@@ -6,7 +6,7 @@ Elice Custom HTML 학습자료 프로젝트입니다 (문서 템플릿: PDF · P
|
|
|
6
6
|
|
|
7
7
|
| 파일 | 화면 |
|
|
8
8
|
| --------------------------------- | ------------------------------------------------------------------------------------ |
|
|
9
|
-
| `screens/learn.js` · `index.html` | 학생 화면 (어두운 바탕 문서 뷰어: 화면 높이에 맞춤, 아래 `< [n] / N쪽 >`
|
|
9
|
+
| `screens/learn.js` · `index.html` | 학생 화면 (어두운 바탕 문서 뷰어: 화면 높이에 맞춤, 아래 `< [n] / N쪽 >` 넘기기) |
|
|
10
10
|
| `screens/edit.js` · `edit.html` | 내용 편집 화면 (CMS): 문서 올리기 · 다른 파일로 변경 · PPTX 글자 고치기 |
|
|
11
11
|
| `ui/` | 모양: 색 · 간격 · 문구 · 마크업 (아래 표) |
|
|
12
12
|
| `styles.css` | 이 콘텐츠의 스타일 (값은 `ui/theme.css`의 변수) |
|
|
@@ -22,7 +22,7 @@ screens/ 배치 — 어떤 블록을 어떤 순서로 보일지
|
|
|
22
22
|
core/ 동작 — 고치지 않습니다
|
|
23
23
|
├─ file-type.js 올릴 파일 형식 확인 (.pdf · .pptx만, 이름 · 첫 바이트)
|
|
24
24
|
├─ settings.js 저장 내용 모양 · 기본값 · 검증 · 크기 한도
|
|
25
|
-
├─ viewer.js 넘기기 · n / N
|
|
25
|
+
├─ viewer.js 넘기기 · n / N · 쪽 번호 입력 · 폭 · 높이 맞춤 · 키보드(← → Home End)
|
|
26
26
|
├─ load.js 파일 받기 · 종류에 맞는 그리기 모듈 열기
|
|
27
27
|
├─ pdf.js PDF 그리기 (pdf.js legacy 빌드, canvas + 글자 층)
|
|
28
28
|
├─ pdf-worker.js pdf.js 작업자 띄우기 (출처 null에서도: 일반 blob 작업자 → 안 되면 작업자 없이)
|
|
@@ -37,7 +37,7 @@ core/ 동작 — 고치지 않습니다
|
|
|
37
37
|
| ------------------------------------ | -------------------------------------------------------------------- |
|
|
38
38
|
| 색 · 간격 · 화면 폭 | `ui/theme.css`의 `--dc-*` 변수 (예: `--dc-accent`, `--dc-max-width`) |
|
|
39
39
|
| 문구 ("초안으로 저장", 안내 문구 등) | `ui/texts.js` |
|
|
40
|
-
| 뷰어 넘기기 줄 (`< [n] / N쪽 >`, 쪽 번호 입력
|
|
40
|
+
| 뷰어 넘기기 줄 (`< [n] / N쪽 >`, 쪽 번호 입력 칸) | `ui/templates/viewer.js` |
|
|
41
41
|
| 편집 화면 파일 줄 · 올리는 중 · 안내 · 쪽 목록 | `ui/templates/edit.js` |
|
|
42
42
|
| 학생 화면 빈 안내 (그림 · 문구) | 키트 `app.emptyState({ theme: 'dark' })` (`screens/learn.js`). 문구를 바꾸려면 `title` · `description`을 넘깁니다 |
|
|
43
43
|
| 블록 순서 | `screens/*.js` |
|
|
@@ -58,8 +58,6 @@ core/ 동작 — 고치지 않습니다
|
|
|
58
58
|
- **PPTX 글자 고치기**: 편집 화면에서 슬라이드의 글자를 누르면 그 글자를 슬라이드 모양 그대로 고칩니다 (렌더러가 그린 글자 상자가 입력 칸, 파일 좌표 · 글자로 도형과 짝지음, `core/inline-edit.js`. Enter는 새 문단 · Shift+Enter는 줄바꿈, 다른 곳을 누르거나 Ctrl+Enter · ⌘+Enter면 적용, Esc 취소, 붙여넣기는 글자만, 한글 조합 그대로). 누를 수 있는 곳은 글자가 있는 곳(문단을 글자 폭으로 줄여 정렬대로 놓음)이고, 가리키면 점선 · 고치는 중 실선 테두리는 글자 상자마다 하나로 상자 안 문단 전체를 감쌉니다 (문단이 늘거나 줄면 다시 잼, 회전 · 그룹 도형은 도형과 같이 기움. 표 칸은 칸 전체). 바꾸지 않은 글자의 서식과 글자가 아닌 요소(그림 · 도형 · 표 · 차트)는 원래 파일 그대로입니다. 고친 글자는 화면에 바로 보이고 파일은 그때 다시 쓰지 않습니다. **초안으로 저장**을 누르면 고친 글자를 한 번에 넣은 .pptx를 같은 흐름으로 새로 올리고 `asset_key`를 바꿉니다 (글자 차이를 따로 저장하지 않음).
|
|
59
59
|
- **파일을 고르면** 미리보기를 먼저 보이고 뒤에서 올립니다 (올리는 동안 저장은 막음, 올리지 못하면 앞 문서로 돌아감). 편집 화면의 큰 쪽 · 넘기기 줄 · 쪽 목록은 화면 높이(LXP 편집 iframe 512px) 안에 들어오게 맞춥니다.
|
|
60
60
|
- **PDF**는 보기만 합니다 (파일 줄 · 다른 파일로 변경 · 쪽 목록 · 큰 쪽). 디자이너 시안에 PDF 편집 도구가 없어 넣지 않았습니다. 내용을 바꾸려면 고친 파일로 바꿉니다.
|
|
61
|
-
- **학생 화면 크기**: 화면(`main`) 폭 < 480px 또는 높이 < 320px이면(보조 칸 · 휴대폰) 쪽이 칸을 채우고 아래 24px 줄에 `‹ n / N ›`(글자만)와 오른쪽 끝 내려받기 버튼을 보입니다 (`styles.css` `@container dc-learn`, 줄 높이 `--dc-compact-bar`). 그보다 크면 지금 모양 그대로입니다.
|
|
62
|
-
- **내려받기**는 올린 파일 그대로(PDF는 PDF, PPTX는 편집 화면에서 고친 최종 .pptx)를 `document.name` 이름으로 줍니다. 주소가 화면과 같은 출처면 `<a download>`로, 다른 출처면(`ecdk dev`) 받아서 blob 주소로 내려받고, 받지 못하면 새 탭으로 주소를 엽니다 (브라우저 기본 동작).
|
|
63
61
|
- 채점 설정(`grading`)은 없고 학생 화면은 제출하지 않습니다. LXP 자료 편집 화면의 '설정'에서 완료 정책을 **열람 시 학습 완료**로 고릅니다.
|
|
64
62
|
|
|
65
63
|
`ecdk dev`의 내용 편집에서 올린 파일은 `.ecdk/assets/`에, 저장한 내용은 `.ecdk/settings.json`에 남습니다 (zip에는 들어가지 않음). 기본으로는 로컬에만 있고, publish 스킬로 올릴 때 동의하면 업로드와 함께 보냅니다. 보내지 않으면 LXP에 올린 뒤 편집 화면에서 입력합니다. 저장하기 전에는 학생 화면이 그림과 "학습 자료를 준비하고 있어요" 안내를 보입니다 (키트 `app.hasContent` · `app.emptyState({ theme: 'dark' })`: 어두운 바탕이라 어두운 색).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 문서 뷰어 동작 (고치지 않습니다): 쪽 넘기기 · n / N
|
|
1
|
+
// 문서 뷰어 동작 (고치지 않습니다): 쪽 넘기기 · n / N · 쪽 번호 입력 · 폭 맞춤 · 키보드 · 크기 바뀌면 다시 맞춤 (확대 버튼 없음).
|
|
2
2
|
// 마크업은 ui/templates/viewer.js (data-role로 찾음), 그리기는 core/pdf.js · core/pptx-view.js가 합니다.
|
|
3
3
|
import { part } from './dom.js';
|
|
4
4
|
|
|
@@ -29,8 +29,6 @@ export function mountViewer(root, doc, opts = {}) {
|
|
|
29
29
|
const next = part(root, 'next');
|
|
30
30
|
const current = part(root, 'current');
|
|
31
31
|
const total = part(root, 'total');
|
|
32
|
-
// 쪽 번호 글 (선택): 좁은 칸에서 입력 칸 대신 보이는 "n" (CSS가 둘 중 하나만 보임)
|
|
33
|
-
const currentText = root.querySelector('[data-role="current-text"]');
|
|
34
32
|
const alert = root.querySelector('[data-role="alert"]');
|
|
35
33
|
const showAlert = (text) => {
|
|
36
34
|
if (!alert) return;
|
|
@@ -47,7 +45,6 @@ export function mountViewer(root, doc, opts = {}) {
|
|
|
47
45
|
const showCurrent = () => {
|
|
48
46
|
if (isInput) current.value = String(index + 1);
|
|
49
47
|
else current.textContent = String(index + 1);
|
|
50
|
-
if (currentText) currentText.textContent = String(index + 1);
|
|
51
48
|
};
|
|
52
49
|
|
|
53
50
|
const available = () => {
|
|
@@ -47,11 +47,9 @@ async function show(file) {
|
|
|
47
47
|
root.replaceChildren(notice({ text: isLoadError(e) ? t.loadFailed : t.openFailed, error: true }));
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
const view = viewer({ kind: file.type, name: title || file.name, download: { name: downloadName } });
|
|
50
|
+
const view = viewer({ kind: file.type, name: title || file.name });
|
|
52
51
|
root.replaceChildren(view);
|
|
53
|
-
// 연주님 시안: 쪽 전체가 화면(무대) 안에 보이게 폭 · 높이에 맞추고, 아래 < [n] / N쪽 >만 (확대 버튼 없음)
|
|
54
|
-
// 좁거나 낮은 칸은 ‹ n / N › + 내려받기 (styles.css @container dc-learn)
|
|
52
|
+
// 연주님 시안: 쪽 전체가 화면(무대) 안에 보이게 폭 · 높이에 맞추고, 아래 < [n] / N쪽 >만 (확대 버튼 없음)
|
|
55
53
|
const stage = part(view, 'stage');
|
|
56
54
|
mountViewer(view, doc, {
|
|
57
55
|
// 넘긴 쪽을 받지 못하면(서명 주소 6시간 만료) 빈 쪽 대신 안내. 다시 받지 않는다 (새 주소 받기는 SDK 추후 작업)
|
|
@@ -61,48 +59,5 @@ async function show(file) {
|
|
|
61
59
|
return stage.clientHeight - (parseFloat(style.paddingTop) || 0) - (parseFloat(style.paddingBottom) || 0);
|
|
62
60
|
},
|
|
63
61
|
});
|
|
64
|
-
// 내려받기: 올린 파일 그대로 (PPTX는 편집 화면에서 고친 최종 파일)
|
|
65
|
-
const button = part(view, 'download');
|
|
66
|
-
button.addEventListener('click', async () => {
|
|
67
|
-
button.disabled = true;
|
|
68
|
-
try {
|
|
69
|
-
await download(url, downloadName);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
// 받지 못하면 새 탭에서 주소를 연다 (보기 · 저장은 브라우저 기본 동작)
|
|
72
|
-
console.error('[document] 문서를 내려받지 못해 새 탭으로 엽니다', url, e);
|
|
73
|
-
openInNewTab(url);
|
|
74
|
-
} finally {
|
|
75
|
-
button.disabled = false;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 파일을 이름(name)으로 내려받는다. 같은 출처 주소면 <a download>로 바로 (운영: 자료 파일이 콘텐츠와 같은 출처).
|
|
82
|
-
* 다른 출처면 브라우저가 download 이름을 무시하고 PDF는 화면이 그 주소로 넘어가므로, 받아서 blob 주소로 (ecdk dev)
|
|
83
|
-
*/
|
|
84
|
-
async function download(url, name) {
|
|
85
|
-
const link = document.createElement('a');
|
|
86
|
-
link.download = name;
|
|
87
|
-
if (new URL(url, location.href).origin === location.origin) {
|
|
88
|
-
link.href = url;
|
|
89
|
-
link.click();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const res = await fetch(url);
|
|
93
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
94
|
-
const blob = URL.createObjectURL(await res.blob());
|
|
95
|
-
link.href = blob;
|
|
96
|
-
link.click();
|
|
97
|
-
// 바로 지우면 받기를 취소하는 브라우저가 있어 잠깐 뒤에 지운다
|
|
98
|
-
setTimeout(() => URL.revokeObjectURL(blob), 1000);
|
|
99
|
-
}
|
|
100
62
|
|
|
101
|
-
/** 주소를 새 탭으로 (window.open은 sandbox를 물려받으므로 링크로: LXP가 sandbox 밖 새 탭으로 연다) */
|
|
102
|
-
function openInNewTab(url) {
|
|
103
|
-
const link = document.createElement('a');
|
|
104
|
-
link.href = url;
|
|
105
|
-
link.target = '_blank';
|
|
106
|
-
link.rel = 'noopener';
|
|
107
|
-
link.click();
|
|
108
63
|
}
|
|
@@ -15,8 +15,6 @@ body.dc-learn {
|
|
|
15
15
|
overflow: hidden;
|
|
16
16
|
}
|
|
17
17
|
body.dc-learn main {
|
|
18
|
-
/* 좁거나 낮은 칸(아래 @container dc-learn)을 학생 화면 크기로 판단한다. 높이는 100dvh로 정해져 있어 size로 둔다 */
|
|
19
|
-
container: dc-learn / size;
|
|
20
18
|
display: flex;
|
|
21
19
|
flex-direction: column;
|
|
22
20
|
gap: 0;
|
|
@@ -194,11 +192,6 @@ button.dc-icon-button,
|
|
|
194
192
|
white-space: nowrap;
|
|
195
193
|
font-variant-numeric: tabular-nums;
|
|
196
194
|
}
|
|
197
|
-
/* 쪽 번호 글 · 내려받기는 좁은 학생 화면(아래 @container dc-learn)에서만 보인다 */
|
|
198
|
-
.dc-current-text,
|
|
199
|
-
button.dc-icon-button.dc-download {
|
|
200
|
-
display: none;
|
|
201
|
-
}
|
|
202
195
|
input.dc-current-input {
|
|
203
196
|
width: 3ch;
|
|
204
197
|
height: 28px;
|
|
@@ -313,72 +306,6 @@ button.dc-icon-button:disabled {
|
|
|
313
306
|
}
|
|
314
307
|
}
|
|
315
308
|
|
|
316
|
-
/* 좁거나 낮은 학생 화면 (보조 칸 · 휴대폰, 디자이너 시안 340×190): 쪽이 칸을 채우고, 아래 24px 줄에
|
|
317
|
-
"‹ n / N ›"(글자만) 가운데 · 내려받기 오른쪽 끝. 위 @media 버튼 크기 규칙보다 뒤에 둬서 이긴다.
|
|
318
|
-
경계값은 @container 조건에 변수를 쓸 수 없어 숫자로 둔다 */
|
|
319
|
-
@container dc-learn (width < 480px) or (height < 320px) {
|
|
320
|
-
body.dc-learn .dc-stage {
|
|
321
|
-
padding: 0 12px;
|
|
322
|
-
}
|
|
323
|
-
body.dc-learn .dc-toolbar {
|
|
324
|
-
display: grid;
|
|
325
|
-
grid-template-columns: 1fr auto 1fr;
|
|
326
|
-
height: var(--dc-compact-bar);
|
|
327
|
-
padding: 0 12px;
|
|
328
|
-
}
|
|
329
|
-
body.dc-learn .dc-nav {
|
|
330
|
-
grid-column: 2;
|
|
331
|
-
gap: 10px;
|
|
332
|
-
}
|
|
333
|
-
body.dc-learn button.dc-icon-button {
|
|
334
|
-
width: 20px;
|
|
335
|
-
height: 20px;
|
|
336
|
-
border: 0;
|
|
337
|
-
background: transparent;
|
|
338
|
-
}
|
|
339
|
-
body.dc-learn button.dc-icon-button svg {
|
|
340
|
-
width: 16px;
|
|
341
|
-
height: 16px;
|
|
342
|
-
}
|
|
343
|
-
body.dc-learn button.dc-icon-button.dc-download {
|
|
344
|
-
display: inline-flex;
|
|
345
|
-
grid-column: 3;
|
|
346
|
-
justify-self: end;
|
|
347
|
-
}
|
|
348
|
-
body.dc-learn .dc-count {
|
|
349
|
-
height: auto;
|
|
350
|
-
padding: 0;
|
|
351
|
-
border: 0;
|
|
352
|
-
border-radius: 0;
|
|
353
|
-
font-size: 14px;
|
|
354
|
-
font-weight: 500;
|
|
355
|
-
line-height: 1.4;
|
|
356
|
-
}
|
|
357
|
-
body.dc-learn input.dc-current-input,
|
|
358
|
-
body.dc-learn .dc-unit {
|
|
359
|
-
display: none;
|
|
360
|
-
}
|
|
361
|
-
body.dc-learn .dc-current-text {
|
|
362
|
-
display: inline;
|
|
363
|
-
}
|
|
364
|
-
@media (hover: hover) {
|
|
365
|
-
body.dc-learn button.dc-icon-button:hover:not(:disabled) {
|
|
366
|
-
background: var(--dc-nav-hover-bg);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
/* 손가락: 보이는 크기는 시안대로 두고 누르는 자리만 32px로 넓힌다 */
|
|
370
|
-
@media (pointer: coarse) {
|
|
371
|
-
body.dc-learn button.dc-icon-button {
|
|
372
|
-
position: relative;
|
|
373
|
-
}
|
|
374
|
-
body.dc-learn button.dc-icon-button::after {
|
|
375
|
-
content: '';
|
|
376
|
-
position: absolute;
|
|
377
|
-
inset: -6px;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
309
|
/* pdf.js 글자 층 (pdfjs-dist web/pdf_viewer.css에서 필요한 것만, Apache-2.0): 글자를 고르고 복사할 수 있게 */
|
|
383
310
|
.dc-pdf-page .textLayer {
|
|
384
311
|
position: absolute;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// 남겨야 하는 data-role (동작 core/viewer.js가 찾음):
|
|
3
3
|
// stage(쪽을 놓는 영역, 키보드 ← →) · sheet(쪽 크기 틀) · page(그림이 들어감)
|
|
4
4
|
// alert(쪽을 그리지 못했을 때 안내, 없어도 됨) · prev · next · current(쪽 번호 입력 칸: 숫자를 넣고 Enter면 그 쪽으로. <span>이면 글만 바뀜) · total
|
|
5
|
-
// current-text(쪽 번호 글, 없어도 됨: 좁은 칸에서 입력 칸 대신 보임) · download(학생 화면 내려받기, screens/learn.js가 처리)
|
|
6
5
|
import { html } from '../../core/dom.js';
|
|
7
6
|
import { texts } from '../texts.js';
|
|
8
7
|
|
|
@@ -16,10 +15,9 @@ const icon = (d) => html`
|
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* 뷰어 틀
|
|
19
|
-
* @param {{ kind: 'pdf' | 'pptx', name?: string
|
|
20
|
-
* download: 넘기기 줄 오른쪽에 내려받기 버튼 (학생 화면만). name은 버튼 이름에 쓰는 파일 이름
|
|
18
|
+
* @param {{ kind: 'pdf' | 'pptx', name?: string }} opts
|
|
21
19
|
*/
|
|
22
|
-
export const viewer = ({ kind, name = ''
|
|
20
|
+
export const viewer = ({ kind, name = '' }) => html`
|
|
23
21
|
<section class="dc-viewer" data-kind="${kind}" data-ec-quiet>
|
|
24
22
|
<p class="dc-viewer-alert" data-role="alert" role="alert" hidden></p>
|
|
25
23
|
<div class="dc-stage" data-role="stage" tabindex="0" role="region" aria-label="${t.label(name)}">
|
|
@@ -30,12 +28,9 @@ export const viewer = ({ kind, name = '', download }) => html`
|
|
|
30
28
|
<div class="dc-toolbar">
|
|
31
29
|
<div class="dc-nav">
|
|
32
30
|
<button type="button" class="dc-icon-button" data-role="prev" aria-label="${t.prev[kind]}" title="${t.prev[kind]}">${icon('m15 18-6-6 6-6')}</button>
|
|
33
|
-
<span class="dc-count" aria-live="polite"><input type="text" inputmode="numeric" autocomplete="off" class="dc-current-input" data-role="current" value="1" aria-label="${t.current}"
|
|
31
|
+
<span class="dc-count" aria-live="polite"><input type="text" inputmode="numeric" autocomplete="off" class="dc-current-input" data-role="current" value="1" aria-label="${t.current}" /> / <span data-role="total">1</span>${t.unit}</span>
|
|
34
32
|
<button type="button" class="dc-icon-button" data-role="next" aria-label="${t.next[kind]}" title="${t.next[kind]}">${icon('m9 18 6-6-6-6')}</button>
|
|
35
33
|
</div>
|
|
36
|
-
${download
|
|
37
|
-
? html`<button type="button" class="dc-icon-button dc-download" data-role="download" aria-label="${t.download(download.name)}" title="${t.download(download.name)}">${icon('M12 4v11m-5-5 5 5 5-5M5 20h14')}</button>`
|
|
38
|
-
: ''}
|
|
39
34
|
</div>
|
|
40
35
|
</section>
|
|
41
36
|
`;
|
|
@@ -23,8 +23,6 @@ export const texts = {
|
|
|
23
23
|
/** 연 뒤 넘긴 쪽을 받지 못함 (서명 주소 만료: 학생 화면 6시간) */
|
|
24
24
|
expired: '문서 주소가 만료됐어요. 새로고침해 주세요.',
|
|
25
25
|
openFailed: '문서를 열지 못했어요. 파일이 손상되었거나 지원하지 않는 내용이 있을 수 있어요.',
|
|
26
|
-
/** 학생 화면 내려받기 버튼 (올린 파일 그대로. 받지 못하면 새 탭으로 엶) */
|
|
27
|
-
download: (name) => (name ? `${name} 내려받기` : '문서 내려받기'),
|
|
28
26
|
thumbnails: '쪽 목록',
|
|
29
27
|
thumbnail: (n) => `${n}쪽`,
|
|
30
28
|
},
|
|
@@ -32,8 +32,6 @@
|
|
|
32
32
|
--dc-nav-hover-line: var(--ec-edit-hover-line);
|
|
33
33
|
--dc-nav-input-hover-bg: color-mix(in srgb, var(--eds-text-primary) 8%, transparent);
|
|
34
34
|
--dc-nav-input-focus-bg: var(--eds-background-paper);
|
|
35
|
-
/* 좁거나 낮은 학생 화면의 넘기기 줄 높이 (styles.css @container dc-learn) */
|
|
36
|
-
--dc-compact-bar: 24px;
|
|
37
35
|
|
|
38
36
|
/* 학생 화면: 어두운 바탕. 디자이너(연주님) 시안의 고정값이라 밝은 · 어두운 테마 모두 같은 색입니다 */
|
|
39
37
|
--dc-learn-bg: #212121;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
Elice Custom HTML 학습자료 프로젝트입니다 (YouTube 템플릿). YouTube 영상 주소 하나를 받아 학생 화면에 플레이어로 보여 줍니다. 제출은 없고, 완료 정책은 **열람 시 완료(on_access)**를 권장합니다.
|
|
4
|
+
|
|
5
|
+
플레이어는 `https://www.youtube-nocookie.com/embed/<영상 ID>` iframe입니다. YouTube IFrame API 스크립트는 쓰지 않습니다 (콘텐츠 CSP가 외부 스크립트를 막음). 콘텐츠 CSP는 `frame-src`에서 `https://www.youtube-nocookie.com/embed/` 경로만 허용합니다 (`rules.json` `externalAllow`). 서버 콘텐츠 CSP에 이 경로가 들어가기 전의 LXP에서는 플레이어 자리가 비어 보이고, 'YouTube에서 보기' 링크만 동작합니다.
|
|
6
|
+
|
|
7
|
+
## 고치는 곳
|
|
8
|
+
|
|
9
|
+
| 파일 | 화면 |
|
|
10
|
+
| --------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
11
|
+
| `screens/learn.js` · `index.html` | 학생 화면 (16:9 플레이어 + 'YouTube에서 보기' 링크, 제출 없음) |
|
|
12
|
+
| `screens/edit.js` · `edit.html` | 내용 편집 화면 ('YouTube 주소' 한 칸 · 미리보기 · '초안으로 저장'). 키트 편집 화면(`body.ec-edit-page`) |
|
|
13
|
+
| `ui/` | 모양: 색 · 문구 · 마크업 (`theme.css` · `texts.js` · `templates/`) |
|
|
14
|
+
| `styles.css` | 플레이어 자리 · 링크 줄 · 미리보기 자리 |
|
|
15
|
+
| `core/youtube.js` | 주소 읽기 · 플레이어 주소 만들기 (고치지 않음) |
|
|
16
|
+
| `core/settings.js` | 저장 모양과 검증 (고치지 않음) |
|
|
17
|
+
| `metadata.json` | 화면 구성(`screens`) · 학습 참고 내용(`commentary`). `ecdk build`가 `build`만 채움 |
|
|
18
|
+
| `package.json` | SDK 버전(`@eliceio/cdk`) · 빌드 옵션 `"ecdk"`. zip에 들어가지 않음 |
|
|
19
|
+
|
|
20
|
+
플레이어 안(재생 · 컨트롤 · 화질 · 자막 · '동영상을 재생할 수 없음' 같은 오류)은 YouTube iframe이라 이 프로젝트에서 바꿀 수 없습니다.
|
|
21
|
+
|
|
22
|
+
## 받는 주소
|
|
23
|
+
|
|
24
|
+
- `https://www.youtube.com/watch?v=ID` (`&t=90` · `&t=1m30s` · `&start=90`이 있으면 그 시각부터)
|
|
25
|
+
- `https://youtu.be/ID` · `https://www.youtube.com/embed/ID` · `/shorts/ID` · `/live/ID`
|
|
26
|
+
- `https://m.youtube.com/watch?v=ID` · `https://music.youtube.com/watch?v=ID` · `https://www.youtube-nocookie.com/embed/ID`
|
|
27
|
+
- 앞의 `https://`는 생략해도 됩니다. ID는 영문 · 숫자 · `-` · `_` 11자입니다. 재생목록 · 채널 주소처럼 영상 ID가 없는 주소는 받지 않습니다.
|
|
28
|
+
|
|
29
|
+
## 학생 화면
|
|
30
|
+
|
|
31
|
+
- 플레이어: `https://www.youtube-nocookie.com/embed/ID?rel=0&playsinline=1`(시작 시각이 있으면 `&start=N`), `allow="autoplay; encrypted-media; picture-in-picture; fullscreen"` · `allowfullscreen` · `referrerpolicy="strict-origin-when-cross-origin"`. YouTube는 퍼가는 페이지의 출처(리퍼러)를 보고 재생을 허락하므로 `referrerpolicy`를 지우지 마세요 (리퍼러가 없으면 "오류 153").
|
|
32
|
+
- 플레이어 아래 'YouTube에서 보기'는 보통 `<a href>` 링크입니다. LXP가 sandbox 밖 새 탭(앱은 앱 브라우저)으로 엽니다. `window.open`은 쓰지 않습니다 (sandbox 팝업에서 YouTube 페이지가 깨짐). 퍼가기를 막은 영상은 플레이어에서 재생되지 않으니 이 링크로 보게 됩니다.
|
|
33
|
+
- 화면 폭을 채우되, 링크 줄까지 한 화면에 보이도록 높이에 맞춰 폭을 줄입니다.
|
|
34
|
+
- 주소를 저장하지 않았으면 빈 안내("학습 자료를 준비하고 있어요")를 보입니다 (`app.hasContent` · `app.emptyState()`).
|
|
35
|
+
|
|
36
|
+
## 학습 완료
|
|
37
|
+
|
|
38
|
+
- 제출하지 않습니다. LXP 페이지 설정의 완료 정책은 **열람 시 완료(on_access)**로 둡니다 (기존 LXP YouTube 자료와 같음). publish 스킬이 동의를 받아 업로드 때 정하거나, 교육자가 LXP 편집 페이지 위쪽 '설정' 패널에서 고릅니다.
|
|
39
|
+
- 시청 비율 · 끝까지 봄 · 재생 위치는 읽지 않습니다 (IFrame API를 쓰지 않음). 출결 · 이수 증빙이 필요한 과정에는 Elice 비디오 자료를 쓰세요.
|
|
40
|
+
|
|
41
|
+
## 저장 모양 (`settings`)
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
{
|
|
45
|
+
youtube: {
|
|
46
|
+
url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ&t=30', // 교육자가 넣은 주소
|
|
47
|
+
videoId: 'aqz-KE-bpKQ', // 주소에서 읽은 영상 ID
|
|
48
|
+
start: 30, // 시작 초 (주소에 t= · start=가 있을 때만)
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- 다른 키(예: AI · MCP가 넣은 `title`)는 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
54
|
+
- `ecdk dev`의 내용 편집에서 저장한 것은 `.ecdk/settings.json`에 남습니다 (zip에는 들어가지 않음). 기본으로는 로컬에만 있고, publish 스킬로 올릴 때 동의하면 업로드와 함께 보냅니다.
|
|
55
|
+
|
|
56
|
+
교육자 화면은 없습니다 (`metadata.json` `screens.instructor.enabled: false`). LXP에서 교육자가 열면 학생 화면이 열립니다.
|
|
57
|
+
|
|
58
|
+
`lib/`(화면 키트)는 플랫폼 연결 로직이라 고치지 않습니다. SDK는 `package.json` 의존성(`@eliceio/cdk`)이고 키트가 import하며, `ecdk build`(Vite)가 화면 코드와 함께 번들로 묶습니다 (처음 한 번 `npm install`, 올리기 `npm update @eliceio/cdk`).
|
|
59
|
+
|
|
60
|
+
## 명령
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
ecdk dev # 로컬에서 보기 (ecdk dev CSP도 youtube-nocookie /embed/를 허용해 플레이어가 뜸)
|
|
64
|
+
ecdk doctor # 환경·프로젝트 점검
|
|
65
|
+
ecdk build # 검사 후 dist/content.zip (편집 화면에 올릴 파일)
|
|
66
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// core/dom.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export declare const present: (nodes: any[]) => any[];
|
|
4
|
+
export declare function el(
|
|
5
|
+
tag: string,
|
|
6
|
+
props?: Record<string, unknown>,
|
|
7
|
+
...children: any[]
|
|
8
|
+
): HTMLElement;
|
|
9
|
+
/** 최상위 요소가 하나면 그 요소(HTMLElement로 다룸), 아니면 DocumentFragment */
|
|
10
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): any;
|
|
11
|
+
export declare function part(root: Element, name: string): HTMLElement | null;
|
|
12
|
+
export declare function parts(root: Element, name: string): HTMLElement[];
|
|
13
|
+
export declare function lock<T extends Element>(root: T): T;
|
|
@@ -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 = 'yt-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/settings.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export interface YouTubeValue {
|
|
3
|
+
url: string;
|
|
4
|
+
videoId: string;
|
|
5
|
+
start?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface YouTubeDraft {
|
|
9
|
+
rest: Record<string, unknown>;
|
|
10
|
+
youtube: YouTubeValue | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare function normalizeSettings(
|
|
14
|
+
raw: Record<string, unknown> | null | undefined
|
|
15
|
+
): YouTubeDraft;
|
|
16
|
+
export declare function fromUrl(text: string): YouTubeValue | null;
|
|
17
|
+
export declare function toSettings(draft: YouTubeDraft): Record<string, unknown>;
|
|
18
|
+
export declare function validateUrl(
|
|
19
|
+
text: string,
|
|
20
|
+
messages: { urlRequired: string; urlInvalid: string }
|
|
21
|
+
): true | string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// 저장 모양(settings)과 검증. 편집 화면이 저장하고 학생 화면이 읽습니다. 고치지 않습니다: 키 이름을 바꾸면 저장한 자료를 읽지 못합니다.
|
|
2
|
+
//
|
|
3
|
+
// {
|
|
4
|
+
// youtube: {
|
|
5
|
+
// url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ&t=30', // 교육자가 넣은 주소 (앞뒤 공백만 뺌)
|
|
6
|
+
// videoId: 'aqz-KE-bpKQ', // 주소에서 읽은 영상 ID
|
|
7
|
+
// start: 30, // 시작 초 (주소에 t= · start=가 있을 때만)
|
|
8
|
+
// },
|
|
9
|
+
// }
|
|
10
|
+
// 학생 화면은 videoId · start만 씁니다 (url은 편집 화면이 다시 보여 줄 때). 그 밖의 키(예: AI · MCP가 넣은 title)는
|
|
11
|
+
// 저장 때 그대로 둡니다. 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
12
|
+
import { parseYouTubeUrl } from './youtube.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 저장된 settings를 화면이 쓰는 모양으로. videoId가 맞지 않으면 url을 다시 읽고, 그래도 아니면 youtube 없음
|
|
16
|
+
* @param {Record<string, unknown> | null | undefined} raw
|
|
17
|
+
*/
|
|
18
|
+
export function normalizeSettings(raw) {
|
|
19
|
+
const s = raw && typeof raw === 'object' ? raw : {};
|
|
20
|
+
const y = s.youtube && typeof s.youtube === 'object' ? s.youtube : null;
|
|
21
|
+
const url = y && typeof y.url === 'string' ? y.url.trim() : '';
|
|
22
|
+
const parsed = parseYouTubeUrl(url);
|
|
23
|
+
let youtube = null;
|
|
24
|
+
if (parsed) youtube = { url, ...parsed };
|
|
25
|
+
else if (y && typeof y.videoId === 'string' && parseYouTubeUrl(`youtu.be/${y.videoId}`)) {
|
|
26
|
+
const start = Number.isSafeInteger(y.start) && y.start > 0 ? y.start : undefined;
|
|
27
|
+
youtube = { url, videoId: y.videoId, ...(start ? { start } : {}) };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
/** 저장 때 그대로 둘 다른 키 */
|
|
31
|
+
rest: Object.fromEntries(Object.entries(s).filter(([k]) => k !== 'youtube')),
|
|
32
|
+
youtube,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 편집 화면의 주소 칸 글을 저장할 youtube 값으로. 빈 칸 · YouTube 주소가 아니면 null
|
|
38
|
+
* @param {string} text
|
|
39
|
+
*/
|
|
40
|
+
export function fromUrl(text) {
|
|
41
|
+
const url = typeof text === 'string' ? text.trim() : '';
|
|
42
|
+
const parsed = parseYouTubeUrl(url);
|
|
43
|
+
return parsed ? { url, ...parsed } : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 화면 상태를 저장 모양으로 */
|
|
47
|
+
export function toSettings(draft) {
|
|
48
|
+
const y = draft.youtube;
|
|
49
|
+
return {
|
|
50
|
+
...draft.rest,
|
|
51
|
+
...(y
|
|
52
|
+
? {
|
|
53
|
+
youtube: {
|
|
54
|
+
url: y.url,
|
|
55
|
+
videoId: y.videoId,
|
|
56
|
+
...(y.start ? { start: y.start } : {}),
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 저장 전 검증. 통과면 true, 아니면 화면에 보일 문구
|
|
65
|
+
* @param {string} text 주소 칸 글
|
|
66
|
+
* @param {{ urlRequired: string, urlInvalid: string }} messages
|
|
67
|
+
*/
|
|
68
|
+
export function validateUrl(text, messages) {
|
|
69
|
+
if (typeof text !== 'string' || text.trim() === '') return messages.urlRequired;
|
|
70
|
+
return fromUrl(text) ? true : messages.urlInvalid;
|
|
71
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// core/youtube.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export declare const VIDEO_ID: RegExp;
|
|
3
|
+
export declare const EMBED_BASE: string;
|
|
4
|
+
export declare function parseStart(value: string | null | undefined): number | undefined;
|
|
5
|
+
export declare function parseYouTubeUrl(
|
|
6
|
+
input: string | null | undefined
|
|
7
|
+
): { videoId: string; start?: number } | null;
|
|
8
|
+
export declare function embedUrl(videoId: string, start?: number): string;
|
|
9
|
+
export declare function watchUrl(videoId: string, start?: number): string;
|