@objectifthunes/three-book 0.4.0 → 0.4.1

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.
Files changed (46) hide show
  1. package/dist/AutoTurn.d.ts +2 -10
  2. package/dist/AutoTurn.d.ts.map +1 -1
  3. package/dist/Book.d.ts +34 -14
  4. package/dist/Book.d.ts.map +1 -1
  5. package/dist/BookBinding.d.ts +7 -2
  6. package/dist/BookBinding.d.ts.map +1 -1
  7. package/dist/BookContent.d.ts +4 -0
  8. package/dist/BookContent.d.ts.map +1 -1
  9. package/dist/Cylinder.d.ts +25 -1
  10. package/dist/Cylinder.d.ts.map +1 -1
  11. package/dist/PageContent.d.ts +2 -7
  12. package/dist/PageContent.d.ts.map +1 -1
  13. package/dist/Paper.d.ts +24 -51
  14. package/dist/Paper.d.ts.map +1 -1
  15. package/dist/PaperMaterialData.d.ts +6 -1
  16. package/dist/PaperMaterialData.d.ts.map +1 -1
  17. package/dist/PaperMeshData.d.ts +0 -6
  18. package/dist/PaperMeshData.d.ts.map +1 -1
  19. package/dist/PaperMeshUtility.d.ts +0 -16
  20. package/dist/PaperMeshUtility.d.ts.map +1 -1
  21. package/dist/PaperNode.d.ts +0 -1
  22. package/dist/PaperNode.d.ts.map +1 -1
  23. package/dist/Renderer.d.ts +6 -9
  24. package/dist/Renderer.d.ts.map +1 -1
  25. package/dist/SpreadContent.d.ts.map +1 -1
  26. package/dist/StapleBinding.d.ts +12 -57
  27. package/dist/StapleBinding.d.ts.map +1 -1
  28. package/dist/TextOverlayContent.d.ts.map +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +958 -991
  32. package/dist/mathUtils.d.ts +18 -0
  33. package/dist/mathUtils.d.ts.map +1 -0
  34. package/dist/textContentUtils.d.ts +26 -0
  35. package/dist/textContentUtils.d.ts.map +1 -0
  36. package/dist/types.d.ts +57 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/utils/LoopUtility.d.ts +0 -5
  39. package/dist/utils/LoopUtility.d.ts.map +1 -1
  40. package/dist/utils/TextureUtility.d.ts +0 -1
  41. package/dist/utils/TextureUtility.d.ts.map +1 -1
  42. package/dist/utils/VectorUtility.d.ts +0 -12
  43. package/dist/utils/VectorUtility.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/dist/utils/index.d.ts +0 -8
  46. package/dist/utils/index.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import * as c from "three";
1
+ import * as o from "three";
2
2
  class ut {
3
3
  constructor() {
4
- this.m_PositionX = 0, this.m_PositionZ = 0, this.m_DirectionX = 0, this.m_DirectionZ = 0, this.m_EulerY = 0, this.m_Radius = 0;
4
+ this.m_PositionX = 0, this.m_PositionZ = 0, this.m_DirectionX = 0, this.m_DirectionZ = 0, this.m_EulerY = 0, this.m_Radius = 0, this._positionOut = new o.Vector3(), this._scratchRP1 = new o.Vector3(), this._scratchRP2 = new o.Vector3(), this._scratchRollClosest = new o.Vector3(), this._scratchRollEuler = new o.Vector3(), this._scratchOffsetRoll = new o.Vector3();
5
5
  }
6
6
  // ── Properties ────────────────────────────────────────────────────────
7
+ /** Returns internal vector — do NOT mutate. Copy if you need to store it. */
7
8
  get position() {
8
- return new c.Vector3(this.m_PositionX, 0, this.m_PositionZ);
9
+ return this._positionOut.set(this.m_PositionX, 0, this.m_PositionZ);
9
10
  }
10
11
  set position(t) {
11
12
  this.m_PositionX = t.x, this.m_PositionZ = t.z;
@@ -18,7 +19,7 @@ class ut {
18
19
  }
19
20
  // ── Public API ────────────────────────────────────────────────────────
20
21
  rollPoint(t) {
21
- return this.roll(t.clone()).sub(this.getOffset(t.clone()));
22
+ return this._scratchRP1.copy(t), this.roll(this._scratchRP1), this._scratchRP2.copy(t), this.getOffset(this._scratchRP2), t.copy(this._scratchRP1).sub(this._scratchRP2), t;
22
23
  }
23
24
  // ── Private helpers ───────────────────────────────────────────────────
24
25
  /**
@@ -28,31 +29,46 @@ class ut {
28
29
  * 1. Rotate (x, 0, 0) by Z degrees around Z-axis.
29
30
  * 2. Rotate by X degrees around X-axis (X = 0 here, so skip).
30
31
  * 3. Rotate by Y degrees around Y-axis.
32
+ *
33
+ * Writes result into `out` and returns it.
31
34
  */
32
- eulerRotateVector(t, e, s) {
33
- const i = s * Math.PI / 180, n = e * Math.PI / 180, o = Math.cos(i), a = Math.sin(i), h = t * o, m = t * a, l = 0, d = Math.cos(n), g = Math.sin(n), _ = h * d + l * g, u = m, f = -h * g + l * d;
34
- return new c.Vector3(_, u, f);
35
+ eulerRotateVector(t, e, s, i) {
36
+ const n = s * Math.PI / 180, h = e * Math.PI / 180, a = Math.cos(n), c = Math.sin(n), u = t * a, l = t * c, _ = 0, d = Math.cos(h), f = Math.sin(h), m = u * d + _ * f, g = l, p = -u * f + _ * d;
37
+ return i.set(m, g, p);
35
38
  }
39
+ /**
40
+ * Rolls `point` in place around the cylinder. Mutates and returns `point`.
41
+ * Uses _scratchRollClosest for closest-point calculation and
42
+ * _scratchRollEuler for euler rotation result.
43
+ */
36
44
  roll(t) {
37
45
  if (this.getSide(t) >= 0) return t;
38
- const e = this.getClosestPoint(t.clone());
46
+ this._scratchRollClosest.copy(t), this.getClosestPointInto(this._scratchRollClosest);
47
+ const e = this._scratchRollClosest;
39
48
  let s = t.distanceTo(e);
40
- if (s > Math.PI * this.m_Radius) {
41
- s = s - Math.PI * this.m_Radius;
42
- const i = this.eulerRotateVector(-s, this.m_EulerY, 0);
43
- t.copy(i.add(e)), t.y += this.m_Radius * 2;
44
- } else {
45
- const i = 180 / Math.PI * (s / this.m_Radius) - 90, n = this.eulerRotateVector(this.m_Radius, this.m_EulerY, i);
46
- t.copy(n.add(e)), t.y += this.m_Radius;
49
+ if (s > Math.PI * this.m_Radius)
50
+ s = s - Math.PI * this.m_Radius, this.eulerRotateVector(-s, this.m_EulerY, 0, this._scratchRollEuler), t.copy(this._scratchRollEuler.add(e)), t.y += this.m_Radius * 2;
51
+ else {
52
+ const i = 180 / Math.PI * (s / this.m_Radius) - 90;
53
+ this.eulerRotateVector(this.m_Radius, this.m_EulerY, i, this._scratchRollEuler), t.copy(this._scratchRollEuler.add(e)), t.y += this.m_Radius;
47
54
  }
48
55
  return t;
49
56
  }
57
+ /**
58
+ * Computes offset for `point`. Mutates and returns `point`.
59
+ * Offset = roll(point with x=0) with z adjusted.
60
+ * Uses _scratchOffsetRoll to hold a copy for rolling (avoids aliasing
61
+ * with `point` itself when roll() internally reads and writes).
62
+ */
50
63
  getOffset(t) {
51
- t.x = 0;
52
- const e = this.roll(t.clone());
53
- return e.z -= t.z, e;
64
+ const e = t.z;
65
+ return this._scratchOffsetRoll.set(0, t.y, t.z), this.roll(this._scratchOffsetRoll), t.copy(this._scratchOffsetRoll), t.z -= e, t;
54
66
  }
55
- getClosestPoint(t) {
67
+ /**
68
+ * Projects `point` onto the cylinder axis, writing the result into `point`.
69
+ * Returns the mutated `point`.
70
+ */
71
+ getClosestPointInto(t) {
56
72
  const e = t.x - this.m_PositionX, s = t.z - this.m_PositionZ, i = e * this.m_DirectionX + s * this.m_DirectionZ;
57
73
  return t.x = this.m_PositionX + this.m_DirectionX * i, t.z = this.m_PositionZ + this.m_DirectionZ * i, t;
58
74
  }
@@ -66,33 +82,33 @@ class ut {
66
82
  return t.m_PositionX = this.m_PositionX, t.m_PositionZ = this.m_PositionZ, t.m_DirectionX = this.m_DirectionX, t.m_DirectionZ = this.m_DirectionZ, t.m_EulerY = this.m_EulerY, t.m_Radius = this.m_Radius, t;
67
83
  }
68
84
  }
69
- function gt(r, t, e, s, i = 1 / 0, n = 1 / 60) {
85
+ function ft(r, t, e, s, i = 1 / 0, n = 1 / 60) {
70
86
  s = Math.max(s, 1e-4);
71
- const o = 2 / s, a = o * n, h = 1 / (1 + a + 0.48 * a * a + 0.235 * a * a * a);
72
- let m = r - t;
73
- const l = t, d = i * s;
74
- m = c.MathUtils.clamp(m, -d, d), t = r - m;
75
- const g = (e + o * m) * n;
76
- e = (e - o * g) * h;
77
- let _ = t + (m + g) * h;
78
- return l - r > 0 == _ > l && (_ = l, e = (_ - l) / n), { value: _, velocity: e };
79
- }
80
- function ie(r, t, e, s, i = 1 / 0, n = 1 / 60) {
81
- const o = gt(
87
+ const h = 2 / s, a = h * n, c = 1 / (1 + a + 0.48 * a * a + 0.235 * a * a * a);
88
+ let u = r - t;
89
+ const l = t, _ = i * s;
90
+ u = o.MathUtils.clamp(u, -_, _), t = r - u;
91
+ const d = (e + h * u) * n;
92
+ e = (e - h * d) * c;
93
+ let f = t + (u + d) * c;
94
+ return l - r > 0 == f > l && (f = l, e = (f - l) / n), { value: f, velocity: e };
95
+ }
96
+ function Yt(r, t, e, s, i = 1 / 0, n = 1 / 60) {
97
+ const h = ft(
82
98
  r.x,
83
99
  t.x,
84
100
  e.x,
85
101
  s.x,
86
102
  i,
87
103
  n
88
- ), a = gt(
104
+ ), a = ft(
89
105
  r.y,
90
106
  t.y,
91
107
  e.y,
92
108
  s.y,
93
109
  i,
94
110
  n
95
- ), h = gt(
111
+ ), c = ft(
96
112
  r.z,
97
113
  t.z,
98
114
  e.z,
@@ -100,20 +116,20 @@ function ie(r, t, e, s, i = 1 / 0, n = 1 / 60) {
100
116
  i,
101
117
  n
102
118
  );
103
- return e.set(o.velocity, a.velocity, h.velocity), new c.Vector3(o.value, a.value, h.value);
119
+ return e.set(h.velocity, a.velocity, c.velocity), new o.Vector3(h.value, a.value, c.value);
104
120
  }
105
- function ne(r) {
106
- return new c.Vector3(r.x, 0, r.y);
121
+ function Kt(r) {
122
+ return new o.Vector3(r.x, 0, r.y);
107
123
  }
108
- function re(r) {
109
- return new c.Vector3(r.x, r.z, 0);
124
+ function Jt(r) {
125
+ return new o.Vector3(r.x, r.z, 0);
110
126
  }
111
- function vt(r, t, e) {
127
+ function Tt(r, t, e) {
112
128
  const s = t * t - 4 * r * e;
113
129
  if (s < 0)
114
130
  return { rootCount: 0, root0: 0, root1: 0 };
115
131
  if (s === 0)
116
- return { rootCount: 1, root0: -t / 2 * r, root1: 0 };
132
+ return { rootCount: 1, root0: -t / (2 * r), root1: 0 };
117
133
  {
118
134
  const i = Math.sqrt(s);
119
135
  return {
@@ -123,84 +139,86 @@ function vt(r, t, e) {
123
139
  };
124
140
  }
125
141
  }
126
- function kt(r, t, e) {
127
- return oe(r, t, e) ? r.clone() : ae(
128
- new c.Vector2(r.x, t.y),
142
+ function vt(r, t, e) {
143
+ return te(r, t, e) ? r.clone() : ee(
144
+ new o.Vector2(r.x, t.y),
129
145
  r,
130
146
  t,
131
147
  e
132
148
  );
133
149
  }
134
- function oe(r, t, e) {
150
+ function te(r, t, e) {
135
151
  const s = r.x - t.x;
136
152
  let i = r.y - t.y;
137
153
  return i *= e.x / e.y, Math.sqrt(s * s + i * i) < e.x;
138
154
  }
139
- function ae(r, t, e, s) {
140
- const i = e.x, n = e.y, o = r.x, a = r.y, h = t.x, m = t.y, l = s.x, d = s.y, g = 1 / (l * l), _ = 1 / (d * d);
141
- if (Math.abs(o - h) < 1e-5) {
142
- if (o >= i - l && o <= i + l) {
143
- const u = vt(
144
- _,
145
- -2 * _ * n,
146
- g * (o * o - 2 * i * o + i * i) + _ * n * n - 1
155
+ function ee(r, t, e, s) {
156
+ const i = e.x, n = e.y, h = r.x, a = r.y, c = t.x, u = t.y, l = s.x, _ = s.y, d = 1 / (l * l), f = 1 / (_ * _);
157
+ if (Math.abs(h - c) < 1e-5) {
158
+ if (h >= i - l && h <= i + l) {
159
+ const m = Tt(
160
+ f,
161
+ -2 * f * n,
162
+ d * (h * h - 2 * i * h + i * i) + f * n * n - 1
147
163
  );
148
- if (u.rootCount === 1)
149
- return new c.Vector2(o, u.root0);
150
- if (u.rootCount === 2) {
151
- let f = u.root0, p = u.root1;
152
- return a < m && ([f, p] = [p, f]), new c.Vector2(o, p);
164
+ if (m.rootCount === 1)
165
+ return new o.Vector2(h, m.root0);
166
+ if (m.rootCount === 2) {
167
+ let g = m.root0, p = m.root1;
168
+ return a < u && ([g, p] = [p, g]), new o.Vector2(h, p);
153
169
  }
154
170
  }
155
171
  } else {
156
- const u = (m - a) / (h - o), f = a - u * o, p = f - n, P = vt(
157
- g + _ * u * u,
158
- 2 * p * u * _ - 2 * i * g,
159
- i * i * g + p * p * _ - 1
172
+ const m = (u - a) / (c - h), g = a - m * h, p = g - n, M = Tt(
173
+ d + f * m * m,
174
+ 2 * p * m * f - 2 * i * d,
175
+ i * i * d + p * p * f - 1
160
176
  );
161
- if (P.rootCount === 1)
162
- return new c.Vector2(P.root0, u * P.root0 + f);
163
- if (P.rootCount === 2) {
164
- let B = P.root0, M = P.root1;
165
- return o < h && ([B, M] = [M, B]), new c.Vector2(M, u * M + f);
177
+ if (M.rootCount === 1)
178
+ return new o.Vector2(M.root0, m * M.root0 + g);
179
+ if (M.rootCount === 2) {
180
+ let T = M.root0, C = M.root1;
181
+ return h < c && ([T, C] = [C, T]), new o.Vector2(C, m * C + g);
166
182
  }
167
183
  }
168
184
  return r.clone();
169
185
  }
170
- function bt(r, t) {
186
+ function kt(r, t) {
171
187
  const e = r.origin.clone().applyMatrix4(t), s = r.origin.clone().add(r.direction).applyMatrix4(t);
172
- return new c.Ray(e, s.sub(e));
173
- }
174
- function he(r) {
175
- return new c.Vector4(-r.x, r.y, r.z + r.x, r.w);
188
+ return new o.Ray(e, s.sub(e).normalize());
176
189
  }
177
- function le(r) {
178
- return new c.Vector4(r.x, -r.y, r.z, r.w + r.y);
190
+ function se(r) {
191
+ return new o.Vector4(-r.x, r.y, r.z + r.x, r.w);
179
192
  }
180
- var X = /* @__PURE__ */ ((r) => (r[r.LeftToRight = 0] = "LeftToRight", r[r.RightToLeft = 1] = "RightToLeft", r[r.UpToDown = 2] = "UpToDown", r[r.DownToUp = 3] = "DownToUp", r))(X || {});
181
- const Bt = Math.PI / 180, Rt = 180 / Math.PI, ce = 1192093e-13;
182
- function dt(r) {
183
- return r < 0 ? 0 : r > 1 ? 1 : r;
193
+ function ie(r) {
194
+ return new o.Vector4(r.x, -r.y, r.z, r.w + r.y);
184
195
  }
185
- function Dt(r, t, e) {
196
+ var j = /* @__PURE__ */ ((r) => (r[r.LeftToRight = 0] = "LeftToRight", r[r.RightToLeft = 1] = "RightToLeft", r[r.UpToDown = 2] = "UpToDown", r[r.DownToUp = 3] = "DownToUp", r))(j || {});
197
+ const J = Math.PI / 180, et = 180 / Math.PI;
198
+ function H(r, t, e) {
186
199
  return r < t ? t : r > e ? e : r;
187
200
  }
188
- function mt(r, t, e) {
189
- return r !== t ? dt((e - r) / (t - r)) : 0;
201
+ function ct(r) {
202
+ return r < 0 ? 0 : r > 1 ? 1 : r;
203
+ }
204
+ function F(r, t, e) {
205
+ return e = ct(e), r + (t - r) * e;
190
206
  }
191
- function It(r, t, e) {
207
+ function Bt(r, t, e) {
192
208
  return r + (t - r) * e;
193
209
  }
194
- function zt(r, t, e) {
195
- return r + (t - r) * e;
210
+ function Q(r, t, e) {
211
+ return r !== t ? ct((e - r) / (t - r)) : 0;
196
212
  }
197
- function Vt(r, t, e) {
198
- return e = dt((e - r) / (t - r)), e * e * (3 - 2 * e);
213
+ var mt = /* @__PURE__ */ ((r) => (r[r.Surface = 0] = "Surface", r[r.Edge = 1] = "Edge", r))(mt || {});
214
+ const ne = 1192093e-13;
215
+ function Rt(r, t, e) {
216
+ return e = ct((e - r) / (t - r)), e * e * (3 - 2 * e);
199
217
  }
200
- class me {
218
+ class re {
201
219
  // ---- Constructor ----
202
220
  constructor(t, e, s, i) {
203
- this.m_UseBackContentForSides = !1, this.m_Prev = null, this.m_Next = null, this.m_NoHole = !1, this.m_Size = new c.Vector2(), this.m_Thickness = 0, this.m_Stiffness = 0, this.m_Margin = 0, this.m_MeshDataType = 1, this.m_Cylinder = new ut(), this.m_IsRolling = !1, this.m_IsAutoTurning = !1, this.m_WorldPlane = new c.Plane(), this.m_StartHandle = new c.Vector3(), this.m_CurrentHandle = new c.Vector3(), this.m_EndHandle = new c.Vector3(), this.m_PrevHandle = new c.Vector3(), this.m_HandleOffset = new c.Vector3(), this.m_HandleVelocity = new c.Vector3(), this.m_HandleVelocities = [], this.m_SubMeshCount = -1, this.m_MinTurningRadius = 0, this.m_TurningRadius = 0, this.m_FallDuration = 0, this.m_FallTime = 0.2, this.m_XTime = 0, this.m_ZTime = 0, this.m_IsTurning = !1, this.m_IsFalling = !1, this.m_IsFallingLeft = !1, this.m_isMeshChanged = !1, this.sizeXOffset = 0, this.m_IsCover = t, this.m_Book = s, this.m_Index = e, this.m_Renderer = i, this.m_Transform = i.transform;
221
+ this.m_UseBackContentForSides = !1, this.m_Prev = null, this.m_Next = null, this.m_NoHole = !1, this.m_Size = new o.Vector2(), this.m_Thickness = 0, this.m_Stiffness = 0, this.m_Margin = 0, this.m_MeshDataType = 1, this.m_Cylinder = new ut(), this.m_IsRolling = !1, this.m_IsAutoTurning = !1, this.m_WorldPlane = new o.Plane(), this.m_StartHandle = new o.Vector3(), this.m_CurrentHandle = new o.Vector3(), this.m_EndHandle = new o.Vector3(), this.m_PrevHandle = new o.Vector3(), this.m_HandleOffset = new o.Vector3(), this.m_HandleVelocity = new o.Vector3(), this.m_HandleVelocities = [], this.m_SubMeshCount = -1, this.m_MinTurningRadius = 0, this.m_TurningRadius = 0, this.m_FallDuration = 0, this.m_FallTime = 0.2, this.m_XTime = 0, this.m_ZTime = 0, this.m_IsTurning = !1, this.m_IsFalling = !1, this.m_IsFallingLeft = !1, this.m_isMeshChanged = !1, this.sizeXOffset = 0, this._ucStartHandle = new o.Vector3(), this._ucCurrentHandle = new o.Vector3(), this._ucHandleDir = new o.Vector3(), this._ucA = new o.Vector3(), this._ucB = new o.Vector3(), this._ucMid = new o.Vector3(), this._ucRollResult = new o.Vector3(), this._ucCylDir = new o.Vector3(), this._utV1 = new o.Vector3(), this._utV2 = new o.Vector3(), this._utV3 = new o.Vector3(), this._utV4 = new o.Vector3(), this._chP = new o.Vector3(), this._chA = new o.Vector3(), this._chC = new o.Vector3(), this._chEllipseCenter1 = new o.Vector2(), this._chEllipseCenter2 = new o.Vector2(), this._chEllipseSize1 = new o.Vector2(), this._chEllipseSize2 = new o.Vector2(), this.m_IsCover = t, this.m_Book = s, this.m_Index = e, this.m_Renderer = i, this.m_Transform = i.transform;
204
222
  }
205
223
  // ---- Properties (mirrors C#) ----
206
224
  get isMeshChanged() {
@@ -240,8 +258,8 @@ class me {
240
258
  return this.m_IsFalling || this.m_IsTurning ? this.m_Transform.scale.x === -1 ? 1 - this.m_ZTime : this.m_ZTime : this.m_Transform.scale.x === -1 ? 1 : 0;
241
259
  }
242
260
  get direction() {
243
- const e = this.zTime * 180 * Bt, s = Math.cos(e), i = Math.sin(e);
244
- return new c.Vector3(-s, -i, 0);
261
+ const e = this.zTime * 180 * J, s = Math.cos(e), i = Math.sin(e);
262
+ return new o.Vector3(-s, -i, 0);
245
263
  }
246
264
  get isTurning() {
247
265
  return this.m_IsTurning;
@@ -281,9 +299,6 @@ class me {
281
299
  get isIdle() {
282
300
  return !this.m_IsFalling && !this.m_IsTurning;
283
301
  }
284
- get isInMiddelOfStack() {
285
- return this.m_Prev === null || this.m_Next === null ? !1 : this.isIdle && this.m_Prev.isIdle && this.m_Next.isIdle && this.m_Prev.isOnRightStack === this.m_Next.isOnRightStack;
286
- }
287
302
  // ---- Methods (faithful port, same order as C#) ----
288
303
  setTime(t) {
289
304
  this.m_XTime = t, this.m_ZTime = t;
@@ -313,52 +328,52 @@ class me {
313
328
  this.m_MinTurningRadius = t;
314
329
  }
315
330
  updateTurningRadius(t = 1) {
316
- let e = Math.max(this.m_Stiffness, 1 - dt(t));
317
- e <= 0.5 ? this.m_TurningRadius = mt(0, 0.5, e) * this.m_Size.x / Math.PI : this.m_TurningRadius = this.m_Size.x / (Math.max(180 * (1 - mt(0.5, 1, e)), 5) * Bt), this.m_TurningRadius = Math.max(
331
+ let e = Math.max(this.m_Stiffness, 1 - ct(t));
332
+ e <= 0.5 ? this.m_TurningRadius = Q(0, 0.5, e) * this.m_Size.x / Math.PI : this.m_TurningRadius = this.m_Size.x / (Math.max(180 * (1 - Q(0.5, 1, e)), 5) * J), this.m_TurningRadius = Math.max(
318
333
  this.m_TurningRadius,
319
334
  this.m_MinTurningRadius
320
335
  );
321
336
  }
322
337
  startTurning(t) {
323
- var n, o;
338
+ var n, h;
324
339
  const e = t.clone();
325
- t = bt(
340
+ t = kt(
326
341
  t,
327
342
  this.m_Transform.matrixWorld.clone().invert()
328
343
  ), this.m_WorldPlane.setFromNormalAndCoplanarPoint(
329
- new c.Vector3(0, 1, 0).applyQuaternion(this.m_Transform.quaternion),
344
+ new o.Vector3(0, 1, 0).applyQuaternion(this.m_Transform.quaternion),
330
345
  this.m_Transform.position
331
346
  );
332
- const s = new c.Plane(new c.Vector3(0, 1, 0), 0), i = new c.Vector3();
347
+ const s = new o.Plane(new o.Vector3(0, 1, 0), 0), i = new o.Vector3();
333
348
  if (t.intersectPlane(s, i) !== null) {
334
349
  const a = i;
335
350
  if (a.x > 0 && a.x < this.m_Size.x && a.z > 0 && a.z < this.m_Size.y) {
336
351
  if (this.m_IsRolling = !0, this.m_IsTurning = !0, this.m_IsFalling = !1, this.m_HandleOffset.set(0, 0, 0), this.m_StartHandle.copy(a), this.m_StartHandle.x = this.m_Size.x, this.m_CurrentHandle.copy(this.m_StartHandle), a.x < this.m_Size.x * 0.9) {
337
352
  this.m_HandleOffset.set(a.x - this.m_Size.x, 0, 0);
338
- const h = this.m_Transform.scale;
339
- h.x *= -1;
353
+ const c = this.m_Transform.scale;
354
+ c.x *= -1;
340
355
  }
341
356
  return this.m_HandleVelocity.set(0, 0, 0), this.m_PrevHandle.copy(this.m_CurrentHandle), this.m_HandleVelocities.length = 0, this.switchMeshData(
342
357
  0
343
358
  /* Highpoly */
344
- ), (n = this.m_Prev) == null || n.trySwitchMeshData(1), (o = this.m_Next) == null || o.trySwitchMeshData(1), this.updateTurning(e), this.clampHandle(), this.updateCylinder(), !0;
359
+ ), (n = this.m_Prev) == null || n.trySwitchMeshData(1), (h = this.m_Next) == null || h.trySwitchMeshData(1), this.updateTurning(e), this.clampHandle(), this.updateCylinder(), !0;
345
360
  }
346
361
  }
347
362
  return !1;
348
363
  }
349
364
  stopTurning() {
350
365
  this.clampHandle(), this.m_IsTurning = !1, this.m_IsFalling = !0;
351
- const t = new c.Vector3(0, 0, 0);
366
+ const t = new o.Vector3(0, 0, 0);
352
367
  for (const e of this.m_HandleVelocities)
353
368
  t.add(e);
354
- t.divideScalar(this.m_HandleVelocities.length), t.length() > 0.1 ? this.m_IsFallingLeft = t.x < 0 : this.m_IsFallingLeft = this.m_XTime > 0.5 && this.m_ZTime > 0.1, this.m_IsFallingLeft ? this.m_FallTime = 1 - this.m_XTime : this.m_FallTime = this.m_XTime, this.m_FallTime = It(0.1, 0.2, this.m_FallTime), this.m_EndHandle.copy(this.m_StartHandle), this.m_IsFallingLeft && (this.m_EndHandle.x = -this.m_Size.x);
369
+ t.divideScalar(this.m_HandleVelocities.length), t.length() > 0.1 ? this.m_IsFallingLeft = t.x < 0 : this.m_IsFallingLeft = this.m_XTime > 0.5 && this.m_ZTime > 0.1, this.m_IsFallingLeft ? this.m_FallTime = 1 - this.m_XTime : this.m_FallTime = this.m_XTime, this.m_FallTime = F(0.1, 0.2, this.m_FallTime), this.m_EndHandle.copy(this.m_StartHandle), this.m_IsFallingLeft && (this.m_EndHandle.x = -this.m_Size.x);
355
370
  }
356
371
  /**
357
372
  * Called each frame while the user is dragging.
358
373
  * `dt` replaces Time.deltaTime.
359
374
  */
360
375
  updateTurning(t, e = 1 / 60) {
361
- const s = new c.Vector3();
376
+ const s = new o.Vector3();
362
377
  if (t.intersectPlane(this.m_WorldPlane, s) !== null) {
363
378
  const i = s;
364
379
  this.m_Book.bound.resetPaperPosition(this), this.m_CurrentHandle.copy(
@@ -375,19 +390,19 @@ class me {
375
390
  var s, i;
376
391
  let e = !1;
377
392
  if (this.m_IsAutoTurning) {
378
- let n = dt(this.m_FallTime / this.m_FallDuration);
379
- n = Vt(0, 1, n), n = Vt(0, 1, n), this.m_CurrentHandle.lerpVectors(
393
+ let n = ct(this.m_FallTime / this.m_FallDuration);
394
+ n = Rt(0, 1, n), n = Rt(0, 1, n), this.m_CurrentHandle.lerpVectors(
380
395
  this.m_StartHandle,
381
396
  this.m_EndHandle,
382
397
  this.m_IsFallingLeft ? n : 1 - n
383
- ), this.m_FallTime += t, e = Math.abs(n - 1) < ce;
398
+ ), this.m_FallTime += t, e = Math.abs(n - 1) < ne;
384
399
  } else {
385
- const n = new c.Vector3(
400
+ const n = new o.Vector3(
386
401
  this.m_FallTime,
387
402
  0,
388
403
  this.m_FallTime * 0.75
389
404
  );
390
- this.m_CurrentHandle = ie(
405
+ this.m_CurrentHandle = Yt(
391
406
  this.m_CurrentHandle,
392
407
  this.m_EndHandle,
393
408
  this.m_HandleVelocity,
@@ -415,12 +430,12 @@ class me {
415
430
  }
416
431
  getTextureCoordinate(t) {
417
432
  const e = this.raycastLocal(t, !0);
418
- return e !== null ? this.hit2UV(e) : new c.Vector2(0, 0);
433
+ return e !== null ? this.hit2UV(e) : new o.Vector2(0, 0);
419
434
  }
420
435
  raycast(t) {
421
436
  const e = {
422
- point: new c.Vector3(),
423
- textureCoordinate: new c.Vector2(),
437
+ point: new o.Vector3(),
438
+ textureCoordinate: new o.Vector2(),
424
439
  pageContent: null,
425
440
  paperIndex: 0,
426
441
  pageIndex: 0
@@ -433,13 +448,13 @@ class me {
433
448
  return { hit: !1, hitInfo: e };
434
449
  }
435
450
  hit2UV(t) {
436
- const e = new c.Vector2(
437
- mt(-this.sizeXOffset, this.m_Size.x, t.x),
451
+ const e = new o.Vector2(
452
+ Q(-this.sizeXOffset, this.m_Size.x, t.x),
438
453
  t.z / this.m_Size.y
439
454
  );
440
455
  this.m_UVMargin.fixUV(e);
441
456
  const s = this.m_Book.direction;
442
- if (s === X.UpToDown || s === X.DownToUp) {
457
+ if (s === j.UpToDown || s === j.DownToUp) {
443
458
  const i = e.x;
444
459
  e.x = e.y, e.y = i, this.isOnRightStack && (e.y = 1 - e.y);
445
460
  } else
@@ -451,11 +466,11 @@ class me {
451
466
  * Returns the local-space hit point, or null if no hit / out of bounds.
452
467
  */
453
468
  raycastLocal(t, e = !1) {
454
- t = bt(
469
+ t = kt(
455
470
  t,
456
471
  this.m_Transform.matrixWorld.clone().invert()
457
472
  );
458
- const s = new c.Plane(new c.Vector3(0, 1, 0), 0), i = new c.Vector3();
473
+ const s = new o.Plane(new o.Vector3(0, 1, 0), 0), i = new o.Vector3();
459
474
  if (t.intersectPlane(s, i) !== null) {
460
475
  const n = i;
461
476
  if (n.x > 0 && n.x < this.m_Size.x && n.z > 0 && n.z < this.m_Size.y || e)
@@ -490,13 +505,13 @@ class me {
490
505
  ), this.m_SubMeshCount = t);
491
506
  const e = this.m_FrontContent.textureST.clone();
492
507
  let s = this.m_BackContent.textureST.clone();
493
- this.m_Book.direction > 1 ? s = le(s) : s = he(s);
508
+ this.m_Book.direction > 1 ? s = ie(s) : s = se(s);
494
509
  const i = this.m_FrontContent.texture, n = this.m_BackContent.texture;
495
510
  if (t === 3) {
496
- let o = 0, a = 1;
497
- this.m_Transform.scale.x === -1 && (o = 1, a = 0), this.m_MaterialData.updatePropertyBlock(i, e), this.m_Renderer.setPropertyBlock(
511
+ let h = 0, a = 1;
512
+ this.m_Transform.scale.x === -1 && (h = 1, a = 0), this.m_MaterialData.updatePropertyBlock(i, e), this.m_Renderer.setPropertyBlock(
498
513
  this.m_MaterialData.propertyBlock,
499
- o
514
+ h
500
515
  ), this.m_UseBackContentForSides || this.m_Renderer.setPropertyBlock(
501
516
  this.m_MaterialData.propertyBlock,
502
517
  2
@@ -524,100 +539,97 @@ class me {
524
539
  this.updateMaterials(), this.m_MeshData.updateMesh(), this.m_isMeshChanged = !0;
525
540
  }
526
541
  getDirection(t) {
527
- let e = new c.Vector3(0, 0, t), s = new c.Vector3(0.1, 0, t);
542
+ let e = new o.Vector3(0, 0, t), s = new o.Vector3(0.1, 0, t);
528
543
  return e = this.rollPoint(e), s = this.rollPoint(s), e = this.m_Transform.localToWorld(e), s = this.m_Transform.localToWorld(s), this.m_Transform.parent && (e = this.m_Transform.parent.worldToLocal(e), s = this.m_Transform.parent.worldToLocal(s)), e.sub(s).normalize();
529
544
  }
530
545
  updateTime() {
531
546
  if (this.isTurning || this.isFalling) {
532
- const t = this.findTime(new c.Vector3(this.m_Size.x, 0, 0)), e = this.findTime(
533
- new c.Vector3(this.m_Size.x, 0, this.m_Size.y)
534
- );
535
- this.m_XTime = It(
547
+ this._utV1.set(this.m_Size.x, 0, 0);
548
+ const t = this.findTime(this._utV1);
549
+ this._utV2.set(this.m_Size.x, 0, this.m_Size.y);
550
+ const e = this.findTime(this._utV2);
551
+ this.m_XTime = F(
536
552
  Math.min(t, e),
537
553
  Math.max(t, e),
538
554
  0.9
539
555
  );
540
- const s = this.m_MeshData.pattern.baseXArray, i = this.m_MeshData.pattern.baseZArray, n = this.rollPoint(new c.Vector3(s[1], 0, 0)), o = this.rollPoint(new c.Vector3(s[2], 0, 0)), a = this.rollPoint(
541
- new c.Vector3(s[1], 0, i[i.length - 1])
542
- ), h = this.rollPoint(
543
- new c.Vector3(s[2], 0, i[i.length - 1])
544
- ), m = o.clone().sub(n).normalize(), l = h.clone().sub(a).normalize(), d = Rt * Math.atan2(m.y, m.x), g = Rt * Math.atan2(l.y, l.x), _ = (d + g) / 2;
545
- this.m_ZTime = _ / 180;
556
+ const s = this.m_MeshData.pattern.baseXArray, i = this.m_MeshData.pattern.baseZArray;
557
+ this._utV1.set(s[1], 0, 0);
558
+ const n = this.rollPoint(this._utV1);
559
+ this._utV2.set(s[2], 0, 0);
560
+ const h = this.rollPoint(this._utV2);
561
+ this._utV3.set(s[1], 0, i[i.length - 1]);
562
+ const a = this.rollPoint(this._utV3);
563
+ this._utV4.set(s[2], 0, i[i.length - 1]);
564
+ const c = this.rollPoint(this._utV4), u = h.x - n.x, l = h.y - n.y, _ = c.x - a.x, d = c.y - a.y, f = Math.sqrt(u * u + l * l) || 1, m = Math.sqrt(_ * _ + d * d) || 1, g = et * Math.atan2(l / f, u / f), p = et * Math.atan2(d / m, _ / m), M = (g + p) / 2;
565
+ this.m_ZTime = M / 180;
546
566
  } else
547
567
  this.m_XTime = 0, this.m_ZTime = 0;
548
568
  }
549
569
  findTime(t) {
550
- return t = this.rollPoint(t), mt(this.m_Size.x, -this.m_Size.x, t.x);
570
+ return t = this.rollPoint(t), Q(this.m_Size.x, -this.m_Size.x, t.x);
551
571
  }
552
572
  clampHandle() {
553
573
  this.m_StartHandle.y = 0, this.m_CurrentHandle.y = 0;
554
- const t = this.m_CurrentHandle.clone(), e = new c.Vector3(0, 0, 0), s = new c.Vector3(0, 0, this.m_Size.y), i = e.distanceTo(this.m_StartHandle), n = s.distanceTo(this.m_StartHandle), o = Math.max(i - this.m_TurningRadius, 0.01), a = Math.max(n - this.m_TurningRadius, 0.01), h = this.m_StartHandle.z, m = new c.Vector2(
574
+ const t = this._chP.copy(this.m_CurrentHandle), e = this._chA.set(0, 0, 0), s = this._chC.set(0, 0, this.m_Size.y), i = e.distanceTo(this.m_StartHandle), n = s.distanceTo(this.m_StartHandle), h = Math.max(i - this.m_TurningRadius, 0.01), a = Math.max(n - this.m_TurningRadius, 0.01), c = this.m_StartHandle.z, u = this._chEllipseCenter1.set(
555
575
  0,
556
- h + (e.z - h) * (o / i)
557
- ), l = new c.Vector2(
576
+ c + (e.z - c) * (h / i)
577
+ ), l = this._chEllipseCenter2.set(
558
578
  0,
559
- h + (s.z - h) * (a / n)
560
- ), d = new c.Vector2(i, o), g = new c.Vector2(n, a);
561
- t.x = Dt(t.x, -this.m_Size.x, this.m_Size.x);
562
- const _ = re(t), u = kt(
563
- new c.Vector2(_.x, _.y),
564
- m,
565
- d
566
- ), f = kt(
567
- new c.Vector2(u.x, u.y),
579
+ c + (s.z - c) * (a / n)
580
+ ), _ = this._chEllipseSize1.set(i, h), d = this._chEllipseSize2.set(n, a);
581
+ t.x = H(t.x, -this.m_Size.x, this.m_Size.x);
582
+ const f = Jt(t), m = vt(
583
+ new o.Vector2(f.x, f.y),
584
+ u,
585
+ _
586
+ ), g = vt(
587
+ new o.Vector2(m.x, m.y),
568
588
  l,
569
- g
570
- ), p = ne(
571
- new c.Vector3(f.x, f.y, 0)
589
+ d
590
+ ), p = Kt(
591
+ new o.Vector3(g.x, g.y, 0)
572
592
  );
573
593
  this.m_CurrentHandle.copy(p);
574
594
  }
575
595
  updateCylinder() {
576
- const t = this.m_StartHandle.clone(), e = this.m_CurrentHandle.clone(), s = t.clone().sub(e).normalize();
596
+ const t = this._ucStartHandle.copy(this.m_StartHandle), e = this._ucCurrentHandle.copy(this.m_CurrentHandle), s = this._ucHandleDir.copy(t).sub(e).normalize();
577
597
  s.length() === 0 && s.set(1, 0, 0);
578
- const i = t.clone().sub(
579
- s.clone().multiplyScalar(
580
- this.m_Size.x * 2 + this.m_TurningRadius * Math.PI
581
- )
582
- ), n = t.clone(), o = new ut();
583
- o.radius = this.m_TurningRadius, o.direction = new c.Vector3(
584
- -s.z,
585
- 0,
586
- s.x
587
- );
588
- for (let a = 0; a < 100; a++) {
589
- o.position = i.clone().add(n).multiplyScalar(0.5), this.m_Cylinder = o, this.m_Book.bound.updatePaperPosition(this);
590
- const h = o.rollPoint(t.clone());
591
- if (Math.abs(e.x - h.x) < 1e-4) break;
592
- h.x > e.x ? n.copy(o.position) : i.copy(o.position);
598
+ const i = this.m_Size.x * 2 + this.m_TurningRadius * Math.PI, n = this._ucA.copy(t).sub(
599
+ this._ucCylDir.copy(s).multiplyScalar(i)
600
+ ), h = this._ucB.copy(t), a = new ut();
601
+ a.radius = this.m_TurningRadius, this._ucCylDir.set(-s.z, 0, s.x), a.direction = this._ucCylDir;
602
+ for (let c = 0; c < 100; c++) {
603
+ this._ucMid.copy(n).add(h).multiplyScalar(0.5), a.position = this._ucMid, this.m_Cylinder = a, this.m_Book.bound.updatePaperPosition(this), this._ucRollResult.copy(t);
604
+ const u = a.rollPoint(this._ucRollResult);
605
+ if (Math.abs(e.x - u.x) < 1e-4) break;
606
+ u.x > e.x ? h.copy(a.position) : n.copy(a.position);
593
607
  }
594
608
  }
595
609
  rollPoint(t) {
596
610
  return this.m_IsRolling ? this.m_Cylinder.rollPoint(t) : t;
597
611
  }
598
- drawWireframe(t) {
599
- }
600
612
  startAutoTurning(t, e, s, i) {
601
- var m, l;
602
- if (this.updateTurningRadius(s), this.m_PrevHandle.copy(this.m_CurrentHandle), this.m_IsRolling = !0, this.m_HandleOffset.set(0, 0, 0), t === 0) {
603
- const d = this.m_Transform.scale;
604
- d.x *= -1;
613
+ var u, l;
614
+ if (this.updateTurningRadius(s), this.m_PrevHandle.copy(this.m_CurrentHandle), this.m_IsRolling = !0, this.m_HandleOffset.set(0, 0, 0), t === mt.Surface) {
615
+ const _ = this.m_Transform.scale;
616
+ _.x *= -1;
605
617
  }
606
618
  this.switchMeshData(
607
619
  0
608
620
  /* Highpoly */
609
- ), (m = this.m_Prev) == null || m.trySwitchMeshData(1), (l = this.m_Next) == null || l.trySwitchMeshData(1), this.m_IsFallingLeft = t === 1, this.m_IsTurning = !1, this.m_IsFalling = !0, this.m_FallTime = 0, this.m_FallDuration = i;
610
- const n = this.m_Size.x, o = this.m_Size.y;
611
- e = Dt(e, -0.99, 0.99);
612
- const a = zt(0.5, 1, e), h = zt(0.5, 0, e);
613
- this.m_StartHandle.set(n, 0, o * a), this.m_EndHandle.set(-n, 0, o * h), this.m_IsAutoTurning = !0;
621
+ ), (u = this.m_Prev) == null || u.trySwitchMeshData(1), (l = this.m_Next) == null || l.trySwitchMeshData(1), this.m_IsFallingLeft = t === mt.Edge, this.m_IsTurning = !1, this.m_IsFalling = !0, this.m_FallTime = 0, this.m_FallDuration = i;
622
+ const n = this.m_Size.x, h = this.m_Size.y;
623
+ e = H(e, -0.99, 0.99);
624
+ const a = Bt(0.5, 1, e), c = Bt(0.5, 0, e);
625
+ this.m_StartHandle.set(n, 0, h * a), this.m_EndHandle.set(-n, 0, h * c), this.m_IsAutoTurning = !0;
614
626
  }
615
627
  // ---- Public getter for the cylinder (used by BookBound etc.) ----
616
628
  get cylinder() {
617
629
  return this.m_Cylinder;
618
630
  }
619
631
  }
620
- const Y = class Y {
632
+ const st = class st {
621
633
  constructor() {
622
634
  this.m_Left = 0, this.m_Right = 0, this.m_Down = 0, this.m_Up = 0;
623
635
  }
@@ -648,7 +660,7 @@ const Y = class Y {
648
660
  }
649
661
  // ── Helpers ───────────────────────────────────────────────────────────
650
662
  clamp(t) {
651
- return Math.max(Y.kMin, Math.min(t, Y.kMax));
663
+ return Math.max(st.kMin, Math.min(t, st.kMax));
652
664
  }
653
665
  // ── Transform ─────────────────────────────────────────────────────────
654
666
  /**
@@ -656,18 +668,18 @@ const Y = class Y {
656
668
  * book direction.
657
669
  */
658
670
  transform(t) {
659
- const e = new Y();
671
+ const e = new st();
660
672
  switch (t) {
661
- case X.LeftToRight:
673
+ case j.LeftToRight:
662
674
  e.m_Left = this.m_Left, e.m_Right = this.m_Right, e.m_Down = this.m_Down, e.m_Up = this.m_Up;
663
675
  break;
664
- case X.RightToLeft:
676
+ case j.RightToLeft:
665
677
  e.m_Left = this.m_Right, e.m_Right = this.m_Left, e.m_Down = this.m_Down, e.m_Up = this.m_Up;
666
678
  break;
667
- case X.UpToDown:
679
+ case j.UpToDown:
668
680
  e.m_Left = this.m_Up, e.m_Right = this.m_Down, e.m_Down = this.m_Left, e.m_Up = this.m_Right;
669
681
  break;
670
- case X.DownToUp:
682
+ case j.DownToUp:
671
683
  default:
672
684
  e.m_Left = this.m_Down, e.m_Right = this.m_Up, e.m_Down = this.m_Left, e.m_Up = this.m_Right;
673
685
  break;
@@ -682,7 +694,7 @@ const Y = class Y {
682
694
  * Unity's `Mathf.InverseLerp(a, b, v)` = `(v - a) / (b - a)` clamped to [0,1].
683
695
  */
684
696
  fixUV(t) {
685
- return t.x = Y.inverseLerp(this.m_Left, 1 - this.m_Right, t.x), t.y = Y.inverseLerp(this.m_Down, 1 - this.m_Up, t.y), t;
697
+ return t.x = st.inverseLerp(this.m_Left, 1 - this.m_Right, t.x), t.y = st.inverseLerp(this.m_Down, 1 - this.m_Up, t.y), t;
686
698
  }
687
699
  static inverseLerp(t, e, s) {
688
700
  if (t === e) return 0;
@@ -691,15 +703,15 @@ const Y = class Y {
691
703
  }
692
704
  // ── Value-type clone ──────────────────────────────────────────────────
693
705
  clone() {
694
- const t = new Y();
706
+ const t = new st();
695
707
  return t.m_Left = this.m_Left, t.m_Right = this.m_Right, t.m_Down = this.m_Down, t.m_Up = this.m_Up, t;
696
708
  }
697
709
  };
698
- Y.kMin = 0, Y.kMax = 0.25;
699
- let pt = Y;
700
- const N = class N {
710
+ st.kMin = 0, st.kMax = 0.25;
711
+ let gt = st;
712
+ const X = class X {
701
713
  constructor(t) {
702
- this.m_Material = null, this.m_Color = new c.Color(1, 1, 1), this.m_Width = 0, this.m_Height = 0, this.m_Thickness = 0, this.m_Stiffness = 0, this.m_Quality = 0, this.m_UVMargin = new pt(), this.margin = 0, this.bookDirection = X.LeftToRight, this.color = (t == null ? void 0 : t.color) ?? new c.Color(1, 1, 1), this.width = (t == null ? void 0 : t.width) ?? N.kMinSize * 2, this.height = (t == null ? void 0 : t.height) ?? N.kMinSize * 2, this.thickness = (t == null ? void 0 : t.thickness) ?? N.kMinThickness * 2, this.stiffness = (t == null ? void 0 : t.stiffness) ?? 0.1, this.quality = (t == null ? void 0 : t.quality) ?? 3, (t == null ? void 0 : t.material) !== void 0 && (this.m_Material = t.material);
714
+ this.m_Material = null, this.m_Color = new o.Color(1, 1, 1), this.m_Width = 0, this.m_Height = 0, this.m_Thickness = 0, this.m_Stiffness = 0, this.m_Quality = 0, this.m_UVMargin = new gt(), this.margin = 0, this.bookDirection = j.LeftToRight, this.color = (t == null ? void 0 : t.color) ?? new o.Color(1, 1, 1), this.width = (t == null ? void 0 : t.width) ?? X.kMinSize * 2, this.height = (t == null ? void 0 : t.height) ?? X.kMinSize * 2, this.thickness = (t == null ? void 0 : t.thickness) ?? X.kMinThickness * 2, this.stiffness = (t == null ? void 0 : t.stiffness) ?? 0.1, this.quality = (t == null ? void 0 : t.quality) ?? 3, (t == null ? void 0 : t.material) !== void 0 && (this.m_Material = t.material);
703
715
  }
704
716
  // ── Properties ────────────────────────────────────────────────────────
705
717
  get material() {
@@ -718,19 +730,19 @@ const N = class N {
718
730
  return this.bookDirection > 1 ? this.m_Height : this.m_Width;
719
731
  }
720
732
  set width(t) {
721
- this.m_Width = Math.max(t, N.kMinSize);
733
+ this.m_Width = Math.max(t, X.kMinSize);
722
734
  }
723
735
  get height() {
724
736
  return this.bookDirection > 1 ? this.m_Width : this.m_Height;
725
737
  }
726
738
  set height(t) {
727
- this.m_Height = Math.max(t, N.kMinSize);
739
+ this.m_Height = Math.max(t, X.kMinSize);
728
740
  }
729
741
  get thickness() {
730
742
  return this.m_Thickness;
731
743
  }
732
744
  set thickness(t) {
733
- this.m_Thickness = Math.max(t, N.kMinThickness);
745
+ this.m_Thickness = Math.max(t, X.kMinThickness);
734
746
  }
735
747
  get stiffness() {
736
748
  return this.m_Stiffness;
@@ -743,8 +755,8 @@ const N = class N {
743
755
  }
744
756
  set quality(t) {
745
757
  this.m_Quality = Math.max(
746
- N.kMinQuality,
747
- Math.min(t, N.kMaxQuality)
758
+ X.kMinQuality,
759
+ Math.min(t, X.kMaxQuality)
748
760
  );
749
761
  }
750
762
  get uvMargin() {
@@ -754,15 +766,15 @@ const N = class N {
754
766
  this.m_UVMargin = t;
755
767
  }
756
768
  get size() {
757
- return new c.Vector2(this.width, this.height);
769
+ return new o.Vector2(this.width, this.height);
758
770
  }
759
771
  };
760
- N.kMinSize = 1, N.kMinThickness = 1e-4, N.kMinQuality = 1, N.kMaxQuality = 5;
761
- let nt = N;
762
- class At {
772
+ X.kMinSize = 1, X.kMinThickness = 1e-4, X.kMinQuality = 1, X.kMaxQuality = 5;
773
+ let rt = X;
774
+ class bt {
763
775
  constructor(t) {
764
- this.m_Texture = null, this.m_TextureST = new c.Vector4(1, 1, 0, 0);
765
- const e = t.material ?? new c.MeshStandardMaterial();
776
+ this.m_Texture = null, this.m_TextureST = new o.Vector4(1, 1, 0, 0), this._cachedPropertyBlock = null, this._propertyBlockDirty = !0;
777
+ const e = t.material ?? new o.MeshStandardMaterial();
766
778
  this.m_Materials1 = [e.clone()], this.m_Materials3 = [e.clone(), e.clone(), e.clone()], this.m_Color = t.color.clone();
767
779
  }
768
780
  get materials1() {
@@ -783,27 +795,29 @@ class At {
783
795
  /**
784
796
  * Mirrors Unity's MaterialPropertyBlock: stores color, texture, and textureST.
785
797
  * Paper.ts reads this after calling updatePropertyBlock.
798
+ *
799
+ * Returns a cached object — callers must NOT mutate the returned values.
786
800
  */
787
801
  get propertyBlock() {
788
- return {
802
+ return (this._propertyBlockDirty || this._cachedPropertyBlock === null) && (this._cachedPropertyBlock = {
789
803
  color: this.m_Color.clone(),
790
804
  map: this.m_Texture,
791
805
  textureST: this.m_TextureST.clone()
792
- };
806
+ }, this._propertyBlockDirty = !1), this._cachedPropertyBlock;
793
807
  }
794
808
  updatePropertyBlock(t, e) {
795
- this.m_Texture = t, this.m_TextureST.copy(e);
809
+ this.m_Texture = t, this.m_TextureST.copy(e), this._propertyBlockDirty = !0;
796
810
  }
797
811
  }
798
- function Ht(r, t, e, s = new c.Vector3()) {
799
- let i = t.x - r.x, n = t.y - r.y, o = t.z - r.z, a = 1 / Math.sqrt(i * i + n * n + o * o);
800
- i *= a, n *= a, o *= a;
801
- let h = e.x - r.x, m = e.y - r.y, l = e.z - r.z;
802
- a = 1 / Math.sqrt(h * h + m * m + l * l), h *= a, m *= a, l *= a;
803
- const d = n * l - o * m, g = o * h - i * l, _ = i * m - n * h;
804
- return a = 1 / Math.sqrt(d * d + g * g + _ * _), s.set(d * a, g * a, _ * a);
812
+ function Vt(r, t, e, s = new o.Vector3()) {
813
+ let i = t.x - r.x, n = t.y - r.y, h = t.z - r.z, a = 1 / Math.sqrt(i * i + n * n + h * h);
814
+ i *= a, n *= a, h *= a;
815
+ let c = e.x - r.x, u = e.y - r.y, l = e.z - r.z;
816
+ a = 1 / Math.sqrt(c * c + u * u + l * l), c *= a, u *= a, l *= a;
817
+ const _ = n * l - h * u, d = h * c - i * l, f = i * u - n * c;
818
+ return a = 1 / Math.sqrt(_ * _ + d * d + f * f), s.set(_ * a, d * a, f * a);
805
819
  }
806
- class st {
820
+ class ht {
807
821
  constructor(t, e = !1, s = !1) {
808
822
  this.prev = null, this.next = null, this.index = 0, this.value = t, this.hole = e, this.seam = s;
809
823
  }
@@ -822,13 +836,7 @@ class st {
822
836
  }
823
837
  // ── Factory helpers ───────────────────────────────────────────────────
824
838
  createNext(t, e = !1, s = !1) {
825
- const i = new st(t, e, s);
826
- return i.prev = this, this.next = i, i;
827
- }
828
- // C# had a double overload — in TS numbers are already IEEE 754 doubles.
829
- // Keeping a separate method for parity; it simply casts to number.
830
- createNextFromDouble(t, e = !1, s = !1) {
831
- const i = new st(t, e, s);
839
+ const i = new ht(t, e, s);
832
840
  return i.prev = this, this.next = i, i;
833
841
  }
834
842
  // ── Insertion (sorted linked-list insert) ─────────────────────────────
@@ -860,21 +868,21 @@ class st {
860
868
  t.push(this.hole), this.next !== null && this.next._getHolesRecursive(t);
861
869
  }
862
870
  }
863
- class Pt {
871
+ class wt {
864
872
  constructor(t, e, s, i) {
865
873
  this.active = !0, this.prevIndex = t, this.index = e, this.nextIndex = s, this.time = i;
866
874
  }
867
875
  clone() {
868
- const t = new Pt(this.prevIndex, this.index, this.nextIndex, this.time);
876
+ const t = new wt(this.prevIndex, this.index, this.nextIndex, this.time);
869
877
  return t.active = this.active, t;
870
878
  }
871
879
  }
872
- class St {
873
- constructor(t, e, s, i, n, o = !0) {
874
- this.startX = t, this.startZ = e, this.endX = s, this.endZ = i, this.flip = n, this.left = o;
880
+ class Pt {
881
+ constructor(t, e, s, i, n, h = !0) {
882
+ this.startX = t, this.startZ = e, this.endX = s, this.endZ = i, this.flip = n, this.left = h;
875
883
  }
876
884
  clone() {
877
- return new St(
885
+ return new Pt(
878
886
  this.startX,
879
887
  this.startZ,
880
888
  this.endX,
@@ -884,197 +892,157 @@ class St {
884
892
  );
885
893
  }
886
894
  }
887
- class ue {
895
+ class he {
888
896
  constructor(t, e, s) {
889
897
  const i = t.size;
890
- this.leftNode = new st(e.left * i.x, s, !0), this.rightNode = new st((1 - e.right) * i.x, s, !0), this.downNode = new st(e.down * i.y, s, !0), this.upNode = new st((1 - e.up) * i.y, s, !0);
898
+ this.leftNode = new ht(e.left * i.x, s, !0), this.rightNode = new ht((1 - e.right) * i.x, s, !0), this.downNode = new ht(e.down * i.y, s, !0), this.upNode = new ht((1 - e.up) * i.y, s, !0);
891
899
  }
892
900
  insert(t, e, s, i) {
893
901
  t.insert(this.leftNode) && s.push(this.leftNode), t.insert(this.rightNode) && s.push(this.rightNode), e.insert(this.downNode) && i.push(this.downNode), e.insert(this.upNode) && i.push(this.upNode);
894
902
  }
895
903
  }
896
- function lt(r, t, e) {
897
- if (r === t) return 0;
898
- const s = (e - r) / (t - r);
899
- return Math.max(0, Math.min(1, s));
900
- }
901
- function xt(r, t) {
904
+ function pt(r, t) {
902
905
  for (const e of r) {
903
- const s = e.prevNoneSeam, i = e.nextNoneSeam, n = lt(s.value, i.value, e.value), o = new Pt(s.index, e.index, i.index, n);
904
- t.push(o);
906
+ const s = e.prevNoneSeam, i = e.nextNoneSeam, n = Q(s.value, i.value, e.value), h = new wt(s.index, e.index, i.index, n);
907
+ t.push(h);
905
908
  }
906
909
  }
907
- function Mt(r, t, e, s, i) {
908
- for (const n of r) {
909
- if (!n.active) return;
910
- for (let o = 0; o < s; o++) {
911
- const a = n.prevIndex, h = n.nextIndex, m = t[o * e + a], l = t[o * e + h], d = t[o * e + n.index];
912
- i ? qt(m, l, n.time, d) : d.copy(m).lerp(l, n.time);
913
- }
914
- }
910
+ function xt(r, t, e, s, i) {
911
+ for (const n of r)
912
+ if (n.active)
913
+ for (let h = 0; h < s; h++) {
914
+ const a = n.prevIndex, c = n.nextIndex, u = t[h * e + a], l = t[h * e + c], _ = t[h * e + n.index];
915
+ i ? Et(u, l, n.time, _) : _.copy(u).lerp(l, n.time);
916
+ }
915
917
  }
916
- function Ct(r, t, e, s, i) {
917
- for (const n of r) {
918
- if (!n.active) return;
919
- for (let o = 0; o < e; o++) {
920
- const a = n.prevIndex, h = n.nextIndex, m = t[a * e + o], l = t[h * e + o], d = t[n.index * e + o];
921
- i ? qt(m, l, n.time, d) : d.copy(m).lerp(l, n.time);
922
- }
923
- }
918
+ function Mt(r, t, e, s, i) {
919
+ for (const n of r)
920
+ if (n.active)
921
+ for (let h = 0; h < e; h++) {
922
+ const a = n.prevIndex, c = n.nextIndex, u = t[a * e + h], l = t[c * e + h], _ = t[n.index * e + h];
923
+ i ? Et(u, l, n.time, _) : _.copy(u).lerp(l, n.time);
924
+ }
924
925
  }
925
- function qt(r, t, e, s = new c.Vector3()) {
926
+ function Et(r, t, e, s = new o.Vector3()) {
926
927
  const i = Math.sqrt(r.x * r.x + r.y * r.y + r.z * r.z), n = Math.sqrt(t.x * t.x + t.y * t.y + t.z * t.z);
927
928
  if (i === 0 || n === 0)
928
929
  return s.copy(r).lerp(t, e);
929
- const o = r.x / i, a = r.y / i, h = r.z / i, m = t.x / n, l = t.y / n, d = t.z / n;
930
- let g = o * m + a * l + h * d;
931
- g = Math.max(-1, Math.min(1, g));
932
- const _ = Math.acos(g);
933
- if (_ < 1e-6)
930
+ const h = r.x / i, a = r.y / i, c = r.z / i, u = t.x / n, l = t.y / n, _ = t.z / n;
931
+ let d = h * u + a * l + c * _;
932
+ d = Math.max(-1, Math.min(1, d));
933
+ const f = Math.acos(d);
934
+ if (f < 1e-6)
934
935
  return s.copy(r).lerp(t, e);
935
- const u = Math.sin(_), f = Math.sin((1 - e) * _) / u, p = Math.sin(e * _) / u, P = i + (n - i) * e;
936
+ const m = Math.sin(f), g = Math.sin((1 - e) * f) / m, p = Math.sin(e * f) / m, M = i + (n - i) * e;
936
937
  return s.set(
937
- (o * f + m * p) * P,
938
- (a * f + l * p) * P,
939
- (h * f + d * p) * P
938
+ (h * g + u * p) * M,
939
+ (a * g + l * p) * M,
940
+ (c * g + _ * p) * M
940
941
  );
941
942
  }
942
- function Qt(r, t, e, s, i) {
943
+ function Nt(r, t, e, s, i) {
943
944
  for (const n of r) {
944
- const o = (n.endX - n.startX + 1) * 2, a = (n.endZ - n.startZ + 1) * 2, h = e.length;
945
- for (let l = 0, d = n.endX - n.startX; l < d; l++) {
946
- const g = h + l * 2 + 0, _ = h + l * 2 + 1, u = h + l * 2 + 2, f = h + l * 2 + 3;
947
- n.flip ? Ot(t, g, _, u, f, o) : Ft(t, g, _, u, f, o);
945
+ const h = (n.endX - n.startX + 1) * 2, a = (n.endZ - n.startZ + 1) * 2, c = e.length;
946
+ for (let l = 0, _ = n.endX - n.startX; l < _; l++) {
947
+ const d = c + l * 2 + 0, f = c + l * 2 + 1, m = c + l * 2 + 2, g = c + l * 2 + 3;
948
+ n.flip ? It(t, d, f, m, g, h) : Dt(t, d, f, m, g, h);
948
949
  }
949
950
  if (n.left)
950
- for (let l = 0, d = n.endZ - n.startZ; l < d; l++) {
951
- const g = h + l * 2 + 0 + o * 2, _ = h + l * 2 + 1 + o * 2, u = h + l * 2 + 2 + o * 2, f = h + l * 2 + 3 + o * 2;
952
- n.flip ? Ot(t, g, _, u, f, a) : Ft(t, g, _, u, f, a);
951
+ for (let l = 0, _ = n.endZ - n.startZ; l < _; l++) {
952
+ const d = c + l * 2 + 0 + h * 2, f = c + l * 2 + 1 + h * 2, m = c + l * 2 + 2 + h * 2, g = c + l * 2 + 3 + h * 2;
953
+ n.flip ? It(t, d, f, m, g, a) : Dt(t, d, f, m, g, a);
953
954
  }
954
955
  else
955
- for (let l = 0, d = n.endZ - n.startZ; l < d; l++) {
956
- const g = h + l * 2 + 0 + o * 2 + a, _ = h + l * 2 + 1 + o * 2 + a, u = h + l * 2 + 2 + o * 2 + a, f = h + l * 2 + 3 + o * 2 + a;
957
- n.flip ? ft(t, g, _, u, f) : _t(t, g, _, u, f);
956
+ for (let l = 0, _ = n.endZ - n.startZ; l < _; l++) {
957
+ const d = c + l * 2 + 0 + h * 2 + a, f = c + l * 2 + 1 + h * 2 + a, m = c + l * 2 + 2 + h * 2 + a, g = c + l * 2 + 3 + h * 2 + a;
958
+ n.flip ? dt(t, d, f, m, g) : _t(t, d, f, m, g);
958
959
  }
959
- const m = s * i;
960
+ const u = s * i;
960
961
  for (let l = n.startX; l <= n.endX; l++) {
961
- const d = n.startZ * s + l;
962
- e.push(e[d].clone()), e.push(e[d + m].clone());
962
+ const _ = n.startZ * s + l;
963
+ e.push(e[_].clone()), e.push(e[_ + u].clone());
963
964
  }
964
965
  for (let l = n.startX; l <= n.endX; l++) {
965
- const d = l + n.endZ * s;
966
- e.push(e[d + m].clone()), e.push(e[d].clone());
966
+ const _ = l + n.endZ * s;
967
+ e.push(e[_ + u].clone()), e.push(e[_].clone());
967
968
  }
968
969
  for (let l = n.startZ; l <= n.endZ; l++) {
969
- const d = n.startX + l * s;
970
- e.push(e[d + m].clone()), e.push(e[d].clone());
970
+ const _ = n.startX + l * s;
971
+ e.push(e[_ + u].clone()), e.push(e[_].clone());
971
972
  }
972
973
  for (let l = n.startZ; l <= n.endZ; l++) {
973
- const d = l * s + n.endX;
974
- e.push(e[d].clone()), e.push(e[d + m].clone());
974
+ const _ = l * s + n.endX;
975
+ e.push(e[_].clone()), e.push(e[_ + u].clone());
975
976
  }
976
977
  }
977
978
  }
978
- function $t(r, t, e, s, i) {
979
+ function Xt(r, t, e, s, i) {
979
980
  const n = s * i;
980
- let o = n * 2;
981
- const a = new c.Vector3();
982
- for (const h of r) {
983
- for (let m = h.startX; m <= h.endX; m++) {
984
- const l = m + h.startZ * s, d = t[l], g = t[l + s];
985
- a.subVectors(d, g).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(d), e[o].copy(a), t[o++].copy(t[l + n]);
986
- }
987
- for (let m = h.startX; m <= h.endX; m++) {
988
- const l = m + h.endZ * s, d = t[l + n], g = t[l + n - s];
989
- a.subVectors(d, g).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(d), e[o].copy(a), t[o++].copy(t[l]);
990
- }
991
- for (let m = h.startZ; m <= h.endZ; m++) {
992
- const l = m * s + h.startX, d = t[l + n], g = t[l + n + 1];
993
- a.subVectors(d, g).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(d), e[o].copy(a), t[o++].copy(t[l]);
994
- }
995
- for (let m = h.startZ; m <= h.endZ; m++) {
996
- const l = m * s + h.endX, d = t[l], g = t[l - 1];
997
- a.subVectors(d, g).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(d), e[o].copy(a), t[o++].copy(t[l + n]);
981
+ let h = n * 2;
982
+ const a = new o.Vector3();
983
+ for (const c of r) {
984
+ for (let u = c.startX; u <= c.endX; u++) {
985
+ const l = u + c.startZ * s, _ = t[l], d = t[l + s];
986
+ a.subVectors(_, d).normalize(), c.flip && a.multiplyScalar(-1), e[h].copy(a), t[h++].copy(_), e[h].copy(a), t[h++].copy(t[l + n]);
998
987
  }
999
- }
1000
- }
1001
- function de(r, t, e, s, i) {
1002
- const n = [];
1003
- for (const o of r) {
1004
- for (let a = o.startX; a < o.endX; a++) {
1005
- const h = a + o.startZ * e, m = t[h].clone().applyMatrix4(i), l = t[h + 1].clone().applyMatrix4(i);
1006
- n.push([m, l]);
988
+ for (let u = c.startX; u <= c.endX; u++) {
989
+ const l = u + c.endZ * s, _ = t[l + n], d = t[l + n - s];
990
+ a.subVectors(_, d).normalize(), c.flip && a.multiplyScalar(-1), e[h].copy(a), t[h++].copy(_), e[h].copy(a), t[h++].copy(t[l]);
1007
991
  }
1008
- for (let a = o.startX; a < o.endX; a++) {
1009
- const h = a + o.endZ * e, m = t[h].clone().applyMatrix4(i), l = t[h + 1].clone().applyMatrix4(i);
1010
- n.push([m, l]);
992
+ for (let u = c.startZ; u <= c.endZ; u++) {
993
+ const l = u * s + c.startX, _ = t[l + n], d = t[l + n + 1];
994
+ a.subVectors(_, d).normalize(), c.flip && a.multiplyScalar(-1), e[h].copy(a), t[h++].copy(_), e[h].copy(a), t[h++].copy(t[l]);
1011
995
  }
1012
- for (let a = o.startZ; a < o.endZ; a++) {
1013
- const h = a * e + o.startX, m = (a + 1) * e + o.startX, l = t[h].clone().applyMatrix4(i), d = t[m].clone().applyMatrix4(i);
1014
- n.push([l, d]);
1015
- }
1016
- for (let a = o.startZ; a < o.endZ; a++) {
1017
- const h = a * e + o.endX, m = (a + 1) * e + o.endX, l = t[h].clone().applyMatrix4(i), d = t[m].clone().applyMatrix4(i);
1018
- n.push([l, d]);
996
+ for (let u = c.startZ; u <= c.endZ; u++) {
997
+ const l = u * s + c.endX, _ = t[l], d = t[l - 1];
998
+ a.subVectors(_, d).normalize(), c.flip && a.multiplyScalar(-1), e[h].copy(a), t[h++].copy(_), e[h].copy(a), t[h++].copy(t[l + n]);
1019
999
  }
1020
1000
  }
1021
- return n;
1022
1001
  }
1023
- function Ft(r, t, e, s, i, n) {
1002
+ function Dt(r, t, e, s, i, n) {
1024
1003
  _t(r, t, e, s, i), t += n, e += n, s += n, i += n, _t(r, t, e, s, i);
1025
1004
  }
1026
- function Ot(r, t, e, s, i, n) {
1027
- ft(r, t, e, s, i), t += n, e += n, s += n, i += n, ft(r, t, e, s, i);
1005
+ function It(r, t, e, s, i, n) {
1006
+ dt(r, t, e, s, i), t += n, e += n, s += n, i += n, dt(r, t, e, s, i);
1028
1007
  }
1029
- function Yt(r, t, e, s, i, n, o) {
1030
- _t(r, e, s, i, n), e += o, s += o, i += o, n += o, ft(t, e, s, i, n);
1008
+ function Wt(r, t, e, s, i, n, h) {
1009
+ _t(r, e, s, i, n), e += h, s += h, i += h, n += h, dt(t, e, s, i, n);
1031
1010
  }
1032
- function Kt(r, t, e, s, i, n) {
1033
- const o = i.left * s.x, a = (1 - i.right) * s.x, h = i.down * s.y, m = (1 - i.up) * s.y, l = t.length, d = e.length;
1011
+ function Gt(r, t, e, s, i, n) {
1012
+ const h = i.left * s.x, a = (1 - i.right) * s.x, c = i.down * s.y, u = (1 - i.up) * s.y, l = t.length, _ = e.length;
1034
1013
  if (n > 1)
1035
- for (let _ = 0; _ < d; _++)
1036
- for (let u = 0; u < l; u++) {
1037
- const f = lt(a, o, t[u]), p = lt(m, h, e[_]);
1038
- r.push(new c.Vector2(p, f));
1014
+ for (let f = 0; f < _; f++)
1015
+ for (let m = 0; m < l; m++) {
1016
+ const g = Q(a, h, t[m]), p = Q(u, c, e[f]);
1017
+ r.push(new o.Vector2(p, g));
1039
1018
  }
1040
1019
  else
1041
- for (let _ = 0; _ < d; _++)
1042
- for (let u = 0; u < l; u++) {
1043
- const f = lt(o, a, t[u]), p = lt(m, h, e[_]);
1044
- r.push(new c.Vector2(f, p));
1020
+ for (let f = 0; f < _; f++)
1021
+ for (let m = 0; m < l; m++) {
1022
+ const g = Q(h, a, t[m]), p = Q(u, c, e[f]);
1023
+ r.push(new o.Vector2(g, p));
1045
1024
  }
1046
- const g = r.length;
1047
- for (let _ = 0; _ < g; _++)
1048
- r.push(r[_].clone());
1025
+ const d = r.length;
1026
+ for (let f = 0; f < d; f++)
1027
+ r.push(r[f].clone());
1049
1028
  }
1050
1029
  function _t(r, t, e, s, i) {
1051
1030
  r.push(t), r.push(s), r.push(e), r.push(e), r.push(s), r.push(i);
1052
1031
  }
1053
- function ft(r, t, e, s, i) {
1032
+ function dt(r, t, e, s, i) {
1054
1033
  r.push(t), r.push(e), r.push(s), r.push(e), r.push(i), r.push(s);
1055
1034
  }
1056
- function Jt(r, t, e, s) {
1057
- const i = [];
1058
- for (let n = 0; n < e - 1; n++)
1059
- for (let o = 0; o < t - 1; o++) {
1060
- let a = r[n * t + o].clone(), h = r[n * t + o + 1].clone(), m = r[(n + 1) * t + o].clone(), l = r[(n + 1) * t + o + 1].clone();
1061
- a.applyMatrix4(s), h.applyMatrix4(s), m.applyMatrix4(s), l.applyMatrix4(s), i.push([a, h, m, l]);
1062
- }
1063
- return i;
1064
- }
1065
- const Ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1035
+ const ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1066
1036
  __proto__: null,
1067
- addBorders: Qt,
1068
- addFrontAndBackFaces: Yt,
1069
- addFrontAndBackTexcoords: Kt,
1070
- debugDrawBorders: de,
1071
- drawWireframe: Jt,
1072
- seamNodesToSeams: xt,
1073
- updateBorders: $t,
1074
- updateXSeams: Mt,
1075
- updateZSeams: Ct
1037
+ addBorders: Nt,
1038
+ addFrontAndBackFaces: Wt,
1039
+ addFrontAndBackTexcoords: Gt,
1040
+ seamNodesToSeams: pt,
1041
+ updateBorders: Xt,
1042
+ updateXSeams: xt,
1043
+ updateZSeams: Mt
1076
1044
  }, Symbol.toStringTag, { value: "Module" }));
1077
- class Zt {
1045
+ class zt {
1078
1046
  get geometry() {
1079
1047
  return this.m_Geometry;
1080
1048
  }
@@ -1086,34 +1054,34 @@ class Zt {
1086
1054
  }
1087
1055
  constructor(t, e) {
1088
1056
  this.m_Pattern = e, this.m_BaseVertices = new Array(e.baseVertexCount);
1089
- for (let o = 0; o < e.baseVertexCount; o++)
1090
- this.m_BaseVertices[o] = new c.Vector3();
1057
+ for (let h = 0; h < e.baseVertexCount; h++)
1058
+ this.m_BaseVertices[h] = new o.Vector3();
1091
1059
  this.m_Vertices = new Array(e.vertexCount);
1092
- for (let o = 0; o < e.vertexCount; o++)
1093
- this.m_Vertices[o] = new c.Vector3();
1060
+ for (let h = 0; h < e.vertexCount; h++)
1061
+ this.m_Vertices[h] = new o.Vector3();
1094
1062
  this.m_Normals = new Array(e.vertexCount);
1095
- for (let o = 0; o < e.vertexCount; o++)
1096
- this.m_Normals[o] = new c.Vector3();
1063
+ for (let h = 0; h < e.vertexCount; h++)
1064
+ this.m_Normals[h] = new o.Vector3();
1097
1065
  if (this.m_Geometry = t, this.m_Pattern.subMeshCount === 1) {
1098
- const o = new Uint32Array(e.triangles);
1099
- this.m_Geometry.setIndex(new c.BufferAttribute(o, 1)), this.m_Geometry.addGroup(0, e.triangles.length, 0);
1066
+ const h = new Uint32Array(e.triangles);
1067
+ this.m_Geometry.setIndex(new o.BufferAttribute(h, 1)), this.m_Geometry.addGroup(0, e.triangles.length, 0);
1100
1068
  } else {
1101
- const o = e.frontTriangles.length + e.backTriangles.length + e.borderTriangles.length, a = new Uint32Array(o);
1102
- let h = 0;
1103
- a.set(e.frontTriangles, h), this.m_Geometry.addGroup(h, e.frontTriangles.length, 0), h += e.frontTriangles.length, a.set(e.backTriangles, h), this.m_Geometry.addGroup(h, e.backTriangles.length, 1), h += e.backTriangles.length, a.set(e.borderTriangles, h), this.m_Geometry.addGroup(h, e.borderTriangles.length, 2), this.m_Geometry.setIndex(new c.BufferAttribute(a, 1));
1069
+ const h = e.frontTriangles.length + e.backTriangles.length + e.borderTriangles.length, a = new Uint32Array(h);
1070
+ let c = 0;
1071
+ a.set(e.frontTriangles, c), this.m_Geometry.addGroup(c, e.frontTriangles.length, 0), c += e.frontTriangles.length, a.set(e.backTriangles, c), this.m_Geometry.addGroup(c, e.backTriangles.length, 1), c += e.backTriangles.length, a.set(e.borderTriangles, c), this.m_Geometry.addGroup(c, e.borderTriangles.length, 2), this.m_Geometry.setIndex(new o.BufferAttribute(a, 1));
1104
1072
  }
1105
1073
  const s = new Float32Array(e.vertexCount * 3), i = new Float32Array(e.vertexCount * 3), n = new Float32Array(e.vertexCount * 2);
1106
- for (let o = 0; o < e.texcoords.length; o++)
1107
- n[o * 2] = e.texcoords[o].x, n[o * 2 + 1] = e.texcoords[o].y;
1074
+ for (let h = 0; h < e.texcoords.length; h++)
1075
+ n[h * 2] = e.texcoords[h].x, n[h * 2 + 1] = e.texcoords[h].y;
1108
1076
  this.m_Geometry.setAttribute(
1109
1077
  "position",
1110
- new c.BufferAttribute(s, 3)
1078
+ new o.BufferAttribute(s, 3)
1111
1079
  ), this.m_Geometry.setAttribute(
1112
1080
  "normal",
1113
- new c.BufferAttribute(i, 3)
1081
+ new o.BufferAttribute(i, 3)
1114
1082
  ), this.m_Geometry.setAttribute(
1115
1083
  "uv",
1116
- new c.BufferAttribute(n, 2)
1084
+ new o.BufferAttribute(n, 2)
1117
1085
  ), this.updateBaseVertices();
1118
1086
  }
1119
1087
  // ── UpdateBaseVertices ──────────────────────────────────────────────────
@@ -1124,11 +1092,11 @@ class Zt {
1124
1092
  * Ported from lines ~2167-2183.
1125
1093
  */
1126
1094
  updateBaseVertices() {
1127
- const t = this.m_BaseVertices, e = this.m_Pattern.baseXArray, s = this.m_Pattern.baseZArray, i = this.m_Pattern.baseXOffset, n = e.length, o = s.length;
1095
+ const t = this.m_BaseVertices, e = this.m_Pattern.baseXArray, s = this.m_Pattern.baseZArray, i = this.m_Pattern.baseXOffset, n = e.length, h = s.length;
1128
1096
  let a = 0;
1129
- for (let h = 0; h < o; h++)
1130
- for (let m = 0; m < n; m++)
1131
- t[a++].set(e[m] + i, 0, s[h]);
1097
+ for (let c = 0; c < h; c++)
1098
+ for (let u = 0; u < n; u++)
1099
+ t[a++].set(e[u] + i, 0, s[c]);
1132
1100
  }
1133
1101
  // ── UpdateMesh ─────────────────────────────────────────────────────────
1134
1102
  /**
@@ -1147,59 +1115,49 @@ class Zt {
1147
1115
  * Ported from lines ~2185-2255.
1148
1116
  */
1149
1117
  updateMesh() {
1150
- const t = this.m_BaseVertices, e = this.m_Vertices, s = this.m_Normals, i = this.m_Pattern.weights, n = this.m_Pattern.baseXArray.length, o = this.m_Pattern.baseZArray.length, a = this.m_Pattern.baseVertexCount, h = new c.Vector3(), m = new c.Vector3(), l = new c.Vector3();
1151
- for (let u = 0; u < a; u++)
1152
- s[u].set(0, 0, 0);
1153
- Mt(this.m_Pattern.xSeams, t, n, o, !1), Ct(this.m_Pattern.zSeams, t, n, o, !1);
1154
- for (let u = 0; u < o - 1; u++) {
1155
- const f = u + 1;
1118
+ const t = this.m_BaseVertices, e = this.m_Vertices, s = this.m_Normals, i = this.m_Pattern.weights, n = this.m_Pattern.baseXArray.length, h = this.m_Pattern.baseZArray.length, a = this.m_Pattern.baseVertexCount, c = new o.Vector3(), u = new o.Vector3(), l = new o.Vector3();
1119
+ for (let m = 0; m < a; m++)
1120
+ s[m].set(0, 0, 0);
1121
+ xt(this.m_Pattern.xSeams, t, n, h, !1), Mt(this.m_Pattern.zSeams, t, n, h, !1);
1122
+ for (let m = 0; m < h - 1; m++) {
1123
+ const g = m + 1;
1156
1124
  for (let p = 0; p < n - 1; p++) {
1157
- const P = p + 1, B = u * n + p, M = u * n + P, w = f * n + p, T = f * n + P, k = t[B], O = t[M], Z = t[w], z = t[T];
1158
- Ht(k, Z, O, h), Ht(z, O, Z, m), l.addVectors(h, m), s[B].add(l), s[M].add(l), s[w].add(l), s[T].add(l);
1125
+ const M = p + 1, T = m * n + p, C = m * n + M, S = g * n + p, k = g * n + M, D = t[T], U = t[C], L = t[S], z = t[k];
1126
+ Vt(D, L, U, c), Vt(z, U, L, u), l.addVectors(c, u), s[T].add(l), s[C].add(l), s[S].add(l), s[k].add(l);
1159
1127
  }
1160
1128
  }
1161
- for (let u = 0; u < a; u++)
1162
- s[u].divideScalar(i[u]).normalize();
1163
- Mt(this.m_Pattern.xSeams, s, n, o, !0), Ct(this.m_Pattern.zSeams, s, n, o, !0);
1164
- const d = this.m_Pattern.thickness / 2;
1165
- for (let u = 0; u < a; u++) {
1166
- const f = s[u];
1167
- s[u + a].copy(f).negate();
1168
- const p = t[u];
1169
- e[u].copy(p).addScaledVector(f, d), e[u + a].copy(p).addScaledVector(f, -d);
1170
- }
1171
- $t(this.m_Pattern.borders, e, s, n, o);
1172
- const g = this.m_Geometry.getAttribute(
1129
+ for (let m = 0; m < a; m++)
1130
+ s[m].divideScalar(i[m]).normalize();
1131
+ xt(this.m_Pattern.xSeams, s, n, h, !0), Mt(this.m_Pattern.zSeams, s, n, h, !0);
1132
+ const _ = this.m_Pattern.thickness / 2;
1133
+ for (let m = 0; m < a; m++) {
1134
+ const g = s[m];
1135
+ s[m + a].copy(g).negate();
1136
+ const p = t[m];
1137
+ e[m].copy(p).addScaledVector(g, _), e[m + a].copy(p).addScaledVector(g, -_);
1138
+ }
1139
+ Xt(this.m_Pattern.borders, e, s, n, h);
1140
+ const d = this.m_Geometry.getAttribute(
1173
1141
  "position"
1174
- ), _ = this.m_Geometry.getAttribute(
1142
+ ), f = this.m_Geometry.getAttribute(
1175
1143
  "normal"
1176
1144
  );
1177
- for (let u = 0; u < e.length; u++) {
1178
- const f = e[u];
1179
- g.setXYZ(u, f.x, f.y, f.z);
1180
- const p = s[u];
1181
- _.setXYZ(u, p.x, p.y, p.z);
1145
+ for (let m = 0; m < e.length; m++) {
1146
+ const g = e[m];
1147
+ d.setXYZ(m, g.x, g.y, g.z);
1148
+ const p = s[m];
1149
+ f.setXYZ(m, p.x, p.y, p.z);
1182
1150
  }
1183
- g.needsUpdate = !0, _.needsUpdate = !0, this.m_Geometry.computeBoundingBox(), this.m_Geometry.computeBoundingSphere();
1184
- }
1185
- // ── DrawWireframe (debug) ──────────────────────────────────────────────
1186
- /**
1187
- * Returns wireframe quad data for debug visualisation.
1188
- *
1189
- * Ported from lines ~2257-2262.
1190
- */
1191
- drawWireframe(t) {
1192
- const e = this.m_Pattern.baseXArray.length, s = this.m_Pattern.baseZArray.length;
1193
- return Jt(this.m_Vertices, e, s, t);
1151
+ d.needsUpdate = !0, f.needsUpdate = !0, this.m_Geometry.computeBoundingBox(), this.m_Geometry.computeBoundingSphere();
1194
1152
  }
1195
1153
  }
1196
- class _e {
1154
+ class ae {
1197
1155
  constructor() {
1198
1156
  this.m_UsedMeshs = [], this.m_FreeMeshs = [], this.m_Meshs = /* @__PURE__ */ new Set();
1199
1157
  }
1200
1158
  get() {
1201
1159
  let t;
1202
- return this.m_FreeMeshs.length > 0 ? t = this.m_FreeMeshs.pop() : (t = new c.BufferGeometry(), this.m_Meshs.add(t)), this.m_UsedMeshs.push(t), t;
1160
+ return this.m_FreeMeshs.length > 0 ? t = this.m_FreeMeshs.pop() : (t = new o.BufferGeometry(), this.m_Meshs.add(t)), this.m_UsedMeshs.push(t), t;
1203
1161
  }
1204
1162
  recycle() {
1205
1163
  for (const t of this.m_UsedMeshs)
@@ -1212,19 +1170,16 @@ class _e {
1212
1170
  this.m_Meshs.clear();
1213
1171
  }
1214
1172
  }
1215
- class fe {
1173
+ class oe {
1216
1174
  constructor(t) {
1217
- this.m_CreateMeshCollider = !1, this.m_UsedRenderers = [], this.m_FreeRenderers = [], this.m_Renderers = /* @__PURE__ */ new Set(), this.m_Ids = [], this.m_Root = t;
1218
- }
1219
- set createColliders(t) {
1220
- this.m_CreateMeshCollider = t;
1175
+ this.m_UsedRenderers = [], this.m_FreeRenderers = [], this.m_Renderers = /* @__PURE__ */ new Set(), this.m_Ids = [], this.m_Root = t;
1221
1176
  }
1222
1177
  get ids() {
1223
1178
  return [...this.m_Ids];
1224
1179
  }
1225
1180
  get(t) {
1226
1181
  let e;
1227
- return this.m_FreeRenderers.length > 0 ? (e = this.m_FreeRenderers.pop(), e.createCollider = this.m_CreateMeshCollider, e.reset(t)) : (e = new pe(this.m_Root, t, this.m_CreateMeshCollider), this.m_Renderers.add(e)), this.m_UsedRenderers.push(e), this.m_Ids.push(e.id), e;
1182
+ return this.m_FreeRenderers.length > 0 ? (e = this.m_FreeRenderers.pop(), e.reset(t)) : (e = new le(this.m_Root, t), this.m_Renderers.add(e)), this.m_UsedRenderers.push(e), this.m_Ids.push(e.id), e;
1228
1183
  }
1229
1184
  recycle() {
1230
1185
  for (const t of this.m_UsedRenderers)
@@ -1237,29 +1192,23 @@ class fe {
1237
1192
  this.m_Renderers.clear();
1238
1193
  }
1239
1194
  getBounds() {
1240
- const t = new c.Box3();
1195
+ const t = new o.Box3();
1241
1196
  let e = !0;
1242
1197
  for (const s of this.m_UsedRenderers)
1243
1198
  e ? (t.copy(s.bounds), e = !1) : t.union(s.bounds);
1244
1199
  return t;
1245
1200
  }
1246
1201
  }
1247
- let ge = 1;
1248
- class pe {
1249
- constructor(t, e, s) {
1250
- this.m_Visibility = !0, this.m_PropertyBlocks = /* @__PURE__ */ new Map(), this.m_MaterialTextures = /* @__PURE__ */ new Map(), this.m_Id = ge++, this.m_Object3D = new c.Object3D(), this.m_Object3D.name = e, this.m_Mesh = new c.Mesh(
1251
- new c.BufferGeometry(),
1252
- new c.MeshStandardMaterial()
1253
- ), this.m_Object3D.add(this.m_Mesh), t.add(this.m_Object3D), this.m_CreateCollider = s;
1254
- }
1255
- get createCollider() {
1256
- return this.m_CreateCollider;
1257
- }
1258
- set createCollider(t) {
1259
- this.m_CreateCollider = t;
1202
+ let ce = 1;
1203
+ class le {
1204
+ constructor(t, e) {
1205
+ this.m_Visibility = !0, this.m_PropertyBlocks = /* @__PURE__ */ new Map(), this.m_MaterialTextures = /* @__PURE__ */ new Map(), this.m_Id = ce++, this.m_Object3D = new o.Object3D(), this.m_Object3D.name = e, this.m_Mesh = new o.Mesh(
1206
+ new o.BufferGeometry(),
1207
+ new o.MeshStandardMaterial()
1208
+ ), this.m_Object3D.add(this.m_Mesh), t.add(this.m_Object3D);
1260
1209
  }
1261
1210
  get bounds() {
1262
- const t = new c.Box3();
1211
+ const t = new o.Box3();
1263
1212
  return this.m_Mesh.geometry && (this.m_Mesh.geometry.computeBoundingBox(), this.m_Mesh.geometry.boundingBox && (t.copy(this.m_Mesh.geometry.boundingBox), t.applyMatrix4(this.m_Mesh.matrixWorld))), t;
1264
1213
  }
1265
1214
  get id() {
@@ -1271,9 +1220,15 @@ class pe {
1271
1220
  get visibility() {
1272
1221
  return this.m_Visibility;
1273
1222
  }
1223
+ get castShadows() {
1224
+ return this.m_Mesh.castShadow;
1225
+ }
1274
1226
  set castShadows(t) {
1275
1227
  this.m_Mesh.castShadow = t;
1276
1228
  }
1229
+ get mesh() {
1230
+ return this.m_Mesh.geometry ?? null;
1231
+ }
1277
1232
  set mesh(t) {
1278
1233
  t && (this.m_Mesh.geometry = t);
1279
1234
  }
@@ -1281,23 +1236,23 @@ class pe {
1281
1236
  return this.m_Mesh;
1282
1237
  }
1283
1238
  setMaterials(t) {
1284
- this.disposeManagedTextures(), this.disposeCurrentMaterials(), Array.isArray(t) ? t.length === 0 ? this.m_Mesh.material = new c.MeshStandardMaterial() : t.length === 1 ? this.m_Mesh.material = t[0].clone() : this.m_Mesh.material = t.map((e) => e.clone()) : this.m_Mesh.material = t.clone(), this.m_PropertyBlocks.clear();
1239
+ this.disposeManagedTextures(), this.disposeCurrentMaterials(), Array.isArray(t) ? t.length === 0 ? this.m_Mesh.material = new o.MeshStandardMaterial() : t.length === 1 ? this.m_Mesh.material = t[0].clone() : this.m_Mesh.material = t.map((e) => e.clone()) : this.m_Mesh.material = t.clone(), this.m_PropertyBlocks.clear();
1285
1240
  }
1286
1241
  setPropertyBlock(t, e) {
1287
1242
  this.m_PropertyBlocks.set(e, t);
1288
1243
  const s = this.getMaterial(e);
1289
- s && (this.isMapCapable(s) && (t.map instanceof c.Texture ? this.applyTextureProperty(
1244
+ s && (this.isMapCapable(s) && (t.map instanceof o.Texture ? this.applyTextureProperty(
1290
1245
  s,
1291
1246
  e,
1292
1247
  t.map,
1293
1248
  t.textureST
1294
- ) : this.clearMaterialTexture(e, s)), this.isColorCapable(s) && t.color instanceof c.Color && s.color.copy(t.color));
1249
+ ) : this.clearMaterialTexture(e, s)), this.isColorCapable(s) && s.color.copy(t.color));
1295
1250
  }
1296
1251
  reset(t) {
1297
- this.m_Object3D.name = t, this.setVisibility(!0), this.m_Mesh.geometry = new c.BufferGeometry(), this.setMaterials([]);
1252
+ this.m_Object3D.name = t, this.setVisibility(!0), this.m_Mesh.geometry.dispose(), this.m_Mesh.geometry = new o.BufferGeometry(), this.setMaterials([]);
1298
1253
  }
1299
1254
  clear() {
1300
- this.m_Object3D.name = "", this.m_Mesh.geometry = new c.BufferGeometry(), this.m_PropertyBlocks.clear(), this.setVisibility(!1), this.m_Object3D.position.set(0, 0, 0), this.m_Object3D.rotation.set(0, 0, 0), this.m_Object3D.scale.set(1, 1, 1);
1255
+ this.m_Object3D.name = "", this.m_Mesh.geometry.dispose(), this.m_Mesh.geometry = new o.BufferGeometry(), this.m_PropertyBlocks.clear(), this.setVisibility(!1), this.m_Object3D.position.set(0, 0, 0), this.m_Object3D.rotation.set(0, 0, 0), this.m_Object3D.scale.set(1, 1, 1);
1301
1256
  }
1302
1257
  destroy() {
1303
1258
  this.disposeManagedTextures(), this.disposeCurrentMaterials(), this.m_Mesh.geometry && this.m_Mesh.geometry.dispose(), this.m_Object3D.parent && this.m_Object3D.parent.remove(this.m_Object3D);
@@ -1305,8 +1260,6 @@ class pe {
1305
1260
  setVisibility(t) {
1306
1261
  this.m_Visibility !== t && (this.m_Visibility = t, this.m_Object3D.visible = t);
1307
1262
  }
1308
- updateCollider() {
1309
- }
1310
1263
  getMaterial(t) {
1311
1264
  return Array.isArray(this.m_Mesh.material) ? this.m_Mesh.material[t] ?? null : this.m_Mesh.material;
1312
1265
  }
@@ -1314,20 +1267,20 @@ class pe {
1314
1267
  return "map" in t;
1315
1268
  }
1316
1269
  isColorCapable(t) {
1317
- return "color" in t && t.color instanceof c.Color;
1270
+ return "color" in t && t.color instanceof o.Color;
1318
1271
  }
1319
1272
  getSTKey(t) {
1320
1273
  return t ? `${t.x.toFixed(6)},${t.y.toFixed(6)},${t.z.toFixed(6)},${t.w.toFixed(6)}` : "1,1,0,0";
1321
1274
  }
1322
1275
  applyTextureProperty(t, e, s, i) {
1323
- const n = this.getSTKey(i), o = this.m_MaterialTextures.get(e);
1324
- if (o && o.source === s && o.stKey === n) {
1325
- t.map !== o.texture && (t.map = o.texture, t.needsUpdate = !0);
1276
+ const n = this.getSTKey(i), h = this.m_MaterialTextures.get(e);
1277
+ if (h && h.source === s && h.stKey === n) {
1278
+ t.map !== h.texture && (t.map = h.texture, t.needsUpdate = !0);
1326
1279
  return;
1327
1280
  }
1328
1281
  this.clearManagedTexture(e);
1329
1282
  const a = s.clone();
1330
- a.needsUpdate = !0, i && (a.repeat.set(i.x, i.y), a.offset.set(i.z, i.w), a.wrapS = c.RepeatWrapping, a.wrapT = c.RepeatWrapping), t.map = a, t.needsUpdate = !0, this.m_MaterialTextures.set(e, {
1283
+ a.needsUpdate = !0, i && (a.repeat.set(i.x, i.y), a.offset.set(i.z, i.w), a.wrapS = o.RepeatWrapping, a.wrapT = o.RepeatWrapping), t.map = a, t.needsUpdate = !0, this.m_MaterialTextures.set(e, {
1331
1284
  source: s,
1332
1285
  texture: a,
1333
1286
  stKey: n
@@ -1351,20 +1304,20 @@ class pe {
1351
1304
  e.dispose();
1352
1305
  }
1353
1306
  }
1354
- class xe {
1307
+ class ue {
1355
1308
  constructor(t, e, s = !1) {
1356
- this.m_Stack = [], this.m_SharedData = null, this.m_MeshFactory = t, this.m_Pattern = e, (this.m_UseSharedData = s) && (this.m_SharedData = new Zt(this.m_MeshFactory.get(), this.m_Pattern), this.m_SharedData.updateMesh());
1309
+ this.m_Stack = [], this.m_SharedData = null, this.m_MeshFactory = t, this.m_Pattern = e, (this.m_UseSharedData = s) && (this.m_SharedData = new zt(this.m_MeshFactory.get(), this.m_Pattern), this.m_SharedData.updateMesh());
1357
1310
  }
1358
1311
  get() {
1359
- return this.m_UseSharedData ? this.m_SharedData : this.m_Stack.length > 0 ? this.m_Stack.pop() : new Zt(this.m_MeshFactory.get(), this.m_Pattern);
1312
+ return this.m_UseSharedData ? this.m_SharedData : this.m_Stack.length > 0 ? this.m_Stack.pop() : new zt(this.m_MeshFactory.get(), this.m_Pattern);
1360
1313
  }
1361
1314
  free(t) {
1362
1315
  if (this.m_UseSharedData) throw new Error("Not implemented");
1363
1316
  this.m_Stack.push(t);
1364
1317
  }
1365
1318
  }
1366
- var wt = /* @__PURE__ */ ((r) => (r[r.Next = 0] = "Next", r[r.Back = 1] = "Back", r))(wt || {}), Me = /* @__PURE__ */ ((r) => (r[r.Surface = 0] = "Surface", r[r.Edge = 1] = "Edge", r))(Me || {}), Ce = /* @__PURE__ */ ((r) => (r[r.Constant = 0] = "Constant", r[r.RandomBetweenTwoConstants = 1] = "RandomBetweenTwoConstants", r[r.Curve = 2] = "Curve", r[r.RandomBetweenTwoCurves = 3] = "RandomBetweenTwoCurves", r))(Ce || {}), we = /* @__PURE__ */ ((r) => (r[r.PaperIndexTime = 0] = "PaperIndexTime", r[r.TurnIndexTime = 1] = "TurnIndexTime", r))(we || {});
1367
- class ye {
1319
+ var yt = /* @__PURE__ */ ((r) => (r[r.Next = 0] = "Next", r[r.Back = 1] = "Back", r))(yt || {}), me = /* @__PURE__ */ ((r) => (r[r.Constant = 0] = "Constant", r[r.RandomBetweenTwoConstants = 1] = "RandomBetweenTwoConstants", r[r.Curve = 2] = "Curve", r[r.RandomBetweenTwoCurves = 3] = "RandomBetweenTwoCurves", r))(me || {}), _e = /* @__PURE__ */ ((r) => (r[r.PaperIndexTime = 0] = "PaperIndexTime", r[r.TurnIndexTime = 1] = "TurnIndexTime", r))(_e || {});
1320
+ class de {
1368
1321
  constructor(t) {
1369
1322
  this.keys = t ? t.map((e) => ({ time: e.time, value: e.value })) : [];
1370
1323
  }
@@ -1386,16 +1339,10 @@ class ye {
1386
1339
  return e[s - 1].value;
1387
1340
  }
1388
1341
  }
1389
- function rt(r, t, e) {
1390
- return Math.max(t, Math.min(e, r));
1391
- }
1392
- function Pe(r, t, e) {
1393
- return r === t ? 0 : rt((e - r) / (t - r), 0, 1);
1394
- }
1395
- function Ut(r, t) {
1342
+ function At(r, t) {
1396
1343
  return r + Math.random() * (t - r);
1397
1344
  }
1398
- class ot {
1345
+ class at {
1399
1346
  constructor(t, e) {
1400
1347
  this.m_Mode = 0, this.m_Constant = 0, this.m_ConstantMin = 0, this.m_ConstantMax = 0, this.m_Curve = null, this.m_CurveMin = null, this.m_CurveMax = null, this.m_CurveTimeMode = 0, t !== void 0 && (e === void 0 ? (this.m_Constant = t, this.m_ConstantMin = t, this.m_ConstantMax = t, this.m_Curve = null, this.m_CurveMin = null, this.m_CurveMax = null, this.m_Mode = 0, this.m_CurveTimeMode = 0) : (this.m_Constant = 0, this.m_ConstantMin = t, this.m_ConstantMax = e, this.m_Curve = null, this.m_CurveMin = null, this.m_CurveMax = null, this.m_Mode = 1, this.m_CurveTimeMode = 0));
1401
1348
  }
@@ -1450,12 +1397,12 @@ class ot {
1450
1397
  }
1451
1398
  /** A value based on a curve. */
1452
1399
  static fromCurve(t, e) {
1453
- const s = new ot();
1400
+ const s = new at();
1454
1401
  return s.m_Constant = 0, s.m_ConstantMin = 0, s.m_ConstantMax = 0, s.m_Curve = t, s.m_CurveMin = null, s.m_CurveMax = null, s.m_Mode = 2, s.m_CurveTimeMode = e, s;
1455
1402
  }
1456
1403
  /** A random value generated between two curves. */
1457
1404
  static fromCurveRange(t, e, s) {
1458
- const i = new ot();
1405
+ const i = new at();
1459
1406
  return i.m_Constant = 0, i.m_ConstantMin = 0, i.m_ConstantMax = 0, i.m_Curve = null, i.m_CurveMin = t, i.m_CurveMax = e, i.m_Mode = 3, i.m_CurveTimeMode = s, i;
1460
1407
  }
1461
1408
  // ── Internal API ────────────────────────────────────────────────────────
@@ -1463,12 +1410,12 @@ class ot {
1463
1410
  getValue(t, e) {
1464
1411
  if (this.m_Mode === 0) return this.m_Constant;
1465
1412
  if (this.m_Mode === 1)
1466
- return Ut(this.m_ConstantMin, this.m_ConstantMax);
1413
+ return At(this.m_ConstantMin, this.m_ConstantMax);
1467
1414
  const s = this.m_CurveTimeMode === 0 ? t : e;
1468
1415
  if (this.m_Mode === 2)
1469
1416
  return this.m_Curve.evaluate(s);
1470
1417
  if (this.m_Mode === 3)
1471
- return Ut(
1418
+ return At(
1472
1419
  this.m_CurveMin.evaluate(s),
1473
1420
  this.m_CurveMax.evaluate(s)
1474
1421
  );
@@ -1476,31 +1423,31 @@ class ot {
1476
1423
  }
1477
1424
  /** @internal */
1478
1425
  clampValues(t, e) {
1479
- return this.m_Constant = rt(this.m_Constant, t, e), this.m_ConstantMin = rt(this.m_ConstantMin, t, e), this.m_ConstantMax = rt(this.m_ConstantMax, t, e), this.m_Curve = this.clampCurve(this.m_Curve, t, e), this.m_CurveMin = this.clampCurve(this.m_CurveMin, t, e), this.m_CurveMax = this.clampCurve(this.m_CurveMax, t, e), this;
1426
+ return this.m_Constant = H(this.m_Constant, t, e), this.m_ConstantMin = H(this.m_ConstantMin, t, e), this.m_ConstantMax = H(this.m_ConstantMax, t, e), this.m_Curve = this.clampCurve(this.m_Curve, t, e), this.m_CurveMin = this.clampCurve(this.m_CurveMin, t, e), this.m_CurveMax = this.clampCurve(this.m_CurveMax, t, e), this;
1480
1427
  }
1481
1428
  clampCurve(t, e, s) {
1482
1429
  if (this.m_Curve === null || t === null) return null;
1483
- const i = t.keys.map((h) => ({ time: h.time, value: h.value })), n = i.length;
1484
- let o = 1 / 0, a = -1 / 0;
1485
- for (let h = 0; h < n; h++) {
1486
- const m = i[h].time;
1487
- o = Math.min(o, m), a = Math.max(a, m);
1430
+ const i = t.keys.map((c) => ({ time: c.time, value: c.value })), n = i.length;
1431
+ let h = 1 / 0, a = -1 / 0;
1432
+ for (let c = 0; c < n; c++) {
1433
+ const u = i[c].time;
1434
+ h = Math.min(h, u), a = Math.max(a, u);
1488
1435
  }
1489
- for (let h = 0; h < n; h++) {
1490
- let m = i[h].time, l = i[h].value;
1491
- m = Pe(o, a, m), l = rt(l, e, s), i[h].time = m, i[h].value = l;
1436
+ for (let c = 0; c < n; c++) {
1437
+ let u = i[c].time, l = i[c].value;
1438
+ u = Q(h, a, u), l = H(l, e, s), i[c].time = u, i[c].value = l;
1492
1439
  }
1493
- return new ye(i);
1440
+ return new de(i);
1494
1441
  }
1495
1442
  // ── Value-type clone ────────────────────────────────────────────────────
1496
1443
  clone() {
1497
- const t = new ot();
1444
+ const t = new at();
1498
1445
  return t.m_Mode = this.m_Mode, t.m_Constant = this.m_Constant, t.m_ConstantMin = this.m_ConstantMin, t.m_ConstantMax = this.m_ConstantMax, t.m_Curve = this.m_Curve, t.m_CurveMin = this.m_CurveMin, t.m_CurveMax = this.m_CurveMax, t.m_CurveTimeMode = this.m_CurveTimeMode, t;
1499
1446
  }
1500
1447
  }
1501
- const R = class R {
1448
+ const V = class V {
1502
1449
  constructor() {
1503
- this.m_Mode = 0, this.m_Twist = new ot(), this.m_Bend = new ot(1), this.m_Duration = new ot(0.5);
1450
+ this.m_Mode = mt.Surface, this.m_Twist = new at(), this.m_Bend = new at(1), this.m_Duration = new at(0.5);
1504
1451
  }
1505
1452
  // ── Properties ──────────────────────────────────────────────────────────
1506
1453
  get mode() {
@@ -1514,8 +1461,8 @@ const R = class R {
1514
1461
  }
1515
1462
  set twist(t) {
1516
1463
  this.m_Twist = t.clampValues(
1517
- R.kMinTwist,
1518
- R.kMaxTwist
1464
+ V.kMinTwist,
1465
+ V.kMaxTwist
1519
1466
  );
1520
1467
  }
1521
1468
  get bend() {
@@ -1523,8 +1470,8 @@ const R = class R {
1523
1470
  }
1524
1471
  set bend(t) {
1525
1472
  this.m_Bend = t.clampValues(
1526
- R.kMinBend,
1527
- R.kMaxBend
1473
+ V.kMinBend,
1474
+ V.kMaxBend
1528
1475
  );
1529
1476
  }
1530
1477
  get duration() {
@@ -1532,8 +1479,8 @@ const R = class R {
1532
1479
  }
1533
1480
  set duration(t) {
1534
1481
  this.m_Duration = t.clampValues(
1535
- R.kMinDuration,
1536
- R.kMaxDuration
1482
+ V.kMinDuration,
1483
+ V.kMaxDuration
1537
1484
  );
1538
1485
  }
1539
1486
  // ── Internal API ────────────────────────────────────────────────────────
@@ -1543,70 +1490,71 @@ const R = class R {
1543
1490
  }
1544
1491
  /** @internal */
1545
1492
  getBendValue(t, e) {
1546
- return rt(
1493
+ return H(
1547
1494
  this.m_Bend.getValue(t, e),
1548
- R.kMinBend,
1549
- R.kMaxBend
1495
+ V.kMinBend,
1496
+ V.kMaxBend
1550
1497
  );
1551
1498
  }
1552
1499
  /** @internal */
1553
1500
  getDurationValue(t, e) {
1554
- return rt(
1501
+ return H(
1555
1502
  this.m_Duration.getValue(t, e),
1556
- R.kMinDuration,
1557
- R.kMaxDuration
1503
+ V.kMinDuration,
1504
+ V.kMaxDuration
1558
1505
  );
1559
1506
  }
1560
1507
  /** @internal */
1561
1508
  getTwistValue(t, e) {
1562
- return rt(
1509
+ return H(
1563
1510
  this.m_Twist.getValue(t, e),
1564
- R.kMinTwist,
1565
- R.kMaxTwist
1511
+ V.kMinTwist,
1512
+ V.kMaxTwist
1566
1513
  );
1567
1514
  }
1568
1515
  };
1569
- R.kMinTwist = -1, R.kMaxTwist = 1, R.kMinBend = 0, R.kMaxBend = 1, R.kMinDuration = 0, R.kMaxDuration = 5;
1570
- let Lt = R, Xe = class extends Error {
1516
+ V.kMinTwist = -1, V.kMaxTwist = 1, V.kMinBend = 0, V.kMaxBend = 1, V.kMinDuration = 0, V.kMaxDuration = 5;
1517
+ let Ht = V;
1518
+ class fe extends Error {
1571
1519
  constructor() {
1572
1520
  super(
1573
1521
  "The book's height exceeds the maximum limit. Please consider using thinner paper, increasing the width of the paper, or reducing the number of pages."
1574
1522
  );
1575
1523
  }
1576
- };
1577
- const at = class at extends c.Group {
1524
+ }
1525
+ const W = class W extends o.Group {
1578
1526
  // ── Constructor ────────────────────────────────────────────────────────
1579
1527
  constructor(t) {
1580
- super(), this.m_Content = null, this.m_Binding = null, this.m_InitialOpenProgress = 0, this.m_BuildOnAwake = !0, this.m_CastShadows = !0, this.m_AlignToGround = !1, this.m_HideBinder = !1, this.m_CreateColliders = !1, this.m_ReduceShadows = !1, this.m_ReduceSubMeshes = !1, this.m_ReduceOverdraw = !1, this.m_CoverPaperSetup = new nt({
1581
- color: new c.Color(1, 0, 0),
1528
+ super(), this.m_Content = null, this.m_Binding = null, this.m_InitialOpenProgress = 0, this.m_BuildOnAwake = !0, this.m_CastShadows = !0, this.m_AlignToGround = !1, this.m_HideBinder = !1, this.m_ReduceShadows = !1, this.m_ReduceSubMeshes = !1, this.m_ReduceOverdraw = !1, this.m_CoverPaperSetup = new rt({
1529
+ color: new o.Color(1, 0, 0),
1582
1530
  width: 2.1,
1583
1531
  height: 3.1,
1584
1532
  thickness: 0.04,
1585
1533
  stiffness: 0.5
1586
- }), this.m_PagePaperSetup = new nt({
1587
- color: new c.Color(1, 1, 1),
1534
+ }), this.m_PagePaperSetup = new rt({
1535
+ color: new o.Color(1, 1, 1),
1588
1536
  width: 2,
1589
1537
  height: 3,
1590
1538
  thickness: 0.02,
1591
1539
  stiffness: 0.2
1592
- }), this.m_Root = null, this.m_IsBuilt = !1, this.m_HasCover = !1, this.m_RendererFactory = null, this.m_MeshFactory = null, this.m_Bound = null, this.m_Papers = [], this.m_SelectedPaper = null, this.m_Direction = X.LeftToRight, this.m_AutoTurnQueue = [], this.m_AutoTurnTimer = 0, this.m_AutoTurningEndTime = -1, this.m_CurrentTime = 0, this.m_CoverPaperCount = 0, this.m_PagePaperCount = 0, this.m_TotalThickness = 0, this.m_MinPaperWidth = 0, this.m_MinPaperHeight = 0, this.m_MinPaperThickness = 0, this.m_MaxPaperThickness = 0, this.m_RendererIds = [], this.m_WasIdle = !1, this.m_ContentDirty = !1, this.m_StructuralDirty = !1, this.m_AppliedDirection = void 0, t && (t.content && (this.m_Content = t.content), t.binding && (this.m_Binding = t.binding), t.initialOpenProgress !== void 0 && (this.m_InitialOpenProgress = c.MathUtils.clamp(t.initialOpenProgress, 0, 1)), t.buildOnAwake !== void 0 && (this.m_BuildOnAwake = t.buildOnAwake), t.castShadows !== void 0 && (this.m_CastShadows = t.castShadows), t.alignToGround !== void 0 && (this.m_AlignToGround = t.alignToGround), t.hideBinder !== void 0 && (this.m_HideBinder = t.hideBinder), t.createColliders !== void 0 && (this.m_CreateColliders = t.createColliders), t.reduceShadows !== void 0 && (this.m_ReduceShadows = t.reduceShadows), t.reduceSubMeshes !== void 0 && (this.m_ReduceSubMeshes = t.reduceSubMeshes), t.reduceOverdraw !== void 0 && (this.m_ReduceOverdraw = t.reduceOverdraw), t.coverPaperSetup && (this.m_CoverPaperSetup = new nt({
1593
- color: t.coverPaperSetup.color ?? new c.Color(1, 0, 0),
1540
+ }), this.m_Root = null, this.m_IsBuilt = !1, this.m_HasCover = !1, this.m_RendererFactory = null, this.m_MeshFactory = null, this.m_Bound = null, this.m_Papers = [], this.m_SelectedPaper = null, this.m_Direction = j.LeftToRight, this.m_AutoTurnQueue = [], this.m_AutoTurnTimer = 0, this.m_AutoTurningEndTime = -1, this.m_CurrentTime = 0, this.m_CoverPaperCount = 0, this.m_PagePaperCount = 0, this.m_TotalThickness = 0, this.m_MinPaperWidth = 0, this.m_MinPaperHeight = 0, this.m_MinPaperThickness = 0, this.m_MaxPaperThickness = 0, this.m_RendererIds = [], this.m_WasIdle = !1, this.m_ContentDirty = !1, this.m_StructuralDirty = !1, this.m_AppliedDirection = void 0, this._frontPapersCache = null, t && (t.content && (this.m_Content = t.content), t.binding && (this.m_Binding = t.binding), t.initialOpenProgress !== void 0 && (this.m_InitialOpenProgress = o.MathUtils.clamp(t.initialOpenProgress, 0, 1)), t.buildOnAwake !== void 0 && (this.m_BuildOnAwake = t.buildOnAwake), t.castShadows !== void 0 && (this.m_CastShadows = t.castShadows), t.alignToGround !== void 0 && (this.m_AlignToGround = t.alignToGround), t.hideBinder !== void 0 && (this.m_HideBinder = t.hideBinder), t.reduceShadows !== void 0 && (this.m_ReduceShadows = t.reduceShadows), t.reduceSubMeshes !== void 0 && (this.m_ReduceSubMeshes = t.reduceSubMeshes), t.reduceOverdraw !== void 0 && (this.m_ReduceOverdraw = t.reduceOverdraw), t.coverPaperSetup && (this.m_CoverPaperSetup = new rt({
1541
+ color: t.coverPaperSetup.color ?? new o.Color(1, 0, 0),
1594
1542
  width: t.coverPaperSetup.width ?? 2.1,
1595
1543
  height: t.coverPaperSetup.height ?? 3.1,
1596
1544
  thickness: t.coverPaperSetup.thickness ?? 0.04,
1597
1545
  stiffness: t.coverPaperSetup.stiffness ?? 0.5,
1598
1546
  material: t.coverPaperSetup.material ?? null
1599
- })), t.pagePaperSetup && (this.m_PagePaperSetup = new nt({
1600
- color: t.pagePaperSetup.color ?? new c.Color(1, 1, 1),
1547
+ })), t.pagePaperSetup && (this.m_PagePaperSetup = new rt({
1548
+ color: t.pagePaperSetup.color ?? new o.Color(1, 1, 1),
1601
1549
  width: t.pagePaperSetup.width ?? 2,
1602
1550
  height: t.pagePaperSetup.height ?? 3,
1603
1551
  thickness: t.pagePaperSetup.thickness ?? 0.02,
1604
1552
  stiffness: t.pagePaperSetup.stiffness ?? 0.2,
1605
1553
  material: t.pagePaperSetup.material ?? null
1606
- }))), at.s_Instances.add(this);
1554
+ }))), W.s_Instances.add(this), W.s_InstancesArray = null;
1607
1555
  }
1608
1556
  static get instances() {
1609
- return [...at.s_Instances];
1557
+ return W.s_InstancesArray === null && (W.s_InstancesArray = [...W.s_Instances]), W.s_InstancesArray;
1610
1558
  }
1611
1559
  // ── Internal accessors ─────────────────────────────────────────────────
1612
1560
  get minPaperWidth() {
@@ -1671,13 +1619,13 @@ const at = class at extends c.Group {
1671
1619
  return this.m_CoverPaperSetup;
1672
1620
  }
1673
1621
  set coverPaperSetup(t) {
1674
- const e = this.m_CoverPaperSetup, s = t.width ?? e.width, i = t.height ?? e.height, n = t.thickness ?? e.thickness, o = t.stiffness ?? e.stiffness;
1675
- e.width === s && e.height === i && e.thickness === n && e.stiffness === o || (this.m_CoverPaperSetup = new nt({
1622
+ const e = this.m_CoverPaperSetup, s = t.width ?? e.width, i = t.height ?? e.height, n = t.thickness ?? e.thickness, h = t.stiffness ?? e.stiffness;
1623
+ e.width === s && e.height === i && e.thickness === n && e.stiffness === h || (this.m_CoverPaperSetup = new rt({
1676
1624
  color: t.color ?? e.color,
1677
1625
  width: s,
1678
1626
  height: i,
1679
1627
  thickness: n,
1680
- stiffness: o,
1628
+ stiffness: h,
1681
1629
  material: t.material !== void 0 ? t.material : e.material
1682
1630
  }), this.m_StructuralDirty = !0);
1683
1631
  }
@@ -1685,13 +1633,13 @@ const at = class at extends c.Group {
1685
1633
  return this.m_PagePaperSetup;
1686
1634
  }
1687
1635
  set pagePaperSetup(t) {
1688
- const e = this.m_PagePaperSetup, s = t.width ?? e.width, i = t.height ?? e.height, n = t.thickness ?? e.thickness, o = t.stiffness ?? e.stiffness;
1689
- e.width === s && e.height === i && e.thickness === n && e.stiffness === o || (this.m_PagePaperSetup = new nt({
1636
+ const e = this.m_PagePaperSetup, s = t.width ?? e.width, i = t.height ?? e.height, n = t.thickness ?? e.thickness, h = t.stiffness ?? e.stiffness;
1637
+ e.width === s && e.height === i && e.thickness === n && e.stiffness === h || (this.m_PagePaperSetup = new rt({
1690
1638
  color: t.color ?? e.color,
1691
1639
  width: s,
1692
1640
  height: i,
1693
1641
  thickness: n,
1694
- stiffness: o,
1642
+ stiffness: h,
1695
1643
  material: t.material !== void 0 ? t.material : e.material
1696
1644
  }), this.m_StructuralDirty = !0);
1697
1645
  }
@@ -1724,7 +1672,7 @@ const at = class at extends c.Group {
1724
1672
  return this.m_InitialOpenProgress;
1725
1673
  }
1726
1674
  set initialOpenProgress(t) {
1727
- this.m_InitialOpenProgress = c.MathUtils.clamp(t, 0, 1);
1675
+ this.m_InitialOpenProgress = o.MathUtils.clamp(t, 0, 1);
1728
1676
  }
1729
1677
  get isBuilt() {
1730
1678
  return this.m_IsBuilt;
@@ -1758,7 +1706,7 @@ const at = class at extends c.Group {
1758
1706
  get autoTurningEndTime() {
1759
1707
  return this.m_AutoTurningEndTime;
1760
1708
  }
1761
- /** Current open progress (01), read from actual paper positions. */
1709
+ /** Current open progress (0-1), read from actual paper positions. */
1762
1710
  get openProgress() {
1763
1711
  return this.getCurrentOpenProgress();
1764
1712
  }
@@ -1773,58 +1721,71 @@ const at = class at extends c.Group {
1773
1721
  }
1774
1722
  for (const s of e)
1775
1723
  if (!s.isFalling && s.startTurning(t))
1776
- return this.m_SelectedPaper = s, !0;
1724
+ return this.m_SelectedPaper = s, this._frontPapersCache = null, !0;
1777
1725
  return !1;
1778
1726
  }
1779
1727
  updateTurning(t) {
1780
1728
  this.m_IsBuilt && this.m_SelectedPaper !== null && this.m_SelectedPaper.updateTurning(t);
1781
1729
  }
1782
1730
  stopTurning() {
1783
- this.m_IsBuilt && this.m_SelectedPaper !== null && (this.m_SelectedPaper.stopTurning(), this.m_SelectedPaper = null);
1731
+ this.m_IsBuilt && this.m_SelectedPaper !== null && (this.m_SelectedPaper.stopTurning(), this.m_SelectedPaper = null, this._frontPapersCache = null);
1784
1732
  }
1785
1733
  getActivePaperSideIndices(t) {
1786
- if (t.length = 0, !this.m_IsBuilt) return;
1787
- const e = this.m_Content.direction === X.RightToLeft, s = this.m_Papers.length, i = (n, o) => {
1734
+ if (t.clear(), !this.m_IsBuilt) return;
1735
+ const e = this.m_Content.direction === j.RightToLeft, s = this.m_Papers.length, i = (n, h) => {
1788
1736
  let a = n * 2;
1789
- o && a++, e && (a = s * 2 - a - 1), t.includes(a) || t.push(a);
1737
+ h && a++, e && (a = s * 2 - a - 1), t.add(a);
1790
1738
  };
1791
1739
  for (let n = 0; n < s; n++) {
1792
- const o = this.m_Papers[n];
1793
- if (o.isFalling || o.isTurning)
1740
+ const h = this.m_Papers[n];
1741
+ if (h.isFalling || h.isTurning)
1794
1742
  n > 0 && i(n - 1, !0), i(n, !1), i(n, !0), n < s - 1 && i(n + 1, !1);
1795
- else if (o.isOnRightStack) {
1743
+ else if (h.isOnRightStack) {
1796
1744
  n > 0 && i(n - 1, !0), i(n, !1);
1797
1745
  break;
1798
1746
  }
1799
1747
  }
1800
- t.length === 0 && i(this.m_Papers.length - 1, !0), e && t.reverse();
1748
+ t.size === 0 && i(this.m_Papers.length - 1, !0);
1801
1749
  }
1750
+ /**
1751
+ * Sets the book's open progress to a value between 0 (fully closed) and 1 (fully open).
1752
+ * This cancels any pending auto turns and immediately moves all papers to match
1753
+ * the requested progress.
1754
+ */
1802
1755
  setOpenProgress(t) {
1803
1756
  this.cancelPendingAutoTurns(), this.m_Content.direction % 2 !== 0 && (t = 1 - t);
1804
- const e = this.m_Papers.length, s = Math.round(c.MathUtils.lerp(0, e, t));
1757
+ const e = this.m_Papers.length, s = Math.round(o.MathUtils.lerp(0, e, t));
1805
1758
  for (let i = 0; i < e; i++) {
1806
1759
  const n = i >= s;
1807
1760
  this.m_Papers[i].restState(n);
1808
1761
  }
1809
1762
  for (let i = 0; i < e; i++)
1810
1763
  this.m_Papers[i].restMesh();
1811
- this.m_WasIdle = !1;
1764
+ this.m_WasIdle = !1, this._frontPapersCache = null;
1812
1765
  }
1813
1766
  setOpenProgressByIndex(t) {
1814
1767
  const e = this.m_Content.convertPaperSideIndexToOpenProgress(t);
1815
1768
  this.setOpenProgress(e);
1816
1769
  }
1817
1770
  // ── Auto Turning ──────────────────────────────────────────────────────
1771
+ /**
1772
+ * Starts auto-turning pages in the given direction.
1773
+ * @param direction - Which direction to turn (Next or Back)
1774
+ * @param settings - Turn animation settings (twist, bend, duration)
1775
+ * @param turnCount - Number of pages to turn
1776
+ * @param delayPerTurn - Delay between consecutive turns (number in seconds, or AutoTurnSetting)
1777
+ * @returns true if at least one turn was queued
1778
+ */
1818
1779
  startAutoTurning(t, e, s = 1, i = 0) {
1819
1780
  if (!this.m_IsBuilt) return !1;
1820
1781
  this.cancelPendingAutoTurns();
1821
- const n = typeof i == "number" ? new ot(i) : i;
1782
+ const n = typeof i == "number" ? new at(i) : i;
1822
1783
  if (s = Math.min(s, this.getMaxAutoTurnCount(t)), s === 0) return !1;
1823
- for (let o = 0; o < s && this.canAutoTurn(t); o++) {
1824
- const a = o / (s - 1 || 1), h = this.getAutoTurnPaperIndexTime(t), m = o > 0 ? n.getValue(h, a) : 0, l = e.getModeValue(), d = e.getTwistValue(h, a), g = e.getBendValue(h, a), _ = e.getDurationValue(h, a);
1825
- this.m_AutoTurnQueue.push({ direction: t, mode: l, twist: d, bend: g, duration: _, delay: m });
1784
+ for (let h = 0; h < s && this.canAutoTurn(t); h++) {
1785
+ const a = h / (s - 1 || 1), c = this.getAutoTurnPaperIndexTime(t), u = h > 0 ? n.getValue(c, a) : 0, l = e.getModeValue(), _ = e.getTwistValue(c, a), d = e.getBendValue(c, a), f = e.getDurationValue(c, a);
1786
+ this.m_AutoTurnQueue.push({ direction: t, mode: l, twist: _, bend: d, duration: f, delay: u });
1826
1787
  }
1827
- return this.m_AutoTurnTimer = 0, !0;
1788
+ return this.m_AutoTurnTimer = 0, this._frontPapersCache = null, !0;
1828
1789
  }
1829
1790
  cancelPendingAutoTurns() {
1830
1791
  this.m_AutoTurnQueue.length = 0;
@@ -1844,13 +1805,13 @@ const at = class at extends c.Group {
1844
1805
  s.startAutoTurning(e.mode, e.twist, e.bend, e.duration), this.m_AutoTurningEndTime = Math.max(
1845
1806
  this.m_AutoTurningEndTime,
1846
1807
  this.m_CurrentTime + e.duration
1847
- ), this.m_AutoTurnQueue.shift(), this.m_AutoTurnQueue.length > 0 && (this.m_AutoTurnTimer = this.m_AutoTurnQueue[0].delay);
1808
+ ), this.m_AutoTurnQueue.shift(), this._frontPapersCache = null, this.m_AutoTurnQueue.length > 0 && (this.m_AutoTurnTimer = this.m_AutoTurnQueue[0].delay);
1848
1809
  }
1849
1810
  getAutoTurnPaper(t) {
1850
1811
  if (this.isTurning) return null;
1851
1812
  const e = this.getFrontPapers();
1852
1813
  if (e.length > 0) {
1853
- const s = t === wt.Next, i = e[s ? e.length - 1 : 0];
1814
+ const s = t === yt.Next, i = e[s ? e.length - 1 : 0];
1854
1815
  if (!i.isTurning && !i.isFalling && s === i.isOnRightStack)
1855
1816
  return i;
1856
1817
  }
@@ -1860,7 +1821,7 @@ const at = class at extends c.Group {
1860
1821
  const e = this.getAutoTurnPaper(t);
1861
1822
  if (e === null) return 0;
1862
1823
  let s = 1;
1863
- return t === wt.Next ? s += this.m_Papers.length - e.index - 1 : s += e.index, s;
1824
+ return t === yt.Next ? s += this.m_Papers.length - e.index - 1 : s += e.index, s;
1864
1825
  }
1865
1826
  canAutoTurn(t) {
1866
1827
  return this.getAutoTurnPaper(t) !== null;
@@ -1876,11 +1837,12 @@ const at = class at extends c.Group {
1876
1837
  */
1877
1838
  init() {
1878
1839
  var t;
1879
- at.s_Instances.add(this), this.hardClear(), this.m_BuildOnAwake && (this.build(), this.m_ContentDirty = !1, this.m_StructuralDirty = !1, this.m_AppliedDirection = (t = this.m_Content) == null ? void 0 : t.direction);
1840
+ W.s_Instances.add(this), W.s_InstancesArray = null, this.hardClear(), this.m_BuildOnAwake && (this.build(), this.m_ContentDirty = !1, this.m_StructuralDirty = !1, this.m_AppliedDirection = (t = this.m_Content) == null ? void 0 : t.direction);
1880
1841
  }
1881
1842
  /**
1882
- * Call every frame with delta time.
1843
+ * Call every frame with delta time in seconds.
1883
1844
  * Equivalent to Unity's LateUpdate.
1845
+ * @param dt - Delta time in seconds since the last frame
1884
1846
  */
1885
1847
  update(t) {
1886
1848
  var e;
@@ -1902,64 +1864,79 @@ const at = class at extends c.Group {
1902
1864
  this.m_WasIdle = this.isIdle;
1903
1865
  for (const s of this.m_Papers)
1904
1866
  s.isFalling && s.updateFalling(t);
1905
- this.updateLivePages(), this.m_Bound.onLateUpdate();
1867
+ this._frontPapersCache = null, this.updateLivePages(), this.m_Bound.onLateUpdate();
1906
1868
  }
1907
1869
  }
1870
+ /**
1871
+ * Dispose the book and release all resources.
1872
+ * MANDATORY: You must call dispose() when removing a Book to prevent memory leaks.
1873
+ * The Book holds a reference in the static `s_Instances` set; without dispose(),
1874
+ * it will never be garbage collected.
1875
+ */
1908
1876
  dispose() {
1909
- at.s_Instances.delete(this), this.hardClear();
1877
+ W.s_Instances.delete(this), W.s_InstancesArray = null, this.hardClear();
1910
1878
  }
1911
1879
  // ── Build ─────────────────────────────────────────────────────────────
1912
1880
  build() {
1881
+ var B;
1913
1882
  if (this.clear(), this.m_Content === null || this.m_Content.isEmpty || this.m_Binding === null) return;
1914
- if (this.m_MeshFactory === null && (this.m_MeshFactory = new _e()), this.m_RendererFactory === null) {
1915
- const C = new c.Object3D();
1916
- C.name = "Root", this.add(C), this.m_Root = C, this.m_RendererFactory = new fe(this.m_Root);
1883
+ if (this.m_MeshFactory === null && (this.m_MeshFactory = new ae()), this.m_RendererFactory === null) {
1884
+ const w = new o.Object3D();
1885
+ w.name = "Root", this.add(w), this.m_Root = w, this.m_RendererFactory = new oe(this.m_Root);
1917
1886
  }
1918
- this.m_RendererFactory.createColliders = this.m_CreateColliders, this.m_Direction = this.m_Content.direction;
1887
+ this.m_Direction = this.m_Content.direction;
1919
1888
  const t = this.m_Direction > 1 ? Math.PI / 2 : 0;
1920
1889
  this.m_Root.rotation.set(0, t, 0), this.m_CoverPaperSetup.bookDirection = this.m_Content.direction, this.m_PagePaperSetup.bookDirection = this.m_Content.direction, this.m_PagePaperSetup.height < this.m_CoverPaperSetup.height ? (this.m_CoverPaperSetup.margin = 0, this.m_PagePaperSetup.margin = (this.m_CoverPaperSetup.height - this.m_PagePaperSetup.height) / 2) : (this.m_CoverPaperSetup.margin = (this.m_PagePaperSetup.height - this.m_CoverPaperSetup.height) / 2, this.m_PagePaperSetup.margin = 0);
1921
- const e = new At(this.m_CoverPaperSetup), s = new At(this.m_PagePaperSetup);
1890
+ const e = new bt(this.m_CoverPaperSetup), s = new bt(this.m_PagePaperSetup);
1922
1891
  this.m_Content.init(this);
1923
- let i = this.m_Content.coverContents, n = this.m_Content.pageContents, o = this.m_InitialOpenProgress;
1924
- this.m_Content.direction % 2 !== 0 && (i = [...i].reverse(), n = [...n].reverse(), o = 1 - o), this.m_HasCover = i.length > 0, this.m_CoverPaperCount = Math.floor(i.length / 2), this.m_PagePaperCount = Math.floor(n.length / 2);
1925
- const a = this.m_CoverPaperCount + this.m_PagePaperCount, h = Math.floor(i.length / 4);
1926
- let m = 0, l = 0, d = 0;
1892
+ let i = this.m_Content.coverContents, n = this.m_Content.pageContents, h = this.m_InitialOpenProgress;
1893
+ this.m_Content.direction % 2 !== 0 && (i = [...i].reverse(), n = [...n].reverse(), h = 1 - h), this.m_HasCover = i.length > 0, this.m_CoverPaperCount = Math.floor(i.length / 2), this.m_PagePaperCount = Math.floor(n.length / 2);
1894
+ const a = this.m_CoverPaperCount + this.m_PagePaperCount, c = Math.floor(i.length / 4);
1895
+ let u = 0, l = 0, _ = 0;
1927
1896
  this.m_Papers = new Array(a);
1928
- for (let C = 0; C < a; C++) {
1929
- const D = this.m_HasCover && (C < h || C >= a - h), L = this.m_RendererFactory.get("Paper"), v = this.m_Papers[C] = new me(D, C, this, L);
1930
- v.renderer.castShadows = this.m_CastShadows, C < Math.round(c.MathUtils.lerp(0, a, o)) && (v.transform.scale.set(-1, 1, 1), v.setTime(1)), D ? (v.setContentData(i[l++], i[l++], C > h), v.setMaterialData(e), v.setPaperSetup(this.m_CoverPaperSetup)) : (v.setContentData(n[m++], n[m++]), v.setMaterialData(s), v.setPaperSetup(this.m_PagePaperSetup)), d += v.thickness;
1931
- }
1932
- this.m_TotalThickness = d;
1933
- const g = this.m_Papers[0].thickness, _ = this.m_Papers[Math.floor(a / 2)].thickness;
1934
- this.m_MinPaperThickness = Math.min(g, _), this.m_MaxPaperThickness = Math.max(g, _);
1935
- const u = this.m_Papers[0].size.x, f = this.m_Papers[Math.floor(a / 2)].size.x;
1936
- this.m_MinPaperWidth = Math.min(u, f);
1937
- const p = this.m_Papers[0].size.y, P = this.m_Papers[Math.floor(a / 2)].size.y;
1938
- this.m_MinPaperHeight = Math.min(p, P), this.m_Bound = this.m_Binding.createBound(
1897
+ for (let w = 0; w < a; w++) {
1898
+ const v = this.m_HasCover && (w < c || w >= a - c), N = this.m_RendererFactory.get("Paper"), R = this.m_Papers[w] = new re(v, w, this, N);
1899
+ R.renderer.castShadows = this.m_CastShadows, w < Math.round(o.MathUtils.lerp(0, a, h)) && (R.transform.scale.set(-1, 1, 1), R.setTime(1)), v ? (R.setContentData(i[l++], i[l++], w > c), R.setMaterialData(e), R.setPaperSetup(this.m_CoverPaperSetup)) : (R.setContentData(n[u++], n[u++]), R.setMaterialData(s), R.setPaperSetup(this.m_PagePaperSetup)), _ += R.thickness;
1900
+ }
1901
+ this.m_TotalThickness = _;
1902
+ const d = this.m_Papers[0].thickness, f = this.m_Papers[Math.floor(a / 2)].thickness;
1903
+ this.m_MinPaperThickness = Math.min(d, f), this.m_MaxPaperThickness = Math.max(d, f);
1904
+ const m = this.m_Papers[0].size.x, g = this.m_Papers[Math.floor(a / 2)].size.x;
1905
+ this.m_MinPaperWidth = Math.min(m, g);
1906
+ const p = this.m_Papers[0].size.y, M = this.m_Papers[Math.floor(a / 2)].size.y;
1907
+ this.m_MinPaperHeight = Math.min(p, M), this.m_Bound = this.m_Binding.createBound(
1939
1908
  this,
1940
1909
  this.m_Root,
1941
1910
  this.m_RendererFactory,
1942
1911
  this.m_MeshFactory
1943
1912
  ), this.m_Bound.binderRenderer.setVisibility(!this.m_HideBinder);
1944
- const B = this.m_ReduceOverdraw && n.length > 0, M = this.m_ReduceSubMeshes, w = this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, M), T = B ? this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, M, !0) : null, k = this.createPaperMeshDataPool(this.m_PagePaperSetup, !1), O = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !0), Z = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !1), z = Math.floor(a / 2) - 1, U = z + 1, V = this.m_Bound.constructor.name.includes("Staple");
1945
- for (let C = 0; C < a; C++) {
1946
- const D = this.m_Papers[C];
1947
- C !== 0 && (D.prev = this.m_Papers[C - 1]), C !== a - 1 && (D.next = this.m_Papers[C + 1]), D.noHole = V && (C === z || C === U), D.isCover ? D.setMeshData(O.get(), null, Z) : D.setMeshData(
1948
- w.get(),
1949
- (T == null ? void 0 : T.get()) ?? null,
1950
- k
1913
+ const T = this.m_ReduceOverdraw && n.length > 0, C = this.m_ReduceSubMeshes, S = this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, C), k = T ? this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, C, !0) : null, D = this.createPaperMeshDataPool(this.m_PagePaperSetup, !1), U = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !0), L = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !1), z = Math.floor(a / 2) - 1, E = z + 1, A = ((B = this.m_Bound) == null ? void 0 : B.bindingType) === "staple";
1914
+ for (let w = 0; w < a; w++) {
1915
+ const v = this.m_Papers[w];
1916
+ w !== 0 && (v.prev = this.m_Papers[w - 1]), w !== a - 1 && (v.next = this.m_Papers[w + 1]), v.noHole = A && (w === z || w === E), v.isCover ? v.setMeshData(U.get(), null, L) : v.setMeshData(
1917
+ S.get(),
1918
+ (k == null ? void 0 : k.get()) ?? null,
1919
+ D
1951
1920
  );
1952
1921
  }
1953
- this.m_IsBuilt = !0, this.m_RendererIds = this.m_RendererFactory.ids, this.update(0), this.m_Bound.binderRenderer.updateCollider(), this.m_CoverPaperSetup.bookDirection = X.LeftToRight, this.m_PagePaperSetup.bookDirection = X.LeftToRight;
1922
+ this.m_IsBuilt = !0, this.m_RendererIds = this.m_RendererFactory.ids, this._frontPapersCache = null, this.update(0), this.m_CoverPaperSetup.bookDirection = j.LeftToRight, this.m_PagePaperSetup.bookDirection = j.LeftToRight;
1954
1923
  }
1924
+ /**
1925
+ * Clears the built state of the book.
1926
+ * NOTE: This does NOT call super.clear() — it has different semantics from
1927
+ * THREE.Group.clear(). It resets internal book state (papers, bound, flags)
1928
+ * without removing children from the Three.js scene graph.
1929
+ */
1955
1930
  clear() {
1956
- return this.m_CoverPaperCount = this.m_PagePaperCount = 0, this.m_IsBuilt = !1, this.m_WasIdle = !1, this.m_Bound = null, this.m_MeshFactory !== null && this.m_MeshFactory.recycle(), this.m_RendererFactory !== null && this.m_RendererFactory.recycle(), this;
1931
+ var t;
1932
+ return this.m_CoverPaperCount = this.m_PagePaperCount = 0, this.m_IsBuilt = !1, this.m_WasIdle = !1, (t = this.m_Bound) == null || t.dispose(), this.m_Bound = null, this._frontPapersCache = null, this.m_MeshFactory !== null && this.m_MeshFactory.recycle(), this.m_RendererFactory !== null && this.m_RendererFactory.recycle(), this;
1957
1933
  }
1958
1934
  hardClear() {
1959
- this.m_CoverPaperCount = this.m_PagePaperCount = 0, this.m_IsBuilt = !1, this.m_WasIdle = !1, this.m_Bound = null, this.m_Root !== null && (this.remove(this.m_Root), this.m_Root = null), this.m_MeshFactory !== null && (this.m_MeshFactory.destroy(), this.m_MeshFactory = null), this.m_RendererFactory !== null && (this.m_RendererFactory.destroy(), this.m_RendererFactory = null);
1935
+ var t;
1936
+ this.m_CoverPaperCount = this.m_PagePaperCount = 0, this.m_IsBuilt = !1, this.m_WasIdle = !1, (t = this.m_Bound) == null || t.dispose(), this.m_Bound = null, this._frontPapersCache = null, this.m_Root !== null && (this.remove(this.m_Root), this.m_Root = null), this.m_MeshFactory !== null && (this.m_MeshFactory.destroy(), this.m_MeshFactory = null), this.m_RendererFactory !== null && (this.m_RendererFactory.destroy(), this.m_RendererFactory = null);
1960
1937
  }
1961
1938
  createPaperMeshDataPool(t, e, s = !1, i = !1) {
1962
- const n = e ? 0 : t.quality, o = this.m_Bound.createPaperPattern(
1939
+ const n = e ? 0 : t.quality, h = this.m_Bound.createPaperPattern(
1963
1940
  n,
1964
1941
  t.size,
1965
1942
  t.thickness,
@@ -1967,14 +1944,16 @@ const at = class at extends c.Group {
1967
1944
  i,
1968
1945
  s
1969
1946
  );
1970
- return new xe(
1947
+ return new ue(
1971
1948
  this.m_MeshFactory,
1972
- o,
1949
+ h,
1973
1950
  e && this.m_Bound.useSharedMeshDataForLowpoly
1974
1951
  );
1975
1952
  }
1976
1953
  // ── Query methods ─────────────────────────────────────────────────────
1977
1954
  getFrontPapers() {
1955
+ if (this._frontPapersCache !== null)
1956
+ return this._frontPapersCache;
1978
1957
  const t = [];
1979
1958
  if (this.m_SelectedPaper !== null) {
1980
1959
  const e = this.m_SelectedPaper.index;
@@ -1987,7 +1966,7 @@ const at = class at extends c.Group {
1987
1966
  }
1988
1967
  t.length === 0 && t.push(this.m_Papers[this.m_Papers.length - 1]);
1989
1968
  }
1990
- return t;
1969
+ return this._frontPapersCache = t, t;
1991
1970
  }
1992
1971
  getAverageTime() {
1993
1972
  const t = this.m_Papers.length;
@@ -2016,14 +1995,14 @@ const at = class at extends c.Group {
2016
1995
  if (s !== this.m_CoverPaperCount || i !== this.m_PagePaperCount)
2017
1996
  return !1;
2018
1997
  this.m_Content.direction % 2 !== 0 && (t = [...t].reverse(), e = [...e].reverse());
2019
- const n = this.m_Papers.length, o = Math.floor(t.length / 4);
2020
- let a = 0, h = 0;
2021
- for (let m = 0; m < n; m++) {
2022
- const l = this.m_Papers[m];
2023
- this.m_HasCover && (m < o || m >= n - o) ? l.setContentData(
2024
- t[h++],
2025
- t[h++],
2026
- m > o
1998
+ const n = this.m_Papers.length, h = Math.floor(t.length / 4);
1999
+ let a = 0, c = 0;
2000
+ for (let u = 0; u < n; u++) {
2001
+ const l = this.m_Papers[u];
2002
+ this.m_HasCover && (u < h || u >= n - h) ? l.setContentData(
2003
+ t[c++],
2004
+ t[c++],
2005
+ u > h
2027
2006
  ) : l.setContentData(e[a++], e[a++]), l.updateMaterials();
2028
2007
  }
2029
2008
  return this.m_WasIdle = !1, !0;
@@ -2054,14 +2033,14 @@ const at = class at extends c.Group {
2054
2033
  s.frontContent.setActive(t.has(s.frontContent)), s.backContent.setActive(t.has(s.backContent));
2055
2034
  }
2056
2035
  };
2057
- at.s_Instances = /* @__PURE__ */ new Set();
2058
- let yt = at;
2059
- class Se {
2036
+ W.s_Instances = /* @__PURE__ */ new Set(), W.s_InstancesArray = null;
2037
+ let Ct = W;
2038
+ class ge {
2060
2039
  constructor() {
2061
- this.baseXArray = [], this.baseZArray = [], this.baseXOffset = 0, this.baseVertexCount = 0, this.xSeams = [], this.zSeams = [], this.xNoneSeamIndexes = [], this.borders = [], this.texcoords = [], this.weights = [], this.triangles = [], this.frontTriangles = [], this.backTriangles = [], this.borderTriangles = [], this.vertexCount = 0, this.subMeshCount = 0, this.size = new c.Vector2(), this.thickness = 0;
2040
+ this.baseXArray = [], this.baseZArray = [], this.baseXOffset = 0, this.baseVertexCount = 0, this.xSeams = [], this.zSeams = [], this.xNoneSeamIndexes = [], this.borders = [], this.texcoords = [], this.weights = [], this.triangles = [], this.frontTriangles = [], this.backTriangles = [], this.borderTriangles = [], this.vertexCount = 0, this.subMeshCount = 0, this.size = new o.Vector2(), this.thickness = 0;
2062
2041
  }
2063
2042
  }
2064
- class Ge {
2043
+ class Ae {
2065
2044
  constructor() {
2066
2045
  this.m_BookContent = null, this.m_IsActive = !1, this.onActiveChangedCallback = null;
2067
2046
  }
@@ -2072,7 +2051,7 @@ class Ge {
2072
2051
  return this.m_IsActive;
2073
2052
  }
2074
2053
  get textureST() {
2075
- return new c.Vector4(1, 1, 0, 0);
2054
+ return new o.Vector4(1, 1, 0, 0);
2076
2055
  }
2077
2056
  get isShareable() {
2078
2057
  return !0;
@@ -2096,15 +2075,15 @@ class Ge {
2096
2075
  this.m_IsActive !== t && (this.m_IsActive = t, this.onActiveChanged(), (e = this.onActiveChangedCallback) == null || e.call(this));
2097
2076
  }
2098
2077
  }
2099
- class Nt {
2078
+ class Ft {
2100
2079
  constructor(t, e) {
2101
- this.m_Texture = t, this.m_TextureST = e ?? new c.Vector4(1, 1, 0, 0);
2080
+ this.m_Texture = t, this.m_TextureST = e ?? new o.Vector4(1, 1, 0, 0);
2102
2081
  }
2103
2082
  get texture() {
2104
2083
  return this.m_Texture;
2105
2084
  }
2106
2085
  get textureST() {
2107
- return this.m_Texture ? this.m_TextureST : new c.Vector4(1, 1, 0, 0);
2086
+ return this.m_Texture ? this.m_TextureST : new o.Vector4(1, 1, 0, 0);
2108
2087
  }
2109
2088
  isPointOverUI(t) {
2110
2089
  return !1;
@@ -2114,9 +2093,9 @@ class Nt {
2114
2093
  setActive(t) {
2115
2094
  }
2116
2095
  }
2117
- class je {
2096
+ class He {
2118
2097
  constructor() {
2119
- this.m_Direction = X.LeftToRight, this.m_Covers = [null, null, null, null], this.m_Pages = [null, null, null, null, null, null, null, null], this.m_Book = null;
2098
+ this.m_Direction = j.LeftToRight, this.m_Covers = [null, null, null, null], this.m_Pages = [null, null, null, null, null, null, null, null], this.m_Book = null, this._cachedCovers = null, this._cachedPages = null;
2120
2099
  }
2121
2100
  get coverCount4() {
2122
2101
  return this.nextMultipleOf4(this.m_Covers.length);
@@ -2130,9 +2109,15 @@ class je {
2130
2109
  get covers() {
2131
2110
  return this.m_Covers;
2132
2111
  }
2112
+ set covers(t) {
2113
+ this.m_Covers = t, this._cachedCovers = null;
2114
+ }
2133
2115
  get pages() {
2134
2116
  return this.m_Pages;
2135
2117
  }
2118
+ set pages(t) {
2119
+ this.m_Pages = t, this._cachedPages = null;
2120
+ }
2136
2121
  get isEmpty() {
2137
2122
  return this.m_Covers.length === 0 && this.m_Pages.length === 0;
2138
2123
  }
@@ -2143,18 +2128,18 @@ class je {
2143
2128
  this.m_Direction = t;
2144
2129
  }
2145
2130
  get coverContents() {
2146
- return this.getContents(this.m_Covers, !1);
2131
+ return this._cachedCovers === null && (this._cachedCovers = this.getContents(this.m_Covers, !1)), this._cachedCovers;
2147
2132
  }
2148
2133
  get pageContents() {
2149
- return this.getContents(this.m_Pages, !1);
2134
+ return this._cachedPages === null && (this._cachedPages = this.getContents(this.m_Pages, !1)), this._cachedPages;
2150
2135
  }
2151
2136
  getContents(t, e) {
2152
2137
  const s = t.length;
2153
2138
  let i = this.nextMultipleOf4(s);
2154
2139
  e && (i = Math.min(i, 4));
2155
2140
  const n = new Array(i);
2156
- for (let o = 0; o < i; o++)
2157
- n[o] = this.getContent(o < s ? t[o] : null);
2141
+ for (let h = 0; h < i; h++)
2142
+ n[h] = this.getContent(h < s ? t[h] : null);
2158
2143
  return n;
2159
2144
  }
2160
2145
  nextMultipleOf4(t) {
@@ -2162,15 +2147,15 @@ class je {
2162
2147
  }
2163
2148
  getContent(t) {
2164
2149
  if (t !== null) {
2165
- if (t instanceof c.Texture)
2166
- return new Nt(t);
2150
+ if (t instanceof o.Texture)
2151
+ return new Ft(t);
2167
2152
  if (typeof t.init == "function")
2168
2153
  return t;
2169
2154
  }
2170
- return new Nt(null);
2155
+ return new Ft(null);
2171
2156
  }
2172
2157
  init(t) {
2173
- this.m_Book = t;
2158
+ this.m_Book = t, this._cachedCovers = null, this._cachedPages = null;
2174
2159
  for (const e of this.coverContents)
2175
2160
  e.init(this);
2176
2161
  for (const e of this.pageContents)
@@ -2215,16 +2200,16 @@ class je {
2215
2200
  return !this.isCoverPaperSideIndex(t);
2216
2201
  }
2217
2202
  }
2218
- class qe {
2203
+ class Fe {
2219
2204
  constructor(t, e) {
2220
- this.enabled = !0, this.m_Raycaster = new c.Raycaster(), this.m_Mouse = new c.Vector2(), this.m_SelectedBook = null, this.m_IsPointerDown = !1, this.m_OnPointerDown = (s) => {
2205
+ this.enabled = !0, this.m_Raycaster = new o.Raycaster(), this.m_Mouse = new o.Vector2(), this.m_SelectedBook = null, this.m_IsPointerDown = !1, this.m_OnPointerDown = (s) => {
2221
2206
  var n;
2222
2207
  if (!this.enabled || s.button !== 0) return;
2223
2208
  this.m_IsPointerDown = !0;
2224
2209
  const i = this.m_GetRay(s);
2225
- for (const o of yt.instances)
2226
- if (o.startTurning(i)) {
2227
- this.m_SelectedBook = o, (n = this.onTurnStart) == null || n.call(this, o);
2210
+ for (const h of Ct.instances)
2211
+ if (h.startTurning(i)) {
2212
+ this.m_SelectedBook = h, (n = this.onTurnStart) == null || n.call(this, h);
2228
2213
  break;
2229
2214
  }
2230
2215
  }, this.m_OnPointerMove = (s) => {
@@ -2242,56 +2227,46 @@ class qe {
2242
2227
  return this.m_Mouse.x = (t.clientX - e.left) / e.width * 2 - 1, this.m_Mouse.y = -((t.clientY - e.top) / e.height) * 2 + 1, this.m_Raycaster.setFromCamera(this.m_Mouse, this.m_Camera), this.m_Raycaster.ray;
2243
2228
  }
2244
2229
  }
2245
- class Te {
2230
+ class pe {
2246
2231
  }
2247
- class Qe {
2232
+ class xe {
2248
2233
  constructor(t, e) {
2249
- this.m_Book = t, this.m_Root = e;
2234
+ this.bindingType = "", this.m_Book = t, this.m_Root = e;
2235
+ }
2236
+ /** Release GPU resources. Override in subclasses. */
2237
+ dispose() {
2250
2238
  }
2251
2239
  }
2252
- function Et(r, t, e, s) {
2240
+ function Ot(r, t, e, s) {
2253
2241
  const i = 1 - s;
2254
- return new c.Vector3(
2242
+ return new o.Vector3(
2255
2243
  i * i * r.x + 2 * i * s * t.x + s * s * e.x,
2256
2244
  i * i * r.y + 2 * i * s * t.y + s * s * e.y,
2257
2245
  i * i * r.z + 2 * i * s * t.z + s * s * e.z
2258
2246
  );
2259
2247
  }
2260
- function Xt(r, t) {
2248
+ function Zt(r, t) {
2261
2249
  return r++, r === t ? 0 : r;
2262
2250
  }
2263
- function ve(r, t) {
2251
+ function Me(r, t) {
2264
2252
  return r === 0 ? t - 1 : r - 1;
2265
2253
  }
2266
- const ke = 0.01, be = 0.1, Be = 0.04, Re = 0.4, De = 2, Ie = 10, ze = 0, Ve = 5;
2267
- function et(r, t, e) {
2268
- return Math.max(t, Math.min(e, r));
2269
- }
2270
- function te(r) {
2271
- return Math.max(0, Math.min(1, r));
2272
- }
2273
- function F(r, t, e) {
2274
- return r + (t - r) * e;
2275
- }
2276
- function Wt(r, t, e) {
2277
- return r === t ? 0 : te((e - r) / (t - r));
2278
- }
2279
- function Ae(r, t) {
2254
+ const ye = 0.01, Ce = 0.1, we = 0.04, Pe = 0.4, Se = 2, Te = 10, ve = 0, ke = 5;
2255
+ function Be(r, t) {
2280
2256
  const e = r.clone().normalize();
2281
- if (e.lengthSq() === 0) return new c.Quaternion();
2282
- let s = new c.Vector3().crossVectors(t, e);
2257
+ if (e.lengthSq() === 0) return new o.Quaternion();
2258
+ let s = new o.Vector3().crossVectors(t, e);
2283
2259
  if (s.lengthSq() === 0) {
2284
- const o = Math.abs(e.y) < 0.999 ? new c.Vector3(0, 1, 0) : new c.Vector3(1, 0, 0);
2285
- s = new c.Vector3().crossVectors(o, e);
2260
+ const h = Math.abs(e.y) < 0.999 ? new o.Vector3(0, 1, 0) : new o.Vector3(1, 0, 0);
2261
+ s = new o.Vector3().crossVectors(h, e);
2286
2262
  }
2287
2263
  s.normalize();
2288
- const i = new c.Vector3().crossVectors(e, s).normalize(), n = new c.Matrix4().makeBasis(s, i, e);
2289
- return new c.Quaternion().setFromRotationMatrix(n);
2264
+ const i = new o.Vector3().crossVectors(e, s).normalize(), n = new o.Matrix4().makeBasis(s, i, e);
2265
+ return new o.Quaternion().setFromRotationMatrix(n);
2290
2266
  }
2291
- const tt = Math.PI / 180, it = 180 / Math.PI;
2292
- class He {
2267
+ class Re {
2293
2268
  constructor() {
2294
- this._material = null, this._color = new c.Color(1, 1, 1), this._thickness = 0.05, this._crown = 0.2, this._margin = 0.1, this._count = 4, this._quality = 3;
2269
+ this._material = null, this._color = new o.Color(1, 1, 1), this._thickness = 0.05, this._crown = 0.2, this._margin = 0.1, this._count = 4, this._quality = 3;
2295
2270
  }
2296
2271
  get material() {
2297
2272
  return this._material;
@@ -2309,69 +2284,64 @@ class He {
2309
2284
  return this._thickness;
2310
2285
  }
2311
2286
  set thickness(t) {
2312
- this._thickness = et(t, ke, be);
2287
+ this._thickness = H(t, ye, Ce);
2313
2288
  }
2314
2289
  get margin() {
2315
2290
  return this._margin;
2316
2291
  }
2317
2292
  set margin(t) {
2318
- this._margin = te(t);
2293
+ this._margin = ct(t);
2319
2294
  }
2320
2295
  get crown() {
2321
2296
  return this._crown;
2322
2297
  }
2323
2298
  set crown(t) {
2324
- this._crown = et(t, Be, Re);
2299
+ this._crown = H(t, we, Pe);
2325
2300
  }
2326
2301
  get count() {
2327
2302
  return this._count;
2328
2303
  }
2329
2304
  set count(t) {
2330
- this._count = et(t, De, Ie);
2305
+ this._count = H(t, Se, Te);
2331
2306
  }
2332
2307
  get quality() {
2333
2308
  return this._quality;
2334
2309
  }
2335
2310
  set quality(t) {
2336
- this._quality = et(t, ze, Ve);
2337
- }
2338
- }
2339
- class Fe extends Error {
2340
- constructor() {
2341
- super("Book height is too large relative to paper width."), this.name = "BookHeightException";
2311
+ this._quality = H(t, ve, ke);
2342
2312
  }
2343
2313
  }
2344
- class Oe {
2314
+ class be extends xe {
2345
2315
  // ── Constructor ────────────────────────────────────────────────────────
2346
2316
  constructor(t, e, s, i, n) {
2347
- if (this.m_StapleMargin = 0, this.m_StapleThickness = 0, this.m_BindingRadius = 0, this.m_BindingMidSpace = 0, this.m_StackHeight = 0, this.m_BindingVertexCount = 0, this.useSharedMeshDataForLowpoly = !1, this._binderRendererAdapter = null, this.m_Book = s, this.m_Root = i, this.m_Quality = t, s.totalThickness * 1.25 > s.minPaperWidth)
2348
- throw new Fe();
2349
- const o = this.m_Book.coverPaperSetup, a = this.m_Book.pagePaperSetup, h = new c.BufferGeometry();
2350
- this.updateStapleMesh(e, h);
2351
- const m = n ?? new c.MeshStandardMaterial({
2317
+ if (super(s, i), this.bindingType = "staple", this.m_StapleMargin = 0, this.m_StapleThickness = 0, this.m_BindingRadius = 0, this.m_BindingMidSpace = 0, this.m_StackHeight = 0, this.m_BindingVertexCount = 0, this.useSharedMeshDataForLowpoly = !1, this._binderRendererAdapter = null, this.m_Quality = t, s.totalThickness * 1.25 > s.minPaperWidth)
2318
+ throw new fe();
2319
+ const h = this.m_Book.coverPaperSetup, a = this.m_Book.pagePaperSetup, c = new o.BufferGeometry();
2320
+ this.updateStapleMesh(e, c);
2321
+ const u = n ?? new o.MeshStandardMaterial({
2352
2322
  color: e.color,
2353
2323
  metalness: 0.9,
2354
2324
  roughness: 0.3
2355
2325
  });
2356
- this.stapleMesh = new c.Mesh(h, m), this.stapleMesh.name = "Staple", this.stapleMesh.castShadow = this.m_Book.castShadows, i.add(this.stapleMesh), this.stapleMesh.position.set(
2326
+ this.stapleMesh = new o.Mesh(c, u), this.stapleMesh.name = "Staple", this.stapleMesh.castShadow = this.m_Book.castShadows, i.add(this.stapleMesh), this.stapleMesh.position.set(
2357
2327
  0,
2358
2328
  0,
2359
- this.m_StapleMargin + a.margin + o.margin
2329
+ this.m_StapleMargin + a.margin + h.margin
2360
2330
  );
2361
- let l = o.thickness;
2331
+ let l = h.thickness;
2362
2332
  l = Math.max(this.m_BindingRadius, l);
2363
- for (const d of this.m_Book.papers) {
2364
- const g = d.size.clone();
2365
- g.x -= this.m_BindingRadius, d.sizeXOffset = this.m_BindingRadius, d.size = g, d.setMinTurningRadius(l), d.updateTurningRadius(), this.updatePaperPosition(d);
2333
+ for (const _ of this.m_Book.papers) {
2334
+ const d = _.size.clone();
2335
+ d.x -= this.m_BindingRadius, _.sizeXOffset = this.m_BindingRadius, _.size = d, _.setMinTurningRadius(l), _.updateTurningRadius(), this.updatePaperPosition(_);
2366
2336
  }
2367
2337
  this.updateRootPosition();
2368
2338
  }
2369
2339
  get binderRenderer() {
2370
- return this._binderRendererAdapter || (this._binderRendererAdapter = new Ze(this.stapleMesh)), this._binderRendererAdapter;
2340
+ return this._binderRendererAdapter || (this._binderRendererAdapter = new Ve(this.stapleMesh)), this._binderRendererAdapter;
2371
2341
  }
2372
2342
  // ── updateStapleMesh ──────────────────────────────────────────────────
2373
2343
  updateStapleMesh(t, e) {
2374
- this.m_StapleThickness = t.thickness, this.m_StackHeight = this.m_Book.totalThickness, this.m_BindingMidSpace = this.m_StapleThickness * 1.75, this.m_BindingRadius = (this.m_StackHeight + this.m_BindingMidSpace) / 2 / Math.sin(45 * tt), this.m_StackHeight += this.m_BindingMidSpace;
2344
+ this.m_StapleThickness = t.thickness, this.m_StackHeight = this.m_Book.totalThickness, this.m_BindingMidSpace = this.m_StapleThickness * 1.75, this.m_BindingRadius = (this.m_StackHeight + this.m_BindingMidSpace) / 2 / Math.sin(45 * J), this.m_StackHeight += this.m_BindingMidSpace;
2375
2345
  let s = t.crown;
2376
2346
  s = Math.max(s, this.m_StapleThickness * 4);
2377
2347
  const i = this.m_StapleThickness * 0.5, n = Math.max(
@@ -2379,175 +2349,175 @@ class Oe {
2379
2349
  i
2380
2350
  );
2381
2351
  this.m_StapleMargin = F(i, n, t.margin);
2382
- const o = this.m_Book.minPaperHeight - this.m_StapleMargin * 2;
2383
- let a = t.count, h = (o - s * a) / (a - 1);
2384
- for (h = Math.max(h, 0); h < this.m_StapleThickness * 2 && a > 2; )
2385
- a--, h = (o - s * a) / (a - 1), h = Math.max(h, 0);
2386
- const m = t.quality / 5, l = Math.floor(F(4, 20, m)), d = Math.floor(F(4, 10, m)), g = Math.floor(F(3, 10, m)), _ = this.m_StapleThickness / 2, u = _ * 2.5, f = 0.9, p = _ * 1;
2387
- let P = s / 2 * f;
2388
- P = Math.max(P, p * 2);
2389
- let B = 0;
2390
- B += this.m_Book.totalThickness / 2, B += _;
2391
- const M = -(this.m_Book.papers[0].thickness / 2 + _), w = [];
2352
+ const h = this.m_Book.minPaperHeight - this.m_StapleMargin * 2;
2353
+ let a = t.count, c = (h - s * a) / (a - 1);
2354
+ for (c = Math.max(c, 0); c < this.m_StapleThickness * 2 && a > 2; )
2355
+ a--, c = (h - s * a) / (a - 1), c = Math.max(c, 0);
2356
+ const u = t.quality / 5, l = Math.floor(F(4, 20, u)), _ = Math.floor(F(4, 10, u)), d = Math.floor(F(3, 10, u)), f = this.m_StapleThickness / 2, m = f * 2.5, g = 0.9, p = f * 1;
2357
+ let M = s / 2 * g;
2358
+ M = Math.max(M, p * 2);
2359
+ let T = 0;
2360
+ T += this.m_Book.totalThickness / 2, T += f;
2361
+ const C = -(this.m_Book.papers[0].thickness / 2 + f), S = [];
2392
2362
  {
2393
- for (let I = 0; I < d; I++) {
2394
- const E = I / (d - 1), q = F(-90, -180, E) * tt, y = new c.Vector3(
2395
- p * Math.sin(q),
2363
+ for (let I = 0; I < _; I++) {
2364
+ const G = I / (_ - 1), K = F(-90, -180, G) * J, y = new o.Vector3(
2365
+ p * Math.sin(K),
2396
2366
  0,
2397
- p * Math.cos(q)
2367
+ p * Math.cos(K)
2398
2368
  );
2399
- y.x += p, y.z += p, y.x += M, w.push(y);
2369
+ y.x += p, y.z += p, y.x += C, S.push(y);
2400
2370
  }
2401
- const x = new c.Vector3(B, 0, 0), H = new c.Vector3(B + u * 0.75, 0, 0), S = new c.Vector3(B - _ * 0.5, 0, P);
2402
- for (let I = 0; I < g; I++) {
2403
- const E = I / (g - 1), j = Et(x, H, S, E);
2404
- j.x += M, w.push(j);
2371
+ const x = new o.Vector3(T, 0, 0), Z = new o.Vector3(T + m * 0.75, 0, 0), P = new o.Vector3(T - f * 0.5, 0, M);
2372
+ for (let I = 0; I < d; I++) {
2373
+ const G = I / (d - 1), Y = Ot(x, Z, P, G);
2374
+ Y.x += C, S.push(Y);
2405
2375
  }
2406
- w.reverse();
2376
+ S.reverse();
2407
2377
  }
2408
- const T = new Array(l);
2378
+ const k = new Array(l);
2409
2379
  for (let x = 0; x < l; x++) {
2410
- const S = (90 - x * (360 / l)) * tt;
2411
- T[x] = new c.Vector3(Math.cos(S), Math.sin(S), 0), T[x].x *= 0.75;
2380
+ const P = (90 - x * (360 / l)) * J;
2381
+ k[x] = new o.Vector3(Math.cos(P), Math.sin(P), 0), k[x].x *= 0.75;
2412
2382
  }
2413
- const k = w.length, O = k * l, Z = new Array(O * 2), z = new Array(O * 2), U = new Array(
2414
- (O * 2 - 1) * l * 2 * 3
2383
+ const D = S.length, U = D * l, L = new Array(U * 2), z = new Array(U * 2), E = new Array(
2384
+ (U * 2 - 1) * l * 2 * 3
2415
2385
  );
2416
- for (let x = 0; x < O * 2; x++)
2417
- Z[x] = new c.Vector3(), z[x] = new c.Vector3();
2418
- let V = 0;
2419
- for (let x = 0; x < k; x++) {
2420
- const H = w[ve(x, k)], S = w[x], I = w[Xt(x, k)];
2421
- let E;
2386
+ for (let x = 0; x < U * 2; x++)
2387
+ L[x] = new o.Vector3(), z[x] = new o.Vector3();
2388
+ let A = 0;
2389
+ for (let x = 0; x < D; x++) {
2390
+ const Z = S[Me(x, D)], P = S[x], I = S[Zt(x, D)];
2391
+ let G;
2422
2392
  if (x === 0)
2423
- E = new c.Vector3(1, 0, -2).normalize();
2424
- else if (x === k - 1)
2425
- E = new c.Vector3(0, 0, 1);
2393
+ G = new o.Vector3(1, 0, -2).normalize();
2394
+ else if (x === D - 1)
2395
+ G = new o.Vector3(0, 0, 1);
2426
2396
  else {
2427
- const K = S.clone().sub(H).normalize(), J = I.clone().sub(S).normalize();
2428
- E = K.add(J).multiplyScalar(0.5);
2397
+ const it = P.clone().sub(Z).normalize(), nt = I.clone().sub(P).normalize();
2398
+ G = it.add(nt).multiplyScalar(0.5);
2429
2399
  }
2430
- const j = new c.Vector3(0, 1, 0), q = Ae(E, j), y = V;
2431
- let b = Wt(0, g / 4, x);
2400
+ const Y = new o.Vector3(0, 1, 0), K = Be(G, Y), y = A;
2401
+ let b = Q(0, d / 4, x);
2432
2402
  b = F(0.1, 1, b), b = Math.sqrt(b);
2433
- for (let K = 0; K < l; K++) {
2434
- const J = T[K].clone().applyQuaternion(q).multiplyScalar(b), ct = S.clone().add(J.clone().multiplyScalar(_));
2435
- Z[V] = ct, z[V] = J.clone();
2436
- const ht = S.clone().add(J.clone().multiplyScalar(_));
2437
- ht.z = s - ht.z;
2438
- const se = y + l - K - 1, Tt = O * 2 - se - 1;
2439
- Z[Tt] = ht, z[Tt] = J.clone(), V++;
2403
+ for (let it = 0; it < l; it++) {
2404
+ const nt = k[it].clone().applyQuaternion(K).multiplyScalar(b), lt = P.clone().add(nt.clone().multiplyScalar(f));
2405
+ L[A] = lt, z[A] = nt.clone();
2406
+ const ot = P.clone().add(nt.clone().multiplyScalar(f));
2407
+ ot.z = s - ot.z;
2408
+ const $t = y + l - it - 1, St = U * 2 - $t - 1;
2409
+ L[St] = ot, z[St] = nt.clone(), A++;
2440
2410
  }
2441
2411
  }
2442
- let C = 0;
2443
- const D = w.length * 2;
2444
- for (let x = 0; x < D - 1; x++) {
2445
- const H = x * l, S = (x + 1) * l;
2412
+ let B = 0;
2413
+ const w = S.length * 2;
2414
+ for (let x = 0; x < w - 1; x++) {
2415
+ const Z = x * l, P = (x + 1) * l;
2446
2416
  for (let I = 0; I < l; I++) {
2447
- const E = Xt(I, l), j = H + I, q = H + E, y = S + E, b = S + I;
2448
- U[C++] = j, U[C++] = b, U[C++] = q, U[C++] = q, U[C++] = b, U[C++] = y;
2417
+ const G = Zt(I, l), Y = Z + I, K = Z + G, y = P + G, b = P + I;
2418
+ E[B++] = Y, E[B++] = b, E[B++] = K, E[B++] = K, E[B++] = b, E[B++] = y;
2449
2419
  }
2450
2420
  }
2451
- const L = [...Z], v = [...z], Q = [...U], G = Z.map((x) => x.clone()), $ = [...U];
2421
+ const v = [...L], N = [...z], R = [...E], $ = L.map((x) => x.clone()), tt = [...E];
2452
2422
  for (let x = 0; x < a - 1; x++) {
2453
- const H = G.length;
2454
- for (let S = 0; S < $.length; S++)
2455
- $[S] += H;
2456
- for (let S = 0; S < G.length; S++)
2457
- G[S].z += h + s;
2458
- L.push(...G.map((S) => S.clone())), v.push(...z.map((S) => S.clone())), Q.push(...$);
2459
- }
2460
- const W = new Float32Array(L.length * 3), A = new Float32Array(v.length * 3);
2461
- for (let x = 0; x < L.length; x++)
2462
- W[x * 3] = L[x].x, W[x * 3 + 1] = L[x].y, W[x * 3 + 2] = L[x].z, A[x * 3] = v[x].x, A[x * 3 + 1] = v[x].y, A[x * 3 + 2] = v[x].z;
2423
+ const Z = $.length;
2424
+ for (let P = 0; P < tt.length; P++)
2425
+ tt[P] += Z;
2426
+ for (let P = 0; P < $.length; P++)
2427
+ $[P].z += c + s;
2428
+ v.push(...$.map((P) => P.clone())), N.push(...z.map((P) => P.clone())), R.push(...tt);
2429
+ }
2430
+ const q = new Float32Array(v.length * 3), O = new Float32Array(N.length * 3);
2431
+ for (let x = 0; x < v.length; x++)
2432
+ q[x * 3] = v[x].x, q[x * 3 + 1] = v[x].y, q[x * 3 + 2] = v[x].z, O[x * 3] = N[x].x, O[x * 3 + 1] = N[x].y, O[x * 3 + 2] = N[x].z;
2463
2433
  e.setAttribute(
2464
2434
  "position",
2465
- new c.BufferAttribute(W, 3)
2435
+ new o.BufferAttribute(q, 3)
2466
2436
  ), e.setAttribute(
2467
2437
  "normal",
2468
- new c.BufferAttribute(A, 3)
2469
- ), e.setIndex(Q);
2438
+ new o.BufferAttribute(O, 3)
2439
+ ), e.setIndex(R);
2470
2440
  }
2471
2441
  // ── createPaperPattern ────────────────────────────────────────────────
2472
- createPaperPattern(t, e, s, i, n, o) {
2473
- const a = new Se();
2442
+ createPaperPattern(t, e, s, i, n, h) {
2443
+ const a = new ge();
2474
2444
  a.size = e, a.thickness = s;
2475
- const h = this.m_BindingRadius;
2476
- a.baseXOffset = -h;
2477
- const m = this.m_Quality + 1;
2478
- this.m_BindingVertexCount = m;
2479
- const l = t / 5, d = Math.min(e.x, e.y) / 60, g = Math.floor(
2480
- F(0, (e.x - h) / d, l)
2481
- ), _ = Math.floor(F(0, e.y / d, l));
2482
- let u = 2 + g + 1 + m, f = 2 + _;
2483
- const p = new st(0);
2484
- let P = p;
2485
- const B = h / m;
2486
- let M = 0;
2487
- for (let y = 1; y < m + 1; y++)
2488
- P = P.createNext(M), M += B;
2489
- const w = (e.x - h) / (g + 1);
2490
- for (let y = m + 1; y < u; y++)
2491
- P = P.createNext(M), M += w;
2492
- const T = new st(0);
2493
- let k = T;
2494
- const O = e.y / (f - 1);
2495
- let Z = 0;
2496
- for (let y = 0; y < f - 1; y++)
2497
- Z += O, k = k.createNext(Z);
2498
- const z = [], U = [], V = i.clone();
2445
+ const c = this.m_BindingRadius;
2446
+ a.baseXOffset = -c;
2447
+ const u = this.m_Quality + 1;
2448
+ this.m_BindingVertexCount = u;
2449
+ const l = t / 5, _ = Math.min(e.x, e.y) / 60, d = Math.floor(
2450
+ F(0, (e.x - c) / _, l)
2451
+ ), f = Math.floor(F(0, e.y / _, l));
2452
+ let m = 2 + d + 1 + u, g = 2 + f;
2453
+ const p = new ht(0);
2454
+ let M = p;
2455
+ const T = c / u;
2456
+ let C = 0;
2457
+ for (let y = 1; y < u + 1; y++)
2458
+ M = M.createNext(C), C += T;
2459
+ const S = (e.x - c) / (d + 1);
2460
+ for (let y = u + 1; y < m; y++)
2461
+ M = M.createNext(C), C += S;
2462
+ const k = new ht(0);
2463
+ let D = k;
2464
+ const U = e.y / (g - 1);
2465
+ let L = 0;
2466
+ for (let y = 0; y < g - 1; y++)
2467
+ L += U, D = D.createNext(L);
2468
+ const z = [], E = [], A = i.clone();
2499
2469
  if (n) {
2500
2470
  let y = 0;
2501
2471
  this.m_Book.hasCover && (y = Math.floor(this.m_Book.coverPaperCount / 2));
2502
2472
  const b = Math.max(0.01, s);
2503
- V.left = 0, V.right = (this.getPX(y + 1, s) - this.getPX(y, s) + b) / e.x, V.down = b / e.y, V.up = b / e.y;
2504
- }
2505
- const C = new ue(a, V, !1);
2506
- C.insert(p, T, z, U), p.updateIndex(0), T.updateIndex(0), xt(z, a.xSeams), xt(U, a.zSeams);
2507
- const D = this.m_BindingVertexCount + 2, L = new Array(D);
2508
- a.xNoneSeamIndexes = L, P = p;
2509
- for (let y = 0; y < D; y++) {
2510
- L[y] = P.index;
2473
+ A.left = 0, A.right = (this.getPX(y + 1, s) - this.getPX(y, s) + b) / e.x, A.down = b / e.y, A.up = b / e.y;
2474
+ }
2475
+ const B = new he(a, A, !1);
2476
+ B.insert(p, k, z, E), p.updateIndex(0), k.updateIndex(0), pt(z, a.xSeams), pt(E, a.zSeams);
2477
+ const w = this.m_BindingVertexCount + 2, v = new Array(w);
2478
+ a.xNoneSeamIndexes = v, M = p;
2479
+ for (let y = 0; y < w; y++) {
2480
+ v[y] = M.index;
2511
2481
  do
2512
- P = P.next;
2513
- while (P.seam);
2514
- }
2515
- const v = p.getValues(), Q = T.getValues();
2516
- u = v.length, f = Q.length;
2517
- const G = u * f, $ = [], W = new Array(G).fill(0), A = [], x = [], H = [], S = [];
2518
- Kt(
2519
- $,
2520
- v,
2521
- Q,
2482
+ M = M.next;
2483
+ while (M.seam);
2484
+ }
2485
+ const N = p.getValues(), R = k.getValues();
2486
+ m = N.length, g = R.length;
2487
+ const $ = m * g, tt = [], q = new Array($).fill(0), O = [], x = [], Z = [], P = [];
2488
+ Gt(
2489
+ tt,
2490
+ N,
2491
+ R,
2522
2492
  e,
2523
2493
  i,
2524
2494
  this.m_Book.direction
2525
2495
  );
2526
- const I = C.leftNode.index, E = C.downNode.index;
2527
- let j = C.rightNode.index, q = C.upNode.index;
2528
- j === 0 && (j = u - 1), q === 0 && (q = f - 1);
2529
- for (let y = 0; y < f - 1; y++)
2530
- for (let b = 0; b < u - 1; b++) {
2531
- if (n && y >= E && y < q && b >= I && b < j)
2496
+ const I = B.leftNode.index, G = B.downNode.index;
2497
+ let Y = B.rightNode.index, K = B.upNode.index;
2498
+ Y === 0 && (Y = m - 1), K === 0 && (K = g - 1);
2499
+ for (let y = 0; y < g - 1; y++)
2500
+ for (let b = 0; b < m - 1; b++) {
2501
+ if (n && y >= G && y < K && b >= I && b < Y)
2532
2502
  continue;
2533
- const K = y * u + b, J = y * u + (b + 1), ct = (y + 1) * u + b, ht = (y + 1) * u + (b + 1);
2534
- W[K] += 2, W[J] += 2, W[ct] += 2, W[ht] += 2, Yt(
2535
- A,
2503
+ const it = y * m + b, nt = y * m + (b + 1), lt = (y + 1) * m + b, ot = (y + 1) * m + (b + 1);
2504
+ q[it] += 2, q[nt] += 2, q[lt] += 2, q[ot] += 2, Wt(
2505
+ O,
2536
2506
  x,
2537
- K,
2538
- J,
2539
- ct,
2540
- ht,
2541
- G
2507
+ it,
2508
+ nt,
2509
+ lt,
2510
+ ot,
2511
+ $
2542
2512
  );
2543
2513
  }
2544
- if (S.push(new St(0, 0, u - 1, f - 1, !1, !1)), Qt(S, H, $, u, f), a.baseXArray = v, a.baseZArray = Q, a.baseVertexCount = G, a.vertexCount = $.length, a.texcoords = $, a.weights = W, o) {
2514
+ if (P.push(new Pt(0, 0, m - 1, g - 1, !1, !1)), Nt(P, Z, tt, m, g), a.baseXArray = N, a.baseZArray = R, a.baseVertexCount = $, a.vertexCount = tt.length, a.texcoords = tt, a.weights = q, h) {
2545
2515
  a.subMeshCount = 1;
2546
2516
  const y = [];
2547
- y.push(...A), y.push(...H), y.push(...x), a.triangles = y;
2517
+ y.push(...O), y.push(...Z), y.push(...x), a.triangles = y;
2548
2518
  } else
2549
- a.subMeshCount = 3, a.frontTriangles = A, a.backTriangles = x, a.borderTriangles = H;
2550
- return a.borders = S, a;
2519
+ a.subMeshCount = 3, a.frontTriangles = O, a.backTriangles = x, a.borderTriangles = Z;
2520
+ return a.borders = P, a;
2551
2521
  }
2552
2522
  // ── updateRootPosition ────────────────────────────────────────────────
2553
2523
  updateRootPosition() {
@@ -2559,97 +2529,82 @@ class Oe {
2559
2529
  resetPaperPosition(t) {
2560
2530
  const e = this.m_Book.papers, s = e.length;
2561
2531
  let i = 0;
2562
- const n = e.length / 2 - 1, o = e.length / 2;
2563
- for (let M = 0; M < s; M++) {
2564
- const w = e[M];
2565
- w.updateTime();
2566
- const T = w.zTime, k = w.thickness;
2567
- i += T * k, M === n && (i += T * this.m_BindingMidSpace / 2), M === o && (i += T * this.m_BindingMidSpace / 2);
2532
+ const n = e.length / 2 - 1, h = e.length / 2;
2533
+ for (let C = 0; C < s; C++) {
2534
+ const S = e[C];
2535
+ S.updateTime();
2536
+ const k = S.zTime, D = S.thickness;
2537
+ i += k * D, C === n && (i += k * this.m_BindingMidSpace / 2), C === h && (i += k * this.m_BindingMidSpace / 2);
2568
2538
  }
2569
2539
  let a = this.getStackHeight(t.index) - t.thickness / 2;
2570
- const h = this.getStackZ(a), m = 180 + h;
2571
- let l = t.isFlipped ? 1 : 0, d = F(h, m, l);
2572
- const g = d * tt, _ = new c.Vector3(
2573
- Math.cos(g) * this.m_BindingRadius,
2574
- Math.sin(g) * this.m_BindingRadius,
2540
+ const c = this.getStackZ(a), u = 180 + c;
2541
+ let l = t.isFlipped ? 1 : 0, _ = F(c, u, l);
2542
+ const d = _ * J, f = new o.Vector3(
2543
+ Math.cos(d) * this.m_BindingRadius,
2544
+ Math.sin(d) * this.m_BindingRadius,
2575
2545
  0
2576
2546
  );
2577
- _.z = t.margin;
2578
- let u = e[Math.floor(s / 2)].size.x, f = this.m_BindingMidSpace, p = Math.sqrt(u * u - f * f), P = Math.asin(p / u) * it - 90;
2547
+ f.z = t.margin;
2548
+ let m = e[Math.floor(s / 2)].size.x, g = this.m_BindingMidSpace, p = Math.sqrt(m * m - g * g), M = Math.asin(p / m) * et - 90;
2579
2549
  if (t.index < Math.floor(s / 2)) {
2580
- let M = 0;
2550
+ let C = 0;
2581
2551
  if (this.m_Book.alignToGround) {
2582
- u = e[0].size.x;
2583
- const w = this.m_StackHeight / 2;
2584
- f = et(i, 0, w) - w, p = Math.sqrt(u * u - f * f), M = (Math.asin(p / u) * it - 90) * 2;
2552
+ m = e[0].size.x;
2553
+ const S = this.m_StackHeight / 2;
2554
+ g = H(i, 0, S) - S, p = Math.sqrt(m * m - g * g), C = (Math.asin(p / m) * et - 90) * 2;
2585
2555
  }
2586
- d = F(P, -M, l);
2556
+ _ = F(M, -C, l);
2587
2557
  } else {
2588
- let M = 0;
2558
+ let C = 0;
2589
2559
  if (this.m_Book.alignToGround) {
2590
- u = e[0].size.x;
2591
- const w = this.m_StackHeight / 2;
2592
- f = w - et(i, w, w * 2), p = Math.sqrt(u * u - f * f), M = (Math.asin(p / u) * it - 90) * 2;
2560
+ m = e[0].size.x;
2561
+ const S = this.m_StackHeight / 2;
2562
+ g = S - H(i, S, S * 2), p = Math.sqrt(m * m - g * g), C = (Math.asin(p / m) * et - 90) * 2;
2593
2563
  }
2594
- d = F(M, -P, l);
2564
+ _ = F(C, -M, l);
2595
2565
  }
2596
- t.transform.position.copy(_), t.transform.quaternion.setFromEuler(
2597
- new c.Euler(0, 0, d * tt)
2566
+ t.transform.position.copy(f), t.transform.quaternion.setFromEuler(
2567
+ new o.Euler(0, 0, _ * J)
2598
2568
  );
2599
2569
  }
2600
2570
  // ── getPX (private helper) ───────────────────────────────────────────
2601
2571
  getPX(t, e) {
2602
- const s = this.m_Book.papers, i = s.length;
2603
- let n = 0;
2604
- const o = s.length / 2 - 1, a = s.length / 2;
2605
- for (let f = 0; f < i; f++)
2606
- n += 0 * e, f === o && (n += 0 * this.m_BindingMidSpace / 2), f === a && (n += 0 * this.m_BindingMidSpace / 2);
2607
- const h = this.getStackHeight(t) - e / 2, m = this.getStackZ(h), l = 180 + m, _ = F(m, l, 0) * tt;
2608
- return new c.Vector3(
2609
- Math.cos(_) * this.m_BindingRadius,
2610
- Math.sin(_) * this.m_BindingRadius,
2611
- 0
2612
- ).x;
2572
+ const s = this.getStackHeight(t) - e / 2, n = this.getStackZ(s) * J;
2573
+ return Math.cos(n) * this.m_BindingRadius;
2613
2574
  }
2614
2575
  // ── updatePaperPosition ───────────────────────────────────────────────
2615
2576
  updatePaperPosition(t) {
2616
- const e = this.m_Book.papers, s = e.length;
2617
- let i = 0;
2618
- const n = e.length / 2 - 1, o = e.length / 2;
2619
- for (let M = 0; M < s; M++) {
2620
- const w = e[M];
2621
- w.updateTime();
2622
- const T = w.zTime, k = w.thickness;
2623
- i += T * k, M === n && (i += T * this.m_BindingMidSpace / 2), M === o && (i += T * this.m_BindingMidSpace / 2);
2624
- }
2625
- const a = this.getStackHeight(t.index) - t.thickness / 2, h = this.getStackZ(a + i), m = 180 + this.getStackZ(a + i - this.m_StackHeight);
2626
- let l = t.zTime, d = F(h, m, l);
2627
- const g = d * tt, _ = new c.Vector3(
2628
- Math.cos(g) * this.m_BindingRadius,
2629
- Math.sin(g) * this.m_BindingRadius,
2577
+ this.updatePaperPositionWithTh(t, this.computeTh());
2578
+ }
2579
+ updatePaperPositionWithTh(t, e) {
2580
+ const s = this.m_Book.papers, i = s.length, n = this.getStackHeight(t.index) - t.thickness / 2, h = this.getStackZ(n + e), a = 180 + this.getStackZ(n + e - this.m_StackHeight);
2581
+ let c = t.zTime, u = F(h, a, c);
2582
+ const l = u * J, _ = new o.Vector3(
2583
+ Math.cos(l) * this.m_BindingRadius,
2584
+ Math.sin(l) * this.m_BindingRadius,
2630
2585
  0
2631
2586
  );
2632
2587
  _.z = t.margin;
2633
- let u = e[Math.floor(s / 2)].size.x, f = this.m_BindingMidSpace, p = Math.sqrt(u * u - f * f), P = Math.asin(p / u) * it - 90;
2634
- if (t.index < Math.floor(s / 2)) {
2588
+ let d = s[Math.floor(i / 2)].size.x, f = this.m_BindingMidSpace, m = Math.sqrt(d * d - f * f), g = Math.asin(m / d) * et - 90;
2589
+ if (t.index < Math.floor(i / 2)) {
2635
2590
  let M = 0;
2636
2591
  if (this.m_Book.alignToGround) {
2637
- u = e[0].size.x;
2638
- const w = this.m_StackHeight / 2;
2639
- f = et(i, 0, w) - w, p = Math.sqrt(u * u - f * f), M = (Math.asin(p / u) * it - 90) * 2;
2592
+ d = s[0].size.x;
2593
+ const T = this.m_StackHeight / 2;
2594
+ f = H(e, 0, T) - T, m = Math.sqrt(d * d - f * f), M = (Math.asin(m / d) * et - 90) * 2;
2640
2595
  }
2641
- d = F(P, -M, l);
2596
+ u = F(g, -M, c);
2642
2597
  } else {
2643
2598
  let M = 0;
2644
2599
  if (this.m_Book.alignToGround) {
2645
- u = e[0].size.x;
2646
- const w = this.m_StackHeight / 2;
2647
- f = w - et(i, w, w * 2), p = Math.sqrt(u * u - f * f), M = (Math.asin(p / u) * it - 90) * 2;
2600
+ d = s[0].size.x;
2601
+ const T = this.m_StackHeight / 2;
2602
+ f = T - H(e, T, T * 2), m = Math.sqrt(d * d - f * f), M = (Math.asin(m / d) * et - 90) * 2;
2648
2603
  }
2649
- d = F(M, -P, l);
2604
+ u = F(M, -g, c);
2650
2605
  }
2651
2606
  t.transform.position.copy(_), t.transform.quaternion.setFromEuler(
2652
- new c.Euler(0, 0, d * tt)
2607
+ new o.Euler(0, 0, u * J)
2653
2608
  );
2654
2609
  }
2655
2610
  // ── getStackHeight ────────────────────────────────────────────────────
@@ -2663,58 +2618,70 @@ class Oe {
2663
2618
  }
2664
2619
  // ── getStackZ ─────────────────────────────────────────────────────────
2665
2620
  getStackZ(t) {
2666
- t = et(t, 0, this.m_StackHeight);
2621
+ t = H(t, 0, this.m_StackHeight);
2667
2622
  const e = t - this.m_StackHeight * 0.5;
2668
- return Math.asin(e / this.m_BindingRadius) * it;
2623
+ return Math.asin(e / this.m_BindingRadius) * et;
2669
2624
  }
2670
2625
  // ── onLateUpdate ──────────────────────────────────────────────────────
2626
+ /** Precompute cumulative th once instead of per-paper (O(n) instead of O(n²)). */
2627
+ computeTh() {
2628
+ const t = this.m_Book.papers, e = t.length / 2 - 1, s = t.length / 2;
2629
+ let i = 0;
2630
+ for (let n = 0; n < t.length; n++) {
2631
+ const h = t[n];
2632
+ h.updateTime();
2633
+ const a = h.zTime;
2634
+ i += a * h.thickness, n === e && (i += a * this.m_BindingMidSpace / 2), n === s && (i += a * this.m_BindingMidSpace / 2);
2635
+ }
2636
+ return i;
2637
+ }
2671
2638
  onLateUpdate() {
2672
- const t = this.m_Book.papers;
2673
- for (const e of t)
2674
- this.updatePaperPosition(e);
2639
+ const t = this.m_Book.papers, e = this.computeTh();
2640
+ for (const s of t)
2641
+ this.updatePaperPositionWithTh(s, e);
2675
2642
  this.m_Root.updateMatrixWorld(!0), this.updateBindingVertices();
2676
- for (const e of t)
2677
- e.updateMesh();
2643
+ for (const s of t)
2644
+ s.updateMesh();
2678
2645
  this.updateRootPosition();
2679
2646
  }
2680
2647
  // ── updateBindingVertices ─────────────────────────────────────────────
2681
2648
  updateBindingVertices() {
2682
2649
  const t = this.m_Book.papers;
2683
- let e = new c.Vector3(0, 0, 0), s = new c.Vector3(0, 0, 0), i = this.m_BindingRadius * 0.6;
2684
- const n = this.m_StapleThickness * 0.5, o = t[0].thickness, a = this.m_Root.matrixWorld.clone(), h = t.length;
2685
- for (let m = 0; m < h; m++) {
2686
- const l = t[m], d = l.transform, g = l.meshData.pattern, _ = l.meshData.baseVertices, u = g.baseXArray, f = g.baseZArray, p = u.length, P = f.length, B = this.m_BindingVertexCount + 1, M = l.thickness, w = g.xNoneSeamIndexes, T = d.position.clone();
2687
- let k = m, O = n;
2688
- m >= Math.floor(h / 2) && (k = h - m - 1, O *= -1);
2689
- const Z = (o + M) * 0.5 + M * (k - 1), z = d.matrixWorld.clone().invert().multiply(a), U = k / (h / 2);
2690
- i = this.m_BindingRadius * F(0.45, 0.65, 1 - U);
2691
- for (let V = 0; V < P; V++) {
2692
- const C = f[V], D = new c.Vector3(0, 0, T.z + C), L = T.clone();
2693
- L.z += C;
2694
- const v = l.getDirection(C).multiplyScalar(i).add(L.clone());
2695
- if (m === 0 && V === 0) {
2696
- const A = t[h - 1], H = A.transform.position.clone().clone();
2697
- H.z += C;
2698
- const S = A.getDirection(C).multiplyScalar(i).add(H);
2699
- s = v.clone().sub(S).normalize(), e = new c.Vector3(
2650
+ let e = new o.Vector3(0, 0, 0), s = new o.Vector3(0, 0, 0), i = this.m_BindingRadius * 0.6;
2651
+ const n = this.m_StapleThickness * 0.5, h = t[0].thickness, a = this.m_Root.matrixWorld.clone(), c = t.length;
2652
+ for (let u = 0; u < c; u++) {
2653
+ const l = t[u], _ = l.transform, d = l.meshData.pattern, f = l.meshData.baseVertices, m = d.baseXArray, g = d.baseZArray, p = m.length, M = g.length, T = this.m_BindingVertexCount + 1, C = l.thickness, S = d.xNoneSeamIndexes, k = _.position.clone();
2654
+ let D = u, U = n;
2655
+ u >= Math.floor(c / 2) && (D = c - u - 1, U *= -1);
2656
+ const L = (h + C) * 0.5 + C * (D - 1), z = _.matrixWorld.clone().invert().multiply(a), E = D / (c / 2);
2657
+ i = this.m_BindingRadius * F(0.45, 0.65, 1 - E);
2658
+ for (let A = 0; A < M; A++) {
2659
+ const B = g[A], w = new o.Vector3(0, 0, k.z + B), v = k.clone();
2660
+ v.z += B;
2661
+ const N = l.getDirection(B).multiplyScalar(i).add(v.clone());
2662
+ if (u === 0 && A === 0) {
2663
+ const O = t[c - 1], Z = O.transform.position.clone().clone();
2664
+ Z.z += B;
2665
+ const P = O.getDirection(B).multiplyScalar(i).add(Z);
2666
+ s = N.clone().sub(P).normalize(), e = new o.Vector3(
2700
2667
  -s.y,
2701
2668
  s.x,
2702
2669
  0
2703
2670
  ).normalize().negate();
2704
- const I = Math.atan2(e.y, e.x) * it;
2705
- this.stapleMesh.rotation.set(0, 0, I * tt);
2671
+ const I = Math.atan2(e.y, e.x) * et;
2672
+ this.stapleMesh.rotation.set(0, 0, I * J);
2706
2673
  }
2707
- k > 0 && D.add(e.clone().multiplyScalar(Z));
2708
- const Q = V * p;
2709
- _[Q] = D.clone().applyMatrix4(z), D.add(s.clone().multiplyScalar(O));
2710
- const G = D.clone().applyMatrix4(z), $ = v.clone().applyMatrix4(z), W = L.clone().applyMatrix4(z);
2711
- _[Q + w[1]] = G;
2712
- for (let A = 2; A < B; A++) {
2713
- const x = Wt(1, B, A);
2714
- _[Q + w[A]] = Et(
2715
- G,
2674
+ D > 0 && w.add(e.clone().multiplyScalar(L));
2675
+ const R = A * p;
2676
+ f[R] = w.clone().applyMatrix4(z), w.add(s.clone().multiplyScalar(U));
2677
+ const $ = w.clone().applyMatrix4(z), tt = N.clone().applyMatrix4(z), q = v.clone().applyMatrix4(z);
2678
+ f[R + S[1]] = $;
2679
+ for (let O = 2; O < T; O++) {
2680
+ const x = Q(1, T, O);
2681
+ f[R + S[O]] = Ot(
2716
2682
  $,
2717
- W,
2683
+ tt,
2684
+ q,
2718
2685
  x
2719
2686
  );
2720
2687
  }
@@ -2743,16 +2710,18 @@ class Oe {
2743
2710
  get stapleThickness() {
2744
2711
  return this.m_StapleThickness;
2745
2712
  }
2713
+ /** Releases GPU resources held by the staple mesh. */
2714
+ dispose() {
2715
+ this.stapleMesh.geometry.dispose(), this.stapleMesh.material instanceof o.Material && this.stapleMesh.material.dispose(), this.stapleMesh.parent && this.stapleMesh.parent.remove(this.stapleMesh);
2716
+ }
2746
2717
  }
2747
- class Ze {
2718
+ class Ve {
2748
2719
  constructor(t) {
2749
2720
  this.mesh = t;
2750
2721
  }
2751
2722
  setVisibility(t) {
2752
2723
  this.mesh.visible = t;
2753
2724
  }
2754
- updateCollider() {
2755
- }
2756
2725
  get castShadows() {
2757
2726
  return this.mesh.castShadow;
2758
2727
  }
@@ -2760,7 +2729,7 @@ class Ze {
2760
2729
  this.mesh.castShadow = t;
2761
2730
  }
2762
2731
  get bounds() {
2763
- const t = new c.Box3();
2732
+ const t = new o.Box3();
2764
2733
  return this.mesh.geometry && (this.mesh.geometry.computeBoundingBox(), this.mesh.geometry.boundingBox && (t.copy(this.mesh.geometry.boundingBox), t.applyMatrix4(this.mesh.matrixWorld))), t;
2765
2734
  }
2766
2735
  get transform() {
@@ -2770,12 +2739,12 @@ class Ze {
2770
2739
  return this.mesh;
2771
2740
  }
2772
2741
  }
2773
- class $e extends Te {
2742
+ class Oe extends pe {
2774
2743
  constructor() {
2775
- super(...arguments), this.quality = 3, this.stapleSetup = new He();
2744
+ super(...arguments), this.quality = 3, this.stapleSetup = new Re();
2776
2745
  }
2777
2746
  createBound(t, e, s, i) {
2778
- return new Oe(
2747
+ return new be(
2779
2748
  this.quality,
2780
2749
  this.stapleSetup,
2781
2750
  t,
@@ -2783,7 +2752,7 @@ class $e extends Te {
2783
2752
  );
2784
2753
  }
2785
2754
  }
2786
- class ee {
2755
+ class jt {
2787
2756
  constructor(t) {
2788
2757
  this.x = (t == null ? void 0 : t.x) ?? 0, this.y = (t == null ? void 0 : t.y) ?? 0, this.width = (t == null ? void 0 : t.width) ?? 0, this.text = (t == null ? void 0 : t.text) ?? "", this.fontFamily = (t == null ? void 0 : t.fontFamily) ?? "Georgia", this.fontSize = (t == null ? void 0 : t.fontSize) ?? 24, this.fontWeight = (t == null ? void 0 : t.fontWeight) ?? "normal", this.fontStyle = (t == null ? void 0 : t.fontStyle) ?? "normal", this.color = (t == null ? void 0 : t.color) ?? "#222", this.lineHeight = (t == null ? void 0 : t.lineHeight) ?? 1.4, this.textAlign = (t == null ? void 0 : t.textAlign) ?? "left", this.opacity = (t == null ? void 0 : t.opacity) ?? 1, this.shadowColor = (t == null ? void 0 : t.shadowColor) ?? "", this.shadowBlur = (t == null ? void 0 : t.shadowBlur) ?? 0;
2789
2758
  }
@@ -2807,9 +2776,9 @@ class ee {
2807
2776
  }
2808
2777
  const i = s.split(/\s+/);
2809
2778
  let n = "";
2810
- for (const o of i) {
2811
- const a = n ? `${n} ${o}` : o;
2812
- t.measureText(a).width > this.width && n ? (e.push(n), n = o) : n = a;
2779
+ for (const h of i) {
2780
+ const a = n ? `${n} ${h}` : h;
2781
+ t.measureText(a).width > this.width && n ? (e.push(n), n = h) : n = a;
2813
2782
  }
2814
2783
  n && e.push(n);
2815
2784
  }
@@ -2823,8 +2792,8 @@ class ee {
2823
2792
  hitTest(t, e, s) {
2824
2793
  const i = this.wrapLines(t);
2825
2794
  if (i.length === 0) return !1;
2826
- const n = i.length * this.fontSize * this.lineHeight, o = this.width > 0 ? this.width : this._maxLineWidth(t, i);
2827
- return e >= this.x && e <= this.x + o && s >= this.y && s <= this.y + n;
2795
+ const n = i.length * this.fontSize * this.lineHeight, h = this.width > 0 ? this.width : this._maxLineWidth(t, i);
2796
+ return e >= this.x && e <= this.x + h && s >= this.y && s <= this.y + n;
2828
2797
  }
2829
2798
  _maxLineWidth(t, e) {
2830
2799
  t.font = this._font();
@@ -2842,23 +2811,34 @@ class ee {
2842
2811
  t.save(), t.globalAlpha = this.opacity, t.font = this._font(), t.fillStyle = this.color, t.textBaseline = "top", this.shadowColor && this.shadowBlur > 0 && (t.shadowColor = this.shadowColor, t.shadowBlur = this.shadowBlur);
2843
2812
  const s = this.fontSize * this.lineHeight, i = this.width > 0 ? this.width : this._maxLineWidth(t, e);
2844
2813
  for (let n = 0; n < e.length; n++) {
2845
- let o = this.x;
2846
- this.textAlign === "center" ? o = this.x + (i - t.measureText(e[n]).width) / 2 : this.textAlign === "right" && (o = this.x + i - t.measureText(e[n]).width), t.fillText(e[n], o, this.y + n * s);
2814
+ let h = this.x;
2815
+ this.textAlign === "center" ? h = this.x + (i - t.measureText(e[n]).width) / 2 : this.textAlign === "right" && (h = this.x + i - t.measureText(e[n]).width), t.fillText(e[n], h, this.y + n * s);
2847
2816
  }
2848
2817
  t.restore();
2849
2818
  }
2850
2819
  }
2851
- function Ue(r) {
2852
- return r.map instanceof c.Texture;
2820
+ function De(r) {
2821
+ return r.map instanceof o.Texture;
2822
+ }
2823
+ function qt(r, t) {
2824
+ r.traverse((e) => {
2825
+ if (!e.isMesh) return;
2826
+ const s = e, i = Array.isArray(s.material) ? s.material : [s.material];
2827
+ for (const n of i)
2828
+ De(n) && n.map.image === t && (n.map.needsUpdate = !0);
2829
+ });
2853
2830
  }
2854
- class Ye {
2831
+ function Qt(r, t) {
2832
+ t.x !== void 0 && (r.x = t.x), t.y !== void 0 && (r.y = t.y), t.width !== void 0 && (r.width = t.width), t.text !== void 0 && (r.text = t.text), t.fontFamily !== void 0 && (r.fontFamily = t.fontFamily), t.fontSize !== void 0 && (r.fontSize = t.fontSize), t.fontWeight !== void 0 && (r.fontWeight = t.fontWeight), t.fontStyle !== void 0 && (r.fontStyle = t.fontStyle), t.color !== void 0 && (r.color = t.color), t.lineHeight !== void 0 && (r.lineHeight = t.lineHeight), t.textAlign !== void 0 && (r.textAlign = t.textAlign), t.opacity !== void 0 && (r.opacity = t.opacity), t.shadowColor !== void 0 && (r.shadowColor = t.shadowColor), t.shadowBlur !== void 0 && (r.shadowBlur = t.shadowBlur);
2833
+ }
2834
+ class Ze {
2855
2835
  constructor(t) {
2856
- this.texts = [], this._textureST = new c.Vector4(1, 1, 0, 0);
2836
+ this.texts = [], this._textureST = new o.Vector4(1, 1, 0, 0);
2857
2837
  const e = (t == null ? void 0 : t.width) ?? 512, s = (t == null ? void 0 : t.height) ?? 512;
2858
2838
  this.canvas = document.createElement("canvas"), this.canvas.width = e, this.canvas.height = s;
2859
2839
  const i = this.canvas.getContext("2d");
2860
2840
  if (!i) throw new Error("TextOverlayContent: could not get 2D context");
2861
- this.ctx = i, this._source = (t == null ? void 0 : t.source) ?? null, this._texture = new c.CanvasTexture(this.canvas), this._texture.colorSpace = c.SRGBColorSpace;
2841
+ this.ctx = i, this._source = (t == null ? void 0 : t.source) ?? null, this._texture = new o.CanvasTexture(this.canvas), this._texture.colorSpace = o.SRGBColorSpace;
2862
2842
  }
2863
2843
  get texture() {
2864
2844
  return this._texture;
@@ -2875,7 +2855,7 @@ class Ye {
2875
2855
  }
2876
2856
  // ── Text API ─────────────────────────────────────────────────────────────
2877
2857
  addText(t) {
2878
- const e = new ee(t);
2858
+ const e = new jt(t);
2879
2859
  return this.texts.push(e), e;
2880
2860
  }
2881
2861
  removeText(t) {
@@ -2885,7 +2865,7 @@ class Ye {
2885
2865
  /** Update a text block by index. Only provided fields are changed. */
2886
2866
  updateText(t, e) {
2887
2867
  const s = this.texts[t];
2888
- s && (e.x !== void 0 && (s.x = e.x), e.y !== void 0 && (s.y = e.y), e.width !== void 0 && (s.width = e.width), e.text !== void 0 && (s.text = e.text), e.fontFamily !== void 0 && (s.fontFamily = e.fontFamily), e.fontSize !== void 0 && (s.fontSize = e.fontSize), e.fontWeight !== void 0 && (s.fontWeight = e.fontWeight), e.fontStyle !== void 0 && (s.fontStyle = e.fontStyle), e.color !== void 0 && (s.color = e.color), e.lineHeight !== void 0 && (s.lineHeight = e.lineHeight), e.textAlign !== void 0 && (s.textAlign = e.textAlign), e.opacity !== void 0 && (s.opacity = e.opacity), e.shadowColor !== void 0 && (s.shadowColor = e.shadowColor), e.shadowBlur !== void 0 && (s.shadowBlur = e.shadowBlur));
2868
+ s && Qt(s, e);
2889
2869
  }
2890
2870
  // ── Per-frame update ─────────────────────────────────────────────────────
2891
2871
  /**
@@ -2899,7 +2879,7 @@ class Ye {
2899
2879
  update(t) {
2900
2880
  const { ctx: e, canvas: s } = this, i = s.width, n = s.height;
2901
2881
  e.clearRect(0, 0, i, n), this._source && e.drawImage(this._source, 0, 0, i, n);
2902
- for (const o of this.texts) o.draw(e);
2882
+ for (const h of this.texts) h.draw(e);
2903
2883
  this._texture.needsUpdate = !0, t && this.syncMaterials(t);
2904
2884
  }
2905
2885
  /**
@@ -2907,12 +2887,7 @@ class Ye {
2907
2887
  * source image is this overlay's canvas.
2908
2888
  */
2909
2889
  syncMaterials(t) {
2910
- t.traverse((e) => {
2911
- if (!e.isMesh) return;
2912
- const s = e, i = Array.isArray(s.material) ? s.material : [s.material];
2913
- for (const n of i)
2914
- Ue(n) && n.map.image === this.canvas && (n.map.needsUpdate = !0);
2915
- });
2890
+ qt(t, this.canvas);
2916
2891
  }
2917
2892
  // ── IPageContent ─────────────────────────────────────────────────────────
2918
2893
  isPointOverUI(t) {
@@ -2923,15 +2898,12 @@ class Ye {
2923
2898
  setActive(t) {
2924
2899
  }
2925
2900
  dispose() {
2926
- this._texture.dispose();
2901
+ this._texture.dispose(), this.canvas.width = 0, this.canvas.height = 0;
2927
2902
  }
2928
2903
  }
2929
- function Le(r) {
2930
- return r.map instanceof c.Texture;
2931
- }
2932
- class Gt {
2904
+ class Ut {
2933
2905
  constructor(t, e) {
2934
- this._spread = t, this._textureST = e === "left" ? new c.Vector4(0.5, 1, 0, 0) : new c.Vector4(0.5, 1, 0.5, 0);
2906
+ this._spread = t, this._textureST = e === "left" ? new o.Vector4(0.5, 1, 0, 0) : new o.Vector4(0.5, 1, 0.5, 0);
2935
2907
  }
2936
2908
  get texture() {
2937
2909
  return this._spread.texture;
@@ -2947,18 +2919,18 @@ class Gt {
2947
2919
  setActive(t) {
2948
2920
  }
2949
2921
  }
2950
- function Ke(r) {
2922
+ function Ue(r) {
2951
2923
  const t = [];
2952
2924
  for (let e = 1; e + 1 < r; e += 2)
2953
2925
  t.push(e);
2954
2926
  return t;
2955
2927
  }
2956
- class Je {
2928
+ class Le {
2957
2929
  constructor(t) {
2958
2930
  this.texts = [], this.pageWidth = (t == null ? void 0 : t.pageWidth) ?? 512, this.pageHeight = (t == null ? void 0 : t.pageHeight) ?? 512, this.canvas = document.createElement("canvas"), this.canvas.width = this.pageWidth * 2, this.canvas.height = this.pageHeight;
2959
2931
  const e = this.canvas.getContext("2d");
2960
2932
  if (!e) throw new Error("SpreadContent: could not get 2D context");
2961
- this.ctx = e, this._source = (t == null ? void 0 : t.source) ?? null, this._texture = new c.CanvasTexture(this.canvas), this._texture.colorSpace = c.SRGBColorSpace, this.left = new Gt(this, "left"), this.right = new Gt(this, "right");
2933
+ this.ctx = e, this._source = (t == null ? void 0 : t.source) ?? null, this._texture = new o.CanvasTexture(this.canvas), this._texture.colorSpace = o.SRGBColorSpace, this.left = new Ut(this, "left"), this.right = new Ut(this, "right");
2962
2934
  }
2963
2935
  get texture() {
2964
2936
  return this._texture;
@@ -2972,7 +2944,7 @@ class Je {
2972
2944
  }
2973
2945
  // ── Text API ─────────────────────────────────────────────────────────────
2974
2946
  addText(t) {
2975
- const e = new ee(t);
2947
+ const e = new jt(t);
2976
2948
  return this.texts.push(e), e;
2977
2949
  }
2978
2950
  removeText(t) {
@@ -2982,7 +2954,7 @@ class Je {
2982
2954
  /** Update a text block by index. Only provided fields are changed. */
2983
2955
  updateText(t, e) {
2984
2956
  const s = this.texts[t];
2985
- s && (e.x !== void 0 && (s.x = e.x), e.y !== void 0 && (s.y = e.y), e.width !== void 0 && (s.width = e.width), e.text !== void 0 && (s.text = e.text), e.fontFamily !== void 0 && (s.fontFamily = e.fontFamily), e.fontSize !== void 0 && (s.fontSize = e.fontSize), e.fontWeight !== void 0 && (s.fontWeight = e.fontWeight), e.fontStyle !== void 0 && (s.fontStyle = e.fontStyle), e.color !== void 0 && (s.color = e.color), e.lineHeight !== void 0 && (s.lineHeight = e.lineHeight), e.textAlign !== void 0 && (s.textAlign = e.textAlign), e.opacity !== void 0 && (s.opacity = e.opacity), e.shadowColor !== void 0 && (s.shadowColor = e.shadowColor), e.shadowBlur !== void 0 && (s.shadowBlur = e.shadowBlur));
2957
+ s && Qt(s, e);
2986
2958
  }
2987
2959
  // ── Per-frame update ─────────────────────────────────────────────────────
2988
2960
  /**
@@ -2995,7 +2967,7 @@ class Je {
2995
2967
  update(t) {
2996
2968
  const { ctx: e, canvas: s } = this, i = s.width, n = s.height;
2997
2969
  e.clearRect(0, 0, i, n), this._source && e.drawImage(this._source, 0, 0, i, n);
2998
- for (const o of this.texts) o.draw(e);
2970
+ for (const h of this.texts) h.draw(e);
2999
2971
  this._texture.needsUpdate = !0, t && this.syncMaterials(t);
3000
2972
  }
3001
2973
  /**
@@ -3003,45 +2975,40 @@ class Je {
3003
2975
  * source image is this spread's canvas.
3004
2976
  */
3005
2977
  syncMaterials(t) {
3006
- t.traverse((e) => {
3007
- if (!e.isMesh) return;
3008
- const s = e, i = Array.isArray(s.material) ? s.material : [s.material];
3009
- for (const n of i)
3010
- Le(n) && n.map.image === this.canvas && (n.map.needsUpdate = !0);
3011
- });
2978
+ qt(t, this.canvas);
3012
2979
  }
3013
2980
  // ── Lifecycle ────────────────────────────────────────────────────────────
3014
2981
  dispose() {
3015
- this._texture.dispose();
2982
+ this._texture.dispose(), this.canvas.width = 0, this.canvas.height = 0;
3016
2983
  }
3017
2984
  }
3018
- const jt = 256;
3019
- function Ne(r, t, e, s, i, n, o) {
3020
- const a = t.naturalWidth || t.width, h = t.naturalHeight || t.height;
3021
- if (a <= 0 || h <= 0) return;
3022
- if (o === "fill") {
2985
+ const Lt = 256;
2986
+ function Ie(r, t, e, s, i, n, h) {
2987
+ const a = t.naturalWidth || t.width, c = t.naturalHeight || t.height;
2988
+ if (a <= 0 || c <= 0) return;
2989
+ if (h === "fill") {
3023
2990
  r.drawImage(t, e, s, i, n);
3024
2991
  return;
3025
2992
  }
3026
- const m = o === "contain" ? Math.min(i / a, n / h) : Math.max(i / a, n / h), l = a * m, d = h * m;
3027
- r.drawImage(t, e + (i - l) * 0.5, s + (n - d) * 0.5, l, d);
2993
+ const u = h === "contain" ? Math.min(i / a, n / c) : Math.max(i / a, n / c), l = a * u, _ = c * u;
2994
+ r.drawImage(t, e + (i - l) * 0.5, s + (n - _) * 0.5, l, _);
3028
2995
  }
3029
- function ts(r, t, e, s, i, n, o) {
3030
- const a = n ? Math.round(n * jt) : 512, h = o ? Math.round(o * jt) : 512, m = document.createElement("canvas");
3031
- m.width = a, m.height = h;
3032
- const l = m.getContext("2d");
3033
- if (l.fillStyle = r, l.fillRect(0, 0, a, h), e) {
3034
- const g = i ? 0 : Math.round(Math.min(a, h) * 0.11);
3035
- Ne(l, e, g, g, a - g * 2, h - g * 2, s);
2996
+ function Ee(r, t, e, s, i, n, h) {
2997
+ const a = n ? Math.round(n * Lt) : 512, c = h ? Math.round(h * Lt) : 512, u = document.createElement("canvas");
2998
+ u.width = a, u.height = c;
2999
+ const l = u.getContext("2d");
3000
+ if (l.fillStyle = r, l.fillRect(0, 0, a, c), e) {
3001
+ const d = i ? 0 : Math.round(Math.min(a, c) * 0.11);
3002
+ Ie(l, e, d, d, a - d * 2, c - d * 2, s);
3036
3003
  } else {
3037
3004
  l.fillStyle = "#333";
3038
- const g = Math.round(Math.min(a, h) * 0.094);
3039
- l.font = `bold ${g}px Arial`, l.textAlign = "center", l.textBaseline = "middle", l.fillText(t, a / 2, h / 2);
3005
+ const d = Math.round(Math.min(a, c) * 0.094);
3006
+ l.font = `bold ${d}px Arial`, l.textAlign = "center", l.textBaseline = "middle", l.fillText(t, a / 2, c / 2);
3040
3007
  }
3041
- const d = new c.CanvasTexture(m);
3042
- return d.colorSpace = c.SRGBColorSpace, d;
3008
+ const _ = new o.CanvasTexture(u);
3009
+ return _.colorSpace = o.SRGBColorSpace, _;
3043
3010
  }
3044
- async function es(r) {
3011
+ async function Ne(r) {
3045
3012
  if (!r) return null;
3046
3013
  const t = URL.createObjectURL(r), e = new Image();
3047
3014
  e.decoding = "async", e.src = t;
@@ -3054,47 +3021,47 @@ async function es(r) {
3054
3021
  }
3055
3022
  }
3056
3023
  export {
3057
- ye as AnimationCurve,
3058
- wt as AutoTurnDirection,
3059
- Me as AutoTurnMode,
3060
- ot as AutoTurnSetting,
3061
- we as AutoTurnSettingCurveTimeMode,
3062
- Ce as AutoTurnSettingMode,
3063
- Lt as AutoTurnSettings,
3064
- yt as Book,
3065
- Te as BookBinding,
3066
- Qe as BookBound,
3067
- je as BookContent,
3068
- X as BookDirection,
3069
- Xe as BookHeightException,
3070
- qe as BookPointerInteraction,
3071
- pe as BookRenderer,
3024
+ de as AnimationCurve,
3025
+ yt as AutoTurnDirection,
3026
+ mt as AutoTurnMode,
3027
+ at as AutoTurnSetting,
3028
+ _e as AutoTurnSettingCurveTimeMode,
3029
+ me as AutoTurnSettingMode,
3030
+ Ht as AutoTurnSettings,
3031
+ Ct as Book,
3032
+ pe as BookBinding,
3033
+ xe as BookBound,
3034
+ He as BookContent,
3035
+ j as BookDirection,
3036
+ fe as BookHeightException,
3037
+ Fe as BookPointerInteraction,
3038
+ le as BookRenderer,
3072
3039
  ut as Cylinder,
3073
- _e as MeshFactory,
3074
- jt as PX_PER_UNIT,
3075
- Ge as PageContent,
3076
- me as Paper,
3077
- St as PaperBorder,
3078
- At as PaperMaterialData,
3079
- Zt as PaperMeshData,
3080
- xe as PaperMeshDataPool,
3081
- Ee as PaperMeshUtility,
3082
- st as PaperNode,
3083
- ue as PaperNodeMargin,
3084
- Se as PaperPattern,
3085
- Pt as PaperSeam,
3086
- nt as PaperSetup,
3087
- pt as PaperUVMargin,
3088
- fe as RendererFactory,
3089
- Je as SpreadContent,
3090
- Nt as SpritePageContent2,
3091
- $e as StapleBookBinding,
3092
- Oe as StapleBookBound,
3093
- He as StapleSetup,
3094
- ee as TextBlock,
3095
- Ye as TextOverlayContent,
3096
- ts as createPageTexture,
3097
- Ne as drawImageWithFit,
3098
- Ke as getSpreadPairs,
3099
- es as loadImage
3040
+ ae as MeshFactory,
3041
+ Lt as PX_PER_UNIT,
3042
+ Ae as PageContent,
3043
+ re as Paper,
3044
+ Pt as PaperBorder,
3045
+ bt as PaperMaterialData,
3046
+ zt as PaperMeshData,
3047
+ ue as PaperMeshDataPool,
3048
+ ze as PaperMeshUtility,
3049
+ ht as PaperNode,
3050
+ he as PaperNodeMargin,
3051
+ ge as PaperPattern,
3052
+ wt as PaperSeam,
3053
+ rt as PaperSetup,
3054
+ gt as PaperUVMargin,
3055
+ oe as RendererFactory,
3056
+ Le as SpreadContent,
3057
+ Ft as SpritePageContent2,
3058
+ Oe as StapleBookBinding,
3059
+ be as StapleBookBound,
3060
+ Re as StapleSetup,
3061
+ jt as TextBlock,
3062
+ Ze as TextOverlayContent,
3063
+ Ee as createPageTexture,
3064
+ Ie as drawImageWithFit,
3065
+ Ue as getSpreadPairs,
3066
+ Ne as loadImage
3100
3067
  };