@@ -34,29 +34,54 @@ const GRANULARITY_OPTIONS: { label: string; value: StreamAnimationGranularity }[
3434 { label : 'Word' , value : 'word' } ,
3535] ;
3636
37+ const TPS_MODE_OPTIONS = [
38+ { label : 'Fixed' , value : 'fixed' } ,
39+ { label : 'Range' , value : 'range' } ,
40+ ] as const ;
41+
42+ type TpsMode = ( typeof TPS_MODE_OPTIONS ) [ number ] [ 'value' ] ;
43+
3744export const Playground = ( ) => {
3845 const [ sampleKey , setSampleKey ] = useState < SampleKey > ( 'markdown' ) ;
3946 const [ chunkSize , setChunkSize ] = useState ( 6 ) ;
40- const [ delayMs , setDelayMs ] = useState ( 24 ) ;
47+ const [ tpsMode , setTpsMode ] = useState < TpsMode > ( 'fixed' ) ;
48+ const [ tps , setTps ] = useState ( 250 ) ;
49+ const [ tpsMin , setTpsMin ] = useState ( 80 ) ;
50+ const [ tpsMax , setTpsMax ] = useState ( 400 ) ;
4151 const [ jitter , setJitter ] = useState ( 50 ) ;
4252 const [ smoothing , setSmoothing ] = useState < StreamSmoothingPreset > ( 'balanced' ) ;
4353 const [ granularity , setGranularity ] = useState < StreamAnimationGranularity > ( 'char' ) ;
4454 const [ latexGuard , setLatexGuard ] = useState ( true ) ;
4555 const [ preprocess , setPreprocess ] = useState ( true ) ;
4656
57+ const rateMin = tpsMode === 'range' ? Math . min ( tpsMin , tpsMax ) : tps ;
58+ const rateMax = tpsMode === 'range' ? Math . max ( tpsMin , tpsMax ) : tps ;
59+ const batchDelayMs = Math . max ( 1 , Math . round ( ( chunkSize / Math . max ( rateMin , 0.001 ) ) * 1000 ) ) ;
60+
4761 const { onScroll : onOutputScroll , ref : outputRef } = useStickToBottom ( ) ;
4862 const profiler = useMemo ( ( ) => createStreamdownProfiler ( { label : 'playground' } ) , [ ] ) ;
4963 const { restart, text } = useLocalStream ( samples [ sampleKey ] . content , {
5064 chunkSize,
51- delayMs,
5265 jitter : jitter / 100 ,
66+ tps : rateMin ,
67+ tpsMax : rateMax ,
5368 } ) ;
5469 const remarkPlugins = useMemo ( ( ) => [ remarkGfm , remarkMath ] , [ ] ) ;
5570 const rehypePlugins = useMemo ( ( ) => [ rehypeKatex ] , [ ] ) ;
5671
5772 useEffect ( ( ) => {
5873 profiler . reset ( 'playground' ) ;
59- } , [ profiler , sampleKey , chunkSize , delayMs , jitter , smoothing , granularity , preprocess ] ) ;
74+ } , [
75+ profiler ,
76+ sampleKey ,
77+ chunkSize ,
78+ rateMin ,
79+ rateMax ,
80+ jitter ,
81+ smoothing ,
82+ granularity ,
83+ preprocess ,
84+ ] ) ;
6085
6186 return (
6287 < section className = "playground" id = "playground" >
@@ -83,12 +108,53 @@ export const Playground = () => {
83108 if ( key in paragraphBatchCases ) {
84109 const preset = paragraphBatchCases [ key as keyof typeof paragraphBatchCases ] ;
85110 setChunkSize ( preset . chunkSize ) ;
86- setDelayMs ( preset . delayMs ) ;
111+ setTps ( Math . round ( ( preset . chunkSize / preset . delayMs ) * 1000 ) ) ;
112+ setTpsMode ( 'fixed' ) ;
87113 setJitter ( 0 ) ;
88114 }
89115 restart ( ) ;
90116 } }
91117 />
118+ < Segmented
119+ label = "TPS"
120+ options = { TPS_MODE_OPTIONS }
121+ value = { tpsMode }
122+ onChange = { setTpsMode }
123+ />
124+ { tpsMode === 'fixed' ? (
125+ < Range
126+ hint = { `${ batchDelayMs } ms / batch at ${ chunkSize } ch` }
127+ label = "Rate"
128+ max = { 5000 }
129+ min = { 10 }
130+ step = { 10 }
131+ unit = "chars/s"
132+ value = { tps }
133+ onChange = { setTps }
134+ />
135+ ) : (
136+ < >
137+ < Range
138+ label = "TPS min"
139+ max = { 5000 }
140+ min = { 10 }
141+ step = { 10 }
142+ unit = "chars/s"
143+ value = { tpsMin }
144+ onChange = { setTpsMin }
145+ />
146+ < Range
147+ hint = { `${ Math . max ( 1 , Math . round ( ( chunkSize / Math . max ( rateMax , 0.001 ) ) * 1000 ) ) } –${ batchDelayMs } ms / batch` }
148+ label = "TPS max"
149+ max = { 5000 }
150+ min = { 10 }
151+ step = { 10 }
152+ unit = "chars/s"
153+ value = { tpsMax }
154+ onChange = { setTpsMax }
155+ />
156+ </ >
157+ ) }
92158 < Range
93159 label = "Chunk size"
94160 max = { 100 }
@@ -97,14 +163,6 @@ export const Playground = () => {
97163 value = { chunkSize }
98164 onChange = { setChunkSize }
99165 />
100- < Range
101- label = "Chunk delay"
102- max = { 500 }
103- min = { 4 }
104- unit = "ms"
105- value = { delayMs }
106- onChange = { setDelayMs }
107- />
108166 < Range
109167 label = "Jitter"
110168 max = { 100 }
0 commit comments