@s25studio/sinth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4069 @@
1
+ /*! Sinth 1.0.0 (v48) · @s25studio/sinth@1.0.0 · https://unpkg.com/@s25studio/sinth@1.0.0
2
+ * Copyright (c) 2026 S25 Studio. Licensed, not sold — see LICENSE.md in the
3
+ * package or https://unpkg.com/@s25studio/sinth@1.0.0/LICENSE.md
4
+ *
5
+ * Bundles three.js addons and, via TTFLoader, opentype.js — both MIT. The
6
+ * script build three.min.js inlines three.js itself.
7
+ * Full notices: THIRD-PARTY-NOTICES.md in the package.
8
+ *
9
+ * Copyright (c) 2010-2026 three.js authors
10
+ * Copyright (c) Frederik De Bleser and other contributors (opentype.js)
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in
20
+ * all copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ * THE SOFTWARE. */
29
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./instanceTypes-zqDi1nZx.js";
30
+ import * as u from "three";
31
+ import { Box3 as d, BoxGeometry as f, Float32BufferAttribute as p, InstancedBufferGeometry as m, InstancedInterleavedBuffer as h, InterleavedBufferAttribute as g, Line3 as _, MathUtils as v, Matrix4 as y, Mesh as b, ShaderLib as x, ShaderMaterial as ee, Sphere as S, UniformsLib as C, UniformsUtils as w, Vector2 as te, Vector3 as T, Vector4 as ne, WireframeGeometry as re } from "three";
32
+ //#region node_modules/three/examples/jsm/lines/LineSegmentsGeometry.js
33
+ var ie = new d(), ae = new T(), oe = class extends m {
34
+ constructor() {
35
+ super(), this.isLineSegmentsGeometry = !0, this.type = "LineSegmentsGeometry", this.setIndex([
36
+ 0,
37
+ 2,
38
+ 1,
39
+ 2,
40
+ 3,
41
+ 1,
42
+ 2,
43
+ 4,
44
+ 3,
45
+ 4,
46
+ 5,
47
+ 3,
48
+ 4,
49
+ 6,
50
+ 5,
51
+ 6,
52
+ 7,
53
+ 5
54
+ ]), this.setAttribute("position", new p([
55
+ -1,
56
+ 2,
57
+ 0,
58
+ 1,
59
+ 2,
60
+ 0,
61
+ -1,
62
+ 1,
63
+ 0,
64
+ 1,
65
+ 1,
66
+ 0,
67
+ -1,
68
+ 0,
69
+ 0,
70
+ 1,
71
+ 0,
72
+ 0,
73
+ -1,
74
+ -1,
75
+ 0,
76
+ 1,
77
+ -1,
78
+ 0
79
+ ], 3)), this.setAttribute("uv", new p([
80
+ -1,
81
+ 2,
82
+ 1,
83
+ 2,
84
+ -1,
85
+ 1,
86
+ 1,
87
+ 1,
88
+ -1,
89
+ -1,
90
+ 1,
91
+ -1,
92
+ -1,
93
+ -2,
94
+ 1,
95
+ -2
96
+ ], 2));
97
+ }
98
+ applyMatrix4(e) {
99
+ let t = this.attributes.instanceStart, n = this.attributes.instanceEnd;
100
+ return t !== void 0 && (t.applyMatrix4(e), n.applyMatrix4(e), t.needsUpdate = !0), this.boundingBox !== null && this.computeBoundingBox(), this.boundingSphere !== null && this.computeBoundingSphere(), this;
101
+ }
102
+ setPositions(e) {
103
+ let t;
104
+ e instanceof Float32Array ? t = e : Array.isArray(e) && (t = new Float32Array(e));
105
+ let n = new h(t, 6, 1);
106
+ return this.setAttribute("instanceStart", new g(n, 3, 0)), this.setAttribute("instanceEnd", new g(n, 3, 3)), this.instanceCount = this.attributes.instanceStart.count, this.computeBoundingBox(), this.computeBoundingSphere(), this;
107
+ }
108
+ setColors(e) {
109
+ let t;
110
+ e instanceof Float32Array ? t = e : Array.isArray(e) && (t = new Float32Array(e));
111
+ let n = new h(t, 6, 1);
112
+ return this.setAttribute("instanceColorStart", new g(n, 3, 0)), this.setAttribute("instanceColorEnd", new g(n, 3, 3)), this;
113
+ }
114
+ fromWireframeGeometry(e) {
115
+ return this.setPositions(e.attributes.position.array), this;
116
+ }
117
+ fromEdgesGeometry(e) {
118
+ return this.setPositions(e.attributes.position.array), this;
119
+ }
120
+ fromMesh(e) {
121
+ return this.fromWireframeGeometry(new re(e.geometry)), this;
122
+ }
123
+ fromLineSegments(e) {
124
+ let t = e.geometry;
125
+ return this.setPositions(t.attributes.position.array), this;
126
+ }
127
+ computeBoundingBox() {
128
+ this.boundingBox === null && (this.boundingBox = new d());
129
+ let e = this.attributes.instanceStart, t = this.attributes.instanceEnd;
130
+ e !== void 0 && t !== void 0 && (this.boundingBox.setFromBufferAttribute(e), ie.setFromBufferAttribute(t), this.boundingBox.union(ie));
131
+ }
132
+ computeBoundingSphere() {
133
+ this.boundingSphere === null && (this.boundingSphere = new S()), this.boundingBox === null && this.computeBoundingBox();
134
+ let e = this.attributes.instanceStart, t = this.attributes.instanceEnd;
135
+ if (e !== void 0 && t !== void 0) {
136
+ let n = this.boundingSphere.center;
137
+ this.boundingBox.getCenter(n);
138
+ let r = 0;
139
+ for (let i = 0, a = e.count; i < a; i++) ae.fromBufferAttribute(e, i), r = Math.max(r, n.distanceToSquared(ae)), ae.fromBufferAttribute(t, i), r = Math.max(r, n.distanceToSquared(ae));
140
+ this.boundingSphere.radius = Math.sqrt(r), isNaN(this.boundingSphere.radius) && console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.", this);
141
+ }
142
+ }
143
+ toJSON() {}
144
+ };
145
+ C.line = {
146
+ worldUnits: { value: 1 },
147
+ linewidth: { value: 1 },
148
+ resolution: { value: new te(1, 1) },
149
+ dashOffset: { value: 0 },
150
+ dashScale: { value: 1 },
151
+ dashSize: { value: 1 },
152
+ gapSize: { value: 1 }
153
+ }, x.line = {
154
+ uniforms: w.merge([
155
+ C.common,
156
+ C.fog,
157
+ C.line
158
+ ]),
159
+ vertexShader: "\n #include <common>\n #include <color_pars_vertex>\n #include <fog_pars_vertex>\n #include <logdepthbuf_pars_vertex>\n #include <clipping_planes_pars_vertex>\n\n uniform float linewidth;\n uniform vec2 resolution;\n\n attribute vec3 instanceStart;\n attribute vec3 instanceEnd;\n\n attribute vec3 instanceColorStart;\n attribute vec3 instanceColorEnd;\n\n #ifdef WORLD_UNITS\n\n varying vec4 worldPos;\n varying vec3 worldStart;\n varying vec3 worldEnd;\n\n #ifdef USE_DASH\n\n varying vec2 vUv;\n\n #endif\n\n #else\n\n varying vec2 vUv;\n\n #endif\n\n #ifdef USE_DASH\n\n uniform float dashScale;\n attribute float instanceDistanceStart;\n attribute float instanceDistanceEnd;\n varying float vLineDistance;\n\n #endif\n\n void trimSegment( const in vec4 start, inout vec4 end ) {\n\n // trim end segment so it terminates between the camera plane and the near plane\n\n // conservative estimate of the near plane\n float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n float nearEstimate = - 0.5 * b / a;\n\n float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n end.xyz = mix( start.xyz, end.xyz, alpha );\n\n }\n\n void main() {\n\n #ifdef USE_COLOR\n\n vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n #endif\n\n #ifdef USE_DASH\n\n vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n vUv = uv;\n\n #endif\n\n float aspect = resolution.x / resolution.y;\n\n // camera space\n vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n #ifdef WORLD_UNITS\n\n worldStart = start.xyz;\n worldEnd = end.xyz;\n\n #else\n\n vUv = uv;\n\n #endif\n\n // special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n // but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n // perhaps there is a more elegant solution -- WestLangley\n\n bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n if ( perspective ) {\n\n if ( start.z < 0.0 && end.z >= 0.0 ) {\n\n trimSegment( start, end );\n\n } else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n trimSegment( end, start );\n\n }\n\n }\n\n // clip space\n vec4 clipStart = projectionMatrix * start;\n vec4 clipEnd = projectionMatrix * end;\n\n // ndc space\n vec3 ndcStart = clipStart.xyz / clipStart.w;\n vec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n // direction\n vec2 dir = ndcEnd.xy - ndcStart.xy;\n\n // account for clip-space aspect ratio\n dir.x *= aspect;\n dir = normalize( dir );\n\n #ifdef WORLD_UNITS\n\n vec3 worldDir = normalize( end.xyz - start.xyz );\n vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );\n vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );\n vec3 worldFwd = cross( worldDir, worldUp );\n worldPos = position.y < 0.5 ? start: end;\n\n // height offset\n float hw = linewidth * 0.5;\n worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;\n\n // don't extend the line if we're rendering dashes because we\n // won't be rendering the endcaps\n #ifndef USE_DASH\n\n // cap extension\n worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;\n\n // add width to the box\n worldPos.xyz += worldFwd * hw;\n\n // endcaps\n if ( position.y > 1.0 || position.y < 0.0 ) {\n\n worldPos.xyz -= worldFwd * 2.0 * hw;\n\n }\n\n #endif\n\n // project the worldpos\n vec4 clip = projectionMatrix * worldPos;\n\n // shift the depth of the projected points so the line\n // segments overlap neatly\n vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n clip.z = clipPose.z * clip.w;\n\n #else\n\n vec2 offset = vec2( dir.y, - dir.x );\n // undo aspect ratio adjustment\n dir.x /= aspect;\n offset.x /= aspect;\n\n // sign flip\n if ( position.x < 0.0 ) offset *= - 1.0;\n\n // endcaps\n if ( position.y < 0.0 ) {\n\n offset += - dir;\n\n } else if ( position.y > 1.0 ) {\n\n offset += dir;\n\n }\n\n // adjust for linewidth\n offset *= linewidth;\n\n // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n offset /= resolution.y;\n\n // select end\n vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n // back to clip space\n offset *= clip.w;\n\n clip.xy += offset;\n\n #endif\n\n gl_Position = clip;\n\n vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <fog_vertex>\n\n }\n ",
160
+ fragmentShader: "\n uniform vec3 diffuse;\n uniform float opacity;\n uniform float linewidth;\n\n #ifdef USE_DASH\n\n uniform float dashOffset;\n uniform float dashSize;\n uniform float gapSize;\n\n #endif\n\n varying float vLineDistance;\n\n #ifdef WORLD_UNITS\n\n varying vec4 worldPos;\n varying vec3 worldStart;\n varying vec3 worldEnd;\n\n #ifdef USE_DASH\n\n varying vec2 vUv;\n\n #endif\n\n #else\n\n varying vec2 vUv;\n\n #endif\n\n #include <common>\n #include <color_pars_fragment>\n #include <fog_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n #include <clipping_planes_pars_fragment>\n\n vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n float mua;\n float mub;\n\n vec3 p13 = p1 - p3;\n vec3 p43 = p4 - p3;\n\n vec3 p21 = p2 - p1;\n\n float d1343 = dot( p13, p43 );\n float d4321 = dot( p43, p21 );\n float d1321 = dot( p13, p21 );\n float d4343 = dot( p43, p43 );\n float d2121 = dot( p21, p21 );\n\n float denom = d2121 * d4343 - d4321 * d4321;\n\n float numer = d1343 * d4321 - d1321 * d4343;\n\n mua = numer / denom;\n mua = clamp( mua, 0.0, 1.0 );\n mub = ( d1343 + d4321 * ( mua ) ) / d4343;\n mub = clamp( mub, 0.0, 1.0 );\n\n return vec2( mua, mub );\n\n }\n\n void main() {\n\n float alpha = opacity;\n vec4 diffuseColor = vec4( diffuse, alpha );\n\n #include <clipping_planes_fragment>\n\n #ifdef USE_DASH\n\n if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n #endif\n\n #ifdef WORLD_UNITS\n\n // Find the closest points on the view ray and the line segment\n vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n vec3 lineDir = worldEnd - worldStart;\n vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n vec3 p1 = worldStart + lineDir * params.x;\n vec3 p2 = rayEnd * params.y;\n vec3 delta = p1 - p2;\n float len = length( delta );\n float norm = len / linewidth;\n\n #ifndef USE_DASH\n\n #ifdef USE_ALPHA_TO_COVERAGE\n\n float dnorm = fwidth( norm );\n alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n #else\n\n if ( norm > 0.5 ) {\n\n discard;\n\n }\n\n #endif\n\n #endif\n\n #else\n\n #ifdef USE_ALPHA_TO_COVERAGE\n\n // artifacts appear on some hardware if a derivative is taken within a conditional\n float a = vUv.x;\n float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n float len2 = a * a + b * b;\n float dlen = fwidth( len2 );\n\n if ( abs( vUv.y ) > 1.0 ) {\n\n alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n }\n\n #else\n\n if ( abs( vUv.y ) > 1.0 ) {\n\n float a = vUv.x;\n float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n float len2 = a * a + b * b;\n\n if ( len2 > 1.0 ) discard;\n\n }\n\n #endif\n\n #endif\n\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n\n gl_FragColor = vec4( diffuseColor.rgb, alpha );\n\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n\n }\n "
161
+ };
162
+ var E = class extends ee {
163
+ constructor(e) {
164
+ super({
165
+ type: "LineMaterial",
166
+ uniforms: w.clone(x.line.uniforms),
167
+ vertexShader: x.line.vertexShader,
168
+ fragmentShader: x.line.fragmentShader,
169
+ clipping: !0
170
+ }), this.isLineMaterial = !0, this.setValues(e);
171
+ }
172
+ get color() {
173
+ return this.uniforms.diffuse.value;
174
+ }
175
+ set color(e) {
176
+ this.uniforms.diffuse.value = e;
177
+ }
178
+ get worldUnits() {
179
+ return "WORLD_UNITS" in this.defines;
180
+ }
181
+ set worldUnits(e) {
182
+ e === !0 !== this.worldUnits && (this.needsUpdate = !0), e === !0 ? this.defines.WORLD_UNITS = "" : delete this.defines.WORLD_UNITS;
183
+ }
184
+ get linewidth() {
185
+ return this.uniforms.linewidth.value;
186
+ }
187
+ set linewidth(e) {
188
+ this.uniforms.linewidth && (this.uniforms.linewidth.value = e);
189
+ }
190
+ get dashed() {
191
+ return "USE_DASH" in this.defines;
192
+ }
193
+ set dashed(e) {
194
+ e === !0 !== this.dashed && (this.needsUpdate = !0), e === !0 ? this.defines.USE_DASH = "" : delete this.defines.USE_DASH;
195
+ }
196
+ get dashScale() {
197
+ return this.uniforms.dashScale.value;
198
+ }
199
+ set dashScale(e) {
200
+ this.uniforms.dashScale.value = e;
201
+ }
202
+ get dashSize() {
203
+ return this.uniforms.dashSize.value;
204
+ }
205
+ set dashSize(e) {
206
+ this.uniforms.dashSize.value = e;
207
+ }
208
+ get dashOffset() {
209
+ return this.uniforms.dashOffset.value;
210
+ }
211
+ set dashOffset(e) {
212
+ this.uniforms.dashOffset.value = e;
213
+ }
214
+ get gapSize() {
215
+ return this.uniforms.gapSize.value;
216
+ }
217
+ set gapSize(e) {
218
+ this.uniforms.gapSize.value = e;
219
+ }
220
+ get opacity() {
221
+ return this.uniforms.opacity.value;
222
+ }
223
+ set opacity(e) {
224
+ this.uniforms && (this.uniforms.opacity.value = e);
225
+ }
226
+ get resolution() {
227
+ return this.uniforms.resolution.value;
228
+ }
229
+ set resolution(e) {
230
+ this.uniforms.resolution.value.copy(e);
231
+ }
232
+ get alphaToCoverage() {
233
+ return "USE_ALPHA_TO_COVERAGE" in this.defines;
234
+ }
235
+ set alphaToCoverage(e) {
236
+ this.defines && (e === !0 !== this.alphaToCoverage && (this.needsUpdate = !0), e === !0 ? this.defines.USE_ALPHA_TO_COVERAGE = "" : delete this.defines.USE_ALPHA_TO_COVERAGE);
237
+ }
238
+ }, D = new ne(), se = new T(), ce = new T(), O = new ne(), k = new ne(), A = new ne(), le = new T(), ue = new y(), j = new _(), de = new T(), fe = new d(), pe = new S(), M = new ne(), N, P;
239
+ function me(e, t, n) {
240
+ return M.set(0, 0, -t, 1).applyMatrix4(e.projectionMatrix), M.multiplyScalar(1 / M.w), M.x = P / n.width, M.y = P / n.height, M.applyMatrix4(e.projectionMatrixInverse), M.multiplyScalar(1 / M.w), Math.abs(Math.max(M.x, M.y));
241
+ }
242
+ function he(e, t) {
243
+ let n = e.matrixWorld, r = e.geometry, i = r.attributes.instanceStart, a = r.attributes.instanceEnd, o = Math.min(r.instanceCount, i.count);
244
+ for (let r = 0, s = o; r < s; r++) {
245
+ j.start.fromBufferAttribute(i, r), j.end.fromBufferAttribute(a, r), j.applyMatrix4(n);
246
+ let o = new T(), s = new T();
247
+ N.distanceSqToSegment(j.start, j.end, s, o), s.distanceTo(o) < P * .5 && t.push({
248
+ point: s,
249
+ pointOnLine: o,
250
+ distance: N.origin.distanceTo(s),
251
+ object: e,
252
+ face: null,
253
+ faceIndex: r,
254
+ uv: null,
255
+ uv1: null
256
+ });
257
+ }
258
+ }
259
+ function ge(e, t, n) {
260
+ let r = t.projectionMatrix, i = e.material.resolution, a = e.matrixWorld, o = e.geometry, s = o.attributes.instanceStart, c = o.attributes.instanceEnd, l = Math.min(o.instanceCount, s.count), u = -t.near;
261
+ N.at(1, A), A.w = 1, A.applyMatrix4(t.matrixWorldInverse), A.applyMatrix4(r), A.multiplyScalar(1 / A.w), A.x *= i.x / 2, A.y *= i.y / 2, A.z = 0, le.copy(A), ue.multiplyMatrices(t.matrixWorldInverse, a);
262
+ for (let t = 0, o = l; t < o; t++) {
263
+ if (O.fromBufferAttribute(s, t), k.fromBufferAttribute(c, t), O.w = 1, k.w = 1, O.applyMatrix4(ue), k.applyMatrix4(ue), O.z > u && k.z > u) continue;
264
+ if (O.z > u) {
265
+ let e = O.z - k.z, t = (O.z - u) / e;
266
+ O.lerp(k, t);
267
+ } else if (k.z > u) {
268
+ let e = k.z - O.z, t = (k.z - u) / e;
269
+ k.lerp(O, t);
270
+ }
271
+ O.applyMatrix4(r), k.applyMatrix4(r), O.multiplyScalar(1 / O.w), k.multiplyScalar(1 / k.w), O.x *= i.x / 2, O.y *= i.y / 2, k.x *= i.x / 2, k.y *= i.y / 2, j.start.copy(O), j.start.z = 0, j.end.copy(k), j.end.z = 0;
272
+ let o = j.closestPointToPointParameter(le, !0);
273
+ j.at(o, de);
274
+ let l = v.lerp(O.z, k.z, o), d = l >= -1 && l <= 1, f = le.distanceTo(de) < P * .5;
275
+ if (d && f) {
276
+ j.start.fromBufferAttribute(s, t), j.end.fromBufferAttribute(c, t), j.start.applyMatrix4(a), j.end.applyMatrix4(a);
277
+ let r = new T(), i = new T();
278
+ N.distanceSqToSegment(j.start, j.end, i, r), n.push({
279
+ point: i,
280
+ pointOnLine: r,
281
+ distance: N.origin.distanceTo(i),
282
+ object: e,
283
+ face: null,
284
+ faceIndex: t,
285
+ uv: null,
286
+ uv1: null
287
+ });
288
+ }
289
+ }
290
+ }
291
+ var _e = class extends b {
292
+ constructor(e = new oe(), t = new E({ color: Math.random() * 16777215 })) {
293
+ super(e, t), this.isLineSegments2 = !0, this.type = "LineSegments2";
294
+ }
295
+ computeLineDistances() {
296
+ let e = this.geometry, t = e.attributes.instanceStart, n = e.attributes.instanceEnd, r = new Float32Array(2 * t.count);
297
+ for (let e = 0, i = 0, a = t.count; e < a; e++, i += 2) se.fromBufferAttribute(t, e), ce.fromBufferAttribute(n, e), r[i] = i === 0 ? 0 : r[i - 1], r[i + 1] = r[i] + se.distanceTo(ce);
298
+ let i = new h(r, 2, 1);
299
+ return e.setAttribute("instanceDistanceStart", new g(i, 1, 0)), e.setAttribute("instanceDistanceEnd", new g(i, 1, 1)), this;
300
+ }
301
+ raycast(e, t) {
302
+ let n = this.material.worldUnits, r = e.camera;
303
+ r === null && !n && console.error("LineSegments2: \"Raycaster.camera\" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.");
304
+ let i = e.params.Line2 === void 0 ? 0 : e.params.Line2.threshold || 0;
305
+ N = e.ray;
306
+ let a = this.matrixWorld, o = this.geometry, s = this.material;
307
+ P = s.linewidth + i, o.boundingSphere === null && o.computeBoundingSphere(), pe.copy(o.boundingSphere).applyMatrix4(a);
308
+ let c;
309
+ if (c = n ? P * .5 : me(r, Math.max(r.near, pe.distanceToPoint(N.origin)), s.resolution), pe.radius += c, N.intersectsSphere(pe) === !1) return;
310
+ o.boundingBox === null && o.computeBoundingBox(), fe.copy(o.boundingBox).applyMatrix4(a);
311
+ let l;
312
+ l = n ? P * .5 : me(r, Math.max(r.near, fe.distanceToPoint(N.origin)), s.resolution), fe.expandByScalar(l), N.intersectsBox(fe) !== !1 && (n ? he(this, t) : ge(this, r, t));
313
+ }
314
+ onBeforeRender(e) {
315
+ let t = this.material.uniforms;
316
+ t && t.resolution && (e.getViewport(D), this.material.uniforms.resolution.value.set(D.z, D.w));
317
+ }
318
+ }, F = {
319
+ renderer: {
320
+ pixelRatio: {
321
+ min: .75,
322
+ max: 2
323
+ },
324
+ maxPixelRatio: 2
325
+ },
326
+ distribution: { instanceLimit: {
327
+ min: 1,
328
+ max: Infinity
329
+ } },
330
+ camera: {
331
+ distance: {
332
+ min: .01,
333
+ max: 1e3
334
+ },
335
+ orbitDistanceFloor: 1,
336
+ orthographicScale: {
337
+ min: .1,
338
+ max: 1e3
339
+ },
340
+ orthographicFrustumScale: {
341
+ min: .01,
342
+ max: Infinity
343
+ },
344
+ focalLength: {
345
+ min: 8,
346
+ max: Infinity
347
+ },
348
+ perspectiveClip: {
349
+ near: .1,
350
+ far: 1e3
351
+ },
352
+ orthographicClip: {
353
+ near: -1e4,
354
+ far: 1e4
355
+ }
356
+ },
357
+ instance: {
358
+ dimension: {
359
+ min: .01,
360
+ max: Infinity
361
+ },
362
+ scaleMultiplier: {
363
+ min: .01,
364
+ max: Infinity
365
+ },
366
+ scaleVariationMultiplier: {
367
+ min: .35,
368
+ max: 6
369
+ },
370
+ assetScale: {
371
+ min: .01,
372
+ max: Infinity
373
+ },
374
+ aspectRatio: {
375
+ min: .01,
376
+ max: Infinity
377
+ },
378
+ cornerRadius: {
379
+ min: 0,
380
+ max: .5
381
+ }
382
+ },
383
+ text: {
384
+ lineHeight: {
385
+ min: .1,
386
+ max: Infinity
387
+ },
388
+ maxLineLength: {
389
+ min: 0,
390
+ max: Infinity
391
+ }
392
+ },
393
+ motion: {
394
+ ringOrbitFriction: {
395
+ min: 0,
396
+ max: 4
397
+ },
398
+ fadeDuration: {
399
+ min: 0,
400
+ max: Infinity
401
+ },
402
+ buildZoomStartScale: {
403
+ min: .01,
404
+ max: 10
405
+ },
406
+ easingStrength: {
407
+ min: .01,
408
+ max: Infinity
409
+ }
410
+ },
411
+ render: {
412
+ opacity: {
413
+ min: 0,
414
+ max: 1
415
+ },
416
+ nonNegativeIntensity: {
417
+ min: 0,
418
+ max: Infinity
419
+ },
420
+ materialFactor: {
421
+ min: 0,
422
+ max: 1
423
+ },
424
+ thickness: {
425
+ min: 0,
426
+ max: Infinity
427
+ },
428
+ lightElevation: {
429
+ min: -Math.PI / 2,
430
+ max: Math.PI / 2
431
+ }
432
+ }
433
+ };
434
+ function I(e, t) {
435
+ return typeof e == "number" && Number.isFinite(e) ? e : t;
436
+ }
437
+ function L(e, t, n) {
438
+ let r = I(e, t);
439
+ return Math.min(n.max, Math.max(n.min, r));
440
+ }
441
+ function ve(e, t = 24) {
442
+ let n = L(e, F.camera.focalLength.min, F.camera.focalLength);
443
+ return 2 * Math.atan(t / (2 * n)) * (180 / Math.PI);
444
+ }
445
+ function ye({ cameraDistance: e, cameraHeight: t, cameraFocalLength: n }) {
446
+ let r = ve(n) * (Math.PI / 180);
447
+ return 2 * L(Math.abs(e), F.camera.distance.min, F.camera.distance) * Math.tan(r / 2);
448
+ }
449
+ function be({ cameraDistance: e, cameraHeight: t, cameraFocalLength: n, referenceZoom: r, referenceFrustumSize: i }) {
450
+ let a = ye({
451
+ cameraDistance: e,
452
+ cameraHeight: t,
453
+ cameraFocalLength: n
454
+ });
455
+ return i * r / L(a, F.camera.orthographicFrustumScale.min, F.camera.orthographicFrustumScale);
456
+ }
457
+ //#endregion
458
+ //#region src/camera/createCameraCanvasControls.ts
459
+ var xe = 250, Se = .5, Ce = .25, we = 15, Te = 1.5, Ee = 3;
460
+ function De({ canvas: e, onZoom: t, onOrbit: n, onPan: r, onInteractionEnd: i }) {
461
+ let a = null, o = /* @__PURE__ */ new Map(), s = null, c = !1, l = !1, u = null, d = () => {
462
+ i && (u && clearTimeout(u), u = setTimeout(() => {
463
+ u = null, i?.();
464
+ }, xe));
465
+ }, f = (e) => Se * (e.shiftKey || c ? Ce : 1), p = () => {
466
+ if (o.size !== 2) return null;
467
+ let [e, t] = Array.from(o.values()), n = t.x - e.x, r = t.y - e.y;
468
+ return Math.sqrt(n * n + r * r);
469
+ }, m = (e) => {
470
+ if (e.preventDefault(), a) return;
471
+ d();
472
+ let i = f(e);
473
+ if (e.altKey) {
474
+ r(-e.deltaX * i, -e.deltaY * i);
475
+ return;
476
+ }
477
+ if (e.ctrlKey) {
478
+ n(e.deltaX * i * we, e.deltaY * i * we);
479
+ return;
480
+ }
481
+ t(e.deltaY * i);
482
+ }, h = (t) => {
483
+ if (l = !1, t.pointerType === "touch") {
484
+ t.preventDefault(), o.set(t.pointerId, {
485
+ x: t.clientX,
486
+ y: t.clientY
487
+ }), s = p(), e.setPointerCapture(t.pointerId), a = {
488
+ pointerId: t.pointerId,
489
+ lastX: t.clientX,
490
+ lastY: t.clientY,
491
+ buttonMask: 1,
492
+ panMultiplier: Ee
493
+ };
494
+ return;
495
+ }
496
+ t.button === 0 && (t.preventDefault(), a = {
497
+ pointerId: t.pointerId,
498
+ lastX: t.clientX,
499
+ lastY: t.clientY,
500
+ buttonMask: 1,
501
+ panMultiplier: Te
502
+ }, e.setPointerCapture(t.pointerId));
503
+ }, g = (e) => {
504
+ if (e.pointerType === "touch" && o.has(e.pointerId)) {
505
+ e.preventDefault(), o.set(e.pointerId, {
506
+ x: e.clientX,
507
+ y: e.clientY
508
+ });
509
+ let n = p();
510
+ if (n !== null && s !== null) {
511
+ t((s - n) * 1.4 * f(e)), s = n, l = !0;
512
+ return;
513
+ }
514
+ s = n;
515
+ }
516
+ if (a?.pointerId !== e.pointerId) return;
517
+ if ((e.buttons & a.buttonMask) === 0 && e.pointerType !== "touch") {
518
+ a = null;
519
+ return;
520
+ }
521
+ let r = e.clientX - a.lastX, i = e.clientY - a.lastY, c = f(e);
522
+ e.preventDefault(), a = {
523
+ ...a,
524
+ lastX: e.clientX,
525
+ lastY: e.clientY
526
+ }, n(r * c * a.panMultiplier, i * c * a.panMultiplier), l = !0;
527
+ }, _ = (t) => {
528
+ if (t.pointerType === "touch") {
529
+ o.delete(t.pointerId), s = p(), e.hasPointerCapture(t.pointerId) && e.releasePointerCapture(t.pointerId), o.size === 0 && l && (l = !1, i?.());
530
+ return;
531
+ }
532
+ a?.pointerId === t.pointerId && (a = null, e.hasPointerCapture(t.pointerId) && e.releasePointerCapture(t.pointerId), l && (l = !1, i?.()));
533
+ }, v = (e) => {
534
+ e.preventDefault();
535
+ }, y = (e) => {
536
+ e.key === "Shift" && (c = !0);
537
+ }, b = (e) => {
538
+ e.key === "Shift" && (c = !1);
539
+ }, x = () => {
540
+ c = !1;
541
+ };
542
+ return e.addEventListener("wheel", m, { passive: !1 }), e.addEventListener("pointerdown", h), e.addEventListener("pointermove", g), e.addEventListener("pointerup", _), e.addEventListener("pointercancel", _), e.addEventListener("lostpointercapture", _), e.addEventListener("contextmenu", v), window.addEventListener("keydown", y), window.addEventListener("keyup", b), window.addEventListener("blur", x), { dispose() {
543
+ u && clearTimeout(u), e.removeEventListener("wheel", m), e.removeEventListener("pointerdown", h), e.removeEventListener("pointermove", g), e.removeEventListener("pointerup", _), e.removeEventListener("pointercancel", _), e.removeEventListener("lostpointercapture", _), e.removeEventListener("contextmenu", v), window.removeEventListener("keydown", y), window.removeEventListener("keyup", b), window.removeEventListener("blur", x);
544
+ } };
545
+ }
546
+ //#endregion
547
+ //#region src/camera/cameraOrbit.ts
548
+ var Oe = .01, R = Math.PI * 2;
549
+ function ke(e, t) {
550
+ return typeof e == "number" && Number.isFinite(e) ? e : t;
551
+ }
552
+ function Ae(e) {
553
+ return ((e + Math.PI) % R + R) % R - Math.PI;
554
+ }
555
+ function je(e) {
556
+ return ((e + R) % (R * 2) + R * 2) % (R * 2) - R;
557
+ }
558
+ function Me(e, t) {
559
+ return Math.asin(Math.max(-1, Math.min(1, t / Math.max(Oe, Math.abs(e)))));
560
+ }
561
+ function z(e, t) {
562
+ return Math.sin(t) * Math.max(Oe, e);
563
+ }
564
+ function Ne({ distance: e, azimuth: t, elevation: n, target: r }) {
565
+ return {
566
+ distance: Math.max(Oe, ke(e, Oe)),
567
+ azimuth: Ae(ke(t, 0)),
568
+ elevation: je(ke(n, 0)),
569
+ target: {
570
+ x: ke(r.x, 0),
571
+ y: ke(r.y, 0),
572
+ z: ke(r.z, 0)
573
+ }
574
+ };
575
+ }
576
+ function Pe(e) {
577
+ let t = z(e.distance, e.elevation), n = Math.cos(e.elevation) * Math.max(Oe, e.distance);
578
+ return {
579
+ x: e.target.x + Math.cos(e.azimuth) * n,
580
+ y: e.target.y + t,
581
+ z: e.target.z + Math.sin(e.azimuth) * n
582
+ };
583
+ }
584
+ function Fe(e) {
585
+ return {
586
+ x: -Math.cos(e.azimuth) * Math.sin(e.elevation),
587
+ y: Math.cos(e.elevation),
588
+ z: -Math.sin(e.azimuth) * Math.sin(e.elevation)
589
+ };
590
+ }
591
+ function Ie(e) {
592
+ let t = z(e.distance, e.elevation), n = Pe(e);
593
+ return {
594
+ cameraDistance: e.distance,
595
+ cameraHeight: t,
596
+ cameraOrbitAngle: e.azimuth,
597
+ cameraPositionX: n.x,
598
+ cameraPositionY: n.y,
599
+ cameraPositionZ: n.z,
600
+ cameraTargetX: e.target.x,
601
+ cameraTargetY: e.target.y,
602
+ cameraTargetZ: e.target.z
603
+ };
604
+ }
605
+ //#endregion
606
+ //#region src/distribution/distributionSettings.ts
607
+ var Le = [
608
+ "single",
609
+ "grid",
610
+ "cube-grid",
611
+ "rings",
612
+ "ring-path",
613
+ "line-path",
614
+ "spiral-path",
615
+ "sphere",
616
+ "spline-path",
617
+ "starfield"
618
+ ], Re = [
619
+ "center",
620
+ "up",
621
+ "down"
622
+ ], B = {
623
+ distributionMode: "single",
624
+ gridSize: 20,
625
+ gridSpacing: 2,
626
+ gridLayers: 4,
627
+ gridLayerSpacing: 2,
628
+ ringCount: 4,
629
+ ringSpacing: 2,
630
+ ringDensity: 8,
631
+ pathInstanceCount: 64,
632
+ pathRadius: 4,
633
+ pathLength: 12,
634
+ pathCurvature: 0,
635
+ spiralTurns: 3,
636
+ sphereHemisphere: !1,
637
+ pathRows: 1,
638
+ pathRowSpacing: 1,
639
+ pathRowAlignment: "center",
640
+ pathRowPhase: 0,
641
+ pathCurvePhaseDegrees: 0,
642
+ pathSplineBend: 0,
643
+ pathAngle: Math.PI / 4,
644
+ pathOrientationX: 0,
645
+ pathOrientationY: 0,
646
+ pathOrientationZ: 0,
647
+ alignToPath: !0
648
+ };
649
+ function ze(e) {
650
+ let t = V(e.gridSpacing, B.gridSpacing, .001, 1e3), n = Be(e.distributionMode), r = n === "line-path", i = He(e.pathCurvature, B.pathCurvature);
651
+ return {
652
+ distributionMode: r ? "spline-path" : n,
653
+ gridSize: Math.round(V(e.gridSize, B.gridSize, 1, 200)),
654
+ gridSpacing: t,
655
+ gridLayerSpacing: V(e.gridLayerSpacing ?? t, t, .001, 1e3),
656
+ gridLayers: Math.round(V(e.gridLayers, B.gridLayers, 1, 200)),
657
+ ringCount: Math.round(V(e.ringCount, B.ringCount, 0, 200)),
658
+ ringSpacing: V(e.ringSpacing, B.ringSpacing, .001, 1e3),
659
+ ringDensity: V(e.ringDensity, B.ringDensity, .001, 500),
660
+ pathInstanceCount: Math.round(V(e.pathInstanceCount, B.pathInstanceCount, 1, 1e3)),
661
+ pathRadius: V(e.pathRadius, B.pathRadius, .001, 1e3),
662
+ pathLength: V(e.pathLength, B.pathLength, .001, 1e3),
663
+ pathCurvature: r ? 0 : V(e.pathCurvature, B.pathCurvature, -2, 2),
664
+ spiralTurns: V(e.spiralTurns, B.spiralTurns, .05, 100),
665
+ sphereHemisphere: e.sphereHemisphere ?? B.sphereHemisphere,
666
+ pathRows: Math.round(V(e.pathRows, B.pathRows, 1, 250)),
667
+ pathRowSpacing: V(e.pathRowSpacing, B.pathRowSpacing, 0, 1e3),
668
+ pathRowAlignment: Ve(e.pathRowAlignment),
669
+ pathRowPhase: V(e.pathRowPhase, B.pathRowPhase, -10, 10),
670
+ pathCurvePhaseDegrees: V(e.pathCurvePhaseDegrees, B.pathCurvePhaseDegrees, -90, 90),
671
+ pathSplineBend: V(r ? i : e.pathSplineBend, B.pathSplineBend, -2, 2),
672
+ pathAngle: He(e.pathAngle, B.pathAngle),
673
+ pathOrientationX: He(e.pathOrientationX, B.pathOrientationX),
674
+ pathOrientationY: He(e.pathOrientationY, B.pathOrientationY),
675
+ pathOrientationZ: He(e.pathOrientationZ, B.pathOrientationZ),
676
+ alignToPath: e.alignToPath ?? B.alignToPath
677
+ };
678
+ }
679
+ function Be(e) {
680
+ return Le.includes(e) ? e : B.distributionMode;
681
+ }
682
+ function Ve(e) {
683
+ return Re.includes(e) ? e : B.pathRowAlignment;
684
+ }
685
+ function He(e, t) {
686
+ return typeof e == "number" && Number.isFinite(e) ? e : t;
687
+ }
688
+ function V(e, t, n, r) {
689
+ return Math.min(r, Math.max(n, He(e, t)));
690
+ }
691
+ //#endregion
692
+ //#region src/distribution/createLayouts.ts
693
+ function Ue(e) {
694
+ let t = ze(e);
695
+ return t.distributionMode === "single" ? We() : t.distributionMode === "cube-grid" ? Ke(t) : t.distributionMode === "rings" ? qe(t) : t.distributionMode === "ring-path" ? Je(t) : t.distributionMode === "line-path" ? Ye(t) : t.distributionMode === "spiral-path" ? Xe(t) : t.distributionMode === "sphere" ? Ze(t) : t.distributionMode === "spline-path" ? $e(t) : t.distributionMode === "starfield" ? Qe(t) : Ge(t);
696
+ }
697
+ function We() {
698
+ return [{
699
+ x: 0,
700
+ z: 0,
701
+ y: 0,
702
+ distance: 0,
703
+ gridX: 0,
704
+ gridZ: 0,
705
+ angle: 0,
706
+ ringIndex: 0,
707
+ pathProgress: 0,
708
+ spinProgress: 0,
709
+ alignDir: null
710
+ }];
711
+ }
712
+ function Ge(e) {
713
+ let { gridSize: t, gridSpacing: n } = e, r = [], i = (t - 1) * n / 2;
714
+ for (let e = 0; e < t; e += 1) for (let a = 0; a < t; a += 1) {
715
+ let t = e * n - i, o = a * n - i, s = Math.sqrt(t * t + o * o), c = Math.atan2(o, t);
716
+ r.push({
717
+ x: t,
718
+ z: o,
719
+ y: 0,
720
+ distance: s,
721
+ gridX: e,
722
+ gridZ: a,
723
+ angle: c,
724
+ ringIndex: 0,
725
+ pathProgress: 0,
726
+ spinProgress: 0,
727
+ alignDir: null
728
+ });
729
+ }
730
+ return r;
731
+ }
732
+ function Ke(e) {
733
+ let { gridSize: t, gridSpacing: n, gridLayers: r, gridLayerSpacing: i } = e, a = [], o = Math.max(1, Math.round(r)), s = (t - 1) * n / 2, c = (o - 1) * i / 2, l = t * t * o;
734
+ for (let e = 0; e < o; e += 1) for (let r = 0; r < t; r += 1) for (let o = 0; o < t; o += 1) {
735
+ let u = r * n - s, d = e * i - c, f = o * n - s, p = Math.sqrt(u * u + d * d + f * f), m = e * t * t + r * t + o;
736
+ a.push({
737
+ x: u,
738
+ z: f,
739
+ y: d,
740
+ distance: p,
741
+ gridX: r,
742
+ gridZ: o + e * t,
743
+ angle: Math.atan2(f, u),
744
+ ringIndex: e,
745
+ pathProgress: l === 1 ? 0 : m / (l - 1),
746
+ spinProgress: l === 1 ? 0 : m / (l - 1),
747
+ alignDir: null
748
+ });
749
+ }
750
+ return a;
751
+ }
752
+ function qe(e) {
753
+ let { ringCount: t, ringSpacing: n, ringDensity: r } = e, i = [{
754
+ x: 0,
755
+ z: 0,
756
+ y: 0,
757
+ distance: 0,
758
+ gridX: 0,
759
+ gridZ: 0,
760
+ angle: 0,
761
+ ringIndex: 0,
762
+ pathProgress: 0,
763
+ spinProgress: 0,
764
+ alignDir: G(e, Math.PI / Math.max(1, Math.round(r)) + Math.PI / 2, !1),
765
+ alignUp: K(e, !1)
766
+ }], a = Math.max(0, Math.round(t));
767
+ for (let t = 1; t <= a; t += 1) {
768
+ let a = t * n, o = Math.max(1, Math.round(t * r)), s = t % 2 == 0 ? 0 : Math.PI / o;
769
+ for (let n = 0; n < o; n += 1) {
770
+ let r = n / o * Math.PI * 2 + s, c = Math.cos(r) * a, l = Math.sin(r) * a;
771
+ i.push({
772
+ x: c,
773
+ z: l,
774
+ y: 0,
775
+ distance: a,
776
+ gridX: n,
777
+ gridZ: t,
778
+ angle: r,
779
+ ringIndex: t,
780
+ pathProgress: o === 1 ? 0 : n / o,
781
+ spinProgress: o === 1 ? 0 : n / o,
782
+ alignDir: G(e, r + Math.PI / 2, !1),
783
+ alignUp: K(e, !1)
784
+ });
785
+ }
786
+ }
787
+ return i;
788
+ }
789
+ function Je(e) {
790
+ let { pathInstanceCount: t, pathRadius: n, alignToPath: r } = e, i = [], a = Math.max(1, Math.round(t)), o = H(e), s = a * o;
791
+ for (let t = 0; t < o; t += 1) {
792
+ let c = U(e, t, o);
793
+ for (let o = 0; o < a; o += 1) {
794
+ let l = at(e, t), u = a === 1 ? 0 : ot(o / a + l), d = u * Math.PI * 2, f = ct(e, Math.cos(d) * n, c, Math.sin(d) * n), p = r ? d + Math.PI / 2 : 0, m = t * a + o;
795
+ i.push({
796
+ x: f.x,
797
+ z: f.z,
798
+ y: f.y,
799
+ distance: n,
800
+ gridX: o,
801
+ gridZ: t,
802
+ angle: p,
803
+ ringIndex: t,
804
+ pathProgress: u,
805
+ spinProgress: s === 1 ? 0 : m / s,
806
+ alignDir: G(e, d + Math.PI / 2, !0),
807
+ alignUp: K(e, !0)
808
+ });
809
+ }
810
+ }
811
+ return i;
812
+ }
813
+ function Ye(e) {
814
+ let { pathInstanceCount: t, pathAngle: n, alignToPath: r } = e, i = [], a = Math.max(1, Math.round(t)), o = H(e), s = a * o;
815
+ for (let t = 0; t < o; t += 1) {
816
+ let c = U(e, t, o), l = at(e, t);
817
+ for (let o = 0; o < a; o += 1) {
818
+ let u = a === 1 ? 0 : W(o / (a - 1) + l), d = tt(e, u), f = ct(e, d.x, c, d.z), p = Math.sqrt(d.x * d.x + d.z * d.z), m = r ? n + d.tangentAngle : 0, h = t * a + o;
819
+ i.push({
820
+ x: f.x,
821
+ z: f.z,
822
+ y: f.y,
823
+ distance: p,
824
+ gridX: o,
825
+ gridZ: t,
826
+ angle: m,
827
+ ringIndex: t,
828
+ pathProgress: u,
829
+ spinProgress: s === 1 ? 0 : h / s,
830
+ alignDir: G(e, n + d.tangentAngle, !0),
831
+ alignUp: K(e, !0)
832
+ });
833
+ }
834
+ }
835
+ return i;
836
+ }
837
+ function Xe(e) {
838
+ let { pathInstanceCount: t, alignToPath: n } = e, r = [], i = Math.max(1, Math.round(t)), a = H(e), o = i * a;
839
+ for (let t = 0; t < a; t += 1) {
840
+ let s = U(e, t, a), c = at(e, t);
841
+ for (let a = 0; a < i; a += 1) {
842
+ let l = i === 1 ? 0 : W(a / (i - 1) + c), u = nt(e, l), d = ct(e, u.x, s, u.z), f = t * i + a;
843
+ r.push({
844
+ x: d.x,
845
+ z: d.z,
846
+ y: d.y,
847
+ distance: u.distance,
848
+ gridX: a,
849
+ gridZ: t,
850
+ angle: n ? u.tangentAngle : 0,
851
+ ringIndex: t,
852
+ pathProgress: l,
853
+ spinProgress: o === 1 ? 0 : f / (o - 1),
854
+ alignDir: G(e, u.tangentAngle, !0),
855
+ alignUp: K(e, !0)
856
+ });
857
+ }
858
+ }
859
+ return r;
860
+ }
861
+ function Ze(e) {
862
+ let { pathInstanceCount: t, pathRadius: n, sphereHemisphere: r, alignToPath: i } = e, a = [], o = Math.max(1, Math.round(t)), s = Math.PI * (3 - Math.sqrt(5)), c = r ? 0 : -1, l = r ? 1 : 2;
863
+ for (let e = 0; e < o; e += 1) {
864
+ let t = o === 1 ? 0 : e / (o - 1), u = c + l * (r ? t : 1 - t), d = Math.sqrt(Math.max(0, 1 - u * u)), f = e * s, p = Math.cos(f) * d * n, m = u * n, h = Math.sin(f) * d * n;
865
+ a.push({
866
+ x: p,
867
+ z: h,
868
+ y: m,
869
+ distance: n,
870
+ gridX: e,
871
+ gridZ: 0,
872
+ angle: i ? Math.atan2(h, p) + Math.PI / 2 : 0,
873
+ ringIndex: 0,
874
+ pathProgress: t,
875
+ spinProgress: t,
876
+ alignDir: lt(p, m, h)
877
+ });
878
+ }
879
+ return a;
880
+ }
881
+ function Qe(e) {
882
+ let { pathInstanceCount: t, pathRadius: n, pathLength: r } = e, i = [], a = Math.max(1, Math.round(t)), o = Math.max(1e-4, r), s = o * .35, c = -o, l = s - c;
883
+ for (let t = 0; t < a; t += 1) {
884
+ let r = a === 1 ? 0 : t / a, o = Math.sqrt(st(t, 1)) * n, s = st(t, 2) * Math.PI * 2, u = st(t, 3), d = ct(e, Math.cos(s) * o, (st(t, 4) * 2 - 1) * n, c + u * l), f = Math.sqrt(d.x * d.x + d.y * d.y + d.z * d.z);
885
+ i.push({
886
+ x: d.x,
887
+ z: d.z,
888
+ y: d.y,
889
+ distance: f,
890
+ gridX: t,
891
+ gridZ: 0,
892
+ angle: 0,
893
+ ringIndex: 0,
894
+ pathProgress: u,
895
+ spinProgress: r,
896
+ alignDir: null
897
+ });
898
+ }
899
+ return i;
900
+ }
901
+ function $e(e) {
902
+ let { pathInstanceCount: t, alignToPath: n } = e, r = [], i = Math.max(1, Math.round(t)), a = H(e), o = i * a;
903
+ for (let t = 0; t < a; t += 1) {
904
+ let s = U(e, t, a), c = at(e, t);
905
+ for (let a = 0; a < i; a += 1) {
906
+ let l = i === 1 ? 0 : W(a / (i - 1) + c), u = it(e, l), d = ct(e, u.x, s, u.z), f = t * i + a;
907
+ r.push({
908
+ x: d.x,
909
+ z: d.z,
910
+ y: d.y,
911
+ distance: Math.sqrt(u.x * u.x + u.z * u.z),
912
+ gridX: a,
913
+ gridZ: t,
914
+ angle: n ? u.tangentAngle : 0,
915
+ ringIndex: t,
916
+ pathProgress: l,
917
+ spinProgress: o === 1 ? 0 : f / (o - 1),
918
+ alignDir: G(e, u.tangentAngle, !0),
919
+ alignUp: K(e, !0)
920
+ });
921
+ }
922
+ }
923
+ return r;
924
+ }
925
+ function et(e, t, n) {
926
+ let r = Math.max(-2, Math.min(2, e)), i = Math.max(1e-4, t);
927
+ if (Math.abs(r) < 1e-4) return {
928
+ x: (n - .5) * t,
929
+ z: 0,
930
+ tx: 1,
931
+ tz: 0
932
+ };
933
+ let a = Math.sign(r), o = Math.min(Math.abs(r), 1.95) * Math.PI, s = i / (2 * Math.sin(o / 2)), c = s * Math.cos(o / 2), l = -o / 2 + n * o;
934
+ return {
935
+ x: s * Math.sin(l),
936
+ z: a * (s * Math.cos(l) - c),
937
+ tx: s * Math.cos(l),
938
+ tz: a * -s * Math.sin(l)
939
+ };
940
+ }
941
+ function tt(e, t) {
942
+ let n = Math.cos(e.pathAngle), r = Math.sin(e.pathAngle), i = et(e.pathCurvature, e.pathLength, t);
943
+ return {
944
+ x: n * i.x - r * i.z,
945
+ z: r * i.x + n * i.z,
946
+ tangentAngle: i.tz === 0 && i.tx > 0 ? 0 : Math.atan2(i.tz, i.tx)
947
+ };
948
+ }
949
+ function nt(e, t) {
950
+ let n = W(t), r = n * Math.PI * 2 * Math.max(.05, e.spiralTurns), i = n * e.pathRadius;
951
+ return {
952
+ x: Math.cos(r) * i,
953
+ z: Math.sin(r) * i,
954
+ distance: i,
955
+ tangentAngle: r + Math.PI / 2
956
+ };
957
+ }
958
+ function rt(e, t) {
959
+ let n = e.pathLength, r = e.pathCurvature * n * .25, i = et(e.pathSplineBend, n, t), a = -Math.PI / 2 + e.pathCurvePhaseDegrees * Math.PI / 180, o = Math.sin(t * Math.PI * 2 + a) * r, s = Math.hypot(i.tx, i.tz) || 1, c = -i.tz / s, l = i.tx / s;
960
+ return {
961
+ x: i.x + c * o,
962
+ z: i.z + l * o
963
+ };
964
+ }
965
+ function it(e, t) {
966
+ let n = W(t), r = rt(e, n), i = 5e-4, a = rt(e, W(n - i)), o = rt(e, W(n + i)), s = Math.cos(e.pathAngle), c = Math.sin(e.pathAngle);
967
+ return {
968
+ x: s * r.x - c * r.z,
969
+ z: c * r.x + s * r.z,
970
+ tangentAngle: e.pathAngle + Math.atan2(o.z - a.z, o.x - a.x)
971
+ };
972
+ }
973
+ function H(e) {
974
+ return Math.max(1, Math.round(e.pathRows));
975
+ }
976
+ function U(e, t, n) {
977
+ return e.pathRowAlignment === "up" ? t * e.pathRowSpacing : e.pathRowAlignment === "down" ? -t * e.pathRowSpacing : (t - (n - 1) / 2) * e.pathRowSpacing;
978
+ }
979
+ function at(e, t) {
980
+ return t * e.pathRowPhase;
981
+ }
982
+ function ot(e) {
983
+ return (e % 1 + 1) % 1;
984
+ }
985
+ function W(e) {
986
+ return Math.max(0, Math.min(1, e));
987
+ }
988
+ function st(e, t) {
989
+ let n = Math.sin((e + 1) * 12.9898 + t * 78.233) * 43758.5453;
990
+ return n - Math.floor(n);
991
+ }
992
+ function ct(e, t, n, r) {
993
+ return new u.Vector3(t, n, r).applyEuler(new u.Euler(e.pathOrientationX, e.pathOrientationY, e.pathOrientationZ));
994
+ }
995
+ function G(e, t, n) {
996
+ let r = Math.cos(t), i = Math.sin(t);
997
+ if (!n) return {
998
+ x: r,
999
+ y: 0,
1000
+ z: i
1001
+ };
1002
+ let a = ct(e, r, 0, i);
1003
+ return {
1004
+ x: a.x,
1005
+ y: a.y,
1006
+ z: a.z
1007
+ };
1008
+ }
1009
+ function lt(e, t, n) {
1010
+ let r = Math.hypot(e, t, n);
1011
+ return r < 1e-6 ? null : {
1012
+ x: e / r,
1013
+ y: t / r,
1014
+ z: n / r
1015
+ };
1016
+ }
1017
+ function K(e, t) {
1018
+ if (!t) return {
1019
+ x: 0,
1020
+ y: 1,
1021
+ z: 0
1022
+ };
1023
+ let n = ct(e, 0, 1, 0);
1024
+ return {
1025
+ x: n.x,
1026
+ y: n.y,
1027
+ z: n.z
1028
+ };
1029
+ }
1030
+ //#endregion
1031
+ //#region src/motion/easing.ts
1032
+ var q = "0.00, 1.00, 0.00, 1.00", ut = "ease-out", dt = {
1033
+ "ease-in": {
1034
+ x1: .42,
1035
+ y1: 0,
1036
+ x2: 1,
1037
+ y2: 1
1038
+ },
1039
+ "ease-out": {
1040
+ x1: 0,
1041
+ y1: 0,
1042
+ x2: .58,
1043
+ y2: 1
1044
+ },
1045
+ "ease-in-out": {
1046
+ x1: .42,
1047
+ y1: 0,
1048
+ x2: .58,
1049
+ y2: 1
1050
+ }
1051
+ };
1052
+ function J(e, t = ut) {
1053
+ return e === "linear" || e === "ease-in" || e === "ease-out" || e === "ease-in-out" || e === "custom-bezier" ? e : t;
1054
+ }
1055
+ function Y(e, t = q) {
1056
+ return typeof e == "string" && ft(e) ? e.trim() : t;
1057
+ }
1058
+ function ft(e) {
1059
+ let t = e.trim().replace(/^cubic-bezier\(/i, "").replace(/^\(/, "").replace(/\)$/, "").split(",").map((e) => Number(e.trim()));
1060
+ if (t.length !== 4 || t.some((e) => !Number.isFinite(e))) return null;
1061
+ let [n, r, i, a] = t;
1062
+ return {
1063
+ x1: vt(n),
1064
+ y1: r,
1065
+ x2: vt(i),
1066
+ y2: a
1067
+ };
1068
+ }
1069
+ function pt(e, t, n = q) {
1070
+ let r = vt(e);
1071
+ if (t === "linear") return r;
1072
+ if (t === "custom-bezier") {
1073
+ let e = ft(n);
1074
+ if (e) return ht(e.x1, e.y1, e.x2, e.y2, r);
1075
+ }
1076
+ let i = t === "ease-in" || t === "ease-in-out" ? dt[t] : dt["ease-out"];
1077
+ return ht(i.x1, i.y1, i.x2, i.y2, r);
1078
+ }
1079
+ function mt(e, t, n = q) {
1080
+ return yt(pt((yt(e) + 1) / 2, t, n) * 2 - 1);
1081
+ }
1082
+ function ht(e, t, n, r, i) {
1083
+ let a = i;
1084
+ for (let t = 0; t < 5; t += 1) {
1085
+ let t = gt(a, e, n), r = _t(a, e, n);
1086
+ if (Math.abs(r) < 1e-4) break;
1087
+ a = vt(a - (t - i) / r);
1088
+ }
1089
+ return vt(gt(a, t, r));
1090
+ }
1091
+ function gt(e, t, n) {
1092
+ let r = 1 - e;
1093
+ return 3 * r * r * e * t + 3 * r * e * e * n + e * e * e;
1094
+ }
1095
+ function _t(e, t, n) {
1096
+ let r = 1 - e;
1097
+ return 3 * r * r * t + 6 * r * e * (n - t) + 3 * e * e * (1 - n);
1098
+ }
1099
+ function vt(e) {
1100
+ return Math.min(1, Math.max(0, e));
1101
+ }
1102
+ function yt(e) {
1103
+ return Math.min(1, Math.max(-1, e));
1104
+ }
1105
+ //#endregion
1106
+ //#region src/distribution/animateLayouts.ts
1107
+ function bt({ layout: e, settings: t, pathTravelProgress: n, ringOrbitProgress: r }) {
1108
+ return St(xt(e, t, n), t, r);
1109
+ }
1110
+ function xt(e, t, n) {
1111
+ if (t.distributionMode === "starfield") {
1112
+ let r = Math.max(1e-4, t.pathLength), i = r * .35, a = -r, o = i - a, s = Tt(e, t, n, e.pathProgress), c = a + s * o, l = t.starfieldCenter ?? new u.Vector3(0, 0, 0), d = t.starfieldRight ?? Et(t, 1, 0, 0).normalize(), f = t.starfieldUp ?? Et(t, 0, 1, 0).normalize(), p = t.starfieldForward ?? Et(t, 0, 0, 1).normalize(), m = Math.max(0, Math.round(e.gridX)), h = Math.sqrt(Dt(m, 1)) * t.pathRadius, g = Dt(m, 2) * Math.PI * 2, _ = Math.cos(g) * h, v = (Dt(m, 4) * 2 - 1) * t.pathRadius, y = l.clone().addScaledVector(d, _).addScaledVector(f, v).addScaledVector(p, c);
1113
+ return {
1114
+ ...e,
1115
+ x: y.x,
1116
+ y: y.y,
1117
+ z: y.z,
1118
+ distance: Math.sqrt(y.x * y.x + y.y * y.y + y.z * y.z),
1119
+ pathProgress: s
1120
+ };
1121
+ }
1122
+ if (n === 0) return e;
1123
+ if (t.distributionMode === "ring-path") {
1124
+ let r = Tt(e, t, n, e.pathProgress), i = r * Math.PI * 2, a = Math.cos(i) * t.pathRadius, o = Math.sin(i) * t.pathRadius, s = Et(t, a, U(t, e.gridZ, H(t)), o), c = t.alignToPath ? i + Math.PI / 2 : 0;
1125
+ return {
1126
+ ...e,
1127
+ x: s.x,
1128
+ y: s.y,
1129
+ z: s.z,
1130
+ angle: c,
1131
+ pathProgress: r,
1132
+ alignDir: G(t, i + Math.PI / 2, !0),
1133
+ alignUp: K(t, !0)
1134
+ };
1135
+ }
1136
+ if (t.distributionMode === "line-path") {
1137
+ let r = Tt(e, t, n, e.pathProgress), i = tt(t, r), a = U(t, e.gridZ, H(t)), o = Et(t, i.x, a, i.z), s = t.alignToPath ? t.pathAngle + i.tangentAngle : 0;
1138
+ return {
1139
+ ...e,
1140
+ x: o.x,
1141
+ y: o.y,
1142
+ z: o.z,
1143
+ angle: s,
1144
+ pathProgress: r,
1145
+ alignDir: G(t, t.pathAngle + i.tangentAngle, !0),
1146
+ alignUp: K(t, !0)
1147
+ };
1148
+ }
1149
+ if (t.distributionMode === "spiral-path") {
1150
+ let r = Tt(e, t, n, e.pathProgress), i = nt(t, r), a = U(t, e.gridZ, H(t)), o = Et(t, i.x, a, i.z), s = t.alignToPath ? i.tangentAngle : 0;
1151
+ return {
1152
+ ...e,
1153
+ x: o.x,
1154
+ y: o.y,
1155
+ z: o.z,
1156
+ angle: s,
1157
+ pathProgress: r,
1158
+ alignDir: G(t, i.tangentAngle, !0),
1159
+ alignUp: K(t, !0)
1160
+ };
1161
+ }
1162
+ if (t.distributionMode === "spline-path") {
1163
+ let r = Tt(e, t, n, e.pathProgress), i = it(t, r), a = U(t, e.gridZ, H(t)), o = Et(t, i.x, a, i.z), s = t.alignToPath ? i.tangentAngle : 0;
1164
+ return {
1165
+ ...e,
1166
+ x: o.x,
1167
+ y: o.y,
1168
+ z: o.z,
1169
+ angle: s,
1170
+ pathProgress: r,
1171
+ alignDir: G(t, i.tangentAngle, !0),
1172
+ alignUp: K(t, !0)
1173
+ };
1174
+ }
1175
+ return e;
1176
+ }
1177
+ function St(e, t, n) {
1178
+ if (t.distributionMode !== "rings" || e.ringIndex === 0 || n === 0) return e;
1179
+ let r = Math.max(1, Math.round(t.ringCount)), i = Math.max(1, r), a = e.ringIndex / i, o = Tt(e, t, n * (1 - u.MathUtils.clamp(t.ringOrbitFriction, 0, 4) * a), e.pathProgress) * Math.PI * 2, s = e.ringIndex * t.ringSpacing;
1180
+ return {
1181
+ ...e,
1182
+ x: Math.cos(o) * s,
1183
+ z: Math.sin(o) * s,
1184
+ angle: o,
1185
+ alignDir: G(t, o + Math.PI / 2, !1),
1186
+ alignUp: K(t, !1)
1187
+ };
1188
+ }
1189
+ var Ct = new Set([
1190
+ "line-path",
1191
+ "spiral-path",
1192
+ "spline-path"
1193
+ ]);
1194
+ function wt(e, t) {
1195
+ if (!Ct.has(e.distributionMode)) return t;
1196
+ let n = Math.max(1, Math.round(e.pathInstanceCount));
1197
+ return n <= 1 ? t : t * ((n - 1) / n);
1198
+ }
1199
+ function Tt(e, t, n, r) {
1200
+ let i = wt(t, r);
1201
+ if (t.pathTravelMode !== "stepped") return Ot(i + n);
1202
+ let a = Math.max(.001, t.pathTravelStepInterval ?? 1), o = Math.max(0, Math.min(a, t.pathTravelStepDuration ?? .25)), s = t.pathTravelStepDistance ?? .1, c = Math.max(0, t.pathTravelStepStagger ?? 0), l = n - (Number.isFinite(e.spinProgress) ? e.spinProgress : r) * c, d = Math.floor(l / a), f = l - d * a;
1203
+ return Ot(i + (d + pt(o <= 0 ? 1 : u.MathUtils.clamp(f / o, 0, 1), t.pathTravelStepEasing ?? "ease-out", t.pathTravelStepCustomBezier ?? "0.00, 1.00, 0.00, 1.00")) * s);
1204
+ }
1205
+ function Et(e, t, n, r) {
1206
+ return new u.Vector3(t, n, r).applyEuler(new u.Euler(e.pathOrientationX, e.pathOrientationY, e.pathOrientationZ));
1207
+ }
1208
+ function Dt(e, t) {
1209
+ let n = Math.sin((e + 1) * 12.9898 + t * 78.233) * 43758.5453;
1210
+ return n - Math.floor(n);
1211
+ }
1212
+ function Ot(e) {
1213
+ return (e % 1 + 1) % 1;
1214
+ }
1215
+ //#endregion
1216
+ //#region node_modules/three/examples/jsm/geometries/RoundedBoxGeometry.js
1217
+ var kt = new T();
1218
+ function X(e, t, n, r, i, a) {
1219
+ let o = 2 * Math.PI * i / 4, s = Math.max(a - 2 * i, 0), c = Math.PI / 4;
1220
+ kt.copy(t), kt[r] = 0, kt.normalize();
1221
+ let l = .5 * o / (o + s), u = 1 - kt.angleTo(e) / c;
1222
+ return Math.sign(kt[n]) === 1 ? u * l : s / (o + s) + l + l * (1 - u);
1223
+ }
1224
+ var At = class e extends f {
1225
+ constructor(e = 1, t = 1, n = 1, r = 2, i = .1) {
1226
+ let a = r * 2 + 1;
1227
+ if (i = Math.min(e / 2, t / 2, n / 2, i), super(1, 1, 1, a, a, a), this.type = "RoundedBoxGeometry", this.parameters = {
1228
+ width: e,
1229
+ height: t,
1230
+ depth: n,
1231
+ segments: r,
1232
+ radius: i
1233
+ }, a === 1) return;
1234
+ let o = this.toNonIndexed();
1235
+ this.index = null, this.attributes.position = o.attributes.position, this.attributes.normal = o.attributes.normal, this.attributes.uv = o.attributes.uv;
1236
+ let s = new T(), c = new T(), l = new T(e, t, n).divideScalar(2).subScalar(i), u = this.attributes.position.array, d = this.attributes.normal.array, f = this.attributes.uv.array, p = u.length / 6, m = new T(), h = .5 / a;
1237
+ for (let r = 0, a = 0; r < u.length; r += 3, a += 2) switch (s.fromArray(u, r), c.copy(s), c.x -= Math.sign(c.x) * h, c.y -= Math.sign(c.y) * h, c.z -= Math.sign(c.z) * h, c.normalize(), u[r + 0] = l.x * Math.sign(s.x) + c.x * i, u[r + 1] = l.y * Math.sign(s.y) + c.y * i, u[r + 2] = l.z * Math.sign(s.z) + c.z * i, d[r + 0] = c.x, d[r + 1] = c.y, d[r + 2] = c.z, Math.floor(r / p)) {
1238
+ case 0:
1239
+ m.set(1, 0, 0), f[a + 0] = X(m, c, "z", "y", i, n), f[a + 1] = 1 - X(m, c, "y", "z", i, t);
1240
+ break;
1241
+ case 1:
1242
+ m.set(-1, 0, 0), f[a + 0] = 1 - X(m, c, "z", "y", i, n), f[a + 1] = 1 - X(m, c, "y", "z", i, t);
1243
+ break;
1244
+ case 2:
1245
+ m.set(0, 1, 0), f[a + 0] = 1 - X(m, c, "x", "z", i, e), f[a + 1] = X(m, c, "z", "x", i, n);
1246
+ break;
1247
+ case 3:
1248
+ m.set(0, -1, 0), f[a + 0] = 1 - X(m, c, "x", "z", i, e), f[a + 1] = 1 - X(m, c, "z", "x", i, n);
1249
+ break;
1250
+ case 4:
1251
+ m.set(0, 0, 1), f[a + 0] = 1 - X(m, c, "x", "y", i, e), f[a + 1] = 1 - X(m, c, "y", "x", i, t);
1252
+ break;
1253
+ case 5:
1254
+ m.set(0, 0, -1), f[a + 0] = X(m, c, "x", "y", i, e), f[a + 1] = 1 - X(m, c, "y", "x", i, t);
1255
+ break;
1256
+ }
1257
+ }
1258
+ static fromJSON(t) {
1259
+ return new e(t.width, t.height, t.depth, t.segments, t.radius);
1260
+ }
1261
+ };
1262
+ //#endregion
1263
+ //#region src/instance/createInstanceGeometry.ts
1264
+ function jt(e) {
1265
+ return e === "low" ? {
1266
+ radial: 12,
1267
+ sphereWidth: 16,
1268
+ sphereHeight: 8,
1269
+ torusTubular: 24,
1270
+ torusRadial: 8,
1271
+ capsuleCap: 4,
1272
+ roundedBoxSegments: 2,
1273
+ roundedCardCurve: 6
1274
+ } : e === "high" ? {
1275
+ radial: 64,
1276
+ sphereWidth: 48,
1277
+ sphereHeight: 24,
1278
+ torusTubular: 72,
1279
+ torusRadial: 24,
1280
+ capsuleCap: 12,
1281
+ roundedBoxSegments: 6,
1282
+ roundedCardCurve: 18
1283
+ } : {
1284
+ radial: 32,
1285
+ sphereWidth: 32,
1286
+ sphereHeight: 16,
1287
+ torusTubular: 48,
1288
+ torusRadial: 16,
1289
+ capsuleCap: 8,
1290
+ roundedBoxSegments: 4,
1291
+ roundedCardCurve: 12
1292
+ };
1293
+ }
1294
+ function Mt({ settings: t, customObjGeometry: n, customSvgGeometry: r, textGeometry: i }) {
1295
+ let { instanceShape: a } = t, { scaleX: o, scaleY: s, scaleZ: c } = e(t), l = jt(t.geometryDetail);
1296
+ if (a === "custom-obj") return n ? Pt(n.clone(), o, s, c) : new u.BoxGeometry(o, s, c);
1297
+ if (a === "svg") {
1298
+ let e = r?.clone() ?? new u.BoxGeometry(o, s, c);
1299
+ return r && (e.scale(o, c, t.svgSolidify ? s : 1), e.rotateX(-Math.PI / 2), e.computeVertexNormals(), e.computeBoundingBox(), e.computeBoundingSphere()), e;
1300
+ }
1301
+ if (a === "image") {
1302
+ let e = new u.PlaneGeometry(o, c);
1303
+ return e.rotateX(-Math.PI / 2), e;
1304
+ }
1305
+ if (a === "cylinder") return Pt(new u.CylinderGeometry(.5, .5, 1, l.radial, 1), o, s, c);
1306
+ if (a === "sphere") return Pt(new u.SphereGeometry(.5, l.sphereWidth, l.sphereHeight), o, s, c);
1307
+ if (a === "pill") {
1308
+ let e = Math.max(.01, Math.min(o, c)), t = Math.max(.01, s - e) / e;
1309
+ return Pt(new u.CapsuleGeometry(.5, t, l.capsuleCap, l.radial), o, e, c);
1310
+ }
1311
+ if (a === "rounded-cube") {
1312
+ let e = Math.min(o, s, c) * Math.min(.5, Math.max(0, t.roundedCardRadius));
1313
+ return new At(o, s, c, l.roundedBoxSegments, e);
1314
+ }
1315
+ return a === "text" ? i ? i.createTextGeometry(t, i.textFonts, l) : new u.BoxGeometry(o, s, c) : a === "cone" ? Pt(new u.ConeGeometry(.5, 1, l.radial, 1), o, s, c) : a === "torus" ? Pt(new u.TorusGeometry(.38, .12, l.torusRadial, l.torusTubular), o, s, c) : a === "rounded-card" ? Nt(t, l) : new u.BoxGeometry(o, s, c);
1316
+ }
1317
+ function Nt(t, n) {
1318
+ let { scaleX: r, scaleY: i, scaleZ: a } = e(t), o = t.roundedCardAxis, s, c, l;
1319
+ o === "z" ? (s = r, c = i, l = a) : o === "x" ? (s = a, c = i, l = r) : (s = r, c = a, l = i);
1320
+ let d = Math.min(s, c) * Math.min(.5, Math.max(0, t.roundedCardRadius)), f = s * .5, p = c * .5, m = new u.Shape();
1321
+ m.moveTo(-f + d, -p), m.lineTo(f - d, -p), m.quadraticCurveTo(f, -p, f, -p + d), m.lineTo(f, p - d), m.quadraticCurveTo(f, p, f - d, p), m.lineTo(-f + d, p), m.quadraticCurveTo(-f, p, -f, p - d), m.lineTo(-f, -p + d), m.quadraticCurveTo(-f, -p, -f + d, -p);
1322
+ let h = new u.ExtrudeGeometry(m, {
1323
+ depth: Math.max(.01, l),
1324
+ bevelEnabled: !1,
1325
+ curveSegments: n.roundedCardCurve
1326
+ });
1327
+ return h.center(), o === "y" ? h.rotateX(Math.PI / 2) : o === "x" && h.rotateY(Math.PI / 2), h;
1328
+ }
1329
+ function Pt(e, t, n, r) {
1330
+ return e.scale(t, n, r), e;
1331
+ }
1332
+ //#endregion
1333
+ //#region src/engine/Sinth.ts
1334
+ var Ft = class extends Error {
1335
+ constructor() {
1336
+ super("Custom asset load was superseded by a newer load."), this.name = "StaleCustomAssetLoadError";
1337
+ }
1338
+ }, It = 20, Lt = It / Math.sqrt(3), Z = 1e-4, Rt = new u.Vector3(0, 1, 0), Q = 6, zt = Q * 2, Bt = 3, Vt = "#FAFAFA", Ht = "#EBEBEB", Ut = 20, Wt = [
1339
+ "gridSize",
1340
+ "gridSpacing",
1341
+ "gridLayers",
1342
+ "gridLayerSpacing",
1343
+ "ringCount",
1344
+ "ringDensity",
1345
+ "ringSpacing",
1346
+ "pathInstanceCount",
1347
+ "pathRadius",
1348
+ "pathLength",
1349
+ "pathCurvature",
1350
+ "spiralTurns",
1351
+ "pathRows",
1352
+ "pathRowSpacing",
1353
+ "pathRowPhase",
1354
+ "pathRowAlignment",
1355
+ "pathCurvePhaseDegrees",
1356
+ "pathSplineBend",
1357
+ "sphereHemisphere",
1358
+ "pathOrientationX",
1359
+ "pathOrientationY",
1360
+ "pathOrientationZ",
1361
+ "alignToPath",
1362
+ "alignToPattern"
1363
+ ], $ = {
1364
+ gridSize: B.gridSize,
1365
+ instanceLimit: 2,
1366
+ gridSpacing: B.gridSpacing,
1367
+ gridLayers: B.gridLayers,
1368
+ gridLayerSpacing: B.gridLayerSpacing,
1369
+ ringSpacing: B.ringSpacing,
1370
+ ringCount: B.ringCount,
1371
+ ringDensity: 12,
1372
+ instanceShape: "cube",
1373
+ scaleX: .5,
1374
+ scaleY: .5,
1375
+ scaleZ: .5,
1376
+ geometryDetail: "medium",
1377
+ roundedCardRatio: 1.6,
1378
+ roundedCardRadius: .12,
1379
+ roundedCardAxis: "y",
1380
+ imageCornerRadius: 0,
1381
+ textValue: o,
1382
+ textFont: c,
1383
+ textFontSource: { ...i },
1384
+ textCustomFontUrl: "",
1385
+ textSolidify: !0,
1386
+ svgSolidify: !1,
1387
+ textLetterSpacing: 0,
1388
+ textLineHeight: 1.15,
1389
+ textMaxLineLength: 0,
1390
+ assetUrl: "",
1391
+ assetScale: 1,
1392
+ assetNormalize: !0,
1393
+ assetDoubleSided: !1,
1394
+ imageSetUrls: [],
1395
+ imageAspectRatio: 1,
1396
+ imagePreserveAspectRatio: !0,
1397
+ baseY: 0,
1398
+ groundAlign: !0,
1399
+ instanceRotationX: 0,
1400
+ instanceRotationY: 0,
1401
+ instanceRotationZ: -.2,
1402
+ viewMode: "perspective",
1403
+ orthographicView: "custom",
1404
+ orthoScale: 150,
1405
+ cameraFocalLength: 50,
1406
+ cameraDistance: It,
1407
+ cameraHeight: Lt,
1408
+ cameraOrbitAngle: Math.PI / 4,
1409
+ cameraElevation: Math.asin(Lt / It),
1410
+ cameraPositionX: Lt,
1411
+ cameraPositionY: Lt,
1412
+ cameraPositionZ: Lt,
1413
+ cameraTargetX: 0,
1414
+ cameraTargetY: 0,
1415
+ cameraTargetZ: 0,
1416
+ distributionMode: B.distributionMode,
1417
+ animationMode: "radial-wave",
1418
+ instanceSpinX: 0,
1419
+ instanceSpinY: .1,
1420
+ instanceSpinZ: 0,
1421
+ instanceSpinStagger: 0,
1422
+ instanceSpinStaggerMode: "progressive",
1423
+ instanceSpinPhaseStagger: 0,
1424
+ pathRotationX: 0,
1425
+ pathRotationY: 0,
1426
+ pathRotationZ: 0,
1427
+ pathTravelMode: "flow",
1428
+ pathTravelSpeed: 0,
1429
+ pathTravelStepDistance: .1,
1430
+ pathTravelStepInterval: 1,
1431
+ pathTravelStepDuration: .25,
1432
+ pathTravelStepEasing: ut,
1433
+ pathTravelStepCustomBezier: q,
1434
+ pathTravelStepStagger: 0,
1435
+ ringOrbitSpeed: 0,
1436
+ ringOrbitFriction: 0,
1437
+ waveAmplitude: 1.5,
1438
+ waveFrequency: .5,
1439
+ waveSpeed: 0,
1440
+ easingMode: "linear",
1441
+ easingStrength: 1,
1442
+ easingCustomBezier: q,
1443
+ fadeDuration: .3,
1444
+ fadeEasing: ut,
1445
+ fadeCustomBezier: q,
1446
+ pathEdgeFadeDuration: .3,
1447
+ pathEdgeFadeEasing: ut,
1448
+ pathEdgeFadeCustomBezier: q,
1449
+ buildFadeEnabled: !1,
1450
+ buildSceneZoomEnabled: !1,
1451
+ buildSceneZoomStartScale: .2,
1452
+ buildZoomEnabled: !1,
1453
+ buildZoomStartScale: .2,
1454
+ buildDropEnabled: !1,
1455
+ buildDropOffsetY: -6,
1456
+ buildRotateEnabled: !1,
1457
+ buildRotateAxis: "y",
1458
+ buildRotateOffset: Math.PI,
1459
+ buildDuration: 1,
1460
+ buildDelay: 0,
1461
+ buildEasing: ut,
1462
+ buildCustomBezier: q,
1463
+ staggerAmount: 0,
1464
+ scaleMode: "constant",
1465
+ scaleAmount: 0,
1466
+ ringSpacingFactor: .72,
1467
+ pathInstanceCount: B.pathInstanceCount,
1468
+ pathRadius: B.pathRadius,
1469
+ pathLength: B.pathLength,
1470
+ pathCurvature: B.pathCurvature,
1471
+ spiralTurns: B.spiralTurns,
1472
+ sphereHemisphere: B.sphereHemisphere,
1473
+ pathRows: B.pathRows,
1474
+ pathRowSpacing: B.pathRowSpacing,
1475
+ pathRowAlignment: B.pathRowAlignment,
1476
+ pathRowPhase: B.pathRowPhase,
1477
+ pathCurvePhaseDegrees: B.pathCurvePhaseDegrees,
1478
+ pathSplineBend: B.pathSplineBend,
1479
+ pathAngle: B.pathAngle,
1480
+ pathOrientationX: B.pathOrientationX,
1481
+ pathOrientationY: B.pathOrientationY,
1482
+ pathOrientationZ: B.pathOrientationZ,
1483
+ alignToPath: B.alignToPath,
1484
+ alignToPattern: !0,
1485
+ starfieldFaceCamera: !0,
1486
+ backgroundColor: "#050505",
1487
+ backgroundMode: "solid",
1488
+ backgroundGradientDirection: "y",
1489
+ backgroundGradientMidpoint: .5,
1490
+ backgroundGradientEasing: "linear",
1491
+ backgroundGradientCustomBezier: q,
1492
+ backgroundGradientColorA: "#050505",
1493
+ backgroundGradientColorB: "#3fc6ff",
1494
+ backgroundImageUrl: "",
1495
+ backgroundImageFit: "fill",
1496
+ objectColor: "#f2f2f2",
1497
+ colorMode: "solid",
1498
+ gradientScope: "object",
1499
+ gradientDirection: "x",
1500
+ gradientMidpoint: .5,
1501
+ gradientEasing: "linear",
1502
+ gradientCustomBezier: q,
1503
+ gradientColorA: "#3fc6ff",
1504
+ gradientColorB: "#f26df9",
1505
+ materialTextureUrl: "",
1506
+ materialTextureScope: "object",
1507
+ materialTextureProjection: "box",
1508
+ materialTextureFit: "fill",
1509
+ materialTextureRepeatX: 1,
1510
+ materialTextureRepeatY: 1,
1511
+ materialTextureOffsetX: 0,
1512
+ materialTextureOffsetY: 0,
1513
+ materialTextureRotation: 0,
1514
+ shadingMode: "flat",
1515
+ silhouetteColor: "#050505",
1516
+ edgeColor: "#050505",
1517
+ outlineThickness: .01,
1518
+ edgeThickness: .001,
1519
+ outlineOpacity: 1,
1520
+ outlineSeeThrough: !1,
1521
+ edgeCompositing: "overlay",
1522
+ ambientIntensity: 2.2,
1523
+ lightIntensity: 1.6,
1524
+ lightAzimuth: Math.atan2(10, 8),
1525
+ lightElevation: Math.atan2(14, Math.hypot(8, 10)),
1526
+ renderPixelRatio: F.renderer.maxPixelRatio,
1527
+ roughness: .72,
1528
+ metalness: .02
1529
+ }, Gt = 26, Kt = 26;
1530
+ function qt(e) {
1531
+ return {
1532
+ instance: {
1533
+ shape: e.instanceShape,
1534
+ scaleX: e.scaleX,
1535
+ scaleY: e.scaleY,
1536
+ scaleZ: e.scaleZ,
1537
+ detail: e.geometryDetail,
1538
+ roundedCardRatio: e.roundedCardRatio,
1539
+ roundedCardRadius: e.roundedCardRadius,
1540
+ roundedCardAxis: e.roundedCardAxis,
1541
+ imageCornerRadius: e.imageCornerRadius,
1542
+ textValue: e.textValue,
1543
+ textFont: s(e.textFontSource),
1544
+ textFontSource: e.textFontSource,
1545
+ textCustomFontUrl: a(e.textFontSource),
1546
+ textSolidify: e.textSolidify,
1547
+ svgSolidify: e.svgSolidify,
1548
+ textLetterSpacing: e.textLetterSpacing,
1549
+ textLineHeight: e.textLineHeight,
1550
+ textMaxLineLength: e.textMaxLineLength,
1551
+ assetUrl: e.assetUrl,
1552
+ assetScale: e.assetScale,
1553
+ assetNormalize: e.assetNormalize,
1554
+ assetDoubleSided: e.assetDoubleSided,
1555
+ imageSetUrls: e.imageSetUrls,
1556
+ imageAspectRatio: e.imageAspectRatio,
1557
+ imagePreserveAspectRatio: e.imagePreserveAspectRatio,
1558
+ baseY: e.baseY,
1559
+ groundAlign: e.groundAlign,
1560
+ rotation: {
1561
+ x: e.instanceRotationX,
1562
+ y: e.instanceRotationY,
1563
+ z: e.instanceRotationZ
1564
+ },
1565
+ color: e.objectColor,
1566
+ colorMode: e.colorMode,
1567
+ gradientScope: e.gradientScope,
1568
+ gradientDirection: e.gradientDirection,
1569
+ gradientMidpoint: e.gradientMidpoint,
1570
+ gradientEasing: e.gradientEasing,
1571
+ gradientCustomBezier: e.gradientCustomBezier,
1572
+ gradientColorA: e.gradientColorA,
1573
+ gradientColorB: e.gradientColorB,
1574
+ materialTextureUrl: e.materialTextureUrl,
1575
+ materialTextureScope: e.materialTextureScope,
1576
+ materialTextureProjection: e.materialTextureProjection,
1577
+ materialTextureFit: e.materialTextureFit,
1578
+ materialTextureRepeatX: e.materialTextureRepeatX,
1579
+ materialTextureRepeatY: e.materialTextureRepeatY,
1580
+ materialTextureOffsetX: e.materialTextureOffsetX,
1581
+ materialTextureOffsetY: e.materialTextureOffsetY,
1582
+ materialTextureRotation: e.materialTextureRotation
1583
+ },
1584
+ distribution: {
1585
+ type: e.distributionMode,
1586
+ gridSize: e.gridSize,
1587
+ instanceLimit: e.instanceLimit,
1588
+ gridSpacing: e.gridSpacing,
1589
+ gridLayers: e.gridLayers,
1590
+ gridLayerSpacing: e.gridLayerSpacing,
1591
+ ringSpacing: e.ringSpacing,
1592
+ ringCount: e.ringCount,
1593
+ ringDensity: e.ringDensity,
1594
+ ringSpacingFactor: e.ringSpacingFactor,
1595
+ pathInstanceCount: e.pathInstanceCount,
1596
+ pathRadius: e.pathRadius,
1597
+ pathLength: e.pathLength,
1598
+ pathCurvature: e.pathCurvature,
1599
+ spiralTurns: e.spiralTurns,
1600
+ sphereHemisphere: e.sphereHemisphere,
1601
+ pathRows: e.pathRows,
1602
+ pathRowSpacing: e.pathRowSpacing,
1603
+ pathRowAlignment: e.pathRowAlignment,
1604
+ pathRowPhase: e.pathRowPhase,
1605
+ pathCurvePhaseDegrees: e.pathCurvePhaseDegrees,
1606
+ pathSplineBend: e.pathSplineBend,
1607
+ pathAngle: e.pathAngle,
1608
+ pathOrientationX: e.pathOrientationX,
1609
+ pathOrientationY: e.pathOrientationY,
1610
+ pathOrientationZ: e.pathOrientationZ,
1611
+ alignToPath: e.alignToPath,
1612
+ alignToPattern: e.alignToPattern,
1613
+ starfieldFaceCamera: e.starfieldFaceCamera
1614
+ },
1615
+ motion: {
1616
+ mode: e.animationMode,
1617
+ instanceSpinX: e.instanceSpinX,
1618
+ instanceSpinY: e.instanceSpinY,
1619
+ instanceSpinZ: e.instanceSpinZ,
1620
+ instanceSpinStagger: e.instanceSpinStagger,
1621
+ instanceSpinStaggerMode: e.instanceSpinStaggerMode,
1622
+ instanceSpinPhaseStagger: e.instanceSpinPhaseStagger,
1623
+ pathRotationX: e.pathRotationX,
1624
+ pathRotationY: e.pathRotationY,
1625
+ pathRotationZ: e.pathRotationZ,
1626
+ pathTravelMode: e.pathTravelMode,
1627
+ pathTravelSpeed: e.pathTravelSpeed,
1628
+ pathTravelStepDistance: e.pathTravelStepDistance,
1629
+ pathTravelStepInterval: e.pathTravelStepInterval,
1630
+ pathTravelStepDuration: e.pathTravelStepDuration,
1631
+ pathTravelStepEasing: e.pathTravelStepEasing,
1632
+ pathTravelStepCustomBezier: e.pathTravelStepCustomBezier,
1633
+ pathTravelStepStagger: e.pathTravelStepStagger,
1634
+ ringOrbitSpeed: e.ringOrbitSpeed,
1635
+ ringOrbitFriction: e.ringOrbitFriction,
1636
+ waveAmplitude: e.waveAmplitude,
1637
+ waveFrequency: e.waveFrequency,
1638
+ waveSpeed: e.waveSpeed,
1639
+ easingMode: e.easingMode,
1640
+ easingStrength: e.easingStrength,
1641
+ easingCustomBezier: e.easingCustomBezier,
1642
+ fadeDuration: e.fadeDuration,
1643
+ fadeEasing: e.fadeEasing,
1644
+ fadeCustomBezier: e.fadeCustomBezier,
1645
+ pathEdgeFadeDuration: e.pathEdgeFadeDuration,
1646
+ pathEdgeFadeEasing: e.pathEdgeFadeEasing,
1647
+ pathEdgeFadeCustomBezier: e.pathEdgeFadeCustomBezier,
1648
+ buildFadeEnabled: e.buildFadeEnabled,
1649
+ buildSceneZoomEnabled: e.buildSceneZoomEnabled,
1650
+ buildSceneZoomStartScale: e.buildSceneZoomStartScale,
1651
+ buildZoomEnabled: e.buildZoomEnabled,
1652
+ buildZoomStartScale: e.buildZoomStartScale,
1653
+ buildDropEnabled: e.buildDropEnabled,
1654
+ buildDropOffsetY: e.buildDropOffsetY,
1655
+ buildRotateEnabled: e.buildRotateEnabled,
1656
+ buildRotateAxis: e.buildRotateAxis,
1657
+ buildRotateOffset: e.buildRotateOffset,
1658
+ buildDuration: e.buildDuration,
1659
+ buildDelay: e.buildDelay,
1660
+ buildEasing: e.buildEasing,
1661
+ buildCustomBezier: e.buildCustomBezier,
1662
+ staggerAmount: e.staggerAmount,
1663
+ scaleMode: e.scaleMode,
1664
+ scaleAmount: e.scaleAmount
1665
+ },
1666
+ view: {
1667
+ camera: {
1668
+ distance: e.cameraDistance,
1669
+ azimuth: e.cameraOrbitAngle,
1670
+ elevation: e.cameraElevation,
1671
+ target: {
1672
+ x: e.cameraTargetX,
1673
+ y: e.cameraTargetY,
1674
+ z: e.cameraTargetZ
1675
+ }
1676
+ },
1677
+ viewMode: e.viewMode,
1678
+ orthographicView: e.orthographicView,
1679
+ orthoScale: e.orthoScale,
1680
+ cameraFocalLength: e.cameraFocalLength,
1681
+ backgroundColor: e.backgroundColor,
1682
+ backgroundMode: e.backgroundMode,
1683
+ backgroundGradientDirection: e.backgroundGradientDirection,
1684
+ backgroundGradientMidpoint: e.backgroundGradientMidpoint,
1685
+ backgroundGradientEasing: e.backgroundGradientEasing,
1686
+ backgroundGradientCustomBezier: e.backgroundGradientCustomBezier,
1687
+ backgroundGradientColorA: e.backgroundGradientColorA,
1688
+ backgroundGradientColorB: e.backgroundGradientColorB,
1689
+ backgroundImageUrl: e.backgroundImageUrl,
1690
+ backgroundImageFit: e.backgroundImageFit,
1691
+ shadingMode: e.shadingMode,
1692
+ silhouetteColor: e.silhouetteColor,
1693
+ edgeColor: e.edgeColor,
1694
+ outlineThickness: e.outlineThickness,
1695
+ edgeThickness: e.edgeThickness,
1696
+ outlineOpacity: e.outlineOpacity,
1697
+ outlineSeeThrough: e.outlineSeeThrough,
1698
+ edgeCompositing: e.edgeCompositing,
1699
+ ambientIntensity: e.ambientIntensity,
1700
+ lightIntensity: e.lightIntensity,
1701
+ lightAzimuth: e.lightAzimuth,
1702
+ lightElevation: e.lightElevation,
1703
+ renderPixelRatio: e.renderPixelRatio,
1704
+ roughness: e.roughness,
1705
+ metalness: e.metalness
1706
+ }
1707
+ };
1708
+ }
1709
+ function Jt(e) {
1710
+ return e === "surface" ? "surface" : $.edgeCompositing;
1711
+ }
1712
+ function Yt(e) {
1713
+ return e === "gradient" || e === "texture" ? e : $.colorMode;
1714
+ }
1715
+ function Xt(e, t) {
1716
+ return e === "transparent" ? "transparent" : e === "gradient" || e === "image" || e === "solid" ? e === "image" && !t ? $.backgroundMode : e : t ? "image" : $.backgroundMode;
1717
+ }
1718
+ function Zt(e) {
1719
+ return e === "object" ? "object" : $.gradientScope;
1720
+ }
1721
+ function Qt(e) {
1722
+ return e === "x" || e === "radial" ? e : $.backgroundGradientDirection;
1723
+ }
1724
+ function $t(e) {
1725
+ return e === "fit" ? "fit" : $.backgroundImageFit;
1726
+ }
1727
+ function en(e) {
1728
+ return e === "y" || e === "z" || e === "radial" || e === "path" ? e : $.gradientDirection;
1729
+ }
1730
+ function tn(e) {
1731
+ return e === "stretch" || e === "fit" || e === "repeat" ? e : $.materialTextureFit;
1732
+ }
1733
+ function nn(e) {
1734
+ return e === "triplanar" ? e : $.materialTextureProjection;
1735
+ }
1736
+ function rn(e) {
1737
+ return e === "pattern" ? "pattern" : $.materialTextureScope;
1738
+ }
1739
+ function an(e) {
1740
+ return e === "stepped" ? "stepped" : $.pathTravelMode;
1741
+ }
1742
+ var on = new Set([
1743
+ "cube",
1744
+ "cylinder",
1745
+ "sphere",
1746
+ "pill",
1747
+ "rounded-cube",
1748
+ "rounded-card",
1749
+ "cone",
1750
+ "torus",
1751
+ "text",
1752
+ "svg",
1753
+ "image",
1754
+ "custom-obj"
1755
+ ]);
1756
+ function sn(e) {
1757
+ return typeof e == "string" && on.has(e) ? e : $.instanceShape;
1758
+ }
1759
+ function cn(e) {
1760
+ return typeof e == "number" && Number.isFinite(e) ? u.MathUtils.clamp(e, .01, .99) : $.gradientMidpoint;
1761
+ }
1762
+ function ln(e, t) {
1763
+ if (typeof e != "string") return t;
1764
+ let n = e.trim();
1765
+ return /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(n) ? n : t;
1766
+ }
1767
+ function un(e) {
1768
+ return e === "x" || e === "z" ? e : $.roundedCardAxis;
1769
+ }
1770
+ function dn(e) {
1771
+ return e === "x" || e === "y" || e === "z" ? e : $.buildRotateAxis;
1772
+ }
1773
+ function fn(e) {
1774
+ return e === "ring-path" || e === "line-path" || e === "spiral-path" || e === "spline-path";
1775
+ }
1776
+ function pn(e, t, n) {
1777
+ let r = e / 2, i = t / 2, a = Math.min(n, r, i), o = new u.Shape();
1778
+ o.moveTo(-r + a, -i), o.lineTo(r - a, -i), o.quadraticCurveTo(r, -i, r, -i + a), o.lineTo(r, i - a), o.quadraticCurveTo(r, i, r - a, i), o.lineTo(-r + a, i), o.quadraticCurveTo(-r, i, -r, i - a), o.lineTo(-r, -i + a), o.quadraticCurveTo(-r, -i, -r + a, -i);
1779
+ let s = new u.ShapeGeometry(o, 12), c = s.attributes.position, l = s.attributes.uv;
1780
+ for (let n = 0; n < c.count; n += 1) l.setXY(n, (c.getX(n) + r) / e, (c.getY(n) + i) / t);
1781
+ return l.needsUpdate = !0, s;
1782
+ }
1783
+ function mn(e) {
1784
+ return e === "perspective" ? "perspective" : $.viewMode;
1785
+ }
1786
+ function hn(e) {
1787
+ return e ? e.orthographicView ?? $.orthographicView : $.orthographicView;
1788
+ }
1789
+ function gn(e) {
1790
+ return Array.isArray(e) ? e.map((e) => typeof e == "string" ? e.trim() : "").filter(Boolean).slice(0, Ut) : [];
1791
+ }
1792
+ function _n(e) {
1793
+ return /^[a-z][a-z\d+.-]*:/i.test(e) ? e : e.split("/").map((e) => {
1794
+ if (!e) return e;
1795
+ try {
1796
+ return encodeURIComponent(decodeURIComponent(e));
1797
+ } catch {
1798
+ return encodeURIComponent(e);
1799
+ }
1800
+ }).join("/");
1801
+ }
1802
+ function vn(e) {
1803
+ let t = qt($), n = e.instance ?? t.instance, i = e.distribution ?? t.distribution, o = e.motion ?? t.motion, c = e.view ?? t.view, l = c.camera ?? t.view.camera, u = Ne({
1804
+ distance: L(l?.distance, $.cameraDistance, F.camera.distance),
1805
+ azimuth: l?.azimuth,
1806
+ elevation: l?.elevation,
1807
+ target: l?.target ?? {}
1808
+ }), d = Ie(u), f = ze({
1809
+ distributionMode: i.type,
1810
+ gridSize: i.gridSize,
1811
+ gridSpacing: i.gridSpacing,
1812
+ gridLayers: i.gridLayers,
1813
+ gridLayerSpacing: i.gridLayerSpacing,
1814
+ ringSpacing: i.ringSpacing,
1815
+ ringCount: i.ringCount,
1816
+ ringDensity: i.ringDensity,
1817
+ pathInstanceCount: i.pathInstanceCount,
1818
+ pathRadius: i.pathRadius,
1819
+ pathLength: i.pathLength,
1820
+ pathCurvature: i.pathCurvature,
1821
+ spiralTurns: i.spiralTurns,
1822
+ sphereHemisphere: i.sphereHemisphere,
1823
+ pathRows: i.pathRows,
1824
+ pathRowSpacing: i.pathRowSpacing,
1825
+ pathRowAlignment: i.pathRowAlignment,
1826
+ pathRowPhase: i.pathRowPhase,
1827
+ pathCurvePhaseDegrees: i.pathCurvePhaseDegrees,
1828
+ pathSplineBend: i.pathSplineBend,
1829
+ pathAngle: i.pathAngle,
1830
+ pathOrientationX: i.pathOrientationX,
1831
+ pathOrientationY: i.pathOrientationY,
1832
+ pathOrientationZ: i.pathOrientationZ,
1833
+ alignToPath: i.alignToPath
1834
+ }), p = {
1835
+ scaleX: L(n.scaleX, $.scaleX, F.instance.dimension),
1836
+ scaleY: L(n.scaleY, $.scaleY, F.instance.dimension),
1837
+ scaleZ: L(n.scaleZ, $.scaleZ, F.instance.dimension)
1838
+ }, m = r(n.textFontSource), h = L(n.roundedCardRadius, $.roundedCardRadius, F.instance.cornerRadius), g = L(n.imageCornerRadius, $.imageCornerRadius, F.instance.cornerRadius), _ = L(n.textLineHeight, $.textLineHeight, F.text.lineHeight), v = Math.round(L(n.textMaxLineLength, $.textMaxLineLength, F.text.maxLineLength)), y = L(n.assetScale, $.assetScale, F.instance.assetScale), b = L(n.imageAspectRatio, $.imageAspectRatio, F.instance.aspectRatio), x = gn(n.imageSetUrls), ee = typeof c.backgroundImageUrl == "string" ? c.backgroundImageUrl.trim() : $.backgroundImageUrl, S = typeof n.materialTextureUrl == "string" ? n.materialTextureUrl.trim() : $.materialTextureUrl, C = L(c.orthoScale, $.orthoScale, F.camera.orthographicScale), w = L(c.cameraFocalLength, $.cameraFocalLength, F.camera.focalLength);
1839
+ return {
1840
+ gridSize: f.gridSize,
1841
+ instanceLimit: Math.round(L(i.instanceLimit, $.instanceLimit, F.distribution.instanceLimit)),
1842
+ gridSpacing: f.gridSpacing,
1843
+ gridLayers: f.gridLayers,
1844
+ gridLayerSpacing: f.gridLayerSpacing,
1845
+ ringSpacing: f.ringSpacing,
1846
+ ringCount: f.ringCount,
1847
+ ringDensity: f.ringDensity,
1848
+ instanceShape: sn(n.shape),
1849
+ scaleX: p.scaleX,
1850
+ scaleY: p.scaleY,
1851
+ scaleZ: p.scaleZ,
1852
+ geometryDetail: n.detail ?? $.geometryDetail,
1853
+ roundedCardRatio: I(n.roundedCardRatio, $.roundedCardRatio),
1854
+ roundedCardRadius: h,
1855
+ roundedCardAxis: un(n.roundedCardAxis),
1856
+ imageCornerRadius: g,
1857
+ textValue: n.textValue ?? $.textValue,
1858
+ textFont: s(m),
1859
+ textFontSource: m,
1860
+ textCustomFontUrl: a(m),
1861
+ textSolidify: n.textSolidify ?? $.textSolidify,
1862
+ svgSolidify: n.svgSolidify ?? $.svgSolidify,
1863
+ textLetterSpacing: I(n.textLetterSpacing, $.textLetterSpacing),
1864
+ textLineHeight: _,
1865
+ textMaxLineLength: v,
1866
+ assetUrl: n.assetUrl ?? $.assetUrl,
1867
+ assetScale: y,
1868
+ assetNormalize: n.assetNormalize ?? $.assetNormalize,
1869
+ assetDoubleSided: n.assetDoubleSided ?? $.assetDoubleSided,
1870
+ imageSetUrls: x,
1871
+ imageAspectRatio: b,
1872
+ imagePreserveAspectRatio: n.imagePreserveAspectRatio ?? $.imagePreserveAspectRatio,
1873
+ baseY: I(n.baseY, $.baseY),
1874
+ groundAlign: n.groundAlign ?? $.groundAlign,
1875
+ instanceRotationX: I(n.rotation?.x, $.instanceRotationX),
1876
+ instanceRotationY: I(n.rotation?.y, $.instanceRotationY),
1877
+ instanceRotationZ: I(n.rotation?.z, $.instanceRotationZ),
1878
+ viewMode: mn(c.viewMode),
1879
+ orthographicView: hn(c),
1880
+ orthoScale: C,
1881
+ cameraFocalLength: w,
1882
+ cameraDistance: d.cameraDistance,
1883
+ cameraHeight: d.cameraHeight,
1884
+ cameraOrbitAngle: d.cameraOrbitAngle,
1885
+ cameraElevation: u.elevation,
1886
+ cameraPositionX: d.cameraPositionX,
1887
+ cameraPositionY: d.cameraPositionY,
1888
+ cameraPositionZ: d.cameraPositionZ,
1889
+ cameraTargetX: d.cameraTargetX,
1890
+ cameraTargetY: d.cameraTargetY,
1891
+ cameraTargetZ: d.cameraTargetZ,
1892
+ distributionMode: f.distributionMode,
1893
+ animationMode: o.mode ?? $.animationMode,
1894
+ instanceSpinX: I(o.instanceSpinX, $.instanceSpinX),
1895
+ instanceSpinY: I(o.instanceSpinY, $.instanceSpinY),
1896
+ instanceSpinZ: I(o.instanceSpinZ, $.instanceSpinZ),
1897
+ instanceSpinStagger: I(o.instanceSpinStagger, $.instanceSpinStagger),
1898
+ instanceSpinStaggerMode: o.instanceSpinStaggerMode ?? $.instanceSpinStaggerMode,
1899
+ instanceSpinPhaseStagger: I(o.instanceSpinPhaseStagger, $.instanceSpinPhaseStagger),
1900
+ pathRotationX: I(o.pathRotationX, $.pathRotationX),
1901
+ pathRotationY: I(o.pathRotationY, $.pathRotationY),
1902
+ pathRotationZ: I(o.pathRotationZ, $.pathRotationZ),
1903
+ pathTravelMode: an(o.pathTravelMode),
1904
+ pathTravelSpeed: I(o.pathTravelSpeed, $.pathTravelSpeed),
1905
+ pathTravelStepDistance: I(o.pathTravelStepDistance, $.pathTravelStepDistance),
1906
+ pathTravelStepInterval: L(o.pathTravelStepInterval, $.pathTravelStepInterval, {
1907
+ min: .001,
1908
+ max: 60
1909
+ }),
1910
+ pathTravelStepDuration: L(o.pathTravelStepDuration, $.pathTravelStepDuration, {
1911
+ min: 0,
1912
+ max: 60
1913
+ }),
1914
+ pathTravelStepEasing: J(o.pathTravelStepEasing, $.pathTravelStepEasing),
1915
+ pathTravelStepCustomBezier: Y(o.pathTravelStepCustomBezier, $.pathTravelStepCustomBezier),
1916
+ pathTravelStepStagger: L(o.pathTravelStepStagger, $.pathTravelStepStagger, {
1917
+ min: 0,
1918
+ max: 60
1919
+ }),
1920
+ ringOrbitSpeed: I(o.ringOrbitSpeed, $.ringOrbitSpeed),
1921
+ ringOrbitFriction: L(o.ringOrbitFriction, $.ringOrbitFriction, F.motion.ringOrbitFriction),
1922
+ waveAmplitude: I(o.waveAmplitude, $.waveAmplitude),
1923
+ waveFrequency: I(o.waveFrequency, $.waveFrequency),
1924
+ waveSpeed: I(o.waveSpeed, $.waveSpeed),
1925
+ easingMode: J(o.easingMode, $.easingMode),
1926
+ easingStrength: L(o.easingStrength, $.easingStrength, F.motion.easingStrength),
1927
+ easingCustomBezier: Y(o.easingCustomBezier, $.easingCustomBezier),
1928
+ fadeDuration: L(o.fadeDuration, $.fadeDuration, F.motion.fadeDuration),
1929
+ fadeEasing: J(o.fadeEasing, $.fadeEasing),
1930
+ fadeCustomBezier: Y(o.fadeCustomBezier, $.fadeCustomBezier),
1931
+ pathEdgeFadeDuration: L(o.pathEdgeFadeDuration, $.pathEdgeFadeDuration, F.motion.fadeDuration),
1932
+ pathEdgeFadeEasing: J(o.pathEdgeFadeEasing, $.pathEdgeFadeEasing),
1933
+ pathEdgeFadeCustomBezier: Y(o.pathEdgeFadeCustomBezier, $.pathEdgeFadeCustomBezier),
1934
+ buildFadeEnabled: o.buildFadeEnabled ?? $.buildFadeEnabled,
1935
+ buildSceneZoomEnabled: o.buildSceneZoomEnabled ?? $.buildSceneZoomEnabled,
1936
+ buildSceneZoomStartScale: L(o.buildSceneZoomStartScale, $.buildSceneZoomStartScale, F.motion.buildZoomStartScale),
1937
+ buildZoomEnabled: o.buildZoomEnabled ?? $.buildZoomEnabled,
1938
+ buildZoomStartScale: L(o.buildZoomStartScale, $.buildZoomStartScale, F.motion.buildZoomStartScale),
1939
+ buildDropEnabled: o.buildDropEnabled ?? $.buildDropEnabled,
1940
+ buildDropOffsetY: I(o.buildDropOffsetY, $.buildDropOffsetY),
1941
+ buildRotateEnabled: o.buildRotateEnabled ?? $.buildRotateEnabled,
1942
+ buildRotateAxis: dn(o.buildRotateAxis),
1943
+ buildRotateOffset: I(o.buildRotateOffset, $.buildRotateOffset),
1944
+ buildDuration: L(o.buildDuration, $.buildDuration, F.motion.fadeDuration),
1945
+ buildDelay: L(o.buildDelay, $.buildDelay, F.motion.fadeDuration),
1946
+ buildEasing: J(o.buildEasing, $.buildEasing),
1947
+ buildCustomBezier: Y(o.buildCustomBezier, $.buildCustomBezier),
1948
+ staggerAmount: I(o.staggerAmount, $.staggerAmount),
1949
+ scaleMode: o.scaleMode ?? $.scaleMode,
1950
+ scaleAmount: I(o.scaleAmount, $.scaleAmount),
1951
+ ringSpacingFactor: I(i.ringSpacingFactor, $.ringSpacingFactor),
1952
+ pathInstanceCount: f.pathInstanceCount,
1953
+ pathRadius: f.pathRadius,
1954
+ pathLength: f.pathLength,
1955
+ pathCurvature: f.pathCurvature,
1956
+ spiralTurns: f.spiralTurns,
1957
+ sphereHemisphere: f.sphereHemisphere,
1958
+ pathRows: f.pathRows,
1959
+ pathRowSpacing: f.pathRowSpacing,
1960
+ pathRowAlignment: f.pathRowAlignment,
1961
+ pathRowPhase: f.pathRowPhase,
1962
+ pathCurvePhaseDegrees: f.pathCurvePhaseDegrees,
1963
+ pathSplineBend: f.pathSplineBend,
1964
+ pathAngle: f.pathAngle,
1965
+ pathOrientationX: f.pathOrientationX,
1966
+ pathOrientationY: f.pathOrientationY,
1967
+ pathOrientationZ: f.pathOrientationZ,
1968
+ alignToPath: f.alignToPath,
1969
+ alignToPattern: i.alignToPattern ?? $.alignToPattern,
1970
+ starfieldFaceCamera: i.starfieldFaceCamera ?? $.starfieldFaceCamera,
1971
+ backgroundColor: ln(c.backgroundColor, $.backgroundColor),
1972
+ backgroundMode: Xt(c.backgroundMode, !!ee),
1973
+ backgroundGradientDirection: Qt(c.backgroundGradientDirection),
1974
+ backgroundGradientMidpoint: cn(c.backgroundGradientMidpoint),
1975
+ backgroundGradientEasing: J(c.backgroundGradientEasing, $.backgroundGradientEasing),
1976
+ backgroundGradientCustomBezier: Y(c.backgroundGradientCustomBezier, $.backgroundGradientCustomBezier),
1977
+ backgroundGradientColorA: ln(c.backgroundGradientColorA, $.backgroundGradientColorA),
1978
+ backgroundGradientColorB: ln(c.backgroundGradientColorB, $.backgroundGradientColorB),
1979
+ backgroundImageUrl: ee,
1980
+ backgroundImageFit: $t(c.backgroundImageFit),
1981
+ objectColor: ln(n.color, $.objectColor),
1982
+ colorMode: S ? Yt(n.colorMode) : n.colorMode === "texture" ? $.colorMode : Yt(n.colorMode),
1983
+ gradientScope: Zt(n.gradientScope),
1984
+ gradientDirection: en(n.gradientDirection),
1985
+ gradientMidpoint: cn(n.gradientMidpoint),
1986
+ gradientEasing: J(n.gradientEasing, $.gradientEasing),
1987
+ gradientCustomBezier: Y(n.gradientCustomBezier, $.gradientCustomBezier),
1988
+ gradientColorA: ln(n.gradientColorA, $.gradientColorA),
1989
+ gradientColorB: ln(n.gradientColorB, $.gradientColorB),
1990
+ materialTextureUrl: S,
1991
+ materialTextureScope: rn(n.materialTextureScope),
1992
+ materialTextureProjection: nn(n.materialTextureProjection),
1993
+ materialTextureFit: tn(n.materialTextureFit),
1994
+ materialTextureRepeatX: I(n.materialTextureRepeatX, $.materialTextureRepeatX),
1995
+ materialTextureRepeatY: I(n.materialTextureRepeatY, $.materialTextureRepeatY),
1996
+ materialTextureOffsetX: I(n.materialTextureOffsetX, $.materialTextureOffsetX),
1997
+ materialTextureOffsetY: I(n.materialTextureOffsetY, $.materialTextureOffsetY),
1998
+ materialTextureRotation: I(n.materialTextureRotation, $.materialTextureRotation),
1999
+ shadingMode: c.shadingMode ?? $.shadingMode,
2000
+ silhouetteColor: c.silhouetteColor ?? c.outlineColor ?? $.silhouetteColor,
2001
+ edgeColor: c.edgeColor ?? c.outlineColor ?? $.edgeColor,
2002
+ outlineThickness: L(c.outlineThickness, $.outlineThickness, F.render.thickness),
2003
+ edgeThickness: L(c.edgeThickness, $.edgeThickness, F.render.thickness),
2004
+ outlineOpacity: L(c.outlineOpacity, $.outlineOpacity, F.render.opacity),
2005
+ outlineSeeThrough: c.outlineSeeThrough ?? $.outlineSeeThrough,
2006
+ edgeCompositing: Jt(c.edgeCompositing),
2007
+ ambientIntensity: L(c.ambientIntensity, $.ambientIntensity, F.render.nonNegativeIntensity),
2008
+ lightIntensity: L(c.lightIntensity, $.lightIntensity, F.render.nonNegativeIntensity),
2009
+ lightAzimuth: I(c.lightAzimuth, $.lightAzimuth),
2010
+ lightElevation: L(c.lightElevation, $.lightElevation, F.render.lightElevation),
2011
+ renderPixelRatio: L(c.renderPixelRatio, $.renderPixelRatio, F.renderer.pixelRatio),
2012
+ roughness: L(c.roughness, $.roughness, F.render.materialFactor),
2013
+ metalness: L(c.metalness, $.metalness, F.render.materialFactor)
2014
+ };
2015
+ }
2016
+ function yn(e) {
2017
+ return qt(vn(e));
2018
+ }
2019
+ var bn = class {
2020
+ settings = { ...$ };
2021
+ assetUrlAliases = /* @__PURE__ */ new Map();
2022
+ getConfig() {
2023
+ return this.applyAssetUrlAliases(), qt(this.settings);
2024
+ }
2025
+ replaceAssetUrl(e, t) {
2026
+ return !e || !t || e === t ? !1 : (this.assetUrlAliases.set(e, t), this.applyAssetUrlAliases(), !0);
2027
+ }
2028
+ applyAssetUrlAliases() {
2029
+ if (this.assetUrlAliases.size === 0) return;
2030
+ let e = (e) => this.assetUrlAliases.get(e) ?? e;
2031
+ this.settings.assetUrl = e(this.settings.assetUrl), this.settings.backgroundImageUrl = e(this.settings.backgroundImageUrl), this.settings.materialTextureUrl = e(this.settings.materialTextureUrl), this.settings.imageSetUrls.some((e) => this.assetUrlAliases.has(e)) && (this.settings.imageSetUrls = this.settings.imageSetUrls.map(e)), this.settings.textCustomFontUrl = e(this.settings.textCustomFontUrl), this.settings.textFontSource.source === "url" && this.assetUrlAliases.has(this.settings.textFontSource.url) && (this.settings.textFontSource = {
2032
+ source: "url",
2033
+ url: e(this.settings.textFontSource.url)
2034
+ });
2035
+ }
2036
+ setConfig(e) {
2037
+ this.startTime = performance.now(), this.previousAnimationElapsed = 0, this.pathTravelProgress = 0, this.ringOrbitProgress = 0, this.scaleBeforeShapeDefault = null, this.shapeAutoModified = {
2038
+ x: !1,
2039
+ y: !1,
2040
+ z: !1
2041
+ }, this.customAssetLoadId += 1, this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.imageTexture?.dispose(), this.imageTexture = null, this.materialTexture?.dispose(), this.materialTexture = null, this.materialTextureDisplayTexture?.dispose(), this.materialTextureDisplayTexture = null, this.checkerTexture?.dispose(), this.checkerTexture = null, this.backgroundTexture?.dispose(), this.backgroundTexture = null, this.backgroundImageDisplayTexture?.dispose(), this.backgroundImageDisplayTexture = null, this.backgroundGradientTexture?.dispose(), this.backgroundGradientTexture = null, this.transparentBackgroundPreviewTexture?.dispose(), this.transparentBackgroundPreviewTexture = null, Object.assign(this.settings, vn(e)), this.modeMemory = new Map([[this.settings.distributionMode, this.snapshotModeSettings()]]), this.settings.assetUrl.startsWith("blob:") && (this.settings.assetUrl = ""), this.settings.imageSetUrls.some((e) => e.startsWith("blob:")) && (this.settings.imageSetUrls = this.settings.imageSetUrls.filter((e) => !e.startsWith("blob:"))), this.settings.backgroundImageUrl.startsWith("blob:") && (this.settings.backgroundImageUrl = ""), this.settings.materialTextureUrl.startsWith("blob:") && (this.settings.materialTextureUrl = ""), this.applySettings(), this.settings.instanceShape === "custom-obj" && this.settings.assetUrl && !this.settings.assetUrl.startsWith("blob:") && this.loadCustomObj().catch((e) => {
2042
+ console.warn("Unable to load custom OBJ asset.", e);
2043
+ }), this.settings.instanceShape === "svg" && this.settings.assetUrl && !this.settings.assetUrl.startsWith("blob:") && this.loadSvgAsset().catch((e) => {
2044
+ console.warn("Unable to load SVG asset.", e);
2045
+ }), this.settings.instanceShape === "image" && (this.settings.imageSetUrls.length > 0 || this.settings.assetUrl) && !this.settings.assetUrl.startsWith("blob:") && (this.settings.imageSetUrls.length > 0 ? this.loadImageSet() : this.loadImageAsset()).catch((e) => {
2046
+ console.warn("Unable to load image asset.", e);
2047
+ }), this.settings.textFont === "custom" && this.settings.textCustomFontUrl ? this.loadCustomTextFont().catch((e) => {
2048
+ console.warn("Unable to load custom text font.", e);
2049
+ }) : t(this.settings.textFont) && this.ensureWebTextFont(this.settings.textFont).catch((e) => {
2050
+ console.warn("Unable to load text font.", e);
2051
+ }), this.settings.backgroundImageUrl && !this.settings.backgroundImageUrl.startsWith("blob:") && this.loadBackgroundImage().catch((e) => {
2052
+ console.warn("Unable to load background image.", e);
2053
+ }), this.settings.materialTextureUrl && !this.settings.materialTextureUrl.startsWith("blob:") && this.loadMaterialTexture().catch((e) => {
2054
+ console.warn("Unable to load material texture.", e), this.clearMaterialTexture();
2055
+ });
2056
+ }
2057
+ applySettings() {
2058
+ this.ensureCameraType(), this.rebuildGeometry(), this.updateCamera(), this.updateColors(), this.updatePattern();
2059
+ }
2060
+ container;
2061
+ scene;
2062
+ camera;
2063
+ frustumSize = this.getOrthographicFrustumSize();
2064
+ renderer;
2065
+ mesh;
2066
+ outlineMesh;
2067
+ edgeGroup = new u.Group();
2068
+ edgeLines = [];
2069
+ edgeGeometry = null;
2070
+ edgeMaterial = null;
2071
+ imageSetMeshes = [];
2072
+ dummy = new u.Object3D();
2073
+ alignQuatScratch = new u.Quaternion();
2074
+ manualQuatScratch = new u.Quaternion();
2075
+ spinQuatScratch = new u.Quaternion();
2076
+ orientationEulerScratch = new u.Euler();
2077
+ alignVecScratch = new u.Vector3();
2078
+ alignUpScratch = new u.Vector3();
2079
+ alignRightScratch = new u.Vector3();
2080
+ alignMatrixScratch = new u.Matrix4();
2081
+ gradientColorScratch = new u.Color();
2082
+ gradientColorAScratch = new u.Color();
2083
+ gradientColorBScratch = new u.Color();
2084
+ startTime = performance.now();
2085
+ previousAnimationElapsed = 0;
2086
+ pathTravelProgress = 0;
2087
+ ringOrbitProgress = 0;
2088
+ animationFrameId = null;
2089
+ scaleBeforeShapeDefault = null;
2090
+ shapeAutoModified = {
2091
+ x: !1,
2092
+ y: !1,
2093
+ z: !1
2094
+ };
2095
+ modeMemory = /* @__PURE__ */ new Map();
2096
+ layouts = [];
2097
+ instanceBirthTimes = [];
2098
+ fadeUntil = 0;
2099
+ ambientLight = null;
2100
+ directionalLight = null;
2101
+ customObjGeometry = null;
2102
+ customSvgGeometry = null;
2103
+ imageTexture = null;
2104
+ imageSetTextures = [];
2105
+ materialTexture = null;
2106
+ materialTextureDisplayTexture = null;
2107
+ checkerTexture = null;
2108
+ backgroundTexture = null;
2109
+ backgroundImageDisplayTexture = null;
2110
+ backgroundGradientTexture = null;
2111
+ transparentBackgroundPreviewTexture = null;
2112
+ pausedMotionSnapshot = null;
2113
+ exportSizeOverride = null;
2114
+ customAssetLoadId = 0;
2115
+ activeUserCustomAssetLoadId = 0;
2116
+ enableCameraControls = !1;
2117
+ previewTransparentBackground = !1;
2118
+ viewportGrid = null;
2119
+ cameraChangeListeners = /* @__PURE__ */ new Set();
2120
+ cameraInteractionEndListeners = /* @__PURE__ */ new Set();
2121
+ cameraCanvasControls = null;
2122
+ textureLoader = new u.TextureLoader();
2123
+ textGeometryRuntime = null;
2124
+ textFonts = null;
2125
+ textRuntimeLoadPromise = null;
2126
+ adaptiveQualityLowSamples = 0;
2127
+ adaptiveQualityHighSamples = 0;
2128
+ renderCount = 0;
2129
+ containerResizeObserver = null;
2130
+ observedWidth = 0;
2131
+ observedHeight = 0;
2132
+ disposed = !1;
2133
+ constructor(e, n = {}) {
2134
+ this.container = e, this.enableCameraControls = n.enableCameraControls ?? !1, this.previewTransparentBackground = n.previewTransparentBackground ?? !1, n.config && Object.assign(this.settings, vn(n.config)), this.settings.assetUrl.startsWith("blob:") && (this.settings.assetUrl = ""), this.settings.imageSetUrls.some((e) => e.startsWith("blob:")) && (this.settings.imageSetUrls = this.settings.imageSetUrls.filter((e) => !e.startsWith("blob:"))), this.settings.backgroundImageUrl.startsWith("blob:") && (this.settings.backgroundImageUrl = "");
2135
+ let r = this.settings.instanceShape === "custom-obj" && !!this.settings.assetUrl && !this.settings.assetUrl.startsWith("blob:"), i = this.settings.instanceShape === "image" && (this.settings.imageSetUrls.length > 0 || !!this.settings.assetUrl) && !this.settings.assetUrl.startsWith("blob:"), a = this.settings.instanceShape === "svg" && !!this.settings.assetUrl && !this.settings.assetUrl.startsWith("blob:"), o = !!this.settings.backgroundImageUrl && !this.settings.backgroundImageUrl.startsWith("blob:"), s = !!this.settings.materialTextureUrl && !this.settings.materialTextureUrl.startsWith("blob:");
2136
+ this.scene = new u.Scene(), this.scene.background = new u.Color(this.settings.backgroundColor), this.viewportGrid = n.enableViewportGrid ? this.createViewportGrid() : null, this.viewportGrid && this.scene.add(this.viewportGrid), this.camera = this.createCamera(), this.updateCamera(), this.renderer = new u.WebGLRenderer({
2137
+ antialias: !0,
2138
+ alpha: !0,
2139
+ preserveDrawingBuffer: !1
2140
+ }), this.renderer.setClearAlpha(0), this.applyRendererPixelRatio();
2141
+ let { width: c, height: l } = this.getContainerSize();
2142
+ this.renderer.setSize(c, l), this.container.appendChild(this.renderer.domElement), this.enableCameraControls && (this.cameraCanvasControls = De({
2143
+ canvas: this.renderer.domElement,
2144
+ onZoom: (e) => this.zoomCamera(e),
2145
+ onOrbit: (e, t) => this.orbitCamera(e, t),
2146
+ onPan: (e, t) => this.panCamera(e, t),
2147
+ onInteractionEnd: () => this.notifyCameraInteractionEnd()
2148
+ }));
2149
+ let d = this.createGeometry(), f = this.createMaterial();
2150
+ this.mesh = new u.InstancedMesh(d, f, this.getMaxInstanceCount()), this.mesh.renderOrder = 1, this.mesh.frustumCulled = !1, this.scene.add(this.mesh), this.outlineMesh = new u.InstancedMesh(d.clone(), this.createOutlineMaterial(), this.getMaxInstanceCount()), this.outlineMesh.renderOrder = 0, this.outlineMesh.frustumCulled = !1, this.outlineMesh.visible = this.shouldShowSilhouetteOutline(), this.scene.add(this.outlineMesh), this.edgeGeometry = this.shouldShowEdgeOutline() ? this.createEdgeGeometry(d) : null, this.edgeMaterial = this.createEdgeMaterial(), this.edgeGroup.visible = this.shouldShowEdgeOutline(), this.edgeGroup.renderOrder = this.getEdgeRenderOrder(), this.scene.add(this.edgeGroup), this.addLights(), this.updatePattern(), r && this.loadCustomObj().catch((e) => {
2151
+ console.warn("Unable to load initial custom OBJ asset.", e);
2152
+ }), i && (this.settings.imageSetUrls.length > 0 ? this.loadImageSet() : this.loadImageAsset()).catch((e) => {
2153
+ console.warn("Unable to load initial image asset.", e);
2154
+ }), a && this.loadSvgAsset().catch((e) => {
2155
+ console.warn("Unable to load initial SVG asset.", e);
2156
+ }), this.settings.textFont === "custom" && this.settings.textCustomFontUrl ? this.loadCustomTextFont().catch((e) => {
2157
+ console.warn("Unable to load initial custom text font.", e);
2158
+ }) : t(this.settings.textFont) && this.ensureWebTextFont(this.settings.textFont).catch((e) => {
2159
+ console.warn("Unable to load initial text font.", e);
2160
+ }), o && this.loadBackgroundImage().catch((e) => {
2161
+ console.warn("Unable to load initial background image.", e);
2162
+ }), s && this.loadMaterialTexture().catch((e) => {
2163
+ console.warn("Unable to load initial material texture.", e), this.clearMaterialTexture();
2164
+ }), window.addEventListener("resize", this.handleResize), this.observeContainerSize(), (n.autoStart ?? !0) && this.start();
2165
+ }
2166
+ start() {
2167
+ this.animationFrameId === null && (this.previousAnimationElapsed = (performance.now() - this.startTime) / 1e3, this.animate());
2168
+ }
2169
+ stop() {
2170
+ this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null);
2171
+ }
2172
+ dispose() {
2173
+ this.disposed || (this.disposed = !0, this.stop(), window.removeEventListener("resize", this.handleResize), this.containerResizeObserver?.disconnect(), this.containerResizeObserver = null, this.cameraCanvasControls?.dispose(), this.mesh.geometry.dispose(), Array.isArray(this.mesh.material) ? this.mesh.material.forEach((e) => e.dispose()) : this.mesh.material.dispose(), this.outlineMesh.geometry.dispose(), Array.isArray(this.outlineMesh.material) ? this.outlineMesh.material.forEach((e) => e.dispose()) : this.outlineMesh.material.dispose(), this.edgeLines.forEach((e) => {
2174
+ this.edgeGroup.remove(e);
2175
+ }), this.edgeLines = [], this.edgeGeometry?.dispose(), this.edgeMaterial?.dispose(), this.imageTexture?.dispose(), this.materialTexture?.dispose(), this.materialTextureDisplayTexture?.dispose(), this.checkerTexture?.dispose(), this.backgroundTexture?.dispose(), this.backgroundImageDisplayTexture?.dispose(), this.backgroundGradientTexture?.dispose(), this.transparentBackgroundPreviewTexture?.dispose(), this.disposeImageSetTextures(), this.disposeImageSetMeshes(), this.customObjGeometry?.dispose(), this.customSvgGeometry?.dispose(), this.renderer.dispose(), this.renderer.forceContextLoss(), this.renderer.domElement.remove());
2176
+ }
2177
+ get isDisposed() {
2178
+ return this.disposed;
2179
+ }
2180
+ capturePosterDataUrl(e = 480, t = .7) {
2181
+ try {
2182
+ let n = this.renderer.domElement;
2183
+ if (n.width === 0 || n.height === 0) return null;
2184
+ this.renderScene();
2185
+ let r = Math.min(1, e / Math.max(n.width, n.height)), i = document.createElement("canvas");
2186
+ i.width = Math.max(1, Math.round(n.width * r)), i.height = Math.max(1, Math.round(n.height * r));
2187
+ let a = i.getContext("2d");
2188
+ if (!a) return null;
2189
+ a.drawImage(n, 0, 0, i.width, i.height);
2190
+ let o = i.toDataURL("image/jpeg", t);
2191
+ return o.length > 256 ? o : null;
2192
+ } catch {
2193
+ return null;
2194
+ }
2195
+ }
2196
+ async captureFramePngBlob(e = {}) {
2197
+ let { width: t, height: n } = this.getContainerSize(), r = e.width ? Math.max(1, Math.round(e.width)) : Math.max(1, Math.round(t)), i = e.height ? Math.max(1, Math.round(e.height)) : Math.max(1, Math.round(n)), a = new u.WebGLRenderer({
2198
+ antialias: !0,
2199
+ alpha: !0,
2200
+ preserveDrawingBuffer: !0
2201
+ });
2202
+ a.setClearAlpha(0), a.setPixelRatio(1), a.setSize(r, i, !1);
2203
+ try {
2204
+ return this.renderWithTemporaryRenderSize(r, i, () => {
2205
+ this.renderScene(a);
2206
+ }), await new Promise((e, t) => {
2207
+ a.domElement.toBlob((n) => {
2208
+ if (!n) {
2209
+ t(/* @__PURE__ */ Error("Unable to capture image PNG."));
2210
+ return;
2211
+ }
2212
+ e(n);
2213
+ }, "image/png");
2214
+ });
2215
+ } finally {
2216
+ a.dispose(), a.domElement.remove(), this.restoreRendererSize();
2217
+ }
2218
+ }
2219
+ async captureVideoBlob({ durationSeconds: e, fps: t, width: n, height: r, mimeType: i, videoBitsPerSecond: a, signal: o, onProgress: s }) {
2220
+ let c = Math.max(1, Math.round(t)), l = Math.max(1, Math.round(Math.max(.1, e) * c)), d = Math.max(1, Math.round(n)), f = Math.max(1, Math.round(r)), p = new u.WebGLRenderer({
2221
+ antialias: !0,
2222
+ alpha: !0,
2223
+ preserveDrawingBuffer: !0
2224
+ });
2225
+ p.setClearAlpha(0), p.setPixelRatio(1), p.setSize(d, f, !1);
2226
+ let m = p.domElement, h = m.captureStream?.bind(m);
2227
+ if (!h || typeof MediaRecorder > "u") throw p.dispose(), Error("Video recording is not supported in this browser.");
2228
+ let g = this.getSupportedVideoMimeType(i);
2229
+ if (!g) throw p.dispose(), p.domElement.remove(), Error("No supported video encoder was found in this browser.");
2230
+ this.throwIfVideoExportAborted(o);
2231
+ let _ = h(0), v = _.getVideoTracks()[0];
2232
+ v?.requestFrame || (_.getTracks().forEach((e) => e.stop()), _ = h(c), v = _.getVideoTracks()[0]);
2233
+ let y = [], b = new MediaRecorder(_, {
2234
+ mimeType: g,
2235
+ videoBitsPerSecond: a ?? 12e6
2236
+ }), x = new Promise((e, t) => {
2237
+ b.addEventListener("dataavailable", (e) => {
2238
+ e.data.size > 0 && y.push(e.data);
2239
+ }), b.addEventListener("stop", () => e(new Blob(y, { type: g })), { once: !0 }), b.addEventListener("error", () => t(/* @__PURE__ */ Error("Video recording failed.")), { once: !0 });
2240
+ });
2241
+ try {
2242
+ b.start();
2243
+ let e = performance.now();
2244
+ for (let t = 0; t < l; t++) {
2245
+ this.throwIfVideoExportAborted(o), this.renderWithTemporaryRenderSize(d, f, () => {
2246
+ this.renderExportFrameAt(t / c, p);
2247
+ }), v?.requestFrame?.();
2248
+ let n = t + 1;
2249
+ s?.(n / l);
2250
+ let r = e + n / c * 1e3;
2251
+ await this.waitForVideoFrame(Math.max(0, r - performance.now()));
2252
+ }
2253
+ return b.stop(), {
2254
+ blob: await x,
2255
+ mimeType: g,
2256
+ extension: g.includes("mp4") ? "mp4" : "webm"
2257
+ };
2258
+ } finally {
2259
+ if (b.state !== "inactive") try {
2260
+ b.stop();
2261
+ } catch {}
2262
+ _.getTracks().forEach((e) => e.stop()), p.dispose(), p.domElement.remove(), this.restoreRendererSize();
2263
+ }
2264
+ }
2265
+ throwIfVideoExportAborted(e) {
2266
+ if (e?.aborted) throw new DOMException("Recording cancelled.", "AbortError");
2267
+ }
2268
+ getSupportedVideoMimeType(e) {
2269
+ return [
2270
+ e,
2271
+ "video/mp4;codecs=\"avc1.42E01E\"",
2272
+ "video/mp4",
2273
+ "video/webm;codecs=vp9",
2274
+ "video/webm;codecs=vp8",
2275
+ "video/webm"
2276
+ ].filter(Boolean).find((e) => MediaRecorder.isTypeSupported(e)) ?? "";
2277
+ }
2278
+ waitForVideoFrame(e) {
2279
+ return new Promise((t) => {
2280
+ window.setTimeout(t, Math.max(0, e));
2281
+ });
2282
+ }
2283
+ setTemporaryRenderSize(e, t) {
2284
+ this.exportSizeOverride = {
2285
+ width: e,
2286
+ height: t
2287
+ }, this.applyRenderSizeState(e, t);
2288
+ }
2289
+ restoreRendererSize() {
2290
+ this.exportSizeOverride = null;
2291
+ let { width: e, height: t } = this.getLiveContainerSize();
2292
+ this.renderer.setSize(e, t), this.applyRenderSizeState(e, t), this.renderIdleFrame();
2293
+ }
2294
+ renderWithTemporaryRenderSize(e, t, n) {
2295
+ let r = this.exportSizeOverride, i = this.getLiveContainerSize();
2296
+ this.setTemporaryRenderSize(e, t);
2297
+ try {
2298
+ n();
2299
+ } finally {
2300
+ this.exportSizeOverride = r;
2301
+ let e = r ?? i;
2302
+ this.applyRenderSizeState(e.width, e.height);
2303
+ }
2304
+ }
2305
+ applyRenderSizeState(e, t) {
2306
+ this.updateCameraProjection(), this.invalidateBackgroundImageDisplayTexture(), this.updateSceneBackground(), this.updateEdgeResolution(e, t);
2307
+ }
2308
+ updateEdgeResolution(e, t) {
2309
+ this.edgeMaterial?.resolution.set(e, t), this.edgeLines.forEach((n) => {
2310
+ n.material.resolution.set(e, t);
2311
+ });
2312
+ }
2313
+ onCameraChange(e) {
2314
+ return this.cameraChangeListeners.add(e), () => {
2315
+ this.cameraChangeListeners.delete(e);
2316
+ };
2317
+ }
2318
+ onCameraInteractionEnd(e) {
2319
+ return this.cameraInteractionEndListeners.add(e), () => {
2320
+ this.cameraInteractionEndListeners.delete(e);
2321
+ };
2322
+ }
2323
+ setGridSize(e) {
2324
+ this.settings.gridSize = e, this.updatePatternAndUseGeneratedLimit();
2325
+ }
2326
+ setDistributionMode(e) {
2327
+ let t = this.settings.distributionMode;
2328
+ if (t === e) {
2329
+ this.updatePatternAndUseGeneratedLimit();
2330
+ return;
2331
+ }
2332
+ this.modeMemory.set(t, this.snapshotModeSettings()), this.settings.distributionMode = e;
2333
+ let n = this.modeMemory.get(e);
2334
+ n ? Object.assign(this.settings, n) : (this.applyDistributionModeDefaults(e), e === "starfield" && this.setStarfieldFlightFromCamera(!1)), this.updatePatternAndUseGeneratedLimit();
2335
+ }
2336
+ snapshotModeSettings() {
2337
+ let e = {};
2338
+ for (let t of Wt) e[t] = this.settings[t];
2339
+ return e;
2340
+ }
2341
+ applyDistributionModeDefaults(e) {
2342
+ let t = (e, t, n) => {
2343
+ this.settings.pathInstanceCount = e, this.settings.pathRadius = t, this.settings.pathLength = n, this.settings.pathRows = 1, this.settings.pathRowSpacing = 1.2, this.settings.pathRowPhase = 0;
2344
+ };
2345
+ if (e === "single") {
2346
+ this.settings.instanceLimit = 1;
2347
+ return;
2348
+ }
2349
+ if (e === "grid") {
2350
+ this.settings.gridSize = 20, this.settings.gridSpacing = 2, this.settings.alignToPattern = !1;
2351
+ return;
2352
+ }
2353
+ if (e === "cube-grid") {
2354
+ this.settings.gridSize = 20, this.settings.gridLayers = 4, this.settings.gridSpacing = 2, this.settings.gridLayerSpacing = 2, this.settings.alignToPattern = !1;
2355
+ return;
2356
+ }
2357
+ if (e === "rings") {
2358
+ this.settings.ringCount = 6, this.settings.ringDensity = 8, this.settings.ringSpacing = 2, this.settings.alignToPattern = !0;
2359
+ return;
2360
+ }
2361
+ if (e === "ring-path") {
2362
+ t(40, 6, 12), this.settings.alignToPath = !0;
2363
+ return;
2364
+ }
2365
+ if (e === "line-path") {
2366
+ t(12, 4, 20), this.settings.pathCurvature = 0, this.settings.alignToPath = !0;
2367
+ return;
2368
+ }
2369
+ if (e === "spiral-path") {
2370
+ t(40, 8, 12), this.settings.spiralTurns = 2, this.settings.alignToPath = !0;
2371
+ return;
2372
+ }
2373
+ if (e === "sphere") {
2374
+ t(400, 20, 12), this.settings.sphereHemisphere = !1, this.settings.alignToPath = !0;
2375
+ return;
2376
+ }
2377
+ if (e === "spline-path") {
2378
+ t(20, 4, 20), this.settings.pathCurvature = 1, this.settings.alignToPath = !0;
2379
+ return;
2380
+ }
2381
+ e === "starfield" && (t(160, 18, 80), this.settings.pathTravelSpeed = .08, this.settings.waveAmplitude = 0, this.settings.pathRotationX = 0, this.settings.pathRotationY = 0, this.settings.pathRotationZ = 0, this.settings.alignToPath = !0);
2382
+ }
2383
+ resetSettings(e) {
2384
+ e.forEach((e) => {
2385
+ this.settings[e] = $[e];
2386
+ }), this.updatePattern();
2387
+ }
2388
+ resetSpin() {
2389
+ this.resetSettings([
2390
+ "instanceSpinX",
2391
+ "instanceSpinY",
2392
+ "instanceSpinZ",
2393
+ "instanceSpinStagger",
2394
+ "instanceSpinPhaseStagger",
2395
+ "instanceSpinStaggerMode",
2396
+ "pathRotationX",
2397
+ "pathRotationY",
2398
+ "pathRotationZ"
2399
+ ]);
2400
+ }
2401
+ resetWave() {
2402
+ this.resetSettings([
2403
+ "animationMode",
2404
+ "waveAmplitude",
2405
+ "waveSpeed",
2406
+ "waveFrequency",
2407
+ "staggerAmount",
2408
+ "easingMode",
2409
+ "easingCustomBezier"
2410
+ ]);
2411
+ }
2412
+ resetAppear() {
2413
+ this.resetSettings([
2414
+ "fadeDuration",
2415
+ "fadeEasing",
2416
+ "fadeCustomBezier"
2417
+ ]);
2418
+ }
2419
+ resetBuild() {
2420
+ this.resetSettings([
2421
+ "buildFadeEnabled",
2422
+ "buildSceneZoomEnabled",
2423
+ "buildSceneZoomStartScale",
2424
+ "buildZoomEnabled",
2425
+ "buildZoomStartScale",
2426
+ "buildDropEnabled",
2427
+ "buildDropOffsetY",
2428
+ "buildRotateEnabled",
2429
+ "buildRotateAxis",
2430
+ "buildRotateOffset",
2431
+ "buildDuration",
2432
+ "buildDelay",
2433
+ "buildEasing",
2434
+ "buildCustomBezier"
2435
+ ]);
2436
+ }
2437
+ restartBuildIn() {
2438
+ this.startTime = performance.now(), this.previousAnimationElapsed = 0, this.pathTravelProgress = 0, this.ringOrbitProgress = 0, this.updatePattern(), this.hasTimeVaryingMotion() && this.start();
2439
+ }
2440
+ setViewMode(e) {
2441
+ this.settings.viewMode === "perspective" && e === "orthographic" && (this.settings.orthoScale = be({
2442
+ cameraDistance: this.settings.cameraDistance,
2443
+ cameraHeight: this.settings.cameraHeight,
2444
+ cameraFocalLength: this.settings.cameraFocalLength,
2445
+ referenceZoom: Gt,
2446
+ referenceFrustumSize: Kt
2447
+ })), this.settings.viewMode = e, e === "orthographic" && (this.settings.orthographicView = "custom"), this.camera = this.createCamera(), this.updateCamera(), this.renderIdleFrame();
2448
+ }
2449
+ setViewportGridVisible(e) {
2450
+ this.viewportGrid && (this.viewportGrid.visible = e, this.renderIdleFrame());
2451
+ }
2452
+ isViewportGridVisible() {
2453
+ return this.viewportGrid?.visible ?? !1;
2454
+ }
2455
+ getCameraViewSnapshot() {
2456
+ return {
2457
+ viewMode: this.settings.viewMode,
2458
+ orthographicView: this.settings.orthographicView,
2459
+ orthoScale: this.settings.orthoScale,
2460
+ cameraFocalLength: this.settings.cameraFocalLength,
2461
+ cameraDistance: this.settings.cameraDistance,
2462
+ cameraHeight: this.settings.cameraHeight,
2463
+ cameraOrbitAngle: this.settings.cameraOrbitAngle,
2464
+ cameraElevation: this.settings.cameraElevation,
2465
+ cameraPositionX: this.settings.cameraPositionX,
2466
+ cameraPositionY: this.settings.cameraPositionY,
2467
+ cameraPositionZ: this.settings.cameraPositionZ,
2468
+ cameraTargetX: this.settings.cameraTargetX,
2469
+ cameraTargetY: this.settings.cameraTargetY,
2470
+ cameraTargetZ: this.settings.cameraTargetZ
2471
+ };
2472
+ }
2473
+ applyCameraViewSnapshot(e) {
2474
+ this.settings.viewMode = e.viewMode, this.settings.orthographicView = e.orthographicView, this.settings.orthoScale = e.orthoScale, this.settings.cameraFocalLength = e.cameraFocalLength, this.settings.cameraDistance = e.cameraDistance, this.settings.cameraHeight = e.cameraHeight, this.settings.cameraOrbitAngle = e.cameraOrbitAngle, this.settings.cameraElevation = e.cameraElevation, this.settings.cameraPositionX = e.cameraPositionX, this.settings.cameraPositionY = e.cameraPositionY, this.settings.cameraPositionZ = e.cameraPositionZ, this.settings.cameraTargetX = e.cameraTargetX, this.settings.cameraTargetY = e.cameraTargetY, this.settings.cameraTargetZ = e.cameraTargetZ, this.ensureCameraType(), this.applyCameraSettings();
2475
+ }
2476
+ getCameraFramingBounds() {
2477
+ let e = this.getSubjectBounds(), t = new u.Vector3(), n = new u.Vector3();
2478
+ e.getCenter(t), e.getSize(n);
2479
+ let r = Math.max(.5, n.length() * .5);
2480
+ this.mesh.geometry.boundingSphere || this.mesh.geometry.computeBoundingSphere();
2481
+ let i = Math.max(.25, this.mesh.geometry.boundingSphere?.radius ?? r);
2482
+ return {
2483
+ sceneRadius: r,
2484
+ center: {
2485
+ x: t.x,
2486
+ y: t.y,
2487
+ z: t.z
2488
+ },
2489
+ objectRadius: i
2490
+ };
2491
+ }
2492
+ centerCameraTarget() {
2493
+ let e = this.getSubjectBounds(), t = new u.Vector3();
2494
+ e.getCenter(t), this.settings.cameraTargetX = t.x, this.settings.cameraTargetY = t.y, this.settings.cameraTargetZ = t.z, this.settings.viewMode === "orthographic" && (this.settings.orthographicView = "custom"), this.applyCameraSettings();
2495
+ }
2496
+ frameSubject() {
2497
+ let e = this.getSubjectBounds(), t = new u.Vector3(), n = new u.Vector3();
2498
+ e.getCenter(t), e.getSize(n);
2499
+ let r = Math.max(.5, n.length() * .5) * 2 * 1.25;
2500
+ if (this.settings.cameraTargetX = t.x, this.settings.cameraTargetY = t.y, this.settings.cameraTargetZ = t.z, this.settings.viewMode === "orthographic") this.settings.orthographicView = "custom", this.settings.orthoScale = u.MathUtils.clamp(Kt * Gt / r, F.camera.orthographicScale.min, F.camera.orthographicScale.max);
2501
+ else {
2502
+ let e = this.getPerspectiveFovFromFocalLength() * (Math.PI / 180), t = r / (2 * Math.tan(e / 2));
2503
+ this.settings.cameraDistance = u.MathUtils.clamp(t, F.camera.distance.min, F.camera.distance.max), this.settings.cameraHeight = z(this.settings.cameraDistance, this.settings.cameraElevation);
2504
+ }
2505
+ this.applyCameraSettings();
2506
+ }
2507
+ getRenderDiagnostics() {
2508
+ return {
2509
+ isRenderLoopActive: this.animationFrameId !== null,
2510
+ renderCount: this.renderCount,
2511
+ drawCalls: this.renderer.info.render.calls,
2512
+ triangles: this.renderer.info.render.triangles,
2513
+ pixelRatio: this.renderer.getPixelRatio()
2514
+ };
2515
+ }
2516
+ setRenderPixelRatio(e) {
2517
+ this.settings.renderPixelRatio = L(e, $.renderPixelRatio, F.renderer.pixelRatio), this.applyRendererPixelRatio();
2518
+ let { width: t, height: n } = this.getContainerSize();
2519
+ this.renderer.setSize(t, n), this.updateEdgeResolution(t, n), this.renderIdleFrame();
2520
+ }
2521
+ updateAdaptiveRenderQuality(e) {
2522
+ if (!this.animationFrameId) {
2523
+ this.adaptiveQualityLowSamples = 0, this.adaptiveQualityHighSamples = 0;
2524
+ return;
2525
+ }
2526
+ let t = [
2527
+ 1,
2528
+ 1.5,
2529
+ 2
2530
+ ], n = t.reduce((e, n, r) => Math.abs(n - this.settings.renderPixelRatio) < Math.abs(t[e] - this.settings.renderPixelRatio) ? r : e, 0), r = Math.min(window.devicePixelRatio, F.renderer.pixelRatio.max), i = 0;
2531
+ if (t.forEach((e, t) => {
2532
+ e <= r && (i = t);
2533
+ }), e < 50 && n > 0) {
2534
+ this.adaptiveQualityLowSamples += 1, this.adaptiveQualityHighSamples = 0, this.adaptiveQualityLowSamples >= 3 && (this.adaptiveQualityLowSamples = 0, this.setRenderPixelRatio(t[n - 1]));
2535
+ return;
2536
+ }
2537
+ if (e >= 59 && n < i) {
2538
+ this.adaptiveQualityHighSamples += 1, this.adaptiveQualityLowSamples = 0, this.adaptiveQualityHighSamples >= 10 && (this.adaptiveQualityHighSamples = 0, this.setRenderPixelRatio(t[n + 1]));
2539
+ return;
2540
+ }
2541
+ this.adaptiveQualityLowSamples = 0, this.adaptiveQualityHighSamples = 0;
2542
+ }
2543
+ pauseMotion() {
2544
+ this.pausedMotionSnapshot ||= this.getMotionPauseSnapshot(), this.settings.instanceSpinX = 0, this.settings.instanceSpinY = 0, this.settings.instanceSpinZ = 0, this.settings.pathRotationX = 0, this.settings.pathRotationY = 0, this.settings.pathRotationZ = 0, this.settings.pathTravelSpeed = 0, this.settings.pathTravelStepDistance = 0, this.settings.ringOrbitSpeed = 0, this.settings.waveAmplitude = $.waveAmplitude, this.settings.waveSpeed = 0, this.stop(), this.updatePattern();
2545
+ }
2546
+ resumeMotion() {
2547
+ this.pausedMotionSnapshot && (Object.assign(this.settings, this.pausedMotionSnapshot), this.pausedMotionSnapshot = null, this.updatePattern(), this.start());
2548
+ }
2549
+ isMotionPaused() {
2550
+ return this.pausedMotionSnapshot !== null;
2551
+ }
2552
+ getMotionPauseSnapshot() {
2553
+ return {
2554
+ instanceSpinX: this.settings.instanceSpinX,
2555
+ instanceSpinY: this.settings.instanceSpinY,
2556
+ instanceSpinZ: this.settings.instanceSpinZ,
2557
+ pathRotationX: this.settings.pathRotationX,
2558
+ pathRotationY: this.settings.pathRotationY,
2559
+ pathRotationZ: this.settings.pathRotationZ,
2560
+ pathTravelMode: this.settings.pathTravelMode,
2561
+ pathTravelSpeed: this.settings.pathTravelSpeed,
2562
+ pathTravelStepDistance: this.settings.pathTravelStepDistance,
2563
+ ringOrbitSpeed: this.settings.ringOrbitSpeed,
2564
+ waveAmplitude: this.settings.waveAmplitude,
2565
+ waveSpeed: this.settings.waveSpeed
2566
+ };
2567
+ }
2568
+ setCameraDistance(e) {
2569
+ this.settings.cameraDistance = L(Math.abs(e), $.cameraDistance, F.camera.distance), this.settings.cameraHeight = z(this.settings.cameraDistance, this.settings.cameraElevation), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2570
+ }
2571
+ getInstancePresetSnapshot() {
2572
+ return { ...qt(this.settings).instance };
2573
+ }
2574
+ applyInstancePresetSnapshot(e) {
2575
+ let t = this.getConfig();
2576
+ this.setConfig({
2577
+ ...t,
2578
+ instance: {
2579
+ ...t.instance,
2580
+ ...e
2581
+ }
2582
+ });
2583
+ }
2584
+ setCameraHeight(e) {
2585
+ this.settings.cameraDistance = Math.max(F.camera.distance.min, this.settings.cameraDistance, Math.abs(e)), this.settings.cameraElevation = Me(this.settings.cameraDistance, e), this.settings.cameraHeight = z(this.settings.cameraDistance, this.settings.cameraElevation), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2586
+ }
2587
+ setCameraElevation(e) {
2588
+ this.settings.cameraElevation = je(e), this.settings.cameraHeight = z(this.settings.cameraDistance, this.settings.cameraElevation), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2589
+ }
2590
+ setGridSpacing(e) {
2591
+ this.settings.gridSpacing = e, this.updatePatternAndUseGeneratedLimit();
2592
+ }
2593
+ setGridLayerSpacing(e) {
2594
+ this.settings.gridLayerSpacing = e, this.updatePatternAndUseGeneratedLimit();
2595
+ }
2596
+ setGridLayers(e) {
2597
+ this.settings.gridLayers = e, this.updatePatternAndUseGeneratedLimit();
2598
+ }
2599
+ setRingSpacing(e) {
2600
+ this.settings.ringSpacing = e, this.updatePatternAndUseGeneratedLimit();
2601
+ }
2602
+ setRingCount(e) {
2603
+ this.settings.ringCount = e, this.updatePatternAndUseGeneratedLimit();
2604
+ }
2605
+ setRingDensity(e) {
2606
+ this.settings.ringDensity = e, this.updatePatternAndUseGeneratedLimit();
2607
+ }
2608
+ setRingSpacingFactor(e) {
2609
+ this.settings.ringSpacingFactor = e, this.updatePatternAndUseGeneratedLimit();
2610
+ }
2611
+ setPathInstanceCount(e) {
2612
+ this.settings.pathInstanceCount = e, this.updatePatternAndUseGeneratedLimit();
2613
+ }
2614
+ setPathRows(e) {
2615
+ this.settings.pathRows = e, this.updatePatternAndUseGeneratedLimit();
2616
+ }
2617
+ updateCameraOrbit() {
2618
+ let e = L(Number.isFinite(this.settings.cameraDistance) ? Math.abs(this.settings.cameraDistance) : $.cameraDistance, $.cameraDistance, F.camera.distance), t = Number.isFinite(this.settings.cameraElevation) ? this.settings.cameraElevation : Me(e, $.cameraHeight), n = Number.isFinite(this.settings.cameraOrbitAngle) ? this.settings.cameraOrbitAngle : $.cameraOrbitAngle, r = this.settings.cameraTargetX, i = this.settings.cameraTargetY, a = this.settings.cameraTargetZ;
2619
+ this.settings.cameraDistance = e, this.settings.cameraHeight = z(e, t), this.settings.cameraOrbitAngle = Ae(n), this.settings.cameraElevation = t;
2620
+ let o = Pe({
2621
+ distance: e,
2622
+ azimuth: this.settings.cameraOrbitAngle,
2623
+ elevation: t,
2624
+ target: {
2625
+ x: r,
2626
+ y: i,
2627
+ z: a
2628
+ }
2629
+ });
2630
+ this.settings.cameraPositionX = o.x, this.settings.cameraPositionY = o.y, this.settings.cameraPositionZ = o.z;
2631
+ }
2632
+ zoomCamera(e) {
2633
+ let t = Math.exp(e * .001);
2634
+ this.settings.viewMode === "orthographic" ? this.settings.orthoScale = u.MathUtils.clamp(this.settings.orthoScale / t, F.camera.orthographicScale.min, F.camera.orthographicScale.max) : (this.settings.cameraDistance = u.MathUtils.clamp(this.settings.cameraDistance * t, F.camera.distance.min, F.camera.distance.max), this.settings.cameraHeight = z(this.settings.cameraDistance, this.settings.cameraElevation)), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2635
+ }
2636
+ orbitCamera(e, t) {
2637
+ let n = Math.max(F.camera.orbitDistanceFloor, Math.abs(this.settings.cameraDistance));
2638
+ this.settings.cameraOrbitAngle = Ae(this.settings.cameraOrbitAngle + e * .01), this.settings.cameraElevation = je(this.settings.cameraElevation + t * .006), this.settings.cameraHeight = z(n, this.settings.cameraElevation), this.settings.viewMode === "orthographic" && (this.settings.orthographicView = "custom"), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2639
+ }
2640
+ panCamera(e, t) {
2641
+ this.camera.updateMatrixWorld();
2642
+ let { width: n, height: r } = this.getContainerSize(), i = Math.max(1, Math.min(n, r)), a = this.settings.viewMode === "orthographic" ? this.frustumSize / i : Math.max(F.camera.orbitDistanceFloor, Math.abs(this.settings.cameraDistance)) * .0015, o = new u.Vector3().setFromMatrixColumn(this.camera.matrixWorld, 0), s = new u.Vector3().setFromMatrixColumn(this.camera.matrixWorld, 1), c = new u.Vector3().addScaledVector(o, -e * a).addScaledVector(s, t * a);
2643
+ this.settings.cameraTargetX += c.x, this.settings.cameraTargetY += c.y, this.settings.cameraTargetZ += c.z, this.settings.viewMode === "orthographic" && (this.settings.orthographicView = "custom"), this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
2644
+ }
2645
+ notifyCameraChange() {
2646
+ this.cameraChangeListeners.forEach((e) => {
2647
+ e();
2648
+ });
2649
+ }
2650
+ notifyCameraInteractionEnd() {
2651
+ this.cameraInteractionEndListeners.forEach((e) => {
2652
+ e();
2653
+ });
2654
+ }
2655
+ renderIdleFrame() {
2656
+ this.animationFrameId === null && this.renderScene();
2657
+ }
2658
+ renderScene(e = this.renderer) {
2659
+ this.updateObjectGradientUniforms(this.mesh), this.updateMaterialTextureUniforms(this.mesh);
2660
+ let t = e === this.renderer && this.previewTransparentBackground && this.settings.backgroundMode === "transparent", n = this.scene.background;
2661
+ t && (this.scene.background = this.updateTransparentBackgroundPreviewTexture());
2662
+ try {
2663
+ e.render(this.scene, this.camera), this.renderCount += 1;
2664
+ } finally {
2665
+ t && (this.scene.background = n);
2666
+ }
2667
+ }
2668
+ updateObjectGradientUniforms(e) {
2669
+ if (!this.usesObjectGradient()) return;
2670
+ let t = (Array.isArray(e.material) ? e.material[0] : e.material)?.userData.speObjectGradientUniforms;
2671
+ if (!t) return;
2672
+ e.geometry.computeBoundingBox();
2673
+ let n = e.geometry.boundingBox;
2674
+ if (!n) return;
2675
+ let r = t.center.value, i = new u.Vector3();
2676
+ n.getCenter(r), n.getSize(i), t.colorA.value.set(this.settings.gradientColorA), t.colorB.value.set(this.settings.gradientColorB), t.direction.value = this.getObjectGradientDirectionIndex(), t.midpoint.value = this.getGradientMidpoint(), t.easingMode.value = this.getGradientEasingModeIndex(), t.bezier.value.copy(this.getGradientBezierVector()), t.min.value.copy(n.min), t.max.value.copy(n.max), t.maxRadius.value = Math.max(1e-4, ...Array.from({ length: 8 }, (e, t) => {
2677
+ let i = t & 1 ? n.max.x : n.min.x, a = t & 2 ? n.max.y : n.min.y, o = t & 4 ? n.max.z : n.min.z;
2678
+ return new u.Vector3(i, a, o).distanceTo(r);
2679
+ }), i.length() * .5);
2680
+ }
2681
+ updateMaterialTextureUniforms(e) {
2682
+ if (!this.usesMaterialTextureSurface()) return;
2683
+ let t = (Array.isArray(e.material) ? e.material[0] : e.material)?.userData.speMaterialTextureUniforms;
2684
+ if (!t) return;
2685
+ e.geometry.computeBoundingBox();
2686
+ let n = e.geometry.boundingBox;
2687
+ if (!n) return;
2688
+ let r = this.getMaterialTexture();
2689
+ t.map.value = r, t.scope.value = this.getMaterialTextureScopeIndex(), t.projection.value = this.getMaterialTextureProjectionIndex(), t.mode.value = this.getMaterialTextureModeIndex(), t.imageAspect.value = this.getTextureAspectRatio(r), t.repeat.value.set(this.getMaterialTextureRepeat(this.settings.materialTextureRepeatX), this.getMaterialTextureRepeat(this.settings.materialTextureRepeatY)), t.offset.value.set(this.settings.materialTextureOffsetX, this.settings.materialTextureOffsetY), t.rotation.value = this.settings.materialTextureRotation, t.min.value.copy(n.min), t.max.value.copy(n.max);
2690
+ let i = this.getSubjectBounds();
2691
+ t.patternMin.value.copy(i.min), t.patternMax.value.copy(i.max), t.fillColor.value.set(this.settings.objectColor);
2692
+ }
2693
+ syncImageSetMeshTransforms() {
2694
+ this.imageSetMeshes.forEach((e) => {
2695
+ e.position.copy(this.mesh.position), e.rotation.copy(this.mesh.rotation), e.scale.copy(this.mesh.scale);
2696
+ });
2697
+ }
2698
+ setStructureRotation(e, t, n) {
2699
+ this.mesh.rotation.set(e, t, n), this.outlineMesh.rotation.copy(this.mesh.rotation), this.edgeGroup.rotation.copy(this.mesh.rotation), this.edgeGroup.updateMatrixWorld(!0), this.syncImageSetMeshTransforms();
2700
+ }
2701
+ updatePattern() {
2702
+ this.updatePatternFromLayouts(this.createLayouts());
2703
+ }
2704
+ updatePatternAndUseGeneratedLimit() {
2705
+ let e = this.createLayouts();
2706
+ this.settings.instanceLimit = e.length, this.updatePatternFromLayouts(e);
2707
+ }
2708
+ alignQuaternion(e, t) {
2709
+ let n = this.settings.distributionMode;
2710
+ if (n === "starfield") return this.settings.starfieldFaceCamera ? this.starfieldBillboardQuaternion(t) : t.identity();
2711
+ if (!(n === "grid" || n === "cube-grid" || n === "rings" ? this.settings.alignToPattern : this.settings.alignToPath)) return t.identity();
2712
+ if (n === "grid" || n === "cube-grid") return t.setFromAxisAngle(Rt, e.angle);
2713
+ let r = e.alignDir;
2714
+ if (!r) return t.identity();
2715
+ let i = this.alignVecScratch.set(r.x, r.y, r.z);
2716
+ if (i.lengthSq() < 1e-8) return t.identity();
2717
+ i.normalize();
2718
+ let a = e.alignUp;
2719
+ if (!a) return t.setFromUnitVectors(this.faceAlignAxis(), i);
2720
+ let o = this.alignUpScratch.set(a.x, a.y, a.z).normalize().multiplyScalar(-1), s = this.alignRightScratch.copy(i).cross(o);
2721
+ return s.lengthSq() < 1e-8 ? t.setFromUnitVectors(this.faceAlignAxis(), i) : (s.normalize(), this.alignMatrixScratch.makeBasis(s, i, o), t.setFromRotationMatrix(this.alignMatrixScratch));
2722
+ }
2723
+ starfieldBillboardQuaternion(e) {
2724
+ let t = this.alignVecScratch.set(this.settings.cameraPositionX - this.settings.cameraTargetX, this.settings.cameraPositionY - this.settings.cameraTargetY, this.settings.cameraPositionZ - this.settings.cameraTargetZ);
2725
+ if (t.lengthSq() < 1e-8) return e.identity();
2726
+ t.normalize();
2727
+ let n = this.alignUpScratch.setFromMatrixColumn(this.camera.matrixWorld, 1).normalize().multiplyScalar(-1), r = this.alignRightScratch.copy(t).cross(n);
2728
+ return r.lengthSq() < 1e-8 ? e.setFromUnitVectors(this.faceAlignAxis(), t) : (r.normalize(), this.alignMatrixScratch.makeBasis(r, t, n), e.setFromRotationMatrix(this.alignMatrixScratch));
2729
+ }
2730
+ faceAlignAxis() {
2731
+ return Rt;
2732
+ }
2733
+ updatePatternFromLayouts(e) {
2734
+ this.layouts = this.applyInstanceLimit(e);
2735
+ let t = performance.now(), n = this.instanceBirthTimes, r = !1;
2736
+ this.instanceBirthTimes = this.layouts.map((e, i) => n[i] === void 0 ? (r = !0, t) : n[i]), r && (this.fadeUntil = Math.max(this.fadeUntil, t + this.getFadeDurationMs())), this.ensureMeshCapacity(this.layouts.length), this.syncImageSetMeshes(), this.clearInstanceColorsForImageSurfaces(), this.ensureInstanceOpacityAttribute(this.mesh), this.ensureInstanceOpacityAttribute(this.outlineMesh), this.imageSetMeshes.forEach((e) => this.ensureInstanceOpacityAttribute(e));
2737
+ let i = this.createSurfaceWriteState(), a = this.getLayoutBounds(this.layouts);
2738
+ this.outlineMesh.count = this.layouts.length, this.syncEdgeLineCount();
2739
+ let o = this.settings.baseY + (this.settings.groundAlign ? this.settings.scaleY / 2 : 0), s = this.getEdgeScaleLift(), c = this.getBuildTransform(this.getBuildProgress((t - this.startTime) / 1e3));
2740
+ this.layouts.forEach((e, t) => {
2741
+ let n = this.getInstanceScale(e, this.settings.scaleMode, this.settings.scaleAmount) * c.scale * c.sceneScale;
2742
+ this.dummy.position.set(e.x * c.sceneScale, (o + e.y) * c.sceneScale + c.offsetY, e.z * c.sceneScale), this.dummy.scale.set(n, n, n);
2743
+ let r = this.alignQuaternion(e, this.alignQuatScratch);
2744
+ this.manualQuatScratch.setFromEuler(this.orientationEulerScratch.set(this.settings.instanceRotationX + c.rotationX, this.settings.instanceRotationY + c.rotationY, this.settings.instanceRotationZ + c.rotationZ)), this.dummy.quaternion.copy(r).multiply(this.manualQuatScratch), this.dummy.updateMatrix();
2745
+ let l = this.getInstanceOpacity(t, e) * c.opacity, u = this.setSurfaceMatrixAt(t, this.dummy.matrix, i);
2746
+ this.setInstanceOpacityAt(u.mesh, u.index, l), this.setInstanceColorAt(u.mesh, u.index, this.getInstanceColor(e, a)), this.dummy.scale.setScalar(n * s), this.dummy.updateMatrix();
2747
+ let d = this.edgeLines[t];
2748
+ d && (d.matrix.copy(this.dummy.matrix), d.matrixWorldNeedsUpdate = !0, this.setEdgeLineOpacity(d, l)), this.dummy.scale.setScalar(n * (1 + this.settings.outlineThickness)), this.dummy.updateMatrix(), this.outlineMesh.setMatrixAt(t, this.dummy.matrix), this.setInstanceOpacityAt(this.outlineMesh, t, l);
2749
+ }), this.finishSurfaceWrites(i), this.outlineMesh.instanceMatrix.needsUpdate = !0, this.renderIdleFrame(), this.animationFrameId === null && (r || this.hasTimeVaryingMotion()) && this.start();
2750
+ }
2751
+ getInstanceOpacity(e, t) {
2752
+ let n = performance.now() - (this.instanceBirthTimes[e] ?? performance.now()), r = this.getFadeDurationMs(), i = pt(r === 0 ? 1 : u.MathUtils.clamp(n / r, 0, 1), this.settings.fadeEasing, this.settings.fadeCustomBezier);
2753
+ if (!this.shouldFadePathEdges()) return i;
2754
+ let a = t.pathProgress, o = this.getPathEdgeFadeZone(), s = pt(this.getOpenPathEdgeOpacity(a, o), this.settings.pathEdgeFadeEasing, this.settings.pathEdgeFadeCustomBezier);
2755
+ return Math.min(i, Math.max(0, s));
2756
+ }
2757
+ getOpenPathEdgeOpacity(e, t) {
2758
+ return Math.min(1, u.MathUtils.clamp(e / t, 0, 1), u.MathUtils.clamp((1 - e) / t, 0, 1));
2759
+ }
2760
+ shouldFadePathEdges() {
2761
+ return (this.settings.distributionMode === "line-path" || this.settings.distributionMode === "spiral-path" || this.settings.distributionMode === "spline-path" || this.settings.distributionMode === "starfield") && (this.settings.pathTravelMode === "stepped" ? Math.abs(this.settings.pathTravelStepDistance) > Z : Math.abs(this.settings.pathTravelSpeed) > Z);
2762
+ }
2763
+ getPathEdgeFadeZone() {
2764
+ let e = this.settings.pathEdgeFadeDuration, t = (this.settings.pathTravelMode === "stepped" ? Math.abs(this.settings.pathTravelStepDistance) / Math.max(.001, this.settings.pathTravelStepInterval) : Math.abs(this.settings.pathTravelSpeed)) * e;
2765
+ return u.MathUtils.clamp(t, .001, .5);
2766
+ }
2767
+ getFadeDurationMs() {
2768
+ return Math.max(0, this.settings.fadeDuration) * 1e3;
2769
+ }
2770
+ setAppearFade(e, t) {
2771
+ this.settings.fadeDuration = e, this.settings.fadeEasing = t, this.fadeUntil = Math.max(this.fadeUntil, performance.now() + this.getFadeDurationMs()), this.start();
2772
+ }
2773
+ hasBuildInMotion() {
2774
+ return this.settings.buildFadeEnabled || this.settings.buildSceneZoomEnabled || this.settings.buildZoomEnabled || this.settings.buildDropEnabled || this.settings.buildRotateEnabled;
2775
+ }
2776
+ getBuildProgress(e) {
2777
+ if (!this.hasBuildInMotion()) return 1;
2778
+ let t = Math.max(0, this.settings.buildDuration), n = Math.max(0, this.settings.buildDelay);
2779
+ return e < n ? 0 : t === 0 ? 1 : pt(u.MathUtils.clamp((e - n) / t, 0, 1), this.settings.buildEasing, this.settings.buildCustomBezier);
2780
+ }
2781
+ getBuildTransform(e) {
2782
+ let t = 1 - e;
2783
+ return {
2784
+ opacity: this.settings.buildFadeEnabled ? e : 1,
2785
+ sceneScale: this.settings.buildSceneZoomEnabled ? u.MathUtils.lerp(this.settings.buildSceneZoomStartScale, 1, e) : 1,
2786
+ scale: this.settings.buildZoomEnabled ? u.MathUtils.lerp(this.settings.buildZoomStartScale, 1, e) : 1,
2787
+ offsetY: this.settings.buildDropEnabled ? this.settings.buildDropOffsetY * t : 0,
2788
+ rotationX: this.settings.buildRotateEnabled && this.settings.buildRotateAxis === "x" ? this.settings.buildRotateOffset * t : 0,
2789
+ rotationY: this.settings.buildRotateEnabled && this.settings.buildRotateAxis === "y" ? this.settings.buildRotateOffset * t : 0,
2790
+ rotationZ: this.settings.buildRotateEnabled && this.settings.buildRotateAxis === "z" ? this.settings.buildRotateOffset * t : 0
2791
+ };
2792
+ }
2793
+ hasTimeVaryingMotion() {
2794
+ let e = (performance.now() - this.startTime) / 1e3;
2795
+ return Math.abs(this.settings.instanceSpinX) > Z || Math.abs(this.settings.instanceSpinY) > Z || Math.abs(this.settings.instanceSpinZ) > Z || Math.abs(this.settings.pathRotationX) > Z || Math.abs(this.settings.pathRotationY) > Z || Math.abs(this.settings.pathRotationZ) > Z || Math.abs(this.settings.pathTravelSpeed) > Z || this.settings.pathTravelMode === "stepped" && Math.abs(this.settings.pathTravelStepDistance) > Z || Math.abs(this.settings.ringOrbitSpeed) > Z || performance.now() < this.fadeUntil || this.hasBuildInMotion() && this.getBuildProgress(e) < 1 || Math.abs(this.settings.waveAmplitude) > Z && Math.abs(this.settings.waveSpeed) > Z;
2796
+ }
2797
+ applyInstanceLimit(e) {
2798
+ let t = Math.max(1, Math.min(this.settings.instanceLimit, e.length));
2799
+ return t >= e.length ? e : fn(this.settings.distributionMode) ? this.pickEvenPathLayouts(e, t) : [...e].sort((e, t) => e.distance === t.distance ? e.ringIndex === t.ringIndex ? e.angle - t.angle : e.ringIndex - t.ringIndex : e.distance - t.distance).slice(0, t);
2800
+ }
2801
+ pickEvenPathLayouts(e, t) {
2802
+ let n = [...e].sort((e, t) => e.ringIndex === t.ringIndex ? e.pathProgress - t.pathProgress : e.ringIndex - t.ringIndex), r = [];
2803
+ for (let e = 0; e < t; e += 1) {
2804
+ let i = Math.floor(e * n.length / t), a = n[Math.min(n.length - 1, i)];
2805
+ r.push({
2806
+ ...a,
2807
+ gridX: e,
2808
+ pathProgress: t === 1 ? 0 : e / t,
2809
+ spinProgress: t === 1 ? 0 : e / t
2810
+ });
2811
+ }
2812
+ return r;
2813
+ }
2814
+ getImageTextures() {
2815
+ return this.settings.instanceShape === "image" ? this.imageSetTextures.length > 0 ? this.imageSetTextures : this.imageTexture ? [this.imageTexture] : [] : [];
2816
+ }
2817
+ usesImageSetMeshes() {
2818
+ return this.getImageTextures().length > 1;
2819
+ }
2820
+ createSurfaceWriteState() {
2821
+ let e = this.usesImageSetMeshes() ? this.getImageTextures().length : 0;
2822
+ if (e === 0) return this.mesh.count = this.layouts.length, this.imageSetMeshes.forEach((e) => {
2823
+ e.count = 0;
2824
+ }), null;
2825
+ let t = Array.from({ length: e }, () => 0);
2826
+ return this.mesh.count = 0, this.imageSetMeshes.forEach((e) => {
2827
+ e.count = 0;
2828
+ }), {
2829
+ textureCount: e,
2830
+ counts: t
2831
+ };
2832
+ }
2833
+ setSurfaceMatrixAt(e, t, n) {
2834
+ if (!n) return this.mesh.setMatrixAt(e, t), {
2835
+ mesh: this.mesh,
2836
+ index: e
2837
+ };
2838
+ let r = e % n.textureCount, i = r === 0 ? this.mesh : this.imageSetMeshes[r - 1], a = n.counts[r];
2839
+ return i?.setMatrixAt(a, t), n.counts[r] += 1, {
2840
+ mesh: i,
2841
+ index: a
2842
+ };
2843
+ }
2844
+ finishSurfaceWrites(e) {
2845
+ if (!e) {
2846
+ this.mesh.instanceMatrix.needsUpdate = !0;
2847
+ return;
2848
+ }
2849
+ this.mesh.count = e.counts[0], this.mesh.instanceMatrix.needsUpdate = !0, this.imageSetMeshes.forEach((t, n) => {
2850
+ t.count = e.counts[n + 1] ?? 0, t.instanceMatrix.needsUpdate = !0;
2851
+ });
2852
+ }
2853
+ ensureInstanceOpacityAttribute(e) {
2854
+ let t = e.instanceMatrix.count, n = e.geometry.getAttribute("instanceOpacity");
2855
+ if (n && n.count === t) return n;
2856
+ let r = new Float32Array(t);
2857
+ r.fill(1);
2858
+ let i = new u.InstancedBufferAttribute(r, 1);
2859
+ return e.geometry.setAttribute("instanceOpacity", i), i;
2860
+ }
2861
+ setInstanceOpacityAt(e, t, n) {
2862
+ if (!e) return;
2863
+ let r = this.ensureInstanceOpacityAttribute(e);
2864
+ r.setX(t, u.MathUtils.clamp(n, 0, 1)), r.needsUpdate = !0;
2865
+ }
2866
+ setInstanceColorAt(e, t, n) {
2867
+ !e || this.settings.instanceShape === "image" || (e.setColorAt(t, n), e.instanceColor && (e.instanceColor.needsUpdate = !0));
2868
+ }
2869
+ clearInstanceColorsForImageSurfaces() {
2870
+ this.settings.instanceShape === "image" && [this.mesh, ...this.imageSetMeshes].forEach((e) => {
2871
+ e.instanceColor && (e.instanceColor = null, (Array.isArray(e.material) ? e.material : [e.material]).forEach((e) => {
2872
+ e.needsUpdate = !0;
2873
+ }));
2874
+ });
2875
+ }
2876
+ getInstanceColor(e, t) {
2877
+ if (!this.usesInstanceColors()) return this.gradientColorScratch.set("#ffffff");
2878
+ let n = this.getGradientProgress(e, t), r = this.gradientColorAScratch.set(this.settings.gradientColorA), i = this.gradientColorBScratch.set(this.settings.gradientColorB);
2879
+ return this.gradientColorScratch.copy(r).lerp(i, this.shapeGradientProgress(n));
2880
+ }
2881
+ getGradientProgress(e, t) {
2882
+ if (this.settings.gradientScope === "object") return this.getObjectGradientProgress();
2883
+ if (this.settings.gradientDirection === "path") return u.MathUtils.clamp(e.pathProgress, 0, 1);
2884
+ if (this.settings.gradientDirection === "radial") {
2885
+ let t = Math.max(1e-4, this.layouts.reduce((e, t) => Math.max(e, t.distance), 0));
2886
+ return u.MathUtils.clamp(e.distance / t, 0, 1);
2887
+ }
2888
+ let n = t.min[this.settings.gradientDirection], r = t.max[this.settings.gradientDirection], i = this.settings.gradientDirection === "x" ? e.x : this.settings.gradientDirection === "y" ? e.y : e.z;
2889
+ return Math.abs(r - n) < 1e-4 ? .5 : u.MathUtils.clamp((i - n) / (r - n), 0, 1);
2890
+ }
2891
+ getObjectGradientProgress() {
2892
+ return this.settings.gradientDirection === "radial" || this.settings.gradientDirection === "path" ? .5 : this.settings.gradientDirection === "x" ? 0 : this.settings.gradientDirection === "y" ? .5 : 1;
2893
+ }
2894
+ getGradientMidpoint() {
2895
+ return u.MathUtils.clamp(this.settings.gradientMidpoint, .01, .99);
2896
+ }
2897
+ remapGradientProgress(e) {
2898
+ return this.remapGradientProgressWithMidpoint(e, this.getGradientMidpoint());
2899
+ }
2900
+ remapGradientProgressWithMidpoint(e, t) {
2901
+ let n = u.MathUtils.clamp(e, 0, 1), r = u.MathUtils.clamp(t, .01, .99);
2902
+ return n <= r ? n / r * .5 : .5 + .5 * ((n - r) / (1 - r));
2903
+ }
2904
+ shapeGradientProgress(e) {
2905
+ return pt(this.remapGradientProgress(e), this.settings.gradientEasing, this.settings.gradientCustomBezier);
2906
+ }
2907
+ getGradientEasingModeIndex() {
2908
+ return this.settings.gradientEasing === "ease-in" ? 1 : this.settings.gradientEasing === "ease-out" ? 2 : this.settings.gradientEasing === "ease-in-out" ? 3 : this.settings.gradientEasing === "custom-bezier" ? 4 : 0;
2909
+ }
2910
+ getGradientBezierVector() {
2911
+ let e = (this.settings.gradientEasing === "custom-bezier" ? ft(this.settings.gradientCustomBezier) : null) ?? {
2912
+ x1: 0,
2913
+ y1: 0,
2914
+ x2: 1,
2915
+ y2: 1
2916
+ };
2917
+ return new u.Vector4(e.x1, e.y1, e.x2, e.y2);
2918
+ }
2919
+ getObjectGradientDirectionIndex() {
2920
+ return this.settings.gradientDirection === "y" ? 1 : this.settings.gradientDirection === "z" ? 2 : this.settings.gradientDirection === "radial" ? 3 : 0;
2921
+ }
2922
+ getLayoutBounds(e) {
2923
+ let t = new u.Box3();
2924
+ return e.forEach((e) => {
2925
+ t.expandByPoint(new u.Vector3(e.x, e.y, e.z));
2926
+ }), t.isEmpty() && t.setFromCenterAndSize(new u.Vector3(), new u.Vector3(1, 1, 1)), t;
2927
+ }
2928
+ enableInstanceOpacity(e, t = {}) {
2929
+ let n = e;
2930
+ return e.transparent = !t.alphaHash, e.depthWrite = t.depthWrite ?? e.depthWrite, n.alphaHash = t.alphaHash ?? !1, e.onBeforeCompile = (n) => {
2931
+ if (t.objectGradient) {
2932
+ let t = {
2933
+ colorA: { value: new u.Color(this.settings.gradientColorA) },
2934
+ colorB: { value: new u.Color(this.settings.gradientColorB) },
2935
+ direction: { value: this.getObjectGradientDirectionIndex() },
2936
+ midpoint: { value: this.getGradientMidpoint() },
2937
+ easingMode: { value: this.getGradientEasingModeIndex() },
2938
+ bezier: { value: this.getGradientBezierVector() },
2939
+ min: { value: new u.Vector3(-.5, -.5, -.5) },
2940
+ max: { value: new u.Vector3(.5, .5, .5) },
2941
+ center: { value: new u.Vector3() },
2942
+ maxRadius: { value: 1 }
2943
+ };
2944
+ Object.assign(n.uniforms, {
2945
+ speObjectGradientColorA: t.colorA,
2946
+ speObjectGradientColorB: t.colorB,
2947
+ speObjectGradientDirection: t.direction,
2948
+ speObjectGradientMidpoint: t.midpoint,
2949
+ speObjectGradientEasingMode: t.easingMode,
2950
+ speObjectGradientBezier: t.bezier,
2951
+ speObjectGradientMin: t.min,
2952
+ speObjectGradientMax: t.max,
2953
+ speObjectGradientCenter: t.center,
2954
+ speObjectGradientMaxRadius: t.maxRadius
2955
+ }), e.userData.speObjectGradientUniforms = t;
2956
+ }
2957
+ if (t.materialTexture) {
2958
+ let t = this.getMaterialTexture(), r = {
2959
+ map: { value: t },
2960
+ scope: { value: this.getMaterialTextureScopeIndex() },
2961
+ projection: { value: this.getMaterialTextureProjectionIndex() },
2962
+ mode: { value: this.getMaterialTextureModeIndex() },
2963
+ imageAspect: { value: this.getTextureAspectRatio(t) },
2964
+ repeat: { value: new u.Vector2(this.getMaterialTextureRepeat(this.settings.materialTextureRepeatX), this.getMaterialTextureRepeat(this.settings.materialTextureRepeatY)) },
2965
+ offset: { value: new u.Vector2(this.settings.materialTextureOffsetX, this.settings.materialTextureOffsetY) },
2966
+ rotation: { value: this.settings.materialTextureRotation },
2967
+ min: { value: new u.Vector3(-.5, -.5, -.5) },
2968
+ max: { value: new u.Vector3(.5, .5, .5) },
2969
+ patternMin: { value: new u.Vector3(-.5, -.5, -.5) },
2970
+ patternMax: { value: new u.Vector3(.5, .5, .5) },
2971
+ fillColor: { value: new u.Color(this.settings.objectColor) }
2972
+ };
2973
+ Object.assign(n.uniforms, {
2974
+ speMaterialTextureMap: r.map,
2975
+ speMaterialTextureScope: r.scope,
2976
+ speMaterialTextureProjection: r.projection,
2977
+ speMaterialTextureMode: r.mode,
2978
+ speMaterialTextureImageAspect: r.imageAspect,
2979
+ speMaterialTextureRepeat: r.repeat,
2980
+ speMaterialTextureOffset: r.offset,
2981
+ speMaterialTextureRotation: r.rotation,
2982
+ speMaterialTextureMin: r.min,
2983
+ speMaterialTextureMax: r.max,
2984
+ speMaterialTexturePatternMin: r.patternMin,
2985
+ speMaterialTexturePatternMax: r.patternMax,
2986
+ speMaterialTextureFillColor: r.fillColor
2987
+ }), e.userData.speMaterialTextureUniforms = r;
2988
+ }
2989
+ n.vertexShader = n.vertexShader.replace("#include <common>", `#include <common>
2990
+ attribute float instanceOpacity;
2991
+ varying float vInstanceOpacity;
2992
+ ${t.objectGradient ? "varying vec3 vSpeObjectGradientPosition;" : ""}
2993
+ ${t.materialTexture ? "varying vec3 vSpeMaterialTexturePosition;\nvarying vec3 vSpeMaterialTextureNormal;\nvarying vec3 vSpeMaterialTextureWorldPosition;" : ""}`).replace("#include <begin_vertex>", `vInstanceOpacity = instanceOpacity;
2994
+ ${t.objectGradient ? "vSpeObjectGradientPosition = position;" : ""}
2995
+ ${t.materialTexture ? "vSpeMaterialTexturePosition = position;\nvSpeMaterialTextureNormal = normal;\nvec4 speMaterialWorldPosition = modelMatrix * vec4(position, 1.0);\n#ifdef USE_INSTANCING\nspeMaterialWorldPosition = modelMatrix * instanceMatrix * vec4(position, 1.0);\n#endif\nvSpeMaterialTextureWorldPosition = speMaterialWorldPosition.xyz;" : ""}
2996
+ #include <begin_vertex>`), n.fragmentShader = n.fragmentShader.replace("#include <common>", `#include <common>
2997
+ varying float vInstanceOpacity;
2998
+ ${t.objectGradient ? "\nvarying vec3 vSpeObjectGradientPosition;\nuniform vec3 speObjectGradientColorA;\nuniform vec3 speObjectGradientColorB;\nuniform int speObjectGradientDirection;\nuniform float speObjectGradientMidpoint;\nuniform int speObjectGradientEasingMode;\nuniform vec4 speObjectGradientBezier;\nuniform vec3 speObjectGradientMin;\nuniform vec3 speObjectGradientMax;\nuniform vec3 speObjectGradientCenter;\nuniform float speObjectGradientMaxRadius;\nfloat speCubicBezierValue(float t, float p1, float p2) {\n float inverse = 1.0 - t;\n return 3.0 * inverse * inverse * t * p1 + 3.0 * inverse * t * t * p2 + t * t * t;\n}\nfloat speCubicBezierDerivative(float t, float p1, float p2) {\n float inverse = 1.0 - t;\n return 3.0 * inverse * inverse * p1 + 6.0 * inverse * t * (p2 - p1) + 3.0 * t * t * (1.0 - p2);\n}\nfloat speSampleCubicBezier(float x1, float y1, float x2, float y2, float x) {\n float t = clamp(x, 0.0, 1.0);\n for (int index = 0; index < 5; index++) {\n float currentX = speCubicBezierValue(t, x1, x2);\n float derivative = speCubicBezierDerivative(t, x1, x2);\n if (abs(derivative) < 0.0001) {\n break;\n }\n t = clamp(t - (currentX - x) / derivative, 0.0, 1.0);\n }\n return clamp(speCubicBezierValue(t, y1, y2), 0.0, 1.0);\n}\nfloat easeSpeObjectGradientProgress(float progress) {\n float t = clamp(progress, 0.0, 1.0);\n if (speObjectGradientEasingMode == 1) {\n return speSampleCubicBezier(0.42, 0.0, 1.0, 1.0, t);\n }\n if (speObjectGradientEasingMode == 2) {\n return speSampleCubicBezier(0.0, 0.0, 0.58, 1.0, t);\n }\n if (speObjectGradientEasingMode == 3) {\n return speSampleCubicBezier(0.42, 0.0, 0.58, 1.0, t);\n }\n if (speObjectGradientEasingMode == 4) {\n return speSampleCubicBezier(speObjectGradientBezier.x, speObjectGradientBezier.y, speObjectGradientBezier.z, speObjectGradientBezier.w, t);\n }\n return t;\n}\nfloat remapSpeObjectGradientProgress(float progress) {\n float clampedProgress = clamp(progress, 0.0, 1.0);\n float midpoint = clamp(speObjectGradientMidpoint, 0.01, 0.99);\n float remappedProgress = 0.5;\n if (clampedProgress <= midpoint) {\n remappedProgress = 0.5 * (clampedProgress / midpoint);\n } else {\n remappedProgress = 0.5 + 0.5 * ((clampedProgress - midpoint) / (1.0 - midpoint));\n }\n return easeSpeObjectGradientProgress(remappedProgress);\n}\nfloat getSpeObjectGradientProgress() {\n if (speObjectGradientDirection == 3) {\n return remapSpeObjectGradientProgress(length(vSpeObjectGradientPosition - speObjectGradientCenter) / max(0.0001, speObjectGradientMaxRadius));\n }\n float minValue = speObjectGradientDirection == 0 ? speObjectGradientMin.x : (speObjectGradientDirection == 1 ? speObjectGradientMin.y : speObjectGradientMin.z);\n float maxValue = speObjectGradientDirection == 0 ? speObjectGradientMax.x : (speObjectGradientDirection == 1 ? speObjectGradientMax.y : speObjectGradientMax.z);\n float value = speObjectGradientDirection == 0 ? vSpeObjectGradientPosition.x : (speObjectGradientDirection == 1 ? vSpeObjectGradientPosition.y : vSpeObjectGradientPosition.z);\n if (abs(maxValue - minValue) < 0.0001) {\n return 0.5;\n }\n return remapSpeObjectGradientProgress((value - minValue) / (maxValue - minValue));\n}" : ""}`).replace("#include <common>", `#include <common>
2999
+ ${t.materialTexture ? "\nvarying vec3 vSpeMaterialTexturePosition;\nvarying vec3 vSpeMaterialTextureNormal;\nvarying vec3 vSpeMaterialTextureWorldPosition;\nuniform sampler2D speMaterialTextureMap;\nuniform int speMaterialTextureScope;\nuniform int speMaterialTextureProjection;\nuniform int speMaterialTextureMode;\nuniform float speMaterialTextureImageAspect;\nuniform vec2 speMaterialTextureRepeat;\nuniform vec2 speMaterialTextureOffset;\nuniform float speMaterialTextureRotation;\nuniform vec3 speMaterialTextureMin;\nuniform vec3 speMaterialTextureMax;\nuniform vec3 speMaterialTexturePatternMin;\nuniform vec3 speMaterialTexturePatternMax;\nuniform vec3 speMaterialTextureFillColor;\nvec2 rotateSpeMaterialUv(vec2 uv) {\n float s = sin(speMaterialTextureRotation);\n float c = cos(speMaterialTextureRotation);\n vec2 centered = uv - vec2(0.5);\n return vec2(centered.x * c - centered.y * s, centered.x * s + centered.y * c) + vec2(0.5);\n}\nvec2 transformSpeMaterialUv(vec2 uv, bool useRepeat) {\n vec2 transformedUv = rotateSpeMaterialUv(uv);\n if (useRepeat) {\n transformedUv *= max(speMaterialTextureRepeat, vec2(0.001));\n }\n return transformedUv + speMaterialTextureOffset;\n}\nvec4 sampleSpeMaterialTexture(vec2 uv, vec2 faceSize) {\n float faceAspect = max(0.0001, faceSize.x / max(0.0001, faceSize.y));\n float imageAspect = max(0.0001, speMaterialTextureImageAspect);\n vec2 sampleUv = uv;\n float mask = 1.0;\n\n if (speMaterialTextureMode == 1) {\n vec2 rectSize = vec2(1.0);\n if (imageAspect > faceAspect) {\n rectSize.y = faceAspect / imageAspect;\n } else {\n rectSize.x = imageAspect / faceAspect;\n }\n vec2 rectMin = (vec2(1.0) - rectSize) * 0.5;\n vec2 rectMax = rectMin + rectSize;\n mask = step(rectMin.x, uv.x) * step(uv.x, rectMax.x) * step(rectMin.y, uv.y) * step(uv.y, rectMax.y);\n sampleUv = (uv - rectMin) / max(rectSize, vec2(0.0001));\n sampleUv = transformSpeMaterialUv(sampleUv, false);\n } else if (speMaterialTextureMode == 2) {\n if (imageAspect > faceAspect) {\n sampleUv.x = (uv.x - 0.5) * (faceAspect / imageAspect) + 0.5;\n } else {\n sampleUv.y = (uv.y - 0.5) * (imageAspect / faceAspect) + 0.5;\n }\n sampleUv = transformSpeMaterialUv(sampleUv, false);\n } else if (speMaterialTextureMode == 3) {\n sampleUv = transformSpeMaterialUv(uv, true);\n } else {\n sampleUv = transformSpeMaterialUv(uv, false);\n }\n\n vec4 texel = texture2D(speMaterialTextureMap, sampleUv);\n if (speMaterialTextureMode == 1) {\n texel.rgb = mix(speMaterialTextureFillColor, texel.rgb, mask);\n texel.a = mix(1.0, texel.a, mask);\n }\n return texel;\n}\nvec4 getSpeMaterialTextureColor() {\n vec3 size = max(speMaterialTextureMax - speMaterialTextureMin, vec3(0.0001));\n vec3 local = clamp((vSpeMaterialTexturePosition - speMaterialTextureMin) / size, vec3(0.0), vec3(1.0));\n vec3 n = abs(normalize(vSpeMaterialTextureNormal));\n if (speMaterialTextureScope == 1) {\n vec3 patternSize = max(speMaterialTexturePatternMax - speMaterialTexturePatternMin, vec3(0.0001));\n vec3 patternLocal = clamp((vSpeMaterialTextureWorldPosition - speMaterialTexturePatternMin) / patternSize, vec3(0.0), vec3(1.0));\n if (speMaterialTextureProjection == 1) {\n vec4 sampleX = sampleSpeMaterialTexture(vec2(patternLocal.z, patternLocal.y), vec2(patternSize.z, patternSize.y));\n vec4 sampleY = sampleSpeMaterialTexture(vec2(patternLocal.x, patternLocal.z), vec2(patternSize.x, patternSize.z));\n vec4 sampleZ = sampleSpeMaterialTexture(vec2(patternLocal.x, patternLocal.y), vec2(patternSize.x, patternSize.y));\n vec3 weights = max(pow(n, vec3(4.0)), vec3(0.0001));\n weights /= weights.x + weights.y + weights.z;\n return sampleX * weights.x + sampleY * weights.y + sampleZ * weights.z;\n }\n vec2 patternUv = patternLocal.xy;\n vec2 patternFaceSize = patternSize.xy;\n if (n.x >= n.y && n.x >= n.z) {\n patternUv = vec2(patternLocal.z, patternLocal.y);\n patternFaceSize = vec2(patternSize.z, patternSize.y);\n } else if (n.y >= n.z) {\n patternUv = vec2(patternLocal.x, patternLocal.z);\n patternFaceSize = vec2(patternSize.x, patternSize.z);\n }\n return sampleSpeMaterialTexture(patternUv, patternFaceSize);\n }\n if (speMaterialTextureProjection == 1) {\n vec4 sampleX = sampleSpeMaterialTexture(vec2(local.z, local.y), vec2(size.z, size.y));\n vec4 sampleY = sampleSpeMaterialTexture(vec2(local.x, local.z), vec2(size.x, size.z));\n vec4 sampleZ = sampleSpeMaterialTexture(vec2(local.x, local.y), vec2(size.x, size.y));\n vec3 weights = max(pow(n, vec3(4.0)), vec3(0.0001));\n weights /= weights.x + weights.y + weights.z;\n return sampleX * weights.x + sampleY * weights.y + sampleZ * weights.z;\n }\n vec2 uv = local.xy;\n vec2 faceSize = size.xy;\n if (n.x >= n.y && n.x >= n.z) {\n uv = vec2(local.z, local.y);\n faceSize = vec2(size.z, size.y);\n } else if (n.y >= n.z) {\n uv = vec2(local.x, local.z);\n faceSize = vec2(size.x, size.z);\n }\n return sampleSpeMaterialTexture(uv, faceSize);\n}" : ""}`).replace("#include <color_fragment>", `#include <color_fragment>
3000
+ ${t.objectGradient ? "diffuseColor.rgb *= mix(speObjectGradientColorA, speObjectGradientColorB, getSpeObjectGradientProgress());" : ""}
3001
+ ${t.materialTexture ? "vec4 speMaterialTextureColor = getSpeMaterialTextureColor();\ndiffuseColor.rgb *= speMaterialTextureColor.rgb;\ndiffuseColor.a *= speMaterialTextureColor.a;" : ""}`).replace("#include <alphatest_fragment>", "diffuseColor.a *= vInstanceOpacity;\nif (diffuseColor.a <= 0.001) discard;\n#include <alphatest_fragment>");
3002
+ }, e.customProgramCacheKey = () => [
3003
+ "spe-instance-opacity",
3004
+ t.alphaHash ? "alpha-hash" : "transparent",
3005
+ t.objectGradient ? "object-gradient" : "solid",
3006
+ t.materialTexture ? "material-texture" : "no-material-texture"
3007
+ ].join(":"), e;
3008
+ }
3009
+ rebuildGeometry() {
3010
+ let e = this.createGeometry();
3011
+ this.mesh.geometry.dispose(), this.outlineMesh.geometry.dispose(), this.edgeGeometry?.dispose(), this.mesh.geometry = e, this.outlineMesh.geometry = e.clone(), this.edgeGeometry = this.createEdgeGeometry(e), this.syncImageSetMeshes(), this.rebuildEdgeLines(), this.updatePattern();
3012
+ }
3013
+ setInstanceShape(e) {
3014
+ this.settings.instanceShape = e, this.settings.colorMode === "texture" && !this.isTextureMaterialShape() && (this.settings.colorMode = "solid"), this.applyInstanceShapeDefaults(e), this.updateMaterial(), this.rebuildGeometry();
3015
+ }
3016
+ applyInstanceShapeDefaults(e) {
3017
+ if (this.scaleBeforeShapeDefault && (this.shapeAutoModified.x && (this.settings.scaleX = this.scaleBeforeShapeDefault.x), this.shapeAutoModified.y && (this.settings.scaleY = this.scaleBeforeShapeDefault.y), this.shapeAutoModified.z && (this.settings.scaleZ = this.scaleBeforeShapeDefault.z)), this.scaleBeforeShapeDefault = {
3018
+ x: this.settings.scaleX,
3019
+ y: this.settings.scaleY,
3020
+ z: this.settings.scaleZ
3021
+ }, this.shapeAutoModified = {
3022
+ x: !1,
3023
+ y: !1,
3024
+ z: !1
3025
+ }, e === "pill") {
3026
+ let e = Math.max(this.settings.scaleX, this.settings.scaleZ), t = Math.max(this.settings.scaleY, e * 2.8);
3027
+ t !== this.settings.scaleY && (this.settings.scaleY = t, this.shapeAutoModified.y = !0);
3028
+ }
3029
+ }
3030
+ setInstanceDimension(e, t) {
3031
+ this.shapeAutoModified[e] = !1;
3032
+ let n = L(t, $.scaleX, F.instance.dimension);
3033
+ e === "x" ? (this.settings.scaleX = n, this.shouldLockImageAspectRatio() && (this.settings.scaleZ = L(n / this.settings.imageAspectRatio, $.scaleZ, F.instance.dimension))) : e === "y" ? this.settings.scaleY = n : (this.settings.scaleZ = n, this.shouldLockImageAspectRatio() && (this.settings.scaleX = L(n * this.settings.imageAspectRatio, $.scaleX, F.instance.dimension))), this.syncRoundedCardRatio(), this.rebuildGeometry();
3034
+ }
3035
+ setImagePreserveAspectRatio(e) {
3036
+ this.settings.imagePreserveAspectRatio = e, this.shouldLockImageAspectRatio() && (this.settings.scaleX = L(this.settings.scaleZ * this.settings.imageAspectRatio, $.scaleX, F.instance.dimension)), this.rebuildGeometry();
3037
+ }
3038
+ shouldLockImageAspectRatio() {
3039
+ return this.settings.instanceShape === "image" && this.settings.imagePreserveAspectRatio && this.settings.imageAspectRatio > 0;
3040
+ }
3041
+ async ensureTextRuntimeLoaded() {
3042
+ if (!(this.textGeometryRuntime && this.textFonts)) {
3043
+ if (this.textRuntimeLoadPromise) {
3044
+ await this.textRuntimeLoadPromise;
3045
+ return;
3046
+ }
3047
+ this.textRuntimeLoadPromise = import("./createTextGeometry-C1mQrq4Z.js").then(async (e) => {
3048
+ this.textGeometryRuntime = e, this.textFonts ??= new e.TextFontManager(), this.settings.textFontSource.source === "url" && await this.textFonts.loadCustomFont(this.settings.textFontSource.url);
3049
+ }).finally(() => {
3050
+ this.textRuntimeLoadPromise = null;
3051
+ }), await this.textRuntimeLoadPromise;
3052
+ }
3053
+ }
3054
+ scheduleTextRuntimeLoad() {
3055
+ this.ensureTextRuntimeLoaded().then(() => {
3056
+ this.settings.instanceShape === "text" && this.rebuildGeometry();
3057
+ }).catch((e) => {
3058
+ console.warn("Unable to load text runtime support.", e);
3059
+ });
3060
+ }
3061
+ async loadCustomTextFont(e = this.settings.textCustomFontUrl) {
3062
+ let t = e.trim();
3063
+ if (!t) {
3064
+ this.textFonts?.clearCustomFont(), this.settings.textFontSource = { ...i }, this.settings.textCustomFontUrl = "", this.rebuildGeometry();
3065
+ return;
3066
+ }
3067
+ await this.ensureTextRuntimeLoaded(), await this.textFonts?.loadCustomFont(t), this.settings.textCustomFontUrl = t, this.settings.textFont = "custom", this.settings.textFontSource = {
3068
+ source: "url",
3069
+ url: t
3070
+ }, this.rebuildGeometry();
3071
+ }
3072
+ async ensureWebTextFont(e) {
3073
+ await this.ensureTextRuntimeLoaded(), !this.textFonts?.hasFont(e) && (await this.textFonts?.loadWebFont(e), this.settings.textFont === e && this.settings.instanceShape === "text" && this.rebuildGeometry());
3074
+ }
3075
+ setTextFont(e) {
3076
+ if (this.settings.textFont = e, e === "custom") {
3077
+ this.settings.textCustomFontUrl.trim() ? this.loadCustomTextFont().catch((e) => {
3078
+ console.warn("Unable to load custom text font.", e);
3079
+ }) : (this.textFonts?.clearCustomFont(), this.settings.textFontSource = { ...i }, this.rebuildGeometry());
3080
+ return;
3081
+ }
3082
+ this.settings.textFontSource = {
3083
+ source: "library",
3084
+ id: e
3085
+ }, this.settings.textCustomFontUrl = "", t(e) && this.ensureWebTextFont(e).catch((e) => {
3086
+ console.warn("Unable to load text font.", e);
3087
+ }), this.rebuildGeometry();
3088
+ }
3089
+ syncRoundedCardRatio() {
3090
+ this.settings.instanceShape === "rounded-card" && (this.settings.roundedCardRatio = this.settings.scaleX / Math.max(.01, this.settings.scaleZ));
3091
+ }
3092
+ async loadCustomObj(e = this.settings.assetUrl, t = {}) {
3093
+ await this.loadCustomAsset(e, t);
3094
+ }
3095
+ async loadCustomAsset(e = this.settings.assetUrl, { showPlaceholder: t = !1, source: n = "background" } = {}) {
3096
+ let r = e.trim();
3097
+ if (n === "background" && this.activeUserCustomAssetLoadId > 0) throw new Ft();
3098
+ let i = ++this.customAssetLoadId;
3099
+ if (n === "user" && (this.activeUserCustomAssetLoadId = i), this.settings.assetUrl = r, !r) {
3100
+ this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.activeUserCustomAssetLoadId === i && (this.activeUserCustomAssetLoadId = 0), this.rebuildGeometry();
3101
+ return;
3102
+ }
3103
+ t && (this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.settings.instanceShape = "custom-obj", this.rebuildGeometry());
3104
+ try {
3105
+ let e = await import("./customAssetGeometry-MXHVov4w.js"), t = await e.loadCustomAssetGeometry(_n(r));
3106
+ this.completeCustomAssetLoad(i, t, e.prepareCustomAssetGeometry);
3107
+ } catch (e) {
3108
+ throw this.activeUserCustomAssetLoadId === i && (this.activeUserCustomAssetLoadId = 0), e;
3109
+ }
3110
+ }
3111
+ async loadCustomFile(e, t, n = {}) {
3112
+ let r = t.trim(), i = this.beginCustomAssetLoad(r, n);
3113
+ try {
3114
+ if (!r) {
3115
+ this.clearCustomAssetLoad(i);
3116
+ return;
3117
+ }
3118
+ let t = await import("./customAssetGeometry-MXHVov4w.js"), n = await t.loadCustomAssetGeometryFromFile(e);
3119
+ this.completeCustomAssetLoad(i, n, t.prepareCustomAssetGeometry);
3120
+ } catch (e) {
3121
+ throw this.activeUserCustomAssetLoadId === i && (this.activeUserCustomAssetLoadId = 0), e;
3122
+ }
3123
+ }
3124
+ async loadSvgAsset(e = this.settings.assetUrl, t = {}) {
3125
+ let n = e.trim(), r = this.beginCustomAssetLoad(n, t);
3126
+ try {
3127
+ if (!n) {
3128
+ this.clearSvgAssetLoad(r);
3129
+ return;
3130
+ }
3131
+ let e = await (await import("./svgAssetGeometry-CSnPWwR1.js")).loadSvgAssetGeometry(_n(n), this.settings.svgSolidify);
3132
+ this.completeSvgAssetLoad(r, e);
3133
+ } catch (e) {
3134
+ throw this.activeUserCustomAssetLoadId === r && (this.activeUserCustomAssetLoadId = 0), e;
3135
+ }
3136
+ }
3137
+ async loadSvgFile(e, t, n = {}) {
3138
+ let r = t.trim(), i = this.beginCustomAssetLoad(r, n);
3139
+ try {
3140
+ if (!r) {
3141
+ this.clearSvgAssetLoad(i);
3142
+ return;
3143
+ }
3144
+ let t = await (await import("./svgAssetGeometry-CSnPWwR1.js")).loadSvgAssetGeometryFromFile(e, this.settings.svgSolidify);
3145
+ this.completeSvgAssetLoad(i, t);
3146
+ } catch (e) {
3147
+ throw this.activeUserCustomAssetLoadId === i && (this.activeUserCustomAssetLoadId = 0), e;
3148
+ }
3149
+ }
3150
+ async loadImageAsset(e = this.settings.assetUrl, t = {}) {
3151
+ let n = e.trim(), r = this.beginCustomAssetLoad(n, t);
3152
+ try {
3153
+ if (!n) {
3154
+ this.clearImageAssetLoad(r);
3155
+ return;
3156
+ }
3157
+ let e = await this.textureLoader.loadAsync(_n(n));
3158
+ this.completeImageAssetLoad(r, e);
3159
+ } catch (e) {
3160
+ throw this.activeUserCustomAssetLoadId === r && (this.activeUserCustomAssetLoadId = 0), e;
3161
+ }
3162
+ }
3163
+ async loadImageFile(e, t, n = {}) {
3164
+ await this.loadImageAsset(t, n);
3165
+ }
3166
+ async loadImageSet(e = this.settings.imageSetUrls, t = {}) {
3167
+ let n = gn(e), r = this.beginCustomAssetLoad(n[0] ?? "", t);
3168
+ try {
3169
+ if (n.length === 0) {
3170
+ this.clearImageAssetLoad(r);
3171
+ return;
3172
+ }
3173
+ let e = await Promise.all(n.map((e) => this.textureLoader.loadAsync(_n(e))));
3174
+ this.completeImageSetAssetLoad(r, n, e);
3175
+ } catch (e) {
3176
+ throw this.activeUserCustomAssetLoadId === r && (this.activeUserCustomAssetLoadId = 0), e;
3177
+ }
3178
+ }
3179
+ async loadBackgroundImage(e = this.settings.backgroundImageUrl) {
3180
+ let t = e.trim();
3181
+ if (this.settings.backgroundImageUrl = t, !t) {
3182
+ this.clearBackgroundImage();
3183
+ return;
3184
+ }
3185
+ let n = await this.textureLoader.loadAsync(_n(t));
3186
+ this.backgroundTexture?.dispose(), this.backgroundImageDisplayTexture?.dispose(), this.backgroundImageDisplayTexture = null, this.backgroundTexture = n, this.configureImageTexture(n), this.settings.backgroundMode = "image", this.updateSceneBackground(), this.renderIdleFrame();
3187
+ }
3188
+ async loadBackgroundImageFile(e, t) {
3189
+ await this.loadBackgroundImage(t);
3190
+ }
3191
+ async loadMaterialTexture(e = this.settings.materialTextureUrl) {
3192
+ let t = e.trim();
3193
+ if (this.settings.materialTextureUrl = t, !t) {
3194
+ this.clearMaterialTexture();
3195
+ return;
3196
+ }
3197
+ let n = await this.textureLoader.loadAsync(_n(t));
3198
+ this.materialTexture?.dispose(), this.materialTextureDisplayTexture?.dispose(), this.materialTextureDisplayTexture = null, this.materialTexture = n, this.configureImageTexture(n), n.wrapS = u.RepeatWrapping, n.wrapT = u.RepeatWrapping, this.settings.colorMode = "texture", this.updateMaterial(), this.renderIdleFrame();
3199
+ }
3200
+ async loadMaterialTextureFile(e, t) {
3201
+ await this.loadMaterialTexture(t);
3202
+ }
3203
+ clearMaterialTexture() {
3204
+ this.settings.materialTextureUrl = "", this.materialTexture?.dispose(), this.materialTexture = null, this.materialTextureDisplayTexture?.dispose(), this.materialTextureDisplayTexture = null, this.updateMaterial(), this.renderIdleFrame();
3205
+ }
3206
+ clearBackgroundImage() {
3207
+ this.settings.backgroundImageUrl = "", this.backgroundTexture?.dispose(), this.backgroundTexture = null, this.backgroundImageDisplayTexture?.dispose(), this.backgroundImageDisplayTexture = null, this.updateSceneBackground(), this.renderIdleFrame();
3208
+ }
3209
+ clearCustomAsset() {
3210
+ this.customAssetLoadId += 1, this.activeUserCustomAssetLoadId = 0, this.settings.assetUrl = "", this.settings.imageSetUrls = [], this.settings.imageAspectRatio = $.imageAspectRatio, this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.imageTexture?.dispose(), this.imageTexture = null, this.disposeImageSetTextures(), this.updateMaterial(), this.rebuildGeometry();
3211
+ }
3212
+ clearSvgAssetLoad(e) {
3213
+ this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.activeUserCustomAssetLoadId === e && (this.activeUserCustomAssetLoadId = 0), this.rebuildGeometry();
3214
+ }
3215
+ beginCustomAssetLoad(e, { showPlaceholder: t = !1, source: n = "background" }) {
3216
+ if (n === "background" && this.activeUserCustomAssetLoadId > 0) throw new Ft();
3217
+ let r = ++this.customAssetLoadId;
3218
+ return n === "user" && (this.activeUserCustomAssetLoadId = r), this.settings.assetUrl = e, t && (this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.settings.instanceShape = "custom-obj", this.rebuildGeometry()), r;
3219
+ }
3220
+ clearCustomAssetLoad(e) {
3221
+ this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.activeUserCustomAssetLoadId === e && (this.activeUserCustomAssetLoadId = 0), this.rebuildGeometry();
3222
+ }
3223
+ clearImageAssetLoad(e) {
3224
+ this.imageTexture?.dispose(), this.imageTexture = null, this.disposeImageSetTextures(), this.settings.imageAspectRatio = $.imageAspectRatio, this.activeUserCustomAssetLoadId === e && (this.activeUserCustomAssetLoadId = 0), this.updateMaterial(), this.rebuildGeometry();
3225
+ }
3226
+ completeCustomAssetLoad(e, t, n) {
3227
+ let r = this.activeUserCustomAssetLoadId === e;
3228
+ if (e !== this.customAssetLoadId && !r) throw t.dispose(), new Ft();
3229
+ this.customAssetLoadId = e, n(t, {
3230
+ assetScale: this.settings.assetScale,
3231
+ assetNormalize: this.settings.assetNormalize
3232
+ }), this.customObjGeometry = t, this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.disposeImageSetTextures(), this.imageTexture?.dispose(), this.imageTexture = null, this.settings.imageSetUrls = [], this.settings.instanceShape = "custom-obj", r && (this.activeUserCustomAssetLoadId = 0), this.rebuildGeometry();
3233
+ }
3234
+ completeSvgAssetLoad(e, t) {
3235
+ let n = this.activeUserCustomAssetLoadId === e;
3236
+ if (e !== this.customAssetLoadId && !n) throw t.dispose(), new Ft();
3237
+ this.customAssetLoadId = e, this.customSvgGeometry?.dispose(), this.customSvgGeometry = t, this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.disposeImageSetTextures(), this.imageTexture?.dispose(), this.imageTexture = null, this.settings.imageSetUrls = [], this.settings.instanceShape = "svg", n && (this.activeUserCustomAssetLoadId = 0), this.updateMaterial(), this.rebuildGeometry();
3238
+ }
3239
+ completeImageAssetLoad(e, t) {
3240
+ let n = this.activeUserCustomAssetLoadId === e;
3241
+ if (e !== this.customAssetLoadId && !n) throw t.dispose(), new Ft();
3242
+ this.customAssetLoadId = e, this.imageTexture?.dispose(), this.disposeImageSetTextures(), this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.customObjGeometry?.dispose(), this.customObjGeometry = null, this.configureImageTexture(t), this.imageTexture = t, this.imageSetTextures = [t], this.settings.imageSetUrls = [];
3243
+ let r = t.image, i = r?.width ?? $.imageAspectRatio, a = r?.height ?? 1;
3244
+ this.settings.imageAspectRatio = a > 0 ? Math.max(.01, i / a) : $.imageAspectRatio, this.settings.instanceShape = "image", n && (this.settings.imagePreserveAspectRatio && (this.settings.scaleX = this.settings.scaleZ * this.settings.imageAspectRatio), this.activeUserCustomAssetLoadId = 0), this.updateMaterial(), this.rebuildGeometry();
3245
+ }
3246
+ completeImageSetAssetLoad(e, t, n) {
3247
+ let r = this.activeUserCustomAssetLoadId === e;
3248
+ if (e !== this.customAssetLoadId && !r) throw n.forEach((e) => e.dispose()), new Ft();
3249
+ this.customAssetLoadId = e, this.imageTexture?.dispose(), this.disposeImageSetTextures(), this.customSvgGeometry?.dispose(), this.customSvgGeometry = null, this.customObjGeometry?.dispose(), this.customObjGeometry = null, n.forEach((e) => this.configureImageTexture(e)), this.imageSetTextures = n, this.imageTexture = n[0] ?? null, this.settings.assetUrl = t[0] ?? "", this.settings.imageSetUrls = t;
3250
+ let i = this.imageTexture?.image, a = i?.width ?? $.imageAspectRatio, o = i?.height ?? 1;
3251
+ this.settings.imageAspectRatio = o > 0 ? Math.max(.01, a / o) : $.imageAspectRatio, this.settings.instanceShape = "image", r && (this.settings.imagePreserveAspectRatio && (this.settings.scaleX = this.settings.scaleZ * this.settings.imageAspectRatio), this.activeUserCustomAssetLoadId = 0), this.updateMaterial(), this.rebuildGeometry();
3252
+ }
3253
+ configureImageTexture(e) {
3254
+ e.colorSpace = u.SRGBColorSpace, e.needsUpdate = !0;
3255
+ }
3256
+ updateSceneBackground() {
3257
+ if (this.settings.backgroundMode === "transparent") {
3258
+ this.scene.background = null;
3259
+ return;
3260
+ }
3261
+ if (this.settings.backgroundMode === "image") {
3262
+ this.scene.background = this.updateBackgroundImageDisplayTexture();
3263
+ return;
3264
+ }
3265
+ if (this.settings.backgroundMode === "gradient") {
3266
+ this.scene.background = this.updateBackgroundGradientTexture();
3267
+ return;
3268
+ }
3269
+ this.scene.background = new u.Color(this.settings.backgroundColor);
3270
+ }
3271
+ invalidateBackgroundImageDisplayTexture() {
3272
+ this.backgroundImageDisplayTexture?.dispose(), this.backgroundImageDisplayTexture = null;
3273
+ }
3274
+ invalidateTransparentBackgroundPreviewTexture() {
3275
+ this.transparentBackgroundPreviewTexture?.dispose(), this.transparentBackgroundPreviewTexture = null;
3276
+ }
3277
+ updateTransparentBackgroundPreviewTexture() {
3278
+ let { width: e, height: t } = this.getContainerSize(), n = Math.max(1, Math.round(e)), r = Math.max(1, Math.round(t)), i = this.transparentBackgroundPreviewTexture, a = i?.image instanceof HTMLCanvasElement ? i.image : document.createElement("canvas");
3279
+ if (i && a.width === n && a.height === r) return i;
3280
+ a.width = n, a.height = r;
3281
+ let o = a.getContext("2d");
3282
+ return o && this.drawCheckerBackground(o, n, r), this.transparentBackgroundPreviewTexture || (this.transparentBackgroundPreviewTexture = new u.CanvasTexture(a), this.transparentBackgroundPreviewTexture.colorSpace = u.SRGBColorSpace, this.transparentBackgroundPreviewTexture.wrapS = u.ClampToEdgeWrapping, this.transparentBackgroundPreviewTexture.wrapT = u.ClampToEdgeWrapping), this.transparentBackgroundPreviewTexture.needsUpdate = !0, this.transparentBackgroundPreviewTexture;
3283
+ }
3284
+ updateBackgroundImageDisplayTexture() {
3285
+ let { width: e, height: t } = this.getContainerSize(), n = Math.min(1, 1600 / Math.max(e, t)), r = Math.max(1, Math.round(e * n)), i = Math.max(1, Math.round(t * n)), a = r / i, o = this.backgroundImageDisplayTexture?.image instanceof HTMLCanvasElement ? this.backgroundImageDisplayTexture.image : document.createElement("canvas");
3286
+ o.width = r, o.height = i;
3287
+ let s = o.getContext("2d");
3288
+ if (!s) return this.backgroundTexture ?? this.getCheckerTexture();
3289
+ if (!this.backgroundTexture) this.drawCheckerBackground(s, r, i);
3290
+ else {
3291
+ let e = this.backgroundTexture.image, t = this.getTextureImageAspect(this.backgroundTexture);
3292
+ if (!t) return this.backgroundTexture;
3293
+ s.fillStyle = this.settings.backgroundColor, s.fillRect(0, 0, r, i);
3294
+ let n = this.settings.backgroundImageFit === "fit" ? t > a ? r / this.getTextureImageWidth(this.backgroundTexture) : i / this.getTextureImageHeight(this.backgroundTexture) : t > a ? i / this.getTextureImageHeight(this.backgroundTexture) : r / this.getTextureImageWidth(this.backgroundTexture), o = this.getTextureImageWidth(this.backgroundTexture) * n, c = this.getTextureImageHeight(this.backgroundTexture) * n;
3295
+ s.drawImage(e, (r - o) * .5, (i - c) * .5, o, c);
3296
+ }
3297
+ return this.backgroundImageDisplayTexture || (this.backgroundImageDisplayTexture = new u.CanvasTexture(o), this.backgroundImageDisplayTexture.colorSpace = u.SRGBColorSpace, this.backgroundImageDisplayTexture.wrapS = u.ClampToEdgeWrapping, this.backgroundImageDisplayTexture.wrapT = u.ClampToEdgeWrapping), this.backgroundImageDisplayTexture.needsUpdate = !0, this.backgroundImageDisplayTexture;
3298
+ }
3299
+ drawCheckerBackground(e, t, n) {
3300
+ e.fillStyle = Vt, e.fillRect(0, 0, t, n), e.fillStyle = Ht;
3301
+ for (let r = 0; r < n; r += zt) for (let n = r / zt % 2 == 0 ? zt : 0; n < t; n += zt * 2) e.fillRect(n, r, zt, zt);
3302
+ }
3303
+ updateBackgroundGradientTexture() {
3304
+ let e = this.backgroundGradientTexture?.image instanceof HTMLCanvasElement ? this.backgroundGradientTexture.image : document.createElement("canvas");
3305
+ e.width = 512, e.height = 512;
3306
+ let t = e.getContext("2d");
3307
+ if (!t) return new u.Color(this.settings.backgroundColor);
3308
+ let n = t.createImageData(512, 512), r = new u.Color(this.settings.backgroundGradientColorA), i = new u.Color(this.settings.backgroundGradientColorB), a = new u.Color(), o = cn(this.settings.backgroundGradientMidpoint), s = 511 * .5, c = Math.max(1e-4, Math.hypot(s, s));
3309
+ for (let e = 0; e < 512; e += 1) for (let t = 0; t < 512; t += 1) {
3310
+ let l = this.getBackgroundGradientProgress(t, e, 512, s, c), u = pt(this.remapGradientProgressWithMidpoint(l, o), this.settings.backgroundGradientEasing, this.settings.backgroundGradientCustomBezier);
3311
+ a.copy(r).lerp(i, u);
3312
+ let d = (e * 512 + t) * 4;
3313
+ n.data[d] = Math.round(a.r * 255), n.data[d + 1] = Math.round(a.g * 255), n.data[d + 2] = Math.round(a.b * 255), n.data[d + 3] = 255;
3314
+ }
3315
+ return t.putImageData(n, 0, 0), this.backgroundGradientTexture || (this.backgroundGradientTexture = new u.CanvasTexture(e), this.backgroundGradientTexture.colorSpace = u.SRGBColorSpace, this.backgroundGradientTexture.wrapS = u.ClampToEdgeWrapping, this.backgroundGradientTexture.wrapT = u.ClampToEdgeWrapping), this.backgroundGradientTexture.needsUpdate = !0, this.backgroundGradientTexture;
3316
+ }
3317
+ getBackgroundGradientProgress(e, t, n, r, i) {
3318
+ return this.settings.backgroundGradientDirection === "x" ? n <= 1 ? .5 : e / (n - 1) : this.settings.backgroundGradientDirection === "radial" ? u.MathUtils.clamp(Math.hypot(e - r, t - r) / i, 0, 1) : n <= 1 ? .5 : 1 - t / (n - 1);
3319
+ }
3320
+ getTextureImageAspect(e) {
3321
+ let t = this.getTextureImageWidth(e), n = this.getTextureImageHeight(e);
3322
+ return t <= 0 || n <= 0 ? null : t / n;
3323
+ }
3324
+ getTextureImageWidth(e) {
3325
+ let t = e.image;
3326
+ return t?.naturalWidth ?? t?.width ?? 0;
3327
+ }
3328
+ getTextureImageHeight(e) {
3329
+ let t = e.image;
3330
+ return t?.naturalHeight ?? t?.height ?? 0;
3331
+ }
3332
+ disposeImageSetTextures() {
3333
+ this.imageSetTextures.forEach((e) => {
3334
+ e !== this.imageTexture && e.dispose();
3335
+ }), this.imageSetTextures = [];
3336
+ }
3337
+ createGeometry() {
3338
+ return this.settings.instanceShape === "text" && (!this.textGeometryRuntime || !this.textFonts) && this.scheduleTextRuntimeLoad(), this.settings.instanceShape === "image" && this.imageTexture ? this.createImageGeometryForTexture(this.imageTexture) : this.settings.instanceShape === "image" && !this.imageTexture || this.settings.instanceShape === "svg" && !this.customSvgGeometry ? this.createImagePlaceholderGeometry() : Mt({
3339
+ settings: this.settings,
3340
+ customObjGeometry: this.customObjGeometry,
3341
+ customSvgGeometry: this.customSvgGeometry,
3342
+ textGeometry: this.textGeometryRuntime && this.textFonts ? {
3343
+ createTextGeometry: this.textGeometryRuntime.createTextGeometry,
3344
+ textFonts: this.textFonts
3345
+ } : null
3346
+ });
3347
+ }
3348
+ getInstanceDimensions() {
3349
+ return e(this.settings);
3350
+ }
3351
+ createMaterial() {
3352
+ let e, t = this.settings.shadingMode === "edge-outline" || this.settings.shadingMode === "silhouette-edge-outline", n = this.usesMaterialTextureSurface();
3353
+ if (e = this.settings.instanceShape === "image" ? this.imageTexture ? this.createImageMaterial(this.imageTexture) : this.createCheckerImageMaterial() : this.settings.instanceShape === "svg" && !this.customSvgGeometry ? this.createCheckerImageMaterial() : this.settings.shadingMode === "flat" || this.settings.shadingMode === "silhouette-outline" || this.settings.shadingMode === "edge-outline" || this.settings.shadingMode === "silhouette-edge-outline" ? new u.MeshBasicMaterial({ color: this.usesGradientSurfaceColor() || n ? "#ffffff" : this.settings.objectColor }) : this.settings.shadingMode === "toon" ? new u.MeshToonMaterial({ color: this.usesGradientSurfaceColor() || n ? "#ffffff" : this.settings.objectColor }) : new u.MeshStandardMaterial({
3354
+ color: this.usesGradientSurfaceColor() || n ? "#ffffff" : this.settings.objectColor,
3355
+ roughness: this.settings.roughness,
3356
+ metalness: this.settings.metalness
3357
+ }), t) e.side = u.DoubleSide, e.polygonOffset = !1, e.polygonOffsetFactor = 0, e.polygonOffsetUnits = 0;
3358
+ else {
3359
+ let t = this.settings.instanceShape === "image", n = this.settings.instanceShape === "svg" && !this.settings.svgSolidify, r = this.settings.instanceShape === "text" && !this.settings.textSolidify, i = this.settings.instanceShape === "custom-obj" && this.settings.assetDoubleSided;
3360
+ (t || n || r || i) && (e.side = u.DoubleSide), e.polygonOffset = !0, e.polygonOffsetFactor = 1, e.polygonOffsetUnits = 1;
3361
+ }
3362
+ return this.enableInstanceOpacity(e, {
3363
+ alphaHash: !0,
3364
+ objectGradient: this.usesObjectGradient(),
3365
+ materialTexture: n
3366
+ });
3367
+ }
3368
+ usesGradientSurfaceColor() {
3369
+ return this.settings.colorMode === "gradient" && this.settings.instanceShape !== "image";
3370
+ }
3371
+ usesMaterialTextureSurface() {
3372
+ return this.settings.colorMode === "texture" && this.isTextureMaterialShape();
3373
+ }
3374
+ isTextureMaterialShape() {
3375
+ return this.settings.instanceShape !== "image" && this.settings.instanceShape !== "svg";
3376
+ }
3377
+ usesInstanceColors() {
3378
+ return this.usesGradientSurfaceColor() && this.settings.gradientScope === "pattern";
3379
+ }
3380
+ usesObjectGradient() {
3381
+ return this.usesGradientSurfaceColor() && this.settings.gradientScope === "object";
3382
+ }
3383
+ getMaterialTextureModeIndex() {
3384
+ return this.materialTexture ? this.settings.materialTextureFit === "fit" ? 1 : this.settings.materialTextureFit === "fill" ? 2 : this.settings.materialTextureFit === "repeat" ? 3 : 0 : 3;
3385
+ }
3386
+ getMaterialTextureScopeIndex() {
3387
+ return +(this.settings.materialTextureScope === "pattern");
3388
+ }
3389
+ getMaterialTextureProjectionIndex() {
3390
+ return +(this.settings.materialTextureProjection === "triplanar");
3391
+ }
3392
+ createImageMaterial(e) {
3393
+ return this.enableInstanceOpacity(new u.MeshBasicMaterial({
3394
+ map: e,
3395
+ transparent: !0,
3396
+ alphaTest: .01,
3397
+ depthTest: !0,
3398
+ depthWrite: !0,
3399
+ side: u.DoubleSide
3400
+ }), { alphaHash: !0 });
3401
+ }
3402
+ createCheckerImageMaterial() {
3403
+ return this.enableInstanceOpacity(new u.MeshBasicMaterial({
3404
+ map: this.getCheckerTexture(),
3405
+ depthTest: !0,
3406
+ depthWrite: !0,
3407
+ side: u.DoubleSide
3408
+ }), { alphaHash: !0 });
3409
+ }
3410
+ getMaterialTexture() {
3411
+ return this.materialTexture ?? this.getCheckerTexture();
3412
+ }
3413
+ getMaterialTextureRepeat(e) {
3414
+ return this.materialTexture ? Math.max(.001, e) : Bt;
3415
+ }
3416
+ getCheckerTexture() {
3417
+ if (this.checkerTexture) return this.checkerTexture;
3418
+ let e = document.createElement("canvas");
3419
+ e.width = Q * 2, e.height = Q * 2;
3420
+ let t = e.getContext("2d");
3421
+ return t && (t.fillStyle = Vt, t.fillRect(0, 0, e.width, e.height), t.fillStyle = Ht, t.fillRect(Q, 0, Q, Q), t.fillRect(0, Q, Q, Q)), this.checkerTexture = new u.CanvasTexture(e), this.checkerTexture.colorSpace = u.SRGBColorSpace, this.checkerTexture.wrapS = u.RepeatWrapping, this.checkerTexture.wrapT = u.RepeatWrapping, this.checkerTexture.magFilter = u.NearestFilter, this.checkerTexture.minFilter = u.NearestFilter, this.checkerTexture.repeat.set(Bt, Bt), this.checkerTexture.needsUpdate = !0, this.checkerTexture;
3422
+ }
3423
+ getTextureAspectRatio(e) {
3424
+ let t = e.image, n = t?.width ?? $.imageAspectRatio, r = t?.height ?? 1;
3425
+ return r > 0 ? Math.max(.01, n / r) : $.imageAspectRatio;
3426
+ }
3427
+ createImageGeometryForTexture(e) {
3428
+ let { scaleX: t, scaleZ: n } = this.getInstanceDimensions(), r = this.settings.imagePreserveAspectRatio ? n * this.getTextureAspectRatio(e) : t, i = Math.min(.5, Math.max(0, this.settings.imageCornerRadius)), a = i > 0 ? pn(r, n, Math.min(r, n) * i) : new u.PlaneGeometry(r, n);
3429
+ return a.rotateX(-Math.PI / 2), a;
3430
+ }
3431
+ createImagePlaceholderGeometry() {
3432
+ let { scaleX: e, scaleZ: t } = this.getInstanceDimensions(), n = new u.PlaneGeometry(e, t);
3433
+ return n.rotateX(-Math.PI / 2), n;
3434
+ }
3435
+ createOutlineMaterial() {
3436
+ return this.enableInstanceOpacity(new u.MeshBasicMaterial({
3437
+ color: this.settings.silhouetteColor,
3438
+ side: u.BackSide,
3439
+ opacity: 1,
3440
+ depthTest: !0,
3441
+ depthWrite: !0
3442
+ }), { alphaHash: !0 });
3443
+ }
3444
+ createEdgeGeometry(e) {
3445
+ let t = new u.EdgesGeometry(e, 1), n = t.getAttribute("position").array, r = new oe();
3446
+ return r.setPositions(Array.from(n)), t.dispose(), r;
3447
+ }
3448
+ createEdgeMaterial() {
3449
+ let e = new E({
3450
+ color: new u.Color(this.settings.edgeColor).getHex(),
3451
+ linewidth: this.settings.edgeThickness * 1e3,
3452
+ transparent: !0,
3453
+ opacity: this.settings.outlineOpacity,
3454
+ depthTest: !this.settings.outlineSeeThrough,
3455
+ depthWrite: !1,
3456
+ polygonOffset: !1,
3457
+ polygonOffsetFactor: 0,
3458
+ polygonOffsetUnits: 0
3459
+ }), { width: t, height: n } = this.getContainerSize();
3460
+ return e.resolution.set(t, n), e;
3461
+ }
3462
+ shouldShowSilhouetteOutline() {
3463
+ return this.settings.shadingMode === "silhouette-outline" || this.settings.shadingMode === "silhouette-edge-outline";
3464
+ }
3465
+ shouldShowEdgeOutline() {
3466
+ return this.settings.shadingMode === "edge-outline" || this.settings.shadingMode === "silhouette-edge-outline";
3467
+ }
3468
+ createEdgeLine() {
3469
+ if (!this.edgeGeometry || !this.edgeMaterial) return null;
3470
+ let e = this.edgeMaterial.clone(), { width: t, height: n } = this.getContainerSize();
3471
+ e.resolution.set(t, n), e.depthTest = !this.settings.outlineSeeThrough, e.depthWrite = !1, e.polygonOffset = !1, e.polygonOffsetFactor = 0, e.polygonOffsetUnits = 0;
3472
+ let r = new _e(this.edgeGeometry, e);
3473
+ return r.renderOrder = this.getEdgeRenderOrder(), r.matrixAutoUpdate = !1, r.frustumCulled = !1, r;
3474
+ }
3475
+ syncImageSetMeshes() {
3476
+ let e = this.getImageTextures(), t = Math.max(0, e.length - 1), n = this.mesh.instanceMatrix.count;
3477
+ for (; this.imageSetMeshes.length > t;) {
3478
+ let e = this.imageSetMeshes.pop();
3479
+ e && (this.scene.remove(e), e.geometry.dispose(), this.disposeMeshMaterial(e.material));
3480
+ }
3481
+ for (; this.imageSetMeshes.length < t;) {
3482
+ let t = e[this.imageSetMeshes.length + 1], r = new u.InstancedMesh(this.createImageGeometryForTexture(t), this.createImageMaterial(t), n);
3483
+ r.renderOrder = this.mesh.renderOrder, r.frustumCulled = !1, this.imageSetMeshes.push(r), this.scene.add(r);
3484
+ }
3485
+ this.imageSetMeshes.forEach((t, r) => {
3486
+ let i = e[r + 1];
3487
+ if (t.instanceMatrix.count !== n) {
3488
+ let e = new u.InstancedMesh(this.createImageGeometryForTexture(i), this.createImageMaterial(i), n);
3489
+ e.renderOrder = t.renderOrder, e.frustumCulled = !1, e.count = t.count, this.scene.remove(t), t.geometry.dispose(), this.disposeMeshMaterial(t.material), this.imageSetMeshes[r] = e, this.scene.add(e);
3490
+ return;
3491
+ }
3492
+ t.geometry.dispose(), t.geometry = this.createImageGeometryForTexture(i), this.disposeMeshMaterial(t.material), t.material = this.createImageMaterial(i), t.renderOrder = this.mesh.renderOrder;
3493
+ }), this.syncImageSetMeshTransforms();
3494
+ }
3495
+ disposeImageSetMeshes() {
3496
+ this.imageSetMeshes.forEach((e) => {
3497
+ this.scene.remove(e), e.geometry.dispose(), this.disposeMeshMaterial(e.material);
3498
+ }), this.imageSetMeshes = [];
3499
+ }
3500
+ disposeMeshMaterial(e) {
3501
+ if (Array.isArray(e)) {
3502
+ e.forEach((e) => e.dispose());
3503
+ return;
3504
+ }
3505
+ e.dispose();
3506
+ }
3507
+ rebuildEdgeLines() {
3508
+ this.edgeLines.forEach((e) => {
3509
+ this.edgeGroup.remove(e), this.disposeMeshMaterial(e.material);
3510
+ }), this.edgeLines = [], this.shouldShowEdgeOutline() && this.syncEdgeLineCount();
3511
+ }
3512
+ syncEdgeLineCount() {
3513
+ if (!this.shouldShowEdgeOutline()) {
3514
+ this.edgeGroup.visible = !1;
3515
+ return;
3516
+ }
3517
+ for (this.edgeGroup.visible = !0; this.edgeLines.length < this.layouts.length;) {
3518
+ let e = this.createEdgeLine();
3519
+ if (!e) return;
3520
+ this.edgeLines.push(e), this.edgeGroup.add(e);
3521
+ }
3522
+ this.edgeLines.forEach((e, t) => {
3523
+ e.visible = t < this.layouts.length, e.renderOrder = this.getEdgeRenderOrder();
3524
+ });
3525
+ }
3526
+ setEdgeLineOpacity(e, t) {
3527
+ let n = e.material;
3528
+ n.opacity = this.settings.outlineOpacity * u.MathUtils.clamp(t, 0, 1), n.transparent = !0, n.needsUpdate = !0;
3529
+ }
3530
+ getEdgeRenderOrder() {
3531
+ return this.settings.edgeCompositing === "surface" ? 2 : 10;
3532
+ }
3533
+ getEdgeScaleLift() {
3534
+ return 1;
3535
+ }
3536
+ ensureCameraType() {
3537
+ this.settings.viewMode === "perspective" != this.camera instanceof u.PerspectiveCamera && (this.camera = this.createCamera());
3538
+ }
3539
+ updateCamera() {
3540
+ this.settings.viewMode === "orthographic" && (this.frustumSize = this.getOrthographicFrustumSize()), this.settings.viewMode === "orthographic" && this.settings.orthographicView !== "custom" ? this.updateOrthographicViewCamera() : this.updateCameraOrbit(), this.updateCameraProjection(), this.camera.position.set(this.settings.cameraPositionX, this.settings.cameraPositionY, this.settings.cameraPositionZ);
3541
+ let e = Fe({
3542
+ distance: this.settings.cameraDistance,
3543
+ azimuth: this.settings.cameraOrbitAngle,
3544
+ elevation: this.settings.cameraElevation,
3545
+ target: {
3546
+ x: this.settings.cameraTargetX,
3547
+ y: this.settings.cameraTargetY,
3548
+ z: this.settings.cameraTargetZ
3549
+ }
3550
+ });
3551
+ this.camera.up.set(e.x, e.y, e.z), this.camera.lookAt(this.settings.cameraTargetX, this.settings.cameraTargetY, this.settings.cameraTargetZ), this.camera.updateProjectionMatrix();
3552
+ }
3553
+ applyCameraSettings() {
3554
+ this.updateCamera(), this.notifyCameraChange(), this.renderIdleFrame();
3555
+ }
3556
+ setStarfieldFlightFromCamera(e = !0) {
3557
+ if (this.settings.distributionMode !== "starfield") return;
3558
+ let t = this.alignVecScratch.set(this.settings.cameraPositionX - this.settings.cameraTargetX, this.settings.cameraPositionY - this.settings.cameraTargetY, this.settings.cameraPositionZ - this.settings.cameraTargetZ);
3559
+ if (t.lengthSq() < 1e-8) return;
3560
+ t.normalize();
3561
+ let n = this.alignUpScratch.setFromMatrixColumn(this.camera.matrixWorld, 1).normalize(), r = this.alignRightScratch.copy(n).cross(t);
3562
+ if (r.lengthSq() < 1e-8) return;
3563
+ r.normalize();
3564
+ let i = n.copy(t).cross(r).normalize();
3565
+ this.alignMatrixScratch.makeBasis(r, i, t), this.orientationEulerScratch.setFromRotationMatrix(this.alignMatrixScratch), this.settings.pathOrientationX = this.orientationEulerScratch.x, this.settings.pathOrientationY = this.orientationEulerScratch.y, this.settings.pathOrientationZ = this.orientationEulerScratch.z, e && this.updatePattern();
3566
+ }
3567
+ updateOrthographicViewCamera() {
3568
+ let e = Math.max(1, this.settings.cameraDistance || 42), t = this.settings.cameraTargetX, n = this.settings.cameraTargetY, r = this.settings.cameraTargetZ;
3569
+ switch (this.settings.orthographicView) {
3570
+ case "front":
3571
+ this.settings.cameraPositionX = t, this.settings.cameraPositionY = n, this.settings.cameraPositionZ = r + e;
3572
+ break;
3573
+ case "back":
3574
+ this.settings.cameraPositionX = t, this.settings.cameraPositionY = n, this.settings.cameraPositionZ = r - e;
3575
+ break;
3576
+ case "left":
3577
+ this.settings.cameraPositionX = t - e, this.settings.cameraPositionY = n, this.settings.cameraPositionZ = r;
3578
+ break;
3579
+ case "right":
3580
+ this.settings.cameraPositionX = t + e, this.settings.cameraPositionY = n, this.settings.cameraPositionZ = r;
3581
+ break;
3582
+ case "top":
3583
+ this.settings.cameraPositionX = t, this.settings.cameraPositionY = n + e, this.settings.cameraPositionZ = r;
3584
+ break;
3585
+ default:
3586
+ this.updateCameraOrbit();
3587
+ break;
3588
+ }
3589
+ }
3590
+ getOrthographicFrustumSize() {
3591
+ return Kt * (Gt / L(this.settings.orthoScale, $.orthoScale, F.camera.orthographicFrustumScale));
3592
+ }
3593
+ createCamera() {
3594
+ let { width: e, height: t } = this.getContainerSize(), n = e / t;
3595
+ return this.settings.viewMode === "perspective" ? new u.PerspectiveCamera(this.getPerspectiveFovFromFocalLength(), n, F.camera.perspectiveClip.near, F.camera.perspectiveClip.far) : new u.OrthographicCamera(this.frustumSize * n / -2, this.frustumSize * n / 2, this.frustumSize / 2, this.frustumSize / -2, F.camera.orthographicClip.near, F.camera.orthographicClip.far);
3596
+ }
3597
+ createViewportGrid() {
3598
+ let e = new u.GridHelper(80, 80, "#6c6c6c", "#6c6c6c");
3599
+ return e.visible = !1, e.renderOrder = -1, (Array.isArray(e.material) ? e.material : [e.material]).forEach((e) => {
3600
+ e.transparent = !0, e.opacity = .32, e.depthWrite = !1;
3601
+ }), e;
3602
+ }
3603
+ updateCameraProjection() {
3604
+ let { width: e, height: t } = this.getContainerSize(), n = e / t;
3605
+ if (this.camera instanceof u.PerspectiveCamera) {
3606
+ this.camera.fov = this.getPerspectiveFovFromFocalLength(), this.camera.aspect = n, this.camera.near = F.camera.perspectiveClip.near, this.camera.far = this.getPerspectiveFarClip(), this.camera.updateProjectionMatrix();
3607
+ return;
3608
+ }
3609
+ this.camera.left = this.frustumSize * n / -2, this.camera.right = this.frustumSize * n / 2, this.camera.top = this.frustumSize / 2, this.camera.bottom = this.frustumSize / -2, this.camera.updateProjectionMatrix();
3610
+ }
3611
+ getPerspectiveFarClip() {
3612
+ let e = F.camera.perspectiveClip.far;
3613
+ if (!this.mesh) return e;
3614
+ let t = this.getSubjectBounds(), n = new u.Sphere();
3615
+ t.getBoundingSphere(n);
3616
+ let r = new u.Vector3(this.settings.cameraPositionX, this.settings.cameraPositionY, this.settings.cameraPositionZ).distanceTo(n.center) + n.radius;
3617
+ return Math.max(e, r * 1.25);
3618
+ }
3619
+ getContainerSize() {
3620
+ return this.exportSizeOverride ? this.exportSizeOverride : this.getLiveContainerSize();
3621
+ }
3622
+ getLiveContainerSize() {
3623
+ let e = this.container.getBoundingClientRect();
3624
+ return {
3625
+ width: Math.max(1, e.width || window.innerWidth),
3626
+ height: Math.max(1, e.height || window.innerHeight)
3627
+ };
3628
+ }
3629
+ getSubjectBounds() {
3630
+ let e = new u.Box3(), t = new u.Matrix4(), n = new u.Matrix4(), r = new u.Box3(), i = (i) => {
3631
+ i.geometry.computeBoundingBox();
3632
+ let a = i.geometry.boundingBox;
3633
+ if (a) {
3634
+ i.updateMatrixWorld();
3635
+ for (let o = 0; o < i.count; o += 1) i.getMatrixAt(o, t), n.multiplyMatrices(i.matrixWorld, t), r.copy(a).applyMatrix4(n), e.union(r);
3636
+ }
3637
+ };
3638
+ return i(this.mesh), this.imageSetMeshes.forEach(i), e.isEmpty() && e.setFromCenterAndSize(new u.Vector3(this.settings.cameraTargetX, this.settings.cameraTargetY, this.settings.cameraTargetZ), new u.Vector3(1, 1, 1)), e;
3639
+ }
3640
+ getPerspectiveFovFromFocalLength() {
3641
+ return ve(this.settings.cameraFocalLength);
3642
+ }
3643
+ updateColors() {
3644
+ this.settings.backgroundMode === "image" && this.invalidateBackgroundImageDisplayTexture(), this.updateSceneBackground(), this.updateMaterial(), this.renderIdleFrame();
3645
+ }
3646
+ updateMaterial() {
3647
+ let e = this.mesh.material;
3648
+ this.disposeMeshMaterial(e);
3649
+ let t = this.outlineMesh.material;
3650
+ this.disposeMeshMaterial(t), this.mesh.material = this.createMaterial(), this.syncImageSetMeshes(), this.outlineMesh.material = this.createOutlineMaterial(), this.edgeMaterial?.dispose(), this.edgeMaterial = this.createEdgeMaterial(), this.outlineMesh.visible = this.shouldShowSilhouetteOutline(), this.edgeGroup.visible = this.shouldShowEdgeOutline(), this.edgeGroup.renderOrder = this.getEdgeRenderOrder(), this.shouldShowEdgeOutline() ? (this.edgeGeometry ||= this.createEdgeGeometry(this.mesh.geometry), this.edgeLines.forEach((e) => {
3651
+ this.disposeMeshMaterial(e.material), e.material = this.edgeMaterial.clone();
3652
+ }), this.syncEdgeLineCount()) : this.rebuildEdgeLines(), this.updateLights(), this.renderIdleFrame();
3653
+ }
3654
+ getMaxInstanceCount() {
3655
+ let { gridSize: e, gridLayers: t, ringCount: n, ringDensity: r, pathInstanceCount: i, pathRows: a } = ze(this.settings), o = Math.ceil(1 + r * (n * (n + 1)) / 2), s = i * Math.max(1, Math.round(a)), c = e * e * Math.max(1, Math.round(t));
3656
+ return Math.max(1, e * e, c, o, s);
3657
+ }
3658
+ ensureMeshCapacity(e) {
3659
+ if (e <= this.mesh.instanceMatrix.count) return;
3660
+ let t = this.mesh.geometry, n = this.mesh.material, r = Math.ceil(e * 1.25), i = new u.InstancedMesh(t, n, r);
3661
+ i.renderOrder = 1, i.frustumCulled = !1;
3662
+ let a = new u.InstancedMesh(this.outlineMesh.geometry, this.outlineMesh.material, r);
3663
+ a.renderOrder = 0, a.frustumCulled = !1, a.visible = this.outlineMesh.visible, this.scene.remove(this.mesh), this.scene.remove(this.outlineMesh), this.mesh = i, this.outlineMesh = a, this.scene.add(this.mesh), this.scene.add(this.outlineMesh), this.syncImageSetMeshes();
3664
+ }
3665
+ createLayouts() {
3666
+ return Ue(this.settings);
3667
+ }
3668
+ getSpinStaggerFactor(e, t) {
3669
+ let n = this.settings.instanceSpinStagger;
3670
+ if (n === 0) return 1;
3671
+ let r = fn(this.settings.distributionMode) ? e.spinProgress : this.getLayoutProgress(e, t);
3672
+ if (this.settings.instanceSpinStaggerMode === "alternating") {
3673
+ let t = e.gridX % 2 == 0 ? 1 : -1;
3674
+ return Math.max(-4, 1 + t * n * r);
3675
+ }
3676
+ return Math.max(-4, 1 + n * r);
3677
+ }
3678
+ getSpinPhaseOffset(e, t) {
3679
+ let n = this.settings.instanceSpinPhaseStagger;
3680
+ if (n === 0) return 0;
3681
+ let r = fn(this.settings.distributionMode) ? e.spinProgress : this.getLayoutProgress(e, t);
3682
+ return this.settings.instanceSpinStaggerMode === "alternating" ? (e.gridX % 2 == 0 ? 1 : -1) * n * r : n * r;
3683
+ }
3684
+ getLayoutProgress(e, t) {
3685
+ return t === 0 ? 0 : e.distance / t;
3686
+ }
3687
+ renderExportFrameAt(e, t) {
3688
+ if (!this.hasTimeVaryingMotion()) {
3689
+ this.renderScene(t);
3690
+ return;
3691
+ }
3692
+ this.renderAnimatedFrame(e, this.getPathTravelTime(e), this.getRingOrbitTime(e), t);
3693
+ }
3694
+ animate = () => {
3695
+ let e = (performance.now() - this.startTime) / 1e3;
3696
+ if (!this.hasTimeVaryingMotion()) {
3697
+ this.animationFrameId = null, this.updatePattern();
3698
+ return;
3699
+ }
3700
+ let t = Math.max(0, Math.min(.1, e - this.previousAnimationElapsed));
3701
+ this.previousAnimationElapsed = e, this.pathTravelProgress += this.getPathTravelDelta(t), this.ringOrbitProgress += this.getRingOrbitDelta(t), this.renderAnimatedFrame(e, this.pathTravelProgress, this.ringOrbitProgress), this.animationFrameId = requestAnimationFrame(this.animate);
3702
+ };
3703
+ getPathTravelTime(e) {
3704
+ return this.settings.pathTravelMode === "stepped" ? e : e * this.settings.pathTravelSpeed;
3705
+ }
3706
+ getRingOrbitTime(e) {
3707
+ return this.settings.pathTravelMode === "stepped" ? e : e * this.settings.ringOrbitSpeed;
3708
+ }
3709
+ getPathTravelDelta(e) {
3710
+ return this.settings.pathTravelMode === "stepped" ? e : e * this.settings.pathTravelSpeed;
3711
+ }
3712
+ getRingOrbitDelta(e) {
3713
+ return this.settings.pathTravelMode === "stepped" ? e : e * this.settings.ringOrbitSpeed;
3714
+ }
3715
+ renderAnimatedFrame(e, t, n, r = this.renderer) {
3716
+ let { instanceRotationX: i, instanceRotationY: a, instanceRotationZ: o, instanceSpinX: s, instanceSpinY: c, instanceSpinZ: l, instanceSpinStagger: u, instanceSpinPhaseStagger: d, pathRotationX: f, pathRotationY: p, pathRotationZ: m, waveAmplitude: h, waveFrequency: g, waveSpeed: _, easingMode: v, easingCustomBezier: y, staggerAmount: b, scaleMode: x, scaleAmount: ee, animationMode: S, scaleY: C, baseY: w, groundAlign: te } = this.settings;
3717
+ this.setStructureRotation(e * f, e * p, e * m);
3718
+ let T = {
3719
+ ...this.settings,
3720
+ ...ze(this.settings),
3721
+ ringOrbitFriction: this.settings.ringOrbitFriction
3722
+ }, ne = this.getEdgeScaleLift(), re = w + (te ? C / 2 : 0), ie = u === 0 && d === 0 ? 0 : this.layouts.reduce((e, t) => Math.max(e, t.distance), 0);
3723
+ this.clearInstanceColorsForImageSurfaces(), this.ensureInstanceOpacityAttribute(this.mesh), this.ensureInstanceOpacityAttribute(this.outlineMesh), this.imageSetMeshes.forEach((e) => this.ensureInstanceOpacityAttribute(e));
3724
+ let ae = this.createSurfaceWriteState(), oe = this.getLayoutBounds(this.layouts), E = this.getBuildTransform(this.getBuildProgress(e));
3725
+ this.layouts.forEach((r, u) => {
3726
+ let d = bt({
3727
+ layout: r,
3728
+ settings: T,
3729
+ pathTravelProgress: t,
3730
+ ringOrbitProgress: n
3731
+ }), f = (d.gridX + d.gridZ) % 2 == 0 ? 1 : -1, p = d.distance;
3732
+ S === "linear-wave" && (p = d.x + d.z), S === "checker-wave" && (p = d.distance * f), S === "ring-wave" && (p = d.ringIndex);
3733
+ let m = (d.distance + d.ringIndex) * b, C = e * _ - m, w = Math.sin(p * g - C);
3734
+ w = mt(w, v, y), S === "cross-field" && (w = mt(Math.sin(d.x * g - C) * Math.sin(d.z * g + C), v, y));
3735
+ let te = Math.abs(_) <= Z ? 0 : w * h;
3736
+ this.dummy.position.set(d.x * E.sceneScale, (re + d.y + te) * E.sceneScale + E.offsetY, d.z * E.sceneScale);
3737
+ let D = this.getInstanceScale(d, x, ee) * E.scale * E.sceneScale;
3738
+ this.dummy.scale.set(D, D, D);
3739
+ let se = this.getSpinStaggerFactor(d, ie), ce = this.getSpinPhaseOffset(d, ie), O = this.alignQuaternion(d, this.alignQuatScratch);
3740
+ this.manualQuatScratch.setFromEuler(this.orientationEulerScratch.set(i + E.rotationX, a + E.rotationY, o + E.rotationZ)), this.spinQuatScratch.setFromEuler(this.orientationEulerScratch.set(e * s * se + (Math.abs(s) > 1e-4 ? ce : 0), e * c * se + (Math.abs(c) > 1e-4 ? ce : 0), e * l * se + (Math.abs(l) > 1e-4 ? ce : 0))), this.dummy.quaternion.copy(O).multiply(this.manualQuatScratch).multiply(this.spinQuatScratch), this.dummy.updateMatrix();
3741
+ let k = this.getInstanceOpacity(u, d) * E.opacity, A = this.setSurfaceMatrixAt(u, this.dummy.matrix, ae);
3742
+ this.setInstanceOpacityAt(A.mesh, A.index, k), this.setInstanceColorAt(A.mesh, A.index, this.getInstanceColor(d, oe)), this.dummy.scale.setScalar(D * ne), this.dummy.updateMatrix();
3743
+ let le = this.edgeLines[u];
3744
+ le && (le.matrix.copy(this.dummy.matrix), le.matrixWorldNeedsUpdate = !0, this.setEdgeLineOpacity(le, k)), this.dummy.scale.setScalar(D * (1 + this.settings.outlineThickness)), this.dummy.updateMatrix(), this.outlineMesh.setMatrixAt(u, this.dummy.matrix), this.setInstanceOpacityAt(this.outlineMesh, u, k);
3745
+ }), this.finishSurfaceWrites(ae), this.outlineMesh.instanceMatrix.needsUpdate = !0, this.renderScene(r);
3746
+ }
3747
+ getInstanceScale(e, t, n) {
3748
+ if (t === "constant" || n === 0) return 1;
3749
+ let r = this.layouts.reduce((e, t) => Math.max(e, t.distance), 0), i = r === 0 ? 0 : e.distance / r, a = (e) => {
3750
+ let t = Math.max(0, Math.min(1, e));
3751
+ return t * t * (3 - 2 * t);
3752
+ }, o = (e, t = n) => {
3753
+ let r = a(e);
3754
+ return L(t >= 0 ? 1 + r * t : 1 / (1 + r * Math.abs(t)), 1, F.instance.scaleVariationMultiplier);
3755
+ };
3756
+ if (t === "center-out") return o(i);
3757
+ if (t === "edge-out") return o(1 - i);
3758
+ if (t === "alternating") return o(1, ((e.gridX + e.gridZ) % 2 == 0 ? 1 : -1) * n);
3759
+ let s = Math.max(0, Math.min(1, e.pathProgress)), c = 1 - Math.abs(s - .5) * 2, l = Math.abs(s - .5) * 2;
3760
+ if (t === "path-linear") return o(s);
3761
+ if (t === "path-linear-reverse") return o(1 - s);
3762
+ if (t === "path-center") return o(c);
3763
+ if (t === "path-edges") return o(l);
3764
+ if (t === "path-quad") return o(s * s);
3765
+ if (t === "path-quad-reverse") {
3766
+ let e = 1 - s;
3767
+ return o(e * e);
3768
+ }
3769
+ return 1;
3770
+ }
3771
+ addLights() {
3772
+ this.ambientLight = new u.AmbientLight("#ffffff", this.settings.ambientIntensity), this.scene.add(this.ambientLight), this.directionalLight = new u.DirectionalLight("#ffffff", this.settings.lightIntensity), this.setDirectionalLightPosition(), this.scene.add(this.directionalLight);
3773
+ }
3774
+ updateLights() {
3775
+ this.ambientLight && (this.ambientLight.intensity = this.settings.ambientIntensity), this.directionalLight && (this.directionalLight.intensity = this.settings.lightIntensity, this.setDirectionalLightPosition()), this.renderIdleFrame();
3776
+ }
3777
+ setDirectionalLightPosition() {
3778
+ if (!this.directionalLight) return;
3779
+ let e = Math.cos(this.settings.lightElevation) * 18;
3780
+ this.directionalLight.position.set(Math.cos(this.settings.lightAzimuth) * e, Math.sin(this.settings.lightElevation) * 18, Math.sin(this.settings.lightAzimuth) * e), this.directionalLight.lookAt(0, 0, 0);
3781
+ }
3782
+ applyRendererPixelRatio() {
3783
+ this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, this.settings.renderPixelRatio));
3784
+ }
3785
+ observeContainerSize() {
3786
+ if (typeof ResizeObserver > "u") return;
3787
+ let { width: e, height: t } = this.getLiveContainerSize();
3788
+ this.observedWidth = e, this.observedHeight = t, this.containerResizeObserver = new ResizeObserver(() => {
3789
+ if (this.disposed) return;
3790
+ let e = this.getLiveContainerSize();
3791
+ e.width === this.observedWidth && e.height === this.observedHeight || (this.observedWidth = e.width, this.observedHeight = e.height, this.handleResize());
3792
+ }), this.containerResizeObserver.observe(this.container);
3793
+ }
3794
+ handleResize = () => {
3795
+ this.settings.viewMode === "orthographic" && (this.frustumSize = this.getOrthographicFrustumSize()), this.updateCameraProjection();
3796
+ let { width: e, height: t } = this.getContainerSize();
3797
+ this.applyRendererPixelRatio(), this.renderer.setSize(e, t), this.invalidateBackgroundImageDisplayTexture(), this.invalidateTransparentBackgroundPreviewTexture(), this.updateSceneBackground(), this.updateEdgeResolution(e, t), this.renderIdleFrame();
3798
+ };
3799
+ }, xn = 8, Sn = "300px", Cn = /* @__PURE__ */ new Set(), wn = /* @__PURE__ */ new WeakMap(), Tn = /* @__PURE__ */ new WeakSet(), En = /* @__PURE__ */ new Map(), Dn = null, On = xn, kn = 0, An = !1, jn = !1, Mn = () => typeof IntersectionObserver < "u", Nn = () => typeof document > "u" || document.visibilityState !== "hidden", Pn = () => {
3800
+ let e = 0;
3801
+ for (let t of Cn) t.isMounted() && (e += 1);
3802
+ return e;
3803
+ }, Fn = (e) => {
3804
+ let t = null;
3805
+ for (let n of Cn) n === e || !n.isMounted() || !n.evictable || n.visible || (!t || n.lastUsed < t.lastUsed) && (t = n);
3806
+ return t;
3807
+ }, In = () => {
3808
+ An || (An = !0, console.warn(`Sinth: more than ${On} embeds are on screen at once, so the WebGL context budget cannot be honoured. The browser may drop the oldest context. Show fewer patterns at a time, or raise \`maxLiveContexts\` if the page can afford it.`));
3809
+ }, Ln = (e) => {
3810
+ for (; Pn() >= On;) {
3811
+ let t = Fn(e);
3812
+ if (!t) {
3813
+ In();
3814
+ return;
3815
+ }
3816
+ t.unmount();
3817
+ }
3818
+ }, Rn = (e) => {
3819
+ kn += 1, e.lastUsed = kn, !e.isMounted() && (Ln(e), e.mount());
3820
+ }, zn = (e, t) => {
3821
+ if (e.visible = t, !t) {
3822
+ e.suspend();
3823
+ return;
3824
+ }
3825
+ Rn(e), Nn() && e.resume();
3826
+ }, Bn = () => {
3827
+ let e = Nn();
3828
+ for (let t of Cn) t.isMounted() && (e ? t.visible && t.resume() : t.suspend());
3829
+ }, Vn = () => {
3830
+ jn || typeof document > "u" || (jn = !0, document.addEventListener("visibilitychange", Bn));
3831
+ }, Hn = (e) => {
3832
+ let t = En.get(e);
3833
+ return t || (t = new IntersectionObserver((e) => {
3834
+ for (let t of e) {
3835
+ let e = wn.get(t.target);
3836
+ if (e) for (let n of e) zn(n, t.isIntersecting);
3837
+ }
3838
+ }, { rootMargin: e }), En.set(e, t)), t;
3839
+ }, Un = (e) => {
3840
+ if (Tn.has(e)) return;
3841
+ Tn.add(e);
3842
+ let t = e.id ? `id="${e.id}"` : e.className ? `class="${e.className}"` : "the same element";
3843
+ console.warn(`Sinth: more than one embed is pointed at ${t}, so they render on top of one another and only the topmost is visible. Each embed needs its own container. This is usually older embed code that looks the container up by name — re-copy the block from the editor (Embed → Copy embed code) and paste it again. The current code finds the container next to its own <script> tag, so it is safe to paste any number of times.`);
3844
+ };
3845
+ function Wn(e, t) {
3846
+ if (typeof t.maxLiveContexts == "number" && Number.isFinite(t.maxLiveContexts)) {
3847
+ let e = Math.max(1, Math.floor(t.maxLiveContexts));
3848
+ Dn = Dn === null ? e : Math.min(Dn, e), On = Dn;
3849
+ }
3850
+ let n = Mn(), r = t.lazy && n, i = {
3851
+ ...e,
3852
+ evictable: r,
3853
+ visible: !r,
3854
+ lastUsed: 0,
3855
+ rootMargin: t.rootMargin
3856
+ };
3857
+ if (Cn.add(i), Vn(), n) {
3858
+ let t = wn.get(e.container);
3859
+ t ? t.size > 0 && Un(e.container) : (t = /* @__PURE__ */ new Set(), wn.set(e.container, t)), t.add(i), Hn(i.rootMargin).observe(e.container);
3860
+ }
3861
+ return r || (Rn(i), Nn() && i.resume()), {
3862
+ claim: () => {
3863
+ Rn(i);
3864
+ },
3865
+ release: () => {
3866
+ if (Cn.delete(i), !n) return;
3867
+ let t = wn.get(e.container);
3868
+ t?.delete(i), (!t || t.size === 0) && (Hn(i.rootMargin).unobserve(e.container), wn.delete(e.container));
3869
+ }
3870
+ };
3871
+ }
3872
+ //#endregion
3873
+ //#region src/embed/resolveContainer.ts
3874
+ var Gn = "sinth", Kn = `.${Gn}`, qn = /* @__PURE__ */ new WeakSet(), Jn = (e) => {
3875
+ qn.add(e);
3876
+ }, Yn = (e) => qn.has(e), Xn = (e) => e instanceof HTMLElement && e.matches(Kn) && !qn.has(e), Zn = (e) => {
3877
+ if (!e) return null;
3878
+ for (let t of e.querySelectorAll(Kn)) if (Xn(t)) return t;
3879
+ return null;
3880
+ };
3881
+ function Qn(e) {
3882
+ if (Xn(e ?? null)) return e;
3883
+ if (e) {
3884
+ for (let t = e.previousElementSibling; t; t = t.previousElementSibling) if (Xn(t)) return t;
3885
+ let t = Zn(e.parentElement);
3886
+ if (t) return t;
3887
+ }
3888
+ let t = Zn(typeof document > "u" ? null : document);
3889
+ if (t) return t;
3890
+ throw Error(`Sinth: no free container found for this embed. Every block needs its own element with class "${Gn}" — the copied embed code brings one with it, so this usually means the <div> was deleted, or its class was renamed, or another embed has already taken it.`);
3891
+ }
3892
+ //#endregion
3893
+ //#region src/embed/createSinthEmbed.ts
3894
+ var $n = 1e3, er = async (e) => {
3895
+ e.rebuildGeometry(), e.updateMaterial(), e.updateColors(), e.updateLights(), e.updateCamera(), e.updatePattern();
3896
+ };
3897
+ function tr({ container: e, preset: t, autoStart: n = !0, lazy: r = !0, rootMargin: i = Sn, maxLiveContexts: a }) {
3898
+ let o = null, s = t, c = n, l = !1, u = !1, d = !1, f = null, p = !1, m = null, h = () => {
3899
+ let t = e.getBoundingClientRect();
3900
+ return t.width > 0 && t.height > 0;
3901
+ };
3902
+ Jn(e);
3903
+ let g = () => {
3904
+ let t = new bn(e, {
3905
+ config: s,
3906
+ autoStart: c && !u
3907
+ });
3908
+ o = t, s && er(t).catch((e) => {
3909
+ console.error("Unable to initialise the Sinth embed.", e);
3910
+ });
3911
+ }, _ = () => {
3912
+ p || m !== null || typeof window > "u" || (m = window.setTimeout(() => {
3913
+ if (m = null, l || p || h() || !(e.offsetParent !== null || window.getComputedStyle(e).position === "fixed")) return;
3914
+ p = !0;
3915
+ let t = e.getBoundingClientRect().height === 0 ? "height" : "width";
3916
+ console.warn(`Sinth: this container has no ${t}, so there is nothing to render into and the embed is waiting. Sinth fills the box it is given — if the container is sized \`${t}: 100%\`, give its parent a ${t} (or set a ${t} on the container itself). It will start on its own the moment the container has one.`, e);
3917
+ }, $n));
3918
+ }, v = () => {
3919
+ if (d = !0, _(), !f) {
3920
+ if (typeof ResizeObserver > "u") {
3921
+ d = !1, g();
3922
+ return;
3923
+ }
3924
+ f = new ResizeObserver(() => {
3925
+ if (!(l || !d)) {
3926
+ if (!h()) {
3927
+ _();
3928
+ return;
3929
+ }
3930
+ d = !1, g();
3931
+ }
3932
+ }), f.observe(e);
3933
+ }
3934
+ }, y = () => {
3935
+ if (!(o || l)) {
3936
+ if (!h()) {
3937
+ v();
3938
+ return;
3939
+ }
3940
+ g();
3941
+ }
3942
+ }, b = () => {
3943
+ d = !1, o &&= (o.dispose(), null);
3944
+ }, x = Wn({
3945
+ container: e,
3946
+ mount: y,
3947
+ unmount: b,
3948
+ resume: () => {
3949
+ u = !1, c && o?.start();
3950
+ },
3951
+ suspend: () => {
3952
+ u = !0, o?.stop();
3953
+ },
3954
+ isMounted: () => o !== null
3955
+ }, {
3956
+ lazy: r,
3957
+ rootMargin: i,
3958
+ maxLiveContexts: a
3959
+ });
3960
+ return {
3961
+ get engine() {
3962
+ return o;
3963
+ },
3964
+ updatePreset: (e) => {
3965
+ s = e, o && (o.setConfig(e), er(o).catch((e) => {
3966
+ console.error("Unable to update the Sinth embed preset.", e);
3967
+ }));
3968
+ },
3969
+ start: () => {
3970
+ c = !0, x.claim(), o?.start();
3971
+ },
3972
+ stop: () => {
3973
+ c = !1, o?.stop();
3974
+ },
3975
+ destroy: () => {
3976
+ l = !0, m !== null && (clearTimeout(m), m = null), f?.disconnect(), f = null, x.release(), b();
3977
+ }
3978
+ };
3979
+ }
3980
+ //#endregion
3981
+ //#region src/embed/autoMount.ts
3982
+ var nr = `.${Gn}, [data-sinth-preset]`, rr = ":scope > script[type=\"application/json\"]", ir = /* @__PURE__ */ new WeakSet(), ar = !1, or = (e, t) => {
3983
+ try {
3984
+ return JSON.parse(e);
3985
+ } catch (e) {
3986
+ return console.error("Sinth: this embed’s preset is not valid JSON, so it was skipped.", t, e), null;
3987
+ }
3988
+ }, sr = (e) => {
3989
+ if (e === null || e.trim() === "") return;
3990
+ let t = Number(e);
3991
+ return Number.isFinite(t) ? t : void 0;
3992
+ }, cr = (e) => {
3993
+ let t = {};
3994
+ e.dataset.sinthLazy === "false" && (t.lazy = !1), e.dataset.sinthAutostart === "false" && (t.autoStart = !1), e.dataset.sinthRootMargin && (t.rootMargin = e.dataset.sinthRootMargin);
3995
+ let n = sr(e.dataset.sinthMaxContexts ?? null);
3996
+ return n !== void 0 && (t.maxLiveContexts = n), t;
3997
+ }, lr = (e, t) => {
3998
+ if (Yn(e)) return null;
3999
+ try {
4000
+ return tr({
4001
+ container: e,
4002
+ preset: t,
4003
+ ...cr(e)
4004
+ });
4005
+ } catch (t) {
4006
+ return console.error("Sinth: this embed could not be created.", e, t), null;
4007
+ }
4008
+ }, ur = (e) => {
4009
+ if (Yn(e) || ir.has(e)) return null;
4010
+ let t = e.querySelector(rr);
4011
+ if (t) {
4012
+ let n = or(t.textContent ?? "", e);
4013
+ return n ? lr(e, n) : null;
4014
+ }
4015
+ let n = e.dataset.sinthPreset?.trim();
4016
+ if (!n) return null;
4017
+ if (n.startsWith("{")) {
4018
+ let t = or(n, e);
4019
+ return t ? lr(e, t) : null;
4020
+ }
4021
+ return ir.add(e), fetch(n, { credentials: "omit" }).then((e) => {
4022
+ if (!e.ok) throw Error(`${e.status} ${e.statusText}`);
4023
+ return e.json();
4024
+ }).then((t) => {
4025
+ ir.delete(e), lr(e, t);
4026
+ }).catch((t) => {
4027
+ ir.delete(e), console.error(`Sinth: could not load the preset at "${n}".`, e, t);
4028
+ }), null;
4029
+ };
4030
+ function dr(e = document) {
4031
+ let t = [];
4032
+ for (let n of e.querySelectorAll(nr)) {
4033
+ let e = ur(n);
4034
+ e && t.push(e);
4035
+ }
4036
+ return t;
4037
+ }
4038
+ var fr = (e) => e instanceof Element ? e.matches(nr) || e.querySelector(nr) !== null : !1;
4039
+ function pr() {
4040
+ if (ar || typeof document > "u" || window.SINTH_AUTO_MOUNT === !1) return;
4041
+ ar = !0;
4042
+ let e = () => {
4043
+ if (dr(document), typeof MutationObserver > "u") return;
4044
+ let e = !1;
4045
+ new MutationObserver((t) => {
4046
+ if (!e) {
4047
+ for (let n of t) for (let t of n.addedNodes) if (fr(t)) {
4048
+ e = !0, requestAnimationFrame(() => {
4049
+ e = !1, dr(document);
4050
+ });
4051
+ return;
4052
+ }
4053
+ }
4054
+ }).observe(document.documentElement, {
4055
+ childList: !0,
4056
+ subtree: !0
4057
+ });
4058
+ };
4059
+ if (document.readyState === "loading") {
4060
+ document.addEventListener("DOMContentLoaded", e, { once: !0 });
4061
+ return;
4062
+ }
4063
+ e();
4064
+ }
4065
+ //#endregion
4066
+ //#region src/version.ts
4067
+ var mr = "1.0.0", hr = "v48", gr = `${mr} · v48`;
4068
+ //#endregion
4069
+ export { Gn as SINTH_CONTAINER_CLASS, hr as SNAPSHOT, mr as VERSION, gr as VERSION_LABEL, tr as createSinthEmbed, n as fontBaseUrl, dr as mountAll, yn as normalizeSinthConfig, Qn as resolveContainer, l as setFontBaseUrl, pr as startAutoMount };