strata-react 1.0.33 → 1.0.35
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/README.md +12 -2
- package/UPGRADING.md +1 -0
- package/dist/components/conversation.d.ts +67 -0
- package/dist/components/dialog.d.ts +1 -1
- package/dist/components/folder-picker.d.ts +42 -0
- package/dist/components/lightbox.d.ts +34 -0
- package/dist/components/markable-text.d.ts +56 -0
- package/dist/components/media-group.d.ts +25 -0
- package/dist/components/media-player.d.ts +80 -2
- package/dist/components/region-editor.d.ts +55 -0
- package/dist/components/sequence-timeline.d.ts +50 -0
- package/dist/components/transcript-view.d.ts +36 -0
- package/dist/components/tree.d.ts +41 -0
- package/dist/components/waveform.d.ts +66 -0
- package/dist/{cursor-DplHNzj3.js → cursor-DDGBPiTJ.js} +2 -200
- package/dist/cursor-DDGBPiTJ.js.map +1 -0
- package/dist/field-7Z4N5r5g.js +178 -0
- package/dist/field-7Z4N5r5g.js.map +1 -0
- package/dist/format-B32-PVi2.js +201 -0
- package/dist/format-B32-PVi2.js.map +1 -0
- package/dist/hls/index.d.ts +19 -0
- package/dist/hls.js +84 -0
- package/dist/hls.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +3454 -568
- package/dist/index.js.map +1 -1
- package/dist/lib/marks.d.ts +6 -0
- package/dist/lib/region.d.ts +46 -0
- package/dist/lib/rich-text.d.ts +44 -0
- package/dist/lib/sequence.d.ts +34 -0
- package/dist/lib/transcript.d.ts +28 -0
- package/dist/lib/waveform.d.ts +36 -0
- package/dist/map.js +4 -2
- package/dist/map.js.map +1 -1
- package/dist/panorama/gl.d.ts +16 -0
- package/dist/panorama/index.d.ts +2 -0
- package/dist/panorama/panorama-viewer.d.ts +56 -0
- package/dist/panorama/projection.d.ts +45 -0
- package/dist/panorama.js +657 -0
- package/dist/panorama.js.map +1 -0
- package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
- package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
- package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
- package/dist/run-DzyLrZlA.js.map +1 -0
- package/dist/testing.js +2 -2
- package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
- package/dist/theme-CFNi6WUO.js.map +1 -0
- package/dist/value-controls-D6O9TsM6.js +356 -0
- package/dist/value-controls-D6O9TsM6.js.map +1 -0
- package/dist/visual-cli.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +19 -4
- package/dist/cursor-DplHNzj3.js.map +0 -1
- package/dist/run-BqZGKhW9.js.map +0 -1
- package/dist/theme-BgTOESmN.js.map +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/lib/format.ts
|
|
2
|
+
var NBSP = "\xA0";
|
|
3
|
+
/** The placeholder printed for a value that is not known: an en dash. */
|
|
4
|
+
var MISSING = "–";
|
|
5
|
+
var BYTE_UNITS = [
|
|
6
|
+
"B",
|
|
7
|
+
"kB",
|
|
8
|
+
"MB",
|
|
9
|
+
"GB",
|
|
10
|
+
"TB",
|
|
11
|
+
"PB"
|
|
12
|
+
];
|
|
13
|
+
var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
|
|
14
|
+
/** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
|
|
15
|
+
function toDate(value) {
|
|
16
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
17
|
+
if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
|
|
18
|
+
return date;
|
|
19
|
+
}
|
|
20
|
+
function callableDate(df, missing) {
|
|
21
|
+
const format = (value) => value == null ? missing : df.format(toDate(value));
|
|
22
|
+
return Object.assign(format, {
|
|
23
|
+
format,
|
|
24
|
+
formatToParts: (value) => df.formatToParts(toDate(value)),
|
|
25
|
+
formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
|
|
26
|
+
resolvedOptions: () => df.resolvedOptions()
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function callable(nf, missing) {
|
|
30
|
+
const format = (value) => value == null ? missing : nf.format(value);
|
|
31
|
+
return Object.assign(format, {
|
|
32
|
+
format,
|
|
33
|
+
formatToParts: (value) => nf.formatToParts(value),
|
|
34
|
+
resolvedOptions: () => nf.resolvedOptions()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var DAY = 864e5;
|
|
38
|
+
var AGO_STEPS = [
|
|
39
|
+
["year", 365 * DAY],
|
|
40
|
+
["month", 30 * DAY],
|
|
41
|
+
["week", 7 * DAY],
|
|
42
|
+
["day", DAY],
|
|
43
|
+
["hour", 36e5],
|
|
44
|
+
["minute", 6e4]
|
|
45
|
+
];
|
|
46
|
+
/** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */
|
|
47
|
+
function createFormat(locale, options = {}) {
|
|
48
|
+
const { timeZone, missing = "–" } = options;
|
|
49
|
+
const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
|
|
50
|
+
...opts,
|
|
51
|
+
timeZone
|
|
52
|
+
}), missing);
|
|
53
|
+
const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);
|
|
54
|
+
const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);
|
|
55
|
+
const percent = callable(new Intl.NumberFormat(locale, {
|
|
56
|
+
style: "percent",
|
|
57
|
+
maximumFractionDigits: 0
|
|
58
|
+
}), missing);
|
|
59
|
+
const compact = callable(new Intl.NumberFormat(locale, {
|
|
60
|
+
notation: "compact",
|
|
61
|
+
maximumFractionDigits: 1
|
|
62
|
+
}), missing);
|
|
63
|
+
const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
64
|
+
const plurals = new Intl.PluralRules(locale);
|
|
65
|
+
const clock = dates({
|
|
66
|
+
hour: "2-digit",
|
|
67
|
+
minute: "2-digit"
|
|
68
|
+
});
|
|
69
|
+
const day = dates({
|
|
70
|
+
weekday: "long",
|
|
71
|
+
day: "numeric",
|
|
72
|
+
month: "long"
|
|
73
|
+
});
|
|
74
|
+
const shortDay = dates({
|
|
75
|
+
weekday: "short",
|
|
76
|
+
hour: "2-digit",
|
|
77
|
+
minute: "2-digit"
|
|
78
|
+
});
|
|
79
|
+
const date = dates({ dateStyle: "medium" });
|
|
80
|
+
const dateTime = dates({
|
|
81
|
+
dateStyle: "medium",
|
|
82
|
+
timeStyle: "short"
|
|
83
|
+
});
|
|
84
|
+
const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
|
|
85
|
+
return {
|
|
86
|
+
locale,
|
|
87
|
+
/** The zone times are shown in, or `undefined` for the viewer's own. */
|
|
88
|
+
timeZone,
|
|
89
|
+
/** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
|
|
90
|
+
integer,
|
|
91
|
+
/** One decimal place at most: `format.decimal(3.14)` is "3.1". */
|
|
92
|
+
decimal,
|
|
93
|
+
/** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
|
|
94
|
+
percent,
|
|
95
|
+
/**
|
|
96
|
+
* A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that
|
|
97
|
+
* rounds to 0 is "<1%", and one short of the whole that rounds to 100 is ">99%".
|
|
98
|
+
* `format.share(2.4 / 512)` is "<1%".
|
|
99
|
+
*/
|
|
100
|
+
share: (value) => {
|
|
101
|
+
if (value == null || Number.isNaN(value)) return missing;
|
|
102
|
+
if (value > 0 && value < .005) return `<${percent.format(.01)}`;
|
|
103
|
+
if (value >= .995 && value < 1) return `>${percent.format(.99)}`;
|
|
104
|
+
return percent.format(value);
|
|
105
|
+
},
|
|
106
|
+
/** A figure in short form for counts that run to thousands: `format.compact(1234)` is "1.2k" in en-GB, "1.2K" in en-US. */
|
|
107
|
+
compact,
|
|
108
|
+
/**
|
|
109
|
+
* How long ago (or how far ahead) a time is, in the largest unit it reaches:
|
|
110
|
+
* "3 weeks ago", "yesterday", "in 2 hours", "now" under a minute. Pass `now` in tests.
|
|
111
|
+
*/
|
|
112
|
+
ago: (value, now = /* @__PURE__ */ new Date()) => {
|
|
113
|
+
if (value == null) return missing;
|
|
114
|
+
const diff = toDate(value).getTime() - toDate(now).getTime();
|
|
115
|
+
const span = Math.abs(diff);
|
|
116
|
+
for (const [unit, size] of AGO_STEPS) if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);
|
|
117
|
+
return relative.format(0, "second");
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* A media running time from seconds, as a player shows it: "4:05", "1:02:09". Unknown
|
|
121
|
+
* (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
|
|
122
|
+
*/
|
|
123
|
+
runningTime: (seconds) => {
|
|
124
|
+
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
|
|
125
|
+
const s = Math.floor(seconds);
|
|
126
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
127
|
+
const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
|
|
128
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* A position in media as an editor shows it, to a chosen precision: "4:05" (seconds), "4:05.250"
|
|
132
|
+
* (`"ms"`), or "0:04:05:07" (`"frames"` at `fps`, the last part the frame). Hours appear only
|
|
133
|
+
* from one hour, except in frames. Frames are always four parts, hours included, as SMPTE
|
|
134
|
+
* timecode is (non-drop frame, with colons): a three-part "1:05:00" reads as one hour five, so
|
|
135
|
+
* a frame count must never be three. Editors write the same four parts (strata-react issue
|
|
136
|
+
* #122). Floors, never rounds up, so a time never reads ahead of the picture. Unknown (null,
|
|
137
|
+
* negative, not finite) prints the placeholder. Set it in `tabular-nums`.
|
|
138
|
+
*/
|
|
139
|
+
timecode: (seconds, { precision = "seconds", fps = 30 } = {}) => {
|
|
140
|
+
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
|
|
141
|
+
const whole = Math.floor(seconds);
|
|
142
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
143
|
+
const [h, m] = [Math.floor(whole / 3600), Math.floor(whole % 3600 / 60)];
|
|
144
|
+
const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;
|
|
145
|
+
if (precision === "ms") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1e3 + 1e-6), 999)).padStart(3, "0")}`;
|
|
146
|
+
if (precision === "frames") return `${h}:${two(m)}:${two(whole % 60)}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;
|
|
147
|
+
return base;
|
|
148
|
+
},
|
|
149
|
+
/** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
|
|
150
|
+
missing,
|
|
151
|
+
/** A time of day: `format.clock(at)` is "06:05". */
|
|
152
|
+
clock,
|
|
153
|
+
/** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
|
|
154
|
+
day,
|
|
155
|
+
/** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
|
|
156
|
+
shortDay,
|
|
157
|
+
/** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
|
|
158
|
+
date,
|
|
159
|
+
/** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
|
|
160
|
+
dateTime,
|
|
161
|
+
/** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
|
|
162
|
+
withUnit,
|
|
163
|
+
/** A temperature in °C, joined by a non-breaking space. */
|
|
164
|
+
celsius: (value) => withUnit(value, "°C"),
|
|
165
|
+
/**
|
|
166
|
+
* A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
|
|
167
|
+
* networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
|
|
168
|
+
* to fix the unit, so figures compared side by side ("431 of 466 GB") share one.
|
|
169
|
+
*/
|
|
170
|
+
bytes: (value, unit) => {
|
|
171
|
+
const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B";
|
|
172
|
+
const scaled = value / BYTE_SIZE[chosen];
|
|
173
|
+
return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* A distance in metres as a person says it: metres under a kilometre ("850 m"), then
|
|
177
|
+
* kilometres, one decimal below 100 ("12.4 km"), whole above; `"imperial"` is feet under a
|
|
178
|
+
* tenth of a mile ("320 ft"), then miles ("7.7 mi").
|
|
179
|
+
*/
|
|
180
|
+
distance: (metres, system = "metric") => {
|
|
181
|
+
if (system === "imperial") {
|
|
182
|
+
const miles = metres / 1609.344;
|
|
183
|
+
return miles < .1 ? withUnit(metres * 3.28084, "ft") : withUnit(miles, "mi", miles < 100 ? decimal : integer);
|
|
184
|
+
}
|
|
185
|
+
return Math.abs(metres) < 1e3 ? withUnit(metres, "m") : withUnit(metres / 1e3, "km", Math.abs(metres) < 1e5 ? decimal : integer);
|
|
186
|
+
},
|
|
187
|
+
/** The unit `bytes` would choose for a value, to share it across a set of figures. */
|
|
188
|
+
byteUnit: (value) => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B",
|
|
189
|
+
/**
|
|
190
|
+
* "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
|
|
191
|
+
* joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
|
|
192
|
+
* call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
|
|
193
|
+
*/
|
|
194
|
+
count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)} ${plurals.select(value) === "one" ? one : many}`
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** The en-GB formatters. */
|
|
198
|
+
var format = createFormat("en-GB");
|
|
199
|
+
export { toDate as a, format as i, NBSP as n, createFormat as r, MISSING as t };
|
|
200
|
+
|
|
201
|
+
//# sourceMappingURL=format-B32-PVi2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-B32-PVi2.js","names":[],"sources":["../src/lib/format.ts"],"sourcesContent":["// Every number and date on screen goes through Intl, once, here. Units are joined with a\n// non-breaking space so \"212 °C\" never wraps between figure and unit. A product that is not\n// en-GB calls createFormat with its locale once and exports the result from its own lib.\n//\n// The number formatters are callable (`format.integer(n)`) because that is the form people reach\n// for (strata-react issue #12), and they keep Intl's methods (`format.integer.format(n)`,\n// `formatToParts`, `resolvedOptions`) so existing calls and Intl knowledge still work.\n//\n// Dates follow the same shape. Every date formatter is callable with a Date, an ISO string or\n// epoch milliseconds (`format.dateTime(row.at)`), because rows arrive from an API as ISO strings\n// and an app that has to wrap each one in `new Date(...)` soon builds its own Intl.DateTimeFormat\n// beside it instead (strata-react issue #31, from the Bright Horizons History screen). An invalid\n// date throws a RangeError naming the input rather than printing \"Invalid Date\" into a row.\n// `date` and `dateTime` use Intl's medium/short styles, so the locale decides the order\n// (\"8 Nov 2026, 06:05\" in en-GB, \"Nov 8, 2026, 6:05 AM\" in en-US) and nobody hand-writes a\n// pattern. `timeZone` is optional: left out, times are the viewer's; a product that shows a place's\n// times (a kiln in one room, a shop's opening hours) passes that place's zone once.\n//\n// Tests: the non-breaking space is a real character in the DOM. Testing Library's text matchers\n// (`getByText`, `toHaveTextContent`) collapse whitespace and match \"6 pieces\", but accessible-name\n// matching (`getByRole(\"heading\", { name: \"6 pieces\" })`) compares the name exactly and does not.\n// Build the expected string with the same formatter (`{ name: format.count(6, \"piece\") }`), or\n// use a regex with `\\s` (`/6\\spieces/`), which matches U+00A0.\n//\n// A value that is not known (`null` or `undefined`: a count the source does not give, a date for\n// something never synced) prints as the placeholder, an en dash unless `createFormat`'s `missing`\n// says otherwise, from every number and date formatter (strata-react issue #47). Each screen used\n// to pick its own (\"–\", \"Never\", blank), so tables and cards disagreed. An invalid date still\n// throws: that is a bug, not a missing value.\n//\n// Three formatters came from the Tubes viewer, which wrote its own (strata-react issue #52): `ago`\n// (\"3 weeks ago\", from Intl.RelativeTimeFormat, with `now` passed in by tests), `compact` (\"1.2k\"\n// in en-GB, and `count`'s `{ compact: true }` for \"1.2k views\") and `runningTime` (\"4:05\", \"1:02:09\"), the\n// m:ss of a media player, which Intl.DurationFormat's long form is not. `share` is `percent` for a\n// part of a whole (strata-react issue #43): a part that is there never prints as \"0%\", nor a part\n// short of the whole as \"100%\".\n\nexport const NBSP = \" \";\n\n/** The placeholder printed for a value that is not known: an en dash. */\nexport const MISSING = \"–\";\n\n/** The decimal byte units `format.bytes` writes. */\nexport type ByteUnit = \"B\" | \"kB\" | \"MB\" | \"GB\" | \"TB\" | \"PB\";\nconst BYTE_UNITS: readonly ByteUnit[] = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\"];\nconst BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1000 ** i])) as Record<ByteUnit, number>;\n\n/** An `Intl.NumberFormat` that can also be called directly: `f(n)` is `f.format(n)`. `null` or `undefined` prints the placeholder. */\nexport type NumberFormatter = ((value: number | bigint | Intl.StringNumericLiteral | null | undefined) => string) & {\n format: (value: number | bigint | Intl.StringNumericLiteral | null | undefined) => string;\n} & Pick<Intl.NumberFormat, \"formatToParts\" | \"resolvedOptions\">;\n\n/** What a date formatter accepts: a Date, an ISO 8601 string, or epoch milliseconds. */\nexport type DateInput = Date | string | number;\n\n/** An `Intl.DateTimeFormat` that can also be called directly, with a Date, an ISO string or epoch milliseconds. */\nexport type DateFormatter = ((value: DateInput | null | undefined) => string) & {\n format: (value: DateInput | null | undefined) => string;\n formatToParts: (value: DateInput) => Intl.DateTimeFormatPart[];\n formatRange: (start: DateInput, end: DateInput) => string;\n} & Pick<Intl.DateTimeFormat, \"resolvedOptions\">;\n\n/** Options shared by every date formatter one `createFormat` call makes. */\nexport interface FormatOptions {\n /** An IANA zone (\"Europe/London\", \"UTC\") to show times in. Left out, times are the viewer's own. */\n timeZone?: string;\n /** What a missing value (`null`, `undefined`) prints as. Default an en dash (`MISSING`). */\n missing?: string;\n}\n\n/** Options for `format.count`. */\nexport interface CountOptions {\n /** Write the figure compactly: \"1.2k views\". The noun still agrees with the exact count. */\n compact?: boolean;\n}\n\n/** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */\nexport function toDate(value: DateInput): Date {\n const date = value instanceof Date ? value : new Date(value);\n if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);\n return date;\n}\n\nfunction callableDate(df: Intl.DateTimeFormat, missing: string): DateFormatter {\n const format = (value: DateInput | null | undefined) => (value == null ? missing : df.format(toDate(value)));\n return Object.assign(format, {\n format,\n formatToParts: (value: DateInput) => df.formatToParts(toDate(value)),\n formatRange: (start: DateInput, end: DateInput) => df.formatRange(toDate(start), toDate(end)),\n resolvedOptions: () => df.resolvedOptions(),\n });\n}\n\nfunction callable(nf: Intl.NumberFormat, missing: string): NumberFormatter {\n const format = (value: number | bigint | Intl.StringNumericLiteral | null | undefined) => (value == null ? missing : nf.format(value));\n return Object.assign(format, {\n format,\n formatToParts: (value: number | bigint) => nf.formatToParts(value),\n resolvedOptions: () => nf.resolvedOptions(),\n });\n}\n\n// Largest first: `ago` says a span in the largest unit it fills at least once, rounded down, so\n// 13 days is \"last week\" and 20 days \"2 weeks ago\", never \"3 weeks\" too early.\nconst DAY = 86_400_000;\nconst AGO_STEPS: readonly [Intl.RelativeTimeFormatUnit, number][] = [\n [\"year\", 365 * DAY],\n [\"month\", 30 * DAY],\n [\"week\", 7 * DAY],\n [\"day\", DAY],\n [\"hour\", 3_600_000],\n [\"minute\", 60_000],\n];\n\n/** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */\nexport function createFormat(locale: string, options: FormatOptions = {}) {\n const { timeZone, missing = MISSING } = options;\n const dates = (opts: Intl.DateTimeFormatOptions) => callableDate(new Intl.DateTimeFormat(locale, { ...opts, timeZone }), missing);\n const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);\n const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);\n const percent = callable(new Intl.NumberFormat(locale, { style: \"percent\", maximumFractionDigits: 0 }), missing);\n const compact = callable(new Intl.NumberFormat(locale, { notation: \"compact\", maximumFractionDigits: 1 }), missing);\n const relative = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\" });\n const plurals = new Intl.PluralRules(locale);\n const clock = dates({ hour: \"2-digit\", minute: \"2-digit\" });\n const day = dates({ weekday: \"long\", day: \"numeric\", month: \"long\" });\n const shortDay = dates({ weekday: \"short\", hour: \"2-digit\", minute: \"2-digit\" });\n const date = dates({ dateStyle: \"medium\" });\n const dateTime = dates({ dateStyle: \"medium\", timeStyle: \"short\" });\n const withUnit = (value: number, unit: string, fmt: Pick<Intl.NumberFormat, \"format\"> = integer) =>\n `${fmt.format(value)}${NBSP}${unit}`;\n return {\n locale,\n /** The zone times are shown in, or `undefined` for the viewer's own. */\n timeZone,\n /** Whole numbers with grouping: `format.integer(1222)` is \"1,222\". */\n integer,\n /** One decimal place at most: `format.decimal(3.14)` is \"3.1\". */\n decimal,\n /** A ratio as a whole percent: `format.percent(0.42)` is \"42%\". */\n percent,\n /**\n * A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that\n * rounds to 0 is \"<1%\", and one short of the whole that rounds to 100 is \">99%\".\n * `format.share(2.4 / 512)` is \"<1%\".\n */\n share: (value: number | null | undefined) => {\n if (value == null || Number.isNaN(value)) return missing;\n if (value > 0 && value < 0.005) return `<${percent.format(0.01)}`;\n if (value >= 0.995 && value < 1) return `>${percent.format(0.99)}`;\n return percent.format(value);\n },\n /** A figure in short form for counts that run to thousands: `format.compact(1234)` is \"1.2k\" in en-GB, \"1.2K\" in en-US. */\n compact,\n /**\n * How long ago (or how far ahead) a time is, in the largest unit it reaches:\n * \"3 weeks ago\", \"yesterday\", \"in 2 hours\", \"now\" under a minute. Pass `now` in tests.\n */\n ago: (value: DateInput | null | undefined, now: DateInput = new Date()) => {\n if (value == null) return missing;\n const diff = toDate(value).getTime() - toDate(now).getTime();\n const span = Math.abs(diff);\n for (const [unit, size] of AGO_STEPS) {\n if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);\n }\n return relative.format(0, \"second\");\n },\n /**\n * A media running time from seconds, as a player shows it: \"4:05\", \"1:02:09\". Unknown\n * (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.\n */\n runningTime: (seconds: number | null | undefined) => {\n if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;\n const s = Math.floor(seconds);\n const two = (n: number) => String(n).padStart(2, \"0\");\n const [h, m] = [Math.floor(s / 3600), Math.floor((s % 3600) / 60)];\n return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;\n },\n /**\n * A position in media as an editor shows it, to a chosen precision: \"4:05\" (seconds), \"4:05.250\"\n * (`\"ms\"`), or \"0:04:05:07\" (`\"frames\"` at `fps`, the last part the frame). Hours appear only\n * from one hour, except in frames. Frames are always four parts, hours included, as SMPTE\n * timecode is (non-drop frame, with colons): a three-part \"1:05:00\" reads as one hour five, so\n * a frame count must never be three. Editors write the same four parts (strata-react issue\n * #122). Floors, never rounds up, so a time never reads ahead of the picture. Unknown (null,\n * negative, not finite) prints the placeholder. Set it in `tabular-nums`.\n */\n timecode: (seconds: number | null | undefined, { precision = \"seconds\", fps = 30 }: { precision?: \"seconds\" | \"ms\" | \"frames\"; fps?: number } = {}) => {\n if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;\n const whole = Math.floor(seconds);\n const two = (n: number) => String(n).padStart(2, \"0\");\n const [h, m] = [Math.floor(whole / 3600), Math.floor((whole % 3600) / 60)];\n const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;\n if (precision === \"ms\") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1000 + 1e-6), 999)).padStart(3, \"0\")}`;\n if (precision === \"frames\") return `${h}:${two(m)}:${two(whole % 60)}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;\n return base;\n },\n /** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */\n missing,\n /** A time of day: `format.clock(at)` is \"06:05\". */\n clock,\n /** A day without its year, for this week's things: `format.day(at)` is \"Sunday 8 November\". */\n day,\n /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is \"Sun 06:05\". */\n shortDay,\n /** A date with its year, for a record or a deadline: `format.date(at)` is \"8 Nov 2026\". */\n date,\n /** A date and time, for a log or history row: `format.dateTime(at)` is \"8 Nov 2026, 06:05\". */\n dateTime,\n /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */\n withUnit,\n /** A temperature in °C, joined by a non-breaking space. */\n celsius: (value: number) => withUnit(value, \"°C\"),\n /**\n * A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and\n * networks are sold): one decimal below 10 (\"5.2 GB\"), whole above (\"431 GB\"). Pass `unit`\n * to fix the unit, so figures compared side by side (\"431 of 466 GB\") share one.\n */\n bytes: (value: number, unit?: ByteUnit) => {\n const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? \"B\";\n const scaled = value / BYTE_SIZE[chosen];\n return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== \"B\" ? decimal : integer);\n },\n /**\n * A distance in metres as a person says it: metres under a kilometre (\"850 m\"), then\n * kilometres, one decimal below 100 (\"12.4 km\"), whole above; `\"imperial\"` is feet under a\n * tenth of a mile (\"320 ft\"), then miles (\"7.7 mi\").\n */\n distance: (metres: number, system: \"metric\" | \"imperial\" = \"metric\") => {\n if (system === \"imperial\") {\n const miles = metres / 1609.344;\n return miles < 0.1 ? withUnit(metres * 3.28084, \"ft\") : withUnit(miles, \"mi\", miles < 100 ? decimal : integer);\n }\n return Math.abs(metres) < 1000 ? withUnit(metres, \"m\") : withUnit(metres / 1000, \"km\", Math.abs(metres) < 100_000 ? decimal : integer);\n },\n /** The unit `bytes` would choose for a value, to share it across a set of figures. */\n byteUnit: (value: number): ByteUnit => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? \"B\",\n /**\n * \"1 piece\", \"6 pieces\": the count and its noun, so copy never reads \"1 pieces\". They are\n * joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same\n * call or a `\\s` regex, not a typed \"6 pieces\" string in a role's `name`.\n */\n count: (value: number | null | undefined, one: string, many = `${one}s`, { compact: short = false }: CountOptions = {}) =>\n value == null\n ? missing\n : `${(short ? compact : integer).format(value)}${NBSP}${plurals.select(value) === \"one\" ? one : many}`,\n };\n}\n\nexport type Format = ReturnType<typeof createFormat>;\n\n/** The en-GB formatters. */\nexport const format = createFormat(\"en-GB\");\n"],"mappings":";AAqCA,IAAa,OAAO;;AAGpB,IAAa,UAAU;AAIvB,IAAM,aAAkC;CAAC;CAAK;CAAM;CAAM;CAAM;CAAM;AAAI;AAC1E,IAAM,YAAY,OAAO,YAAY,WAAW,KAAK,GAAG,MAAM,CAAC,GAAG,OAAQ,CAAC,CAAC,CAAC;;AAgC7E,SAAgB,OAAO,OAAwB;CAC7C,MAAM,OAAO,iBAAiB,OAAO,QAAQ,IAAI,KAAK,KAAK;CAC3D,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG,MAAM,IAAI,WAAW,eAAe,KAAK,UAAU,OAAO,KAAK,CAAC,GAAG;CACrG,OAAO;AACT;AAEA,SAAS,aAAa,IAAyB,SAAgC;CAC7E,MAAM,UAAU,UAAyC,SAAS,OAAO,UAAU,GAAG,OAAO,OA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of hls.js this entry uses, so the engine can be handed in (a test's, or an app's own build). */
|
|
4
|
+
export type HlsEngine = typeof Hls;
|
|
5
|
+
/** Options of an HLS attacher. */
|
|
6
|
+
export type HlsAttacherOptions = {
|
|
7
|
+
/** Which to use where both would do: `"engine"` (default) is hls.js, `"native"` is the element's own HLS. Where only one is available that one is used. */
|
|
8
|
+
prefer?: "engine" | "native";
|
|
9
|
+
/** hls.js's own configuration. */
|
|
10
|
+
config?: Partial<HlsConfig>;
|
|
11
|
+
};
|
|
12
|
+
/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */
|
|
13
|
+
export declare function createHlsAttacher(Engine: HlsEngine, { prefer, config }?: HlsAttacherOptions): SourceAttacher;
|
|
14
|
+
/** HLS for `MediaPlayer attach` and `useAttachedSource`: hls.js where the browser has Media Source Extensions, the element's own HLS where it does not. */
|
|
15
|
+
export declare const attachHls: SourceAttacher;
|
|
16
|
+
/** An HLS attacher with options: `prefer: "native"`, or hls.js's own `config` (buffer sizes, headers). */
|
|
17
|
+
export declare const hlsAttacher: (options: HlsAttacherOptions) => SourceAttacher;
|
|
18
|
+
/** Whether this browser can play HLS at all, natively or through hls.js. */
|
|
19
|
+
export declare function hlsSupported(): boolean;
|
package/dist/hls.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import Hls from "hls.js";
|
|
2
|
+
// src/hls/index.ts
|
|
3
|
+
var WORDS = {
|
|
4
|
+
network: "The connection to the stream dropped.",
|
|
5
|
+
media: "The stream could not be decoded.",
|
|
6
|
+
other: "The stream could not be played.",
|
|
7
|
+
unsupported: "This browser cannot play this kind of stream."
|
|
8
|
+
};
|
|
9
|
+
/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */
|
|
10
|
+
function createHlsAttacher(Engine, { prefer = "engine", config = {} } = {}) {
|
|
11
|
+
return (el, src, context) => {
|
|
12
|
+
const native = el.canPlayType("application/vnd.apple.mpegurl") !== "" && (prefer === "native" || !Engine.isSupported());
|
|
13
|
+
let engine = null;
|
|
14
|
+
let seekOnLoad = null;
|
|
15
|
+
const stop = () => {
|
|
16
|
+
engine?.destroy();
|
|
17
|
+
engine = null;
|
|
18
|
+
if (seekOnLoad) el.removeEventListener("loadedmetadata", seekOnLoad);
|
|
19
|
+
seekOnLoad = null;
|
|
20
|
+
};
|
|
21
|
+
const start = (at) => {
|
|
22
|
+
stop();
|
|
23
|
+
if (native) {
|
|
24
|
+
el.src = src;
|
|
25
|
+
if (at > 0) {
|
|
26
|
+
seekOnLoad = () => {
|
|
27
|
+
el.currentTime = at;
|
|
28
|
+
seekOnLoad = null;
|
|
29
|
+
};
|
|
30
|
+
el.addEventListener("loadedmetadata", seekOnLoad, { once: true });
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!Engine.isSupported()) {
|
|
35
|
+
context.onProblem(WORDS.unsupported);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const hls = new Engine({
|
|
39
|
+
...config,
|
|
40
|
+
startPosition: at > 0 ? at : -1
|
|
41
|
+
});
|
|
42
|
+
engine = hls;
|
|
43
|
+
let recoveries = 0;
|
|
44
|
+
hls.on(Engine.Events.FRAG_LOADED, () => {
|
|
45
|
+
recoveries = 0;
|
|
46
|
+
});
|
|
47
|
+
hls.on(Engine.Events.ERROR, (_event, data) => {
|
|
48
|
+
if (!data.fatal || engine !== hls) return;
|
|
49
|
+
if (recoveries < 3 && data.type === Engine.ErrorTypes.NETWORK_ERROR) {
|
|
50
|
+
recoveries++;
|
|
51
|
+
hls.startLoad();
|
|
52
|
+
} else if (recoveries < 3 && data.type === Engine.ErrorTypes.MEDIA_ERROR) {
|
|
53
|
+
recoveries++;
|
|
54
|
+
hls.recoverMediaError();
|
|
55
|
+
} else {
|
|
56
|
+
context.onProblem(data.type === Engine.ErrorTypes.NETWORK_ERROR ? WORDS.network : data.type === Engine.ErrorTypes.MEDIA_ERROR ? WORDS.media : WORDS.other);
|
|
57
|
+
stop();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
hls.loadSource(src);
|
|
61
|
+
hls.attachMedia(el);
|
|
62
|
+
};
|
|
63
|
+
start(context.startAt);
|
|
64
|
+
return {
|
|
65
|
+
detach: () => {
|
|
66
|
+
stop();
|
|
67
|
+
if (native) el.removeAttribute("src");
|
|
68
|
+
},
|
|
69
|
+
reload: start
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** HLS for `MediaPlayer attach` and `useAttachedSource`: hls.js where the browser has Media Source Extensions, the element's own HLS where it does not. */
|
|
74
|
+
var attachHls = createHlsAttacher(Hls);
|
|
75
|
+
/** An HLS attacher with options: `prefer: "native"`, or hls.js's own `config` (buffer sizes, headers). */
|
|
76
|
+
var hlsAttacher = (options) => createHlsAttacher(Hls, options);
|
|
77
|
+
/** Whether this browser can play HLS at all, natively or through hls.js. */
|
|
78
|
+
function hlsSupported() {
|
|
79
|
+
if (typeof document === "undefined") return false;
|
|
80
|
+
return document.createElement("video").canPlayType("application/vnd.apple.mpegurl") !== "" || Hls.isSupported();
|
|
81
|
+
}
|
|
82
|
+
export { attachHls, createHlsAttacher, hlsAttacher, hlsSupported };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=hls.js.map
|
package/dist/hls.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hls.js","names":[],"sources":["../src/hls/index.ts"],"sourcesContent":["import Hls, { type HlsConfig } from \"hls.js\";\nimport type { SourceAttacher, StreamAttachment, StreamContext } from \"../components/media-player\";\n\n// The HLS entry: `import { attachHls } from \"strata-react/hls\"` (strata-react issue #179, from\n// strata-360, whose film preview is an HLS stream that starts playing after a couple of seconds and\n// keeps growing while the rest is made). `hls.js` is an optional peer that only this entry imports, as\n// `leaflet` is for the map, so an app that never plays a stream never installs it, and the main entry\n// never reaches it (the peer-contract test walks the built chunks to keep that true).\n//\n// It is a `SourceAttacher`, the one shape the main entry knows: `<MediaPlayer attach={attachHls}\n// src=\"…/film.m3u8\" />`, or `useAttachedSource(ref, src, attachHls, media.reportProblem)` beside\n// `useMediaElement` for a plain `<video>` (the panorama viewer, the compare components). It does three\n// things the engine does not do for a player:\n//\n// - **The engine wherever it can run, the element's own HLS where it cannot.** The brief was \"native\n// where the browser plays it\", but Chromium now plays HLS natively and, checked in Chromium 158 here,\n// its native pipeline failed (`DEMUXER_ERROR_COULD_NOT_PARSE`) on a growing playlist that hls.js plays,\n// which is the case this exists for. So hls.js is used wherever Media Source Extensions exist, one\n// behaviour on every browser, and the element's `src` only where they do not (older iOS). `prefer:\n// \"native\"` turns that around for an app that wants the system's own player behaviour.\n// - **Recovers what can be recovered, and says what cannot.** hls.js reports a fatal error for a\n// dropped connection or a decoder hiccup that its own `startLoad()` or `recoverMediaError()` fixes;\n// up to three of those are tried quietly (the count resets once a segment loads), and only then does\n// the player's load error appear, in words, with Try again. Try again restarts the engine at the\n// time playback had reached.\n// - **Cleans up**: the engine is destroyed when the source changes, the attacher changes or the player\n// unmounts, so a source switch never leaves two engines on one element.\n//\n// What is *growing* is the player's business (`MediaPlayer growing`), not the engine's: hls.js plays a\n// playlist with no end-list as a live one and the element reports the end of what exists as its\n// seekable range.\n//\n// Checked: hls.js has `isSupported()` (false with no Media Source Extensions), `startPosition` for a\n// restart in place, `startLoad()` and `recoverMediaError()` for the two recoverable kinds of fatal\n// error, and `Events.FRAG_LOADED` to know it is working again.\n\n/** The parts of hls.js this entry uses, so the engine can be handed in (a test's, or an app's own build). */\nexport type HlsEngine = typeof Hls;\n\nconst WORDS = {\n network: \"The connection to the stream dropped.\",\n media: \"The stream could not be decoded.\",\n other: \"The stream could not be played.\",\n unsupported: \"This browser cannot play this kind of stream.\",\n};\n\n/** Options of an HLS attacher. */\nexport type HlsAttacherOptions = {\n /** Which to use where both would do: `\"engine\"` (default) is hls.js, `\"native\"` is the element's own HLS. Where only one is available that one is used. */\n prefer?: \"engine\" | \"native\";\n /** hls.js's own configuration. */\n config?: Partial<HlsConfig>;\n};\n\n/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */\nexport function createHlsAttacher(Engine: HlsEngine, { prefer = \"engine\", config = {} }: HlsAttacherOptions = {}): SourceAttacher {\n return (el: HTMLMediaElement, src: string, context: StreamContext): StreamAttachment => {\n const canNative = el.canPlayType(\"application/vnd.apple.mpegurl\") !== \"\";\n const native = canNative && (prefer === \"native\" || !Engine.isSupported());\n let engine: Hls | null = null;\n let seekOnLoad: (() => void) | null = null;\n\n const stop = () => {\n engine?.destroy();\n engine = null;\n if (seekOnLoad) el.removeEventListener(\"loadedmetadata\", seekOnLoad);\n seekOnLoad = null;\n };\n\n const start = (at: number) => {\n stop();\n if (native) {\n el.src = src;\n if (at > 0) {\n seekOnLoad = () => {\n el.currentTime = at;\n seekOnLoad = null;\n };\n el.addEventListener(\"loadedmetadata\", seekOnLoad, { once: true });\n }\n return;\n }\n if (!Engine.isSupported()) {\n context.onProblem(WORDS.unsupported);\n return;\n }\n const hls = new Engine({ ...config, startPosition: at > 0 ? at : -1 });\n engine = hls;\n let recoveries = 0;\n hls.on(Engine.Events.FRAG_LOADED, () => {\n recoveries = 0;\n });\n hls.on(Engine.Events.ERROR, (_event, data) => {\n if (!data.fatal || engine !== hls) return;\n if (recoveries < 3 && data.type === Engine.ErrorTypes.NETWORK_ERROR) {\n recoveries++;\n hls.startLoad();\n } else if (recoveries < 3 && data.type === Engine.ErrorTypes.MEDIA_ERROR) {\n recoveries++;\n hls.recoverMediaError();\n } else {\n context.onProblem(data.type === Engine.ErrorTypes.NETWORK_ERROR ? WORDS.network : data.type === Engine.ErrorTypes.MEDIA_ERROR ? WORDS.media : WORDS.other);\n stop();\n }\n });\n hls.loadSource(src);\n hls.attachMedia(el);\n };\n\n start(context.startAt);\n return {\n detach: () => {\n stop();\n if (native) el.removeAttribute(\"src\");\n },\n reload: start,\n };\n };\n}\n\n/** HLS for `MediaPlayer attach` and `useAttachedSource`: hls.js where the browser has Media Source Extensions, the element's own HLS where it does not. */\nexport const attachHls: SourceAttacher = createHlsAttacher(Hls);\n\n/** An HLS attacher with options: `prefer: \"native\"`, or hls.js's own `config` (buffer sizes, headers). */\nexport const hlsAttacher = (options: HlsAttacherOptions): SourceAttacher => createHlsAttacher(Hls, options);\n\n/** Whether this browser can play HLS at all, natively or through hls.js. */\nexport function hlsSupported(): boolean {\n if (typeof document === \"undefined\") return false;\n return document.createElement(\"video\").canPlayType(\"application/vnd.apple.mpegurl\") !== \"\" || Hls.isSupported();\n}\n"],"mappings":";;AAuCA,IAAM,QAAQ;CACZ,SAAS;CACT,OAAO;CACP,OAAO;CACP,aAAa;AACf;;AAWA,SAAgB,kBAAkB,QAAmB,EAAE,SAAS,UAAU,SAAS,CAAC,MAA0B,CAAC,GAAmB;CAChI,QAAQ,IAAsB,KAAa,YAA6C;EAEtF,MAAM,SADY,GAAG,YAAY,+BAA+B,MAAM,OACzC,WAAW,YAAY,CAAC,OAAO,YAAY;EACxE,IAAI,SAAqB;EACzB,IAAI,aAAkC;EAEtC,MAAM,aAAa;GACjB,QAAQ,QAAQ;GAChB,SAAS;GACT,IAAI,YAAY,GAAG,oBAAoB,kBAAkB,UAAU;GACnE,aAAa;EACf;EAEA,MAAM,SAAS,OAAe;GAC5B,KAAK;GACL,IAAI,QAAQ;IACV,GAAG,MAAM;IACT,IAAI,KAAK,GAAG;KACV,mBAAmB;MACjB,GAAG,cAAc;MACjB,aAAa;KACf;KACA,GAAG,iBAAiB,kBAAkB,YAAY,EAAE,MAAM,KAAK,CAAC;IAClE;IACA;GACF;GACA,IAAI,CAAC,OAAO,YAAY,GAAG;IACzB,QAAQ,UAAU,MAAM,WAAW;IACnC;GACF;GACA,MAAM,MAAM,IAAI,OAAO;IAAE,GAAG;IAAQ,eAAe,KAAK,IAAI,KAAK;GAAG,CAAC;GACrE,SAAS;GACT,IAAI,aAAa;GACjB,IAAI,GAAG,OAAO,OAAO,mBAAmB;IACtC,aAAa;GACf,CAAC;GACD,IAAI,GAAG,OAAO,OAAO,QAAQ,QAAQ,SAAS;IAC5C,IAAI,CAAC,KAAK,SAAS,WAAW,KAAK;IACnC,IAAI,aAAa,KAAK,KAAK,SAAS,OAAO,WAAW,eAAe;KACnE;KACA,IAAI,UAAU;IAChB,OAAO,IAAI,aAAa,KAAK,KAAK,SAAS,OAAO,WAAW,aAAa;KACxE;KACA,IAAI,kBAAkB;IACxB,OAAO;KACL,QAAQ,UAAU,KAAK,SAAS,OAAO,WAAW,gBAAgB,MAAM,UAAU,KAAK,SAAS,OAAO,WAAW,cAAc,MAAM,QAAQ,MAAM,KAAK;KACzJ,KAAK;IACP;GACF,CAAC;GACD,IAAI,WAAW,GAAG;GAClB,IAAI,YAAY,EAAE;EACpB;EAEA,MAAM,QAAQ,OAAO;EACrB,OAAO;GACL,cAAc;IACZ,KAAK;IACL,IAAI,QAAQ,GAAG,gBAAgB,KAAK;GACtC;GACA,QAAQ;EACV;CACF;AACF;;AAGA,IAAa,YAA4B,kBAAkB,GAAG;;AAG9D,IAAa,eAAe,YAAgD,kBAAkB,KAAK,OAAO;;AAG1G,SAAgB,eAAwB;CACtC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,OAAO,SAAS,cAAc,OAAO,CAAC,CAAC,YAAY,+BAA+B,MAAM,MAAM,IAAI,YAAY;AAChH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,12 @@ export { useClientWork, type ClientWork, type WorkContext, type WorkPhase } from
|
|
|
35
35
|
export { JobStatus, type JobStatusProps, type JobFailure, type JobWords } from './components/job-status';
|
|
36
36
|
export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
|
|
37
37
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type CellValue, type Column, type Sort, type DataTableProps, type RowSelection, type RowExpansion, } from './components/data-table';
|
|
38
|
-
export { MediaPlayer, useMediaElement, SPEECH_RATES, type MediaPlayerProps, type MediaElementState, type MediaProblem, type MediaSource, type MediaSession } from './components/media-player';
|
|
38
|
+
export { MediaPlayer, useMediaElement, useAttachedSource, SPEECH_RATES, type MediaPlayerProps, type MediaElementState, type MediaElementOptions, type MediaWindow, type StreamContext, type StreamAttachment, type SourceAttacher, type MediaProblem, type MediaSource, type MediaSession } from './components/media-player';
|
|
39
|
+
export { TranscriptView, type TranscriptViewProps, type TranscriptSeek } from './components/transcript-view';
|
|
40
|
+
export { phraseAt, wordAt, type TranscriptGroup, type TranscriptPhrase, type TranscriptWord } from './lib/transcript';
|
|
41
|
+
export { Waveform, type WaveformProps, type WaveformMark, type WaveformMarkKind, type WaveformSpan, type WaveformTone } from './components/waveform';
|
|
42
|
+
export { resamplePeaks, toPeakPair, peaksFromAudio, type WaveformPeaks, type PeakPair, type DecodedAudio } from './lib/waveform';
|
|
43
|
+
export { MediaGroup, PlayWindowButton, joinMediaGroup, type PlayWindowButtonProps } from './components/media-group';
|
|
39
44
|
export { Transport, TimeReadout, SeekBar, VolumeControl, RateChoice, MediaStage, StageGuides, transportShortcuts, type TransportProps, type SeekBarProps, type VolumeControlProps, type Precision } from './components/media';
|
|
40
45
|
export { Timeline, TimelineZoomControls, useTimelineZoom, noOverlap, type TimelineProps, type TimelineItem, type TimelineLane, type TimelineMarker, type TimelineChange, type TimelineDrop } from './components/timeline';
|
|
41
46
|
export { tickStep, ticksBetween, tickLabel } from './lib/timeline';
|
|
@@ -79,3 +84,14 @@ export { differences, readPixels, resample, MAX_SIDE, DEFAULT_TOLERANCE, type Di
|
|
|
79
84
|
export { Workspace, Split, Pane, useWorkspaceState, type WorkspaceState, type PaneProps } from './components/workspace';
|
|
80
85
|
export { useHistory, useHistoryState, type History, type HistoryOptions, type HistoryStep, type HistoryStateOptions, type SetOptions, } from './components/history';
|
|
81
86
|
export { useAutoSave, useLeaveGuard, SaveStatus, type AutoSave, type AutoSaveOptions, type SaveState } from './components/save';
|
|
87
|
+
export { RichText, Conversation, Composer, type RichTextProps, type ConversationProps, type ConversationTurn, type ComposerProps } from './components/conversation';
|
|
88
|
+
export { parseRichText, parseInline, matchEntities, safeHref, plainText, type EntityMatch, type EntityMatcher, type Block as RichBlock, type Inline as RichInline } from './lib/rich-text';
|
|
89
|
+
export { Lightbox, type LightboxProps, type LightboxItem } from './components/lightbox';
|
|
90
|
+
export { RegionEditor, describeRegion, type RegionEditorProps, type EditableRegion, type RegionTone } from './components/region-editor';
|
|
91
|
+
export { moveRect, resizeRect, fitRect, drawRect, lerpRect, ease, type Rect, type Handle, type RectLimits, type Easing } from './lib/region';
|
|
92
|
+
export { SequenceTimeline, type SequenceTimelineProps, type SequenceItem, type CutRoom, type CutChange } from './components/sequence-timeline';
|
|
93
|
+
export { snapToGrid, stepOnGrid, gridPoints, clampToRoom, settleCut, type Grid, type CutLimit } from './lib/sequence';
|
|
94
|
+
export { Tree, type TreeProps, type TreeNodeState } from './components/tree';
|
|
95
|
+
export { FolderPicker, parentOf, ancestorsOf, type FolderPickerProps, type Folder } from './components/folder-picker';
|
|
96
|
+
export { MarkableText, Mark, MarkSummary, type MarkableTextProps, type MarkKind, type MarkTone, type MarkPattern } from './components/markable-text';
|
|
97
|
+
export { rangeBetween, countMarks, stepId } from './lib/marks';
|