import{type PropertyValues,type TemplateResult}from'lit';import{LyraElement}from'../../../internal/lyra-element.js';import{type LyraAnchorTargetEventMap}from'../../../internal/anchor-target.js';import type{LyraAnchor,LyraAnchorKind}from'../document-viewer/anchors.js';import{type LyraViewerSource}from'../viewer-source.js';import type{LyraSearchChangeDetail}from'../../../internal/text-viewer-target.js';interface NotebookOutput{readonly output_type:'stream'|'error'|'display_data'|'execute_result';readonly name?:'stdout'|'stderr';readonly text?:string|readonly string[];readonly ename?:string;readonly evalue?:string;readonly traceback?:readonly string[];readonly data?:Readonly>;}interface NotebookCell{readonly cell_type:'markdown'|'code'|'raw';readonly id?:string;readonly source:string|readonly string[];readonly execution_count?:number|null;readonly outputs?:readonly NotebookOutput[];readonly metadata?:Readonly<{language_info?:unknown;}>;}interface NotebookDoc{readonly nbformat:number;readonly nbformat_minor:number;readonly cells:readonly NotebookCell[];readonly metadata?:Readonly<{language_info?:Readonly<{name?:string;}>;kernelspec?:Readonly<{language?:string;}>;}>;} /** Effective source authority. Inline values win by presence (including an empty string); clearing * them returns authority to the already configured URL without requiring a `src` reassignment. */ export type LyraNotebookViewerSource=LyraViewerSource;export interface LyraNotebookViewerEventMap extends LyraAnchorTargetEventMap{'lr-load':CustomEvent<{cellCount:number;language:string;}>;'lr-search-change':CustomEvent;'lr-render-error':CustomEvent<{error:unknown;}>;}declare class LyraNotebookViewerBase extends LyraElement{}declare const LyraNotebookViewer_base:Omit &(new(...args:ConstructorParameters)=>InstanceType &import("../../../lyra.js").LyraAnchorTarget&{renderAnchorLiveRegion():unknown;}); /** * `` — read-only Jupyter notebook (nbformat 4.x) renderer, composing existing * components per cell. Execution is a hard non-goal. * * Markdown cells render through ``, code cells through `` (using the * notebook's kernel language for syntax highlighting), and raw cells as plain preformatted text. A * code cell's `execute_result`/`display_data` outputs prefer, in order, `image/png`, `image/jpeg`, * `image/svg+xml` (sanitized), `text/html` (sanitized), `application/json` (via ``), * then `text/plain`. Stream/error outputs (tinted `danger` for stderr/tracebacks) interpret embedded * ANSI SGR color/style escapes via the shared `internal/ansi.ts` parser, same as ``. * Sanitizing raw HTML/SVG * output markup lazy-loads the optional peer dependency `dompurify` via `dompurify-loader.ts`; when * that peer isn't installed, the output renders a localized notice instead of raw markup. * Sanitized `text/html` output uses the passive-document profile: anchors, form controls, and * custom elements are unwrapped to ordinary text/children where safe, remote navigation/resource * attributes are removed, and only inline base64 raster image sources render. Sanitized * `image/svg+xml` output is likewise network-silent and non-interactive: animation is removed and * only same-document fragment references or inline base64 raster image references survive. * * Cells are virtualized through `` so a notebook with many cells stays cheap to * scroll. `node-path` anchors resolve `path[0]` as a cell index; `fragment` anchors resolve a cell's * own `id`. * * Identified virtual cells use the same key for active paint and navigation. Repeating an anchor * returns to that cell after manual scrolling; max-height also bounds the virtual scroll viewport. * Adopts `DocumentAnchorTarget`: `scrollToAnchor()`/the declarative `anchor` property resolve * through the cell-granularity model above, and `highlights`/`activeHighlightId` resolve through * that exact same model (`resolveAnchorCellIndex()`), not a pixel-precise text range within a * cell's own rendered markdown/code/output -- this viewer's addressable unit is the cell, matching * its `anchorKinds`. A `highlights` entry whose anchor resolves paints its matched cell with a * `cell-highlighted` part plus a tone-specific `cell-highlighted-` part (`accent` default, * `success`, `warning`, `danger`, `neutral`); the entry whose `id` equals `activeHighlightId` * additionally carries `cell-highlight-active`. Unlike docx-viewer/ebook-viewer there is no raw * markup to imperatively wrap or annotate -- cells are already declaratively re-rendered by Lit on * every `highlights`/`activeHighlightId`/load-state change, so `repaintHighlights()` just recomputes * that per-cell mapping ahead of the next render pass. `lr-highlight-activate` and `lr-text-select` * are present on this component's event map only because it's inherited, structurally, from the * shared `LyraAnchorTargetEventMap` every `DocumentAnchorTarget` adopter carries -- neither is * actually emitted by this viewer: there is no keyboard-accessible highlight-activation surface * (docx-viewer's/ebook-viewer's own click-to-activate needs a raw content DOM to hit-test or an * annotation-click callback, neither of which this cell-level model has), and the mixin's default * `bindTextSelection()` would anchor a selection as a `text-quote`, a kind outside this viewer's own * `anchorKinds`/highlight-resolution model, so wiring it would offer a selection event whose own * anchor could never be fed back in as a highlight. * * `search()`/`searchNext()`/`searchPrevious()`/`clearSearch()` follow the shared viewer search * contract (`internal/text-viewer-target.ts`'s `LyraTextViewerTarget`): `search()` resolves the * match count and the two navigation methods resolve `true` once the active match moved, `false` * when there is nothing to move to. A find-in-page host can therefore drive this viewer through the * same typed surface as every other one. * * Parsed `notebook` assignments are synchronously clone-owned and recursively frozen. Mutate a * copy and reassign it to update the viewer; later changes to the source object are not observed. * * @customElement lr-notebook-viewer * @event lr-load - Fired once a notebook has been parsed and validated. `detail: { cellCount, * language }`. * @event lr-search-change - Fired whenever the search query, match count, or active match index * changes, including source-reset and effective-locale re-evaluation. `detail: { query, * matchCount, matchCountExact, activeIndex }`. Notebook validation caps the corpus at 2,000 * cells and search retains at most one match per cell. Search accepts at most 4,096 query code * units and scans at most 4,000,000 source/output code units; a false `matchCountExact` makes the * returned count a lower bound after either ceiling is reached. * @event lr-render-error - Fired when fetching, parsing, or validating the notebook fails. * `detail: { error }`. * @event lr-anchor-result - Fired after an `anchor` property assignment or a `scrollToAnchor()` * call is applied. Non-cancelable. `detail: { found }`. * @csspart base - The root scroll container. * @csspart cell - One cell row (`data-cell-type`, `data-active`, `data-highlighted`). * @csspart cell-active - Added alongside `cell` on the cell currently targeted by an anchor or the * active search match. A second part name rather than an attribute selector, because Shadow Parts * forbids an attribute selector after `::part()`. * @csspart cell-highlighted - Added alongside `cell` on a cell matched by a `highlights` entry. * Always paired with a tone-specific `cell-highlighted-` part below (a second part name * rather than an attribute selector, for the same Shadow Parts reason as `cell-active`). * @csspart cell-highlighted-accent - Tone-specific highlight styling hook (the default tone). * @csspart cell-highlighted-success - Tone-specific highlight styling hook. * @csspart cell-highlighted-warning - Tone-specific highlight styling hook. * @csspart cell-highlighted-danger - Tone-specific highlight styling hook. * @csspart cell-highlighted-neutral - Tone-specific highlight styling hook. * @csspart cell-highlight-active - Added alongside `cell-highlighted`/`cell-highlighted-` when * the matched highlight's `id` equals `activeHighlightId`. * @csspart cell-gutter - The `In [n]`/`Out [n]` label column. * @csspart cell-source - A cell's source content. * @csspart raw-source - A horizontally scrollable raw-cell source surface. * @csspart outputs - The wrapper around a code cell's outputs. * @csspart output - One output (`data-output-type`, `data-stream`). * @csspart output-error - Added alongside `output` on a stderr stream or an error output. * @csspart error-output-label - The label introducing an error output's traceback. * @csspart output-toggle - Expands/collapses a long text output. * @csspart error - The error region. * @csspart spinner - Visible ordinary loading content with a motion-safe progress indicator. * @cssprop [--lr-notebook-viewer-max-height=none] - Maximum block size of the scrollable body * before it scrolls internally. Also settable via the `max-height` property. * @cssprop [--lr-notebook-viewer-active-bg=var(--lr-color-brand-quiet)] - Background of the * `[part="cell"]` currently targeted by an anchor or the active search match. * @cssprop [--lr-notebook-viewer-highlight-accent-background=var(--lr-color-brand-quiet)] - * Background of an `accent`-tone (the default) highlighted cell. * @cssprop [--lr-notebook-viewer-highlight-success-background=var(--lr-color-success-quiet)] - * Background of a `success`-tone highlighted cell. * @cssprop [--lr-notebook-viewer-highlight-warning-background=var(--lr-color-warning-quiet)] - * Background of a `warning`-tone highlighted cell. * @cssprop [--lr-notebook-viewer-highlight-danger-background=var(--lr-color-danger-quiet)] - * Background of a `danger`-tone highlighted cell. * @cssprop [--lr-notebook-viewer-highlight-neutral-background=var(--lr-color-surface-raised)] - * Background of a `neutral`-tone highlighted cell. * @cssprop [--lr-notebook-viewer-highlight-active-outline=var(--lr-focus-ring-color)] - Outline of * the highlighted cell whose highlight `id` equals `activeHighlightId`. * @status stable * @since 4.0.0 */ export declare class LyraNotebookViewer extends LyraNotebookViewer_base{protected static readonly ownedCollectionProperties:readonly string[];protected static readonly identityCollectionObjectProperties:readonly string[];static styles:import("lit").CSSResultGroup[]; /** URL to fetch and parse as a notebook. Ignored while `notebook` is present. */ src:string; /** A parsed notebook document, or its raw JSON text. Presence wins over `src` (including `''`) * and is parsed synchronously. Assigning `undefined` clears inline authority, invalidates its * rendering/sanitization work, and immediately resumes the already configured `src`. */ get notebook():NotebookDoc|string|undefined;set notebook(value:NotebookDoc|string|undefined);private _notebook?; /** Readonly discriminated snapshot of the effective source authority. */ get source():LyraNotebookViewerSource; /** Intentionally inert -- `source` is always derived live from `src`/`notebook`. A getter with * no setter throws (in strict-mode module code, which every consumer runs) the moment * anything assigns to it, including a stray `.source=${x}` template binding; this no-op keeps * that assignment harmless instead of throwing from inside framework internals. */ set source(_value:LyraNotebookViewerSource); /** Display name used as the viewer's accessible label, and matched against a `fragment` anchor's * cell id. */ name:string; /** A plain-text output longer than this many lines renders collapsed behind a toggle. `0` * disables collapsing. */ outputCollapseLines:number; /** A CSS length (e.g. `"30rem"`); once set, the notebook scrolls internally past this height * instead of growing the page. */ /** A CSS `max-height`; invalid values are ignored. */ maxHeight:string; /** Anchor kinds this component resolves via `scrollToAnchor()`. */ readonly anchorKinds:readonly LyraAnchorKind[];private loadState; /** Keyed by `${cellIndex}:${outputIndex}` (a colon-separated string, not a packed number) -- * `cellIndex * 1000 + outputIndex` would collide once a cell holds >= 1000 outputs (e.g. * cell 0's output 1000 and cell 1's output 0 both reduced to 1000). */ private expandedOutputs;private activeCellIndex;private searchQuery;private searchMatches;private searchMatchCountExact;private activeSearchIndex;private virtualListEl?;private readonly cellKey; /** Cell index -> the highest-priority `highlights` entry resolved against it, recomputed by * `repaintHighlights()` (called from `willUpdate()`, ahead of the render pass that same property * change already triggers -- a plain field, not `@state()`, is enough since nothing else needs to * independently schedule an update for it). */ private highlightedCells;private generation;private lastSearchLocale;private sanitizerGeneration;private sanitizerFailureReported;private sourceLoadScheduled;private readonly announcements; /** `outputCollapseLines`, normalized to a finite non-negative integer (falling back to the * property's own default of `40`) -- a raw `NaN` (e.g. an invalid `output-collapse-lines` * attribute) would otherwise make `lines.length > outputCollapseLines` always false, silently * disabling collapsing instead of falling back to the default threshold. */ private get effectiveOutputCollapseLines();protected updated(changed:PropertyValues):void;protected willUpdate(changed:PropertyValues):void;connectedCallback():void;disconnectedCallback():void;adoptedCallback():void;private parseInline;private resetParsedState;private beginSourceTransition;private scheduleSourceLoad;private loadFromSrc;private setDoc;protected applyAnchor(anchor:LyraAnchor):Promise;private activateCell; /** Resolves an anchor to a cell index using this viewer's own addressable units -- `node-path` * treats `path[0]` as a cell index, `fragment` matches a cell's own `id`. Shared by * `applyAnchor()` (`scrollToAnchor()`/the declarative `anchor` property) and * `repaintHighlights()` (`highlights` painting), since both resolve against the exact same * cell-granularity anchor model. `-1` when nothing is loaded, the anchor kind isn't one of this * viewer's `anchorKinds`, or the resolved index is out of range. */ private resolveAnchorCellIndex; /** Re-resolves every `highlights` entry against `resolveAnchorCellIndex()` and records, per * matched cell index, the highest-priority entry targeting it (`prioritizedHighlightCandidates()` * always orders an `activeHighlightId` match first, so it wins any same-cell collision). * `renderCell()` reads this map to paint `cell-highlighted`/`cell-highlighted-`/ * `cell-highlight-active`. Unlike docx-viewer/ebook-viewer there is no raw markup to imperatively * wrap or annotate here -- cells are already declaratively re-rendered by Lit on every * `highlights`/`activeHighlightId`/load-state change (see `willUpdate()`), so "repainting" is * just recomputing this derived map ahead of that same render pass. At most * `MAX_NOTEBOOK_PAINTED_HIGHLIGHTS` candidates are considered per pass. Only `node-path`/ * `fragment` highlight anchors -- this viewer's own `anchorKinds` -- ever resolve; any other kind * (e.g. a `text-quote` highlight authored for a different viewer) is silently skipped, exactly * like that same anchor kind fed to `scrollToAnchor()`. */ private repaintHighlights; /** Case-insensitive substring search over every accepted cell's joined source text and * text-bearing outputs -- at most one match per cell. Queries are capped at 4,096 code units * and one pass scans at most 4,000,000 source/output code units; `matchCountExact=false` * identifies a truncated lower bound. */ search(query:string):Promise; /** Advances to the next match, wrapping to the first after the last. Resolves `true` once the * active match moved, `false` (no-op) when there are no matches -- the same shape every other * viewer's `searchNext()` resolves, so a find-in-page host can drive them all through the shared * `LyraTextViewerTarget` surface. */ searchNext():Promise; /** Moves to the previous match, wrapping to the last before the first. Resolves `true` once the * active match moved, `false` (no-op) when there are no matches. */ searchPrevious():Promise; /** Clears the query, matches, and active index, and resets `lr-search-change` to a * 0-match/no-active-index state. */ clearSearch():void;private clearSearchState;private activateSearchMatch;private emitSearchChange;private toggleOutput; /** Feeds `text` through a fresh, one-shot ANSI parser (this is always a complete, already-final * string -- never a live stream chunk -- so there is no parser state to persist across renders, * unlike ``'s incremental `push()` usage) and renders the resulting segments as * styled spans, same color/style token mapping `` uses. */ private renderAnsiText;private segmentStyle;private renderTextOutput;private renderOutput; /** Cache of already-sanitized SVG/HTML output markup, keyed by `profile:rawMarkup` -- `undefined` * means "not requested yet", `null` means "sanitizer peer unavailable" (missing-peer notice), * otherwise the sanitized string. Sanitizing is async (`loadNotebookSanitizer()` lazy-loads the * `dompurify` peer), which can't resolve inside a synchronous `render()` pass -- `renderSanitized()` * kicks off the async work on first render and repaints via `requestUpdate()` once it resolves. */ private sanitizedOutputCache;private sanitizationTasks;private ensureSanitized;private renderSanitized;private renderCell;private notebookLanguage;private stopOwnedEvent;render():TemplateResult;}declare global{interface HTMLElementTagNameMap{'lr-notebook-viewer':LyraNotebookViewer;}}export{};