@ugoku/core 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.
- package/CHANGELOG.md +7 -0
- package/README.md +34 -0
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @ugoku/core
|
|
2
|
+
|
|
3
|
+
Runtime for [ugoku](https://github.com/ugokujs/ugoku): the Web Worker runner, streamed console output panel, and (lazily loaded) edit overlay + TypeScript stripping. Framework adapters (`@ugoku/vitepress`, `@ugoku/astro`) depend on this package; most users won't import it directly.
|
|
4
|
+
|
|
5
|
+
Everything runs fully in-browser — no server, works offline after first load.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
- Reads `<pre>` elements stamped by [`@ugoku/shiki`](https://www.npmjs.com/package/@ugoku/shiki)'s transformer and mounts a Run button + output panel.
|
|
10
|
+
- Executes code in a module Web Worker (built from a Blob URL): real top-level `await`, a timeout, and a Stop button via `worker.terminate()`.
|
|
11
|
+
- Streams `console.*` output back to the main thread as it arrives.
|
|
12
|
+
- `run edit` blocks: a transparent textarea overlay over the highlighted code, with lazy Shiki re-highlighting loaded on first focus. Edits persist to `localStorage` keyed by a source hash, with a Reset button; if the author changes the snippet, the hash changes and stale edits are discarded automatically.
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { mount, unmount } from '@ugoku/core';
|
|
18
|
+
|
|
19
|
+
mount(document.body); // scan a root for ugoku blocks and wire them up
|
|
20
|
+
unmount(document.body); // tear down listeners/workers before removing the DOM
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`mount`/`unmount` touch only the DOM — call them explicitly (e.g. on route change in an SPA). They don't run on import and don't scan automatically on `DOMContentLoaded`.
|
|
24
|
+
|
|
25
|
+
Also exported: `runCode` (the worker runner used internally by `mount`) and `OutputPanel`/`renderValue` (the output panel and its value serializer), for adapters or advanced use.
|
|
26
|
+
|
|
27
|
+
## Who should use this directly
|
|
28
|
+
|
|
29
|
+
Most readers want an adapter instead:
|
|
30
|
+
|
|
31
|
+
- [`@ugoku/vitepress`](https://www.npmjs.com/package/@ugoku/vitepress) for VitePress
|
|
32
|
+
- [`@ugoku/astro`](https://www.npmjs.com/package/@ugoku/astro) for plain Astro
|
|
33
|
+
|
|
34
|
+
See the [main README](https://github.com/ugokujs/ugoku#readme) for the full picture.
|