@pieceful/ravel-host-browser 0.2.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.
- package/LICENSE +21 -0
- package/README.md +55 -0
- package/package.json +45 -0
- package/src/index.d.ts +42 -0
- package/src/index.js +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 James Taylor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# `@pieceful/ravel-host-browser`
|
|
2
|
+
|
|
3
|
+
An in-memory, browser-safe [Ravel](https://github.com/jostylr/ravel) host for rendering one Markdown document into
|
|
4
|
+
a Ravel Map, completed program, generated deliverables, diagnostics, and
|
|
5
|
+
provenance maps.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @pieceful/ravel-host-browser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { renderMarkdownDocument } from "@pieceful/ravel-host-browser";
|
|
13
|
+
|
|
14
|
+
const result = renderMarkdownDocument(
|
|
15
|
+
`
|
|
16
|
+
---
|
|
17
|
+
ravel:
|
|
18
|
+
document: greeting
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
\`\`\`javascript {.ravel #main type=js}
|
|
22
|
+
console.log("Hello from Ravel");
|
|
23
|
+
\`\`\`
|
|
24
|
+
|
|
25
|
+
\`\`\`ravel
|
|
26
|
+
out("dist/greeting.js", _"main.js")
|
|
27
|
+
\`\`\`
|
|
28
|
+
`,
|
|
29
|
+
{ uri: "greeting.md" },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!result.ok) {
|
|
33
|
+
console.error(result.diagnostics);
|
|
34
|
+
} else {
|
|
35
|
+
console.log(result.deliverables[0].value);
|
|
36
|
+
console.log(result.deliverables[0].provenanceMap);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`BrowserRenderResult` always returns structured diagnostics instead of throwing
|
|
41
|
+
for authored source errors. On success it contains the parsed map, completed
|
|
42
|
+
`RavelProgram`, and every declared deliverable with a provenance map. Use the
|
|
43
|
+
program with `@pieceful/ravel-explorer` when you want a bounded dependency
|
|
44
|
+
graph in a browser UI.
|
|
45
|
+
|
|
46
|
+
## Boundary
|
|
47
|
+
|
|
48
|
+
This host has no filesystem, network, project loading, artifact writing, or
|
|
49
|
+
live `.run` execution capability. It evaluates one caller-supplied Markdown
|
|
50
|
+
string using the explicit opt-in Markdown profile by default. Its optional
|
|
51
|
+
`transforms` are trusted synchronous functions supplied by the embedding
|
|
52
|
+
application; a document cannot register or discover them.
|
|
53
|
+
|
|
54
|
+
The [Ravel playground](https://ravel.jostylr.com/playground/) is a complete
|
|
55
|
+
browser example built with this package.
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pieceful/ravel-host-browser",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Portable in-memory Markdown host for the Ravel graph engine.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "James Taylor",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/jostylr/ravel.git",
|
|
12
|
+
"directory": "packages/host-browser"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/jostylr/ravel/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://ravel.jostylr.com/",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"ravel",
|
|
23
|
+
"literate-programming",
|
|
24
|
+
"browser",
|
|
25
|
+
"markdown",
|
|
26
|
+
"provenance"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./src/index.js"
|
|
33
|
+
},
|
|
34
|
+
"types": "./src/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"src",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@pieceful/ravel-core": "0.2.0",
|
|
42
|
+
"@pieceful/ravel-map": "0.2.0",
|
|
43
|
+
"@pieceful/ravel-markdown": "0.2.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Deliverable,
|
|
3
|
+
DeliverableProvenanceMap,
|
|
4
|
+
Diagnostic,
|
|
5
|
+
RavelProgram,
|
|
6
|
+
RavelMap
|
|
7
|
+
} from "@pieceful/ravel-core";
|
|
8
|
+
|
|
9
|
+
export interface BrowserDeliverable extends Deliverable {
|
|
10
|
+
provenanceMap: DeliverableProvenanceMap;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type BrowserTransform = (value: string, context: unknown) => string;
|
|
14
|
+
|
|
15
|
+
export interface BrowserRenderOptions {
|
|
16
|
+
/** Source URI used in diagnostics and provenance. Defaults to `playground.md`. */
|
|
17
|
+
uri?: string;
|
|
18
|
+
/** Optional stable document identity. */
|
|
19
|
+
document?: string;
|
|
20
|
+
/** Markdown profile. Defaults to the explicit opt-in Ravel profile. */
|
|
21
|
+
mode?: "opt-in" | "primary";
|
|
22
|
+
/**
|
|
23
|
+
* Trusted application-supplied synchronous transforms. Document source cannot
|
|
24
|
+
* register transforms, and this host never provides filesystem or network access.
|
|
25
|
+
*/
|
|
26
|
+
transforms?: Record<string, BrowserTransform> | Map<string, BrowserTransform>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BrowserRenderResult {
|
|
30
|
+
version: 1;
|
|
31
|
+
source: { uri: string; document: string | null };
|
|
32
|
+
map: RavelMap | null;
|
|
33
|
+
program: RavelProgram | null;
|
|
34
|
+
deliverables: BrowserDeliverable[];
|
|
35
|
+
diagnostics: Diagnostic[];
|
|
36
|
+
ok: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function renderMarkdownDocument(
|
|
40
|
+
source: string,
|
|
41
|
+
options?: BrowserRenderOptions
|
|
42
|
+
): BrowserRenderResult;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
combineMaps,
|
|
3
|
+
createDeliverableProvenanceMap,
|
|
4
|
+
transformGraph
|
|
5
|
+
} from "@pieceful/ravel-core";
|
|
6
|
+
import { validateRavelMap } from "@pieceful/ravel-map";
|
|
7
|
+
import { markdownToMap } from "@pieceful/ravel-markdown";
|
|
8
|
+
|
|
9
|
+
const point = () => ({ line: 0, column: 0, offset: 0 });
|
|
10
|
+
|
|
11
|
+
const hostDiagnostic = (error, uri) => ({
|
|
12
|
+
code: "RB100",
|
|
13
|
+
severity: "error",
|
|
14
|
+
message: error?.message ?? String(error),
|
|
15
|
+
source: {
|
|
16
|
+
uri,
|
|
17
|
+
range: { start: point(), end: point() }
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Render one in-memory Markdown document through the portable Ravel pipeline.
|
|
23
|
+
*
|
|
24
|
+
* This host intentionally has no filesystem, process, network, load, or export
|
|
25
|
+
* surface. The caller owns the source string and any copy/paste interaction.
|
|
26
|
+
*/
|
|
27
|
+
export const renderMarkdownDocument = (source, options = {}) => {
|
|
28
|
+
const uri = options.uri ?? "playground.md";
|
|
29
|
+
const mode = options.mode ?? "opt-in";
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const adapted = markdownToMap(source, {
|
|
33
|
+
uri,
|
|
34
|
+
mode,
|
|
35
|
+
...(options.document ? { document: options.document } : {})
|
|
36
|
+
});
|
|
37
|
+
const validationDiagnostics = validateRavelMap(adapted.map, { uri });
|
|
38
|
+
const program = transformGraph(combineMaps([adapted.map]), {
|
|
39
|
+
transforms: options.transforms
|
|
40
|
+
});
|
|
41
|
+
const diagnostics = [
|
|
42
|
+
...adapted.diagnostics,
|
|
43
|
+
...validationDiagnostics,
|
|
44
|
+
...program.diagnostics
|
|
45
|
+
];
|
|
46
|
+
const deliverables = Object.values(program.deliverables).map((deliverable) => ({
|
|
47
|
+
...deliverable,
|
|
48
|
+
provenanceMap: createDeliverableProvenanceMap(deliverable)
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
version: 1,
|
|
53
|
+
source: { uri, document: adapted.map.document.id },
|
|
54
|
+
map: adapted.map,
|
|
55
|
+
program,
|
|
56
|
+
deliverables,
|
|
57
|
+
diagnostics,
|
|
58
|
+
ok: diagnostics.every((entry) => entry.severity !== "error")
|
|
59
|
+
};
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return {
|
|
62
|
+
version: 1,
|
|
63
|
+
source: { uri, document: options.document ?? null },
|
|
64
|
+
map: null,
|
|
65
|
+
program: null,
|
|
66
|
+
deliverables: [],
|
|
67
|
+
diagnostics: [hostDiagnostic(error, uri)],
|
|
68
|
+
ok: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|