-
Notifications
You must be signed in to change notification settings - Fork 42
/
deno-dom-native.ts
58 lines (44 loc) · 1.48 KB
/
deno-dom-native.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
prepare,
PerpareOptions,
} from "https://raw.githubusercontent.com/b-fuze/deno-plugin-prepare/master/mod.ts";
import { register } from "./src/parser.ts";
const nativeEnv = "DENO_DOM_PLUGIN";
let denoNativePluginPath: string | undefined;
// Try to read the environment
try {
denoNativePluginPath = Deno.env.get(nativeEnv);
} catch {}
if (denoNativePluginPath) {
// Open native plugin and register the native `parse` function
Deno.openPlugin(denoNativePluginPath);
} else {
const releaseUrl = "https://github.com/b-fuze/deno-dom/releases/download/v0.1.12-alpha";
const pluginOptions: PerpareOptions = {
name: "test_plugin",
// Whether to output log. Optional, default is true
printLog: false,
// Whether to use locally cached files. Optional, default is true
// checkCache: true,
// Support "http://", "https://", "file://"
urls: {
darwin: releaseUrl + "/libplugin.dylib",
windows: releaseUrl + "/plugin.dll",
linux: releaseUrl + "/libplugin.so",
},
};
await prepare(pluginOptions);
}
interface DenoCore {
opSync(op: string, data1?: unknown, data2?: unknown): unknown;
};
const core = <DenoCore> (<any> <unknown> Deno).core;
function parse(html: string): string {
return core.opSync("deno_dom_parse_sync", html) as string;
}
function parseFrag(html: string): string {
return core.opSync("deno_dom_parse_frag_sync", html) as string;
}
// Register parse function
register(parse, parseFrag);
export * from "./src/api.ts";