{"version":3,"sources":["../src/core/ast-types.ts"],"names":[],"mappings":";;;AAgFO,SAAS,WAAW,IAAA,EAA6D;AACtF,EAAA,OAAO,IAAA,CAAK,IAAA,KAAS,MAAA,IAAU,OAAO,KAAK,IAAA,KAAS,QAAA;AACtD;AAOO,SAAS,YAAY,IAAA,EAAgE;AAC1F,EAAA,OAAO,IAAA,CAAK,SAAS,MAAA,IAAU,OAAO,KAAK,IAAA,KAAS,QAAA,IAAY,KAAK,IAAA,KAAS,IAAA;AAChF","file":"chunk-HZ2TNJNL.cjs","sourcesContent":["// ─── Quill Delta Types ───────────────────────────────────────────────────────\n\n/**\n * A single Quill Delta operation.\n * Can be an insert (text or embed), delete, or retain.\n */\nexport interface DeltaOp {\n  insert?: string | Record<string, unknown>;\n  delete?: number;\n  retain?: number;\n  attributes?: Attributes;\n}\n\n/**\n * A Quill Delta document — an ordered list of operations.\n */\nexport interface Delta {\n  ops: DeltaOp[];\n}\n\n// ─── AST Types ───────────────────────────────────────────────────────────────\n\n/**\n * A bag of key-value attributes from Quill (bold, color, header level, etc.).\n */\nexport type Attributes = Record<string, unknown>;\n\n/**\n * Known built-in node types produced by the parser and standard transformers.\n *\n * Custom embed types (e.g. `'my-widget'`) are also valid — the type field\n * accepts any string. This union exists to provide IDE autocomplete for the\n * common cases.\n */\nexport type KnownNodeType =\n  | 'root'\n  | 'text'\n  | 'paragraph'\n  | 'header'\n  | 'blockquote'\n  | 'code-block'\n  | 'code-block-container'\n  | 'list'\n  | 'list-item'\n  | 'table'\n  | 'table-row'\n  | 'table-cell'\n  | 'image'\n  | 'video'\n  | 'formula'\n  | 'mention';\n\n/**\n * The universal AST node. Decouples Quill's flat delta format from\n * the tree structure needed for rendering.\n */\nexport interface TNode {\n  /**\n   * Node type identifier (e.g. `'paragraph'`, `'header'`, `'list-item'`, `'video'`, `'text'`).\n   *\n   * Standard types are listed in {@link KnownNodeType}. Custom string types\n   * are also accepted for embed/extension use cases.\n   */\n  type: KnownNodeType | (string & {});\n  /** Quill attributes (formatting, ids, custom data) */\n  attributes: Attributes;\n  /** Child nodes */\n  children: TNode[];\n  /** Leaf payload — text content for text nodes, embed data for embeds */\n  data?: string | Record<string, unknown>;\n  /** Whether this node represents inline content (text, inline embeds) */\n  isInline: boolean;\n}\n\n// ─── Type Guards ─────────────────────────────────────────────────────────────\n\n/**\n * Check whether a node is a text leaf node.\n * Narrows `node.data` to `string` and `node.type` to `'text'`.\n */\nexport function isTextNode(node: TNode): node is TNode & { type: 'text'; data: string } {\n  return node.type === 'text' && typeof node.data === 'string';\n}\n\n/**\n * Check whether a node is an embed node with object data.\n * Excludes text nodes — only matches nodes whose `data` is a non-null object.\n * Narrows `node.data` to `Record<string, unknown>`.\n */\nexport function isEmbedNode(node: TNode): node is TNode & { data: Record<string, unknown> } {\n  return node.type !== 'text' && typeof node.data === 'object' && node.data !== null;\n}\n\n// ─── Transformer Types ───────────────────────────────────────────────────────\n\n/**\n * A transformer function receives the root's children array and returns\n * a new (or mutated) children array. Used as middleware in the parsing pipeline.\n *\n * Transformers operate on the children array rather than the root node,\n * eliminating the boilerplate of unwrapping/rewrapping the root.\n * The `applyTransformers` utility handles root node management.\n *\n * @example\n * ```ts\n * const imageGrouper: Transformer = (children) => {\n *   // group adjacent image nodes into a gallery container\n *   return groupImages(children);\n * };\n * ```\n */\nexport type Transformer = (children: TNode[]) => TNode[];\n\n// ─── Parser Types ────────────────────────────────────────────────────────────\n\n/**\n * Describes how a block-level attribute maps to an AST node type.\n *\n * @param value - The attribute value from the delta\n * @returns The node type and any attributes to set on the block\n */\nexport type BlockAttributeHandler = (value: unknown) => {\n  blockType: string;\n  blockAttrs: Attributes;\n};\n\n/**\n * Configuration for the DeltaParser.\n * Maps Quill attribute names to their block-level parsing behavior.\n */\nexport interface ParserConfig {\n  /** Block attribute handlers keyed by attribute name */\n  blockAttributes: Record<string, BlockAttributeHandler>;\n  /**\n   * Embed types that are block-level (e.g. `['video']`).\n   * Block embeds are rendered as standalone blocks instead of being\n   * placed inside a paragraph.\n   */\n  blockEmbeds?: string[];\n}\n\n// ─── Renderer Types ─────────────────────────────────────────────────────────\n\n/**\n * Handles rendering of a block-level node (paragraph, header, list, etc.).\n *\n * @typeParam Output - The rendered output type (string, ReactNode, etc.)\n * @typeParam Attrs - The collected attribute type (defined by the renderer)\n *\n * @param node - The AST node being rendered\n * @param childrenOutput - The already-rendered children content\n * @param resolvedAttrs - Pre-computed attributes from block attribute resolvers\n * @returns The rendered output for this block\n */\nexport type BlockHandler<Output, Attrs = unknown> = (\n  node: TNode,\n  childrenOutput: Output,\n  resolvedAttrs: Attrs,\n) => Output;\n\n/**\n * Declarative descriptor for simple blocks that follow the pattern\n * `<tag [attrs]>{children || emptyContent}</tag>`.\n *\n * The renderer auto-applies resolved attributes and handles empty content.\n */\nexport interface BlockDescriptor {\n  /** The tag name, or a function that resolves it from the node */\n  tag: string | ((node: TNode) => string);\n  /** Whether the tag is self-closing (e.g. `<br>`, `<hr>`). Defaults to false. */\n  selfClosing?: boolean;\n}\n\n/**\n * Handles rendering of an inline mark (bold, italic, link, etc.)\n * that creates a wrapper element.\n *\n * @typeParam Output - The rendered output type (string, ReactNode, etc.)\n * @typeParam Attrs - The collected attribute type (defined by the renderer)\n *\n * @param content - The already-rendered inner content\n * @param value - The attribute value (e.g. href for links, color hex for color)\n * @param node - The full AST node for additional context\n * @param collectedAttrs - Attributes collected from attributor marks.\n *   Only provided to the target element mark (innermost or outermost,\n *   controlled by {@link RendererConfig.attributorTarget}).\n * @returns The wrapped/decorated output\n */\nexport type MarkHandler<Output, Attrs = unknown> = (\n  content: Output,\n  value: unknown,\n  node: TNode,\n  collectedAttrs?: Attrs,\n) => Output;\n\n/**\n * Declarative descriptor for simple marks that just wrap content in a tag.\n * The renderer auto-handles collected attrs injection.\n *\n * @example\n * ```ts\n * const boldMark: SimpleTagMark = { tag: 'strong' };\n * const scriptMark: SimpleTagMark = { tag: (v) => v === 'super' ? 'sup' : 'sub' };\n * ```\n */\nexport interface SimpleTagMark {\n  /** The tag name, or a function that resolves it from the mark value */\n  tag: string | ((value: unknown) => string);\n}\n\n/**\n * An inline attributor mark — contributes renderer-specific attributes\n * to the nearest parent element mark instead of creating a wrapper element.\n *\n * Mirrors Quill's Parchment Attributor concept.\n *\n * @typeParam Attrs - The collected attribute type (defined by the renderer)\n *\n * @example\n * ```ts\n * // For an HTML renderer where Attrs = ResolvedAttrs:\n * const colorAttributor: AttributorHandler<ResolvedAttrs> = (value) => ({\n *   style: { color: String(value) },\n * });\n * ```\n */\nexport type AttributorHandler<Attrs> = (value: unknown, node: TNode) => Attrs;\n\n/**\n * Resolves block-level attributes from a node. Multiple resolvers\n * can be composed, and their results are merged by the renderer.\n *\n * @typeParam Attrs - The collected attribute type (defined by the renderer)\n *\n * @example\n * ```ts\n * const layoutResolver: BlockAttributeResolver<ResolvedAttrs> = (node) => ({\n *   classes: getLayoutClasses(node, 'ql'),\n * });\n * ```\n */\nexport type BlockAttributeResolver<Attrs> = (node: TNode) => Attrs;\n\n/**\n * Context object passed to node override handlers, providing access to\n * the renderer's traversal methods.\n */\nexport interface NodeOverrideContext<Output> {\n  /** Invoke the standard block/children rendering for the current node. */\n  defaultRender: () => Output;\n  /** Render an arbitrary child node through the full rendering pipeline. */\n  renderNode: (child: TNode) => Output;\n  /** Render all children of a node and join them into a single output. */\n  renderChildren: (node: TNode) => Output;\n}\n\n/**\n * Handles rendering of a specific node type, with access to the default\n * rendering path and child-rendering utilities as a fallback.\n *\n * @typeParam Output - The rendered output type (string, ReactNode, etc.)\n *\n * @param node - The AST node being rendered\n * @param ctx - Context with `defaultRender`, `renderNode`, and `renderChildren`\n * @returns The rendered output for this node\n */\nexport type NodeOverrideHandler<Output> = (node: TNode, ctx: NodeOverrideContext<Output>) => Output;\n\n/**\n * Configuration for a renderer — maps node types to block handlers\n * and attribute names to mark handlers.\n *\n * @typeParam Output - The rendered output type (string, ReactNode, etc.)\n * @typeParam Attrs - The collected attribute type (defined by the renderer).\n *   Defaults to `unknown` for renderers that don't use attributors.\n */\nexport interface RendererConfig<Output, Attrs = unknown> {\n  /** How to render block-level nodes (paragraph, header, list, etc.) */\n  blocks: Record<string, BlockHandler<Output, Attrs> | BlockDescriptor>;\n  /** How to render inline element marks (bold, link, etc.) that create wrapper elements */\n  marks: Record<string, MarkHandler<Output, Attrs> | SimpleTagMark>;\n  /** Inline attributor marks that contribute attrs to the parent element */\n  attributors?: Record<string, AttributorHandler<Attrs>>;\n  /** Optional mark nesting priorities. Higher value = wraps outer. */\n  markPriorities?: Record<string, number>;\n  /**\n   * Which element mark receives collected attributor attrs.\n   *\n   * - `'innermost'` (default) — attributor styles/classes go on the innermost\n   *   element mark (lowest priority). This matches `quill-delta-to-html` behavior.\n   * - `'outermost'` — attributor styles/classes go on the outermost element\n   *   mark (highest priority). This matches Quill editor's native DOM output,\n   *   where `StyleAttributor`s apply to the outermost formatting blot.\n   */\n  attributorTarget?: 'innermost' | 'outermost';\n  /** Block attribute resolvers — compute generic attrs for all blocks */\n  blockAttributeResolvers?: BlockAttributeResolver<Attrs>[];\n  /**\n   * Override rendering for specific node types. Checked before the standard\n   * block handler lookup. The handler receives a `defaultRender` thunk\n   * for falling back to the standard rendering path.\n   */\n  nodeOverrides?: Record<string, NodeOverrideHandler<Output>>;\n\n  /**\n   * Called when the renderer encounters a node type with no block handler\n   * and no nodeOverride. Useful for diagnostics, logging, or rendering\n   * custom/unknown embed types.\n   *\n   * If the callback returns a value, it is used as the rendered output\n   * for the node. If it returns `undefined`, the default fallback\n   * (rendering children only) is used.\n   */\n  onUnknownNode?: (node: TNode) => Output | undefined;\n}\n"]}