@telepath-computer/television 1.5.10 → 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-CekDfJPz.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,403 @@
|
|
|
1
|
+
// The artifact store is the source of truth. Its keyed events are diffed into
|
|
2
|
+
// the copied calendar component, so a write changes only the affected block.
|
|
3
|
+
//
|
|
4
|
+
// The page shows one of two things in its main element: the calendar (the
|
|
5
|
+
// month title and the calendar-week element), or the error page for data it
|
|
6
|
+
// cannot read. Until the data first arrives, it shows the calendar of a new,
|
|
7
|
+
// empty store. It never writes to the store.
|
|
8
|
+
import "./calendar-event.js";
|
|
9
|
+
import "./calendar-week.js";
|
|
10
|
+
import { motionAllowed, slide } from "./calendar-motion.js";
|
|
11
|
+
import { getStore, onConnectionStatusChanged, onValue, ref } from "/sdk/v1/resources.js";
|
|
12
|
+
|
|
13
|
+
const main = document.querySelector("main");
|
|
14
|
+
const masthead = document.querySelector(".masthead");
|
|
15
|
+
const calendar = document.querySelector("calendar-week");
|
|
16
|
+
const rangeLabel = document.getElementById("range-label");
|
|
17
|
+
// The error page, ready to replace the calendar.
|
|
18
|
+
const unreadable = document.importNode(document.getElementById("unreadable").content.firstElementChild, true);
|
|
19
|
+
const rendered = new Map();
|
|
20
|
+
const colors = new Set(["red", "orange", "yellow", "green", "blue", "purple"]);
|
|
21
|
+
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
22
|
+
const MAX_DAYS = 7;
|
|
23
|
+
// The parts the title shows, so an unchanged title is not rewritten.
|
|
24
|
+
let rangeLabelKey = null;
|
|
25
|
+
// Whether the calendar shows the store's data, rather than the empty week
|
|
26
|
+
// shown before the data arrives or the error page.
|
|
27
|
+
let showsData = false;
|
|
28
|
+
|
|
29
|
+
function localIso(date) {
|
|
30
|
+
const year = date.getFullYear();
|
|
31
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
32
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
33
|
+
return `${year}-${month}-${day}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function startingDate(value, days) {
|
|
37
|
+
if (typeof value === "string" && isDate(value)) return value;
|
|
38
|
+
const today = new Date();
|
|
39
|
+
if (days === 7) today.setDate(today.getDate() - (today.getDay() + 6) % 7);
|
|
40
|
+
return localIso(today);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isObject(value) {
|
|
44
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isDate(value) {
|
|
48
|
+
const match = DATE_RE.exec(value);
|
|
49
|
+
if (!match) return false;
|
|
50
|
+
const [, year, month, day] = match.map(Number);
|
|
51
|
+
const probe = new Date(Date.UTC(year, month - 1, day));
|
|
52
|
+
return probe.getUTCFullYear() === year && probe.getUTCMonth() === month - 1 && probe.getUTCDate() === day;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether the store value as a whole follows the store contract: an object
|
|
57
|
+
* whose `events` is an object. A value that does not is shown as the error
|
|
58
|
+
* page. A `startDate`, `days` or `visibleHours` the page cannot read is
|
|
59
|
+
* treated as absent, and an unreadable event is left out.
|
|
60
|
+
*/
|
|
61
|
+
function isReadable(value) {
|
|
62
|
+
return isObject(value) && isObject(value.events);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isDayCount(value) {
|
|
66
|
+
return Number.isInteger(value) && value >= 1 && value <= MAX_DAYS;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function validEvent(value) {
|
|
70
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
71
|
+
if (typeof value.title !== "string" || typeof value.start !== "string" || typeof value.end !== "string") return false;
|
|
72
|
+
if (value.detail !== undefined && typeof value.detail !== "string") return false;
|
|
73
|
+
if (value.allDay !== undefined && typeof value.allDay !== "boolean") return false;
|
|
74
|
+
if (value.color !== undefined && !colors.has(value.color)) return false;
|
|
75
|
+
if (value.attendees !== undefined && (!Array.isArray(value.attendees) || !value.attendees.every((name) => typeof name === "string"))) return false;
|
|
76
|
+
if (value.highlight !== undefined && typeof value.highlight !== "boolean") return false;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function setAttributeIfChanged(element, name, value) {
|
|
81
|
+
if (value === null) {
|
|
82
|
+
if (element.hasAttribute(name)) element.removeAttribute(name);
|
|
83
|
+
} else if (element.getAttribute(name) !== value) {
|
|
84
|
+
element.setAttribute(name, value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function patchEvent(element, value) {
|
|
89
|
+
setAttributeIfChanged(element, "title", value.title);
|
|
90
|
+
setAttributeIfChanged(element, "start", value.start);
|
|
91
|
+
setAttributeIfChanged(element, "end", value.end);
|
|
92
|
+
setAttributeIfChanged(element, "detail", value.detail ?? null);
|
|
93
|
+
element.attendees = value.attendees ?? null;
|
|
94
|
+
setAttributeIfChanged(element, "color", value.color ?? "blue");
|
|
95
|
+
setAttributeIfChanged(element, "all-day", value.allDay ? "" : null);
|
|
96
|
+
setAttributeIfChanged(element, "highlight", value.highlight ? "" : null);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The title names the month and year shown, as a calendar app's toolbar does:
|
|
100
|
+
// "October 2026", or "Oct – Nov 2026" when the days cross a month. The year
|
|
101
|
+
// parts are set lighter than the month.
|
|
102
|
+
function describeRange(startDate, days) {
|
|
103
|
+
const start = new Date(`${startDate}T12:00:00`);
|
|
104
|
+
if (Number.isNaN(start.getTime())) return [];
|
|
105
|
+
const end = new Date(start);
|
|
106
|
+
end.setDate(end.getDate() + days - 1);
|
|
107
|
+
const sameMonth = start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
|
|
108
|
+
const format = new Intl.DateTimeFormat(undefined, { month: sameMonth ? "long" : "short", year: "numeric" });
|
|
109
|
+
return sameMonth ? format.formatToParts(start) : format.formatRangeToParts(start, end);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const rangeLabelKeyOf = (parts) => parts.map((part) => `${part.type}:${part.value}`).join("|");
|
|
113
|
+
|
|
114
|
+
function renderRangeLabel(parts) {
|
|
115
|
+
const key = rangeLabelKeyOf(parts);
|
|
116
|
+
if (rangeLabelKey === key) return;
|
|
117
|
+
rangeLabelKey = key;
|
|
118
|
+
// The parts between the years are one text node, as the text they make up
|
|
119
|
+
// lays out as one.
|
|
120
|
+
const children = [];
|
|
121
|
+
for (const part of parts) {
|
|
122
|
+
if (part.type === "year") {
|
|
123
|
+
const year = document.createElement("span");
|
|
124
|
+
year.className = "year";
|
|
125
|
+
year.textContent = part.value;
|
|
126
|
+
children.push(year);
|
|
127
|
+
} else if (typeof children.at(-1) === "string") {
|
|
128
|
+
children[children.length - 1] += part.value;
|
|
129
|
+
} else {
|
|
130
|
+
children.push(part.value);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
rangeLabel.replaceChildren(...children);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// While the calendar slides to a new start date, the newest value waits here
|
|
137
|
+
// and is drawn when the slide swaps the days.
|
|
138
|
+
let sliding = null;
|
|
139
|
+
let latest = null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Shows the calendar for a store value that follows the store contract. The
|
|
143
|
+
* first data replaces the empty week at once, and its events then arrive. A
|
|
144
|
+
* new start date, with the same number of days, slides there once the
|
|
145
|
+
* calendar is showing data.
|
|
146
|
+
*/
|
|
147
|
+
function render(store) {
|
|
148
|
+
latest = store;
|
|
149
|
+
if (sliding) return;
|
|
150
|
+
const days = isDayCount(store.days) ? store.days : MAX_DAYS;
|
|
151
|
+
const startDate = startingDate(store.startDate, days);
|
|
152
|
+
const previousStart = calendar.getAttribute("start-date");
|
|
153
|
+
if (!showsData) {
|
|
154
|
+
const motion = calendar.motion;
|
|
155
|
+
calendar.motion = false;
|
|
156
|
+
showRange(days, startDate);
|
|
157
|
+
calendar.updateNow();
|
|
158
|
+
calendar.motion = motion;
|
|
159
|
+
} else if (calendar.hasAttribute("data-ready") && previousStart !== null && previousStart !== startDate && calendar.getAttribute("days") === String(days)) {
|
|
160
|
+
const shift = Math.round((new Date(`${startDate}T12:00:00`) - new Date(`${previousStart}T12:00:00`)) / 86_400_000);
|
|
161
|
+
const titleChanges = rangeLabelKeyOf(describeRange(startDate, days)) !== rangeLabelKey;
|
|
162
|
+
sliding = slide(calendar, { shiftDays: shift, dayCount: days, titleChanges }, () => {
|
|
163
|
+
calendar.sliding = true;
|
|
164
|
+
apply(latest);
|
|
165
|
+
calendar.updateNow();
|
|
166
|
+
calendar.sliding = false;
|
|
167
|
+
});
|
|
168
|
+
if (sliding) {
|
|
169
|
+
sliding.updateCallbackDone.finally(() => { sliding = null; });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
apply(store);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function apply(store) {
|
|
177
|
+
const days = isDayCount(store.days) ? store.days : MAX_DAYS;
|
|
178
|
+
const startDate = startingDate(store.startDate, days);
|
|
179
|
+
const valid = Object.entries(store.events).filter(([, event]) => validEvent(event));
|
|
180
|
+
const nextKeys = new Set(valid.map(([key]) => key));
|
|
181
|
+
let changed = false;
|
|
182
|
+
|
|
183
|
+
// Remove stale keys before adding new ones. The component retains every
|
|
184
|
+
// remaining event node and never scrolls again after its first layout.
|
|
185
|
+
for (const [key, previous] of rendered) {
|
|
186
|
+
if (nextKeys.has(key)) continue;
|
|
187
|
+
calendar.removeEvent(previous.element);
|
|
188
|
+
rendered.delete(key);
|
|
189
|
+
changed = true;
|
|
190
|
+
}
|
|
191
|
+
for (const [key, event] of valid) {
|
|
192
|
+
const serialized = JSON.stringify(event);
|
|
193
|
+
const previous = rendered.get(key);
|
|
194
|
+
if (previous?.serialized === serialized) continue;
|
|
195
|
+
const element = previous?.element ?? document.createElement("calendar-event");
|
|
196
|
+
if (!previous) {
|
|
197
|
+
element.dataset.key = key;
|
|
198
|
+
calendar.append(element);
|
|
199
|
+
}
|
|
200
|
+
patchEvent(element, event);
|
|
201
|
+
rendered.set(key, { element, serialized });
|
|
202
|
+
changed = true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const rangeChanged = showRange(days, startDate);
|
|
206
|
+
if (changed && !rangeChanged) calendar.refreshEvents();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Shows a range of days and its title; returns whether the range changed. */
|
|
210
|
+
function showRange(days, startDate) {
|
|
211
|
+
const rangeChanged = calendar.getAttribute("days") !== String(days) || calendar.getAttribute("start-date") !== startDate;
|
|
212
|
+
setAttributeIfChanged(calendar, "days", String(days));
|
|
213
|
+
setAttributeIfChanged(calendar, "start-date", startDate);
|
|
214
|
+
renderRangeLabel(describeRange(startDate, days));
|
|
215
|
+
return rangeChanged;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Puts the calendar, or the error page, in the main element. */
|
|
219
|
+
function showCalendar(visible) {
|
|
220
|
+
if (visible ? main.contains(calendar) : main.contains(unreadable)) return;
|
|
221
|
+
main.replaceChildren(...(visible ? [masthead, calendar] : [unreadable]));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function showValue(value) {
|
|
225
|
+
if (!isReadable(value)) {
|
|
226
|
+
showError();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
showCalendar(true);
|
|
230
|
+
render(value);
|
|
231
|
+
showHours(hoursOf(value), showsData && calendar.hasAttribute("data-ready"));
|
|
232
|
+
if (showsData) return;
|
|
233
|
+
// The first data, or data after the error page: the hours scroll to an
|
|
234
|
+
// hour before the earliest event, as on first load. Highlight motion starts
|
|
235
|
+
// only after this first frame, so an event that arrives raised appears
|
|
236
|
+
// raised.
|
|
237
|
+
showsData = true;
|
|
238
|
+
calendar.scrollToStartHour();
|
|
239
|
+
requestAnimationFrame(() => { calendar.dataset.ready = ""; });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ------------------------------------------------------------------
|
|
243
|
+
// Hours in view
|
|
244
|
+
// ------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
// `visibleHours` chooses the hours that fill the view: the hours grow or
|
|
247
|
+
// shrink so that range fits the height below the pinned rows, and the view
|
|
248
|
+
// scrolls to its start. Every hour stays, so the rest of the day scrolls into
|
|
249
|
+
// view. Without it, hours keep their usual height.
|
|
250
|
+
const HOURS = 24;
|
|
251
|
+
// Room above the first hour and below the last, so their labels show whole.
|
|
252
|
+
const LABEL_ROOM_PX = 12;
|
|
253
|
+
const MIN_HOUR_PX = 16;
|
|
254
|
+
const ZOOM_MS = 520;
|
|
255
|
+
// The hours in view now, or null for the usual hour height.
|
|
256
|
+
let hoursInView = null;
|
|
257
|
+
let zoomFrame = 0;
|
|
258
|
+
|
|
259
|
+
/** The hours a store value asks for, or null when `visibleHours` is absent or breaks the store contract. */
|
|
260
|
+
function hoursOf(store) {
|
|
261
|
+
if (!isObject(store.visibleHours)) return null;
|
|
262
|
+
const { start, end } = store.visibleHours;
|
|
263
|
+
return Number.isInteger(start) && Number.isInteger(end) && start >= 0 && end <= HOURS && start < end ? { start, end } : null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const hourHeight = () => (calendar.querySelector("calendar-grid")?.offsetHeight ?? 0) / HOURS;
|
|
267
|
+
const pinnedHeight = () => (calendar.querySelector("calendar-headers")?.offsetHeight ?? 0) + (calendar.querySelector("calendar-allday")?.offsetHeight ?? 0);
|
|
268
|
+
|
|
269
|
+
/** The hour height and scroll that show the given hours, or the usual hour height with the top hour kept. */
|
|
270
|
+
function hoursTarget(hours) {
|
|
271
|
+
if (hours) {
|
|
272
|
+
const height = Math.max(MIN_HOUR_PX, (calendar.clientHeight - pinnedHeight() - 2 * LABEL_ROOM_PX) / (hours.end - hours.start));
|
|
273
|
+
return { height, scroll: hours.start * height - LABEL_ROOM_PX };
|
|
274
|
+
}
|
|
275
|
+
const current = hourHeight();
|
|
276
|
+
const topHour = (calendar.scrollTop + LABEL_ROOM_PX) / current;
|
|
277
|
+
const inline = calendar.style.getPropertyValue("--hour-min-height");
|
|
278
|
+
calendar.style.removeProperty("--hour-min-height");
|
|
279
|
+
const height = hourHeight();
|
|
280
|
+
if (inline) calendar.style.setProperty("--hour-min-height", inline);
|
|
281
|
+
return { height, scroll: topHour * height - LABEL_ROOM_PX, usual: true };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function setHours(height, scroll) {
|
|
285
|
+
calendar.style.setProperty("--hour-min-height", `${height}px`);
|
|
286
|
+
calendar.scrollTop = scroll;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The curve the glides use, cubic-bezier(0.32, 0.72, 0, 1), as a function of progress. */
|
|
290
|
+
function ease(progress) {
|
|
291
|
+
const [x1, y1, x2, y2] = [0.32, 0.72, 0, 1];
|
|
292
|
+
const curve = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t * t * (1 - t) + t ** 3;
|
|
293
|
+
let low = 0;
|
|
294
|
+
let high = 1;
|
|
295
|
+
for (let step = 0; step < 24; step += 1) {
|
|
296
|
+
const middle = (low + high) / 2;
|
|
297
|
+
if (curve(x1, x2, middle) < progress) low = middle;
|
|
298
|
+
else high = middle;
|
|
299
|
+
}
|
|
300
|
+
return curve(y1, y2, (low + high) / 2);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Shows the hours a store value asks for, moving there when `animate`. */
|
|
304
|
+
function showHours(hours, animate) {
|
|
305
|
+
if (hours?.start === hoursInView?.start && hours?.end === hoursInView?.end) return;
|
|
306
|
+
hoursInView = hours;
|
|
307
|
+
// The calendar's own first scroll lands on the start hour too.
|
|
308
|
+
if (hours) calendar.setAttribute("start-hour", String(hours.start));
|
|
309
|
+
else calendar.removeAttribute("start-hour");
|
|
310
|
+
// A change part-way through moves on from the hours as they are drawn.
|
|
311
|
+
cancelAnimationFrame(zoomFrame);
|
|
312
|
+
zoomFrame = requestAnimationFrame(() => {
|
|
313
|
+
const target = hoursTarget(hours);
|
|
314
|
+
const finish = () => {
|
|
315
|
+
if (!target.usual) {
|
|
316
|
+
setHours(target.height, target.scroll);
|
|
317
|
+
// On opening, the first scroll lands on the start hour once the
|
|
318
|
+
// hours have their height.
|
|
319
|
+
if (!animate) calendar.scrollToStartHour();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
calendar.style.removeProperty("--hour-min-height");
|
|
323
|
+
calendar.scrollTop = target.scroll;
|
|
324
|
+
};
|
|
325
|
+
if (!animate || !motionAllowed()) {
|
|
326
|
+
finish();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const from = { height: hourHeight(), scroll: calendar.scrollTop };
|
|
330
|
+
const began = performance.now();
|
|
331
|
+
const frame = (now) => {
|
|
332
|
+
const progress = Math.min(1, Math.max(0, now - began) / ZOOM_MS);
|
|
333
|
+
const eased = ease(progress);
|
|
334
|
+
setHours(from.height + (target.height - from.height) * eased, from.scroll + (target.scroll - from.scroll) * eased);
|
|
335
|
+
if (progress < 1) zoomFrame = requestAnimationFrame(frame);
|
|
336
|
+
else finish();
|
|
337
|
+
};
|
|
338
|
+
zoomFrame = requestAnimationFrame(frame);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// A new size keeps the chosen hours filling the view.
|
|
343
|
+
new ResizeObserver(() => {
|
|
344
|
+
if (hoursInView === null) return;
|
|
345
|
+
const target = hoursTarget(hoursInView);
|
|
346
|
+
setHours(target.height, target.scroll);
|
|
347
|
+
}).observe(calendar);
|
|
348
|
+
|
|
349
|
+
// When the all-day band comes, goes or changes height, the chosen hours move
|
|
350
|
+
// to fill the new height below it.
|
|
351
|
+
let fittedPinned = null;
|
|
352
|
+
let observedBand = null;
|
|
353
|
+
|
|
354
|
+
function refitHours() {
|
|
355
|
+
const pinned = pinnedHeight();
|
|
356
|
+
if (pinned === fittedPinned) return;
|
|
357
|
+
fittedPinned = pinned;
|
|
358
|
+
if (hoursInView === null) return;
|
|
359
|
+
const hours = hoursInView;
|
|
360
|
+
hoursInView = null;
|
|
361
|
+
showHours(hours, calendar.hasAttribute("data-ready"));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const bandObserver = new ResizeObserver(refitHours);
|
|
365
|
+
new MutationObserver(() => {
|
|
366
|
+
const band = calendar.querySelector(":scope > calendar-allday");
|
|
367
|
+
if (band !== observedBand) {
|
|
368
|
+
if (observedBand) bandObserver.unobserve(observedBand);
|
|
369
|
+
if (band) bandObserver.observe(band);
|
|
370
|
+
observedBand = band;
|
|
371
|
+
}
|
|
372
|
+
refitHours();
|
|
373
|
+
}).observe(calendar, { childList: true });
|
|
374
|
+
|
|
375
|
+
function showError() {
|
|
376
|
+
showsData = false;
|
|
377
|
+
showCalendar(false);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Until the data arrives, the calendar of a new, empty store. Changes after
|
|
381
|
+
// it move into place, including the events of the first data.
|
|
382
|
+
render({ events: {} });
|
|
383
|
+
calendar.motion = true;
|
|
384
|
+
|
|
385
|
+
// The SDK resubscribes a listener when the page reconnects, so the page
|
|
386
|
+
// catches up by itself. A listener that receives an error is removed; the
|
|
387
|
+
// page listens again the next time the connection opens, as after the server
|
|
388
|
+
// restarts. An error that the page has no access to the store (`no-store`,
|
|
389
|
+
// as after the share link it was opened through is revoked) leaves what it
|
|
390
|
+
// last showed; any other, such as stored data the server reports
|
|
391
|
+
// unavailable, shows the error page.
|
|
392
|
+
let listening = false;
|
|
393
|
+
function listen() {
|
|
394
|
+
listening = true;
|
|
395
|
+
onValue(ref(getStore()), (snapshot) => showValue(snapshot.val()), (error) => {
|
|
396
|
+
listening = false;
|
|
397
|
+
if (error.code !== "no-store") showError();
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
listen();
|
|
401
|
+
onConnectionStatusChanged((status) => {
|
|
402
|
+
if (status === "connected" && !listening) listen();
|
|
403
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Ported from Television tv-calendar calendar-time-axis.ts for an unbundled template.
|
|
2
|
+
const HOURS_PER_HALF_DAY = 12;
|
|
3
|
+
/** Renders the 24 hour labels inside the calendar grid. */
|
|
4
|
+
class CalendarTimeAxisElement extends HTMLElement {
|
|
5
|
+
connectedCallback() {
|
|
6
|
+
this.dispatchEvent(new Event("reactive:connect"));
|
|
7
|
+
this.#render();
|
|
8
|
+
}
|
|
9
|
+
disconnectedCallback() {
|
|
10
|
+
this.dispatchEvent(new Event("reactive:disconnect"));
|
|
11
|
+
}
|
|
12
|
+
#render() {
|
|
13
|
+
const labels = Array.from({ length: 24 }, (_, hour) => {
|
|
14
|
+
const label = document.createElement("div");
|
|
15
|
+
label.classList.add("hour-label");
|
|
16
|
+
label.style.setProperty("--hour-index", String(hour));
|
|
17
|
+
label.setAttribute("data-hour", String(hour));
|
|
18
|
+
label.textContent = formatHour(hour);
|
|
19
|
+
return label;
|
|
20
|
+
});
|
|
21
|
+
this.replaceChildren(...labels);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
customElements.define("calendar-time-axis", CalendarTimeAxisElement);
|
|
25
|
+
function formatHour(hour) {
|
|
26
|
+
const period = hour < HOURS_PER_HALF_DAY ? "AM" : "PM";
|
|
27
|
+
const display = hour % HOURS_PER_HALF_DAY === 0 ? HOURS_PER_HALF_DAY : hour % HOURS_PER_HALF_DAY;
|
|
28
|
+
return `${display} ${period}`;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
CalendarTimeAxisElement
|
|
32
|
+
};
|