@kalyptos/narcissus 0.1.1 → 0.1.3
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.
- package/dist/{controls-BCrDCO3z.js → controls-IBLB-RWS.js} +752 -668
- package/dist/element/index.d.ts +4 -3
- package/dist/element/index.js +31 -19
- package/dist/engine/engine.d.ts +2 -0
- package/dist/engine/gpu/pool.d.ts +8 -6
- package/dist/engine/plan/cut.d.ts +2 -2
- package/dist/engine/plan/draw.d.ts +3 -1
- package/dist/engine/plan/footprint.d.ts +5 -0
- package/dist/engine/quality.d.ts +7 -1
- package/dist/engine/types.d.ts +4 -0
- package/dist/engine/world/tree.d.ts +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -78,24 +78,14 @@ var m = 19, h = 1024, g = class {
|
|
|
78
78
|
#_ = [];
|
|
79
79
|
constructor(e, t) {
|
|
80
80
|
this.capacity = t, this.#e = e;
|
|
81
|
-
let n = this.slots
|
|
82
|
-
|
|
83
|
-
size: n,
|
|
84
|
-
usage: r
|
|
85
|
-
});
|
|
86
|
-
this.geometry = i("pool geometry", t * 4 * 4), this.colour = i("pool colour", t * 3 * 4), this.pages = i("pool pages", n * 36 * 4), this.clusters = i("pool clusters", n * 12 * 4), this.list = i("pool list", n * 4), this.#a = new Uint8Array(n), this.#o = n, this.#c = Array.from({ length: n }, (e, t) => n - 1 - t), this.#u = new Uint32Array(n * 36), this.#d = new Float32Array(this.#u.buffer), this.#p = new Uint32Array(n * 12), this.#m = new Float32Array(this.#p.buffer), this.#g = new Uint32Array(n);
|
|
81
|
+
let n = this.slots;
|
|
82
|
+
this.#y(), this.#a = new Uint8Array(n), this.#o = n, this.#c = Array.from({ length: n }, (e, t) => n - 1 - t), this.#u = new Uint32Array(n * 36), this.#d = new Float32Array(this.#u.buffer), this.#p = new Uint32Array(n * 12), this.#m = new Float32Array(this.#p.buffer), this.#g = new Uint32Array(n);
|
|
87
83
|
}
|
|
88
84
|
get slots() {
|
|
89
85
|
return this.capacity / 256;
|
|
90
86
|
}
|
|
91
87
|
get bytes() {
|
|
92
|
-
return
|
|
93
|
-
this.geometry,
|
|
94
|
-
this.colour,
|
|
95
|
-
this.pages,
|
|
96
|
-
this.clusters,
|
|
97
|
-
this.list
|
|
98
|
-
].reduce((e, t) => e + t.size, 0);
|
|
88
|
+
return this.#v().reduce((e, t) => e + t.size, 0);
|
|
99
89
|
}
|
|
100
90
|
has(e) {
|
|
101
91
|
let t = this.#t.get(e);
|
|
@@ -110,13 +100,13 @@ var m = 19, h = 1024, g = class {
|
|
|
110
100
|
add(e, n, r, i) {
|
|
111
101
|
if (this.#t.has(e)) return !0;
|
|
112
102
|
let a = c(n.count) / 256;
|
|
113
|
-
if (!this.#
|
|
103
|
+
if (!this.#S(a, i)) return !1;
|
|
114
104
|
let o = t.origin, s = {
|
|
115
105
|
id: e,
|
|
116
106
|
previous: null,
|
|
117
107
|
next: null,
|
|
118
108
|
page: n,
|
|
119
|
-
slots: this.#
|
|
109
|
+
slots: this.#E(a),
|
|
120
110
|
active: [],
|
|
121
111
|
mask: 0,
|
|
122
112
|
table: this.#c.pop(),
|
|
@@ -127,14 +117,14 @@ var m = 19, h = 1024, g = class {
|
|
|
127
117
|
],
|
|
128
118
|
factors: 0
|
|
129
119
|
};
|
|
130
|
-
return this.#t.set(e, s), this.#
|
|
120
|
+
return this.#t.set(e, s), this.#x(s), this.#i.add(e), !0;
|
|
131
121
|
}
|
|
132
122
|
remove(e) {
|
|
133
123
|
let t = this.#t.get(e);
|
|
134
124
|
if (t) {
|
|
135
|
-
this.#
|
|
125
|
+
this.#b(t), this.#t.delete(e), this.#i.delete(e);
|
|
136
126
|
for (let e of t.slots) this.#a[e] = 0;
|
|
137
|
-
this.#s = Math.min(this.#s, t.slots[0]), this.#o += t.slots.length, this.#c.push(t.table), t.page === null && t.factors !== 0 && this.#
|
|
127
|
+
this.#s = Math.min(this.#s, t.slots[0]), this.#o += t.slots.length, this.#c.push(t.table), t.page === null && t.factors !== 0 && this.#T(t, 0);
|
|
138
128
|
}
|
|
139
129
|
}
|
|
140
130
|
clear() {
|
|
@@ -147,7 +137,7 @@ var m = 19, h = 1024, g = class {
|
|
|
147
137
|
let t = 0;
|
|
148
138
|
for (let n of this.#i) {
|
|
149
139
|
if (t >= e) break;
|
|
150
|
-
t += this.#
|
|
140
|
+
t += this.#C(this.#t.get(n)), this.#i.delete(n);
|
|
151
141
|
}
|
|
152
142
|
return t;
|
|
153
143
|
}
|
|
@@ -157,7 +147,7 @@ var m = 19, h = 1024, g = class {
|
|
|
157
147
|
let e = this.#t.get(i);
|
|
158
148
|
if (!e || e.page !== null) continue;
|
|
159
149
|
let o = e.active;
|
|
160
|
-
e.factors !== a && this.#
|
|
150
|
+
e.factors !== a && this.#T(e, a), r ||= o !== e.active, this.#x(e), r ||= this.#_[n] !== e, this.#_[n++] = e, r && this.#g.set(e.active, t), t += e.active.length;
|
|
161
151
|
}
|
|
162
152
|
r ||= this.#_.length !== n, this.#_.length = n, this.listed = t;
|
|
163
153
|
let i = this.#e.queue;
|
|
@@ -169,26 +159,53 @@ var m = 19, h = 1024, g = class {
|
|
|
169
159
|
e[1],
|
|
170
160
|
e[2]
|
|
171
161
|
];
|
|
172
|
-
for (let e of this.#t.values()) e.page === null && this.#
|
|
162
|
+
for (let e of this.#t.values()) e.page === null && this.#w(e);
|
|
173
163
|
this.#e.queue.writeBuffer(this.pages, 0, this.#u), this.#f.clear();
|
|
174
164
|
}
|
|
165
|
+
grow(e) {
|
|
166
|
+
if (e <= this.capacity) return;
|
|
167
|
+
let t = this.slots, n = this.#v();
|
|
168
|
+
this.capacity = e, this.#y();
|
|
169
|
+
let r = this.#e.createCommandEncoder({ label: "pool grow" });
|
|
170
|
+
this.#v().forEach((e, t) => r.copyBufferToBuffer(n[t], 0, e, 0, n[t].size)), this.#e.queue.submit([r.finish()]);
|
|
171
|
+
for (let e of n) e.destroy();
|
|
172
|
+
let i = this.slots, a = new Uint8Array(i);
|
|
173
|
+
a.set(this.#a), this.#a = a, this.#o += i - t;
|
|
174
|
+
for (let e = i - 1; e >= t; e--) this.#c.push(e);
|
|
175
|
+
let o = new Uint32Array(i * 36);
|
|
176
|
+
o.set(this.#u), this.#u = o, this.#d = new Float32Array(o.buffer);
|
|
177
|
+
let s = new Uint32Array(i * 12);
|
|
178
|
+
s.set(this.#p), this.#p = s, this.#m = new Float32Array(s.buffer);
|
|
179
|
+
let c = new Uint32Array(i);
|
|
180
|
+
c.set(this.#g), this.#g = c;
|
|
181
|
+
}
|
|
175
182
|
destroy() {
|
|
176
|
-
let e
|
|
183
|
+
for (let e of this.#v()) e.destroy();
|
|
184
|
+
}
|
|
185
|
+
#v() {
|
|
186
|
+
return [
|
|
177
187
|
this.geometry,
|
|
178
188
|
this.colour,
|
|
179
189
|
this.pages,
|
|
180
190
|
this.clusters,
|
|
181
191
|
this.list
|
|
182
192
|
];
|
|
183
|
-
for (let t of e) t.destroy();
|
|
184
193
|
}
|
|
185
|
-
#
|
|
194
|
+
#y() {
|
|
195
|
+
let { capacity: e, slots: t } = this, n = GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC, r = (e, t) => this.#e.createBuffer({
|
|
196
|
+
label: e,
|
|
197
|
+
size: t,
|
|
198
|
+
usage: n
|
|
199
|
+
});
|
|
200
|
+
this.geometry = r("pool geometry", e * 4 * 4), this.colour = r("pool colour", e * 3 * 4), this.pages = r("pool pages", t * 36 * 4), this.clusters = r("pool clusters", t * 12 * 4), this.list = r("pool list", t * 4);
|
|
201
|
+
}
|
|
202
|
+
#b(e) {
|
|
186
203
|
e.previous ? e.previous.next = e.next : this.#n === e && (this.#n = e.next), e.next ? e.next.previous = e.previous : this.#r === e && (this.#r = e.previous), e.previous = null, e.next = null;
|
|
187
204
|
}
|
|
188
|
-
#
|
|
189
|
-
this.#r !== e && (this.#
|
|
205
|
+
#x(e) {
|
|
206
|
+
this.#r !== e && (this.#b(e), e.previous = this.#r, this.#r ? this.#r.next = e : this.#n = e, this.#r = e);
|
|
190
207
|
}
|
|
191
|
-
#
|
|
208
|
+
#S(e, t) {
|
|
192
209
|
let n = this.#o;
|
|
193
210
|
if (n >= e) return !0;
|
|
194
211
|
let r = [];
|
|
@@ -197,7 +214,7 @@ var m = 19, h = 1024, g = class {
|
|
|
197
214
|
for (let e of r) this.remove(e);
|
|
198
215
|
return !0;
|
|
199
216
|
}
|
|
200
|
-
#
|
|
217
|
+
#C(e) {
|
|
201
218
|
let n = e.page, { slots: r } = e, i = this.#e.queue, a = r.length, o = this.#p, s = this.#m;
|
|
202
219
|
for (let t = 0; t < a; t++) {
|
|
203
220
|
let i = r[t] * 12;
|
|
@@ -211,13 +228,13 @@ var m = 19, h = 1024, g = class {
|
|
|
211
228
|
i.writeBuffer(this.geometry, c * 4 * 4, n.geometry, o * 4, s * 4), i.writeBuffer(this.colour, c * 3 * 4, n.colour, o * 3, s * 3), this.#h.mark(r[e] * 12, (r[e] + t) * 12), e += t;
|
|
212
229
|
}
|
|
213
230
|
let c = e.table * 36, l = this.#u, u = this.#d, d = n.params, [f, p, m] = n.quadrants;
|
|
214
|
-
return l.fill(0, c, c + 36), this.#
|
|
231
|
+
return l.fill(0, c, c + 36), this.#w(e), l[c + 3] = n.count, u.set(d.subarray(t.step, t.step + 3), c + 4), l[c + 7] = f, u.set(d.subarray(t.scaleMin, t.scaleMin + 3), c + 8), l[c + 11] = p, u.set(d.subarray(t.scaleMax, t.scaleMax + 3), c + 12), l[c + 15] = m, u.set(d.subarray(t.dcMin, t.dcMin + 3), c + 16), u.set(d.subarray(t.dcMax, t.dcMax + 3), c + 20), u.set(d.subarray(t.shScale, t.shScale + 9), c + 24), this.#f.mark(c, c + 36), e.page = null, n.count * 7 * 4 + a * 12 * 4 + 144;
|
|
215
232
|
}
|
|
216
|
-
#
|
|
233
|
+
#w(e) {
|
|
217
234
|
let t = e.table * 36;
|
|
218
235
|
for (let n = 0; n < 3; n++) this.#d[t + n] = e.base[n] - this.#l[n];
|
|
219
236
|
}
|
|
220
|
-
#
|
|
237
|
+
#T(e, t) {
|
|
221
238
|
let n = 0;
|
|
222
239
|
for (let e = 0; e < 4; e++) t >>> 8 * e & 255 && (n |= 1 << e);
|
|
223
240
|
if (n !== e.mask) {
|
|
@@ -236,7 +253,7 @@ var m = 19, h = 1024, g = class {
|
|
|
236
253
|
let r = e.table * 36 + m;
|
|
237
254
|
this.#u[r] = t, this.#f.mark(r, r + 1);
|
|
238
255
|
}
|
|
239
|
-
#
|
|
256
|
+
#E(e) {
|
|
240
257
|
let t = this.#a, n = -1;
|
|
241
258
|
for (let r = this.#s; r <= t.length - e;) {
|
|
242
259
|
let i = r;
|
|
@@ -681,7 +698,7 @@ function he(e, t, n, r, i, a, o) {
|
|
|
681
698
|
}
|
|
682
699
|
//#endregion
|
|
683
700
|
//#region src/engine/gpu/sort.wgsl?raw
|
|
684
|
-
var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan, a stable scatter; no spin-waits\n\nconst THREADS: u32 = 128u;\nconst ITEMS: u32 = 8u;\nconst BLOCK: u32 = 1024u;\n// blocks per scan chunk\nconst CHUNK: u32 = 64u;\nconst DIGITS: u32 = 256u;\n\nstruct SortParams {\n shift: u32,\n // word offsets of the keys read and written; their values follow capacity words later\n src: u32,\n dst: u32,\n capacity: u32,\n // word offsets in the work buffer\n projected: u32,\n drawArgs: u32,\n}\n\nstruct SortState {\n count: u32,\n blocks: u32,\n chunks: u32,\n}\n\n@group(0) @binding(0) var<uniform> params: SortParams;\n@group(0) @binding(1) var<storage, read_write> data: array<u32>;\n// block-major: count, then exclusive global offset, of digit d in block b at b DIGITS + d\n@group(0) @binding(2) var<storage, read_write> hist: array<u32>;\n// chunk-major sums of hist, then their exclusive global offsets\n@group(0) @binding(3) var<storage, read_write> sums: array<u32>;\n@group(0) @binding(4) var<storage, read> state: SortState;\n@group(0) @binding(5) var<storage, read_write> stateOut: SortState;\n@group(0) @binding(6) var<storage, read_write> work: array<u32>;\n\nvar<workgroup> bins: array<atomic<u32>, DIGITS>;\nvar<workgroup> totals: array<u32, DIGITS>;\nvar<workgroup> bitValues: atomic<u32>;\nvar<workgroup> activeBits: u32;\nvar<workgroup> sk: array<u32, BLOCK>;\nvar<workgroup> sv: array<u32, BLOCK>;\n// three 10-bit counts; the fourth follows from the number of items\nvar<workgroup> counts: array<u32, THREADS * 2u>;\nvar<workgroup> tail: u32;\nvar<workgroup> starts: array<u32, DIGITS>;\nvar<workgroup> offsets: array<u32, DIGITS>;\n\nfn unpack(packed: u32, count: u32) -> vec4u {\n let a = packed & 1023u;\n let b = (packed >> 10u) & 1023u;\n let c = (packed >> 20u) & 1023u;\n return vec4u(a, b, c, count - a - b - c);\n}\n\nfn digit(key: u32) -> u32 {\n return (key >> params.shift) & 0xffu;\n}\n\n@compute @workgroup_size(1)\nfn prepare() {\n let count = min(work[params.projected], params.capacity);\n let blocks = (count + BLOCK - 1u) / BLOCK;\n work[params.drawArgs] = 4u;\n work[params.drawArgs + 1u] = count;\n work[params.drawArgs + 2u] = 0u;\n work[params.drawArgs + 3u] = 0u;\n stateOut = SortState(count, blocks, (blocks + CHUNK - 1u) / CHUNK);\n}\n\n@compute @workgroup_size(THREADS)\nfn histogram(\n @builtin(workgroup_id) wid: vec3u,\n @builtin(num_workgroups) groups: vec3u,\n @builtin(local_invocation_index) t: u32\n) {\n for (var block = wid.y * groups.x + wid.x; block < state.blocks; block += groups.x * groups.y) {\n let head = block * BLOCK;\n for (var k = 0u; k < ITEMS; k++) {\n let i = head + k * THREADS + t;\n if (i < state.count) {\n atomicAdd(&bins[digit(data[params.src + i])], 1u);\n }\n }\n workgroupBarrier();\n for (var d = t; d < DIGITS; d += THREADS) {\n hist[block * DIGITS + d] = atomicExchange(&bins[d], 0u);\n }\n workgroupBarrier();\n }\n}\n\n@compute @workgroup_size(DIGITS)\nfn reduce(@builtin(workgroup_id) wid: vec3u, @builtin(local_invocation_index) t: u32) {\n let end = min((wid.x + 1u) * CHUNK, state.blocks);\n var sum = 0u;\n for (var b = wid.x * CHUNK; b < end; b++) {\n sum += hist[b * DIGITS + t];\n }\n sums[wid.x * DIGITS + t] = sum;\n}\n\n@compute @workgroup_size(DIGITS)\nfn top(@builtin(local_invocation_index) t: u32) {\n var run = 0u;\n for (var c = 0u; c < state.chunks; c++) {\n let x = sums[c * DIGITS + t];\n sums[c * DIGITS + t] = run;\n run += x;\n }\n totals[t] = run;\n // a bit varies only when both zero and one occur in nonempty digits\n if (run > 0u) {\n atomicOr(&bitValues, t | ((255u ^ t) << 8u));\n }\n workgroupBarrier();\n if (t == 0u) {\n let values = atomicLoad(&bitValues);\n sums[arrayLength(&sums) - 1u] = values & (values >> 8u);\n }\n for (var o = 1u; o < DIGITS; o *= 2u) {\n var x = 0u;\n if (t >= o) {\n x = totals[t - o];\n }\n workgroupBarrier();\n totals[t] += x;\n workgroupBarrier();\n }\n let base = totals[t] - run;\n for (var c = 0u; c < state.chunks; c++) {\n sums[c * DIGITS + t] += base;\n }\n}\n\n@compute @workgroup_size(DIGITS)\nfn down(@builtin(workgroup_id) wid: vec3u, @builtin(local_invocation_index) t: u32) {\n let end = min((wid.x + 1u) * CHUNK, state.blocks);\n var run = sums[wid.x * DIGITS + t];\n for (var b = wid.x * CHUNK; b < end; b++) {\n let x = hist[b * DIGITS + t];\n hist[b * DIGITS + t] = run;\n run += x;\n }\n}\n\n@compute @workgroup_size(THREADS)\nfn scatter(\n @builtin(workgroup_id) wid: vec3u,\n @builtin(num_workgroups) groups: vec3u,\n @builtin(local_invocation_index) t: u32\n) {\n let first = wid.y * groups.x + wid.x;\n if (first >= state.blocks) {\n return;\n }\n if (t == 0u) {\n activeBits = sums[arrayLength(&sums) - 1u];\n }\n let bits = workgroupUniformLoad(&activeBits);\n for (var block = first; block < state.blocks; block += groups.x * groups.y) {\n let head = block * BLOCK;\n let valid = min(BLOCK, state.count - head);\n // padding has digit 255 at every shift, so it sorts behind the valid keys and is never written\n for (var k = 0u; k < ITEMS; k++) {\n let i = k * THREADS + t;\n var key = 0xffffffffu;\n var value = 0u;\n if (i < valid) {\n key = data[params.src + head + i];\n value = data[params.src + params.capacity + head + i];\n }\n sk[i] = key;\n sv[i] = value;\n }\n for (var d = t; d < DIGITS; d += THREADS) {\n offsets[d] = hist[block * DIGITS + d];\n }\n workgroupBarrier();\n\n // stable local sort by the digit, two bits a split; thread t owns positions t ITEMS + k\n for (var bit = 0u; bit < 8u; bit += 2u) {\n if ((bits & (3u << bit)) == 0u) {\n continue;\n }\n var keys: array<u32, ITEMS>;\n var values: array<u32, ITEMS>;\n var before: array<u32, ITEMS>;\n var mine = vec4u(0u);\n for (var k = 0u; k < ITEMS; k++) {\n keys[k] = sk[t * ITEMS + k];\n values[k] = sv[t * ITEMS + k];\n let b = (keys[k] >> (params.shift + bit)) & 3u;\n before[k] = mine[b];\n mine[b] += 1u;\n }\n counts[t] = mine.x | (mine.y << 10u) | (mine.z << 20u);\n if (t == THREADS - 1u) {\n tail = counts[t];\n }\n workgroupBarrier();\n // separate reads and writes need only one barrier per scan step\n var source = 0u;\n for (var o = 1u; o < THREADS; o *= 2u) {\n var x = counts[source + t];\n if (t >= o) {\n x += counts[source + t - o];\n }\n let dest = source ^ THREADS;\n counts[dest + t] = x;\n workgroupBarrier();\n source = dest;\n }\n // prefixes stop at 1016 items, so no count carries into its neighbour\n let total = unpack(counts[source + THREADS - 2u], BLOCK - ITEMS) + unpack(tail, ITEMS);\n var prior = vec4u(0u);\n if (t > 0u) {\n prior = unpack(counts[source + t - 1u], t * ITEMS);\n }\n let base = vec4u(0u, total.x, total.x + total.y, total.x + total.y + total.z);\n for (var k = 0u; k < ITEMS; k++) {\n let b = (keys[k] >> (params.shift + bit)) & 3u;\n let p = base[b] + prior[b] + before[k];\n sk[p] = keys[k];\n sv[p] = values[k];\n }\n workgroupBarrier();\n }\n\n for (var k = 0u; k < ITEMS; k++) {\n let i = t * ITEMS + k;\n let d = digit(sk[i]);\n if (i == 0u || digit(sk[i - 1u]) != d) {\n starts[d] = i;\n }\n }\n workgroupBarrier();\n for (var k = 0u; k < ITEMS; k++) {\n let i = k * THREADS + t;\n if (i < valid) {\n let d = digit(sk[i]);\n let slot = offsets[d] + i - starts[d];\n data[params.dst + slot] = sk[i];\n data[params.dst + params.capacity + slot] = sv[i];\n }\n }\n workgroupBarrier();\n }\n}\n",
|
|
701
|
+
var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan, a stable scatter; no spin-waits\n\nconst THREADS: u32 = 128u;\nconst ITEMS: u32 = 8u;\nconst BLOCK: u32 = 1024u;\n// blocks per scan chunk\nconst CHUNK: u32 = 64u;\nconst DIGITS: u32 = 256u;\n\nstruct SortParams {\n shift: u32,\n // word offsets of the keys read and written; their values follow capacity words later\n src: u32,\n dst: u32,\n capacity: u32,\n // word offsets in the work buffer\n projected: u32,\n drawArgs: u32,\n}\n\nstruct SortState {\n count: u32,\n blocks: u32,\n chunks: u32,\n}\n\n@group(0) @binding(0) var<uniform> params: SortParams;\n@group(0) @binding(1) var<storage, read_write> data: array<u32>;\n// block-major: count, then exclusive global offset, of digit d in block b at b DIGITS + d\n@group(0) @binding(2) var<storage, read_write> hist: array<u32>;\n// chunk-major sums of hist, then their exclusive global offsets\n@group(0) @binding(3) var<storage, read_write> sums: array<u32>;\n@group(0) @binding(4) var<storage, read> state: SortState;\n@group(0) @binding(5) var<storage, read_write> stateOut: SortState;\n@group(0) @binding(6) var<storage, read_write> work: array<u32>;\n\nvar<workgroup> bins: array<atomic<u32>, DIGITS>;\nvar<workgroup> totals: array<u32, DIGITS>;\nvar<workgroup> bitValues: atomic<u32>;\nvar<workgroup> activeBits: u32;\nvar<workgroup> sk: array<u32, BLOCK>;\nvar<workgroup> sv: array<u32, BLOCK>;\n// three 10-bit counts; the fourth follows from the number of items\nvar<workgroup> counts: array<u32, THREADS * 2u>;\nvar<workgroup> tail: u32;\nvar<workgroup> starts: array<u32, DIGITS>;\nvar<workgroup> offsets: array<u32, DIGITS>;\n\nfn unpack(packed: u32, count: u32) -> vec4u {\n let a = packed & 1023u;\n let b = (packed >> 10u) & 1023u;\n let c = (packed >> 20u) & 1023u;\n return vec4u(a, b, c, count - a - b - c);\n}\n\nfn digit(key: u32) -> u32 {\n return (key >> params.shift) & 0xffu;\n}\n\n@compute @workgroup_size(1)\nfn prepare() {\n let count = min(work[params.projected], params.capacity);\n let blocks = (count + BLOCK - 1u) / BLOCK;\n work[params.drawArgs] = 4u;\n work[params.drawArgs + 1u] = count;\n work[params.drawArgs + 2u] = 0u;\n work[params.drawArgs + 3u] = 0u;\n stateOut = SortState(count, blocks, (blocks + CHUNK - 1u) / CHUNK);\n}\n\n@compute @workgroup_size(THREADS)\nfn histogram(\n @builtin(workgroup_id) wid: vec3u,\n @builtin(num_workgroups) groups: vec3u,\n @builtin(local_invocation_index) t: u32\n) {\n for (var block = wid.y * groups.x + wid.x; block < state.blocks; block += groups.x * groups.y) {\n let head = block * BLOCK;\n for (var k = 0u; k < ITEMS; k++) {\n let i = head + k * THREADS + t;\n if (i < state.count) {\n atomicAdd(&bins[digit(data[params.src + i])], 1u);\n }\n }\n workgroupBarrier();\n for (var d = t; d < DIGITS; d += THREADS) {\n hist[block * DIGITS + d] = atomicExchange(&bins[d], 0u);\n }\n workgroupBarrier();\n }\n}\n\n@compute @workgroup_size(DIGITS)\nfn reduce(@builtin(workgroup_id) wid: vec3u, @builtin(local_invocation_index) t: u32) {\n let end = min((wid.x + 1u) * CHUNK, state.blocks);\n var sum = 0u;\n for (var b = wid.x * CHUNK; b < end; b++) {\n sum += hist[b * DIGITS + t];\n }\n sums[wid.x * DIGITS + t] = sum;\n}\n\n@compute @workgroup_size(DIGITS)\nfn top(@builtin(local_invocation_index) t: u32) {\n var run = 0u;\n for (var c = 0u; c < state.chunks; c++) {\n let x = sums[c * DIGITS + t];\n sums[c * DIGITS + t] = run;\n run += x;\n }\n totals[t] = run;\n // a bit varies only when both zero and one occur in nonempty digits\n if (run > 0u) {\n atomicOr(&bitValues, t | ((255u ^ t) << 8u));\n }\n workgroupBarrier();\n if (t == 0u) {\n let values = atomicLoad(&bitValues);\n sums[arrayLength(&sums) - 1u] = values & (values >> 8u);\n }\n for (var o = 1u; o < DIGITS; o *= 2u) {\n var x = 0u;\n if (t >= o) {\n x = totals[t - o];\n }\n workgroupBarrier();\n totals[t] += x;\n workgroupBarrier();\n }\n let base = totals[t] - run;\n for (var c = 0u; c < state.chunks; c++) {\n sums[c * DIGITS + t] += base;\n }\n}\n\n@compute @workgroup_size(DIGITS)\nfn down(@builtin(workgroup_id) wid: vec3u, @builtin(local_invocation_index) t: u32) {\n let end = min((wid.x + 1u) * CHUNK, state.blocks);\n var run = sums[wid.x * DIGITS + t];\n for (var b = wid.x * CHUNK; b < end; b++) {\n let x = hist[b * DIGITS + t];\n hist[b * DIGITS + t] = run;\n run += x;\n }\n}\n\n@compute @workgroup_size(THREADS)\nfn scatter(\n @builtin(workgroup_id) wid: vec3u,\n @builtin(num_workgroups) groups: vec3u,\n @builtin(local_invocation_index) t: u32\n) {\n let first = wid.y * groups.x + wid.x;\n if (first >= state.blocks) {\n return;\n }\n if (t == 0u) {\n activeBits = sums[arrayLength(&sums) - 1u];\n }\n let bits = workgroupUniformLoad(&activeBits);\n for (var block = first; block < state.blocks; block += groups.x * groups.y) {\n let head = block * BLOCK;\n let valid = min(BLOCK, state.count - head);\n // padding has digit 255 at every shift, so it sorts behind the valid keys and is never written\n for (var k = 0u; k < ITEMS; k++) {\n let i = k * THREADS + t;\n var key = 0xffffffffu;\n var value = 0u;\n if (i < valid) {\n key = data[params.src + head + i];\n value = data[params.src + params.capacity + head + i];\n }\n sk[i] = key;\n sv[i] = value;\n }\n for (var d = t; d < DIGITS; d += THREADS) {\n offsets[d] = hist[block * DIGITS + d];\n }\n workgroupBarrier();\n\n // stable local sort by the digit, two bits a split; thread t owns positions t ITEMS + k\n for (var bit = 0u; bit < 8u; bit += 2u) {\n if ((bits & (3u << bit)) == 0u) {\n continue;\n }\n var keys: array<u32, ITEMS>;\n var values: array<u32, ITEMS>;\n var before: array<u32, ITEMS>;\n var mine = vec4u(0u);\n for (var k = 0u; k < ITEMS; k++) {\n keys[k] = sk[t * ITEMS + k];\n values[k] = sv[t * ITEMS + k];\n let b = (keys[k] >> (params.shift + bit)) & 3u;\n before[k] = mine[b];\n mine[b] += 1u;\n }\n counts[t] = mine.x | (mine.y << 10u) | (mine.z << 20u);\n if (t == THREADS - 1u) {\n tail = counts[t];\n }\n workgroupBarrier();\n // separate reads and writes need only one barrier per scan step\n var source = 0u;\n for (var o = 1u; o < THREADS; o *= 2u) {\n var x = counts[source + t];\n if (t >= o) {\n x += counts[source + t - o];\n }\n let dest = source ^ THREADS;\n counts[dest + t] = x;\n workgroupBarrier();\n source = dest;\n }\n // prefixes stop at 1016 items, so no count carries into its neighbour\n let total = unpack(counts[source + THREADS - 2u], BLOCK - ITEMS) + unpack(tail, ITEMS);\n var prior = vec4u(0u);\n if (t > 0u) {\n prior = unpack(counts[source + t - 1u], t * ITEMS);\n }\n let base = vec4u(0u, total.x, total.x + total.y, total.x + total.y + total.z);\n for (var k = 0u; k < ITEMS; k++) {\n let b = (keys[k] >> (params.shift + bit)) & 3u;\n let p = base[b] + prior[b] + before[k];\n sk[p] = keys[k];\n sv[p] = values[k];\n }\n workgroupBarrier();\n }\n\n for (var k = 0u; k < ITEMS; k++) {\n let i = t * ITEMS + k;\n let d = digit(sk[i]);\n if (i == 0u || digit(sk[i - 1u]) != d) {\n starts[d] = i;\n }\n }\n workgroupBarrier();\n for (var k = 0u; k < ITEMS; k++) {\n let i = k * THREADS + t;\n if (i < valid) {\n let d = digit(sk[i]);\n let slot = offsets[d] + i - starts[d];\n data[params.dst + slot] = sk[i];\n data[params.dst + params.capacity + slot] = sv[i];\n }\n }\n workgroupBarrier();\n }\n}\n", P = 1024, _e = 64, ve = 256, F = 3, I = 256, ye = 32, be = class {
|
|
685
702
|
keys;
|
|
686
703
|
values;
|
|
687
704
|
bytes;
|
|
@@ -694,21 +711,21 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
694
711
|
constructor(e, t) {
|
|
695
712
|
let { capacity: n } = t;
|
|
696
713
|
this.keys = n * 8, this.values = n * 12;
|
|
697
|
-
let r = Math.max(1, Math.ceil(n /
|
|
714
|
+
let r = Math.max(1, Math.ceil(n / P));
|
|
698
715
|
this.#a = r;
|
|
699
|
-
let i = Math.ceil(r /
|
|
716
|
+
let i = Math.ceil(r / _e), a = (t, n, r) => e.createBuffer({
|
|
700
717
|
label: t,
|
|
701
718
|
size: n,
|
|
702
719
|
usage: r
|
|
703
|
-
}), o = GPUBufferUsage.STORAGE, s = a("sort params",
|
|
720
|
+
}), o = GPUBufferUsage.STORAGE, s = a("sort params", F * I, GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST), c = a("sort histograms", r * ve * 4, o), u = a("sort chunk sums", (i * ve + 1) * 4, o), d = a("sort state", 12, o);
|
|
704
721
|
this.#e = [
|
|
705
722
|
s,
|
|
706
723
|
c,
|
|
707
724
|
u,
|
|
708
725
|
d
|
|
709
726
|
], this.bytes = this.#e.reduce((e, t) => e + t.size, 0);
|
|
710
|
-
let f = new Uint32Array(
|
|
711
|
-
for (let e = 0; e <
|
|
727
|
+
let f = new Uint32Array(F * I / 4);
|
|
728
|
+
for (let e = 0; e < F; e++) {
|
|
712
729
|
let [t, r] = e % 2 ? [2 * n, 0] : [0, 2 * n];
|
|
713
730
|
f.set([
|
|
714
731
|
8 * e,
|
|
@@ -717,7 +734,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
717
734
|
n,
|
|
718
735
|
l.projected,
|
|
719
736
|
l.drawArgs
|
|
720
|
-
], e *
|
|
737
|
+
], e * I / 4);
|
|
721
738
|
}
|
|
722
739
|
e.queue.writeBuffer(s, 0, f);
|
|
723
740
|
let p = (e, t) => ({
|
|
@@ -757,8 +774,8 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
757
774
|
].map((e) => _(e, m));
|
|
758
775
|
let v = (e) => ({
|
|
759
776
|
buffer: s,
|
|
760
|
-
offset: e *
|
|
761
|
-
size:
|
|
777
|
+
offset: e * I,
|
|
778
|
+
size: ye
|
|
762
779
|
});
|
|
763
780
|
this.#r = e.createBindGroup({
|
|
764
781
|
label: "sort prepare",
|
|
@@ -777,7 +794,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
777
794
|
resource: { buffer: t.work }
|
|
778
795
|
}
|
|
779
796
|
]
|
|
780
|
-
}), this.#i = Array.from({ length:
|
|
797
|
+
}), this.#i = Array.from({ length: F }, (n, r) => e.createBindGroup({
|
|
781
798
|
label: `sort pass ${r}`,
|
|
782
799
|
layout: m,
|
|
783
800
|
entries: [
|
|
@@ -805,7 +822,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
805
822
|
}));
|
|
806
823
|
}
|
|
807
824
|
encode(e, t, n, r) {
|
|
808
|
-
let [i, a, o, s, c] = this.#n, l = Math.max(1, Math.min(this.#a, Math.ceil(t /
|
|
825
|
+
let [i, a, o, s, c] = this.#n, l = Math.max(1, Math.min(this.#a, Math.ceil(t / P))), u = Math.max(l / 16, (n || t) / P), f = d(Math.min(Math.ceil(l / 4), Math.ceil(u))), p = Math.ceil(l / _e), m = e.beginComputePass({
|
|
809
826
|
label: "sort",
|
|
810
827
|
timestampWrites: r
|
|
811
828
|
});
|
|
@@ -816,7 +833,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
816
833
|
destroy() {
|
|
817
834
|
for (let e of this.#e) e.destroy();
|
|
818
835
|
}
|
|
819
|
-
},
|
|
836
|
+
}, xe = class {
|
|
820
837
|
ms = {};
|
|
821
838
|
#e;
|
|
822
839
|
#t;
|
|
@@ -867,14 +884,14 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
867
884
|
destroy() {
|
|
868
885
|
this.#t?.destroy(), this.#n?.destroy(), this.#r?.destroy();
|
|
869
886
|
}
|
|
870
|
-
},
|
|
887
|
+
}, Se = [
|
|
871
888
|
"cull",
|
|
872
889
|
"project",
|
|
873
890
|
"sort",
|
|
874
891
|
"raster",
|
|
875
892
|
"heights",
|
|
876
893
|
"post"
|
|
877
|
-
],
|
|
894
|
+
], L = {
|
|
878
895
|
view: 0,
|
|
879
896
|
proj: 16,
|
|
880
897
|
viewProj: 32,
|
|
@@ -887,7 +904,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
887
904
|
far: 81,
|
|
888
905
|
lowPass: 82,
|
|
889
906
|
clusters: 83
|
|
890
|
-
},
|
|
907
|
+
}, Ce = class {
|
|
891
908
|
#e;
|
|
892
909
|
#t;
|
|
893
910
|
#n;
|
|
@@ -916,7 +933,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
916
933
|
#T = 0;
|
|
917
934
|
constructor(e, t, n, r) {
|
|
918
935
|
let { device: i } = e;
|
|
919
|
-
this.#e = i, this.#t = t, this.#n = e.format, this.#r = n, this.#i = T(i, r, n.slots), this.#a = new j(i, n, this.#i), this.#o = new le(i, n, this.#i), this.#s = new
|
|
936
|
+
this.#e = i, this.#t = t, this.#n = e.format, this.#r = n, this.#i = T(i, r, n.slots), this.#a = new j(i, n, this.#i), this.#o = new le(i, n, this.#i), this.#s = new be(i, this.#i), this.#c = new me(i, this.#i, this.#s), this.#u = new re(i, n), this.#d = new xe(i, e.timestamps, Se), this.#S = i.createBuffer({
|
|
920
937
|
label: "counts readback",
|
|
921
938
|
size: (l.projected + 1) * 4,
|
|
922
939
|
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
@@ -1009,7 +1026,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
1009
1026
|
}
|
|
1010
1027
|
#D(e, t) {
|
|
1011
1028
|
let n = this.#f, [r, i] = [this.#b, this.#x];
|
|
1012
|
-
n.set(e.view,
|
|
1029
|
+
n.set(e.view, L.view), n.set(e.proj, L.proj), n.set(S(this.#m, e.proj, e.view), L.viewProj), n.set(t, L.planes), n.set(e.camera.subarray(0, 3), L.camera), n[L.time] = e.time, n.set([r, i], L.viewport), n.set([e.proj[0] * r / 2, e.proj[5] * i / 2], L.focal), n[L.near] = e.near, n[L.far] = e.far, n[L.lowPass] = f, this.#p[L.clusters] = this.#r.listed, this.#e.queue.writeBuffer(this.#i.uniforms, 0, n);
|
|
1013
1030
|
for (let { shade: t, slot: n } of this.#g) t.update(e, this.#h.subarray(n * 4, (n + t.uniforms) * 4));
|
|
1014
1031
|
this.#g.length && this.#e.queue.writeBuffer(this.#i.plugins, 0, this.#h);
|
|
1015
1032
|
}
|
|
@@ -1042,7 +1059,7 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
1042
1059
|
this.#T = t[l.visible], this.#w = Math.min(t[l.projected], this.#i.capacity), e.unmap();
|
|
1043
1060
|
}).catch(() => {}).finally(() => this.#C = !1);
|
|
1044
1061
|
}
|
|
1045
|
-
},
|
|
1062
|
+
}, we = [
|
|
1046
1063
|
[0, 1],
|
|
1047
1064
|
[0, -1],
|
|
1048
1065
|
[1, 1],
|
|
@@ -1050,195 +1067,42 @@ var ge = "// lsd radix sort, 8 bits a pass: block digit counts, a two-level scan
|
|
|
1050
1067
|
[2, 0],
|
|
1051
1068
|
[2, -1]
|
|
1052
1069
|
];
|
|
1053
|
-
function
|
|
1070
|
+
function Te(e, t) {
|
|
1054
1071
|
let n = (e, n) => t[n * 4 + e];
|
|
1055
|
-
return
|
|
1072
|
+
return we.forEach(([t, r], i) => {
|
|
1056
1073
|
for (let a = 0; a < 4; a++) e[i * 4 + a] = r ? n(3, a) + r * n(t, a) : n(t, a);
|
|
1057
1074
|
let a = Math.hypot(e[i * 4], e[i * 4 + 1], e[i * 4 + 2]) || 1;
|
|
1058
1075
|
for (let t = 0; t < 4; t++) e[i * 4 + t] /= a;
|
|
1059
1076
|
}), e;
|
|
1060
1077
|
}
|
|
1061
|
-
|
|
1062
|
-
//#region src/engine/plan/footprint.ts
|
|
1063
|
-
var De = [
|
|
1064
|
-
0,
|
|
1065
|
-
0,
|
|
1066
|
-
0
|
|
1067
|
-
];
|
|
1068
|
-
function Oe(e, t, n, r) {
|
|
1069
|
-
let i = (e * e + e * t + t * t + n * n + n * r + r * r) / 3;
|
|
1070
|
-
return 1 + 15 * Math.max(0, 1 - i) ** 2;
|
|
1071
|
-
}
|
|
1072
|
-
function ke(e, t, n, r, i, a, o, s = 1, c = {
|
|
1073
|
-
shown: !1,
|
|
1074
|
-
pixels: 0,
|
|
1075
|
-
weight: 1
|
|
1076
|
-
}, l = De) {
|
|
1077
|
-
let u = (e[0] + e[3]) / 2 - l[0], d = (e[1] + e[4]) / 2 - l[1], f = (e[2] + e[5]) / 2 - l[2], p = (e[3] - e[0]) / 2, m = (e[4] - e[1]) / 2, h = (e[5] - e[2]) / 2, g = t[0] * u + t[4] * d + t[8] * f + t[12], _ = t[1] * u + t[5] * d + t[9] * f + t[13], v = -(t[2] * u + t[6] * d + t[10] * f + t[14]), y = Math.abs(t[0]) * p + Math.abs(t[4]) * m + Math.abs(t[8]) * h, b = Math.abs(t[1]) * p + Math.abs(t[5]) * m + Math.abs(t[9]) * h, x = Math.abs(t[2]) * p + Math.abs(t[6]) * m + Math.abs(t[10]) * h;
|
|
1078
|
-
if (c.pixels = 0, c.weight = 1, c.shown = !1, v + x < a || v - x > o) return c;
|
|
1079
|
-
let S = Math.max(a, v - x), C = Math.max(a, v + x), w = i * n / r;
|
|
1080
|
-
if (Math.abs(g) - y > s * w * C || Math.abs(_) - b > s * i * C) return c;
|
|
1081
|
-
let T = Math.min((g - y) / S, (g - y) / C) / w, E = Math.max((g + y) / S, (g + y) / C) / w, D = Math.min((_ - b) / S, (_ - b) / C) / i, O = Math.max((_ + b) / S, (_ + b) / C) / i;
|
|
1082
|
-
if (E < -s || T > s || O < -s || D > s) return c;
|
|
1083
|
-
let k = Math.max(-s, T), A = Math.min(s, E), j = Math.max(-s, D), M = Math.min(s, O), N = (E - T) * (O - D), ee = (A - k) * (M - j);
|
|
1084
|
-
return N <= 0 || ee <= 0 || (c.shown = E > -1 && T < 1 && O > -1 && D < 1, c.pixels = N * n * r / 4, c.weight = Oe(k, A, j, M)), c;
|
|
1085
|
-
}
|
|
1086
|
-
//#endregion
|
|
1087
|
-
//#region src/engine/plan/cut.ts
|
|
1088
|
-
var Ae = 1 / .8 ** 2, je = 1.1, Me = class {
|
|
1089
|
-
#e = /* @__PURE__ */ new Map();
|
|
1090
|
-
#t = /* @__PURE__ */ new Map();
|
|
1091
|
-
#n = {
|
|
1092
|
-
shown: !1,
|
|
1093
|
-
pixels: 0,
|
|
1094
|
-
weight: 1
|
|
1095
|
-
};
|
|
1096
|
-
plan(e, t, n, r) {
|
|
1097
|
-
let { budget: i, capacity: a, now: o, predicted: s } = r, l = [], u = [], d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = e.wanted(), m = /* @__PURE__ */ new Map(), h = new Pe(), g = 0, _ = 0, v = (e) => {
|
|
1098
|
-
let t = e.page, r = t.row.count;
|
|
1099
|
-
l.push(t), u.push(+!!e.shown | (e.near ? 2 : 0)), _ += c(r), e.shown && (g += r);
|
|
1100
|
-
let i = this.#e.get(t.id), a = i !== void 0, s = e.pixels * e.weight, d = s / Math.max(1, r);
|
|
1101
|
-
p.length && e.pixels > 0 && m.set(t.id, d);
|
|
1102
|
-
let f = a && !e.shown && o - (this.#t.get(t.id) ?? -Infinity) <= 1500 ? i : null;
|
|
1103
|
-
(r < s * (a ? Ae : 1) || f !== null) && Ne(t, n) && h.push({
|
|
1104
|
-
page: t,
|
|
1105
|
-
shown: e.shown,
|
|
1106
|
-
held: f,
|
|
1107
|
-
ratio: d
|
|
1108
|
-
});
|
|
1109
|
-
};
|
|
1110
|
-
for (let n of e.roots) v(this.#r(n, t, s));
|
|
1111
|
-
let y = !1;
|
|
1112
|
-
for (; h.size;) {
|
|
1113
|
-
let { page: e, shown: n, held: r } = h.pop(), l = [], u = 0;
|
|
1114
|
-
for (let n = 0; n < e.children.length; n++) {
|
|
1115
|
-
let i = e.children[n];
|
|
1116
|
-
if (!i) continue;
|
|
1117
|
-
let a = this.#r(i, t, s);
|
|
1118
|
-
a.pixels <= 0 && !((r ?? 0) & 1 << n) || (l.push(a), u |= 1 << n);
|
|
1119
|
-
}
|
|
1120
|
-
if (!l.length) continue;
|
|
1121
|
-
let p = 0, m = n ? -e.row.count : 0;
|
|
1122
|
-
for (let e of l) p += c(e.page.row.count), e.shown && (m += e.page.row.count);
|
|
1123
|
-
if (_ + p > a) break;
|
|
1124
|
-
if (m > 0 && (y || g + m > i)) {
|
|
1125
|
-
y = !0;
|
|
1126
|
-
continue;
|
|
1127
|
-
}
|
|
1128
|
-
d.set(e.id, u);
|
|
1129
|
-
let b = n ? o : this.#t.get(e.id);
|
|
1130
|
-
b !== void 0 && f.set(e.id, b), n && (g -= e.row.count);
|
|
1131
|
-
for (let e of l) v(e);
|
|
1132
|
-
}
|
|
1133
|
-
this.#e = d, this.#t = f;
|
|
1134
|
-
let b = [], x = [], S = new Set(d.keys()), C = 0;
|
|
1135
|
-
for (let e = 0; e < l.length; e++) {
|
|
1136
|
-
let t = l[e];
|
|
1137
|
-
d.has(t.id) || (b.push(t), S.add(t.id), n(t.id) || (u[e] & 1 && (C += t.row.count), x.push({
|
|
1138
|
-
page: t,
|
|
1139
|
-
near: !!(u[e] & 2)
|
|
1140
|
-
})));
|
|
1141
|
-
}
|
|
1142
|
-
let w = [];
|
|
1143
|
-
for (let e of p) {
|
|
1144
|
-
let t = -1;
|
|
1145
|
-
for (let n of e.over) t = Math.max(t, m.get(n.id) ?? -1);
|
|
1146
|
-
t >= 0 && w.push({
|
|
1147
|
-
wanted: e,
|
|
1148
|
-
rank: t
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
return w.sort((e, t) => t.rank - e.rank), {
|
|
1152
|
-
cut: b,
|
|
1153
|
-
load: x.filter(({ near: e }) => e || !s && C === 0).map(({ page: e }) => e),
|
|
1154
|
-
idx: w.map((e) => e.wanted),
|
|
1155
|
-
keep: S,
|
|
1156
|
-
planned: g,
|
|
1157
|
-
missing: C
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
#r(e, t, n) {
|
|
1161
|
-
let r = this.#i(e, t, je), i = r.shown, { pixels: a, weight: o } = r, s = i;
|
|
1162
|
-
if (n) {
|
|
1163
|
-
let t = this.#i(e, n, je);
|
|
1164
|
-
t.pixels > a && ({pixels: a, weight: o} = t), s ||= t.shown;
|
|
1165
|
-
}
|
|
1166
|
-
return {
|
|
1167
|
-
page: e,
|
|
1168
|
-
shown: i,
|
|
1169
|
-
near: s,
|
|
1170
|
-
pixels: a,
|
|
1171
|
-
weight: o
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
#i(e, t, n) {
|
|
1175
|
-
let { width: r, height: i, tan: a, near: o, far: s } = t;
|
|
1176
|
-
return ke(e.box, t.view, r, i, a, o, s, n, this.#n, t.origin);
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
function Ne(e, t) {
|
|
1180
|
-
let { children: n } = e;
|
|
1181
|
-
return e.g > 0 && t(e.id) && !n.includes(void 0) && n.some((e) => e !== null);
|
|
1182
|
-
}
|
|
1183
|
-
var Pe = class {
|
|
1184
|
-
#e = [];
|
|
1185
|
-
get size() {
|
|
1186
|
-
return this.#e.length;
|
|
1187
|
-
}
|
|
1188
|
-
push(e) {
|
|
1189
|
-
let t = this.#e;
|
|
1190
|
-
t.push(e);
|
|
1191
|
-
let n = t.length - 1;
|
|
1192
|
-
for (; n > 0;) {
|
|
1193
|
-
let r = n - 1 >> 1;
|
|
1194
|
-
if (!L(e, t[r])) break;
|
|
1195
|
-
t[n] = t[r], n = r;
|
|
1196
|
-
}
|
|
1197
|
-
t[n] = e;
|
|
1198
|
-
}
|
|
1199
|
-
pop() {
|
|
1200
|
-
let e = this.#e, t = e[0], n = e.pop();
|
|
1201
|
-
if (e.length) {
|
|
1202
|
-
let t = 0;
|
|
1203
|
-
for (; 2 * t + 1 < e.length;) {
|
|
1204
|
-
let r = 2 * t + 1;
|
|
1205
|
-
if (r + 1 < e.length && L(e[r + 1], e[r]) && r++, !L(e[r], n)) break;
|
|
1206
|
-
e[t] = e[r], t = r;
|
|
1207
|
-
}
|
|
1208
|
-
e[t] = n;
|
|
1209
|
-
}
|
|
1210
|
-
return t;
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
function L(e, t) {
|
|
1214
|
-
return e.shown === t.shown ? e.ratio > t.ratio : e.shown;
|
|
1215
|
-
}
|
|
1216
|
-
var R = .25, Fe = class {
|
|
1078
|
+
var Ee = class {
|
|
1217
1079
|
#e = /* @__PURE__ */ new Map();
|
|
1218
1080
|
update(e, t, n, r) {
|
|
1219
|
-
let i = this.#e, a =
|
|
1220
|
-
for (let [e, r] of i) t(r.page.id) ? (o = Math.max(o, r.level), !r.held && (r.start !== null && n - r.start >= 250 && (r.start = null), a.has(e) || (r.frozen =
|
|
1081
|
+
let i = this.#e, a = De(e, t), o = -1;
|
|
1082
|
+
for (let [e, r] of i) t(r.page.id) ? (o = Math.max(o, r.level), !r.held && (r.start !== null && n - r.start >= 250 && (r.start = null), a.has(e) || (r.frozen = z(r, n), r.start = null, r.out = null, r.covered = !1, r.held = !0))) : i.delete(e);
|
|
1221
1083
|
let s = /* @__PURE__ */ new Set();
|
|
1222
1084
|
for (let [e, t] of a) {
|
|
1223
1085
|
let r = i.get(e);
|
|
1224
|
-
if (r)
|
|
1225
|
-
|
|
1226
|
-
let r = Le(t, e % 4, n);
|
|
1086
|
+
if (!r) {
|
|
1087
|
+
let r = Oe(t, e % 4, n);
|
|
1227
1088
|
o = Math.max(o, r.level), i.set(e, r), s.add(r);
|
|
1089
|
+
} else if (r.held) {
|
|
1090
|
+
let e = z(r, n);
|
|
1091
|
+
r.held = !1, r.out = null, e < 255 && (r.start = n - e / 255 * 250, s.add(r));
|
|
1228
1092
|
}
|
|
1229
1093
|
}
|
|
1230
1094
|
let l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
|
|
1231
1095
|
for (let e of i.values()) if (e.held) {
|
|
1232
1096
|
l.set(e.cell, e);
|
|
1233
1097
|
for (let t = e.level, n = e.col, r = e.row; t <= o; t++, n >>= 1, r >>= 1) {
|
|
1234
|
-
let i =
|
|
1098
|
+
let i = R(t, n, r), a = u.get(i);
|
|
1235
1099
|
a ? a.push(e) : u.set(i, [e]);
|
|
1236
1100
|
}
|
|
1237
1101
|
}
|
|
1238
1102
|
let d = (e) => {
|
|
1239
1103
|
let t = [...u.get(e.cell) ?? []];
|
|
1240
1104
|
for (let n = e.level + 1, r = e.col >> 1, i = e.row >> 1; n <= o; n++, r >>= 1, i >>= 1) {
|
|
1241
|
-
let e = l.get(
|
|
1105
|
+
let e = l.get(R(n, r, i));
|
|
1242
1106
|
e && t.push(e);
|
|
1243
1107
|
}
|
|
1244
1108
|
return t;
|
|
@@ -1249,7 +1113,8 @@ var R = .25, Fe = class {
|
|
|
1249
1113
|
m += e.splats;
|
|
1250
1114
|
for (let t of d(e)) f.has(t) || (f.add(t), m += t.splats, g(t.page));
|
|
1251
1115
|
}
|
|
1252
|
-
let
|
|
1116
|
+
for (let e of i.values()) e.held && e.out !== null && !f.has(e) && (m += e.splats);
|
|
1117
|
+
let _ = 1 * r;
|
|
1253
1118
|
for (let e of s) {
|
|
1254
1119
|
let t = d(e).filter((e) => !f.has(e)), n = t.reduce((e, t) => e + t.splats, e.splats), r = new Set(t.map((e) => e.page).filter((e) => !p.has(e))), i = [...r].reduce((e, t) => e + c(t.row.count), 0);
|
|
1255
1120
|
if (m + n > _ || h + i > _) e.start = null;
|
|
@@ -1261,12 +1126,13 @@ var R = .25, Fe = class {
|
|
|
1261
1126
|
}
|
|
1262
1127
|
let v = /* @__PURE__ */ new Map(), y = !1;
|
|
1263
1128
|
for (let [e, t] of i) {
|
|
1264
|
-
if (t.held &&
|
|
1129
|
+
if (t.held && f.has(t)) t.out !== null && (t.frozen = z(t, n)), t.out = null, t.covered = !0;
|
|
1130
|
+
else if (t.held && (t.covered && t.out === null && (t.out = n), !t.covered || z(t, n) === 0)) {
|
|
1265
1131
|
i.delete(e);
|
|
1266
1132
|
continue;
|
|
1267
1133
|
}
|
|
1268
1134
|
(t.held || t.start !== null) && (y = !0);
|
|
1269
|
-
let r =
|
|
1135
|
+
let r = z(t, n);
|
|
1270
1136
|
if (!r) continue;
|
|
1271
1137
|
let a = v.get(t.page.id);
|
|
1272
1138
|
a ? a.factors = (a.factors | r << 8 * t.q) >>> 0 : v.set(t.page.id, {
|
|
@@ -1280,7 +1146,7 @@ var R = .25, Fe = class {
|
|
|
1280
1146
|
};
|
|
1281
1147
|
}
|
|
1282
1148
|
};
|
|
1283
|
-
function
|
|
1149
|
+
function De(e, t) {
|
|
1284
1150
|
let n = new Set(e), r = /* @__PURE__ */ new Set(), i = [];
|
|
1285
1151
|
for (let t of e) for (let e = t; e && !r.has(e); e = e.parent) r.add(e), e.parent || i.push(e);
|
|
1286
1152
|
let a = /* @__PURE__ */ new Map(), o = (e) => {
|
|
@@ -1292,7 +1158,7 @@ function Ie(e, t) {
|
|
|
1292
1158
|
for (let e of i) t(e.id) && o(e);
|
|
1293
1159
|
return a;
|
|
1294
1160
|
}
|
|
1295
|
-
function
|
|
1161
|
+
function Oe(t, n, r) {
|
|
1296
1162
|
let i = e * 2 ** t.g, a = t.g - 1, o = 2 * (Math.round(t.unit.e / i) + t.row.i) + (n & 1), s = 2 * (Math.round(t.unit.n / i) + t.row.j) + (n >> 1);
|
|
1297
1163
|
return {
|
|
1298
1164
|
page: t,
|
|
@@ -1300,122 +1166,506 @@ function Le(t, n, r) {
|
|
|
1300
1166
|
level: a,
|
|
1301
1167
|
col: o,
|
|
1302
1168
|
row: s,
|
|
1303
|
-
cell:
|
|
1304
|
-
splats:
|
|
1169
|
+
cell: R(a, o, s),
|
|
1170
|
+
splats: ke(t.row, n),
|
|
1305
1171
|
start: r,
|
|
1306
1172
|
frozen: 0,
|
|
1173
|
+
out: null,
|
|
1174
|
+
covered: !1,
|
|
1307
1175
|
held: !1
|
|
1308
1176
|
};
|
|
1309
1177
|
}
|
|
1310
|
-
var
|
|
1311
|
-
function
|
|
1178
|
+
var R = (e, t, n) => ((e + 1) * 2 ** 21 + t) * 2 ** 21 + n;
|
|
1179
|
+
function ke({ count: e, quadrants: t }, n) {
|
|
1312
1180
|
return (n < 3 ? t[n] : e) - (n > 0 ? t[n - 1] : 0);
|
|
1313
1181
|
}
|
|
1314
|
-
function
|
|
1315
|
-
return e.held ? e.frozen : e.start === null ? 255 : Math.min(255, Math.round((t - e.start) / 250 * 255));
|
|
1182
|
+
function z(e, t) {
|
|
1183
|
+
return e.held ? e.out === null ? e.frozen : Math.max(0, Math.round(e.frozen * (1 - (t - e.out) / 250))) : e.start === null ? 255 : Math.min(255, Math.round((t - e.start) / 250 * 255));
|
|
1316
1184
|
}
|
|
1317
1185
|
//#endregion
|
|
1318
|
-
//#region src/engine/
|
|
1319
|
-
var
|
|
1320
|
-
|
|
1321
|
-
|
|
1186
|
+
//#region src/engine/plan/footprint.ts
|
|
1187
|
+
var Ae = [
|
|
1188
|
+
0,
|
|
1189
|
+
0,
|
|
1190
|
+
0
|
|
1191
|
+
];
|
|
1192
|
+
function je(e, t, n, r) {
|
|
1193
|
+
let i = (e * e + e * t + t * t + n * n + n * r + r * r) / 3;
|
|
1194
|
+
return 1 + 15 * Math.max(0, 1 - i) ** 2;
|
|
1322
1195
|
}
|
|
1323
|
-
function
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1196
|
+
function Me(e, t, n, r, i, a, o, s = 1, c = {
|
|
1197
|
+
shown: !1,
|
|
1198
|
+
pixels: 0,
|
|
1199
|
+
weight: 1
|
|
1200
|
+
}, l = Ae) {
|
|
1201
|
+
let u = (e[0] + e[3]) / 2 - l[0], d = (e[1] + e[4]) / 2 - l[1], f = (e[2] + e[5]) / 2 - l[2], p = (e[3] - e[0]) / 2, m = (e[4] - e[1]) / 2, h = (e[5] - e[2]) / 2, g = t[0] * u + t[4] * d + t[8] * f + t[12], _ = t[1] * u + t[5] * d + t[9] * f + t[13], v = -(t[2] * u + t[6] * d + t[10] * f + t[14]), y = Math.abs(t[0]) * p + Math.abs(t[4]) * m + Math.abs(t[8]) * h, b = Math.abs(t[1]) * p + Math.abs(t[5]) * m + Math.abs(t[9]) * h, x = Math.abs(t[2]) * p + Math.abs(t[6]) * m + Math.abs(t[10]) * h;
|
|
1202
|
+
if (c.pixels = 0, c.weight = 1, c.shown = !1, v + x < a || v - x > o) return c;
|
|
1203
|
+
let S = Math.max(a, v - x), C = Math.max(a, v + x), w = i * n / r;
|
|
1204
|
+
if (Math.abs(g) - y > s * w * C || Math.abs(_) - b > s * i * C) return c;
|
|
1205
|
+
let T = Math.min((g - y) / S, (g - y) / C) / w, E = Math.max((g + y) / S, (g + y) / C) / w, D = Math.min((_ - b) / S, (_ - b) / C) / i, O = Math.max((_ + b) / S, (_ + b) / C) / i;
|
|
1206
|
+
if (E < -s || T > s || O < -s || D > s) return c;
|
|
1207
|
+
let k = Math.max(-s, T), A = Math.min(s, E), j = Math.max(-s, D), M = Math.min(s, O), N = (E - T) * (O - D), ee = (A - k) * (M - j);
|
|
1208
|
+
return N <= 0 || ee <= 0 || (c.shown = E > -1 && T < 1 && O > -1 && D < 1, c.pixels = N * n * r / 4, c.weight = je(k, A, j, M)), c;
|
|
1327
1209
|
}
|
|
1328
|
-
var
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
}), this.#t = this.#t.filter((n) => t - n.time <= Math.max(1e3, 2 * e)), t - this.#t[0].time < 300) return !1;
|
|
1350
|
-
let i = B(this.#t.map((e) => e.ms), .9);
|
|
1351
|
-
if (this.#r = i > 20 ? this.#r + r : 0, this.#i = i < 14 ? this.#i + r : 0, this.#r >= 2e3) {
|
|
1352
|
-
if (this.#e < He.length - 1) this.#e++;
|
|
1353
|
-
else return !1;
|
|
1354
|
-
} else if (this.#i >= 5e3) {
|
|
1355
|
-
if (this.#e > 0) this.#e--;
|
|
1356
|
-
else return !1;
|
|
1357
|
-
} else return !1;
|
|
1358
|
-
return this.#a(), !0;
|
|
1359
|
-
}
|
|
1360
|
-
}, Ge = class {
|
|
1210
|
+
var B = /* @__PURE__ */ new Float64Array(6), Ne = {
|
|
1211
|
+
shown: !1,
|
|
1212
|
+
pixels: 0,
|
|
1213
|
+
weight: 1
|
|
1214
|
+
};
|
|
1215
|
+
function Pe(e, [t, n, r], i, a, o, s, c, l, u = Ae) {
|
|
1216
|
+
let d = r / 2, f = Math.max(0, t - e[0], n - e[1], e[3] - t - r, e[4] - n - r);
|
|
1217
|
+
B[2] = e[2], B[5] = e[5];
|
|
1218
|
+
let p = 0;
|
|
1219
|
+
for (let r = 0; r < 4; r++) {
|
|
1220
|
+
let m = t + (r & 1) * d, h = n + (r >> 1) * d;
|
|
1221
|
+
B[0] = Math.max(e[0], m - f), B[1] = Math.max(e[1], h - f), B[3] = Math.min(e[3], m + d + f), B[4] = Math.min(e[4], h + d + f), !(B[0] > B[3] || B[1] > B[4]) && Me(B, i, a, o, s, c, l, 1, Ne, u).shown && (p |= 1 << r);
|
|
1222
|
+
}
|
|
1223
|
+
return p;
|
|
1224
|
+
}
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/engine/world/tree.ts
|
|
1227
|
+
var V = (e, t, n) => (e * 256 + t) * 256 + n, Fe = class {
|
|
1228
|
+
roots = [];
|
|
1229
|
+
pages = /* @__PURE__ */ new Map();
|
|
1230
|
+
units = /* @__PURE__ */ new Map();
|
|
1361
1231
|
#e;
|
|
1362
|
-
#t
|
|
1363
|
-
#n =
|
|
1364
|
-
#r = /* @__PURE__ */ new
|
|
1365
|
-
#i = /* @__PURE__ */ new
|
|
1366
|
-
#a = /* @__PURE__ */ new Map();
|
|
1232
|
+
#t;
|
|
1233
|
+
#n = 0;
|
|
1234
|
+
#r = /* @__PURE__ */ new Map();
|
|
1235
|
+
#i = /* @__PURE__ */ new Map();
|
|
1367
1236
|
constructor(e) {
|
|
1368
|
-
this.#e = e;
|
|
1237
|
+
this.#e = new Set(e.roots.map(H)), this.#t = Math.max(...e.roots.map((e) => e.level));
|
|
1369
1238
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1239
|
+
add(e, t) {
|
|
1240
|
+
let n = H(e), r = this.units.get(n);
|
|
1241
|
+
if (r) return r;
|
|
1242
|
+
let o = /* @__PURE__ */ new Map(), s = {
|
|
1243
|
+
level: e.level,
|
|
1244
|
+
e: e.e,
|
|
1245
|
+
n: e.n,
|
|
1246
|
+
idx: e,
|
|
1247
|
+
path: t,
|
|
1248
|
+
parent: null,
|
|
1249
|
+
pages: [],
|
|
1250
|
+
grid: o
|
|
1380
1251
|
};
|
|
1381
|
-
let
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1252
|
+
for (let t of e.rows) {
|
|
1253
|
+
let n = t.box, r = {
|
|
1254
|
+
id: this.#n++,
|
|
1255
|
+
unit: s,
|
|
1256
|
+
row: t,
|
|
1257
|
+
g: t.g,
|
|
1258
|
+
box: Float64Array.of(e.e + n[0], e.n + n[1], n[2], e.e + n[3], e.n + n[4], n[5]),
|
|
1259
|
+
parent: null,
|
|
1260
|
+
children: [
|
|
1261
|
+
null,
|
|
1262
|
+
null,
|
|
1263
|
+
null,
|
|
1264
|
+
null
|
|
1265
|
+
]
|
|
1266
|
+
};
|
|
1267
|
+
this.pages.set(r.id, r), s.pages.push(r), o.set(V(t.g, t.i, t.j), r);
|
|
1386
1268
|
}
|
|
1387
|
-
|
|
1388
|
-
for (let e
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
let r = this.#o(e, n.get(e.pack));
|
|
1392
|
-
for (let e of r.pages) this.#a.set(e.id, r);
|
|
1393
|
-
this.#r.add(r), t.push(r);
|
|
1269
|
+
this.units.set(n, s), this.#r.delete(n);
|
|
1270
|
+
for (let t = e.level + 1; t <= this.#t; t++) {
|
|
1271
|
+
let n = H(U(e, t));
|
|
1272
|
+
this.#i.set(n, (this.#i.get(n) ?? 0) + 1);
|
|
1394
1273
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
for (let t of e.pages) this.#a.get(t.id) === e && this.#a.delete(t.id);
|
|
1274
|
+
let c = new Set(e.rows.map((e) => e.g)), l = Math.max(...c), u = e.level === 0 ? 0 : e.level + 1, d = new Set(e.children.map((e) => e.quadrant));
|
|
1275
|
+
for (let e of s.pages) {
|
|
1276
|
+
let { g: t, i: n, j: r } = e.row;
|
|
1277
|
+
c.has(t + 1) && (e.parent = o.get(V(t + 1, n >> 1, r >> 1)) ?? null);
|
|
1278
|
+
for (let i = 0; i < 4; i++) {
|
|
1279
|
+
let a = 2 * n + (i & 1), s = 2 * r + (i >> 1);
|
|
1280
|
+
c.has(t - 1) ? e.children[i] = o.get(V(t - 1, a, s)) ?? null : t === u && t > 0 && (e.children[i] = d.has((a >> 3) + 2 * (s >> 3)) ? void 0 : null);
|
|
1281
|
+
}
|
|
1404
1282
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
let {
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1283
|
+
if (this.#e.has(n)) for (let e of s.pages) e.g === l && this.roots.push(e);
|
|
1284
|
+
else {
|
|
1285
|
+
let t = this.units.get(H(U(e, e.level + 1)));
|
|
1286
|
+
t && this.#o(t, s);
|
|
1287
|
+
}
|
|
1288
|
+
let f = a(s.idx);
|
|
1289
|
+
for (let { key: t } of f) {
|
|
1290
|
+
let n = t.level === e.level - 1 ? this.units.get(H(t)) : void 0;
|
|
1291
|
+
n && this.#o(s, n);
|
|
1292
|
+
}
|
|
1293
|
+
for (let { key: e, hash: t } of f) {
|
|
1294
|
+
let n = H(e);
|
|
1295
|
+
if (this.units.has(n)) continue;
|
|
1296
|
+
let r = this.#r.get(n);
|
|
1297
|
+
if (r && r.from <= s.level) continue;
|
|
1298
|
+
let a = this.#s(s, e), o = {
|
|
1299
|
+
...e,
|
|
1300
|
+
path: i(e, t, "idx"),
|
|
1301
|
+
over: a
|
|
1302
|
+
};
|
|
1303
|
+
this.#r.set(n, {
|
|
1304
|
+
wanted: o,
|
|
1305
|
+
from: s.level
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
return s;
|
|
1309
|
+
}
|
|
1310
|
+
wanted() {
|
|
1311
|
+
return Array.from(this.#r.values(), (e) => e.wanted);
|
|
1312
|
+
}
|
|
1313
|
+
ground(e, t) {
|
|
1314
|
+
for (let n of this.roots) {
|
|
1315
|
+
let [r, i, a] = W(n);
|
|
1316
|
+
if (e < r || e >= r + a || t < i || t >= i + a) continue;
|
|
1317
|
+
let o = n;
|
|
1318
|
+
for (;;) {
|
|
1319
|
+
let n = +(e >= r + a / 2), s = +(t >= i + a / 2), c = o.children[n + 2 * s];
|
|
1320
|
+
if (!c) return o.box[2];
|
|
1321
|
+
o = c, [r, i, a] = W(o);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
async load(e, t, n) {
|
|
1326
|
+
for (;;) {
|
|
1327
|
+
let r = this.wanted().filter((n) => Ie(n, e, t));
|
|
1328
|
+
if (r.length === 0) return;
|
|
1329
|
+
(await Promise.all(r.map((e) => n(e.path)))).forEach((e, t) => this.add(e, r[t].path));
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
prune(e) {
|
|
1333
|
+
let t = [], n = [...this.units.values()].sort((e, t) => e.level - t.level);
|
|
1334
|
+
for (let r of n) {
|
|
1335
|
+
let n = H(r);
|
|
1336
|
+
if (this.#e.has(n) || this.#i.has(n) || r.pages.some((t) => e.has(t.id))) continue;
|
|
1337
|
+
for (let e of r.pages) this.pages.delete(e.id), t.push(e.id);
|
|
1338
|
+
let i = r.parent;
|
|
1339
|
+
if (i) {
|
|
1340
|
+
let e = 250 * 2 ** r.level, t = (r.e - i.e) / e, n = (r.n - i.n) / e, a = i.idx.children.some((e) => e.quadrant === t + 2 * n);
|
|
1341
|
+
for (let e of this.#s(i, r)) e.children.fill(a ? void 0 : null);
|
|
1342
|
+
}
|
|
1343
|
+
this.units.delete(n);
|
|
1344
|
+
for (let e = r.level + 1; e <= this.#t; e++) {
|
|
1345
|
+
let t = H(U(r, e)), n = this.#i.get(t) - 1;
|
|
1346
|
+
n ? this.#i.set(t, n) : this.#i.delete(t);
|
|
1347
|
+
}
|
|
1348
|
+
for (let { key: e } of a(r.idx)) this.#a(e);
|
|
1349
|
+
this.#a(r);
|
|
1350
|
+
}
|
|
1351
|
+
return t;
|
|
1352
|
+
}
|
|
1353
|
+
#a(e) {
|
|
1354
|
+
let t = H(e);
|
|
1355
|
+
this.#r.delete(t);
|
|
1356
|
+
for (let n = e.level + 1; n <= e.level + 3; n++) {
|
|
1357
|
+
let r = this.units.get(H(U(e, n)));
|
|
1358
|
+
if (!r) continue;
|
|
1359
|
+
let o = a(r.idx).find((e) => H(e.key) === t);
|
|
1360
|
+
if (!o) continue;
|
|
1361
|
+
let s = {
|
|
1362
|
+
level: e.level,
|
|
1363
|
+
e: e.e,
|
|
1364
|
+
n: e.n,
|
|
1365
|
+
path: i(o.key, o.hash, "idx"),
|
|
1366
|
+
over: this.#s(r, e)
|
|
1367
|
+
};
|
|
1368
|
+
this.#r.set(t, {
|
|
1369
|
+
wanted: s,
|
|
1370
|
+
from: r.level
|
|
1371
|
+
});
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
#o(e, t) {
|
|
1376
|
+
t.parent = e;
|
|
1377
|
+
let n = t.level + 1, r = 250 * 2 ** t.level, i = (t.e - e.e) / r, a = (t.n - e.n) / r, o = e.grid;
|
|
1378
|
+
for (let n of this.#s(e, t)) n.children.fill(null);
|
|
1379
|
+
for (let e of t.pages) {
|
|
1380
|
+
if (e.g !== n) continue;
|
|
1381
|
+
let t = 8 * i + e.row.i, r = 8 * a + e.row.j, s = o.get(V(n + 1, t >> 1, r >> 1)) ?? null;
|
|
1382
|
+
e.parent = s, s && (s.children[(t & 1) + 2 * (r & 1)] = e);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
#s(t, n) {
|
|
1386
|
+
let r = t.level + 1, i = e * 2 ** r, a = (n.e - t.e) / i, o = (n.n - t.n) / i, s = 250 * 2 ** n.level / i, c = [];
|
|
1387
|
+
for (let e = o; e < o + s; e++) for (let n = a; n < a + s; n++) {
|
|
1388
|
+
let i = t.grid.get(V(r, n, e));
|
|
1389
|
+
i && c.push(i);
|
|
1390
|
+
}
|
|
1391
|
+
return c;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
function H(e) {
|
|
1395
|
+
return `${e.level}/${e.e}/${e.n}`;
|
|
1396
|
+
}
|
|
1397
|
+
function U(e, t) {
|
|
1398
|
+
let n = 250 * 2 ** t;
|
|
1399
|
+
return {
|
|
1400
|
+
level: t,
|
|
1401
|
+
e: Math.floor(e.e / n) * n,
|
|
1402
|
+
n: Math.floor(e.n / n) * n
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
function Ie(e, t, n) {
|
|
1406
|
+
let r = 250 * 2 ** e.level;
|
|
1407
|
+
return t >= e.e && t < e.e + r && n >= e.n && n < e.n + r;
|
|
1408
|
+
}
|
|
1409
|
+
function W(t) {
|
|
1410
|
+
let n = e * 2 ** t.g;
|
|
1411
|
+
return [
|
|
1412
|
+
t.unit.e + t.row.i * n,
|
|
1413
|
+
t.unit.n + t.row.j * n,
|
|
1414
|
+
n
|
|
1415
|
+
];
|
|
1416
|
+
}
|
|
1417
|
+
//#endregion
|
|
1418
|
+
//#region src/engine/plan/cut.ts
|
|
1419
|
+
var Le = 1 / .8 ** 2, Re = 1.1, ze = class {
|
|
1420
|
+
#e = /* @__PURE__ */ new Map();
|
|
1421
|
+
#t = /* @__PURE__ */ new Map();
|
|
1422
|
+
#n = {
|
|
1423
|
+
shown: !1,
|
|
1424
|
+
pixels: 0,
|
|
1425
|
+
weight: 1
|
|
1426
|
+
};
|
|
1427
|
+
plan(e, t, n, r) {
|
|
1428
|
+
let { budget: i, capacity: a, now: o, predicted: s } = r, l = [], u = [], d = [], f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = e.wanted(), h = /* @__PURE__ */ new Map(), g = new He(), _ = 0, v = 0, y = (e) => {
|
|
1429
|
+
let t = e.page, r = t.row.count;
|
|
1430
|
+
l.push(t), u.push(e.visible), d.push(e.near), v += c(r), _ += e.visible;
|
|
1431
|
+
let i = this.#e.get(t.id), a = i !== void 0, s = e.pixels * e.weight, f = s / Math.max(1, r);
|
|
1432
|
+
m.length && e.pixels > 0 && h.set(t.id, f);
|
|
1433
|
+
let p = a && !e.shown && o - (this.#t.get(t.id) ?? -Infinity) <= 1500 ? i : null;
|
|
1434
|
+
(r < s * (a ? Le : 1) || p !== null) && Ve(t, n) && g.push({
|
|
1435
|
+
page: t,
|
|
1436
|
+
shown: e.shown,
|
|
1437
|
+
held: p,
|
|
1438
|
+
visible: e.visible,
|
|
1439
|
+
ratio: f
|
|
1440
|
+
});
|
|
1441
|
+
};
|
|
1442
|
+
for (let n of e.roots) y(this.#r(n, t, s));
|
|
1443
|
+
let b = [];
|
|
1444
|
+
for (; g.size;) {
|
|
1445
|
+
let e = g.pop(), { page: n, shown: r, held: l } = e, u = [], d = 0;
|
|
1446
|
+
for (let e = 0; e < n.children.length; e++) {
|
|
1447
|
+
let r = n.children[e];
|
|
1448
|
+
if (!r) continue;
|
|
1449
|
+
let i = this.#r(r, t, s);
|
|
1450
|
+
i.pixels <= 0 && !((l ?? 0) & 1 << e) || (u.push(i), d |= 1 << e);
|
|
1451
|
+
}
|
|
1452
|
+
if (!u.length) continue;
|
|
1453
|
+
let m = 0, h = -e.visible;
|
|
1454
|
+
for (let e of u) m += c(e.page.row.count), h += e.visible;
|
|
1455
|
+
if (v + m > a) break;
|
|
1456
|
+
if (h > 0 && (b.length || _ + h > i)) {
|
|
1457
|
+
b.push(e);
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
if (h < 0) for (let e of b.splice(0)) g.push(e);
|
|
1461
|
+
f.set(n.id, d);
|
|
1462
|
+
let x = r ? o : this.#t.get(n.id);
|
|
1463
|
+
x !== void 0 && p.set(n.id, x), _ -= e.visible;
|
|
1464
|
+
for (let e of u) y(e);
|
|
1465
|
+
}
|
|
1466
|
+
this.#e = f, this.#t = p;
|
|
1467
|
+
let x = [], S = [], C = new Set(f.keys()), w = 0;
|
|
1468
|
+
for (let e = 0; e < l.length; e++) {
|
|
1469
|
+
let t = l[e];
|
|
1470
|
+
f.has(t.id) || (x.push(t), C.add(t.id), n(t.id) || (w += u[e], S.push({
|
|
1471
|
+
page: t,
|
|
1472
|
+
near: d[e]
|
|
1473
|
+
})));
|
|
1474
|
+
}
|
|
1475
|
+
let T = [];
|
|
1476
|
+
for (let e of m) {
|
|
1477
|
+
let t = -1;
|
|
1478
|
+
for (let n of e.over) t = Math.max(t, h.get(n.id) ?? -1);
|
|
1479
|
+
t >= 0 && T.push({
|
|
1480
|
+
wanted: e,
|
|
1481
|
+
rank: t
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
return T.sort((e, t) => t.rank - e.rank), {
|
|
1485
|
+
cut: x,
|
|
1486
|
+
load: S.filter(({ near: e }) => e || !s && w === 0).map(({ page: e }) => e),
|
|
1487
|
+
idx: T.map((e) => e.wanted),
|
|
1488
|
+
keep: C,
|
|
1489
|
+
planned: _,
|
|
1490
|
+
missing: w
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
#r(e, t, n) {
|
|
1494
|
+
let r = this.#i(e, t, Re), i = r.shown, { pixels: a, weight: o } = r, s = i;
|
|
1495
|
+
if (n) {
|
|
1496
|
+
let t = this.#i(e, n, Re);
|
|
1497
|
+
t.pixels > a && ({pixels: a, weight: o} = t), s ||= t.shown;
|
|
1498
|
+
}
|
|
1499
|
+
return {
|
|
1500
|
+
page: e,
|
|
1501
|
+
shown: i,
|
|
1502
|
+
near: s,
|
|
1503
|
+
visible: i ? Be(e, t) : 0,
|
|
1504
|
+
pixels: a,
|
|
1505
|
+
weight: o
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
#i(e, t, n) {
|
|
1509
|
+
let { width: r, height: i, tan: a, near: o, far: s } = t;
|
|
1510
|
+
return Me(e.box, t.view, r, i, a, o, s, n, this.#n, t.origin);
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
function Be(e, t) {
|
|
1514
|
+
let { width: n, height: r, tan: i, near: a, far: o, origin: s } = t, c = Pe(e.box, W(e), t.view, n, r, i, a, o, s), l = 0;
|
|
1515
|
+
for (let t = 0; t < 4; t++) c & 1 << t && (l += ke(e.row, t));
|
|
1516
|
+
return l;
|
|
1517
|
+
}
|
|
1518
|
+
function Ve(e, t) {
|
|
1519
|
+
let { children: n } = e;
|
|
1520
|
+
return e.g > 0 && t(e.id) && !n.includes(void 0) && n.some((e) => e !== null);
|
|
1521
|
+
}
|
|
1522
|
+
var He = class {
|
|
1523
|
+
#e = [];
|
|
1524
|
+
get size() {
|
|
1525
|
+
return this.#e.length;
|
|
1526
|
+
}
|
|
1527
|
+
push(e) {
|
|
1528
|
+
let t = this.#e;
|
|
1529
|
+
t.push(e);
|
|
1530
|
+
let n = t.length - 1;
|
|
1531
|
+
for (; n > 0;) {
|
|
1532
|
+
let r = n - 1 >> 1;
|
|
1533
|
+
if (!G(e, t[r])) break;
|
|
1534
|
+
t[n] = t[r], n = r;
|
|
1535
|
+
}
|
|
1536
|
+
t[n] = e;
|
|
1537
|
+
}
|
|
1538
|
+
pop() {
|
|
1539
|
+
let e = this.#e, t = e[0], n = e.pop();
|
|
1540
|
+
if (e.length) {
|
|
1541
|
+
let t = 0;
|
|
1542
|
+
for (; 2 * t + 1 < e.length;) {
|
|
1543
|
+
let r = 2 * t + 1;
|
|
1544
|
+
if (r + 1 < e.length && G(e[r + 1], e[r]) && r++, !G(e[r], n)) break;
|
|
1545
|
+
e[t] = e[r], t = r;
|
|
1546
|
+
}
|
|
1547
|
+
e[t] = n;
|
|
1548
|
+
}
|
|
1549
|
+
return t;
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
function G(e, t) {
|
|
1553
|
+
return e.shown === t.shown ? e.ratio > t.ratio : e.shown;
|
|
1554
|
+
}
|
|
1555
|
+
//#endregion
|
|
1556
|
+
//#region src/engine/quality.ts
|
|
1557
|
+
var Ue = 5e5, We = 2073600, Ge = [1, .85], Ke = 30, qe = 55, Je = 2e3, Ye = 5e3, Xe = 5e5, Ze = .9;
|
|
1558
|
+
function Qe(e, t, n, r) {
|
|
1559
|
+
return Math.min(n, Math.sqrt(We / Math.max(1, e * t))) * r;
|
|
1560
|
+
}
|
|
1561
|
+
function $e(e, t) {
|
|
1562
|
+
if (!e.length) return 0;
|
|
1563
|
+
let n = [...e].sort((e, t) => e - t);
|
|
1564
|
+
return n[Math.ceil(n.length * t) - 1];
|
|
1565
|
+
}
|
|
1566
|
+
var et = class {
|
|
1567
|
+
#e = 0;
|
|
1568
|
+
#t;
|
|
1569
|
+
#n;
|
|
1570
|
+
#r;
|
|
1571
|
+
#i = [];
|
|
1572
|
+
#a = -Infinity;
|
|
1573
|
+
#o = 0;
|
|
1574
|
+
#s = 0;
|
|
1575
|
+
constructor(e, [t, n] = [e, e]) {
|
|
1576
|
+
this.#n = t, this.#r = Math.max(t, n), this.#t = Math.min(this.#r, Math.max(this.#n, e));
|
|
1577
|
+
}
|
|
1578
|
+
get scale() {
|
|
1579
|
+
return Ge[this.#e];
|
|
1580
|
+
}
|
|
1581
|
+
get budget() {
|
|
1582
|
+
return this.#t;
|
|
1583
|
+
}
|
|
1584
|
+
full() {
|
|
1585
|
+
this.#e = 0, this.#c();
|
|
1586
|
+
}
|
|
1587
|
+
#c() {
|
|
1588
|
+
this.#i = [], this.#o = 0, this.#s = 0, this.#a = -Infinity;
|
|
1589
|
+
}
|
|
1590
|
+
sample(e, t, n, r) {
|
|
1591
|
+
if (!n || t - this.#a > Math.max(250, 2 * e) || !Number.isFinite(e) || e <= 0) return this.#c(), this.#a = t, !1;
|
|
1592
|
+
let i = Math.max(0, t - this.#a);
|
|
1593
|
+
if (this.#a = t, this.#i.push({
|
|
1594
|
+
time: t,
|
|
1595
|
+
ms: e
|
|
1596
|
+
}), this.#i = this.#i.filter((n) => t - n.time <= Math.max(1e3, 2 * e)), t - this.#i[0].time < 300) return !1;
|
|
1597
|
+
let a = this.#i.reduce((e, t) => e + t.ms, 0) / this.#i.length;
|
|
1598
|
+
if (this.#o = a > 1e3 / Ke ? this.#o + i : 0, this.#s = a <= 1e3 / qe ? this.#s + i : 0, this.#o >= Je) {
|
|
1599
|
+
let e = Math.floor(Math.min(.9, 1e3 / Ke / a) * this.#t);
|
|
1600
|
+
if (this.#t > this.#n) this.#t = Math.max(this.#n, e);
|
|
1601
|
+
else if (this.#e < Ge.length - 1) this.#e++;
|
|
1602
|
+
else return !1;
|
|
1603
|
+
} else if (this.#s >= Ye) {
|
|
1604
|
+
if (this.#e > 0) this.#e--;
|
|
1605
|
+
else if (this.#t < this.#r && r >= Ze * this.#t) this.#t = Math.min(this.#r, this.#t + Xe);
|
|
1606
|
+
else return !1;
|
|
1607
|
+
} else return !1;
|
|
1608
|
+
return this.#c(), !0;
|
|
1609
|
+
}
|
|
1610
|
+
}, tt = class {
|
|
1611
|
+
#e;
|
|
1612
|
+
#t = [];
|
|
1613
|
+
#n = /* @__PURE__ */ new Set();
|
|
1614
|
+
#r = /* @__PURE__ */ new Set();
|
|
1615
|
+
#i = /* @__PURE__ */ new Set();
|
|
1616
|
+
#a = /* @__PURE__ */ new Map();
|
|
1617
|
+
constructor(e) {
|
|
1618
|
+
this.#e = e;
|
|
1619
|
+
}
|
|
1620
|
+
want(e) {
|
|
1621
|
+
this.#t = e, this.#n = new Set(e.map((e) => e.id));
|
|
1622
|
+
}
|
|
1623
|
+
next() {
|
|
1624
|
+
let e = [];
|
|
1625
|
+
for (let t of this.#r) this.#i.has(t) || t.pages.some((e) => this.#n.has(e.id)) || (this.#i.add(t), e.push(t));
|
|
1626
|
+
let t = [];
|
|
1627
|
+
if (this.#r.size >= this.#e.concurrency) return {
|
|
1628
|
+
start: t,
|
|
1629
|
+
abort: e
|
|
1630
|
+
};
|
|
1631
|
+
let n = /* @__PURE__ */ new Map();
|
|
1632
|
+
for (let e of this.#t) {
|
|
1633
|
+
if (this.#a.has(e.id)) continue;
|
|
1634
|
+
let t = n.get(e.pack);
|
|
1635
|
+
t ? t.push(e) : n.set(e.pack, [e]);
|
|
1636
|
+
}
|
|
1637
|
+
for (let e of n.values()) e.sort((e, t) => e.offset - t.offset);
|
|
1638
|
+
for (let e of this.#t) {
|
|
1639
|
+
if (this.#r.size >= this.#e.concurrency) break;
|
|
1640
|
+
if (this.#a.has(e.id)) continue;
|
|
1641
|
+
let r = this.#o(e, n.get(e.pack));
|
|
1642
|
+
for (let e of r.pages) this.#a.set(e.id, r);
|
|
1643
|
+
this.#r.add(r), t.push(r);
|
|
1644
|
+
}
|
|
1645
|
+
return {
|
|
1646
|
+
start: t,
|
|
1647
|
+
abort: e
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
done(e) {
|
|
1651
|
+
if (this.#r.delete(e)) {
|
|
1652
|
+
this.#i.delete(e);
|
|
1653
|
+
for (let t of e.pages) this.#a.get(t.id) === e && this.#a.delete(t.id);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
get queued() {
|
|
1657
|
+
let e = 0;
|
|
1658
|
+
for (let t of this.#n) this.#a.has(t) || e++;
|
|
1659
|
+
return e;
|
|
1660
|
+
}
|
|
1661
|
+
get loading() {
|
|
1662
|
+
return this.#a.size;
|
|
1663
|
+
}
|
|
1664
|
+
#o(e, t) {
|
|
1665
|
+
let { gap: n, span: r } = this.#e, i = Math.floor(e.offset / r), a = t.indexOf(e), o = [e], s = e.offset, c = e.offset + e.length;
|
|
1666
|
+
for (let e = a + 1; e < t.length; e++) {
|
|
1667
|
+
let a = t[e];
|
|
1668
|
+
if (this.#a.has(a.id)) continue;
|
|
1419
1669
|
let l = Math.max(c, a.offset + a.length);
|
|
1420
1670
|
if (a.offset - c > n || l - s > r || Math.floor(a.offset / r) !== i) break;
|
|
1421
1671
|
o.push(a), c = l;
|
|
@@ -1436,12 +1686,12 @@ var We = class {
|
|
|
1436
1686
|
pages: o
|
|
1437
1687
|
};
|
|
1438
1688
|
}
|
|
1439
|
-
},
|
|
1689
|
+
}, nt = {
|
|
1440
1690
|
idx: 8,
|
|
1441
1691
|
concurrency: 8,
|
|
1442
1692
|
gap: 65536,
|
|
1443
1693
|
span: 2097152
|
|
1444
|
-
},
|
|
1694
|
+
}, rt = 1e3, it = 3e4, at = 1e3, ot = 2e3, st = class {
|
|
1445
1695
|
#e;
|
|
1446
1696
|
#t;
|
|
1447
1697
|
#n;
|
|
@@ -1471,8 +1721,8 @@ var We = class {
|
|
|
1471
1721
|
#y = -Infinity;
|
|
1472
1722
|
#b = !1;
|
|
1473
1723
|
#x = !1;
|
|
1474
|
-
constructor(e, t, n, r, i, a =
|
|
1475
|
-
this.#e = e, this.#t = t, this.#n = n, this.#r = r, this.#i = i, this.#a = a, this.#o = new
|
|
1724
|
+
constructor(e, t, n, r, i, a = nt) {
|
|
1725
|
+
this.#e = e, this.#t = t, this.#n = n, this.#r = r, this.#i = i, this.#a = a, this.#o = new tt(a);
|
|
1476
1726
|
}
|
|
1477
1727
|
update(e, t, n) {
|
|
1478
1728
|
if (!this.#x) {
|
|
@@ -1539,7 +1789,7 @@ var We = class {
|
|
|
1539
1789
|
let n = this.#e.pages.get(e);
|
|
1540
1790
|
if (!n) return;
|
|
1541
1791
|
let { keep: r } = this.#s, i = this.#c;
|
|
1542
|
-
this.#n.add(e, t, [n.unit.e, n.unit.n], (e) => r.has(e) || i.has(e)) ? (this.#g.add(e), this.#m.delete(e) && this.#j(e)) : (this.#m.set(e, this.#u +
|
|
1792
|
+
this.#n.add(e, t, [n.unit.e, n.unit.n], (e) => r.has(e) || i.has(e)) ? (this.#g.add(e), this.#m.delete(e) && this.#j(e)) : (this.#m.set(e, this.#u + at), this.#A(e, at)), this.#r();
|
|
1543
1793
|
};
|
|
1544
1794
|
#E(e) {
|
|
1545
1795
|
this.#x || (this.#f.delete(e), this.#k(e.pack), this.#l = this.#l.filter((e) => this.#N(e.id, e.pack)), this.#o.want(this.#l), this.#o.done(e), this.#w(), this.#r());
|
|
@@ -1553,7 +1803,7 @@ var We = class {
|
|
|
1553
1803
|
this.#b = !0, this.#i();
|
|
1554
1804
|
return;
|
|
1555
1805
|
}
|
|
1556
|
-
let n = this.#p.get(e), r = n ? Math.min(2 * n.delay,
|
|
1806
|
+
let n = this.#p.get(e), r = n ? Math.min(2 * n.delay, it) : rt;
|
|
1557
1807
|
this.#p.set(e, {
|
|
1558
1808
|
delay: r,
|
|
1559
1809
|
until: this.#u + r
|
|
@@ -1574,11 +1824,11 @@ var We = class {
|
|
|
1574
1824
|
}
|
|
1575
1825
|
#M() {
|
|
1576
1826
|
let e = this.#u;
|
|
1577
|
-
if (e - this.#y <
|
|
1827
|
+
if (e - this.#y < ot) return;
|
|
1578
1828
|
this.#y = e;
|
|
1579
1829
|
for (let e of this.#g) this.#n.holds(e) || this.#g.delete(e);
|
|
1580
1830
|
for (let [t, n] of this.#m) n <= e && this.#m.delete(t);
|
|
1581
|
-
for (let [t, n] of this.#_) e - n >=
|
|
1831
|
+
for (let [t, n] of this.#_) e - n >= ot && this.#_.delete(t);
|
|
1582
1832
|
let { keep: t } = this.#s;
|
|
1583
1833
|
if (this.#e.pages.size <= 2 * (this.#g.size + t.size)) return;
|
|
1584
1834
|
let n = /* @__PURE__ */ new Set([
|
|
@@ -1603,7 +1853,7 @@ var We = class {
|
|
|
1603
1853
|
};
|
|
1604
1854
|
//#endregion
|
|
1605
1855
|
//#region src/engine/stream/remote.ts
|
|
1606
|
-
function
|
|
1856
|
+
function ct(e, t) {
|
|
1607
1857
|
let n = /* @__PURE__ */ new Map();
|
|
1608
1858
|
return (r) => {
|
|
1609
1859
|
if ("unfetch" in r) return void n.get(r.unfetch)?.abort();
|
|
@@ -1626,29 +1876,29 @@ function Qe(e, t) {
|
|
|
1626
1876
|
}
|
|
1627
1877
|
//#endregion
|
|
1628
1878
|
//#region src/engine/stream/worker.ts?worker&inline
|
|
1629
|
-
var $e = "(function(){var e=class extends Error{name=`Missing`};let t=async(t,n,r)=>{let i=await fetch(t,n?{signal:r,headers:{Range:`bytes=${n[0]}-${n[1]-1}`}}:{signal:r});if(i.status===404)throw new e(`http 404 for ${t}`);if(i.status!==200&&i.status!==206)throw Error(`http ${i.status} for ${t}`);let a=new Uint8Array(await i.arrayBuffer());return n&&i.status===200?a.slice(n[0],n[1]):a},n=.28209479177387814,r=15.625,i=`GMIX`,a={position:0,alpha:6,rotationIndex:7,rotation:8,scale:11,dc:14,label:17},o={origin:0,step:3,scaleMin:6,scaleMax:9,dcMin:12,dcMax:15,shScale:18};async function s(e,t){let n=new ReadableStream({start(t){t.enqueue(e),t.close()}}).pipeThrough(t);return new Uint8Array(await new Response(n).arrayBuffer())}function c(e){return s(e,new DecompressionStream(`deflate-raw`))}function l(e){return s(e,new CompressionStream(`deflate-raw`))}async function u(e,t,n){let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<8||String.fromCharCode(...e.subarray(0,4))!==t)throw Error(`not a ${n} file`);let i=r.getUint16(4,!0);if(i!==1)throw Error(`${n} version ${i}; narcissus reads 1`);let a;try{a=await c(e.subarray(8))}catch{throw Error(`${n} body is not a valid deflate stream`)}return new DataView(a.buffer,a.byteOffset,a.byteLength)}function d(e,t){let n=``;for(let r=0;r<8;r++){let i=e.getUint8(t+r);n+=i.toString(16).padStart(2,`0`)}return n}function f(e,t){let n=/* @__PURE__ */ new Float32Array(6);for(let r=0;r<6;r++)n[r]=e.getFloat32(t+20+4*r,!0);return{g:e.getUint8(t),i:e.getUint8(t+1),j:e.getUint8(t+2),count:e.getUint32(t+4,!0),quadrants:[e.getUint32(t+8,!0),e.getUint32(t+12,!0),e.getUint32(t+16,!0)],box:n,offset:e.getUint32(t+44,!0),length:e.getUint32(t+48,!0)}}async function p(e){let t=await u(e,i,`.idx`);if(t.byteLength<40)throw Error(`.idx header is cut off`);let n=t.getUint16(32,!0),r=t.getUint8(34),a=t.getUint16(36,!0),o=40+n*52+r*9+a*11;if(t.byteLength!==o)throw Error(`.idx holds ${t.byteLength} bytes, its counts need ${o}`);let s=d(t,24),c={level:t.getUint8(0),e:t.getInt32(4,!0),n:t.getInt32(8,!0),pack:d(t,12),packSize:t.getUint32(20,!0),col:s===`0000000000000000`?null:s,rows:[],children:[],descendants:[]},l=40;for(let e=0;e<n;e++,l+=52)c.rows.push(f(t,l));for(let e=0;e<r;e++,l+=9)c.children.push({quadrant:t.getUint8(l),idx:d(t,l+1)});for(let e=0;e<a;e++,l+=11)c.descendants.push({depth:t.getUint8(l),column:t.getUint8(l+1),row:t.getUint8(l+2),idx:d(t,l+3)});return c}function m(e,t,n){return`u/${e.level}/${e.e}/${e.n}.${t}.${n}`}let h=/(?:^|\\/)u\\/(\\d+)\\/(-?\\d+)\\/(-?\\d+)\\.([0-9a-f]{16})\\.(?:idx|pack|col)$/;function g(e){let t=h.exec(e);return t?{level:Number(t[1]),e:Number(t[2]),n:Number(t[3]),hash:t[4]}:null}async function _(e){let t=await u(e,`GMCL`,`.col`);if(t.byteLength<60)throw Error(`.col header is cut off`);let n=t.getUint16(0,!0),r=60+12*n*n;if(t.byteLength!==r)throw Error(`.col holds ${t.byteLength} bytes, ${n} nodes need ${r}`);let i=new Float32Array(12*n*n),a=60;for(let e=0;e<12;e++){let r=t.getFloat32(12+4*e,!0)/127;for(let o=0;o<n;o++){let s=0;for(let c=0;c<n;c++,a++)s=s+t.getInt8(a)<<24>>24,i[(e*n+o)*n+c]=s*r}}return{n,pitch:t.getFloat32(4,!0),margin:t.getFloat32(8,!0),values:i}}function v(e,t,n,r){let{n:i,pitch:a,margin:o,values:s}=e,c=i-1,l=Math.min(Math.max((t+o)/a-.5,0),c),u=Math.min(Math.max((n+o)/a-.5,0),c),d=Math.min(Math.floor(l),Math.max(c-1,0)),f=Math.min(Math.floor(u),Math.max(c-1,0)),p=Math.min(d+1,c),m=Math.min(f+1,c),h=l-d,g=u-f,_=(1-h)*(1-g),v=h*(1-g),y=(1-h)*g,b=h*g,x=i*i;for(let e=0,t=0;e<12;e++,t+=x)r[e]=s[t+f*i+d]*_+s[t+f*i+p]*v+s[t+m*i+d]*y+s[t+m*i+p]*b;return r}let y=Float64Array.from({length:256},(e,t)=>(t/255-.5)*Math.SQRT2);function b(e,t,n,r,i){let a=y[t],o=y[n],s=y[r];i[e]=Math.sqrt(Math.max(0,1-a*a-o*o-s*s)),i[e>0?0:1]=a,i[e>1?1:2]=o,i[e>2?2:3]=s}function x(e,t,n,r,i){let a=e[0],o=e[1],s=e[2],c=e[3],l=t*t,u=n*n,d=r*r,f=1-2*(s*s+c*c),p=2*(o*s-a*c),m=2*(o*c+a*s),h=2*(o*s+a*c),g=1-2*(o*o+c*c),_=2*(s*c-a*o),v=2*(o*c-a*s),y=2*(s*c+a*o),b=1-2*(o*o+s*s);i[0]=3*Math.sqrt(f*f*l+p*p*u+m*m*d),i[1]=3*Math.sqrt(h*h*l+g*g*u+_*_*d),i[2]=3*Math.sqrt(v*v*l+y*y*u+b*b*d)}function S(e){if(e.length<128)throw Error(`page payload is shorter than its header`);return new DataView(e.buffer,e.byteOffset,e.byteLength)}function C(e){let t=S(e),n=t.getUint32(0,!0),r=t.getUint16(16,!0),i=128+(17+(r>0?2:0))*n,a=i+r*9;if(e.length!==a)throw Error(`page payload holds ${e.length} bytes, its header needs ${a}`);return{view:t,count:n,k:r,book:i}}function w(e){return[e.getUint32(4,!0),e.getUint32(8,!0),e.getUint32(12,!0)]}function T(e,t){let{view:n,count:r,k:i,book:s}=C(e),c=/* @__PURE__ */ new Float32Array(27);for(let e=0;e<27;e++)c[e]=n.getFloat32(20+4*e,!0);i===0&&c.fill(0,o.shScale);let l=new Uint32Array(r*4),u=new Float32Array(Math.ceil(r/256)*6),d=/* @__PURE__ */ new Float64Array(768);for(let e=0;e<3;e++){let t=c[o.scaleMin+e],n=c[o.scaleMax+e]-t;for(let r=0;r<256;r++)d[e*256+r]=Math.exp(t+r/255*n)}let f=c[o.step],p=c[o.step+1],m=c[o.step+2],h=128+a.position*r,g=128+a.alpha*r,_=128+a.rotationIndex*r,v=128+a.rotation*r,y=128+a.scale*r,S=/* @__PURE__ */ new Float64Array(4),T=/* @__PURE__ */ new Float64Array(3),O=0,k=0,A=0;for(let t=0,n=0;n<r;t++){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,C=-1/0;for(let t=Math.min(n+256,r);n<t;n++){let t=e[h+n]|e[h+r+n]<<8;O=O+(t>>>1^-(t&1))&65535,t=e[h+2*r+n]|e[h+3*r+n]<<8,k=k+(t>>>1^-(t&1))&65535,t=e[h+4*r+n]|e[h+5*r+n]<<8,A=A+(t>>>1^-(t&1))&65535;let u=e[_+n],w=e[v+n],E=e[v+r+n],D=e[v+2*r+n],j=e[y+n],M=e[y+r+n],N=e[y+2*r+n],P=n*4;l[P]=O|k<<16,l[P+1]=A|e[g+n]<<16|u<<24,l[P+2]=w|E<<8|D<<16|j<<24,l[P+3]=M|N<<8,b(u,w,E,D,S),x(S,d[j],d[256+M],d[512+N],T);let F=O*f,I=k*p,L=A*m;i=Math.min(i,F-T[0]),a=Math.min(a,I-T[1]),o=Math.min(o,L-T[2]),s=Math.max(s,F+T[0]),c=Math.max(c,I+T[1]),C=Math.max(C,L+T[2])}u.set([i,a,o,s,c,C],t*6)}let j=t?D(e,r,i,s,l,c,t):E(e,r,i,s);return{count:r,quadrants:w(n),geometry:l,colour:j,params:c,clusters:u}}function E(e,t,n,r){let i=new Uint32Array(t*3),o=128+a.dc*t,s=128+a.label*t;for(let a=0;a<t;a++){let c=a*3;if(i[c]=e[o+a]|e[o+t+a]<<8|e[o+2*t+a]<<16,n===0)continue;let l=r+(e[s+a]|e[s+t+a]<<8)*9;i[c]|=e[l]<<24,i[c+1]=e[l+1]|e[l+2]<<8|e[l+3]<<16|e[l+4]<<24,i[c+2]=e[l+5]|e[l+6]<<8|e[l+7]<<16|e[l+8]<<24}return i}function D(e,t,r,i,s,c,l){let u=128+a.dc*t,d=128+a.label*t,f=new Int8Array(e.buffer,e.byteOffset+i,r*9),p=new Float32Array(t*3),m=new Float32Array(t*9),h=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],_=/* @__PURE__ */ new Float32Array(9),y=/* @__PURE__ */ new Float32Array(12),b=c[o.origin],x=c[o.origin+1],S=c[o.step],C=c[o.step+1],w=/* @__PURE__ */ new Float64Array(768);for(let e=0;e<3;e++){let t=c[o.dcMin+e],n=c[o.dcMax+e]-t;for(let r=0;r<256;r++)w[e*256+r]=t+r/255*n}let T=new Float64Array(Math.max(r,1)*9);for(let e=0;e<r*9;e++)T[e]=f[e]/127*c[o.shScale+e%9];for(let i=0;i<t;i++){let a=s[i*4];v(l,b+(a&65535)*S,x+(a>>>16)*C,y);for(let r=0;r<3;r++){let a=i*3+r;p[a]=w[r*256+e[u+r*t+i]]+y[r]/n,h[r]=Math.min(h[r],p[a]),g[r]=Math.max(g[r],p[a])}let o=r>0?(e[d+i]|e[d+t+i]<<8)*9:0;for(let e=0;e<9;e++){let t=i*9+e;m[t]=T[o+e]+y[3+e],_[e]=Math.max(_[e],Math.abs(m[t]))}}for(let e=0;e<3;e++)c[o.dcMin+e]=t>0?h[e]:0,c[o.dcMax+e]=t>0?g[e]:0;c.set(_,o.shScale);let E=[0,1,2].map(e=>{let t=c[o.dcMax+e]-c[o.dcMin+e];return t>0?255/t:0}),D=Array.from(_,e=>e>0?127/e:0),O=[0,1,2].map(e=>c[o.dcMin+e]),k=new Uint32Array(t*3),A=new Uint8Array(k.buffer);for(let e=0;e<t;e++){let t=e*4*3;for(let n=0;n<3;n++){let r=Math.round((p[e*3+n]-O[n])*E[n]);A[t+n]=Math.min(255,Math.max(0,r))}for(let n=0;n<9;n++){let r=Math.round(m[e*9+n]*D[n]);A[t+3+n]=Math.min(127,Math.max(-127,r))}}return k}async function O(e,t){return p(await A(e,t))}async function*k(e,t,n,r){let i=t.col===null?null:M(e,t.col,n),a=await j(e,t,r),o=await i;for(let[e,n]of t.pages.entries()){let t=await c(a[e]);r?.throwIfAborted(),yield{id:n.id,page:T(t,o)}}}async function A(e,t){let n=await e.cache.get(t);if(n)return n;let r=await e.fetch(e.base+t,null);return e.cache.put(t,r),r}async function j(e,t,n){let r=t.pages.map(e=>`${t.pack}#${e.offset}+${e.length}`),i=await Promise.all(r.map(t=>e.cache.get(t)));if(n?.throwIfAborted(),i.every(e=>e!==void 0))return i;let a=await e.fetch(e.base+t.pack,[t.start,t.end],n);if(a.length!==t.end-t.start)throw Error(`${t.pack}: ${a.length} bytes for ${t.start}-${t.end}`);return t.pages.map((n,o)=>{let s=a.slice(n.offset-t.start,n.offset-t.start+n.length);return i[o]||e.cache.put(r[o],s),s})}function M(e,t,n){let r=n.get(t);if(r)n.delete(t);else{let i=A(e,t).then(_);i.catch(()=>{n.get(t)===i&&n.delete(t)}),r=i}if(n.set(t,r),n.size>64){let[e]=n.keys();n.delete(e)}return r}function N(e){let t=/* @__PURE__ */ new Map,n=0;return{async get(e){let n=t.get(e);return n&&(t.delete(e),t.set(e,n)),n},async put(r,i){let a=t.get(r);if(a&&(t.delete(r),n-=a.length),!(i.length>e)){t.set(r,i),n+=i.length;for(let[r,i]of t){if(n<=e)break;t.delete(r),n-=i.length}}}}}async function P(e,t){let n;try{n=await(await I()).getDirectoryHandle(String(t),{create:!0})}catch{return null}let r=/* @__PURE__ */ new Map,i=0,a=!1,o=(e,t)=>{i+=t-(r.get(e)??0),r.delete(e),r.set(e,t)},s=e=>{i-=r.get(e)??0,r.delete(e)},c=()=>{if(a)for(let[t,a]of r){if(i<=e)break;r.delete(t),i-=a,n.removeEntry(t).catch(()=>void 0)}};return z(n).then(e=>{let t=[...r];r.clear(),i=0;for(let{name:t,size:n}of e.sort((e,t)=>e.time-t.time))o(t,n);for(let[e,n]of t)o(e,n);a=!0,c()}),{async get(e){let t=encodeURIComponent(e);if(a&&!r.has(t))return;let i=await L(n,t);return i?o(t,i.length):s(t),i},async put(t,r){if(r.length===0||r.length>e)return;let i=encodeURIComponent(t);await R(n,i,r)&&(o(i,r.length),c())}}}async function F(e){let t=new Set(Array.from({length:e},(e,t)=>String(t)));try{let e=await I(),n=[];for await(let[r,i]of e.entries())(i.kind!==`directory`||!t.has(r))&&n.push(r);let r={recursive:!0};for(let t of n)await e.removeEntry(t,r).catch(()=>void 0)}catch{}}async function I(){return(await navigator.storage.getDirectory()).getDirectoryHandle(`cache`,{create:!0})}async function L(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return n.size>0?new Uint8Array(await n.arrayBuffer()):void 0}catch{return}}async function R(e,t,n){let r;try{return r=await(await e.getFileHandle(t,{create:!0})).createWritable(),await r.write(n),await r.close(),!0}catch{return r?.abort().catch(()=>void 0),!1}}async function z(e){let t=[];try{for await(let[n,r]of e.entries()){if(r.kind!==`file`)continue;let e=await r.getFile().catch(()=>null);e&&t.push({name:n,size:e.size,time:e.lastModified})}}catch{}return t}function B(t){let n=/* @__PURE__ */ new Map,r=0;return{fetch:(i,a,o)=>new Promise((s,c)=>{if(o?.aborted)return c(o.reason);let l=++r,u=()=>{n.delete(l),t({unfetch:l}),c(o.reason)};n.set(l,t=>{o?.removeEventListener(`abort`,u),`bytes`in t?s(t.bytes):c(t.missing?new e(t.error):Error(t.error))}),o?.addEventListener(`abort`,u,{once:!0}),t({fetch:l,url:i,range:a})}),take(e){let t=n.get(e.fetched);n.delete(e.fetched),t?.(e)}}}let V=(e,t,n)=>Math.min(n,Math.max(t,e));function ee(e,t,n){return n>t?V(Math.round((e-t)/(n-t)*255),0,255):0}function te(e,t){return t>0?V(Math.round(e/t*127),-127,127):0}function H(e){return e&=1023,e=(e|e<<16)&50331903,e=(e|e<<8)&50393103,e=(e|e<<4)&51130563,(e|e<<2)&153391689}function ne(e,t,n){return H(e>>6)|H(t>>6)<<1|H(n>>6)<<2}function re(e,t){let n=/* @__PURE__ */ new Float32Array(9);for(let r=0;r<t;r++)for(let t=0;t<9;t++)n[t]=Math.max(n[t],Math.abs(e[r*9+t]));return n}function ie(e,t,n){let r=new Int8Array(t*9);for(let i=0;i<t;i++)for(let t=0;t<9;t++)r[i*9+t]=te(e[i*9+t],n[t]);let i=e=>r.subarray(e*9,(e+1)*9),a=/* @__PURE__ */ new Map,o=[],s=new Uint16Array(t);for(let e=0;e<t;e++){let t=i(e).join(),n=a.get(t);n===void 0&&(n=o.length,a.set(t,n),o.push(e)),s[e]=n}if(o.length>2048){let e=o.length/256,n=Array.from({length:256},(t,n)=>o[Math.floor(n*e)]);o.splice(0,o.length,...n);for(let e=0;e<t;e++){let t=1/0;for(let n=0;n<256;n++){let i=0;for(let t=0;t<9;t++)i+=(r[e*9+t]-r[o[n]*9+t])**2;i<t&&(t=i,s[e]=n)}}}let c=new Int8Array(o.length*9);return o.forEach((e,t)=>c.set(i(e),t*9)),{book:c,labels:s}}function ae(e,t){let{count:n,position:i,rotation:o,scale:s,alpha:c,dc:l,sh:u}=e,d=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],p=[...d],m=[...f],h=[...d],g=[...f];for(let e=0;e<n;e++)for(let t=0;t<3;t++)d[t]=Math.min(d[t],i[e*3+t]),f[t]=Math.max(f[t],i[e*3+t]),p[t]=Math.min(p[t],s[e*3+t]),m[t]=Math.max(m[t],s[e*3+t]),h[t]=Math.min(h[t],l[e*3+t]),g[t]=Math.max(g[t],l[e*3+t]);let _=5e-4*2**t.g,v=Float32Array.from(d),y=Float32Array.from(d,(e,t)=>Math.max(_,(f[t]-e)/65535)),b=new Uint16Array(n*3);for(let e=0;e<n;e++)for(let t=0;t<3;t++){let n=(i[e*3+t]-v[t])/y[t];b[e*3+t]=V(Math.round(n),0,65535)}let S=r*2**t.g,C=(t.i+.5)*S,w=(t.j+.5)*S,T=new Uint8Array(n),E=new Float64Array(n);for(let e=0;e<n;e++){let t=+(i[e*3]>=C),n=+(i[e*3+1]>=w);T[e]=t+2*n,E[e]=T[e]*2**30+ne(b[e*3],b[e*3+1],b[e*3+2])}let D=Uint32Array.from({length:n},(e,t)=>t).sort((e,t)=>E[e]-E[t]),O=[0,0,0];for(let e=1;e<4;e++)O[e-1]=T.filter(t=>t<e).length;let k=u?re(u,n):/* @__PURE__ */ new Float32Array(9),{book:A,labels:j}=u?ie(u,n,k):{book:null,labels:null},M=A?A.length/9:0,N=17+(M>0?2:0),P=new Uint8Array(128+N*n+M*9),F=new DataView(P.buffer);F.setUint32(0,n,!0),O.forEach((e,t)=>F.setUint32(4+4*t,e,!0)),F.setUint16(16,M,!0),[...v,...y,...p,...m,...h,...g,...k].forEach((e,t)=>F.setFloat32(20+4*t,e,!0));let I=e=>128+e*n,L=new Float32Array([...d,...f]),R=/* @__PURE__ */ new Float64Array(4),z=/* @__PURE__ */ new Float64Array(3),B=[0,0,0];for(let e=0;e<n;e++){let t=D[e];for(let n=0;n<3;n++){let r=b[t*3+n]-B[n]<<16>>16,i=r<0?-2*r-1:2*r;B[n]=b[t*3+n],P[I(a.position+2*n)+e]=i&255,P[I(a.position+2*n+1)+e]=i>>8}P[I(a.alpha)+e]=V(Math.round(c[t]*255),0,255);let n=Math.hypot(...o.subarray(t*4,t*4+4));for(let e=0;e<4;e++)R[e]=o[t*4+e]/n;let r=0;for(let e=1;e<4;e++)Math.abs(R[e])>Math.abs(R[r])&&(r=e);let u=R[r]<0?-1:1;P[I(a.rotationIndex)+e]=r;for(let t=0,n=0;t<4;t++){if(t===r)continue;let i=Math.round((u*R[t]/Math.SQRT2+.5)*255);P[I(a.rotation+n++)+e]=V(i,0,255)}for(let n=0;n<3;n++)P[I(a.scale+n)+e]=ee(s[t*3+n],p[n],m[n]),P[I(a.dc+n)+e]=ee(l[t*3+n],h[n],g[n]);j&&(P[I(a.label)+e]=j[t]&255,P[I(a.label+1)+e]=j[t]>>8);let[d,f,_]=[0,1,2].map(e=>Math.exp(s[t*3+e]));x(R,d,f,_,z);for(let e=0;e<3;e++)L[e]=Math.min(L[e],i[t*3+e]-z[e]),L[3+e]=Math.max(L[3+e],i[t*3+e]+z[e])}return A&&P.set(new Uint8Array(A.buffer),I(N)),{payload:P,row:{g:t.g,i:t.i,j:t.j,count:n,quadrants:O,box:L,offset:0,length:0}}}function oe(e,t,n){e.setUint8(t,n.g),e.setUint8(t+1,n.i),e.setUint8(t+2,n.j),e.setUint32(t+4,n.count,!0),n.quadrants.forEach((n,r)=>e.setUint32(t+8+4*r,n,!0)),n.box.forEach((n,r)=>e.setFloat32(t+20+4*r,n,!0)),e.setUint32(t+44,n.offset,!0),e.setUint32(t+48,n.length,!0)}function se(e,t,n){for(let r=0;r<4;r++)e[t+r]=n.charCodeAt(r)}function U(e){return Uint8Array.from({length:8},(t,n)=>parseInt(e.slice(2*n,2*n+2),16))}async function ce(e,t){let n=await l(e),r=new Uint8Array(8+n.length);return se(r,0,t),new DataView(r.buffer).setUint16(4,1,!0),r.set(n,8),r}async function le(e){let{rows:t,children:n,descendants:r}=e,a=new Uint8Array(40+t.length*52+n.length*9+r.length*11),o=new DataView(a.buffer);o.setUint8(0,e.level),o.setInt32(4,e.e,!0),o.setInt32(8,e.n,!0),a.set(U(e.pack),12),o.setUint32(20,e.packSize,!0),e.col&&a.set(U(e.col),24),o.setUint16(32,t.length,!0),o.setUint8(34,n.length),o.setUint16(36,r.length,!0);let s=40;for(let e of t)oe(o,s,e),s+=52;for(let e of n)o.setUint8(s,e.quadrant),a.set(U(e.idx),s+1),s+=9;for(let e of r)o.setUint8(s,e.depth),o.setUint8(s+1,e.column),o.setUint8(s+2,e.row),a.set(U(e.idx),s+3),s+=11;return ce(a,i)}function ue(e){let t=3421674724,n=2216829733;for(let r=0;r<e.length;r++){n=(n^e[r])>>>0;let i=n*435;t=t*435+(n<<8>>>0)+Math.floor(i/4294967296)>>>0,n=i>>>0}return t.toString(16).padStart(8,`0`)+n.toString(16).padStart(8,`0`)}function de(e){return()=>{e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/2**32}}let W=16384,fe=1408,pe=65535,G=324121,me=.4,he=[[12,1/7e3,0,1/9e3,.7],[9,1/2300,1.1,1/3100,.4],[6,1/800,.3,1/1100,2],[3,1/150,.9,1/210,1.7]],ge=he.reduce((e,[t,n,,r])=>e+t*(n+r),0),_e=Float32Array.from({length:fe*9},(e,t)=>{let n=Math.floor(t/9),r=t%9,i=(n*(37+2*r)+11*r)%255-127;return r===0&&(i=n%255-127),r===1&&(i=20*Math.floor(n/255)-50),i/127*.04}),K=new TextEncoder,ve={version:1,crs:`synthetic`,height:`synthetic`,leaf:250,roots:[512e4,6144e3].map(e=>({level:12,e:0,n:e})).map(e=>({...e,idx:m(e,q(e,`idx`),`idx`)})),extent:{e:[44e4,9e5],n:[605e4,641e4],h:[0,80]}},ye=K.encode(JSON.stringify(ve));function be(){return async(t,n)=>{if(t.endsWith(`world.json`))return Se(ye,n);let r=g(t),i=t.slice(t.lastIndexOf(`.`)+1);if(!r||i!==`idx`&&i!==`pack`||!Ce(r)||r.hash!==q(r,i))throw new e(`no file ${t}`);return i===`idx`?Se(await ke(r),n):Ae(r,n,t)}}function xe(e,t){let n=30;for(let[r,i,a,o,s]of he)n+=r*Math.sin(i*e+a)*Math.sin(o*t+s);return n}function Se(e,t){return t?e.slice(t[0],t[1]):e.slice()}function q(e,t){return ue(K.encode(`${e.level}/${e.e}/${e.n}.${t}`))}function J(e,t,n){let{e:r,n:i}=ve.extent;return e<r[1]&&e+n>r[0]&&t<i[1]&&t+n>i[0]}function Ce({level:e,e:t,n}){let r=250*2**e;return e<=12&&t%r===0&&n%r===0&&J(t,n,r)}function we(e){return e===0?[1,0]:e===12?[16,15,14,13]:[e+1]}function Te(e){let t=0;for(let n=0;n<8;n++)t|=(e>>2*n&1)<<n;return t}function Ee(e){let t=[];for(let n of we(e.level)){let i=r*2**n,a=250*2**e.level/i;for(let r=0;r<a*a;r++){let a=Te(r),o=Te(r>>1);J(e.e+a*i,e.n+o*i,i)&&t.push({g:n,i:a,j:o})}}return t}function De(e,t){let n=e.level-t,r=250*2**n,i=[];for(let a=0;n>=0&&a<2**t;a++)for(let o=0;o<2**t;o++){let t={level:n,e:e.e+o*r,n:e.n+a*r};J(t.e,t.n,r)&&i.push({column:o,row:a,unit:t})}return i}function Oe(e,{g:t,i:n,j:i},a){let o=r*2**t,s=o/128,c=3*1.2*s,l=1.17*s,u=xe(e.e+(n+.5)*o,e.n+(i+.5)*o),d=ge*o/2,f=Float32Array.of(n*o-c,i*o-c,Math.max(0,u-d)-l,(n+1)*o+c,(i+1)*o+c,Math.min(60,u+d)+l),p=W/4;return{g:t,i:n,j:i,count:W,quadrants:[p,2*p,3*p],box:f,offset:a,length:G}}function ke(e){let t=Ee(e),n=[];for(let{column:t,row:r,unit:i}of De(e,1))n.push({quadrant:t+2*r,idx:q(i,`idx`)});let r=[];for(let t of[2,3])for(let{column:n,row:i,unit:a}of De(e,t))r.push({depth:t,column:n,row:i,idx:q(a,`idx`)});return le({level:e.level,e:e.e,n:e.n,pack:q(e,`pack`),packSize:t.length*324173+16,col:null,rows:t.map((t,n)=>Oe(e,t,n*G)),children:n,descendants:r})}function Ae(e,t,n){let r=Ee(e);if(!t||t[0]%G!=0||t[1]%G!=0||t[0]>=t[1]||t[1]>r.length*G)throw Error(`${n}: the synthetic world serves whole pages only`);let i=new Uint8Array(t[1]-t[0]);for(let n=0;n<i.length;n+=G)je(Ne(e,r[(t[0]+n)/G]),i,n);return i}function je(e,t,n){let r=n;for(let n=0;n<e.length;n+=pe){let i=Math.min(pe,e.length-n);t[r]=+(n+i===e.length),t[r+1]=i&255,t[r+2]=i>>8,t[r+3]=~i&255,t[r+4]=~i>>8&255,t.set(e.subarray(n,n+i),r+5),r+=5+i}}let Me=e=>de(parseInt(ue(K.encode(e)).slice(8),16));function Ne(e,{g:t,i,j:a}){let o=W,s=r*2**t/128,c=Me(`${e.level}/${e.e}/${e.n}/${t}/${i}/${a}`),l=new Float64Array(3*o),u=new Float32Array(4*o),d=new Float32Array(3*o),f=new Float32Array(o),p=new Float32Array(3*o),m=new Float32Array(9*o);for(let t=0;t<o;t++){let r=(i*128+t%128+.5+me*(2*c()-1))*s,o=(a*128+Math.floor(t/128)+.5+me*(2*c()-1))*s,h=xe(e.e+r,e.n+o);l[3*t]=r,l[3*t+1]=o,l[3*t+2]=h;let g=Math.PI*c(),_=.1/2*(2*c()-1);u[4*t]=Math.cos(g)*Math.cos(_),u[4*t+1]=Math.cos(g)*Math.sin(_),u[4*t+2]=Math.sin(g)*Math.sin(_),u[4*t+3]=Math.sin(g)*Math.cos(_);for(let e=0;e<2;e++)d[3*t+e]=Math.log(s*(.6+.6*c()));d[3*t+2]=Math.log(s*.15*(.5+.5*c())),f[t]=.35+.65*c();let v=h/60,y=.5+.5*Math.sin((e.e+r)/410)*Math.sin((e.n+o)/330);p[3*t]=(.32+.2*v+.1*y-.5)/n,p[3*t+1]=(.42+.15*y-.1*v-.5)/n,p[3*t+2]=(.25+.1*v+.04*c()-.5)/n;let b=t%fe;m.set(_e.subarray(9*b,9*(b+1)),9*t)}return ae({count:o,position:l,rotation:u,scale:d,alpha:f,dc:p,sh:m},{g:t,i,j:a}).payload}let Y=2**20,X=self,Z,Pe=/* @__PURE__ */ new Map,Q=/* @__PURE__ */ new Map,Fe=B(e=>X.postMessage(e,[]));X.onmessage=({data:e})=>{`fetched`in e?Fe.take(e):e.type===`init`?(Z=Ie(e),Z.catch(()=>void 0)):e.type===`abort`?Q.get(e.id)?.abort():Re(e)};async function Ie(e){return e.source===`synthetic`?{fetch:be(),cache:await $({...e,cache:`none`}),base:e.base}:{fetch:e.source===`page`?Fe.fetch:t,cache:await $(e),base:e.base}}async function $({cache:e,shard:t,shards:n}){return e===`memory`?N(256*Y):e===`none`?{get:async()=>void 0,put:async()=>void 0}:(t===0&&F(n),await P(await Le()/n,t)??N(256*Y))}async function Le(){try{let{quota:e}=await navigator.storage.estimate();return Math.min(4096*Y,e===void 0?1/0:e/2)}catch{return 4096*Y}}async function Re(t){let{id:n}=t,r=new AbortController;Q.set(n,r);try{if(!Z)throw Error(`stream worker used before init`);let e=await Z;if(t.type===`idx`)X.postMessage({id:n,value:await O(e,t.path)},[]);else{for await(let i of k(e,t.batch,Pe,r.signal))X.postMessage({id:n,page:i},ze(i));X.postMessage({id:n,done:!0},[])}}catch(t){let r=t instanceof Error?t.message:String(t);X.postMessage({id:n,error:r,missing:t instanceof e},[])}finally{Q.delete(n)}}function ze({page:e}){let t=/* @__PURE__ */ new Set;for(let n of[e.geometry,e.colour,e.params,e.clusters])t.add(n.buffer);return[...t]}})();", et = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", $e], { type: "text/javascript;charset=utf-8" });
|
|
1630
|
-
function
|
|
1879
|
+
var lt = "(function(){var e=class extends Error{name=`Missing`};let t=async(t,n,r)=>{let i=await fetch(t,n?{signal:r,headers:{Range:`bytes=${n[0]}-${n[1]-1}`}}:{signal:r});if(i.status===404)throw new e(`http 404 for ${t}`);if(i.status!==200&&i.status!==206)throw Error(`http ${i.status} for ${t}`);let a=new Uint8Array(await i.arrayBuffer());return n&&i.status===200?a.slice(n[0],n[1]):a},n=.28209479177387814,r=15.625,i=`GMIX`,a={position:0,alpha:6,rotationIndex:7,rotation:8,scale:11,dc:14,label:17},o={origin:0,step:3,scaleMin:6,scaleMax:9,dcMin:12,dcMax:15,shScale:18};async function s(e,t){let n=new ReadableStream({start(t){t.enqueue(e),t.close()}}).pipeThrough(t);return new Uint8Array(await new Response(n).arrayBuffer())}function c(e){return s(e,new DecompressionStream(`deflate-raw`))}function l(e){return s(e,new CompressionStream(`deflate-raw`))}async function u(e,t,n){let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<8||String.fromCharCode(...e.subarray(0,4))!==t)throw Error(`not a ${n} file`);let i=r.getUint16(4,!0);if(i!==1)throw Error(`${n} version ${i}; narcissus reads 1`);let a;try{a=await c(e.subarray(8))}catch{throw Error(`${n} body is not a valid deflate stream`)}return new DataView(a.buffer,a.byteOffset,a.byteLength)}function d(e,t){let n=``;for(let r=0;r<8;r++){let i=e.getUint8(t+r);n+=i.toString(16).padStart(2,`0`)}return n}function f(e,t){let n=/* @__PURE__ */ new Float32Array(6);for(let r=0;r<6;r++)n[r]=e.getFloat32(t+20+4*r,!0);return{g:e.getUint8(t),i:e.getUint8(t+1),j:e.getUint8(t+2),count:e.getUint32(t+4,!0),quadrants:[e.getUint32(t+8,!0),e.getUint32(t+12,!0),e.getUint32(t+16,!0)],box:n,offset:e.getUint32(t+44,!0),length:e.getUint32(t+48,!0)}}async function p(e){let t=await u(e,i,`.idx`);if(t.byteLength<40)throw Error(`.idx header is cut off`);let n=t.getUint16(32,!0),r=t.getUint8(34),a=t.getUint16(36,!0),o=40+n*52+r*9+a*11;if(t.byteLength!==o)throw Error(`.idx holds ${t.byteLength} bytes, its counts need ${o}`);let s=d(t,24),c={level:t.getUint8(0),e:t.getInt32(4,!0),n:t.getInt32(8,!0),pack:d(t,12),packSize:t.getUint32(20,!0),col:s===`0000000000000000`?null:s,rows:[],children:[],descendants:[]},l=40;for(let e=0;e<n;e++,l+=52)c.rows.push(f(t,l));for(let e=0;e<r;e++,l+=9)c.children.push({quadrant:t.getUint8(l),idx:d(t,l+1)});for(let e=0;e<a;e++,l+=11)c.descendants.push({depth:t.getUint8(l),column:t.getUint8(l+1),row:t.getUint8(l+2),idx:d(t,l+3)});return c}function m(e,t,n){return`u/${e.level}/${e.e}/${e.n}.${t}.${n}`}let h=/(?:^|\\/)u\\/(\\d+)\\/(-?\\d+)\\/(-?\\d+)\\.([0-9a-f]{16})\\.(?:idx|pack|col)$/;function g(e){let t=h.exec(e);return t?{level:Number(t[1]),e:Number(t[2]),n:Number(t[3]),hash:t[4]}:null}async function _(e){let t=await u(e,`GMCL`,`.col`);if(t.byteLength<60)throw Error(`.col header is cut off`);let n=t.getUint16(0,!0),r=60+12*n*n;if(t.byteLength!==r)throw Error(`.col holds ${t.byteLength} bytes, ${n} nodes need ${r}`);let i=new Float32Array(12*n*n),a=60;for(let e=0;e<12;e++){let r=t.getFloat32(12+4*e,!0)/127;for(let o=0;o<n;o++){let s=0;for(let c=0;c<n;c++,a++)s=s+t.getInt8(a)<<24>>24,i[(e*n+o)*n+c]=s*r}}return{n,pitch:t.getFloat32(4,!0),margin:t.getFloat32(8,!0),values:i}}function v(e,t,n,r){let{n:i,pitch:a,margin:o,values:s}=e,c=i-1,l=Math.min(Math.max((t+o)/a-.5,0),c),u=Math.min(Math.max((n+o)/a-.5,0),c),d=Math.min(Math.floor(l),Math.max(c-1,0)),f=Math.min(Math.floor(u),Math.max(c-1,0)),p=Math.min(d+1,c),m=Math.min(f+1,c),h=l-d,g=u-f,_=(1-h)*(1-g),v=h*(1-g),y=(1-h)*g,b=h*g,x=i*i;for(let e=0,t=0;e<12;e++,t+=x)r[e]=s[t+f*i+d]*_+s[t+f*i+p]*v+s[t+m*i+d]*y+s[t+m*i+p]*b;return r}let y=Float64Array.from({length:256},(e,t)=>(t/255-.5)*Math.SQRT2);function b(e,t,n,r,i){let a=y[t],o=y[n],s=y[r];i[e]=Math.sqrt(Math.max(0,1-a*a-o*o-s*s)),i[e>0?0:1]=a,i[e>1?1:2]=o,i[e>2?2:3]=s}function x(e,t,n,r,i){let a=e[0],o=e[1],s=e[2],c=e[3],l=t*t,u=n*n,d=r*r,f=1-2*(s*s+c*c),p=2*(o*s-a*c),m=2*(o*c+a*s),h=2*(o*s+a*c),g=1-2*(o*o+c*c),_=2*(s*c-a*o),v=2*(o*c-a*s),y=2*(s*c+a*o),b=1-2*(o*o+s*s);i[0]=3*Math.sqrt(f*f*l+p*p*u+m*m*d),i[1]=3*Math.sqrt(h*h*l+g*g*u+_*_*d),i[2]=3*Math.sqrt(v*v*l+y*y*u+b*b*d)}function S(e){if(e.length<128)throw Error(`page payload is shorter than its header`);return new DataView(e.buffer,e.byteOffset,e.byteLength)}function C(e){let t=S(e),n=t.getUint32(0,!0),r=t.getUint16(16,!0),i=128+(17+(r>0?2:0))*n,a=i+r*9;if(e.length!==a)throw Error(`page payload holds ${e.length} bytes, its header needs ${a}`);return{view:t,count:n,k:r,book:i}}function w(e){return[e.getUint32(4,!0),e.getUint32(8,!0),e.getUint32(12,!0)]}function T(e,t){let{view:n,count:r,k:i,book:s}=C(e),c=/* @__PURE__ */ new Float32Array(27);for(let e=0;e<27;e++)c[e]=n.getFloat32(20+4*e,!0);i===0&&c.fill(0,o.shScale);let l=new Uint32Array(r*4),u=new Float32Array(Math.ceil(r/256)*6),d=/* @__PURE__ */ new Float64Array(768);for(let e=0;e<3;e++){let t=c[o.scaleMin+e],n=c[o.scaleMax+e]-t;for(let r=0;r<256;r++)d[e*256+r]=Math.exp(t+r/255*n)}let f=c[o.step],p=c[o.step+1],m=c[o.step+2],h=128+a.position*r,g=128+a.alpha*r,_=128+a.rotationIndex*r,v=128+a.rotation*r,y=128+a.scale*r,S=/* @__PURE__ */ new Float64Array(4),T=/* @__PURE__ */ new Float64Array(3),O=0,k=0,A=0;for(let t=0,n=0;n<r;t++){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,C=-1/0;for(let t=Math.min(n+256,r);n<t;n++){let t=e[h+n]|e[h+r+n]<<8;O=O+(t>>>1^-(t&1))&65535,t=e[h+2*r+n]|e[h+3*r+n]<<8,k=k+(t>>>1^-(t&1))&65535,t=e[h+4*r+n]|e[h+5*r+n]<<8,A=A+(t>>>1^-(t&1))&65535;let u=e[_+n],w=e[v+n],E=e[v+r+n],D=e[v+2*r+n],j=e[y+n],M=e[y+r+n],N=e[y+2*r+n],P=n*4;l[P]=O|k<<16,l[P+1]=A|e[g+n]<<16|u<<24,l[P+2]=w|E<<8|D<<16|j<<24,l[P+3]=M|N<<8,b(u,w,E,D,S),x(S,d[j],d[256+M],d[512+N],T);let F=O*f,I=k*p,L=A*m;i=Math.min(i,F-T[0]),a=Math.min(a,I-T[1]),o=Math.min(o,L-T[2]),s=Math.max(s,F+T[0]),c=Math.max(c,I+T[1]),C=Math.max(C,L+T[2])}u.set([i,a,o,s,c,C],t*6)}let j=t?D(e,r,i,s,l,c,t):E(e,r,i,s);return{count:r,quadrants:w(n),geometry:l,colour:j,params:c,clusters:u}}function E(e,t,n,r){let i=new Uint32Array(t*3),o=128+a.dc*t,s=128+a.label*t;for(let a=0;a<t;a++){let c=a*3;if(i[c]=e[o+a]|e[o+t+a]<<8|e[o+2*t+a]<<16,n===0)continue;let l=r+(e[s+a]|e[s+t+a]<<8)*9;i[c]|=e[l]<<24,i[c+1]=e[l+1]|e[l+2]<<8|e[l+3]<<16|e[l+4]<<24,i[c+2]=e[l+5]|e[l+6]<<8|e[l+7]<<16|e[l+8]<<24}return i}function D(e,t,r,i,s,c,l){let u=128+a.dc*t,d=128+a.label*t,f=new Int8Array(e.buffer,e.byteOffset+i,r*9),p=new Float32Array(t*3),m=new Float32Array(t*9),h=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],_=/* @__PURE__ */ new Float32Array(9),y=/* @__PURE__ */ new Float32Array(12),b=c[o.origin],x=c[o.origin+1],S=c[o.step],C=c[o.step+1],w=/* @__PURE__ */ new Float64Array(768);for(let e=0;e<3;e++){let t=c[o.dcMin+e],n=c[o.dcMax+e]-t;for(let r=0;r<256;r++)w[e*256+r]=t+r/255*n}let T=new Float64Array(Math.max(r,1)*9);for(let e=0;e<r*9;e++)T[e]=f[e]/127*c[o.shScale+e%9];for(let i=0;i<t;i++){let a=s[i*4];v(l,b+(a&65535)*S,x+(a>>>16)*C,y);for(let r=0;r<3;r++){let a=i*3+r;p[a]=w[r*256+e[u+r*t+i]]+y[r]/n,h[r]=Math.min(h[r],p[a]),g[r]=Math.max(g[r],p[a])}let o=r>0?(e[d+i]|e[d+t+i]<<8)*9:0;for(let e=0;e<9;e++){let t=i*9+e;m[t]=T[o+e]+y[3+e],_[e]=Math.max(_[e],Math.abs(m[t]))}}for(let e=0;e<3;e++)c[o.dcMin+e]=t>0?h[e]:0,c[o.dcMax+e]=t>0?g[e]:0;c.set(_,o.shScale);let E=[0,1,2].map(e=>{let t=c[o.dcMax+e]-c[o.dcMin+e];return t>0?255/t:0}),D=Array.from(_,e=>e>0?127/e:0),O=[0,1,2].map(e=>c[o.dcMin+e]),k=new Uint32Array(t*3),A=new Uint8Array(k.buffer);for(let e=0;e<t;e++){let t=e*4*3;for(let n=0;n<3;n++){let r=Math.round((p[e*3+n]-O[n])*E[n]);A[t+n]=Math.min(255,Math.max(0,r))}for(let n=0;n<9;n++){let r=Math.round(m[e*9+n]*D[n]);A[t+3+n]=Math.min(127,Math.max(-127,r))}}return k}async function O(e,t){return p(await A(e,t))}async function*k(e,t,n,r){let i=t.col===null?null:M(e,t.col,n),a=await j(e,t,r),o=await i;for(let[e,n]of t.pages.entries()){let t=await c(a[e]);r?.throwIfAborted(),yield{id:n.id,page:T(t,o)}}}async function A(e,t){let n=await e.cache.get(t);if(n)return n;let r=await e.fetch(e.base+t,null);return e.cache.put(t,r),r}async function j(e,t,n){let r=t.pages.map(e=>`${t.pack}#${e.offset}+${e.length}`),i=await Promise.all(r.map(t=>e.cache.get(t)));if(n?.throwIfAborted(),i.every(e=>e!==void 0))return i;let a=await e.fetch(e.base+t.pack,[t.start,t.end],n);if(a.length!==t.end-t.start)throw Error(`${t.pack}: ${a.length} bytes for ${t.start}-${t.end}`);return t.pages.map((n,o)=>{let s=a.slice(n.offset-t.start,n.offset-t.start+n.length);return i[o]||e.cache.put(r[o],s),s})}function M(e,t,n){let r=n.get(t);if(r)n.delete(t);else{let i=A(e,t).then(_);i.catch(()=>{n.get(t)===i&&n.delete(t)}),r=i}if(n.set(t,r),n.size>64){let[e]=n.keys();n.delete(e)}return r}function N(e){let t=/* @__PURE__ */ new Map,n=0;return{async get(e){let n=t.get(e);return n&&(t.delete(e),t.set(e,n)),n},async put(r,i){let a=t.get(r);if(a&&(t.delete(r),n-=a.length),!(i.length>e)){t.set(r,i),n+=i.length;for(let[r,i]of t){if(n<=e)break;t.delete(r),n-=i.length}}}}}async function P(e,t){let n;try{n=await(await I()).getDirectoryHandle(String(t),{create:!0})}catch{return null}let r=/* @__PURE__ */ new Map,i=0,a=!1,o=(e,t)=>{i+=t-(r.get(e)??0),r.delete(e),r.set(e,t)},s=e=>{i-=r.get(e)??0,r.delete(e)},c=()=>{if(a)for(let[t,a]of r){if(i<=e)break;r.delete(t),i-=a,n.removeEntry(t).catch(()=>void 0)}};return z(n).then(e=>{let t=[...r];r.clear(),i=0;for(let{name:t,size:n}of e.sort((e,t)=>e.time-t.time))o(t,n);for(let[e,n]of t)o(e,n);a=!0,c()}),{async get(e){let t=encodeURIComponent(e);if(a&&!r.has(t))return;let i=await L(n,t);return i?o(t,i.length):s(t),i},async put(t,r){if(r.length===0||r.length>e)return;let i=encodeURIComponent(t);await R(n,i,r)&&(o(i,r.length),c())}}}async function F(e){let t=new Set(Array.from({length:e},(e,t)=>String(t)));try{let e=await I(),n=[];for await(let[r,i]of e.entries())(i.kind!==`directory`||!t.has(r))&&n.push(r);let r={recursive:!0};for(let t of n)await e.removeEntry(t,r).catch(()=>void 0)}catch{}}async function I(){return(await navigator.storage.getDirectory()).getDirectoryHandle(`cache`,{create:!0})}async function L(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return n.size>0?new Uint8Array(await n.arrayBuffer()):void 0}catch{return}}async function R(e,t,n){let r;try{return r=await(await e.getFileHandle(t,{create:!0})).createWritable(),await r.write(n),await r.close(),!0}catch{return r?.abort().catch(()=>void 0),!1}}async function z(e){let t=[];try{for await(let[n,r]of e.entries()){if(r.kind!==`file`)continue;let e=await r.getFile().catch(()=>null);e&&t.push({name:n,size:e.size,time:e.lastModified})}}catch{}return t}function B(t){let n=/* @__PURE__ */ new Map,r=0;return{fetch:(i,a,o)=>new Promise((s,c)=>{if(o?.aborted)return c(o.reason);let l=++r,u=()=>{n.delete(l),t({unfetch:l}),c(o.reason)};n.set(l,t=>{o?.removeEventListener(`abort`,u),`bytes`in t?s(t.bytes):c(t.missing?new e(t.error):Error(t.error))}),o?.addEventListener(`abort`,u,{once:!0}),t({fetch:l,url:i,range:a})}),take(e){let t=n.get(e.fetched);n.delete(e.fetched),t?.(e)}}}let V=(e,t,n)=>Math.min(n,Math.max(t,e));function ee(e,t,n){return n>t?V(Math.round((e-t)/(n-t)*255),0,255):0}function te(e,t){return t>0?V(Math.round(e/t*127),-127,127):0}function H(e){return e&=1023,e=(e|e<<16)&50331903,e=(e|e<<8)&50393103,e=(e|e<<4)&51130563,(e|e<<2)&153391689}function ne(e,t,n){return H(e>>6)|H(t>>6)<<1|H(n>>6)<<2}function re(e,t){let n=/* @__PURE__ */ new Float32Array(9);for(let r=0;r<t;r++)for(let t=0;t<9;t++)n[t]=Math.max(n[t],Math.abs(e[r*9+t]));return n}function ie(e,t,n){let r=new Int8Array(t*9);for(let i=0;i<t;i++)for(let t=0;t<9;t++)r[i*9+t]=te(e[i*9+t],n[t]);let i=e=>r.subarray(e*9,(e+1)*9),a=/* @__PURE__ */ new Map,o=[],s=new Uint16Array(t);for(let e=0;e<t;e++){let t=i(e).join(),n=a.get(t);n===void 0&&(n=o.length,a.set(t,n),o.push(e)),s[e]=n}if(o.length>2048){let e=o.length/256,n=Array.from({length:256},(t,n)=>o[Math.floor(n*e)]);o.splice(0,o.length,...n);for(let e=0;e<t;e++){let t=1/0;for(let n=0;n<256;n++){let i=0;for(let t=0;t<9;t++)i+=(r[e*9+t]-r[o[n]*9+t])**2;i<t&&(t=i,s[e]=n)}}}let c=new Int8Array(o.length*9);return o.forEach((e,t)=>c.set(i(e),t*9)),{book:c,labels:s}}function ae(e,t){let{count:n,position:i,rotation:o,scale:s,alpha:c,dc:l,sh:u}=e,d=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],p=[...d],m=[...f],h=[...d],g=[...f];for(let e=0;e<n;e++)for(let t=0;t<3;t++)d[t]=Math.min(d[t],i[e*3+t]),f[t]=Math.max(f[t],i[e*3+t]),p[t]=Math.min(p[t],s[e*3+t]),m[t]=Math.max(m[t],s[e*3+t]),h[t]=Math.min(h[t],l[e*3+t]),g[t]=Math.max(g[t],l[e*3+t]);let _=5e-4*2**t.g,v=Float32Array.from(d),y=Float32Array.from(d,(e,t)=>Math.max(_,(f[t]-e)/65535)),b=new Uint16Array(n*3);for(let e=0;e<n;e++)for(let t=0;t<3;t++){let n=(i[e*3+t]-v[t])/y[t];b[e*3+t]=V(Math.round(n),0,65535)}let S=r*2**t.g,C=(t.i+.5)*S,w=(t.j+.5)*S,T=new Uint8Array(n),E=new Float64Array(n);for(let e=0;e<n;e++){let t=+(i[e*3]>=C),n=+(i[e*3+1]>=w);T[e]=t+2*n,E[e]=T[e]*2**30+ne(b[e*3],b[e*3+1],b[e*3+2])}let D=Uint32Array.from({length:n},(e,t)=>t).sort((e,t)=>E[e]-E[t]),O=[0,0,0];for(let e=1;e<4;e++)O[e-1]=T.filter(t=>t<e).length;let k=u?re(u,n):/* @__PURE__ */ new Float32Array(9),{book:A,labels:j}=u?ie(u,n,k):{book:null,labels:null},M=A?A.length/9:0,N=17+(M>0?2:0),P=new Uint8Array(128+N*n+M*9),F=new DataView(P.buffer);F.setUint32(0,n,!0),O.forEach((e,t)=>F.setUint32(4+4*t,e,!0)),F.setUint16(16,M,!0),[...v,...y,...p,...m,...h,...g,...k].forEach((e,t)=>F.setFloat32(20+4*t,e,!0));let I=e=>128+e*n,L=new Float32Array([...d,...f]),R=/* @__PURE__ */ new Float64Array(4),z=/* @__PURE__ */ new Float64Array(3),B=[0,0,0];for(let e=0;e<n;e++){let t=D[e];for(let n=0;n<3;n++){let r=b[t*3+n]-B[n]<<16>>16,i=r<0?-2*r-1:2*r;B[n]=b[t*3+n],P[I(a.position+2*n)+e]=i&255,P[I(a.position+2*n+1)+e]=i>>8}P[I(a.alpha)+e]=V(Math.round(c[t]*255),0,255);let n=Math.hypot(...o.subarray(t*4,t*4+4));for(let e=0;e<4;e++)R[e]=o[t*4+e]/n;let r=0;for(let e=1;e<4;e++)Math.abs(R[e])>Math.abs(R[r])&&(r=e);let u=R[r]<0?-1:1;P[I(a.rotationIndex)+e]=r;for(let t=0,n=0;t<4;t++){if(t===r)continue;let i=Math.round((u*R[t]/Math.SQRT2+.5)*255);P[I(a.rotation+n++)+e]=V(i,0,255)}for(let n=0;n<3;n++)P[I(a.scale+n)+e]=ee(s[t*3+n],p[n],m[n]),P[I(a.dc+n)+e]=ee(l[t*3+n],h[n],g[n]);j&&(P[I(a.label)+e]=j[t]&255,P[I(a.label+1)+e]=j[t]>>8);let[d,f,_]=[0,1,2].map(e=>Math.exp(s[t*3+e]));x(R,d,f,_,z);for(let e=0;e<3;e++)L[e]=Math.min(L[e],i[t*3+e]-z[e]),L[3+e]=Math.max(L[3+e],i[t*3+e]+z[e])}return A&&P.set(new Uint8Array(A.buffer),I(N)),{payload:P,row:{g:t.g,i:t.i,j:t.j,count:n,quadrants:O,box:L,offset:0,length:0}}}function oe(e,t,n){e.setUint8(t,n.g),e.setUint8(t+1,n.i),e.setUint8(t+2,n.j),e.setUint32(t+4,n.count,!0),n.quadrants.forEach((n,r)=>e.setUint32(t+8+4*r,n,!0)),n.box.forEach((n,r)=>e.setFloat32(t+20+4*r,n,!0)),e.setUint32(t+44,n.offset,!0),e.setUint32(t+48,n.length,!0)}function se(e,t,n){for(let r=0;r<4;r++)e[t+r]=n.charCodeAt(r)}function U(e){return Uint8Array.from({length:8},(t,n)=>parseInt(e.slice(2*n,2*n+2),16))}async function ce(e,t){let n=await l(e),r=new Uint8Array(8+n.length);return se(r,0,t),new DataView(r.buffer).setUint16(4,1,!0),r.set(n,8),r}async function le(e){let{rows:t,children:n,descendants:r}=e,a=new Uint8Array(40+t.length*52+n.length*9+r.length*11),o=new DataView(a.buffer);o.setUint8(0,e.level),o.setInt32(4,e.e,!0),o.setInt32(8,e.n,!0),a.set(U(e.pack),12),o.setUint32(20,e.packSize,!0),e.col&&a.set(U(e.col),24),o.setUint16(32,t.length,!0),o.setUint8(34,n.length),o.setUint16(36,r.length,!0);let s=40;for(let e of t)oe(o,s,e),s+=52;for(let e of n)o.setUint8(s,e.quadrant),a.set(U(e.idx),s+1),s+=9;for(let e of r)o.setUint8(s,e.depth),o.setUint8(s+1,e.column),o.setUint8(s+2,e.row),a.set(U(e.idx),s+3),s+=11;return ce(a,i)}function ue(e){let t=3421674724,n=2216829733;for(let r=0;r<e.length;r++){n=(n^e[r])>>>0;let i=n*435;t=t*435+(n<<8>>>0)+Math.floor(i/4294967296)>>>0,n=i>>>0}return t.toString(16).padStart(8,`0`)+n.toString(16).padStart(8,`0`)}function de(e){return()=>{e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/2**32}}let W=16384,fe=1408,pe=65535,G=324121,me=.4,he=[[12,1/7e3,0,1/9e3,.7],[9,1/2300,1.1,1/3100,.4],[6,1/800,.3,1/1100,2],[3,1/150,.9,1/210,1.7]],ge=he.reduce((e,[t,n,,r])=>e+t*(n+r),0),_e=Float32Array.from({length:fe*9},(e,t)=>{let n=Math.floor(t/9),r=t%9,i=(n*(37+2*r)+11*r)%255-127;return r===0&&(i=n%255-127),r===1&&(i=20*Math.floor(n/255)-50),i/127*.04}),K=new TextEncoder,ve={version:1,crs:`synthetic`,height:`synthetic`,leaf:250,roots:[512e4,6144e3].map(e=>({level:12,e:0,n:e})).map(e=>({...e,idx:m(e,q(e,`idx`),`idx`)})),extent:{e:[44e4,9e5],n:[605e4,641e4],h:[0,80]}},ye=K.encode(JSON.stringify(ve));function be(){return async(t,n)=>{if(t.endsWith(`world.json`))return Se(ye,n);let r=g(t),i=t.slice(t.lastIndexOf(`.`)+1);if(!r||i!==`idx`&&i!==`pack`||!Ce(r)||r.hash!==q(r,i))throw new e(`no file ${t}`);return i===`idx`?Se(await ke(r),n):Ae(r,n,t)}}function xe(e,t){let n=30;for(let[r,i,a,o,s]of he)n+=r*Math.sin(i*e+a)*Math.sin(o*t+s);return n}function Se(e,t){return t?e.slice(t[0],t[1]):e.slice()}function q(e,t){return ue(K.encode(`${e.level}/${e.e}/${e.n}.${t}`))}function J(e,t,n){let{e:r,n:i}=ve.extent;return e<r[1]&&e+n>r[0]&&t<i[1]&&t+n>i[0]}function Ce({level:e,e:t,n}){let r=250*2**e;return e<=12&&t%r===0&&n%r===0&&J(t,n,r)}function we(e){return e===0?[1,0]:e===12?[16,15,14,13]:[e+1]}function Te(e){let t=0;for(let n=0;n<8;n++)t|=(e>>2*n&1)<<n;return t}function Ee(e){let t=[];for(let n of we(e.level)){let i=r*2**n,a=250*2**e.level/i;for(let r=0;r<a*a;r++){let a=Te(r),o=Te(r>>1);J(e.e+a*i,e.n+o*i,i)&&t.push({g:n,i:a,j:o})}}return t}function De(e,t){let n=e.level-t,r=250*2**n,i=[];for(let a=0;n>=0&&a<2**t;a++)for(let o=0;o<2**t;o++){let t={level:n,e:e.e+o*r,n:e.n+a*r};J(t.e,t.n,r)&&i.push({column:o,row:a,unit:t})}return i}function Oe(e,{g:t,i:n,j:i},a){let o=r*2**t,s=o/128,c=3*1.2*s,l=1.17*s,u=xe(e.e+(n+.5)*o,e.n+(i+.5)*o),d=ge*o/2,f=Float32Array.of(n*o-c,i*o-c,Math.max(0,u-d)-l,(n+1)*o+c,(i+1)*o+c,Math.min(60,u+d)+l),p=W/4;return{g:t,i:n,j:i,count:W,quadrants:[p,2*p,3*p],box:f,offset:a,length:G}}function ke(e){let t=Ee(e),n=[];for(let{column:t,row:r,unit:i}of De(e,1))n.push({quadrant:t+2*r,idx:q(i,`idx`)});let r=[];for(let t of[2,3])for(let{column:n,row:i,unit:a}of De(e,t))r.push({depth:t,column:n,row:i,idx:q(a,`idx`)});return le({level:e.level,e:e.e,n:e.n,pack:q(e,`pack`),packSize:t.length*324173+16,col:null,rows:t.map((t,n)=>Oe(e,t,n*G)),children:n,descendants:r})}function Ae(e,t,n){let r=Ee(e);if(!t||t[0]%G!=0||t[1]%G!=0||t[0]>=t[1]||t[1]>r.length*G)throw Error(`${n}: the synthetic world serves whole pages only`);let i=new Uint8Array(t[1]-t[0]);for(let n=0;n<i.length;n+=G)je(Ne(e,r[(t[0]+n)/G]),i,n);return i}function je(e,t,n){let r=n;for(let n=0;n<e.length;n+=pe){let i=Math.min(pe,e.length-n);t[r]=+(n+i===e.length),t[r+1]=i&255,t[r+2]=i>>8,t[r+3]=~i&255,t[r+4]=~i>>8&255,t.set(e.subarray(n,n+i),r+5),r+=5+i}}let Me=e=>de(parseInt(ue(K.encode(e)).slice(8),16));function Ne(e,{g:t,i,j:a}){let o=W,s=r*2**t/128,c=Me(`${e.level}/${e.e}/${e.n}/${t}/${i}/${a}`),l=new Float64Array(3*o),u=new Float32Array(4*o),d=new Float32Array(3*o),f=new Float32Array(o),p=new Float32Array(3*o),m=new Float32Array(9*o);for(let t=0;t<o;t++){let r=(i*128+t%128+.5+me*(2*c()-1))*s,o=(a*128+Math.floor(t/128)+.5+me*(2*c()-1))*s,h=xe(e.e+r,e.n+o);l[3*t]=r,l[3*t+1]=o,l[3*t+2]=h;let g=Math.PI*c(),_=.1/2*(2*c()-1);u[4*t]=Math.cos(g)*Math.cos(_),u[4*t+1]=Math.cos(g)*Math.sin(_),u[4*t+2]=Math.sin(g)*Math.sin(_),u[4*t+3]=Math.sin(g)*Math.cos(_);for(let e=0;e<2;e++)d[3*t+e]=Math.log(s*(.6+.6*c()));d[3*t+2]=Math.log(s*.15*(.5+.5*c())),f[t]=.35+.65*c();let v=h/60,y=.5+.5*Math.sin((e.e+r)/410)*Math.sin((e.n+o)/330);p[3*t]=(.32+.2*v+.1*y-.5)/n,p[3*t+1]=(.42+.15*y-.1*v-.5)/n,p[3*t+2]=(.25+.1*v+.04*c()-.5)/n;let b=t%fe;m.set(_e.subarray(9*b,9*(b+1)),9*t)}return ae({count:o,position:l,rotation:u,scale:d,alpha:f,dc:p,sh:m},{g:t,i,j:a}).payload}let Y=2**20,X=self,Z,Pe=/* @__PURE__ */ new Map,Q=/* @__PURE__ */ new Map,Fe=B(e=>X.postMessage(e,[]));X.onmessage=({data:e})=>{`fetched`in e?Fe.take(e):e.type===`init`?(Z=Ie(e),Z.catch(()=>void 0)):e.type===`abort`?Q.get(e.id)?.abort():Re(e)};async function Ie(e){return e.source===`synthetic`?{fetch:be(),cache:await $({...e,cache:`none`}),base:e.base}:{fetch:e.source===`page`?Fe.fetch:t,cache:await $(e),base:e.base}}async function $({cache:e,shard:t,shards:n}){return e===`memory`?N(256*Y):e===`none`?{get:async()=>void 0,put:async()=>void 0}:(t===0&&F(n),await P(await Le()/n,t)??N(256*Y))}async function Le(){try{let{quota:e}=await navigator.storage.estimate();return Math.min(4096*Y,e===void 0?1/0:e/2)}catch{return 4096*Y}}async function Re(t){let{id:n}=t,r=new AbortController;Q.set(n,r);try{if(!Z)throw Error(`stream worker used before init`);let e=await Z;if(t.type===`idx`)X.postMessage({id:n,value:await O(e,t.path)},[]);else{for await(let i of k(e,t.batch,Pe,r.signal))X.postMessage({id:n,page:i},ze(i));X.postMessage({id:n,done:!0},[])}}catch(t){let r=t instanceof Error?t.message:String(t);X.postMessage({id:n,error:r,missing:t instanceof e},[])}finally{Q.delete(n)}}function ze({page:e}){let t=/* @__PURE__ */ new Set;for(let n of[e.geometry,e.colour,e.params,e.clusters])t.add(n.buffer);return[...t]}})();", ut = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", lt], { type: "text/javascript;charset=utf-8" });
|
|
1880
|
+
function dt(e) {
|
|
1631
1881
|
let t;
|
|
1632
1882
|
try {
|
|
1633
|
-
if (t =
|
|
1883
|
+
if (t = ut && (self.URL || self.webkitURL).createObjectURL(ut), !t) throw "";
|
|
1634
1884
|
let n = new Worker(t, { name: e?.name });
|
|
1635
1885
|
return n.addEventListener("error", () => {
|
|
1636
1886
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
1637
1887
|
}), n;
|
|
1638
1888
|
} catch {
|
|
1639
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
1889
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(lt), { name: e?.name });
|
|
1640
1890
|
}
|
|
1641
1891
|
}
|
|
1642
1892
|
//#endregion
|
|
1643
1893
|
//#region src/engine/stream/loader.ts
|
|
1644
|
-
var
|
|
1894
|
+
var ft = class {
|
|
1645
1895
|
#e;
|
|
1646
1896
|
#t = /* @__PURE__ */ new Map();
|
|
1647
1897
|
#n = 0;
|
|
1648
1898
|
constructor(e) {
|
|
1649
1899
|
let { base: t, cache: n, source: r, workers: i } = e;
|
|
1650
1900
|
this.#e = Array.from({ length: i }, (e, a) => {
|
|
1651
|
-
let o = new
|
|
1901
|
+
let o = new dt(), s = { worker: o }, c = typeof r == "function" ? ct(r, (e, t) => o.postMessage(e, t)) : void 0;
|
|
1652
1902
|
o.onmessage = ({ data: e }) => {
|
|
1653
1903
|
"id" in e ? this.#i(e) : c?.(e);
|
|
1654
1904
|
}, o.onerror = () => this.#a(s);
|
|
@@ -1672,8 +1922,8 @@ var nt = class {
|
|
|
1672
1922
|
return this.#r(this.#e[0], t);
|
|
1673
1923
|
}
|
|
1674
1924
|
batch(e, t, n) {
|
|
1675
|
-
if (t.aborted) return Promise.reject(
|
|
1676
|
-
let r = this.#e[
|
|
1925
|
+
if (t.aborted) return Promise.reject(K());
|
|
1926
|
+
let r = this.#e[pt(`${e.pack}#${e.window}`, this.#e.length)], i = {
|
|
1677
1927
|
type: "batch",
|
|
1678
1928
|
id: ++this.#n,
|
|
1679
1929
|
batch: e
|
|
@@ -1682,7 +1932,7 @@ var nt = class {
|
|
|
1682
1932
|
}
|
|
1683
1933
|
destroy() {
|
|
1684
1934
|
for (let { worker: e } of this.#e) e.terminate();
|
|
1685
|
-
for (let e of this.#t.values()) e.reject(
|
|
1935
|
+
for (let e of this.#t.values()) e.reject(K());
|
|
1686
1936
|
}
|
|
1687
1937
|
#r(e, t, n, r) {
|
|
1688
1938
|
if (e.error) return Promise.reject(e.error);
|
|
@@ -1694,7 +1944,7 @@ var nt = class {
|
|
|
1694
1944
|
s(), e.worker.postMessage({
|
|
1695
1945
|
type: "abort",
|
|
1696
1946
|
id: i
|
|
1697
|
-
}), o(
|
|
1947
|
+
}), o(K());
|
|
1698
1948
|
};
|
|
1699
1949
|
this.#t.set(i, {
|
|
1700
1950
|
slot: e,
|
|
@@ -1717,237 +1967,56 @@ var nt = class {
|
|
|
1717
1967
|
for (let t of this.#t.values()) t.slot === e && t.reject(e.error);
|
|
1718
1968
|
}
|
|
1719
1969
|
};
|
|
1720
|
-
function
|
|
1970
|
+
function pt(e, t) {
|
|
1721
1971
|
let n = 2166136261;
|
|
1722
1972
|
for (let t = 0; t < e.length; t++) n = Math.imul(n ^ e.charCodeAt(t), 16777619);
|
|
1723
1973
|
return (n >>> 0) % t;
|
|
1724
1974
|
}
|
|
1725
|
-
function
|
|
1975
|
+
function K() {
|
|
1726
1976
|
return new DOMException("The request was aborted.", "AbortError");
|
|
1727
1977
|
}
|
|
1728
1978
|
//#endregion
|
|
1729
|
-
//#region src/engine/world/tree.ts
|
|
1730
|
-
var H = (e, t, n) => (e * 256 + t) * 256 + n, it = class {
|
|
1731
|
-
roots = [];
|
|
1732
|
-
pages = /* @__PURE__ */ new Map();
|
|
1733
|
-
units = /* @__PURE__ */ new Map();
|
|
1734
|
-
#e;
|
|
1735
|
-
#t;
|
|
1736
|
-
#n = 0;
|
|
1737
|
-
#r = /* @__PURE__ */ new Map();
|
|
1738
|
-
#i = /* @__PURE__ */ new Map();
|
|
1739
|
-
constructor(e) {
|
|
1740
|
-
this.#e = new Set(e.roots.map(U)), this.#t = Math.max(...e.roots.map((e) => e.level));
|
|
1741
|
-
}
|
|
1742
|
-
add(e, t) {
|
|
1743
|
-
let n = U(e), r = this.units.get(n);
|
|
1744
|
-
if (r) return r;
|
|
1745
|
-
let o = /* @__PURE__ */ new Map(), s = {
|
|
1746
|
-
level: e.level,
|
|
1747
|
-
e: e.e,
|
|
1748
|
-
n: e.n,
|
|
1749
|
-
idx: e,
|
|
1750
|
-
path: t,
|
|
1751
|
-
parent: null,
|
|
1752
|
-
pages: [],
|
|
1753
|
-
grid: o
|
|
1754
|
-
};
|
|
1755
|
-
for (let t of e.rows) {
|
|
1756
|
-
let n = t.box, r = {
|
|
1757
|
-
id: this.#n++,
|
|
1758
|
-
unit: s,
|
|
1759
|
-
row: t,
|
|
1760
|
-
g: t.g,
|
|
1761
|
-
box: Float64Array.of(e.e + n[0], e.n + n[1], n[2], e.e + n[3], e.n + n[4], n[5]),
|
|
1762
|
-
parent: null,
|
|
1763
|
-
children: [
|
|
1764
|
-
null,
|
|
1765
|
-
null,
|
|
1766
|
-
null,
|
|
1767
|
-
null
|
|
1768
|
-
]
|
|
1769
|
-
};
|
|
1770
|
-
this.pages.set(r.id, r), s.pages.push(r), o.set(H(t.g, t.i, t.j), r);
|
|
1771
|
-
}
|
|
1772
|
-
this.units.set(n, s), this.#r.delete(n);
|
|
1773
|
-
for (let t = e.level + 1; t <= this.#t; t++) {
|
|
1774
|
-
let n = U(W(e, t));
|
|
1775
|
-
this.#i.set(n, (this.#i.get(n) ?? 0) + 1);
|
|
1776
|
-
}
|
|
1777
|
-
let c = new Set(e.rows.map((e) => e.g)), l = Math.max(...c), u = e.level === 0 ? 0 : e.level + 1, d = new Set(e.children.map((e) => e.quadrant));
|
|
1778
|
-
for (let e of s.pages) {
|
|
1779
|
-
let { g: t, i: n, j: r } = e.row;
|
|
1780
|
-
c.has(t + 1) && (e.parent = o.get(H(t + 1, n >> 1, r >> 1)) ?? null);
|
|
1781
|
-
for (let i = 0; i < 4; i++) {
|
|
1782
|
-
let a = 2 * n + (i & 1), s = 2 * r + (i >> 1);
|
|
1783
|
-
c.has(t - 1) ? e.children[i] = o.get(H(t - 1, a, s)) ?? null : t === u && t > 0 && (e.children[i] = d.has((a >> 3) + 2 * (s >> 3)) ? void 0 : null);
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
if (this.#e.has(n)) for (let e of s.pages) e.g === l && this.roots.push(e);
|
|
1787
|
-
else {
|
|
1788
|
-
let t = this.units.get(U(W(e, e.level + 1)));
|
|
1789
|
-
t && this.#o(t, s);
|
|
1790
|
-
}
|
|
1791
|
-
let f = a(s.idx);
|
|
1792
|
-
for (let { key: t } of f) {
|
|
1793
|
-
let n = t.level === e.level - 1 ? this.units.get(U(t)) : void 0;
|
|
1794
|
-
n && this.#o(s, n);
|
|
1795
|
-
}
|
|
1796
|
-
for (let { key: e, hash: t } of f) {
|
|
1797
|
-
let n = U(e);
|
|
1798
|
-
if (this.units.has(n)) continue;
|
|
1799
|
-
let r = this.#r.get(n);
|
|
1800
|
-
if (r && r.from <= s.level) continue;
|
|
1801
|
-
let a = this.#s(s, e), o = {
|
|
1802
|
-
...e,
|
|
1803
|
-
path: i(e, t, "idx"),
|
|
1804
|
-
over: a
|
|
1805
|
-
};
|
|
1806
|
-
this.#r.set(n, {
|
|
1807
|
-
wanted: o,
|
|
1808
|
-
from: s.level
|
|
1809
|
-
});
|
|
1810
|
-
}
|
|
1811
|
-
return s;
|
|
1812
|
-
}
|
|
1813
|
-
wanted() {
|
|
1814
|
-
return Array.from(this.#r.values(), (e) => e.wanted);
|
|
1815
|
-
}
|
|
1816
|
-
ground(e, t) {
|
|
1817
|
-
for (let n of this.roots) {
|
|
1818
|
-
let [r, i, a] = at(n);
|
|
1819
|
-
if (e < r || e >= r + a || t < i || t >= i + a) continue;
|
|
1820
|
-
let o = n;
|
|
1821
|
-
for (;;) {
|
|
1822
|
-
let n = +(e >= r + a / 2), s = +(t >= i + a / 2), c = o.children[n + 2 * s];
|
|
1823
|
-
if (!c) return o.box[2];
|
|
1824
|
-
o = c, [r, i, a] = at(o);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
prune(e) {
|
|
1829
|
-
let t = [], n = [...this.units.values()].sort((e, t) => e.level - t.level);
|
|
1830
|
-
for (let r of n) {
|
|
1831
|
-
let n = U(r);
|
|
1832
|
-
if (this.#e.has(n) || this.#i.has(n) || r.pages.some((t) => e.has(t.id))) continue;
|
|
1833
|
-
for (let e of r.pages) this.pages.delete(e.id), t.push(e.id);
|
|
1834
|
-
let i = r.parent;
|
|
1835
|
-
if (i) {
|
|
1836
|
-
let e = 250 * 2 ** r.level, t = (r.e - i.e) / e, n = (r.n - i.n) / e, a = i.idx.children.some((e) => e.quadrant === t + 2 * n);
|
|
1837
|
-
for (let e of this.#s(i, r)) e.children.fill(a ? void 0 : null);
|
|
1838
|
-
}
|
|
1839
|
-
this.units.delete(n);
|
|
1840
|
-
for (let e = r.level + 1; e <= this.#t; e++) {
|
|
1841
|
-
let t = U(W(r, e)), n = this.#i.get(t) - 1;
|
|
1842
|
-
n ? this.#i.set(t, n) : this.#i.delete(t);
|
|
1843
|
-
}
|
|
1844
|
-
for (let { key: e } of a(r.idx)) this.#a(e);
|
|
1845
|
-
this.#a(r);
|
|
1846
|
-
}
|
|
1847
|
-
return t;
|
|
1848
|
-
}
|
|
1849
|
-
#a(e) {
|
|
1850
|
-
let t = U(e);
|
|
1851
|
-
this.#r.delete(t);
|
|
1852
|
-
for (let n = e.level + 1; n <= e.level + 3; n++) {
|
|
1853
|
-
let r = this.units.get(U(W(e, n)));
|
|
1854
|
-
if (!r) continue;
|
|
1855
|
-
let o = a(r.idx).find((e) => U(e.key) === t);
|
|
1856
|
-
if (!o) continue;
|
|
1857
|
-
let s = {
|
|
1858
|
-
level: e.level,
|
|
1859
|
-
e: e.e,
|
|
1860
|
-
n: e.n,
|
|
1861
|
-
path: i(o.key, o.hash, "idx"),
|
|
1862
|
-
over: this.#s(r, e)
|
|
1863
|
-
};
|
|
1864
|
-
this.#r.set(t, {
|
|
1865
|
-
wanted: s,
|
|
1866
|
-
from: r.level
|
|
1867
|
-
});
|
|
1868
|
-
return;
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
#o(e, t) {
|
|
1872
|
-
t.parent = e;
|
|
1873
|
-
let n = t.level + 1, r = 250 * 2 ** t.level, i = (t.e - e.e) / r, a = (t.n - e.n) / r, o = e.grid;
|
|
1874
|
-
for (let n of this.#s(e, t)) n.children.fill(null);
|
|
1875
|
-
for (let e of t.pages) {
|
|
1876
|
-
if (e.g !== n) continue;
|
|
1877
|
-
let t = 8 * i + e.row.i, r = 8 * a + e.row.j, s = o.get(H(n + 1, t >> 1, r >> 1)) ?? null;
|
|
1878
|
-
e.parent = s, s && (s.children[(t & 1) + 2 * (r & 1)] = e);
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
#s(t, n) {
|
|
1882
|
-
let r = t.level + 1, i = e * 2 ** r, a = (n.e - t.e) / i, o = (n.n - t.n) / i, s = 250 * 2 ** n.level / i, c = [];
|
|
1883
|
-
for (let e = o; e < o + s; e++) for (let n = a; n < a + s; n++) {
|
|
1884
|
-
let i = t.grid.get(H(r, n, e));
|
|
1885
|
-
i && c.push(i);
|
|
1886
|
-
}
|
|
1887
|
-
return c;
|
|
1888
|
-
}
|
|
1889
|
-
};
|
|
1890
|
-
function U(e) {
|
|
1891
|
-
return `${e.level}/${e.e}/${e.n}`;
|
|
1892
|
-
}
|
|
1893
|
-
function W(e, t) {
|
|
1894
|
-
let n = 250 * 2 ** t;
|
|
1895
|
-
return {
|
|
1896
|
-
level: t,
|
|
1897
|
-
e: Math.floor(e.e / n) * n,
|
|
1898
|
-
n: Math.floor(e.n / n) * n
|
|
1899
|
-
};
|
|
1900
|
-
}
|
|
1901
|
-
function at(t) {
|
|
1902
|
-
let n = e * 2 ** t.g;
|
|
1903
|
-
return [
|
|
1904
|
-
t.unit.e + t.row.i * n,
|
|
1905
|
-
t.unit.n + t.row.j * n,
|
|
1906
|
-
n
|
|
1907
|
-
];
|
|
1908
|
-
}
|
|
1909
|
-
//#endregion
|
|
1910
1979
|
//#region src/engine/engine.ts
|
|
1911
|
-
var
|
|
1980
|
+
var mt = class extends Error {
|
|
1912
1981
|
constructor() {
|
|
1913
1982
|
super("This viewer needs WebGPU. Update to the latest Chrome, Edge, Safari or Firefox."), this.name = "NoWebGpu";
|
|
1914
1983
|
}
|
|
1915
1984
|
};
|
|
1916
|
-
async function
|
|
1985
|
+
async function ht(e, t) {
|
|
1917
1986
|
let n = await p();
|
|
1918
|
-
if (!n) throw new
|
|
1987
|
+
if (!n) throw new mt();
|
|
1919
1988
|
let r = e.getContext("webgpu");
|
|
1920
|
-
if (!r) throw n.device.destroy(), new
|
|
1989
|
+
if (!r) throw n.device.destroy(), new mt();
|
|
1921
1990
|
r.configure({
|
|
1922
1991
|
device: n.device,
|
|
1923
1992
|
format: n.format,
|
|
1924
1993
|
alphaMode: "opaque"
|
|
1925
1994
|
}), (t.cache ?? "opfs") === "opfs" && navigator.storage?.persist().catch(() => !1);
|
|
1926
1995
|
let { source: i = "http" } = t;
|
|
1927
|
-
return new
|
|
1996
|
+
return new zt(e, n, r, t, i === "synthetic" ? (await import("./synthetic-BeGCzYIv.js")).synthetic() : i === "http" ? s : i);
|
|
1928
1997
|
}
|
|
1929
|
-
var
|
|
1930
|
-
function
|
|
1998
|
+
var gt = .2, _t = 25165824, vt = 3.25, yt = 2, bt = 1024, xt = 2048, St = 100, Ct = 2, wt = 300, Tt = 100, Et = 250, Dt = 300, Ot = 1e3, kt = 400, At = 5e3, jt = 60, q = Math.PI / 180, Mt = "The viewer was closed.", Nt = "Another world was opened.";
|
|
1999
|
+
function Pt(e, t) {
|
|
1931
2000
|
let n = Math.min(t.maxStorageBufferBindingSize, t.maxBufferSize), r = (t, r) => {
|
|
1932
2001
|
let i = Math.ceil(e * t / 256) * 256;
|
|
1933
2002
|
return Math.min(i, Math.floor(n / r / 256) * 256);
|
|
1934
2003
|
};
|
|
1935
2004
|
return {
|
|
1936
|
-
pool: r(
|
|
1937
|
-
frame: r(
|
|
2005
|
+
pool: r(vt, 16),
|
|
2006
|
+
frame: r(yt, 24)
|
|
1938
2007
|
};
|
|
1939
2008
|
}
|
|
1940
|
-
function
|
|
2009
|
+
function Ft(e, t) {
|
|
1941
2010
|
let [n, r, i] = t;
|
|
1942
|
-
if (Math.hypot(n - e[0], r - e[1], i - e[2]) <=
|
|
1943
|
-
let a = (e) => Math.round(e /
|
|
2011
|
+
if (Math.hypot(n - e[0], r - e[1], i - e[2]) <= xt) return e;
|
|
2012
|
+
let a = (e) => Math.round(e / bt) * bt;
|
|
1944
2013
|
return [
|
|
1945
2014
|
a(n),
|
|
1946
2015
|
a(r),
|
|
1947
2016
|
a(i)
|
|
1948
2017
|
];
|
|
1949
2018
|
}
|
|
1950
|
-
function
|
|
2019
|
+
function It(e, t, n, r, i, a) {
|
|
1951
2020
|
let o = 2 * e[0] / t[0] - 1, s = 1 - 2 * e[1] / t[1], c = [
|
|
1952
2021
|
n * o / r[0],
|
|
1953
2022
|
n * s / r[5],
|
|
@@ -1959,29 +2028,29 @@ function Tt(e, t, n, r, i, a) {
|
|
|
1959
2028
|
d + a[2]
|
|
1960
2029
|
];
|
|
1961
2030
|
}
|
|
1962
|
-
function
|
|
2031
|
+
function Lt(e, t) {
|
|
1963
2032
|
return [
|
|
1964
2033
|
e.e - t[0],
|
|
1965
2034
|
e.n - t[1],
|
|
1966
2035
|
e.h - t[2]
|
|
1967
2036
|
];
|
|
1968
2037
|
}
|
|
1969
|
-
function
|
|
1970
|
-
e.push(t), e.length >
|
|
2038
|
+
function Rt(e, t) {
|
|
2039
|
+
e.push(t), e.length > jt && e.shift();
|
|
1971
2040
|
}
|
|
1972
|
-
var
|
|
2041
|
+
var zt = class {
|
|
1973
2042
|
#e;
|
|
1974
2043
|
#t;
|
|
1975
2044
|
#n;
|
|
1976
2045
|
#r;
|
|
1977
2046
|
#i;
|
|
1978
2047
|
#a;
|
|
1979
|
-
#o
|
|
2048
|
+
#o;
|
|
1980
2049
|
#s;
|
|
1981
2050
|
#c;
|
|
1982
2051
|
#l;
|
|
1983
|
-
#u = new
|
|
1984
|
-
#d = new
|
|
2052
|
+
#u = new ze();
|
|
2053
|
+
#d = new Ee();
|
|
1985
2054
|
#f = (e) => this.#s.has(e);
|
|
1986
2055
|
#p = null;
|
|
1987
2056
|
#m = null;
|
|
@@ -2042,13 +2111,13 @@ var Ot = class {
|
|
|
2042
2111
|
#ee = !1;
|
|
2043
2112
|
#te = !1;
|
|
2044
2113
|
constructor(e, t, n, r, i) {
|
|
2045
|
-
this.#e = e, this.#t = t, this.#n = n, this.#r = r, this.#i = i, this.#a = { ...r.settings }, this.#O = [
|
|
2114
|
+
this.#e = e, this.#t = t, this.#n = n, this.#r = r, this.#i = i, this.#a = { ...r.settings }, this.#o = this.#re(), this.#O = [
|
|
2046
2115
|
e.width,
|
|
2047
2116
|
e.height,
|
|
2048
2117
|
1
|
|
2049
2118
|
], this.#k = [Math.max(1, e.width), Math.max(1, e.height)];
|
|
2050
|
-
let { pool: a, frame: o } =
|
|
2051
|
-
this.#s = new _(t.device, a), this.#c = new
|
|
2119
|
+
let { pool: a, frame: o } = Pt(this.#ne, t.device.limits);
|
|
2120
|
+
this.#s = new _(t.device, a), this.#c = new Ce(t, n, this.#s, o), this.#l = o, t.device.lost.then((e) => {
|
|
2052
2121
|
if (!this.#ee) {
|
|
2053
2122
|
this.#te = !0, cancelAnimationFrame(this.#A);
|
|
2054
2123
|
for (let t of this.#Z) t(e.message || e.reason);
|
|
@@ -2056,53 +2125,54 @@ var Ot = class {
|
|
|
2056
2125
|
});
|
|
2057
2126
|
}
|
|
2058
2127
|
async open(e) {
|
|
2059
|
-
if (this.#ee) throw Error(
|
|
2128
|
+
if (this.#ee) throw Error(Mt);
|
|
2060
2129
|
let t = ++this.#_, i = () => {
|
|
2061
|
-
if (this.#ee) throw Error(
|
|
2062
|
-
if (t !== this.#_) throw Error(
|
|
2130
|
+
if (this.#ee) throw Error(Mt);
|
|
2131
|
+
if (t !== this.#_) throw Error(Nt);
|
|
2063
2132
|
}, { cache: a = "opfs", source: o = "http" } = this.#r;
|
|
2064
2133
|
o === "http" && (e = new URL(e, document.baseURI).href);
|
|
2065
2134
|
let s = await this.#i(e, null), c = r(JSON.parse(new TextDecoder().decode(s)));
|
|
2066
2135
|
i();
|
|
2067
|
-
let l = new
|
|
2136
|
+
let l = new ft({
|
|
2068
2137
|
base: n(e),
|
|
2069
2138
|
workers: Math.min(6, Math.max(2, navigator.hardwareConcurrency - 2)),
|
|
2070
2139
|
cache: a,
|
|
2071
2140
|
source: o
|
|
2072
|
-
}), u = new
|
|
2141
|
+
}), u = new Fe(c);
|
|
2073
2142
|
try {
|
|
2074
2143
|
let e = await Promise.all(c.roots.map((e) => l.idx(e.idx)));
|
|
2075
2144
|
i(), e.forEach((e, t) => u.add(e, c.roots[t].idx));
|
|
2076
2145
|
} catch (e) {
|
|
2077
2146
|
throw l.destroy(), e;
|
|
2078
2147
|
}
|
|
2079
|
-
return this.#g?.destroy(), this.#g = null, this.#h?.destroy(), this.#p = e, this.#m = u, this.#h = l, this.#N = null, this.#u = new
|
|
2148
|
+
return this.#g?.destroy(), this.#g = null, this.#h?.destroy(), this.#p = e, this.#m = u, this.#h = l, this.#N = null, this.#u = new ze(), this.#d = new Ee(), this.#s.clear(), this.#g = this.#oe(u, l), this.#I = !0, this.requestFrame(), c;
|
|
2080
2149
|
}
|
|
2081
2150
|
setCamera(e) {
|
|
2082
2151
|
if (this.#ee) return;
|
|
2083
2152
|
let t = performance.now(), n = t - this.#b, r = this.#y, i = this.#x;
|
|
2084
|
-
if (n >
|
|
2153
|
+
if (n > Et) i.fill(0);
|
|
2085
2154
|
else if (n > 0) {
|
|
2086
|
-
let t = 1 - Math.exp(-n /
|
|
2155
|
+
let t = 1 - Math.exp(-n / Tt);
|
|
2087
2156
|
i[0] += t * ((e.e - r.e) / n - i[0]), i[1] += t * ((e.n - r.n) / n - i[1]), i[2] += t * ((e.h - r.h) / n - i[2]);
|
|
2088
2157
|
}
|
|
2089
2158
|
this.#b = t, this.#y = { ...e }, this.#F = !0, this.#$ || this.requestFrame();
|
|
2090
2159
|
}
|
|
2091
2160
|
configure(e) {
|
|
2092
2161
|
if (this.#ee) return;
|
|
2162
|
+
let { budget: t, budgetRange: n } = this.#a;
|
|
2093
2163
|
this.#a = {
|
|
2094
2164
|
...this.#a,
|
|
2095
2165
|
...e
|
|
2096
2166
|
};
|
|
2097
|
-
let
|
|
2098
|
-
(
|
|
2167
|
+
let r = this.#a;
|
|
2168
|
+
(r.budget !== t || !((e, t) => e?.join() === t?.join())(r.budgetRange, n)) && (this.#o = this.#re(), this.#le()), this.#ie();
|
|
2099
2169
|
}
|
|
2100
2170
|
resize(e, t, n) {
|
|
2101
2171
|
this.#ee || (this.#O = [
|
|
2102
2172
|
e,
|
|
2103
2173
|
t,
|
|
2104
2174
|
n
|
|
2105
|
-
], this.#
|
|
2175
|
+
], this.#le());
|
|
2106
2176
|
}
|
|
2107
2177
|
pick(e, t) {
|
|
2108
2178
|
if (this.#ee || this.#te) return Promise.resolve(null);
|
|
@@ -2118,6 +2188,10 @@ var Ot = class {
|
|
|
2118
2188
|
ground(e, t) {
|
|
2119
2189
|
return this.#m?.ground(e, t);
|
|
2120
2190
|
}
|
|
2191
|
+
async groundAt(e, t) {
|
|
2192
|
+
let n = this.#m, r = this.#h;
|
|
2193
|
+
if (n && r) return await n.load(e, t, (e) => r.idx(e)), this.#R = !0, this.requestFrame(), n.ground(e, t);
|
|
2194
|
+
}
|
|
2121
2195
|
heights(e, t, n) {
|
|
2122
2196
|
return this.#ee || this.#te ? Promise.resolve(null) : new Promise((r) => {
|
|
2123
2197
|
this.#Y.push({
|
|
@@ -2131,8 +2205,8 @@ var Ot = class {
|
|
|
2131
2205
|
stats() {
|
|
2132
2206
|
let e = this.#s, t = this.#g, n = this.#c.stats();
|
|
2133
2207
|
return {
|
|
2134
|
-
frameMs:
|
|
2135
|
-
cpuMs:
|
|
2208
|
+
frameMs: $e(this.#W, .5),
|
|
2209
|
+
cpuMs: $e(this.#G, .5),
|
|
2136
2210
|
gpuMs: n.gpuMs,
|
|
2137
2211
|
passes: n.passes,
|
|
2138
2212
|
drawn: n.drawn,
|
|
@@ -2149,6 +2223,7 @@ var Ot = class {
|
|
|
2149
2223
|
buffers: n.bytes
|
|
2150
2224
|
},
|
|
2151
2225
|
capacity: e.capacity,
|
|
2226
|
+
budget: this.#ne,
|
|
2152
2227
|
scale: this.#o.scale,
|
|
2153
2228
|
loading: t !== null && !t.idle
|
|
2154
2229
|
};
|
|
@@ -2161,8 +2236,8 @@ var Ot = class {
|
|
|
2161
2236
|
use(e) {
|
|
2162
2237
|
if (this.#ee) return () => {};
|
|
2163
2238
|
let t = e({
|
|
2164
|
-
shade: (e) => this.#
|
|
2165
|
-
post: (e) => this.#
|
|
2239
|
+
shade: (e) => this.#ce(this.#K, e, this.#c.shade(e)),
|
|
2240
|
+
post: (e) => this.#ce(this.#q, e, this.#c.post(e))
|
|
2166
2241
|
});
|
|
2167
2242
|
return () => {
|
|
2168
2243
|
this.#ee || t();
|
|
@@ -2170,7 +2245,7 @@ var Ot = class {
|
|
|
2170
2245
|
}
|
|
2171
2246
|
warm() {
|
|
2172
2247
|
let e = performance.now();
|
|
2173
|
-
e - this.#V <
|
|
2248
|
+
e - this.#V < Ot || (this.#H = e + kt, this.requestFrame());
|
|
2174
2249
|
}
|
|
2175
2250
|
onFrame(e) {
|
|
2176
2251
|
return this.#Q.add(e), () => this.#Q.delete(e);
|
|
@@ -2179,7 +2254,7 @@ var Ot = class {
|
|
|
2179
2254
|
return this.#Z.add(e), () => this.#Z.delete(e);
|
|
2180
2255
|
}
|
|
2181
2256
|
requestFrame() {
|
|
2182
|
-
this.#ee || this.#te || this.#r.manual || this.#A || (this.#A = requestAnimationFrame(this.#
|
|
2257
|
+
this.#ee || this.#te || this.#r.manual || this.#A || (this.#A = requestAnimationFrame(this.#ue));
|
|
2183
2258
|
}
|
|
2184
2259
|
async step() {
|
|
2185
2260
|
if (this.#ee || this.#te) return {
|
|
@@ -2187,7 +2262,7 @@ var Ot = class {
|
|
|
2187
2262
|
gpuMs: 0,
|
|
2188
2263
|
passes: {}
|
|
2189
2264
|
};
|
|
2190
|
-
let { done: e, cpuMs: t } = this.#
|
|
2265
|
+
let { done: e, cpuMs: t } = this.#de(!1);
|
|
2191
2266
|
await e;
|
|
2192
2267
|
let { gpuMs: n, passes: r } = this.#c.stats();
|
|
2193
2268
|
return {
|
|
@@ -2206,29 +2281,36 @@ var Ot = class {
|
|
|
2206
2281
|
}
|
|
2207
2282
|
}
|
|
2208
2283
|
get #ne() {
|
|
2209
|
-
|
|
2210
|
-
|
|
2284
|
+
return this.#o.budget;
|
|
2285
|
+
}
|
|
2286
|
+
#re() {
|
|
2287
|
+
let { budget: e, budgetRange: t = [e, e] } = this.#a, n = Math.floor(Pt(Infinity, this.#t.device.limits).frame / yt), r = (e) => Math.max(1, Math.min(e, n));
|
|
2288
|
+
return new et(r(e), [r(t[0]), r(t[1])]);
|
|
2211
2289
|
}
|
|
2212
|
-
#
|
|
2213
|
-
|
|
2214
|
-
|
|
2290
|
+
#ie() {
|
|
2291
|
+
let { pool: e, frame: t } = Pt(this.#ne, this.#t.device.limits);
|
|
2292
|
+
(e > this.#s.capacity || t > this.#l) && this.#ae(e, t), this.#I = !0, this.requestFrame();
|
|
2293
|
+
}
|
|
2294
|
+
#ae(e, t) {
|
|
2295
|
+
this.#s.grow(e), this.#c.destroy();
|
|
2296
|
+
let n = new Ce(this.#t, this.#n, this.#s, t);
|
|
2215
2297
|
n.resize(...this.#k);
|
|
2216
2298
|
for (let e of this.#K) e.off = n.shade(e.hook);
|
|
2217
2299
|
for (let e of this.#q) e.off = n.post(e.hook);
|
|
2218
|
-
this.#c = n, this.#l = t
|
|
2300
|
+
this.#c = n, this.#l = t;
|
|
2219
2301
|
}
|
|
2220
|
-
#
|
|
2221
|
-
return new
|
|
2302
|
+
#oe(e, t) {
|
|
2303
|
+
return new st(e, t, this.#s, () => {
|
|
2222
2304
|
this.#R = !0, this.requestFrame();
|
|
2223
|
-
}, this.#
|
|
2305
|
+
}, this.#se);
|
|
2224
2306
|
}
|
|
2225
|
-
#
|
|
2307
|
+
#se = () => {
|
|
2226
2308
|
let e = this.#p, t = this.#m;
|
|
2227
2309
|
this.#v || this.#ee || e === null || (this.#v = !0, this.open(e).then(() => this.#v = !1, () => {
|
|
2228
|
-
this.#v = !1, this.#m === t && setTimeout(this.#
|
|
2310
|
+
this.#v = !1, this.#m === t && setTimeout(this.#se, At);
|
|
2229
2311
|
}));
|
|
2230
2312
|
};
|
|
2231
|
-
#
|
|
2313
|
+
#ce(e, t, n) {
|
|
2232
2314
|
let r = {
|
|
2233
2315
|
hook: t,
|
|
2234
2316
|
off: n
|
|
@@ -2238,105 +2320,105 @@ var Ot = class {
|
|
|
2238
2320
|
this.#ee || t < 0 || (e.splice(t, 1), r.off(), this.requestFrame());
|
|
2239
2321
|
};
|
|
2240
2322
|
}
|
|
2241
|
-
#
|
|
2242
|
-
let [e, t, n] = this.#O, r =
|
|
2323
|
+
#le() {
|
|
2324
|
+
let [e, t, n] = this.#O, r = Qe(e, t, n, this.#o.scale), i = Math.max(1, Math.round(e * r)), a = Math.max(1, Math.round(t * r));
|
|
2243
2325
|
(i !== this.#k[0] || a !== this.#k[1]) && (this.#k = [i, a], this.#e.width = i, this.#e.height = a, this.#c.resize(i, a), this.#I = !0, this.requestFrame());
|
|
2244
2326
|
}
|
|
2245
|
-
#
|
|
2327
|
+
#ue = (e) => {
|
|
2246
2328
|
if (this.#A = 0, !(this.#ee || this.#te)) {
|
|
2247
|
-
if (this.#j >=
|
|
2329
|
+
if (this.#j >= Ct) this.#M = !0;
|
|
2248
2330
|
else {
|
|
2249
2331
|
this.#$ = !0;
|
|
2250
2332
|
for (let t of this.#Q) t(e);
|
|
2251
|
-
this.#$ = !1, this.#j++, this.#
|
|
2333
|
+
this.#$ = !1, this.#j++, this.#de(!0).done.finally(() => {
|
|
2252
2334
|
this.#j--, this.#M && (this.#M = !1, this.requestFrame());
|
|
2253
2335
|
});
|
|
2254
2336
|
}
|
|
2255
2337
|
}
|
|
2256
2338
|
};
|
|
2257
|
-
#
|
|
2339
|
+
#de(e) {
|
|
2258
2340
|
let t = performance.now(), n = this.#o, r = this.#s, i = this.#y, [a, o] = this.#k, s = this.#a.viewDistance, c = this.#F;
|
|
2259
2341
|
this.#F = !1;
|
|
2260
|
-
let l =
|
|
2342
|
+
let l = Ft(this.#S, [
|
|
2261
2343
|
i.e,
|
|
2262
2344
|
i.n,
|
|
2263
2345
|
i.h
|
|
2264
2346
|
]);
|
|
2265
2347
|
l !== this.#S && (this.#S = l, r.setOrigin(l));
|
|
2266
|
-
let u =
|
|
2267
|
-
y(this.#C, u, i.yaw *
|
|
2348
|
+
let u = Lt(i, l);
|
|
2349
|
+
y(this.#C, u, i.yaw * q, i.pitch * q), b(this.#w, i.fov * q, a / o, gt, s);
|
|
2268
2350
|
let d = {
|
|
2269
2351
|
time: t,
|
|
2270
2352
|
width: a,
|
|
2271
2353
|
height: o,
|
|
2272
2354
|
view: new Float32Array(this.#C),
|
|
2273
2355
|
proj: new Float32Array(this.#w),
|
|
2274
|
-
near:
|
|
2356
|
+
near: gt,
|
|
2275
2357
|
far: s,
|
|
2276
2358
|
camera: Float32Array.from(u),
|
|
2277
2359
|
origin: l
|
|
2278
2360
|
};
|
|
2279
|
-
|
|
2361
|
+
Te(this.#D, S(this.#E, d.proj, d.view));
|
|
2280
2362
|
let f = this.#m, p = this.#g, m = this.#R || this.#I || this.#z, h = this.#N, g = h;
|
|
2281
2363
|
if (f && p) {
|
|
2282
|
-
let e = !p.idle && t - this.#P >=
|
|
2283
|
-
(!g || c || e || n) && (g = this.#
|
|
2364
|
+
let e = !p.idle && t - this.#P >= St, n = this.#I || this.#R || this.#z || this.#L;
|
|
2365
|
+
(!g || c || e || n) && (g = this.#fe(f, t, c));
|
|
2284
2366
|
}
|
|
2285
2367
|
let _ = this.#B, v = this.#z;
|
|
2286
|
-
g && p && (g !== h && (m || !h || g.cut.length !== h.cut.length || g.cut.some((e, t) => e !== h.cut[t])) && ({drawn: _, fading: v} = this.#d.update(g.cut, this.#f, t, this.#ne)), p.update(g, new Set(_.map((e) => e.id)), t)), r.upload(
|
|
2287
|
-
let x = this.#J.splice(0).map((e) => this.#
|
|
2368
|
+
g && p && (g !== h && (m || !h || g.cut.length !== h.cut.length || g.cut.some((e, t) => e !== h.cut[t])) && ({drawn: _, fading: v} = this.#d.update(g.cut, this.#f, t, this.#ne)), p.update(g, new Set(_.map((e) => e.id)), t)), r.upload(_t) > 0 && (this.#R = !0), (_ !== this.#B || this.#R) && r.draw(_), this.#z = v, this.#B = _;
|
|
2369
|
+
let x = this.#J.splice(0).map((e) => this.#me(e, d)), C = this.#Y.splice(0).map((e) => this.#he(e, l)), w = this.#c.render(d, this.#D, this.#r.sky, x, C), T = performance.now() - t;
|
|
2288
2370
|
if (!this.#R && !this.#L && !v && r.queued === 0 && (!p || p.idle) && (!g || g.load.length === 0 && g.idx.length === 0) && this.#X.length) {
|
|
2289
2371
|
let e = this.#X.splice(0);
|
|
2290
2372
|
w.then(() => e.forEach((e) => e()));
|
|
2291
2373
|
}
|
|
2292
|
-
e && this.#
|
|
2374
|
+
e && this.#ge(t, T, c);
|
|
2293
2375
|
let E = t < this.#H;
|
|
2294
2376
|
return (r.queued > 0 || this.#R || this.#L || v || n.scale < 1 || E) && this.requestFrame(), {
|
|
2295
2377
|
done: w,
|
|
2296
2378
|
cpuMs: T
|
|
2297
2379
|
};
|
|
2298
2380
|
}
|
|
2299
|
-
#
|
|
2381
|
+
#fe(e, t, n) {
|
|
2300
2382
|
let r = this.#y, i = this.#s, [a, o] = this.#k, s = this.#o.scale, c = this.#ne, l = {
|
|
2301
2383
|
origin: this.#S,
|
|
2302
2384
|
width: a / s,
|
|
2303
2385
|
height: o / s,
|
|
2304
|
-
tan: Math.tan(r.fov *
|
|
2305
|
-
near:
|
|
2386
|
+
tan: Math.tan(r.fov * q / 2),
|
|
2387
|
+
near: gt,
|
|
2306
2388
|
far: this.#a.viewDistance
|
|
2307
2389
|
}, u = {
|
|
2308
2390
|
...l,
|
|
2309
2391
|
view: this.#C
|
|
2310
2392
|
}, d = {
|
|
2311
2393
|
budget: c,
|
|
2312
|
-
capacity: i.capacity - Math.ceil(
|
|
2394
|
+
capacity: i.capacity - Math.ceil(1 * c),
|
|
2313
2395
|
now: t,
|
|
2314
|
-
predicted: n ? this.#
|
|
2396
|
+
predicted: n ? this.#pe(l) : void 0
|
|
2315
2397
|
}, f = this.#u.plan(e, u, this.#f, d);
|
|
2316
2398
|
return this.#N = f, this.#P = t, this.#I = !1, this.#L = d.predicted !== void 0, this.#R = !1, f;
|
|
2317
2399
|
}
|
|
2318
|
-
#
|
|
2400
|
+
#pe(e) {
|
|
2319
2401
|
let t = this.#x;
|
|
2320
2402
|
if (t.every((e) => e === 0)) return;
|
|
2321
2403
|
let n = this.#y, r = [
|
|
2322
|
-
n.e + t[0] *
|
|
2323
|
-
n.n + t[1] *
|
|
2324
|
-
n.h + t[2] *
|
|
2404
|
+
n.e + t[0] * wt - e.origin[0],
|
|
2405
|
+
n.n + t[1] * wt - e.origin[1],
|
|
2406
|
+
n.h + t[2] * wt - e.origin[2]
|
|
2325
2407
|
];
|
|
2326
2408
|
return {
|
|
2327
2409
|
...e,
|
|
2328
|
-
view: y(this.#T, r, n.yaw *
|
|
2410
|
+
view: y(this.#T, r, n.yaw * q, n.pitch * q)
|
|
2329
2411
|
};
|
|
2330
2412
|
}
|
|
2331
|
-
#
|
|
2332
|
-
let i = this.#C.slice(), a = this.#S, o = [r.width, r.height], s = (n) =>
|
|
2413
|
+
#me({ x: e, y: t, resolve: n }, r) {
|
|
2414
|
+
let i = this.#C.slice(), a = this.#S, o = [r.width, r.height], s = (n) => It([e, t], o, n, r.proj, i, a);
|
|
2333
2415
|
return {
|
|
2334
2416
|
x: e,
|
|
2335
2417
|
y: t,
|
|
2336
2418
|
resolve: (e) => n(e === null ? null : s(e))
|
|
2337
2419
|
};
|
|
2338
2420
|
}
|
|
2339
|
-
#
|
|
2421
|
+
#he({ west: e, south: t, cells: n, resolve: r }, i) {
|
|
2340
2422
|
return {
|
|
2341
2423
|
x: e - i[0],
|
|
2342
2424
|
y: t - i[1],
|
|
@@ -2347,21 +2429,23 @@ var Ot = class {
|
|
|
2347
2429
|
}
|
|
2348
2430
|
};
|
|
2349
2431
|
}
|
|
2350
|
-
#
|
|
2351
|
-
let r = this.#o, { gpuMs: i } = this.#c.stats(), a = e - this.#V <= Math.max(
|
|
2352
|
-
|
|
2432
|
+
#ge(e, t, n) {
|
|
2433
|
+
let r = this.#o, { gpuMs: i } = this.#c.stats(), a = e - this.#V, o = a <= Math.max(Et, 2 * i, 2 * t);
|
|
2434
|
+
o && Rt(this.#W, a), Rt(this.#G, t), this.#V = e;
|
|
2435
|
+
let s = r.budget;
|
|
2436
|
+
r.sample(a, e, o && n, this.#N?.planned ?? 0) && (this.#le(), r.budget !== s && this.#ie()), n ? this.#U = e : r.scale < 1 && e - this.#U > Dt && (r.full(), this.#le());
|
|
2353
2437
|
}
|
|
2354
|
-
},
|
|
2438
|
+
}, Bt = 45, Vt = {
|
|
2355
2439
|
yaw: 0,
|
|
2356
2440
|
pitch: -35,
|
|
2357
2441
|
dist: 300
|
|
2358
|
-
},
|
|
2442
|
+
}, J = {
|
|
2359
2443
|
pitch: [-90, -20],
|
|
2360
2444
|
dist: [1, 2485],
|
|
2361
2445
|
clearance: 10,
|
|
2362
2446
|
floor: 50
|
|
2363
|
-
},
|
|
2364
|
-
function
|
|
2447
|
+
}, Ht = .1, Y = Math.PI / 180, Ut = (e, [t, n]) => Math.min(n, Math.max(t, e)), Wt = (e) => (e % 360 + 360) % 360, Gt = (e, t) => (t - e + 540) % 360 - 180;
|
|
2448
|
+
function Kt({ leaf: e, roots: t, extent: n }) {
|
|
2365
2449
|
let r = {
|
|
2366
2450
|
e: (n.e[0] + n.e[1]) / 2,
|
|
2367
2451
|
n: (n.n[0] + n.n[1]) / 2,
|
|
@@ -2378,7 +2462,7 @@ function Ft({ leaf: e, roots: t, extent: n }) {
|
|
|
2378
2462
|
}
|
|
2379
2463
|
return i;
|
|
2380
2464
|
}
|
|
2381
|
-
function
|
|
2465
|
+
function qt(e) {
|
|
2382
2466
|
let t = e.split(",");
|
|
2383
2467
|
if (t.length !== 6 || t.some((e) => e.trim() === "")) return null;
|
|
2384
2468
|
let [n, r, i, a, o, s] = t.map(Number);
|
|
@@ -2398,7 +2482,7 @@ function It(e) {
|
|
|
2398
2482
|
dist: s
|
|
2399
2483
|
};
|
|
2400
2484
|
}
|
|
2401
|
-
function
|
|
2485
|
+
function Jt(e) {
|
|
2402
2486
|
let t = (e, t) => +e.toFixed(t);
|
|
2403
2487
|
return [
|
|
2404
2488
|
t(e.e, 2),
|
|
@@ -2409,19 +2493,19 @@ function Lt(e) {
|
|
|
2409
2493
|
t(e.dist, 1)
|
|
2410
2494
|
].join(",");
|
|
2411
2495
|
}
|
|
2412
|
-
function
|
|
2496
|
+
function X(e, t, n = J) {
|
|
2413
2497
|
let r = {
|
|
2414
2498
|
e: e.e,
|
|
2415
2499
|
n: e.n,
|
|
2416
2500
|
h: e.h,
|
|
2417
|
-
yaw:
|
|
2418
|
-
pitch:
|
|
2419
|
-
dist:
|
|
2501
|
+
yaw: Wt(e.yaw),
|
|
2502
|
+
pitch: Ut(e.pitch, n.pitch),
|
|
2503
|
+
dist: Ut(e.dist, n.dist)
|
|
2420
2504
|
};
|
|
2421
2505
|
if (t) {
|
|
2422
|
-
let e =
|
|
2506
|
+
let e = Z(r), i = Math.max(n.floor, t(e.e, e.n) + n.clearance);
|
|
2423
2507
|
if (e.h < i) return {
|
|
2424
|
-
...
|
|
2508
|
+
...Qt({
|
|
2425
2509
|
...e,
|
|
2426
2510
|
h: i
|
|
2427
2511
|
}, r),
|
|
@@ -2430,42 +2514,42 @@ function Z(e, t, n = Y) {
|
|
|
2430
2514
|
}
|
|
2431
2515
|
return r;
|
|
2432
2516
|
}
|
|
2433
|
-
function
|
|
2434
|
-
let n = Math.cos(t *
|
|
2517
|
+
function Yt(e, t) {
|
|
2518
|
+
let n = Math.cos(t * Y);
|
|
2435
2519
|
return {
|
|
2436
|
-
e: Math.sin(e *
|
|
2437
|
-
n: Math.cos(e *
|
|
2438
|
-
h: Math.sin(t *
|
|
2520
|
+
e: Math.sin(e * Y) * n,
|
|
2521
|
+
n: Math.cos(e * Y) * n,
|
|
2522
|
+
h: Math.sin(t * Y)
|
|
2439
2523
|
};
|
|
2440
2524
|
}
|
|
2441
|
-
function
|
|
2442
|
-
let t =
|
|
2525
|
+
function Z(e) {
|
|
2526
|
+
let t = Yt(e.yaw, e.pitch);
|
|
2443
2527
|
return {
|
|
2444
2528
|
e: e.e - t.e * e.dist,
|
|
2445
2529
|
n: e.n - t.n * e.dist,
|
|
2446
2530
|
h: e.h - t.h * e.dist
|
|
2447
2531
|
};
|
|
2448
2532
|
}
|
|
2449
|
-
function
|
|
2533
|
+
function Xt(e) {
|
|
2450
2534
|
return {
|
|
2451
|
-
...
|
|
2535
|
+
...Z(e),
|
|
2452
2536
|
yaw: e.yaw,
|
|
2453
2537
|
pitch: e.pitch,
|
|
2454
2538
|
fov: 45
|
|
2455
2539
|
};
|
|
2456
2540
|
}
|
|
2457
|
-
function
|
|
2458
|
-
let r =
|
|
2541
|
+
function Zt(e, t, n) {
|
|
2542
|
+
let r = Z(e), [i, a, o] = [
|
|
2459
2543
|
n.e - r.e,
|
|
2460
2544
|
n.n - r.n,
|
|
2461
2545
|
n.h - r.h
|
|
2462
|
-
], [s, c] = [Math.sin(e.yaw *
|
|
2546
|
+
], [s, c] = [Math.sin(e.yaw * Y), Math.cos(e.yaw * Y)], [l, u] = [Math.sin(e.pitch * Y), Math.cos(e.pitch * Y)], d = i * s + a * c, f = 2 * Math.tan(t * Y / 2) * (d * u + o * l);
|
|
2463
2547
|
return {
|
|
2464
2548
|
x: (i * c - a * s) / f,
|
|
2465
2549
|
y: (d * l - o * u) / f
|
|
2466
2550
|
};
|
|
2467
2551
|
}
|
|
2468
|
-
function
|
|
2552
|
+
function Qt(e, t) {
|
|
2469
2553
|
let [n, r, i] = [
|
|
2470
2554
|
t.e - e.e,
|
|
2471
2555
|
t.n - e.n,
|
|
@@ -2475,17 +2559,17 @@ function Vt(e, t) {
|
|
|
2475
2559
|
e: t.e,
|
|
2476
2560
|
n: t.n,
|
|
2477
2561
|
h: t.h,
|
|
2478
|
-
yaw:
|
|
2479
|
-
pitch: Math.asin(i / a) /
|
|
2562
|
+
yaw: Wt(Math.atan2(n, r) / Y),
|
|
2563
|
+
pitch: Math.asin(i / a) / Y,
|
|
2480
2564
|
dist: a
|
|
2481
2565
|
};
|
|
2482
2566
|
}
|
|
2483
|
-
function
|
|
2484
|
-
let i =
|
|
2567
|
+
function $t(e, t, n, r = J) {
|
|
2568
|
+
let i = Z(e), a = X({
|
|
2485
2569
|
...e,
|
|
2486
2570
|
yaw: t,
|
|
2487
2571
|
pitch: n
|
|
2488
|
-
}, void 0, r), o =
|
|
2572
|
+
}, void 0, r), o = Yt(a.yaw, a.pitch);
|
|
2489
2573
|
return {
|
|
2490
2574
|
...a,
|
|
2491
2575
|
e: i.e + o.e * a.dist,
|
|
@@ -2493,11 +2577,11 @@ function Ht(e, t, n, r = Y) {
|
|
|
2493
2577
|
h: i.h + o.h * a.dist
|
|
2494
2578
|
};
|
|
2495
2579
|
}
|
|
2496
|
-
function
|
|
2497
|
-
return e.dist * Math.max(Math.sin(-e.pitch *
|
|
2580
|
+
function en(e) {
|
|
2581
|
+
return e.dist * Math.max(Math.sin(-e.pitch * Y), Ht);
|
|
2498
2582
|
}
|
|
2499
|
-
function
|
|
2500
|
-
let [i, a] = [Math.sin(e.yaw *
|
|
2583
|
+
function Q(e, t, n, r) {
|
|
2584
|
+
let [i, a] = [Math.sin(e.yaw * Y), Math.cos(e.yaw * Y)];
|
|
2501
2585
|
return {
|
|
2502
2586
|
...e,
|
|
2503
2587
|
e: e.e + t * a + n * i,
|
|
@@ -2505,30 +2589,30 @@ function Wt(e, t, n, r) {
|
|
|
2505
2589
|
h: e.h + r
|
|
2506
2590
|
};
|
|
2507
2591
|
}
|
|
2508
|
-
function
|
|
2509
|
-
return
|
|
2592
|
+
function tn(e, t, n) {
|
|
2593
|
+
return Q(e, t, n * e.dist / en(e), 0);
|
|
2510
2594
|
}
|
|
2511
|
-
function
|
|
2595
|
+
function nn(e, t, n) {
|
|
2512
2596
|
return {
|
|
2513
2597
|
e: e.e + (t.e - e.e) * n,
|
|
2514
2598
|
n: e.n + (t.n - e.n) * n,
|
|
2515
2599
|
h: e.h + (t.h - e.h) * n,
|
|
2516
|
-
yaw:
|
|
2600
|
+
yaw: Wt(e.yaw + Gt(e.yaw, t.yaw) * n),
|
|
2517
2601
|
pitch: e.pitch + (t.pitch - e.pitch) * n,
|
|
2518
2602
|
dist: e.dist * (t.dist / e.dist) ** n
|
|
2519
2603
|
};
|
|
2520
2604
|
}
|
|
2521
|
-
function
|
|
2605
|
+
function rn(e, t) {
|
|
2522
2606
|
let n = e.dist * 1e-5;
|
|
2523
|
-
return Math.abs(e.e - t.e) < n && Math.abs(e.n - t.n) < n && Math.abs(e.h - t.h) < n && Math.abs(e.dist - t.dist) < n && Math.abs(
|
|
2607
|
+
return Math.abs(e.e - t.e) < n && Math.abs(e.n - t.n) < n && Math.abs(e.h - t.h) < n && Math.abs(e.dist - t.dist) < n && Math.abs(Gt(e.yaw, t.yaw)) < .001 && Math.abs(e.pitch - t.pitch) < .001;
|
|
2524
2608
|
}
|
|
2525
2609
|
//#endregion
|
|
2526
2610
|
//#region src/controls/controls.ts
|
|
2527
|
-
var
|
|
2528
|
-
function
|
|
2611
|
+
var an = .2, on = .002, sn = .005, cn = .5, ln = .05;
|
|
2612
|
+
function un(e, t) {
|
|
2529
2613
|
return 2 * e * Math.tan(45 * Math.PI / 360) / Math.max(1, t);
|
|
2530
2614
|
}
|
|
2531
|
-
function
|
|
2615
|
+
function dn(e) {
|
|
2532
2616
|
let t = (t) => +!!e.has(t);
|
|
2533
2617
|
return [
|
|
2534
2618
|
t("KeyD") - t("KeyA") + t("ArrowRight") - t("ArrowLeft"),
|
|
@@ -2536,10 +2620,10 @@ function en(e) {
|
|
|
2536
2620
|
t("KeyE") - t("KeyQ")
|
|
2537
2621
|
];
|
|
2538
2622
|
}
|
|
2539
|
-
function
|
|
2540
|
-
return
|
|
2623
|
+
function fn(e, t, n, r, i = J) {
|
|
2624
|
+
return rn(e, t) ? t : X(nn(e, t, 1 - Math.exp(-n / ln)), r, i);
|
|
2541
2625
|
}
|
|
2542
|
-
var
|
|
2626
|
+
var pn = class {
|
|
2543
2627
|
#e;
|
|
2544
2628
|
#t;
|
|
2545
2629
|
#n;
|
|
@@ -2556,7 +2640,7 @@ var nn = class {
|
|
|
2556
2640
|
#p = /* @__PURE__ */ new Set();
|
|
2557
2641
|
#m;
|
|
2558
2642
|
#h = null;
|
|
2559
|
-
constructor(e, t, n, r, i =
|
|
2643
|
+
constructor(e, t, n, r, i = J) {
|
|
2560
2644
|
this.#e = e, this.#t = t, this.#n = n, this.#r = i, this.#d = this.#E(r), this.#f = this.#d, this.#m = t.onFrame(this.#T);
|
|
2561
2645
|
let a = this.#i.signal;
|
|
2562
2646
|
e.addEventListener("pointerdown", this.#g, { signal: a }), e.addEventListener("pointermove", this.#_, { signal: a });
|
|
@@ -2577,7 +2661,7 @@ var nn = class {
|
|
|
2577
2661
|
return this.#p.add(e), () => this.#p.delete(e);
|
|
2578
2662
|
}
|
|
2579
2663
|
moveTo(e, t) {
|
|
2580
|
-
let n = this.#d, r = Math.min(n.dist,
|
|
2664
|
+
let n = this.#d, r = Math.min(n.dist, Vt.dist);
|
|
2581
2665
|
this.#d = this.#E({
|
|
2582
2666
|
...n,
|
|
2583
2667
|
e,
|
|
@@ -2604,7 +2688,7 @@ var nn = class {
|
|
|
2604
2688
|
e.buttons & 6 || t && e.shiftKey ? $(this.#c, r, i) : t && $(this.#s, r, i);
|
|
2605
2689
|
} else if (n) {
|
|
2606
2690
|
let e = this.#C();
|
|
2607
|
-
$(this.#c, e.x - n.x, e.y - n.y), this.#l += (n.d - e.d) *
|
|
2691
|
+
$(this.#c, e.x - n.x, e.y - n.y), this.#l += (n.d - e.d) * sn;
|
|
2608
2692
|
} else $(this.#s, r, i);
|
|
2609
2693
|
this.#w();
|
|
2610
2694
|
};
|
|
@@ -2612,7 +2696,7 @@ var nn = class {
|
|
|
2612
2696
|
this.#a.delete(e.pointerId);
|
|
2613
2697
|
};
|
|
2614
2698
|
#y = (e) => {
|
|
2615
|
-
e.preventDefault(), this.#l += e.deltaY *
|
|
2699
|
+
e.preventDefault(), this.#l += e.deltaY * on, this.#w();
|
|
2616
2700
|
};
|
|
2617
2701
|
#b = (e) => {
|
|
2618
2702
|
e.code === "KeyF" && !e.repeat && (this.#u = !this.#u), this.#o.add(e.code), this.#u && this.#w();
|
|
@@ -2624,7 +2708,7 @@ var nn = class {
|
|
|
2624
2708
|
let t = await this.#t.pick(e.offsetX, e.offsetY);
|
|
2625
2709
|
if (!t || this.#i.signal.aborted) return;
|
|
2626
2710
|
let [n, r, i] = t;
|
|
2627
|
-
this.#d =
|
|
2711
|
+
this.#d = X(Qt(Z(this.#f), {
|
|
2628
2712
|
e: n,
|
|
2629
2713
|
n: r,
|
|
2630
2714
|
h: i
|
|
@@ -2647,43 +2731,43 @@ var nn = class {
|
|
|
2647
2731
|
this.#h = e;
|
|
2648
2732
|
let n = this.#d, [r, i] = this.#c;
|
|
2649
2733
|
if (r || i) {
|
|
2650
|
-
let e =
|
|
2651
|
-
n =
|
|
2734
|
+
let e = un(n.dist, this.#e.clientHeight);
|
|
2735
|
+
n = tn(n, -r * e, i * e);
|
|
2652
2736
|
}
|
|
2653
2737
|
let [a, o] = this.#s;
|
|
2654
2738
|
if (a || o) {
|
|
2655
|
-
let [e, t] = [n.yaw + a *
|
|
2656
|
-
n = this.#u ?
|
|
2739
|
+
let [e, t] = [n.yaw + a * an, n.pitch - o * an];
|
|
2740
|
+
n = this.#u ? $t(n, e, t, this.#r) : X({
|
|
2657
2741
|
...n,
|
|
2658
2742
|
yaw: e,
|
|
2659
2743
|
pitch: t
|
|
2660
2744
|
}, void 0, this.#r);
|
|
2661
2745
|
}
|
|
2662
|
-
this.#l && (n =
|
|
2746
|
+
this.#l && (n = X({
|
|
2663
2747
|
...n,
|
|
2664
2748
|
dist: n.dist * Math.exp(this.#l)
|
|
2665
2749
|
}, void 0, this.#r)), this.#c = [0, 0], this.#s = [0, 0], this.#l = 0;
|
|
2666
|
-
let [s, c, l] =
|
|
2750
|
+
let [s, c, l] = dn(this.#o), u = this.#u && (s !== 0 || l !== 0 || c !== 0);
|
|
2667
2751
|
if (u) {
|
|
2668
|
-
let e =
|
|
2669
|
-
n =
|
|
2752
|
+
let e = cn * en(n) * t;
|
|
2753
|
+
n = Q(n, s * e, c * e, l * e);
|
|
2670
2754
|
}
|
|
2671
2755
|
let d = this.#f;
|
|
2672
2756
|
if (d !== n) {
|
|
2673
|
-
this.#d = n = this.#E(n), this.#f =
|
|
2757
|
+
this.#d = n = this.#E(n), this.#f = fn(d, n, t, this.#n, this.#r), this.#D();
|
|
2674
2758
|
for (let e of this.#p) e();
|
|
2675
2759
|
}
|
|
2676
2760
|
u || this.#f !== this.#d ? this.#w() : this.#h = null;
|
|
2677
2761
|
};
|
|
2678
2762
|
#E(e) {
|
|
2679
|
-
return
|
|
2763
|
+
return X(e, this.#n, this.#r);
|
|
2680
2764
|
}
|
|
2681
2765
|
#D() {
|
|
2682
|
-
this.#t.setCamera(
|
|
2766
|
+
this.#t.setCamera(Xt(this.#f));
|
|
2683
2767
|
}
|
|
2684
2768
|
};
|
|
2685
2769
|
function $(e, t, n) {
|
|
2686
2770
|
e[0] += t, e[1] += n;
|
|
2687
2771
|
}
|
|
2688
2772
|
//#endregion
|
|
2689
|
-
export { ae as S,
|
|
2773
|
+
export { ae as S, rn as _, Z as a, ht as b, Q as c, $t as d, Qt as f, Zt as g, qt as h, nn as i, Jt as l, tn as m, Bt as n, X as o, Kt as p, J as r, Vt as s, pn as t, en as u, Xt as v, Ue as x, mt as y };
|