@stream-mdx/worker 0.0.1 → 0.0.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # @stream-mdx/worker
2
+
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 47d1374: Add opt-in streaming format anticipation and an optional Mermaid diagram addon for ` ```mermaid ` code blocks.
8
+ - 7c79f09: Port the docs demo page to match the ql-homepage streaming UI, and fix several streaming parser/rendering edge cases (hard line breaks and display-math handling) while keeping the hosted worker bundle self-contained for static hosting.
9
+ - Updated dependencies [47d1374]
10
+ - Updated dependencies [7c79f09]
11
+ - @stream-mdx/core@0.0.3
12
+ - @stream-mdx/plugins@0.0.3
13
+
14
+ ## 0.0.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 9e94660: Docs and release-quality improvements: ship package READMEs/CHANGELOGs, add pack+install smoke tests, expose MDX parity helper entrypoints, and add a deployable docs site workflow.
19
+ - Updated dependencies [9e94660]
20
+ - @stream-mdx/core@0.0.2
21
+ - @stream-mdx/plugins@0.0.2
22
+
23
+ ## 0.0.1
24
+
25
+ ### Patch Changes
26
+
27
+ - Release maintenance: CI/build fixes, missing runtime deps (e.g. `rehype-katex`), and improved docs/README wiring for the `stream-mdx` package page.
28
+ - Updated dependencies
29
+ - @stream-mdx/core@0.0.1
30
+ - @stream-mdx/plugins@0.0.1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # `@stream-mdx/worker`
2
2
 
3
- Web Worker entry point for the streaming renderer. Handles markdown parsing (Lezer), inline enrichment, Shiki highlighting, MDX detection, and patch emission. Consumers rarely interact with this package directly unless they need explicit control over worker instantiation or CSP compliance.
3
+ Worker client utilities and hosted worker bundle used by StreamMDX.
4
+
5
+ Most consumers interact with this package indirectly via `<StreamingMarkdown />`. You only need `@stream-mdx/worker` directly if you want explicit control over worker instantiation, MDX compilation parity helpers, or strict CSP setups.
4
6
 
5
7
  ## Install
6
8
 
@@ -8,53 +10,43 @@ Web Worker entry point for the streaming renderer. Handles markdown parsing (Lez
8
10
  npm install @stream-mdx/worker
9
11
  ```
10
12
 
11
- ## Usage
13
+ ## Hosted worker bundle (recommended)
12
14
 
13
- ```ts
14
- import { MarkdownWorkerClient } from "@stream-mdx/worker";
15
+ For production, host the worker bundle from static assets (avoids `blob:` CSP requirements):
15
16
 
16
- const client = new MarkdownWorkerClient({
17
- // For CSP-restricted environments, host the worker and point to it here:
18
- workerUrl: "/workers/markdown-worker.js",
19
- });
17
+ ```bash
18
+ mkdir -p public/workers
19
+ cp node_modules/@stream-mdx/worker/dist/hosted/markdown-worker.js public/workers/markdown-worker.js
20
+ ```
20
21
 
21
- client.onMessage((msg) => {
22
- if (msg.type === "PATCH") {
23
- // apply patches
24
- }
25
- });
22
+ Then point StreamMDX at it:
26
23
 
27
- client.init("# Hello");
24
+ ```tsx
25
+ <StreamingMarkdown worker="/workers/markdown-worker.js" />
28
26
  ```
29
27
 
30
- `MarkdownWorkerClient` will try `createDefaultWorker()` first (Blob/inline), then fall back to a hosted worker URL (`/workers/markdown-worker.js` by default).
28
+ ## Node / CLI worker threads
31
29
 
32
- > Keep `docPlugins` in sync with the renderer when enabling math+MDX. Follow the [cookbook recipe](../../docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md#5-math--mdx-workerrenderer-registration); the worker and React packages now ship tests enforcing it.
30
+ To run the hosted worker bundle in Node (e.g., Ink TUIs), use:
33
31
 
34
- ## Message unions
32
+ ```ts
33
+ import { createWorkerThread } from "@stream-mdx/worker/node";
34
+ ```
35
35
 
36
- | Type | Direction | Payload |
37
- | --- | --- | --- |
38
- | `INIT` | Main → Worker | `{ text?: string; stream?: boolean; prewarmLangs?: string[]; plugins?: PluginConfig }` |
39
- | `APPEND` | Main → Worker | `{ chunk: string }` |
40
- | `FINALIZE` | Main → Worker | Flush + emit remaining patches. |
41
- | `RESET` | Main → Worker | Clear state (used on restart). |
42
- | `PATCH` | Worker → Main | `{ tx, at, patches: Patch[], notes }` |
43
- | `METRICS` | Worker → Main | Parse/highlight timings, block stats. |
44
- | `INITIALIZED`, `ERROR`, `DEBUG` | Worker → Main | Lifecycle events. |
36
+ This spawns a `worker_threads` worker and installs WebWorker-like shims so the hosted bundle can run under Node.
45
37
 
46
- Exact shapes live in `@stream-mdx/core` (`WorkerMessageIn`, `WorkerMessageOut`).
38
+ ## MDX compilation parity helper
47
39
 
48
- ## Hosting guidance
40
+ If you compile MDX on the server (e.g. Next.js API route), use the same compilation logic as the worker:
49
41
 
50
- - **Blob (default):** easiest for local dev, but CSP must allow `blob:` execution.
51
- - **Hosted URL:** build the hosted worker bundle and copy it into your app’s static assets (e.g. `public/workers/markdown-worker.js`).
52
- - **Build hosted worker:** from the repo root, run `npm run worker:build`.
42
+ ```ts
43
+ import { compileMdxContent } from "@stream-mdx/worker/mdx-compile";
44
+ ```
53
45
 
54
- For CSP-restricted environments, prehost the worker and set `Cross-Origin-Embedder-Policy` / `Cross-Origin-Opener-Policy` headers if you rely on SharedArrayBuffers.
46
+ See `docs/REACT_INTEGRATION_GUIDE.md` for the full wiring and parity notes.
55
47
 
56
- ## Troubleshooting
48
+ ## Docs
57
49
 
58
- - **`setStreamLimit` missing** ensure you updated the demo automation shim; the worker no longer exports legacy control messages.
59
- - **Import errors in worker bundle** – verify your bundler targets `type: "module"` workers and preserves ESM syntax. When in doubt, use the prebuilt `public/workers/markdown-worker.js`.
60
- - **MDX compilation issues** – match the worker’s plugin registry with the React side, and confirm you set `mdxCompileMode="worker"` if you expect in-worker compilation.
50
+ - React integration guide: `docs/REACT_INTEGRATION_GUIDE.md`
51
+ - Security model / CSP: `docs/SECURITY_MODEL.md`
52
+ - Plugins & custom worker bundles: `docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md`