@bug-on/m3-expressive 1.2.6 → 1.2.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @bug-on/m3-expressive
2
2
 
3
+ ## 1.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 81a5076: Fix issues Circular Indeterminate do not work.
8
+
3
9
  ## 1.2.6
4
10
 
5
11
  ### Patch Changes
package/dist/buttons.js CHANGED
@@ -278,7 +278,7 @@ function generateWavyCircularPath(center, radius, amplitude, wavelength) {
278
278
  if (i === 0) d += `M ${xAt(t0).toFixed(2)} ${yAt(t0).toFixed(2)}`;
279
279
  d += ` C ${cp1x.toFixed(2)} ${cp1y.toFixed(2)}, ${cp2x.toFixed(2)} ${cp2y.toFixed(2)}, ${xAt(t1).toFixed(2)} ${yAt(t1).toFixed(2)}`;
280
280
  }
281
- return d;
281
+ return `${d} Z`;
282
282
  }
283
283
  function getSinePath(startX, endX, phase, wl, amp) {
284
284
  if (startX >= endX) return "";
@@ -310,6 +310,14 @@ function getSinePath(startX, endX, phase, wl, amp) {
310
310
  }
311
311
  return d;
312
312
  }
313
+ var GLOBAL_ROTATION_DURATION = 6e3;
314
+ var GLOBAL_ROTATION_TARGET = 1080;
315
+ var ADDITIONAL_ROTATION_CYCLE = 1500;
316
+ var ADDITIONAL_ROTATION_STEP = 90;
317
+ var ADDITIONAL_ROTATION_EASE_DURATION = 500;
318
+ var DEFAULT_MIN_PROGRESS = 0.1;
319
+ var DEFAULT_MAX_PROGRESS = 0.8;
320
+ var PROGRESS_CYCLE_DURATION = 1500;
313
321
  var CircularProgress = React16__namespace.forwardRef(
314
322
  (_a, ref) => {
315
323
  var _b = _a, {
@@ -323,6 +331,10 @@ var CircularProgress = React16__namespace.forwardRef(
323
331
  crawlerSpeed = 1,
324
332
  color,
325
333
  trackColor,
334
+ showTrack = "auto",
335
+ minProgress = DEFAULT_MIN_PROGRESS,
336
+ maxProgress = DEFAULT_MAX_PROGRESS,
337
+ amplitudeRange,
326
338
  className,
327
339
  "aria-label": ariaLabel
328
340
  } = _b, restProps = __objRest(_b, [
@@ -336,6 +348,10 @@ var CircularProgress = React16__namespace.forwardRef(
336
348
  "crawlerSpeed",
337
349
  "color",
338
350
  "trackColor",
351
+ "showTrack",
352
+ "minProgress",
353
+ "maxProgress",
354
+ "amplitudeRange",
339
355
  "className",
340
356
  "aria-label"
341
357
  ]);
@@ -346,6 +362,7 @@ var CircularProgress = React16__namespace.forwardRef(
346
362
  const activeColor = color || "var(--md-sys-color-indicator-active)";
347
363
  const bgTrackColor = trackColor || "var(--md-sys-color-indicator-track)";
348
364
  const isWavy = shape === "wavy";
365
+ const shouldShowIndeterminateTrack = showTrack === "auto" ? isWavy : showTrack;
349
366
  const BASELINE_SIZE = 48;
350
367
  const scaleFactor = size / BASELINE_SIZE;
351
368
  const effectiveAmplitude = React16__namespace.useMemo(
@@ -356,6 +373,10 @@ var CircularProgress = React16__namespace.forwardRef(
356
373
  () => wavelength != null ? wavelength : 15 * scaleFactor,
357
374
  [wavelength, scaleFactor]
358
375
  );
376
+ const resolvedAmplitudeRange = React16__namespace.useMemo(
377
+ () => amplitudeRange != null ? amplitudeRange : [0, effectiveAmplitude],
378
+ [amplitudeRange, effectiveAmplitude]
379
+ );
359
380
  const wavyActivePath = React16__namespace.useMemo(
360
381
  () => isWavy ? generateWavyCircularPath(
361
382
  center,
@@ -375,6 +396,145 @@ var CircularProgress = React16__namespace.forwardRef(
375
396
  const trackLength = isDeterminate ? Math.max(1e-3, 1 - activeAngularFraction - 2 * gapForTrack) : 1;
376
397
  const ActiveCircleElem = react.m.circle;
377
398
  const ActivePathElem = react.m.path;
399
+ const indeterminateSvgRef = React16__namespace.useRef(null);
400
+ const indeterminateTrackRef = React16__namespace.useRef(null);
401
+ const indeterminateActiveRef = React16__namespace.useRef(null);
402
+ const indeterminateWavyTrackPathRef = React16__namespace.useRef(null);
403
+ const indeterminateWavyActivePathRef = React16__namespace.useRef(null);
404
+ const cachedPathLengthRef = React16__namespace.useRef(0);
405
+ React16__namespace.useLayoutEffect(() => {
406
+ if (!isWavy || !wavyActivePath) {
407
+ cachedPathLengthRef.current = circumference;
408
+ return;
409
+ }
410
+ const el = indeterminateActiveRef.current;
411
+ if (el && "getTotalLength" in el) {
412
+ try {
413
+ const len = el.getTotalLength();
414
+ if (len > 0) {
415
+ cachedPathLengthRef.current = len;
416
+ return;
417
+ }
418
+ } catch (e) {
419
+ }
420
+ }
421
+ cachedPathLengthRef.current = circumference;
422
+ }, [isWavy, circumference, wavyActivePath]);
423
+ react.useAnimationFrame((time) => {
424
+ if (isDeterminate) return;
425
+ const safeCrawlerSpeed = Math.max(0.1, crawlerSpeed);
426
+ const scaledTime = time * safeCrawlerSpeed;
427
+ const globalCycle = scaledTime % GLOBAL_ROTATION_DURATION;
428
+ const globalAngle = globalCycle / GLOBAL_ROTATION_DURATION * GLOBAL_ROTATION_TARGET;
429
+ const additionalFullCycles = Math.floor(
430
+ scaledTime / ADDITIONAL_ROTATION_CYCLE
431
+ );
432
+ const additionalCycleTime = scaledTime % ADDITIONAL_ROTATION_CYCLE;
433
+ const additionalEaseT = Math.min(
434
+ 1,
435
+ additionalCycleTime / ADDITIONAL_ROTATION_EASE_DURATION
436
+ );
437
+ const additionalAngle = (additionalFullCycles + easeInOutCubic(additionalEaseT)) * ADDITIONAL_ROTATION_STEP;
438
+ const totalRotation = globalAngle + additionalAngle;
439
+ if (indeterminateSvgRef.current) {
440
+ indeterminateSvgRef.current.style.transform = `rotate(${totalRotation - 90}deg)`;
441
+ }
442
+ const progressFullCycle = PROGRESS_CYCLE_DURATION * 2;
443
+ const progressCycleTime = scaledTime % progressFullCycle;
444
+ let progress;
445
+ if (progressCycleTime < PROGRESS_CYCLE_DURATION) {
446
+ const t = progressCycleTime / PROGRESS_CYCLE_DURATION;
447
+ progress = minProgress + (maxProgress - minProgress) * easeInOutCubic(t);
448
+ } else {
449
+ const t = (progressCycleTime - PROGRESS_CYCLE_DURATION) / PROGRESS_CYCLE_DURATION;
450
+ progress = maxProgress - (maxProgress - minProgress) * easeInOutCubic(t);
451
+ }
452
+ if (isWavy) {
453
+ const amplitudeT = (progress - minProgress) / (maxProgress - minProgress);
454
+ const currentAmplitude = resolvedAmplitudeRange[0] + (resolvedAmplitudeRange[1] - resolvedAmplitudeRange[0]) * amplitudeT;
455
+ const dynamicPath = generateWavyCircularPath(
456
+ center,
457
+ radius,
458
+ currentAmplitude,
459
+ effectiveWavelength
460
+ );
461
+ if (indeterminateWavyActivePathRef.current) {
462
+ indeterminateWavyActivePathRef.current.setAttribute("d", dynamicPath);
463
+ }
464
+ if (indeterminateWavyTrackPathRef.current) {
465
+ indeterminateWavyTrackPathRef.current.setAttribute("d", dynamicPath);
466
+ }
467
+ const pathEl = indeterminateWavyActivePathRef.current;
468
+ let totalLen = cachedPathLengthRef.current || circumference;
469
+ if (pathEl) {
470
+ try {
471
+ const len = pathEl.getTotalLength();
472
+ if (len > 0) totalLen = len;
473
+ } catch (e) {
474
+ }
475
+ }
476
+ const gapFrac = (gapSize + trackHeight) / totalLen;
477
+ const activeLen = totalLen * progress;
478
+ const activeOff = 0;
479
+ if (indeterminateWavyActivePathRef.current) {
480
+ indeterminateWavyActivePathRef.current.setAttribute(
481
+ "stroke-dasharray",
482
+ `${activeLen} ${totalLen}`
483
+ );
484
+ indeterminateWavyActivePathRef.current.setAttribute(
485
+ "stroke-dashoffset",
486
+ `${activeOff}`
487
+ );
488
+ }
489
+ if (shouldShowIndeterminateTrack && indeterminateWavyTrackPathRef.current) {
490
+ const trackStartFrac = progress + gapFrac;
491
+ const trackLen = Math.max(
492
+ 1e-3,
493
+ totalLen * (1 - progress - 2 * gapFrac)
494
+ );
495
+ const trackOff = -totalLen * trackStartFrac;
496
+ indeterminateWavyTrackPathRef.current.setAttribute(
497
+ "stroke-dasharray",
498
+ `${trackLen} ${totalLen}`
499
+ );
500
+ indeterminateWavyTrackPathRef.current.setAttribute(
501
+ "stroke-dashoffset",
502
+ `${trackOff}`
503
+ );
504
+ }
505
+ } else {
506
+ const totalLen = circumference;
507
+ const activeLen = totalLen * progress;
508
+ const activeOff = 0;
509
+ if (indeterminateActiveRef.current) {
510
+ indeterminateActiveRef.current.setAttribute(
511
+ "stroke-dasharray",
512
+ `${activeLen} ${totalLen}`
513
+ );
514
+ indeterminateActiveRef.current.setAttribute(
515
+ "stroke-dashoffset",
516
+ `${activeOff}`
517
+ );
518
+ }
519
+ if (shouldShowIndeterminateTrack && indeterminateTrackRef.current) {
520
+ const gapFrac = (gapSize + trackHeight) / totalLen;
521
+ const trackStartFrac = progress + gapFrac;
522
+ const trackLen = Math.max(
523
+ 1e-3,
524
+ totalLen * (1 - progress - 2 * gapFrac)
525
+ );
526
+ const trackOff = -totalLen * trackStartFrac;
527
+ indeterminateTrackRef.current.setAttribute(
528
+ "stroke-dasharray",
529
+ `${trackLen} ${totalLen}`
530
+ );
531
+ indeterminateTrackRef.current.setAttribute(
532
+ "stroke-dashoffset",
533
+ `${trackOff}`
534
+ );
535
+ }
536
+ }
537
+ });
378
538
  return /* @__PURE__ */ jsxRuntime.jsx(
379
539
  "div",
380
540
  __spreadProps(__spreadValues({
@@ -451,9 +611,10 @@ var CircularProgress = React16__namespace.forwardRef(
451
611
  ]
452
612
  }
453
613
  ),
454
- !isDeterminate && /* @__PURE__ */ jsxRuntime.jsxs(
455
- react.m.svg,
614
+ !isDeterminate && /* @__PURE__ */ jsxRuntime.jsx(
615
+ "svg",
456
616
  {
617
+ ref: indeterminateSvgRef,
457
618
  width: size,
458
619
  height: size,
459
620
  viewBox: `0 0 ${size} ${size}`,
@@ -462,84 +623,60 @@ var CircularProgress = React16__namespace.forwardRef(
462
623
  position: "absolute",
463
624
  inset: 0,
464
625
  overflow: "visible",
465
- transformOrigin: "center"
626
+ transformOrigin: "center",
627
+ transform: "rotate(-90deg)"
466
628
  },
467
- animate: { rotate: [0, 360] },
468
- transition: {
469
- duration: 2 / Math.max(0.1, crawlerSpeed),
470
- repeat: Number.POSITIVE_INFINITY,
471
- ease: "linear"
472
- },
473
- children: [
474
- /* @__PURE__ */ jsxRuntime.jsx(
475
- react.m.circle,
629
+ children: isWavy ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
630
+ shouldShowIndeterminateTrack && /* @__PURE__ */ jsxRuntime.jsx(
631
+ "path",
476
632
  {
477
- cx: center,
478
- cy: center,
479
- r: radius,
633
+ ref: indeterminateWavyTrackPathRef,
634
+ d: wavyActivePath != null ? wavyActivePath : "",
480
635
  fill: "none",
481
636
  stroke: bgTrackColor,
482
637
  strokeWidth: trackHeight,
483
- strokeLinecap: "round",
484
- animate: {
485
- pathLength: [
486
- Math.max(1e-3, 0.9 - 2 * gapForTrack),
487
- Math.max(1e-3, 0.25 - 2 * gapForTrack),
488
- Math.max(1e-3, 0.9 - 2 * gapForTrack)
489
- ],
490
- pathOffset: [
491
- 0.1 + gapForTrack,
492
- 0.75 + gapForTrack,
493
- 0.1 + gapForTrack
494
- ]
495
- },
496
- transition: {
497
- duration: 2 / Math.max(0.1, crawlerSpeed),
498
- repeat: Number.POSITIVE_INFINITY,
499
- ease: [0.4, 0, 0.2, 1]
500
- }
638
+ strokeLinecap: "round"
501
639
  }
502
640
  ),
503
- isWavy ? /* @__PURE__ */ jsxRuntime.jsx(
504
- ActivePathElem,
641
+ /* @__PURE__ */ jsxRuntime.jsx(
642
+ "path",
505
643
  {
644
+ ref: indeterminateWavyActivePathRef,
506
645
  d: wavyActivePath != null ? wavyActivePath : "",
507
646
  fill: "none",
508
647
  stroke: activeColor,
509
648
  strokeWidth: trackHeight,
510
- strokeLinecap: "round",
511
- animate: {
512
- pathLength: [0.1, 0.75, 0.1],
513
- pathOffset: [0, 0.65, 1]
514
- },
515
- transition: {
516
- duration: 2 / Math.max(0.1, crawlerSpeed),
517
- repeat: Number.POSITIVE_INFINITY,
518
- ease: [0.4, 0, 0.2, 1]
519
- }
649
+ strokeLinecap: "round"
520
650
  }
521
- ) : /* @__PURE__ */ jsxRuntime.jsx(
522
- ActiveCircleElem,
651
+ )
652
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
653
+ shouldShowIndeterminateTrack && /* @__PURE__ */ jsxRuntime.jsx(
654
+ "circle",
523
655
  {
656
+ ref: indeterminateTrackRef,
657
+ cx: center,
658
+ cy: center,
659
+ r: radius,
660
+ fill: "none",
661
+ stroke: bgTrackColor,
662
+ strokeWidth: trackHeight,
663
+ strokeLinecap: "round"
664
+ }
665
+ ),
666
+ /* @__PURE__ */ jsxRuntime.jsx(
667
+ "circle",
668
+ {
669
+ ref: indeterminateActiveRef,
524
670
  cx: center,
525
671
  cy: center,
526
672
  r: radius,
527
673
  fill: "none",
528
674
  stroke: activeColor,
529
675
  strokeWidth: trackHeight,
530
- strokeLinecap: "round",
531
- animate: {
532
- pathLength: [0.1, 0.75, 0.1],
533
- pathOffset: [0, 0.65, 1]
534
- },
535
- transition: {
536
- duration: 2 / Math.max(0.1, crawlerSpeed),
537
- repeat: Number.POSITIVE_INFINITY,
538
- ease: [0.4, 0, 0.2, 1]
539
- }
676
+ strokeLinecap: "round"
540
677
  }
541
678
  )
542
- ]
679
+ ] })
543
680
  }
544
681
  )
545
682
  ] })
@@ -745,7 +882,7 @@ var WavyLinearTrack = React16__namespace.memo(function WavyLinearTrack2({
745
882
  currentAmp
746
883
  );
747
884
  } else if (fraction === 0) {
748
- activePathD = `M ${capWidth} 0 L ${capWidth + 0.01} 0`;
885
+ activePathD = "";
749
886
  }
750
887
  const trackStart = adjHead + totalGap;
751
888
  if (trackStart < width - capWidth) {
@@ -777,20 +914,20 @@ var WavyLinearTrack = React16__namespace.memo(function WavyLinearTrack2({
777
914
  activeLines.push({ tail: l1T, head: l1H });
778
915
  activeLines.push({ tail: l2T, head: l2H });
779
916
  }
780
- const segments = activeLines.map((line) => {
781
- const barTail = line.tail * width;
782
- const barHead = line.head * width;
917
+ const activeSegments = activeLines.map((line) => {
918
+ const rawTail = line.tail * width;
919
+ const rawHead = line.head * width;
783
920
  const adjTail = Math.max(
784
921
  capWidth,
785
- Math.min(width - capWidth, barTail)
922
+ Math.min(width - capWidth, rawTail)
786
923
  );
787
924
  const adjHead = Math.max(
788
925
  capWidth,
789
- Math.min(width - capWidth, barHead)
926
+ Math.min(width - capWidth, rawHead)
790
927
  );
791
928
  return { adjTail, adjHead };
792
929
  }).filter((seg) => seg.adjHead - seg.adjTail > 0.1);
793
- activePathD = segments.map(
930
+ activePathD = activeSegments.map(
794
931
  (seg) => getSinePath(
795
932
  seg.adjTail,
796
933
  seg.adjHead,
@@ -799,13 +936,24 @@ var WavyLinearTrack = React16__namespace.memo(function WavyLinearTrack2({
799
936
  currentAmp
800
937
  )
801
938
  ).join(" ");
939
+ const validActiveLines = activeLines.filter(
940
+ (line) => line.head > line.tail && line.head * width > 0 && line.tail * width < width
941
+ ).sort((a, b) => a.tail - b.tail);
802
942
  let currentTrackX = capWidth;
803
- for (const seg of segments) {
804
- const trackEnd = seg.adjTail - totalGap;
943
+ for (const line of validActiveLines) {
944
+ const blockStart = line.tail * width - totalGap;
945
+ const blockEnd = line.head * width + totalGap;
946
+ const trackEnd = Math.min(width - capWidth, blockStart);
805
947
  if (trackEnd > currentTrackX) {
806
- trackD += `${getSinePath(currentTrackX, trackEnd, phase, activeWavelength, trackAmp)} `;
948
+ trackD += `${getSinePath(
949
+ currentTrackX,
950
+ trackEnd,
951
+ phase,
952
+ activeWavelength,
953
+ trackAmp
954
+ )} `;
807
955
  }
808
- currentTrackX = Math.max(currentTrackX, seg.adjHead + totalGap);
956
+ currentTrackX = Math.max(currentTrackX, blockEnd);
809
957
  }
810
958
  if (currentTrackX < width - capWidth) {
811
959
  trackD += getSinePath(
@@ -818,9 +966,9 @@ var WavyLinearTrack = React16__namespace.memo(function WavyLinearTrack2({
818
966
  }
819
967
  }
820
968
  if (activePathRef.current)
821
- activePathRef.current.setAttribute("d", activePathD);
969
+ activePathRef.current.setAttribute("d", activePathD || "");
822
970
  if (trackPathRef.current)
823
- trackPathRef.current.setAttribute("d", trackD.trim());
971
+ trackPathRef.current.setAttribute("d", trackD.trim() || "");
824
972
  });
825
973
  return /* @__PURE__ */ jsxRuntime.jsx(
826
974
  "div",