import { c as SceneDocument, f as SceneElementKind, d as SceneElement, g as ScenePage } from '../model-BBwyOuWG.js';
export { B as Bounds, E as EllipseElement, G as GroupElement, I as ImageElement, L as LineElement, N as NewPageOptions, P as PageBleed, a as PageGuides, R as RectElement, S as SCENE_ELEMENT_KINDS, b as SCENE_SCHEMA_VERSION, e as SceneElementBase, h as SceneSettings, T as TextElement, V as VideoElement, i as assertColor, j as assertFinite, k as assertPositiveFinite, l as assertSceneMediaSrc, m as boundsIntersect, n as collectSlots, o as createEmptyDocument, p as createPage, q as elementAabb, r as elementExtent, s as estimateTextHeight, t as findElement, u as requireElement, v as requirePage } from '../model-BBwyOuWG.js';
import { g as SceneOperation, i as ScenePlan } from '../operations-DLIvvD00.js';
export { A as AddElementOperation, a as AddPageOperation, b as ApplyDataOperation, B as BindSlotOperation, D as DeleteElementOperation, c as DeletePageOperation, d as DuplicatePageOperation, G as GroupElementsOperation, R as ReorderElementOperation, e as ReorderPageOperation, S as SCENE_OPERATION_TYPES, f as SceneAttrsPatch, h as SceneOperationType, j as SetAttrsOperation, k as SetDocumentTitleOperation, l as SetPageGuidesOperation, m as SetPagePropsOperation, U as UngroupElementOperation } from '../operations-DLIvvD00.js';
import { d as SceneStore, N as NewSceneDecision, a as SceneDocumentRecord } from '../store-CFyxgTlD.js';
export { S as SceneDecision, b as SceneExportFormat, c as SceneExportRecord, e as SceneStoreScope } from '../store-CFyxgTlD.js';
export { C as CHANNEL_PRESETS, a as ChannelPreset, b as ChannelPresetId, c as ChannelScaleResult, E as EXPORT_PRESETS, d as ExportCropRect, e as ExportFormat, f as ExportPreset, S as SIZE_PRESETS, g as SizePreset, h as bleedAwareExportBounds, i as bleedAwareExportRect, j as findPreset, m as matchPreset, r as requireChannelPreset, s as scaleForPreset, k as scalePageForChannelPreset } from '../export-presets-DAsU5Wal.js';
import { c as McpToolDefinition } from '../mcp-rpc-DLw_r9PQ.js';
import { S as ScopedMcpServerEntryOptions, A as AppToolMcpServer } from '../mcp-BHfIoGLW.js';
import '../types-BEOvc_ue.js';
import '../auth-DuptSkWh.js';

/**
 * Pre-write validation for scene operations. Every rule runs against a
 * `SceneDocument` snapshot BEFORE any mutation, so a rejected batch leaves no
 * partial state. Batch errors carry the shape `operation N (type): reason` —
 * precise enough for an LLM planner to repair the offending operation and
 * resubmit.
 *
 * Validation is static: a batch is checked against the document as given, so
 * an operation may not reference entities created by an earlier operation in
 * the same batch. Dispatchers that chain operations must refresh the document
 * between applications and validate per-operation.
 *
 * Slot typing contract (for apply_data bindings):
 *   text    elements  → value is any string
 *   image   elements  → value must pass assertSceneMediaSrc (src rewrite)
 *   video   elements  → value must pass assertSceneMediaSrc (src rewrite)
 *   rect    elements  → value must pass assertColor (fill recolor)
 *   ellipse elements  → value must pass assertColor (fill recolor)
 *   line    elements  → value must pass assertColor (stroke recolor)
 *   group   elements  → value must pass assertColor (fill/stroke passed down to children)
 */

declare function validateSceneOperations(document: SceneDocument, operations: SceneOperation[]): void;
declare function validateSceneOperation(document: SceneDocument, operation: SceneOperation): void;
/**
 * Validates that a slot binding value matches the slot element's kind.
 * text → any string; image/video → media src; rect/ellipse/line/group → color.
 */
declare function validateSlotValue(slotName: string, elementKind: SceneElementKind, value: string): void;

/**
 * Pure application of validated scene operations to a SceneDocument.
 * `applySceneOperations` deep-clones the document then mutates the clone,
 * returning the new document and per-op results. It never touches the store,
 * a clock, or a PRNG — all id generation goes through the caller-supplied
 * `mintId` option so callers control determinism (counter in tests,
 * crypto.randomUUID in production).
 *
 * Rotation semantics for group/ungroup:
 *   Group: children retain their absolute rotation. The group origin is the
 *   min-x, min-y corner of the AABB union of all member elements. Children
 *   are rebased so their position in group-local space equals
 *   (element.x - group.x, element.y - group.y). A rotated child appears at
 *   the same absolute page position after grouping because the group's additive
 *   translation preserves the child's own-origin transform.
 *   Ungroup: inverse — child.x += group.x, child.y += group.y; rotation stays.
 *   This is consistent with Konva's transform-about-own-origin model without
 *   needing a full matrix concatenation for the common case.
 *
 * `storeApplyScenePlan` layers store I/O on top: getDocument → validate →
 * apply → saveDocument(expectedRev) → recordDecision, retrying once on
 * stale-rev by refetch + revalidate + reapply.
 */

type SceneApplyResult = {
    kind: 'element';
    pageId: string;
    element: SceneElement;
} | {
    kind: 'page';
    page: ScenePage;
} | {
    kind: 'document';
};
interface ApplySceneOptions {
    /**
     * Provides fresh ids when duplicate_page re-mints element ids. Never called
     * by any other operation. Counter-based in tests; crypto.randomUUID in
     * production (wrapped so `mintId()` has no arguments, matching this signature).
     */
    mintId: () => string;
}
/** Full form: returns the new document AND per-op results. `mintId` must be
 *  provided when any operation in the list may be `duplicate_page` (which
 *  re-mints element ids); for all other operation types it is never called. */
declare function applySceneOperations(document: SceneDocument, operations: SceneOperation[], options: ApplySceneOptions): {
    document: SceneDocument;
    results: SceneApplyResult[];
};
/** Convenience 2-arg form: returns the new document directly. Uses a
 *  monotonic counter as the mintId so `duplicate_page` never collides within
 *  a single call (suitable for editor-local optimistic state; server will
 *  re-mint on persist). */
declare function applySceneOperations(document: SceneDocument, operations: SceneOperation[]): SceneDocument;
/** Apply a single operation to a document and return the new document.
 *  Equivalent to `applySceneOperations(doc, [op])` but returns `SceneDocument`
 *  directly — the common case in editor commands and tests. */
declare function applySceneOperation(document: SceneDocument, operation: SceneOperation): SceneDocument;
declare function storeApplyScenePlan(store: SceneStore, plan: ScenePlan, opts: {
    actorKind: NewSceneDecision['kind'];
    mintId: () => string;
}): Promise<{
    record: SceneDocumentRecord;
    results: SceneApplyResult[];
}>;

/**
 * Template helpers for design-canvas documents. A template is any document
 * whose elements carry `slot` names — those slots define the fillable surface
 * that data sources and agents target. The helpers here are pure (no store,
 * no Konva) so they run server-side, in MCP tools, or in tests without a DOM.
 *
 * Binding semantics (shared with `apply_data` operation):
 *   - text elements: binding value replaces `element.text`
 *   - image/video elements: binding value replaces `element.src`
 *   - rect/ellipse elements with a slot: binding value replaces `element.fill`
 *     (color-slot convention — background swatch templates)
 *   - line/group slots are reserved; binding them throws a loud error
 * Unknown binding keys (no matching slot) throw — callers must preflight with
 * `validateBindings` or accept that the throw is the signal to fix their data.
 */

type SlotFillKind = 'text' | 'src' | 'color';
interface TemplateSlot {
    name: string;
    pageId: string;
    elementId: string;
    elementKind: SceneElementKind;
    fillKind: SlotFillKind;
}
/**
 * Wraps `collectSlots` with kind-aware fill typing so callers know WHAT to
 * put in each slot without inspecting the element tree themselves.
 * Throws when duplicate slot names exist (propagated from collectSlots).
 */
declare function listTemplateSlots(document: SceneDocument): TemplateSlot[];
/**
 * Preflight check: every key in `bindings` must name a slot in the document.
 * Returns a list of problems; an empty array means the bindings are clean.
 * Does NOT throw — designed to run before `instantiateTemplate` so callers
 * can surface a structured error instead of catching.
 */
declare function validateBindings(document: SceneDocument, bindings: Record<string, string>): string[];
interface InstantiateOptions {
    /** Human-readable title for the new document. */
    title: string;
    /** Slot bindings to apply after id re-minting. Partial application allowed. */
    bindings?: Record<string, string>;
    /**
     * Caller-supplied id factory — every page/element id in the source document
     * is replaced with a fresh value from this callback. The callback receives
     * the source id so implementations can build stable deterministic ids (e.g.
     * `crypto.randomUUID()` or `nanoid()` from the host).
     */
    mintId(sourceId: string): string;
}
/**
 * Produces a new `SceneDocument` from a template:
 * 1. Re-mints every page and element id via `options.mintId` (slot *names* are
 *    preserved so apply_data still targets them by name).
 * 2. Applies `options.bindings` with the same semantics as `apply_data`.
 * 3. Stamps `metadata.templateSourceId` with the source document's title so
 *    the lineage is traceable without storing separate template provenance rows.
 *
 * Throws when bindings reference unknown slots (validated via `validateBindings`
 * before mutation so no partial state is possible).
 */
declare function instantiateTemplate(document: SceneDocument, options: InstantiateOptions): SceneDocument;
/**
 * Applies slot bindings to a document in place (mutates a deep copy produced
 * by the caller). Unknown slot names throw — the preflight in `instantiateTemplate`
 * guarantees this is unreachable there; exported so the `apply_data` operation
 * handler can reuse it without duplicating the switch.
 */
declare function applyBindingsToDocument(document: SceneDocument, bindings: Record<string, string>): SceneDocument;

/**
 * Design-canvas MCP tool registry — what the in-sandbox agent sees over the
 * live agent→canvas channel. Each entry carries an LLM-facing description, a
 * JSON Schema for the arguments, and the typed dispatch that validates the
 * resulting operations, applies them through the store, and records ONE
 * decision row per mutating call.
 *
 * Every mutation: validate → apply via storeApplyScenePlan → recordDecision.
 * Throws anywhere become isError results the model reads to correct its call.
 *
 * Convenience sugar tools (add_text, move_element, etc.) expand to the
 * underlying operation primitives before reaching the kernel — no separate
 * code path to drift.
 */

interface DesignCanvasMcpToolEnv {
    store: SceneStore;
    mintId: () => string;
}
declare const CANVAS_MCP_TOOLS: McpToolDefinition<DesignCanvasMcpToolEnv>[];

declare function findCanvasMcpTool(name: string): McpToolDefinition<DesignCanvasMcpToolEnv> | undefined;
declare const CANVAS_MCP_TOOL_NAMES: string[];
declare const CANVAS_ELEMENT_KINDS: readonly string[];

/**
 * Streamable-HTTP MCP server for one design-canvas document — the live
 * agent→canvas channel. JSON-RPC 2.0 over POST, stateless per request
 * (Workers-compatible: no session table, no SSE).
 *
 * Trust boundary: the product authenticates the request (capability token,
 * workspace RBAC) BEFORE constructing the scoped {@link SceneStore} and
 * calling this handler — the handler trusts its store completely. Tool
 * execution failures (argument shape, validation, stale rev) become `isError`
 * tool results carrying the thrown message verbatim so the model can read WHY
 * and retry.
 *
 * The JSON-RPC envelope (initialize/ping/tools/list/tools/call, -32601) lives
 * in {@link createMcpToolHandler}; this module wires the canvas tool list +
 * the caller-supplied id-minting function.
 */

interface DesignCanvasMcpServerInfo {
    name: string;
    version: string;
}
interface CreateDesignCanvasMcpHandlerOptions {
    /** Already scoped + authorized for one (workspace, document, actor). */
    store: SceneStore;
    /** Id-minting function threaded into every mutating tool. Must return
     *  a string unique within the document scope — use crypto.randomUUID()
     *  in production; a deterministic counter in tests. */
    mintId: () => string;
    serverInfo?: DesignCanvasMcpServerInfo;
}
declare function createDesignCanvasMcpHandler(opts: CreateDesignCanvasMcpHandlerOptions): (request: Request) => Promise<Response>;

/**
 * Profile entry for the design-canvas MCP server — what a product spreads
 * into its sandbox `AgentProfile.mcp` map so the in-sandbox agent gets the
 * live canvas channel. A thin wrapper over the shared `buildScopedMcpServerEntry`
 * mechanism (../tools/mcp): transport 'http', capability token in the
 * Authorization header (server-set, never a tool argument). The only
 * domain-specific values are this channel's default description and name.
 */

declare const DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION = "Live visual asset editor for the current design document: read scene state, add/move/resize/delete elements, manage pages, bind template slots, apply data, and queue exports. All coordinates are CSS pixels.";
type BuildDesignCanvasMcpServerEntryOptions = ScopedMcpServerEntryOptions;
/** Build the `AgentProfileMcpServer`-shaped entry for the design-canvas channel. */
declare function buildDesignCanvasMcpServerEntry(opts: BuildDesignCanvasMcpServerEntryOptions): AppToolMcpServer;

export { type ApplySceneOptions, type BuildDesignCanvasMcpServerEntryOptions, CANVAS_ELEMENT_KINDS, CANVAS_MCP_TOOLS, CANVAS_MCP_TOOL_NAMES, type CreateDesignCanvasMcpHandlerOptions, DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION, type DesignCanvasMcpServerInfo, type DesignCanvasMcpToolEnv, type InstantiateOptions, NewSceneDecision, type SceneApplyResult, SceneDocument, SceneDocumentRecord, SceneElement, SceneElementKind, SceneOperation, ScenePage, ScenePlan, SceneStore, type SlotFillKind, type TemplateSlot, applyBindingsToDocument, applySceneOperation, applySceneOperations, buildDesignCanvasMcpServerEntry, createDesignCanvasMcpHandler, findCanvasMcpTool, instantiateTemplate, listTemplateSlots, storeApplyScenePlan, validateBindings, validateSceneOperation, validateSceneOperations, validateSlotValue };
