@carbon/ai-chat-components 1.13.0 → 1.14.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +1147 -462
- package/es/components/audio-player/src/audio-player.scss.js +1 -1
- package/es/components/audio-player/src/transcript.js +15 -0
- package/es/components/audio-player/src/transcript.js.map +1 -1
- package/es/components/card/src/card-footer.scss.js +1 -1
- package/es/components/card/src/card-steps.scss.js +1 -1
- package/es/components/card/src/card.scss.js +1 -1
- package/es/components/chat-button/src/chat-button.scss.js +1 -1
- package/es/components/chat-history/src/chat-history.scss.js +1 -1
- package/es/components/chat-shell/src/shell.scss.js +1 -1
- package/es/components/code-snippet/src/code-snippet.d.ts +3 -2
- package/es/components/code-snippet/src/code-snippet.js +4 -3
- package/es/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es/components/code-snippet/src/code-snippet.scss.js +1 -1
- package/es/components/feedback/src/feedback.js +17 -3
- package/es/components/feedback/src/feedback.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es/components/launcher/src/launcher.scss.js +1 -1
- package/es/components/markdown/__tests__/inline-selection-fixture.d.ts +13 -0
- package/es/components/markdown/index.d.ts +2 -0
- package/es/components/markdown/index.js +3 -0
- package/es/components/markdown/index.js.map +1 -1
- package/es/components/markdown/src/inline-markdown.d.ts +41 -0
- package/es/components/markdown/src/inline-markdown.js +92 -0
- package/es/components/markdown/src/inline-markdown.js.map +1 -0
- package/es/components/markdown/src/inline-markdown.scss.js +13 -0
- package/es/components/markdown/src/inline-markdown.scss.js.map +1 -0
- package/es/components/markdown/src/inline-run-projection.scss.js +13 -0
- package/es/components/markdown/src/inline-run-projection.scss.js.map +1 -0
- package/es/components/markdown/src/markdown-renderer.js +131 -25
- package/es/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es/components/markdown/src/markdown.js +1 -0
- package/es/components/markdown/src/markdown.js.map +1 -1
- package/es/components/markdown/src/markdown.scss.js +1 -1
- package/es/components/markdown/src/utils/inline-run-projection.d.ts +15 -0
- package/es/components/markdown/src/utils/inline-run-projection.js +196 -0
- package/es/components/markdown/src/utils/inline-run-projection.js.map +1 -0
- package/es/components/markdown/src/utils/inline-validation.d.ts +13 -0
- package/es/components/markdown/src/utils/inline-validation.js +97 -0
- package/es/components/markdown/src/utils/inline-validation.js.map +1 -0
- package/es/components/markdown/src/utils/plugin-fallback.js +20 -13
- package/es/components/markdown/src/utils/plugin-fallback.js.map +1 -1
- package/es/components/markdown/src/utils/plugin-host-container.d.ts +5 -6
- package/es/components/markdown/src/utils/plugin-host-container.js.map +1 -1
- package/es/components/messages-shell/index.d.ts +11 -0
- package/es/components/messages-shell/index.js +9 -0
- package/es/components/messages-shell/index.js.map +1 -0
- package/es/components/messages-shell/src/messages-shell.d.ts +57 -0
- package/es/components/messages-shell/src/messages-shell.js +141 -0
- package/es/components/messages-shell/src/messages-shell.js.map +1 -0
- package/es/components/messages-shell/src/messages-shell.scss.js +13 -0
- package/es/components/messages-shell/src/messages-shell.scss.js.map +1 -0
- package/es/components/processing/src/processing.scss.js +1 -1
- package/es/components/prompt-line/autocomplete/src/autocomplete.d.ts +26 -9
- package/es/components/prompt-line/autocomplete/src/autocomplete.js +116 -107
- package/es/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
- package/es/components/prompt-line/src/autocomplete-controller-element.js +13 -1
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
- package/es/components/prompt-line/src/autocomplete-controller.js +9 -2
- package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-controller.d.ts +7 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +17 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +1 -0
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +3 -0
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.d.ts +7 -0
- package/es/components/prompt-line/src/prompt-line.js +9 -0
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/send-control.scss.js +1 -1
- package/es/components/prompt-line/src/stop-streaming-button.scss.js +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +43 -21
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/plain-text-paste.js +8 -3
- package/es/components/prompt-line/src/tiptap/plain-text-paste.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +3 -3
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/types.d.ts +27 -11
- package/es/components/reasoning-steps/src/reasoning-step.d.ts +3 -3
- package/es/components/reasoning-steps/src/reasoning-step.js +4 -4
- package/es/components/reasoning-steps/src/reasoning-step.js.map +1 -1
- package/es/components/reasoning-steps/src/reasoning-step.scss.js +1 -1
- package/es/components/reasoning-steps/src/reasoning-steps-toggle.scss.js +1 -1
- package/es/components/reasoning-steps/src/reasoning-steps.d.ts +5 -4
- package/es/components/reasoning-steps/src/reasoning-steps.js +5 -4
- package/es/components/reasoning-steps/src/reasoning-steps.js.map +1 -1
- package/es/components/truncated-text/src/truncated-text.scss.js +1 -1
- package/es/components/video-player/src/video-player.scss.js +1 -1
- package/es/react/hooks/useChatAutocomplete.js +7 -1
- package/es/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es/react/messages-shell.d.ts +3 -0
- package/es/react/messages-shell.js +32 -0
- package/es/react/messages-shell.js.map +1 -0
- package/es-custom/components/audio-player/src/audio-player.scss.js +1 -1
- package/es-custom/components/audio-player/src/transcript.js +15 -0
- package/es-custom/components/audio-player/src/transcript.js.map +1 -1
- package/es-custom/components/card/src/card-footer.scss.js +1 -1
- package/es-custom/components/card/src/card-steps.scss.js +1 -1
- package/es-custom/components/card/src/card.scss.js +1 -1
- package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
- package/es-custom/components/chat-history/src/chat-history.scss.js +1 -1
- package/es-custom/components/chat-shell/src/shell.scss.js +1 -1
- package/es-custom/components/code-snippet/src/code-snippet.d.ts +3 -2
- package/es-custom/components/code-snippet/src/code-snippet.js +4 -3
- package/es-custom/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es-custom/components/code-snippet/src/code-snippet.scss.js +1 -1
- package/es-custom/components/feedback/src/feedback.js +17 -3
- package/es-custom/components/feedback/src/feedback.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es-custom/components/launcher/src/launcher.scss.js +1 -1
- package/es-custom/components/markdown/__tests__/inline-selection-fixture.d.ts +13 -0
- package/es-custom/components/markdown/index.d.ts +2 -0
- package/es-custom/components/markdown/index.js +3 -0
- package/es-custom/components/markdown/index.js.map +1 -1
- package/es-custom/components/markdown/src/inline-markdown.d.ts +41 -0
- package/es-custom/components/markdown/src/inline-markdown.js +92 -0
- package/es-custom/components/markdown/src/inline-markdown.js.map +1 -0
- package/es-custom/components/markdown/src/inline-markdown.scss.js +13 -0
- package/es-custom/components/markdown/src/inline-markdown.scss.js.map +1 -0
- package/es-custom/components/markdown/src/inline-run-projection.scss.js +13 -0
- package/es-custom/components/markdown/src/inline-run-projection.scss.js.map +1 -0
- package/es-custom/components/markdown/src/markdown-renderer.js +131 -25
- package/es-custom/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es-custom/components/markdown/src/markdown.js +1 -0
- package/es-custom/components/markdown/src/markdown.js.map +1 -1
- package/es-custom/components/markdown/src/markdown.scss.js +1 -1
- package/es-custom/components/markdown/src/utils/inline-run-projection.d.ts +15 -0
- package/es-custom/components/markdown/src/utils/inline-run-projection.js +196 -0
- package/es-custom/components/markdown/src/utils/inline-run-projection.js.map +1 -0
- package/es-custom/components/markdown/src/utils/inline-validation.d.ts +13 -0
- package/es-custom/components/markdown/src/utils/inline-validation.js +97 -0
- package/es-custom/components/markdown/src/utils/inline-validation.js.map +1 -0
- package/es-custom/components/markdown/src/utils/plugin-fallback.js +20 -13
- package/es-custom/components/markdown/src/utils/plugin-fallback.js.map +1 -1
- package/es-custom/components/markdown/src/utils/plugin-host-container.d.ts +5 -6
- package/es-custom/components/markdown/src/utils/plugin-host-container.js.map +1 -1
- package/es-custom/components/messages-shell/index.d.ts +11 -0
- package/es-custom/components/messages-shell/index.js +9 -0
- package/es-custom/components/messages-shell/index.js.map +1 -0
- package/es-custom/components/messages-shell/src/messages-shell.d.ts +57 -0
- package/es-custom/components/messages-shell/src/messages-shell.js +141 -0
- package/es-custom/components/messages-shell/src/messages-shell.js.map +1 -0
- package/es-custom/components/messages-shell/src/messages-shell.scss.js +13 -0
- package/es-custom/components/messages-shell/src/messages-shell.scss.js.map +1 -0
- package/es-custom/components/processing/src/processing.scss.js +1 -1
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.d.ts +26 -9
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js +116 -107
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +13 -1
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +9 -2
- package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +7 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +17 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +1 -0
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +3 -0
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.d.ts +7 -0
- package/es-custom/components/prompt-line/src/prompt-line.js +9 -0
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/send-control.scss.js +1 -1
- package/es-custom/components/prompt-line/src/stop-streaming-button.scss.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +43 -21
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/plain-text-paste.js +8 -3
- package/es-custom/components/prompt-line/src/tiptap/plain-text-paste.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +3 -3
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +27 -11
- package/es-custom/components/reasoning-steps/src/reasoning-step.d.ts +3 -3
- package/es-custom/components/reasoning-steps/src/reasoning-step.js +4 -4
- package/es-custom/components/reasoning-steps/src/reasoning-step.js.map +1 -1
- package/es-custom/components/reasoning-steps/src/reasoning-step.scss.js +1 -1
- package/es-custom/components/reasoning-steps/src/reasoning-steps-toggle.scss.js +1 -1
- package/es-custom/components/reasoning-steps/src/reasoning-steps.d.ts +5 -4
- package/es-custom/components/reasoning-steps/src/reasoning-steps.js +5 -4
- package/es-custom/components/reasoning-steps/src/reasoning-steps.js.map +1 -1
- package/es-custom/components/truncated-text/src/truncated-text.scss.js +1 -1
- package/es-custom/components/video-player/src/video-player.scss.js +1 -1
- package/es-custom/react/hooks/useChatAutocomplete.js +7 -1
- package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es-custom/react/messages-shell.d.ts +3 -0
- package/es-custom/react/messages-shell.js +32 -0
- package/es-custom/react/messages-shell.js.map +1 -0
- package/package.json +4 -4
- package/scss/_markdown-inline.scss +138 -0
- package/telemetry.yml +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sources":["../../../../src/components/markdown/src/markdown.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { html, LitElement, PropertyValues, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport commonStyles from '../../../globals/scss/common.scss?lit';\nimport styles from './markdown.scss?lit';\nimport throttle from 'lodash-es/throttle.js';\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\n\nimport MarkdownIt from 'markdown-it';\n\nimport {\n markdownToTokenTree,\n type MarkdownItPlugin,\n type TokenTree,\n} from './markdown-token-tree.js';\nimport type {\n MarkdownCustomRendererMountDetail,\n MarkdownPluginFallbackMountDetail,\n} from './utils/plugin-host-container.js';\nimport {\n renderMarkdownTree,\n type MarkdownCustomRenderers,\n type MarkdownRendererSlotDescriptor,\n} from './markdown-renderer.js';\nimport {\n hasLikelyPartialTableTail,\n hasNodeAfterTable,\n hasTrailingTableToken,\n} from './utils/streaming-table.js';\nimport { nextMarkdownInstanceId } from './utils/slot-names.js';\n\nconst CONSOLE_PREFIX = '[carbon-ai-chat-components]';\n\n/**\n * True if `node` is inside (or is) a light-DOM element with a `slot` attribute\n * set, up to (but not including) `boundary`. Portal hosts mounted by consumers\n * carry a `slot` attribute, so this is used to skip both `textContent`\n * contributions and observed mutations that originated inside a portal subtree.\n */\nfunction isInsidePortalHost(node: Node, boundary: Node): boolean {\n let cur: Node | null = node;\n while (cur && cur !== boundary) {\n if (cur instanceof Element && cur.hasAttribute('slot')) {\n return true;\n }\n cur = cur.parentNode;\n }\n return false;\n}\n\n/**\n * Concatenates the markdown source from `element`'s light-DOM children,\n * skipping any `<element slot=\"…\">` portal hosts so consumer-rendered overrides\n * don't contaminate the parsed markdown source.\n */\nfunction readLightDomMarkdownSource(element: Element): string {\n let out = '';\n for (const child of Array.from(element.childNodes)) {\n if (child instanceof Element && child.hasAttribute('slot')) {\n continue;\n }\n if (child.nodeType === Node.TEXT_NODE) {\n out += child.nodeValue ?? '';\n } else if (child instanceof Element) {\n out += child.textContent ?? '';\n }\n }\n return out.trim();\n}\n\n/**\n * Renders markdown as Carbon-styled DOM. Streaming-friendly: incremental updates reparse the markdown source into a `TokenTree`, diff it against the prior tree to reuse stable subtrees, then walk it into a Lit `TemplateResult` — Lit's `repeat` directive keys off the diffed nodes so unchanged DOM stays put.\n *\n * ### Lifecycle\n *\n * 1. A property setter (or a light-DOM mutation) lands. `willUpdate` decides whether the change requires a reparse (`markdown`, `removeHTML`, `markdownItPlugins`) or only a re-render (translated strings, `streaming`, `sanitizeHTML`, `customRenderers`).\n * 2. `scheduleRender` throttles bursts to 100ms (leading + trailing).\n * 3. `renderMarkdown` parses (if needed) via {@link markdownToTokenTree}, then calls {@link renderMarkdownTree} to produce both a `TemplateResult` and a batch of {@link MarkdownRendererSlotDescriptor} records.\n * 4. After Lit commits, `updated()` runs `reconcileCustomRendererHosts` — that is where consumer-supplied `customRenderers` callbacks fire and plugin-fallback HTML is adopted into light-DOM slot hosts.\n *\n * ### Extensibility\n *\n * - {@link markdownItPlugins} runs after the built-in markdown-it plugins (markdown-it-attrs, highlight, task-lists). A new array identity rebuilds the markdown-it instance and forces a full reparse. Tokens introduced by a plugin that the native dispatch can't handle — either an unknown tag, or a plugin-overridden rule on a curated allow-list of leaf tokens — route through `md.renderer.render()` via `./utils/plugin-fallback.ts` and surface as `pluginFallback` descriptors. Their rendered HTML is adopted into a light-DOM slot host so consumer-supplied CSS (e.g. a KaTeX stylesheet on the host page) reaches it.\n * - {@link customRenderers} overrides per-element rendering for `table` and `codeBlock`. The renderer emits a named `<slot>` placeholder; the reconciler invokes the consumer's callback with the parsed data and appends the returned `HTMLElement` as a `<div slot=\"…\">` light-DOM child. Returning the same element reference across renders avoids DOM churn.\n *\n * ### Light-DOM source adoption\n *\n * When the `markdown` property has never been set explicitly, the element treats its light-DOM text content as the initial source and watches for further mutations via a `MutationObserver`. Setting the property explicitly stops the observer — the property is then the authoritative source.\n *\n * ### Related files\n *\n * - `./markdown-token-tree.ts` — markdown-it parse + tree builder + streaming-aware diff (with `cachedHtml` carry-forward for plugin-delegated tokens).\n * - `./markdown-renderer.ts` — `TokenTree` → Lit `TemplateResult`, plus descriptor collection.\n * - `./markdown-renderer-types.ts` — public ({@link MarkdownCustomRenderers}) and internal ({@link MarkdownRendererSlotDescriptor}, `RenderTokenTreeOptions`) contracts.\n * - `./utils/plugin-fallback.ts` — delegation to `md.renderer.render()` for plugin-introduced tokens.\n * - `./utils/streaming-table.ts` — heuristics that hold a streaming table in a skeleton \"loading\" state until its tail stabilizes.\n *\n * @element cds-aichat-markdown\n */\n@carbonElement(`${prefix}-markdown`)\nclass CDSAIChatMarkdown extends LitElement {\n static styles = [commonStyles, styles];\n\n /**\n * Sanitize any HTML included in the markdown. e.g. remove script tags, onclick handlers, etc.\n */\n @property({ type: Boolean, attribute: 'sanitize-html' })\n sanitizeHTML = false;\n\n /**\n * Remove all HTML from included markdown.\n */\n @property({ type: Boolean, attribute: 'remove-html' })\n removeHTML = false;\n\n /**\n * Internal storage for markdown content.\n * @internal\n */\n private _markdown = '';\n\n /**\n * Flag to temporarily allow internal markdown updates without marking as explicitly set.\n * @internal\n */\n private isInternalMarkdownUpdate = false;\n\n /**\n * Direct markdown source input.\n */\n @property({ type: String })\n get markdown(): string {\n return this._markdown;\n }\n set markdown(value: string) {\n const oldValue = this._markdown;\n this._markdown = value;\n\n // Track that markdown was explicitly set (not from Light DOM adoption)\n // Only mark as explicitly set if this is NOT an internal update\n if (!this.isInternalMarkdownUpdate) {\n this.markdownPropertyExplicitlySet = true;\n this.stopObservingLightDom();\n }\n\n this.requestUpdate('markdown', oldValue);\n }\n\n /**\n * If you are actively streaming, setting this to true can help prevent needless UI thrashing when writing\n * complex components (like a sortable and filterable table).\n */\n @property({ type: Boolean, attribute: 'streaming' })\n streaming = false;\n\n // Code snippet properties\n /** Enable syntax highlighting for any code fence blocks. */\n @property({ type: Boolean, attribute: 'code-snippet-highlight' })\n codeSnippetHighlight = true;\n\n /** Label for collapsing long code blocks. */\n @property({ type: String, attribute: 'code-snippet-show-less-text' })\n codeSnippetShowLessText = 'Show less';\n\n /** Label for expanding long code blocks. */\n @property({ type: String, attribute: 'code-snippet-show-more-text' })\n codeSnippetShowMoreText = 'Show more';\n\n /** Tooltip content for the copy action on code blocks. */\n @property({\n type: String,\n attribute: 'code-snippet-copy-button-tooltip-content',\n })\n codeSnippetCopyButtonTooltipContent = 'Copy code';\n\n /** Formatter for the code block line count. */\n @property({ type: Object, attribute: false })\n codeSnippetGetLineCountText?: ({ count }: { count: number }) => string;\n\n /** Aria-label for code snippets when in read-only mode. */\n @property({ type: String, attribute: 'code-snippet-aria-label-readonly' })\n codeSnippetAriaLabelReadOnly = 'Code snippet';\n\n /** Aria-label for code snippets when in editable mode. */\n @property({ type: String, attribute: 'code-snippet-aria-label-editable' })\n codeSnippetAriaLabelEditable = 'Code editor';\n\n // Table properties\n /** Placeholder text for table filters. */\n @property({ type: String, attribute: 'table-filter-placeholder-text' })\n tableFilterPlaceholderText = 'Filter table...';\n\n /** Label for the previous page control in tables. */\n @property({ type: String, attribute: 'table-previous-page-text' })\n tablePreviousPageText = 'Previous page';\n\n /** Label for the next page control in tables. */\n @property({ type: String, attribute: 'table-next-page-text' })\n tableNextPageText = 'Next page';\n\n /** Label for the items-per-page control in tables. */\n @property({ type: String, attribute: 'table-items-per-page-text' })\n tableItemsPerPageText = 'Items per page:';\n\n /** Label for download of CSV of table data. */\n @property({ type: String, attribute: 'table-download-label-text' })\n tableDownloadLabelText = 'Download table data';\n\n /** Locale used for table pagination and formatting. */\n @property({ type: String, attribute: 'table-locale' })\n tableLocale = 'en';\n\n /** Optional formatter for supplemental pagination text. */\n @property({ type: Object, attribute: false })\n tableGetPaginationSupplementalText?: ({ count }: { count: number }) => string;\n\n /** Optional formatter for pagination status text. */\n @property({ type: Object, attribute: false })\n tableGetPaginationStatusText?: ({\n start,\n end,\n count,\n }: {\n start: number;\n end: number;\n count: number;\n }) => string;\n\n /**\n * Markdown-it plugins applied after the built-in plugins\n * (markdown-it-attrs, markdown-it-highlight, markdown-it-task-lists).\n * Changes force a reparse. Memoize this array — a new reference each render\n * rebuilds the markdown-it instance.\n */\n @property({ type: Array, attribute: false })\n markdownItPlugins?: MarkdownItPlugin[];\n\n /**\n * Per-element render overrides. For each `kind` whose callback is provided,\n * the markdown element emits a named `<slot>` placeholder in its shadow\n * DOM, then — after each render — invokes the callback with the parsed\n * data and adopts the returned `HTMLElement` as a `<div slot=\"…\">`\n * light-DOM child of this element. Return `null` to fall back to the\n * default Carbon rendering. Returning the same element reference across\n * renders avoids DOM churn.\n *\n * Inside a chat, a container relocates the returned element into its own\n * light DOM — page DOM at the top of the chain — and this element forwards\n * it back into the named slot, so consumer-loaded page CSS reaches it.\n * Standalone (no chat ancestor), it stays a light-DOM child of this element.\n */\n @property({ attribute: false })\n customRenderers?: MarkdownCustomRenderers;\n\n /**\n * Descriptors collected during the most recent render task; consumed by\n * the `updated()` reconcile to invoke {@link customRenderers} callbacks.\n * @internal\n */\n private latestRendererDescriptors: MarkdownRendererSlotDescriptor[] = [];\n\n /**\n * Light-DOM slot hosts adopted on behalf of {@link customRenderers}, keyed\n * by slot name. Reused across renders for stable identity.\n * @internal\n */\n private slotHosts: Map<string, HTMLElement> = new Map();\n\n /**\n * `<slot name=X slot=X>` forwarders minted for {@link customRenderers} hosts\n * an outer listener relocated into its own light DOM, keyed by slot name.\n *\n * Appended imperatively rather than rendered: Lit commits into the shadow\n * root, and this hop has to be a light-DOM child of this element to gather\n * the relocated host out of the chat element's light DOM and hand it to the\n * shadow `<slot>` the renderer emitted. Minted where the claim is read\n * rather than by a subscriber, because the mount event fires once per host\n * and is never replayed — a listener that subscribes later cannot mint it.\n * @internal\n */\n private rendererForwarders: Map<string, HTMLSlotElement> = new Map();\n\n /**\n * Namespace appended to every slot name this element mints, so two markdown\n * elements rendering identical markdown never collide in the shared\n * page-level host container a chat container hoists slot hosts into.\n *\n * Assigned in the field initializer (construction) rather than\n * `connectedCallback`, which runs again after a DOM move — the namespace, and\n * therefore every slot name and every adopted host, must survive a\n * disconnect/reconnect.\n * @internal\n */\n private readonly slotNamespace = nextMarkdownInstanceId();\n\n /**\n * Slot names whose host was created by an outer listener (a chat container\n * that called `preventDefault()` on the host-mount event). We track these so\n * we can fire matching unmount events without trying to remove a host we\n * never appended.\n * @internal\n */\n private delegatedPluginSlots: Set<string> = new Set();\n\n /**\n * The markdown-it instance produced by the most recent parse. Forwarded into\n * the renderer so unknown tokens can fall back to `md.renderer.render()`.\n * @internal\n */\n private markdownItInstance?: MarkdownIt;\n\n /**\n * @internal\n */\n private needsReparse = false;\n\n /**\n * Tracks the latest asynchronous rendering work so callers waiting on `updateComplete` know when throttled updates are done.\n *\n * @internal\n */\n private renderTask: Promise<void> | null = null;\n\n private hasRenderedStreamingTableLoadingFrame = false;\n /**\n * The most recent tree parsed while in streaming table loading mode, held back\n * from rendering. It seeds `previousTreeForDiff`, so the tick that leaves loading\n * mode without a reparse still renders the content staged during it.\n * @internal\n */\n private stagedStreamingTokenTree: TokenTree | null = null;\n\n /**\n * @internal\n */\n private isStreamingTableLoadingMode = false;\n\n /**\n * @internal\n */\n private hasConnected = false;\n\n /**\n * Tracks whether the markdown property has been explicitly set by the user.\n * When false, the component will monitor Light DOM changes.\n * @internal\n */\n private markdownPropertyExplicitlySet = false;\n\n /**\n * MutationObserver to monitor Light DOM changes when markdown property isn't explicitly set.\n * @internal\n */\n private lightDomObserver: MutationObserver | null = null;\n\n /**\n * Generation counter for Light DOM mutation processing. Incremented when a\n * mutation is observed and decremented when the resulting microtask\n * completes. `updateComplete` waits while the counter is non-zero.\n * @internal\n */\n private pendingLightDomMutations = 0;\n\n connectedCallback() {\n super.connectedCallback();\n this.hasConnected = true;\n\n if (IS_PHONE) {\n this.setAttribute('phone', '');\n }\n\n this.adoptLightDomMarkdown();\n\n // Task-list checkbox toggles bubble (composed) out of the rendered\n // `cds-checkbox` elements; one delegated listener forwards them to a\n // consumer `checklist.onToggle`.\n this.addEventListener(\n 'cds-checkbox-changed',\n this.handleChecklistToggle as EventListener\n );\n\n // Ensure we parse and render on initial mount, even if markdown was set before connection\n this.needsReparse = true;\n this.scheduleRender();\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeEventListener(\n 'cds-checkbox-changed',\n this.handleChecklistToggle as EventListener\n );\n this.stopObservingLightDom();\n // Tear down any adopted slot hosts so they don't leak across re-connect.\n for (const host of this.slotHosts.values()) {\n host.remove();\n }\n this.slotHosts.clear();\n // Ask any delegating chat container to drop its hosts too. The loop above\n // already detached every relocated node — `slotHosts` holds the reference\n // wherever the node ended up — so this retires forwarders and announces.\n for (const slotName of this.delegatedPluginSlots.keys()) {\n this.retireDelegatedSlot(slotName);\n }\n this.latestRendererDescriptors = [];\n }\n\n /**\n * Delegated handler for `cds-checkbox-changed` from rendered task-list\n * checkboxes. Resolves the toggled checkbox via the composed event path (a\n * host listener would otherwise see a retargeted `event.target`), reads the\n * identity stamped by the task-list plugin, and forwards the new state to a\n * consumer `checklist.onToggle`.\n */\n private handleChecklistToggle = (event: Event): void => {\n const onToggle = this.customRenderers?.checklist?.onToggle;\n if (!onToggle) {\n return;\n }\n const checkbox = event\n .composedPath()\n .find(\n (target): target is HTMLElement =>\n target instanceof HTMLElement &&\n target.tagName.toLowerCase() === 'cds-checkbox'\n );\n const id = checkbox?.getAttribute('data-cds-aichat-checklist-id');\n if (!checkbox || id == null) {\n // Not a stamped task-list checkbox — ignore unrelated cds-checkboxes.\n return;\n }\n const checked = !!(event as CustomEvent<{ checked?: boolean }>).detail\n ?.checked;\n const label =\n checkbox.closest('cds-list-item, li')?.textContent?.trim() ?? '';\n onToggle({ id, label, checked });\n };\n\n private adoptLightDomMarkdown() {\n // Backward compatibility: treat static light-DOM text as initial markdown\n // when the explicit `markdown` property was not provided.\n if (!this.markdownPropertyExplicitlySet) {\n const lightDomMarkdown = readLightDomMarkdownSource(this);\n if (lightDomMarkdown) {\n // Set markdown without triggering the \"explicitly set\" flag\n this.isInternalMarkdownUpdate = true;\n this.markdown = lightDomMarkdown;\n this.isInternalMarkdownUpdate = false;\n }\n\n // Start observing Light DOM changes only if markdown property wasn't explicitly set\n this.startObservingLightDom();\n }\n }\n\n private startObservingLightDom() {\n if (this.lightDomObserver || this.markdownPropertyExplicitlySet) {\n return;\n }\n\n this.lightDomObserver = new MutationObserver((records) => {\n // Only update from Light DOM if markdown property still hasn't been explicitly set\n if (!this.markdownPropertyExplicitlySet) {\n // Mutations that happened entirely inside a portal host (a light-DOM\n // child with a `slot` attribute) are noise from the consumer's\n // overrides re-rendering — they don't change the markdown source.\n const relevant = records.filter(\n (record) => !isInsidePortalHost(record.target, this)\n );\n if (relevant.length === 0) {\n return;\n }\n\n // Process the mutation in a microtask so the DOM has settled. Track\n // it via a counter so `updateComplete` can await any concurrent\n // mutations without the fragility of a single-slot promise field.\n this.pendingLightDomMutations += 1;\n Promise.resolve()\n .then(() => {\n const lightDomMarkdown = readLightDomMarkdownSource(this);\n if (this.markdown !== lightDomMarkdown) {\n this.isInternalMarkdownUpdate = true;\n this.markdown = lightDomMarkdown;\n this.isInternalMarkdownUpdate = false;\n }\n })\n .finally(() => {\n this.pendingLightDomMutations -= 1;\n });\n } else {\n // If markdown was explicitly set, stop observing\n this.stopObservingLightDom();\n }\n });\n\n this.lightDomObserver.observe(this, {\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n\n private stopObservingLightDom() {\n if (this.lightDomObserver) {\n this.lightDomObserver.disconnect();\n this.lightDomObserver = null;\n }\n }\n\n protected willUpdate(changed: PropertyValues<this>) {\n // Handle initial render case: if markdown was set before connectedCallback,\n // Lit won't report it as \"changed\" but we still need to parse it\n const isInitialRender = !this.hasConnected && this.markdown;\n\n if (\n changed.has('removeHTML') ||\n changed.has('markdown') ||\n changed.has('markdownItPlugins') ||\n isInitialRender\n ) {\n // Properties that affect token tree structure require full reparse\n // - removeHTML: toggles post-parse HTML-token stripping\n // - markdown: updates the source text to parse\n // - markdownItPlugins: swaps the markdown-it instance, new parser rules\n // - isInitialRender: ensures pre-set markdown gets parsed on first render\n this.needsReparse = true;\n this.scheduleRender();\n } else if (\n // Properties that only affect rendering can skip reparsing\n // - sanitizeHTML: applies DOMPurify during render, doesn't change tokens\n // - string properties: change translated strings in rendered output\n // - streaming: affects loading states in rendered output\n // - customRenderers: only changes which tokens emit a slot\n changed.has('sanitizeHTML') ||\n changed.has('streaming') ||\n changed.has('customRenderers') ||\n // Code snippet properties\n changed.has('codeSnippetHighlight') ||\n changed.has('codeSnippetShowLessText') ||\n changed.has('codeSnippetShowMoreText') ||\n changed.has('codeSnippetCopyButtonTooltipContent') ||\n changed.has('codeSnippetGetLineCountText') ||\n changed.has('codeSnippetAriaLabelReadOnly') ||\n changed.has('codeSnippetAriaLabelEditable') ||\n // Table properties\n changed.has('tableFilterPlaceholderText') ||\n changed.has('tablePreviousPageText') ||\n changed.has('tableNextPageText') ||\n changed.has('tableItemsPerPageText') ||\n changed.has('tableDownloadLabelText') ||\n changed.has('tableLocale') ||\n changed.has('tableGetPaginationSupplementalText') ||\n changed.has('tableGetPaginationStatusText')\n ) {\n this.scheduleRender();\n }\n }\n\n /**\n * @internal\n */\n @state()\n tokenTree: TokenTree = {\n key: 'root',\n token: {\n type: 'root',\n tag: '',\n nesting: 0,\n level: 0,\n content: '',\n attrs: null,\n children: null,\n markup: '',\n block: true,\n hidden: false,\n map: null,\n info: '',\n meta: null,\n },\n children: [],\n };\n\n /**\n * @internal\n */\n @state()\n renderedContent: TemplateResult | null = null;\n\n /**\n * Throttled function that updates the rendered content.\n * If needsReparse is true, parses markdown into a token tree first.\n * Otherwise, just re-renders the existing token tree with current settings.\n *\n * @internal\n */\n private renderMarkdown = async () => {\n try {\n const markdownContent = this.markdown ?? '';\n const previousTreeForDiff =\n this.stagedStreamingTokenTree ?? this.tokenTree;\n let nextTokenTree = previousTreeForDiff;\n\n if (this.needsReparse) {\n // First, we take the markdown we were given and use the markdown-it parser to turn is into a tree we can\n // transform into Lit components and compare smartly to avoid re-renders of components that were already\n // rendered when the markdown is updated (likely by streaming, but possibly by an edit somewhere in the\n // middle). It takes the current tokenTree as an argument for quick diffing to avoid re-creating parts\n // of the tree.\n const parsed = markdownToTokenTree(\n markdownContent,\n previousTreeForDiff,\n {\n removeHtml: this.removeHTML,\n markdownItPlugins: this.markdownItPlugins,\n }\n );\n nextTokenTree = parsed.tree;\n this.markdownItInstance = parsed.md;\n this.needsReparse = false;\n }\n\n const hasStreamingTailTable =\n Boolean(this.streaming) && hasTrailingTableToken(nextTokenTree);\n const hasParsedNodeAfterTable = hasNodeAfterTable(nextTokenTree);\n\n if (!this.streaming) {\n this.isStreamingTableLoadingMode = false;\n } else if (this.isStreamingTableLoadingMode) {\n if (\n hasParsedNodeAfterTable &&\n !hasLikelyPartialTableTail(markdownContent)\n ) {\n this.isStreamingTableLoadingMode = false;\n }\n } else if (hasStreamingTailTable) {\n this.isStreamingTableLoadingMode = true;\n }\n\n // Render-and-stash helper. Each invocation produces a fresh batch of\n // renderer-slot descriptors; the `updated()` reconcile then invokes\n // the consumer's `customRenderers` callbacks for each descriptor and\n // adopts the returned `HTMLElement` as a light-DOM slot host.\n const renderAndDispatch = (tree: TokenTree): void => {\n const { template, batch } = renderMarkdownTree(tree, {\n sanitize: this.sanitizeHTML,\n streaming: this.streaming,\n // Code snippet properties\n codeSnippetHighlight: this.codeSnippetHighlight,\n codeSnippetShowLessText: this.codeSnippetShowLessText,\n codeSnippetShowMoreText: this.codeSnippetShowMoreText,\n codeSnippetCopyButtonTooltipContent:\n this.codeSnippetCopyButtonTooltipContent,\n codeSnippetGetLineCountText: this.codeSnippetGetLineCountText,\n codeSnippetAriaLabelReadOnly: this.codeSnippetAriaLabelReadOnly,\n codeSnippetAriaLabelEditable: this.codeSnippetAriaLabelEditable,\n // Table properties\n tableFilterPlaceholderText: this.tableFilterPlaceholderText,\n tablePreviousPageText: this.tablePreviousPageText,\n tableNextPageText: this.tableNextPageText,\n tableItemsPerPageText: this.tableItemsPerPageText,\n tableDownloadLabelText: this.tableDownloadLabelText,\n tableLocale: this.tableLocale,\n tableGetPaginationSupplementalText:\n this.tableGetPaginationSupplementalText,\n tableGetPaginationStatusText: this.tableGetPaginationStatusText,\n // Custom-renderer hooks\n customRenderers: this.customRenderers,\n slotNamespace: this.slotNamespace,\n md: this.markdownItInstance,\n });\n this.renderedContent = template;\n this.latestRendererDescriptors = batch;\n };\n\n if (this.streaming && this.isStreamingTableLoadingMode) {\n if (!this.hasRenderedStreamingTableLoadingFrame) {\n if (nextTokenTree !== this.tokenTree) {\n this.tokenTree = nextTokenTree;\n }\n renderAndDispatch(nextTokenTree);\n this.hasRenderedStreamingTableLoadingFrame = true;\n this.stagedStreamingTokenTree = null;\n } else {\n this.stagedStreamingTokenTree = nextTokenTree;\n }\n return;\n }\n\n // Never prefer the staged tree here: when nothing was reparsed `nextTokenTree`\n // *is* the staged tree (see `previousTreeForDiff` above), and when something\n // was, it came from newer source.\n this.stagedStreamingTokenTree = null;\n this.hasRenderedStreamingTableLoadingFrame = false;\n if (nextTokenTree !== this.tokenTree) {\n this.tokenTree = nextTokenTree;\n }\n\n // Next we take that tree and transform it into Lit content to be rendered into the template.\n // this.renderedContent is what is rendered in the template directly.\n renderAndDispatch(nextTokenTree);\n } catch (error) {\n console.error(`${CONSOLE_PREFIX} Failed to parse markdown`, error);\n }\n };\n\n /**\n * @internal\n */\n private scheduleRender = throttle(\n () => {\n // Lit's getter/setter pipeline can schedule multiple renders quickly.\n // We capture the active render promise so we can report completion later.\n const task = this.renderMarkdown();\n const trackedTask = task.finally(() => {\n if (this.renderTask === trackedTask) {\n this.renderTask = null;\n }\n });\n\n this.renderTask = trackedTask;\n return trackedTask;\n },\n 100,\n { leading: true, trailing: true }\n );\n\n protected async getUpdateComplete(): Promise<boolean> {\n // `updateComplete` is Lit's public hook for consumers/tests to await\n // all pending work. Because we throttle renders, the base implementation\n // might resolve before the throttled callback runs. Overriding this\n // method lets us flush the throttle and await the render promise so\n // callers can reliably wait for `renderedContent` to update.\n const result = await super.getUpdateComplete();\n\n const flushResult = (\n this.scheduleRender as {\n flush?: () => Promise<void> | void;\n }\n ).flush?.();\n\n if (flushResult instanceof Promise) {\n await flushResult;\n }\n\n if (this.renderTask) {\n await this.renderTask;\n }\n\n // Drain any in-flight Light DOM mutation microtasks and their resulting\n // renders. Each iteration yields the event loop so newly enqueued\n // mutations can settle; the counter goes back to zero once everything\n // has flushed.\n while (this.pendingLightDomMutations > 0) {\n await Promise.resolve();\n\n const postMutationFlush = (\n this.scheduleRender as {\n flush?: () => Promise<void> | void;\n }\n ).flush?.();\n\n if (postMutationFlush instanceof Promise) {\n await postMutationFlush;\n }\n\n if (this.renderTask) {\n await this.renderTask;\n }\n }\n\n return result;\n }\n\n protected updated(changed: PropertyValues<this>) {\n super.updated(changed);\n this.reconcileCustomRendererHosts();\n }\n\n /**\n * Drops a claim: retires the forwarder minted for it, if any, then tells the\n * container to let go.\n *\n * The forwarder goes first. An assigned node suppresses the shadow slot's\n * fallback content for as long as it exists, so a surviving forwarder turns\n * a removed host into a blank region instead of the default rendering.\n * @internal\n */\n /**\n * Records a claim and mints the innermost hop back to the host the listener\n * just relocated. Called in the same pass that read the claim because the\n * mount event fires once per host and is never replayed — minting here is\n * what makes a claim without its forwarder unrepresentable.\n * @internal\n */\n private adoptDelegatedSlot(slotName: string) {\n this.delegatedPluginSlots.add(slotName);\n const forwarder = document.createElement('slot');\n forwarder.setAttribute('name', slotName);\n forwarder.setAttribute('slot', slotName);\n this.rendererForwarders.set(slotName, forwarder);\n this.appendChild(forwarder);\n }\n\n private retireDelegatedSlot(slotName: string) {\n this.rendererForwarders.get(slotName)?.remove();\n this.rendererForwarders.delete(slotName);\n this.delegatedPluginSlots.delete(slotName);\n this.dispatchEvent(\n new CustomEvent('cds-aichat-markdown-plugin-host-unmount', {\n bubbles: true,\n composed: true,\n detail: { slotName },\n })\n );\n }\n\n /**\n * Invoke the consumer's `customRenderers` callbacks once per descriptor and\n * adopt their returned `HTMLElement` as a `<span slot=\"…\">` (for inline\n * plugin tokens) or `<div slot=\"…\">` (block tokens and consumer renderers)\n * light-DOM child. Hosts persist across renders so a consumer returning the\n * same element reference produces no DOM churn; hosts whose slot names\n * dropped out of the latest descriptor batch are removed.\n *\n * @internal\n */\n private reconcileCustomRendererHosts() {\n const renderers = this.customRenderers;\n const descriptors = this.latestRendererDescriptors;\n const wanted = new Set<string>();\n\n for (const descriptor of descriptors) {\n if (descriptor.kind === 'pluginFallback') {\n wanted.add(descriptor.slotName);\n\n // Offer the slot to a chat-container ancestor first. The chain\n // appends the host to its OWN light DOM (page DOM at the top of the\n // chain) so external CSS (e.g. a KaTeX stylesheet on the host page)\n // reaches the plugin output. If a listener calls preventDefault, it\n // has taken over hosting and we skip the local appendChild path.\n const alreadyDelegated = this.delegatedPluginSlots.has(\n descriptor.slotName\n );\n if (!alreadyDelegated && !this.slotHosts.has(descriptor.slotName)) {\n const mountEvent = new CustomEvent(\n 'cds-aichat-markdown-plugin-host-mount',\n {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n kind: 'pluginFallback',\n slotName: descriptor.slotName,\n html: descriptor.html,\n isInline: descriptor.isInline,\n } satisfies MarkdownPluginFallbackMountDetail,\n }\n );\n this.dispatchEvent(mountEvent);\n if (mountEvent.defaultPrevented) {\n this.adoptDelegatedSlot(descriptor.slotName);\n }\n } else if (alreadyDelegated) {\n // The chain owns this slot; push HTML updates through a second\n // event so streaming chunks reach the page-level host element.\n this.dispatchEvent(\n new CustomEvent('cds-aichat-markdown-plugin-host-update', {\n bubbles: true,\n composed: true,\n detail: {\n slotName: descriptor.slotName,\n html: descriptor.html,\n },\n })\n );\n }\n\n if (this.delegatedPluginSlots.has(descriptor.slotName)) {\n continue;\n }\n\n // Fallback: no outer listener took over (standalone usage, e.g.\n // storybook). Adopt the host as our own light-DOM child, matching\n // the pre-event behavior so existing tests/stories keep working.\n let host = this.slotHosts.get(descriptor.slotName);\n if (!host) {\n const tag = descriptor.isInline ? 'span' : 'div';\n host = document.createElement(tag);\n host.setAttribute('slot', descriptor.slotName);\n this.slotHosts.set(descriptor.slotName, host);\n this.appendChild(host);\n }\n // Only rewrite innerHTML when the plugin output actually changed;\n // streaming re-renders frequently land here with the same HTML.\n if (host.innerHTML !== descriptor.html) {\n host.innerHTML = descriptor.html;\n }\n continue;\n }\n\n const callback = renderers?.[descriptor.kind];\n if (!callback) {\n continue;\n }\n let result: HTMLElement | null;\n try {\n result = (\n callback as (\n args: Parameters<NonNullable<typeof callback>>[0]\n ) => HTMLElement | null\n )({\n ...descriptor.data,\n token: descriptor.token,\n slotName: descriptor.slotName,\n });\n } catch (error) {\n console.error(\n `[carbon-ai-chat-components] customRenderers.${descriptor.kind} threw`,\n error\n );\n continue;\n }\n if (result == null) {\n const existing = this.slotHosts.get(descriptor.slotName);\n if (existing) {\n existing.remove();\n this.slotHosts.delete(descriptor.slotName);\n }\n continue;\n }\n wanted.add(descriptor.slotName);\n let host = this.slotHosts.get(descriptor.slotName);\n if (!host) {\n host = document.createElement('div');\n host.setAttribute('slot', descriptor.slotName);\n this.slotHosts.set(descriptor.slotName, host);\n\n // Offer the host to a chat-container ancestor so it lives in page\n // light DOM, where consumer-loaded global CSS (e.g. `@carbon/styles`\n // for a returned `@carbon/react` component) can reach it — the markdown\n // element's own light DOM sits inside the chat's shadow root, where it\n // cannot. Mirrors the plugin-fallback path above, but forwards the live\n // host element instead of an HTML string; the markdown element keeps\n // ownership of the host's content across renders, and mints the slot\n // hop back to it below. If no ancestor takes over (standalone usage,\n // e.g. storybook), host it locally.\n const mountEvent = new CustomEvent(\n 'cds-aichat-markdown-plugin-host-mount',\n {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n kind: 'customRenderer',\n slotName: descriptor.slotName,\n element: host,\n isInline: false,\n } satisfies MarkdownCustomRendererMountDetail,\n }\n );\n this.dispatchEvent(mountEvent);\n if (mountEvent.defaultPrevented) {\n this.adoptDelegatedSlot(descriptor.slotName);\n } else {\n this.appendChild(host);\n }\n }\n if (host.firstChild !== result || host.childNodes.length !== 1) {\n host.replaceChildren(result);\n }\n }\n\n for (const [slotName, host] of this.slotHosts) {\n if (!wanted.has(slotName)) {\n host.remove();\n this.slotHosts.delete(slotName);\n }\n }\n\n // Drop claims whose descriptor disappeared (a streaming chunk removed a\n // math node, a `customRenderers` callback returned null): the host was\n // already detached above, so this retires the hop and announces.\n for (const slotName of this.delegatedPluginSlots.keys()) {\n if (!wanted.has(slotName)) {\n this.retireDelegatedSlot(slotName);\n }\n }\n }\n\n protected render() {\n const { renderedContent } = this;\n return html`<div class=\"cds-aichat-markdown-stack\">\n ${renderedContent}\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-aichat-markdown': CDSAIChatMarkdown;\n }\n}\n\nexport { CDSAIChatMarkdown };\nexport default CDSAIChatMarkdown;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAkCH,MAAM,cAAc,GAAG,6BAA6B;AAEpD;;;;;AAKG;AACH,SAAS,kBAAkB,CAAC,IAAU,EAAE,QAAc,EAAA;IACpD,IAAI,GAAG,GAAgB,IAAI;AAC3B,IAAA,OAAO,GAAG,IAAI,GAAG,KAAK,QAAQ,EAAE;QAC9B,IAAI,GAAG,YAAY,OAAO,IAAI,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;AACtD,YAAA,OAAO,IAAI;QACb;AACA,QAAA,G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CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;AACJ,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AAiBvC,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE;AACY,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,MAAA,CAAA;AAsT1C,UAAA,CAAA;AADC,IAAA,KAAK;AAmBJ,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAMF,UAAA,CAAA;AADC,IAAA,KAAK;AACwC,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,MAAA,CAAA;AAte1C,iBAAiB,GAAA,UAAA,CAAA;AADtB,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,SAAA,CAAW;AAC7B,CAAA,EAAA,iBAAiB,CA+3BtB;AASD,0BAAe,iBAAiB;;"}
|
|
1
|
+
{"version":3,"file":"markdown.js","sources":["../../../../src/components/markdown/src/markdown.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2025, 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { html, LitElement, PropertyValues, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport commonStyles from '../../../globals/scss/common.scss?lit';\nimport styles from './markdown.scss?lit';\nimport throttle from 'lodash-es/throttle.js';\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\n\nimport MarkdownIt from 'markdown-it';\n\nimport {\n markdownToTokenTree,\n type MarkdownItPlugin,\n type TokenTree,\n} from './markdown-token-tree.js';\nimport type {\n MarkdownCustomRendererMountDetail,\n MarkdownPluginFallbackMountDetail,\n} from './utils/plugin-host-container.js';\nimport {\n renderMarkdownTree,\n type MarkdownCustomRenderers,\n type MarkdownRendererSlotDescriptor,\n} from './markdown-renderer.js';\nimport {\n hasLikelyPartialTableTail,\n hasNodeAfterTable,\n hasTrailingTableToken,\n} from './utils/streaming-table.js';\nimport { nextMarkdownInstanceId } from './utils/slot-names.js';\n\nconst CONSOLE_PREFIX = '[carbon-ai-chat-components]';\n\n/**\n * True if `node` is inside (or is) a light-DOM element with a `slot` attribute\n * set, up to (but not including) `boundary`. Portal hosts mounted by consumers\n * carry a `slot` attribute, so this is used to skip both `textContent`\n * contributions and observed mutations that originated inside a portal subtree.\n */\nfunction isInsidePortalHost(node: Node, boundary: Node): boolean {\n let cur: Node | null = node;\n while (cur && cur !== boundary) {\n if (cur instanceof Element && cur.hasAttribute('slot')) {\n return true;\n }\n cur = cur.parentNode;\n }\n return false;\n}\n\n/**\n * Concatenates the markdown source from `element`'s light-DOM children,\n * skipping any `<element slot=\"…\">` portal hosts so consumer-rendered overrides\n * don't contaminate the parsed markdown source.\n */\nfunction readLightDomMarkdownSource(element: Element): string {\n let out = '';\n for (const child of Array.from(element.childNodes)) {\n if (child instanceof Element && child.hasAttribute('slot')) {\n continue;\n }\n if (child.nodeType === Node.TEXT_NODE) {\n out += child.nodeValue ?? '';\n } else if (child instanceof Element) {\n out += child.textContent ?? '';\n }\n }\n return out.trim();\n}\n\n/**\n * Renders markdown as Carbon-styled DOM. Streaming-friendly: incremental updates reparse the markdown source into a `TokenTree`, diff it against the prior tree to reuse stable subtrees, then walk it into a Lit `TemplateResult` — Lit's `repeat` directive keys off the diffed nodes so unchanged DOM stays put.\n *\n * ### Lifecycle\n *\n * 1. A property setter (or a light-DOM mutation) lands. `willUpdate` decides whether the change requires a reparse (`markdown`, `removeHTML`, `markdownItPlugins`) or only a re-render (translated strings, `streaming`, `sanitizeHTML`, `customRenderers`).\n * 2. `scheduleRender` throttles bursts to 100ms (leading + trailing).\n * 3. `renderMarkdown` parses (if needed) via {@link markdownToTokenTree}, then calls {@link renderMarkdownTree} to produce both a `TemplateResult` and a batch of {@link MarkdownRendererSlotDescriptor} records.\n * 4. After Lit commits, `updated()` runs `reconcileCustomRendererHosts` — that is where consumer-supplied `customRenderers` callbacks fire and plugin-fallback HTML is adopted into light-DOM slot hosts.\n *\n * ### Extensibility\n *\n * - {@link markdownItPlugins} runs after the built-in markdown-it plugins (markdown-it-attrs, highlight, task-lists). A new array identity rebuilds the markdown-it instance and forces a full reparse. Tokens introduced by a plugin that the native dispatch can't handle — either an unknown tag, or a plugin-overridden rule on a curated allow-list of leaf tokens — route through `md.renderer.render()` via `./utils/plugin-fallback.ts` and surface as `pluginFallback` descriptors. Their rendered HTML is adopted into a light-DOM slot host so consumer-supplied CSS (e.g. a KaTeX stylesheet on the host page) reaches it.\n * - {@link customRenderers} overrides per-element rendering for `table` and `codeBlock`. The renderer emits a named `<slot>` placeholder; the reconciler invokes the consumer's callback with the parsed data and appends the returned `HTMLElement` as a `<div slot=\"…\">` light-DOM child. Returning the same element reference across renders avoids DOM churn.\n *\n * ### Light-DOM source adoption\n *\n * When the `markdown` property has never been set explicitly, the element treats its light-DOM text content as the initial source and watches for further mutations via a `MutationObserver`. Setting the property explicitly stops the observer — the property is then the authoritative source.\n *\n * ### Related files\n *\n * - `./markdown-token-tree.ts` — markdown-it parse + tree builder + streaming-aware diff (with `cachedHtml` carry-forward for plugin-delegated tokens).\n * - `./markdown-renderer.ts` — `TokenTree` → Lit `TemplateResult`, plus descriptor collection.\n * - `./markdown-renderer-types.ts` — public ({@link MarkdownCustomRenderers}) and internal ({@link MarkdownRendererSlotDescriptor}, `RenderTokenTreeOptions`) contracts.\n * - `./utils/plugin-fallback.ts` — delegation to `md.renderer.render()` for plugin-introduced tokens.\n * - `./utils/streaming-table.ts` — heuristics that hold a streaming table in a skeleton \"loading\" state until its tail stabilizes.\n *\n * @element cds-aichat-markdown\n */\n@carbonElement(`${prefix}-markdown`)\nclass CDSAIChatMarkdown extends LitElement {\n static styles = [commonStyles, styles];\n\n /**\n * Sanitize any HTML included in the markdown. e.g. remove script tags, onclick handlers, etc.\n */\n @property({ type: Boolean, attribute: 'sanitize-html' })\n sanitizeHTML = false;\n\n /**\n * Remove all HTML from included markdown.\n */\n @property({ type: Boolean, attribute: 'remove-html' })\n removeHTML = false;\n\n /**\n * Internal storage for markdown content.\n * @internal\n */\n private _markdown = '';\n\n /**\n * Flag to temporarily allow internal markdown updates without marking as explicitly set.\n * @internal\n */\n private isInternalMarkdownUpdate = false;\n\n /**\n * Direct markdown source input.\n */\n @property({ type: String })\n get markdown(): string {\n return this._markdown;\n }\n set markdown(value: string) {\n const oldValue = this._markdown;\n this._markdown = value;\n\n // Track that markdown was explicitly set (not from Light DOM adoption)\n // Only mark as explicitly set if this is NOT an internal update\n if (!this.isInternalMarkdownUpdate) {\n this.markdownPropertyExplicitlySet = true;\n this.stopObservingLightDom();\n }\n\n this.requestUpdate('markdown', oldValue);\n }\n\n /**\n * If you are actively streaming, setting this to true can help prevent needless UI thrashing when writing\n * complex components (like a sortable and filterable table).\n */\n @property({ type: Boolean, attribute: 'streaming' })\n streaming = false;\n\n // Code snippet properties\n /** Enable syntax highlighting for any code fence blocks. */\n @property({ type: Boolean, attribute: 'code-snippet-highlight' })\n codeSnippetHighlight = true;\n\n /** Label for collapsing long code blocks. */\n @property({ type: String, attribute: 'code-snippet-show-less-text' })\n codeSnippetShowLessText = 'Show less';\n\n /** Label for expanding long code blocks. */\n @property({ type: String, attribute: 'code-snippet-show-more-text' })\n codeSnippetShowMoreText = 'Show more';\n\n /** Tooltip content for the copy action on code blocks. */\n @property({\n type: String,\n attribute: 'code-snippet-copy-button-tooltip-content',\n })\n codeSnippetCopyButtonTooltipContent = 'Copy code';\n\n /** Formatter for the code block line count. */\n @property({ type: Object, attribute: false })\n codeSnippetGetLineCountText?: ({ count }: { count: number }) => string;\n\n /** Aria-label for code snippets when in read-only mode. */\n @property({ type: String, attribute: 'code-snippet-aria-label-readonly' })\n codeSnippetAriaLabelReadOnly = 'Code snippet';\n\n /** Aria-label for code snippets when in editable mode. */\n @property({ type: String, attribute: 'code-snippet-aria-label-editable' })\n codeSnippetAriaLabelEditable = 'Code editor';\n\n // Table properties\n /** Placeholder text for table filters. */\n @property({ type: String, attribute: 'table-filter-placeholder-text' })\n tableFilterPlaceholderText = 'Filter table...';\n\n /** Label for the previous page control in tables. */\n @property({ type: String, attribute: 'table-previous-page-text' })\n tablePreviousPageText = 'Previous page';\n\n /** Label for the next page control in tables. */\n @property({ type: String, attribute: 'table-next-page-text' })\n tableNextPageText = 'Next page';\n\n /** Label for the items-per-page control in tables. */\n @property({ type: String, attribute: 'table-items-per-page-text' })\n tableItemsPerPageText = 'Items per page:';\n\n /** Label for download of CSV of table data. */\n @property({ type: String, attribute: 'table-download-label-text' })\n tableDownloadLabelText = 'Download table data';\n\n /** Locale used for table pagination and formatting. */\n @property({ type: String, attribute: 'table-locale' })\n tableLocale = 'en';\n\n /** Optional formatter for supplemental pagination text. */\n @property({ type: Object, attribute: false })\n tableGetPaginationSupplementalText?: ({ count }: { count: number }) => string;\n\n /** Optional formatter for pagination status text. */\n @property({ type: Object, attribute: false })\n tableGetPaginationStatusText?: ({\n start,\n end,\n count,\n }: {\n start: number;\n end: number;\n count: number;\n }) => string;\n\n /**\n * Markdown-it plugins applied after the built-in plugins\n * (markdown-it-attrs, markdown-it-highlight, markdown-it-task-lists).\n * Changes force a reparse. Memoize this array — a new reference each render\n * rebuilds the markdown-it instance.\n */\n @property({ type: Array, attribute: false })\n markdownItPlugins?: MarkdownItPlugin[];\n\n /**\n * Per-element render overrides. For each `kind` whose callback is provided,\n * the markdown element emits a named `<slot>` placeholder in its shadow\n * DOM, then — after each render — invokes the callback with the parsed\n * data and adopts the returned `HTMLElement` as a `<div slot=\"…\">`\n * light-DOM child of this element. Return `null` to fall back to the\n * default Carbon rendering. Returning the same element reference across\n * renders avoids DOM churn.\n *\n * Inside a chat, a container relocates the returned element into its own\n * light DOM — page DOM at the top of the chain — and this element forwards\n * it back into the named slot, so consumer-loaded page CSS reaches it.\n * Standalone (no chat ancestor), it stays a light-DOM child of this element.\n */\n @property({ attribute: false })\n customRenderers?: MarkdownCustomRenderers;\n\n /**\n * Descriptors collected during the most recent render task; consumed by\n * the `updated()` reconcile to invoke {@link customRenderers} callbacks.\n * @internal\n */\n private latestRendererDescriptors: MarkdownRendererSlotDescriptor[] = [];\n\n /**\n * Light-DOM slot hosts adopted on behalf of {@link customRenderers}, keyed\n * by slot name. Reused across renders for stable identity.\n * @internal\n */\n private slotHosts: Map<string, HTMLElement> = new Map();\n\n /**\n * `<slot name=X slot=X>` forwarders minted for {@link customRenderers} hosts\n * an outer listener relocated into its own light DOM, keyed by slot name.\n *\n * Appended imperatively rather than rendered: Lit commits into the shadow\n * root, and this hop has to be a light-DOM child of this element to gather\n * the relocated host out of the chat element's light DOM and hand it to the\n * shadow `<slot>` the renderer emitted. Minted where the claim is read\n * rather than by a subscriber, because the mount event fires once per host\n * and is never replayed — a listener that subscribes later cannot mint it.\n * @internal\n */\n private rendererForwarders: Map<string, HTMLSlotElement> = new Map();\n\n /**\n * Namespace appended to every slot name this element mints, so two markdown\n * elements rendering identical markdown never collide in the shared\n * page-level host container a chat container hoists slot hosts into.\n *\n * Assigned in the field initializer (construction) rather than\n * `connectedCallback`, which runs again after a DOM move — the namespace, and\n * therefore every slot name and every adopted host, must survive a\n * disconnect/reconnect.\n * @internal\n */\n private readonly slotNamespace = nextMarkdownInstanceId();\n\n /**\n * Slot names whose host was created by an outer listener (a chat container\n * that called `preventDefault()` on the host-mount event). We track these so\n * we can fire matching unmount events without trying to remove a host we\n * never appended.\n * @internal\n */\n private delegatedPluginSlots: Set<string> = new Set();\n\n /**\n * The markdown-it instance produced by the most recent parse. Forwarded into\n * the renderer so unknown tokens can fall back to `md.renderer.render()`.\n * @internal\n */\n private markdownItInstance?: MarkdownIt;\n\n /**\n * @internal\n */\n private needsReparse = false;\n\n /**\n * Tracks the latest asynchronous rendering work so callers waiting on `updateComplete` know when throttled updates are done.\n *\n * @internal\n */\n private renderTask: Promise<void> | null = null;\n\n private hasRenderedStreamingTableLoadingFrame = false;\n /**\n * The most recent tree parsed while in streaming table loading mode, held back\n * from rendering. It seeds `previousTreeForDiff`, so the tick that leaves loading\n * mode without a reparse still renders the content staged during it.\n * @internal\n */\n private stagedStreamingTokenTree: TokenTree | null = null;\n\n /**\n * @internal\n */\n private isStreamingTableLoadingMode = false;\n\n /**\n * @internal\n */\n private hasConnected = false;\n\n /**\n * Tracks whether the markdown property has been explicitly set by the user.\n * When false, the component will monitor Light DOM changes.\n * @internal\n */\n private markdownPropertyExplicitlySet = false;\n\n /**\n * MutationObserver to monitor Light DOM changes when markdown property isn't explicitly set.\n * @internal\n */\n private lightDomObserver: MutationObserver | null = null;\n\n /**\n * Generation counter for Light DOM mutation processing. Incremented when a\n * mutation is observed and decremented when the resulting microtask\n * completes. `updateComplete` waits while the counter is non-zero.\n * @internal\n */\n private pendingLightDomMutations = 0;\n\n connectedCallback() {\n super.connectedCallback();\n this.hasConnected = true;\n\n if (IS_PHONE) {\n this.setAttribute('phone', '');\n }\n\n this.adoptLightDomMarkdown();\n\n // Task-list checkbox toggles bubble (composed) out of the rendered\n // `cds-checkbox` elements; one delegated listener forwards them to a\n // consumer `checklist.onToggle`.\n this.addEventListener(\n 'cds-checkbox-changed',\n this.handleChecklistToggle as EventListener\n );\n\n // Ensure we parse and render on initial mount, even if markdown was set before connection\n this.needsReparse = true;\n this.scheduleRender();\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeEventListener(\n 'cds-checkbox-changed',\n this.handleChecklistToggle as EventListener\n );\n this.stopObservingLightDom();\n // Tear down any adopted slot hosts so they don't leak across re-connect.\n for (const host of this.slotHosts.values()) {\n host.remove();\n }\n this.slotHosts.clear();\n // Ask any delegating chat container to drop its hosts too. The loop above\n // already detached every relocated node — `slotHosts` holds the reference\n // wherever the node ended up — so this retires forwarders and announces.\n for (const slotName of this.delegatedPluginSlots.keys()) {\n this.retireDelegatedSlot(slotName);\n }\n this.latestRendererDescriptors = [];\n }\n\n /**\n * Delegated handler for `cds-checkbox-changed` from rendered task-list\n * checkboxes. Resolves the toggled checkbox via the composed event path (a\n * host listener would otherwise see a retargeted `event.target`), reads the\n * identity stamped by the task-list plugin, and forwards the new state to a\n * consumer `checklist.onToggle`.\n */\n private handleChecklistToggle = (event: Event): void => {\n const onToggle = this.customRenderers?.checklist?.onToggle;\n if (!onToggle) {\n return;\n }\n const checkbox = event\n .composedPath()\n .find(\n (target): target is HTMLElement =>\n target instanceof HTMLElement &&\n target.tagName.toLowerCase() === 'cds-checkbox'\n );\n const id = checkbox?.getAttribute('data-cds-aichat-checklist-id');\n if (!checkbox || id == null) {\n // Not a stamped task-list checkbox — ignore unrelated cds-checkboxes.\n return;\n }\n const checked = !!(event as CustomEvent<{ checked?: boolean }>).detail\n ?.checked;\n const label =\n checkbox.closest('cds-list-item, li')?.textContent?.trim() ?? '';\n onToggle({ id, label, checked });\n };\n\n private adoptLightDomMarkdown() {\n // Backward compatibility: treat static light-DOM text as initial markdown\n // when the explicit `markdown` property was not provided.\n if (!this.markdownPropertyExplicitlySet) {\n const lightDomMarkdown = readLightDomMarkdownSource(this);\n if (lightDomMarkdown) {\n // Set markdown without triggering the \"explicitly set\" flag\n this.isInternalMarkdownUpdate = true;\n this.markdown = lightDomMarkdown;\n this.isInternalMarkdownUpdate = false;\n }\n\n // Start observing Light DOM changes only if markdown property wasn't explicitly set\n this.startObservingLightDom();\n }\n }\n\n private startObservingLightDom() {\n if (this.lightDomObserver || this.markdownPropertyExplicitlySet) {\n return;\n }\n\n this.lightDomObserver = new MutationObserver((records) => {\n // Only update from Light DOM if markdown property still hasn't been explicitly set\n if (!this.markdownPropertyExplicitlySet) {\n // Mutations that happened entirely inside a portal host (a light-DOM\n // child with a `slot` attribute) are noise from the consumer's\n // overrides re-rendering — they don't change the markdown source.\n const relevant = records.filter(\n (record) => !isInsidePortalHost(record.target, this)\n );\n if (relevant.length === 0) {\n return;\n }\n\n // Process the mutation in a microtask so the DOM has settled. Track\n // it via a counter so `updateComplete` can await any concurrent\n // mutations without the fragility of a single-slot promise field.\n this.pendingLightDomMutations += 1;\n Promise.resolve()\n .then(() => {\n const lightDomMarkdown = readLightDomMarkdownSource(this);\n if (this.markdown !== lightDomMarkdown) {\n this.isInternalMarkdownUpdate = true;\n this.markdown = lightDomMarkdown;\n this.isInternalMarkdownUpdate = false;\n }\n })\n .finally(() => {\n this.pendingLightDomMutations -= 1;\n });\n } else {\n // If markdown was explicitly set, stop observing\n this.stopObservingLightDom();\n }\n });\n\n this.lightDomObserver.observe(this, {\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n\n private stopObservingLightDom() {\n if (this.lightDomObserver) {\n this.lightDomObserver.disconnect();\n this.lightDomObserver = null;\n }\n }\n\n protected willUpdate(changed: PropertyValues<this>) {\n // Handle initial render case: if markdown was set before connectedCallback,\n // Lit won't report it as \"changed\" but we still need to parse it\n const isInitialRender = !this.hasConnected && this.markdown;\n\n if (\n changed.has('removeHTML') ||\n changed.has('markdown') ||\n changed.has('markdownItPlugins') ||\n isInitialRender\n ) {\n // Properties that affect token tree structure require full reparse\n // - removeHTML: toggles post-parse HTML-token stripping\n // - markdown: updates the source text to parse\n // - markdownItPlugins: swaps the markdown-it instance, new parser rules\n // - isInitialRender: ensures pre-set markdown gets parsed on first render\n this.needsReparse = true;\n this.scheduleRender();\n } else if (\n // Properties that only affect rendering can skip reparsing\n // - sanitizeHTML: applies DOMPurify during render, doesn't change tokens\n // - string properties: change translated strings in rendered output\n // - streaming: affects loading states in rendered output\n // - customRenderers: only changes which tokens emit a slot\n changed.has('sanitizeHTML') ||\n changed.has('streaming') ||\n changed.has('customRenderers') ||\n // Code snippet properties\n changed.has('codeSnippetHighlight') ||\n changed.has('codeSnippetShowLessText') ||\n changed.has('codeSnippetShowMoreText') ||\n changed.has('codeSnippetCopyButtonTooltipContent') ||\n changed.has('codeSnippetGetLineCountText') ||\n changed.has('codeSnippetAriaLabelReadOnly') ||\n changed.has('codeSnippetAriaLabelEditable') ||\n // Table properties\n changed.has('tableFilterPlaceholderText') ||\n changed.has('tablePreviousPageText') ||\n changed.has('tableNextPageText') ||\n changed.has('tableItemsPerPageText') ||\n changed.has('tableDownloadLabelText') ||\n changed.has('tableLocale') ||\n changed.has('tableGetPaginationSupplementalText') ||\n changed.has('tableGetPaginationStatusText')\n ) {\n this.scheduleRender();\n }\n }\n\n /**\n * @internal\n */\n @state()\n tokenTree: TokenTree = {\n key: 'root',\n token: {\n type: 'root',\n tag: '',\n nesting: 0,\n level: 0,\n content: '',\n attrs: null,\n children: null,\n markup: '',\n block: true,\n hidden: false,\n map: null,\n info: '',\n meta: null,\n },\n children: [],\n };\n\n /**\n * @internal\n */\n @state()\n renderedContent: TemplateResult | null = null;\n\n /**\n * Throttled function that updates the rendered content.\n * If needsReparse is true, parses markdown into a token tree first.\n * Otherwise, just re-renders the existing token tree with current settings.\n *\n * @internal\n */\n private renderMarkdown = async () => {\n try {\n const markdownContent = this.markdown ?? '';\n const previousTreeForDiff =\n this.stagedStreamingTokenTree ?? this.tokenTree;\n let nextTokenTree = previousTreeForDiff;\n\n if (this.needsReparse) {\n // First, we take the markdown we were given and use the markdown-it parser to turn is into a tree we can\n // transform into Lit components and compare smartly to avoid re-renders of components that were already\n // rendered when the markdown is updated (likely by streaming, but possibly by an edit somewhere in the\n // middle). It takes the current tokenTree as an argument for quick diffing to avoid re-creating parts\n // of the tree.\n const parsed = markdownToTokenTree(\n markdownContent,\n previousTreeForDiff,\n {\n removeHtml: this.removeHTML,\n markdownItPlugins: this.markdownItPlugins,\n }\n );\n nextTokenTree = parsed.tree;\n this.markdownItInstance = parsed.md;\n this.needsReparse = false;\n }\n\n const hasStreamingTailTable =\n Boolean(this.streaming) && hasTrailingTableToken(nextTokenTree);\n const hasParsedNodeAfterTable = hasNodeAfterTable(nextTokenTree);\n\n if (!this.streaming) {\n this.isStreamingTableLoadingMode = false;\n } else if (this.isStreamingTableLoadingMode) {\n if (\n hasParsedNodeAfterTable &&\n !hasLikelyPartialTableTail(markdownContent)\n ) {\n this.isStreamingTableLoadingMode = false;\n }\n } else if (hasStreamingTailTable) {\n this.isStreamingTableLoadingMode = true;\n }\n\n // Render-and-stash helper. Each invocation produces a fresh batch of\n // renderer-slot descriptors; the `updated()` reconcile then invokes\n // the consumer's `customRenderers` callbacks for each descriptor and\n // adopts the returned `HTMLElement` as a light-DOM slot host.\n const renderAndDispatch = (tree: TokenTree): void => {\n const { template, batch } = renderMarkdownTree(tree, {\n sanitize: this.sanitizeHTML,\n streaming: this.streaming,\n // Code snippet properties\n codeSnippetHighlight: this.codeSnippetHighlight,\n codeSnippetShowLessText: this.codeSnippetShowLessText,\n codeSnippetShowMoreText: this.codeSnippetShowMoreText,\n codeSnippetCopyButtonTooltipContent:\n this.codeSnippetCopyButtonTooltipContent,\n codeSnippetGetLineCountText: this.codeSnippetGetLineCountText,\n codeSnippetAriaLabelReadOnly: this.codeSnippetAriaLabelReadOnly,\n codeSnippetAriaLabelEditable: this.codeSnippetAriaLabelEditable,\n // Table properties\n tableFilterPlaceholderText: this.tableFilterPlaceholderText,\n tablePreviousPageText: this.tablePreviousPageText,\n tableNextPageText: this.tableNextPageText,\n tableItemsPerPageText: this.tableItemsPerPageText,\n tableDownloadLabelText: this.tableDownloadLabelText,\n tableLocale: this.tableLocale,\n tableGetPaginationSupplementalText:\n this.tableGetPaginationSupplementalText,\n tableGetPaginationStatusText: this.tableGetPaginationStatusText,\n // Custom-renderer hooks\n customRenderers: this.customRenderers,\n slotNamespace: this.slotNamespace,\n projectionHost: this,\n md: this.markdownItInstance,\n });\n this.renderedContent = template;\n this.latestRendererDescriptors = batch;\n };\n\n if (this.streaming && this.isStreamingTableLoadingMode) {\n if (!this.hasRenderedStreamingTableLoadingFrame) {\n if (nextTokenTree !== this.tokenTree) {\n this.tokenTree = nextTokenTree;\n }\n renderAndDispatch(nextTokenTree);\n this.hasRenderedStreamingTableLoadingFrame = true;\n this.stagedStreamingTokenTree = null;\n } else {\n this.stagedStreamingTokenTree = nextTokenTree;\n }\n return;\n }\n\n // Never prefer the staged tree here: when nothing was reparsed `nextTokenTree`\n // *is* the staged tree (see `previousTreeForDiff` above), and when something\n // was, it came from newer source.\n this.stagedStreamingTokenTree = null;\n this.hasRenderedStreamingTableLoadingFrame = false;\n if (nextTokenTree !== this.tokenTree) {\n this.tokenTree = nextTokenTree;\n }\n\n // Next we take that tree and transform it into Lit content to be rendered into the template.\n // this.renderedContent is what is rendered in the template directly.\n renderAndDispatch(nextTokenTree);\n } catch (error) {\n console.error(`${CONSOLE_PREFIX} Failed to parse markdown`, error);\n }\n };\n\n /**\n * @internal\n */\n private scheduleRender = throttle(\n () => {\n // Lit's getter/setter pipeline can schedule multiple renders quickly.\n // We capture the active render promise so we can report completion later.\n const task = this.renderMarkdown();\n const trackedTask = task.finally(() => {\n if (this.renderTask === trackedTask) {\n this.renderTask = null;\n }\n });\n\n this.renderTask = trackedTask;\n return trackedTask;\n },\n 100,\n { leading: true, trailing: true }\n );\n\n protected async getUpdateComplete(): Promise<boolean> {\n // `updateComplete` is Lit's public hook for consumers/tests to await\n // all pending work. Because we throttle renders, the base implementation\n // might resolve before the throttled callback runs. Overriding this\n // method lets us flush the throttle and await the render promise so\n // callers can reliably wait for `renderedContent` to update.\n const result = await super.getUpdateComplete();\n\n const flushResult = (\n this.scheduleRender as {\n flush?: () => Promise<void> | void;\n }\n ).flush?.();\n\n if (flushResult instanceof Promise) {\n await flushResult;\n }\n\n if (this.renderTask) {\n await this.renderTask;\n }\n\n // Drain any in-flight Light DOM mutation microtasks and their resulting\n // renders. Each iteration yields the event loop so newly enqueued\n // mutations can settle; the counter goes back to zero once everything\n // has flushed.\n while (this.pendingLightDomMutations > 0) {\n await Promise.resolve();\n\n const postMutationFlush = (\n this.scheduleRender as {\n flush?: () => Promise<void> | void;\n }\n ).flush?.();\n\n if (postMutationFlush instanceof Promise) {\n await postMutationFlush;\n }\n\n if (this.renderTask) {\n await this.renderTask;\n }\n }\n\n return result;\n }\n\n protected updated(changed: PropertyValues<this>) {\n super.updated(changed);\n this.reconcileCustomRendererHosts();\n }\n\n /**\n * Drops a claim: retires the forwarder minted for it, if any, then tells the\n * container to let go.\n *\n * The forwarder goes first. An assigned node suppresses the shadow slot's\n * fallback content for as long as it exists, so a surviving forwarder turns\n * a removed host into a blank region instead of the default rendering.\n * @internal\n */\n /**\n * Records a claim and mints the innermost hop back to the host the listener\n * just relocated. Called in the same pass that read the claim because the\n * mount event fires once per host and is never replayed — minting here is\n * what makes a claim without its forwarder unrepresentable.\n * @internal\n */\n private adoptDelegatedSlot(slotName: string) {\n this.delegatedPluginSlots.add(slotName);\n const forwarder = document.createElement('slot');\n forwarder.setAttribute('name', slotName);\n forwarder.setAttribute('slot', slotName);\n this.rendererForwarders.set(slotName, forwarder);\n this.appendChild(forwarder);\n }\n\n private retireDelegatedSlot(slotName: string) {\n this.rendererForwarders.get(slotName)?.remove();\n this.rendererForwarders.delete(slotName);\n this.delegatedPluginSlots.delete(slotName);\n this.dispatchEvent(\n new CustomEvent('cds-aichat-markdown-plugin-host-unmount', {\n bubbles: true,\n composed: true,\n detail: { slotName },\n })\n );\n }\n\n /**\n * Invoke the consumer's `customRenderers` callbacks once per descriptor and\n * adopt their returned `HTMLElement` as a `<span slot=\"…\">` (for inline\n * plugin tokens) or `<div slot=\"…\">` (block tokens and consumer renderers)\n * light-DOM child. Hosts persist across renders so a consumer returning the\n * same element reference produces no DOM churn; hosts whose slot names\n * dropped out of the latest descriptor batch are removed.\n *\n * @internal\n */\n private reconcileCustomRendererHosts() {\n const renderers = this.customRenderers;\n const descriptors = this.latestRendererDescriptors;\n const wanted = new Set<string>();\n\n for (const descriptor of descriptors) {\n if (descriptor.kind === 'pluginFallback') {\n wanted.add(descriptor.slotName);\n\n // Offer the slot to a chat-container ancestor first. The chain\n // appends the host to its OWN light DOM (page DOM at the top of the\n // chain) so external CSS (e.g. a KaTeX stylesheet on the host page)\n // reaches the plugin output. If a listener calls preventDefault, it\n // has taken over hosting and we skip the local appendChild path.\n const alreadyDelegated = this.delegatedPluginSlots.has(\n descriptor.slotName\n );\n if (!alreadyDelegated && !this.slotHosts.has(descriptor.slotName)) {\n const mountEvent = new CustomEvent(\n 'cds-aichat-markdown-plugin-host-mount',\n {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n kind: 'pluginFallback',\n slotName: descriptor.slotName,\n html: descriptor.html,\n isInline: descriptor.isInline,\n } satisfies MarkdownPluginFallbackMountDetail,\n }\n );\n this.dispatchEvent(mountEvent);\n if (mountEvent.defaultPrevented) {\n this.adoptDelegatedSlot(descriptor.slotName);\n }\n } else if (alreadyDelegated) {\n // The chain owns this slot; push HTML updates through a second\n // event so streaming chunks reach the page-level host element.\n this.dispatchEvent(\n new CustomEvent('cds-aichat-markdown-plugin-host-update', {\n bubbles: true,\n composed: true,\n detail: {\n slotName: descriptor.slotName,\n html: descriptor.html,\n },\n })\n );\n }\n\n if (this.delegatedPluginSlots.has(descriptor.slotName)) {\n continue;\n }\n\n // Fallback: no outer listener took over (standalone usage, e.g.\n // storybook). Adopt the host as our own light-DOM child, matching\n // the pre-event behavior so existing tests/stories keep working.\n let host = this.slotHosts.get(descriptor.slotName);\n if (!host) {\n const tag = descriptor.isInline ? 'span' : 'div';\n host = document.createElement(tag);\n host.setAttribute('slot', descriptor.slotName);\n this.slotHosts.set(descriptor.slotName, host);\n this.appendChild(host);\n }\n // Only rewrite innerHTML when the plugin output actually changed;\n // streaming re-renders frequently land here with the same HTML.\n if (host.innerHTML !== descriptor.html) {\n host.innerHTML = descriptor.html;\n }\n continue;\n }\n\n const callback = renderers?.[descriptor.kind];\n if (!callback) {\n continue;\n }\n let result: HTMLElement | null;\n try {\n result = (\n callback as (\n args: Parameters<NonNullable<typeof callback>>[0]\n ) => HTMLElement | null\n )({\n ...descriptor.data,\n token: descriptor.token,\n slotName: descriptor.slotName,\n });\n } catch (error) {\n console.error(\n `[carbon-ai-chat-components] customRenderers.${descriptor.kind} threw`,\n error\n );\n continue;\n }\n if (result == null) {\n const existing = this.slotHosts.get(descriptor.slotName);\n if (existing) {\n existing.remove();\n this.slotHosts.delete(descriptor.slotName);\n }\n continue;\n }\n wanted.add(descriptor.slotName);\n let host = this.slotHosts.get(descriptor.slotName);\n if (!host) {\n host = document.createElement('div');\n host.setAttribute('slot', descriptor.slotName);\n this.slotHosts.set(descriptor.slotName, host);\n\n // Offer the host to a chat-container ancestor so it lives in page\n // light DOM, where consumer-loaded global CSS (e.g. `@carbon/styles`\n // for a returned `@carbon/react` component) can reach it — the markdown\n // element's own light DOM sits inside the chat's shadow root, where it\n // cannot. Mirrors the plugin-fallback path above, but forwards the live\n // host element instead of an HTML string; the markdown element keeps\n // ownership of the host's content across renders, and mints the slot\n // hop back to it below. If no ancestor takes over (standalone usage,\n // e.g. storybook), host it locally.\n const mountEvent = new CustomEvent(\n 'cds-aichat-markdown-plugin-host-mount',\n {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n kind: 'customRenderer',\n slotName: descriptor.slotName,\n element: host,\n isInline: false,\n } satisfies MarkdownCustomRendererMountDetail,\n }\n );\n this.dispatchEvent(mountEvent);\n if (mountEvent.defaultPrevented) {\n this.adoptDelegatedSlot(descriptor.slotName);\n } else {\n this.appendChild(host);\n }\n }\n if (host.firstChild !== result || host.childNodes.length !== 1) {\n host.replaceChildren(result);\n }\n }\n\n for (const [slotName, host] of this.slotHosts) {\n if (!wanted.has(slotName)) {\n host.remove();\n this.slotHosts.delete(slotName);\n }\n }\n\n // Drop claims whose descriptor disappeared (a streaming chunk removed a\n // math node, a `customRenderers` callback returned null): the host was\n // already detached above, so this retires the hop and announces.\n for (const slotName of this.delegatedPluginSlots.keys()) {\n if (!wanted.has(slotName)) {\n this.retireDelegatedSlot(slotName);\n }\n }\n }\n\n protected render() {\n const { renderedContent } = this;\n return html`<div class=\"cds-aichat-markdown-stack\">\n ${renderedContent}\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-aichat-markdown': CDSAIChatMarkdown;\n }\n}\n\nexport { CDSAIChatMarkdown };\nexport default CDSAIChatMarkdown;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAkCH,MAAM,cAAc,GAAG,6BAA6B;AAEpD;;;;;AAKG;AACH,SAAS,kBAAkB,CAAC,IAAU,EAAE,QAAc,EAAA;IACpD,IAAI,GAAG,GAAgB,IAAI;AAC3B,IAAA,OAAO,GAAG,IAAI,GAAG,KAAK,QAAQ,EAAE;QAC9B,IAAI,GAAG,YAAY,OAAO,IAAI,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;AACtD,YAAA,OAAO,IAAI;QACb;AACA,QAAA,GAAG,GAAG,GAAG,CAAC,UAAU;IACtB;AACA,IAAA,OAAO,KAAK;AACd;AAEA;;;;AAIG;AACH,SAAS,0BAA0B,CAAC,OAAgB,EAAA;IAClD,IAAI,GAAG,GAAG,EAAE;AACZ,IAAA,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAClD,IAAI,KAAK,YAAY,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YAC1D;QACF;QACA,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,SAAS,EAAE;AACrC,YAAA,GAAG,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE;QAC9B;AAAO,aAAA,IAAI,KAAK,YAAY,OAAO,EAAE;AACnC,YAAA,GAAG,IAAI,KAAK,CAAC,WAAW,IAAI,EAAE;QAChC;IACF;AACA,IAAA,OAAO,GAAG,CAAC,IAAI,EAAE;AACnB;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AAEH,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU,CAAA;AAA1C,IAAA,WAAA,GAAA;;AAGE;;AAEG;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10
|
-
var styles = css(["@charset \"UTF-8\";:host{
|
|
10
|
+
var styles = css(["@charset \"UTF-8\";:host{display:block;inline-size:100%;max-inline-size:100%;--cds-aichat-border-radius-start-start:0.5rem;--cds-aichat-border-radius-start-end:0.5rem;--cds-aichat-border-radius-end-start:0.5rem;--cds-aichat-border-radius-end-end:0.5rem;font-size:var(--cds-body-01-font-size,.875rem);font-weight:var(--cds-body-01-font-weight,400);letter-spacing:var(--cds-body-01-letter-spacing,.16px);line-height:var(--cds-body-01-line-height,1.42857)}:host mark{background-color:var(--cds-highlight,#d0e2ff);border-radius:.25rem;color:var(--cds-text-primary,#161616)}:host b,:host strong{font-weight:700}:host em,:host i{font-style:italic}:host blockquote{border-inline-start:2px solid var(--cds-border-subtle-00,#e0e0e0);padding-inline-start:.5rem}:host blockquote>:not(:first-child){margin-block-start:1rem}:host blockquote>h1+:not(:first-child),:host blockquote>h2+:not(:first-child),:host blockquote>h3+:not(:first-child),:host blockquote>h4+:not(:first-child),:host blockquote>h5+:not(:first-child),:host blockquote>h6+:not(:first-child){margin-block-start:.5rem}:host .cds-aichat-markdown-stack{display:block;max-inline-size:100%}:host .cds-aichat-markdown-stack>slot{display:block}:host .cds-aichat-markdown-stack>:not(:first-child){margin-block-start:1rem}:host .cds-aichat-markdown-stack>h1+:not(:first-child),:host .cds-aichat-markdown-stack>h2+:not(:first-child),:host .cds-aichat-markdown-stack>h3+:not(:first-child),:host .cds-aichat-markdown-stack>h4+:not(:first-child),:host .cds-aichat-markdown-stack>h5+:not(:first-child),:host .cds-aichat-markdown-stack>h6+:not(:first-child){margin-block-start:.25rem}:host p{font-size:var(--cds-body-01-font-size,.875rem);font-weight:var(--cds-body-01-font-weight,400);letter-spacing:var(--cds-body-01-letter-spacing,.16px);line-height:var(--cds-body-01-line-height,1.42857)}:host a{color:var(--cds-link-primary,#0f62fe);outline:none;text-decoration:none}@media (prefers-reduced-motion:no-preference){:host a{transition:color motion(standard,productive) 70ms}}:host a:hover{color:var(--cds-link-primary-hover,#0043ce);text-decoration:underline}:host a:focus{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){:host a:focus{outline-style:dotted}}:host a:focus{outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}:host a:visited{color:var(--cds-link-primary,#0f62fe)}:host a:active{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){:host a:active{outline-style:dotted}}:host a:active{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}:host a:visited:hover{color:var(--cds-link-primary-hover,#0043ce)}:host a:active:visited,:host a:active:visited:hover{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){:host a:active:visited,:host a:active:visited:hover{outline-style:dotted}}:host a:active:visited,:host a:active:visited:hover{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}:host pre{background-color:var(--cds-layer-02,#fff);border:1px solid var(--cds-chat-bubble-border,#e0e0e0);font-family:var(--cds-code-02-font-family,\"IBM Plex Mono\",system-ui,-apple-system,BlinkMacSystemFont,\".SFNSText-Regular\",monospace);font-size:var(--cds-code-02-font-size,.875rem);font-weight:var(--cds-code-02-font-weight,400);letter-spacing:var(--cds-code-02-letter-spacing,.32px);line-height:var(--cds-code-02-line-height,1.42857);overflow:auto hidden;padding:1rem;white-space:pre-wrap}:host hr{background-color:var(--cds-border-subtle-01,#c6c6c6);block-size:1px;border:0;margin:0}:host img{max-inline-size:100%}:host h1{font-size:var(--cds-heading-04-font-size,1.75rem);font-weight:var(--cds-heading-04-font-weight,400);letter-spacing:var(--cds-heading-04-letter-spacing,0);line-height:var(--cds-heading-04-line-height,1.28572)}:host h2{font-size:var(--cds-heading-03-font-size,1.25rem);font-weight:var(--cds-heading-03-font-weight,400);letter-spacing:var(--cds-heading-03-letter-spacing,0);line-height:var(--cds-heading-03-line-height,1.4)}:host h3{font-size:var(--cds-heading-02-font-size,1rem);font-weight:var(--cds-heading-02-font-weight,600);letter-spacing:var(--cds-heading-02-letter-spacing,0);line-height:var(--cds-heading-02-line-height,1.5)}:host h4{font-size:var(--cds-heading-01-font-size,.875rem);font-weight:var(--cds-heading-01-font-weight,600);letter-spacing:var(--cds-heading-01-letter-spacing,.16px);line-height:var(--cds-heading-01-line-height,1.42857)}:host h5{font-size:var(--cds-heading-01-font-size,.875rem);font-weight:var(--cds-heading-01-font-weight,600);letter-spacing:var(--cds-heading-01-letter-spacing,.16px);line-height:var(--cds-heading-01-line-height,1.42857)}:host h6{font-size:var(--cds-heading-01-font-size,.875rem);font-weight:var(--cds-heading-01-font-weight,600);letter-spacing:var(--cds-heading-01-letter-spacing,.16px);line-height:var(--cds-heading-01-line-height,1.42857)}:host ol,:host ul{font-size:var(--cds-body-01-font-size,.875rem);font-weight:var(--cds-body-01-font-weight,400);letter-spacing:var(--cds-body-01-letter-spacing,.16px);line-height:var(--cds-body-01-line-height,1.42857);list-style:none;margin:0;padding:0}:host li{padding-inline-start:.25rem}:host li+li{margin-block-start:.5rem}:host ul{margin-inline-start:1rem}:host ul>li{color:var(--cds-text-primary,#161616);position:relative}:host ul>li:before{content:\"–\";inset-inline-start:-1rem;position:absolute}:host ol{counter-reset:item;margin-inline-start:1rem}:host ol>li{color:var(--cds-text-primary,#161616);position:relative}:host ol>li:before{content:counter(item) \".\";counter-increment:item;inset-inline-start:-1rem;position:absolute}:host ol ol,:host ol ul,:host ul ol,:host ul ul{margin-block-start:.5rem;margin-inline-start:2rem}:host ul ul>li:before{content:\"▪\";inset-inline-start:-.75rem}:host ol ol{list-style-type:lower-latin}:host ol ol>li:before{content:counter(item,lower-latin) \".\"}:host .cds-aichat-table--square{--cds-aichat-border-radius-start-start:0;--cds-aichat-border-radius-start-end:0;--cds-aichat-border-radius-end-start:0;--cds-aichat-border-radius-end-end:0}:host cds-ordered-list cds-list-item:not([nested]){margin-inline-start:1rem}:host cds-aichat-code-snippet{display:block}:host cds-aichat-code-snippet:not(:defined){display:none}:host([phone]){font-size:var(--cds-body-02-font-size,1rem);font-weight:var(--cds-body-02-font-weight,400);letter-spacing:var(--cds-body-02-letter-spacing,0);line-height:var(--cds-body-02-line-height,1.5)}:host([phone]) p{font-size:var(--cds-body-02-font-size,1rem);font-weight:var(--cds-body-02-font-weight,400);letter-spacing:var(--cds-body-02-letter-spacing,0);line-height:var(--cds-body-02-line-height,1.5)}:host([phone]) ol,:host([phone]) ul{font-size:var(--cds-body-02-font-size,1rem);font-weight:var(--cds-body-02-font-weight,400);letter-spacing:var(--cds-body-02-letter-spacing,0);line-height:var(--cds-body-02-line-height,1.5)}"]);
|
|
11
11
|
|
|
12
12
|
export { styles as default };
|
|
13
13
|
//# sourceMappingURL=markdown.scss.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type TemplateResult } from 'lit';
|
|
2
|
+
import { Directive, type ChildPart } from 'lit/directive.js';
|
|
3
|
+
export declare function installInlineRunStyles(host: HTMLElement): () => void;
|
|
4
|
+
declare class ProjectedInlinePlugin extends Directive {
|
|
5
|
+
render(_markup: string, fallback: string): string;
|
|
6
|
+
update(part: ChildPart, [markup, fallback]: [string, string]): string | TemplateResult<1>;
|
|
7
|
+
}
|
|
8
|
+
export declare const projectedInlinePlugin: (_markup: string, fallback: string) => import("lit-html/directive.js").DirectiveResult<typeof ProjectedInlinePlugin>;
|
|
9
|
+
interface InlineRunOptions {
|
|
10
|
+
slotName: string;
|
|
11
|
+
fallbackHost?: HTMLElement;
|
|
12
|
+
resetInlineStyles?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function projectInlineRun(content: TemplateResult, options: InlineRunOptions): TemplateResult;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { html, nothing, render } from 'lit';
|
|
9
|
+
import { AsyncDirective } from 'lit/async-directive.js';
|
|
10
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
11
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
12
|
+
import prefix from '../../../../globals/settings.js';
|
|
13
|
+
import styles from '../inline-run-projection.scss.js';
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Copyright IBM Corp. 2026
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*
|
|
21
|
+
* @license
|
|
22
|
+
*/
|
|
23
|
+
const projectionHosts = new WeakSet();
|
|
24
|
+
const styleRoots = new WeakMap();
|
|
25
|
+
function installInlineRunStyles(host) {
|
|
26
|
+
const root = host.getRootNode();
|
|
27
|
+
if (!(root instanceof Document || root instanceof ShadowRoot)) {
|
|
28
|
+
return () => { };
|
|
29
|
+
}
|
|
30
|
+
let entry = styleRoots.get(root);
|
|
31
|
+
if (!entry) {
|
|
32
|
+
entry = { count: 0 };
|
|
33
|
+
try {
|
|
34
|
+
const sheet = new CSSStyleSheet();
|
|
35
|
+
sheet.replaceSync(styles.cssText);
|
|
36
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
37
|
+
entry.sheet = sheet;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
const element = host.ownerDocument.createElement('style');
|
|
41
|
+
element.textContent = styles.cssText;
|
|
42
|
+
(root instanceof Document ? root.head : root).append(element);
|
|
43
|
+
entry.element = element;
|
|
44
|
+
}
|
|
45
|
+
styleRoots.set(root, entry);
|
|
46
|
+
}
|
|
47
|
+
entry.count++;
|
|
48
|
+
return () => {
|
|
49
|
+
entry.count--;
|
|
50
|
+
if (entry.count) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (entry.sheet) {
|
|
54
|
+
root.adoptedStyleSheets = root.adoptedStyleSheets.filter((sheet) => sheet !== entry.sheet);
|
|
55
|
+
}
|
|
56
|
+
entry.element?.remove();
|
|
57
|
+
styleRoots.delete(root);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
class ProjectedInlinePlugin extends Directive {
|
|
61
|
+
render(_markup, fallback) {
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
update(part, [markup, fallback]) {
|
|
65
|
+
const host = part.options?.host;
|
|
66
|
+
return host && projectionHosts.has(host)
|
|
67
|
+
? html `<span class=${`${prefix}-markdown-inline-plugin`}
|
|
68
|
+
>${unsafeHTML(markup)}</span
|
|
69
|
+
>`
|
|
70
|
+
: fallback;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const projectedInlinePlugin = directive(ProjectedInlinePlugin);
|
|
74
|
+
class InlineRunProjection extends AsyncDirective {
|
|
75
|
+
constructor() {
|
|
76
|
+
super(...arguments);
|
|
77
|
+
this.mounted = false;
|
|
78
|
+
}
|
|
79
|
+
render(_content, _options) {
|
|
80
|
+
return nothing;
|
|
81
|
+
}
|
|
82
|
+
update(part, [content, options]) {
|
|
83
|
+
if (this.options?.slotName !== options.slotName) {
|
|
84
|
+
this.unmount();
|
|
85
|
+
this.host = part.element.ownerDocument.createElement('span');
|
|
86
|
+
projectionHosts.add(this.host);
|
|
87
|
+
}
|
|
88
|
+
this.slot = part.element;
|
|
89
|
+
this.options = options;
|
|
90
|
+
this.host.className = options.resetInlineStyles
|
|
91
|
+
? `${prefix}-markdown-inline-run ${prefix}-markdown-inline-run--reset`
|
|
92
|
+
: `${prefix}-markdown-inline-run`;
|
|
93
|
+
this.host.slot = options.slotName;
|
|
94
|
+
this.rootPart = render(content, this.host, {
|
|
95
|
+
host: this.host,
|
|
96
|
+
isConnected: this.mounted,
|
|
97
|
+
});
|
|
98
|
+
queueMicrotask(() => this.connectRun());
|
|
99
|
+
return nothing;
|
|
100
|
+
}
|
|
101
|
+
connectRun() {
|
|
102
|
+
if (!this.isConnected ||
|
|
103
|
+
this.mounted ||
|
|
104
|
+
!this.slot ||
|
|
105
|
+
!this.host ||
|
|
106
|
+
!this.options) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!this.slot.isConnected) {
|
|
110
|
+
this.connectionFrame ??= requestAnimationFrame(() => {
|
|
111
|
+
this.connectionFrame = undefined;
|
|
112
|
+
this.connectRun();
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.cancelConnectionFrame();
|
|
117
|
+
const detail = {
|
|
118
|
+
kind: 'customRenderer',
|
|
119
|
+
slotName: this.options.slotName,
|
|
120
|
+
element: this.host,
|
|
121
|
+
isInline: true,
|
|
122
|
+
};
|
|
123
|
+
const claimed = !this.slot.dispatchEvent(new CustomEvent(`${prefix}-markdown-plugin-host-mount`, {
|
|
124
|
+
bubbles: true,
|
|
125
|
+
composed: true,
|
|
126
|
+
cancelable: true,
|
|
127
|
+
detail,
|
|
128
|
+
}));
|
|
129
|
+
this.mounted = true;
|
|
130
|
+
if (this.options.fallbackHost) {
|
|
131
|
+
if (claimed) {
|
|
132
|
+
this.forwarder = this.slot.ownerDocument.createElement('slot');
|
|
133
|
+
this.forwarder.name = this.options.slotName;
|
|
134
|
+
this.forwarder.slot = this.options.slotName;
|
|
135
|
+
this.options.fallbackHost.append(this.forwarder);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.options.fallbackHost.append(this.host);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (this.host.isConnected) {
|
|
142
|
+
this.releaseStyles = installInlineRunStyles(this.host);
|
|
143
|
+
this.rootPart?.setConnected(true);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
cancelConnectionFrame() {
|
|
147
|
+
if (this.connectionFrame !== undefined) {
|
|
148
|
+
cancelAnimationFrame(this.connectionFrame);
|
|
149
|
+
this.connectionFrame = undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
unmount() {
|
|
153
|
+
this.cancelConnectionFrame();
|
|
154
|
+
if (this.mounted) {
|
|
155
|
+
this.slot?.dispatchEvent(new CustomEvent(`${prefix}-markdown-plugin-host-unmount`, {
|
|
156
|
+
bubbles: true,
|
|
157
|
+
composed: true,
|
|
158
|
+
detail: { slotName: this.options.slotName },
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
this.mounted = false;
|
|
162
|
+
this.rootPart?.setConnected(false);
|
|
163
|
+
this.releaseStyles?.();
|
|
164
|
+
this.releaseStyles = undefined;
|
|
165
|
+
this.host?.remove();
|
|
166
|
+
this.forwarder?.remove();
|
|
167
|
+
this.forwarder = undefined;
|
|
168
|
+
}
|
|
169
|
+
disconnected() {
|
|
170
|
+
this.cancelConnectionFrame();
|
|
171
|
+
if (this.slot?.isConnected) {
|
|
172
|
+
this.unmount();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// A same-task DOM move reconnects before this microtask runs.
|
|
176
|
+
queueMicrotask(() => {
|
|
177
|
+
if (!this.isConnected || !this.slot?.isConnected) {
|
|
178
|
+
this.unmount();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
reconnected() {
|
|
183
|
+
this.connectRun();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const inlineRunProjection = directive(InlineRunProjection);
|
|
187
|
+
function projectInlineRun(content, options) {
|
|
188
|
+
return html `<slot
|
|
189
|
+
name=${options.slotName}
|
|
190
|
+
${inlineRunProjection(content, options)}
|
|
191
|
+
>${content}</slot
|
|
192
|
+
>`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { installInlineRunStyles, projectInlineRun, projectedInlinePlugin };
|
|
196
|
+
//# sourceMappingURL=inline-run-projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-run-projection.js","sources":["../../../../../src/components/markdown/src/utils/inline-run-projection.ts"],"sourcesContent":["/*\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @license\n */\n\nimport { html, nothing, render, type RootPart, type TemplateResult } from 'lit';\nimport { AsyncDirective } from 'lit/async-directive.js';\nimport {\n Directive,\n directive,\n type ChildPart,\n type ElementPart,\n} from 'lit/directive.js';\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js';\nimport prefix from '../../../../globals/settings.js';\nimport styles from '../inline-run-projection.scss?lit';\nimport type { MarkdownCustomRendererMountDetail } from './plugin-host-container.js';\n\nconst projectionHosts = new WeakSet<object>();\nconst styleRoots = new WeakMap<\n Document | ShadowRoot,\n {\n count: number;\n sheet?: CSSStyleSheet;\n element?: HTMLStyleElement;\n }\n>();\n\nexport function installInlineRunStyles(host: HTMLElement): () => void {\n const root = host.getRootNode();\n if (!(root instanceof Document || root instanceof ShadowRoot)) {\n return () => {};\n }\n let entry = styleRoots.get(root);\n if (!entry) {\n entry = { count: 0 };\n try {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(styles.cssText);\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n entry.sheet = sheet;\n } catch {\n const element = host.ownerDocument.createElement('style');\n element.textContent = styles.cssText;\n (root instanceof Document ? root.head : root).append(element);\n entry.element = element;\n }\n styleRoots.set(root, entry);\n }\n entry.count++;\n return () => {\n entry.count--;\n if (entry.count) {\n return;\n }\n if (entry.sheet) {\n root.adoptedStyleSheets = root.adoptedStyleSheets.filter(\n (sheet) => sheet !== entry.sheet\n );\n }\n entry.element?.remove();\n styleRoots.delete(root);\n };\n}\n\nclass ProjectedInlinePlugin extends Directive {\n render(_markup: string, fallback: string) {\n return fallback;\n }\n\n update(part: ChildPart, [markup, fallback]: [string, string]) {\n const host = part.options?.host;\n return host && projectionHosts.has(host)\n ? html`<span class=${`${prefix}-markdown-inline-plugin`}\n >${unsafeHTML(markup)}</span\n >`\n : fallback;\n }\n}\n\nexport const projectedInlinePlugin = directive(ProjectedInlinePlugin);\n\ninterface InlineRunOptions {\n slotName: string;\n fallbackHost?: HTMLElement;\n resetInlineStyles?: boolean;\n}\n\nclass InlineRunProjection extends AsyncDirective {\n private slot?: HTMLSlotElement;\n private host?: HTMLSpanElement;\n private forwarder?: HTMLSlotElement;\n private rootPart?: RootPart;\n private options?: InlineRunOptions;\n private mounted = false;\n private connectionFrame?: number;\n private releaseStyles?: () => void;\n\n render(_content: TemplateResult, _options: InlineRunOptions) {\n return nothing;\n }\n\n update(\n part: ElementPart,\n [content, options]: [TemplateResult, InlineRunOptions]\n ) {\n if (this.options?.slotName !== options.slotName) {\n this.unmount();\n this.host = part.element.ownerDocument.createElement('span');\n projectionHosts.add(this.host);\n }\n this.slot = part.element as HTMLSlotElement;\n this.options = options;\n this.host!.className = options.resetInlineStyles\n ? `${prefix}-markdown-inline-run ${prefix}-markdown-inline-run--reset`\n : `${prefix}-markdown-inline-run`;\n this.host!.slot = options.slotName;\n this.rootPart = render(content, this.host!, {\n host: this.host,\n isConnected: this.mounted,\n });\n queueMicrotask(() => this.connectRun());\n return nothing;\n }\n\n private connectRun() {\n if (\n !this.isConnected ||\n this.mounted ||\n !this.slot ||\n !this.host ||\n !this.options\n ) {\n return;\n }\n if (!this.slot.isConnected) {\n this.connectionFrame ??= requestAnimationFrame(() => {\n this.connectionFrame = undefined;\n this.connectRun();\n });\n return;\n }\n this.cancelConnectionFrame();\n const detail: MarkdownCustomRendererMountDetail = {\n kind: 'customRenderer',\n slotName: this.options.slotName,\n element: this.host,\n isInline: true,\n };\n const claimed = !this.slot.dispatchEvent(\n new CustomEvent(`${prefix}-markdown-plugin-host-mount`, {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail,\n })\n );\n this.mounted = true;\n if (this.options.fallbackHost) {\n if (claimed) {\n this.forwarder = this.slot.ownerDocument.createElement('slot');\n this.forwarder.name = this.options.slotName;\n this.forwarder.slot = this.options.slotName;\n this.options.fallbackHost.append(this.forwarder);\n } else {\n this.options.fallbackHost.append(this.host);\n }\n }\n if (this.host.isConnected) {\n this.releaseStyles = installInlineRunStyles(this.host);\n this.rootPart?.setConnected(true);\n }\n }\n\n private cancelConnectionFrame() {\n if (this.connectionFrame !== undefined) {\n cancelAnimationFrame(this.connectionFrame);\n this.connectionFrame = undefined;\n }\n }\n\n private unmount() {\n this.cancelConnectionFrame();\n if (this.mounted) {\n this.slot?.dispatchEvent(\n new CustomEvent(`${prefix}-markdown-plugin-host-unmount`, {\n bubbles: true,\n composed: true,\n detail: { slotName: this.options!.slotName },\n })\n );\n }\n this.mounted = false;\n this.rootPart?.setConnected(false);\n this.releaseStyles?.();\n this.releaseStyles = undefined;\n this.host?.remove();\n this.forwarder?.remove();\n this.forwarder = undefined;\n }\n\n protected disconnected() {\n this.cancelConnectionFrame();\n if (this.slot?.isConnected) {\n this.unmount();\n return;\n }\n // A same-task DOM move reconnects before this microtask runs.\n queueMicrotask(() => {\n if (!this.isConnected || !this.slot?.isConnected) {\n this.unmount();\n }\n });\n }\n\n protected reconnected() {\n this.connectRun();\n }\n}\n\nconst inlineRunProjection = directive(InlineRunProjection);\n\nexport function projectInlineRun(\n content: TemplateResult,\n options: InlineRunOptions\n): TemplateResult {\n return html`<slot\n name=${options.slotName}\n ${inlineRunProjection(content, options)}\n >${content}</slot\n >`;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAeH,MAAM,eAAe,GAAG,IAAI,OAAO,EAAU;AAC7C,MAAM,UAAU,GAAG,IAAI,OAAO,EAO3B;AAEG,SAAU,sBAAsB,CAAC,IAAiB,EAAA;AACtD,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;IAC/B,IAAI,EAAE,IAAI,YAAY,QAAQ,IAAI,IAAI,YAAY,UAAU,CAAC,EAAE;AAC7D,QAAA,OAAO,MAAK,EAAE,CAAC;IACjB;IACA,IAAI,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE;AACV,QA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G,KAAK;AACpB,QAAA,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC;AAClC,QAAA,IAAI,CAAC,aAAa,IAAI;AACtB,QAAA,IAAI,CAAC,aAAa,GAAG,SAAS;AAC9B,QAAA,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE;AACnB,QAAA,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE;AACxB,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;IAC5B;IAEU,YAAY,GAAA;QACpB,IAAI,CAAC,qBAAqB,EAAE;AAC5B,QAAA,IAAI,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE;YAC1B,IAAI,CAAC,OAAO,EAAE;YACd;QACF;;QAEA,cAAc,CAAC,MAAK;AAClB,YAAA,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE;gBAChD,IAAI,CAAC,OAAO,EAAE;YAChB;AACF,QAAA,CAAC,CAAC;IACJ;IAEU,WAAW,GAAA;QACnB,IAAI,CAAC,UAAU,EAAE;IACnB;AACD;AAED,MAAM,mBAAmB,GAAG,SAAS,CAAC,mBAAmB,CAAC;AAEpD,SAAU,gBAAgB,CAC9B,OAAuB,EACvB,OAAyB,EAAA;AAEzB,IAAA,OAAO,IAAI,CAAA,CAAA;AACF,SAAA,EAAA,OAAO,CAAC,QAAQ;AACrB,IAAA,EAAA,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;OACpC,OAAO,CAAA;IACV;AACJ;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TokenTree } from '../markdown-token-tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reports source or output that cannot join an inline paragraph.
|
|
4
|
+
* @category Messaging
|
|
5
|
+
*/
|
|
6
|
+
export declare class InlineMarkdownError extends Error {
|
|
7
|
+
/** Stable reason for rejecting the complete run. */
|
|
8
|
+
readonly code: 'block-content' | 'non-inline-output';
|
|
9
|
+
constructor(code: 'block-content' | 'non-inline-output', message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare function validateInlineTree(tree: TokenTree, source: string): TokenTree | undefined;
|
|
12
|
+
export declare function validateInlineAttributes(attributes: Record<string, string>): void;
|
|
13
|
+
export declare function validateInlineHTML(html: string): void;
|