@newtonedev/components 0.1.9 → 0.1.11

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
@@ -835,10 +835,20 @@ function Icon({
835
835
 
836
836
  // src/fonts/measureFont.ts
837
837
  var REF_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
838
+ function withTimeout(promise, ms, fallback) {
839
+ return Promise.race([
840
+ promise,
841
+ new Promise((resolve) => setTimeout(() => resolve(fallback), ms))
842
+ ]);
843
+ }
838
844
  async function measureAvgCharWidth(fontFamily, fontWeight, fallback, fontSize = 16) {
839
845
  if (typeof document === "undefined") return 0.55;
840
846
  try {
841
- await document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`);
847
+ await withTimeout(
848
+ document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`),
849
+ 3e3,
850
+ []
851
+ );
842
852
  const canvas = document.createElement("canvas");
843
853
  const ctx = canvas.getContext("2d");
844
854
  if (!ctx) return 0.55;
@@ -2483,6 +2493,7 @@ function Slider({
2483
2493
  const trackRef = React14.useRef(null);
2484
2494
  const trackWidth = React14.useRef(0);
2485
2495
  const trackPageX = React14.useRef(0);
2496
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2486
2497
  const onValueChangeRef = React14.useRef(onValueChange);
2487
2498
  const minRef = React14.useRef(min);
2488
2499
  const maxRef = React14.useRef(max);
@@ -2523,7 +2534,7 @@ function Slider({
2523
2534
  })
2524
2535
  ).current;
2525
2536
  const ratio = max > min ? (value - min) / (max - min) : 0;
2526
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE2);
2537
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE2);
2527
2538
  const thumbLeft = ratio * usableWidth;
2528
2539
  const fillWidth = thumbLeft + THUMB_SIZE2 / 2;
2529
2540
  const handleValueTextSubmit = React14.useCallback(
@@ -2558,7 +2569,9 @@ function Slider({
2558
2569
  ref: trackRef,
2559
2570
  style: styles.trackContainer,
2560
2571
  onLayout: (e) => {
2561
- trackWidth.current = e.nativeEvent.layout.width;
2572
+ const w = e.nativeEvent.layout.width;
2573
+ trackWidth.current = w;
2574
+ setLayoutWidth(w);
2562
2575
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2563
2576
  if (pageX != null) trackPageX.current = pageX;
2564
2577
  });
@@ -2701,6 +2714,7 @@ function HueSlider({
2701
2714
  const trackRef = React14.useRef(null);
2702
2715
  const trackWidth = React14.useRef(0);
2703
2716
  const trackPageX = React14.useRef(0);
2717
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2704
2718
  const onValueChangeRef = React14.useRef(onValueChange);
2705
2719
  const minRef = React14.useRef(min);
2706
2720
  const maxRef = React14.useRef(max);
@@ -2738,7 +2752,7 @@ function HueSlider({
2738
2752
  ).current;
2739
2753
  const sliderValue = max > 359 && value < min ? value + 360 : value;
2740
2754
  const ratio = max > min ? (sliderValue - min) / (max - min) : 0;
2741
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE3);
2755
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE3);
2742
2756
  const thumbLeft = ratio * usableWidth;
2743
2757
  const handleValueTextSubmit = React14.useCallback(
2744
2758
  (text) => {
@@ -2772,7 +2786,9 @@ function HueSlider({
2772
2786
  ref: trackRef,
2773
2787
  style: styles.trackContainer,
2774
2788
  onLayout: (e) => {
2775
- trackWidth.current = e.nativeEvent.layout.width;
2789
+ const w = e.nativeEvent.layout.width;
2790
+ trackWidth.current = w;
2791
+ setLayoutWidth(w);
2776
2792
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2777
2793
  if (pageX != null) trackPageX.current = pageX;
2778
2794
  });
@@ -2860,6 +2876,7 @@ function ColorScaleSlider({
2860
2876
  const trackPageX = React14.useRef(0);
2861
2877
  const isDragging = React14.useRef(false);
2862
2878
  const thumbAnim = React14.useRef(new Animated.Value(0)).current;
2879
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2863
2880
  const onValueChangeRef = React14.useRef(onValueChange);
2864
2881
  const disabledRef = React14.useRef(disabled);
2865
2882
  const colorsLengthRef = React14.useRef(colors.length);
@@ -2921,7 +2938,7 @@ function ColorScaleSlider({
2921
2938
  const range = maxNV - minNV;
2922
2939
  const clampedValue = value !== void 0 ? Math.min(maxNV, Math.max(minNV, value)) : (maxNV + minNV) / 2;
2923
2940
  const ratio = range > 0 ? (maxNV - clampedValue) / range : 0.5;
2924
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE4);
2941
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE4);
2925
2942
  const thumbLeft = ratio * usableWidth;
2926
2943
  React14.useEffect(() => {
2927
2944
  if (isDragging.current || !animateValue) {
@@ -2940,9 +2957,9 @@ function ColorScaleSlider({
2940
2957
  ref: trackRef,
2941
2958
  style: styles.trackContainer,
2942
2959
  onLayout: (e) => {
2943
- trackWidth.current = e.nativeEvent.layout.width;
2944
- const newUsableWidth = Math.max(0, e.nativeEvent.layout.width - THUMB_SIZE4);
2945
- thumbAnim.setValue(ratio * newUsableWidth);
2960
+ const w = e.nativeEvent.layout.width;
2961
+ trackWidth.current = w;
2962
+ setLayoutWidth(w);
2946
2963
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2947
2964
  if (pageX != null) trackPageX.current = pageX;
2948
2965
  });