import{type TemplateResult,type PropertyValues}from'lit';import{LyraElement}from'../../../internal/lyra-element.js';import type{LyraClipboardWriteFailure,LyraClipboardWriteSuccess}from'../../../internal/clipboard.js';import{type ShikiLanguageSource}from'./shiki-types.js';import type{LyraCodeBlockCopyAppearance}from'./code-block-shared.js';import type{LyraAnchor,LyraHighlight,TextSelectRect}from'../../viewers/document-viewer/anchors.js';import'../../overlays/skeleton/skeleton.class.js';export interface LyraCodeBlockCoreEventMap{'lr-copy':CustomEvent;'lr-error':CustomEvent;'lr-copy-error':CustomEvent;'lr-toggle-request':CustomEvent<{collapsed:boolean;}>;'lr-toggle':CustomEvent<{collapsed:boolean;}>;'lr-line-activate':CustomEvent<{line:number;}>;'lr-text-select':CustomEvent<{readonly text:string;readonly anchor:LyraAnchor;readonly rects:readonly TextSelectRect[];}>;} /** * `` — a build-lean variant of `` for * a consumer whose `languages` map already covers every language it will * ever render. It only ever calls `loadShikiHighlighterCore()` (from the peer-neutral Shiki * capability leaf) with `languages`' already-resolved entries — never `loadShikiHighlighter()`, the * default ~200-language dynamic-import table loader `` calls. This component's own * module never textually contains a call to (or import of) `loadShikiHighlighter` at all, so a * consumer importing this entry point instead of `code-block.js` gets a * genuinely shiki-full-table-free build. * * A `languages` entry may also be a lazy loader (`() => import('@shikijs/langs/')`) instead * of an already-resolved grammar — resolved and registered into the highlighter (via * `HighlighterCore.loadLanguage()`) the first time a fence actually requests that key, memoized per * key so it is never re-imported. See the `languages` property doc for the exact shape. * * A `language` value absent from `languages` always renders the plain * `
` fallback — there is no default/full-table highlighter here
* to fall back to, unlike ``'s dynamic-import path for an
* unmapped language, and neither does a `languages` entry whose lazy loader rejects. That fallback
* is the *default* rendering path, not a degraded one, same as ``'s own plain-text
* fallback.
*
* Everything else — `code`/`language`/`filename`/`copyable`/`collapsible`/
* `collapsed`/`maxHeight`, the copy button, the collapse header toggle, the
* loading-skeleton behavior while the fine-grained highlighter itself
* resolves — matches `` exactly. A host `aria-label` (or
* the matching `accessibleLabel` property) is forwarded to the internal
* focusable element that owns the named `group` role.
*
* Adopts the `line-range` slice of this library's shared anchor-target contract, identical to
* ``: `highlights`/`activeHighlightId` paint (and `highlight-lines` additionally
* marks) per-line emphasis in both the shiki and plain-text-fallback rendering paths identically,
* and `scrollToAnchor()` resolves a `line-range` anchor. `activatable-lines` is a separate, purely
* local affordance that turns the (`line-numbers`-gated) gutter into a keyboard-navigable,
* clickable roving-tabindex group emitting `lr-line-activate` — it doesn't require `highlights` to
* be set. If controlled `code` shrinks while a line owns focus, focus follows the clamped
* surviving line through both plain and highlighted DOM replacement; an explicit move to another
* control during the update is never overridden.
*
* @customElement lr-code-block-core
* @event lr-copy - The raw `code` was written to the clipboard. Frozen detail:
*   `{ ok: true, text }`.
* @event lr-error - Clipboard writing failed; generic no-detail notification.
* @event lr-copy-error - Clipboard writing failed. Frozen detail:
*   `{ ok: false, text, reason, error }`, where `reason` is
*   `'unsupported' | 'denied' | 'failed'`.
* @event lr-toggle-request - Cancelable request emitted before collapse state changes.
*   `detail: { collapsed }` is the proposed next state.
* @event lr-toggle - The collapse/expand header button was activated.
*   `detail: { collapsed }` — same event name and shape convention as
*   ``'s own `lr-toggle`.
* @event lr-line-activate - A gutter line number was activated (click, or Enter/Space while
*   focused) while `activatable-lines` is set. `detail: { line }`.
* @event lr-text-select - Fired when a text selection inside the code body ends. `detail: {
*   text, anchor, rects }`; `anchor` is a `line-range` anchor covering the selected lines.
* @csspart base - The outer container.
* @csspart header - The row above the code (filename/language/copy/toggle),
*   present whenever there's anything to put in it.
* @csspart filename - The `filename` text, when set.
* @csspart language - The `language` badge, when set, so the language is
*   exposed to assistive tech as visible text rather than only a `language`
*   attribute a screen reader would never announce.
* @csspart copy-button - The copy-to-clipboard control, when `copyable`. A composed
*   `` as of 16.0.0: it still owns the accessible name, the activation and the part
*   names, while its background, radius, hover/press mixes, focus ring and hit-area floor now come
*   from `--lr-icon-button-*`. Also carries `copy-button-text` or `copy-button-icon` for the active
*   `copyAppearance`, since a state cannot be selected with `::part(copy-button)[attr]`.
* @csspart copy-button-text - The copy control while `copyAppearance` is `'text'`.
* @csspart copy-button-icon - The copy control while `copyAppearance` is `'icon'`.
* @csspart copy-button__control - The copy control's own native `