@objectifthunes/three-book 0.1.5 → 0.2.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.
package/dist/index.js CHANGED
@@ -30,8 +30,8 @@ class ut {
30
30
  * 3. Rotate by Y degrees around Y-axis.
31
31
  */
32
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, _ = Math.cos(n), p = Math.sin(n), d = h * _ + l * p, u = m, f = -h * p + l * _;
34
- return new c.Vector3(d, u, f);
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
35
  }
36
36
  roll(t) {
37
37
  if (this.getSide(t) >= 0) return t;
@@ -66,33 +66,33 @@ class ut {
66
66
  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
67
  }
68
68
  }
69
- function pt(r, t, e, s, i = 1 / 0, n = 1 / 60) {
69
+ function gt(r, t, e, s, i = 1 / 0, n = 1 / 60) {
70
70
  s = Math.max(s, 1e-4);
71
71
  const o = 2 / s, a = o * n, h = 1 / (1 + a + 0.48 * a * a + 0.235 * a * a * a);
72
72
  let m = r - t;
73
- const l = t, _ = i * s;
74
- m = c.MathUtils.clamp(m, -_, _), t = r - m;
75
- const p = (e + o * m) * n;
76
- e = (e - o * p) * h;
77
- let d = t + (m + p) * h;
78
- return l - r > 0 == d > l && (d = l, e = (d - l) / n), { value: d, velocity: e };
79
- }
80
- function te(r, t, e, s, i = 1 / 0, n = 1 / 60) {
81
- const o = pt(
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 ee(r, t, e, s, i = 1 / 0, n = 1 / 60) {
81
+ const o = gt(
82
82
  r.x,
83
83
  t.x,
84
84
  e.x,
85
85
  s.x,
86
86
  i,
87
87
  n
88
- ), a = pt(
88
+ ), a = gt(
89
89
  r.y,
90
90
  t.y,
91
91
  e.y,
92
92
  s.y,
93
93
  i,
94
94
  n
95
- ), h = pt(
95
+ ), h = gt(
96
96
  r.z,
97
97
  t.z,
98
98
  e.z,
@@ -102,13 +102,13 @@ function te(r, t, e, s, i = 1 / 0, n = 1 / 60) {
102
102
  );
103
103
  return e.set(o.velocity, a.velocity, h.velocity), new c.Vector3(o.value, a.value, h.value);
104
104
  }
105
- function ee(r) {
105
+ function se(r) {
106
106
  return new c.Vector3(r.x, 0, r.y);
107
107
  }
108
- function se(r) {
108
+ function ie(r) {
109
109
  return new c.Vector3(r.x, r.z, 0);
110
110
  }
111
- function kt(r, t, e) {
111
+ function vt(r, t, e) {
112
112
  const s = t * t - 4 * r * e;
113
113
  if (s < 0)
114
114
  return { rootCount: 0, root0: 0, root1: 0 };
@@ -123,45 +123,45 @@ function kt(r, t, e) {
123
123
  };
124
124
  }
125
125
  }
126
- function vt(r, t, e) {
127
- return ie(r, t, e) ? r.clone() : ne(
126
+ function kt(r, t, e) {
127
+ return ne(r, t, e) ? r.clone() : re(
128
128
  new c.Vector2(r.x, t.y),
129
129
  r,
130
130
  t,
131
131
  e
132
132
  );
133
133
  }
134
- function ie(r, t, e) {
134
+ function ne(r, t, e) {
135
135
  const s = r.x - t.x;
136
136
  let i = r.y - t.y;
137
137
  return i *= e.x / e.y, Math.sqrt(s * s + i * i) < e.x;
138
138
  }
139
- function ne(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, _ = s.y, p = 1 / (l * l), d = 1 / (_ * _);
139
+ function re(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
141
  if (Math.abs(o - h) < 1e-5) {
142
142
  if (o >= i - l && o <= i + l) {
143
- const u = kt(
144
- d,
145
- -2 * d * n,
146
- p * (o * o - 2 * i * o + i * i) + d * n * n - 1
143
+ const u = vt(
144
+ _,
145
+ -2 * _ * n,
146
+ g * (o * o - 2 * i * o + i * i) + _ * n * n - 1
147
147
  );
148
148
  if (u.rootCount === 1)
149
149
  return new c.Vector2(o, u.root0);
150
150
  if (u.rootCount === 2) {
151
- let f = u.root0, g = u.root1;
152
- return a < m && ([f, g] = [g, f]), new c.Vector2(o, g);
151
+ let f = u.root0, p = u.root1;
152
+ return a < m && ([f, p] = [p, f]), new c.Vector2(o, p);
153
153
  }
154
154
  }
155
155
  } else {
156
- const u = (m - a) / (h - o), f = a - u * o, g = f - n, w = kt(
157
- p + d * u * u,
158
- 2 * g * u * d - 2 * i * p,
159
- i * i * p + g * g * d - 1
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
160
160
  );
161
- if (w.rootCount === 1)
162
- return new c.Vector2(w.root0, u * w.root0 + f);
163
- if (w.rootCount === 2) {
164
- let B = w.root0, x = w.root1;
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, x = P.root1;
165
165
  return o < h && ([B, x] = [x, B]), new c.Vector2(x, u * x + f);
166
166
  }
167
167
  }
@@ -171,33 +171,33 @@ function bt(r, t) {
171
171
  const e = r.origin.clone().applyMatrix4(t), s = r.origin.clone().add(r.direction).applyMatrix4(t);
172
172
  return new c.Ray(e, s.sub(e));
173
173
  }
174
- function re(r) {
174
+ function oe(r) {
175
175
  return new c.Vector4(-r.x, r.y, r.z + r.x, r.w);
176
176
  }
177
- function oe(r) {
177
+ function ae(r) {
178
178
  return new c.Vector4(r.x, -r.y, r.z, r.w + r.y);
179
179
  }
180
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, ae = 1192093e-13;
182
- function _t(r) {
181
+ const Bt = Math.PI / 180, Rt = 180 / Math.PI, he = 1192093e-13;
182
+ function dt(r) {
183
183
  return r < 0 ? 0 : r > 1 ? 1 : r;
184
184
  }
185
185
  function It(r, t, e) {
186
186
  return r < t ? t : r > e ? e : r;
187
187
  }
188
188
  function mt(r, t, e) {
189
- return r !== t ? _t((e - r) / (t - r)) : 0;
189
+ return r !== t ? dt((e - r) / (t - r)) : 0;
190
190
  }
191
- function Vt(r, t, e) {
191
+ function zt(r, t, e) {
192
192
  return r + (t - r) * e;
193
193
  }
194
- function zt(r, t, e) {
194
+ function Vt(r, t, e) {
195
195
  return r + (t - r) * e;
196
196
  }
197
197
  function Dt(r, t, e) {
198
- return e = _t((e - r) / (t - r)), e * e * (3 - 2 * e);
198
+ return e = dt((e - r) / (t - r)), e * e * (3 - 2 * e);
199
199
  }
200
- class he {
200
+ class le {
201
201
  // ---- Constructor ----
202
202
  constructor(t, e, s, i) {
203
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;
@@ -313,7 +313,7 @@ class he {
313
313
  this.m_MinTurningRadius = t;
314
314
  }
315
315
  updateTurningRadius(t = 1) {
316
- let e = Math.max(this.m_Stiffness, 1 - _t(t));
316
+ let e = Math.max(this.m_Stiffness, 1 - dt(t));
317
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(
318
318
  this.m_TurningRadius,
319
319
  this.m_MinTurningRadius
@@ -351,7 +351,7 @@ class he {
351
351
  const t = new c.Vector3(0, 0, 0);
352
352
  for (const e of this.m_HandleVelocities)
353
353
  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 = Vt(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);
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 = zt(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
355
  }
356
356
  /**
357
357
  * Called each frame while the user is dragging.
@@ -375,19 +375,19 @@ class he {
375
375
  var s, i;
376
376
  let e = !1;
377
377
  if (this.m_IsAutoTurning) {
378
- let n = _t(this.m_FallTime / this.m_FallDuration);
378
+ let n = dt(this.m_FallTime / this.m_FallDuration);
379
379
  n = Dt(0, 1, n), n = Dt(0, 1, n), this.m_CurrentHandle.lerpVectors(
380
380
  this.m_StartHandle,
381
381
  this.m_EndHandle,
382
382
  this.m_IsFallingLeft ? n : 1 - n
383
- ), this.m_FallTime += t, e = Math.abs(n - 1) < ae;
383
+ ), this.m_FallTime += t, e = Math.abs(n - 1) < he;
384
384
  } else {
385
385
  const n = new c.Vector3(
386
386
  this.m_FallTime,
387
387
  0,
388
388
  this.m_FallTime * 0.75
389
389
  );
390
- this.m_CurrentHandle = te(
390
+ this.m_CurrentHandle = ee(
391
391
  this.m_CurrentHandle,
392
392
  this.m_EndHandle,
393
393
  this.m_HandleVelocity,
@@ -490,7 +490,7 @@ class he {
490
490
  ), this.m_SubMeshCount = t);
491
491
  const e = this.m_FrontContent.textureST.clone();
492
492
  let s = this.m_BackContent.textureST.clone();
493
- this.m_Book.direction > 1 ? s = oe(s) : s = re(s);
493
+ this.m_Book.direction > 1 ? s = ae(s) : s = oe(s);
494
494
  const i = this.m_FrontContent.texture, n = this.m_BackContent.texture;
495
495
  if (t === 3) {
496
496
  let o = 0, a = 1;
@@ -532,7 +532,7 @@ class he {
532
532
  const t = this.findTime(new c.Vector3(this.m_Size.x, 0, 0)), e = this.findTime(
533
533
  new c.Vector3(this.m_Size.x, 0, this.m_Size.y)
534
534
  );
535
- this.m_XTime = Vt(
535
+ this.m_XTime = zt(
536
536
  Math.min(t, e),
537
537
  Math.max(t, e),
538
538
  0.9
@@ -541,8 +541,8 @@ class he {
541
541
  new c.Vector3(s[1], 0, i[i.length - 1])
542
542
  ), h = this.rollPoint(
543
543
  new c.Vector3(s[2], 0, i[i.length - 1])
544
- ), m = o.clone().sub(n).normalize(), l = h.clone().sub(a).normalize(), _ = Rt * Math.atan2(m.y, m.x), p = Rt * Math.atan2(l.y, l.x), d = (_ + p) / 2;
545
- this.m_ZTime = d / 180;
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;
546
546
  } else
547
547
  this.m_XTime = 0, this.m_ZTime = 0;
548
548
  }
@@ -557,20 +557,20 @@ class he {
557
557
  ), l = new c.Vector2(
558
558
  0,
559
559
  h + (s.z - h) * (a / n)
560
- ), _ = new c.Vector2(i, o), p = new c.Vector2(n, a);
560
+ ), d = new c.Vector2(i, o), g = new c.Vector2(n, a);
561
561
  t.x = It(t.x, -this.m_Size.x, this.m_Size.x);
562
- const d = se(t), u = vt(
563
- new c.Vector2(d.x, d.y),
562
+ const _ = ie(t), u = kt(
563
+ new c.Vector2(_.x, _.y),
564
564
  m,
565
- _
566
- ), f = vt(
565
+ d
566
+ ), f = kt(
567
567
  new c.Vector2(u.x, u.y),
568
568
  l,
569
- p
570
- ), g = ee(
569
+ g
570
+ ), p = se(
571
571
  new c.Vector3(f.x, f.y, 0)
572
572
  );
573
- this.m_CurrentHandle.copy(g);
573
+ this.m_CurrentHandle.copy(p);
574
574
  }
575
575
  updateCylinder() {
576
576
  const t = this.m_StartHandle.clone(), e = this.m_CurrentHandle.clone(), s = t.clone().sub(e).normalize();
@@ -600,8 +600,8 @@ class he {
600
600
  startAutoTurning(t, e, s, i) {
601
601
  var m, l;
602
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 _ = this.m_Transform.scale;
604
- _.x *= -1;
603
+ const d = this.m_Transform.scale;
604
+ d.x *= -1;
605
605
  }
606
606
  this.switchMeshData(
607
607
  0
@@ -609,7 +609,7 @@ class he {
609
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
610
  const n = this.m_Size.x, o = this.m_Size.y;
611
611
  e = It(e, -0.99, 0.99);
612
- const a = zt(0.5, 1, e), h = zt(0.5, 0, e);
612
+ const a = Vt(0.5, 1, e), h = Vt(0.5, 0, e);
613
613
  this.m_StartHandle.set(n, 0, o * a), this.m_EndHandle.set(-n, 0, o * h), this.m_IsAutoTurning = !0;
614
614
  }
615
615
  // ---- Public getter for the cylinder (used by BookBound etc.) ----
@@ -696,10 +696,10 @@ const Y = class Y {
696
696
  }
697
697
  };
698
698
  Y.kMin = 0, Y.kMax = 0.25;
699
- let gt = Y;
699
+ let pt = Y;
700
700
  const U = class U {
701
701
  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 gt(), 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) ?? U.kMinSize * 2, this.height = (t == null ? void 0 : t.height) ?? U.kMinSize * 2, this.thickness = (t == null ? void 0 : t.thickness) ?? U.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);
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) ?? U.kMinSize * 2, this.height = (t == null ? void 0 : t.height) ?? U.kMinSize * 2, this.thickness = (t == null ? void 0 : t.thickness) ?? U.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
703
  }
704
704
  // ── Properties ────────────────────────────────────────────────────────
705
705
  get material() {
@@ -800,8 +800,8 @@ function Ht(r, t, e, s = new c.Vector3()) {
800
800
  i *= a, n *= a, o *= a;
801
801
  let h = e.x - r.x, m = e.y - r.y, l = e.z - r.z;
802
802
  a = 1 / Math.sqrt(h * h + m * m + l * l), h *= a, m *= a, l *= a;
803
- const _ = n * l - o * m, p = o * h - i * l, d = i * m - n * h;
804
- return a = 1 / Math.sqrt(_ * _ + p * p + d * d), s.set(_ * a, p * a, d * 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);
805
805
  }
806
806
  class st {
807
807
  constructor(t, e = !1, s = !1) {
@@ -860,12 +860,12 @@ class st {
860
860
  t.push(this.hole), this.next !== null && this.next._getHolesRecursive(t);
861
861
  }
862
862
  }
863
- class wt {
863
+ class Pt {
864
864
  constructor(t, e, s, i) {
865
865
  this.active = !0, this.prevIndex = t, this.index = e, this.nextIndex = s, this.time = i;
866
866
  }
867
867
  clone() {
868
- const t = new wt(this.prevIndex, this.index, this.nextIndex, this.time);
868
+ const t = new Pt(this.prevIndex, this.index, this.nextIndex, this.time);
869
869
  return t.active = this.active, t;
870
870
  }
871
871
  }
@@ -884,7 +884,7 @@ class Tt {
884
884
  );
885
885
  }
886
886
  }
887
- class le {
887
+ class ce {
888
888
  constructor(t, e, s) {
889
889
  const i = t.size;
890
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);
@@ -900,7 +900,7 @@ function lt(r, t, e) {
900
900
  }
901
901
  function Mt(r, t) {
902
902
  for (const e of r) {
903
- const s = e.prevNoneSeam, i = e.nextNoneSeam, n = lt(s.value, i.value, e.value), o = new wt(s.index, e.index, i.index, n);
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
904
  t.push(o);
905
905
  }
906
906
  }
@@ -908,97 +908,97 @@ function xt(r, t, e, s, i) {
908
908
  for (const n of r) {
909
909
  if (!n.active) return;
910
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], _ = t[o * e + n.index];
912
- i ? Gt(m, l, n.time, _) : _.copy(m).lerp(l, n.time);
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 ? Wt(m, l, n.time, d) : d.copy(m).lerp(l, n.time);
913
913
  }
914
914
  }
915
915
  }
916
- function Ct(r, t, e, s, i) {
916
+ function yt(r, t, e, s, i) {
917
917
  for (const n of r) {
918
918
  if (!n.active) return;
919
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], _ = t[n.index * e + o];
921
- i ? Gt(m, l, n.time, _) : _.copy(m).lerp(l, n.time);
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 ? Wt(m, l, n.time, d) : d.copy(m).lerp(l, n.time);
922
922
  }
923
923
  }
924
924
  }
925
- function Gt(r, t, e, s = new c.Vector3()) {
925
+ function Wt(r, t, e, s = new c.Vector3()) {
926
926
  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
927
  if (i === 0 || n === 0)
928
928
  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, _ = t.z / n;
930
- let p = o * m + a * l + h * _;
931
- p = Math.max(-1, Math.min(1, p));
932
- const d = Math.acos(p);
933
- if (d < 1e-6)
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)
934
934
  return s.copy(r).lerp(t, e);
935
- const u = Math.sin(d), f = Math.sin((1 - e) * d) / u, g = Math.sin(e * d) / u, w = i + (n - i) * e;
935
+ const u = Math.sin(_), f = Math.sin((1 - e) * _) / u, p = Math.sin(e * _) / u, P = i + (n - i) * e;
936
936
  return s.set(
937
- (o * f + m * g) * w,
938
- (a * f + l * g) * w,
939
- (h * f + _ * g) * w
937
+ (o * f + m * p) * P,
938
+ (a * f + l * p) * P,
939
+ (h * f + d * p) * P
940
940
  );
941
941
  }
942
942
  function qt(r, t, e, s, i) {
943
943
  for (const n of r) {
944
944
  const o = (n.endX - n.startX + 1) * 2, a = (n.endZ - n.startZ + 1) * 2, h = e.length;
945
- for (let l = 0, _ = n.endX - n.startX; l < _; l++) {
946
- const p = h + l * 2 + 0, d = h + l * 2 + 1, u = h + l * 2 + 2, f = h + l * 2 + 3;
947
- n.flip ? Ot(t, p, d, u, f, o) : Ft(t, p, d, u, f, o);
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);
948
948
  }
949
949
  if (n.left)
950
- for (let l = 0, _ = n.endZ - n.startZ; l < _; l++) {
951
- const p = h + l * 2 + 0 + o * 2, d = 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, p, d, u, f, a) : Ft(t, p, d, u, f, a);
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);
953
953
  }
954
954
  else
955
- for (let l = 0, _ = n.endZ - n.startZ; l < _; l++) {
956
- const p = h + l * 2 + 0 + o * 2 + a, d = 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, p, d, u, f) : dt(t, p, d, u, f);
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);
958
958
  }
959
959
  const m = s * i;
960
960
  for (let l = n.startX; l <= n.endX; l++) {
961
- const _ = n.startZ * s + l;
962
- e.push(e[_].clone()), e.push(e[_ + m].clone());
961
+ const d = n.startZ * s + l;
962
+ e.push(e[d].clone()), e.push(e[d + m].clone());
963
963
  }
964
964
  for (let l = n.startX; l <= n.endX; l++) {
965
- const _ = l + n.endZ * s;
966
- e.push(e[_ + m].clone()), e.push(e[_].clone());
965
+ const d = l + n.endZ * s;
966
+ e.push(e[d + m].clone()), e.push(e[d].clone());
967
967
  }
968
968
  for (let l = n.startZ; l <= n.endZ; l++) {
969
- const _ = n.startX + l * s;
970
- e.push(e[_ + m].clone()), e.push(e[_].clone());
969
+ const d = n.startX + l * s;
970
+ e.push(e[d + m].clone()), e.push(e[d].clone());
971
971
  }
972
972
  for (let l = n.startZ; l <= n.endZ; l++) {
973
- const _ = l * s + n.endX;
974
- e.push(e[_].clone()), e.push(e[_ + m].clone());
973
+ const d = l * s + n.endX;
974
+ e.push(e[d].clone()), e.push(e[d + m].clone());
975
975
  }
976
976
  }
977
977
  }
978
- function Wt(r, t, e, s, i) {
978
+ function Qt(r, t, e, s, i) {
979
979
  const n = s * i;
980
980
  let o = n * 2;
981
981
  const a = new c.Vector3();
982
982
  for (const h of r) {
983
983
  for (let m = h.startX; m <= h.endX; m++) {
984
- const l = m + h.startZ * s, _ = t[l], p = t[l + s];
985
- a.subVectors(_, p).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(_), e[o].copy(a), t[o++].copy(t[l + n]);
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
986
  }
987
987
  for (let m = h.startX; m <= h.endX; m++) {
988
- const l = m + h.endZ * s, _ = t[l + n], p = t[l + n - s];
989
- a.subVectors(_, p).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(_), e[o].copy(a), t[o++].copy(t[l]);
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
990
  }
991
991
  for (let m = h.startZ; m <= h.endZ; m++) {
992
- const l = m * s + h.startX, _ = t[l + n], p = t[l + n + 1];
993
- a.subVectors(_, p).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(_), e[o].copy(a), t[o++].copy(t[l]);
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
994
  }
995
995
  for (let m = h.startZ; m <= h.endZ; m++) {
996
- const l = m * s + h.endX, _ = t[l], p = t[l - 1];
997
- a.subVectors(_, p).normalize(), h.flip && a.multiplyScalar(-1), e[o].copy(a), t[o++].copy(_), e[o].copy(a), t[o++].copy(t[l + n]);
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]);
998
998
  }
999
999
  }
1000
1000
  }
1001
- function ce(r, t, e, s, i) {
1001
+ function me(r, t, e, s, i) {
1002
1002
  const n = [];
1003
1003
  for (const o of r) {
1004
1004
  for (let a = o.startX; a < o.endX; a++) {
@@ -1010,50 +1010,50 @@ function ce(r, t, e, s, i) {
1010
1010
  n.push([m, l]);
1011
1011
  }
1012
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), _ = t[m].clone().applyMatrix4(i);
1014
- n.push([l, _]);
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
1015
  }
1016
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), _ = t[m].clone().applyMatrix4(i);
1018
- n.push([l, _]);
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]);
1019
1019
  }
1020
1020
  }
1021
1021
  return n;
1022
1022
  }
1023
1023
  function Ft(r, t, e, s, i, n) {
1024
- dt(r, t, e, s, i), t += n, e += n, s += n, i += n, dt(r, t, e, s, i);
1024
+ _t(r, t, e, s, i), t += n, e += n, s += n, i += n, _t(r, t, e, s, i);
1025
1025
  }
1026
1026
  function Ot(r, t, e, s, i, n) {
1027
1027
  ft(r, t, e, s, i), t += n, e += n, s += n, i += n, ft(r, t, e, s, i);
1028
1028
  }
1029
- function Qt(r, t, e, s, i, n, o) {
1030
- dt(r, e, s, i, n), e += o, s += o, i += o, n += o, ft(t, e, s, i, n);
1029
+ function $t(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);
1031
1031
  }
1032
- function $t(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, _ = e.length;
1032
+ function Yt(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;
1034
1034
  if (n > 1)
1035
- for (let d = 0; d < _; d++)
1035
+ for (let _ = 0; _ < d; _++)
1036
1036
  for (let u = 0; u < l; u++) {
1037
- const f = lt(a, o, t[u]), g = lt(m, h, e[d]);
1038
- r.push(new c.Vector2(g, f));
1037
+ const f = lt(a, o, t[u]), p = lt(m, h, e[_]);
1038
+ r.push(new c.Vector2(p, f));
1039
1039
  }
1040
1040
  else
1041
- for (let d = 0; d < _; d++)
1041
+ for (let _ = 0; _ < d; _++)
1042
1042
  for (let u = 0; u < l; u++) {
1043
- const f = lt(o, a, t[u]), g = lt(m, h, e[d]);
1044
- r.push(new c.Vector2(f, g));
1043
+ const f = lt(o, a, t[u]), p = lt(m, h, e[_]);
1044
+ r.push(new c.Vector2(f, p));
1045
1045
  }
1046
- const p = r.length;
1047
- for (let d = 0; d < p; d++)
1048
- r.push(r[d].clone());
1046
+ const g = r.length;
1047
+ for (let _ = 0; _ < g; _++)
1048
+ r.push(r[_].clone());
1049
1049
  }
1050
- function dt(r, t, e, s, i) {
1050
+ function _t(r, t, e, s, i) {
1051
1051
  r.push(t), r.push(s), r.push(e), r.push(e), r.push(s), r.push(i);
1052
1052
  }
1053
1053
  function ft(r, t, e, s, i) {
1054
1054
  r.push(t), r.push(e), r.push(s), r.push(e), r.push(i), r.push(s);
1055
1055
  }
1056
- function Yt(r, t, e, s) {
1056
+ function Kt(r, t, e, s) {
1057
1057
  const i = [];
1058
1058
  for (let n = 0; n < e - 1; n++)
1059
1059
  for (let o = 0; o < t - 1; o++) {
@@ -1062,17 +1062,17 @@ function Yt(r, t, e, s) {
1062
1062
  }
1063
1063
  return i;
1064
1064
  }
1065
- const Fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1065
+ const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1066
1066
  __proto__: null,
1067
1067
  addBorders: qt,
1068
- addFrontAndBackFaces: Qt,
1069
- addFrontAndBackTexcoords: $t,
1070
- debugDrawBorders: ce,
1071
- drawWireframe: Yt,
1068
+ addFrontAndBackFaces: $t,
1069
+ addFrontAndBackTexcoords: Yt,
1070
+ debugDrawBorders: me,
1071
+ drawWireframe: Kt,
1072
1072
  seamNodesToSeams: Mt,
1073
- updateBorders: Wt,
1073
+ updateBorders: Qt,
1074
1074
  updateXSeams: xt,
1075
- updateZSeams: Ct
1075
+ updateZSeams: yt
1076
1076
  }, Symbol.toStringTag, { value: "Module" }));
1077
1077
  class Zt {
1078
1078
  get geometry() {
@@ -1150,37 +1150,37 @@ class Zt {
1150
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
1151
  for (let u = 0; u < a; u++)
1152
1152
  s[u].set(0, 0, 0);
1153
- xt(this.m_Pattern.xSeams, t, n, o, !1), Ct(this.m_Pattern.zSeams, t, n, o, !1);
1153
+ xt(this.m_Pattern.xSeams, t, n, o, !1), yt(this.m_Pattern.zSeams, t, n, o, !1);
1154
1154
  for (let u = 0; u < o - 1; u++) {
1155
1155
  const f = u + 1;
1156
- for (let g = 0; g < n - 1; g++) {
1157
- const w = g + 1, B = u * n + g, x = u * n + w, y = f * n + g, S = f * n + w, v = t[B], O = t[x], Z = t[y], z = t[S];
1158
- Ht(v, Z, O, h), Ht(z, O, Z, m), l.addVectors(h, m), s[B].add(l), s[x].add(l), s[y].add(l), s[S].add(l);
1156
+ for (let p = 0; p < n - 1; p++) {
1157
+ const P = p + 1, B = u * n + p, x = u * n + P, w = f * n + p, S = f * n + P, k = t[B], O = t[x], Z = t[w], V = t[S];
1158
+ Ht(k, Z, O, h), Ht(V, O, Z, m), l.addVectors(h, m), s[B].add(l), s[x].add(l), s[w].add(l), s[S].add(l);
1159
1159
  }
1160
1160
  }
1161
1161
  for (let u = 0; u < a; u++)
1162
1162
  s[u].divideScalar(i[u]).normalize();
1163
- xt(this.m_Pattern.xSeams, s, n, o, !0), Ct(this.m_Pattern.zSeams, s, n, o, !0);
1164
- const _ = this.m_Pattern.thickness / 2;
1163
+ xt(this.m_Pattern.xSeams, s, n, o, !0), yt(this.m_Pattern.zSeams, s, n, o, !0);
1164
+ const d = this.m_Pattern.thickness / 2;
1165
1165
  for (let u = 0; u < a; u++) {
1166
1166
  const f = s[u];
1167
1167
  s[u + a].copy(f).negate();
1168
- const g = t[u];
1169
- e[u].copy(g).addScaledVector(f, _), e[u + a].copy(g).addScaledVector(f, -_);
1168
+ const p = t[u];
1169
+ e[u].copy(p).addScaledVector(f, d), e[u + a].copy(p).addScaledVector(f, -d);
1170
1170
  }
1171
- Wt(this.m_Pattern.borders, e, s, n, o);
1172
- const p = this.m_Geometry.getAttribute(
1171
+ Qt(this.m_Pattern.borders, e, s, n, o);
1172
+ const g = this.m_Geometry.getAttribute(
1173
1173
  "position"
1174
- ), d = this.m_Geometry.getAttribute(
1174
+ ), _ = this.m_Geometry.getAttribute(
1175
1175
  "normal"
1176
1176
  );
1177
1177
  for (let u = 0; u < e.length; u++) {
1178
1178
  const f = e[u];
1179
- p.setXYZ(u, f.x, f.y, f.z);
1180
- const g = s[u];
1181
- d.setXYZ(u, g.x, g.y, g.z);
1179
+ g.setXYZ(u, f.x, f.y, f.z);
1180
+ const p = s[u];
1181
+ _.setXYZ(u, p.x, p.y, p.z);
1182
1182
  }
1183
- p.needsUpdate = !0, d.needsUpdate = !0, this.m_Geometry.computeBoundingBox(), this.m_Geometry.computeBoundingSphere();
1183
+ g.needsUpdate = !0, _.needsUpdate = !0, this.m_Geometry.computeBoundingBox(), this.m_Geometry.computeBoundingSphere();
1184
1184
  }
1185
1185
  // ── DrawWireframe (debug) ──────────────────────────────────────────────
1186
1186
  /**
@@ -1190,10 +1190,10 @@ class Zt {
1190
1190
  */
1191
1191
  drawWireframe(t) {
1192
1192
  const e = this.m_Pattern.baseXArray.length, s = this.m_Pattern.baseZArray.length;
1193
- return Yt(this.m_Vertices, e, s, t);
1193
+ return Kt(this.m_Vertices, e, s, t);
1194
1194
  }
1195
1195
  }
1196
- class me {
1196
+ class ue {
1197
1197
  constructor() {
1198
1198
  this.m_UsedMeshs = [], this.m_FreeMeshs = [], this.m_Meshs = /* @__PURE__ */ new Set();
1199
1199
  }
@@ -1212,7 +1212,7 @@ class me {
1212
1212
  this.m_Meshs.clear();
1213
1213
  }
1214
1214
  }
1215
- class ue {
1215
+ class de {
1216
1216
  constructor(t) {
1217
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
1218
  }
@@ -1224,7 +1224,7 @@ class ue {
1224
1224
  }
1225
1225
  get(t) {
1226
1226
  let e;
1227
- return this.m_FreeRenderers.length > 0 ? (e = this.m_FreeRenderers.pop(), e.createCollider = this.m_CreateMeshCollider, e.reset(t)) : (e = new de(this.m_Root, t, this.m_CreateMeshCollider), this.m_Renderers.add(e)), this.m_UsedRenderers.push(e), this.m_Ids.push(e.id), e;
1227
+ return this.m_FreeRenderers.length > 0 ? (e = this.m_FreeRenderers.pop(), e.createCollider = this.m_CreateMeshCollider, e.reset(t)) : (e = new fe(this.m_Root, t, this.m_CreateMeshCollider), this.m_Renderers.add(e)), this.m_UsedRenderers.push(e), this.m_Ids.push(e.id), e;
1228
1228
  }
1229
1229
  recycle() {
1230
1230
  for (const t of this.m_UsedRenderers)
@@ -1245,7 +1245,7 @@ class ue {
1245
1245
  }
1246
1246
  }
1247
1247
  let _e = 1;
1248
- class de {
1248
+ class fe {
1249
1249
  constructor(t, e, s) {
1250
1250
  this.m_Visibility = !0, this.m_PropertyBlocks = /* @__PURE__ */ new Map(), this.m_MaterialTextures = /* @__PURE__ */ new Map(), this.m_Id = _e++, this.m_Object3D = new c.Object3D(), this.m_Object3D.name = e, this.m_Mesh = new c.Mesh(
1251
1251
  new c.BufferGeometry(),
@@ -1351,7 +1351,7 @@ class de {
1351
1351
  e.dispose();
1352
1352
  }
1353
1353
  }
1354
- class fe {
1354
+ class ge {
1355
1355
  constructor(t, e, s = !1) {
1356
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());
1357
1357
  }
@@ -1363,8 +1363,8 @@ class fe {
1363
1363
  this.m_Stack.push(t);
1364
1364
  }
1365
1365
  }
1366
- var yt = /* @__PURE__ */ ((r) => (r[r.Next = 0] = "Next", r[r.Back = 1] = "Back", r))(yt || {}), pe = /* @__PURE__ */ ((r) => (r[r.Surface = 0] = "Surface", r[r.Edge = 1] = "Edge", r))(pe || {}), ge = /* @__PURE__ */ ((r) => (r[r.Constant = 0] = "Constant", r[r.RandomBetweenTwoConstants = 1] = "RandomBetweenTwoConstants", r[r.Curve = 2] = "Curve", r[r.RandomBetweenTwoCurves = 3] = "RandomBetweenTwoCurves", r))(ge || {}), Me = /* @__PURE__ */ ((r) => (r[r.PaperIndexTime = 0] = "PaperIndexTime", r[r.TurnIndexTime = 1] = "TurnIndexTime", r))(Me || {});
1367
- class xe {
1366
+ var wt = /* @__PURE__ */ ((r) => (r[r.Next = 0] = "Next", r[r.Back = 1] = "Back", r))(wt || {}), pe = /* @__PURE__ */ ((r) => (r[r.Surface = 0] = "Surface", r[r.Edge = 1] = "Edge", r))(pe || {}), 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 || {}), xe = /* @__PURE__ */ ((r) => (r[r.PaperIndexTime = 0] = "PaperIndexTime", r[r.TurnIndexTime = 1] = "TurnIndexTime", r))(xe || {});
1367
+ class ye {
1368
1368
  constructor(t) {
1369
1369
  this.keys = t ? t.map((e) => ({ time: e.time, value: e.value })) : [];
1370
1370
  }
@@ -1389,10 +1389,10 @@ class xe {
1389
1389
  function nt(r, t, e) {
1390
1390
  return Math.max(t, Math.min(e, r));
1391
1391
  }
1392
- function Ce(r, t, e) {
1392
+ function we(r, t, e) {
1393
1393
  return r === t ? 0 : nt((e - r) / (t - r), 0, 1);
1394
1394
  }
1395
- function Nt(r, t) {
1395
+ function Lt(r, t) {
1396
1396
  return r + Math.random() * (t - r);
1397
1397
  }
1398
1398
  class rt {
@@ -1463,12 +1463,12 @@ class rt {
1463
1463
  getValue(t, e) {
1464
1464
  if (this.m_Mode === 0) return this.m_Constant;
1465
1465
  if (this.m_Mode === 1)
1466
- return Nt(this.m_ConstantMin, this.m_ConstantMax);
1466
+ return Lt(this.m_ConstantMin, this.m_ConstantMax);
1467
1467
  const s = this.m_CurveTimeMode === 0 ? t : e;
1468
1468
  if (this.m_Mode === 2)
1469
1469
  return this.m_Curve.evaluate(s);
1470
1470
  if (this.m_Mode === 3)
1471
- return Nt(
1471
+ return Lt(
1472
1472
  this.m_CurveMin.evaluate(s),
1473
1473
  this.m_CurveMax.evaluate(s)
1474
1474
  );
@@ -1488,9 +1488,9 @@ class rt {
1488
1488
  }
1489
1489
  for (let h = 0; h < n; h++) {
1490
1490
  let m = i[h].time, l = i[h].value;
1491
- m = Ce(o, a, m), l = nt(l, e, s), i[h].time = m, i[h].value = l;
1491
+ m = we(o, a, m), l = nt(l, e, s), i[h].time = m, i[h].value = l;
1492
1492
  }
1493
- return new xe(i);
1493
+ return new ye(i);
1494
1494
  }
1495
1495
  // ── Value-type clone ────────────────────────────────────────────────────
1496
1496
  clone() {
@@ -1567,7 +1567,7 @@ const R = class R {
1567
1567
  }
1568
1568
  };
1569
1569
  R.kMinTwist = -1, R.kMaxTwist = 1, R.kMinBend = 0, R.kMaxBend = 1, R.kMinDuration = 0, R.kMaxDuration = 5;
1570
- let Lt = R, Oe = class extends Error {
1570
+ let Nt = R, Ue = class extends Error {
1571
1571
  constructor() {
1572
1572
  super(
1573
1573
  "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."
@@ -1768,8 +1768,8 @@ const ot = class ot extends c.Group {
1768
1768
  const n = typeof i == "number" ? new rt(i) : i;
1769
1769
  if (s = Math.min(s, this.getMaxAutoTurnCount(t)), s === 0) return !1;
1770
1770
  for (let o = 0; o < s && this.canAutoTurn(t); o++) {
1771
- const a = o / (s - 1 || 1), h = this.getAutoTurnPaperIndexTime(t), m = o > 0 ? n.getValue(h, a) : 0, l = e.getModeValue(), _ = e.getTwistValue(h, a), p = e.getBendValue(h, a), d = e.getDurationValue(h, a);
1772
- this.m_AutoTurnQueue.push({ direction: t, mode: l, twist: _, bend: p, duration: d, delay: m });
1771
+ 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);
1772
+ this.m_AutoTurnQueue.push({ direction: t, mode: l, twist: d, bend: g, duration: _, delay: m });
1773
1773
  }
1774
1774
  return this.m_AutoTurnTimer = 0, !0;
1775
1775
  }
@@ -1797,7 +1797,7 @@ const ot = class ot extends c.Group {
1797
1797
  if (this.isTurning) return null;
1798
1798
  const e = this.getFrontPapers();
1799
1799
  if (e.length > 0) {
1800
- const s = t === yt.Next, i = e[s ? e.length - 1 : 0];
1800
+ const s = t === wt.Next, i = e[s ? e.length - 1 : 0];
1801
1801
  if (!i.isTurning && !i.isFalling && s === i.isOnRightStack)
1802
1802
  return i;
1803
1803
  }
@@ -1807,7 +1807,7 @@ const ot = class ot extends c.Group {
1807
1807
  const e = this.getAutoTurnPaper(t);
1808
1808
  if (e === null) return 0;
1809
1809
  let s = 1;
1810
- return t === yt.Next ? s += this.m_Papers.length - e.index - 1 : s += e.index, s;
1810
+ return t === wt.Next ? s += this.m_Papers.length - e.index - 1 : s += e.index, s;
1811
1811
  }
1812
1812
  canAutoTurn(t) {
1813
1813
  return this.getAutoTurnPaper(t) !== null;
@@ -1842,9 +1842,9 @@ const ot = class ot extends c.Group {
1842
1842
  // ── Build ─────────────────────────────────────────────────────────────
1843
1843
  build() {
1844
1844
  if (this.clear(), this.m_Content === null || this.m_Content.isEmpty || this.m_Binding === null) return;
1845
- if (this.m_MeshFactory === null && (this.m_MeshFactory = new me()), this.m_RendererFactory === null) {
1846
- const C = new c.Object3D();
1847
- C.name = "Root", this.add(C), this.m_Root = C, this.m_RendererFactory = new ue(this.m_Root);
1845
+ if (this.m_MeshFactory === null && (this.m_MeshFactory = new ue()), this.m_RendererFactory === null) {
1846
+ const y = new c.Object3D();
1847
+ y.name = "Root", this.add(y), this.m_Root = y, this.m_RendererFactory = new de(this.m_Root);
1848
1848
  }
1849
1849
  this.m_RendererFactory.createColliders = this.m_CreateColliders, this.m_Direction = this.m_Content.direction;
1850
1850
  const t = this.m_Direction > 1 ? Math.PI / 2 : 0;
@@ -1854,31 +1854,31 @@ const ot = class ot extends c.Group {
1854
1854
  let i = this.m_Content.coverContents, n = this.m_Content.pageContents, o = this.m_InitialOpenProgress;
1855
1855
  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);
1856
1856
  const a = this.m_CoverPaperCount + this.m_PagePaperCount, h = Math.floor(i.length / 4);
1857
- let m = 0, l = 0, _ = 0;
1857
+ let m = 0, l = 0, d = 0;
1858
1858
  this.m_Papers = new Array(a);
1859
- for (let C = 0; C < a; C++) {
1860
- const I = this.m_HasCover && (C < h || C >= a - h), L = this.m_RendererFactory.get("Paper"), k = this.m_Papers[C] = new he(I, C, this, L);
1861
- k.renderer.castShadows = this.m_CastShadows, C < Math.round(c.MathUtils.lerp(0, a, o)) && (k.transform.scale.set(-1, 1, 1), k.setTime(1)), I ? (k.setContentData(i[l++], i[l++], C > h), k.setMaterialData(e), k.setPaperSetup(this.m_CoverPaperSetup)) : (k.setContentData(n[m++], n[m++]), k.setMaterialData(s), k.setPaperSetup(this.m_PagePaperSetup)), _ += k.thickness;
1859
+ for (let y = 0; y < a; y++) {
1860
+ const I = this.m_HasCover && (y < h || y >= a - h), N = this.m_RendererFactory.get("Paper"), v = this.m_Papers[y] = new le(I, y, this, N);
1861
+ v.renderer.castShadows = this.m_CastShadows, y < Math.round(c.MathUtils.lerp(0, a, o)) && (v.transform.scale.set(-1, 1, 1), v.setTime(1)), I ? (v.setContentData(i[l++], i[l++], y > 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;
1862
1862
  }
1863
- this.m_TotalThickness = _;
1864
- const p = this.m_Papers[0].thickness, d = this.m_Papers[Math.floor(a / 2)].thickness;
1865
- this.m_MinPaperThickness = Math.min(p, d), this.m_MaxPaperThickness = Math.max(p, d);
1863
+ this.m_TotalThickness = d;
1864
+ const g = this.m_Papers[0].thickness, _ = this.m_Papers[Math.floor(a / 2)].thickness;
1865
+ this.m_MinPaperThickness = Math.min(g, _), this.m_MaxPaperThickness = Math.max(g, _);
1866
1866
  const u = this.m_Papers[0].size.x, f = this.m_Papers[Math.floor(a / 2)].size.x;
1867
1867
  this.m_MinPaperWidth = Math.min(u, f);
1868
- const g = this.m_Papers[0].size.y, w = this.m_Papers[Math.floor(a / 2)].size.y;
1869
- this.m_MinPaperHeight = Math.min(g, w), this.m_Bound = this.m_Binding.createBound(
1868
+ const p = this.m_Papers[0].size.y, P = this.m_Papers[Math.floor(a / 2)].size.y;
1869
+ this.m_MinPaperHeight = Math.min(p, P), this.m_Bound = this.m_Binding.createBound(
1870
1870
  this,
1871
1871
  this.m_Root,
1872
1872
  this.m_RendererFactory,
1873
1873
  this.m_MeshFactory
1874
1874
  ), this.m_Bound.binderRenderer.setVisibility(!this.m_HideBinder);
1875
- const B = this.m_ReduceOverdraw && n.length > 0, x = this.m_ReduceSubMeshes, y = this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, x), S = B ? this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, x, !0) : null, v = 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, N = z + 1, D = this.m_Bound.constructor.name.includes("Staple");
1876
- for (let C = 0; C < a; C++) {
1877
- const I = this.m_Papers[C];
1878
- C !== 0 && (I.prev = this.m_Papers[C - 1]), C !== a - 1 && (I.next = this.m_Papers[C + 1]), I.noHole = D && (C === z || C === N), I.isCover ? I.setMeshData(O.get(), null, Z) : I.setMeshData(
1879
- y.get(),
1875
+ const B = this.m_ReduceOverdraw && n.length > 0, x = this.m_ReduceSubMeshes, w = this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, x), S = B ? this.createPaperMeshDataPool(this.m_PagePaperSetup, !0, x, !0) : null, k = this.createPaperMeshDataPool(this.m_PagePaperSetup, !1), O = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !0), Z = this.createPaperMeshDataPool(this.m_CoverPaperSetup, !1), V = Math.floor(a / 2) - 1, L = V + 1, D = this.m_Bound.constructor.name.includes("Staple");
1876
+ for (let y = 0; y < a; y++) {
1877
+ const I = this.m_Papers[y];
1878
+ y !== 0 && (I.prev = this.m_Papers[y - 1]), y !== a - 1 && (I.next = this.m_Papers[y + 1]), I.noHole = D && (y === V || y === L), I.isCover ? I.setMeshData(O.get(), null, Z) : I.setMeshData(
1879
+ w.get(),
1880
1880
  (S == null ? void 0 : S.get()) ?? null,
1881
- v
1881
+ k
1882
1882
  );
1883
1883
  }
1884
1884
  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;
@@ -1898,7 +1898,7 @@ const ot = class ot extends c.Group {
1898
1898
  i,
1899
1899
  s
1900
1900
  );
1901
- return new fe(
1901
+ return new ge(
1902
1902
  this.m_MeshFactory,
1903
1903
  o,
1904
1904
  e && this.m_Bound.useSharedMeshDataForLowpoly
@@ -1953,13 +1953,13 @@ const ot = class ot extends c.Group {
1953
1953
  }
1954
1954
  };
1955
1955
  ot.s_Instances = /* @__PURE__ */ new Set();
1956
- let Pt = ot;
1957
- class ye {
1956
+ let Ct = ot;
1957
+ class Ce {
1958
1958
  constructor() {
1959
1959
  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;
1960
1960
  }
1961
1961
  }
1962
- class Ne {
1962
+ class Xe {
1963
1963
  constructor() {
1964
1964
  this.m_BookContent = null, this.m_IsActive = !1, this.onActiveChangedCallback = null;
1965
1965
  }
@@ -2012,7 +2012,7 @@ class Ut {
2012
2012
  setActive(t) {
2013
2013
  }
2014
2014
  }
2015
- class Le {
2015
+ class je {
2016
2016
  constructor() {
2017
2017
  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;
2018
2018
  }
@@ -2113,14 +2113,14 @@ class Le {
2113
2113
  return !this.isCoverPaperSideIndex(t);
2114
2114
  }
2115
2115
  }
2116
- class Ue {
2116
+ class Ge {
2117
2117
  constructor(t, e) {
2118
2118
  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) => {
2119
2119
  var n;
2120
2120
  if (!this.enabled || s.button !== 0) return;
2121
2121
  this.m_IsPointerDown = !0;
2122
2122
  const i = this.m_GetRay(s);
2123
- for (const o of Pt.instances)
2123
+ for (const o of Ct.instances)
2124
2124
  if (o.startTurning(i)) {
2125
2125
  this.m_SelectedBook = o, (n = this.onTurnStart) == null || n.call(this, o);
2126
2126
  break;
@@ -2142,7 +2142,7 @@ class Ue {
2142
2142
  }
2143
2143
  class Pe {
2144
2144
  }
2145
- class Ee {
2145
+ class We {
2146
2146
  constructor(t, e) {
2147
2147
  this.m_Book = t, this.m_Root = e;
2148
2148
  }
@@ -2158,21 +2158,21 @@ function Et(r, t, e, s) {
2158
2158
  function Xt(r, t) {
2159
2159
  return r++, r === t ? 0 : r;
2160
2160
  }
2161
- function we(r, t) {
2161
+ function Te(r, t) {
2162
2162
  return r === 0 ? t - 1 : r - 1;
2163
2163
  }
2164
- const Te = 0.01, Se = 0.1, ke = 0.04, ve = 0.4, be = 2, Be = 10, Re = 0, Ie = 5;
2164
+ const Se = 0.01, ve = 0.1, ke = 0.04, be = 0.4, Be = 2, Re = 10, Ie = 0, ze = 5;
2165
2165
  function et(r, t, e) {
2166
2166
  return Math.max(t, Math.min(e, r));
2167
2167
  }
2168
- function Kt(r) {
2168
+ function Jt(r) {
2169
2169
  return Math.max(0, Math.min(1, r));
2170
2170
  }
2171
2171
  function F(r, t, e) {
2172
2172
  return r + (t - r) * e;
2173
2173
  }
2174
2174
  function jt(r, t, e) {
2175
- return r === t ? 0 : Kt((e - r) / (t - r));
2175
+ return r === t ? 0 : Jt((e - r) / (t - r));
2176
2176
  }
2177
2177
  function Ve(r, t) {
2178
2178
  const e = r.clone().normalize();
@@ -2187,7 +2187,7 @@ function Ve(r, t) {
2187
2187
  return new c.Quaternion().setFromRotationMatrix(n);
2188
2188
  }
2189
2189
  const tt = Math.PI / 180, it = 180 / Math.PI;
2190
- class ze {
2190
+ class De {
2191
2191
  constructor() {
2192
2192
  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;
2193
2193
  }
@@ -2207,43 +2207,43 @@ class ze {
2207
2207
  return this._thickness;
2208
2208
  }
2209
2209
  set thickness(t) {
2210
- this._thickness = et(t, Te, Se);
2210
+ this._thickness = et(t, Se, ve);
2211
2211
  }
2212
2212
  get margin() {
2213
2213
  return this._margin;
2214
2214
  }
2215
2215
  set margin(t) {
2216
- this._margin = Kt(t);
2216
+ this._margin = Jt(t);
2217
2217
  }
2218
2218
  get crown() {
2219
2219
  return this._crown;
2220
2220
  }
2221
2221
  set crown(t) {
2222
- this._crown = et(t, ke, ve);
2222
+ this._crown = et(t, ke, be);
2223
2223
  }
2224
2224
  get count() {
2225
2225
  return this._count;
2226
2226
  }
2227
2227
  set count(t) {
2228
- this._count = et(t, be, Be);
2228
+ this._count = et(t, Be, Re);
2229
2229
  }
2230
2230
  get quality() {
2231
2231
  return this._quality;
2232
2232
  }
2233
2233
  set quality(t) {
2234
- this._quality = et(t, Re, Ie);
2234
+ this._quality = et(t, Ie, ze);
2235
2235
  }
2236
2236
  }
2237
- class De extends Error {
2237
+ class Ae extends Error {
2238
2238
  constructor() {
2239
2239
  super("Book height is too large relative to paper width."), this.name = "BookHeightException";
2240
2240
  }
2241
2241
  }
2242
- class Ae {
2242
+ class He {
2243
2243
  // ── Constructor ────────────────────────────────────────────────────────
2244
2244
  constructor(t, e, s, i, n) {
2245
2245
  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)
2246
- throw new De();
2246
+ throw new Ae();
2247
2247
  const o = this.m_Book.coverPaperSetup, a = this.m_Book.pagePaperSetup, h = new c.BufferGeometry();
2248
2248
  this.updateStapleMesh(e, h);
2249
2249
  const m = n ?? new c.MeshStandardMaterial({
@@ -2258,14 +2258,14 @@ class Ae {
2258
2258
  );
2259
2259
  let l = o.thickness;
2260
2260
  l = Math.max(this.m_BindingRadius, l);
2261
- for (const _ of this.m_Book.papers) {
2262
- const p = _.size.clone();
2263
- p.x -= this.m_BindingRadius, _.sizeXOffset = this.m_BindingRadius, _.size = p, _.setMinTurningRadius(l), _.updateTurningRadius(), this.updatePaperPosition(_);
2261
+ for (const d of this.m_Book.papers) {
2262
+ const g = d.size.clone();
2263
+ g.x -= this.m_BindingRadius, d.sizeXOffset = this.m_BindingRadius, d.size = g, d.setMinTurningRadius(l), d.updateTurningRadius(), this.updatePaperPosition(d);
2264
2264
  }
2265
2265
  this.updateRootPosition();
2266
2266
  }
2267
2267
  get binderRenderer() {
2268
- return this._binderRendererAdapter || (this._binderRendererAdapter = new He(this.stapleMesh)), this._binderRendererAdapter;
2268
+ return this._binderRendererAdapter || (this._binderRendererAdapter = new Fe(this.stapleMesh)), this._binderRendererAdapter;
2269
2269
  }
2270
2270
  // ── updateStapleMesh ──────────────────────────────────────────────────
2271
2271
  updateStapleMesh(t, e) {
@@ -2281,83 +2281,83 @@ class Ae {
2281
2281
  let a = t.count, h = (o - s * a) / (a - 1);
2282
2282
  for (h = Math.max(h, 0); h < this.m_StapleThickness * 2 && a > 2; )
2283
2283
  a--, h = (o - s * a) / (a - 1), h = Math.max(h, 0);
2284
- const m = t.quality / 5, l = Math.floor(F(4, 20, m)), _ = Math.floor(F(4, 10, m)), p = Math.floor(F(3, 10, m)), d = this.m_StapleThickness / 2, u = d * 2.5, f = 0.9, g = d * 1;
2285
- let w = s / 2 * f;
2286
- w = Math.max(w, g * 2);
2284
+ 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;
2285
+ let P = s / 2 * f;
2286
+ P = Math.max(P, p * 2);
2287
2287
  let B = 0;
2288
- B += this.m_Book.totalThickness / 2, B += d;
2289
- const x = -(this.m_Book.papers[0].thickness / 2 + d), y = [];
2288
+ B += this.m_Book.totalThickness / 2, B += _;
2289
+ const x = -(this.m_Book.papers[0].thickness / 2 + _), w = [];
2290
2290
  {
2291
- for (let V = 0; V < _; V++) {
2292
- const E = V / (_ - 1), W = F(-90, -180, E) * tt, P = new c.Vector3(
2293
- g * Math.sin(W),
2291
+ for (let z = 0; z < d; z++) {
2292
+ const E = z / (d - 1), q = F(-90, -180, E) * tt, C = new c.Vector3(
2293
+ p * Math.sin(q),
2294
2294
  0,
2295
- g * Math.cos(W)
2295
+ p * Math.cos(q)
2296
2296
  );
2297
- P.x += g, P.z += g, P.x += x, y.push(P);
2297
+ C.x += p, C.z += p, C.x += x, w.push(C);
2298
2298
  }
2299
- const M = new c.Vector3(B, 0, 0), H = new c.Vector3(B + u * 0.75, 0, 0), T = new c.Vector3(B - d * 0.5, 0, w);
2300
- for (let V = 0; V < p; V++) {
2301
- const E = V / (p - 1), q = Et(M, H, T, E);
2302
- q.x += x, y.push(q);
2299
+ const M = new c.Vector3(B, 0, 0), H = new c.Vector3(B + u * 0.75, 0, 0), T = new c.Vector3(B - _ * 0.5, 0, P);
2300
+ for (let z = 0; z < g; z++) {
2301
+ const E = z / (g - 1), W = Et(M, H, T, E);
2302
+ W.x += x, w.push(W);
2303
2303
  }
2304
- y.reverse();
2304
+ w.reverse();
2305
2305
  }
2306
2306
  const S = new Array(l);
2307
2307
  for (let M = 0; M < l; M++) {
2308
2308
  const T = (90 - M * (360 / l)) * tt;
2309
2309
  S[M] = new c.Vector3(Math.cos(T), Math.sin(T), 0), S[M].x *= 0.75;
2310
2310
  }
2311
- const v = y.length, O = v * l, Z = new Array(O * 2), z = new Array(O * 2), N = new Array(
2311
+ const k = w.length, O = k * l, Z = new Array(O * 2), V = new Array(O * 2), L = new Array(
2312
2312
  (O * 2 - 1) * l * 2 * 3
2313
2313
  );
2314
2314
  for (let M = 0; M < O * 2; M++)
2315
- Z[M] = new c.Vector3(), z[M] = new c.Vector3();
2315
+ Z[M] = new c.Vector3(), V[M] = new c.Vector3();
2316
2316
  let D = 0;
2317
- for (let M = 0; M < v; M++) {
2318
- const H = y[we(M, v)], T = y[M], V = y[Xt(M, v)];
2317
+ for (let M = 0; M < k; M++) {
2318
+ const H = w[Te(M, k)], T = w[M], z = w[Xt(M, k)];
2319
2319
  let E;
2320
2320
  if (M === 0)
2321
2321
  E = new c.Vector3(1, 0, -2).normalize();
2322
- else if (M === v - 1)
2322
+ else if (M === k - 1)
2323
2323
  E = new c.Vector3(0, 0, 1);
2324
2324
  else {
2325
- const K = T.clone().sub(H).normalize(), J = V.clone().sub(T).normalize();
2325
+ const K = T.clone().sub(H).normalize(), J = z.clone().sub(T).normalize();
2326
2326
  E = K.add(J).multiplyScalar(0.5);
2327
2327
  }
2328
- const q = new c.Vector3(0, 1, 0), W = Ve(E, q), P = D;
2329
- let b = jt(0, p / 4, M);
2328
+ const W = new c.Vector3(0, 1, 0), q = Ve(E, W), C = D;
2329
+ let b = jt(0, g / 4, M);
2330
2330
  b = F(0.1, 1, b), b = Math.sqrt(b);
2331
2331
  for (let K = 0; K < l; K++) {
2332
- const J = S[K].clone().applyQuaternion(W).multiplyScalar(b), ct = T.clone().add(J.clone().multiplyScalar(d));
2333
- Z[D] = ct, z[D] = J.clone();
2334
- const at = T.clone().add(J.clone().multiplyScalar(d));
2332
+ const J = S[K].clone().applyQuaternion(q).multiplyScalar(b), ct = T.clone().add(J.clone().multiplyScalar(_));
2333
+ Z[D] = ct, V[D] = J.clone();
2334
+ const at = T.clone().add(J.clone().multiplyScalar(_));
2335
2335
  at.z = s - at.z;
2336
- const Jt = P + l - K - 1, St = O * 2 - Jt - 1;
2337
- Z[St] = at, z[St] = J.clone(), D++;
2336
+ const te = C + l - K - 1, St = O * 2 - te - 1;
2337
+ Z[St] = at, V[St] = J.clone(), D++;
2338
2338
  }
2339
2339
  }
2340
- let C = 0;
2341
- const I = y.length * 2;
2340
+ let y = 0;
2341
+ const I = w.length * 2;
2342
2342
  for (let M = 0; M < I - 1; M++) {
2343
2343
  const H = M * l, T = (M + 1) * l;
2344
- for (let V = 0; V < l; V++) {
2345
- const E = Xt(V, l), q = H + V, W = H + E, P = T + E, b = T + V;
2346
- N[C++] = q, N[C++] = b, N[C++] = W, N[C++] = W, N[C++] = b, N[C++] = P;
2344
+ for (let z = 0; z < l; z++) {
2345
+ const E = Xt(z, l), W = H + z, q = H + E, C = T + E, b = T + z;
2346
+ L[y++] = W, L[y++] = b, L[y++] = q, L[y++] = q, L[y++] = b, L[y++] = C;
2347
2347
  }
2348
2348
  }
2349
- const L = [...Z], k = [...z], Q = [...N], G = Z.map((M) => M.clone()), $ = [...N];
2349
+ const N = [...Z], v = [...V], Q = [...L], G = Z.map((M) => M.clone()), $ = [...L];
2350
2350
  for (let M = 0; M < a - 1; M++) {
2351
2351
  const H = G.length;
2352
2352
  for (let T = 0; T < $.length; T++)
2353
2353
  $[T] += H;
2354
2354
  for (let T = 0; T < G.length; T++)
2355
2355
  G[T].z += h + s;
2356
- L.push(...G.map((T) => T.clone())), k.push(...z.map((T) => T.clone())), Q.push(...$);
2356
+ N.push(...G.map((T) => T.clone())), v.push(...V.map((T) => T.clone())), Q.push(...$);
2357
2357
  }
2358
- const j = new Float32Array(L.length * 3), A = new Float32Array(k.length * 3);
2359
- for (let M = 0; M < L.length; M++)
2360
- j[M * 3] = L[M].x, j[M * 3 + 1] = L[M].y, j[M * 3 + 2] = L[M].z, A[M * 3] = k[M].x, A[M * 3 + 1] = k[M].y, A[M * 3 + 2] = k[M].z;
2358
+ const j = new Float32Array(N.length * 3), A = new Float32Array(v.length * 3);
2359
+ for (let M = 0; M < N.length; M++)
2360
+ j[M * 3] = N[M].x, j[M * 3 + 1] = N[M].y, j[M * 3 + 2] = N[M].z, A[M * 3] = v[M].x, A[M * 3 + 1] = v[M].y, A[M * 3 + 2] = v[M].z;
2361
2361
  e.setAttribute(
2362
2362
  "position",
2363
2363
  new c.BufferAttribute(j, 3)
@@ -2368,68 +2368,68 @@ class Ae {
2368
2368
  }
2369
2369
  // ── createPaperPattern ────────────────────────────────────────────────
2370
2370
  createPaperPattern(t, e, s, i, n, o) {
2371
- const a = new ye();
2371
+ const a = new Ce();
2372
2372
  a.size = e, a.thickness = s;
2373
2373
  const h = this.m_BindingRadius;
2374
2374
  a.baseXOffset = -h;
2375
2375
  const m = this.m_Quality + 1;
2376
2376
  this.m_BindingVertexCount = m;
2377
- const l = t / 5, _ = Math.min(e.x, e.y) / 60, p = Math.floor(
2378
- F(0, (e.x - h) / _, l)
2379
- ), d = Math.floor(F(0, e.y / _, l));
2380
- let u = 2 + p + 1 + m, f = 2 + d;
2381
- const g = new st(0);
2382
- let w = g;
2377
+ const l = t / 5, d = Math.min(e.x, e.y) / 60, g = Math.floor(
2378
+ F(0, (e.x - h) / d, l)
2379
+ ), _ = Math.floor(F(0, e.y / d, l));
2380
+ let u = 2 + g + 1 + m, f = 2 + _;
2381
+ const p = new st(0);
2382
+ let P = p;
2383
2383
  const B = h / m;
2384
2384
  let x = 0;
2385
- for (let P = 1; P < m + 1; P++)
2386
- w = w.createNext(x), x += B;
2387
- const y = (e.x - h) / (p + 1);
2388
- for (let P = m + 1; P < u; P++)
2389
- w = w.createNext(x), x += y;
2385
+ for (let C = 1; C < m + 1; C++)
2386
+ P = P.createNext(x), x += B;
2387
+ const w = (e.x - h) / (g + 1);
2388
+ for (let C = m + 1; C < u; C++)
2389
+ P = P.createNext(x), x += w;
2390
2390
  const S = new st(0);
2391
- let v = S;
2391
+ let k = S;
2392
2392
  const O = e.y / (f - 1);
2393
2393
  let Z = 0;
2394
- for (let P = 0; P < f - 1; P++)
2395
- Z += O, v = v.createNext(Z);
2396
- const z = [], N = [], D = i.clone();
2394
+ for (let C = 0; C < f - 1; C++)
2395
+ Z += O, k = k.createNext(Z);
2396
+ const V = [], L = [], D = i.clone();
2397
2397
  if (n) {
2398
- let P = 0;
2399
- this.m_Book.hasCover && (P = Math.floor(this.m_Book.coverPaperCount / 2));
2398
+ let C = 0;
2399
+ this.m_Book.hasCover && (C = Math.floor(this.m_Book.coverPaperCount / 2));
2400
2400
  const b = Math.max(0.01, s);
2401
- D.left = 0, D.right = (this.getPX(P + 1, s) - this.getPX(P, s) + b) / e.x, D.down = b / e.y, D.up = b / e.y;
2402
- }
2403
- const C = new le(a, D, !1);
2404
- C.insert(g, S, z, N), g.updateIndex(0), S.updateIndex(0), Mt(z, a.xSeams), Mt(N, a.zSeams);
2405
- const I = this.m_BindingVertexCount + 2, L = new Array(I);
2406
- a.xNoneSeamIndexes = L, w = g;
2407
- for (let P = 0; P < I; P++) {
2408
- L[P] = w.index;
2401
+ D.left = 0, D.right = (this.getPX(C + 1, s) - this.getPX(C, s) + b) / e.x, D.down = b / e.y, D.up = b / e.y;
2402
+ }
2403
+ const y = new ce(a, D, !1);
2404
+ y.insert(p, S, V, L), p.updateIndex(0), S.updateIndex(0), Mt(V, a.xSeams), Mt(L, a.zSeams);
2405
+ const I = this.m_BindingVertexCount + 2, N = new Array(I);
2406
+ a.xNoneSeamIndexes = N, P = p;
2407
+ for (let C = 0; C < I; C++) {
2408
+ N[C] = P.index;
2409
2409
  do
2410
- w = w.next;
2411
- while (w.seam);
2410
+ P = P.next;
2411
+ while (P.seam);
2412
2412
  }
2413
- const k = g.getValues(), Q = S.getValues();
2414
- u = k.length, f = Q.length;
2413
+ const v = p.getValues(), Q = S.getValues();
2414
+ u = v.length, f = Q.length;
2415
2415
  const G = u * f, $ = [], j = new Array(G).fill(0), A = [], M = [], H = [], T = [];
2416
- $t(
2416
+ Yt(
2417
2417
  $,
2418
- k,
2418
+ v,
2419
2419
  Q,
2420
2420
  e,
2421
2421
  i,
2422
2422
  this.m_Book.direction
2423
2423
  );
2424
- const V = C.leftNode.index, E = C.downNode.index;
2425
- let q = C.rightNode.index, W = C.upNode.index;
2426
- q === 0 && (q = u - 1), W === 0 && (W = f - 1);
2427
- for (let P = 0; P < f - 1; P++)
2424
+ const z = y.leftNode.index, E = y.downNode.index;
2425
+ let W = y.rightNode.index, q = y.upNode.index;
2426
+ W === 0 && (W = u - 1), q === 0 && (q = f - 1);
2427
+ for (let C = 0; C < f - 1; C++)
2428
2428
  for (let b = 0; b < u - 1; b++) {
2429
- if (n && P >= E && P < W && b >= V && b < q)
2429
+ if (n && C >= E && C < q && b >= z && b < W)
2430
2430
  continue;
2431
- const K = P * u + b, J = P * u + (b + 1), ct = (P + 1) * u + b, at = (P + 1) * u + (b + 1);
2432
- j[K] += 2, j[J] += 2, j[ct] += 2, j[at] += 2, Qt(
2431
+ const K = C * u + b, J = C * u + (b + 1), ct = (C + 1) * u + b, at = (C + 1) * u + (b + 1);
2432
+ j[K] += 2, j[J] += 2, j[ct] += 2, j[at] += 2, $t(
2433
2433
  A,
2434
2434
  M,
2435
2435
  K,
@@ -2439,10 +2439,10 @@ class Ae {
2439
2439
  G
2440
2440
  );
2441
2441
  }
2442
- if (T.push(new Tt(0, 0, u - 1, f - 1, !1, !1)), qt(T, H, $, u, f), a.baseXArray = k, a.baseZArray = Q, a.baseVertexCount = G, a.vertexCount = $.length, a.texcoords = $, a.weights = j, o) {
2442
+ if (T.push(new Tt(0, 0, u - 1, f - 1, !1, !1)), qt(T, H, $, u, f), a.baseXArray = v, a.baseZArray = Q, a.baseVertexCount = G, a.vertexCount = $.length, a.texcoords = $, a.weights = j, o) {
2443
2443
  a.subMeshCount = 1;
2444
- const P = [];
2445
- P.push(...A), P.push(...H), P.push(...M), a.triangles = P;
2444
+ const C = [];
2445
+ C.push(...A), C.push(...H), C.push(...M), a.triangles = C;
2446
2446
  } else
2447
2447
  a.subMeshCount = 3, a.frontTriangles = A, a.backTriangles = M, a.borderTriangles = H;
2448
2448
  return a.borders = T, a;
@@ -2459,40 +2459,40 @@ class Ae {
2459
2459
  let i = 0;
2460
2460
  const n = e.length / 2 - 1, o = e.length / 2;
2461
2461
  for (let x = 0; x < s; x++) {
2462
- const y = e[x];
2463
- y.updateTime();
2464
- const S = y.zTime, v = y.thickness;
2465
- i += S * v, x === n && (i += S * this.m_BindingMidSpace / 2), x === o && (i += S * this.m_BindingMidSpace / 2);
2462
+ const w = e[x];
2463
+ w.updateTime();
2464
+ const S = w.zTime, k = w.thickness;
2465
+ i += S * k, x === n && (i += S * this.m_BindingMidSpace / 2), x === o && (i += S * this.m_BindingMidSpace / 2);
2466
2466
  }
2467
2467
  let a = this.getStackHeight(t.index) - t.thickness / 2;
2468
2468
  const h = this.getStackZ(a), m = 180 + h;
2469
- let l = t.isFlipped ? 1 : 0, _ = F(h, m, l);
2470
- const p = _ * tt, d = new c.Vector3(
2471
- Math.cos(p) * this.m_BindingRadius,
2472
- Math.sin(p) * this.m_BindingRadius,
2469
+ let l = t.isFlipped ? 1 : 0, d = F(h, m, l);
2470
+ const g = d * tt, _ = new c.Vector3(
2471
+ Math.cos(g) * this.m_BindingRadius,
2472
+ Math.sin(g) * this.m_BindingRadius,
2473
2473
  0
2474
2474
  );
2475
- d.z = t.margin;
2476
- let u = e[Math.floor(s / 2)].size.x, f = this.m_BindingMidSpace, g = Math.sqrt(u * u - f * f), w = Math.asin(g / u) * it - 90;
2475
+ _.z = t.margin;
2476
+ 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;
2477
2477
  if (t.index < Math.floor(s / 2)) {
2478
2478
  let x = 0;
2479
2479
  if (this.m_Book.alignToGround) {
2480
2480
  u = e[0].size.x;
2481
- const y = this.m_StackHeight / 2;
2482
- f = et(i, 0, y) - y, g = Math.sqrt(u * u - f * f), x = (Math.asin(g / u) * it - 90) * 2;
2481
+ const w = this.m_StackHeight / 2;
2482
+ f = et(i, 0, w) - w, p = Math.sqrt(u * u - f * f), x = (Math.asin(p / u) * it - 90) * 2;
2483
2483
  }
2484
- _ = F(w, -x, l);
2484
+ d = F(P, -x, l);
2485
2485
  } else {
2486
2486
  let x = 0;
2487
2487
  if (this.m_Book.alignToGround) {
2488
2488
  u = e[0].size.x;
2489
- const y = this.m_StackHeight / 2;
2490
- f = y - et(i, y, y * 2), g = Math.sqrt(u * u - f * f), x = (Math.asin(g / u) * it - 90) * 2;
2489
+ const w = this.m_StackHeight / 2;
2490
+ f = w - et(i, w, w * 2), p = Math.sqrt(u * u - f * f), x = (Math.asin(p / u) * it - 90) * 2;
2491
2491
  }
2492
- _ = F(x, -w, l);
2492
+ d = F(x, -P, l);
2493
2493
  }
2494
- t.transform.position.copy(d), t.transform.quaternion.setFromEuler(
2495
- new c.Euler(0, 0, _ * tt)
2494
+ t.transform.position.copy(_), t.transform.quaternion.setFromEuler(
2495
+ new c.Euler(0, 0, d * tt)
2496
2496
  );
2497
2497
  }
2498
2498
  // ── getPX (private helper) ───────────────────────────────────────────
@@ -2502,10 +2502,10 @@ class Ae {
2502
2502
  const o = s.length / 2 - 1, a = s.length / 2;
2503
2503
  for (let f = 0; f < i; f++)
2504
2504
  n += 0 * e, f === o && (n += 0 * this.m_BindingMidSpace / 2), f === a && (n += 0 * this.m_BindingMidSpace / 2);
2505
- const h = this.getStackHeight(t) - e / 2, m = this.getStackZ(h), l = 180 + m, d = F(m, l, 0) * tt;
2505
+ const h = this.getStackHeight(t) - e / 2, m = this.getStackZ(h), l = 180 + m, _ = F(m, l, 0) * tt;
2506
2506
  return new c.Vector3(
2507
- Math.cos(d) * this.m_BindingRadius,
2508
- Math.sin(d) * this.m_BindingRadius,
2507
+ Math.cos(_) * this.m_BindingRadius,
2508
+ Math.sin(_) * this.m_BindingRadius,
2509
2509
  0
2510
2510
  ).x;
2511
2511
  }
@@ -2515,39 +2515,39 @@ class Ae {
2515
2515
  let i = 0;
2516
2516
  const n = e.length / 2 - 1, o = e.length / 2;
2517
2517
  for (let x = 0; x < s; x++) {
2518
- const y = e[x];
2519
- y.updateTime();
2520
- const S = y.zTime, v = y.thickness;
2521
- i += S * v, x === n && (i += S * this.m_BindingMidSpace / 2), x === o && (i += S * this.m_BindingMidSpace / 2);
2518
+ const w = e[x];
2519
+ w.updateTime();
2520
+ const S = w.zTime, k = w.thickness;
2521
+ i += S * k, x === n && (i += S * this.m_BindingMidSpace / 2), x === o && (i += S * this.m_BindingMidSpace / 2);
2522
2522
  }
2523
2523
  const a = this.getStackHeight(t.index) - t.thickness / 2, h = this.getStackZ(a + i), m = 180 + this.getStackZ(a + i - this.m_StackHeight);
2524
- let l = t.zTime, _ = F(h, m, l);
2525
- const p = _ * tt, d = new c.Vector3(
2526
- Math.cos(p) * this.m_BindingRadius,
2527
- Math.sin(p) * this.m_BindingRadius,
2524
+ let l = t.zTime, d = F(h, m, l);
2525
+ const g = d * tt, _ = new c.Vector3(
2526
+ Math.cos(g) * this.m_BindingRadius,
2527
+ Math.sin(g) * this.m_BindingRadius,
2528
2528
  0
2529
2529
  );
2530
- d.z = t.margin;
2531
- let u = e[Math.floor(s / 2)].size.x, f = this.m_BindingMidSpace, g = Math.sqrt(u * u - f * f), w = Math.asin(g / u) * it - 90;
2530
+ _.z = t.margin;
2531
+ 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;
2532
2532
  if (t.index < Math.floor(s / 2)) {
2533
2533
  let x = 0;
2534
2534
  if (this.m_Book.alignToGround) {
2535
2535
  u = e[0].size.x;
2536
- const y = this.m_StackHeight / 2;
2537
- f = et(i, 0, y) - y, g = Math.sqrt(u * u - f * f), x = (Math.asin(g / u) * it - 90) * 2;
2536
+ const w = this.m_StackHeight / 2;
2537
+ f = et(i, 0, w) - w, p = Math.sqrt(u * u - f * f), x = (Math.asin(p / u) * it - 90) * 2;
2538
2538
  }
2539
- _ = F(w, -x, l);
2539
+ d = F(P, -x, l);
2540
2540
  } else {
2541
2541
  let x = 0;
2542
2542
  if (this.m_Book.alignToGround) {
2543
2543
  u = e[0].size.x;
2544
- const y = this.m_StackHeight / 2;
2545
- f = y - et(i, y, y * 2), g = Math.sqrt(u * u - f * f), x = (Math.asin(g / u) * it - 90) * 2;
2544
+ const w = this.m_StackHeight / 2;
2545
+ f = w - et(i, w, w * 2), p = Math.sqrt(u * u - f * f), x = (Math.asin(p / u) * it - 90) * 2;
2546
2546
  }
2547
- _ = F(x, -w, l);
2547
+ d = F(x, -P, l);
2548
2548
  }
2549
- t.transform.position.copy(d), t.transform.quaternion.setFromEuler(
2550
- new c.Euler(0, 0, _ * tt)
2549
+ t.transform.position.copy(_), t.transform.quaternion.setFromEuler(
2550
+ new c.Euler(0, 0, d * tt)
2551
2551
  );
2552
2552
  }
2553
2553
  // ── getStackHeight ────────────────────────────────────────────────────
@@ -2581,35 +2581,35 @@ class Ae {
2581
2581
  let e = new c.Vector3(0, 0, 0), s = new c.Vector3(0, 0, 0), i = this.m_BindingRadius * 0.6;
2582
2582
  const n = this.m_StapleThickness * 0.5, o = t[0].thickness, a = this.m_Root.matrixWorld.clone(), h = t.length;
2583
2583
  for (let m = 0; m < h; m++) {
2584
- const l = t[m], _ = l.transform, p = l.meshData.pattern, d = l.meshData.baseVertices, u = p.baseXArray, f = p.baseZArray, g = u.length, w = f.length, B = this.m_BindingVertexCount + 1, x = l.thickness, y = p.xNoneSeamIndexes, S = _.position.clone();
2585
- let v = m, O = n;
2586
- m >= Math.floor(h / 2) && (v = h - m - 1, O *= -1);
2587
- const Z = (o + x) * 0.5 + x * (v - 1), z = _.matrixWorld.clone().invert().multiply(a), N = v / (h / 2);
2588
- i = this.m_BindingRadius * F(0.45, 0.65, 1 - N);
2589
- for (let D = 0; D < w; D++) {
2590
- const C = f[D], I = new c.Vector3(0, 0, S.z + C), L = S.clone();
2591
- L.z += C;
2592
- const k = l.getDirection(C).multiplyScalar(i).add(L.clone());
2584
+ 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, x = l.thickness, w = g.xNoneSeamIndexes, S = d.position.clone();
2585
+ let k = m, O = n;
2586
+ m >= Math.floor(h / 2) && (k = h - m - 1, O *= -1);
2587
+ const Z = (o + x) * 0.5 + x * (k - 1), V = d.matrixWorld.clone().invert().multiply(a), L = k / (h / 2);
2588
+ i = this.m_BindingRadius * F(0.45, 0.65, 1 - L);
2589
+ for (let D = 0; D < P; D++) {
2590
+ const y = f[D], I = new c.Vector3(0, 0, S.z + y), N = S.clone();
2591
+ N.z += y;
2592
+ const v = l.getDirection(y).multiplyScalar(i).add(N.clone());
2593
2593
  if (m === 0 && D === 0) {
2594
2594
  const A = t[h - 1], H = A.transform.position.clone().clone();
2595
- H.z += C;
2596
- const T = A.getDirection(C).multiplyScalar(i).add(H);
2597
- s = k.clone().sub(T).normalize(), e = new c.Vector3(
2595
+ H.z += y;
2596
+ const T = A.getDirection(y).multiplyScalar(i).add(H);
2597
+ s = v.clone().sub(T).normalize(), e = new c.Vector3(
2598
2598
  -s.y,
2599
2599
  s.x,
2600
2600
  0
2601
2601
  ).normalize().negate();
2602
- const V = Math.atan2(e.y, e.x) * it;
2603
- this.stapleMesh.rotation.set(0, 0, V * tt);
2602
+ const z = Math.atan2(e.y, e.x) * it;
2603
+ this.stapleMesh.rotation.set(0, 0, z * tt);
2604
2604
  }
2605
- v > 0 && I.add(e.clone().multiplyScalar(Z));
2606
- const Q = D * g;
2607
- d[Q] = I.clone().applyMatrix4(z), I.add(s.clone().multiplyScalar(O));
2608
- const G = I.clone().applyMatrix4(z), $ = k.clone().applyMatrix4(z), j = L.clone().applyMatrix4(z);
2609
- d[Q + y[1]] = G;
2605
+ k > 0 && I.add(e.clone().multiplyScalar(Z));
2606
+ const Q = D * p;
2607
+ _[Q] = I.clone().applyMatrix4(V), I.add(s.clone().multiplyScalar(O));
2608
+ const G = I.clone().applyMatrix4(V), $ = v.clone().applyMatrix4(V), j = N.clone().applyMatrix4(V);
2609
+ _[Q + w[1]] = G;
2610
2610
  for (let A = 2; A < B; A++) {
2611
2611
  const M = jt(1, B, A);
2612
- d[Q + y[A]] = Et(
2612
+ _[Q + w[A]] = Et(
2613
2613
  G,
2614
2614
  $,
2615
2615
  j,
@@ -2642,7 +2642,7 @@ class Ae {
2642
2642
  return this.m_StapleThickness;
2643
2643
  }
2644
2644
  }
2645
- class He {
2645
+ class Fe {
2646
2646
  constructor(t) {
2647
2647
  this.mesh = t;
2648
2648
  }
@@ -2668,12 +2668,12 @@ class He {
2668
2668
  return this.mesh;
2669
2669
  }
2670
2670
  }
2671
- class Xe extends Pe {
2671
+ class qe extends Pe {
2672
2672
  constructor() {
2673
- super(...arguments), this.quality = 3, this.stapleSetup = new ze();
2673
+ super(...arguments), this.quality = 3, this.stapleSetup = new De();
2674
2674
  }
2675
2675
  createBound(t, e, s, i) {
2676
- return new Ae(
2676
+ return new He(
2677
2677
  this.quality,
2678
2678
  this.stapleSetup,
2679
2679
  t,
@@ -2681,40 +2681,227 @@ class Xe extends Pe {
2681
2681
  );
2682
2682
  }
2683
2683
  }
2684
+ class Oe {
2685
+ constructor(t) {
2686
+ 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;
2687
+ }
2688
+ _font() {
2689
+ return `${this.fontStyle} ${this.fontWeight} ${this.fontSize}px ${this.fontFamily}`;
2690
+ }
2691
+ /**
2692
+ * Word-wrap `text` into lines that fit within `width` pixels.
2693
+ * Respects explicit newlines.
2694
+ */
2695
+ wrapLines(t) {
2696
+ if (!this.text) return [];
2697
+ if (t.font = this._font(), this.width <= 0) return this.text.split(`
2698
+ `);
2699
+ const e = [];
2700
+ for (const s of this.text.split(`
2701
+ `)) {
2702
+ if (s === "") {
2703
+ e.push("");
2704
+ continue;
2705
+ }
2706
+ const i = s.split(/\s+/);
2707
+ let n = "";
2708
+ for (const o of i) {
2709
+ const a = n ? `${n} ${o}` : o;
2710
+ t.measureText(a).width > this.width && n ? (e.push(n), n = o) : n = a;
2711
+ }
2712
+ n && e.push(n);
2713
+ }
2714
+ return e;
2715
+ }
2716
+ /** Total rendered height in canvas pixels. */
2717
+ measureHeight(t) {
2718
+ return this.wrapLines(t).length * this.fontSize * this.lineHeight;
2719
+ }
2720
+ /** Returns true if the point (px, py) is within the text bounding box. */
2721
+ hitTest(t, e, s) {
2722
+ const i = this.wrapLines(t);
2723
+ if (i.length === 0) return !1;
2724
+ const n = i.length * this.fontSize * this.lineHeight, o = this.width > 0 ? this.width : this._maxLineWidth(t, i);
2725
+ return e >= this.x && e <= this.x + o && s >= this.y && s <= this.y + n;
2726
+ }
2727
+ _maxLineWidth(t, e) {
2728
+ t.font = this._font();
2729
+ let s = 0;
2730
+ for (const i of e) {
2731
+ const n = t.measureText(i).width;
2732
+ n > s && (s = n);
2733
+ }
2734
+ return s;
2735
+ }
2736
+ draw(t) {
2737
+ if (!this.text || this.opacity <= 0) return;
2738
+ const e = this.wrapLines(t);
2739
+ if (e.length === 0) return;
2740
+ 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);
2741
+ const s = this.fontSize * this.lineHeight, i = this.width > 0 ? this.width : this._maxLineWidth(t, e);
2742
+ for (let n = 0; n < e.length; n++) {
2743
+ let o = this.x;
2744
+ 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);
2745
+ }
2746
+ t.restore();
2747
+ }
2748
+ }
2749
+ function Ze(r) {
2750
+ return r.map instanceof c.Texture;
2751
+ }
2752
+ class Qe {
2753
+ constructor(t) {
2754
+ this.texts = [], this._textureST = new c.Vector4(1, 1, 0, 0);
2755
+ const e = (t == null ? void 0 : t.width) ?? 512, s = (t == null ? void 0 : t.height) ?? 512;
2756
+ this.canvas = document.createElement("canvas"), this.canvas.width = e, this.canvas.height = s;
2757
+ const i = this.canvas.getContext("2d");
2758
+ if (!i) throw new Error("TextOverlayContent: could not get 2D context");
2759
+ this.ctx = i, this._source = (t == null ? void 0 : t.source) ?? null, this._texture = new c.CanvasTexture(this.canvas), this._texture.colorSpace = c.SRGBColorSpace;
2760
+ }
2761
+ get texture() {
2762
+ return this._texture;
2763
+ }
2764
+ get textureST() {
2765
+ return this._textureST;
2766
+ }
2767
+ /** The base layer drawn beneath text blocks. */
2768
+ get source() {
2769
+ return this._source;
2770
+ }
2771
+ set source(t) {
2772
+ this._source = t;
2773
+ }
2774
+ // ── Text API ─────────────────────────────────────────────────────────────
2775
+ addText(t) {
2776
+ const e = new Oe(t);
2777
+ return this.texts.push(e), e;
2778
+ }
2779
+ removeText(t) {
2780
+ const e = this.texts.indexOf(t);
2781
+ e !== -1 && this.texts.splice(e, 1);
2782
+ }
2783
+ /** Update a text block by index. Only provided fields are changed. */
2784
+ updateText(t, e) {
2785
+ const s = this.texts[t];
2786
+ 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));
2787
+ }
2788
+ // ── Per-frame update ─────────────────────────────────────────────────────
2789
+ /**
2790
+ * Re-composite the canvas: source layer + text blocks.
2791
+ * Call every frame (or when content changes).
2792
+ *
2793
+ * @param root Optional THREE.Object3D to traverse for texture sync
2794
+ * (same pattern as SpriteScene — needed because three-book
2795
+ * clones material textures).
2796
+ */
2797
+ update(t) {
2798
+ const { ctx: e, canvas: s } = this, i = s.width, n = s.height;
2799
+ e.clearRect(0, 0, i, n), this._source && e.drawImage(this._source, 0, 0, i, n);
2800
+ for (const o of this.texts) o.draw(e);
2801
+ this._texture.needsUpdate = !0, t && this.syncMaterials(t);
2802
+ }
2803
+ /**
2804
+ * Traverse `root` and set `needsUpdate = true` on every material map whose
2805
+ * source image is this overlay's canvas.
2806
+ */
2807
+ syncMaterials(t) {
2808
+ t.traverse((e) => {
2809
+ if (!e.isMesh) return;
2810
+ const s = e, i = Array.isArray(s.material) ? s.material : [s.material];
2811
+ for (const n of i)
2812
+ Ze(n) && n.map.image === this.canvas && (n.map.needsUpdate = !0);
2813
+ });
2814
+ }
2815
+ // ── IPageContent ─────────────────────────────────────────────────────────
2816
+ isPointOverUI(t) {
2817
+ return !1;
2818
+ }
2819
+ init(t) {
2820
+ }
2821
+ setActive(t) {
2822
+ }
2823
+ dispose() {
2824
+ this._texture.dispose();
2825
+ }
2826
+ }
2827
+ const Gt = 256;
2828
+ function Le(r, t, e, s, i, n, o) {
2829
+ const a = t.naturalWidth || t.width, h = t.naturalHeight || t.height;
2830
+ if (a <= 0 || h <= 0) return;
2831
+ if (o === "fill") {
2832
+ r.drawImage(t, e, s, i, n);
2833
+ return;
2834
+ }
2835
+ const m = o === "contain" ? Math.min(i / a, n / h) : Math.max(i / a, n / h), l = a * m, d = h * m;
2836
+ r.drawImage(t, e + (i - l) * 0.5, s + (n - d) * 0.5, l, d);
2837
+ }
2838
+ function $e(r, t, e, s, i, n, o) {
2839
+ const a = n ? Math.round(n * Gt) : 512, h = o ? Math.round(o * Gt) : 512, m = document.createElement("canvas");
2840
+ m.width = a, m.height = h;
2841
+ const l = m.getContext("2d");
2842
+ if (l.fillStyle = r, l.fillRect(0, 0, a, h), e) {
2843
+ const g = i ? 0 : Math.round(Math.min(a, h) * 0.11);
2844
+ Le(l, e, g, g, a - g * 2, h - g * 2, s);
2845
+ } else {
2846
+ l.fillStyle = "#333";
2847
+ const g = Math.round(Math.min(a, h) * 0.094);
2848
+ l.font = `bold ${g}px Arial`, l.textAlign = "center", l.textBaseline = "middle", l.fillText(t, a / 2, h / 2);
2849
+ }
2850
+ const d = new c.CanvasTexture(m);
2851
+ return d.colorSpace = c.SRGBColorSpace, d;
2852
+ }
2853
+ async function Ye(r) {
2854
+ if (!r) return null;
2855
+ const t = URL.createObjectURL(r), e = new Image();
2856
+ e.decoding = "async", e.src = t;
2857
+ try {
2858
+ return await new Promise((s, i) => {
2859
+ e.onload = () => s(), e.onerror = () => i(new Error(`Failed to decode image: ${r.name}`));
2860
+ }), { image: e, objectUrl: t };
2861
+ } catch (s) {
2862
+ return URL.revokeObjectURL(t), console.error(s), null;
2863
+ }
2864
+ }
2684
2865
  export {
2685
- xe as AnimationCurve,
2686
- yt as AutoTurnDirection,
2866
+ ye as AnimationCurve,
2867
+ wt as AutoTurnDirection,
2687
2868
  pe as AutoTurnMode,
2688
2869
  rt as AutoTurnSetting,
2689
- Me as AutoTurnSettingCurveTimeMode,
2690
- ge as AutoTurnSettingMode,
2691
- Lt as AutoTurnSettings,
2692
- Pt as Book,
2870
+ xe as AutoTurnSettingCurveTimeMode,
2871
+ Me as AutoTurnSettingMode,
2872
+ Nt as AutoTurnSettings,
2873
+ Ct as Book,
2693
2874
  Pe as BookBinding,
2694
- Ee as BookBound,
2695
- Le as BookContent,
2875
+ We as BookBound,
2876
+ je as BookContent,
2696
2877
  X as BookDirection,
2697
- Oe as BookHeightException,
2698
- Ue as BookPointerInteraction,
2699
- de as BookRenderer,
2878
+ Ue as BookHeightException,
2879
+ Ge as BookPointerInteraction,
2880
+ fe as BookRenderer,
2700
2881
  ut as Cylinder,
2701
- me as MeshFactory,
2702
- Ne as PageContent,
2703
- he as Paper,
2882
+ ue as MeshFactory,
2883
+ Gt as PX_PER_UNIT,
2884
+ Xe as PageContent,
2885
+ le as Paper,
2704
2886
  Tt as PaperBorder,
2705
2887
  At as PaperMaterialData,
2706
2888
  Zt as PaperMeshData,
2707
- fe as PaperMeshDataPool,
2708
- Fe as PaperMeshUtility,
2889
+ ge as PaperMeshDataPool,
2890
+ Ne as PaperMeshUtility,
2709
2891
  st as PaperNode,
2710
- le as PaperNodeMargin,
2711
- ye as PaperPattern,
2712
- wt as PaperSeam,
2892
+ ce as PaperNodeMargin,
2893
+ Ce as PaperPattern,
2894
+ Pt as PaperSeam,
2713
2895
  ht as PaperSetup,
2714
- gt as PaperUVMargin,
2715
- ue as RendererFactory,
2896
+ pt as PaperUVMargin,
2897
+ de as RendererFactory,
2716
2898
  Ut as SpritePageContent2,
2717
- Xe as StapleBookBinding,
2718
- Ae as StapleBookBound,
2719
- ze as StapleSetup
2899
+ qe as StapleBookBinding,
2900
+ He as StapleBookBound,
2901
+ De as StapleSetup,
2902
+ Oe as TextBlock,
2903
+ Qe as TextOverlayContent,
2904
+ $e as createPageTexture,
2905
+ Le as drawImageWithFit,
2906
+ Ye as loadImage
2720
2907
  };