bundle.js 1.27 KB
import * as v from 'valibot'
import { ScriptLine } from './script-line.js'

/**
 * 场景引用:Bundle 内联引用一个场景(按 id 指向 assets 库的场景资源),
 * 仅在 Bundle 内部使用,不单独作为公共 schema 出包。
 * @typedef {{ id: string, background?: string, props?: string[] }} SceneRefT
 */
export const SceneRef = v.object({
  id: v.string(),
  background: v.optional(v.string()),
  props: v.optional(v.array(v.string())),
})

/**
 * Bundle 元信息:drama 级别的播放元数据。
 * @typedef {{ locale: string, version: number, duration?: number }} BundleMetaT
 */
export const BundleMeta = v.object({
  locale: v.string(),
  version: v.number(),
  duration: v.optional(v.number()),
})

/**
 * 播放包:`<DramaPlayer :bundle>` 的入参、`@drama/core` 消费、`@drama/bundle` 出包。
 * 组合 drama 元信息 + rig 引用 + 场景序列 + 剧本行序列。
 * @typedef {{
 *   drama_id: string,
 *   title: string,
 *   rig_ref: string,
 *   scenes: SceneRefT[],
 *   lines: import('./script-line.js').ScriptLineT[],
 *   meta: BundleMetaT
 * }} BundleT
 */
export const Bundle = v.object({
  drama_id: v.string(),
  title: v.string(),
  rig_ref: v.string(),
  scenes: v.array(SceneRef),
  lines: v.array(ScriptLine),
  meta: BundleMeta,
})