@tableslayer/ui 0.1.25 → 0.2.0
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.
|
@@ -4,67 +4,14 @@
|
|
|
4
4
|
onBrushSizeChange: (value: number) => void;
|
|
5
5
|
min?: number;
|
|
6
6
|
max?: number;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
step?: number;
|
|
8
|
+
displayUnit?: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
let {
|
|
12
|
-
brushSize,
|
|
13
|
-
onBrushSizeChange,
|
|
14
|
-
min = 1,
|
|
15
|
-
max = 200,
|
|
16
|
-
curve = 'quadratic',
|
|
17
|
-
displayAsPercentage = false
|
|
18
|
-
}: Props = $props();
|
|
19
|
-
|
|
20
|
-
// For quadratic curve: size = coefficient * slider^2
|
|
21
|
-
// We want: at slider=50%, size should be at the midpoint between min and max
|
|
22
|
-
// midpoint = (min + max) / 2
|
|
23
|
-
// So: midpoint = coefficient * 50^2
|
|
24
|
-
// coefficient = midpoint / 2500
|
|
25
|
-
const midpoint = $derived((min + max) / 2);
|
|
26
|
-
const coefficient = $derived(midpoint / 2500);
|
|
27
|
-
|
|
28
|
-
const brushSizeToSlider = (size: number): number => {
|
|
29
|
-
const clampedSize = Math.max(min, Math.min(max, size));
|
|
30
|
-
|
|
31
|
-
if (curve === 'linear') {
|
|
32
|
-
// Linear: map size range to 0-100 slider range
|
|
33
|
-
return ((clampedSize - min) / (max - min)) * 100;
|
|
34
|
-
} else {
|
|
35
|
-
// Quadratic: inverse of size = coefficient * slider^2
|
|
36
|
-
return Math.sqrt(clampedSize / coefficient);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const sliderToBrushSize = (slider: number): number => {
|
|
41
|
-
if (curve === 'linear') {
|
|
42
|
-
// Linear mapping from slider (0-100) to size range (min-max)
|
|
43
|
-
const size = min + (slider / 100) * (max - min);
|
|
44
|
-
// For linear curve (used by fog), keep decimal precision
|
|
45
|
-
// Round to 1 decimal place
|
|
46
|
-
return Math.max(min, Math.min(max, Math.round(size * 10) / 10));
|
|
47
|
-
} else {
|
|
48
|
-
// Quadratic curve (used by annotations)
|
|
49
|
-
const size = coefficient * slider * slider;
|
|
50
|
-
// For quadratic, we can round to integers as the range is small decimals (0.01-5.0)
|
|
51
|
-
// but we need to preserve decimal precision, so round to 2 decimal places
|
|
52
|
-
return Math.max(min, Math.min(max, Math.round(size * 100) / 100));
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
let brushSliderValue = $derived(brushSizeToSlider(brushSize));
|
|
11
|
+
let { brushSize, onBrushSizeChange, min = 1, max = 5, step = 1, displayUnit }: Props = $props();
|
|
57
12
|
|
|
58
13
|
const handleBrushSliderChange = (value: number) => {
|
|
59
|
-
|
|
60
|
-
console.log('[BrushSizeSlider] Slider change:', {
|
|
61
|
-
sliderValue: value,
|
|
62
|
-
actualSize,
|
|
63
|
-
min,
|
|
64
|
-
max,
|
|
65
|
-
curve
|
|
66
|
-
});
|
|
67
|
-
onBrushSizeChange(actualSize);
|
|
14
|
+
onBrushSizeChange(Math.max(min, Math.min(max, value)));
|
|
68
15
|
};
|
|
69
16
|
|
|
70
17
|
// Touch event handlers for better mobile support
|
|
@@ -85,15 +32,17 @@
|
|
|
85
32
|
id="brush-size-slider"
|
|
86
33
|
type="range"
|
|
87
34
|
class="brushSizeSlider__input"
|
|
88
|
-
min
|
|
89
|
-
max
|
|
90
|
-
step
|
|
91
|
-
value={
|
|
35
|
+
{min}
|
|
36
|
+
{max}
|
|
37
|
+
{step}
|
|
38
|
+
value={brushSize}
|
|
92
39
|
oninput={(e) => handleBrushSliderChange(Number(e.currentTarget.value))}
|
|
93
40
|
ontouchstart={handleTouchStart}
|
|
94
41
|
ontouchmove={handleTouchMove}
|
|
95
42
|
/>
|
|
96
|
-
<div class="brushSizeSlider__value">
|
|
43
|
+
<div class="brushSizeSlider__value">
|
|
44
|
+
{Number(brushSize.toFixed(2))}{displayUnit ? ` ${displayUnit}` : ''}
|
|
45
|
+
</div>
|
|
97
46
|
</div>
|
|
98
47
|
|
|
99
48
|
<style>
|
|
@@ -3,8 +3,8 @@ interface Props {
|
|
|
3
3
|
onBrushSizeChange: (value: number) => void;
|
|
4
4
|
min?: number;
|
|
5
5
|
max?: number;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
step?: number;
|
|
7
|
+
displayUnit?: string;
|
|
8
8
|
}
|
|
9
9
|
declare const BrushSizeSlider: import("svelte").Component<Props, {}, "">;
|
|
10
10
|
type BrushSizeSlider = ReturnType<typeof BrushSizeSlider>;
|
|
@@ -4,29 +4,13 @@
|
|
|
4
4
|
interface Props {
|
|
5
5
|
brushSize: number;
|
|
6
6
|
onBrushSizeChange: (value: number) => void;
|
|
7
|
-
gridSpacing?: number;
|
|
8
|
-
displayWidth?: number;
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
let { brushSize, onBrushSizeChange
|
|
12
|
-
|
|
13
|
-
const minBrushSize = $derived.by(() => {
|
|
14
|
-
if (gridSpacing && displayWidth && displayWidth > 0) {
|
|
15
|
-
return Math.max(0.5, (gridSpacing / displayWidth) * 100);
|
|
16
|
-
}
|
|
17
|
-
return 2;
|
|
18
|
-
});
|
|
9
|
+
let { brushSize, onBrushSizeChange }: Props = $props();
|
|
19
10
|
</script>
|
|
20
11
|
|
|
21
12
|
<div class="fogSliders">
|
|
22
|
-
<BrushSizeSlider
|
|
23
|
-
{brushSize}
|
|
24
|
-
{onBrushSizeChange}
|
|
25
|
-
min={minBrushSize}
|
|
26
|
-
max={20}
|
|
27
|
-
curve="linear"
|
|
28
|
-
displayAsPercentage={true}
|
|
29
|
-
/>
|
|
13
|
+
<BrushSizeSlider {brushSize} {onBrushSizeChange} min={1} max={5} step={1} displayUnit="sq" />
|
|
30
14
|
</div>
|
|
31
15
|
|
|
32
16
|
<style>
|