diff --git a/src/client/index.ts b/src/client/index.ts index 2850b72..309579a 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -15,8 +15,6 @@ import "./scope.ts"; declare global { interface Window { - __location: Location; - __window: Window; //@ts-ignore scope function cant be typed __s: any; } @@ -37,4 +35,4 @@ for (const script of scripts) { script.insertAdjacentElement("afterend", clone); script.remove(); -} \ No newline at end of file +} diff --git a/src/client/location.ts b/src/client/location.ts index 87068b3..42058aa 100644 --- a/src/client/location.ts +++ b/src/client/location.ts @@ -7,28 +7,24 @@ function urlLocation() { loc.reload = () => location.reload(); loc.replace = (url: string) => location.replace(encodeUrl(url)); loc.toString = () => loc.href; - + return loc; } -export function LocationProxy() { - const loc = urlLocation(); +const loc = urlLocation(); +export const locationProxy = new Proxy(window.location, { + get(target, prop) { + return loc[prop]; + }, - return new Proxy(window.location, { - get(target, prop) { - return loc[prop]; - }, - - set(obj, prop, value) { - if (prop === "href") { - location.href = encodeUrl(value); - } else { - loc[prop] = value; - } - - return true; + set(obj, prop, value) { + if (prop === "href") { + location.href = encodeUrl(value); + } else { + loc[prop] = value; } - }) -} -window.__location = LocationProxy(); \ No newline at end of file + return true; + } +}) + diff --git a/src/client/scope.ts b/src/client/scope.ts index 7d4ee6f..a4abf47 100644 --- a/src/client/scope.ts +++ b/src/client/scope.ts @@ -1,12 +1,15 @@ +import { locationProxy } from "./location"; +import { windowProxy } from "./window"; + function scope(identifier: any) { if (identifier instanceof Window) { - return window.__window; + return windowProxy; } else if (identifier instanceof Location) { - return window.__location; + return locationProxy; } return identifier; } // shorthand because this can get out of hand reall quickly -window.__s = scope; \ No newline at end of file +window.__s = scope; diff --git a/src/client/storage.ts b/src/client/storage.ts index 28142fd..f81bfc6 100644 --- a/src/client/storage.ts +++ b/src/client/storage.ts @@ -1,5 +1,7 @@ import IDBMapSync from "@webreflection/idb-map/sync"; -const store = new IDBMapSync(window.__location.host, { +import { locationProxy } from "./location"; + +const store = new IDBMapSync(locationProxy.host, { prefix: "Storage", durability: "relaxed" }); diff --git a/src/client/window.ts b/src/client/window.ts index d80702f..8477002 100644 --- a/src/client/window.ts +++ b/src/client/window.ts @@ -1,10 +1,12 @@ -const windowProxy = new Proxy(window, { +import { locationProxy } from "./location"; + +export const windowProxy = new Proxy(window, { get(target, prop) { const propIsString = typeof prop === "string"; if (propIsString && prop === "location") { - return target.__location; + return locationProxy; } else if (propIsString && ["window", "top", "parent", "self", "globalThis"].includes(prop)) { - return target.__window; + return windowProxy; } return target[prop]; @@ -19,5 +21,3 @@ const windowProxy = new Proxy(window, { return Reflect.set(target, prop, newValue); }, }); - -window.__window = windowProxy; \ No newline at end of file