@carbon/ai-chat-components 1.13.0 → 1.14.0-rc.1

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.
Files changed (206) hide show
  1. package/custom-elements.json +1147 -462
  2. package/es/components/audio-player/src/audio-player.scss.js +1 -1
  3. package/es/components/audio-player/src/transcript.js +15 -0
  4. package/es/components/audio-player/src/transcript.js.map +1 -1
  5. package/es/components/card/src/card-footer.scss.js +1 -1
  6. package/es/components/card/src/card-steps.scss.js +1 -1
  7. package/es/components/card/src/card.scss.js +1 -1
  8. package/es/components/chat-button/src/chat-button.scss.js +1 -1
  9. package/es/components/chat-history/src/chat-history.scss.js +1 -1
  10. package/es/components/chat-history/src/history-header.js +1 -0
  11. package/es/components/chat-history/src/history-header.js.map +1 -1
  12. package/es/components/chat-history/src/history-toolbar.js +4 -1
  13. package/es/components/chat-history/src/history-toolbar.js.map +1 -1
  14. package/es/components/chat-shell/src/shell.scss.js +1 -1
  15. package/es/components/code-snippet/src/code-snippet.d.ts +3 -2
  16. package/es/components/code-snippet/src/code-snippet.js +4 -3
  17. package/es/components/code-snippet/src/code-snippet.js.map +1 -1
  18. package/es/components/code-snippet/src/code-snippet.scss.js +1 -1
  19. package/es/components/feedback/src/feedback.js +17 -3
  20. package/es/components/feedback/src/feedback.js.map +1 -1
  21. package/es/components/file-uploads/src/file-upload-item.scss.js +1 -1
  22. package/es/components/file-uploads/src/file-uploads.scss.js +1 -1
  23. package/es/components/launcher/src/launcher.scss.js +1 -1
  24. package/es/components/markdown/__tests__/inline-selection-fixture.d.ts +13 -0
  25. package/es/components/markdown/index.d.ts +2 -0
  26. package/es/components/markdown/index.js +3 -0
  27. package/es/components/markdown/index.js.map +1 -1
  28. package/es/components/markdown/src/inline-markdown.d.ts +41 -0
  29. package/es/components/markdown/src/inline-markdown.js +92 -0
  30. package/es/components/markdown/src/inline-markdown.js.map +1 -0
  31. package/es/components/markdown/src/inline-markdown.scss.js +13 -0
  32. package/es/components/markdown/src/inline-markdown.scss.js.map +1 -0
  33. package/es/components/markdown/src/inline-run-projection.scss.js +13 -0
  34. package/es/components/markdown/src/inline-run-projection.scss.js.map +1 -0
  35. package/es/components/markdown/src/markdown-renderer-types.d.ts +132 -0
  36. package/es/components/markdown/src/markdown-renderer.js +131 -25
  37. package/es/components/markdown/src/markdown-renderer.js.map +1 -1
  38. package/es/components/markdown/src/markdown.js +1 -0
  39. package/es/components/markdown/src/markdown.js.map +1 -1
  40. package/es/components/markdown/src/markdown.scss.js +1 -1
  41. package/es/components/markdown/src/utils/inline-run-projection.d.ts +15 -0
  42. package/es/components/markdown/src/utils/inline-run-projection.js +196 -0
  43. package/es/components/markdown/src/utils/inline-run-projection.js.map +1 -0
  44. package/es/components/markdown/src/utils/inline-validation.d.ts +13 -0
  45. package/es/components/markdown/src/utils/inline-validation.js +97 -0
  46. package/es/components/markdown/src/utils/inline-validation.js.map +1 -0
  47. package/es/components/markdown/src/utils/plugin-fallback.js +20 -13
  48. package/es/components/markdown/src/utils/plugin-fallback.js.map +1 -1
  49. package/es/components/markdown/src/utils/plugin-host-container.d.ts +5 -6
  50. package/es/components/markdown/src/utils/plugin-host-container.js.map +1 -1
  51. package/es/components/messages-shell/index.d.ts +11 -0
  52. package/es/components/messages-shell/index.js +9 -0
  53. package/es/components/messages-shell/index.js.map +1 -0
  54. package/es/components/messages-shell/src/messages-shell.d.ts +57 -0
  55. package/es/components/messages-shell/src/messages-shell.js +141 -0
  56. package/es/components/messages-shell/src/messages-shell.js.map +1 -0
  57. package/es/components/messages-shell/src/messages-shell.scss.js +13 -0
  58. package/es/components/messages-shell/src/messages-shell.scss.js.map +1 -0
  59. package/es/components/processing/src/processing.scss.js +1 -1
  60. package/es/components/prompt-line/autocomplete/src/autocomplete.d.ts +26 -9
  61. package/es/components/prompt-line/autocomplete/src/autocomplete.js +116 -107
  62. package/es/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
  63. package/es/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
  64. package/es/components/prompt-line/src/autocomplete-controller-element.js +13 -1
  65. package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
  66. package/es/components/prompt-line/src/autocomplete-controller.js +9 -2
  67. package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
  68. package/es/components/prompt-line/src/prompt-line-controller.d.ts +7 -0
  69. package/es/components/prompt-line/src/prompt-line-rich-runtime.js +17 -0
  70. package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  71. package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
  72. package/es/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +1 -0
  73. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +3 -0
  74. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
  75. package/es/components/prompt-line/src/prompt-line.d.ts +7 -0
  76. package/es/components/prompt-line/src/prompt-line.js +9 -0
  77. package/es/components/prompt-line/src/prompt-line.js.map +1 -1
  78. package/es/components/prompt-line/src/send-control.scss.js +1 -1
  79. package/es/components/prompt-line/src/stop-streaming-button.scss.js +1 -1
  80. package/es/components/prompt-line/src/tiptap/carbon-mention.js +43 -21
  81. package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
  82. package/es/components/prompt-line/src/tiptap/plain-text-paste.js +8 -3
  83. package/es/components/prompt-line/src/tiptap/plain-text-paste.js.map +1 -1
  84. package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +3 -3
  85. package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -1
  86. package/es/components/prompt-line/src/tiptap/types.d.ts +27 -11
  87. package/es/components/reasoning-steps/src/reasoning-step.d.ts +3 -3
  88. package/es/components/reasoning-steps/src/reasoning-step.js +4 -4
  89. package/es/components/reasoning-steps/src/reasoning-step.js.map +1 -1
  90. package/es/components/reasoning-steps/src/reasoning-step.scss.js +1 -1
  91. package/es/components/reasoning-steps/src/reasoning-steps-toggle.scss.js +1 -1
  92. package/es/components/reasoning-steps/src/reasoning-steps.d.ts +5 -4
  93. package/es/components/reasoning-steps/src/reasoning-steps.js +5 -4
  94. package/es/components/reasoning-steps/src/reasoning-steps.js.map +1 -1
  95. package/es/components/truncated-text/src/truncated-text.scss.js +1 -1
  96. package/es/components/video-player/src/video-player.scss.js +1 -1
  97. package/es/globals/scss/common.scss.js +1 -1
  98. package/es/react/hooks/useChatAutocomplete.js +7 -1
  99. package/es/react/hooks/useChatAutocomplete.js.map +1 -1
  100. package/es/react/messages-shell.d.ts +3 -0
  101. package/es/react/messages-shell.js +32 -0
  102. package/es/react/messages-shell.js.map +1 -0
  103. package/es-custom/components/audio-player/src/audio-player.scss.js +1 -1
  104. package/es-custom/components/audio-player/src/transcript.js +15 -0
  105. package/es-custom/components/audio-player/src/transcript.js.map +1 -1
  106. package/es-custom/components/card/src/card-footer.scss.js +1 -1
  107. package/es-custom/components/card/src/card-steps.scss.js +1 -1
  108. package/es-custom/components/card/src/card.scss.js +1 -1
  109. package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
  110. package/es-custom/components/chat-history/src/chat-history.scss.js +1 -1
  111. package/es-custom/components/chat-history/src/history-header.js +1 -0
  112. package/es-custom/components/chat-history/src/history-header.js.map +1 -1
  113. package/es-custom/components/chat-history/src/history-toolbar.js +4 -1
  114. package/es-custom/components/chat-history/src/history-toolbar.js.map +1 -1
  115. package/es-custom/components/chat-shell/src/shell.scss.js +1 -1
  116. package/es-custom/components/code-snippet/src/code-snippet.d.ts +3 -2
  117. package/es-custom/components/code-snippet/src/code-snippet.js +4 -3
  118. package/es-custom/components/code-snippet/src/code-snippet.js.map +1 -1
  119. package/es-custom/components/code-snippet/src/code-snippet.scss.js +1 -1
  120. package/es-custom/components/feedback/src/feedback.js +17 -3
  121. package/es-custom/components/feedback/src/feedback.js.map +1 -1
  122. package/es-custom/components/file-uploads/src/file-upload-item.scss.js +1 -1
  123. package/es-custom/components/file-uploads/src/file-uploads.scss.js +1 -1
  124. package/es-custom/components/launcher/src/launcher.scss.js +1 -1
  125. package/es-custom/components/markdown/__tests__/inline-selection-fixture.d.ts +13 -0
  126. package/es-custom/components/markdown/index.d.ts +2 -0
  127. package/es-custom/components/markdown/index.js +3 -0
  128. package/es-custom/components/markdown/index.js.map +1 -1
  129. package/es-custom/components/markdown/src/inline-markdown.d.ts +41 -0
  130. package/es-custom/components/markdown/src/inline-markdown.js +92 -0
  131. package/es-custom/components/markdown/src/inline-markdown.js.map +1 -0
  132. package/es-custom/components/markdown/src/inline-markdown.scss.js +13 -0
  133. package/es-custom/components/markdown/src/inline-markdown.scss.js.map +1 -0
  134. package/es-custom/components/markdown/src/inline-run-projection.scss.js +13 -0
  135. package/es-custom/components/markdown/src/inline-run-projection.scss.js.map +1 -0
  136. package/es-custom/components/markdown/src/markdown-renderer-types.d.ts +132 -0
  137. package/es-custom/components/markdown/src/markdown-renderer.js +131 -25
  138. package/es-custom/components/markdown/src/markdown-renderer.js.map +1 -1
  139. package/es-custom/components/markdown/src/markdown.js +1 -0
  140. package/es-custom/components/markdown/src/markdown.js.map +1 -1
  141. package/es-custom/components/markdown/src/markdown.scss.js +1 -1
  142. package/es-custom/components/markdown/src/utils/inline-run-projection.d.ts +15 -0
  143. package/es-custom/components/markdown/src/utils/inline-run-projection.js +196 -0
  144. package/es-custom/components/markdown/src/utils/inline-run-projection.js.map +1 -0
  145. package/es-custom/components/markdown/src/utils/inline-validation.d.ts +13 -0
  146. package/es-custom/components/markdown/src/utils/inline-validation.js +97 -0
  147. package/es-custom/components/markdown/src/utils/inline-validation.js.map +1 -0
  148. package/es-custom/components/markdown/src/utils/plugin-fallback.js +20 -13
  149. package/es-custom/components/markdown/src/utils/plugin-fallback.js.map +1 -1
  150. package/es-custom/components/markdown/src/utils/plugin-host-container.d.ts +5 -6
  151. package/es-custom/components/markdown/src/utils/plugin-host-container.js.map +1 -1
  152. package/es-custom/components/messages-shell/index.d.ts +11 -0
  153. package/es-custom/components/messages-shell/index.js +9 -0
  154. package/es-custom/components/messages-shell/index.js.map +1 -0
  155. package/es-custom/components/messages-shell/src/messages-shell.d.ts +57 -0
  156. package/es-custom/components/messages-shell/src/messages-shell.js +141 -0
  157. package/es-custom/components/messages-shell/src/messages-shell.js.map +1 -0
  158. package/es-custom/components/messages-shell/src/messages-shell.scss.js +13 -0
  159. package/es-custom/components/messages-shell/src/messages-shell.scss.js.map +1 -0
  160. package/es-custom/components/processing/src/processing.scss.js +1 -1
  161. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.d.ts +26 -9
  162. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js +116 -107
  163. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
  164. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
  165. package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +13 -1
  166. package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
  167. package/es-custom/components/prompt-line/src/autocomplete-controller.js +9 -2
  168. package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
  169. package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +7 -0
  170. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +17 -0
  171. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  172. package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
  173. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +1 -0
  174. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +3 -0
  175. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
  176. package/es-custom/components/prompt-line/src/prompt-line.d.ts +7 -0
  177. package/es-custom/components/prompt-line/src/prompt-line.js +9 -0
  178. package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
  179. package/es-custom/components/prompt-line/src/send-control.scss.js +1 -1
  180. package/es-custom/components/prompt-line/src/stop-streaming-button.scss.js +1 -1
  181. package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +43 -21
  182. package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
  183. package/es-custom/components/prompt-line/src/tiptap/plain-text-paste.js +8 -3
  184. package/es-custom/components/prompt-line/src/tiptap/plain-text-paste.js.map +1 -1
  185. package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +3 -3
  186. package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -1
  187. package/es-custom/components/prompt-line/src/tiptap/types.d.ts +27 -11
  188. package/es-custom/components/reasoning-steps/src/reasoning-step.d.ts +3 -3
  189. package/es-custom/components/reasoning-steps/src/reasoning-step.js +4 -4
  190. package/es-custom/components/reasoning-steps/src/reasoning-step.js.map +1 -1
  191. package/es-custom/components/reasoning-steps/src/reasoning-step.scss.js +1 -1
  192. package/es-custom/components/reasoning-steps/src/reasoning-steps-toggle.scss.js +1 -1
  193. package/es-custom/components/reasoning-steps/src/reasoning-steps.d.ts +5 -4
  194. package/es-custom/components/reasoning-steps/src/reasoning-steps.js +5 -4
  195. package/es-custom/components/reasoning-steps/src/reasoning-steps.js.map +1 -1
  196. package/es-custom/components/truncated-text/src/truncated-text.scss.js +1 -1
  197. package/es-custom/components/video-player/src/video-player.scss.js +1 -1
  198. package/es-custom/globals/scss/common.scss.js +1 -1
  199. package/es-custom/react/hooks/useChatAutocomplete.js +7 -1
  200. package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
  201. package/es-custom/react/messages-shell.d.ts +3 -0
  202. package/es-custom/react/messages-shell.js +32 -0
  203. package/es-custom/react/messages-shell.js.map +1 -0
  204. package/package.json +6 -6
  205. package/scss/_markdown-inline.scss +138 -0
  206. package/telemetry.yml +4 -0
@@ -0,0 +1,41 @@
1
+ import { type TemplateResult } from 'lit';
2
+ import { type MarkdownItPlugin } from './markdown-token-tree.js';
3
+ import type { MarkdownCustomRenderers } from './markdown-renderer-types.js';
4
+ export { InlineMarkdownError } from './utils/inline-validation.js';
5
+ /**
6
+ * Styles for {@link renderInlineMarkdown} output. Install them in each root
7
+ * that renders the result.
8
+ * @category Messaging
9
+ */
10
+ export { default as inlineMarkdownStyles } from './inline-markdown.scss?lit';
11
+ /**
12
+ * Controls inline parsing, HTML filtering, and host transforms.
13
+ * @category Messaging
14
+ */
15
+ export interface InlineMarkdownOptions {
16
+ /** Filter unsafe HTML and attributes. Defaults to false. */
17
+ sanitizeHTML?: boolean;
18
+ /** Keep source HTML as escaped text. Defaults to false. */
19
+ removeHTML?: boolean;
20
+ /** Extend the shared parser. Use a new array when plugins change. */
21
+ markdownItPlugins?: MarkdownItPlugin[];
22
+ /** Transform native links and images with the block renderer's callbacks. */
23
+ customRenderers?: Pick<MarkdownCustomRenderers, 'link' | 'image'>;
24
+ /**
25
+ * Project plugin HTML through the plugin-host slot protocol. Defaults to
26
+ * false. An unclaimed slot shows the token source as fallback text. A slot
27
+ * rendered while detached checks each frame until it connects, so dispose a
28
+ * root with `setConnected(false)`.
29
+ */
30
+ projectPluginOutput?: boolean;
31
+ }
32
+ /**
33
+ * Returns a template for one inline paragraph, preserving edge spaces. Render
34
+ * it into your own root and install {@link inlineMarkdownStyles} there.
35
+ * Parsing, callbacks, and validation finish before this function returns.
36
+ *
37
+ * @throws {@link InlineMarkdownError} when the source contains blocks or the output is not inline.
38
+ * @category Messaging
39
+ */
40
+ export declare function renderInlineMarkdown(source: string, options?: InlineMarkdownOptions): TemplateResult;
41
+ export declare function renderInlineMarkdownInRun(source: string, options: InlineMarkdownOptions): TemplateResult;
@@ -0,0 +1,92 @@
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 } from 'lit';
9
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
10
+ import prefix from '../../../globals/settings.js';
11
+ import { renderTokenTree } from './markdown-renderer.js';
12
+ import { markdownToTokenTree } from './markdown-token-tree.js';
13
+ import { nextMarkdownInstanceId } from './utils/slot-names.js';
14
+ import { validateInlineTree, validateInlineAttributes, validateInlineHTML } from './utils/inline-validation.js';
15
+ export { InlineMarkdownError } from './utils/inline-validation.js';
16
+ import { projectedInlinePlugin, projectInlineRun } from './utils/inline-run-projection.js';
17
+ export { default as inlineMarkdownStyles } from './inline-markdown.scss.js';
18
+
19
+ /*
20
+ * Copyright IBM Corp. 2026
21
+ *
22
+ * This source code is licensed under the Apache-2.0 license found in the
23
+ * LICENSE file in the root directory of this source tree.
24
+ *
25
+ * @license
26
+ */
27
+ /**
28
+ * Returns a template for one inline paragraph, preserving edge spaces. Render
29
+ * it into your own root and install {@link inlineMarkdownStyles} there.
30
+ * Parsing, callbacks, and validation finish before this function returns.
31
+ *
32
+ * @throws {@link InlineMarkdownError} when the source contains blocks or the output is not inline.
33
+ * @category Messaging
34
+ */
35
+ function renderInlineMarkdown(source, options = {}) {
36
+ return renderInlineSource(source, options, false);
37
+ }
38
+ // Chat already projects the paragraph, so keep plugin markup in that live tree.
39
+ function renderInlineMarkdownInRun(source, options) {
40
+ return renderInlineSource(source, { ...options, projectPluginOutput: false }, true);
41
+ }
42
+ function renderInlineSource(source, options, markPluginOutput) {
43
+ const { tree, md } = markdownToTokenTree(source, undefined, {
44
+ removeHtml: options.removeHTML ?? false,
45
+ markdownItPlugins: options.markdownItPlugins,
46
+ });
47
+ const paragraph = validateInlineTree(tree, source);
48
+ const edgeSource = source.replace(/^[\r\n]+|[\r\n]+$/g, '');
49
+ if (!paragraph) {
50
+ const spaces = source.replace(/[\r\n]/g, '');
51
+ return spaces
52
+ ? html `<span class=${`${prefix}-inline-markdown`}>${spaces}</span>`
53
+ : html ``;
54
+ }
55
+ const namespace = nextMarkdownInstanceId();
56
+ let hasPlugin = false;
57
+ const content = renderTokenTree({ ...paragraph, token: { ...paragraph.token, tag: '', type: 'inline' } }, {
58
+ sanitize: options.sanitizeHTML ?? false,
59
+ md,
60
+ customRenderers: options.customRenderers,
61
+ inline: {
62
+ validateAttributes: validateInlineAttributes,
63
+ renderHTML: (markup, token) => {
64
+ validateInlineHTML(markup);
65
+ if (!options.projectPluginOutput || !token) {
66
+ if (markPluginOutput && token) {
67
+ return html `<span class=${`${prefix}-markdown-inline-plugin`}
68
+ >${unsafeHTML(markup)}</span
69
+ >`;
70
+ }
71
+ return html `${unsafeHTML(markup)}`;
72
+ }
73
+ hasPlugin = true;
74
+ const fallback = token.content || markup.replace(/<[^>]*>/g, '');
75
+ return html `${projectedInlinePlugin(markup, fallback)}`;
76
+ },
77
+ },
78
+ });
79
+ const leading = edgeSource.match(/^[\t ]*/)?.[0] ?? '';
80
+ const trailing = edgeSource.match(/[\t ]*$/)?.[0] ?? '';
81
+ const prepared = html `${leading}${content}${trailing}`;
82
+ const output = hasPlugin
83
+ ? projectInlineRun(prepared, {
84
+ slotName: `${prefix}-inline-markdown-plugin-${namespace}`,
85
+ resetInlineStyles: true,
86
+ })
87
+ : prepared;
88
+ return html `<span class=${`${prefix}-inline-markdown`}>${output}</span>`;
89
+ }
90
+
91
+ export { renderInlineMarkdown, renderInlineMarkdownInRun };
92
+ //# sourceMappingURL=inline-markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-markdown.js","sources":["../../../../src/components/markdown/src/inline-markdown.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, type TemplateResult } from 'lit';\nimport { unsafeHTML } from 'lit/directives/unsafe-html.js';\nimport prefix from '../../../globals/settings.js';\nimport { renderTokenTree } from './markdown-renderer.js';\nimport {\n markdownToTokenTree,\n type MarkdownItPlugin,\n} from './markdown-token-tree.js';\nimport type { MarkdownCustomRenderers } from './markdown-renderer-types.js';\nimport { nextMarkdownInstanceId } from './utils/slot-names.js';\nimport {\n validateInlineAttributes,\n validateInlineHTML,\n validateInlineTree,\n} from './utils/inline-validation.js';\nimport {\n projectInlineRun,\n projectedInlinePlugin,\n} from './utils/inline-run-projection.js';\n\nexport { InlineMarkdownError } from './utils/inline-validation.js';\n/**\n * Styles for {@link renderInlineMarkdown} output. Install them in each root\n * that renders the result.\n * @category Messaging\n */\nexport { default as inlineMarkdownStyles } from './inline-markdown.scss?lit';\n\n/**\n * Controls inline parsing, HTML filtering, and host transforms.\n * @category Messaging\n */\nexport interface InlineMarkdownOptions {\n /** Filter unsafe HTML and attributes. Defaults to false. */\n sanitizeHTML?: boolean;\n /** Keep source HTML as escaped text. Defaults to false. */\n removeHTML?: boolean;\n /** Extend the shared parser. Use a new array when plugins change. */\n markdownItPlugins?: MarkdownItPlugin[];\n /** Transform native links and images with the block renderer's callbacks. */\n customRenderers?: Pick<MarkdownCustomRenderers, 'link' | 'image'>;\n /**\n * Project plugin HTML through the plugin-host slot protocol. Defaults to\n * false. An unclaimed slot shows the token source as fallback text. A slot\n * rendered while detached checks each frame until it connects, so dispose a\n * root with `setConnected(false)`.\n */\n projectPluginOutput?: boolean;\n}\n\n/**\n * Returns a template for one inline paragraph, preserving edge spaces. Render\n * it into your own root and install {@link inlineMarkdownStyles} there.\n * Parsing, callbacks, and validation finish before this function returns.\n *\n * @throws {@link InlineMarkdownError} when the source contains blocks or the output is not inline.\n * @category Messaging\n */\nexport function renderInlineMarkdown(\n source: string,\n options: InlineMarkdownOptions = {}\n): TemplateResult {\n return renderInlineSource(source, options, false);\n}\n\n// Chat already projects the paragraph, so keep plugin markup in that live tree.\nexport function renderInlineMarkdownInRun(\n source: string,\n options: InlineMarkdownOptions\n): TemplateResult {\n return renderInlineSource(\n source,\n { ...options, projectPluginOutput: false },\n true\n );\n}\n\nfunction renderInlineSource(\n source: string,\n options: InlineMarkdownOptions,\n markPluginOutput: boolean\n): TemplateResult {\n const { tree, md } = markdownToTokenTree(source, undefined, {\n removeHtml: options.removeHTML ?? false,\n markdownItPlugins: options.markdownItPlugins,\n });\n const paragraph = validateInlineTree(tree, source);\n const edgeSource = source.replace(/^[\\r\\n]+|[\\r\\n]+$/g, '');\n if (!paragraph) {\n const spaces = source.replace(/[\\r\\n]/g, '');\n return spaces\n ? html`<span class=${`${prefix}-inline-markdown`}>${spaces}</span>`\n : html``;\n }\n const namespace = nextMarkdownInstanceId();\n let hasPlugin = false;\n const content = renderTokenTree(\n { ...paragraph, token: { ...paragraph.token, tag: '', type: 'inline' } },\n {\n sanitize: options.sanitizeHTML ?? false,\n md,\n customRenderers: options.customRenderers,\n inline: {\n validateAttributes: validateInlineAttributes,\n renderHTML: (markup, token) => {\n validateInlineHTML(markup);\n if (!options.projectPluginOutput || !token) {\n if (markPluginOutput && token) {\n return html`<span class=${`${prefix}-markdown-inline-plugin`}\n >${unsafeHTML(markup)}</span\n >`;\n }\n return html`${unsafeHTML(markup)}`;\n }\n hasPlugin = true;\n const fallback = token.content || markup.replace(/<[^>]*>/g, '');\n return html`${projectedInlinePlugin(markup, fallback)}`;\n },\n },\n }\n );\n const leading = edgeSource.match(/^[\\t ]*/)?.[0] ?? '';\n const trailing = edgeSource.match(/[\\t ]*$/)?.[0] ?? '';\n const prepared = html`${leading}${content}${trailing}`;\n const output = hasPlugin\n ? projectInlineRun(prepared, {\n slotName: `${prefix}-inline-markdown-plugin-${namespace}`,\n resetInlineStyles: true,\n })\n : prepared;\n return html`<span class=${`${prefix}-inline-markdown`}>${output}</span>`;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAoDH;;;;;;;AAOG;SACa,oBAAoB,CAClC,MAAc,EACd,UAAiC,EAAE,EAAA;IAEnC,OAAO,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;AACnD;AAEA;AACM,SAAU,yBAAyB,CACvC,MAAc,EACd,OAA8B,EAAA;AAE9B,IAAA,OAAO,kBAAkB,CACvB,MAAM,EACN,EAAE,GAAG,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,EAC1C,IAAI,CACL;AACH;AAEA,SAAS,kBAAkB,CACzB,MAAc,EACd,OAA8B,EAC9B,gBAAyB,EAAA;IAEzB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE;AAC1D,QAAA,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,KAAK;QACvC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;AAC7C,KAAA,CAAC;IACF,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC;IAClD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;IAC3D,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;AAC5C,QAAA,OAAO;cACH,IAAI,CAAA,CAAA,YAAA,EAAe,GAAG,MAAM,CAAA,gBAAA,CAAkB,CAAA,CAAA,EAAI,MAAM,CAAA,OAAA;AAC1D,cAAE,IAAI,CAAA,CAAA,CAAE;IACZ;AACA,IAAA,MAAM,SAAS,GAAG,sBAAsB,EAAE;IAC1C,IAAI,SAAS,GAAG,KAAK;IACrB,MAAM,OAAO,GAAG,eAAe,CAC7B,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EACxE;AACE,QAAA,QAAQ,EAAE,OAAO,CAAC,YAAY,IAAI,KAAK;QACvC,EAAE;QACF,eAAe,EAAE,OAAO,CAAC,eAAe;AACxC,QAAA,MAAM,EAAE;AACN,YAAA,kBAAkB,EAAE,wBAAwB;AAC5C,YAAA,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,KAAI;gBAC5B,kBAAkB,CAAC,MAAM,CAAC;gBAC1B,IAAI,CAAC,OAAO,CAAC,mBAAmB,IAAI,CAAC,KAAK,EAAE;AAC1C,oBAAA,IAAI,gBAAgB,IAAI,KAAK,EAAE;AAC7B,wBAAA,OAAO,IAAI,CAAA,CAAA,YAAA,EAAe,CAAA,EAAG,MAAM,CAAA,uBAAA,CAAyB;mBACvD,UAAU,CAAC,MAAM,CAAC,CAAA;gBACrB;oBACJ;oBACA,OAAO,IAAI,CAAA,CAAA,EAAG,UAAU,CAAC,MAAM,CAAC,EAAE;gBACpC;gBACA,SAAS,GAAG,IAAI;AAChB,gBAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;gBAChE,OAAO,IAAI,CAAA,CAAA,EAAG,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA,CAAE;YACzD,CAAC;AACF,SAAA;AACF,KAAA,CACF;AACD,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;AACtD,IAAA,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;IACvD,MAAM,QAAQ,GAAG,IAAI,CAAA,CAAA,EAAG,OAAO,CAAA,EAAG,OAAO,CAAA,EAAG,QAAQ,CAAA,CAAE;IACtD,MAAM,MAAM,GAAG;AACb,UAAE,gBAAgB,CAAC,QAAQ,EAAE;AACzB,YAAA,QAAQ,EAAE,CAAA,EAAG,MAAM,CAAA,wBAAA,EAA2B,SAAS,CAAA,CAAE;AACzD,YAAA,iBAAiB,EAAE,IAAI;SACxB;UACD,QAAQ;IACZ,OAAO,IAAI,CAAA,CAAA,YAAA,EAAe,CAAA,EAAG,MAAM,CAAA,gBAAA,CAAkB,CAAA,CAAA,EAAI,MAAM,CAAA,OAAA,CAAS;AAC1E;;"}
@@ -0,0 +1,13 @@
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 { css } from 'lit';
9
+
10
+ var inlineMarkdown = css([".cds-custom-aichat-inline-markdown{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)}.cds-custom-aichat-inline-markdown :where(a,abbr,b,code,del,em,i,img,ins,kbd,mark,q,s,samp,small,span,strong,sub,sup,u,var){border:0;font:inherit;font-size:1em;margin:0;padding:0;vertical-align:baseline}.cds-custom-aichat-inline-markdown mark{background-color:var(--cds-highlight,#d0e2ff);border-radius:.25rem;color:var(--cds-text-primary,#161616)}.cds-custom-aichat-inline-markdown b,.cds-custom-aichat-inline-markdown strong{font-weight:700}.cds-custom-aichat-inline-markdown em,.cds-custom-aichat-inline-markdown i{font-style:italic}.cds-custom-aichat-inline-markdown a{color:var(--cds-link-primary,#0f62fe);outline:none;text-decoration:none}@media (prefers-reduced-motion:no-preference){.cds-custom-aichat-inline-markdown a{transition:color motion(standard,productive) 70ms}}.cds-custom-aichat-inline-markdown a:hover{color:var(--cds-link-primary-hover,#0043ce);text-decoration:underline}.cds-custom-aichat-inline-markdown a:focus{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-inline-markdown a:focus{outline-style:dotted}}.cds-custom-aichat-inline-markdown a:focus{outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-inline-markdown a:visited{color:var(--cds-link-primary,#0f62fe)}.cds-custom-aichat-inline-markdown a:active{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-inline-markdown a:active{outline-style:dotted}}.cds-custom-aichat-inline-markdown a:active{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-inline-markdown a:visited:hover{color:var(--cds-link-primary-hover,#0043ce)}.cds-custom-aichat-inline-markdown a:active:visited,.cds-custom-aichat-inline-markdown a:active:visited:hover{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-inline-markdown a:active:visited,.cds-custom-aichat-inline-markdown a:active:visited:hover{outline-style:dotted}}.cds-custom-aichat-inline-markdown a:active:visited,.cds-custom-aichat-inline-markdown a:active:visited:hover{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-inline-markdown img{max-inline-size:100%}"]);
11
+
12
+ export { inlineMarkdown as default };
13
+ //# sourceMappingURL=inline-markdown.scss.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-markdown.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,13 @@
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 { css } from 'lit';
9
+
10
+ var styles = css([".cds-custom-aichat-markdown-inline-run mark:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){background-color:var(--cds-highlight,#d0e2ff);border-radius:.25rem;color:var(--cds-text-primary,#161616)}.cds-custom-aichat-markdown-inline-run b:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)),.cds-custom-aichat-markdown-inline-run strong:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){font-weight:700}.cds-custom-aichat-markdown-inline-run em:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)),.cds-custom-aichat-markdown-inline-run i:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){font-style:italic}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){color:var(--cds-link-primary,#0f62fe);outline:none;text-decoration:none}@media (prefers-reduced-motion:no-preference){.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){transition:color motion(standard,productive) 70ms}}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):hover{color:var(--cds-link-primary-hover,#0043ce);text-decoration:underline}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):visited{color:var(--cds-link-primary,#0f62fe)}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):visited:hover{color:var(--cds-link-primary-hover,#0043ce)}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run img:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){max-inline-size:100%}.cds-custom-aichat-markdown-inline-run--reset{font:inherit}.cds-custom-aichat-markdown-inline-run--reset :where(a,abbr,b,code,del,em,i,img,ins,kbd,mark,q,s,samp,small,span,strong,sub,sup,u,var):not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){border:0;font:inherit;font-size:1em;margin:0;padding:0;vertical-align:baseline}.cds-custom-aichat-markdown-inline-run--reset mark:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){background-color:var(--cds-highlight,#d0e2ff);border-radius:.25rem;color:var(--cds-text-primary,#161616)}.cds-custom-aichat-markdown-inline-run--reset b:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)),.cds-custom-aichat-markdown-inline-run--reset strong:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){font-weight:700}.cds-custom-aichat-markdown-inline-run--reset em:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)),.cds-custom-aichat-markdown-inline-run--reset i:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){font-style:italic}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){color:var(--cds-link-primary,#0f62fe);outline:none;text-decoration:none}@media (prefers-reduced-motion:no-preference){.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){transition:color motion(standard,productive) 70ms}}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):hover{color:var(--cds-link-primary-hover,#0043ce);text-decoration:underline}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):focus{outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):visited{color:var(--cds-link-primary,#0f62fe)}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):visited:hover{color:var(--cds-link-primary-hover,#0043ce)}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{outline:1px solid var(--cds-focus,#0f62fe)}@media screen and (prefers-contrast){.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{outline-style:dotted}}.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited,.cds-custom-aichat-markdown-inline-run--reset a:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)):active:visited:hover{color:var(--cds-link-primary,#0f62fe);outline-color:var(--cds-focus,#0f62fe);text-decoration:underline}.cds-custom-aichat-markdown-inline-run--reset img:not(:where(.cds-custom-aichat-markdown-inline-plugin,.cds-custom-aichat-markdown-inline-plugin *)){max-inline-size:100%}.cds-custom-aichat-markdown-inline-run{font:inherit}"]);
11
+
12
+ export { styles as default };
13
+ //# sourceMappingURL=inline-run-projection.scss.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-run-projection.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -1,5 +1,8 @@
1
+ import type MarkdownIt from 'markdown-it';
2
+ import type { TemplateResult } from 'lit';
1
3
  import type { Token } from 'markdown-it';
2
4
  import type { TableCellData } from './utils/table-helpers.js';
5
+ import type { TokenTree } from './markdown-token-tree.js';
3
6
  /**
4
7
  * Data payload describing a markdown table the consumer can render in place
5
8
  * of the default `cds-custom-aichat-table`.
@@ -261,3 +264,132 @@ export interface MarkdownCustomRenderers {
261
264
  */
262
265
  checklist?: MarkdownRendererChecklist;
263
266
  }
267
+ /**
268
+ * Internal descriptor produced by the renderer for each custom-renderable
269
+ * element it encounters. Consumed by the markdown element's `updated()`
270
+ * reconcile, not part of the public component API. Its declaration is retained
271
+ * because the renderer's exported signatures reference it.
272
+ *
273
+ * @hidden
274
+ */
275
+ export type MarkdownRendererSlotDescriptor = {
276
+ slotName: string;
277
+ kind: 'table';
278
+ token: Readonly<Token>;
279
+ data: MarkdownRendererTableData;
280
+ } | {
281
+ slotName: string;
282
+ kind: 'codeBlock';
283
+ token: Readonly<Token>;
284
+ data: MarkdownRendererCodeBlockData;
285
+ } | {
286
+ slotName: string;
287
+ kind: 'pluginFallback';
288
+ token: Readonly<Token>;
289
+ /**
290
+ * Sanitized HTML produced by the user plugin's renderer rule. The
291
+ * markdown element assigns this to a light-DOM slot host's `innerHTML`
292
+ * (skipping the write when it hasn't changed) so consumer-supplied
293
+ * CSS reaches the rendered output.
294
+ */
295
+ html: string;
296
+ /**
297
+ * True when the matched markdown-it `token.block === false` (an inline
298
+ * token like `math_inline`). The reconciler uses this to pick `<span>`
299
+ * vs `<div>` for the slot host so inline plugin output doesn't break
300
+ * paragraph flow. Carried on the descriptor so listeners outside the
301
+ * markdown element (the chat container's host-mount handler) can make
302
+ * the same decision without re-inspecting the token.
303
+ */
304
+ isInline: boolean;
305
+ };
306
+ /**
307
+ * Internal configuration passed to the renderer, not part of the public
308
+ * component API. Its declaration is retained for exported renderer signatures.
309
+ *
310
+ * @hidden
311
+ */
312
+ export interface RenderTokenTreeOptions {
313
+ /** Local light-DOM mount when no ancestor claims a projected inline run. */
314
+ projectionHost?: HTMLElement;
315
+ /** Prepared inline runs reused when Lit commits the same render again. */
316
+ preparedInlineRuns?: WeakMap<TokenTree, TemplateResult>;
317
+ /** Eager output preparation for a caller-owned inline root. */
318
+ inline?: {
319
+ validateAttributes: (attributes: Record<string, string>) => void;
320
+ renderHTML: (html: string, pluginToken?: Token) => TemplateResult;
321
+ };
322
+ /** Whether to sanitize HTML content using DOMPurify. */
323
+ sanitize: boolean;
324
+ /** Whether content is being streamed (affects loading states). */
325
+ streaming?: boolean;
326
+ /** Context information for nested rendering. */
327
+ context?: {
328
+ /** Whether we're currently inside a table header. */
329
+ isInThead?: boolean;
330
+ /** All children of the parent node. */
331
+ parentChildren?: TokenTree[];
332
+ /** Current index in parent's children array. */
333
+ currentIndex?: number;
334
+ };
335
+ /** Whether to enable syntax highlighting in code blocks. */
336
+ codeSnippetHighlight?: boolean;
337
+ /** Feedback text shown after copying. */
338
+ codeSnippetFeedback?: string;
339
+ /** Text for show less button. */
340
+ codeSnippetShowLessText?: string;
341
+ /** Text for show more button. */
342
+ codeSnippetShowMoreText?: string;
343
+ /** Tooltip text for copy button. */
344
+ codeSnippetCopyButtonTooltipContent?: string;
345
+ /** Function to get formatted line count text. */
346
+ codeSnippetGetLineCountText?: ({ count }: {
347
+ count: number;
348
+ }) => string;
349
+ /** Aria-label for code snippets when in read-only mode. */
350
+ codeSnippetAriaLabelReadOnly?: string;
351
+ /** Aria-label for code snippets when in editable mode. */
352
+ codeSnippetAriaLabelEditable?: string;
353
+ /** Placeholder text for table filter input. */
354
+ tableFilterPlaceholderText?: string;
355
+ /** Text for previous page button tooltip. */
356
+ tablePreviousPageText?: string;
357
+ /** Text for next page button tooltip. */
358
+ tableNextPageText?: string;
359
+ /** Text for items per page label. */
360
+ tableItemsPerPageText?: string;
361
+ /** The text used for the download button's accessible label. */
362
+ tableDownloadLabelText?: string;
363
+ /** Locale for table sorting and formatting. */
364
+ tableLocale?: string;
365
+ /** Function to get supplemental pagination text. */
366
+ tableGetPaginationSupplementalText?: ({ count }: {
367
+ count: number;
368
+ }) => string;
369
+ /** Function to get pagination status text. */
370
+ tableGetPaginationStatusText?: ({ start, end, count, }: {
371
+ start: number;
372
+ end: number;
373
+ count: number;
374
+ }) => string;
375
+ /**
376
+ * Force markdown tables to render in loading mode. Useful for freezing
377
+ * streaming table visuals until stream completion.
378
+ */
379
+ forceTableLoading?: boolean;
380
+ /**
381
+ * Consumer-supplied callbacks. For `table`/`codeBlock` a present callback
382
+ * causes the renderer to emit a named `<slot>` placeholder for that kind,
383
+ * invoked later by the markdown element's `updated()` lifecycle. `link` and
384
+ * `image` callbacks run synchronously during the render pass (attribute
385
+ * transforms, no slot); `checklist` wires a toggle listener on the element.
386
+ */
387
+ customRenderers?: MarkdownCustomRenderers;
388
+ /**
389
+ * The markdown-it instance that produced the current token tree. Required
390
+ * for the unknown-token fallback (`md.renderer.render()` for
391
+ * plugin-introduced tokens). When omitted, unknown tokens fall through to a
392
+ * `<div>` default.
393
+ */
394
+ md?: MarkdownIt;
395
+ }
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import DOMPurify from 'dompurify';
9
+ import { InlineMarkdownError } from './utils/inline-validation.js';
9
10
  import { html } from 'lit';
10
11
  import { repeat } from 'lit/directives/repeat.js';
11
12
  import { unsafeHTML } from 'lit/directives/unsafe-html.js';
@@ -19,8 +20,9 @@ import '../../card/src/card-steps.js';
19
20
  import '../../table/src/table.js';
20
21
  import { defaultLineCountText } from '../../code-snippet/src/formatters.js';
21
22
  import { renderTable } from './utils/table-helpers.js';
23
+ import { projectInlineRun, projectedInlinePlugin } from './utils/inline-run-projection.js';
22
24
  import { combineConsecutiveHtmlInline, combineSplitHtmlBlocks } from './utils/html-helpers.js';
23
- import { sanitizeHtmlContent, htmlContainer, spread } from './utils/lit-directives.js';
25
+ import { htmlContainer, sanitizeHtmlContent, spread } from './utils/lit-directives.js';
24
26
  import { shouldDelegateToPluginRule, renderFallback, isNativelyHandled } from './utils/plugin-fallback.js';
25
27
  import { withInstanceNamespace, MARKDOWN_SLOT_PREFIX } from './utils/slot-names.js';
26
28
 
@@ -95,6 +97,16 @@ function extractText(node) {
95
97
  }
96
98
  function renderChildTokenTrees(children, options, childContext) {
97
99
  const normalizedChildren = combineConsecutiveHtmlInline(combineSplitHtmlBlocks(children));
100
+ if (options.inline) {
101
+ return html `${normalizedChildren.map((child, index) => renderInlineChild(child, {
102
+ ...options,
103
+ context: {
104
+ ...childContext,
105
+ parentChildren: normalizedChildren,
106
+ currentIndex: index,
107
+ },
108
+ }))}`;
109
+ }
98
110
  // Multiple or complex children: use repeat for stable keying
99
111
  return html `${repeat(normalizedChildren, (child, index) => {
100
112
  // Key by start line + type + tag rather than array index so blocks keep
@@ -122,6 +134,114 @@ function renderChildTokenTrees(children, options, childContext) {
122
134
  return result ?? html ``;
123
135
  })}`;
124
136
  }
137
+ /**
138
+ * An inline child that a plugin owns renders through the plugin's rule alone.
139
+ * Rendering its subtree first would run host callbacks for output the plugin
140
+ * then discards.
141
+ */
142
+ function renderInlineChild(child, options) {
143
+ if (options.md && !isNativelyHandled(child.token)) {
144
+ return renderFallback(child.token, child, options.md, options.sanitize, options);
145
+ }
146
+ return renderTokenTree(child, options);
147
+ }
148
+ function renderHTMLString(content, options) {
149
+ return options.inline
150
+ ? options.inline.renderHTML(content)
151
+ : html `${unsafeHTML(content)}`;
152
+ }
153
+ function renderRawHTML(node, options) {
154
+ const { token } = node;
155
+ const { sanitize } = options;
156
+ // Plugin-overridden html_block rules (rare but supported) — route through
157
+ // the plugin's renderer before our default unsafeHTML pass-through.
158
+ if (token.type === 'html_block' &&
159
+ shouldDelegateToPluginRule(token, options.md) &&
160
+ options.md) {
161
+ return renderFallback(token, node, options.md, sanitize, options);
162
+ }
163
+ let content = token.content || '';
164
+ // Apply HTML sanitization if requested
165
+ if (sanitize && content) {
166
+ content = sanitizeHtmlContent(content);
167
+ }
168
+ return renderHTMLString(content, options);
169
+ }
170
+ function containsInlinePlugin(node, options) {
171
+ if (!options.md || (node.token.block && node.token.type !== 'inline')) {
172
+ return false;
173
+ }
174
+ if (!isNativelyHandled(node.token)) {
175
+ return true;
176
+ }
177
+ if (shouldDelegateToPluginRule(node.token, options.md) &&
178
+ !(node.token.tag === 'img' && options.customRenderers?.image)) {
179
+ return true;
180
+ }
181
+ return node.children.some((child) => containsInlinePlugin(child, options));
182
+ }
183
+ function canProjectInlineRun({ token, children }) {
184
+ if ((token.block && token.type !== 'inline') ||
185
+ token.tag?.includes('-') ||
186
+ ['input', 'button', 'select', 'textarea'].includes(token.tag ?? '') ||
187
+ ['html_inline', 'html_block', 'html_container'].includes(token.type ?? '')) {
188
+ return false;
189
+ }
190
+ return children.every(canProjectInlineRun);
191
+ }
192
+ function shouldProjectInlineRun(node, options) {
193
+ return (node.token.type === 'inline' &&
194
+ !options.inline &&
195
+ canProjectInlineRun(node) &&
196
+ containsInlinePlugin(node, options));
197
+ }
198
+ function renderProjectedInlineRun(node, options) {
199
+ const cached = options.preparedInlineRuns?.get(node);
200
+ if (cached) {
201
+ return cached;
202
+ }
203
+ let hasPlugin = false;
204
+ const content = renderChildTokenTrees(node.children, {
205
+ ...options,
206
+ inline: {
207
+ validateAttributes: () => { },
208
+ renderHTML: (markup, pluginToken) => {
209
+ if (!pluginToken) {
210
+ return html `${unsafeHTML(markup)}`;
211
+ }
212
+ hasPlugin = true;
213
+ return html `${projectedInlinePlugin(markup, pluginToken.content || markup.replace(/<[^>]*>/g, ''))}`;
214
+ },
215
+ },
216
+ }, options.context);
217
+ const index = options.pluginSlotCounter?.next(node) ?? 0;
218
+ const slotName = withInstanceNamespace(`${MARKDOWN_SLOT_PREFIX}-pluginFallback-${index}`, options);
219
+ const result = hasPlugin
220
+ ? projectInlineRun(content, {
221
+ slotName,
222
+ fallbackHost: options.projectionHost,
223
+ resetInlineStyles: true,
224
+ })
225
+ : content;
226
+ options.preparedInlineRuns?.set(node, result);
227
+ return result;
228
+ }
229
+ /** The token's attributes as an object, sanitized and checked as requested. */
230
+ function resolveAttrs(token, options) {
231
+ const rawAttrs = Object.fromEntries(token.attrs || []);
232
+ const isCustomElement = !!token.tag && token.tag.includes('-');
233
+ const attrs = options.sanitize && !isCustomElement ? sanitizeAttrs(rawAttrs) : rawAttrs;
234
+ validateInlineAttributes(attrs, options);
235
+ return attrs;
236
+ }
237
+ function validateInlineAttributes(attrs, options) {
238
+ options.inline?.validateAttributes(attrs);
239
+ }
240
+ function rejectInlineBlock(tag, options) {
241
+ if (options.inline) {
242
+ throw new InlineMarkdownError('non-inline-output', `renderInlineMarkdown cannot render the native token tag "${tag}" inline.`);
243
+ }
244
+ }
125
245
  /**
126
246
  * Top-level entry: renders a markdown token tree to a Lit `TemplateResult`
127
247
  * and returns the batch of custom-renderer slot descriptors collected along
@@ -141,6 +261,7 @@ function renderMarkdownTree(node, options) {
141
261
  const pluginSlotIndexes = new WeakMap();
142
262
  const template = renderTokenTree(node, {
143
263
  ...options,
264
+ preparedInlineRuns: new WeakMap(),
144
265
  recordCustomRender: (descriptor) => batch.push(descriptor),
145
266
  pluginSlotCounter: {
146
267
  next: (forNode) => {
@@ -165,21 +286,13 @@ function renderMarkdownTree(node, options) {
165
286
  function renderTokenTree(node, options) {
166
287
  const { token, children } = node;
167
288
  const { context, sanitize } = options;
289
+ // Keep adjacent native text and plugin output in one DOM selection tree.
290
+ if (shouldProjectInlineRun(node, options)) {
291
+ return renderProjectedInlineRun(node, options);
292
+ }
168
293
  // Handle raw HTML blocks and inline HTML
169
294
  if (token.type === 'html_block' || token.type === 'html_inline') {
170
- // Plugin-overridden html_block rules (rare but supported) — route through
171
- // the plugin's renderer before our default unsafeHTML pass-through.
172
- if (token.type === 'html_block' &&
173
- shouldDelegateToPluginRule(token, options.md) &&
174
- options.md) {
175
- return renderFallback(token, node, options.md, sanitize, options);
176
- }
177
- let content = token.content || '';
178
- // Apply HTML sanitization if requested
179
- if (sanitize && content) {
180
- content = sanitizeHtmlContent(content);
181
- }
182
- return html `${unsafeHTML(content)}`;
295
+ return renderRawHTML(node, options);
183
296
  }
184
297
  // Handle split HTML blocks that wrap markdown siblings (e.g. <details>…</details>).
185
298
  if (token.type === 'html_container') {
@@ -251,17 +364,7 @@ function renderTokenTree(node, options) {
251
364
  }
252
365
  // Handle structural elements (paragraphs, headings, lists, etc.)
253
366
  const tag = token.tag;
254
- // Convert markdown-it attributes (array of [key, value]) into an object.
255
- const rawAttrs = (token.attrs || []).reduce((acc, [key, value]) => {
256
- acc[key] = value;
257
- return acc;
258
- }, {});
259
- // Apply attribute sanitization if requested
260
- let attrs = rawAttrs;
261
- const isCustomElement = !!token.tag && token.tag.includes('-');
262
- if (sanitize && !isCustomElement) {
263
- attrs = sanitizeAttrs(rawAttrs);
264
- }
367
+ const attrs = resolveAttrs(token, options);
265
368
  // Set up context for child rendering
266
369
  let childContext = context;
267
370
  if (tag === 'thead') {
@@ -473,6 +576,7 @@ function renderWithStaticTag(tag, token, content, attrs, options, _context, node
473
576
  onClickHandler = result.onClick;
474
577
  }
475
578
  }
579
+ validateInlineAttributes(linkAttrs, options);
476
580
  return html `<a ${spread(linkAttrs)} @click=${onClickHandler}
477
581
  >${content}</a
478
582
  >`;
@@ -501,6 +605,7 @@ function renderWithStaticTag(tag, token, content, attrs, options, _context, node
501
605
  imgAttrs = sanitizeAttrs(imgAttrs);
502
606
  }
503
607
  }
608
+ validateInlineAttributes(imgAttrs, options);
504
609
  return html `<img ${spread(imgAttrs)} />`;
505
610
  }
506
611
  if (node && options.md && shouldDelegateToPluginRule(token, options.md)) {
@@ -526,6 +631,7 @@ function renderWithStaticTag(tag, token, content, attrs, options, _context, node
526
631
  if (options.md && node && !isNativelyHandled(token)) {
527
632
  return renderFallback(token, node, options.md, options.sanitize, options);
528
633
  }
634
+ rejectInlineBlock(tag, options);
529
635
  return html `<div ${spread(attrs)}>${content}</div>`;
530
636
  }
531
637
  }