bunite-core 0.0.3 → 0.0.4
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunite-core",
|
|
3
3
|
"description": "Uniting UI and Bun",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"setup:cef": "bun ../tools/bunite-dev/scripts/setup-cef.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
".": "./src/bun/index.ts",
|
|
13
13
|
"./bun": "./src/bun/index.ts",
|
|
14
14
|
"./view": "./src/view/index.ts",
|
|
15
|
+
"./webview-polyfill": "./src/shared/webviewPolyfill.ts",
|
|
15
16
|
"./shared/rpc": "./src/shared/rpc.ts",
|
|
16
17
|
"./package.json": "./package.json"
|
|
17
18
|
},
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <bunite-webview> iframe polyfill — registered automatically via the
|
|
3
|
+
* bunite-dev vite plugin when the native bunite runtime is not available.
|
|
4
|
+
*
|
|
5
|
+
* In desktop CEF the native element is already registered by the preload
|
|
6
|
+
* runtime, so this module does nothing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
typeof customElements !== "undefined" &&
|
|
11
|
+
!customElements.get("bunite-webview")
|
|
12
|
+
) {
|
|
13
|
+
class BuniteWebviewPolyfill extends HTMLElement {
|
|
14
|
+
static observedAttributes = ["src"];
|
|
15
|
+
|
|
16
|
+
private _iframe: HTMLIFrameElement | null = null;
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
if (this._iframe) return;
|
|
20
|
+
|
|
21
|
+
const iframe = document.createElement("iframe");
|
|
22
|
+
iframe.style.cssText = "display:block;width:100%;height:100%;border:0;background:inherit;";
|
|
23
|
+
const src = this.getAttribute("src");
|
|
24
|
+
if (src) {
|
|
25
|
+
iframe.src = src;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
iframe.addEventListener("load", () => {
|
|
29
|
+
let url = iframe.src;
|
|
30
|
+
try {
|
|
31
|
+
url = iframe.contentWindow?.location.href ?? url;
|
|
32
|
+
} catch {}
|
|
33
|
+
|
|
34
|
+
this.dispatchEvent(new CustomEvent("did-navigate", { detail: { url } }));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this._iframe = iframe;
|
|
38
|
+
this.appendChild(iframe);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
disconnectedCallback() {
|
|
42
|
+
this._iframe?.remove();
|
|
43
|
+
this._iframe = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
|
|
47
|
+
if (name === "src" && this._iframe) {
|
|
48
|
+
this._iframe.src = newValue ?? "";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
navigate(url: string) {
|
|
53
|
+
this.setAttribute("src", url);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
goBack() {
|
|
57
|
+
try {
|
|
58
|
+
this._iframe?.contentWindow?.history.back();
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
reload() {
|
|
63
|
+
try {
|
|
64
|
+
this._iframe?.contentWindow?.location.reload();
|
|
65
|
+
} catch {
|
|
66
|
+
if (this._iframe) {
|
|
67
|
+
this._iframe.src = this._iframe.src;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setHidden(hidden: boolean) {
|
|
73
|
+
if (this._iframe) {
|
|
74
|
+
this._iframe.style.display = hidden ? "none" : "block";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
customElements.define("bunite-webview", BuniteWebviewPolyfill);
|
|
80
|
+
}
|