@stream-mdx/worker 0.0.0 → 0.0.2

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,19 @@
1
+ # @stream-mdx/worker
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+ - Updated dependencies [9e94660]
9
+ - @stream-mdx/core@0.0.2
10
+ - @stream-mdx/plugins@0.0.2
11
+
12
+ ## 0.0.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Release maintenance: CI/build fixes, missing runtime deps (e.g. `rehype-katex`), and improved docs/README wiring for the `stream-mdx` package page.
17
+ - Updated dependencies
18
+ - @stream-mdx/core@0.0.1
19
+ - @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,33 @@ 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
12
-
13
- ```ts
14
- import { MarkdownWorkerClient } from "@stream-mdx/worker";
13
+ ## Hosted worker bundle (recommended)
15
14
 
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
- });
15
+ For production, host the worker bundle from static assets (avoids `blob:` CSP requirements):
20
16
 
21
- client.onMessage((msg) => {
22
- if (msg.type === "PATCH") {
23
- // apply patches
24
- }
25
- });
26
-
27
- client.init("# Hello");
17
+ ```bash
18
+ mkdir -p public/workers
19
+ cp node_modules/@stream-mdx/worker/dist/hosted/markdown-worker.js public/workers/markdown-worker.js
28
20
  ```
29
21
 
30
- `MarkdownWorkerClient` will try `createDefaultWorker()` first (Blob/inline), then fall back to a hosted worker URL (`/workers/markdown-worker.js` by default).
22
+ Then point StreamMDX at it:
31
23
 
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.
33
-
34
- ## Message unions
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. |
24
+ ```tsx
25
+ <StreamingMarkdown worker="/workers/markdown-worker.js" />
26
+ ```
45
27
 
46
- Exact shapes live in `@stream-mdx/core` (`WorkerMessageIn`, `WorkerMessageOut`).
28
+ ## MDX compilation parity helper
47
29
 
48
- ## Hosting guidance
30
+ If you compile MDX on the server (e.g. Next.js API route), use the same compilation logic as the worker:
49
31
 
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`.
32
+ ```ts
33
+ import { compileMdxContent } from "@stream-mdx/worker/mdx-compile";
34
+ ```
53
35
 
54
- For CSP-restricted environments, prehost the worker and set `Cross-Origin-Embedder-Policy` / `Cross-Origin-Opener-Policy` headers if you rely on SharedArrayBuffers.
36
+ See `docs/REACT_INTEGRATION_GUIDE.md` for the full wiring and parity notes.
55
37
 
56
- ## Troubleshooting
38
+ ## Docs
57
39
 
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.
40
+ - React integration guide: `docs/REACT_INTEGRATION_GUIDE.md`
41
+ - Security model / CSP: `docs/SECURITY_MODEL.md`
42
+ - Plugins & custom worker bundles: `docs/STREAMING_MARKDOWN_PLUGINS_COOKBOOK.md`