@2kog/kacha 0.2.0 → 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 (50) hide show
  1. package/README.md +0 -14
  2. package/bin/init-project.js +14 -23
  3. package/package.json +1 -1
  4. package/server/asset-watch.js +12 -3
  5. package/server/image-assets.js +2 -2
  6. package/server/index.js +4 -0
  7. package/server/project-scripts.js +93 -0
  8. package/server/project-settings.js +101 -12
  9. package/server/project-storyboard.js +89 -0
  10. package/src/assets/css/workbench.css +14 -15
  11. package/src/components/AssetStoryEditor.vue +15 -9
  12. package/src/components/JimengPromptPreview.vue +69 -0
  13. package/src/components/ProjectMarkdown.vue +2 -1
  14. package/src/components/ScriptVersionDiff.vue +96 -0
  15. package/src/components/StoryboardDocument.vue +99 -0
  16. package/src/i18n/en.json +42 -7
  17. package/src/layouts/WorkbenchLayout.vue +35 -46
  18. package/src/router/index.js +8 -2
  19. package/src/service/project-markdown.js +13 -1
  20. package/src/service/resume.js +18 -0
  21. package/src/views/assets/CharacterAssets.vue +39 -5
  22. package/src/views/home/ProjectHome.vue +119 -0
  23. package/src/views/scripts/ProjectScripts.vue +272 -0
  24. package/src/views/scripts/ProjectStoryboard.vue +126 -0
  25. package/src/views/settings/ProjectSettings.vue +62 -20
  26. package/templates/project/.lfsconfig +2 -0
  27. package/templates/project/AGENTS.md +116 -15
  28. package/templates/project/README.md +51 -7
  29. package/templates/project/assets/audio/.gitkeep +0 -0
  30. package/templates/project/assets/characters/.gitkeep +0 -0
  31. package/templates/project/assets/other/.gitkeep +0 -0
  32. package/templates/project/assets/props/.gitkeep +0 -0
  33. package/templates/project/assets/scenes/.gitkeep +0 -0
  34. package/templates/project/config/.gitkeep +0 -0
  35. package/templates/project/docs/art//345/234/272/346/231/257/344/270/216/347/251/272/351/227/264.md +3 -0
  36. package/templates/project/docs/art//350/247/222/350/211/262/347/276/216/346/234/257.md +3 -0
  37. package/templates/project/docs/art//351/201/223/345/205/267/347/276/216/346/234/257.md +3 -0
  38. package/templates/project/docs/other//350/241/245/345/205/205/350/257/264/346/230/216.md +7 -0
  39. 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
  40. package/templates/project/env.template +5 -0
  41. package/templates/project/gitignore.template +5 -0
  42. package/templates/project/package.json +8 -0
  43. package/templates/project/scripts/.gitkeep +0 -0
  44. package/templates/project/storyboard/.gitkeep +0 -0
  45. package/vite.config.js +1 -1
  46. package/templates/project/assets/audio/README.md +0 -5
  47. package/templates/project/assets/characters/README.md +0 -5
  48. package/templates/project/assets/other/README.md +0 -3
  49. package/templates/project/assets/props/README.md +0 -3
  50. package/templates/project/assets/scenes/README.md +0 -3
@@ -10,7 +10,7 @@ import 'element-plus/es/components/dropdown/style/css'
10
10
  import 'element-plus/es/components/dropdown-item/style/css'
11
11
  import 'element-plus/es/components/dropdown-menu/style/css'
12
12
  import 'element-plus/es/components/switch/style/css'
13
- import { AudioLines, Check, ChevronDown, Image, Layers3, ListChecks, Pencil, Plus, RefreshCw, Search, Star, Upload, X } from 'lucide-vue-next'
13
+ import { AudioLines, Check, ChevronDown, Image, Layers3, ListChecks, Pencil, Play, Square, Plus, RefreshCw, Search, Star, Upload, X } from 'lucide-vue-next'
14
14
  import { requestAsset } from '@/service/assets.js'
15
15
  import { jimengSyncUrl } from '@/service/jimeng.js'
16
16
 
@@ -29,9 +29,10 @@ const tabs = [
29
29
 
30
30
  export default {
31
31
  name: 'CharacterAssets',
32
- components: { AssetDeleteButton, AssetHistory, AssetStoryEditor, AssetTagInput, ProjectMarkdown, ElCheckbox, ElDropdown, ElDropdownItem, ElDropdownMenu, ElSwitch, AudioLines, Check, ChevronDown, Image, Layers3, ListChecks, Pencil, Plus, RefreshCw, Search, Star, Upload, X },
32
+ components: { AssetDeleteButton, AssetHistory, AssetStoryEditor, AssetTagInput, ProjectMarkdown, ElCheckbox, ElDropdown, ElDropdownItem, ElDropdownMenu, ElSwitch, AudioLines, Check, ChevronDown, Image, Layers3, ListChecks, Pencil, Play, Square, Plus, RefreshCw, Search, Star, Upload, X },
33
33
  data() {
34
34
  return {
35
+ voicePlayer: null, playingVoice: null,
35
36
  mediaTypes, tabs, characters: [], query: '', filters: [], missingVoiceOnly: false, coverPreview: '', cardPreviews: {},
36
37
  selecting: false, selectedIds: new Set(),
37
38
  active: null, activeTab: 'overview', galleryFile: '', creating: false, busy: false,
@@ -84,6 +85,7 @@ export default {
84
85
  if (this.busy) return false
85
86
  },
86
87
  deactivated() {
88
+ this.stopVoice()
87
89
  this.toggleSelection(false)
88
90
  this.openRevision++
89
91
  this.$refs.create.close()
@@ -94,9 +96,33 @@ export default {
94
96
  import.meta.hot?.on('workbench:characters:changed', this.refreshAssets)
95
97
  },
96
98
  beforeUnmount() {
99
+ this.stopVoice()
97
100
  import.meta.hot?.off('workbench:characters:changed', this.refreshAssets)
98
101
  },
99
102
  methods: {
103
+ stopVoice() {
104
+ this.voicePlayer?.pause()
105
+ this.voicePlayer = null
106
+ this.playingVoice = null
107
+ },
108
+ async toggleVoice(character) {
109
+ const alreadyPlaying = this.playingVoice === character.id
110
+ this.stopVoice()
111
+ if (alreadyPlaying) return
112
+ const player = new Audio(character.media.voice)
113
+ this.voicePlayer = player
114
+ this.playingVoice = character.id
115
+ player.onended = () => {
116
+ if (this.voicePlayer === player) this.stopVoice()
117
+ }
118
+ try {
119
+ await player.play()
120
+ } catch {
121
+ if (this.voicePlayer !== player) return
122
+ this.stopVoice()
123
+ this.pageError = this.$t('无法播放默认音色')
124
+ }
125
+ },
100
126
  async refreshAssets() {
101
127
  await this.refresh()
102
128
  const active = this.active
@@ -187,6 +213,7 @@ export default {
187
213
  return character.media[preview] ? preview : character.main
188
214
  },
189
215
  async open(character) {
216
+ this.stopVoice()
190
217
  if (this.selecting) {
191
218
  this.setSelected(character.id, !this.selectedIds.has(character.id))
192
219
  return
@@ -361,9 +388,16 @@ export default {
361
388
  <img v-if="character.main" :src="character.media[cardImage(character)]" loading="lazy" :alt="character.name">
362
389
  <span v-else class="character-cover-empty" aria-hidden="true"></span>
363
390
  </button>
364
- <div v-if="canSwitchCover(character)" class="preview-toggle" role="group" :aria-label="$t('{name} 图片预览', { name: character.name })">
365
- <button :aria-pressed="cardImage(character) === 'image2d'" @click="cardPreviews[character.id] = 'image2d'">2D</button>
366
- <button :aria-pressed="cardImage(character) === 'image3d'" @click="cardPreviews[character.id] = 'image3d'">3D</button>
391
+ <div v-if="canSwitchCover(character) || character.media.voice" class="preview-toggle" role="group" :aria-label="$t('{name} 预览', { name: character.name })">
392
+ <template v-if="canSwitchCover(character)">
393
+ <button :aria-pressed="cardImage(character) === 'image2d'" @click="cardPreviews[character.id] = 'image2d'">2D</button>
394
+ <button :aria-pressed="cardImage(character) === 'image3d'" @click="cardPreviews[character.id] = 'image3d'">3D</button>
395
+ </template>
396
+ <button v-if="character.media.voice" type="button"
397
+ :title="$t('试听默认音色')" :aria-label="$t('试听默认音色')" :aria-pressed="playingVoice === character.id"
398
+ @click="toggleVoice(character)">
399
+ <component :is="playingVoice === character.id ? 'Square' : 'Play'" :size="12" aria-hidden="true" />
400
+ </button>
367
401
  </div>
368
402
  </div>
369
403
  <div class="card-info">
@@ -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>