react-native-streamdown 0.0.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Software Mansion
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # react-native-streamdown
2
+
3
+ > This project is not affiliated with, endorsed by, or sponsored by Vercel.
4
+
5
+ A streaming-ready markdown component for React Native built on top of [`react-native-enriched-markdown`](https://github.com/software-mansion-labs/react-native-enriched-markdown) and [`remend`](https://www.npmjs.com/package/remend).
6
+
7
+ It processes raw, incomplete markdown (as it streams token-by-token from an LLM) in the background using [`react-native-worklets`](https://docs.swmansion.com/react-native-worklets/docs/) powerful concurrency feature - the Bundle Mode - keeping the JS thread free at all times.
8
+
9
+ ## Features
10
+
11
+ - Renders incomplete streaming markdown correctly — no visual glitches mid-stream
12
+ - Background thread processing via `react-native-worklets` Bundle Mode
13
+ - Inline LaTeX support (`$...$`) with streaming completion — applied automatically, no configuration needed (we've also opened a [PR to add this directly to remend](https://github.com/vercel/streamdown/pull/446))
14
+ - CommonMark rendering (headers, bold, italic, inline code, fenced code blocks, links, images) powered by `react-native-enriched-markdown` with built-in `streamingAnimation`
15
+ - Customizable via `remendConfig`
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ yarn add react-native-streamdown
23
+ ```
24
+
25
+ ### Peer dependencies
26
+
27
+ ```sh
28
+ yarn add react-native-enriched-markdown react-native-worklets remend
29
+ ```
30
+
31
+ | Package | Version |
32
+ | -------------------------------- | ----------------------------- |
33
+ | `react-native-enriched-markdown` | `0.4.0` |
34
+ | `react-native-worklets` | `0.8.0-bundle-mode-preview-2` |
35
+ | `remend` | `1.2.2` |
36
+
37
+ ---
38
+
39
+ ## Required setup — Bundle Mode
40
+
41
+ `react-native-streamdown` runs markdown processing on a worklet thread using **Bundle Mode** from `react-native-worklets`. This requires extra configuration steps from the [official Bundle Mode setup guide](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/setup/). Make sure to complete these steps before continuing. For a real-world reference of an app configured with Bundle Mode, check out the [Bundle Mode Showcase App](https://github.com/software-mansion-labs/Bundle-Mode-showcase-app).
42
+
43
+ ### 1. `babel.config.js` — configure Worklets Babel plugin
44
+
45
+ `react-native-streamdown` requires special options to be added to the Worklets Babel plugin config in `babel.config.js`:
46
+
47
+ ```js
48
+ const workletsPluginOptions = {
49
+ bundleMode: true,
50
+ // other options...
51
+ workletizableModules: ['remend'], // add this line
52
+ };
53
+ ```
54
+
55
+ `workletizableModules: ['remend']` tells the Babel plugin to pre-bundle `remend` for the worklet runtime so it can be called off the JS thread.
56
+
57
+ ### 2. `metro.config.js` — configure Metro for monorepos
58
+
59
+ `react-native-worklets` Bundle Mode generates files on the fly that might not be tracked by Metro in some monorepo setups. It might also shadow your resolving function. If you're running into issues with module resolution, you need to add the following to your `metro.config.js`:
60
+
61
+ ```js
62
+ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
63
+ const { bundleModeMetroConfig } = require('react-native-worklets/bundleMode');
64
+
65
+ let config = getDefaultConfig(__dirname);
66
+
67
+ // Watch the .worklets/ output directory
68
+ config.watchFolders.push(
69
+ require('path').resolve(
70
+ __dirname,
71
+ 'node_modules/react-native-worklets/.worklets'
72
+ )
73
+ );
74
+
75
+ // Resolve react-native-worklets/.worklets/* via the Bundle Mode resolver
76
+ const defaultResolver = config.resolver.resolveRequest;
77
+
78
+ config = mergeConfig(config, bundleModeMetroConfig);
79
+
80
+ config.resolver.resolveRequest = (context, moduleName, platform) => {
81
+ if (moduleName.startsWith('react-native-worklets/.worklets/')) {
82
+ return bundleModeMetroConfig.resolver.resolveRequest(
83
+ context,
84
+ moduleName,
85
+ platform
86
+ );
87
+ }
88
+ return defaultResolver(context, moduleName, platform);
89
+ };
90
+
91
+ module.exports = config;
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Usage
97
+
98
+ ```tsx
99
+ import { StreamdownText } from 'react-native-streamdown';
100
+
101
+ // markdown can be updated token-by-token as the LLM streams
102
+ <StreamdownText markdown={partialMarkdown} />;
103
+ ```
104
+
105
+ ### Props
106
+
107
+ `StreamdownText` accepts all props from `EnrichedMarkdownText` (except `flavor`, which is hardcoded to `commonmark`) plus one additional prop:
108
+
109
+ | Prop | Type | Description |
110
+ | -------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
111
+ | `remendConfig` | `RemendOptions` | Optional. Override the default remend processing config. See [remend docs](https://www.npmjs.com/package/remend) for all available options. |
112
+
113
+ ---
114
+
115
+ ## Example app
116
+
117
+ The `example/` directory in this repository contains a fully working demo app that shows:
118
+
119
+ - **Streaming Markdown Simulator** — streams a sample markdown document token-by-token to demonstrate rendering quality and the `streamingAnimation` effect
120
+ - **LLM Streaming Demo** — connects to the OpenAI Chat Completions API via SSE and renders the response live using `StreamdownText`
121
+
122
+ It is a practical reference for the full Bundle Mode setup (Babel, Metro, `package.json` flags) and for how to wire `StreamdownText` into a real streaming UI.
123
+
124
+ ---
125
+
126
+ ## Limitations
127
+
128
+ - **CommonMark only** — `StreamdownText` currently renders using the `commonmark` flavour of `react-native-enriched-markdown`. GitHub Flavored Markdown (GFM) support is planned for a future release.
129
+
130
+ ---
131
+
132
+ Built by [Software Mansion](https://swmansion.com/).
133
+
134
+ [<img width="128" height="69" alt="Software Mansion Logo" src="https://github.com/user-attachments/assets/f0e18471-a7aa-4e80-86ac-87686a86fe56" />](https://swmansion.com/)
135
+
136
+ ---
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ import { EnrichedMarkdownText } from 'react-native-enriched-markdown';
4
+ import { useStreamdownMarkdown } from "./hooks/useStreamdownMarkdown.js";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ /**
7
+ * Streaming-ready markdown component.
8
+ *
9
+ * Processes markdown through remend on a worklet thread,
10
+ * then renders via EnrichedMarkdownText.
11
+ */
12
+ export function StreamdownText({
13
+ markdown,
14
+ remendConfig,
15
+ selectable = true,
16
+ ...enrichedMarkdownProps
17
+ }) {
18
+ const {
19
+ processedMarkdown,
20
+ isStreaming
21
+ } = useStreamdownMarkdown(markdown, {
22
+ remendConfig
23
+ });
24
+ return /*#__PURE__*/_jsx(EnrichedMarkdownText, {
25
+ flavor: "commonmark",
26
+ markdown: processedMarkdown,
27
+ streamingAnimation: true,
28
+ selectable: !isStreaming && selectable,
29
+ ...enrichedMarkdownProps
30
+ });
31
+ }
32
+ //# sourceMappingURL=StreamdownText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EnrichedMarkdownText","useStreamdownMarkdown","jsx","_jsx","StreamdownText","markdown","remendConfig","selectable","enrichedMarkdownProps","processedMarkdown","isStreaming","flavor","streamingAnimation"],"sourceRoot":"../../src","sources":["StreamdownText.tsx"],"mappings":";;AAAA,SAASA,oBAAoB,QAAQ,gCAAgC;AACrE,SAASC,qBAAqB,QAAQ,kCAA+B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGtE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAC;EAC7BC,QAAQ;EACRC,YAAY;EACZC,UAAU,GAAG,IAAI;EACjB,GAAGC;AACgB,CAAC,EAAE;EACtB,MAAM;IAAEC,iBAAiB;IAAEC;EAAY,CAAC,GAAGT,qBAAqB,CAACI,QAAQ,EAAE;IACzEC;EACF,CAAC,CAAC;EAEF,oBACEH,IAAA,CAACH,oBAAoB;IACnBW,MAAM,EAAC,YAAY;IACnBN,QAAQ,EAAEI,iBAAkB;IAC5BG,kBAAkB;IAClBL,UAAU,EAAE,CAACG,WAAW,IAAIH,UAAW;IAAA,GACnCC;EAAqB,CAC1B,CAAC;AAEN","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ import { useState, useEffect, useRef } from 'react';
4
+ import { processRemendInWorklet } from "../worklets/remendWorklet.js";
5
+ export function useStreamdownMarkdown(markdown, options) {
6
+ const [processedMarkdown, setProcessedMarkdown] = useState('');
7
+ const [isStreaming, setIsStreaming] = useState(false);
8
+ const versionRef = useRef(0);
9
+ useEffect(() => {
10
+ if (markdown === '') {
11
+ setProcessedMarkdown('');
12
+ setIsStreaming(false);
13
+ return;
14
+ }
15
+ setIsStreaming(true);
16
+ const currentVersion = ++versionRef.current;
17
+ processRemendInWorklet(markdown, result => {
18
+ if (currentVersion === versionRef.current) {
19
+ setProcessedMarkdown(result);
20
+ setIsStreaming(false);
21
+ }
22
+ }, options?.remendConfig);
23
+ }, [markdown, options?.remendConfig]);
24
+ return {
25
+ processedMarkdown,
26
+ isStreaming
27
+ };
28
+ }
29
+ //# sourceMappingURL=useStreamdownMarkdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useState","useEffect","useRef","processRemendInWorklet","useStreamdownMarkdown","markdown","options","processedMarkdown","setProcessedMarkdown","isStreaming","setIsStreaming","versionRef","currentVersion","current","result","remendConfig"],"sourceRoot":"../../../src","sources":["hooks/useStreamdownMarkdown.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACnD,SAASC,sBAAsB,QAAQ,8BAA2B;AAYlE,OAAO,SAASC,qBAAqBA,CACnCC,QAAgB,EAChBC,OAAsC,EACT;EAC7B,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGR,QAAQ,CAAC,EAAE,CAAC;EAC9D,MAAM,CAACS,WAAW,EAAEC,cAAc,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAMW,UAAU,GAAGT,MAAM,CAAC,CAAC,CAAC;EAE5BD,SAAS,CAAC,MAAM;IACd,IAAII,QAAQ,KAAK,EAAE,EAAE;MACnBG,oBAAoB,CAAC,EAAE,CAAC;MACxBE,cAAc,CAAC,KAAK,CAAC;MACrB;IACF;IAEAA,cAAc,CAAC,IAAI,CAAC;IACpB,MAAME,cAAc,GAAG,EAAED,UAAU,CAACE,OAAO;IAE3CV,sBAAsB,CACpBE,QAAQ,EACPS,MAAM,IAAK;MACV,IAAIF,cAAc,KAAKD,UAAU,CAACE,OAAO,EAAE;QACzCL,oBAAoB,CAACM,MAAM,CAAC;QAC5BJ,cAAc,CAAC,KAAK,CAAC;MACvB;IACF,CAAC,EACDJ,OAAO,EAAES,YACX,CAAC;EACH,CAAC,EAAE,CAACV,QAAQ,EAAEC,OAAO,EAAES,YAAY,CAAC,CAAC;EAErC,OAAO;IAAER,iBAAiB;IAAEE;EAAY,CAAC;AAC3C","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { StreamdownText } from "./StreamdownText.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StreamdownText"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,QAAQ,qBAAkB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { createWorkletRuntime, scheduleOnRuntime, scheduleOnRN } from 'react-native-worklets';
4
+ import remend from 'remend';
5
+ const defaultRemendConfig = {
6
+ bold: true,
7
+ italic: true,
8
+ boldItalic: true,
9
+ strikethrough: true,
10
+ links: true,
11
+ linkMode: 'text-only',
12
+ images: true,
13
+ inlineCode: true,
14
+ katex: false,
15
+ setextHeadings: true
16
+ };
17
+ const remendRuntime = createWorkletRuntime('remend-processor');
18
+ export function processRemendInWorklet(markdown, onComplete, config) {
19
+ const mergedConfig = config ? {
20
+ ...defaultRemendConfig,
21
+ ...config
22
+ } : defaultRemendConfig;
23
+ scheduleOnRuntime(remendRuntime, () => {
24
+ 'worklet';
25
+
26
+ const result = remend(markdown, mergedConfig);
27
+ scheduleOnRN(onComplete, result);
28
+ });
29
+ }
30
+ //# sourceMappingURL=remendWorklet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createWorkletRuntime","scheduleOnRuntime","scheduleOnRN","remend","defaultRemendConfig","bold","italic","boldItalic","strikethrough","links","linkMode","images","inlineCode","katex","setextHeadings","remendRuntime","processRemendInWorklet","markdown","onComplete","config","mergedConfig","result"],"sourceRoot":"../../../src","sources":["worklets/remendWorklet.ts"],"mappings":";;AAAA,SACEA,oBAAoB,EACpBC,iBAAiB,EACjBC,YAAY,QACP,uBAAuB;AAC9B,OAAOC,MAAM,MAAM,QAAQ;AAG3B,MAAMC,mBAAkC,GAAG;EACzCC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,IAAI;EAChBC,aAAa,EAAE,IAAI;EACnBC,KAAK,EAAE,IAAI;EACXC,QAAQ,EAAE,WAAW;EACrBC,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,IAAI;EAChBC,KAAK,EAAE,KAAK;EACZC,cAAc,EAAE;AAClB,CAAC;AAED,MAAMC,aAAa,GAAGf,oBAAoB,CAAC,kBAAkB,CAAC;AAE9D,OAAO,SAASgB,sBAAsBA,CACpCC,QAAgB,EAChBC,UAAoC,EACpCC,MAAsB,EACtB;EACA,MAAMC,YAAY,GAAGD,MAAM,GACvB;IAAE,GAAGf,mBAAmB;IAAE,GAAGe;EAAO,CAAC,GACrCf,mBAAmB;EAEvBH,iBAAiB,CAACc,aAAa,EAAE,MAAM;IACrC,SAAS;;IACT,MAAMM,MAAM,GAAGlB,MAAM,CAACc,QAAQ,EAAEG,YAAY,CAAC;IAC7ClB,YAAY,CAACgB,UAAU,EAAEG,MAAM,CAAC;EAClC,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,9 @@
1
+ import type { StreamdownTextProps } from './types';
2
+ /**
3
+ * Streaming-ready markdown component.
4
+ *
5
+ * Processes markdown through remend on a worklet thread,
6
+ * then renders via EnrichedMarkdownText.
7
+ */
8
+ export declare function StreamdownText({ markdown, remendConfig, selectable, ...enrichedMarkdownProps }: StreamdownTextProps): import("react/jsx-runtime").JSX.Element;
9
+ //# sourceMappingURL=StreamdownText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamdownText.d.ts","sourceRoot":"","sources":["../../../src/StreamdownText.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,UAAiB,EACjB,GAAG,qBAAqB,EACzB,EAAE,mBAAmB,2CAcrB"}
@@ -0,0 +1,11 @@
1
+ import type { RemendOptions } from 'remend';
2
+ interface UseStreamdownMarkdownOptions {
3
+ remendConfig?: RemendOptions;
4
+ }
5
+ interface UseStreamdownMarkdownResult {
6
+ processedMarkdown: string;
7
+ isStreaming: boolean;
8
+ }
9
+ export declare function useStreamdownMarkdown(markdown: string, options?: UseStreamdownMarkdownOptions): UseStreamdownMarkdownResult;
10
+ export {};
11
+ //# sourceMappingURL=useStreamdownMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStreamdownMarkdown.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useStreamdownMarkdown.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,UAAU,4BAA4B;IACpC,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,UAAU,2BAA2B;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,4BAA4B,GACrC,2BAA2B,CA4B7B"}
@@ -0,0 +1,4 @@
1
+ export { StreamdownText } from './StreamdownText';
2
+ export type { StreamdownTextProps } from './types';
3
+ export type { RemendOptions } from 'remend';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { EnrichedMarkdownTextProps } from 'react-native-enriched-markdown';
2
+ import type { RemendOptions } from 'remend';
3
+ export interface StreamdownTextProps extends Omit<EnrichedMarkdownTextProps, 'flavor'> {
4
+ /**
5
+ * Optional custom remend configuration.
6
+ */
7
+ remendConfig?: RemendOptions;
8
+ }
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,QAAQ,CAAC;IACjD;;OAEG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B"}
@@ -0,0 +1,3 @@
1
+ import type { RemendOptions } from 'remend';
2
+ export declare function processRemendInWorklet(markdown: string, onComplete: (result: string) => void, config?: RemendOptions): void;
3
+ //# sourceMappingURL=remendWorklet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remendWorklet.d.ts","sourceRoot":"","sources":["../../../../src/worklets/remendWorklet.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAiB5C,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,aAAa,QAWvB"}
package/package.json CHANGED
@@ -1,4 +1,172 @@
1
1
  {
2
2
  "name": "react-native-streamdown",
3
- "version": "0.0.0"
3
+ "version": "0.1.0",
4
+ "description": "Markdown Streaming ",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace react-native-streamdown-example",
36
+ "clean": "del-cli lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/hryhoriiK97/react-native-streamdown.git"
51
+ },
52
+ "author": "Gregory Moskaliuk <mosckalyuck@gmail.com> (https://github.com/hryhoriiK97)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/hryhoriiK97/react-native-streamdown/issues"
56
+ },
57
+ "homepage": "https://github.com/hryhoriiK97/react-native-streamdown#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^19.8.1",
63
+ "@eslint/compat": "^1.3.2",
64
+ "@eslint/eslintrc": "^3.3.1",
65
+ "@eslint/js": "^9.35.0",
66
+ "@react-native/babel-preset": "0.83.0",
67
+ "@react-native/eslint-config": "0.83.0",
68
+ "@release-it/conventional-changelog": "^10.0.1",
69
+ "@types/jest": "^29.5.14",
70
+ "@types/react": "^19.1.12",
71
+ "commitlint": "^19.8.1",
72
+ "del-cli": "^6.0.0",
73
+ "eslint": "^9.35.0",
74
+ "eslint-config-prettier": "^10.1.8",
75
+ "eslint-plugin-prettier": "^5.5.4",
76
+ "jest": "^29.7.0",
77
+ "lefthook": "^2.0.3",
78
+ "prettier": "^2.8.8",
79
+ "react": "19.2.0",
80
+ "react-native": "0.83.2",
81
+ "react-native-builder-bob": "^0.40.18",
82
+ "react-native-enriched-markdown": "0.4.0",
83
+ "react-native-sse": "1.2.1",
84
+ "react-native-worklets": "0.8.0-bundle-mode-preview-2",
85
+ "release-it": "^19.0.4",
86
+ "remend": "1.2.2",
87
+ "turbo": "^2.5.6",
88
+ "typescript": "^5.9.2"
89
+ },
90
+ "peerDependencies": {
91
+ "react": "*",
92
+ "react-native": "*",
93
+ "react-native-enriched-markdown": "0.4.0",
94
+ "react-native-worklets": "0.8.0-bundle-mode-preview-2",
95
+ "remend": "1.2.2"
96
+ },
97
+ "workspaces": [
98
+ "example"
99
+ ],
100
+ "packageManager": "yarn@4.11.0",
101
+ "resolutions": {
102
+ "metro": "patch:metro@npm%3A0.83.2#~/.yarn/patches/metro-npm-0.83.2-d09f48ca84.patch",
103
+ "metro-runtime": "patch:metro-runtime@npm%3A0.83.2#~/.yarn/patches/metro-runtime-npm-0.83.2-c614bbd3b9.patch"
104
+ },
105
+ "react-native-builder-bob": {
106
+ "source": "src",
107
+ "output": "lib",
108
+ "targets": [
109
+ [
110
+ "module",
111
+ {
112
+ "esm": true
113
+ }
114
+ ],
115
+ [
116
+ "typescript",
117
+ {
118
+ "project": "tsconfig.build.json"
119
+ }
120
+ ]
121
+ ]
122
+ },
123
+ "prettier": {
124
+ "quoteProps": "consistent",
125
+ "singleQuote": true,
126
+ "tabWidth": 2,
127
+ "trailingComma": "es5",
128
+ "useTabs": false
129
+ },
130
+ "jest": {
131
+ "preset": "react-native",
132
+ "modulePathIgnorePatterns": [
133
+ "<rootDir>/example/node_modules",
134
+ "<rootDir>/lib/"
135
+ ]
136
+ },
137
+ "commitlint": {
138
+ "extends": [
139
+ "@commitlint/config-conventional"
140
+ ]
141
+ },
142
+ "release-it": {
143
+ "git": {
144
+ "commitMessage": "chore: release ${version}",
145
+ "tagName": "v${version}"
146
+ },
147
+ "npm": {
148
+ "publish": true
149
+ },
150
+ "github": {
151
+ "release": true
152
+ },
153
+ "plugins": {
154
+ "@release-it/conventional-changelog": {
155
+ "preset": {
156
+ "name": "angular"
157
+ }
158
+ }
159
+ }
160
+ },
161
+ "create-react-native-library": {
162
+ "type": "library",
163
+ "languages": "js",
164
+ "tools": [
165
+ "eslint",
166
+ "jest",
167
+ "lefthook",
168
+ "release-it"
169
+ ],
170
+ "version": "0.57.2"
171
+ }
4
172
  }
@@ -0,0 +1,30 @@
1
+ import { EnrichedMarkdownText } from 'react-native-enriched-markdown';
2
+ import { useStreamdownMarkdown } from './hooks/useStreamdownMarkdown';
3
+ import type { StreamdownTextProps } from './types';
4
+
5
+ /**
6
+ * Streaming-ready markdown component.
7
+ *
8
+ * Processes markdown through remend on a worklet thread,
9
+ * then renders via EnrichedMarkdownText.
10
+ */
11
+ export function StreamdownText({
12
+ markdown,
13
+ remendConfig,
14
+ selectable = true,
15
+ ...enrichedMarkdownProps
16
+ }: StreamdownTextProps) {
17
+ const { processedMarkdown, isStreaming } = useStreamdownMarkdown(markdown, {
18
+ remendConfig,
19
+ });
20
+
21
+ return (
22
+ <EnrichedMarkdownText
23
+ flavor="commonmark"
24
+ markdown={processedMarkdown}
25
+ streamingAnimation
26
+ selectable={!isStreaming && selectable}
27
+ {...enrichedMarkdownProps}
28
+ />
29
+ );
30
+ }
@@ -0,0 +1,45 @@
1
+ import { useState, useEffect, useRef } from 'react';
2
+ import { processRemendInWorklet } from '../worklets/remendWorklet';
3
+ import type { RemendOptions } from 'remend';
4
+
5
+ interface UseStreamdownMarkdownOptions {
6
+ remendConfig?: RemendOptions;
7
+ }
8
+
9
+ interface UseStreamdownMarkdownResult {
10
+ processedMarkdown: string;
11
+ isStreaming: boolean;
12
+ }
13
+
14
+ export function useStreamdownMarkdown(
15
+ markdown: string,
16
+ options?: UseStreamdownMarkdownOptions
17
+ ): UseStreamdownMarkdownResult {
18
+ const [processedMarkdown, setProcessedMarkdown] = useState('');
19
+ const [isStreaming, setIsStreaming] = useState(false);
20
+ const versionRef = useRef(0);
21
+
22
+ useEffect(() => {
23
+ if (markdown === '') {
24
+ setProcessedMarkdown('');
25
+ setIsStreaming(false);
26
+ return;
27
+ }
28
+
29
+ setIsStreaming(true);
30
+ const currentVersion = ++versionRef.current;
31
+
32
+ processRemendInWorklet(
33
+ markdown,
34
+ (result) => {
35
+ if (currentVersion === versionRef.current) {
36
+ setProcessedMarkdown(result);
37
+ setIsStreaming(false);
38
+ }
39
+ },
40
+ options?.remendConfig
41
+ );
42
+ }, [markdown, options?.remendConfig]);
43
+
44
+ return { processedMarkdown, isStreaming };
45
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,4 @@
1
+ export { StreamdownText } from './StreamdownText';
2
+
3
+ export type { StreamdownTextProps } from './types';
4
+ export type { RemendOptions } from 'remend';
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { EnrichedMarkdownTextProps } from 'react-native-enriched-markdown';
2
+ import type { RemendOptions } from 'remend';
3
+
4
+ export interface StreamdownTextProps
5
+ extends Omit<EnrichedMarkdownTextProps, 'flavor'> {
6
+ /**
7
+ * Optional custom remend configuration.
8
+ */
9
+ remendConfig?: RemendOptions;
10
+ }
@@ -0,0 +1,38 @@
1
+ import {
2
+ createWorkletRuntime,
3
+ scheduleOnRuntime,
4
+ scheduleOnRN,
5
+ } from 'react-native-worklets';
6
+ import remend from 'remend';
7
+ import type { RemendOptions } from 'remend';
8
+
9
+ const defaultRemendConfig: RemendOptions = {
10
+ bold: true,
11
+ italic: true,
12
+ boldItalic: true,
13
+ strikethrough: true,
14
+ links: true,
15
+ linkMode: 'text-only',
16
+ images: true,
17
+ inlineCode: true,
18
+ katex: false,
19
+ setextHeadings: true,
20
+ };
21
+
22
+ const remendRuntime = createWorkletRuntime('remend-processor');
23
+
24
+ export function processRemendInWorklet(
25
+ markdown: string,
26
+ onComplete: (result: string) => void,
27
+ config?: RemendOptions
28
+ ) {
29
+ const mergedConfig = config
30
+ ? { ...defaultRemendConfig, ...config }
31
+ : defaultRemendConfig;
32
+
33
+ scheduleOnRuntime(remendRuntime, () => {
34
+ 'worklet';
35
+ const result = remend(markdown, mergedConfig);
36
+ scheduleOnRN(onComplete, result);
37
+ });
38
+ }