orbitchat 3.3.7 → 3.4.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.
Files changed (70) hide show
  1. package/dist/assets/{ChartRenderer-CMTtwa7N.js → ChartRenderer-f1NX6EiP.js} +2 -2
  2. package/dist/assets/{MermaidRenderer-BGfEn-8D.js → MermaidRenderer-CIRXKrUW.js} +6 -6
  3. package/dist/assets/{MusicRenderer-uD3cRUDk.js → MusicRenderer-5IBeIdNL.js} +2 -2
  4. package/dist/assets/{SVGRenderer-DplZ-T1R.js → SVGRenderer-5N8JnME6.js} +1 -1
  5. package/dist/assets/{_basePickBy-CuF4aLpO.js → _basePickBy-DILSsB_e.js} +1 -1
  6. package/dist/assets/{_baseUniq--aFebvuG.js → _baseUniq-4bbGVp76.js} +1 -1
  7. package/dist/assets/{architectureDiagram-VXUJARFQ-CP0xy9PB.js → architectureDiagram-VXUJARFQ-eS3oy19C.js} +1 -1
  8. package/dist/assets/{blockDiagram-VD42YOAC-DaIhCiLV.js → blockDiagram-VD42YOAC-CgMmA0Ue.js} +1 -1
  9. package/dist/assets/{c4Diagram-YG6GDRKO-BmluaJaJ.js → c4Diagram-YG6GDRKO-BsfOyrLR.js} +1 -1
  10. package/dist/assets/channel-B3fOlVXE.js +1 -0
  11. package/dist/assets/{chunk-4BX2VUAB-DHplKZMr.js → chunk-4BX2VUAB-BKhu7quX.js} +1 -1
  12. package/dist/assets/{chunk-55IACEB6-B987CK5e.js → chunk-55IACEB6-BgUfPqoK.js} +1 -1
  13. package/dist/assets/{chunk-B4BG7PRW-BUOgJwMo.js → chunk-B4BG7PRW-DpVrA_ZB.js} +1 -1
  14. package/dist/assets/{chunk-DI55MBZ5-B0C8oW6f.js → chunk-DI55MBZ5-B44ONHRe.js} +1 -1
  15. package/dist/assets/{chunk-FMBD7UC4-BC2UA48D.js → chunk-FMBD7UC4-d-tt_p3A.js} +1 -1
  16. package/dist/assets/{chunk-QN33PNHL-BRQejh6g.js → chunk-QN33PNHL-BE0U4yBJ.js} +1 -1
  17. package/dist/assets/{chunk-QZHKN3VN-CcTE2T0U.js → chunk-QZHKN3VN-JmmqQWka.js} +1 -1
  18. package/dist/assets/{chunk-TZMSLE5B-D6s8s4Wd.js → chunk-TZMSLE5B-D7in22Ny.js} +1 -1
  19. package/dist/assets/classDiagram-2ON5EDUG-DeTrhMN7.js +1 -0
  20. package/dist/assets/classDiagram-v2-WZHVMYZB-DeTrhMN7.js +1 -0
  21. package/dist/assets/clone-pNtiM7wR.js +1 -0
  22. package/dist/assets/{cose-bilkent-S5V4N54A-DaFuCEww.js → cose-bilkent-S5V4N54A-CP8SWrs7.js} +1 -1
  23. package/dist/assets/{dagre-6UL2VRFP-P24bz3q4.js → dagre-6UL2VRFP-DdpYz4eU.js} +1 -1
  24. package/dist/assets/{diagram-PSM6KHXK-DcWwAWn6.js → diagram-PSM6KHXK-CwdCgT3a.js} +1 -1
  25. package/dist/assets/{diagram-QEK2KX5R-C8qX_ZIc.js → diagram-QEK2KX5R-BRLirpQY.js} +1 -1
  26. package/dist/assets/{diagram-S2PKOQOG-y95jPlcA.js → diagram-S2PKOQOG-nr9C1pGv.js} +1 -1
  27. package/dist/assets/{erDiagram-Q2GNP2WA-BvR9Urxi.js → erDiagram-Q2GNP2WA-BQIeXFNJ.js} +1 -1
  28. package/dist/assets/{flowDiagram-NV44I4VS-RNumyFUb.js → flowDiagram-NV44I4VS-ChHiFQ37.js} +1 -1
  29. package/dist/assets/{ganttDiagram-JELNMOA3-BVSoY-AD.js → ganttDiagram-JELNMOA3-CrRAOx2L.js} +1 -1
  30. package/dist/assets/{gitGraphDiagram-V2S2FVAM-AToARZ8f.js → gitGraphDiagram-V2S2FVAM-DmTUGcrW.js} +1 -1
  31. package/dist/assets/{graph-B-xnjVJs.js → graph-DjPD_bIk.js} +1 -1
  32. package/dist/assets/{index-B_VkYlLj.js → index-D_smRcdi.js} +1 -1
  33. package/dist/assets/index-Dj2F_Aiy.css +1 -0
  34. package/dist/assets/{index-Di0lu2HX.js → index-Ds9gSdPm.js} +109 -115
  35. package/dist/assets/{infoDiagram-HS3SLOUP-THYRKFe_.js → infoDiagram-HS3SLOUP-CLeOJpnJ.js} +1 -1
  36. package/dist/assets/{journeyDiagram-XKPGCS4Q-BdNAwEyo.js → journeyDiagram-XKPGCS4Q-rQ891sAH.js} +1 -1
  37. package/dist/assets/{kanban-definition-3W4ZIXB7-kTWYIPgb.js → kanban-definition-3W4ZIXB7-DAeNInkK.js} +1 -1
  38. package/dist/assets/{layout-BXrjXjwv.js → layout-BS0Sgtez.js} +1 -1
  39. package/dist/assets/{mindmap-definition-VGOIOE7T-D96JPac9.js → mindmap-definition-VGOIOE7T-BUNcHei6.js} +1 -1
  40. package/dist/assets/{pieDiagram-ADFJNKIX-Bnl7fLkl.js → pieDiagram-ADFJNKIX-DPsO9TW-.js} +1 -1
  41. package/dist/assets/{quadrantDiagram-AYHSOK5B-D6vKP45f.js → quadrantDiagram-AYHSOK5B-kZZSJ2T2.js} +1 -1
  42. package/dist/assets/{requirementDiagram-UZGBJVZJ-m7mIoHxU.js → requirementDiagram-UZGBJVZJ-SNCvW_SH.js} +1 -1
  43. package/dist/assets/{sankeyDiagram-TZEHDZUN-CRN5DvQ5.js → sankeyDiagram-TZEHDZUN-B_wuKnke.js} +1 -1
  44. package/dist/assets/{sequenceDiagram-WL72ISMW-C30iDcKx.js → sequenceDiagram-WL72ISMW-BOFPTCnf.js} +1 -1
  45. package/dist/assets/{stateDiagram-FKZM4ZOC-BDW55C7L.js → stateDiagram-FKZM4ZOC-D7mkcmix.js} +1 -1
  46. package/dist/assets/stateDiagram-v2-4FDKWEC3-BkijA-km.js +1 -0
  47. package/dist/assets/{timeline-definition-IT6M3QCI-DsLmL9-l.js → timeline-definition-IT6M3QCI-BTODA6yn.js} +1 -1
  48. package/dist/assets/treemap-GDKQZRPO-D_T4Lq-5.js +160 -0
  49. package/dist/assets/{xychartDiagram-PRI3JC2R-v2U7nKNz.js → xychartDiagram-PRI3JC2R-Da89GqP0.js} +1 -1
  50. package/dist/index.html +2 -2
  51. package/package.json +1 -9
  52. package/dist/assets/channel-D122_0gd.js +0 -1
  53. package/dist/assets/classDiagram-2ON5EDUG-D6BaYtGK.js +0 -1
  54. package/dist/assets/classDiagram-v2-WZHVMYZB-D6BaYtGK.js +0 -1
  55. package/dist/assets/clone-DOP8--JF.js +0 -1
  56. package/dist/assets/index-Baf0NBsK.css +0 -1
  57. package/dist/assets/stateDiagram-v2-4FDKWEC3-U8mFO6E0.js +0 -1
  58. package/dist/assets/treemap-GDKQZRPO-DpWJGyRd.js +0 -160
  59. package/markdown-renderer/LICENSE +0 -201
  60. package/markdown-renderer/src/CodeBlock.tsx +0 -332
  61. package/markdown-renderer/src/MarkdownComponents.tsx +0 -233
  62. package/markdown-renderer/src/MarkdownStyles.css +0 -732
  63. package/markdown-renderer/src/css.d.ts +0 -4
  64. package/markdown-renderer/src/index.ts +0 -32
  65. package/markdown-renderer/src/preprocessing.ts +0 -519
  66. package/markdown-renderer/src/renderers/ChartRenderer.tsx +0 -1464
  67. package/markdown-renderer/src/renderers/MermaidRenderer.tsx +0 -474
  68. package/markdown-renderer/src/renderers/MusicRenderer.tsx +0 -394
  69. package/markdown-renderer/src/renderers/SVGRenderer.tsx +0 -307
  70. package/markdown-renderer/src/types.ts +0 -174
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
@@ -1,332 +0,0 @@
1
- import React, { Suspense, lazy, useState, useEffect, useRef } from 'react';
2
- import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
3
- import { vscDarkPlus, vs } from 'react-syntax-highlighter/dist/esm/styles/prism';
4
- import type { CodeBlockProps } from './types';
5
-
6
- type ThemeMode = 'light' | 'dark';
7
-
8
- const MermaidRenderer = lazy(() =>
9
- import('./renderers/MermaidRenderer').then((module) => ({ default: module.MermaidRenderer }))
10
- );
11
- const SVGRenderer = lazy(() =>
12
- import('./renderers/SVGRenderer').then((module) => ({ default: module.SVGRenderer }))
13
- );
14
- const ChartRenderer = lazy(() =>
15
- import('./renderers/ChartRenderer').then((module) => ({ default: module.ChartRenderer }))
16
- );
17
- const MusicRenderer = lazy(() =>
18
- import('./renderers/MusicRenderer').then((module) => ({ default: module.MusicRenderer }))
19
- );
20
-
21
- // Detect theme from element context (parent classes, data attributes, or system preference)
22
- const detectTheme = (element: HTMLElement | null): ThemeMode => {
23
- if (!element) {
24
- // Fallback to system preference
25
- if (typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches) {
26
- return 'dark';
27
- }
28
- return 'light';
29
- }
30
-
31
- // Check for explicit .light or .dark class on .markdown-content
32
- const markdownContent = element.closest('.markdown-content');
33
- if (markdownContent) {
34
- if (markdownContent.classList.contains('dark')) return 'dark';
35
- if (markdownContent.classList.contains('light')) return 'light';
36
- }
37
-
38
- // Check for .dark or .light class on any ancestor
39
- if (element.closest('.dark')) return 'dark';
40
- if (element.closest('.light')) return 'light';
41
-
42
- // Check for data-theme attribute on any ancestor
43
- const themedAncestor = element.closest('[data-theme]');
44
- if (themedAncestor) {
45
- const dataTheme = themedAncestor.getAttribute('data-theme');
46
- if (dataTheme === 'dark') return 'dark';
47
- if (dataTheme === 'light') return 'light';
48
- }
49
-
50
- // Fallback to system preference
51
- if (typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches) {
52
- return 'dark';
53
- }
54
-
55
- return 'light';
56
- };
57
-
58
- const useEffectiveTheme = (
59
- ref: React.RefObject<HTMLElement | null>,
60
- explicitTheme?: ThemeMode
61
- ): ThemeMode => {
62
- const [detectedTheme, setDetectedTheme] = useState<ThemeMode>('light');
63
- const lastThemeRef = useRef<ThemeMode>('light');
64
-
65
- useEffect(() => {
66
- if (explicitTheme) {
67
- return;
68
- }
69
-
70
- if (typeof window === 'undefined' || typeof document === 'undefined') {
71
- return;
72
- }
73
-
74
- const updateTheme = () => {
75
- const newTheme = detectTheme(ref.current);
76
- // Only update if theme actually changed to prevent re-render loops
77
- if (newTheme !== lastThemeRef.current) {
78
- lastThemeRef.current = newTheme;
79
- setDetectedTheme(newTheme);
80
- }
81
- };
82
-
83
- updateTheme();
84
-
85
- const prefersDarkQuery = window.matchMedia?.('(prefers-color-scheme: dark)') ?? null;
86
- const handleMediaChange = () => updateTheme();
87
-
88
- prefersDarkQuery?.addEventListener('change', handleMediaChange);
89
-
90
- const observer =
91
- typeof MutationObserver !== 'undefined'
92
- ? new MutationObserver(() => updateTheme())
93
- : null;
94
-
95
- if (observer) {
96
- const markdownContent = ref.current?.closest?.('.markdown-content') ?? null;
97
- if (markdownContent) {
98
- observer.observe(markdownContent, {
99
- attributes: true,
100
- attributeFilter: ['class', 'data-theme'],
101
- });
102
- }
103
-
104
- if (document.body) {
105
- observer.observe(document.body, {
106
- attributes: true,
107
- attributeFilter: ['class', 'data-theme'],
108
- });
109
- }
110
- }
111
-
112
- return () => {
113
- prefersDarkQuery?.removeEventListener('change', handleMediaChange);
114
- observer?.disconnect();
115
- };
116
- }, [explicitTheme, ref]);
117
-
118
- return explicitTheme ?? detectedTheme;
119
- };
120
-
121
- const LANGUAGE_ALIASES: Record<string, string> = {
122
- js: 'javascript',
123
- jsx: 'javascript',
124
- ts: 'typescript',
125
- tsx: 'tsx',
126
- sh: 'bash',
127
- shell: 'bash',
128
- shellsession: 'bash',
129
- yml: 'yaml',
130
- yaml: 'yaml',
131
- py: 'python',
132
- rb: 'ruby',
133
- kt: 'kotlin',
134
- md: 'markdown',
135
- csharp: 'csharp',
136
- 'c#': 'csharp',
137
- 'c++': 'cpp',
138
- tf: 'hcl',
139
- terraform: 'hcl',
140
- docker: 'dockerfile',
141
- dotenv: 'env',
142
- env: 'env',
143
- plaintext: 'text',
144
- text: 'text',
145
- };
146
-
147
- const extractLanguageFromClassName = (className?: string | null): string => {
148
- if (!className) return '';
149
-
150
- const languageMatch = className.match(/(?:^|\s)language-([^\s]+)/);
151
- if (!languageMatch) return '';
152
-
153
- const raw = languageMatch[1].toLowerCase();
154
- const sanitized = raw
155
- .split('{')[0]
156
- .split('[')[0]
157
- .split('<')[0]
158
- .split(':')[0]
159
- .trim()
160
- .replace(/[^a-z0-9+#-]+$/g, '');
161
-
162
- if (!sanitized) return '';
163
-
164
- return LANGUAGE_ALIASES[sanitized] ?? sanitized;
165
- };
166
-
167
- const getCodeFromChildren = (children: React.ReactNode): string => {
168
- return React.Children.toArray(children)
169
- .map((child) => {
170
- if (typeof child === 'string' || typeof child === 'number') {
171
- return String(child);
172
- }
173
- return '';
174
- })
175
- .join('')
176
- .replace(/\n$/, '');
177
- };
178
-
179
- // Copy button component for code blocks
180
- const CopyButton: React.FC<{ code: string }> = ({ code }) => {
181
- const [copied, setCopied] = useState(false);
182
-
183
- const handleCopy = async () => {
184
- try {
185
- await navigator.clipboard.writeText(code);
186
- setCopied(true);
187
- setTimeout(() => setCopied(false), 2000);
188
- } catch {
189
- // Fallback for older browsers
190
- const textArea = document.createElement('textarea');
191
- textArea.value = code;
192
- textArea.style.position = 'fixed';
193
- textArea.style.opacity = '0';
194
- document.body.appendChild(textArea);
195
- textArea.select();
196
- try {
197
- document.execCommand('copy');
198
- setCopied(true);
199
- setTimeout(() => setCopied(false), 2000);
200
- } catch (fallbackErr) {
201
- console.error('Failed to copy code:', fallbackErr);
202
- }
203
- document.body.removeChild(textArea);
204
- }
205
- };
206
-
207
- return (
208
- <button
209
- className="code-copy-button"
210
- onClick={handleCopy}
211
- title={copied ? 'Copied!' : 'Copy code'}
212
- aria-label={copied ? 'Copied!' : 'Copy code to clipboard'}
213
- >
214
- {copied ? (
215
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
216
- <path d="M13.5 4.5L6 12L2.5 8.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
217
- </svg>
218
- ) : (
219
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
220
- <path d="M5.5 4.5H3.5C2.94772 4.5 2.5 4.94772 2.5 5.5V12.5C2.5 13.0523 2.94772 13.5 3.5 13.5H10.5C11.0523 13.5 11.5 13.0523 11.5 12.5V10.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
221
- <path d="M6.5 2.5H12.5C13.0523 2.5 13.5 2.94772 13.5 3.5V9.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
222
- <path d="M9.5 6.5L13.5 2.5L9.5 2.5V6.5Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
223
- </svg>
224
- )}
225
- <span className="code-copy-button-text">{copied ? 'Copied!' : 'Copy'}</span>
226
- </button>
227
- );
228
- };
229
-
230
- export const CodeBlock: React.FC<CodeBlockProps> = ({
231
- inline,
232
- className = '',
233
- children,
234
- enableGraphs = true,
235
- enableMermaid = true,
236
- enableSVG = true,
237
- enableCharts = true,
238
- enableMusic = true,
239
- enableSyntaxHighlighting = true,
240
- syntaxTheme,
241
- }) => {
242
- const containerRef = useRef<HTMLDivElement>(null);
243
- const effectiveTheme = useEffectiveTheme(containerRef, syntaxTheme);
244
- const rendererFallback = <div className="markdown-code-block code-block-container">Loading renderer...</div>;
245
-
246
- // Handle inline code (always render as code)
247
- if (inline) {
248
- return <code className={className}>{children}</code>;
249
- }
250
-
251
- // Extract language from className (e.g., "language-mermaid" -> "mermaid")
252
- const language = extractLanguageFromClassName(className);
253
- const code = getCodeFromChildren(children);
254
-
255
- // Route to chart renderer (if enabled)
256
- if (enableCharts && (language === 'chart' || language === 'chart-json' || language === 'chart-table')) {
257
- return (
258
- <div ref={containerRef}>
259
- <Suspense fallback={rendererFallback}>
260
- <ChartRenderer code={code} language={language} />
261
- </Suspense>
262
- </div>
263
- );
264
- }
265
-
266
- // Route to music notation renderer (if enabled) - ABC notation only
267
- if (enableMusic && (language === 'abc' || language === 'music')) {
268
- return (
269
- <div ref={containerRef}>
270
- <Suspense fallback={rendererFallback}>
271
- <MusicRenderer code={code} />
272
- </Suspense>
273
- </div>
274
- );
275
- }
276
-
277
- // Route to graph renderers (if enabled)
278
- if (enableGraphs) {
279
- if (language === 'mermaid' && enableMermaid) {
280
- return (
281
- <div ref={containerRef}>
282
- <Suspense fallback={rendererFallback}>
283
- <MermaidRenderer code={code} />
284
- </Suspense>
285
- </div>
286
- );
287
- }
288
-
289
- if (language === 'svg' && enableSVG) {
290
- return (
291
- <div ref={containerRef}>
292
- <Suspense fallback={rendererFallback}>
293
- <SVGRenderer code={code} />
294
- </Suspense>
295
- </div>
296
- );
297
- }
298
- }
299
-
300
- // Use syntax highlighting for regular code blocks
301
- if (enableSyntaxHighlighting && language) {
302
- const style = effectiveTheme === 'light' ? vs : vscDarkPlus;
303
- return (
304
- <div ref={containerRef} className="syntax-highlighted-wrapper code-block-container">
305
- <CopyButton code={code} />
306
- <SyntaxHighlighter
307
- language={language}
308
- style={style}
309
- customStyle={{
310
- margin: '12px 0',
311
- borderRadius: '6px',
312
- fontSize: '0.9em',
313
- }}
314
- showLineNumbers={false}
315
- >
316
- {code}
317
- </SyntaxHighlighter>
318
- </div>
319
- );
320
- }
321
-
322
- // Fallback: render as normal code block
323
- // Use div instead of pre to avoid nesting issues with ReactMarkdown paragraph wrapping
324
- return (
325
- <div ref={containerRef} className={`markdown-code-block code-block-container ${className}`.trim()}>
326
- <CopyButton code={code} />
327
- <pre style={{ margin: 0, padding: 0, background: 'transparent', border: 'none' }}>
328
- <code>{code}</code>
329
- </pre>
330
- </div>
331
- );
332
- };