@waveform-playlist/ui-components 15.0.0-next.13 → 15.0.0-next.15

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.
package/dist/index.mjs CHANGED
@@ -2113,49 +2113,84 @@ import { useId as useId3 } from "react";
2113
2113
  import { useState as useState3 } from "react";
2114
2114
 
2115
2115
  // src/utils/timeFormat.ts
2116
+ function printable(seconds) {
2117
+ return Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
2118
+ }
2119
+ function digits(whole) {
2120
+ return whole < 1e21 ? String(whole) : whole.toLocaleString("en-US", { useGrouping: false });
2121
+ }
2122
+ function fixed(n, decimals) {
2123
+ return n < 1e21 ? n.toFixed(decimals) : n.toLocaleString("en-US", {
2124
+ useGrouping: false,
2125
+ minimumFractionDigits: decimals,
2126
+ maximumFractionDigits: decimals
2127
+ });
2128
+ }
2116
2129
  function clockFormat(seconds, decimals) {
2117
- const hours = Math.floor(seconds / 3600) % 24;
2118
- const minutes = Math.floor(seconds / 60) % 60;
2119
- const secs = (seconds % 60).toFixed(decimals);
2120
- return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs.padStart(decimals > 0 ? decimals + 3 : 2, "0");
2130
+ const remainder = seconds % 60;
2131
+ const rounded = remainder.toFixed(decimals);
2132
+ const carry = Number(rounded) >= 60;
2133
+ const totalMinutes = Math.round((seconds - remainder) / 60) + (carry ? 1 : 0);
2134
+ const secs = (carry ? 0 .toFixed(decimals) : rounded).padStart(
2135
+ decimals > 0 ? decimals + 3 : 2,
2136
+ "0"
2137
+ );
2138
+ return digits(Math.floor(totalMinutes / 60)).padStart(2, "0") + ":" + String(totalMinutes % 60).padStart(2, "0") + ":" + secs;
2121
2139
  }
2122
2140
  function formatTime(seconds, format) {
2141
+ const safe = printable(seconds);
2123
2142
  switch (format) {
2124
2143
  case "seconds":
2125
- return seconds.toFixed(0);
2144
+ return fixed(safe, 0);
2126
2145
  case "thousandths":
2127
- return seconds.toFixed(3);
2146
+ return fixed(safe, 3);
2128
2147
  case "hh:mm:ss":
2129
- return clockFormat(seconds, 0);
2148
+ return clockFormat(safe, 0);
2130
2149
  case "hh:mm:ss.u":
2131
- return clockFormat(seconds, 1);
2150
+ return clockFormat(safe, 1);
2132
2151
  case "hh:mm:ss.uu":
2133
- return clockFormat(seconds, 2);
2152
+ return clockFormat(safe, 2);
2134
2153
  case "hh:mm:ss.uuu":
2135
- return clockFormat(seconds, 3);
2154
+ return clockFormat(safe, 3);
2136
2155
  default:
2137
- return clockFormat(seconds, 3);
2156
+ return clockFormat(safe, 3);
2138
2157
  }
2139
2158
  }
2159
+ var DECIMAL = /^(\d+(\.\d*)?|\.\d+)$/;
2160
+ var WHOLE = /^\d+$/;
2161
+ var SECONDS_PER_UNIT = [3600, 60, 1];
2162
+ function parseNumber(text) {
2163
+ if (!DECIMAL.test(text)) return null;
2164
+ const value = Number(text);
2165
+ return Number.isFinite(value) ? value : null;
2166
+ }
2167
+ function parseClock(text) {
2168
+ const parts = text.split(":");
2169
+ if (parts.length > 3) return null;
2170
+ const units = SECONDS_PER_UNIT.slice(3 - parts.length);
2171
+ let total = 0;
2172
+ for (let i = 0; i < parts.length; i++) {
2173
+ const isLast = i === parts.length - 1;
2174
+ if (!(isLast ? DECIMAL : WHOLE).test(parts[i])) return null;
2175
+ const value = Number(parts[i]);
2176
+ if (i > 0 && value >= 60) return null;
2177
+ total += value * units[i];
2178
+ }
2179
+ return Number.isFinite(total) ? total : null;
2180
+ }
2140
2181
  function parseTime(timeStr, format) {
2141
- if (!timeStr) return 0;
2182
+ if (typeof timeStr !== "string") return null;
2183
+ const text = timeStr.trim();
2142
2184
  switch (format) {
2143
2185
  case "seconds":
2144
2186
  case "thousandths":
2145
- return parseFloat(timeStr) || 0;
2187
+ return parseNumber(text);
2146
2188
  case "hh:mm:ss":
2147
2189
  case "hh:mm:ss.u":
2148
2190
  case "hh:mm:ss.uu":
2149
- case "hh:mm:ss.uuu": {
2150
- const parts = timeStr.split(":");
2151
- if (parts.length !== 3) return 0;
2152
- const hours = parseInt(parts[0], 10) || 0;
2153
- const minutes = parseInt(parts[1], 10) || 0;
2154
- const seconds = parseFloat(parts[2]) || 0;
2155
- return hours * 3600 + minutes * 60 + seconds;
2156
- }
2191
+ case "hh:mm:ss.uuu":
2157
2192
  default:
2158
- return 0;
2193
+ return parseClock(text);
2159
2194
  }
2160
2195
  }
2161
2196
 
@@ -2180,7 +2215,9 @@ var TimeInput = ({
2180
2215
  if (draft === null) return;
2181
2216
  setDraft(null);
2182
2217
  if (activeDraft === null) return;
2183
- onChange?.(parseTime(activeDraft.text, format));
2218
+ const parsed = parseTime(activeDraft.text, format);
2219
+ if (parsed === null) return;
2220
+ onChange?.(parsed);
2184
2221
  };
2185
2222
  const handleKeyDown = (e) => {
2186
2223
  if (e.key === "Enter") {