cubing 0.27.0 → 0.28.2
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/README.md +3 -1
- package/dist/esm/.DS_Store +0 -0
- package/dist/esm/alg/index.js +4 -4
- package/dist/esm/bluetooth/index.js +228 -92
- package/dist/esm/bluetooth/index.js.map +3 -3
- package/dist/esm/{chunk-WQK6XWML.js → chunk-2IZUSAXQ.js} +2 -2
- package/dist/esm/{chunk-WQK6XWML.js.map → chunk-2IZUSAXQ.js.map} +1 -1
- package/dist/esm/{chunk-VY7VF4MA.js → chunk-5744RHHG.js} +145 -58
- package/dist/esm/chunk-5744RHHG.js.map +7 -0
- package/dist/esm/{chunk-KJYODR27.js → chunk-76H7SSCY.js} +28 -12
- package/dist/esm/{chunk-KJYODR27.js.map → chunk-76H7SSCY.js.map} +1 -1
- package/dist/esm/chunk-76UZ2QTB.js +1137 -0
- package/dist/esm/chunk-76UZ2QTB.js.map +7 -0
- package/dist/esm/{chunk-LNUPGLIU.js → chunk-D4YYXJDB.js} +175 -72
- package/dist/esm/{chunk-LNUPGLIU.js.map → chunk-D4YYXJDB.js.map} +3 -3
- package/dist/esm/{chunk-3Y4PK4XI.js → chunk-FEIKQ7FV.js} +6 -6
- package/dist/esm/chunk-FEIKQ7FV.js.map +7 -0
- package/dist/esm/{chunk-HIMSRIID.js → chunk-LOTZ7ZO7.js} +8 -4
- package/dist/esm/{chunk-HIMSRIID.js.map → chunk-LOTZ7ZO7.js.map} +1 -1
- package/dist/esm/{chunk-YBDBUTYE.js → chunk-OX6O2ZO5.js} +1 -1
- package/dist/esm/{chunk-YBDBUTYE.js.map → chunk-OX6O2ZO5.js.map} +1 -1
- package/dist/esm/{chunk-NQORDEXF.js → chunk-PCR6JT2W.js} +466 -322
- package/dist/esm/chunk-PCR6JT2W.js.map +7 -0
- package/dist/esm/{chunk-AU3UW5N4.js → chunk-PTUPP5AW.js} +22 -8
- package/dist/esm/{chunk-AU3UW5N4.js.map → chunk-PTUPP5AW.js.map} +1 -1
- package/dist/esm/{chunk-BEXHMXCT.js → chunk-RHC3DIN3.js} +1 -1
- package/dist/esm/{chunk-BEXHMXCT.js.map → chunk-RHC3DIN3.js.map} +1 -1
- package/dist/esm/{chunk-DSAZCGT2.js → chunk-RTFKKZPH.js} +22 -13
- package/dist/esm/{chunk-DSAZCGT2.js.map → chunk-RTFKKZPH.js.map} +2 -2
- package/dist/esm/{chunk-MGJA5U5O.js → chunk-SBZRVSPK.js} +1 -12
- package/dist/esm/{chunk-MGJA5U5O.js.map → chunk-SBZRVSPK.js.map} +0 -0
- package/dist/esm/{chunk-VYMKSHDI.js → chunk-TX2AQ4XW.js} +35 -13
- package/dist/esm/{chunk-VYMKSHDI.js.map → chunk-TX2AQ4XW.js.map} +2 -2
- package/dist/esm/{chunk-NYAPGKCW.js → chunk-WXCNEGW3.js} +10 -4
- package/dist/esm/{chunk-NYAPGKCW.js.map → chunk-WXCNEGW3.js.map} +1 -1
- package/dist/esm/{chunk-GBMX6FHY.js → chunk-ZB3P5AZN.js} +1 -1
- package/dist/esm/{chunk-GBMX6FHY.js.map → chunk-ZB3P5AZN.js.map} +1 -1
- package/dist/esm/kpuzzle/index.js +3 -3
- package/dist/esm/notation/index.js +3 -3
- package/dist/esm/protocol/index.js +5 -5
- package/dist/esm/puzzle-geometry/index.js +4570 -15
- package/dist/esm/puzzle-geometry/index.js.map +4 -4
- package/dist/esm/puzzles/index.js +5 -5
- package/dist/esm/{puzzles-dynamic-3x3x3-NB2PEZTV.js → puzzles-dynamic-3x3x3-KIG5A6QR.js} +2 -2
- package/dist/esm/{puzzles-dynamic-3x3x3-NB2PEZTV.js.map → puzzles-dynamic-3x3x3-KIG5A6QR.js.map} +0 -0
- package/dist/esm/puzzles-dynamic-4x4x4-PEDAPUZK.js +126 -0
- package/dist/esm/puzzles-dynamic-4x4x4-PEDAPUZK.js.map +7 -0
- package/dist/esm/{puzzles-dynamic-side-events-HOXBZYWI.js → puzzles-dynamic-side-events-5C7LMBWX.js} +2 -2
- package/dist/esm/{puzzles-dynamic-side-events-HOXBZYWI.js.map → puzzles-dynamic-side-events-5C7LMBWX.js.map} +1 -1
- package/dist/esm/{puzzles-dynamic-unofficial-MGVOFUDR.js → puzzles-dynamic-unofficial-WWJ4NJMX.js} +2 -2
- package/dist/esm/{puzzles-dynamic-unofficial-MGVOFUDR.js.map → puzzles-dynamic-unofficial-WWJ4NJMX.js.map} +1 -1
- package/dist/esm/scramble/index.js +6 -6
- package/dist/esm/search/index.js +11 -11
- package/dist/esm/{search-dynamic-sgs-side-events-4UF3XJRB.js → search-dynamic-sgs-side-events-X62KI7ZV.js} +37 -21
- package/dist/esm/search-dynamic-sgs-side-events-X62KI7ZV.js.map +7 -0
- package/dist/esm/{search-dynamic-sgs-unofficial-ZEUVDMBT.js → search-dynamic-sgs-unofficial-YAPJYTMF.js} +35 -14
- package/dist/esm/{search-dynamic-sgs-unofficial-ZEUVDMBT.js.map → search-dynamic-sgs-unofficial-YAPJYTMF.js.map} +2 -2
- package/dist/esm/{search-dynamic-solve-3x3x3-K4TG7P3X.js → search-dynamic-solve-3x3x3-7XZTYQMO.js} +795 -142
- package/dist/esm/{search-dynamic-solve-3x3x3-K4TG7P3X.js.map → search-dynamic-solve-3x3x3-7XZTYQMO.js.map} +1 -1
- package/dist/esm/{search-dynamic-solve-4x4x4-FKEWH5MW.js → search-dynamic-solve-4x4x4-5HST67LZ.js} +135 -29
- package/dist/esm/{search-dynamic-solve-4x4x4-FKEWH5MW.js.map → search-dynamic-solve-4x4x4-5HST67LZ.js.map} +1 -1
- package/dist/esm/{search-dynamic-solve-fto-WROONLZS.js → search-dynamic-solve-fto-4LI23P6K.js} +253 -69
- package/dist/esm/{search-dynamic-solve-fto-WROONLZS.js.map → search-dynamic-solve-fto-4LI23P6K.js.map} +2 -2
- package/dist/esm/{search-dynamic-solve-kilominx-JVBOIWI2.js → search-dynamic-solve-kilominx-PIS3T2P4.js} +32 -8
- package/dist/esm/{search-dynamic-solve-kilominx-JVBOIWI2.js.map → search-dynamic-solve-kilominx-PIS3T2P4.js.map} +2 -2
- package/dist/esm/{search-dynamic-solve-master_tetraminx-3R2CJUKW.js → search-dynamic-solve-master_tetraminx-UB32C7MM.js} +111 -42
- package/dist/esm/{search-dynamic-solve-master_tetraminx-3R2CJUKW.js.map → search-dynamic-solve-master_tetraminx-UB32C7MM.js.map} +2 -2
- package/dist/esm/{search-dynamic-solve-sq1-RS5HN6AH.js → search-dynamic-solve-sq1-HA72TYF2.js} +54 -9
- package/dist/esm/{search-dynamic-solve-sq1-RS5HN6AH.js.map → search-dynamic-solve-sq1-HA72TYF2.js.map} +2 -2
- package/dist/esm/search-worker-inside-generated-string-HMA547DJ.js +3886 -0
- package/dist/esm/search-worker-inside-generated-string-HMA547DJ.js.map +7 -0
- package/dist/esm/{search-worker-js-entry-NTV7KFZ5.js → search-worker-js-entry-3QMPUE4B.js} +149 -55
- package/dist/esm/search-worker-js-entry-3QMPUE4B.js.map +7 -0
- package/dist/esm/{search-worker-ts-entry-EUKJTYA6.js → search-worker-ts-entry-3RHWJNVQ.js} +6 -6
- package/dist/esm/{search-worker-ts-entry-EUKJTYA6.js.map → search-worker-ts-entry-3RHWJNVQ.js.map} +1 -1
- package/dist/esm/stream/index.js +12 -8
- package/dist/esm/stream/index.js.map +1 -1
- package/dist/esm/twisty/index.js +1186 -1533
- package/dist/esm/twisty/index.js.map +4 -4
- package/dist/esm/{twisty-dynamic-3d-UJR5FP6R.js → twisty-dynamic-3d-2KRJEHAN.js} +358 -146
- package/dist/esm/twisty-dynamic-3d-2KRJEHAN.js.map +7 -0
- package/dist/types/{Alg-1b229e63.d.ts → Alg-137fb0d5.d.ts} +53 -46
- package/dist/types/{KState-7a536c23.d.ts → KState-d5f04c9a.d.ts} +1 -1
- package/dist/types/{TwizzleLink-0fbaf9bd.d.ts → TwizzleLink-43d94aca.d.ts} +57 -21
- package/dist/types/alg/index.d.ts +12 -8
- package/dist/types/bluetooth/index.d.ts +4 -4
- package/dist/types/{bluetooth-puzzle-7065b808.d.ts → bluetooth-puzzle-7e1a2576.d.ts} +9 -9
- package/dist/types/kpuzzle/index.d.ts +2 -2
- package/dist/types/notation/index.d.ts +1 -1
- package/dist/types/{outside-f12ca41a.d.ts → outside-f83e819a.d.ts} +2 -2
- package/dist/types/parseAlg-a28f7568.d.ts +9 -0
- package/dist/types/protocol/index.d.ts +2 -2
- package/dist/types/puzzle-geometry/index.d.ts +3 -3
- package/dist/types/puzzles/index.d.ts +5 -5
- package/dist/types/scramble/index.d.ts +3 -3
- package/dist/types/search/index.d.ts +3 -3
- package/dist/types/stream/index.d.ts +5 -5
- package/dist/types/twisty/index.d.ts +13 -6
- package/package.json +32 -28
- package/dist/esm/chunk-3Y4PK4XI.js.map +0 -7
- package/dist/esm/chunk-NQORDEXF.js.map +0 -7
- package/dist/esm/chunk-NS5XT5ZV.js +0 -4386
- package/dist/esm/chunk-NS5XT5ZV.js.map +0 -7
- package/dist/esm/chunk-RECTK3R2.js +0 -342
- package/dist/esm/chunk-RECTK3R2.js.map +0 -7
- package/dist/esm/chunk-VY7VF4MA.js.map +0 -7
- package/dist/esm/search-dynamic-sgs-side-events-4UF3XJRB.js.map +0 -7
- package/dist/esm/search-worker-inside-generated-string-KTF5N656.js +0 -3768
- package/dist/esm/search-worker-inside-generated-string-KTF5N656.js.map +0 -7
- package/dist/esm/search-worker-js-entry-NTV7KFZ5.js.map +0 -7
- package/dist/esm/twisty-dynamic-3d-UJR5FP6R.js.map +0 -7
- package/dist/types/parse-7cf1a92b.d.ts +0 -9
|
@@ -0,0 +1,1137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
from
|
|
3
|
+
} from "./chunk-OX6O2ZO5.js";
|
|
4
|
+
|
|
5
|
+
// src/cubing/twisty/debug.ts
|
|
6
|
+
var twistyDebugGlobals = {
|
|
7
|
+
animateRaiseHintFacelets: true,
|
|
8
|
+
shareAllNewRenderers: "auto",
|
|
9
|
+
showRenderStats: false
|
|
10
|
+
};
|
|
11
|
+
function setTwistyDebug(options) {
|
|
12
|
+
for (const [key, value] of Object.entries(options)) {
|
|
13
|
+
if (key in twistyDebugGlobals) {
|
|
14
|
+
twistyDebugGlobals[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/cubing/twisty/model/PromiseFreshener.ts
|
|
20
|
+
var StaleDropper = class {
|
|
21
|
+
#latestAssignedIdx = 0;
|
|
22
|
+
#latestResolvedIdx = 0;
|
|
23
|
+
queue(p) {
|
|
24
|
+
return new Promise(async (resolve, reject) => {
|
|
25
|
+
try {
|
|
26
|
+
const idx = ++this.#latestAssignedIdx;
|
|
27
|
+
const result = await p;
|
|
28
|
+
if (idx > this.#latestResolvedIdx) {
|
|
29
|
+
this.#latestResolvedIdx = idx;
|
|
30
|
+
resolve(result);
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/cubing/twisty/model/props/TwistyProp.ts
|
|
40
|
+
var globalSourceGeneration = 0;
|
|
41
|
+
var TwistyPropParent = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.#children = /* @__PURE__ */ new Set();
|
|
44
|
+
this.lastSourceGeneration = 0;
|
|
45
|
+
this.#rawListeners = /* @__PURE__ */ new Set();
|
|
46
|
+
this.#rawDispatchPending = false;
|
|
47
|
+
this.#freshListeners = /* @__PURE__ */ new Map();
|
|
48
|
+
}
|
|
49
|
+
canReuse(v1, v2) {
|
|
50
|
+
return v1 === v2 || this.canReuseValue(v1, v2);
|
|
51
|
+
}
|
|
52
|
+
canReuseValue(_v1, _v2) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
debugGetChildren() {
|
|
56
|
+
return Array.from(this.#children.values());
|
|
57
|
+
}
|
|
58
|
+
#children;
|
|
59
|
+
addChild(child) {
|
|
60
|
+
this.#children.add(child);
|
|
61
|
+
}
|
|
62
|
+
removeChild(child) {
|
|
63
|
+
this.#children.delete(child);
|
|
64
|
+
}
|
|
65
|
+
markStale(sourceEvent) {
|
|
66
|
+
if (sourceEvent.detail.generation !== globalSourceGeneration) {
|
|
67
|
+
throw new Error("A TwistyProp was marked stale too late!");
|
|
68
|
+
}
|
|
69
|
+
if (this.lastSourceGeneration === sourceEvent.detail.generation) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.lastSourceGeneration = sourceEvent.detail.generation;
|
|
73
|
+
for (const child of this.#children) {
|
|
74
|
+
child.markStale(sourceEvent);
|
|
75
|
+
}
|
|
76
|
+
this.#scheduleRawDispatch();
|
|
77
|
+
}
|
|
78
|
+
#rawListeners;
|
|
79
|
+
addRawListener(listener, options) {
|
|
80
|
+
this.#rawListeners.add(listener);
|
|
81
|
+
if (options?.initial) {
|
|
82
|
+
listener();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
removeRawListener(listener) {
|
|
86
|
+
this.#rawListeners.delete(listener);
|
|
87
|
+
}
|
|
88
|
+
#scheduleRawDispatch() {
|
|
89
|
+
if (!this.#rawDispatchPending) {
|
|
90
|
+
this.#rawDispatchPending = true;
|
|
91
|
+
setTimeout(() => this.#dispatchRawListeners(), 0);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
#rawDispatchPending;
|
|
95
|
+
#dispatchRawListeners() {
|
|
96
|
+
if (!this.#rawDispatchPending) {
|
|
97
|
+
throw new Error("Invalid dispatch state!");
|
|
98
|
+
}
|
|
99
|
+
for (const listener of this.#rawListeners) {
|
|
100
|
+
listener();
|
|
101
|
+
}
|
|
102
|
+
this.#rawDispatchPending = false;
|
|
103
|
+
}
|
|
104
|
+
#freshListeners;
|
|
105
|
+
addFreshListener(listener) {
|
|
106
|
+
const staleDropper = new StaleDropper();
|
|
107
|
+
let lastResult = null;
|
|
108
|
+
const callback = async () => {
|
|
109
|
+
const result = await staleDropper.queue(this.get());
|
|
110
|
+
if (lastResult !== null && this.canReuse(lastResult, result)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
lastResult = result;
|
|
114
|
+
listener(result);
|
|
115
|
+
};
|
|
116
|
+
this.#freshListeners.set(listener, callback);
|
|
117
|
+
this.addRawListener(callback, { initial: true });
|
|
118
|
+
}
|
|
119
|
+
removeFreshListener(listener) {
|
|
120
|
+
this.removeRawListener(this.#freshListeners.get(listener));
|
|
121
|
+
this.#freshListeners.delete(listener);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var TwistyPropSource = class extends TwistyPropParent {
|
|
125
|
+
#value;
|
|
126
|
+
constructor(initialValue) {
|
|
127
|
+
super();
|
|
128
|
+
this.#value = from(() => this.getDefaultValue());
|
|
129
|
+
if (initialValue) {
|
|
130
|
+
this.#value = this.deriveFromPromiseOrValue(initialValue, this.#value);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
set(input) {
|
|
134
|
+
this.#value = this.deriveFromPromiseOrValue(input, this.#value);
|
|
135
|
+
const sourceEventDetail = {
|
|
136
|
+
sourceProp: this,
|
|
137
|
+
value: this.#value,
|
|
138
|
+
generation: ++globalSourceGeneration
|
|
139
|
+
};
|
|
140
|
+
this.markStale(
|
|
141
|
+
new CustomEvent("stale", {
|
|
142
|
+
detail: sourceEventDetail
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
async get() {
|
|
147
|
+
return this.#value;
|
|
148
|
+
}
|
|
149
|
+
async deriveFromPromiseOrValue(input, oldValuePromise) {
|
|
150
|
+
return this.derive(await input, oldValuePromise);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var SimpleTwistyPropSource = class extends TwistyPropSource {
|
|
154
|
+
derive(input) {
|
|
155
|
+
return input;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var NO_VALUE = Symbol("no value");
|
|
159
|
+
var TwistyPropDerived = class extends TwistyPropParent {
|
|
160
|
+
constructor(parents, userVisibleErrorTracker) {
|
|
161
|
+
super();
|
|
162
|
+
this.userVisibleErrorTracker = userVisibleErrorTracker;
|
|
163
|
+
this.#parents = parents;
|
|
164
|
+
for (const parent of Object.values(parents)) {
|
|
165
|
+
parent.addChild(this);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
#parents;
|
|
169
|
+
#cachedLastSuccessfulCalculation = null;
|
|
170
|
+
#cachedLatestGenerationCalculation = null;
|
|
171
|
+
async get() {
|
|
172
|
+
const generation = this.lastSourceGeneration;
|
|
173
|
+
if (this.#cachedLatestGenerationCalculation?.generation === generation) {
|
|
174
|
+
return this.#cachedLatestGenerationCalculation.output;
|
|
175
|
+
}
|
|
176
|
+
const latestGenerationCalculation = {
|
|
177
|
+
generation,
|
|
178
|
+
output: this.#cacheDerive(
|
|
179
|
+
this.#getParents(),
|
|
180
|
+
generation,
|
|
181
|
+
this.#cachedLastSuccessfulCalculation
|
|
182
|
+
)
|
|
183
|
+
};
|
|
184
|
+
this.#cachedLatestGenerationCalculation = latestGenerationCalculation;
|
|
185
|
+
this.userVisibleErrorTracker?.reset();
|
|
186
|
+
return latestGenerationCalculation.output;
|
|
187
|
+
}
|
|
188
|
+
async #getParents() {
|
|
189
|
+
const inputValuePromises = {};
|
|
190
|
+
for (const [key, parent] of Object.entries(this.#parents)) {
|
|
191
|
+
inputValuePromises[key] = parent.get();
|
|
192
|
+
}
|
|
193
|
+
const inputs = {};
|
|
194
|
+
for (const key in this.#parents) {
|
|
195
|
+
inputs[key] = await inputValuePromises[key];
|
|
196
|
+
}
|
|
197
|
+
return inputs;
|
|
198
|
+
}
|
|
199
|
+
async #cacheDerive(inputsPromise, generation, cachedLatestGenerationCalculation = null) {
|
|
200
|
+
const inputs = await inputsPromise;
|
|
201
|
+
const cache = (output) => {
|
|
202
|
+
this.#cachedLastSuccessfulCalculation = {
|
|
203
|
+
inputs,
|
|
204
|
+
output: Promise.resolve(output),
|
|
205
|
+
generation
|
|
206
|
+
};
|
|
207
|
+
return output;
|
|
208
|
+
};
|
|
209
|
+
if (!cachedLatestGenerationCalculation) {
|
|
210
|
+
return cache(await this.derive(inputs));
|
|
211
|
+
}
|
|
212
|
+
const cachedInputs = cachedLatestGenerationCalculation.inputs;
|
|
213
|
+
for (const key in this.#parents) {
|
|
214
|
+
const parent = this.#parents[key];
|
|
215
|
+
if (!parent.canReuse(inputs[key], cachedInputs[key])) {
|
|
216
|
+
return cache(await this.derive(inputs));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return cachedLatestGenerationCalculation.output;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var FreshListenerManager = class {
|
|
223
|
+
#disconnectionFunctions = [];
|
|
224
|
+
addListener(prop, listener) {
|
|
225
|
+
let disconnected = false;
|
|
226
|
+
const wrappedListener = (value) => {
|
|
227
|
+
if (disconnected) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
listener(value);
|
|
231
|
+
};
|
|
232
|
+
prop.addFreshListener(wrappedListener);
|
|
233
|
+
this.#disconnectionFunctions.push(() => {
|
|
234
|
+
prop.removeFreshListener(wrappedListener);
|
|
235
|
+
disconnected = true;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
addMultiListener3(props, listener) {
|
|
239
|
+
this.addMultiListener(props, listener);
|
|
240
|
+
}
|
|
241
|
+
addMultiListener(props, listener) {
|
|
242
|
+
let disconnected = false;
|
|
243
|
+
let initialIgnoresLeft = props.length - 1;
|
|
244
|
+
const wrappedListener = async (_) => {
|
|
245
|
+
if (initialIgnoresLeft > 0) {
|
|
246
|
+
initialIgnoresLeft--;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (disconnected) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const promises = props.map(
|
|
253
|
+
(prop) => prop.get()
|
|
254
|
+
);
|
|
255
|
+
const values = await Promise.all(promises);
|
|
256
|
+
listener(values);
|
|
257
|
+
};
|
|
258
|
+
for (const prop of props) {
|
|
259
|
+
prop.addFreshListener(wrappedListener);
|
|
260
|
+
}
|
|
261
|
+
this.#disconnectionFunctions.push(() => {
|
|
262
|
+
for (const prop of props) {
|
|
263
|
+
prop.removeFreshListener(wrappedListener);
|
|
264
|
+
}
|
|
265
|
+
disconnected = true;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
disconnect() {
|
|
269
|
+
for (const disconnectionFunction of this.#disconnectionFunctions) {
|
|
270
|
+
disconnectionFunction();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/cubing/twisty/controllers/RenderScheduler.ts
|
|
276
|
+
var RenderScheduler = class {
|
|
277
|
+
constructor(callback) {
|
|
278
|
+
this.callback = callback;
|
|
279
|
+
this.animFrameID = null;
|
|
280
|
+
this.animFrame = this.animFrameWrapper.bind(this);
|
|
281
|
+
}
|
|
282
|
+
requestIsPending() {
|
|
283
|
+
return !!this.animFrameID;
|
|
284
|
+
}
|
|
285
|
+
requestAnimFrame() {
|
|
286
|
+
if (!this.animFrameID) {
|
|
287
|
+
this.animFrameID = requestAnimationFrame(this.animFrame);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
cancelAnimFrame() {
|
|
291
|
+
if (this.animFrameID) {
|
|
292
|
+
cancelAnimationFrame(this.animFrameID);
|
|
293
|
+
this.animFrameID = 0;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
animFrameWrapper(timestamp) {
|
|
297
|
+
this.animFrameID = 0;
|
|
298
|
+
this.callback(timestamp);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/cubing/twisty/model/props/puzzle/display/HintFaceletProp.ts
|
|
303
|
+
var hintFaceletStyles = {
|
|
304
|
+
floating: true,
|
|
305
|
+
none: true
|
|
306
|
+
};
|
|
307
|
+
var HintFaceletProp = class extends SimpleTwistyPropSource {
|
|
308
|
+
getDefaultValue() {
|
|
309
|
+
return "auto";
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// src/cubing/twisty/views/3D/TAU.ts
|
|
314
|
+
var TAU = Math.PI * 2;
|
|
315
|
+
var DEGREES_PER_RADIAN = 360 / TAU;
|
|
316
|
+
|
|
317
|
+
// src/cubing/twisty/views/node-custom-element-shims.ts
|
|
318
|
+
var HTMLElementStub = class {
|
|
319
|
+
};
|
|
320
|
+
var HTMLElementShim;
|
|
321
|
+
if (globalThis.HTMLElement) {
|
|
322
|
+
HTMLElementShim = HTMLElement;
|
|
323
|
+
} else {
|
|
324
|
+
HTMLElementShim = HTMLElementStub;
|
|
325
|
+
}
|
|
326
|
+
var CustomElementsStub = class {
|
|
327
|
+
define() {
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var customElementsShim;
|
|
331
|
+
if (globalThis.customElements) {
|
|
332
|
+
customElementsShim = customElements;
|
|
333
|
+
} else {
|
|
334
|
+
customElementsShim = new CustomElementsStub();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/cubing/twisty/views/ManagedCustomElement.ts
|
|
338
|
+
var CSSSource = class {
|
|
339
|
+
constructor(sourceText) {
|
|
340
|
+
this.sourceText = sourceText;
|
|
341
|
+
}
|
|
342
|
+
getAsString() {
|
|
343
|
+
return this.sourceText;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var ManagedCustomElement = class extends HTMLElementShim {
|
|
347
|
+
constructor(options) {
|
|
348
|
+
super();
|
|
349
|
+
this.#cssSourceMap = /* @__PURE__ */ new Map();
|
|
350
|
+
this.shadow = this.attachShadow({ mode: options?.mode ?? "closed" });
|
|
351
|
+
this.contentWrapper = document.createElement("div");
|
|
352
|
+
this.contentWrapper.classList.add("wrapper");
|
|
353
|
+
this.shadow.appendChild(this.contentWrapper);
|
|
354
|
+
}
|
|
355
|
+
#cssSourceMap;
|
|
356
|
+
addCSS(cssSource) {
|
|
357
|
+
const existing = this.#cssSourceMap.get(cssSource);
|
|
358
|
+
if (existing) {
|
|
359
|
+
return existing;
|
|
360
|
+
}
|
|
361
|
+
const cssElem = document.createElement("style");
|
|
362
|
+
cssElem.textContent = cssSource.getAsString();
|
|
363
|
+
this.#cssSourceMap.set(cssSource, cssElem);
|
|
364
|
+
this.shadow.appendChild(cssElem);
|
|
365
|
+
return cssElem;
|
|
366
|
+
}
|
|
367
|
+
removeCSS(cssSource) {
|
|
368
|
+
const cssElem = this.#cssSourceMap.get(cssSource);
|
|
369
|
+
if (!cssElem) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this.shadow.removeChild(cssElem);
|
|
373
|
+
this.#cssSourceMap.delete(cssSource);
|
|
374
|
+
}
|
|
375
|
+
addElement(element) {
|
|
376
|
+
return this.contentWrapper.appendChild(element);
|
|
377
|
+
}
|
|
378
|
+
prependElement(element) {
|
|
379
|
+
this.contentWrapper.prepend(element);
|
|
380
|
+
}
|
|
381
|
+
removeElement(element) {
|
|
382
|
+
return this.contentWrapper.removeChild(element);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
customElementsShim.define(
|
|
386
|
+
"twisty-managed-custom-element",
|
|
387
|
+
ManagedCustomElement
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
// src/cubing/vendor/three/examples/jsm/libs/stats.modified.module.ts
|
|
391
|
+
var performance = globalThis.performance;
|
|
392
|
+
var Stats = class {
|
|
393
|
+
constructor() {
|
|
394
|
+
this.mode = 0;
|
|
395
|
+
this.dom = document.createElement("div");
|
|
396
|
+
this.beginTime = (performance || Date).now();
|
|
397
|
+
this.prevTime = this.beginTime;
|
|
398
|
+
this.frames = 0;
|
|
399
|
+
this.fpsPanel = this.addPanel(new StatsPanel("FPS", "#0ff", "#002"));
|
|
400
|
+
this.msPanel = this.addPanel(new StatsPanel("MS", "#0f0", "#020"));
|
|
401
|
+
this.memPanel = performance?.memory ? this.addPanel(new StatsPanel("MB", "#f08", "#201")) : null;
|
|
402
|
+
this.REVISION = 16;
|
|
403
|
+
this.dom.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";
|
|
404
|
+
this.dom.addEventListener(
|
|
405
|
+
"click",
|
|
406
|
+
(event) => {
|
|
407
|
+
event.preventDefault();
|
|
408
|
+
this.showPanel(++this.mode % this.dom.children.length);
|
|
409
|
+
},
|
|
410
|
+
false
|
|
411
|
+
);
|
|
412
|
+
this.showPanel(0);
|
|
413
|
+
}
|
|
414
|
+
addPanel(panel) {
|
|
415
|
+
this.dom.appendChild(panel.dom);
|
|
416
|
+
return panel;
|
|
417
|
+
}
|
|
418
|
+
showPanel(id) {
|
|
419
|
+
for (let i = 0; i < this.dom.children.length; i++) {
|
|
420
|
+
this.dom.children[i].style.display = i === id ? "block" : "none";
|
|
421
|
+
}
|
|
422
|
+
this.mode = id;
|
|
423
|
+
}
|
|
424
|
+
begin() {
|
|
425
|
+
this.beginTime = (performance || Date).now();
|
|
426
|
+
}
|
|
427
|
+
end() {
|
|
428
|
+
this.frames++;
|
|
429
|
+
const time = (performance || Date).now();
|
|
430
|
+
this.msPanel.update(time - this.beginTime, 200);
|
|
431
|
+
if (time >= this.prevTime + 1e3) {
|
|
432
|
+
this.fpsPanel.update(this.frames * 1e3 / (time - this.prevTime), 100);
|
|
433
|
+
this.prevTime = time;
|
|
434
|
+
this.frames = 0;
|
|
435
|
+
if (this.memPanel) {
|
|
436
|
+
const memory = performance.memory;
|
|
437
|
+
this.memPanel.update(
|
|
438
|
+
memory.usedJSHeapSize / 1048576,
|
|
439
|
+
memory.jsHeapSizeLimit / 1048576
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return time;
|
|
444
|
+
}
|
|
445
|
+
update() {
|
|
446
|
+
this.beginTime = this.end();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
var PR = Math.round(globalThis?.window?.devicePixelRatio ?? 1);
|
|
450
|
+
var WIDTH = 80 * PR;
|
|
451
|
+
var HEIGHT = 48 * PR;
|
|
452
|
+
var TEXT_X = 3 * PR;
|
|
453
|
+
var TEXT_Y = 2 * PR;
|
|
454
|
+
var GRAPH_X = 3 * PR;
|
|
455
|
+
var GRAPH_Y = 15 * PR;
|
|
456
|
+
var GRAPH_WIDTH = 74 * PR;
|
|
457
|
+
var GRAPH_HEIGHT = 30 * PR;
|
|
458
|
+
var StatsPanel = class {
|
|
459
|
+
constructor(name, fg, bg) {
|
|
460
|
+
this.name = name;
|
|
461
|
+
this.fg = fg;
|
|
462
|
+
this.bg = bg;
|
|
463
|
+
this.min = Infinity;
|
|
464
|
+
this.max = 0;
|
|
465
|
+
this.dom = document.createElement("canvas");
|
|
466
|
+
this.context = this.dom.getContext("2d");
|
|
467
|
+
this.dom.width = WIDTH;
|
|
468
|
+
this.dom.height = HEIGHT;
|
|
469
|
+
this.dom.style.cssText = "width:80px;height:48px";
|
|
470
|
+
this.context.font = `bold ${9 * PR}px Helvetica,Arial,sans-serif`;
|
|
471
|
+
this.context.textBaseline = "top";
|
|
472
|
+
this.context.fillStyle = bg;
|
|
473
|
+
this.context.fillRect(0, 0, WIDTH, HEIGHT);
|
|
474
|
+
this.context.fillStyle = fg;
|
|
475
|
+
this.context.fillText(name, TEXT_X, TEXT_Y);
|
|
476
|
+
this.context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
477
|
+
this.context.fillStyle = bg;
|
|
478
|
+
this.context.globalAlpha = 0.9;
|
|
479
|
+
this.context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
|
|
480
|
+
}
|
|
481
|
+
update(value, maxValue) {
|
|
482
|
+
this.min = Math.min(this.min, value);
|
|
483
|
+
this.max = Math.max(this.max, value);
|
|
484
|
+
this.context.fillStyle = this.bg;
|
|
485
|
+
this.context.globalAlpha = 1;
|
|
486
|
+
this.context.fillRect(0, 0, WIDTH, GRAPH_Y);
|
|
487
|
+
this.context.fillStyle = this.fg;
|
|
488
|
+
this.context.fillText(
|
|
489
|
+
Math.round(value) + " " + this.name + " (" + Math.round(this.min) + "-" + Math.round(this.max) + ")",
|
|
490
|
+
TEXT_X,
|
|
491
|
+
TEXT_Y
|
|
492
|
+
);
|
|
493
|
+
this.context.drawImage(
|
|
494
|
+
this.dom,
|
|
495
|
+
GRAPH_X + PR,
|
|
496
|
+
GRAPH_Y,
|
|
497
|
+
GRAPH_WIDTH - PR,
|
|
498
|
+
GRAPH_HEIGHT,
|
|
499
|
+
GRAPH_X,
|
|
500
|
+
GRAPH_Y,
|
|
501
|
+
GRAPH_WIDTH - PR,
|
|
502
|
+
GRAPH_HEIGHT
|
|
503
|
+
);
|
|
504
|
+
this.context.fillRect(
|
|
505
|
+
GRAPH_X + GRAPH_WIDTH - PR,
|
|
506
|
+
GRAPH_Y,
|
|
507
|
+
PR,
|
|
508
|
+
GRAPH_HEIGHT
|
|
509
|
+
);
|
|
510
|
+
this.context.fillStyle = this.bg;
|
|
511
|
+
this.context.globalAlpha = 0.9;
|
|
512
|
+
this.context.fillRect(
|
|
513
|
+
GRAPH_X + GRAPH_WIDTH - PR,
|
|
514
|
+
GRAPH_Y,
|
|
515
|
+
PR,
|
|
516
|
+
Math.round((1 - value / maxValue) * GRAPH_HEIGHT)
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// src/cubing/twisty/heavy-code-imports/3d.ts
|
|
522
|
+
var cachedConstructorProxy = null;
|
|
523
|
+
async function proxy3D() {
|
|
524
|
+
return cachedConstructorProxy ?? (cachedConstructorProxy = import("./twisty-dynamic-3d-2KRJEHAN.js"));
|
|
525
|
+
}
|
|
526
|
+
var THREEJS = from(
|
|
527
|
+
async () => (await proxy3D()).T3I
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
// src/cubing/twisty/views/canvas.ts
|
|
531
|
+
var globalPixelRatioOverride = null;
|
|
532
|
+
function pixelRatio() {
|
|
533
|
+
return globalPixelRatioOverride ?? (devicePixelRatio || 1);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// src/cubing/twisty/views/3D/Twisty3DVantage.css.ts
|
|
537
|
+
var twisty3DVantageCSS = new CSSSource(`
|
|
538
|
+
:host {
|
|
539
|
+
width: 384px;
|
|
540
|
+
height: 256px;
|
|
541
|
+
display: grid;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.wrapper {
|
|
545
|
+
width: 100%;
|
|
546
|
+
height: 100%;
|
|
547
|
+
display: grid;
|
|
548
|
+
overflow: hidden;
|
|
549
|
+
place-content: center;
|
|
550
|
+
contain: strict;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
.loading {
|
|
554
|
+
width: 4em;
|
|
555
|
+
height: 4em;
|
|
556
|
+
border-radius: 2.5em;
|
|
557
|
+
border: 0.5em solid rgba(0, 0, 0, 0);
|
|
558
|
+
border-top: 0.5em solid rgba(0, 0, 0, 0.7);
|
|
559
|
+
border-right: 0.5em solid rgba(0, 0, 0, 0.7);
|
|
560
|
+
animation: fade-in-delayed 4s, rotate 1s linear infinite;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
@keyframes fade-in-delayed {
|
|
564
|
+
0% { opacity: 0; }
|
|
565
|
+
25% {opacity: 0; }
|
|
566
|
+
100% { opacity: 1; }
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
@keyframes rotate {
|
|
570
|
+
from { transform: rotate(0deg); }
|
|
571
|
+
to { transform: rotate(360deg); }
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/* TODO: This is due to stats hack. Replace with \`canvas\`. */
|
|
575
|
+
.wrapper > canvas {
|
|
576
|
+
max-width: 100%;
|
|
577
|
+
max-height: 100%;
|
|
578
|
+
animation: fade-in 0.25s ease-in;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
@keyframes fade-in {
|
|
582
|
+
from { opacity: 0; }
|
|
583
|
+
to { opacity: 1; }
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.wrapper.invisible {
|
|
587
|
+
opacity: 0;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.wrapper.drag-input-enabled > canvas {
|
|
591
|
+
cursor: grab;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.wrapper.drag-input-enabled > canvas:active {
|
|
595
|
+
cursor: grabbing;
|
|
596
|
+
}
|
|
597
|
+
`);
|
|
598
|
+
|
|
599
|
+
// src/cubing/twisty/views/3D/DragTracker.ts
|
|
600
|
+
var MOVEMENT_EPSILON = 0.1;
|
|
601
|
+
var DragTracker = class extends EventTarget {
|
|
602
|
+
constructor(target) {
|
|
603
|
+
super();
|
|
604
|
+
this.target = target;
|
|
605
|
+
}
|
|
606
|
+
#dragInfoMap = /* @__PURE__ */ new Map();
|
|
607
|
+
start() {
|
|
608
|
+
this.addTargetListener("pointerdown", this.onPointerDown.bind(this));
|
|
609
|
+
this.addTargetListener("contextmenu", (e) => {
|
|
610
|
+
e.preventDefault();
|
|
611
|
+
});
|
|
612
|
+
this.addTargetListener("touchmove", (e) => e.preventDefault());
|
|
613
|
+
this.addTargetListener("dblclick", (e) => e.preventDefault());
|
|
614
|
+
}
|
|
615
|
+
stop() {
|
|
616
|
+
for (const [eventType, listener] of this.#targetListeners.entries()) {
|
|
617
|
+
this.target.removeEventListener(eventType, listener);
|
|
618
|
+
}
|
|
619
|
+
this.#targetListeners.clear();
|
|
620
|
+
this.#lazyListenersRegistered = false;
|
|
621
|
+
}
|
|
622
|
+
#targetListeners = /* @__PURE__ */ new Map();
|
|
623
|
+
addTargetListener(eventType, listener) {
|
|
624
|
+
if (!this.#targetListeners.has(eventType)) {
|
|
625
|
+
this.target.addEventListener(eventType, listener);
|
|
626
|
+
this.#targetListeners.set(eventType, listener);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
#lazyListenersRegistered = false;
|
|
630
|
+
#registerLazyListeners() {
|
|
631
|
+
if (this.#lazyListenersRegistered) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
this.addTargetListener("pointermove", this.onPointerMove.bind(this));
|
|
635
|
+
this.addTargetListener("pointerup", this.onPointerUp.bind(this));
|
|
636
|
+
this.#lazyListenersRegistered = true;
|
|
637
|
+
}
|
|
638
|
+
#clear(e) {
|
|
639
|
+
this.#dragInfoMap.delete(e.pointerId);
|
|
640
|
+
}
|
|
641
|
+
#trackDrag(e) {
|
|
642
|
+
const existing = this.#dragInfoMap.get(e.pointerId);
|
|
643
|
+
if (!existing) {
|
|
644
|
+
return { movementInfo: null, hasMoved: false };
|
|
645
|
+
}
|
|
646
|
+
let movementInfo;
|
|
647
|
+
if ((e.movementX ?? 0) !== 0 || (e.movementY ?? 0) !== 0) {
|
|
648
|
+
movementInfo = {
|
|
649
|
+
attachedInfo: existing.attachedInfo,
|
|
650
|
+
movementX: e.movementX,
|
|
651
|
+
movementY: e.movementY,
|
|
652
|
+
elapsedMs: e.timeStamp - existing.lastTimeStamp
|
|
653
|
+
};
|
|
654
|
+
} else {
|
|
655
|
+
movementInfo = {
|
|
656
|
+
attachedInfo: existing.attachedInfo,
|
|
657
|
+
movementX: e.clientX - existing.lastClientX,
|
|
658
|
+
movementY: e.clientY - existing.lastClientY,
|
|
659
|
+
elapsedMs: e.timeStamp - existing.lastTimeStamp
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
existing.lastClientX = e.clientX;
|
|
663
|
+
existing.lastClientY = e.clientY;
|
|
664
|
+
existing.lastTimeStamp = e.timeStamp;
|
|
665
|
+
if (Math.abs(movementInfo.movementX) < MOVEMENT_EPSILON && Math.abs(movementInfo.movementY) < MOVEMENT_EPSILON) {
|
|
666
|
+
return { movementInfo: null, hasMoved: existing.hasMoved };
|
|
667
|
+
} else {
|
|
668
|
+
existing.hasMoved = true;
|
|
669
|
+
return { movementInfo, hasMoved: existing.hasMoved };
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
onPointerDown(e) {
|
|
673
|
+
this.#registerLazyListeners();
|
|
674
|
+
const newDragInfo = {
|
|
675
|
+
attachedInfo: {},
|
|
676
|
+
hasMoved: false,
|
|
677
|
+
lastClientX: e.clientX,
|
|
678
|
+
lastClientY: e.clientY,
|
|
679
|
+
lastTimeStamp: e.timeStamp
|
|
680
|
+
};
|
|
681
|
+
this.#dragInfoMap.set(e.pointerId, newDragInfo);
|
|
682
|
+
this.target.setPointerCapture(e.pointerId);
|
|
683
|
+
}
|
|
684
|
+
onPointerMove(e) {
|
|
685
|
+
const movementInfo = this.#trackDrag(e).movementInfo;
|
|
686
|
+
if (movementInfo) {
|
|
687
|
+
e.preventDefault();
|
|
688
|
+
this.dispatchEvent(
|
|
689
|
+
new CustomEvent("move", {
|
|
690
|
+
detail: movementInfo
|
|
691
|
+
})
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
onPointerUp(e) {
|
|
696
|
+
const trackDragResult = this.#trackDrag(e);
|
|
697
|
+
const existing = this.#dragInfoMap.get(e.pointerId);
|
|
698
|
+
this.#clear(e);
|
|
699
|
+
this.target.releasePointerCapture(e.pointerId);
|
|
700
|
+
let event;
|
|
701
|
+
if (trackDragResult.hasMoved) {
|
|
702
|
+
event = new CustomEvent("up", {
|
|
703
|
+
detail: { attachedInfo: existing.attachedInfo }
|
|
704
|
+
});
|
|
705
|
+
} else {
|
|
706
|
+
const { altKey, ctrlKey, metaKey, shiftKey } = e;
|
|
707
|
+
event = new CustomEvent("press", {
|
|
708
|
+
detail: {
|
|
709
|
+
normalizedX: e.offsetX / this.target.offsetWidth * 2 - 1,
|
|
710
|
+
normalizedY: 1 - e.offsetY / this.target.offsetHeight * 2,
|
|
711
|
+
rightClick: !!(e.button & 2),
|
|
712
|
+
keys: {
|
|
713
|
+
altKey,
|
|
714
|
+
ctrlOrMetaKey: ctrlKey || metaKey,
|
|
715
|
+
shiftKey
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
this.dispatchEvent(event);
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// src/cubing/twisty/views/3D/RendererPool.ts
|
|
725
|
+
var renderers = [];
|
|
726
|
+
async function renderPooled(width, height, canvas, scene, camera) {
|
|
727
|
+
if (width === 0 || height === 0) {
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (renderers.length === 0) {
|
|
731
|
+
renderers.push(newRenderer());
|
|
732
|
+
}
|
|
733
|
+
const renderer = await renderers[0];
|
|
734
|
+
renderer.setSize(width, height);
|
|
735
|
+
renderer.render(scene, camera);
|
|
736
|
+
const context = canvas.getContext("2d");
|
|
737
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
738
|
+
context.drawImage(renderer.domElement, 0, 0);
|
|
739
|
+
}
|
|
740
|
+
async function newRenderer() {
|
|
741
|
+
const rendererConstructor = (await THREEJS).WebGLRenderer;
|
|
742
|
+
const renderer = new rendererConstructor({
|
|
743
|
+
antialias: true,
|
|
744
|
+
alpha: true
|
|
745
|
+
});
|
|
746
|
+
renderer.setPixelRatio(pixelRatio());
|
|
747
|
+
return renderer;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// src/cubing/twisty/views/3D/TwistyOrbitControls.ts
|
|
751
|
+
var INERTIA_DEFAULT = true;
|
|
752
|
+
var INERTIA_DURATION_MS = 500;
|
|
753
|
+
var INERTIA_TIMEOUT_MS = 50;
|
|
754
|
+
var VERTICAL_MOVEMENT_BASE_SCALE = 0.75;
|
|
755
|
+
function momentumScale(progress) {
|
|
756
|
+
return (Math.exp(1 - progress) - (1 - progress)) / (1 - Math.E) + 1;
|
|
757
|
+
}
|
|
758
|
+
var Inertia = class {
|
|
759
|
+
constructor(startTimestamp, momentumX, momentumY, callback) {
|
|
760
|
+
this.startTimestamp = startTimestamp;
|
|
761
|
+
this.momentumX = momentumX;
|
|
762
|
+
this.momentumY = momentumY;
|
|
763
|
+
this.callback = callback;
|
|
764
|
+
this.scheduler = new RenderScheduler(this.render.bind(this));
|
|
765
|
+
this.scheduler.requestAnimFrame();
|
|
766
|
+
this.lastTimestamp = startTimestamp;
|
|
767
|
+
}
|
|
768
|
+
render(now) {
|
|
769
|
+
const progressBefore = (this.lastTimestamp - this.startTimestamp) / INERTIA_DURATION_MS;
|
|
770
|
+
const progressAfter = Math.min(
|
|
771
|
+
1,
|
|
772
|
+
(now - this.startTimestamp) / INERTIA_DURATION_MS
|
|
773
|
+
);
|
|
774
|
+
if (progressBefore === 0 && progressAfter > INERTIA_TIMEOUT_MS / INERTIA_DURATION_MS) {
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const delta = momentumScale(progressAfter) - momentumScale(progressBefore);
|
|
778
|
+
this.callback(this.momentumX * delta * 1e3, this.momentumY * delta * 1e3);
|
|
779
|
+
if (progressAfter < 1) {
|
|
780
|
+
this.scheduler.requestAnimFrame();
|
|
781
|
+
}
|
|
782
|
+
this.lastTimestamp = now;
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
var TwistyOrbitControls = class {
|
|
786
|
+
constructor(model, mirror, canvas, dragTracker) {
|
|
787
|
+
this.model = model;
|
|
788
|
+
this.mirror = mirror;
|
|
789
|
+
this.canvas = canvas;
|
|
790
|
+
this.dragTracker = dragTracker;
|
|
791
|
+
this.experimentalInertia = INERTIA_DEFAULT;
|
|
792
|
+
this.onMovementBound = this.onMovement.bind(this);
|
|
793
|
+
this.experimentalHasBeenMoved = false;
|
|
794
|
+
this.dragTracker.addEventListener("move", this.onMove.bind(this));
|
|
795
|
+
this.dragTracker.addEventListener("up", this.onUp.bind(this));
|
|
796
|
+
}
|
|
797
|
+
temperMovement(f) {
|
|
798
|
+
return Math.sign(f) * Math.log(Math.abs(f * 10) + 1) / 6;
|
|
799
|
+
}
|
|
800
|
+
onMove(e) {
|
|
801
|
+
var _a;
|
|
802
|
+
(_a = e.detail).attachedInfo ?? (_a.attachedInfo = {});
|
|
803
|
+
const { temperedX, temperedY } = this.onMovement(
|
|
804
|
+
e.detail.movementX,
|
|
805
|
+
e.detail.movementY
|
|
806
|
+
);
|
|
807
|
+
const attachedInfo = e.detail.attachedInfo;
|
|
808
|
+
attachedInfo.lastTemperedX = temperedX * 10;
|
|
809
|
+
attachedInfo.lastTemperedY = temperedY * 10;
|
|
810
|
+
attachedInfo.timestamp = e.timeStamp;
|
|
811
|
+
}
|
|
812
|
+
onMovement(movementX, movementY) {
|
|
813
|
+
const scale = this.mirror ? -1 : 1;
|
|
814
|
+
const minDim = Math.min(this.canvas.offsetWidth, this.canvas.offsetHeight);
|
|
815
|
+
const temperedX = this.temperMovement(movementX / minDim);
|
|
816
|
+
const temperedY = this.temperMovement(
|
|
817
|
+
movementY / minDim * VERTICAL_MOVEMENT_BASE_SCALE
|
|
818
|
+
);
|
|
819
|
+
this.model.twistySceneModel.orbitCoordinatesRequest.set(
|
|
820
|
+
(async () => {
|
|
821
|
+
const prevCoords = await this.model.twistySceneModel.orbitCoordinates.get();
|
|
822
|
+
const newCoords = {
|
|
823
|
+
latitude: prevCoords.latitude + 2 * temperedY * DEGREES_PER_RADIAN * scale,
|
|
824
|
+
longitude: prevCoords.longitude - 2 * temperedX * DEGREES_PER_RADIAN
|
|
825
|
+
};
|
|
826
|
+
return newCoords;
|
|
827
|
+
})()
|
|
828
|
+
);
|
|
829
|
+
return { temperedX, temperedY };
|
|
830
|
+
}
|
|
831
|
+
onUp(e) {
|
|
832
|
+
e.preventDefault();
|
|
833
|
+
if ("lastTemperedX" in e.detail.attachedInfo && "lastTemperedY" in e.detail.attachedInfo && "timestamp" in e.detail.attachedInfo && e.timeStamp - e.detail.attachedInfo.timestamp < 60) {
|
|
834
|
+
new Inertia(
|
|
835
|
+
e.timeStamp,
|
|
836
|
+
e.detail.attachedInfo.lastTemperedX,
|
|
837
|
+
e.detail.attachedInfo.lastTemperedY,
|
|
838
|
+
this.onMovementBound
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
// src/cubing/twisty/views/3D/Twisty3DVantage.ts
|
|
845
|
+
async function setCameraFromOrbitCoordinates(camera, orbitCoordinates, backView = false) {
|
|
846
|
+
const spherical = new (await THREEJS).Spherical(
|
|
847
|
+
orbitCoordinates.distance,
|
|
848
|
+
(90 - (backView ? -1 : 1) * orbitCoordinates.latitude) / DEGREES_PER_RADIAN,
|
|
849
|
+
((backView ? 180 : 0) + orbitCoordinates.longitude) / DEGREES_PER_RADIAN
|
|
850
|
+
);
|
|
851
|
+
spherical.makeSafe();
|
|
852
|
+
camera.position.setFromSpherical(spherical);
|
|
853
|
+
camera.lookAt(0, 0, 0);
|
|
854
|
+
}
|
|
855
|
+
var dedicatedRenderersSoFar = 0;
|
|
856
|
+
var DEFAULT_MAX_DEDICATED_RENDERERS = 2;
|
|
857
|
+
var sharingRenderers = false;
|
|
858
|
+
function shareRenderer() {
|
|
859
|
+
if (twistyDebugGlobals.shareAllNewRenderers !== "auto") {
|
|
860
|
+
if (!twistyDebugGlobals.shareAllNewRenderers) {
|
|
861
|
+
dedicatedRenderersSoFar++;
|
|
862
|
+
}
|
|
863
|
+
return twistyDebugGlobals.shareAllNewRenderers !== "never";
|
|
864
|
+
}
|
|
865
|
+
if (dedicatedRenderersSoFar < DEFAULT_MAX_DEDICATED_RENDERERS) {
|
|
866
|
+
dedicatedRenderersSoFar++;
|
|
867
|
+
return false;
|
|
868
|
+
} else {
|
|
869
|
+
sharingRenderers = true;
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function haveStartedSharingRenderers() {
|
|
874
|
+
return sharingRenderers;
|
|
875
|
+
}
|
|
876
|
+
var Twisty3DVantage = class extends ManagedCustomElement {
|
|
877
|
+
constructor(model, scene, options) {
|
|
878
|
+
super();
|
|
879
|
+
this.model = model;
|
|
880
|
+
this.options = options;
|
|
881
|
+
this.scene = null;
|
|
882
|
+
this.stats = null;
|
|
883
|
+
this.rendererIsShared = shareRenderer();
|
|
884
|
+
this.loadingElement = null;
|
|
885
|
+
this.#onResizeStaleDropper = new StaleDropper();
|
|
886
|
+
this.#width = 0;
|
|
887
|
+
this.#height = 0;
|
|
888
|
+
this.#cachedRenderer = null;
|
|
889
|
+
this.#cachedCanvas = null;
|
|
890
|
+
this.#cachedDragTracker = null;
|
|
891
|
+
this.#cachedCamera = null;
|
|
892
|
+
this.#cachedOrbitControls = null;
|
|
893
|
+
this.#disconnectionFunctions = [];
|
|
894
|
+
this.#experimentalNextRenderFinishedCallback = null;
|
|
895
|
+
this.#scheduler = new RenderScheduler(this.render.bind(this));
|
|
896
|
+
this.scene = scene ?? null;
|
|
897
|
+
this.loadingElement = this.addElement(document.createElement("div"));
|
|
898
|
+
this.loadingElement.classList.add("loading");
|
|
899
|
+
if (twistyDebugGlobals.showRenderStats) {
|
|
900
|
+
this.stats = new Stats();
|
|
901
|
+
this.stats.dom.style.position = "absolute";
|
|
902
|
+
this.contentWrapper.appendChild(this.stats.dom);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
async connectedCallback() {
|
|
906
|
+
this.addCSS(twisty3DVantageCSS);
|
|
907
|
+
this.addElement((await this.canvasInfo()).canvas);
|
|
908
|
+
this.#onResize();
|
|
909
|
+
const observer = new ResizeObserver(this.#onResize.bind(this));
|
|
910
|
+
observer.observe(this.contentWrapper);
|
|
911
|
+
this.orbitControls();
|
|
912
|
+
this.#setupBasicPresses();
|
|
913
|
+
this.scheduleRender();
|
|
914
|
+
}
|
|
915
|
+
async #setupBasicPresses() {
|
|
916
|
+
const dragTracker = await this.#dragTracker();
|
|
917
|
+
dragTracker.addEventListener("press", async (e) => {
|
|
918
|
+
const movePressInput = await this.model.twistySceneModel.movePressInput.get();
|
|
919
|
+
if (movePressInput !== "basic") {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
this.dispatchEvent(
|
|
923
|
+
new CustomEvent("press", {
|
|
924
|
+
detail: {
|
|
925
|
+
pressInfo: e.detail,
|
|
926
|
+
cameraPromise: this.camera()
|
|
927
|
+
}
|
|
928
|
+
})
|
|
929
|
+
);
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
#onResizeStaleDropper;
|
|
933
|
+
async clearCanvas() {
|
|
934
|
+
if (this.rendererIsShared) {
|
|
935
|
+
const canvasInfo = await this.canvasInfo();
|
|
936
|
+
canvasInfo.context.clearRect(
|
|
937
|
+
0,
|
|
938
|
+
0,
|
|
939
|
+
canvasInfo.canvas.width,
|
|
940
|
+
canvasInfo.canvas.height
|
|
941
|
+
);
|
|
942
|
+
} else {
|
|
943
|
+
const renderer = await this.renderer();
|
|
944
|
+
const context = renderer.getContext();
|
|
945
|
+
context.clear(context.COLOR_BUFFER_BIT);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
#width;
|
|
949
|
+
#height;
|
|
950
|
+
async #onResize() {
|
|
951
|
+
const camera = await this.#onResizeStaleDropper.queue(this.camera());
|
|
952
|
+
const w = this.contentWrapper.clientWidth;
|
|
953
|
+
const h = this.contentWrapper.clientHeight;
|
|
954
|
+
this.#width = w;
|
|
955
|
+
this.#height = h;
|
|
956
|
+
const off = 0;
|
|
957
|
+
let yoff = 0;
|
|
958
|
+
let excess = 0;
|
|
959
|
+
if (h > w) {
|
|
960
|
+
excess = h - w;
|
|
961
|
+
yoff = -Math.floor(0.5 * excess);
|
|
962
|
+
}
|
|
963
|
+
camera.aspect = w / h;
|
|
964
|
+
camera.setViewOffset(w, h - excess, off, yoff, w, h);
|
|
965
|
+
camera.updateProjectionMatrix();
|
|
966
|
+
this.clearCanvas();
|
|
967
|
+
if (this.rendererIsShared) {
|
|
968
|
+
const canvasInfo = await this.canvasInfo();
|
|
969
|
+
canvasInfo.canvas.width = w * pixelRatio();
|
|
970
|
+
canvasInfo.canvas.height = h * pixelRatio();
|
|
971
|
+
canvasInfo.canvas.style.width = w.toString();
|
|
972
|
+
canvasInfo.canvas.style.height = h.toString();
|
|
973
|
+
} else {
|
|
974
|
+
const renderer = await this.renderer();
|
|
975
|
+
renderer.setSize(w, h, true);
|
|
976
|
+
}
|
|
977
|
+
this.scheduleRender();
|
|
978
|
+
}
|
|
979
|
+
#cachedRenderer;
|
|
980
|
+
async renderer() {
|
|
981
|
+
if (this.rendererIsShared) {
|
|
982
|
+
throw new Error("renderer expected to be shared.");
|
|
983
|
+
}
|
|
984
|
+
return this.#cachedRenderer ?? (this.#cachedRenderer = newRenderer());
|
|
985
|
+
}
|
|
986
|
+
#cachedCanvas;
|
|
987
|
+
async canvasInfo() {
|
|
988
|
+
return this.#cachedCanvas ?? (this.#cachedCanvas = (async () => {
|
|
989
|
+
let canvas;
|
|
990
|
+
if (this.rendererIsShared) {
|
|
991
|
+
canvas = this.addElement(document.createElement("canvas"));
|
|
992
|
+
} else {
|
|
993
|
+
const renderer = await this.renderer();
|
|
994
|
+
canvas = this.addElement(renderer.domElement);
|
|
995
|
+
}
|
|
996
|
+
this.loadingElement?.remove();
|
|
997
|
+
const context = canvas.getContext("2d");
|
|
998
|
+
return { canvas, context };
|
|
999
|
+
})());
|
|
1000
|
+
}
|
|
1001
|
+
#cachedDragTracker;
|
|
1002
|
+
async #dragTracker() {
|
|
1003
|
+
return this.#cachedDragTracker ?? (this.#cachedDragTracker = (async () => {
|
|
1004
|
+
const dragTracker = new DragTracker((await this.canvasInfo()).canvas);
|
|
1005
|
+
this.model?.twistySceneModel.dragInput.addFreshListener(
|
|
1006
|
+
(dragInputMode) => {
|
|
1007
|
+
let dragInputEnabled = false;
|
|
1008
|
+
switch (dragInputMode) {
|
|
1009
|
+
case "auto":
|
|
1010
|
+
dragTracker.start();
|
|
1011
|
+
dragInputEnabled = true;
|
|
1012
|
+
break;
|
|
1013
|
+
case "none":
|
|
1014
|
+
dragTracker.stop();
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
this.contentWrapper.classList.toggle(
|
|
1018
|
+
"drag-input-enabled",
|
|
1019
|
+
dragInputEnabled
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
);
|
|
1023
|
+
return dragTracker;
|
|
1024
|
+
})());
|
|
1025
|
+
}
|
|
1026
|
+
#cachedCamera;
|
|
1027
|
+
async camera() {
|
|
1028
|
+
return this.#cachedCamera ?? (this.#cachedCamera = (async () => {
|
|
1029
|
+
const camera = new (await THREEJS).PerspectiveCamera(
|
|
1030
|
+
20,
|
|
1031
|
+
1,
|
|
1032
|
+
0.1,
|
|
1033
|
+
20
|
|
1034
|
+
);
|
|
1035
|
+
camera.position.copy(
|
|
1036
|
+
new (await THREEJS).Vector3(2, 4, 4).multiplyScalar(
|
|
1037
|
+
this.options?.backView ? -1 : 1
|
|
1038
|
+
)
|
|
1039
|
+
);
|
|
1040
|
+
camera.lookAt(0, 0, 0);
|
|
1041
|
+
return camera;
|
|
1042
|
+
})());
|
|
1043
|
+
}
|
|
1044
|
+
#cachedOrbitControls;
|
|
1045
|
+
async orbitControls() {
|
|
1046
|
+
return this.#cachedOrbitControls ?? (this.#cachedOrbitControls = (async () => {
|
|
1047
|
+
const orbitControls = new TwistyOrbitControls(
|
|
1048
|
+
this.model,
|
|
1049
|
+
!!this.options?.backView,
|
|
1050
|
+
(await this.canvasInfo()).canvas,
|
|
1051
|
+
await this.#dragTracker()
|
|
1052
|
+
);
|
|
1053
|
+
if (this.model) {
|
|
1054
|
+
this.addListener(
|
|
1055
|
+
this.model.twistySceneModel.orbitCoordinates,
|
|
1056
|
+
async (orbitCoordinates) => {
|
|
1057
|
+
const camera = await this.camera();
|
|
1058
|
+
setCameraFromOrbitCoordinates(
|
|
1059
|
+
camera,
|
|
1060
|
+
orbitCoordinates,
|
|
1061
|
+
this.options?.backView
|
|
1062
|
+
);
|
|
1063
|
+
this.scheduleRender();
|
|
1064
|
+
}
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
return orbitControls;
|
|
1068
|
+
})());
|
|
1069
|
+
}
|
|
1070
|
+
addListener(prop, listener) {
|
|
1071
|
+
prop.addFreshListener(listener);
|
|
1072
|
+
this.#disconnectionFunctions.push(() => {
|
|
1073
|
+
prop.removeFreshListener(listener);
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
#disconnectionFunctions;
|
|
1077
|
+
disconnect() {
|
|
1078
|
+
for (const fn of this.#disconnectionFunctions) {
|
|
1079
|
+
fn();
|
|
1080
|
+
}
|
|
1081
|
+
this.#disconnectionFunctions = [];
|
|
1082
|
+
}
|
|
1083
|
+
#experimentalNextRenderFinishedCallback;
|
|
1084
|
+
experimentalNextRenderFinishedCallback(callback) {
|
|
1085
|
+
this.#experimentalNextRenderFinishedCallback = callback;
|
|
1086
|
+
}
|
|
1087
|
+
async render() {
|
|
1088
|
+
if (!this.scene) {
|
|
1089
|
+
throw new Error("Attempted to render without a scene");
|
|
1090
|
+
}
|
|
1091
|
+
this.stats?.begin();
|
|
1092
|
+
const [scene, camera, canvas] = await Promise.all([
|
|
1093
|
+
this.scene.scene(),
|
|
1094
|
+
this.camera(),
|
|
1095
|
+
this.canvasInfo()
|
|
1096
|
+
]);
|
|
1097
|
+
if (this.rendererIsShared) {
|
|
1098
|
+
renderPooled(this.#width, this.#height, canvas.canvas, scene, camera);
|
|
1099
|
+
} else {
|
|
1100
|
+
(await this.renderer()).render(scene, camera);
|
|
1101
|
+
}
|
|
1102
|
+
this.stats?.end();
|
|
1103
|
+
this.#experimentalNextRenderFinishedCallback?.();
|
|
1104
|
+
this.#experimentalNextRenderFinishedCallback = null;
|
|
1105
|
+
}
|
|
1106
|
+
#scheduler;
|
|
1107
|
+
scheduleRender() {
|
|
1108
|
+
this.#scheduler.requestAnimFrame();
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
customElementsShim.define("twisty-3d-vantage", Twisty3DVantage);
|
|
1112
|
+
|
|
1113
|
+
export {
|
|
1114
|
+
twistyDebugGlobals,
|
|
1115
|
+
setTwistyDebug,
|
|
1116
|
+
RenderScheduler,
|
|
1117
|
+
StaleDropper,
|
|
1118
|
+
TwistyPropSource,
|
|
1119
|
+
SimpleTwistyPropSource,
|
|
1120
|
+
NO_VALUE,
|
|
1121
|
+
TwistyPropDerived,
|
|
1122
|
+
FreshListenerManager,
|
|
1123
|
+
hintFaceletStyles,
|
|
1124
|
+
HintFaceletProp,
|
|
1125
|
+
TAU,
|
|
1126
|
+
DEGREES_PER_RADIAN,
|
|
1127
|
+
HTMLElementShim,
|
|
1128
|
+
customElementsShim,
|
|
1129
|
+
CSSSource,
|
|
1130
|
+
ManagedCustomElement,
|
|
1131
|
+
setCameraFromOrbitCoordinates,
|
|
1132
|
+
haveStartedSharingRenderers,
|
|
1133
|
+
Twisty3DVantage,
|
|
1134
|
+
proxy3D,
|
|
1135
|
+
THREEJS
|
|
1136
|
+
};
|
|
1137
|
+
//# sourceMappingURL=chunk-76UZ2QTB.js.map
|