@genome-spy/app 0.90.0 → 1.1.0

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.
@@ -0,0 +1,207 @@
1
+ //#region ../../node_modules/@gmod/shared-read-cache/esm/throwIfAborted.js
2
+ function e(e) {
3
+ if (e?.aborted) throw t(e);
4
+ }
5
+ function t(e) {
6
+ let t = e.reason;
7
+ return t === void 0 ? new DOMException("This operation was aborted", "AbortError") : t;
8
+ }
9
+ //#endregion
10
+ //#region ../../node_modules/@gmod/shared-read-cache/esm/SharedReadCache.js
11
+ function n(e) {
12
+ typeof e == "object" && e && "unref" in e && typeof e.unref == "function" && e.unref();
13
+ }
14
+ var r = class {
15
+ entries = /* @__PURE__ */ new Map();
16
+ total = 0;
17
+ settledCount = 0;
18
+ limit;
19
+ budget;
20
+ membership;
21
+ fill;
22
+ sizeOf;
23
+ toCacheKey;
24
+ evictionPolicy;
25
+ pending = 0;
26
+ batch = 0;
27
+ idleTimeoutMs;
28
+ sweepTimer;
29
+ constructor({ fill: e, maxSize: t = Infinity, sizeOf: n = () => 1, cacheKey: r = (e) => String(e), evictionPolicy: i = "lru", idleTimeoutMs: a = 0, budget: o } = {}) {
30
+ this.fill = e, this.evictionPolicy = i, this.limit = t, this.budget = o, this.membership = o?.register(this), this.sizeOf = n, this.toCacheKey = r, this.idleTimeoutMs = a > 0 ? a : void 0;
31
+ }
32
+ get size() {
33
+ return this.entries.size;
34
+ }
35
+ get totalSize() {
36
+ return this.total;
37
+ }
38
+ get maxSize() {
39
+ return this.limit;
40
+ }
41
+ set maxSize(e) {
42
+ this.limit = e, this.evict();
43
+ }
44
+ waiterCount(e) {
45
+ return this.entries.get(this.toCacheKey(e))?.signals.size ?? 0;
46
+ }
47
+ async get(t, n, r) {
48
+ e(n);
49
+ let i = this.toCacheKey(t), a = this.entries.get(i);
50
+ a && (this.isDoomed(a) ? (this.deleteKey(i), a = void 0) : this.touch(i, a)), a ??= this.start(i, t, r), a.settled || this.join(a, n);
51
+ try {
52
+ let t = await this.settleFor(a, n);
53
+ return e(n), t;
54
+ } catch (t) {
55
+ throw e(n), t;
56
+ }
57
+ }
58
+ settleFor(e, n) {
59
+ if (e.settled || n === void 0 || typeof n.addEventListener != "function") return e.promise;
60
+ let r = new AbortController();
61
+ return Promise.race([e.promise, new Promise((e, i) => {
62
+ n.addEventListener("abort", () => {
63
+ i(t(n));
64
+ }, {
65
+ once: !0,
66
+ signal: r.signal
67
+ });
68
+ })]).finally(() => {
69
+ r.abort();
70
+ });
71
+ }
72
+ getIfCached(e) {
73
+ let t = this.toCacheKey(e), n = this.entries.get(t);
74
+ if (n) {
75
+ if (this.isDoomed(n)) {
76
+ this.deleteKey(t);
77
+ return;
78
+ }
79
+ return this.touch(t, n), n.promise;
80
+ }
81
+ }
82
+ has(e) {
83
+ let t = this.entries.get(this.toCacheKey(e));
84
+ return t !== void 0 && !this.isDoomed(t);
85
+ }
86
+ delete(e) {
87
+ this.deleteKey(this.toCacheKey(e));
88
+ }
89
+ clear() {
90
+ for (let e of this.entries.values()) this.detach(e);
91
+ this.entries.clear(), this.charge(-this.total), this.total = 0, this.settledCount = 0, this.stopSweep();
92
+ }
93
+ touch(e, t) {
94
+ this.entries.delete(e), this.entries.set(e, t), t.batch = this.batch, t.lastTouched = Date.now(), t.seq = this.stamp();
95
+ }
96
+ stamp() {
97
+ return this.budget ? this.budget.nextSeq() : 0;
98
+ }
99
+ isDoomed(e) {
100
+ return !e.settled && e.controller.signal.aborted;
101
+ }
102
+ sweepIdle() {
103
+ let e = this.idleTimeoutMs;
104
+ if (e === void 0) return;
105
+ let t = Date.now() - e, n = 0;
106
+ for (let [e, r] of this.entries) r.settled && (r.lastTouched <= t ? this.deleteKey(e) : n++);
107
+ n === 0 && this.stopSweep();
108
+ }
109
+ startSweep() {
110
+ let e = this.idleTimeoutMs;
111
+ if (e === void 0 || this.sweepTimer !== void 0) return;
112
+ let t = Math.max(1e3, Math.floor(e / 4));
113
+ this.sweepTimer = setInterval(() => {
114
+ this.sweepIdle();
115
+ }, t), n(this.sweepTimer);
116
+ }
117
+ stopSweep() {
118
+ this.sweepTimer !== void 0 && (clearInterval(this.sweepTimer), this.sweepTimer = void 0);
119
+ }
120
+ start(e, t, n) {
121
+ let r = n ?? (this.fill && ((e) => this.fill(t, e)));
122
+ if (!r) throw Error("SharedReadCache needs a fill, either on the cache or on the get() call");
123
+ let i = new AbortController(), a = {
124
+ promise: r(i.signal),
125
+ signals: /* @__PURE__ */ new Set(),
126
+ pinned: !1,
127
+ controller: i,
128
+ dispose: new AbortController(),
129
+ settled: !1,
130
+ counted: !0,
131
+ size: 0,
132
+ batch: this.batch,
133
+ lastTouched: Date.now(),
134
+ seq: this.stamp()
135
+ };
136
+ this.entries.set(e, a), this.pending++;
137
+ let o = () => {
138
+ a.settled = !0, this.detach(a), a.dispose.abort(), a.signals.clear();
139
+ };
140
+ return a.promise.then((t) => {
141
+ if (o(), this.entries.get(e) === a) {
142
+ let n = this.weigh(t);
143
+ n === void 0 ? this.entries.delete(e) : (a.lastTouched = Date.now(), this.settledCount++, a.size = n, this.total += n, this.charge(n), this.startSweep());
144
+ }
145
+ this.maybeEvict();
146
+ }, () => {
147
+ this.entries.get(e) === a && this.deleteKey(e), o(), this.maybeEvict();
148
+ }), a;
149
+ }
150
+ weigh(e) {
151
+ try {
152
+ let t = this.sizeOf(e);
153
+ return Number.isFinite(t) && t >= 0 ? t : void 0;
154
+ } catch {
155
+ return;
156
+ }
157
+ }
158
+ join(e, t) {
159
+ t === void 0 ? e.pinned = !0 : t.aborted ? !e.pinned && e.signals.size === 0 && e.controller.abort(t.reason) : typeof t.addEventListener == "function" ? e.signals.has(t) || (e.signals.add(t), t.addEventListener("abort", () => {
160
+ e.signals.delete(t), !e.pinned && e.signals.size === 0 && (e.controller.abort(t.reason), this.detach(e));
161
+ }, {
162
+ once: !0,
163
+ signal: e.dispose.signal
164
+ })) : e.pinned = !0;
165
+ }
166
+ deleteKey(e) {
167
+ let t = this.entries.get(e);
168
+ t && (this.entries.delete(e), this.detach(t), t.settled && this.settledCount--, this.total -= t.size, this.charge(-t.size));
169
+ }
170
+ detach(e) {
171
+ e.counted && (e.counted = !1, this.pending--);
172
+ }
173
+ charge(e) {
174
+ this.budget && this.membership && this.budget.charge(this.membership, e);
175
+ }
176
+ lruSpare() {
177
+ if (!(this.settledCount <= 1)) {
178
+ for (let [e, t] of this.entries) if (t.settled) return {
179
+ cacheKey: e,
180
+ seq: t.seq
181
+ };
182
+ }
183
+ }
184
+ release(e) {
185
+ this.deleteKey(e);
186
+ }
187
+ maybeEvict() {
188
+ (this.evictionPolicy === "lru" || this.pending === 0) && (this.evict(), this.evictionPolicy === "batch" && this.batch++, this.budget?.evict());
189
+ }
190
+ evict() {
191
+ if (this.limit !== Infinity) {
192
+ if (this.evictionPolicy === "batch") {
193
+ for (let [e, t] of this.entries) {
194
+ if (this.total <= this.limit) break;
195
+ t.batch !== this.batch && t.settled && this.deleteKey(e);
196
+ }
197
+ return;
198
+ }
199
+ if (!(this.total <= this.limit)) for (let [e, t] of this.entries) {
200
+ if (this.total <= this.limit || this.settledCount <= 1) break;
201
+ t.settled && this.deleteKey(e);
202
+ }
203
+ }
204
+ }
205
+ };
206
+ //#endregion
207
+ export { r as t };