@hpcc-js/observablehq-compiler 3.3.9 → 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.
Files changed (59) hide show
  1. package/dist/dot-DK4iDc2-.js +40 -0
  2. package/dist/dot-DK4iDc2-.js.map +1 -0
  3. package/dist/duckdb-DkM9_nXT.js +298 -0
  4. package/dist/duckdb-DkM9_nXT.js.map +1 -0
  5. package/dist/highlight-Bv8PkwN-.js +2402 -0
  6. package/dist/highlight-Bv8PkwN-.js.map +1 -0
  7. package/dist/index-B7vRtYlU.js +1807 -0
  8. package/dist/index-B7vRtYlU.js.map +1 -0
  9. package/dist/index-COHaJzee.js +260 -0
  10. package/dist/index-COHaJzee.js.map +1 -0
  11. package/dist/index-CP3HrqN0.js +1815 -0
  12. package/dist/index-CP3HrqN0.js.map +1 -0
  13. package/dist/index-D3TL70UM.js +163 -0
  14. package/dist/index-D3TL70UM.js.map +1 -0
  15. package/dist/index-DNwLE6Kk.js +198 -0
  16. package/dist/index-DNwLE6Kk.js.map +1 -0
  17. package/dist/index.js +1716 -302
  18. package/dist/index.js.map +1 -1
  19. package/dist/inputs-CsCXZHQ8.js +3 -0
  20. package/dist/inputs-CsCXZHQ8.js.map +1 -0
  21. package/dist/leaflet-CkvVhxBL.js +9 -0
  22. package/dist/leaflet-CkvVhxBL.js.map +1 -0
  23. package/dist/mapboxgl-C0i2HzjJ.js +9 -0
  24. package/dist/mapboxgl-C0i2HzjJ.js.map +1 -0
  25. package/dist/md-Bxvu6Hld.js +7603 -0
  26. package/dist/md-Bxvu6Hld.js.map +1 -0
  27. package/dist/mermaid-CFg6sgdO.js +17 -0
  28. package/dist/mermaid-CFg6sgdO.js.map +1 -0
  29. package/dist/node/index.cjs +32 -0
  30. package/dist/node/index.cjs.map +7 -0
  31. package/dist/node/index.js +32 -0
  32. package/dist/node/index.js.map +7 -0
  33. package/dist/runtime.js +2501 -0
  34. package/dist/runtime.js.map +1 -0
  35. package/dist/tex-ayRXOMLZ.js +24 -0
  36. package/dist/tex-ayRXOMLZ.js.map +1 -0
  37. package/dist/vega-lite-CESXoehe.js +8 -0
  38. package/dist/vega-lite-CESXoehe.js.map +1 -0
  39. package/package.json +18 -10
  40. package/src/__package__.ts +2 -2
  41. package/src/compiler.ts +23 -6
  42. package/src/cst.ts +1 -2
  43. package/src/index.node.ts +7 -0
  44. package/src/index.ts +2 -3
  45. package/src/kit/compiler.ts +41 -0
  46. package/src/kit/index.ts +3 -0
  47. package/src/kit/runtime.ts +57 -0
  48. package/src/kit/util.ts +157 -0
  49. package/src/util.ts +36 -60
  50. package/types/compiler.d.ts +8 -36
  51. package/types/index.d.ts +2 -2
  52. package/types/kit/compiler.d.ts +6 -0
  53. package/types/kit/index.d.ts +3 -0
  54. package/types/kit/runtime.d.ts +13 -0
  55. package/types/kit/util.d.ts +52 -0
  56. package/types/util.d.ts +3 -14
  57. package/dist/index.umd.cjs +0 -5
  58. package/dist/index.umd.cjs.map +0 -1
  59. package/src/index.css +0 -460
@@ -0,0 +1,41 @@
1
+
2
+ import { type Notebook, transpile } from "@observablehq/notebook-kit";
3
+ import { type Definition } from "@observablehq/notebook-kit/runtime";
4
+ import { constructFunction } from "./util.ts";
5
+
6
+ export interface CompileKitOptions {
7
+ inline?: boolean;
8
+ }
9
+
10
+ export function compile(notebook: Notebook, options: CompileKitOptions = { inline: true }): Definition[] {
11
+ const retVal: Definition[] = [];
12
+ let id = 1;
13
+ for (const cell of notebook.cells) {
14
+ try {
15
+ const compiled = transpile(cell);
16
+ retVal.push({
17
+ id: id++,
18
+ ...compiled,
19
+ body: options.inline ? constructFunction(compiled.body, `cell_${id}`) : compiled.body,
20
+ });
21
+ if (cell.pinned) {
22
+ const compiled = transpile({
23
+ ...cell,
24
+ mode: "md",
25
+ value: `\
26
+ \`\`\`${cell.mode}
27
+ ${cell.value}
28
+ \`\`\``
29
+ });
30
+ retVal.push({
31
+ id: id++,
32
+ ...compiled,
33
+ body: options.inline ? constructFunction(compiled.body, `cell_${id}`) : compiled.body,
34
+ });
35
+ }
36
+ } catch (error) {
37
+ console.error(`Error compiling cell ${id}:`, error);
38
+ }
39
+ }
40
+ return retVal;
41
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./util.ts";
2
+ export * from "./compiler.ts";
3
+ export * from "./util.ts";
@@ -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
+ }
@@ -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,65 +1,8 @@
1
+ import { type Notebook, type Cell, toNotebook, toCell } from "./kit/index.ts";
2
+
1
3
  import type { ohq } from "./observable-shim.ts";
2
4
  import { parseCell, splitModule } from "./observable-shim.ts";
3
5
 
4
- const FuncTypes = {
5
- functionType: Object.getPrototypeOf(function () { }).constructor,
6
- asyncFunctionType: Object.getPrototypeOf(async function () { }).constructor,
7
- generatorFunctionType: Object.getPrototypeOf(function* () { }).constructor,
8
- asyncGeneratorFunctionType: Object.getPrototypeOf(async function* () { }).constructor
9
- };
10
-
11
- function funcType(async: boolean = false, generator: boolean = false) {
12
- if (!async && !generator) return FuncTypes.functionType;
13
- if (async && !generator) return FuncTypes.asyncFunctionType;
14
- if (!async && generator) return FuncTypes.generatorFunctionType;
15
- return FuncTypes.asyncGeneratorFunctionType;
16
- }
17
-
18
- interface Ref {
19
- start: number,
20
- end: number,
21
- newText: string
22
- }
23
-
24
- export interface Refs {
25
- inputs: string[];
26
- args: string[];
27
- patches: Ref[];
28
- }
29
-
30
- export function createFunction(refs: Refs, async = false, generator = false, blockStatement = false, body?: string) {
31
- if (body === undefined) {
32
- return undefined;
33
- }
34
-
35
- refs.patches.sort((l, r) => r.start - l.start);
36
- refs.patches.forEach(r => {
37
- body = body!.substring(0, r.start) + r.newText + body!.substring(r.end);
38
- });
39
- return new (funcType(async, generator))(...refs.args, blockStatement ?
40
- body.substring(1, body.length - 1).trim() :
41
- `return (\n${body}\n);`);
42
- }
43
-
44
- function join(baseURL: string, relativeURL: string) {
45
- return relativeURL
46
- ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "")
47
- : baseURL;
48
- }
49
-
50
- export const isRelativePath = (path: string) => path[0] === ".";
51
- export const fixRelativeUrl = (path: string, basePath: string) => {
52
- if (isRelativePath(path)) {
53
- return join(basePath, path);
54
- }
55
- return path;
56
- };
57
-
58
- // Hide "import" from bundlers as they have a habit of replacing "import" with "require"
59
- export async function obfuscatedImport(url: string) {
60
- return new FuncTypes.asyncFunctionType("url", "return import(url)")(url);
61
- }
62
-
63
6
  interface ParsedOJS {
64
7
  ojs: string;
65
8
  offset: number;
@@ -141,6 +84,17 @@ export function ojs2notebook(ojs: string): ohq.Notebook {
141
84
  } as ohq.Notebook;
142
85
  }
143
86
 
87
+ export function ojs2notebookKit(ojs: string): Notebook {
88
+ const cells: Cell[] = splitModule(ojs).map((cell, idx) => {
89
+ return toCell({
90
+ id: idx,
91
+ mode: "ojs",
92
+ value: cell.text
93
+ });
94
+ });
95
+ return toNotebook({ cells });
96
+ }
97
+
144
98
  export function omd2notebook(omd: string): ohq.Notebook {
145
99
  const cells = splitOmd(omd);
146
100
  return {
@@ -157,6 +111,28 @@ export function omd2notebook(omd: string): ohq.Notebook {
157
111
  } as ohq.Notebook;
158
112
  }
159
113
 
114
+ export function omd2notebookKit(omd: string): Notebook {
115
+ const cells: Cell[] = [];
116
+ splitOmd(omd).forEach((cell) => {
117
+ if (!cell.inlineMD) {
118
+ splitModule(cell.ojs).forEach((subCell) => {
119
+ cells.push(toCell({
120
+ id: cells.length + 1,
121
+ mode: "ojs",
122
+ value: subCell.text
123
+ }));
124
+ });
125
+ } else {
126
+ cells.push(toCell({
127
+ id: cells.length + 1,
128
+ mode: "md",
129
+ value: cell.ojs
130
+ }));
131
+ }
132
+ });
133
+ return toNotebook({ cells });
134
+ }
135
+
160
136
  export function fetchEx(url: string, proxyPrefix = "https://api.codetabs.com/v1/proxy/?quest=", proxyPostfix = "") {
161
137
  const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img);
162
138
  if (!matches || matches.length === 0) {
@@ -176,4 +152,4 @@ export function download(impUrl: string, proxyPrefix?: string, proxyPostfix?: st
176
152
  return fetchEx(impUrl.replace(`https://observablehq.com/${isShared ? "d/" : ""}`, "https://api.observablehq.com/document/"), proxyPrefix, proxyPostfix)
177
153
  .then(r => r.json())
178
154
  ;
179
- }
155
+ }
@@ -1,3 +1,4 @@
1
+ import { type Notebook, type Definition } from "./kit/index.ts";
1
2
  import { ohq } from "./observable-shim.ts";
2
3
  import { Writer } from "./writer.ts";
3
4
  export type InspectorFactoryEx = (name: string | undefined, id: string | number) => Inspector;
@@ -72,40 +73,11 @@ export declare function notebook(_files?: ohq.File[], _cells?: CellFunc[], { bas
72
73
  write(w: Writer): void;
73
74
  toString(w?: Writer): string;
74
75
  };
75
- export declare function compile(notebookOrOjs: ohq.Notebook | string, { baseUrl, importMode }?: CompileOptions): Promise<{
76
- (runtime: ohq.Runtime, inspector?: InspectorFactoryEx): ohq.Module;
77
- fileAttachments: Map<string, any>;
78
- cells: Map<string | number, {
79
- (runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): void;
80
- id: string | number;
81
- modules: {
82
- (runtime: ohq.Runtime, main: ohq.Module, inspector?: InspectorFactoryEx): ohq.Module;
83
- importVariables: {
84
- (main: ohq.Module, otherModule: ohq.Module): void;
85
- delete(): void;
86
- }[];
87
- variables: {
88
- (module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
89
- delete(): void;
90
- write(w: Writer): void;
91
- }[];
92
- delete(): void;
93
- write(w: Writer): void;
94
- }[];
95
- variables: {
96
- (module: ohq.Module, inspector?: InspectorFactoryEx): ohq.Variable;
97
- delete(): void;
98
- write(w: Writer): void;
99
- }[];
100
- delete(): void;
101
- write(w: Writer): void;
102
- }>;
103
- set(n: ohq.Node): Promise<CellFunc>;
104
- get(id: string | number): CellFunc | undefined;
105
- delete(id: string | number): boolean;
106
- clear(): void;
107
- write(w: Writer): void;
108
- toString(w?: Writer): string;
109
- }>;
110
- export type compileFunc = Awaited<ReturnType<typeof compile>>;
76
+ type NotebookFunc = ReturnType<typeof notebook>;
77
+ export declare function isNotebookKit(value: any): value is Notebook;
78
+ export declare function isOhqNotebook(value: any): value is ohq.Notebook;
79
+ export declare function compile(notebookOrOjs: Notebook): Promise<Definition[]>;
80
+ export declare function compile(notebookOrOjs: ohq.Notebook, options?: CompileOptions): Promise<NotebookFunc>;
81
+ export declare function compile(notebookOrOjs: string, options?: CompileOptions): Promise<NotebookFunc>;
82
+ export type CompileFunc = Awaited<ReturnType<typeof compile>>;
111
83
  export {};
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, download } from "./util.ts";
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,3 @@
1
+ export * from "./util.ts";
2
+ export * from "./compiler.ts";
3
+ export * from "./util.ts";
@@ -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,18 +1,5 @@
1
+ import { type Notebook } from "./kit/index.ts";
1
2
  import type { ohq } from "./observable-shim.ts";
2
- interface Ref {
3
- start: number;
4
- end: number;
5
- newText: string;
6
- }
7
- export interface Refs {
8
- inputs: string[];
9
- args: string[];
10
- patches: Ref[];
11
- }
12
- export declare function createFunction(refs: Refs, async?: boolean, generator?: boolean, blockStatement?: boolean, body?: string): any;
13
- export declare const isRelativePath: (path: string) => boolean;
14
- export declare const fixRelativeUrl: (path: string, basePath: string) => string;
15
- export declare function obfuscatedImport(url: string): Promise<any>;
16
3
  interface ParsedOJS {
17
4
  ojs: string;
18
5
  offset: number;
@@ -23,7 +10,9 @@ interface ParsedOJS {
23
10
  export declare function encodeBacktick(str: string): string;
24
11
  export declare function notebook2ojs(_: string): ParsedOJS[];
25
12
  export declare function ojs2notebook(ojs: string): ohq.Notebook;
13
+ export declare function ojs2notebookKit(ojs: string): Notebook;
26
14
  export declare function omd2notebook(omd: string): ohq.Notebook;
15
+ export declare function omd2notebookKit(omd: string): Notebook;
27
16
  export declare function fetchEx(url: string, proxyPrefix?: string, proxyPostfix?: string): Promise<Response>;
28
17
  export declare function download(impUrl: string, proxyPrefix?: string, proxyPostfix?: string): Promise<ohq.Notebook>;
29
18
  export {};