llm-message-react 0.1.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.
@@ -0,0 +1,133 @@
1
+ import { ComponentType, ReactNode } from 'react';
2
+
3
+ /** Props passed to a custom fenced code block renderer. */
4
+ interface CodeBlockProps {
5
+ /** The raw code content (without the trailing newline). */
6
+ code: string;
7
+ /** The language detected from the fence info string (may be empty). */
8
+ language: string;
9
+ className?: string;
10
+ }
11
+ /** Props passed to a custom inline code renderer. */
12
+ interface InlineCodeProps {
13
+ className?: string;
14
+ children?: ReactNode;
15
+ }
16
+ /** Props passed to a code-highlighter component. */
17
+ interface CodeHighlighterProps {
18
+ /** The raw code content (without the trailing newline). */
19
+ code: string;
20
+ /** The language detected from the fence info string (may be empty). */
21
+ language: string;
22
+ className?: string;
23
+ }
24
+ /** A component that renders a syntax-highlighted code body. */
25
+ type CodeHighlighter = ComponentType<CodeHighlighterProps>;
26
+ /**
27
+ * A `codeToHtml`-compatible function. The signature is shared by `shiki`,
28
+ * `shiki/bundle/web`, and a `createHighlighterCore` instance's `codeToHtml`,
29
+ * so any of them can be passed to `createShikiHighlighter`.
30
+ */
31
+ type CodeToHtml = (code: string, options: {
32
+ lang: string;
33
+ themes: {
34
+ light: string;
35
+ dark: string;
36
+ };
37
+ }) => string | Promise<string>;
38
+ /** Props passed to a custom copy button renderer. */
39
+ interface CopyButtonProps {
40
+ /** The text that should be written to the clipboard. */
41
+ text: string;
42
+ className?: string;
43
+ }
44
+ /** Props passed to a custom task-list checkbox renderer. */
45
+ interface CheckboxProps {
46
+ checked: boolean;
47
+ className?: string;
48
+ }
49
+ /** Props passed to generic block/inline element overrides. */
50
+ interface ElementProps {
51
+ className?: string;
52
+ children?: ReactNode;
53
+ }
54
+ /** Props passed to a custom anchor renderer. */
55
+ interface AnchorProps extends ElementProps {
56
+ href?: string;
57
+ }
58
+ /** Props passed to a custom image renderer. */
59
+ interface ImageProps {
60
+ src?: string;
61
+ alt?: string;
62
+ title?: string;
63
+ className?: string;
64
+ }
65
+ /**
66
+ * Per-element class overrides. Each value is merged with the built-in
67
+ * semantic class name, so the default theme still applies unless overridden
68
+ * via CSS.
69
+ */
70
+ interface LLMMessageClassNames {
71
+ root?: string;
72
+ p?: string;
73
+ h1?: string;
74
+ h2?: string;
75
+ h3?: string;
76
+ h4?: string;
77
+ h5?: string;
78
+ h6?: string;
79
+ ul?: string;
80
+ ol?: string;
81
+ li?: string;
82
+ code?: string;
83
+ codeBlock?: string;
84
+ codeHeader?: string;
85
+ codeLanguage?: string;
86
+ copyButton?: string;
87
+ table?: string;
88
+ tableWrapper?: string;
89
+ th?: string;
90
+ td?: string;
91
+ blockquote?: string;
92
+ a?: string;
93
+ hr?: string;
94
+ strong?: string;
95
+ em?: string;
96
+ del?: string;
97
+ img?: string;
98
+ checkbox?: string;
99
+ }
100
+ /**
101
+ * Per-element component overrides. When provided, the user component fully
102
+ * controls the markup for that element; otherwise the built-in native renderer
103
+ * is used.
104
+ */
105
+ interface LLMMessageComponents {
106
+ codeBlock?: ComponentType<CodeBlockProps>;
107
+ code?: ComponentType<InlineCodeProps>;
108
+ copyButton?: ComponentType<CopyButtonProps>;
109
+ checkbox?: ComponentType<CheckboxProps>;
110
+ a?: ComponentType<AnchorProps>;
111
+ img?: ComponentType<ImageProps>;
112
+ p?: ComponentType<ElementProps>;
113
+ h1?: ComponentType<ElementProps>;
114
+ h2?: ComponentType<ElementProps>;
115
+ h3?: ComponentType<ElementProps>;
116
+ h4?: ComponentType<ElementProps>;
117
+ h5?: ComponentType<ElementProps>;
118
+ h6?: ComponentType<ElementProps>;
119
+ ul?: ComponentType<ElementProps>;
120
+ ol?: ComponentType<ElementProps>;
121
+ li?: ComponentType<ElementProps>;
122
+ blockquote?: ComponentType<ElementProps>;
123
+ table?: ComponentType<ElementProps>;
124
+ th?: ComponentType<ElementProps>;
125
+ td?: ComponentType<ElementProps>;
126
+ hr?: ComponentType<ElementProps>;
127
+ strong?: ComponentType<ElementProps>;
128
+ em?: ComponentType<ElementProps>;
129
+ del?: ComponentType<ElementProps>;
130
+ pre?: ComponentType<ElementProps>;
131
+ }
132
+
133
+ export type { AnchorProps as A, CodeHighlighter as C, ElementProps as E, ImageProps as I, LLMMessageClassNames as L, LLMMessageComponents as a, CodeToHtml as b, CheckboxProps as c, CodeBlockProps as d, CodeHighlighterProps as e, CopyButtonProps as f, InlineCodeProps as g };
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "llm-message-react",
3
+ "version": "0.1.0",
4
+ "description": "React component for rendering streaming LLM markdown, repairing incomplete tokens mid-stream, with GFM, KaTeX math and Shiki code highlighting.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Aleksandr Afonasev <dify.chrome@gmail.com>",
8
+ "homepage": "https://github.com/chrome/llm-message-react#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/chrome/llm-message-react.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/chrome/llm-message-react/issues"
15
+ },
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
19
+ "keywords": [
20
+ "react",
21
+ "markdown",
22
+ "llm",
23
+ "chat",
24
+ "ai",
25
+ "katex",
26
+ "shiki",
27
+ "gfm"
28
+ ],
29
+ "sideEffects": [
30
+ "*.css"
31
+ ],
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "main": "./dist/index.cjs",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.js",
42
+ "require": "./dist/index.cjs"
43
+ },
44
+ "./shiki": {
45
+ "types": "./dist/highlighters/shiki.d.ts",
46
+ "import": "./dist/highlighters/shiki.js",
47
+ "require": "./dist/highlighters/shiki.cjs"
48
+ },
49
+ "./shiki-web": {
50
+ "types": "./dist/highlighters/shikiWeb.d.ts",
51
+ "import": "./dist/highlighters/shikiWeb.js",
52
+ "require": "./dist/highlighters/shikiWeb.cjs"
53
+ },
54
+ "./styles.css": "./dist/styles.css",
55
+ "./package.json": "./package.json"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
+ "typecheck": "tsc --noEmit",
61
+ "lint": "eslint src",
62
+ "test": "vitest run",
63
+ "test:watch": "vitest",
64
+ "prepublishOnly": "npm run build"
65
+ },
66
+ "peerDependencies": {
67
+ "react": ">=18",
68
+ "react-dom": ">=18",
69
+ "shiki": ">=1"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "shiki": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "dependencies": {
77
+ "clsx": "^2.1.1",
78
+ "katex": "^0.16.22",
79
+ "react-markdown": "^10.1.0",
80
+ "rehype-katex": "^7.0.1",
81
+ "remark-gfm": "^4.0.1",
82
+ "remark-math": "^6.0.0"
83
+ },
84
+ "devDependencies": {
85
+ "@testing-library/dom": "^10.4.1",
86
+ "@testing-library/jest-dom": "^6.9.1",
87
+ "@testing-library/react": "^16.3.2",
88
+ "@testing-library/user-event": "^14.6.1",
89
+ "@types/react": "^19.2.17",
90
+ "@types/react-dom": "^19.2.3",
91
+ "@vitejs/plugin-react": "^6.0.3",
92
+ "eslint": "^10.6.0",
93
+ "eslint-plugin-react-hooks": "^7.1.1",
94
+ "jsdom": "^29.1.1",
95
+ "react": "^19.2.7",
96
+ "react-dom": "^19.2.7",
97
+ "shiki": "^4.3.0",
98
+ "tsup": "^8.5.1",
99
+ "typescript": "~5.8.3",
100
+ "typescript-eslint": "^8.62.0",
101
+ "vitest": "^4.1.9"
102
+ }
103
+ }