@2kog/kacha 0.2.1 → 0.3.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.
Files changed (49) hide show
  1. package/bin/init-project.js +14 -23
  2. package/package.json +1 -1
  3. package/server/asset-watch.js +12 -3
  4. package/server/image-assets.js +2 -2
  5. package/server/index.js +4 -0
  6. package/server/project-scripts.js +93 -0
  7. package/server/project-settings.js +101 -12
  8. package/server/project-storyboard.js +89 -0
  9. package/src/assets/css/workbench.css +14 -15
  10. package/src/components/AssetStoryEditor.vue +15 -9
  11. package/src/components/JimengPromptPreview.vue +69 -0
  12. package/src/components/ProjectMarkdown.vue +2 -1
  13. package/src/components/ScriptVersionDiff.vue +96 -0
  14. package/src/components/StoryboardDocument.vue +99 -0
  15. package/src/i18n/en.json +42 -7
  16. package/src/layouts/WorkbenchLayout.vue +35 -46
  17. package/src/router/index.js +8 -2
  18. package/src/service/project-markdown.js +13 -1
  19. package/src/service/resume.js +18 -0
  20. package/src/views/assets/CharacterAssets.vue +39 -5
  21. package/src/views/home/ProjectHome.vue +119 -0
  22. package/src/views/scripts/ProjectScripts.vue +272 -0
  23. package/src/views/scripts/ProjectStoryboard.vue +126 -0
  24. package/src/views/settings/ProjectSettings.vue +62 -20
  25. package/templates/project/.lfsconfig +2 -0
  26. package/templates/project/AGENTS.md +116 -15
  27. package/templates/project/README.md +51 -7
  28. package/templates/project/assets/audio/.gitkeep +0 -0
  29. package/templates/project/assets/characters/.gitkeep +0 -0
  30. package/templates/project/assets/other/.gitkeep +0 -0
  31. package/templates/project/assets/props/.gitkeep +0 -0
  32. package/templates/project/assets/scenes/.gitkeep +0 -0
  33. package/templates/project/config/.gitkeep +0 -0
  34. package/templates/project/docs/art//345/234/272/346/231/257/344/270/216/347/251/272/351/227/264.md +3 -0
  35. package/templates/project/docs/art//350/247/222/350/211/262/347/276/216/346/234/257.md +3 -0
  36. package/templates/project/docs/art//351/201/223/345/205/267/347/276/216/346/234/257.md +3 -0
  37. package/templates/project/docs/other//350/241/245/345/205/205/350/257/264/346/230/216.md +7 -0
  38. package/templates/project/docs/story//344/270/226/347/225/214/350/247/202/344/270/216/350/247/222/350/211/262.md +3 -0
  39. package/templates/project/env.template +5 -0
  40. package/templates/project/gitignore.template +5 -0
  41. package/templates/project/package.json +8 -0
  42. package/templates/project/scripts/.gitkeep +0 -0
  43. package/templates/project/storyboard/.gitkeep +0 -0
  44. package/vite.config.js +1 -1
  45. package/templates/project/assets/audio/README.md +0 -5
  46. package/templates/project/assets/characters/README.md +0 -5
  47. package/templates/project/assets/other/README.md +0 -3
  48. package/templates/project/assets/props/README.md +0 -3
  49. package/templates/project/assets/scenes/README.md +0 -3
@@ -0,0 +1,119 @@
1
+ <script>
2
+ import { recentWork } from '@/service/resume.js'
3
+ import { AudioLines, Box, ChevronRight, FileText, Layers3, Mountain, Users } from 'lucide-vue-next'
4
+ import { requestAsset } from '@/service/assets.js'
5
+
6
+ const metrics = [
7
+ { route: 'scripts', label: '分集', icon: 'FileText' },
8
+ { route: 'characters', label: '角色', icon: 'Users' },
9
+ { route: 'scenes', label: '场景', icon: 'Mountain' },
10
+ { route: 'props', label: '道具', icon: 'Box' },
11
+ { route: 'other', label: '其他素材', icon: 'Layers3' },
12
+ { route: 'audio', label: '音频', icon: 'AudioLines' },
13
+ ]
14
+
15
+ export default {
16
+ components: { AudioLines, Box, ChevronRight, FileText, Layers3, Mountain, Users },
17
+ data() {
18
+ return { metrics, counts: {}, resume: recentWork(), playlist: [], position: 0, videoError: false }
19
+ },
20
+ computed: {
21
+ current() { return this.playlist[this.position] },
22
+ },
23
+ mounted() {
24
+ if (!this.resume) this.findLatestWork()
25
+ this.subscriptions = metrics.map(({ route }) => {
26
+ const refresh = () => this.loadCount(route)
27
+ const event = 'workbench:' + route + ':changed'
28
+ import.meta.hot?.on(event, refresh)
29
+ refresh()
30
+ return () => import.meta.hot?.off(event, refresh)
31
+ })
32
+ },
33
+ beforeUnmount() {
34
+ this.subscriptions.forEach(unsubscribe => unsubscribe())
35
+ },
36
+ methods: {
37
+ async findLatestWork() {
38
+ try {
39
+ const episodes = await requestAsset('storyboard')
40
+ const latest = episodes.filter(item => /^\d{3}-/.test(item.name) && item.scenes.some(scene =>
41
+ scene.groups.some(group => group.media.length))).sort((a, b) => b.name.localeCompare(a.name))[0]
42
+ if (latest) this.resume = { name: 'storyboard', query: { episode: latest.name }, labels: [this.episodeTitle(latest.name), this.$t('分镜')] }
43
+ } catch { /* A project without an available storyboard has no suggested position. */ }
44
+ },
45
+ episodeTitle(name) {
46
+ if (name === 'opening') return this.$t('片头')
47
+ if (name === 'ending') return this.$t('片尾')
48
+ return name.replace(/^\d{3}-/, '')
49
+ },
50
+ async playAt(position) {
51
+ if (!this.playlist[position]) return
52
+ this.videoError = false
53
+ this.position = position
54
+ await this.$nextTick()
55
+ try { await this.$refs.player.play() } catch { /* Native controls allow manual playback. */ }
56
+ },
57
+ async loadCount(route) {
58
+ try {
59
+ const items = await requestAsset(route)
60
+ if (route === 'scripts') {
61
+ this.playlist = items.filter(item => item.videos.length).map(item => ({
62
+ episode: item.name,
63
+ file: item.videos.find(file => /^index\.mp4$/i.test(file))
64
+ || item.videos.find(file => /^index\./i.test(file)) || item.videos[0],
65
+ }))
66
+ }
67
+ this.counts[route] = route === 'scripts'
68
+ ? items.filter(item => /^\d{3}-/.test(item.name)).length
69
+ : items.length
70
+ } catch {
71
+ this.counts[route] = null
72
+ }
73
+ },
74
+ },
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <section class="content">
80
+ <h1>{{ $t('项目总览') }}</h1>
81
+ <RouterLink v-if="resume" class="resume-work" :to="{ name: resume.name, query: resume.query }">
82
+ <strong>{{ $t('继续制作') }}</strong><span>{{ resume.labels.join(' / ') }}</span><ChevronRight :size="16" />
83
+ </RouterLink>
84
+ <div class="overview-grid">
85
+ <RouterLink v-for="metric in metrics" :key="metric.route" class="overview-card" :to="{ name: metric.route }">
86
+ <span class="overview-label"><component :is="metric.icon" :size="18" />{{ $t(metric.label) }}</span>
87
+ <strong>{{ counts[metric.route] === null ? $t('读取失败') : counts[metric.route] ?? '…' }}</strong>
88
+ <ChevronRight class="overview-arrow" :size="16" />
89
+ </RouterLink>
90
+ </div>
91
+ <section class="screening">
92
+ <h2>{{ $t('成片连播') }}</h2>
93
+ <template v-if="current">
94
+ <video ref="player" :key="current.episode" controls playsinline preload="metadata"
95
+ :aria-label="episodeTitle(current.episode)" :src="'/api/scripts?video=' + encodeURIComponent(current.episode + '/' + current.file)"
96
+ @error="videoError = true" @ended="playAt(position + 1)" />
97
+ <p v-if="videoError" role="alert">{{ $t('无法播放此视频') }}</p>
98
+ <div class="screening-list">
99
+ <button v-for="(item, index) in playlist" :key="item.episode" :aria-pressed="position === index" @click="playAt(index)">
100
+ {{ episodeTitle(item.episode) }}
101
+ </button>
102
+ </div>
103
+ </template>
104
+ <p v-else>{{ $t(counts.scripts === undefined ? '加载中' : counts.scripts === null ? '读取失败' : '暂无成片') }}</p>
105
+ </section>
106
+ </section>
107
+ </template>
108
+
109
+ <style scoped>
110
+ .resume-work, .screening { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin-top: 20px; }
111
+ .resume-work { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; color: inherit; text-decoration: none; }
112
+ .resume-work span { color: var(--muted); }
113
+ .resume-work svg { margin-left: auto; color: var(--accent); }
114
+ .screening h2 { font-size: 18px; margin: 0 0 14px; }
115
+ .screening video { display: block; width: 100%; max-height: 55vh; background: #12151b; }
116
+ .screening-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
117
+ .screening-list button { border: 1px solid var(--line); border-radius: 8px; background: white; padding: 6px 12px; }
118
+ .screening-list button[aria-pressed=true] { color: var(--accent); background: var(--accent-bg); }
119
+ </style>
@@ -0,0 +1,272 @@
1
+ <script>
2
+ import { rememberWork } from '@/service/resume.js'
3
+ import { ChevronRight, ExternalLink, Film } from 'lucide-vue-next'
4
+ import { ElOption, ElSelect } from 'element-plus'
5
+ import ScriptVersionDiff from '@/components/ScriptVersionDiff.vue'
6
+ import AssetStoryEditor from '@/components/AssetStoryEditor.vue'
7
+ import ProjectMarkdown from '@/components/ProjectMarkdown.vue'
8
+ import { projectFileUrl } from '@/service/project-markdown.js'
9
+
10
+ export default {
11
+ components: { ChevronRight, ExternalLink, Film, ProjectMarkdown, AssetStoryEditor, ScriptVersionDiff, ElOption, ElSelect },
12
+ data() {
13
+ return { scripts: [], active: null, file: '', article: '', error: '', loading: true, loaded: false, draft: null, saving: false, revision: 0, listRevision: 0, version: '', historic: null, versionRevision: 0 }
14
+ },
15
+ async mounted() {
16
+ import.meta.hot?.on('workbench:scripts:changed', this.refresh)
17
+ await this.refresh()
18
+ },
19
+ beforeUnmount() {
20
+ import.meta.hot?.off('workbench:scripts:changed', this.refresh)
21
+ this.listRevision++
22
+ this.revision++
23
+ this.versionRevision++
24
+ },
25
+ methods: {
26
+ async refresh() {
27
+ const revision = ++this.listRevision
28
+ try {
29
+ const response = await fetch('/api/scripts', { cache: 'no-store' })
30
+ if (!response.ok) throw new Error(this.$t('无法读取剧本目录'))
31
+ const scripts = await response.json()
32
+ if (revision !== this.listRevision) return
33
+ this.scripts = scripts
34
+ if (this.draft !== null || this.saving) return
35
+ const script = scripts.find(item => item.name === (this.active?.name || this.$route.query.episode)) || scripts[0]
36
+ const current = this.file.split('/').pop() || this.$route.query.file
37
+ const version = this.version
38
+ this.active = script
39
+ await this.open(script?.documents.includes(current) ? current : script?.documents[0], false)
40
+ if (revision === this.listRevision && this.active === this.scripts.find(item => item.name === script?.name) &&
41
+ version && script?.history.includes(version)) await this.selectVersion(version)
42
+ } catch (cause) {
43
+ if (revision === this.listRevision) this.error = cause.message
44
+ } finally { this.loading = false }
45
+ },
46
+ title(name) {
47
+ if (name === 'opening') return this.$t('片头')
48
+ if (name === 'ending') return this.$t('片尾')
49
+ return name.replace(/^\d{3}-/, '')
50
+ },
51
+ async select(script) {
52
+ this.active = script
53
+ await this.open(script.documents[0])
54
+ },
55
+ async save() {
56
+ this.saving = true
57
+ this.error = ''
58
+ try {
59
+ const response = await fetch(projectFileUrl(this.file), {
60
+ method: 'PUT',
61
+ headers: { 'Content-Type': 'application/json' },
62
+ body: JSON.stringify({ original: this.article, markdown: this.draft }),
63
+ })
64
+ if (!response.ok) throw new Error(await response.text())
65
+ rememberWork('scripts', { episode: this.active.name, file: this.file.split('/').pop() }, [this.title(this.active.name), this.file.split('/').pop()])
66
+ this.article = this.draft
67
+ this.draft = null
68
+ const listing = await fetch('/api/scripts', { cache: 'no-store' })
69
+ if (listing.ok) {
70
+ const updated = (await listing.json()).find(script => script.name === this.active.name)
71
+ if (updated) this.active.history = updated.history
72
+ }
73
+ } catch (cause) {
74
+ this.error = cause.message
75
+ } finally {
76
+ this.saving = false
77
+ }
78
+ },
79
+ async selectVersion(version) {
80
+ const revision = ++this.versionRevision
81
+ this.version = version
82
+ this.historic = null
83
+ this.error = ''
84
+ if (!version) return
85
+ const file = 'scripts/' + this.active.name + '/archive/' + version
86
+ try {
87
+ const response = await fetch(projectFileUrl(file), { cache: 'no-store' })
88
+ if (!response.ok) throw new Error(this.$t('无法读取 {file}', { file }))
89
+ const historic = await response.text()
90
+ if (revision === this.versionRevision) this.historic = historic
91
+ } catch (cause) {
92
+ if (revision === this.versionRevision) {
93
+ this.version = ''
94
+ this.error = cause.message
95
+ }
96
+ }
97
+ },
98
+ async open(document, remember = true) {
99
+ this.selectVersion('')
100
+ const revision = ++this.revision
101
+ this.error = ''
102
+ this.loaded = false
103
+ this.article = ''
104
+ this.file = document ? 'scripts/' + this.active.name + '/' + document : ''
105
+ if (!this.file) return
106
+ try {
107
+ const response = await fetch(projectFileUrl(this.file), { cache: 'no-store' })
108
+ if (!response.ok) throw new Error(this.$t('无法读取 {file}', { file: this.file }))
109
+ const article = await response.text()
110
+ if (revision === this.revision) {
111
+ this.article = article
112
+ this.loaded = true
113
+ if (remember) rememberWork('scripts', { episode: this.active.name, file: document }, [this.title(this.active.name), document === 'index.md' ? this.$t('剧本') : document])
114
+ }
115
+ } catch (cause) {
116
+ if (revision === this.revision) this.error = cause.message
117
+ }
118
+ },
119
+ videoUrl(video) {
120
+ return '/api/scripts?video=' + encodeURIComponent(this.active.name + '/' + video)
121
+ },
122
+ },
123
+ }
124
+ </script>
125
+
126
+ <template>
127
+ <section class="content">
128
+ <div class="heading"><h1>{{ $t('剧本') }}</h1></div>
129
+ <p v-if="error" class="error" role="alert">{{ error }}</p>
130
+ <p v-if="!loading && !error && !scripts.length">{{ $t('暂无剧本') }}</p>
131
+ <div v-if="active" class="settings-layout">
132
+ <nav class="settings-index" :aria-label="$t('剧本目录')">
133
+ <button v-for="script in scripts" :key="script.name"
134
+ :disabled="draft !== null || saving"
135
+ :class="{ current: active.name === script.name }"
136
+ :aria-current="active.name === script.name ? 'page' : undefined" @click="select(script)">
137
+ {{ title(script.name) }}<ChevronRight :size="14" />
138
+ </button>
139
+ </nav>
140
+ <div class="settings-reader">
141
+ <AssetStoryEditor v-model:draft="draft" :label="file" :busy="saving || !loaded || Boolean(version)" @edit="draft = article" @cancel="draft = null; refresh()" @save="save">
142
+ <template #actions>
143
+ <ElSelect v-if="file === 'scripts/' + active.name + '/index.md' && active.history.length"
144
+ class="script-version-select" :empty-values="[null, undefined]" :model-value="version" :aria-label="$t('历史版本')"
145
+ :disabled="draft !== null || saving || !loaded" @change="selectVersion">
146
+ <ElOption :label="$t('当前版本')" value="" />
147
+ <ElOption v-for="item in active.history" :key="item" :label="item" :value="item" />
148
+ </ElSelect>
149
+ </template>
150
+ <template #header>
151
+ <header :key="active.name" class="script-header">
152
+ <h2>{{ title(active.name) }}</h2>
153
+ <div v-if="active.documents.length > 1" class="script-links">
154
+ <button v-for="document in active.documents" :key="document" type="button" :disabled="draft !== null || saving"
155
+ :aria-pressed="file.endsWith('/' + active.name + '/' + document)" @click="open(document)">
156
+ {{ document === 'index.md' ? $t('剧本') : document.replace(/\.(md|markdown)$/i, '') }}
157
+ </button>
158
+ </div>
159
+ <div v-if="active.videos.length" class="script-disclosures">
160
+ <details class="script-disclosure" v-if="active.videos.length">
161
+ <summary>
162
+ <Film :size="17" aria-hidden="true" />
163
+ <span>{{ $t('成片') }}</span>
164
+ <span class="script-count">{{ active.videos.length }}</span>
165
+ <ChevronRight class="script-chevron" :size="16" aria-hidden="true" />
166
+ </summary>
167
+ <div class="script-file-list">
168
+ <a v-for="video in active.videos" :key="video" :href="videoUrl(video)" target="_blank" rel="noopener">
169
+ <span>{{ video }}</span><ExternalLink :size="14" aria-hidden="true" />
170
+ </a>
171
+ </div>
172
+ </details>
173
+ </div>
174
+ </header>
175
+ </template>
176
+ <ScriptVersionDiff v-if="version && historic !== null" :current="article" :historic="historic" :version="version" />
177
+ <p v-else-if="version" role="status">{{ $t('正在读取历史版本') }}</p>
178
+ <ProjectMarkdown v-else-if="file" :source="article" :file="file" show-images />
179
+ <p v-else>{{ $t('暂无剧本') }}</p>
180
+ </AssetStoryEditor>
181
+ </div>
182
+ </div>
183
+ </section>
184
+ </template>
185
+
186
+ <style scoped>
187
+ .script-header { display: grid; gap: 12px; padding-bottom: 16px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
188
+ .script-version-select {
189
+ width: 132px;
190
+ --el-select-border-color-hover: #a9a5d9;
191
+ --el-select-input-focus-border-color: var(--accent);
192
+ }
193
+ .script-version-select :deep(.el-select__wrapper) {
194
+ min-height: 38px;
195
+ padding-inline: 14px;
196
+ border-radius: 8px;
197
+ font-size: 13px;
198
+ font-weight: 650;
199
+ }
200
+ .script-version-select :deep(.el-select__wrapper:not(.is-disabled):not(.is-hovering):not(.is-focused)) {
201
+ box-shadow: 0 0 0 1px var(--line) inset;
202
+ }
203
+ .script-version-select :deep(.el-select__selected-item),
204
+ .script-version-select :deep(.el-select__caret) {
205
+ color: #434b62;
206
+ }
207
+ .script-header h2 { margin: 0; }
208
+ .script-links { display: flex; flex-wrap: wrap; gap: 8px; }
209
+ .script-disclosures {
210
+ display: grid;
211
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
212
+ align-items: start;
213
+ gap: 12px;
214
+ }
215
+ .script-disclosure { min-width: 0; border: 1px solid var(--line); border-radius: 12px; }
216
+ .script-disclosure summary {
217
+ display: flex;
218
+ align-items: center;
219
+ gap: 8px;
220
+ list-style: none;
221
+ cursor: pointer;
222
+ padding: 12px;
223
+ border-radius: 11px;
224
+ font-size: 14px;
225
+ font-weight: 600;
226
+ }
227
+ .script-disclosure summary::-webkit-details-marker { display: none; }
228
+ .script-disclosure summary:hover, .script-disclosure[open] summary { background: var(--accent-bg); color: var(--accent); }
229
+ .script-disclosure[open] summary { border-radius: 11px 11px 0 0; }
230
+ .script-disclosure[open] .script-chevron { transform: rotate(90deg); }
231
+ .script-count {
232
+ margin-inline-start: auto;
233
+ color: var(--muted);
234
+ font-size: 12px;
235
+ font-variant-numeric: tabular-nums;
236
+ }
237
+ .script-file-list { display: grid; gap: 4px; padding: 8px; }
238
+ .script-file-list a, .script-file-list button {
239
+ display: flex;
240
+ align-items: center;
241
+ justify-content: space-between;
242
+ gap: 8px;
243
+ padding: 8px;
244
+ border: 0;
245
+ border-radius: 8px;
246
+ background: transparent;
247
+ color: var(--ink);
248
+ font: inherit;
249
+ font-size: 13px;
250
+ text-align: start;
251
+ text-decoration: none;
252
+ overflow-wrap: anywhere;
253
+ }
254
+ .script-file-list svg { flex-shrink: 0; }
255
+ .script-file-list :is(a, button:not(:disabled)):hover, .script-file-list [aria-pressed="true"] {
256
+ color: var(--accent);
257
+ background: var(--accent-bg);
258
+ }
259
+ .script-links button, .script-links a {
260
+ border: 1px solid var(--line);
261
+ border-radius: 8px;
262
+ background: white;
263
+ color: var(--ink);
264
+ padding: 6px 12px;
265
+ font: inherit;
266
+ text-decoration: none;
267
+ }
268
+ .script-links button:hover, .script-links a:hover, .script-links [aria-pressed="true"] {
269
+ color: var(--accent);
270
+ background: var(--accent-bg);
271
+ }
272
+ </style>
@@ -0,0 +1,126 @@
1
+ <script>
2
+ import { rememberWork } from '@/service/resume.js'
3
+ import { ElOption, ElSelect } from 'element-plus'
4
+ import StoryboardDocument from '@/components/StoryboardDocument.vue'
5
+ import { FileText, X } from 'lucide-vue-next'
6
+
7
+ export default {
8
+ components: { FileText, StoryboardDocument, ElOption, ElSelect, X },
9
+ data() {
10
+ return { revision: 0, restorePending: true, episodes: [], selected: '', loading: true, error: false, preview: null }
11
+ },
12
+ computed: {
13
+ episode() { return this.episodes.find(e => e.name === this.selected) },
14
+ },
15
+ async mounted() {
16
+ import.meta.hot?.on('workbench:storyboard:changed', this.refresh)
17
+ await this.refresh()
18
+ },
19
+ beforeUnmount() {
20
+ this.revision++
21
+ import.meta.hot?.off('workbench:storyboard:changed', this.refresh)
22
+ },
23
+ updated() {
24
+ if (!this.restorePending || !this.$refs.board) return
25
+ this.restorePending = false
26
+ const group = [...this.$refs.board.querySelectorAll('[data-group]')].find(el =>
27
+ el.dataset.scene === this.$route.query.scene && el.dataset.group === this.$route.query.group)
28
+ group?.scrollIntoView({ block: 'start' })
29
+ },
30
+ methods: {
31
+ async refresh() {
32
+ const revision = ++this.revision
33
+ try {
34
+ const response = await fetch('/api/storyboard')
35
+ if (!response.ok) throw new Error()
36
+ const episodes = await response.json()
37
+ if (revision !== this.revision) return
38
+ this.episodes = episodes
39
+ this.error = false
40
+ this.selected = (this.episodes.find(e => e.name === (this.selected || this.$route.query.episode)) || this.episodes.find(e => /^\d/.test(e.name) && e.scenes.length) || this.episodes[0])?.name || ''
41
+ if (this.preview) {
42
+ const key = this.preview.url.split('&modified=')[0]
43
+ this.preview = this.episode?.scenes.flatMap(scene => scene.groups.flatMap(group => group.media))
44
+ .find(media => media.url.split('&modified=')[0] === key) || null
45
+ if (!this.preview) this.$refs.viewer.close()
46
+ }
47
+ } catch { if (revision === this.revision) this.error = true }
48
+ finally { this.loading = false }
49
+ },
50
+ remember(scene, group) {
51
+ if (!this.selected) return
52
+ const query = { episode: this.selected }
53
+ const labels = [this.title(this.selected)]
54
+ if (scene) { query.scene = scene; labels.push(scene) }
55
+ if (group) { query.group = group; if (group !== scene) labels.push(group) }
56
+ rememberWork('storyboard', query, labels)
57
+ },
58
+ title(name) { return name === 'opening' ? this.$t('片头') : name === 'ending' ? this.$t('片尾') : name },
59
+ open(media) { this.preview = media; this.$refs.viewer.showModal() },
60
+ },
61
+ }
62
+ </script>
63
+
64
+ <template>
65
+ <section class="storyboard-page">
66
+ <div class="board-tools">
67
+ <h1>{{ $t('分镜') }}</h1>
68
+ <ElSelect v-model="selected" :aria-label="$t('分集')" style="width:210px" @change="$refs.list.scrollTop = 0; remember()">
69
+ <template #label="{ label }"><span class="episode-number">{{ label.match(/^\d+/)?.[0] }}</span>{{ label.replace(/^\d+/, '') }}</template>
70
+ <ElOption v-for="e in episodes" :key="e.name" :label="title(e.name)" :value="e.name">
71
+ <span class="episode-number">{{ e.name.match(/^\d+/)?.[0] }}</span>{{ title(e.name).replace(/^\d+/, '') }}
72
+ </ElOption>
73
+ </ElSelect>
74
+ </div>
75
+ <div ref="list" class="board-list">
76
+ <p v-if="error || loading || !episode?.scenes.length">{{ $t(error ? '读取失败' : loading ? '加载中' : '暂无分镜') }}</p>
77
+ <div v-else ref="board">
78
+ <section v-for="scene in episode.scenes" :key="scene.name" class="board-scene">
79
+ <h2>{{ scene.name }}</h2>
80
+ <div v-for="group in scene.groups" :key="group.name" class="board-group" :data-scene="scene.name" :data-group="group.name" @click.capture="remember(scene.name, group.name)" @focusin="remember(scene.name, group.name)">
81
+ <div class="group-documents">
82
+ <h3 v-if="group.name !== scene.name">{{ group.name }}</h3>
83
+ <button v-for="doc in group.documents" :key="doc.file" @click="$refs.documentEditor.open(doc)"><FileText :size="14" />{{ doc.name }}</button>
84
+ </div>
85
+ <div class="board-strip">
86
+ <article v-for="m in group.media" :key="m.url">
87
+ <video v-if="m.video" :src="m.url" controls preload="metadata" :aria-label="m.name" />
88
+ <button v-else @click="open(m)"><img :src="m.url" :alt="m.name" loading="lazy" draggable="false" /></button>
89
+ <footer><b v-if="m.primary">{{ $t('默认片段') }}</b>{{ m.name.replace(/\.[^.]+$/, '') }}</footer>
90
+ </article>
91
+ <small v-if="!group.media.length">{{ $t('暂无分镜') }}</small>
92
+ </div>
93
+ </div>
94
+ </section>
95
+ </div>
96
+ </div>
97
+ <StoryboardDocument ref="documentEditor" />
98
+ <dialog ref="viewer" @close="preview = null" @click.self="$refs.viewer.close()">
99
+ <template v-if="preview"><header>{{ preview.name }}<button :aria-label="$t('关闭')" @click="$refs.viewer.close()"><X :size="18" /></button></header><img :src="preview.url" :alt="preview.name" /></template>
100
+ </dialog>
101
+ </section>
102
+ </template>
103
+
104
+ <style scoped>
105
+ .group-documents { display:flex; align-items:center; gap:8px; margin-bottom:8px }
106
+ .group-documents h3 { margin:0 4px 0 0 }
107
+ .group-documents button { display:inline-flex; align-items:center; gap:4px; border:1px solid var(--line); background:white; color:var(--muted); border-radius:8px; padding:4px 8px; font-size:12px }
108
+ .group-documents button:hover { background:var(--accent-bg); color:var(--accent) }
109
+
110
+ .episode-number { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
111
+ .storyboard-page{display:flex;flex-direction:column;height:calc(100dvh - 65px);min-height:320px}
112
+ .board-tools,dialog header{display:flex;align-items:center;gap:12px}
113
+ .board-tools{background:white;padding:16px 24px;flex-wrap:wrap;border-bottom:1px solid var(--line)}
114
+ h1,h2,h3{margin:0}h1{font-size:20px}h2{font-size:18px;margin-bottom:16px}h3{font-size:14px;color:var(--muted);margin-bottom:8px}
115
+ .board-list { flex:1; overflow:auto; padding:clamp(12px,2vw,24px) }
116
+ .board-scene { background:white; border:1px solid var(--line); border-radius:16px; padding:clamp(12px,2vw,20px) }
117
+ .board-scene + .board-scene { margin-top:24px }
118
+ .board-group { scroll-margin-top:16px }
119
+ .board-group + .board-group { margin-top:24px }
120
+ .group-documents { flex-wrap:wrap }
121
+ .board-strip { display:grid; grid-template-columns:repeat(auto-fill,minmax(min(100%,180px),1fr)); gap:12px }
122
+ .board-strip article { min-width:0; border:1px solid var(--line); border-radius:10px; overflow:hidden; background:white }
123
+ dialog button { display:grid; place-items:center; padding:8px; background:white; border:0; border-radius:8px; color:var(--muted) }
124
+ .board-strip article button{display:block;width:100%;border:0;padding:0;cursor:zoom-in}.board-strip img,.board-strip video{display:block;width:100%;aspect-ratio:16/9;object-fit:contain;background:#151821}.board-strip footer{padding:8px 10px;font-size:12px}.board-strip b{color:var(--accent);margin-right:6px}
125
+ dialog{border:0;border-radius:12px;padding:12px;max-width:92vw}dialog::backdrop{background:#121726ba}dialog header{justify-content:space-between;margin-bottom:8px}dialog img{display:block;max-width:86vw;max-height:78vh}
126
+ </style>
@@ -1,16 +1,17 @@
1
1
  <script>
2
2
  import { ChevronRight } from 'lucide-vue-next'
3
+ import AssetStoryEditor from '@/components/AssetStoryEditor.vue'
3
4
  import ProjectMarkdown from '@/components/ProjectMarkdown.vue'
4
5
  import { projectFileUrl } from '@/service/project-markdown.js'
5
6
 
6
7
  export default {
7
- components: { ChevronRight, ProjectMarkdown },
8
+ components: { ChevronRight, ProjectMarkdown, AssetStoryEditor },
8
9
  data() {
9
- return { documents: [], active: null, article: '', error: '', revision: 0 }
10
+ return { draft: null, original: '', saving: false, loaded: false, documents: [], active: null, article: '', error: '', revision: 0, listRevision: 0 }
10
11
  },
11
12
  computed: {
12
13
  groups() {
13
- const groups = new Map()
14
+ const groups = new Map(['故事设定', '美术设定', '其它设定'].map(group => [group, []]))
14
15
  for (const document of this.documents) {
15
16
  if (!groups.has(document.group)) groups.set(document.group, [])
16
17
  groups.get(document.group).push(document)
@@ -21,26 +22,63 @@ export default {
21
22
  async mounted() {
22
23
  import.meta.hot?.on('workbench:settings:changed', this.refresh)
23
24
  import.meta.hot?.on('workbench:scenes:changed', this.refresh)
24
- try {
25
- const response = await fetch('/api/settings')
26
- if (!response.ok) throw new Error(this.$t('无法读取项目设定目录'))
27
- this.documents = await response.json()
28
- if (this.documents.length) await this.open(this.documents[0])
29
- } catch (cause) {
30
- this.error = cause.message
31
- }
25
+ await this.refresh()
32
26
  },
33
27
  beforeUnmount() {
28
+ this.listRevision++
34
29
  this.revision++
35
30
  import.meta.hot?.off('workbench:settings:changed', this.refresh)
36
31
  import.meta.hot?.off('workbench:scenes:changed', this.refresh)
37
32
  },
38
33
  methods: {
39
- refresh() {
40
- if (this.active) return this.open(this.active, true)
34
+ async refresh() {
35
+ const revision = ++this.listRevision
36
+ try {
37
+ const response = await fetch('/api/settings', { cache: 'no-store' })
38
+ if (!response.ok) throw new Error(this.$t('无法读取设定目录'))
39
+ const documents = await response.json()
40
+ if (revision !== this.listRevision) return
41
+ this.documents = documents
42
+ const current = documents.find(doc => doc.file === this.active?.file)
43
+ if (this.draft !== null) return
44
+ if (documents.length) return this.open(current || documents[0], Boolean(current))
45
+ this.revision++
46
+ this.active = null
47
+ this.article = ''
48
+ this.error = ''
49
+ } catch (cause) {
50
+ if (revision === this.listRevision) this.error = cause.message
51
+ }
52
+ },
53
+ edit() {
54
+ this.original = this.article
55
+ this.draft = this.article
56
+ },
57
+ async cancel() {
58
+ this.draft = null
59
+ await this.refresh()
60
+ },
61
+ async save() {
62
+ this.saving = true
63
+ try {
64
+ const response = await fetch(projectFileUrl(this.active.file), {
65
+ method: 'PUT',
66
+ headers: { 'Content-Type': 'application/json' },
67
+ body: JSON.stringify({ original: this.original, markdown: this.draft }),
68
+ })
69
+ if (!response.ok) throw new Error(await response.text())
70
+ this.article = this.draft
71
+ this.draft = null
72
+ await this.refresh()
73
+ } catch (cause) {
74
+ this.error = cause.message
75
+ } finally {
76
+ this.saving = false
77
+ }
41
78
  },
42
79
  async open(document, keepArticle = false) {
43
80
  const revision = ++this.revision
81
+ this.loaded = false
44
82
  this.active = document
45
83
  if (!keepArticle) this.article = ''
46
84
  this.error = ''
@@ -48,7 +86,10 @@ export default {
48
86
  const response = await fetch(projectFileUrl(document.file))
49
87
  if (!response.ok) throw new Error(this.$t('无法读取 {file}', { file: document.file }))
50
88
  const markdown = await response.text()
51
- if (revision === this.revision) this.article = markdown
89
+ if (revision === this.revision) {
90
+ this.article = markdown
91
+ this.loaded = true
92
+ }
52
93
  } catch (cause) {
53
94
  if (revision === this.revision) this.error = cause.message
54
95
  }
@@ -59,21 +100,22 @@ export default {
59
100
 
60
101
  <template>
61
102
  <section class="content">
62
- <div class="heading"><h1>{{ $t('项目设定') }}</h1></div>
103
+ <div class="heading"><h1>{{ $t('设定') }}</h1></div>
63
104
  <p v-if="error" class="error" role="alert">{{ error }}</p>
64
105
  <div class="settings-layout">
65
- <nav class="settings-index" :aria-label="$t('项目设定目录')">
106
+ <nav class="settings-index" :aria-label="$t('设定目录')">
66
107
  <div v-for="[group, items] in groups" :key="group">
67
108
  <h2>{{ $t(group) }}</h2>
68
- <button v-for="document in items" :key="document.file" :class="{ current: active?.file === document.file }"
109
+ <button v-for="document in items" :key="document.file" :disabled="draft !== null || saving" :class="{ current: active?.file === document.file }"
69
110
  :aria-current="active?.file === document.file ? 'page' : undefined" @click="open(document)">
70
- {{ $t(document.title) }}<ChevronRight :size="14" />
111
+ {{ document.title }}<ChevronRight :size="14" />
71
112
  </button>
72
113
  </div>
73
114
  </nav>
74
115
  <div v-if="active" class="settings-reader">
75
- <div class="settings-source">{{ active.file }}</div>
76
- <ProjectMarkdown :source="article" :file="active.file" show-images />
116
+ <AssetStoryEditor v-model:draft="draft" :label="active.file" :busy="saving || !loaded" @edit="edit" @cancel="cancel" @save="save">
117
+ <ProjectMarkdown :source="article" :file="active.file" show-images />
118
+ </AssetStoryEditor>
77
119
  </div>
78
120
  </div>
79
121
  </section>
@@ -0,0 +1,2 @@
1
+ [lfs]
2
+ url = https://kacha-lfs.invalid/{{projectName}}