foss-design 0.9.4 → 0.9.6

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.
@@ -1,3 +1,57 @@
1
+ // src/runtime/storage.ts
2
+ var frame = new URLSearchParams(location.search).get("__design") || location.pathname;
3
+ function memoryStorage() {
4
+ const data = /* @__PURE__ */ new Map();
5
+ const api = {
6
+ get length() {
7
+ return data.size;
8
+ },
9
+ clear: () => data.clear(),
10
+ getItem: (key) => data.get(String(key)) ?? null,
11
+ key: (index) => [...data.keys()][index] ?? null,
12
+ removeItem: (key) => void data.delete(String(key)),
13
+ setItem: (key, value) => void data.set(String(key), String(value))
14
+ };
15
+ return new Proxy(api, {
16
+ get: (target, prop) => typeof prop === "string" && !(prop in target) ? data.get(prop) ?? void 0 : Reflect.get(target, prop),
17
+ set: (target, prop, value) => {
18
+ if (typeof prop === "string" && !(prop in target)) data.set(prop, String(value));
19
+ return true;
20
+ },
21
+ deleteProperty: (_, prop) => typeof prop === "string" ? data.delete(prop) || true : true,
22
+ has: (target, prop) => typeof prop === "string" && data.has(prop) || prop in target,
23
+ ownKeys: () => [...data.keys()],
24
+ getOwnPropertyDescriptor: (_, prop) => typeof prop === "string" && data.has(prop) ? { value: data.get(prop), writable: true, enumerable: true, configurable: true } : void 0
25
+ });
26
+ }
27
+ for (const name of ["localStorage", "sessionStorage"]) {
28
+ try {
29
+ Object.defineProperty(window, name, { configurable: true, value: memoryStorage() });
30
+ } catch {
31
+ }
32
+ }
33
+ var idb = window.indexedDB;
34
+ if (idb) {
35
+ const own = `design:${frame}:`;
36
+ const prefix = `${own}${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}:`;
37
+ const open = idb.open.bind(idb);
38
+ const remove = idb.deleteDatabase.bind(idb);
39
+ const list = idb.databases?.bind(idb);
40
+ idb.open = (name, version) => open(prefix + name, version);
41
+ idb.deleteDatabase = (name) => remove(prefix + name);
42
+ if (list) {
43
+ idb.databases = async () => (await list()).filter((db) => db.name?.startsWith(prefix)).map((db) => ({ ...db, name: db.name.slice(prefix.length) }));
44
+ void list().then((dbs) => {
45
+ for (const db of dbs) {
46
+ if (!db.name?.startsWith(own) || db.name.startsWith(prefix)) continue;
47
+ const born = Number.parseInt(db.name.slice(own.length).split(":")[0].slice(0, -4), 36);
48
+ if (!Number.isFinite(born) || Date.now() - born > 10 * 60 * 1e3) remove(db.name);
49
+ }
50
+ }).catch(() => {
51
+ });
52
+ }
53
+ }
54
+
1
55
  // src/runtime/index.tsx
2
56
  import { Component, useSyncExternalStore as useSyncExternalStore2 } from "react";
3
57
  import { createRoot } from "react-dom/client";