@charcuterie/ui 4.3.0 → 4.5.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.
@@ -90,8 +90,17 @@ export type FormatTimecodeOptions = {
90
90
  * unchanged because the largest field present is unbounded.
91
91
  */
92
92
  isHoursShown?: boolean
93
- /** `0` through `3`. `0` drops the fraction and its separator. */
94
- millisecondDigits?: number
93
+ /**
94
+ * `0` through `3`. `0` drops the fraction and its separator.
95
+ *
96
+ * `"auto"` prints the fraction only when there is one to print: a
97
+ * whole number of seconds comes back as `01:01:00`, and half a
98
+ * second more comes back as `01:01:00.500`. It is how a decimal
99
+ * number is written everywhere else — you write `3`, not `3.000` —
100
+ * and the grammar reads both spellings back to the number that
101
+ * produced them, because its fraction is optional.
102
+ */
103
+ millisecondDigits?: "auto" | number
95
104
  }
96
105
 
97
106
  const padTwo = (value: number) =>
@@ -105,12 +114,16 @@ const padTwo = (value: number) =>
105
114
  * because it has not reached second 2 yet. Rounding would print a
106
115
  * seek point the media has not played.
107
116
  *
108
- * The default is the canonical `hh:mm:ss.mmm`, and that is what the
109
- * field writes back on commit. One spelling means a re-read of the
110
- * field parses to the number that produced it, and a screenshot of
111
- * the same value is the same picture — neither of which is true of
112
- * the fleet's five printers, three of which hide the hour and two of
113
- * which do not pad the minute.
117
+ * The default is the canonical `hh:mm:ss.mmm`. `TimecodeInput` asks
118
+ * for `millisecondDigits: "auto"` instead, so a whole second is
119
+ * written back as `01:01:00` rather than as `01:01:00.000` — a
120
+ * person who typed no fraction did not ask for one, and both
121
+ * spellings re-read to the number that produced them.
122
+ *
123
+ * Either way it is ONE spelling per value, which is what the fleet's
124
+ * five printers never were: three of them hide the hour and two do
125
+ * not pad the minute, so the same position is a different picture in
126
+ * each app.
114
127
  */
115
128
  export const formatTimecode = (
116
129
  milliseconds: number,
@@ -123,10 +136,15 @@ export const formatTimecode = (
123
136
  ? Math.max(0, Math.floor(milliseconds))
124
137
  : 0
125
138
 
126
- const digits = Math.min(
127
- 3,
128
- Math.max(0, Math.floor(millisecondDigits)),
129
- )
139
+ const digits =
140
+ millisecondDigits === "auto"
141
+ ? total % MILLISECONDS_PER_SECOND === 0
142
+ ? 0
143
+ : 3
144
+ : Math.min(
145
+ 3,
146
+ Math.max(0, Math.floor(millisecondDigits)),
147
+ )
130
148
 
131
149
  const hours = isHoursShown
132
150
  ? Math.floor(total / MILLISECONDS_PER_HOUR)
@@ -251,6 +251,13 @@ test("a container-query component is never storied in a shrink-to-fit cell", ()
251
251
  // measured in Docket, before any of the steps contained
252
252
  // anything.
253
253
  "Stepper",
254
+ // `TimecodeInput` queries its own box to decide whether a section
255
+ // is `[start] to [end]` in a row or two captioned fields stacked.
256
+ // The width that decides it is a modal's, not a window's: the
257
+ // report came from a 390px dialog, and the same dialog on a
258
+ // 2560px monitor is the Wide View by every media query and the
259
+ // Narrow View by the only measurement that matters.
260
+ "TimecodeInput",
254
261
  ])
255
262
 
256
263
  // `StoryCell`s are never nested, so the lazy match really does