A row plays only with a timeline to play; the speed shown follows the world clock; mark labels merge whole and cut by character

A weather row's play started the world clock even with no time to show,
where there is no timeline; it now does nothing then, as the timeline's
own Play cannot be reached. A weather layer made without a weather clock
does nothing once destroyed, so enabling it after builds no clock.

The timeline's speed follows the world clock's rate whoever set it, and
its Play runs at that rate, so it and a row's play never run at different
rates; a rate not offered shows as the nearest offered speed. Choosing a
speed sets the clock's rate first, also while a driver steps.

Marks merge on their whole label and are cut for showing after, so two
whose labels only differ past the cut stay two, and the cut counts
graphemes (code points where the runtime cannot tell them), so an emoji is
never split.

Tests that compared a DOM element with null built an assertion message
from the element when they failed, which hung the run; they compare plain
values now, so they fail at once. The timeline tests put the clock back to
real time after each.
This commit is contained in:
Sameh Khamis committed 2026-11-14 21:12:43 -08:00
1 parent 1dc2dbe4ea
commit ac04812db2
26 files changed
+274 -108

No files matched your search

+33 -6
View File
@@ -33,9 +33,37 @@
*/
const MARK_TEXT = ['label', 'id', 'kind'];
/** The longest label a mark carries, ellipsis and all. */
/**
* The longest label a mark carries, ellipsis and all, in characters as a
* reader sees them (graphemes where the runtime can tell them, otherwise code
* points), so an emoji or an accented letter is never split.
*/
export const WORLD_CLOCK_MARK_LABEL_LENGTH = 60;
const graphemes =
typeof Intl?.Segmenter === 'function'
? (() => {
const segmenter = new Intl.Segmenter(undefined, {
granularity: 'grapheme',
});
return (text) =>
Array.from(segmenter.segment(text), ({ segment }) => segment);
})()
: (text) => Array.from(text);
/** `mark` with its label cut to WORLD_CLOCK_MARK_LABEL_LENGTH, ending in `…`. */
function shownMark(mark) {
if (!mark.label || mark.label.length <= WORLD_CLOCK_MARK_LABEL_LENGTH)
return mark;
const parts = graphemes(mark.label);
if (parts.length <= WORLD_CLOCK_MARK_LABEL_LENGTH) return mark;
const label = `${parts
.slice(0, WORLD_CLOCK_MARK_LABEL_LENGTH - 1)
.join('')
.trimEnd()}…`;
return Object.freeze({ ...mark, label });
}
/**
* A mark (a number, or `{time, label?, id?, kind?}`) in its one shape, or
* null for one with no finite time.
@@ -53,10 +81,6 @@ function readMark(input) {
const value = input[key];
if (typeof value === 'string' && value.trim()) mark[key] = value.trim();
}
if (mark.label?.length > WORLD_CLOCK_MARK_LABEL_LENGTH)
mark.label = `${mark.label
.slice(0, WORLD_CLOCK_MARK_LABEL_LENGTH - 1)
.trimEnd()}…`;
return Object.freeze(mark);
}
@@ -484,9 +508,12 @@ export function createWorldClock({
const told = new Set();
for (const mark of details.values())
if (Object.keys(mark).length > 1) told.add(mark.time);
// Marks merge on their whole label, and are cut for showing after, so
// two whose labels only differ past the cut stay two.
const markDetails = [...details.values()]
.filter((mark) => Object.keys(mark).length > 1 || !told.has(mark.time))
.sort(byMark);
.sort(byMark)
.map(shownMark);
const marks = [...new Set(markDetails.map((mark) => mark.time))];
return { start, end, marks, markDetails };
},