@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/dist/index.js CHANGED
@@ -5714,7 +5714,7 @@ function generateWavyCircularPath(center, radius, amplitude, wavelength) {
5714
5714
  if (i === 0) d += `M ${xAt(t0).toFixed(2)} ${yAt(t0).toFixed(2)}`;
5715
5715
  d += ` C ${cp1x.toFixed(2)} ${cp1y.toFixed(2)}, ${cp2x.toFixed(2)} ${cp2y.toFixed(2)}, ${xAt(t1).toFixed(2)} ${yAt(t1).toFixed(2)}`;
5716
5716
  }
5717
- return d;
5717
+ return `${d} Z`;
5718
5718
  }
5719
5719
  function getSinePath(startX, endX, phase, wl, amp) {
5720
5720
  if (startX >= endX) return "";
@@ -5746,6 +5746,14 @@ function getSinePath(startX, endX, phase, wl, amp) {
5746
5746
  }
5747
5747
  return d;
5748
5748
  }
5749
+ var GLOBAL_ROTATION_DURATION = 6e3;
5750
+ var GLOBAL_ROTATION_TARGET = 1080;
5751
+ var ADDITIONAL_ROTATION_CYCLE = 1500;
5752
+ var ADDITIONAL_ROTATION_STEP = 90;
5753
+ var ADDITIONAL_ROTATION_EASE_DURATION = 500;
5754
+ var DEFAULT_MIN_PROGRESS = 0.1;
5755
+ var DEFAULT_MAX_PROGRESS = 0.8;
5756
+ var PROGRESS_CYCLE_DURATION = 1500;
5749
5757
  var CircularProgress = React62__namespace.forwardRef(
5750
5758
  (_a, ref) => {
5751
5759
  var _b = _a, {
@@ -5759,6 +5767,10 @@ var CircularProgress = React62__namespace.forwardRef(
5759
5767
  crawlerSpeed = 1,
5760
5768
  color,
5761
5769
  trackColor,
5770
+ showTrack = "auto",
5771
+ minProgress = DEFAULT_MIN_PROGRESS,
5772
+ maxProgress = DEFAULT_MAX_PROGRESS,
5773
+ amplitudeRange,
5762
5774
  className,
5763
5775
  "aria-label": ariaLabel
5764
5776
  } = _b, restProps = __objRest(_b, [
@@ -5772,6 +5784,10 @@ var CircularProgress = React62__namespace.forwardRef(
5772
5784
  "crawlerSpeed",
5773
5785
  "color",
5774
5786
  "trackColor",
5787
+ "showTrack",
5788
+ "minProgress",
5789
+ "maxProgress",
5790
+ "amplitudeRange",
5775
5791
  "className",
5776
5792
  "aria-label"
5777
5793
  ]);
@@ -5782,6 +5798,7 @@ var CircularProgress = React62__namespace.forwardRef(
5782
5798
  const activeColor = color || "var(--md-sys-color-indicator-active)";
5783
5799
  const bgTrackColor = trackColor || "var(--md-sys-color-indicator-track)";
5784
5800
  const isWavy = shape === "wavy";
5801
+ const shouldShowIndeterminateTrack = showTrack === "auto" ? isWavy : showTrack;
5785
5802
  const BASELINE_SIZE = 48;
5786
5803
  const scaleFactor = size / BASELINE_SIZE;
5787
5804
  const effectiveAmplitude = React62__namespace.useMemo(
@@ -5792,6 +5809,10 @@ var CircularProgress = React62__namespace.forwardRef(
5792
5809
  () => wavelength != null ? wavelength : 15 * scaleFactor,
5793
5810
  [wavelength, scaleFactor]
5794
5811
  );
5812
+ const resolvedAmplitudeRange = React62__namespace.useMemo(
5813
+ () => amplitudeRange != null ? amplitudeRange : [0, effectiveAmplitude],
5814
+ [amplitudeRange, effectiveAmplitude]
5815
+ );
5795
5816
  const wavyActivePath = React62__namespace.useMemo(
5796
5817
  () => isWavy ? generateWavyCircularPath(
5797
5818
  center,
@@ -5811,6 +5832,145 @@ var CircularProgress = React62__namespace.forwardRef(
5811
5832
  const trackLength = isDeterminate ? Math.max(1e-3, 1 - activeAngularFraction - 2 * gapForTrack) : 1;
5812
5833
  const ActiveCircleElem = react.m.circle;
5813
5834
  const ActivePathElem = react.m.path;
5835
+ const indeterminateSvgRef = React62__namespace.useRef(null);
5836
+ const indeterminateTrackRef = React62__namespace.useRef(null);
5837
+ const indeterminateActiveRef = React62__namespace.useRef(null);
5838
+ const indeterminateWavyTrackPathRef = React62__namespace.useRef(null);
5839
+ const indeterminateWavyActivePathRef = React62__namespace.useRef(null);
5840
+ const cachedPathLengthRef = React62__namespace.useRef(0);
5841
+ React62__namespace.useLayoutEffect(() => {
5842
+ if (!isWavy || !wavyActivePath) {
5843
+ cachedPathLengthRef.current = circumference;
5844
+ return;
5845
+ }
5846
+ const el = indeterminateActiveRef.current;
5847
+ if (el && "getTotalLength" in el) {
5848
+ try {
5849
+ const len = el.getTotalLength();
5850
+ if (len > 0) {
5851
+ cachedPathLengthRef.current = len;
5852
+ return;
5853
+ }
5854
+ } catch (e) {
5855
+ }
5856
+ }
5857
+ cachedPathLengthRef.current = circumference;
5858
+ }, [isWavy, circumference, wavyActivePath]);
5859
+ react.useAnimationFrame((time) => {
5860
+ if (isDeterminate) return;
5861
+ const safeCrawlerSpeed = Math.max(0.1, crawlerSpeed);
5862
+ const scaledTime = time * safeCrawlerSpeed;
5863
+ const globalCycle = scaledTime % GLOBAL_ROTATION_DURATION;
5864
+ const globalAngle = globalCycle / GLOBAL_ROTATION_DURATION * GLOBAL_ROTATION_TARGET;
5865
+ const additionalFullCycles = Math.floor(
5866
+ scaledTime / ADDITIONAL_ROTATION_CYCLE
5867
+ );
5868
+ const additionalCycleTime = scaledTime % ADDITIONAL_ROTATION_CYCLE;
5869
+ const additionalEaseT = Math.min(
5870
+ 1,
5871
+ additionalCycleTime / ADDITIONAL_ROTATION_EASE_DURATION
5872
+ );
5873
+ const additionalAngle = (additionalFullCycles + easeInOutCubic(additionalEaseT)) * ADDITIONAL_ROTATION_STEP;
5874
+ const totalRotation = globalAngle + additionalAngle;
5875
+ if (indeterminateSvgRef.current) {
5876
+ indeterminateSvgRef.current.style.transform = `rotate(${totalRotation - 90}deg)`;
5877
+ }
5878
+ const progressFullCycle = PROGRESS_CYCLE_DURATION * 2;
5879
+ const progressCycleTime = scaledTime % progressFullCycle;
5880
+ let progress;
5881
+ if (progressCycleTime < PROGRESS_CYCLE_DURATION) {
5882
+ const t = progressCycleTime / PROGRESS_CYCLE_DURATION;
5883
+ progress = minProgress + (maxProgress - minProgress) * easeInOutCubic(t);
5884
+ } else {
5885
+ const t = (progressCycleTime - PROGRESS_CYCLE_DURATION) / PROGRESS_CYCLE_DURATION;
5886
+ progress = maxProgress - (maxProgress - minProgress) * easeInOutCubic(t);
5887
+ }
5888
+ if (isWavy) {
5889
+ const amplitudeT = (progress - minProgress) / (maxProgress - minProgress);
5890
+ const currentAmplitude = resolvedAmplitudeRange[0] + (resolvedAmplitudeRange[1] - resolvedAmplitudeRange[0]) * amplitudeT;
5891
+ const dynamicPath = generateWavyCircularPath(
5892
+ center,
5893
+ radius,
5894
+ currentAmplitude,
5895
+ effectiveWavelength
5896
+ );
5897
+ if (indeterminateWavyActivePathRef.current) {
5898
+ indeterminateWavyActivePathRef.current.setAttribute("d", dynamicPath);
5899
+ }
5900
+ if (indeterminateWavyTrackPathRef.current) {
5901
+ indeterminateWavyTrackPathRef.current.setAttribute("d", dynamicPath);
5902
+ }
5903
+ const pathEl = indeterminateWavyActivePathRef.current;
5904
+ let totalLen = cachedPathLengthRef.current || circumference;
5905
+ if (pathEl) {
5906
+ try {
5907
+ const len = pathEl.getTotalLength();
5908
+ if (len > 0) totalLen = len;
5909
+ } catch (e) {
5910
+ }
5911
+ }
5912
+ const gapFrac = (gapSize + trackHeight) / totalLen;
5913
+ const activeLen = totalLen * progress;
5914
+ const activeOff = 0;
5915
+ if (indeterminateWavyActivePathRef.current) {
5916
+ indeterminateWavyActivePathRef.current.setAttribute(
5917
+ "stroke-dasharray",
5918
+ `${activeLen} ${totalLen}`
5919
+ );
5920
+ indeterminateWavyActivePathRef.current.setAttribute(
5921
+ "stroke-dashoffset",
5922
+ `${activeOff}`
5923
+ );
5924
+ }
5925
+ if (shouldShowIndeterminateTrack && indeterminateWavyTrackPathRef.current) {
5926
+ const trackStartFrac = progress + gapFrac;
5927
+ const trackLen = Math.max(
5928
+ 1e-3,
5929
+ totalLen * (1 - progress - 2 * gapFrac)
5930
+ );
5931
+ const trackOff = -totalLen * trackStartFrac;
5932
+ indeterminateWavyTrackPathRef.current.setAttribute(
5933
+ "stroke-dasharray",
5934
+ `${trackLen} ${totalLen}`
5935
+ );
5936
+ indeterminateWavyTrackPathRef.current.setAttribute(
5937
+ "stroke-dashoffset",
5938
+ `${trackOff}`
5939
+ );
5940
+ }
5941
+ } else {
5942
+ const totalLen = circumference;
5943
+ const activeLen = totalLen * progress;
5944
+ const activeOff = 0;
5945
+ if (indeterminateActiveRef.current) {
5946
+ indeterminateActiveRef.current.setAttribute(
5947
+ "stroke-dasharray",
5948
+ `${activeLen} ${totalLen}`
5949
+ );
5950
+ indeterminateActiveRef.current.setAttribute(
5951
+ "stroke-dashoffset",
5952
+ `${activeOff}`
5953
+ );
5954
+ }
5955
+ if (shouldShowIndeterminateTrack && indeterminateTrackRef.current) {
5956
+ const gapFrac = (gapSize + trackHeight) / totalLen;
5957
+ const trackStartFrac = progress + gapFrac;
5958
+ const trackLen = Math.max(
5959
+ 1e-3,
5960
+ totalLen * (1 - progress - 2 * gapFrac)
5961
+ );
5962
+ const trackOff = -totalLen * trackStartFrac;
5963
+ indeterminateTrackRef.current.setAttribute(
5964
+ "stroke-dasharray",
5965
+ `${trackLen} ${totalLen}`
5966
+ );
5967
+ indeterminateTrackRef.current.setAttribute(
5968
+ "stroke-dashoffset",
5969
+ `${trackOff}`
5970
+ );
5971
+ }
5972
+ }
5973
+ });
5814
5974
  return /* @__PURE__ */ jsxRuntime.jsx(
5815
5975
  "div",
5816
5976
  __spreadProps(__spreadValues({
@@ -5887,9 +6047,10 @@ var CircularProgress = React62__namespace.forwardRef(
5887
6047
  ]
5888
6048
  }
5889
6049
  ),
5890
- !isDeterminate && /* @__PURE__ */ jsxRuntime.jsxs(
5891
- react.m.svg,
6050
+ !isDeterminate && /* @__PURE__ */ jsxRuntime.jsx(
6051
+ "svg",
5892
6052
  {
6053
+ ref: indeterminateSvgRef,
5893
6054
  width: size,
5894
6055
  height: size,
5895
6056
  viewBox: `0 0 ${size} ${size}`,
@@ -5898,84 +6059,60 @@ var CircularProgress = React62__namespace.forwardRef(
5898
6059
  position: "absolute",
5899
6060
  inset: 0,
5900
6061
  overflow: "visible",
5901
- transformOrigin: "center"
5902
- },
5903
- animate: { rotate: [0, 360] },
5904
- transition: {
5905
- duration: 2 / Math.max(0.1, crawlerSpeed),
5906
- repeat: Number.POSITIVE_INFINITY,
5907
- ease: "linear"
6062
+ transformOrigin: "center",
6063
+ transform: "rotate(-90deg)"
5908
6064
  },
5909
- children: [
5910
- /* @__PURE__ */ jsxRuntime.jsx(
5911
- react.m.circle,
6065
+ children: isWavy ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6066
+ shouldShowIndeterminateTrack && /* @__PURE__ */ jsxRuntime.jsx(
6067
+ "path",
5912
6068
  {
5913
- cx: center,
5914
- cy: center,
5915
- r: radius,
6069
+ ref: indeterminateWavyTrackPathRef,
6070
+ d: wavyActivePath != null ? wavyActivePath : "",
5916
6071
  fill: "none",
5917
6072
  stroke: bgTrackColor,
5918
6073
  strokeWidth: trackHeight,
5919
- strokeLinecap: "round",
5920
- animate: {
5921
- pathLength: [
5922
- Math.max(1e-3, 0.9 - 2 * gapForTrack),
5923
- Math.max(1e-3, 0.25 - 2 * gapForTrack),
5924
- Math.max(1e-3, 0.9 - 2 * gapForTrack)
5925
- ],
5926
- pathOffset: [
5927
- 0.1 + gapForTrack,
5928
- 0.75 + gapForTrack,
5929
- 0.1 + gapForTrack
5930
- ]
5931
- },
5932
- transition: {
5933
- duration: 2 / Math.max(0.1, crawlerSpeed),
5934
- repeat: Number.POSITIVE_INFINITY,
5935
- ease: [0.4, 0, 0.2, 1]
5936
- }
6074
+ strokeLinecap: "round"
5937
6075
  }
5938
6076
  ),
5939
- isWavy ? /* @__PURE__ */ jsxRuntime.jsx(
5940
- ActivePathElem,
6077
+ /* @__PURE__ */ jsxRuntime.jsx(
6078
+ "path",
5941
6079
  {
6080
+ ref: indeterminateWavyActivePathRef,
5942
6081
  d: wavyActivePath != null ? wavyActivePath : "",
5943
6082
  fill: "none",
5944
6083
  stroke: activeColor,
5945
6084
  strokeWidth: trackHeight,
5946
- strokeLinecap: "round",
5947
- animate: {
5948
- pathLength: [0.1, 0.75, 0.1],
5949
- pathOffset: [0, 0.65, 1]
5950
- },
5951
- transition: {
5952
- duration: 2 / Math.max(0.1, crawlerSpeed),
5953
- repeat: Number.POSITIVE_INFINITY,
5954
- ease: [0.4, 0, 0.2, 1]
5955
- }
6085
+ strokeLinecap: "round"
5956
6086
  }
5957
- ) : /* @__PURE__ */ jsxRuntime.jsx(
5958
- ActiveCircleElem,
6087
+ )
6088
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6089
+ shouldShowIndeterminateTrack && /* @__PURE__ */ jsxRuntime.jsx(
6090
+ "circle",
6091
+ {
6092
+ ref: indeterminateTrackRef,
6093
+ cx: center,
6094
+ cy: center,
6095
+ r: radius,
6096
+ fill: "none",
6097
+ stroke: bgTrackColor,
6098
+ strokeWidth: trackHeight,
6099
+ strokeLinecap: "round"
6100
+ }
6101
+ ),
6102
+ /* @__PURE__ */ jsxRuntime.jsx(
6103
+ "circle",
5959
6104
  {
6105
+ ref: indeterminateActiveRef,
5960
6106
  cx: center,
5961
6107
  cy: center,
5962
6108
  r: radius,
5963
6109
  fill: "none",
5964
6110
  stroke: activeColor,
5965
6111
  strokeWidth: trackHeight,
5966
- strokeLinecap: "round",
5967
- animate: {
5968
- pathLength: [0.1, 0.75, 0.1],
5969
- pathOffset: [0, 0.65, 1]
5970
- },
5971
- transition: {
5972
- duration: 2 / Math.max(0.1, crawlerSpeed),
5973
- repeat: Number.POSITIVE_INFINITY,
5974
- ease: [0.4, 0, 0.2, 1]
5975
- }
6112
+ strokeLinecap: "round"
5976
6113
  }
5977
6114
  )
5978
- ]
6115
+ ] })
5979
6116
  }
5980
6117
  )
5981
6118
  ] })
@@ -6181,7 +6318,7 @@ var WavyLinearTrack = React62__namespace.memo(function WavyLinearTrack2({
6181
6318
  currentAmp
6182
6319
  );
6183
6320
  } else if (fraction === 0) {
6184
- activePathD = `M ${capWidth} 0 L ${capWidth + 0.01} 0`;
6321
+ activePathD = "";
6185
6322
  }
6186
6323
  const trackStart = adjHead + totalGap;
6187
6324
  if (trackStart < width - capWidth) {
@@ -6213,20 +6350,20 @@ var WavyLinearTrack = React62__namespace.memo(function WavyLinearTrack2({
6213
6350
  activeLines.push({ tail: l1T, head: l1H });
6214
6351
  activeLines.push({ tail: l2T, head: l2H });
6215
6352
  }
6216
- const segments = activeLines.map((line) => {
6217
- const barTail = line.tail * width;
6218
- const barHead = line.head * width;
6353
+ const activeSegments = activeLines.map((line) => {
6354
+ const rawTail = line.tail * width;
6355
+ const rawHead = line.head * width;
6219
6356
  const adjTail = Math.max(
6220
6357
  capWidth,
6221
- Math.min(width - capWidth, barTail)
6358
+ Math.min(width - capWidth, rawTail)
6222
6359
  );
6223
6360
  const adjHead = Math.max(
6224
6361
  capWidth,
6225
- Math.min(width - capWidth, barHead)
6362
+ Math.min(width - capWidth, rawHead)
6226
6363
  );
6227
6364
  return { adjTail, adjHead };
6228
6365
  }).filter((seg) => seg.adjHead - seg.adjTail > 0.1);
6229
- activePathD = segments.map(
6366
+ activePathD = activeSegments.map(
6230
6367
  (seg) => getSinePath(
6231
6368
  seg.adjTail,
6232
6369
  seg.adjHead,
@@ -6235,13 +6372,24 @@ var WavyLinearTrack = React62__namespace.memo(function WavyLinearTrack2({
6235
6372
  currentAmp
6236
6373
  )
6237
6374
  ).join(" ");
6375
+ const validActiveLines = activeLines.filter(
6376
+ (line) => line.head > line.tail && line.head * width > 0 && line.tail * width < width
6377
+ ).sort((a, b) => a.tail - b.tail);
6238
6378
  let currentTrackX = capWidth;
6239
- for (const seg of segments) {
6240
- const trackEnd = seg.adjTail - totalGap;
6379
+ for (const line of validActiveLines) {
6380
+ const blockStart = line.tail * width - totalGap;
6381
+ const blockEnd = line.head * width + totalGap;
6382
+ const trackEnd = Math.min(width - capWidth, blockStart);
6241
6383
  if (trackEnd > currentTrackX) {
6242
- trackD += `${getSinePath(currentTrackX, trackEnd, phase, activeWavelength, trackAmp)} `;
6384
+ trackD += `${getSinePath(
6385
+ currentTrackX,
6386
+ trackEnd,
6387
+ phase,
6388
+ activeWavelength,
6389
+ trackAmp
6390
+ )} `;
6243
6391
  }
6244
- currentTrackX = Math.max(currentTrackX, seg.adjHead + totalGap);
6392
+ currentTrackX = Math.max(currentTrackX, blockEnd);
6245
6393
  }
6246
6394
  if (currentTrackX < width - capWidth) {
6247
6395
  trackD += getSinePath(
@@ -6254,9 +6402,9 @@ var WavyLinearTrack = React62__namespace.memo(function WavyLinearTrack2({
6254
6402
  }
6255
6403
  }
6256
6404
  if (activePathRef.current)
6257
- activePathRef.current.setAttribute("d", activePathD);
6405
+ activePathRef.current.setAttribute("d", activePathD || "");
6258
6406
  if (trackPathRef.current)
6259
- trackPathRef.current.setAttribute("d", trackD.trim());
6407
+ trackPathRef.current.setAttribute("d", trackD.trim() || "");
6260
6408
  });
6261
6409
  return /* @__PURE__ */ jsxRuntime.jsx(
6262
6410
  "div",