@genome-spy/app 0.56.1 → 0.57.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,212 @@
1
+ import { g as l } from "./_commonjsHelpers-DjF3Plf2.js";
2
+ class d {
3
+ }
4
+ class f {
5
+ constructor() {
6
+ this.signals = /* @__PURE__ */ new Set(), this.abortController = new AbortController();
7
+ }
8
+ /**
9
+ * @param {AbortSignal} [signal] optional AbortSignal to add. if falsy,
10
+ * will be treated as a null-signal, and this abortcontroller will no
11
+ * longer be abortable.
12
+ */
13
+ //@ts-ignore
14
+ addSignal(t = new d()) {
15
+ if (this.signal.aborted)
16
+ throw new Error("cannot add a signal, already aborted!");
17
+ this.signals.add(t), t.aborted ? this.handleAborted(t) : typeof t.addEventListener == "function" && t.addEventListener("abort", () => {
18
+ this.handleAborted(t);
19
+ });
20
+ }
21
+ handleAborted(t) {
22
+ this.signals.delete(t), this.signals.size === 0 && this.abortController.abort();
23
+ }
24
+ get signal() {
25
+ return this.abortController.signal;
26
+ }
27
+ abort() {
28
+ this.abortController.abort();
29
+ }
30
+ }
31
+ class u {
32
+ constructor() {
33
+ this.callbacks = /* @__PURE__ */ new Set();
34
+ }
35
+ addCallback(t = () => {
36
+ }) {
37
+ this.callbacks.add(t), t(this.currentMessage);
38
+ }
39
+ callback(t) {
40
+ this.currentMessage = t;
41
+ for (const e of this.callbacks)
42
+ e(t);
43
+ }
44
+ }
45
+ class n {
46
+ constructor({ fill: t, cache: e }) {
47
+ if (typeof t != "function")
48
+ throw new TypeError("must pass a fill function");
49
+ if (typeof e != "object")
50
+ throw new TypeError("must pass a cache object");
51
+ if (typeof e.get != "function" || typeof e.set != "function" || typeof e.delete != "function")
52
+ throw new TypeError("cache must implement get(key), set(key, val), and and delete(key)");
53
+ this.cache = e, this.fillCallback = t;
54
+ }
55
+ static isAbortException(t) {
56
+ return (
57
+ // DOMException
58
+ t.name === "AbortError" || // standard-ish non-DOM abort exception
59
+ //@ts-ignore
60
+ t.code === "ERR_ABORTED" || // stringified DOMException
61
+ t.message === "AbortError: aborted" || // stringified standard-ish exception
62
+ t.message === "Error: aborted"
63
+ );
64
+ }
65
+ evict(t, e) {
66
+ this.cache.get(t) === e && this.cache.delete(t);
67
+ }
68
+ fill(t, e, r, a) {
69
+ const s = new f(), c = new u();
70
+ c.addCallback(a);
71
+ const i = {
72
+ aborter: s,
73
+ promise: this.fillCallback(e, s.signal, (o) => {
74
+ c.callback(o);
75
+ }),
76
+ settled: !1,
77
+ statusReporter: c,
78
+ get aborted() {
79
+ return this.aborter.signal.aborted;
80
+ }
81
+ };
82
+ i.aborter.addSignal(r), i.aborter.signal.addEventListener("abort", () => {
83
+ i.settled || this.evict(t, i);
84
+ }), i.promise.then(() => {
85
+ i.settled = !0;
86
+ }, () => {
87
+ i.settled = !0, this.evict(t, i);
88
+ }).catch((o) => {
89
+ throw console.error(o), o;
90
+ }), this.cache.set(t, i);
91
+ }
92
+ static checkSinglePromise(t, e) {
93
+ function r() {
94
+ if (e != null && e.aborted)
95
+ throw Object.assign(new Error("aborted"), { code: "ERR_ABORTED" });
96
+ }
97
+ return t.then((a) => (r(), a), (a) => {
98
+ throw r(), a;
99
+ });
100
+ }
101
+ has(t) {
102
+ return this.cache.has(t);
103
+ }
104
+ /**
105
+ * Callback for getting status of the pending async
106
+ *
107
+ * @callback statusCallback
108
+ * @param {any} status, current status string or message object
109
+ */
110
+ /**
111
+ * @param {any} key cache key to use for this request
112
+ * @param {any} data data passed as the first argument to the fill callback
113
+ * @param {AbortSignal} [signal] optional AbortSignal object that aborts the request
114
+ * @param {statusCallback} a callback to get the current status of a pending async operation
115
+ */
116
+ get(t, e, r, a) {
117
+ if (!r && e instanceof AbortSignal)
118
+ throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");
119
+ const s = this.cache.get(t);
120
+ return s ? s.aborted && !s.settled ? (this.evict(t, s), this.get(t, e, r, a)) : s.settled ? s.promise : (s.aborter.addSignal(r), s.statusReporter.addCallback(a), n.checkSinglePromise(s.promise, r)) : (this.fill(t, e, r, a), n.checkSinglePromise(
121
+ //see https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-
122
+ this.cache.get(t).promise,
123
+ r
124
+ ));
125
+ }
126
+ /**
127
+ * delete the given entry from the cache. if it exists and its fill request has
128
+ * not yet settled, the fill will be signaled to abort.
129
+ *
130
+ * @param {any} key
131
+ */
132
+ delete(t) {
133
+ const e = this.cache.get(t);
134
+ e && (e.settled || e.aborter.abort(), this.cache.delete(t));
135
+ }
136
+ /**
137
+ * Clear all requests from the cache. Aborts any that have not settled.
138
+ * @returns {number} count of entries deleted
139
+ */
140
+ clear() {
141
+ const t = this.cache.keys();
142
+ let e = 0;
143
+ for (let r = t.next(); !r.done; r = t.next())
144
+ this.delete(r.value), e += 1;
145
+ return e;
146
+ }
147
+ }
148
+ class b {
149
+ constructor(t = {}) {
150
+ if (!(t.maxSize && t.maxSize > 0))
151
+ throw new TypeError("`maxSize` must be a number greater than 0");
152
+ this.maxSize = t.maxSize, this.cache = /* @__PURE__ */ new Map(), this.oldCache = /* @__PURE__ */ new Map(), this._size = 0;
153
+ }
154
+ _set(t, e) {
155
+ this.cache.set(t, e), this._size++, this._size >= this.maxSize && (this._size = 0, this.oldCache = this.cache, this.cache = /* @__PURE__ */ new Map());
156
+ }
157
+ get(t) {
158
+ if (this.cache.has(t))
159
+ return this.cache.get(t);
160
+ if (this.oldCache.has(t)) {
161
+ const e = this.oldCache.get(t);
162
+ return this.oldCache.delete(t), this._set(t, e), e;
163
+ }
164
+ }
165
+ set(t, e) {
166
+ return this.cache.has(t) ? this.cache.set(t, e) : this._set(t, e), this;
167
+ }
168
+ has(t) {
169
+ return this.cache.has(t) || this.oldCache.has(t);
170
+ }
171
+ peek(t) {
172
+ if (this.cache.has(t))
173
+ return this.cache.get(t);
174
+ if (this.oldCache.has(t))
175
+ return this.oldCache.get(t);
176
+ }
177
+ delete(t) {
178
+ const e = this.cache.delete(t);
179
+ return e && this._size--, this.oldCache.delete(t) || e;
180
+ }
181
+ clear() {
182
+ this.cache.clear(), this.oldCache.clear(), this._size = 0;
183
+ }
184
+ *keys() {
185
+ for (const [t] of this)
186
+ yield t;
187
+ }
188
+ *values() {
189
+ for (const [, t] of this)
190
+ yield t;
191
+ }
192
+ *[Symbol.iterator]() {
193
+ for (const t of this.cache)
194
+ yield t;
195
+ for (const t of this.oldCache) {
196
+ const [e] = t;
197
+ this.cache.has(e) || (yield t);
198
+ }
199
+ }
200
+ get size() {
201
+ let t = 0;
202
+ for (const e of this.oldCache.keys())
203
+ this.cache.has(e) || t++;
204
+ return this._size + t;
205
+ }
206
+ }
207
+ var g = b;
208
+ const p = /* @__PURE__ */ l(g);
209
+ export {
210
+ n as A,
211
+ p as L
212
+ };