@digilogiclabs/saas-factory-ui 1.16.0 → 1.16.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
@@ -30292,6 +30292,8 @@ var SHOW_ROT = {
30292
30292
  6: { x: 90, y: 0 }
30293
30293
  };
30294
30294
  var MAX_COUNT = 6;
30295
+ var TUMBLE_MS = 950;
30296
+ var SETTLE_MS = 1100;
30295
30297
  function simulateDice(arenaW, arenaH, diceSize, starts, numDice) {
30296
30298
  const pad = diceSize * 0.55;
30297
30299
  const minX = pad;
@@ -30304,17 +30306,20 @@ function simulateDice(arenaW, arenaH, diceSize, starts, numDice) {
30304
30306
  for (let i = 0; i < numDice; i++) {
30305
30307
  const s = starts[i] ?? { x: arenaW / 2, y: arenaH / 2 };
30306
30308
  bodies.push({
30307
- x: clamp(s.x + (Math.random() - 0.5) * arenaW * 0.2, minX, maxX),
30308
- y: clamp(s.y + (Math.random() - 0.5) * arenaH * 0.2, minY, maxY),
30309
- vx: (Math.random() - 0.5) * arenaW * 0.9,
30310
- vy: (Math.random() - 0.5) * arenaH * 0.9
30309
+ x: clamp(s.x + (Math.random() - 0.5) * arenaW * 0.25, minX, maxX),
30310
+ y: clamp(s.y + (Math.random() - 0.5) * arenaH * 0.25, minY, maxY),
30311
+ // Minimum baseline velocity so small arenas still bounce visibly
30312
+ // instead of drifting a few pixels. The `|| 1` guard makes sure
30313
+ // we never get a near-zero initial velocity from `random - 0.5`.
30314
+ vx: (Math.sign(Math.random() - 0.5) || 1) * (0.5 + Math.random() * 0.5) * arenaW * 1.4,
30315
+ vy: (Math.sign(Math.random() - 0.5) || 1) * (0.5 + Math.random() * 0.5) * arenaH * 1.6
30311
30316
  });
30312
30317
  }
30313
- const steps = 24;
30318
+ const steps = 32;
30314
30319
  const dt = 2 / steps;
30315
- const friction = 0.86;
30316
- const wallRestitution = -0.55;
30317
- const diceRestitution = 0.7;
30320
+ const friction = 0.9;
30321
+ const wallRestitution = -0.72;
30322
+ const diceRestitution = 0.8;
30318
30323
  const frames = [];
30319
30324
  for (let s = 0; s < steps; s++) {
30320
30325
  for (const b of bodies) {
@@ -30500,6 +30505,7 @@ function DiceRoller({
30500
30505
  );
30501
30506
  const [positions, setPositions] = (0, import_react66.useState)(null);
30502
30507
  const timersRef = (0, import_react66.useRef)([]);
30508
+ const rafHandleRef = (0, import_react66.useRef)(null);
30503
30509
  const arenaRef = (0, import_react66.useRef)(null);
30504
30510
  const arena = useArenaBounds(arenaRef);
30505
30511
  const colors = (0, import_react66.useMemo)(() => {
@@ -30619,13 +30625,27 @@ function DiceRoller({
30619
30625
  }
30620
30626
  return n;
30621
30627
  });
30622
- const stepMs = 40;
30623
- for (let s = 0; s < frames.length; s++) {
30624
- const timer = setTimeout(() => {
30625
- setPositions(frames[s].slice(0, clampedCount));
30626
- }, s * stepMs);
30627
- timersRef.current.push(timer);
30628
- }
30628
+ const playbackMs = TUMBLE_MS;
30629
+ const startTime = typeof performance !== "undefined" ? performance.now() : Date.now();
30630
+ if (rafHandleRef.current != null) {
30631
+ cancelAnimationFrame(rafHandleRef.current);
30632
+ rafHandleRef.current = null;
30633
+ }
30634
+ const tick = (now) => {
30635
+ const elapsed = now - startTime;
30636
+ const progress = Math.max(0, Math.min(1, elapsed / playbackMs));
30637
+ const idx = Math.min(
30638
+ frames.length - 1,
30639
+ Math.floor(progress * frames.length)
30640
+ );
30641
+ setPositions(frames[idx].slice(0, clampedCount));
30642
+ if (progress < 1) {
30643
+ rafHandleRef.current = requestAnimationFrame(tick);
30644
+ } else {
30645
+ rafHandleRef.current = null;
30646
+ }
30647
+ };
30648
+ rafHandleRef.current = requestAnimationFrame(tick);
30629
30649
  requestAnimationFrame(() => {
30630
30650
  requestAnimationFrame(() => {
30631
30651
  setRotations((prev) => {
@@ -30651,7 +30671,7 @@ function DiceRoller({
30651
30671
  if (showHistory) {
30652
30672
  setHistory((prev) => [{ vals, total: total2 }, ...prev].slice(0, historyMax));
30653
30673
  }
30654
- }, 1050);
30674
+ }, SETTLE_MS);
30655
30675
  timersRef.current.push(settleTimer);
30656
30676
  }, [
30657
30677
  rolling,
@@ -30679,6 +30699,10 @@ function DiceRoller({
30679
30699
  () => () => {
30680
30700
  timersRef.current.forEach((t) => clearTimeout(t));
30681
30701
  timersRef.current = [];
30702
+ if (rafHandleRef.current != null) {
30703
+ cancelAnimationFrame(rafHandleRef.current);
30704
+ rafHandleRef.current = null;
30705
+ }
30682
30706
  },
30683
30707
  []
30684
30708
  );