@telepath-computer/television 1.5.9 → 1.6.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.
- package/dist/THIRD-PARTY-NOTICES.txt +701 -0
- package/dist/cli.cjs +9035 -596
- package/dist/onboarding/tv-guide/welcome.html +14 -4
- package/dist/skills/television/SKILL.md +39 -33
- package/dist/skills/television/resources.md +4 -4
- package/dist/skills/television/templates.md +77 -0
- package/dist/skills/television/theming.md +31 -17
- package/dist/templates/calendar/README.md +17 -0
- package/dist/{skills/tv-tasks → templates/calendar}/THIRD-PARTY-NOTICES.txt +22 -22
- package/dist/templates/calendar/calendar-attendees.js +131 -0
- package/dist/templates/calendar/calendar-event.js +22 -0
- package/dist/templates/calendar/calendar-motion.js +273 -0
- package/dist/templates/calendar/calendar-page.js +403 -0
- package/dist/templates/calendar/calendar-time-axis.js +32 -0
- package/dist/templates/calendar/calendar-week.js +711 -0
- package/dist/templates/calendar/data.json +3 -0
- package/dist/templates/calendar/icon.svg +1 -0
- package/dist/templates/calendar/index.html +27 -0
- package/dist/templates/calendar/manifest.json +148 -0
- package/dist/templates/calendar/styles.css +771 -0
- package/dist/templates/checklist/README.md +45 -0
- package/dist/templates/checklist/THIRD-PARTY-NOTICES.txt +29 -0
- package/dist/templates/checklist/data.json +1 -0
- package/dist/templates/checklist/icon.svg +8 -0
- package/dist/templates/checklist/icons.css +61 -0
- package/dist/templates/checklist/index.html +47 -0
- package/dist/templates/checklist/manifest.json +49 -0
- package/dist/templates/checklist/model.d.ts +30 -0
- package/dist/templates/checklist/model.js +60 -0
- package/dist/templates/checklist/page.js +425 -0
- package/dist/templates/checklist/styles.css +206 -0
- package/dist/templates/document/README.md +55 -0
- package/dist/templates/document/THIRD-PARTY-NOTICES.txt +1080 -0
- package/dist/templates/document/data.json +3 -0
- package/dist/templates/document/editor.css +1 -0
- package/dist/templates/document/editor.js +37 -0
- package/dist/templates/document/icon.svg +6 -0
- package/dist/templates/document/index.html +29 -0
- package/dist/templates/document/manifest.json +22 -0
- package/dist/templates/document/page.js +190 -0
- package/dist/templates/document/styles.css +76 -0
- package/dist/templates/map/README.md +85 -0
- package/dist/templates/map/THIRD-PARTY-NOTICES.txt +84 -0
- package/dist/templates/map/data.json +1 -0
- package/dist/templates/map/icon.svg +8 -0
- package/dist/templates/map/icons.svg +43 -0
- package/dist/templates/map/index.html +95 -0
- package/dist/templates/map/manifest.json +227 -0
- package/dist/templates/map/map-model.js +18 -0
- package/dist/templates/map/map.css +202 -0
- package/dist/templates/map/map.js +728 -0
- package/dist/templates/map/vendor/LICENSE +26 -0
- package/dist/templates/map/vendor/README.md +11 -0
- package/dist/templates/map/vendor/leaflet.css +661 -0
- package/dist/templates/map/vendor/leaflet.js +6 -0
- package/dist/templates/map/vendor/lucide/LICENSE +43 -0
- package/dist/templates/map/vendor/lucide/README.md +46 -0
- package/dist/templates/map/vendor/lucide/icons.js +832 -0
- package/dist/templates/map/vendor/lucide/svg/airport.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/bar.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/beach.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/bridge.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/bus.svg +21 -0
- package/dist/templates/map/vendor/lucide/svg/church.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/coffee.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/ferry.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/flag.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/heart.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/home.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/hospital.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/hotel.svg +24 -0
- package/dist/templates/map/vendor/lucide/svg/info.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/landmark.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/mountain.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/museum.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/music.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/park.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/parking.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/pin.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/restaurant.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/school.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/shop.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/sports.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/star.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/theatre.svg +23 -0
- package/dist/templates/map/vendor/lucide/svg/train.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/viewpoint.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/work.svg +18 -0
- package/dist/templates/sticky-note/Caveat-Medium.woff2 +0 -0
- package/dist/templates/sticky-note/README.md +47 -0
- package/dist/templates/sticky-note/THIRD-PARTY-NOTICES.txt +127 -0
- package/dist/templates/sticky-note/data.json +1 -0
- package/dist/templates/sticky-note/icon.svg +16 -0
- package/dist/templates/sticky-note/icons.css +61 -0
- package/dist/templates/sticky-note/index.html +31 -0
- package/dist/templates/sticky-note/manifest.json +27 -0
- package/dist/templates/sticky-note/model.d.ts +33 -0
- package/dist/templates/sticky-note/model.js +152 -0
- package/dist/templates/sticky-note/page.js +84 -0
- package/dist/templates/sticky-note/styles.css +140 -0
- package/dist/templates/table/README.md +107 -0
- package/dist/templates/table/data.json +4 -0
- package/dist/templates/table/icon.svg +6 -0
- package/dist/templates/table/index.html +15 -0
- package/dist/templates/table/manifest.json +70 -0
- package/dist/templates/table/model.d.ts +164 -0
- package/dist/templates/table/model.js +395 -0
- package/dist/templates/table/page.js +1045 -0
- package/dist/templates/table/selection-model.d.ts +67 -0
- package/dist/templates/table/selection-model.js +163 -0
- package/dist/templates/table/styles.css +522 -0
- package/dist/views/markdown/THIRD-PARTY-NOTICES.txt +408 -0
- package/dist/views/markdown/index.html +21 -21
- package/dist/web/assets/main-CRSNodQt.js +864 -0
- package/dist/web/assets/main-DnvQkpg4.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/skills/tv-calendar/SKILL.md +0 -100
- package/dist/skills/tv-calendar/calendar.css +0 -1
- package/dist/skills/tv-calendar/calendar.js +0 -400
- package/dist/skills/tv-table/SKILL.md +0 -95
- package/dist/skills/tv-tasks/SKILL.md +0 -269
- package/dist/skills/tv-tasks/task.css +0 -180
- package/dist/skills/tv-tasks/task.js +0 -304
- package/dist/web/assets/calendar-DToAnkzj.png +0 -0
- package/dist/web/assets/main-CPopSWec.js +0 -848
- package/dist/web/assets/main-CunC2_Nx.css +0 -1
- package/dist/web/assets/markdown-DdDrJuVK.png +0 -0
- package/dist/web/assets/table-oeG9uAN1.png +0 -0
- package/dist/web/assets/tasks-D4xqXFPl.png +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The attendees line of an event block: a person icon, then as many names as
|
|
2
|
+
// fit whole in the block's width and a count of the rest ("Ana, Ben +2"). When
|
|
3
|
+
// not even one name fits, the line shows the icon and the total count. A name
|
|
4
|
+
// is never cut off.
|
|
5
|
+
//
|
|
6
|
+
// The fit is measured with a canvas in the line's own font, so trying each
|
|
7
|
+
// candidate text writes nothing to the page; the line's text changes only
|
|
8
|
+
// when the chosen text does. A resize observer refits a line whenever its
|
|
9
|
+
// width changes, as when a window resize or the 100px column minimum changes
|
|
10
|
+
// a column's width, or when the line first becomes visible. Font loading
|
|
11
|
+
// refits every line, because a fallback font measures differently.
|
|
12
|
+
|
|
13
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
14
|
+
// Phosphor's "user" icon, fill weight, drawn in the line's text colour.
|
|
15
|
+
// Phosphor Icons, MIT. See THIRD-PARTY-NOTICES.txt for the upstream terms.
|
|
16
|
+
const PERSON_ICON_PATH = "M230.93,220a8,8,0,0,1-6.93,4H32a8,8,0,0,1-6.92-12c15.23-26.33,38.7-45.21,66.09-54.16a72,72,0,1,1,73.66,0c27.39,8.95,50.86,27.83,66.09,54.16A8,8,0,0,1,230.93,220Z";
|
|
17
|
+
// Canvas text metrics and layout widths can differ by a fraction of a pixel.
|
|
18
|
+
const FIT_TOLERANCE_PX = 0.5;
|
|
19
|
+
|
|
20
|
+
const namesByLine = new WeakMap();
|
|
21
|
+
const observedLines = new Set();
|
|
22
|
+
let resizeObserver = null;
|
|
23
|
+
let measuringContext = null;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Chooses the attendees text for a line `availablePx` wide: every name that
|
|
27
|
+
* fits whole, in order, then "+n" for the rest, or the total count when no
|
|
28
|
+
* name fits. `measure` returns a candidate text's width in pixels.
|
|
29
|
+
*/
|
|
30
|
+
export function fitAttendees(names, availablePx, measure) {
|
|
31
|
+
for (let shown = names.length; shown >= 1; shown -= 1) {
|
|
32
|
+
const rest = names.length - shown;
|
|
33
|
+
const text = names.slice(0, shown).join(", ") + (rest > 0 ? ` +${rest}` : "");
|
|
34
|
+
if (measure(text) <= availablePx + FIT_TOLERANCE_PX) return text;
|
|
35
|
+
}
|
|
36
|
+
return String(names.length);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Builds an empty attendees line: the icon and the element for its names. */
|
|
40
|
+
export function createAttendeesLine() {
|
|
41
|
+
const line = document.createElement("div");
|
|
42
|
+
line.className = "event-attendees";
|
|
43
|
+
line.hidden = true;
|
|
44
|
+
const icon = document.createElementNS(SVG_NS, "svg");
|
|
45
|
+
icon.setAttribute("class", "event-attendees-icon");
|
|
46
|
+
icon.setAttribute("viewBox", "0 0 256 256");
|
|
47
|
+
icon.setAttribute("fill", "currentColor");
|
|
48
|
+
icon.setAttribute("aria-hidden", "true");
|
|
49
|
+
const path = document.createElementNS(SVG_NS, "path");
|
|
50
|
+
path.setAttribute("d", PERSON_ICON_PATH);
|
|
51
|
+
icon.append(path);
|
|
52
|
+
const label = document.createElement("span");
|
|
53
|
+
label.className = "event-attendees-names";
|
|
54
|
+
line.append(icon, label);
|
|
55
|
+
return line;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Shows `names` on an attendees line, or hides the line when `names` is null
|
|
60
|
+
* or empty, and keeps the line fitted to its width from then on.
|
|
61
|
+
*/
|
|
62
|
+
export function setAttendees(line, names) {
|
|
63
|
+
if (!names || names.length === 0) {
|
|
64
|
+
if (!line.hidden) line.hidden = true;
|
|
65
|
+
namesByLine.delete(line);
|
|
66
|
+
observedLines.delete(line);
|
|
67
|
+
resizeObserver?.unobserve(line);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const previous = namesByLine.get(line);
|
|
71
|
+
if (line.hidden) line.hidden = false;
|
|
72
|
+
if (previous && previous.length === names.length && previous.every((name, index) => name === names[index])) return;
|
|
73
|
+
namesByLine.set(line, [...names]);
|
|
74
|
+
// A line seen before keeps its width, so it is refitted now. A new line is
|
|
75
|
+
// not yet in its place in the calendar; the observer fits it once it has
|
|
76
|
+
// been laid out there, before it is painted.
|
|
77
|
+
if (observedLines.has(line)) {
|
|
78
|
+
fitLine(line);
|
|
79
|
+
} else {
|
|
80
|
+
setLabelText(line, names.join(", "));
|
|
81
|
+
observedLines.add(line);
|
|
82
|
+
observeResizes().observe(line);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function observeResizes() {
|
|
87
|
+
if (resizeObserver) return resizeObserver;
|
|
88
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
89
|
+
for (const entry of entries) fitLine(entry.target);
|
|
90
|
+
});
|
|
91
|
+
document.fonts?.addEventListener("loadingdone", () => {
|
|
92
|
+
for (const line of observedLines) fitLine(line);
|
|
93
|
+
});
|
|
94
|
+
return resizeObserver;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function fitLine(line) {
|
|
98
|
+
const names = namesByLine.get(line);
|
|
99
|
+
if (!names) return;
|
|
100
|
+
// The observer reports a line once more when its event is removed from
|
|
101
|
+
// the page; it is then forgotten.
|
|
102
|
+
if (!line.isConnected) {
|
|
103
|
+
observedLines.delete(line);
|
|
104
|
+
resizeObserver?.unobserve(line);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const label = line.querySelector(".event-attendees-names");
|
|
108
|
+
// A line hidden because its block is too short has no width. It keeps the
|
|
109
|
+
// whole list until it shows, when the observer fits it.
|
|
110
|
+
const availablePx = label.clientWidth;
|
|
111
|
+
if (availablePx === 0) {
|
|
112
|
+
setLabelText(line, names.join(", "));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const context = measuringCanvas();
|
|
116
|
+
// Built from the longhands, because the computed shorthand is empty in some
|
|
117
|
+
// browsers when a font property has no shorthand form.
|
|
118
|
+
const style = getComputedStyle(label);
|
|
119
|
+
context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
120
|
+
setLabelText(line, fitAttendees(names, availablePx, (text) => context.measureText(text).width));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function setLabelText(line, text) {
|
|
124
|
+
const label = line.querySelector(".event-attendees-names");
|
|
125
|
+
if (label.textContent !== text) label.textContent = text;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function measuringCanvas() {
|
|
129
|
+
measuringContext ??= document.createElement("canvas").getContext("2d");
|
|
130
|
+
return measuringContext;
|
|
131
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Ported from Television tv-calendar calendar-event.ts for an unbundled template.
|
|
2
|
+
/**
|
|
3
|
+
* Carries one authored event; calendar-week validates and places it. The
|
|
4
|
+
* event's fields are attributes, except `attendees`, an array of names kept
|
|
5
|
+
* as a property so a name may contain any character.
|
|
6
|
+
*/
|
|
7
|
+
class CalendarEventElement extends HTMLElement {
|
|
8
|
+
/** @type {string[] | null} */
|
|
9
|
+
attendees = null;
|
|
10
|
+
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
this.dispatchEvent(new Event("reactive:connect"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
disconnectedCallback() {
|
|
16
|
+
this.dispatchEvent(new Event("reactive:disconnect"));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
customElements.define("calendar-event", CalendarEventElement);
|
|
20
|
+
export {
|
|
21
|
+
CalendarEventElement
|
|
22
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// Motion for the calendar: events arriving, leaving and moving, and the days
|
|
2
|
+
// sliding when the range changes. Nothing moves when the person has asked for
|
|
3
|
+
// reduced motion.
|
|
4
|
+
//
|
|
5
|
+
// An event that moves or changes size starts where it was drawn and glides
|
|
6
|
+
// to its new place (first, last, invert, play). Days kept across a change in
|
|
7
|
+
// how many days show glide the same way. A day, or an event, that stops
|
|
8
|
+
// showing is put back where it was drawn as a copy that fades out and is then
|
|
9
|
+
// removed. A change of start date slides the whole calendar sideways with a
|
|
10
|
+
// view transition, so the days on screen before and after line up as one
|
|
11
|
+
// strip.
|
|
12
|
+
|
|
13
|
+
const ARRIVE = [
|
|
14
|
+
{ opacity: 0, scale: "0.92", translate: "0 6px" },
|
|
15
|
+
{ opacity: 1, scale: "1", translate: "0 0" },
|
|
16
|
+
];
|
|
17
|
+
const ARRIVE_MS = 520;
|
|
18
|
+
const ARRIVE_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
19
|
+
// Events that arrive together follow one another in time order, all within
|
|
20
|
+
// a short span however many there are.
|
|
21
|
+
const STAGGER_MS = 40;
|
|
22
|
+
const STAGGER_MAX_MS = 360;
|
|
23
|
+
|
|
24
|
+
// Leaving starts from the event as it is drawn, even part-way through
|
|
25
|
+
// arriving, so it has only an end.
|
|
26
|
+
const LEAVE = [{ opacity: 0, scale: "0.94" }];
|
|
27
|
+
const LEAVE_MS = 260;
|
|
28
|
+
const LEAVE_EASE = "cubic-bezier(0.4, 0, 1, 1)";
|
|
29
|
+
|
|
30
|
+
const MOVE_MS = 450;
|
|
31
|
+
const MOVE_EASE = "cubic-bezier(0.32, 0.72, 0, 1)";
|
|
32
|
+
const MOVE_ID = "calendar-move";
|
|
33
|
+
|
|
34
|
+
const SLIDE_MS = 520;
|
|
35
|
+
const SLIDE_EASE = "cubic-bezier(0.32, 0.72, 0, 1)";
|
|
36
|
+
|
|
37
|
+
const DAY_FADE_MS = MOVE_MS;
|
|
38
|
+
const DAY_FADE_EASE = "ease";
|
|
39
|
+
|
|
40
|
+
// Day parts still shown; the copies of days on their way out are left out.
|
|
41
|
+
const DAY_PARTS = ":is(calendar-day, calendar-column, calendar-cell):not([data-leaving])";
|
|
42
|
+
|
|
43
|
+
export function motionAllowed() {
|
|
44
|
+
return !matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const innerOf = (event) => event.querySelector(":scope > .event-block > .event-block-inner");
|
|
48
|
+
|
|
49
|
+
/** Whether an event is drawn on the calendar now, and not on its way out. */
|
|
50
|
+
function isPlaced(event) {
|
|
51
|
+
const parent = event.parentElement?.localName;
|
|
52
|
+
return (parent === "calendar-grid" || parent === "calendar-allday") && !event.hasAttribute("data-leaving") && innerOf(event) !== null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Where an element's layout box sits inside a positioned ancestor, ignoring transforms. */
|
|
56
|
+
function offsetIn(element, container) {
|
|
57
|
+
let left = 0;
|
|
58
|
+
let top = 0;
|
|
59
|
+
for (let node = element; node && node !== container; node = node.offsetParent) {
|
|
60
|
+
left += node.offsetLeft;
|
|
61
|
+
top += node.offsetTop;
|
|
62
|
+
}
|
|
63
|
+
return { left, top, width: element.offsetWidth, height: element.offsetHeight };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Where every drawn event and day is now, as the person sees it, and what is
|
|
68
|
+
* needed to draw it again in place if it stops showing.
|
|
69
|
+
*/
|
|
70
|
+
export function measure(week) {
|
|
71
|
+
const events = new Map();
|
|
72
|
+
for (const event of week.querySelectorAll("calendar-event")) {
|
|
73
|
+
if (!isPlaced(event)) continue;
|
|
74
|
+
const inner = innerOf(event);
|
|
75
|
+
const box = inner.getBoundingClientRect();
|
|
76
|
+
const container = event.parentElement;
|
|
77
|
+
events.set(event, {
|
|
78
|
+
left: box.left,
|
|
79
|
+
top: box.top,
|
|
80
|
+
width: inner.offsetWidth,
|
|
81
|
+
height: inner.offsetHeight,
|
|
82
|
+
block: inner.parentElement,
|
|
83
|
+
container,
|
|
84
|
+
size: event.dataset.size,
|
|
85
|
+
place: offsetIn(inner, container),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const days = new Map();
|
|
89
|
+
for (const part of week.querySelectorAll(DAY_PARTS)) {
|
|
90
|
+
const box = part.getBoundingClientRect();
|
|
91
|
+
days.set(`${part.localName} ${part.getAttribute("date")}`, {
|
|
92
|
+
left: box.left,
|
|
93
|
+
width: box.width,
|
|
94
|
+
part,
|
|
95
|
+
container: part.parentElement,
|
|
96
|
+
background: getComputedStyle(part).backgroundColor,
|
|
97
|
+
place: offsetIn(part, part.parentElement),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return { events, days };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The container to draw a copy in: the one it was in, or the one now in its place. */
|
|
104
|
+
function containerFor(week, container) {
|
|
105
|
+
return container.isConnected ? container : week.querySelector(`:scope > ${container.localName}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Pins an element at a layout box inside its positioned container. */
|
|
109
|
+
function pin(element, { left, top, width, height }) {
|
|
110
|
+
Object.assign(element.style, { position: "absolute", margin: "0", left: `${left}px`, top: `${top}px`, width: `${width}px`, height: `${height}px` });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Draws an event that is still in the calendar but no longer shown, as on a
|
|
115
|
+
* day that stops showing, as a copy where it was, and lets the copy leave.
|
|
116
|
+
*/
|
|
117
|
+
function leaveCopy(week, event, from) {
|
|
118
|
+
const container = containerFor(week, from.container);
|
|
119
|
+
if (!container) return;
|
|
120
|
+
const copy = event.cloneNode(false);
|
|
121
|
+
copy.removeAttribute("data-key");
|
|
122
|
+
copy.removeAttribute("style");
|
|
123
|
+
if (from.size) copy.dataset.size = from.size;
|
|
124
|
+
// The block covers the container, and the block inside sits where it was.
|
|
125
|
+
Object.assign(from.block.style, { position: "absolute", inset: "0", padding: "0", gridArea: "auto" });
|
|
126
|
+
pin(from.block.firstElementChild, from.place);
|
|
127
|
+
copy.append(from.block);
|
|
128
|
+
container.append(copy);
|
|
129
|
+
leave(copy);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Draws a day part that has stopped showing where it was, and fades it out. */
|
|
133
|
+
function fadeOutDay(week, from) {
|
|
134
|
+
const container = containerFor(week, from.container);
|
|
135
|
+
if (!container) return;
|
|
136
|
+
const { part } = from;
|
|
137
|
+
part.setAttribute("data-leaving", "");
|
|
138
|
+
part.style.gridArea = "auto";
|
|
139
|
+
part.style.backgroundColor = from.background;
|
|
140
|
+
pin(part, from.place);
|
|
141
|
+
container.append(part);
|
|
142
|
+
const animation = part.animate([{ opacity: 1 }, { opacity: 0 }], { duration: DAY_FADE_MS, easing: DAY_FADE_EASE, fill: "forwards" });
|
|
143
|
+
animation.finished.then(() => part.remove(), () => part.remove());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Moves what changed from where it was to where it now is: events that moved
|
|
148
|
+
* or resized glide, new events arrive, and events that stopped showing leave.
|
|
149
|
+
* Days kept across a change in the number of days glide to their new
|
|
150
|
+
* columns, new days fade in, and days that stopped showing fade out.
|
|
151
|
+
*/
|
|
152
|
+
export function play(week, before) {
|
|
153
|
+
const arriving = [];
|
|
154
|
+
for (const [event, from] of before.events) {
|
|
155
|
+
if (event.isConnected && !isPlaced(event) && from.block.parentElement !== event) leaveCopy(week, event, from);
|
|
156
|
+
}
|
|
157
|
+
for (const event of week.querySelectorAll("calendar-event")) {
|
|
158
|
+
if (!isPlaced(event)) continue;
|
|
159
|
+
const inner = innerOf(event);
|
|
160
|
+
const from = before.events.get(event);
|
|
161
|
+
if (!from) {
|
|
162
|
+
arriving.push(event);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
for (const animation of inner.getAnimations()) if (animation.id === MOVE_ID) animation.cancel();
|
|
166
|
+
const box = inner.getBoundingClientRect();
|
|
167
|
+
const to = { left: box.left, top: box.top, width: inner.offsetWidth, height: inner.offsetHeight };
|
|
168
|
+
const dx = from.left - to.left;
|
|
169
|
+
const dy = from.top - to.top;
|
|
170
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 && Math.abs(from.width - to.width) < 0.5 && Math.abs(from.height - to.height) < 0.5) continue;
|
|
171
|
+
const animation = inner.animate([
|
|
172
|
+
{ translate: `${dx}px ${dy}px`, width: `${from.width}px`, height: `${from.height}px` },
|
|
173
|
+
{ translate: "0 0", width: `${to.width}px`, height: `${to.height}px` },
|
|
174
|
+
], { duration: MOVE_MS, easing: MOVE_EASE });
|
|
175
|
+
animation.id = MOVE_ID;
|
|
176
|
+
}
|
|
177
|
+
arrive(arriving);
|
|
178
|
+
|
|
179
|
+
if (before.days.size === 0) return;
|
|
180
|
+
const shown = new Set();
|
|
181
|
+
for (const part of week.querySelectorAll(DAY_PARTS)) {
|
|
182
|
+
const key = `${part.localName} ${part.getAttribute("date")}`;
|
|
183
|
+
shown.add(key);
|
|
184
|
+
const from = before.days.get(key);
|
|
185
|
+
if (!from) {
|
|
186
|
+
part.animate([{ opacity: 0 }, { opacity: 1 }], { duration: DAY_FADE_MS, easing: DAY_FADE_EASE });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const box = part.getBoundingClientRect();
|
|
190
|
+
const dx = from.left - box.left;
|
|
191
|
+
// Headers keep their size, so their text never stretches; the columns
|
|
192
|
+
// and all-day cells behind the events stretch to their new width.
|
|
193
|
+
const scale = part.localName === "calendar-day" || box.width === 0 ? 1 : from.width / box.width;
|
|
194
|
+
if (Math.abs(dx) < 0.5 && Math.abs(scale - 1) < 0.005) continue;
|
|
195
|
+
part.animate([
|
|
196
|
+
{ translate: `${dx}px 0`, scale: `${scale} 1`, transformOrigin: "0 0" },
|
|
197
|
+
{ translate: "0 0", scale: "1 1", transformOrigin: "0 0" },
|
|
198
|
+
], { duration: MOVE_MS, easing: MOVE_EASE });
|
|
199
|
+
}
|
|
200
|
+
for (const [key, from] of before.days) {
|
|
201
|
+
if (!shown.has(key) && !from.part.isConnected) fadeOutDay(week, from);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Plays the arrival of new events, in start order. */
|
|
206
|
+
function arrive(events) {
|
|
207
|
+
const ordered = [...events].sort((a, b) => (a.getAttribute("start") ?? "").localeCompare(b.getAttribute("start") ?? ""));
|
|
208
|
+
const step = ordered.length > 1 ? Math.min(STAGGER_MS, STAGGER_MAX_MS / (ordered.length - 1)) : 0;
|
|
209
|
+
ordered.forEach((event, index) => {
|
|
210
|
+
innerOf(event).animate(ARRIVE, { duration: ARRIVE_MS, delay: index * step, easing: ARRIVE_EASE, fill: "backwards" });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Plays an event leaving, then removes it. */
|
|
215
|
+
export function leave(event) {
|
|
216
|
+
event.setAttribute("data-leaving", "");
|
|
217
|
+
const animation = innerOf(event).animate(LEAVE, { duration: LEAVE_MS, easing: LEAVE_EASE, fill: "forwards" });
|
|
218
|
+
animation.finished.then(() => event.remove(), () => event.remove());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Each hour label in view is captured on its own, so it stays put while the
|
|
222
|
+
// days slide. Labels scrolled away, or under the pinned headers, stay in the
|
|
223
|
+
// days' capture, where the clip hides them.
|
|
224
|
+
function nameHourLabels(week, named) {
|
|
225
|
+
const top = week.querySelector("calendar-headers")?.getBoundingClientRect().bottom ?? 0;
|
|
226
|
+
const bottom = week.getBoundingClientRect().bottom;
|
|
227
|
+
week.querySelectorAll(".hour-label").forEach((label, index) => {
|
|
228
|
+
const box = label.getBoundingClientRect();
|
|
229
|
+
label.style.viewTransitionName = named && box.top >= top && box.bottom <= bottom ? `calendar-hour-${index}` : "";
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// The slide under way, so that the end of one cut short by the next leaves
|
|
234
|
+
// the next one's names in place.
|
|
235
|
+
let sliding = null;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Slides the calendar to a new start date: forward slides left, back slides
|
|
239
|
+
* right. A move of up to the days shown slides by that many columns; a
|
|
240
|
+
* longer one brings the new days in right beside the old. When the month
|
|
241
|
+
* title changes, the old title fades out and then the new one fades in.
|
|
242
|
+
* `update` changes the calendar. Returns false, having done nothing, when
|
|
243
|
+
* the browser cannot play the slide or motion is reduced, so the caller
|
|
244
|
+
* updates directly.
|
|
245
|
+
*/
|
|
246
|
+
export function slide(week, { shiftDays, dayCount, titleChanges }, update) {
|
|
247
|
+
if (!document.startViewTransition || !motionAllowed() || shiftDays === 0) return false;
|
|
248
|
+
const root = document.documentElement;
|
|
249
|
+
const column = week.querySelector("calendar-column")?.offsetWidth ?? 0;
|
|
250
|
+
const gutter = parseFloat(getComputedStyle(week).getPropertyValue("--calendar-gutter")) || 0;
|
|
251
|
+
const distance = Math.sign(shiftDays) * Math.min(Math.abs(shiftDays), dayCount) * column;
|
|
252
|
+
root.style.setProperty("--calendar-move-gutter", `${gutter}px`);
|
|
253
|
+
root.dataset.calendarMove = titleChanges ? "month" : "";
|
|
254
|
+
nameHourLabels(week, true);
|
|
255
|
+
const transition = document.startViewTransition(() => {
|
|
256
|
+
update();
|
|
257
|
+
nameHourLabels(week, true);
|
|
258
|
+
});
|
|
259
|
+
transition.ready.then(() => {
|
|
260
|
+
const options = { duration: SLIDE_MS, easing: SLIDE_EASE };
|
|
261
|
+
root.animate({ transform: ["translateX(0)", `translateX(${-distance}px)`] }, { ...options, pseudoElement: "::view-transition-old(calendar-days)" });
|
|
262
|
+
root.animate({ transform: [`translateX(${distance}px)`, "translateX(0)"] }, { ...options, pseudoElement: "::view-transition-new(calendar-days)" });
|
|
263
|
+
}, () => {});
|
|
264
|
+
sliding = transition;
|
|
265
|
+
transition.finished.finally(() => {
|
|
266
|
+
if (sliding !== transition) return;
|
|
267
|
+
sliding = null;
|
|
268
|
+
delete root.dataset.calendarMove;
|
|
269
|
+
root.style.removeProperty("--calendar-move-gutter");
|
|
270
|
+
nameHourLabels(week, false);
|
|
271
|
+
});
|
|
272
|
+
return transition;
|
|
273
|
+
}
|