@hpcc-js/observablehq-compiler 3.4.0 → 3.5.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/dist/dot-DK4iDc2-.js +40 -0
- package/dist/dot-DK4iDc2-.js.map +1 -0
- package/dist/duckdb-DkM9_nXT.js +298 -0
- package/dist/duckdb-DkM9_nXT.js.map +1 -0
- package/dist/highlight-Bv8PkwN-.js +2402 -0
- package/dist/highlight-Bv8PkwN-.js.map +1 -0
- package/dist/index-B7vRtYlU.js +1807 -0
- package/dist/index-B7vRtYlU.js.map +1 -0
- package/dist/index-COHaJzee.js +260 -0
- package/dist/index-COHaJzee.js.map +1 -0
- package/dist/index-CP3HrqN0.js +1815 -0
- package/dist/index-CP3HrqN0.js.map +1 -0
- package/dist/index-D3TL70UM.js +163 -0
- package/dist/index-D3TL70UM.js.map +1 -0
- package/dist/index-DNwLE6Kk.js +198 -0
- package/dist/index-DNwLE6Kk.js.map +1 -0
- package/dist/index.js +4381 -4944
- package/dist/index.js.map +1 -1
- package/dist/inputs-CsCXZHQ8.js +3 -0
- package/dist/inputs-CsCXZHQ8.js.map +1 -0
- package/dist/leaflet-CkvVhxBL.js +9 -0
- package/dist/leaflet-CkvVhxBL.js.map +1 -0
- package/dist/mapboxgl-C0i2HzjJ.js +9 -0
- package/dist/mapboxgl-C0i2HzjJ.js.map +1 -0
- package/dist/md-Bxvu6Hld.js +7603 -0
- package/dist/md-Bxvu6Hld.js.map +1 -0
- package/dist/mermaid-CFg6sgdO.js +17 -0
- package/dist/mermaid-CFg6sgdO.js.map +1 -0
- package/dist/node/index.cjs +10 -6
- package/dist/node/index.cjs.map +4 -4
- package/dist/node/index.js +8 -4
- package/dist/node/index.js.map +4 -4
- package/dist/runtime.js +2501 -0
- package/dist/runtime.js.map +1 -0
- package/dist/tex-ayRXOMLZ.js +24 -0
- package/dist/tex-ayRXOMLZ.js.map +1 -0
- package/dist/vega-lite-CESXoehe.js +8 -0
- package/dist/vega-lite-CESXoehe.js.map +1 -0
- package/package.json +12 -10
- package/src/__package__.ts +2 -2
- package/src/compiler.ts +2 -16
- package/src/cst.ts +1 -2
- package/src/index.ts +2 -3
- package/src/kit/compiler.ts +41 -0
- package/src/kit/index.ts +3 -0
- package/src/kit/runtime.ts +57 -0
- package/src/kit/util.ts +157 -0
- package/src/util.ts +1 -134
- package/types/compiler.d.ts +1 -3
- package/types/index.d.ts +2 -2
- package/types/kit/compiler.d.ts +6 -0
- package/types/kit/index.d.ts +3 -0
- package/types/kit/runtime.d.ts +13 -0
- package/types/kit/util.d.ts +52 -0
- package/types/util.d.ts +1 -49
- package/dist/index.umd.cjs +0 -5
- package/dist/index.umd.cjs.map +0 -1
- package/dist/node/index.css +0 -2
- package/dist/node/index.css.map +0 -7
- package/src/index.css +0 -460
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type DefineState, NotebookRuntime as NotebookRuntimeBase } from "@observablehq/notebook-kit/runtime";
|
|
2
|
+
import { type Definition } from "./index.ts";
|
|
3
|
+
|
|
4
|
+
import "@observablehq/notebook-kit/index.css";
|
|
5
|
+
import "@observablehq/notebook-kit/theme-air.css";
|
|
6
|
+
|
|
7
|
+
export class NotebookRuntime extends NotebookRuntimeBase {
|
|
8
|
+
|
|
9
|
+
stateById = new Map<number, DefineState>();
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
has(cellId: number): boolean {
|
|
16
|
+
return this.stateById.has(cellId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async add(cellId: number, definition: Definition, placeholderDiv: HTMLDivElement): Promise<void> {
|
|
20
|
+
let state: DefineState | undefined = this.stateById.get(cellId);
|
|
21
|
+
if (state) {
|
|
22
|
+
this.remove(cellId);
|
|
23
|
+
}
|
|
24
|
+
state = { root: placeholderDiv, expanded: [], variables: [] };
|
|
25
|
+
this.stateById.set(cellId, state);
|
|
26
|
+
this.define(state, definition);
|
|
27
|
+
await this.runtime._computeNow();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async remove(cellId: number): Promise<void> {
|
|
31
|
+
const state = this.stateById.get(cellId);
|
|
32
|
+
if (!state) return;
|
|
33
|
+
[...state.variables].forEach(v => v.delete());
|
|
34
|
+
this.stateById.delete(cellId);
|
|
35
|
+
state.root?.remove();
|
|
36
|
+
await this.runtime._computeNow();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async removeAll(): Promise<void> {
|
|
40
|
+
const keys = [...this.stateById.keys()];
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
this.remove(key);
|
|
43
|
+
}
|
|
44
|
+
await this.runtime._computeNow();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
render(definitions: Definition[], target: HTMLElement) {
|
|
48
|
+
definitions.forEach(definition => {
|
|
49
|
+
const placeholderDiv = document.createElement("div");
|
|
50
|
+
placeholderDiv.id = `cell-${definition.id}`;
|
|
51
|
+
placeholderDiv.className = "observablehq observablehq--cell";
|
|
52
|
+
this.stateById.set(definition.id, { root: placeholderDiv, expanded: [], variables: [] });
|
|
53
|
+
this.define(this.stateById.get(definition.id)!, definition);
|
|
54
|
+
target.appendChild(placeholderDiv);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/kit/util.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type Notebook, type Cell, parseJavaScript, serialize, deserialize, toNotebook, toCell } from "@observablehq/notebook-kit";
|
|
2
|
+
import { type Definition } from "@observablehq/notebook-kit/runtime";
|
|
3
|
+
|
|
4
|
+
export type { Notebook, Cell, Definition };
|
|
5
|
+
export { toNotebook, toCell };
|
|
6
|
+
|
|
7
|
+
// Shared function constructor utilities to avoid duplication between util modules.
|
|
8
|
+
|
|
9
|
+
export type RegularFunction = (...args: any[]) => any;
|
|
10
|
+
interface RegularFunctionConstructor {
|
|
11
|
+
new(...args: string[]): RegularFunction;
|
|
12
|
+
(...args: string[]): RegularFunction;
|
|
13
|
+
readonly prototype: RegularFunction;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
17
|
+
interface AsyncFunctionConstructor {
|
|
18
|
+
new(...args: string[]): AsyncFunction;
|
|
19
|
+
(...args: string[]): AsyncFunction;
|
|
20
|
+
readonly prototype: AsyncFunction;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type GeneratorFunction = (...args: any[]) => Generator<any, any, any>;
|
|
24
|
+
interface GeneratorFunctionConstructor {
|
|
25
|
+
new(...args: string[]): GeneratorFunction;
|
|
26
|
+
(...args: string[]): GeneratorFunction;
|
|
27
|
+
readonly prototype: GeneratorFunction;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AsyncGeneratorFunction = (...args: any[]) => AsyncGenerator<any, any, any>;
|
|
31
|
+
interface AsyncGeneratorFunctionConstructor {
|
|
32
|
+
new(...args: string[]): AsyncGeneratorFunction;
|
|
33
|
+
(...args: string[]): AsyncGeneratorFunction;
|
|
34
|
+
readonly prototype: AsyncGeneratorFunction;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type AnyFunction = RegularFunction | AsyncFunction | GeneratorFunction | AsyncGeneratorFunction;
|
|
38
|
+
|
|
39
|
+
export const FunctionConstructors: {
|
|
40
|
+
regular: RegularFunctionConstructor;
|
|
41
|
+
async: AsyncFunctionConstructor;
|
|
42
|
+
generator: GeneratorFunctionConstructor;
|
|
43
|
+
asyncGenerator: AsyncGeneratorFunctionConstructor;
|
|
44
|
+
} = {
|
|
45
|
+
regular: Object.getPrototypeOf(function () { }).constructor as RegularFunctionConstructor,
|
|
46
|
+
async: Object.getPrototypeOf(async function () { }).constructor as AsyncFunctionConstructor,
|
|
47
|
+
generator: Object.getPrototypeOf(function* () { }).constructor as GeneratorFunctionConstructor,
|
|
48
|
+
asyncGenerator: Object.getPrototypeOf(async function* () { }).constructor as AsyncGeneratorFunctionConstructor,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function funcType(async: boolean = false, generator: boolean = false) {
|
|
52
|
+
if (!async && !generator) return FunctionConstructors.regular;
|
|
53
|
+
if (async && !generator) return FunctionConstructors.async;
|
|
54
|
+
if (!async && generator) return FunctionConstructors.generator;
|
|
55
|
+
return FunctionConstructors.asyncGenerator;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface Ref {
|
|
59
|
+
start: number,
|
|
60
|
+
end: number,
|
|
61
|
+
newText: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface Refs {
|
|
65
|
+
inputs: string[];
|
|
66
|
+
args: string[];
|
|
67
|
+
patches: Ref[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createFunction(refs: Refs, async = false, generator = false, blockStatement = false, body?: string) {
|
|
71
|
+
if (body === undefined) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
refs.patches.sort((l, r) => r.start - l.start);
|
|
76
|
+
refs.patches.forEach(r => {
|
|
77
|
+
body = body!.substring(0, r.start) + r.newText + body!.substring(r.end);
|
|
78
|
+
});
|
|
79
|
+
return new (funcType(async, generator))(...refs.args, blockStatement ?
|
|
80
|
+
body.substring(1, body.length - 1).trim() :
|
|
81
|
+
`return (\n${body}\n);`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function join(baseURL: string, relativeURL: string) {
|
|
85
|
+
return relativeURL
|
|
86
|
+
? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "")
|
|
87
|
+
: baseURL;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const isRelativePath = (path: string) => path[0] === ".";
|
|
91
|
+
export const fixRelativeUrl = (path: string, basePath: string) => {
|
|
92
|
+
if (isRelativePath(path)) {
|
|
93
|
+
return join(basePath, path);
|
|
94
|
+
}
|
|
95
|
+
return path;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Hide "import" from bundlers as they have a habit of replacing "import" with "require"
|
|
99
|
+
const obfuscatedImportFunction = new FunctionConstructors.async("url", "return import(url)");
|
|
100
|
+
export async function obfuscatedImport(url: string) {
|
|
101
|
+
return obfuscatedImportFunction(url);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function _constructFunction(body: any, bodyStr: string, name?: string) {
|
|
105
|
+
if (body.type !== "FunctionExpression" && body.type !== "FunctionDeclaration" && body.type !== "ArrowFunctionExpression") {
|
|
106
|
+
throw new Error(`Unsupported function type: ${body.type}`);
|
|
107
|
+
}
|
|
108
|
+
const func = body.async && body.generator ?
|
|
109
|
+
FunctionConstructors.asyncGenerator :
|
|
110
|
+
body.async ?
|
|
111
|
+
FunctionConstructors.async :
|
|
112
|
+
body.generator ?
|
|
113
|
+
FunctionConstructors.generator :
|
|
114
|
+
FunctionConstructors.regular;
|
|
115
|
+
|
|
116
|
+
const params = body.params?.map((param) => bodyStr.slice(param.start, param.end)).join(", ") ?? "";
|
|
117
|
+
const isBlock = body.body.type === "BlockStatement";
|
|
118
|
+
const { start, end } = body.body;
|
|
119
|
+
const inner = isBlock
|
|
120
|
+
? bodyStr.slice(start + 1, end - 1)
|
|
121
|
+
: `return ${bodyStr.slice(start, end)}`;
|
|
122
|
+
// If a name is provided, build a true named function expression for reliable naming.
|
|
123
|
+
if (name) {
|
|
124
|
+
// Sanitize to a valid identifier; fallback to underscored name when necessary.
|
|
125
|
+
const sanitize = (n: string): string => {
|
|
126
|
+
let s = n.replace(/[^A-Za-z0-9_$]/g, "_");
|
|
127
|
+
if (!/^[A-Za-z_$]/.test(s)) s = "_" + s;
|
|
128
|
+
return s;
|
|
129
|
+
};
|
|
130
|
+
const id = sanitize(name);
|
|
131
|
+
const asyncKw = body.async ? "async " : "";
|
|
132
|
+
const genMark = body.generator ? "*" : "";
|
|
133
|
+
const src = `return ${asyncKw}function${genMark} ${id}(${params}) {\n${inner}\n}`;
|
|
134
|
+
// Use a plain Function wrapper to evaluate the named function expression.
|
|
135
|
+
const builtNamed = (new Function(src)()) as AnyFunction;
|
|
136
|
+
// Expose the intended display name even if sanitization changed the identifier.
|
|
137
|
+
try { (builtNamed as any).displayName = name; } catch { /* noop */ }
|
|
138
|
+
return builtNamed;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const built = func(params, inner) as AnyFunction;
|
|
142
|
+
return built;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function constructFunction(bodyStr: string, name?: string) {
|
|
146
|
+
const { body } = parseJavaScript(bodyStr);
|
|
147
|
+
if (body.type === "Program") {
|
|
148
|
+
if (body.body.length !== 1) {
|
|
149
|
+
throw new Error(`Expected a single function, but found ${body.body.length} statements`);
|
|
150
|
+
}
|
|
151
|
+
return _constructFunction(body.body[0], bodyStr, name);
|
|
152
|
+
}
|
|
153
|
+
return _constructFunction(body, bodyStr, name);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const html2notebook = (html: string): Notebook => deserialize(html);
|
|
157
|
+
export const notebook2html = (notebook: Notebook): string => serialize(notebook);
|
package/src/util.ts
CHANGED
|
@@ -1,105 +1,8 @@
|
|
|
1
|
-
import { type Notebook, type Cell,
|
|
1
|
+
import { type Notebook, type Cell, toNotebook, toCell } from "./kit/index.ts";
|
|
2
2
|
|
|
3
3
|
import type { ohq } from "./observable-shim.ts";
|
|
4
4
|
import { parseCell, splitModule } from "./observable-shim.ts";
|
|
5
5
|
|
|
6
|
-
// Shared function constructor utilities to avoid duplication between util modules.
|
|
7
|
-
|
|
8
|
-
export type RegularFunction = (...args: any[]) => any;
|
|
9
|
-
interface RegularFunctionConstructor {
|
|
10
|
-
new(...args: string[]): RegularFunction;
|
|
11
|
-
(...args: string[]): RegularFunction;
|
|
12
|
-
readonly prototype: RegularFunction;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
16
|
-
interface AsyncFunctionConstructor {
|
|
17
|
-
new(...args: string[]): AsyncFunction;
|
|
18
|
-
(...args: string[]): AsyncFunction;
|
|
19
|
-
readonly prototype: AsyncFunction;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type GeneratorFunction = (...args: any[]) => Generator<any, any, any>;
|
|
23
|
-
interface GeneratorFunctionConstructor {
|
|
24
|
-
new(...args: string[]): GeneratorFunction;
|
|
25
|
-
(...args: string[]): GeneratorFunction;
|
|
26
|
-
readonly prototype: GeneratorFunction;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type AsyncGeneratorFunction = (...args: any[]) => AsyncGenerator<any, any, any>;
|
|
30
|
-
interface AsyncGeneratorFunctionConstructor {
|
|
31
|
-
new(...args: string[]): AsyncGeneratorFunction;
|
|
32
|
-
(...args: string[]): AsyncGeneratorFunction;
|
|
33
|
-
readonly prototype: AsyncGeneratorFunction;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type AnyFunction = RegularFunction | AsyncFunction | GeneratorFunction | AsyncGeneratorFunction;
|
|
37
|
-
|
|
38
|
-
export const FunctionConstructors: {
|
|
39
|
-
regular: RegularFunctionConstructor;
|
|
40
|
-
async: AsyncFunctionConstructor;
|
|
41
|
-
generator: GeneratorFunctionConstructor;
|
|
42
|
-
asyncGenerator: AsyncGeneratorFunctionConstructor;
|
|
43
|
-
} = {
|
|
44
|
-
regular: Object.getPrototypeOf(function () { }).constructor as RegularFunctionConstructor,
|
|
45
|
-
async: Object.getPrototypeOf(async function () { }).constructor as AsyncFunctionConstructor,
|
|
46
|
-
generator: Object.getPrototypeOf(function* () { }).constructor as GeneratorFunctionConstructor,
|
|
47
|
-
asyncGenerator: Object.getPrototypeOf(async function* () { }).constructor as AsyncGeneratorFunctionConstructor,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
function funcType(async: boolean = false, generator: boolean = false) {
|
|
51
|
-
if (!async && !generator) return FunctionConstructors.regular;
|
|
52
|
-
if (async && !generator) return FunctionConstructors.async;
|
|
53
|
-
if (!async && generator) return FunctionConstructors.generator;
|
|
54
|
-
return FunctionConstructors.asyncGenerator;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface Ref {
|
|
58
|
-
start: number,
|
|
59
|
-
end: number,
|
|
60
|
-
newText: string
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface Refs {
|
|
64
|
-
inputs: string[];
|
|
65
|
-
args: string[];
|
|
66
|
-
patches: Ref[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function createFunction(refs: Refs, async = false, generator = false, blockStatement = false, body?: string) {
|
|
70
|
-
if (body === undefined) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
refs.patches.sort((l, r) => r.start - l.start);
|
|
75
|
-
refs.patches.forEach(r => {
|
|
76
|
-
body = body!.substring(0, r.start) + r.newText + body!.substring(r.end);
|
|
77
|
-
});
|
|
78
|
-
return new (funcType(async, generator))(...refs.args, blockStatement ?
|
|
79
|
-
body.substring(1, body.length - 1).trim() :
|
|
80
|
-
`return (\n${body}\n);`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function join(baseURL: string, relativeURL: string) {
|
|
84
|
-
return relativeURL
|
|
85
|
-
? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "")
|
|
86
|
-
: baseURL;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const isRelativePath = (path: string) => path[0] === ".";
|
|
90
|
-
export const fixRelativeUrl = (path: string, basePath: string) => {
|
|
91
|
-
if (isRelativePath(path)) {
|
|
92
|
-
return join(basePath, path);
|
|
93
|
-
}
|
|
94
|
-
return path;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Hide "import" from bundlers as they have a habit of replacing "import" with "require"
|
|
98
|
-
const obfuscatedImportFunction = new FunctionConstructors.async("url", "return import(url)");
|
|
99
|
-
export async function obfuscatedImport(url: string) {
|
|
100
|
-
return obfuscatedImportFunction(url);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
6
|
interface ParsedOJS {
|
|
104
7
|
ojs: string;
|
|
105
8
|
offset: number;
|
|
@@ -250,39 +153,3 @@ export function download(impUrl: string, proxyPrefix?: string, proxyPostfix?: st
|
|
|
250
153
|
.then(r => r.json())
|
|
251
154
|
;
|
|
252
155
|
}
|
|
253
|
-
|
|
254
|
-
function _constructFunction(body, bodyStr: string) {
|
|
255
|
-
if (body.type !== "FunctionExpression" && body.type !== "FunctionDeclaration" && body.type !== "ArrowFunctionExpression") {
|
|
256
|
-
throw new Error(`Unsupported function type: ${body.type}`);
|
|
257
|
-
}
|
|
258
|
-
const func = body.async && body.generator ?
|
|
259
|
-
FunctionConstructors.asyncGenerator :
|
|
260
|
-
body.async ?
|
|
261
|
-
FunctionConstructors.async :
|
|
262
|
-
body.generator ?
|
|
263
|
-
FunctionConstructors.generator :
|
|
264
|
-
FunctionConstructors.regular;
|
|
265
|
-
|
|
266
|
-
const params = body.params?.map((param) => bodyStr.slice(param.start, param.end)).join(", ") ?? "";
|
|
267
|
-
const isBlock = body.body.type === "BlockStatement";
|
|
268
|
-
const { start, end } = body.body;
|
|
269
|
-
const inner = isBlock
|
|
270
|
-
? bodyStr.slice(start + 1, end - 1)
|
|
271
|
-
: `return ${bodyStr.slice(start, end)}`;
|
|
272
|
-
return func(params, inner);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function constructFunction(bodyStr: string) {
|
|
276
|
-
const { body } = parseJavaScript(bodyStr);
|
|
277
|
-
if (body.type === "Program") {
|
|
278
|
-
if (body.body.length !== 1) {
|
|
279
|
-
throw new Error(`Expected a single function, but found ${body.body.length} statements`);
|
|
280
|
-
}
|
|
281
|
-
return _constructFunction(body.body[0], bodyStr);
|
|
282
|
-
}
|
|
283
|
-
return _constructFunction(body, bodyStr);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export const html2notebook = (html: string): Notebook => deserialize(html);
|
|
287
|
-
export const notebook2html = (notebook: Notebook): string => serialize(notebook);
|
|
288
|
-
|
package/types/compiler.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type Notebook } from "
|
|
2
|
-
import { type Definition } from "@observablehq/notebook-kit/runtime";
|
|
1
|
+
import { type Notebook, type Definition } from "./kit/index.ts";
|
|
3
2
|
import { ohq } from "./observable-shim.ts";
|
|
4
3
|
import { Writer } from "./writer.ts";
|
|
5
4
|
export type InspectorFactoryEx = (name: string | undefined, id: string | number) => Inspector;
|
|
@@ -75,7 +74,6 @@ export declare function notebook(_files?: ohq.File[], _cells?: CellFunc[], { bas
|
|
|
75
74
|
toString(w?: Writer): string;
|
|
76
75
|
};
|
|
77
76
|
type NotebookFunc = ReturnType<typeof notebook>;
|
|
78
|
-
export declare function compileKit(notebook: Notebook): Definition[];
|
|
79
77
|
export declare function isNotebookKit(value: any): value is Notebook;
|
|
80
78
|
export declare function isOhqNotebook(value: any): value is ohq.Notebook;
|
|
81
79
|
export declare function compile(notebookOrOjs: Notebook): Promise<Definition[]>;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ohq } from "./observable-shim.ts";
|
|
2
2
|
export * from "./compiler.ts";
|
|
3
|
-
export { ojs2notebook, omd2notebook, omd2notebookKit, ojs2notebookKit, download
|
|
3
|
+
export { ojs2notebook, omd2notebook, omd2notebookKit, ojs2notebookKit, download } from "./util.ts";
|
|
4
|
+
export { compile as compileKit, html2notebook, notebook2html } from "./kit/index.ts";
|
|
4
5
|
export * from "./writer.ts";
|
|
5
|
-
import "../src/index.css";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Notebook } from "@observablehq/notebook-kit";
|
|
2
|
+
import { type Definition } from "@observablehq/notebook-kit/runtime";
|
|
3
|
+
export interface CompileKitOptions {
|
|
4
|
+
inline?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function compile(notebook: Notebook, options?: CompileKitOptions): Definition[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DefineState, NotebookRuntime as NotebookRuntimeBase } from "@observablehq/notebook-kit/runtime";
|
|
2
|
+
import { type Definition } from "./index.ts";
|
|
3
|
+
import "@observablehq/notebook-kit/index.css";
|
|
4
|
+
import "@observablehq/notebook-kit/theme-air.css";
|
|
5
|
+
export declare class NotebookRuntime extends NotebookRuntimeBase {
|
|
6
|
+
stateById: Map<number, DefineState>;
|
|
7
|
+
constructor();
|
|
8
|
+
has(cellId: number): boolean;
|
|
9
|
+
add(cellId: number, definition: Definition, placeholderDiv: HTMLDivElement): Promise<void>;
|
|
10
|
+
remove(cellId: number): Promise<void>;
|
|
11
|
+
removeAll(): Promise<void>;
|
|
12
|
+
render(definitions: Definition[], target: HTMLElement): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Notebook, type Cell, toNotebook, toCell } from "@observablehq/notebook-kit";
|
|
2
|
+
import { type Definition } from "@observablehq/notebook-kit/runtime";
|
|
3
|
+
export type { Notebook, Cell, Definition };
|
|
4
|
+
export { toNotebook, toCell };
|
|
5
|
+
export type RegularFunction = (...args: any[]) => any;
|
|
6
|
+
interface RegularFunctionConstructor {
|
|
7
|
+
new (...args: string[]): RegularFunction;
|
|
8
|
+
(...args: string[]): RegularFunction;
|
|
9
|
+
readonly prototype: RegularFunction;
|
|
10
|
+
}
|
|
11
|
+
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
12
|
+
interface AsyncFunctionConstructor {
|
|
13
|
+
new (...args: string[]): AsyncFunction;
|
|
14
|
+
(...args: string[]): AsyncFunction;
|
|
15
|
+
readonly prototype: AsyncFunction;
|
|
16
|
+
}
|
|
17
|
+
export type GeneratorFunction = (...args: any[]) => Generator<any, any, any>;
|
|
18
|
+
interface GeneratorFunctionConstructor {
|
|
19
|
+
new (...args: string[]): GeneratorFunction;
|
|
20
|
+
(...args: string[]): GeneratorFunction;
|
|
21
|
+
readonly prototype: GeneratorFunction;
|
|
22
|
+
}
|
|
23
|
+
export type AsyncGeneratorFunction = (...args: any[]) => AsyncGenerator<any, any, any>;
|
|
24
|
+
interface AsyncGeneratorFunctionConstructor {
|
|
25
|
+
new (...args: string[]): AsyncGeneratorFunction;
|
|
26
|
+
(...args: string[]): AsyncGeneratorFunction;
|
|
27
|
+
readonly prototype: AsyncGeneratorFunction;
|
|
28
|
+
}
|
|
29
|
+
export type AnyFunction = RegularFunction | AsyncFunction | GeneratorFunction | AsyncGeneratorFunction;
|
|
30
|
+
export declare const FunctionConstructors: {
|
|
31
|
+
regular: RegularFunctionConstructor;
|
|
32
|
+
async: AsyncFunctionConstructor;
|
|
33
|
+
generator: GeneratorFunctionConstructor;
|
|
34
|
+
asyncGenerator: AsyncGeneratorFunctionConstructor;
|
|
35
|
+
};
|
|
36
|
+
interface Ref {
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
newText: string;
|
|
40
|
+
}
|
|
41
|
+
export interface Refs {
|
|
42
|
+
inputs: string[];
|
|
43
|
+
args: string[];
|
|
44
|
+
patches: Ref[];
|
|
45
|
+
}
|
|
46
|
+
export declare function createFunction(refs: Refs, async?: boolean, generator?: boolean, blockStatement?: boolean, body?: string): RegularFunction | undefined;
|
|
47
|
+
export declare const isRelativePath: (path: string) => boolean;
|
|
48
|
+
export declare const fixRelativeUrl: (path: string, basePath: string) => string;
|
|
49
|
+
export declare function obfuscatedImport(url: string): Promise<any>;
|
|
50
|
+
export declare function constructFunction(bodyStr: string, name?: string): AnyFunction;
|
|
51
|
+
export declare const html2notebook: (html: string) => Notebook;
|
|
52
|
+
export declare const notebook2html: (notebook: Notebook) => string;
|
package/types/util.d.ts
CHANGED
|
@@ -1,50 +1,5 @@
|
|
|
1
|
-
import { type Notebook } from "
|
|
1
|
+
import { type Notebook } from "./kit/index.ts";
|
|
2
2
|
import type { ohq } from "./observable-shim.ts";
|
|
3
|
-
export type RegularFunction = (...args: any[]) => any;
|
|
4
|
-
interface RegularFunctionConstructor {
|
|
5
|
-
new (...args: string[]): RegularFunction;
|
|
6
|
-
(...args: string[]): RegularFunction;
|
|
7
|
-
readonly prototype: RegularFunction;
|
|
8
|
-
}
|
|
9
|
-
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
10
|
-
interface AsyncFunctionConstructor {
|
|
11
|
-
new (...args: string[]): AsyncFunction;
|
|
12
|
-
(...args: string[]): AsyncFunction;
|
|
13
|
-
readonly prototype: AsyncFunction;
|
|
14
|
-
}
|
|
15
|
-
export type GeneratorFunction = (...args: any[]) => Generator<any, any, any>;
|
|
16
|
-
interface GeneratorFunctionConstructor {
|
|
17
|
-
new (...args: string[]): GeneratorFunction;
|
|
18
|
-
(...args: string[]): GeneratorFunction;
|
|
19
|
-
readonly prototype: GeneratorFunction;
|
|
20
|
-
}
|
|
21
|
-
export type AsyncGeneratorFunction = (...args: any[]) => AsyncGenerator<any, any, any>;
|
|
22
|
-
interface AsyncGeneratorFunctionConstructor {
|
|
23
|
-
new (...args: string[]): AsyncGeneratorFunction;
|
|
24
|
-
(...args: string[]): AsyncGeneratorFunction;
|
|
25
|
-
readonly prototype: AsyncGeneratorFunction;
|
|
26
|
-
}
|
|
27
|
-
export type AnyFunction = RegularFunction | AsyncFunction | GeneratorFunction | AsyncGeneratorFunction;
|
|
28
|
-
export declare const FunctionConstructors: {
|
|
29
|
-
regular: RegularFunctionConstructor;
|
|
30
|
-
async: AsyncFunctionConstructor;
|
|
31
|
-
generator: GeneratorFunctionConstructor;
|
|
32
|
-
asyncGenerator: AsyncGeneratorFunctionConstructor;
|
|
33
|
-
};
|
|
34
|
-
interface Ref {
|
|
35
|
-
start: number;
|
|
36
|
-
end: number;
|
|
37
|
-
newText: string;
|
|
38
|
-
}
|
|
39
|
-
export interface Refs {
|
|
40
|
-
inputs: string[];
|
|
41
|
-
args: string[];
|
|
42
|
-
patches: Ref[];
|
|
43
|
-
}
|
|
44
|
-
export declare function createFunction(refs: Refs, async?: boolean, generator?: boolean, blockStatement?: boolean, body?: string): RegularFunction | undefined;
|
|
45
|
-
export declare const isRelativePath: (path: string) => boolean;
|
|
46
|
-
export declare const fixRelativeUrl: (path: string, basePath: string) => string;
|
|
47
|
-
export declare function obfuscatedImport(url: string): Promise<any>;
|
|
48
3
|
interface ParsedOJS {
|
|
49
4
|
ojs: string;
|
|
50
5
|
offset: number;
|
|
@@ -60,7 +15,4 @@ export declare function omd2notebook(omd: string): ohq.Notebook;
|
|
|
60
15
|
export declare function omd2notebookKit(omd: string): Notebook;
|
|
61
16
|
export declare function fetchEx(url: string, proxyPrefix?: string, proxyPostfix?: string): Promise<Response>;
|
|
62
17
|
export declare function download(impUrl: string, proxyPrefix?: string, proxyPostfix?: string): Promise<ohq.Notebook>;
|
|
63
|
-
export declare function constructFunction(bodyStr: string): RegularFunction;
|
|
64
|
-
export declare const html2notebook: (html: string) => Notebook;
|
|
65
|
-
export declare const notebook2html: (notebook: Notebook) => string;
|
|
66
18
|
export {};
|