some styling cleanup

This commit is contained in:
Nystik
2026-03-17 12:38:30 +01:00
parent c70b9e9d0f
commit 0738c47ac5
27 changed files with 479 additions and 105 deletions

View File

@@ -20,7 +20,10 @@ const DEBUG = true;
const _accessLog = new Map(); // "module.property" -> count
function wrapWithProxy(obj, name) {
if (!DEBUG || !obj || typeof obj !== "object") return obj;
if (!DEBUG || !obj || typeof obj !== "object") {
return obj;
}
return new Proxy(obj, {
get(target, prop) {
if (
@@ -31,10 +34,12 @@ function wrapWithProxy(obj, name) {
) {
const key = `${name}.${prop}`;
_accessLog.set(key, (_accessLog.get(key) || 0) + 1);
if (!(prop in target)) {
console.warn(`[shim:MISS] ${key} - property not found on shim`);
}
}
return target[prop];
},
});
@@ -44,6 +49,7 @@ window.__shimLog = function () {
const sorted = [..._accessLog.entries()].sort((a, b) => b[1] - a[1]);
console.table(sorted.map(([k, v]) => ({ api: k, calls: v })));
};
window.__shimMisses = function () {
const sorted = [..._accessLog.entries()]
.filter(([k]) => {
@@ -52,6 +58,7 @@ window.__shimMisses = function () {
return shim && !(prop in shim);
})
.sort((a, b) => b[1] - a[1]);
console.table(sorted.map(([k, v]) => ({ api: k, calls: v })));
};
@@ -82,9 +89,11 @@ window.require = function (moduleName) {
if (throwOnRequire.has(moduleName)) {
throw new Error(`Cannot find module '${moduleName}'`);
}
if (shimRegistry[moduleName]) {
return shimRegistry[moduleName];
}
console.warn("[ignis] Unshimmed require:", moduleName);
return wrapWithProxy({}, `UNKNOWN(${moduleName})`);
};
@@ -97,19 +106,23 @@ if (typeof window.Buffer === "undefined") {
if (typeof data === "string") {
return new TextEncoder().encode(data);
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
return new Uint8Array(data);
},
concat: function (arrays) {
const total = arrays.reduce((sum, a) => sum + a.length, 0);
const result = new Uint8Array(total);
let offset = 0;
for (const arr of arrays) {
result.set(arr, offset);
offset += arr.length;
}
return result;
},
isBuffer: function (obj) {
@@ -127,29 +140,37 @@ const _originalOpen = window.open;
window.open = function (url, target, features) {
if (url === "about:blank" || (features && features.includes("popup"))) {
console.log("[ignis] intercepted popup:", url, features);
registerPopupWindow();
const iframe = document.createElement("iframe");
iframe.style.cssText =
"position:fixed;left:-9999px;width:0;height:0;border:none;";
document.body.appendChild(iframe);
window.__popupIframe = iframe;
const iframeWin = iframe.contentWindow;
iframeWin.require = window.require;
iframeWin.module = window.module;
iframeWin.Buffer = window.Buffer;
iframeWin.process = window.process;
iframeWin.global = iframeWin;
iframeWin.globalEnhance = window.globalEnhance;
iframeWin.close = function () {
unregisterPopupWindow();
iframe.remove();
window.__popupIframe = null;
};
return iframeWin;
}
return _originalOpen.call(window, url, target, features);
};
// hacky fix to prevent browser from showing context menu while allowing obsidian context menu
window.addEventListener(
"contextmenu",
(e) => {
@@ -167,17 +188,23 @@ window.__currentVaultId = _urlParams.get("vault") || "";
const vaultParam = window.__currentVaultId
? "?vault=" + encodeURIComponent(window.__currentVaultId)
: "";
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/vault/info" + vaultParam, false);
xhr.send();
if (xhr.status === 200) {
const info = JSON.parse(xhr.responseText);
window.__currentVaultId = info.id;
window.__obsidianVersion = info.version || "0.0.0";
window.__vaultConfig = {
id: info.id,
path: "/",
};
console.log("[ignis] Vault:", window.__vaultConfig);
console.log("[ignis] Obsidian version:", window.__obsidianVersion);
} else {
@@ -191,8 +218,10 @@ window.__currentVaultId = _urlParams.get("vault") || "";
(function initVaultList() {
try {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/vault/list", false);
xhr.send();
if (xhr.status === 200) {
window.__vaultList = JSON.parse(xhr.responseText);
}
@@ -206,14 +235,19 @@ window.__currentVaultId = _urlParams.get("vault") || "";
const vaultParam = window.__currentVaultId
? "?vault=" + encodeURIComponent(window.__currentVaultId)
: "";
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/fs/tree" + vaultParam, false);
xhr.send();
if (xhr.status === 200) {
const tree = JSON.parse(xhr.responseText);
fsShim._metadataCache.populate(tree);
fsShim._metadataCache.set("", { type: "directory" });
fsShim._metadataCache.set("/", { type: "directory" });
console.log(
"[ignis] Metadata cache populated:",
fsShim._metadataCache.size,