<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: XingYu Chen</title>
    <description>The latest articles on DEV Community by XingYu Chen (@makeshort).</description>
    <link>https://dev.to/makeshort</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4195665%2F4c3797bc-8476-416d-ba03-4c5b90d313ea.jpg</url>
      <title>DEV Community: XingYu Chen</title>
      <link>https://dev.to/makeshort</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/makeshort"/>
    <language>en</language>
    <item>
      <title>Caption Timing in JavaScript: Interval Boundaries, Progress, and NaN</title>
      <dc:creator>XingYu Chen</dc:creator>
      <pubDate>Wed, 11 Nov 2026 07:42:54 +0000</pubDate>
      <link>https://dev.to/makeshort/caption-timing-in-javascript-interval-boundaries-progress-and-nan-3j5d</link>
      <guid>https://dev.to/makeshort/caption-timing-in-javascript-interval-boundaries-progress-and-nan-3j5d</guid>
      <description>&lt;p&gt;The code behind this article comes from &lt;a href="https://www.makeshort.ai/" rel="noopener noreferrer"&gt;MakeShort&lt;/a&gt;, an online short-video tool I develop. While reviewing its caption renderer, I revisited interval boundaries and animation progress. This article explains those details with a standalone example.&lt;/p&gt;

&lt;p&gt;Two small functions underpin several caption effects: deciding whether a caption is active, and calculating its animation progress. Word highlighting, caption transitions, and fades depend on these decisions.&lt;/p&gt;

&lt;p&gt;The discussion starts with the current implementation. The defensive handling below is a proposed improvement, not a claim that it has shipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Who owns the boundary between adjacent captions?
&lt;/h2&gt;

&lt;p&gt;Consider two captions, with all times in milliseconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Caption A: 1000 → 2000
Caption B: 2000 → 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An inclusive test at both ends makes both captions active at exactly 2000 ms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For word highlighting, this can select two words at the boundary. Whether they visibly overlap depends on the rendering logic, but the timing rule itself is ambiguous.&lt;/p&gt;

&lt;p&gt;The interval helper in the existing code uses a half-open interval:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Written as &lt;code&gt;[start, end)&lt;/code&gt;, it includes the start and excludes the end:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Current time&lt;/th&gt;
&lt;th&gt;Caption A&lt;/th&gt;
&lt;th&gt;Caption B&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1999 ms&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;td&gt;Inactive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2000 ms&lt;/td&gt;
&lt;td&gt;Inactive&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2001 ms&lt;/td&gt;
&lt;td&gt;Inactive&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When intervals meet exactly, the boundary belongs only to the next caption.&lt;/p&gt;

&lt;p&gt;This convention does not repair overlapping input. If A ends at 2100 ms and B starts at 2000 ms, both are still active during the overlap. Endpoint ownership and data validation are separate concerns.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Activity and animation progress answer different questions
&lt;/h2&gt;

&lt;p&gt;Animation progress is commonly calculated as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;progress = (current - start) / (end - start)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then it is clamped to the range &lt;code&gt;[0, 1]&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a caption running from 1000 to 2000 ms, progress is zero before the start, 0.5 at the midpoint, and one at and after the end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress reaching one does not mean the caption is still active.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At 2000 ms, caption A can have progress equal to one while already being outside its active interval. Rendering should handle these decisions separately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drawCaption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Testing whether clamped progress is between zero and one cannot determine visibility: every valid clamped result meets that condition.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Clamping does not remove NaN
&lt;/h2&gt;

&lt;p&gt;The existing progress helper divides the elapsed time by the duration and clamps the result. Considered on its own, it does not guard against zero-duration intervals.&lt;/p&gt;

&lt;p&gt;When the current time, start, and end are equal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;progress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// NaN&lt;/span&gt;

&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clamping is not a substitute for validating the input.&lt;/p&gt;

&lt;p&gt;This does not establish that a production failure has occurred. Upstream validation might exclude these inputs, or actual data might never trigger the case. But a reusable helper should state what happens when the input is invalid.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. A standalone implementation with an explicit failure policy
&lt;/h2&gt;

&lt;p&gt;This example adopts four rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All times use milliseconds.&lt;/li&gt;
&lt;li&gt;The end must be later than the start.&lt;/li&gt;
&lt;li&gt;Non-finite values, zero-duration intervals, and reversed intervals are invalid.&lt;/li&gt;
&lt;li&gt;Invalid input returns an inactive state with progress zero.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sampleCue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;endMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;valid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;timeMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;endMs&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isFinite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="n"&gt;endMs&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;timeMs&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;timeMs&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeMs&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endMs&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;startMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skipping invalid intervals is a policy choice. An editor could flag the offending caption for correction. An import pipeline could reject the record and explain why.&lt;/p&gt;

&lt;p&gt;The important part is to choose a behavior before invalid values reach drawing code.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Test the boundaries, not just the midpoint
&lt;/h2&gt;

&lt;p&gt;Checking that 1500 ms produces progress 0.5 will not catch most boundary errors. A useful test matrix also includes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;Expected result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Before the start&lt;/td&gt;
&lt;td&gt;Inactive, progress 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exactly at the start&lt;/td&gt;
&lt;td&gt;Active, progress 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;At the midpoint&lt;/td&gt;
&lt;td&gt;Active, progress 0.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exactly at the end&lt;/td&gt;
&lt;td&gt;Inactive, progress 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After the end&lt;/td&gt;
&lt;td&gt;Inactive, progress 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Equal start and end&lt;/td&gt;
&lt;td&gt;Inactive, progress 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;End before start&lt;/td&gt;
&lt;td&gt;Inactive, progress 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NaN or Infinity in the inputs&lt;/td&gt;
&lt;td&gt;Inactive, progress 0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Test adjacent intervals explicitly as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;sampleCue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;sampleCue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The standalone example passed 11 assertions covering these cases. Those assertions check the timing contract, not the entire video renderer. Preview testing still needs to account for frame sampling, media time units, and overlapping caption data.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Put the time unit in the interface
&lt;/h2&gt;

&lt;p&gt;A correct formula can still produce incorrect timing if seconds and milliseconds are mixed.&lt;/p&gt;

&lt;p&gt;The names &lt;code&gt;timeMs&lt;/code&gt;, &lt;code&gt;startMs&lt;/code&gt;, and &lt;code&gt;endMs&lt;/code&gt; make the unit visible to callers. If a media interface supplies seconds, convert at the boundary into a millisecond-based caption timeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;timeMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentTime&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This assumes the caption data actually uses milliseconds. Centralizing that conversion helps prevent one call path from converting twice while another forgets to convert at all.&lt;/p&gt;

&lt;p&gt;Defining endpoint ownership, invalid-input behavior, and time units gives caption rendering a small, testable contract. That makes animation problems easier to investigate without guessing which part of the timeline a value belongs to.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;AI disclosure:&lt;/strong&gt; The prose and standalone example in this article were generated by an AI agent. The author reviewed the Chinese draft before requesting this English version. The agent checked the discussion against the existing code and ran 11 boundary assertions on the standalone example. This is not a claim of production validation or a shipped change.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Designing digital Tesla wraps in a browser: gallery, editing, and 3D preview</title>
      <dc:creator>XingYu Chen</dc:creator>
      <pubDate>Tue, 20 Oct 2026 09:34:58 +0000</pubDate>
      <link>https://dev.to/makeshort/designing-digital-tesla-wraps-in-a-browser-gallery-editing-and-3d-preview-535e</link>
      <guid>https://dev.to/makeshort/designing-digital-tesla-wraps-in-a-browser-gallery-editing-and-3d-preview-535e</guid>
      <description>&lt;p&gt;I built &lt;a href="https://tesla-wrap.pro/" rel="noopener noreferrer"&gt;Tesla Wrap Pro&lt;/a&gt; for Tesla owners who want to customize the digital vehicle appearance shown on their car screen. This walkthrough explains the workflow and the distinction between a digital wrap file and physical vinyl wrapping.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start with a gallery design
&lt;/h2&gt;

&lt;p&gt;Open the &lt;a href="https://tesla-wrap.pro/gallery" rel="noopener noreferrer"&gt;gallery&lt;/a&gt;, choose a vehicle model, and compare colors and patterns. Open a design to review its details. A downloadable design provides a starting point when you want to use an existing look; editable designs can also help you start a variation without beginning from a blank canvas.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Check the layout in the editor
&lt;/h2&gt;

&lt;p&gt;The browser editor supports images, text, and vehicle panel colors, with a live 3D vehicle preview. Use the preview to check how a design sits across the vehicle surfaces while making adjustments. Pay attention to the model-specific layout rather than assuming one flat image will fit every vehicle.&lt;/p&gt;

&lt;p&gt;Try changing a single element at a time: first the base colors, then the image placement, then text. This makes it easier to spot which change affected the result. Inspect the preview before exporting.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Export and verify compatibility
&lt;/h2&gt;

&lt;p&gt;Export the finished design as a PNG. These digital assets are intended for vehicle visualization in Tesla Paint Shop, where supported. Before importing, check the requirements for your particular vehicle and software version. A successful browser export does not establish compatibility with every Tesla model or software release.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free editing and optional AI
&lt;/h2&gt;

&lt;p&gt;Manual editing, 3D preview, and PNG downloads are free. Optional AI workflows let you generate designs from text or use a reference image; they require an account and prepaid credits. You can use the manual workflow without buying AI credits. Current credit packs are listed on the &lt;a href="https://tesla-wrap.pro/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The project uses Next.js, React, and TypeScript. It is an independent third-party product and is not affiliated with Tesla, Inc. It provides digital design files, not physical wrapping or installation services.&lt;/p&gt;

&lt;p&gt;If you try it, feedback about a specific vehicle layout, preview issue, or export step is especially useful. You can explore the &lt;a href="https://tesla-wrap.pro/" rel="noopener noreferrer"&gt;website&lt;/a&gt; and contact me through the site.&lt;/p&gt;

</description>
      <category>showdev</category>
    </item>
  </channel>
</rss>
