@digilogiclabs/saas-factory-ui 1.16.2 → 1.16.4

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
@@ -30304,44 +30304,53 @@ function simulateDice(arenaW, arenaH, diceSize, starts, numDice) {
30304
30304
  const collisionDist = diceSize * 1.05;
30305
30305
  const bodies = [];
30306
30306
  for (let i = 0; i < numDice; i++) {
30307
- const s = starts[i] ?? { x: arenaW / 2, y: arenaH / 2 };
30307
+ const s = starts[i] ?? { x: arenaW / 2, y: minY };
30308
30308
  bodies.push({
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
30309
+ x: clamp(s.x + (Math.random() - 0.5) * arenaW * 0.2, minX, maxX),
30310
+ y: clamp(minY + Math.random() * 8, minY, maxY),
30311
+ vx: (Math.sign(Math.random() - 0.5) || 1) * (0.35 + Math.random() * 0.55) * arenaW * 1.2,
30312
+ // Always downward initially this is the "drop" feel.
30313
+ vy: (0.25 + Math.random() * 0.4) * arenaH * 2.2
30316
30314
  });
30317
30315
  }
30318
- const steps = 32;
30319
- const dt = 2 / steps;
30320
- const friction = 0.9;
30316
+ const steps = 40;
30317
+ const dt = 2.4 / steps;
30318
+ const friction = 0.93;
30321
30319
  const wallRestitution = -0.72;
30322
30320
  const diceRestitution = 0.8;
30321
+ const gravity = arenaH * 0.9;
30323
30322
  const frames = [];
30323
+ const bounceScaleX = new Array(numDice).fill(1);
30324
+ const bounceScaleY = new Array(numDice).fill(1);
30324
30325
  for (let s = 0; s < steps; s++) {
30325
30326
  for (const b of bodies) {
30327
+ b.vy += gravity * dt;
30326
30328
  b.x += b.vx * dt;
30327
30329
  b.y += b.vy * dt;
30328
30330
  }
30329
- for (const b of bodies) {
30331
+ for (let i = 0; i < numDice; i++) {
30332
+ const b = bodies[i];
30330
30333
  if (b.x <= minX) {
30331
30334
  b.x = minX;
30332
30335
  b.vx *= wallRestitution;
30333
- }
30334
- if (b.x >= maxX) {
30336
+ bounceScaleX[i] = 0.78;
30337
+ bounceScaleY[i] = 1.14;
30338
+ } else if (b.x >= maxX) {
30335
30339
  b.x = maxX;
30336
30340
  b.vx *= wallRestitution;
30341
+ bounceScaleX[i] = 0.78;
30342
+ bounceScaleY[i] = 1.14;
30337
30343
  }
30338
30344
  if (b.y <= minY) {
30339
30345
  b.y = minY;
30340
30346
  b.vy *= wallRestitution;
30341
- }
30342
- if (b.y >= maxY) {
30347
+ bounceScaleY[i] = 0.78;
30348
+ bounceScaleX[i] = 1.14;
30349
+ } else if (b.y >= maxY) {
30343
30350
  b.y = maxY;
30344
30351
  b.vy *= wallRestitution;
30352
+ bounceScaleY[i] = 0.78;
30353
+ bounceScaleX[i] = 1.14;
30345
30354
  }
30346
30355
  }
30347
30356
  for (let i = 0; i < numDice; i++) {
@@ -30367,6 +30376,10 @@ function simulateDice(arenaW, arenaH, diceSize, starts, numDice) {
30367
30376
  a.vy += impulse * ny;
30368
30377
  b.vx -= impulse * nx;
30369
30378
  b.vy -= impulse * ny;
30379
+ bounceScaleX[i] = 0.88;
30380
+ bounceScaleY[i] = 1.08;
30381
+ bounceScaleX[j] = 0.88;
30382
+ bounceScaleY[j] = 1.08;
30370
30383
  }
30371
30384
  }
30372
30385
  }
@@ -30379,7 +30392,18 @@ function simulateDice(arenaW, arenaH, diceSize, starts, numDice) {
30379
30392
  b.x = clamp(b.x, minX, maxX);
30380
30393
  b.y = clamp(b.y, minY, maxY);
30381
30394
  }
30382
- frames.push(bodies.map((b) => ({ x: b.x, y: b.y })));
30395
+ for (let i = 0; i < numDice; i++) {
30396
+ bounceScaleX[i] += (1 - bounceScaleX[i]) * 0.35;
30397
+ bounceScaleY[i] += (1 - bounceScaleY[i]) * 0.35;
30398
+ }
30399
+ frames.push(
30400
+ bodies.map((b, i) => ({
30401
+ x: b.x,
30402
+ y: b.y,
30403
+ sx: bounceScaleX[i],
30404
+ sy: bounceScaleY[i]
30405
+ }))
30406
+ );
30383
30407
  }
30384
30408
  return frames;
30385
30409
  }
@@ -30505,6 +30529,33 @@ function DiceRoller({
30505
30529
  const shadowRefs = (0, import_react66.useRef)([]);
30506
30530
  const currentPositionsRef = (0, import_react66.useRef)(null);
30507
30531
  const rollingRef = (0, import_react66.useRef)(false);
30532
+ const dieSetters = (0, import_react66.useRef)([]);
30533
+ const cubeSetters = (0, import_react66.useRef)([]);
30534
+ const shadowSetters = (0, import_react66.useRef)([]);
30535
+ const getDieSetter = (i) => {
30536
+ if (!dieSetters.current[i]) {
30537
+ dieSetters.current[i] = (el) => {
30538
+ dieWrapperRefs.current[i] = el;
30539
+ };
30540
+ }
30541
+ return dieSetters.current[i];
30542
+ };
30543
+ const getCubeSetter = (i) => {
30544
+ if (!cubeSetters.current[i]) {
30545
+ cubeSetters.current[i] = (el) => {
30546
+ cubeRefs.current[i] = el;
30547
+ };
30548
+ }
30549
+ return cubeSetters.current[i];
30550
+ };
30551
+ const getShadowSetter = (i) => {
30552
+ if (!shadowSetters.current[i]) {
30553
+ shadowSetters.current[i] = (el) => {
30554
+ shadowRefs.current[i] = el;
30555
+ };
30556
+ }
30557
+ return shadowSetters.current[i];
30558
+ };
30508
30559
  const timersRef = (0, import_react66.useRef)([]);
30509
30560
  const rafHandleRef = (0, import_react66.useRef)(null);
30510
30561
  const arenaRef = (0, import_react66.useRef)(null);
@@ -30576,10 +30627,10 @@ function DiceRoller({
30576
30627
  []
30577
30628
  );
30578
30629
  const writeDiePosition = (0, import_react66.useCallback)(
30579
- (i, x, y) => {
30630
+ (i, x, y, sx = 1, sy = 1) => {
30580
30631
  const el = dieWrapperRefs.current[i];
30581
30632
  if (!el) return;
30582
- el.style.transform = `translate3d(${x - half}px, ${y - half}px, 0)`;
30633
+ el.style.transform = `translate3d(${x - half}px, ${y - half}px, 0) scale3d(${sx}, ${sy}, 1)`;
30583
30634
  },
30584
30635
  [half]
30585
30636
  );
@@ -30603,7 +30654,7 @@ function DiceRoller({
30603
30654
  const el = dieWrapperRefs.current[i];
30604
30655
  if (el) {
30605
30656
  el.style.transition = "transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94)";
30606
- el.style.transform = `translate3d(${pos.x - half}px, ${pos.y - half}px, 0)`;
30657
+ el.style.transform = `translate3d(${pos.x - half}px, ${pos.y - half}px, 0) scale3d(1, 1, 1)`;
30607
30658
  }
30608
30659
  const cube = cubeRefs.current[i];
30609
30660
  if (cube) {
@@ -30634,9 +30685,24 @@ function DiceRoller({
30634
30685
  cancelAnimationFrame(rafHandleRef.current);
30635
30686
  rafHandleRef.current = null;
30636
30687
  }
30637
- const w = arenaRef.current?.offsetWidth ?? 400;
30638
- const h = arenaRef.current?.offsetHeight ?? 260;
30688
+ const rawW = arenaRef.current?.offsetWidth ?? 0;
30689
+ const rawH = arenaRef.current?.offsetHeight ?? 0;
30690
+ const w = rawW > 20 ? rawW : 400;
30691
+ const h = rawH > 20 ? rawH : 260;
30639
30692
  const starts = currentPositionsRef.current ?? defaultPositions(w, h, clampedCount);
30693
+ if (typeof console !== "undefined") {
30694
+ console.log("[DiceRoller] roll()", {
30695
+ rawArena: { w: rawW, h: rawH },
30696
+ physicsArena: { w, h },
30697
+ clampedCount,
30698
+ effectiveSize,
30699
+ starts,
30700
+ refs: {
30701
+ die: dieWrapperRefs.current.map((el) => !!el),
30702
+ cube: cubeRefs.current.map((el) => !!el)
30703
+ }
30704
+ });
30705
+ }
30640
30706
  if (reducedMotion) {
30641
30707
  const final = defaultPositions(w, h, clampedCount);
30642
30708
  currentPositionsRef.current = final;
@@ -30645,7 +30711,7 @@ function DiceRoller({
30645
30711
  const el = dieWrapperRefs.current[i];
30646
30712
  if (el) {
30647
30713
  el.style.transition = "transform 0.2s ease-out";
30648
- el.style.transform = `translate3d(${p.x - half}px, ${p.y - half}px, 0)`;
30714
+ el.style.transform = `translate3d(${p.x - half}px, ${p.y - half}px, 0) scale3d(1, 1, 1)`;
30649
30715
  }
30650
30716
  const tgt = SHOW_ROT[vals[i]];
30651
30717
  writeCubeRotation(i, tgt.x, tgt.y, 0, true);
@@ -30677,37 +30743,38 @@ function DiceRoller({
30677
30743
  if (dieWrapperRefs.current[0]) {
30678
30744
  dieWrapperRefs.current[0].offsetHeight;
30679
30745
  }
30680
- const playbackMs = TUMBLE_MS;
30681
- const startTime = typeof performance !== "undefined" ? performance.now() : Date.now();
30682
- const tick = (now) => {
30683
- const elapsed = now - startTime;
30684
- const progress = Math.max(0, Math.min(1, elapsed / playbackMs));
30685
- const idx = Math.min(
30686
- frames.length - 1,
30687
- Math.floor(progress * frames.length)
30688
- );
30689
- const frame = frames[idx];
30690
- if (frame) {
30746
+ const stepMs = Math.max(20, Math.floor(TUMBLE_MS / frames.length));
30747
+ for (let s = 0; s < frames.length; s++) {
30748
+ const capturedStep = s;
30749
+ const timer = setTimeout(() => {
30750
+ const frame = frames[capturedStep];
30751
+ if (!frame) return;
30691
30752
  for (let i = 0; i < clampedCount; i++) {
30692
30753
  const p = frame[i];
30693
- if (p) writeDiePosition(i, p.x, p.y);
30754
+ if (!p) continue;
30755
+ writeDiePosition(i, p.x, p.y, p.sx, p.sy);
30694
30756
  }
30695
- currentPositionsRef.current = frame.slice(0, clampedCount);
30696
- }
30697
- if (progress < 1) {
30698
- rafHandleRef.current = requestAnimationFrame(tick);
30699
- } else {
30700
- rafHandleRef.current = null;
30701
- for (let i = 0; i < clampedCount; i++) {
30702
- const el = dieWrapperRefs.current[i];
30703
- if (el)
30704
- el.style.transition = "transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94)";
30705
- const shadow = shadowRefs.current[i];
30706
- if (shadow) shadow.style.opacity = "0.85";
30757
+ if (capturedStep === 0 && typeof console !== "undefined") {
30758
+ const el0 = dieWrapperRefs.current[0];
30759
+ console.log("[DiceRoller] first frame written", {
30760
+ frame0: frame,
30761
+ el0transform: el0?.style.transform,
30762
+ el0bounds: el0 ? { w: el0.offsetWidth, h: el0.offsetHeight } : null
30763
+ });
30707
30764
  }
30708
- }
30709
- };
30710
- rafHandleRef.current = requestAnimationFrame(tick);
30765
+ currentPositionsRef.current = frame.slice(0, clampedCount).map((f) => ({ x: f.x, y: f.y }));
30766
+ if (capturedStep === frames.length - 1) {
30767
+ for (let i = 0; i < clampedCount; i++) {
30768
+ const el = dieWrapperRefs.current[i];
30769
+ if (el)
30770
+ el.style.transition = "transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94)";
30771
+ const shadow = shadowRefs.current[i];
30772
+ if (shadow) shadow.style.opacity = "0.85";
30773
+ }
30774
+ }
30775
+ }, capturedStep * stepMs);
30776
+ timersRef.current.push(timer);
30777
+ }
30711
30778
  requestAnimationFrame(() => {
30712
30779
  requestAnimationFrame(() => {
30713
30780
  for (let i = 0; i < clampedCount; i++) {
@@ -30794,9 +30861,7 @@ function DiceRoller({
30794
30861
  return /* @__PURE__ */ (0, import_jsx_runtime114.jsxs)(
30795
30862
  "div",
30796
30863
  {
30797
- ref: (el) => {
30798
- dieWrapperRefs.current[d] = el;
30799
- },
30864
+ ref: getDieSetter(d),
30800
30865
  style: {
30801
30866
  position: "absolute",
30802
30867
  left: 0,
@@ -30815,9 +30880,7 @@ function DiceRoller({
30815
30880
  /* @__PURE__ */ (0, import_jsx_runtime114.jsx)(
30816
30881
  "div",
30817
30882
  {
30818
- ref: (el) => {
30819
- shadowRefs.current[d] = el;
30820
- },
30883
+ ref: getShadowSetter(d),
30821
30884
  style: {
30822
30885
  position: "absolute",
30823
30886
  bottom: -6,
@@ -30835,9 +30898,7 @@ function DiceRoller({
30835
30898
  /* @__PURE__ */ (0, import_jsx_runtime114.jsx)(
30836
30899
  "div",
30837
30900
  {
30838
- ref: (el) => {
30839
- cubeRefs.current[d] = el;
30840
- },
30901
+ ref: getCubeSetter(d),
30841
30902
  style: {
30842
30903
  width: "100%",
30843
30904
  height: "100%",