@runbun/astro 0.1.0 → 0.1.1

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.
@@ -2,9 +2,10 @@
2
2
  // A code block highlighted at build time with @pierre/highlights in the page's code theme. Static by default; with
3
3
  // `playground` it gets a Run button that turns it into an embed (Playground.astro) with the code as its file, and
4
4
  // every embed option passes through. `title` names the file, as in a fence. With `files` the block has a tab per file,
5
- // and so does the embed.
6
- import { config } from "virtual:@runbun/astro/config";
7
- import { codeBlock, codeTabs, cssLink, EXT, langOf, withEntry, withTabs } from "../dist/markup.js";
5
+ // and so does the embed. A static block is HTML and CSS only: no script, no request beyond the page's own stylesheet,
6
+ // which Astro bundles the blocks' CSS into (once per page, in <head>).
7
+ import "virtual:@runbun/astro/blocks.css";
8
+ import { codeBlock, codeTabs, EXT, langOf, withEntry, withTabs } from "../dist/markup.js";
8
9
  import Playground, { type Props as PlaygroundProps } from "./Playground.astro";
9
10
 
10
11
  export type Props = Omit<PlaygroundProps, "title"> & {
@@ -19,7 +20,6 @@ const extra = Object.entries(files).map(([name, text]) => ({ name, code: text, l
19
20
  const block = extra.length ? codeTabs([{ name: file, code, lang }, ...extra], options.file ?? file) : codeBlock(code, lang, title);
20
21
  ---
21
22
 
22
- <Fragment set:html={cssLink(config.base)} />
23
23
  {
24
24
  playground ? (
25
25
  <Playground
package/dist/index.js CHANGED
@@ -2,6 +2,10 @@ import { setConfig } from "./config.js";
2
2
  import { BLOCK_CSS, themeCss } from "./highlight.js";
3
3
  import { CSS_PATH } from "./markup.js";
4
4
  const VIRTUAL = "virtual:@runbun/astro/config";
5
+ /** The blocks' stylesheet as a CSS module: <Code> imports it, so Astro bundles it into the page's own CSS. */
6
+ const VIRTUAL_CSS = "virtual:@runbun/astro/blocks.css";
7
+ // Not `\0`-prefixed: Vite's CSS plugins only take ids that end in `.css` and aren't virtual-internal.
8
+ const RESOLVED_CSS = "/@runbun/astro/blocks.css";
5
9
  export default function runbun(options = {}) {
6
10
  const { playgroundUrl = "https://runbun.dev/", themes = ["pierre-light", "pierre-dark"], themeSelector, sync } = options;
7
11
  return {
@@ -18,8 +22,8 @@ export default function runbun(options = {}) {
18
22
  plugins: [
19
23
  {
20
24
  name: "@runbun/astro:config",
21
- resolveId: (id) => (id === VIRTUAL ? "\0" + VIRTUAL : undefined),
22
- load: (id) => (id === "\0" + VIRTUAL ? source : undefined),
25
+ resolveId: (id) => (id === VIRTUAL ? "\0" + VIRTUAL : id === VIRTUAL_CSS ? RESOLVED_CSS : undefined),
26
+ load: (id) => (id === "\0" + VIRTUAL ? source : id === RESOLVED_CSS ? css : undefined),
23
27
  },
24
28
  ],
25
29
  },
package/dist/remark.js CHANGED
@@ -19,6 +19,19 @@ let mdx = false;
19
19
  const html = (value) => mdx
20
20
  ? { type: "mdxJsxFlowElement", name: "Fragment", attributes: [{ type: "mdxJsxAttribute", name: "set:html", value }], children: [] }
21
21
  : { type: "html", value };
22
+ /** `import "virtual:@runbun/astro/blocks.css"` as an MDX ESM node (its estree is what MDX compiles). */
23
+ const CSS_MODULE = "virtual:@runbun/astro/blocks.css";
24
+ const cssImport = () => ({
25
+ type: "mdxjsEsm",
26
+ value: `import ${JSON.stringify(CSS_MODULE)};`,
27
+ data: {
28
+ estree: {
29
+ type: "Program",
30
+ sourceType: "module",
31
+ body: [{ type: "ImportDeclaration", specifiers: [], attributes: [], source: { type: "Literal", value: CSS_MODULE, raw: JSON.stringify(CSS_MODULE) } }],
32
+ },
33
+ },
34
+ });
22
35
  function parse(node) {
23
36
  const toks = tokens(node.meta ?? "");
24
37
  if (!toks.some((t) => t.key === "playground" && t.value === null))
@@ -92,6 +105,10 @@ export default function remarkRunbun(options = {}) {
92
105
  if (!transform(tree.children))
93
106
  return;
94
107
  const { playgroundUrl, base, sync } = { ...CONFIG(), ...options };
95
- tree.children.push(html(cssLink(base) + "\n" + embedScripts(playgroundUrl, sync)));
108
+ // In MDX the blocks' CSS is an import, which Astro bundles into the page's stylesheet as it does for <Code> (one
109
+ // copy for both); Markdown can't import, so it links the integration's route.
110
+ if (mdx)
111
+ tree.children.unshift(cssImport());
112
+ tree.children.push(html((mdx ? "" : cssLink(base) + "\n") + embedScripts(playgroundUrl, sync)));
96
113
  };
97
114
  }
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@runbun/astro",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Code blocks highlighted with @pierre/highlights that turn into a runnable Bun playground (runbun.dev) on click.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "keywords": ["astro-integration", "astro-component", "bun", "playground", "code", "highlight"],
8
8
  "homepage": "https://docs.runbun.dev/guides/astro/",
9
- "repository": { "type": "git", "url": "git+https://github.com/oddcelot/bun-webcontainer.git", "directory": "packages/astro" },
10
- "bugs": "https://github.com/oddcelot/bun-webcontainer/issues",
11
9
  "exports": {
12
10
  ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
13
11
  "./remark": { "types": "./dist/remark.d.ts", "default": "./dist/remark.js" },
package/virtual.d.ts CHANGED
@@ -2,3 +2,4 @@ declare module "virtual:@runbun/astro/config" {
2
2
  export const config: { playgroundUrl: string; base: string; sync?: { scheme?: string; family?: string } };
3
3
  export const css: string;
4
4
  }
5
+ declare module "virtual:@runbun/astro/blocks.css" {}