@brett_lamy/docstream 1.2.4 → 1.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 (216) hide show
  1. package/README.md +76 -14
  2. package/dist/assets.d.ts +3 -0
  3. package/dist/assets.d.ts.map +1 -0
  4. package/dist/assets.js +20 -0
  5. package/dist/assets.js.map +1 -0
  6. package/dist/demo/DemoViewer.d.ts +64 -0
  7. package/dist/demo/DemoViewer.d.ts.map +1 -0
  8. package/dist/demo/DemoViewer.js +426 -0
  9. package/dist/demo/DemoViewer.js.map +1 -0
  10. package/dist/demo/context.d.ts +14 -0
  11. package/dist/demo/context.d.ts.map +1 -0
  12. package/dist/demo/context.js +25 -0
  13. package/dist/demo/context.js.map +1 -0
  14. package/dist/demo/glob.d.ts +60 -0
  15. package/dist/demo/glob.d.ts.map +1 -0
  16. package/dist/demo/glob.js +158 -0
  17. package/dist/demo/glob.js.map +1 -0
  18. package/dist/demo/index.d.ts +10 -0
  19. package/dist/demo/index.d.ts.map +1 -0
  20. package/dist/demo/index.js +6 -0
  21. package/dist/demo/index.js.map +1 -0
  22. package/dist/demo/markdown.d.ts +60 -0
  23. package/dist/demo/markdown.d.ts.map +1 -0
  24. package/dist/demo/markdown.js +181 -0
  25. package/dist/demo/markdown.js.map +1 -0
  26. package/dist/demo/surface.d.ts +11 -0
  27. package/dist/demo/surface.d.ts.map +1 -0
  28. package/dist/demo/surface.js +69 -0
  29. package/dist/demo/surface.js.map +1 -0
  30. package/dist/demo/types.d.ts +91 -0
  31. package/dist/demo/types.d.ts.map +1 -0
  32. package/dist/demo/types.js +2 -0
  33. package/dist/demo/types.js.map +1 -0
  34. package/dist/docs/CollapsibleCode.d.ts +14 -0
  35. package/dist/docs/CollapsibleCode.d.ts.map +1 -0
  36. package/dist/docs/CollapsibleCode.js +19 -0
  37. package/dist/docs/CollapsibleCode.js.map +1 -0
  38. package/dist/docs/DocsRenderer.d.ts +49 -0
  39. package/dist/docs/DocsRenderer.d.ts.map +1 -0
  40. package/dist/docs/DocsRenderer.js +277 -0
  41. package/dist/docs/DocsRenderer.js.map +1 -0
  42. package/dist/docs/HighlightedCode.d.ts +6 -0
  43. package/dist/docs/HighlightedCode.d.ts.map +1 -0
  44. package/dist/docs/HighlightedCode.js +40 -0
  45. package/dist/docs/HighlightedCode.js.map +1 -0
  46. package/dist/docs/Mermaid.d.ts +7 -0
  47. package/dist/docs/Mermaid.d.ts.map +1 -0
  48. package/dist/docs/Mermaid.js +39 -0
  49. package/dist/docs/Mermaid.js.map +1 -0
  50. package/dist/docs/PageActions.d.ts +33 -0
  51. package/dist/docs/PageActions.d.ts.map +1 -0
  52. package/dist/docs/PageActions.js +115 -0
  53. package/dist/docs/PageActions.js.map +1 -0
  54. package/dist/docs/controls.d.ts +29 -0
  55. package/dist/docs/controls.d.ts.map +1 -0
  56. package/dist/docs/controls.js +46 -0
  57. package/dist/docs/controls.js.map +1 -0
  58. package/dist/docs/copy.d.ts +24 -0
  59. package/dist/docs/copy.d.ts.map +1 -0
  60. package/dist/docs/copy.js +62 -0
  61. package/dist/docs/copy.js.map +1 -0
  62. package/dist/docs/math.d.ts +3 -0
  63. package/dist/docs/math.d.ts.map +1 -0
  64. package/dist/docs/math.js +12 -0
  65. package/dist/docs/math.js.map +1 -0
  66. package/dist/docs/reference.d.ts +27 -0
  67. package/dist/docs/reference.d.ts.map +1 -0
  68. package/dist/docs/reference.js +73 -0
  69. package/dist/docs/reference.js.map +1 -0
  70. package/dist/docs/tabs-sync.d.ts +5 -0
  71. package/dist/docs/tabs-sync.d.ts.map +1 -0
  72. package/dist/docs/tabs-sync.js +58 -0
  73. package/dist/docs/tabs-sync.js.map +1 -0
  74. package/dist/gitbook/ast.d.ts +506 -0
  75. package/dist/gitbook/ast.d.ts.map +1 -0
  76. package/dist/gitbook/ast.js +8 -0
  77. package/dist/gitbook/ast.js.map +1 -0
  78. package/dist/gitbook/attrs.d.ts +14 -0
  79. package/dist/gitbook/attrs.d.ts.map +1 -0
  80. package/dist/gitbook/attrs.js +36 -0
  81. package/dist/gitbook/attrs.js.map +1 -0
  82. package/dist/gitbook/flatten.d.ts +14 -0
  83. package/dist/gitbook/flatten.d.ts.map +1 -0
  84. package/dist/gitbook/flatten.js +45 -0
  85. package/dist/gitbook/flatten.js.map +1 -0
  86. package/dist/gitbook/index.d.ts +10 -0
  87. package/dist/gitbook/index.d.ts.map +1 -0
  88. package/dist/gitbook/index.js +8 -0
  89. package/dist/gitbook/index.js.map +1 -0
  90. package/dist/gitbook/inline.d.ts +28 -0
  91. package/dist/gitbook/inline.d.ts.map +1 -0
  92. package/dist/gitbook/inline.js +956 -0
  93. package/dist/gitbook/inline.js.map +1 -0
  94. package/dist/gitbook/outline.d.ts +16 -0
  95. package/dist/gitbook/outline.d.ts.map +1 -0
  96. package/dist/gitbook/outline.js +44 -0
  97. package/dist/gitbook/outline.js.map +1 -0
  98. package/dist/gitbook/package-managers.d.ts +12 -0
  99. package/dist/gitbook/package-managers.d.ts.map +1 -0
  100. package/dist/gitbook/package-managers.js +93 -0
  101. package/dist/gitbook/package-managers.js.map +1 -0
  102. package/dist/gitbook/parse.d.ts +44 -0
  103. package/dist/gitbook/parse.d.ts.map +1 -0
  104. package/dist/gitbook/parse.js +1113 -0
  105. package/dist/gitbook/parse.js.map +1 -0
  106. package/dist/gitbook/serialize.d.ts +23 -0
  107. package/dist/gitbook/serialize.d.ts.map +1 -0
  108. package/dist/gitbook/serialize.js +498 -0
  109. package/dist/gitbook/serialize.js.map +1 -0
  110. package/dist/index.d.ts +34 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +24 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/openapi/OpenApiOperation.d.ts +6 -0
  115. package/dist/openapi/OpenApiOperation.d.ts.map +1 -0
  116. package/dist/openapi/OpenApiOperation.js +112 -0
  117. package/dist/openapi/OpenApiOperation.js.map +1 -0
  118. package/dist/playground/InlineDemoPreview.d.ts +24 -0
  119. package/dist/playground/InlineDemoPreview.d.ts.map +1 -0
  120. package/dist/playground/InlineDemoPreview.js +48 -0
  121. package/dist/playground/InlineDemoPreview.js.map +1 -0
  122. package/dist/playground/PlaygroundStreamdown.d.ts +16 -0
  123. package/dist/playground/PlaygroundStreamdown.d.ts.map +1 -0
  124. package/dist/playground/PlaygroundStreamdown.js +22 -0
  125. package/dist/playground/PlaygroundStreamdown.js.map +1 -0
  126. package/dist/playground/ReactCodePreview.d.ts +64 -0
  127. package/dist/playground/ReactCodePreview.d.ts.map +1 -0
  128. package/dist/playground/ReactCodePreview.js +108 -0
  129. package/dist/playground/ReactCodePreview.js.map +1 -0
  130. package/dist/playground/filesystem.d.ts +27 -0
  131. package/dist/playground/filesystem.d.ts.map +1 -0
  132. package/dist/playground/filesystem.js +65 -0
  133. package/dist/playground/filesystem.js.map +1 -0
  134. package/dist/playground/index.d.ts +9 -0
  135. package/dist/playground/index.d.ts.map +1 -0
  136. package/dist/playground/index.js +7 -0
  137. package/dist/playground/index.js.map +1 -0
  138. package/dist/playground/project.d.ts +57 -0
  139. package/dist/playground/project.d.ts.map +1 -0
  140. package/dist/playground/project.js +137 -0
  141. package/dist/playground/project.js.map +1 -0
  142. package/dist/replay/NativeReplay.d.ts +9 -0
  143. package/dist/replay/NativeReplay.d.ts.map +1 -0
  144. package/dist/replay/NativeReplay.js +173 -0
  145. package/dist/replay/NativeReplay.js.map +1 -0
  146. package/dist/replay/ReplayPreview.d.ts +33 -0
  147. package/dist/replay/ReplayPreview.d.ts.map +1 -0
  148. package/dist/replay/ReplayPreview.js +91 -0
  149. package/dist/replay/ReplayPreview.js.map +1 -0
  150. package/dist/replay/index.d.ts +5 -0
  151. package/dist/replay/index.d.ts.map +1 -0
  152. package/dist/replay/index.js +4 -0
  153. package/dist/replay/index.js.map +1 -0
  154. package/dist/replay/sanitize.d.ts +4 -0
  155. package/dist/replay/sanitize.d.ts.map +1 -0
  156. package/dist/replay/sanitize.js +86 -0
  157. package/dist/replay/sanitize.js.map +1 -0
  158. package/dist/replay/url.d.ts +8 -0
  159. package/dist/replay/url.d.ts.map +1 -0
  160. package/dist/replay/url.js +41 -0
  161. package/dist/replay/url.js.map +1 -0
  162. package/dist/source/SourcePreview.d.ts +13 -0
  163. package/dist/source/SourcePreview.d.ts.map +1 -0
  164. package/dist/source/SourcePreview.js +47 -0
  165. package/dist/source/SourcePreview.js.map +1 -0
  166. package/dist/source/client.d.ts +7 -0
  167. package/dist/source/client.d.ts.map +1 -0
  168. package/dist/source/client.js +52 -0
  169. package/dist/source/client.js.map +1 -0
  170. package/dist/source/index.d.ts +6 -0
  171. package/dist/source/index.d.ts.map +1 -0
  172. package/dist/source/index.js +3 -0
  173. package/dist/source/index.js.map +1 -0
  174. package/dist/source/types.d.ts +33 -0
  175. package/dist/source/types.d.ts.map +1 -0
  176. package/dist/source/types.js +2 -0
  177. package/dist/source/types.js.map +1 -0
  178. package/dist/streamdown.d.ts +19 -0
  179. package/dist/streamdown.d.ts.map +1 -0
  180. package/dist/streamdown.js +15 -0
  181. package/dist/streamdown.js.map +1 -0
  182. package/dist/styles.css +2441 -0
  183. package/dist/video/VideoEmbed.d.ts +17 -0
  184. package/dist/video/VideoEmbed.d.ts.map +1 -0
  185. package/dist/video/VideoEmbed.js +12 -0
  186. package/dist/video/VideoEmbed.js.map +1 -0
  187. package/dist/video/index.d.ts +3 -0
  188. package/dist/video/index.d.ts.map +1 -0
  189. package/dist/video/index.js +2 -0
  190. package/dist/video/index.js.map +1 -0
  191. package/dist/vite/index.d.ts +21 -0
  192. package/dist/vite/index.d.ts.map +1 -0
  193. package/dist/vite/index.js +137 -0
  194. package/dist/vite/index.js.map +1 -0
  195. package/dist/viz/VizEmbed.d.ts +18 -0
  196. package/dist/viz/VizEmbed.d.ts.map +1 -0
  197. package/dist/viz/VizEmbed.js +12 -0
  198. package/dist/viz/VizEmbed.js.map +1 -0
  199. package/dist/viz/index.d.ts +4 -0
  200. package/dist/viz/index.d.ts.map +1 -0
  201. package/dist/viz/index.js +3 -0
  202. package/dist/viz/index.js.map +1 -0
  203. package/package.json +70 -34
  204. package/src/demo/types.ts +2 -2
  205. package/src/docs/DocsRenderer.tsx +31 -7
  206. package/src/docs/Mermaid.tsx +5 -3
  207. package/src/docs/math.ts +3 -0
  208. package/src/index.ts +10 -28
  209. package/src/playground/PlaygroundStreamdown.tsx +28 -61
  210. package/src/playground/filesystem.ts +10 -190
  211. package/src/playground/index.ts +4 -0
  212. package/src/playground/project.ts +194 -0
  213. package/src/replay/NativeReplay.tsx +236 -0
  214. package/src/replay/ReplayPreview.tsx +7 -226
  215. package/src/styles.css +91 -1
  216. package/src/replay/styles.css +0 -87
package/README.md CHANGED
@@ -13,7 +13,7 @@ GitBook-aware markdown rendering for React applications and AI streaming surface
13
13
  Markdown vs HTML images, blank lines between blocks, list markers, fences, table layout and tag lines as written).
14
14
  Layout-only fields (`gap`, `raw`, `opening`, …) are recorded only where the source differs from the default
15
15
  output, and are ignored once they no longer fit an edited node.
16
- - Syntax-highlighted code blocks through `lowlight`.
16
+ - Syntax-highlighted code blocks through `gpu-lexer`; Mermaid diagrams and KaTeX math load on first use.
17
17
  - GitBook block support for hints, tabs, expandables, steppers, embeds, content refs, columns, figures, tables, math, dividers, updates, and OpenAPI operations.
18
18
  - CSS exported as a stable package entrypoint so host apps can theme with CSS variables or shadcn-style design tokens.
19
19
  - Attribute-aware direct video embeds for muted, looping inline clips in long-form posts.
@@ -23,10 +23,31 @@ GitBook-aware markdown rendering for React applications and AI streaming surface
23
23
  ## Installation
24
24
 
25
25
  ```sh
26
- npm install @brett_lamy/docstream react
26
+ pnpm add @brett_lamy/docstream
27
+ # or: npm install @brett_lamy/docstream
28
+ ```
29
+
30
+ React and React DOM are peer dependencies and must be provided by your app.
31
+ Nothing in docstream's dependency tree runs an install script, so
32
+ `pnpm add` succeeds with no build-script prompts (no `ERR_PNPM_IGNORED_BUILDS`).
33
+ Heavy renderers are loaded only when a page needs them: Mermaid for
34
+ ` ```mermaid ` fences, KaTeX for math blocks, rrweb for replay event lists.
35
+
36
+ Two features are opt-in, each behind its own entry and an **optional** peer
37
+ dependency that the rest of the package never references:
38
+
39
+ | Entry | Install to use it | What it adds |
40
+ | --- | --- | --- |
41
+ | `@brett_lamy/docstream/playground` | `@agent-wasm/core` (almost-node, an in-browser Node runtime) | Live React code fences and runnable inline `{% demo %}` files |
42
+ | `@brett_lamy/docstream/viz` | `@brett_lamy/viz-engine` | `VizEmbed` |
43
+
44
+ ```sh
45
+ pnpm add @agent-wasm/core # only if you import @brett_lamy/docstream/playground
27
46
  ```
28
47
 
29
- React is a peer dependency and must be provided by your app.
48
+ Without the playground, live code fences render as highlighted code (or through
49
+ a `liveRenderer` you pass), and inline-file demos open on their Code view with a
50
+ short "needs the playground runtime" note.
30
51
 
31
52
  ## Basic Setup
32
53
 
@@ -50,11 +71,12 @@ If your TypeScript app checks CSS side-effect imports, include Vite's standard e
50
71
 
51
72
  Use `GitbookStreamdown` when markdown may arrive incrementally from an AI stream. The component accepts either `markdown` or string children.
52
73
 
53
- Markdown-only applications can import the renderer from the `streamdown`
54
- subpath. This keeps optional playground integrations out of the host bundle:
74
+ The package root's `GitbookStreamdown` is the same component as the
75
+ `@brett_lamy/docstream/streamdown` entry. For live code fences and runnable
76
+ inline demos, import the playground variant instead (requires `@agent-wasm/core`):
55
77
 
56
78
  ```tsx
57
- import { GitbookStreamdown } from "@brett_lamy/docstream/streamdown"
79
+ import { GitbookStreamdown } from "@brett_lamy/docstream/playground" // = PlaygroundStreamdown
58
80
  ```
59
81
 
60
82
  ```tsx
@@ -367,13 +389,15 @@ what it did before 1.2: a demo, then a code block. While streaming, a block whos
367
389
  | inline files | no runtime (e.g. the `/streamdown` entry) | a one-line note; the viewer opens on Code | the inline files |
368
390
  | `src` only | no resolver | a placeholder chip | — |
369
391
 
370
- The package root's `GitbookStreamdown` (`PlaygroundStreamdown`) runs inline demos
371
- in almost-node by default. Elsewhere pass `demoRuntime`:
392
+ `PlaygroundStreamdown` (also exported as `GitbookStreamdown` from
393
+ `@brett_lamy/docstream/playground`) runs inline demos in almost-node by default.
394
+ Elsewhere pass `demoRuntime` (and `liveRenderer` for live code fences):
372
395
 
373
396
  ```tsx
374
397
  import { createAlmostNodeDemoRuntime } from "@brett_lamy/docstream/playground"
375
398
 
376
399
  const demoRuntime = createAlmostNodeDemoRuntime({ workspaceOptions: { basePath: "/docs" } })
400
+ // live code fences: import { almostNodeLiveRenderer } from "@brett_lamy/docstream/playground"
377
401
 
378
402
  <MarkdownContent markdown={page} demoResolver={demoResolver} demoRuntime={demoRuntime}
379
403
  demoDependencies={{ "@brett_lamy/ui": "^1.2.0" }} />
@@ -546,7 +570,8 @@ You can also resolve paths yourself with `resolveAsset`.
546
570
  - `resolveDemosToMarkdown(markdown, resolver, { format })`: Gives each `{% demo %}` its real files inline — renderable docstream by default, `format: "plain"` for LLM prompts (pure, async).
547
571
  - `inlineDemoMarkdown(node, files, meta)`: One demo as a pasteable block-form `{% demo %}`.
548
572
  - `preloadDemos(resolver, srcs)`: Settle resolver demos before the first render (SSR, static export).
549
- - `createAlmostNodeDemoRuntime(options)` / `InlineDemoPreview` / `createInlineDemoProject(files, { entry, dependencies })` (`/playground`): Run inline demo files in almost-node.
573
+ - `createAlmostNodeDemoRuntime(options)` / `InlineDemoPreview` (`/playground`): Run inline demo files in almost-node. `createInlineDemoProject(files, { entry, dependencies })` (root and `/playground`) builds the runnable project as plain data.
574
+ - `PlaygroundStreamdown`, `almostNodeLiveRenderer`, `ReactDemo` / `ReactCodePreview`, `createAlmostNodeWorkspace`, `useAlmostNodeServer` (`/playground` only): the almost-node playground.
550
575
  - `DocPageActions`: The "Copy page ▾" menu.
551
576
 
552
577
  ### Parser and Serializer
@@ -607,21 +632,58 @@ import { ReactDemo } from "@brett_lamy/docstream/playground"
607
632
 
608
633
  ## Bundler Notes
609
634
 
610
- This release ships TypeScript and TSX source through ESM exports:
635
+ Since 1.4 the package ships compiled ES modules (ES2022, `react-jsx`) with type
636
+ declarations and declaration maps — one file per source module in `dist/`,
637
+ dependencies left as imports, lazy features (Mermaid, KaTeX, rrweb, the
638
+ playground's almost-node) still behind dynamic `import()`:
611
639
 
612
640
  ```json
613
641
  {
614
642
  "exports": {
615
643
  ".": {
616
- "types": "./src/index.ts",
617
- "import": "./src/index.ts"
644
+ "source": "./src/index.ts",
645
+ "types": "./dist/index.d.ts",
646
+ "import": "./dist/index.js",
647
+ "default": "./dist/index.js"
618
648
  },
619
- "./styles.css": "./src/styles.css"
649
+ "./styles.css": "./dist/styles.css"
620
650
  }
621
651
  }
622
652
  ```
623
653
 
624
- It is validated with Vite and modern TypeScript `moduleResolution: "Bundler"`. Plain Node.js, CommonJS, or tooling that does not transpile TypeScript in dependencies may need a future precompiled JS build.
654
+ No bundler configuration is needed: Vite pre-bundles docstream like any other
655
+ dependency (no `optimizeDeps` entries), Next.js and webpack consume it as plain
656
+ ESM, and your type-check reads `.d.ts` files instead of docstream's sources. The
657
+ `@brett_lamy/docstream/vite` entry is a Node-only Vite plugin; import it from
658
+ `vite.config.ts`, never from browser code.
659
+
660
+ The TypeScript sources are published too, behind a `source` export condition, for
661
+ monorepos that want to compile docstream from source (e.g. Vite
662
+ `resolve.conditions: ["source", ...]` or TypeScript `customConditions`).
663
+
664
+ ## Migrating to 1.4
665
+
666
+ No API changes. Exports now resolve to `dist/*.js` + `dist/*.d.ts` instead of
667
+ `src/*.ts(x)`; drop any `optimizeDeps.include` / `exclude` or
668
+ `transpilePackages` entries you added for docstream, and any `lib` / `types`
669
+ settings you added only so your type-check could compile docstream's sources.
670
+
671
+ ## Migrating to 1.3
672
+
673
+ 1.3 moves everything that touches almost-node (`@agent-wasm/core`) out of the
674
+ package root, so installing docstream no longer drags a WASM Node runtime and
675
+ native compressors into every app. `@agent-wasm/core` is now an optional peer.
676
+
677
+ | 1.2 (root import) | 1.3 |
678
+ | --- | --- |
679
+ | `GitbookStreamdown` (ran live code + inline demos in almost-node) | Root `GitbookStreamdown` renders them as code unless you pass `liveRenderer` / `demoRuntime`. For the old behaviour: `import { GitbookStreamdown } from "@brett_lamy/docstream/playground"` and install `@agent-wasm/core`. |
680
+ | `ReactCodePreview`, `ReactDemo`, `InlineDemoPreview`, `almostNodeDemoRuntime`, `createAlmostNodeDemoRuntime`, `createAlmostNodeFilesystem`, `createAlmostNodeWorkspace` and their option/prop types | `@brett_lamy/docstream/playground` |
681
+ | `VizEmbed`, `VizEmbedProps` | `@brett_lamy/docstream/viz`, and install `@brett_lamy/viz-engine` (now an optional peer, no longer a dependency) |
682
+ | `Streamdown`, `StreamdownProps` (re-export of `streamdown`) | Removed: install `streamdown` and import it directly |
683
+
684
+ `createInlineDemoProject`, `createReactDemoFiles` and the `AlmostNodeFile*` data
685
+ types stay on the root (they are plain data helpers). Math blocks now show their
686
+ TeX source for a moment while KaTeX loads.
625
687
 
626
688
  ## Related Package
627
689
 
@@ -0,0 +1,3 @@
1
+ export declare function setAssetBase(repo: string | null, branch: string | null, filePath: string | null): void;
2
+ export declare function resolveAsset(src: string): string;
3
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,QAO/F;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD"}
package/dist/assets.js ADDED
@@ -0,0 +1,20 @@
1
+ // Resolves repo-relative image paths (e.g. "readme-assets/logo.svg") against
2
+ // the raw.githubusercontent.com URL of the file being edited. The AST keeps
3
+ // the original relative src; only rendering resolves it.
4
+ let assetBase = null;
5
+ export function setAssetBase(repo, branch, filePath) {
6
+ if (!repo || !branch || !filePath) {
7
+ assetBase = null;
8
+ return;
9
+ }
10
+ const dir = filePath.includes("/") ? filePath.slice(0, filePath.lastIndexOf("/") + 1) : "";
11
+ assetBase = `https://raw.githubusercontent.com/${repo}/${branch}/${dir}`;
12
+ }
13
+ export function resolveAsset(src) {
14
+ if (!src || /^(https?:|data:|blob:)/i.test(src))
15
+ return src;
16
+ if (!assetBase)
17
+ return src;
18
+ return assetBase + src.replace(/^\.\//, "");
19
+ }
20
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,yDAAyD;AAEzD,IAAI,SAAS,GAAkB,IAAI,CAAA;AAEnC,MAAM,UAAU,YAAY,CAAC,IAAmB,EAAE,MAAqB,EAAE,QAAuB;IAC9F,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClC,SAAS,GAAG,IAAI,CAAA;QAChB,OAAM;IACR,CAAC;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1F,SAAS,GAAG,qCAAqC,IAAI,IAAI,MAAM,IAAI,GAAG,EAAE,CAAA;AAC1E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,CAAC,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IAC3D,IAAI,CAAC,SAAS;QAAE,OAAO,GAAG,CAAA;IAC1B,OAAO,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type CSSProperties } from "react";
2
+ import type { DemoLayout, DemoNode, DemoViewport } from "../gitbook/ast.js";
3
+ import type { DemoFile, DemoResolver, DemoVariant, InlineDemoRuntime } from "./types.js";
4
+ export interface DemoViewerProps {
5
+ /** `<page>/<example>` id handed to the resolver. */
6
+ src: string;
7
+ /** Defaults to the nearest `demoResolver` provided to a renderer. */
8
+ resolver?: DemoResolver;
9
+ title?: string;
10
+ description?: string;
11
+ /** Preview height (px number, digits, or any CSS length). */
12
+ height?: number | string;
13
+ layout?: DemoLayout;
14
+ variants?: DemoVariant[];
15
+ /** Initial viewport of the multi-file preview. */
16
+ viewport?: DemoViewport;
17
+ /**
18
+ * Files carried inline by the block (entry first unless `entry` says otherwise). Used when
19
+ * no resolver knows `src`, or the resolver fails for it.
20
+ */
21
+ files?: DemoFile[];
22
+ /** Entry among `files`. Defaults to the first file. */
23
+ entry?: string;
24
+ /** The block is still streaming in: show its code, but don't run it yet. */
25
+ streaming?: boolean;
26
+ /** Runs inline files in the Preview. Defaults to the runtime in context (`demoRuntime`). */
27
+ runtime?: InlineDemoRuntime;
28
+ /** Extra npm dependencies for the runtime, merged over `demoDependencies` from context. */
29
+ dependencies?: Record<string, string>;
30
+ /** Class on the viewer's outer element. (The preview canvas's class is `canvasClassName`.) */
31
+ className?: string;
32
+ /** Status shown in the header (`meta.status`). */
33
+ status?: string;
34
+ /** Full-bleed canvas without the padded surface (`meta.bleed`). */
35
+ bleed?: boolean;
36
+ /** Extra class on the preview canvas (`meta.className`). */
37
+ canvasClassName?: string;
38
+ /** Canvas inline style: an object like `meta.surface`, or CSS declarations as in the tag's `surface`. */
39
+ surface?: Record<string, string | number> | string;
40
+ /** Width of the variant switch (`meta.variantsWidth`). */
41
+ variantsWidth?: number | string;
42
+ }
43
+ /**
44
+ * Resolve demos ahead of rendering (meta, files and component), so the first render — including
45
+ * server rendering and static export — shows them resolved instead of loading. Failures are
46
+ * remembered too, so inline-file fallbacks apply immediately.
47
+ */
48
+ export declare function preloadDemos(resolver: DemoResolver, srcs: string[]): Promise<void>;
49
+ export declare const NO_RUNTIME_NOTE = "Live preview needs the playground runtime. The code is shown instead.";
50
+ export declare function DemoViewer(props: DemoViewerProps): import("react").JSX.Element;
51
+ /** Renders a parsed `{% demo %}` block with the resolver and runtime from context. */
52
+ export declare function DemoBlock({ node }: {
53
+ node: DemoNode;
54
+ }): import("react").JSX.Element;
55
+ export interface DemoFullscreenProps {
56
+ src: string;
57
+ resolver?: DemoResolver;
58
+ variant?: string;
59
+ className?: string;
60
+ style?: CSSProperties;
61
+ }
62
+ /** One demo filling the viewport, for a `?demo=<src>` deep link the host routes. */
63
+ export declare function DemoFullscreen({ src, resolver: override, variant, className, style }: DemoFullscreenProps): import("react").JSX.Element;
64
+ //# sourceMappingURL=DemoViewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoViewer.d.ts","sourceRoot":"","sources":["../../src/demo/DemoViewer.tsx"],"names":[],"mappings":"AAcA,OAAO,EAQL,KAAK,aAAa,EAKnB,MAAM,OAAO,CAAA;AAId,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAUxE,OAAO,KAAK,EAAiB,QAAQ,EAAY,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE9G,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAA;IACX,qEAAqE;IACrE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;IACxB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;IAClB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4EAA4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4FAA4F;IAC5F,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,8FAA8F;IAC9F,SAAS,CAAC,EAAE,MAAM,CAAA;IAMlB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,4DAA4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,yGAAyG;IACzG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAA;IAClD,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAChC;AAaD;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AA2HD,eAAO,MAAM,eAAe,0EAA0E,CAAA;AA4VtG,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BA8KhD;AAyGD,sFAAsF;AACtF,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,+BAoBrD;AAED,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,mBAAmB,+BAYzG"}