@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/composites/range-inputs/HueSlider/HueSlider.d.ts.map +1 -1
- package/dist/composites/range-inputs/Slider/Slider.d.ts.map +1 -1
- package/dist/fonts/measureFont.d.ts +2 -1
- package/dist/fonts/measureFont.d.ts.map +1 -1
- package/dist/index.cjs +26 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.tsx +5 -5
- package/src/composites/range-inputs/HueSlider/HueSlider.tsx +5 -2
- package/src/composites/range-inputs/Slider/Slider.tsx +5 -2
- package/src/fonts/measureFont.ts +15 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HueSlider.d.ts","sourceRoot":"","sources":["../../../../src/composites/range-inputs/HueSlider/HueSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAQxD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,aAAa,EACb,GAAO,EACP,GAAS,EACT,KAAK,EACL,SAAiB,EACjB,aAAqB,EACrB,QAAgB,EAChB,KAAK,GACN,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"HueSlider.d.ts","sourceRoot":"","sources":["../../../../src/composites/range-inputs/HueSlider/HueSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAQxD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,aAAa,EACb,GAAO,EACP,GAAS,EACT,KAAK,EACL,SAAiB,EACjB,aAAqB,EACrB,QAAgB,EAChB,KAAK,GACN,EAAE,cAAc,qBAkHhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../../src/composites/range-inputs/Slider/Slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,aAAa,EACb,GAAO,EACP,GAAS,EACT,IAAQ,EACR,KAAK,EACL,SAAiB,EACjB,aAAqB,EACrB,QAAgB,EAChB,KAAK,GACN,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../../src/composites/range-inputs/Slider/Slider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,wBAAgB,MAAM,CAAC,EACrB,KAAK,EACL,aAAa,EACb,GAAO,EACP,GAAS,EACT,IAAQ,EACR,KAAK,EACL,SAAiB,EACjB,aAAqB,EACrB,QAAgB,EAChB,KAAK,GACN,EAAE,WAAW,qBA2Gb"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Measure the average character width ratio for a font using the Canvas API.
|
|
3
3
|
*
|
|
4
|
-
* Waits for the font to load via `document.fonts.load()` before measuring
|
|
4
|
+
* Waits for the font to load via `document.fonts.load()` before measuring,
|
|
5
|
+
* with a 3-second timeout to prevent hangs when fonts fail to load silently.
|
|
5
6
|
* Falls back to 0.55 if the browser context is unavailable, the font fails
|
|
6
7
|
* to load, or canvas is not supported.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measureFont.d.ts","sourceRoot":"","sources":["../../src/fonts/measureFont.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"measureFont.d.ts","sourceRoot":"","sources":["../../src/fonts/measureFont.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAAK,GACZ,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
|
package/dist/index.cjs
CHANGED
|
@@ -840,10 +840,20 @@ function Icon({
|
|
|
840
840
|
|
|
841
841
|
// src/fonts/measureFont.ts
|
|
842
842
|
var REF_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
|
|
843
|
+
function withTimeout(promise, ms, fallback) {
|
|
844
|
+
return Promise.race([
|
|
845
|
+
promise,
|
|
846
|
+
new Promise((resolve) => setTimeout(() => resolve(fallback), ms))
|
|
847
|
+
]);
|
|
848
|
+
}
|
|
843
849
|
async function measureAvgCharWidth(fontFamily, fontWeight, fallback, fontSize = 16) {
|
|
844
850
|
if (typeof document === "undefined") return 0.55;
|
|
845
851
|
try {
|
|
846
|
-
await
|
|
852
|
+
await withTimeout(
|
|
853
|
+
document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`),
|
|
854
|
+
3e3,
|
|
855
|
+
[]
|
|
856
|
+
);
|
|
847
857
|
const canvas = document.createElement("canvas");
|
|
848
858
|
const ctx = canvas.getContext("2d");
|
|
849
859
|
if (!ctx) return 0.55;
|
|
@@ -2488,6 +2498,7 @@ function Slider({
|
|
|
2488
2498
|
const trackRef = React14__default.default.useRef(null);
|
|
2489
2499
|
const trackWidth = React14__default.default.useRef(0);
|
|
2490
2500
|
const trackPageX = React14__default.default.useRef(0);
|
|
2501
|
+
const [layoutWidth, setLayoutWidth] = React14__default.default.useState(0);
|
|
2491
2502
|
const onValueChangeRef = React14__default.default.useRef(onValueChange);
|
|
2492
2503
|
const minRef = React14__default.default.useRef(min);
|
|
2493
2504
|
const maxRef = React14__default.default.useRef(max);
|
|
@@ -2528,7 +2539,7 @@ function Slider({
|
|
|
2528
2539
|
})
|
|
2529
2540
|
).current;
|
|
2530
2541
|
const ratio = max > min ? (value - min) / (max - min) : 0;
|
|
2531
|
-
const usableWidth = Math.max(0,
|
|
2542
|
+
const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE2);
|
|
2532
2543
|
const thumbLeft = ratio * usableWidth;
|
|
2533
2544
|
const fillWidth = thumbLeft + THUMB_SIZE2 / 2;
|
|
2534
2545
|
const handleValueTextSubmit = React14__default.default.useCallback(
|
|
@@ -2563,7 +2574,9 @@ function Slider({
|
|
|
2563
2574
|
ref: trackRef,
|
|
2564
2575
|
style: styles.trackContainer,
|
|
2565
2576
|
onLayout: (e) => {
|
|
2566
|
-
|
|
2577
|
+
const w = e.nativeEvent.layout.width;
|
|
2578
|
+
trackWidth.current = w;
|
|
2579
|
+
setLayoutWidth(w);
|
|
2567
2580
|
trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
|
|
2568
2581
|
if (pageX != null) trackPageX.current = pageX;
|
|
2569
2582
|
});
|
|
@@ -2706,6 +2719,7 @@ function HueSlider({
|
|
|
2706
2719
|
const trackRef = React14__default.default.useRef(null);
|
|
2707
2720
|
const trackWidth = React14__default.default.useRef(0);
|
|
2708
2721
|
const trackPageX = React14__default.default.useRef(0);
|
|
2722
|
+
const [layoutWidth, setLayoutWidth] = React14__default.default.useState(0);
|
|
2709
2723
|
const onValueChangeRef = React14__default.default.useRef(onValueChange);
|
|
2710
2724
|
const minRef = React14__default.default.useRef(min);
|
|
2711
2725
|
const maxRef = React14__default.default.useRef(max);
|
|
@@ -2743,7 +2757,7 @@ function HueSlider({
|
|
|
2743
2757
|
).current;
|
|
2744
2758
|
const sliderValue = max > 359 && value < min ? value + 360 : value;
|
|
2745
2759
|
const ratio = max > min ? (sliderValue - min) / (max - min) : 0;
|
|
2746
|
-
const usableWidth = Math.max(0,
|
|
2760
|
+
const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE3);
|
|
2747
2761
|
const thumbLeft = ratio * usableWidth;
|
|
2748
2762
|
const handleValueTextSubmit = React14__default.default.useCallback(
|
|
2749
2763
|
(text) => {
|
|
@@ -2777,7 +2791,9 @@ function HueSlider({
|
|
|
2777
2791
|
ref: trackRef,
|
|
2778
2792
|
style: styles.trackContainer,
|
|
2779
2793
|
onLayout: (e) => {
|
|
2780
|
-
|
|
2794
|
+
const w = e.nativeEvent.layout.width;
|
|
2795
|
+
trackWidth.current = w;
|
|
2796
|
+
setLayoutWidth(w);
|
|
2781
2797
|
trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
|
|
2782
2798
|
if (pageX != null) trackPageX.current = pageX;
|
|
2783
2799
|
});
|
|
@@ -2865,6 +2881,7 @@ function ColorScaleSlider({
|
|
|
2865
2881
|
const trackPageX = React14__default.default.useRef(0);
|
|
2866
2882
|
const isDragging = React14__default.default.useRef(false);
|
|
2867
2883
|
const thumbAnim = React14__default.default.useRef(new reactNative.Animated.Value(0)).current;
|
|
2884
|
+
const [layoutWidth, setLayoutWidth] = React14__default.default.useState(0);
|
|
2868
2885
|
const onValueChangeRef = React14__default.default.useRef(onValueChange);
|
|
2869
2886
|
const disabledRef = React14__default.default.useRef(disabled);
|
|
2870
2887
|
const colorsLengthRef = React14__default.default.useRef(colors.length);
|
|
@@ -2926,7 +2943,7 @@ function ColorScaleSlider({
|
|
|
2926
2943
|
const range = maxNV - minNV;
|
|
2927
2944
|
const clampedValue = value !== void 0 ? Math.min(maxNV, Math.max(minNV, value)) : (maxNV + minNV) / 2;
|
|
2928
2945
|
const ratio = range > 0 ? (maxNV - clampedValue) / range : 0.5;
|
|
2929
|
-
const usableWidth = Math.max(0,
|
|
2946
|
+
const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE4);
|
|
2930
2947
|
const thumbLeft = ratio * usableWidth;
|
|
2931
2948
|
React14__default.default.useEffect(() => {
|
|
2932
2949
|
if (isDragging.current || !animateValue) {
|
|
@@ -2945,9 +2962,9 @@ function ColorScaleSlider({
|
|
|
2945
2962
|
ref: trackRef,
|
|
2946
2963
|
style: styles.trackContainer,
|
|
2947
2964
|
onLayout: (e) => {
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2965
|
+
const w = e.nativeEvent.layout.width;
|
|
2966
|
+
trackWidth.current = w;
|
|
2967
|
+
setLayoutWidth(w);
|
|
2951
2968
|
trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
|
|
2952
2969
|
if (pageX != null) trackPageX.current = pageX;
|
|
2953
2970
|
});
|