Skip to content

Commit 5e589a3

Browse files
committed
change max pips from 1000 -> 500
- there's a significant perf overhead with too many pips I've been back and forth on this for a while, and while running tests and using wild values for pips... the perf issues caught up and I can't see any real scenario where it would be useful to display more than 500 pips (honestly, 200+ is still more than is visually useful) ... so I've reduced the max that will render to 501.
1 parent 5f0509c commit 5e589a3

File tree

12 files changed

+454
-361
lines changed

12 files changed

+454
-361
lines changed

dist/range-slider-pips.js

Lines changed: 177 additions & 154 deletions
Large diffs are not rendered by default.

dist/range-slider-pips.mjs

Lines changed: 177 additions & 154 deletions
Large diffs are not rendered by default.

dist/svelte/components/RangePips.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let clientStart = null;
3434
$: stepMax = vertical ? 50 : 100;
3535
$: tooManySteps = (max - min) / step >= stepMax;
3636
let pipCount = 0;
37-
const limitPipCount = 1e3;
37+
const limitPipCount = 500;
3838
let finalPipStep = 1;
3939
$: {
4040
finalPipStep = pipstep ?? (tooManySteps ? (max - min) / (stepMax / 5) : 1);

dist/svelte/components/RangeSlider.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export let darkmode = false;
5454
export let springValues = { stiffness: 0.15, damping: 0.4 };
5555
export let spring = true;
5656
const dispatch = createEventDispatcher();
57+
let isMounted = false;
5758
let valueLength = 0;
5859
let focus = false;
5960
let handleActivated = false;
@@ -200,10 +201,14 @@ onMount(() => {
200201
rafId = updateSliderSize(entries[0].target);
201202
});
202203
resizeObserver.observe(slider);
204+
setTimeout(() => {
205+
isMounted = true;
206+
}, 16);
203207
}
204208
return () => {
205209
if (rafId) cancelAnimationFrame(rafId);
206210
resizeObserver?.disconnect?.();
211+
isMounted = false;
207212
};
208213
});
209214
function targetIsHandle(el) {
@@ -538,8 +543,8 @@ function ariaLabelFormatter(value2, index) {
538543
on:blur={sliderBlurHandle}
539544
on:focus={sliderFocusHandle}
540545
on:keydown={sliderKeydown}
541-
style:z-index={zindex}
542546
style:--handle-pos={$springPositions[index]}
547+
style="z-index: {zindex}; {isMounted ? '' : 'opacity: 0;'}"
543548
aria-label={ariaLabels[index]}
544549
aria-valuemin={range === true && index === 1 ? values[0] : min}
545550
aria-valuemax={range === true && index === 0 ? values[1] : max}
@@ -575,6 +580,7 @@ function ariaLabelFormatter(value2, index) {
575580
style:--range-start={rangeStartPercent($springPositions)}
576581
style:--range-end={rangeEndPercent($springPositions)}
577582
style:--range-size={rangeEndPercent($springPositions) - rangeStartPercent($springPositions)}
583+
style={isMounted ? '' : 'opacity: 0;'}
578584
>
579585
{#if rangeFloat}
580586
<span class="rangeFloat">
@@ -1008,4 +1014,9 @@ function ariaLabelFormatter(value2, index) {
10081014
:global(.rangeSlider.rsDisabled .rangeNub) {
10091015
background-color: var(--handle-inactive);
10101016
}
1017+
1018+
:global(.rangeSlider .rangeBar),
1019+
:global(.rangeSlider .rangeHandle) {
1020+
transition: opacity 0.2s ease;
1021+
}
10111022
</style>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-range-slider-pips",
3-
"version": "4.0.0-beta.4",
3+
"version": "4.0.0-beta.5",
44
"description": "Multi-Thumb, Accessible, Beautiful Range Slider with Pips",
55
"repository": {
66
"type": "git",

src/lib/components/RangePips.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
5353
// track the number of pips we're actually going to render
5454
let pipCount = 0;
55-
const limitPipCount = 1000;
55+
const limitPipCount = 500;
5656
// track the final pipstep we're going to use
5757
let finalPipStep = 1;
5858

src/lib/components/RangeSlider.svelte

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
// prepare dispatched events
7373
const dispatch = createEventDispatcher();
7474
75+
// loading
76+
let isMounted = false;
77+
7578
// state management
7679
let valueLength = 0;
7780
let focus = false;
@@ -282,10 +285,14 @@
282285
rafId = updateSliderSize(entries[0].target as HTMLDivElement);
283286
}) as ResizeObserver;
284287
resizeObserver.observe(slider);
288+
setTimeout(() => {
289+
isMounted = true;
290+
}, 16);
285291
}
286292
return () => {
287293
if (rafId) cancelAnimationFrame(rafId);
288294
resizeObserver?.disconnect?.();
295+
isMounted = false;
289296
};
290297
});
291298
@@ -794,8 +801,8 @@
794801
on:blur={sliderBlurHandle}
795802
on:focus={sliderFocusHandle}
796803
on:keydown={sliderKeydown}
797-
style:z-index={zindex}
798804
style:--handle-pos={$springPositions[index]}
805+
style="z-index: {zindex}; {isMounted ? '' : 'opacity: 0;'}"
799806
aria-label={ariaLabels[index]}
800807
aria-valuemin={range === true && index === 1 ? values[0] : min}
801808
aria-valuemax={range === true && index === 0 ? values[1] : max}
@@ -831,6 +838,7 @@
831838
style:--range-start={rangeStartPercent($springPositions)}
832839
style:--range-end={rangeEndPercent($springPositions)}
833840
style:--range-size={rangeEndPercent($springPositions) - rangeStartPercent($springPositions)}
841+
style={isMounted ? '' : 'opacity: 0;'}
834842
>
835843
{#if rangeFloat}
836844
<span class="rangeFloat">
@@ -1264,4 +1272,9 @@
12641272
:global(.rangeSlider.rsDisabled .rangeNub) {
12651273
background-color: var(--handle-inactive);
12661274
}
1275+
1276+
:global(.rangeSlider .rangeBar),
1277+
:global(.rangeSlider .rangeHandle) {
1278+
transition: opacity 0.2s ease;
1279+
}
12671280
</style>

src/routes/test/nav/test-nav.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"name": "pipsteps",
8080
"path": "/test/range-slider/pips/pipsteps"
8181
},
82+
{
83+
"name": "pipsteps-large",
84+
"path": "/test/range-slider/pips/pipsteps-large"
85+
},
8286
{
8387
"name": "steps",
8488
"path": "/test/range-slider/pips/steps"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import RangeSlider from '$lib/components/RangeSlider.svelte';
3+
4+
let hasPipstep = false;
5+
let hasAlternatePipstep = false;
6+
7+
function togglePipstep() {
8+
hasPipstep = !hasPipstep;
9+
}
10+
11+
function toggleAlternatePipstep() {
12+
hasAlternatePipstep = !hasAlternatePipstep;
13+
}
14+
</script>
15+
16+
<div class="slider-list">
17+
<h5>Very large number of pips, explicitly set</h5>
18+
<RangeSlider id="very-large-pips" pips first="label" last="label" max={10000} pipstep={1} />
19+
</div>

0 commit comments

Comments
 (0)