{"version":3,"file":"index.cjs","names":[],"sources":["../src/adapter/ChoiceRegistry.ts","../src/adapter/CommandRegistry.ts","../src/constants.ts","../src/file/FileHandler.ts","../src/file/InkjsFileHandler.ts","../src/events/EventEmitter.ts","../src/story/utils.ts","../src/story/ChoiceHandler.ts","../src/story/ContentParser.ts","../src/story/Externals.ts","../src/story/Patches.ts","../src/story/TagHandler.ts","../src/plugin/defaultLayoutPlugin.ts","../src/plugin/PluginRegistry.ts","../src/plugin/PluginLoader.ts","../src/types.ts","../src/state/choices.ts","../src/state/contents.ts","../src/state/variables.ts","../src/story/InteractionManager.ts","../src/story/InkStory.ts","../src/create.ts"],"sourcesContent":["export class ChoiceRegistry<ChoiceComponent = unknown> {\n  private _components: Map<string, ChoiceComponent> = new Map();\n\n  get(type: string): ChoiceComponent | undefined {\n    return this._components.get(type);\n  }\n\n  register(type: string, component: ChoiceComponent) {\n    this._components.set(type, component);\n  }\n\n  unregister(type: string) {\n    this._components.delete(type);\n  }\n\n  clear() {\n    this._components.clear();\n  }\n\n  has(type: string): boolean {\n    return this._components.has(type);\n  }\n}\n","import type { InkStory } from \"../story/InkStory\";\nimport type { Command } from \"./types\";\n\nconst RESTART_ICON =\n  \"M17.65 6.35A7.958 7.958 0 0 0 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z\";\n\nexport class CommandRegistry {\n  private static _commands: Map<string, Command> = new Map();\n  private static _translations: Record<string, string> = {\n    close: \"Close\",\n    menu_restart: \"Restart\",\n    menu_restart_aria: \"Restart game\",\n  };\n\n  static get commands() {\n    return CommandRegistry._commands;\n  }\n\n  static add(id: string, command: Omit<Command, \"id\">) {\n    CommandRegistry._commands.set(id, {\n      id,\n      ...command,\n    });\n  }\n\n  static get(id: string): Command | undefined {\n    return CommandRegistry._commands.get(id);\n  }\n\n  static getAll(): Command[] {\n    return Array.from(CommandRegistry._commands.values());\n  }\n\n  static execute(id: string, ink: InkStory): void | Promise<void> {\n    const command = CommandRegistry._commands.get(id);\n    if (command) {\n      return command.handler(ink);\n    }\n    console.warn(`Command \"${id}\" not found`);\n  }\n\n  static clear() {\n    CommandRegistry._commands.clear();\n  }\n\n  static addTranslations(dict: Record<string, string>) {\n    Object.assign(CommandRegistry._translations, dict);\n  }\n\n  static getTranslation(key: string) {\n    return CommandRegistry._translations[key];\n  }\n}\n\nCommandRegistry.add(\"restart\", {\n  name: \"menu_restart\",\n  description: \"menu_restart_aria\",\n  icon: RESTART_ICON,\n  priority: 100,\n  handler: (ink: InkStory) => {\n    ink.restart();\n  },\n});\n","import type { InkStoryOptions } from \"./types\";\n\nexport const CHOICE_SEPARATOR = \"\\x00ink-divider\\x00\";\n\nexport const DEFAULT_STORY_OPTIONS: InkStoryOptions = {\n  debug: false,\n};\n\nexport const Events = {\n  STORY_INITIALIZED: \"story.initialized\",\n  STORY_CLEARED: \"story.cleared\",\n  STORY_DISPOSE: \"story.dispose\",\n  STORY_RESTART_START: \"story.restart.start\",\n  STORY_RESTART_END: \"story.restart.end\",\n  STORY_CONTINUE_START: \"story.continue.start\",\n  STORY_CONTINUE_END: \"story.continue.end\",\n  CHOICE_SELECTING: \"choice.selecting\",\n  CHOICE_SELECTED: \"choice.selected\",\n  CONTENTS_CHANGED: \"contents.changed\",\n  INTERACTION_TRIGGERED: \"interaction.triggered\",\n} as const;\n","export interface FileHandler {\n  loadFile(filename: string): string;\n  resolveFilename?(filename: string): string;\n}\n\nexport class BaseFileHandler implements FileHandler {\n  protected basePath: string;\n\n  constructor(options?: { basePath?: string }) {\n    this.basePath = options?.basePath || \"\";\n  }\n\n  resolveFilename(filename: string): string {\n    if (this.basePath) {\n      return `${this.basePath.replace(/\\/$/, \"\")}/${filename}`;\n    }\n    return filename;\n  }\n\n  loadFile(_filename: string): string {\n    throw new Error(\"loadFile must be implemented by subclass\");\n  }\n}\n","import type { FileHandler } from \"./FileHandler\";\nimport { BaseFileHandler } from \"./FileHandler\";\n\nexport class InkjsFileHandler {\n  private handler: FileHandler;\n  private resolve: (filename: string) => string;\n\n  constructor(handler: FileHandler) {\n    this.handler = handler;\n    this.resolve =\n      handler instanceof BaseFileHandler || typeof handler.resolveFilename === \"function\"\n        ? (f: string) => handler.resolveFilename?.(f) ?? f\n        : (f: string) => f;\n  }\n\n  readonly ResolveInkFilename = (filename: string): string => {\n    return this.resolve(filename);\n  };\n\n  readonly LoadInkFileContents = (filename: string): string => {\n    return this.handler.loadFile(filename);\n  };\n}\n","import type { EventData, EventEmitterInterface, EventHandler } from \"./types\";\n\nexport class EventEmitter implements EventEmitterInterface {\n  private handlers: Map<string, Set<EventHandler<EventData>>> = new Map();\n\n  on<T extends EventData = EventData>(eventName: string, handler: EventHandler<T>): () => void {\n    if (!this.handlers.has(eventName)) {\n      this.handlers.set(eventName, new Set<EventHandler<EventData>>());\n    }\n\n    this.handlers.get(eventName)?.add(handler as EventHandler<EventData>);\n\n    return () => this.off(eventName, handler);\n  }\n\n  off<T extends EventData = EventData>(eventName: string, handler: EventHandler<T>): void {\n    const handlers = this.handlers.get(eventName);\n    if (handlers) {\n      handlers.delete(handler as EventHandler<EventData>);\n      if (handlers.size === 0) {\n        this.handlers.delete(eventName);\n      }\n    }\n  }\n\n  emit<T extends EventData = EventData>(eventName: string, data?: T): void {\n    const handlers = this.handlers.get(eventName);\n    if (handlers) {\n      const handlersCopy = Array.from(handlers) as EventHandler<T>[];\n      for (const handler of handlersCopy) {\n        try {\n          handler(data || ({} as T));\n        } catch (error) {\n          console.error(`Error in event handler for \"${eventName}\":`, error);\n        }\n      }\n    }\n  }\n\n  once<T extends EventData = EventData>(eventName: string, handler: EventHandler<T>): () => void {\n    const unsubscribe = this.on(eventName, (data: T) => {\n      handler(data);\n      unsubscribe();\n    });\n\n    return unsubscribe;\n  }\n\n  listenerCount(eventName: string): number {\n    const handlers = this.handlers.get(eventName);\n    return handlers?.size ?? 0;\n  }\n\n  clear(): void {\n    this.handlers.clear();\n  }\n}\n","export const splitAtCharacter = (text: string, character: string) => {\n  if (!text) {\n    return;\n  }\n\n  const splitIndex = text.indexOf(character);\n\n  if (splitIndex === -1) {\n    return {\n      before: text.trim().toLowerCase(),\n    };\n  } else {\n    return {\n      before: text.slice(0, splitIndex).trim().toLowerCase(),\n      after: text.slice(splitIndex + 1).trim(),\n    };\n  }\n};\n","import type { Choice as InkChoice } from \"inkjs/engine/Choice\";\nimport type { Choice } from \"../types\";\nimport { splitAtCharacter } from \"./utils\";\n\ntype ChoiceHandlerFn = (choice: Choice, val?: string) => void;\n\nexport class ChoiceHandler {\n  private static _handlers: Map<string, ChoiceHandlerFn> = new Map();\n  private static readonly _builtins: Set<string> = new Set([\"unclickable\"]);\n\n  static get handlers() {\n    return ChoiceHandler._handlers;\n  }\n\n  static clear = () => {\n    for (const [key] of ChoiceHandler._handlers.entries()) {\n      if (!ChoiceHandler._builtins.has(key)) {\n        ChoiceHandler._handlers.delete(key);\n      }\n    }\n  };\n\n  static add = (tag: string, callback: ChoiceHandlerFn) => {\n    ChoiceHandler.handlers.set(tag, callback);\n  };\n\n  static process = (item: InkChoice, choice: Choice) => {\n    if (!item.text) return choice;\n\n    if (item.tags?.length && ChoiceHandler.handlers.size) {\n      item.tags.forEach((tag) => {\n        const splitTag = splitAtCharacter(tag, \":\");\n\n        if (splitTag && ChoiceHandler.handlers.has(splitTag.before)) {\n          ChoiceHandler.handlers.get(splitTag.before)?.(choice, splitTag.after);\n        }\n      });\n    }\n  };\n}\n\nChoiceHandler.add(\"unclickable\", (choice) => {\n  choice.type = \"unclickable\";\n});\n","import type { ContentItem } from \"../types\";\nimport { splitAtCharacter } from \"./utils\";\n\nexport interface ContentParserLine {\n  text: string;\n  tags: string[];\n  classes: string[];\n}\n\ntype ContentParserCallback = (line: ContentParserLine, ...args: unknown[]) => unknown;\n\nexport class ContentParser {\n  private static _tags: Map<string, ContentParserCallback> = new Map();\n  private static _patterns: {\n    matcher: string | RegExp;\n    callback: (line: ContentParserLine) => unknown;\n  }[] = [];\n\n  static get tags() {\n    return ContentParser._tags;\n  }\n\n  static get patterns() {\n    return ContentParser._patterns;\n  }\n\n  static clear = () => {\n    ContentParser._tags = new Map();\n    ContentParser._patterns = [];\n  };\n\n  static tag(tag: string, callback: ContentParserCallback) {\n    ContentParser.tags.set(tag, callback);\n  }\n\n  static pattern(pattern: string | RegExp, callback: (line: ContentParserLine) => unknown) {\n    ContentParser.patterns.push({ matcher: pattern, callback: callback });\n  }\n\n  static process = (text: string, tags: string[] = []): ContentItem => {\n    if (!text) return { text: \"\", classes: [] };\n\n    const line: ContentParserLine = { text: text, tags: tags, classes: [] };\n\n    if (line.tags.length && ContentParser._tags.size > 0) {\n      line.tags.forEach((tag) => {\n        const splitTag = splitAtCharacter(tag, \":\");\n\n        if (splitTag && ContentParser.tags.has(splitTag.before)) {\n          const handler = ContentParser.tags.get(splitTag.before);\n          if (handler) {\n            handler(line, splitTag.before, splitTag.after);\n          }\n        }\n      });\n    }\n\n    if (line.text && ContentParser.patterns.length) {\n      ContentParser.patterns.forEach((pattern) => {\n        if (\n          (typeof pattern.matcher === \"string\" && line.text.includes(pattern.matcher)) ||\n          (pattern.matcher instanceof RegExp && line.text.match(pattern.matcher))\n        ) {\n          pattern.callback(line);\n        }\n      });\n    }\n    return { text: line.text, classes: line.classes };\n  };\n}\n","import type { InkStory } from \"./InkStory\";\n\ntype ExternalFn = (...args: unknown[]) => unknown;\n\ntype ExternalResolver = (id: string) => ExternalFn | undefined;\n\nexport class Externals {\n  private static _functions: Map<string, ExternalFn> = new Map();\n  private static _resolver?: ExternalResolver;\n\n  static get functions() {\n    return Externals._functions;\n  }\n\n  static setResolver(resolver: ExternalResolver) {\n    Externals._resolver = resolver;\n  }\n\n  static add(id: string, func: ExternalFn) {\n    Externals.functions.set(id, func);\n  }\n\n  static get(id: string) {\n    return Externals.functions.get(id);\n  }\n\n  static bind(ink: InkStory, id: string) {\n    let externalFn = Externals.get(id);\n    if (!externalFn && Externals._resolver) {\n      externalFn = Externals._resolver(id);\n    }\n    if (externalFn) {\n      ink.story.BindExternalFunction(id, externalFn.bind(ink));\n    }\n  }\n\n  static clear() {\n    Externals.functions.clear();\n  }\n}\n","import type { InkStoryContext } from \"../types\";\n\nexport type PatchFn = (this: InkStoryContext, content: string) => void;\n\nexport class Patches {\n  private static _patches: PatchFn[] = [];\n  private static _options: Record<string, unknown> = {};\n\n  static get patches() {\n    return Patches._patches;\n  }\n\n  static add(callback: PatchFn | null, patchOptions: Record<string, unknown> = {}) {\n    Object.assign(Patches._options, patchOptions);\n    if (callback) Patches._patches.push(callback);\n  }\n\n  static apply(story: InkStoryContext, content: string) {\n    if (!story.options) return;\n    Object.assign(story.options, Patches._options);\n    for (const patch of Patches._patches) {\n      if (patch) {\n        patch.call(story, content);\n      }\n    }\n  }\n\n  static clear() {\n    Patches._patches = [];\n    Patches._options = {};\n  }\n}\n","import type { InkStory } from \"./InkStory\";\nimport { splitAtCharacter } from \"./utils\";\n\ntype TagHandlerFn = (val: string | null | undefined, ink: InkStory) => void;\n\nexport class TagHandler {\n  private static _handlers: Map<string, TagHandlerFn> = new Map();\n  private static readonly _builtins: Set<string> = new Set([\"clear\", \"restart\"]);\n\n  static get handlers() {\n    return TagHandler._handlers;\n  }\n\n  static clear() {\n    for (const [key] of TagHandler._handlers.entries()) {\n      if (!TagHandler._builtins.has(key)) {\n        TagHandler._handlers.delete(key);\n      }\n    }\n  }\n\n  static add(tagName: string, callback: TagHandlerFn) {\n    TagHandler.handlers.set(tagName, callback);\n  }\n\n  static isFlushTag(tagName: string): boolean {\n    return TagHandler._builtins.has(tagName);\n  }\n\n  static process = (ink: InkStory, inputString: string) => {\n    const splitTag = splitAtCharacter(inputString, \":\");\n    if (splitTag) {\n      if (TagHandler.handlers.has(splitTag.before)) {\n        TagHandler.handlers.get(splitTag.before)?.(splitTag.after, ink);\n      } else {\n        const options = ink.options as Record<string, unknown>;\n        if (options[splitTag.before] !== undefined) {\n          let newValue: string | number | boolean | undefined = splitTag.after;\n          const optionType = typeof options[splitTag.before];\n          switch (optionType) {\n            case \"string\":\n              break;\n            case \"number\":\n              if (typeof newValue === \"string\") {\n                newValue = parseFloat(newValue);\n              } else {\n                newValue = undefined;\n              }\n              break;\n            case \"boolean\":\n              newValue = !!newValue;\n              break;\n            default:\n              newValue = undefined;\n          }\n          if (newValue !== undefined && !Number.isNaN(newValue)) {\n            options[splitTag.before] = newValue;\n          }\n        }\n      }\n    }\n  };\n}\n\nTagHandler.add(\"clear\", (_: string | null | undefined, ink: InkStory) => {\n  ink.clear();\n});\n\nTagHandler.add(\"restart\", (_: string | null | undefined, ink: InkStory) => {\n  ink.restart();\n});\n","import type { Layout } from \"./types\";\n\nexport const defaultLayoutPlugin: Layout = {\n  id: \"default-layout\",\n  name: \"Default Layout Plugin\",\n  description: \"Provides the default InkWeave layout\",\n  onLoad: () => {},\n};\n","import { defaultLayoutPlugin } from \"./defaultLayoutPlugin\";\nimport type { Layout, Plugin } from \"./types\";\n\nexport class PluginRegistry {\n  private static _layouts: Map<string, Layout> = new Map();\n  private static _plugins: Map<string, Plugin> = new Map();\n  private static _enabledConfig: Record<string, boolean> = {};\n  private static _activeLayoutId: string | null = null;\n\n  private static ensureBuiltinPlugins() {\n    if (!PluginRegistry._layouts.has(\"default-layout\")) {\n      PluginRegistry._layouts.set(\"default-layout\", defaultLayoutPlugin);\n    }\n  }\n\n  static register(plugin: Plugin) {\n    PluginRegistry._plugins.set(plugin.id, plugin);\n  }\n\n  static registerLayout(plugin: Layout) {\n    PluginRegistry._layouts.set(plugin.id, plugin);\n  }\n\n  // --- 公共 ---\n\n  static get(id: string): Layout | Plugin | undefined {\n    return PluginRegistry._layouts.get(id) ?? PluginRegistry._plugins.get(id);\n  }\n\n  static getPlugins(): Plugin[] {\n    return Array.from(PluginRegistry._plugins.values());\n  }\n\n  static getLayouts(): Layout[] {\n    return Array.from(PluginRegistry._layouts.values());\n  }\n\n  // --- Layout ---\n\n  static setLayout(pluginId: string | null) {\n    PluginRegistry.ensureBuiltinPlugins();\n    if (pluginId && !PluginRegistry._layouts.has(pluginId)) {\n      console.warn(`InkWeave: display plugin \"${pluginId}\" not found`);\n      return;\n    }\n    PluginRegistry._activeLayoutId = pluginId;\n  }\n\n  static getActiveLayout(): Layout | null {\n    PluginRegistry.ensureBuiltinPlugins();\n    const id = PluginRegistry._activeLayoutId ?? \"default-layout\";\n    return PluginRegistry._layouts.get(id) ?? null;\n  }\n\n  // --- Plugin ---\n\n  static setEnabled(enabled: Record<string, boolean>) {\n    PluginRegistry.ensureBuiltinPlugins();\n    if (!enabled || typeof enabled !== \"object\") return;\n    const validated = Object.fromEntries(\n      Object.entries(enabled).filter(([, value]) => typeof value === \"boolean\"),\n    );\n    const resolved = PluginRegistry.resolveDependencies(validated);\n    PluginRegistry._enabledConfig = { ...PluginRegistry._enabledConfig, ...resolved };\n  }\n\n  static isEnabled(id: string): boolean {\n    if (PluginRegistry._layouts.has(id)) {\n      return id === (PluginRegistry._activeLayoutId ?? \"default-layout\");\n    }\n\n    // 活跃 Layout 的 exclude 列表中的插件自动禁用\n    const layout = PluginRegistry.getActiveLayout();\n    if (layout?.exclude?.includes(id)) {\n      if (!(id in PluginRegistry._enabledConfig)) {\n        return false;\n      }\n    }\n\n    const configValue = PluginRegistry._enabledConfig[id];\n    if (configValue !== undefined) return configValue;\n    return PluginRegistry._plugins.get(id)?.enabledByDefault ?? true;\n  }\n\n  static clear() {\n    PluginRegistry._layouts.clear();\n    PluginRegistry._plugins.clear();\n    PluginRegistry._enabledConfig = {};\n    PluginRegistry._activeLayoutId = null;\n  }\n\n  static resolveDependencies(pluginConfig: Record<string, boolean>): Record<string, boolean> {\n    const resolved = { ...pluginConfig };\n\n    const deps: Record<string, string[]> = {};\n    const rdeps: Record<string, string[]> = {};\n    for (const [id, plugin] of PluginRegistry._plugins) {\n      deps[id] = plugin.dependencies ?? [];\n      if (!rdeps[id]) rdeps[id] = [];\n    }\n    for (const [id, plugin] of PluginRegistry._plugins) {\n      for (const dep of plugin.dependencies ?? []) {\n        if (!rdeps[dep]) rdeps[dep] = [];\n        rdeps[dep].push(id);\n      }\n    }\n\n    const bfs = (start: string, edges: Record<string, string[]>): Set<string> => {\n      const found = new Set<string>();\n      const seen = new Set<string>();\n      const queue = [start];\n      let head = 0;\n      while (head < queue.length) {\n        const id = queue[head++];\n        if (!id || seen.has(id)) continue;\n        seen.add(id);\n        for (const next of edges[id] ?? []) {\n          if (!found.has(next)) {\n            found.add(next);\n            queue.push(next);\n          }\n        }\n      }\n      return found;\n    };\n\n    for (const [id, enabled] of Object.entries(pluginConfig)) {\n      if (enabled) {\n        for (const dep of bfs(id, deps)) {\n          if (!(dep in pluginConfig && !pluginConfig[dep])) {\n            resolved[dep] = true;\n          }\n        }\n      }\n    }\n\n    for (const [id, enabled] of Object.entries(pluginConfig)) {\n      if (!enabled) {\n        for (const dep of bfs(id, rdeps)) {\n          if (!(dep in pluginConfig && pluginConfig[dep])) {\n            if (resolved[dep] !== false) {\n              console.warn(\n                `InkWeave: plugin \"${dep}\" implicitly disabled because \"${id}\" is disabled`,\n              );\n            }\n            resolved[dep] = false;\n          }\n        }\n      }\n    }\n\n    return resolved;\n  }\n}\n","import { Events } from \"../constants\";\nimport { ChoiceHandler } from \"../story/ChoiceHandler\";\nimport { ContentParser } from \"../story/ContentParser\";\nimport { Externals } from \"../story/Externals\";\nimport type { InkStory } from \"../story/InkStory\";\nimport { Patches } from \"../story/Patches\";\nimport { TagHandler } from \"../story/TagHandler\";\nimport { PluginRegistry } from \"./PluginRegistry\";\n\nexport class PluginLoader {\n  private _loadedIds: Set<string> = new Set();\n  private _activeClassName: string | null = null;\n\n  constructor(ink: InkStory) {\n    this.load();\n    ink.eventEmitter.on(Events.STORY_DISPOSE, () => {\n      this.dispose();\n    });\n  }\n\n  get loadedIds() {\n    return Array.from(this._loadedIds);\n  }\n\n  get activeDisplayClassName(): string | null {\n    return this._activeClassName;\n  }\n\n  load() {\n    this._loadedIds.clear();\n    this._activeClassName = null;\n\n    Patches.clear();\n    TagHandler.clear();\n    ChoiceHandler.clear();\n    ContentParser.clear();\n    Externals.clear();\n\n    // 加载显示类插件（基础，只有当前激活的）\n    const displayPlugin = PluginRegistry.getActiveLayout();\n    if (displayPlugin && PluginRegistry.isEnabled(displayPlugin.id)) {\n      displayPlugin.onLoad();\n      this._loadedIds.add(displayPlugin.id);\n      this._activeClassName = displayPlugin.injectClassName ?? null;\n    }\n\n    // 加载功能类插件\n    for (const plugin of PluginRegistry.getPlugins()) {\n      if (PluginRegistry.isEnabled(plugin.id)) {\n        plugin.onLoad();\n        this._loadedIds.add(plugin.id);\n      }\n    }\n  }\n\n  dispose() {\n    this._loadedIds.clear();\n    this._activeClassName = null;\n  }\n}\n","import type { ErrorHandler as InkErrorHandler } from \"inkjs/engine/Error\";\nimport type { EventEmitterInterface } from \"./events/types\";\nimport type { FileHandler } from \"./file/FileHandler\";\n\nexport type ErrorHandler = InkErrorHandler;\n\nexport interface InkStoryOptions {\n  title?: string;\n  errorHandler?: ErrorHandler;\n  fileHandler?: FileHandler;\n  [key: string]: unknown;\n}\n\nexport interface InkStoryContext {\n  options: InkStoryOptions;\n  save_label: string[];\n  eventEmitter: EventEmitterInterface;\n  [key: string]: unknown;\n}\n\nexport interface ContentItem {\n  text: string;\n  classes?: string[];\n}\n\nexport interface SaveData {\n  state: string;\n  contents?: ContentItem[];\n  [key: string]: unknown;\n}\n\nexport class Choice {\n  text: string;\n  index: number;\n  type: string;\n  val?: string;\n  classes: string[];\n  constructor(text: string, index: number, type: string = \"default\") {\n    this.text = text || \"\";\n    this.index = index;\n    this.type = type;\n    this.classes = [\"inkweave-choice\"];\n  }\n}\n\nexport type TranslationFunction = (content: string | undefined) => string | undefined;\n","import type { Choice as InkChoice } from \"inkjs/engine/Choice\";\nimport { create } from \"zustand\";\nimport { ChoiceHandler } from \"../story/ChoiceHandler\";\nimport { Choice } from \"../types\";\n\ntype StoryChoices = {\n  choices: Choice[];\n  choicesVisible: boolean;\n  setChoices: (choices: InkChoice[]) => void;\n  clear: () => void;\n  setChoicesVisible: (v: boolean) => void;\n};\n\nconst choicesStore = create<StoryChoices>((set) => ({\n  choices: [],\n  choicesVisible: true,\n  setChoices: (ink_choices) => {\n    const choices = ink_choices.map((choice) => {\n      const new_choice = new Choice(choice.text, choice.index);\n      if (choice.tags?.length) {\n        ChoiceHandler.process(choice, new_choice);\n      }\n      return new_choice;\n    });\n    set({ choices });\n  },\n  clear: () => set({ choices: [], choicesVisible: true }),\n  setChoicesVisible: (choicesVisible) => set({ choicesVisible }),\n}));\n\nexport default choicesStore;\n","import { create } from \"zustand\";\nimport { CHOICE_SEPARATOR } from \"../constants\";\nimport type { ContentItem } from \"../types\";\n\ntype StoryContent = {\n  contents: ContentItem[];\n  visibleLines: number | null;\n  setContents: (contents: ContentItem[]) => void;\n  add: (content: ContentItem[]) => void;\n  addSeparator: () => void;\n  clear: () => void;\n};\n\nconst contentsStore = create<StoryContent>((set) => ({\n  contents: [],\n  visibleLines: null,\n  setContents: (contents) => set({ contents }),\n  add: (content) => {\n    set((state) => ({\n      contents: [...state.contents, ...content],\n    }));\n  },\n  addSeparator: () => {\n    set((state) => ({\n      visibleLines: state.contents.length > 0 ? state.contents.length - 1 : -1,\n      contents: [...state.contents, { text: CHOICE_SEPARATOR }],\n    }));\n  },\n  clear: () => set({ contents: [], visibleLines: null }),\n}));\n\nexport default contentsStore;\n","import type { VariablesState } from \"inkjs/engine/VariablesState\";\nimport { create } from \"zustand\";\n\ntype StoryVariables = {\n  variables: Map<string, unknown>;\n  setGlobalVars: (variablesState: VariablesState) => void;\n  getPercent: (key: string, max?: number) => number;\n};\n\nconst variablesStore = create<StoryVariables>((set, get) => ({\n  variables: new Map<string, unknown>(),\n  setGlobalVars: (variablesState) => {\n    const globalVars = new Map<string, unknown>();\n\n    // @ts-expect-error - accessing internal property\n    const globalVariables = variablesState._globalVariables;\n\n    if (globalVariables) {\n      for (const key of globalVariables.keys()) {\n        const entry = globalVariables.get(key);\n        if (entry) {\n          globalVars.set(key, entry.value);\n        }\n      }\n    }\n    set({ variables: globalVars });\n  },\n  getPercent: (key, max = 10) => {\n    const raw = get().variables.get(key);\n    const value = typeof raw === \"number\" ? raw : 0;\n    return Math.max(0, Math.min(100, (value / max) * 100));\n  },\n}));\n\nexport default variablesStore;\n","import { Events } from \"../constants\";\nimport type { Choice } from \"../types\";\nimport type { InkStory } from \"./InkStory\";\n\nexport type InteractionResolver = (choices: Choice[]) => number | null;\n\nexport class InteractionManager {\n  private _rules: Map<string, InteractionResolver> = new Map();\n  private _story: InkStory;\n\n  static presets = {\n    left: (choices: Choice[]) => choices[0]?.index ?? null,\n    right: (choices: Choice[]) => choices[1]?.index ?? null,\n    first: (choices: Choice[]) => choices[0]?.index ?? null,\n    second: (choices: Choice[]) => choices[1]?.index ?? null,\n  } as const;\n\n  constructor(story: InkStory) {\n    this._story = story;\n  }\n\n  get story(): InkStory {\n    return this._story;\n  }\n\n  register(name: string, resolver: InteractionResolver): void {\n    this._rules.set(name, resolver);\n  }\n\n  unregister(name: string): void {\n    this._rules.delete(name);\n  }\n\n  trigger(name: string): boolean {\n    const resolver = this._rules.get(name);\n    if (!resolver) {\n      console.warn(`InteractionManager: \"${name}\" is not registered`);\n      return false;\n    }\n\n    const choices = this._story.choices;\n    const index = resolver(choices);\n    if (index === null || index === undefined) return false;\n\n    this._story.eventEmitter.emit(Events.INTERACTION_TRIGGERED, {\n      story: this._story,\n      interaction: name,\n      index,\n    });\n\n    return true;\n  }\n\n  getRegistered(): string[] {\n    return Array.from(this._rules.keys());\n  }\n\n  has(name: string): boolean {\n    return this._rules.has(name);\n  }\n\n  clear(): void {\n    this._rules.clear();\n  }\n}\n","import type { Story } from \"inkjs/engine/Story\";\nimport { DEFAULT_STORY_OPTIONS, Events } from \"../constants\";\nimport { EventEmitter } from \"../events/EventEmitter\";\nimport { PluginLoader } from \"../plugin/PluginLoader\";\nimport choicesStore from \"../state/choices\";\nimport contentsStore from \"../state/contents\";\nimport variablesStore from \"../state/variables\";\nimport type { ContentItem, InkStoryContext, InkStoryOptions } from \"../types\";\nimport { ContentParser } from \"./ContentParser\";\nimport { Externals } from \"./Externals\";\nimport { InteractionManager } from \"./InteractionManager\";\nimport { Patches } from \"./Patches\";\nimport { TagHandler } from \"./TagHandler\";\n\nexport class InkStory implements InkStoryContext {\n  title: string;\n  story: Story;\n  options: InkStoryOptions;\n  eventEmitter: EventEmitter;\n  pluginLoader: PluginLoader;\n  interactionManager: InteractionManager;\n  save_label: string[] = [\"contents\"];\n  [key: string]: unknown;\n\n  constructor(story: Story, title: string, options?: InkStoryOptions) {\n    this.options = { ...DEFAULT_STORY_OPTIONS, ...options };\n    this.story = story;\n    this.title = title;\n    this.eventEmitter = new EventEmitter();\n    this.pluginLoader = new PluginLoader(this);\n    this.interactionManager = new InteractionManager(this);\n    this.eventEmitter.on(Events.INTERACTION_TRIGGERED, (data: { index: number }) => {\n      this.choose(data.index);\n    });\n    const content = this.story.ToJson();\n    if (content) {\n      Patches.apply(this, content);\n      this.bindExternalFunctions(content);\n    }\n\n    const unsubscribeClear = this.eventEmitter.on(Events.STORY_CLEARED, () => {\n      contentsStore.getState().clear();\n    });\n\n    this.eventEmitter.on(Events.STORY_DISPOSE, () => {\n      unsubscribeClear();\n    });\n\n    this.eventEmitter.emit(Events.STORY_INITIALIZED, { story: this });\n  }\n\n  get contents() {\n    return contentsStore.getState().contents;\n  }\n\n  set contents(newContent: ContentItem[]) {\n    const oldContents = this.contents.length > 0 ? [...this.contents] : [];\n    contentsStore.getState().setContents(newContent);\n\n    this.eventEmitter.emit(Events.CONTENTS_CHANGED, {\n      story: this,\n      oldContents,\n      newContents: newContent,\n      timestamp: Date.now(),\n    });\n  }\n\n  get choices() {\n    return choicesStore.getState().choices;\n  }\n\n  continue = () => {\n    this.eventEmitter.emit(Events.STORY_CONTINUE_START, { story: this, state: this.story.state });\n\n    const newContent: ContentItem[] = [];\n\n    while (this.story.canContinue) {\n      let current_content: ContentItem = { text: this.story.Continue() || \"\" };\n      if (this.story.currentTags) {\n        this.story.currentTags.forEach((tag) => {\n          TagHandler.process(this, tag);\n          if (TagHandler.isFlushTag(tag)) {\n            newContent.length = 0;\n          }\n        });\n        if (current_content.text && this.story.currentTags.length) {\n          current_content = ContentParser.process(current_content.text, this.story.currentTags);\n        }\n      }\n\n      if (current_content.text.trim()) newContent.push(current_content);\n    }\n    contentsStore.getState().add(newContent);\n\n    const { currentChoices, variablesState } = this.story;\n    choicesStore.getState().setChoices(currentChoices);\n    variablesStore.getState().setGlobalVars(variablesState);\n\n    this.eventEmitter.emit(Events.CONTENTS_CHANGED, {\n      story: this,\n      newContents: newContent,\n      timestamp: Date.now(),\n    });\n\n    this.eventEmitter.emit(Events.STORY_CONTINUE_END, {\n      story: this,\n      state: this.story.state,\n      newContent,\n      choices: currentChoices,\n      variables: variablesState,\n    });\n  };\n\n  choose = (index: number) => {\n    const preChoices = [...this.choices];\n    const preSelectedChoice = preChoices[index];\n\n    this.eventEmitter.emit(Events.CHOICE_SELECTING, {\n      story: this,\n      index,\n      choices: preChoices,\n      selectedChoice: preSelectedChoice,\n    });\n\n    this.story.ChooseChoiceIndex(index);\n    contentsStore.getState().addSeparator();\n    this.continue();\n\n    this.eventEmitter.emit(Events.CHOICE_SELECTED, {\n      story: this,\n      index,\n      choices: preChoices,\n      selectedChoice: preSelectedChoice,\n    });\n  };\n\n  clear = () => {\n    this.eventEmitter.emit(Events.STORY_CLEARED, { story: this });\n  };\n\n  restart = () => {\n    this.eventEmitter.emit(Events.STORY_RESTART_START, { story: this });\n\n    this.story.ResetState();\n    this.clear();\n    this.continue();\n\n    this.eventEmitter.emit(Events.STORY_RESTART_END, { story: this });\n  };\n\n  dispose = () => {\n    this.clear();\n    this.eventEmitter.emit(Events.STORY_DISPOSE, { story: this });\n    variablesStore.setState({ variables: new Map<string, unknown>() });\n    this.eventEmitter.clear();\n  };\n\n  bindExternalFunctions = (content: string) => {\n    try {\n      const jsonContent = JSON.parse(content);\n      const externalIds = new Set<string>();\n\n      const findExternalFunctions = (obj: unknown) => {\n        if (typeof obj === \"object\" && obj !== null) {\n          const recordObj = obj as Record<string, unknown>;\n          if (\"x()\" in recordObj && typeof recordObj[\"x()\"] === \"string\") {\n            externalIds.add(recordObj[\"x()\"]);\n          }\n          for (const key of Object.keys(recordObj)) {\n            findExternalFunctions(recordObj[key]);\n          }\n        }\n      };\n\n      findExternalFunctions(jsonContent);\n      externalIds.forEach((id) => {\n        Externals.bind(this, id);\n      });\n    } catch (error) {\n      console.warn(\"Failed to parse story content for external functions:\", error);\n    }\n  };\n}\n","import { Compiler } from \"inkjs/compiler/Compiler\";\nimport { CompilerOptions } from \"inkjs/compiler/CompilerOptions\";\nimport { Story } from \"inkjs/engine/Story\";\nimport { InkjsFileHandler } from \"./file/InkjsFileHandler\";\nimport { InkStory } from \"./story/InkStory\";\nimport type { InkStoryOptions } from \"./types\";\n\nfunction isCompiledJson(input: string): boolean {\n  const trimmed = input.trim();\n  return trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\");\n}\n\nexport function createInkStory(source: string | Story, options?: InkStoryOptions): InkStory {\n  let story: Story;\n\n  if (source instanceof Story) {\n    story = source;\n  } else if (typeof source === \"string\") {\n    if (isCompiledJson(source)) {\n      story = new Story(source);\n    } else {\n      const errorHandler = options?.errorHandler || null;\n      const inkjsHandler = options?.fileHandler ? new InkjsFileHandler(options.fileHandler) : null;\n      const compilerOptions = new CompilerOptions(null, [], false, errorHandler, inkjsHandler);\n      const compiler = new Compiler(source, compilerOptions);\n      story = compiler.Compile();\n    }\n  } else {\n    throw new Error(\"Invalid source type: expected string or Story\");\n  }\n\n  return new InkStory(story, options?.title || \"Ink Story\", options);\n}\n"],"mappings":"6MAAA,IAAa,EAAb,KAAuD,CACrD,YAAoD,IAAI,IAExD,IAAI,EAA2C,CAC7C,OAAO,KAAK,YAAY,IAA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