import type { Anchor, Box, DocContext, EditTarget as PolicyTarget, EngineAdapter, FocusCellAddress, FocusOffset, FocusParagraphAddress, FocusTarget, Intent, RunSpec } from "@auto-hwp/editor-core"; import { type FormatRibbonPatch } from "./FormatRibbon"; import { type RegionClass, type ShowEditableRegions } from "./EditableRegionsLayer"; import { type FontCatalogEntry } from "../fonts"; import { type DeepPartial, type WorkspaceMessages } from "../i18n"; /** DEV/test helper: how many times HwpWorkspace has committed since the last reset. */ export declare function __getWorkspaceRenderCount(): number; /** DEV/test helper: zero the workspace render counter (call right before a measured gesture). */ export declare function __resetWorkspaceRenderCount(): void; /** Apply character-only inspector fields while preserving text and every untouched run attribute. An "off" * is sent as `false` (#481 — an omitted flag keeps the replaced text's, so dropping the key would not turn * it off). Exported for its unit test. */ export declare function patchRuns(runs: RunSpec[], patch: FormatRibbonPatch): RunSpec[]; export interface WorkspaceSidePanel { /** A document is open and editable (false → the panel should disable composing). */ canEdit: boolean; /** Live selection as AI anchors (the same `[s/b]` addresses the doc context uses). */ anchors: Anchor[]; /** Platform modifier caption for hints ("⌘" / "Ctrl"). */ modLabel: string; /** Drop one anchor / clear the whole selection. */ removeAnchor: (index: number) => void; clearAnchors: () => void; /** R5-fenced document context string for the AI bridge (profile + anchors + table grids). */ docContext: DocContext; /** Apply validated Intents through the op-bus; resolves with how many landed. */ apply: (intents: Intent[]) => Promise; /** Scroll the canvas to a page (0-based). */ jumpToPage: (page: number) => void; /** Scroll to a block and flash it (the "⊙ 위치 보기" affordance). */ revealTarget: (section: number, block: number) => void; /** Bumps when the host should focus its composer (e.g. the "AI에게 전달" action fired). */ focusToken: number; /** Enrich proposals for preview (e.g. a DeleteBlock card showing the target's 원문). */ previewCards: (intents: Intent[]) => Promise; /** 고스트 프리뷰(이슈 3) — draw these Intents' RESULT over the document as a translucent ghost * (card hover / a "미리 보기" toggle); `null` clears it. Nothing is applied. Insert/delete ops carry * no pre-existing place and are silently skipped (거짓 프리뷰 금지). OPTIONAL so an existing host that * builds its own `WorkspaceSidePanel` object keeps compiling (additive). */ previewIntents?: (intents: Intent[] | null) => void; /** Revert the last applied batch as one unit (false = nothing to revert). */ revert: () => Promise; /** Current undo-stack depth (read at render time). */ undoDepth: () => number; /** Figma-style inspector data for the current single selection. `null` for zero/multi selection. */ designSelection?: WorkspaceDesignSelection | null; /** Apply a design delta to the current selection. Character fields work for a paragraph or cell/range; * cell background/alignment are enabled only for cell/range targets. */ applyDesign?: (patch: FormatRibbonPatch) => void; /** Font families the inspector may offer. A host may ignore this and render its own picker. */ designFonts?: readonly string[]; /** True while the engine glyph caret owns keyboard input. Panels can collapse frame/cell controls * and keep the user focused on typography while the document itself stays visually unchanged. */ textEditing?: boolean; /** #482 — the workspace handle (same object as `handleRef` receives, identity stable across renders). * Lets a panel read zoom/page/history/format and send commands without reaching into the canvas DOM * or synthesizing keyboard shortcuts. OPTIONAL so a host that builds its own panel object compiles. */ handle?: WorkspaceHandle; } /** #482 — character format of the current selection (first run of the target), as the design inspector * and `WorkspaceHandle.getSelectionFormat()` report it. `underline` · `highlight` · `mixed` are additive: * the workspace always fills the first two; `mixed` is present only when the target's runs disagree. */ export interface WorkspaceTextFormat { font: string | null; sizePt: number; color: string | null; bold: boolean; italic: boolean; underline?: boolean; /** 글자 배경(charPr `shadeColor`) as `#RRGGBB`, `null` when none. */ highlight?: string | null; /** Fields that differ across the target's runs (e.g. a paragraph that is only partly bold). */ mixed?: Partial>; } /** #482 — what changed, as `WorkspaceHandle.subscribe` reports it. Several flags can arrive together. */ export interface WorkspaceHandleChange { zoom?: true; page?: true; history?: true; selection?: true; } /** #482 — a stable, render-independent handle on the live workspace: read the view state and send the * same commands the built-in toolbar and shortcuts send, so a host can build its own chrome (menus, * toolbars, status bar) without reading hidden DOM or synthesizing `KeyboardEvent`s. The object identity * never changes while the workspace is mounted; every method reads the live state when called. Methods * are safe without a document (reads return defaults, commands return `false`/the current value). */ export interface WorkspaceHandle { /** Committed zoom factor (1 = 100%). */ getZoom(): number; /** Zoom to an exact factor about the viewport center (clamped to the workspace range). Returns the * clamped factor that will be committed. */ setZoom(zoom: number): number; /** Fit the current page to the canvas width (`"width"`) or the whole page (`"page"`, then scroll to * it). Returns the factor applied, or the current one when the canvas/page size is not known yet. */ fit(mode: "width" | "page"): number; /** The page at the reading line (the status bar's page, 0-based) and the live page count. */ getPage(): { current: number; count: number; }; /** Scroll the canvas to a page (0-based) — the same lane as the outline and `jumpToPage`. */ scrollToPage(page: number): void; /** #507 — place a glyph caret at a model address (offset defaults to 0, clamped to the paragraph). * Success scrolls the target into view and focuses IME input. Policy/geometry/preparation failure * returns false without changing caret or selection. Requires enableEditing and an editable document. */ focusCell(addr: FocusCellAddress, offset?: FocusOffset): Promise; focusParagraph(addr: FocusParagraphAddress, offset?: FocusOffset): Promise; /** Next/previous editable cell paragraph or body paragraph in reading order. No wrap by default; * without a caret, starts at the first/last target. */ focusNext(direction?: 1 | -1, opts?: { wrap?: boolean; }): Promise; /** Undo/redo one batch — the toolbar's lane (same toast). Resolves `true` when something changed. */ undo(): Promise; redo(): Promise; canUndo(): boolean; canRedo(): boolean; /** Toggle a character style on the live glyph-caret selection — the ⌘B/⌘I/⌘U lane (same edit policy, * one undo step). Resolves `false` without a caret selection, while the in-place editor or an IME * composition owns the keyboard, or when the edit is refused. */ toggleStyle(style: "bold" | "italic" | "underline" | "strike"): Promise; /** Character format of the current selection (`designSelection.format`), or `null` without one. */ getSelectionFormat(): WorkspaceTextFormat | null; /** Called after zoom/page/history/selection settle (never per gesture tick). Returns an unsubscribe. */ subscribe(listener: (change: WorkspaceHandleChange) => void): () => void; } /** Stable, reader-facing selection snapshot for a host-owned design inspector. Geometry is own-render * page px, so the panel can show Figma-like X/Y/W/H without reaching into the canvas DOM. */ export interface WorkspaceDesignSelection { kind: "paragraph" | "cell" | "range" | "table" | "image" | "other"; label: string; page: number; section: number; block: number; text: string; box: Box; format: WorkspaceTextFormat; canTextStyle: boolean; canCellStyle: boolean; } /** One switchable control in the global top toolbar (see `HwpWorkspaceProps.toolbarItems`). * `"zoom"` covers the −/%/+ trio, which only makes sense as a group. */ export type WorkspaceToolbarItem = "zoom" | "undo" | "redo" | "insertTable" | "insertImage" | "font" | "normalize" | "exportHtml" | "exportHwpx" | "exportPdf"; export interface HwpWorkspaceProps { /** The backend seam (WasmAdapter for the web, or a host adapter). */ adapter: EngineAdapter; /** Optional product label in the global toolbar. Defaults to the neutral SDK name. */ brand?: string; /** The document to open (bytes + optional name). Re-opens when the `bytes` reference changes. When * omitted, the workspace shows an empty state (the host drives opening). */ document?: { bytes: Uint8Array; name?: string; } | null; /** The host AI bridge (R6): instruction + anchors + doc context → Intents. Never an LLM in-package. * The workspace itself never calls this — it hands it to the host's `sidePanel` (which owns the * conversation UI). Kept on the workspace props so a host can pass one bridge to both. */ onAiRequest: import("@auto-hwp/editor-core").OnAiRequest; /** RIGHT-HAND PANEL SLOT — the workspace deliberately ships NO chat/AI view. It renders whatever * the host returns here and passes the editing surface it needs (see [`WorkspaceSidePanel`]): * live selection anchors, the AI doc context, apply/revert, page + block navigation. * Omit for a bare editor (viewer/manual editing only). */ sidePanel?: (api: WorkspaceSidePanel) => React.ReactNode; /** Supply a TTF/OTF face for PDF export on demand (R8). Called when PDF is requested and no font is * registered yet. Return null to cancel. The DEMO wires this to a local .ttf picker / Noto fetch. */ requestFont?: () => Promise<{ family: string; bytes: Uint8Array; } | null>; /** The curated OFL font catalog (issue 022). When present, a FontPicker is shown in the toolbar so * the user can pick/upload a font that drives screen + layout + PDF alike. Omit to hide the picker. */ fontCatalog?: readonly FontCatalogEntry[]; /** A default font `{ family, bytes }` auto-registered right after opening (issue 022) — screen SVG, * pagination and PDF all use it immediately (PDF button usable without a manual pick). */ defaultFont?: { family: string; bytes: Uint8Array; } | null; /** Base URL the catalog fonts are served from (default `/fonts`); forwarded to the FontPicker. */ fontUrlBase?: string; /** Opt-in (issue 058): also fetch + register the OFL SERIF substitute (Nanum Myeongjo, from the * `fontCatalog`) so the EXPORTED PDF renders 명조 runs serif (the screen already does via `@font-face`). * Best-effort — a 404/offline fetch is swallowed and 명조 falls back to the gothic body in the PDF * (pre-058). Off by default so the injected-font set (and hosts/tests that pin it) is unchanged. */ injectSerifSubstitute?: boolean; /** Opt-in (이슈 6): the PDF button opens a PREVIEW modal of the generated bytes (the browser's own PDF * viewer in an `