@blueshed/joined 0.0.0-stage → 0.1.20

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.
Files changed (213) hide show
  1. package/.claude/skills/joined/SKILL.md +17 -0
  2. package/.claude/skills/joined/reference.md +768 -0
  3. package/LICENSE +19 -0
  4. package/README.md +115 -2
  5. package/docs/design.md +148 -0
  6. package/docs/introduction.md +193 -0
  7. package/docs/learning.md +76 -0
  8. package/docs/stories.md +82 -0
  9. package/examples/app.css +27 -0
  10. package/examples/cafe/books.html +38 -0
  11. package/examples/cafe/books.json +13 -0
  12. package/examples/cafe/books.ts +64 -0
  13. package/examples/cafe/cafe.css +512 -0
  14. package/examples/cafe/front.html +115 -0
  15. package/examples/cafe/front.ts +7 -0
  16. package/examples/cafe/generated/books.elements.ts +52 -0
  17. package/examples/cafe/generated/books.queries.ts +11 -0
  18. package/examples/cafe/generated/books.rules.ts +42 -0
  19. package/examples/cafe/generated/kitchen.elements.ts +87 -0
  20. package/examples/cafe/generated/kitchen.queries.ts +47 -0
  21. package/examples/cafe/generated/kitchen.rules.ts +98 -0
  22. package/examples/cafe/generated/menu.elements.ts +61 -0
  23. package/examples/cafe/generated/menu.queries.ts +28 -0
  24. package/examples/cafe/generated/menu.rules.ts +65 -0
  25. package/examples/cafe/generated/order.elements.ts +87 -0
  26. package/examples/cafe/generated/order.queries.ts +47 -0
  27. package/examples/cafe/generated/order.rules.ts +95 -0
  28. package/examples/cafe/generated/staff.elements.ts +55 -0
  29. package/examples/cafe/generated/staff.queries.ts +27 -0
  30. package/examples/cafe/generated/staff.rules.ts +59 -0
  31. package/examples/cafe/generated/supplies.elements.ts +62 -0
  32. package/examples/cafe/generated/supplies.queries.ts +43 -0
  33. package/examples/cafe/generated/supplies.rules.ts +84 -0
  34. package/examples/cafe/generated/till.elements.ts +93 -0
  35. package/examples/cafe/generated/till.queries.ts +57 -0
  36. package/examples/cafe/generated/till.rules.ts +113 -0
  37. package/examples/cafe/index.html +70 -0
  38. package/examples/cafe/kitchen.css +107 -0
  39. package/examples/cafe/kitchen.html +39 -0
  40. package/examples/cafe/kitchen.ts +125 -0
  41. package/examples/cafe/menu.html +55 -0
  42. package/examples/cafe/menu.json +41 -0
  43. package/examples/cafe/menu.ts +84 -0
  44. package/examples/cafe/migrations/001-cafe.ts +11 -0
  45. package/examples/cafe/order.html +37 -0
  46. package/examples/cafe/order.ts +45 -0
  47. package/examples/cafe/rail-drag.ts +30 -0
  48. package/examples/cafe/routes.ts +32 -0
  49. package/examples/cafe/staff.json +20 -0
  50. package/examples/cafe/stories.jsonl +43 -0
  51. package/examples/cafe/supplies.html +77 -0
  52. package/examples/cafe/supplies.json +33 -0
  53. package/examples/cafe/supplies.ts +170 -0
  54. package/examples/cafe/till.json +95 -0
  55. package/examples/cafe/till.ts +122 -0
  56. package/examples/cafe/trust.ts +20 -0
  57. package/examples/cafe/views.ts +171 -0
  58. package/examples/docs.ts +28 -0
  59. package/examples/film.jpg +0 -0
  60. package/examples/hello/generated/elements.ts +45 -0
  61. package/examples/hello/generated/queries.ts +24 -0
  62. package/examples/hello/generated/rules.ts +45 -0
  63. package/examples/hello/hello.css +27 -0
  64. package/examples/hello/hello.json +1 -0
  65. package/examples/hello/index.html +32 -0
  66. package/examples/hello/migrations/001-hello.ts +6 -0
  67. package/examples/hello/page.ts +49 -0
  68. package/examples/hello/routes.ts +6 -0
  69. package/examples/hello/stories.jsonl +3 -0
  70. package/examples/index.html +146 -0
  71. package/examples/page.ts +11 -0
  72. package/examples/people/adding.ts +20 -0
  73. package/examples/people/generated/elements.ts +68 -0
  74. package/examples/people/generated/queries.ts +28 -0
  75. package/examples/people/generated/rules.ts +85 -0
  76. package/examples/people/links.ts +124 -0
  77. package/examples/people/migrations/001-people.ts +6 -0
  78. package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
  79. package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
  80. package/examples/people/order.ts +61 -0
  81. package/examples/people/people.css +65 -0
  82. package/examples/people/people.json +26 -0
  83. package/examples/people/routes.ts +12 -0
  84. package/examples/people/stories.jsonl +20 -0
  85. package/examples/people/trust.ts +14 -0
  86. package/examples/people/view.ts +115 -0
  87. package/examples/routes.ts +11 -0
  88. package/examples/trip/answer-rows.ts +70 -0
  89. package/examples/trip/answers.ts +11 -0
  90. package/examples/trip/bar.ts +89 -0
  91. package/examples/trip/calendar-map.css +709 -0
  92. package/examples/trip/calendar-map.ts +249 -0
  93. package/examples/trip/drags.ts +143 -0
  94. package/examples/trip/drawer.ts +250 -0
  95. package/examples/trip/event-form.ts +199 -0
  96. package/examples/trip/generated/elements.ts +144 -0
  97. package/examples/trip/generated/queries.ts +46 -0
  98. package/examples/trip/generated/rules.ts +239 -0
  99. package/examples/trip/holding.ts +61 -0
  100. package/examples/trip/ics.ts +117 -0
  101. package/examples/trip/index.html +82 -0
  102. package/examples/trip/line-stops.ts +92 -0
  103. package/examples/trip/line-words.ts +79 -0
  104. package/examples/trip/line.ts +121 -0
  105. package/examples/trip/map.ts +234 -0
  106. package/examples/trip/mercator.ts +28 -0
  107. package/examples/trip/migrations/001-trip.ts +7 -0
  108. package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
  109. package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
  110. package/examples/trip/migrations/004-create-stays.ts +6 -0
  111. package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
  112. package/examples/trip/month.ts +87 -0
  113. package/examples/trip/other-weeks.ts +67 -0
  114. package/examples/trip/page.ts +121 -0
  115. package/examples/trip/peek.ts +71 -0
  116. package/examples/trip/people-chips.ts +74 -0
  117. package/examples/trip/place-search.ts +51 -0
  118. package/examples/trip/places.ts +34 -0
  119. package/examples/trip/routes.ts +27 -0
  120. package/examples/trip/shell.ts +39 -0
  121. package/examples/trip/stays.css +51 -0
  122. package/examples/trip/stays.ts +68 -0
  123. package/examples/trip/stories.jsonl +72 -0
  124. package/examples/trip/time.ts +46 -0
  125. package/examples/trip/told.ts +48 -0
  126. package/examples/trip/trip.json +69 -0
  127. package/examples/trip/trust.ts +51 -0
  128. package/examples/trip/week.ts +237 -0
  129. package/examples/trip/words.ts +4 -0
  130. package/examples/trip/writes.ts +91 -0
  131. package/examples/trip/zones.ts +16 -0
  132. package/examples/trips/card.ts +149 -0
  133. package/examples/trips/generated/elements.ts +60 -0
  134. package/examples/trips/generated/queries.ts +28 -0
  135. package/examples/trips/generated/rules.ts +62 -0
  136. package/examples/trips/index.html +47 -0
  137. package/examples/trips/map.ts +52 -0
  138. package/examples/trips/migrations/001-trips.ts +8 -0
  139. package/examples/trips/new-trip.ts +46 -0
  140. package/examples/trips/page.ts +9 -0
  141. package/examples/trips/routes.ts +7 -0
  142. package/examples/trips/stories.jsonl +12 -0
  143. package/examples/trips/trips.css +183 -0
  144. package/examples/trips/trips.json +7 -0
  145. package/examples/weeks/derive.ts +23 -0
  146. package/examples/weeks/generated/elements.ts +52 -0
  147. package/examples/weeks/generated/rules.ts +33 -0
  148. package/examples/weeks/routes.ts +4 -0
  149. package/examples/weeks/weeks.json +1 -0
  150. package/examples/welcome.css +299 -0
  151. package/package.json +55 -4
  152. package/src/attachment.ts +70 -0
  153. package/src/cli.ts +52 -0
  154. package/src/client.ts +98 -0
  155. package/src/compile.ts +2034 -0
  156. package/src/css.d.ts +5 -0
  157. package/src/definitions.ts +268 -0
  158. package/src/demo.css +29 -0
  159. package/src/demo.ts +42 -0
  160. package/src/draft.ts +69 -0
  161. package/src/engine.ts +288 -0
  162. package/src/file-value.ts +13 -0
  163. package/src/files.ts +187 -0
  164. package/src/follow.ts +56 -0
  165. package/src/hues.ts +3 -0
  166. package/src/icon-names.ts +77 -0
  167. package/src/icon.png +0 -0
  168. package/src/icons.ts +32 -0
  169. package/src/keep.ts +33 -0
  170. package/src/link.ts +31 -0
  171. package/src/mcp.ts +252 -0
  172. package/src/members/demo.ts +53 -0
  173. package/src/members/generated/elements.ts +68 -0
  174. package/src/members/generated/queries.ts +29 -0
  175. package/src/members/generated/rules.ts +65 -0
  176. package/src/members/group.ts +294 -0
  177. package/src/members/keys.ts +221 -0
  178. package/src/members/members.json +9 -0
  179. package/src/members/migrations/001-members.ts +6 -0
  180. package/src/members/migrations/002-guard-members.ts +11 -0
  181. package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
  182. package/src/members/panel.css +208 -0
  183. package/src/members/panel.ts +398 -0
  184. package/src/members/routes.ts +4 -0
  185. package/src/members/stories.jsonl +27 -0
  186. package/src/members/trust.ts +116 -0
  187. package/src/migrate.ts +597 -0
  188. package/src/migrations/001-joined.ts +13 -0
  189. package/src/migrations/002-group-keys.ts +16 -0
  190. package/src/migrations/003-change-inverse.ts +10 -0
  191. package/src/migrations/004-change-followed.ts +6 -0
  192. package/src/ops.ts +61 -0
  193. package/src/page.css +79 -0
  194. package/src/page.ts +413 -0
  195. package/src/parts.css +471 -0
  196. package/src/parts.ts +152 -0
  197. package/src/server.ts +862 -0
  198. package/src/settings.ts +94 -0
  199. package/src/starter.ts +89 -0
  200. package/src/store.ts +815 -0
  201. package/src/stories.ts +387 -0
  202. package/src/toast.ts +52 -0
  203. package/src/together.ts +167 -0
  204. package/src/tokens.css +85 -0
  205. package/src/tokens.json +457 -0
  206. package/src/upkeep.ts +86 -0
  207. package/src/visitors.ts +43 -0
  208. package/src/write.ts +567 -0
  209. package/starter/CLAUDE.md +37 -0
  210. package/starter/gitignore +3 -0
  211. package/starter/tests/hello-page.test.ts +14 -0
  212. package/starter/tests/hello.test.ts +8 -0
  213. package/starter/tsconfig.json +17 -0
@@ -0,0 +1,61 @@
1
+ // What <calendar-map> holds: its <j-events>, a window of the trip's events (a week, or read as a month, the six weeks
2
+ // of its grid), named by its doc (trip:1?week=2026-11-02). Its events are read at most once a change, and only if
3
+ // asked. Another week is the page's to hold, in place of this one: asked for by a "week" event, its Monday (or a
4
+ // "month" event, the Monday its grid starts on).
5
+
6
+ import type { JEvent, JEvents } from "./generated/elements.ts";
7
+ import { collections as trip } from "./generated/rules.ts";
8
+ import { DAY, dayOf, gridOf, local } from "./time.ts";
9
+
10
+ /** What it reads from its display: the week shown, and whether it's read as a month. */
11
+ type From = { at: () => { week: number }; monthly: () => boolean };
12
+
13
+ export class Holding {
14
+ #host: HTMLElement;
15
+ #from: From;
16
+ #changing = false;
17
+ #now: JEvent[] | null = null;
18
+
19
+ /** What `host` holds. */
20
+ constructor(host: HTMLElement, from: From) {
21
+ [this.#host, this.#from] = [host, from];
22
+ }
23
+
24
+ /** Its <j-events>, and the <j-event>s in it. */
25
+ list = () => this.#host.querySelector<JEvents>(`:scope > ${trip.events.place}`);
26
+ /** Its events: while a change is drawn, read once, and only if it's asked (`items` copies them each time, and a
27
+ * title changed asks for none); else afresh. */
28
+ events = () => (this.#changing ? (this.#now ??= this.list()?.items ?? []) : (this.list()?.items ?? []));
29
+ /** A change drawn, its events read once. */
30
+ changing(draw: () => void) {
31
+ this.#changing = true;
32
+ try {
33
+ draw();
34
+ } finally {
35
+ [this.#changing, this.#now] = [false, null];
36
+ }
37
+ }
38
+ /** The trip's key, and the week's Monday (a day), or none until the page holds one. */
39
+ held = () => {
40
+ const [base = "", query] = (this.list()?.getAttribute("doc") ?? "").split("?");
41
+ const q = new URLSearchParams(query),
42
+ week = q.get("week") ?? q.get("month");
43
+ return { trip: Number(base.split(":")[1]), week: week ? dayOf(week) : null };
44
+ };
45
+ /** Another week asked of the page, by its Monday: the page holds it in place of this one (the one shown, or, read as
46
+ * a month, one of its: nothing). */
47
+ go = (week: number) => {
48
+ const monthly = this.#from.monthly();
49
+ if (monthly ? !this.holds(week) : week !== this.#from.at().week)
50
+ this.hold(monthly ? "month" : "week", monthly ? gridOf(week + 3) : week);
51
+ };
52
+ /** Whether a day is held: on the week shown, or the month's six weeks. */
53
+ holds = (day: number) => {
54
+ const { week } = this.#from.at();
55
+ return day >= week && day < week + (this.#from.monthly() ? 42 : 7);
56
+ };
57
+ /** A week, or a month by the Monday its grid starts on, asked of the page in place of what it holds. */
58
+ hold = (by: "week" | "month", day: number) => {
59
+ this.#host.dispatchEvent(new CustomEvent(by, { bubbles: true, detail: local(day * DAY).slice(0, 10) }));
60
+ };
61
+ }
@@ -0,0 +1,117 @@
1
+ import { answerOf, type Answer } from "./answers.ts";
2
+
3
+ // .ics (RFC 5545) at the edge: the trip's events go out as a calendar file, and a file coming in
4
+ // becomes events to add. A start is a wall clock, in its zone where it has one (DTSTART;TZID=Asia/Tokyo), so a
5
+ // calendar anywhere puts it at that hour there, or floating where it hasn't; its length a DURATION (or DTEND), its
6
+ // place a LOCATION and a GEO.
7
+
8
+ export type IcsEvent = {
9
+ title: string;
10
+ start: string;
11
+ duration: string;
12
+ location?: string;
13
+ coordinates?: string;
14
+ zone?: string;
15
+ people?: number[];
16
+ keen?: number[];
17
+ asked?: number[];
18
+ declined?: number[];
19
+ };
20
+ /** An answer as a calendar says it: keen and yes accepted, asked needing it, no declined. */
21
+ const PARTSTAT: Record<Answer, string> = {
22
+ yes: "ACCEPTED",
23
+ keen: "ACCEPTED",
24
+ asked: "NEEDS-ACTION",
25
+ declined: "DECLINED",
26
+ };
27
+
28
+ const esc = (s: string) =>
29
+ s
30
+ .replace(/\\/g, "\\\\")
31
+ .replace(/\n/g, "\\n")
32
+ .replace(/([,;])/g, "\\$1");
33
+ const unesc = (s: string) => s.replace(/\\(.)/g, (_, c: string) => (c.toLowerCase() === "n" ? "\n" : c));
34
+ const fold = (line: string) => line.match(/.{1,73}/g)!.join("\r\n ");
35
+ const stamp = (local: string) => local.replace(/[-:]/g, ""); // 2026-11-12T19:00:00 → 20261112T190000
36
+ const local = (v: string) => {
37
+ const [, y, mo, d, h = "00", mi = "00", s = "00"] = /^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2}))?/.exec(v) ?? [];
38
+ return y ? `${y}-${mo}-${d}T${h}:${mi}:${s}` : null;
39
+ };
40
+ const minutes = (from: string, to: string) => (Date.parse(`${to}Z`) - Date.parse(`${from}Z`)) / 60_000;
41
+
42
+ /** A start a calendar can read: a wall clock, to the second; and a length: days, or hours, minutes and seconds. */
43
+ const WHEN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/,
44
+ LENGTH = /^P(?=\d|T\d)(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$/,
45
+ ZONE = /^[A-Za-z][A-Za-z0-9_+/-]*$/; // a zone as the world names it, and nothing a line could break on
46
+
47
+ /** The events as a calendar file: one whose start or length a calendar couldn't read (one kept from
48
+ * before the database typed them) is left out, rather than the file being one no calendar opens. */
49
+ export function toIcs(events: (IcsEvent & { id: number })[], name: string, names = new Map<number, string>()): string {
50
+ const now = new Date().toISOString().replace(/[-:]/g, "").slice(0, 15) + "Z";
51
+ const lines = ["BEGIN:VCALENDAR", "VERSION:2.0", "PRODID:-//blueshed//joined//EN", `X-WR-CALNAME:${esc(name)}`];
52
+ for (const e of events.filter((e) => WHEN.test(e.start) && LENGTH.test(e.duration))) {
53
+ lines.push(
54
+ "BEGIN:VEVENT",
55
+ `UID:${e.id}@joined`,
56
+ `DTSTAMP:${now}`,
57
+ e.zone && ZONE.test(e.zone) ? `DTSTART;TZID=${e.zone}:${stamp(e.start)}` : `DTSTART:${stamp(e.start)}`,
58
+ `DURATION:${e.duration}`,
59
+ `SUMMARY:${esc(e.title)}`,
60
+ );
61
+ if (e.location) lines.push(`LOCATION:${esc(e.location)}`);
62
+ // its place's digits as they were given (35.6720), so a trip comes back as it went out: not mercator's geo,
63
+ // which reads them as numbers (35.672)
64
+ const geo = /^geo:(-?[\d.]+),(-?[\d.]+)/.exec(e.coordinates ?? "");
65
+ if (geo) lines.push(`GEO:${geo[1]};${geo[2]}`);
66
+ // who's on it, by name where it's known (quoted, so a comma or a colon in it is only a name)
67
+ for (const k of e.people ?? []) {
68
+ const cn = (names.get(k) ?? "").replace(/["\r\n]/g, "");
69
+ lines.push(`ATTENDEE;${cn ? `CN="${cn}";` : ""}PARTSTAT=${PARTSTAT[answerOf(e, k)]}:urn:joined:person:${k}`);
70
+ }
71
+ lines.push("END:VEVENT");
72
+ }
73
+ return [...lines, "END:VCALENDAR"].map(fold).join("\r\n") + "\r\n";
74
+ }
75
+
76
+ /** The time zones the world names (Asia/Tokyo), as this runtime knows them. */
77
+ const ZONES = new Set([...Intl.supportedValuesOf("timeZone"), "UTC"]);
78
+
79
+ export function fromIcs(text: string): IcsEvent[] {
80
+ const lines = text.replace(/\r?\n[ \t]/g, "").split(/\r?\n/);
81
+ const events: IcsEvent[] = [];
82
+ let at: Record<string, string> | null = null;
83
+ for (const line of lines) {
84
+ if (line === "BEGIN:VEVENT") at = {};
85
+ else if (line === "END:VEVENT" && at) {
86
+ const start = local(at.DTSTART ?? "");
87
+ if (start) {
88
+ const end = at.DTEND ? local(at.DTEND) : null;
89
+ const day = /^\d{8}$/.test(at.DTSTART!);
90
+ const duration = at.DURATION ?? (end ? `PT${minutes(start, end)}M` : day ? "P1D" : "PT0M");
91
+ const geo = at.GEO?.split(";");
92
+ // its zone: one the world names (an Outlook name, Tokyo Standard Time, is let go: floating), or UTC's Z, a
93
+ // time in UTC read as a wall clock in UTC
94
+ const zone = at.TZID && ZONES.has(at.TZID) ? at.TZID : /Z$/.test(at.DTSTART!) ? "UTC" : undefined;
95
+ events.push({
96
+ title: unesc(at.SUMMARY ?? "An event"),
97
+ start,
98
+ duration,
99
+ ...(at.LOCATION ? { location: unesc(at.LOCATION) } : {}),
100
+ ...(geo?.length === 2 ? { coordinates: `geo:${geo[0]},${geo[1]}` } : {}),
101
+ ...(zone ? { zone } : {}),
102
+ });
103
+ }
104
+ at = null;
105
+ } else if (at) {
106
+ const colon = line.indexOf(":");
107
+ if (colon > 0) {
108
+ const [name, ...params] = line.slice(0, colon).split(";");
109
+ at[name!.toUpperCase()] = line.slice(colon + 1);
110
+ // a start's zone, as its TZID names it
111
+ const tz = params.find((p) => /^TZID=/i.test(p));
112
+ if (name!.toUpperCase() === "DTSTART" && tz) at.TZID = tz.slice(5).replace(/^"|"$/g, "");
113
+ }
114
+ }
115
+ }
116
+ return events;
117
+ }
@@ -0,0 +1,82 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>joined: the trip</title>
7
+ <link rel="stylesheet" href="joined/tokens.css" />
8
+ <link rel="stylesheet" href="joined/page.css" />
9
+ <link rel="stylesheet" href="../app.css" />
10
+ <link rel="stylesheet" href="../people/people.css" />
11
+ <link rel="stylesheet" href="./stays.css" />
12
+ </head>
13
+ <body>
14
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
15
+ <h1 class="trip-name">The trip</h1>
16
+ <p class="lead">
17
+ Its week, as a calendar or a line, or its month, beside its map. Drag down a day to add an event, or tap the map;
18
+ drag one to another day, or its pin to another place. Open it on another device to see each change arrive.
19
+ <a href="/trips">← Your trips</a>
20
+ </p>
21
+ <p class="bar">
22
+ <members-panel></members-panel>
23
+ <button class="members-only act" popovertarget="people" data-icon="people">People</button>
24
+ <button class="members-only act" popovertarget="stays" data-icon="stay">Stays</button>
25
+ </p>
26
+ <main>
27
+ <j-trips hidden></j-trips>
28
+ <div id="people" class="sheet" popover>
29
+ <header>
30
+ <h2>People</h2>
31
+ <button
32
+ type="button"
33
+ class="icon-only"
34
+ popovertarget="people"
35
+ popovertargetaction="hide"
36
+ aria-label="Close"
37
+ title="Close"
38
+ data-icon="close"
39
+ ></button>
40
+ </header>
41
+ <j-people></j-people>
42
+ <footer>
43
+ <form class="add">
44
+ <input name="name" placeholder="A new person" required autocomplete="off" />
45
+ <button class="act ink" data-icon="person-add">Add</button>
46
+ <p class="said" role="status"></p>
47
+ </form>
48
+ </footer>
49
+ </div>
50
+ <div id="stays" class="sheet" popover>
51
+ <header>
52
+ <h2>Stays</h2>
53
+ <button
54
+ type="button"
55
+ class="icon-only"
56
+ popovertarget="stays"
57
+ popovertargetaction="hide"
58
+ aria-label="Close"
59
+ title="Close"
60
+ data-icon="close"
61
+ ></button>
62
+ </header>
63
+ <footer>
64
+ <form class="add book">
65
+ <input name="name" placeholder="Where we stay" required autocomplete="off" aria-label="Where we stay" />
66
+ <label>From<input name="day" type="date" required /></label>
67
+ <label>Nights<input name="nights" type="number" min="1" value="1" required /></label>
68
+ <button class="act ink" data-icon="add">Book</button>
69
+ <p class="said" role="status"></p>
70
+ </form>
71
+ </footer>
72
+ </div>
73
+ <calendar-map people="people" stays="stays"><j-weeks></j-weeks></calendar-map>
74
+ <p class="edge">
75
+ <a href="trip.ics" download="trip.ics" data-icon="download">Download .ics</a>
76
+ <label data-icon="upload">Add from .ics <input type="file" accept=".ics,text/calendar" /></label>
77
+ </p>
78
+ <p id="said" role="status"></p>
79
+ </main>
80
+ <script type="module" src="./page.ts"></script>
81
+ </body>
82
+ </html>
@@ -0,0 +1,92 @@
1
+ // The line's parts (./line.ts), each a list item drawn from what it says: a day's station, its date in the colour of
2
+ // the stay that night; an event's stop (or a while's, events at one time in lanes), its bead filled where the reader
3
+ // goes (pierced where they're keen, ringed where they're asked and haven't said), hollow where it happens without
4
+ // them, and a card beside it that picks its event; and a terminus, where the line begins and ends.
5
+
6
+ import type { JEvent, JStay } from "./generated/elements.ts";
7
+ import { hueOf } from "joined/hues";
8
+ import { face } from "joined/parts";
9
+ import { answerOf } from "./answers.ts";
10
+ import type { Said } from "./line-words.ts";
11
+ import { hhmm, hours, stayed, wall } from "./time.ts";
12
+
13
+ /** A day's station: its date, the colour of the stay that night, and where a stay begins its name and nights. */
14
+ export function station(words: string, stay: JStay | null, begins: JStay | null, change: boolean) {
15
+ const li = Object.assign(document.createElement("li"), { className: `date${change ? " interchange" : ""}` });
16
+ li.append(words);
17
+ if (stay) li.style.setProperty("--stay", hueOf(stay.key));
18
+ if (begins)
19
+ li.append(
20
+ Object.assign(document.createElement("span"), {
21
+ className: "stay",
22
+ textContent: `${begins.data.name} · ${stayed(begins.data)}`,
23
+ }),
24
+ );
25
+ return li;
26
+ }
27
+
28
+ /** An event's stop (or a while's: events at one time, in lanes): the reader's bead, and a card for each event, which
29
+ * `pick`s it. */
30
+ export function stop(
31
+ group: JEvent[],
32
+ said: Said[],
33
+ names: Map<number, string>,
34
+ stay: JStay | null,
35
+ pick: (el: JEvent) => void,
36
+ ) {
37
+ const mine = said.some((x) => x.mine);
38
+ const li = Object.assign(document.createElement("li"), {
39
+ className: `stop ${mine ? "mine" : "without"}${group.length > 1 ? " while" : ""}`,
40
+ });
41
+ li.style.setProperty("--hue", hueOf(group[0]!.key));
42
+ if (stay) li.style.setProperty("--stay", hueOf(stay.key));
43
+ // the reader's bead: filled where they go (keen, pierced; asked, ringed), hollow without them; where they
44
+ // land, an interchange, and where they go home, a terminus
45
+ const theirs = said.find((x) => x.mine) ?? said[0]!;
46
+ const bead = Object.assign(document.createElement("span"), { className: `bead ${mine ? "filled" : "hollow"}` });
47
+ if (mine && (theirs.answer === "keen" || theirs.answer === "asked")) bead.classList.add(theirs.answer);
48
+ if (said.some((x) => x.lands)) bead.classList.add("lands");
49
+ if (said.some((x) => x.home)) bead.classList.add("home");
50
+ li.append(bead);
51
+ const cards = group.map((el, i) => card(el, said[i]!, names, pick));
52
+ if (group.length === 1) li.append(cards[0]!);
53
+ else {
54
+ const lanes = Object.assign(document.createElement("div"), { className: "lanes" });
55
+ lanes.append(...cards);
56
+ li.append(lanes);
57
+ }
58
+ return li;
59
+ }
60
+
61
+ /** An event's card: a button that picks it, its title, when, where and who, who comes and goes, and its faces. */
62
+ function card(el: JEvent, said: Said, names: Map<number, string>, pick: (el: JEvent) => void) {
63
+ const { title, start, duration, location, party, picked, gates } = said;
64
+ const card = Object.assign(document.createElement("button"), { type: "button", className: "card" });
65
+ card.style.setProperty("--hue", hueOf(el.key));
66
+ card.toggleAttribute("picked", picked);
67
+ card.ariaLabel = [title, hhmm(wall(start)), location, party, gates].filter(Boolean).join(", ");
68
+ card.append(
69
+ Object.assign(document.createElement("b"), { textContent: title }),
70
+ Object.assign(document.createElement("span"), {
71
+ textContent: [hours(start, duration), location, party].filter(Boolean).join(" · "),
72
+ }),
73
+ );
74
+ if (gates) card.append(Object.assign(document.createElement("span"), { className: "gates", textContent: gates }));
75
+ const faces = Object.assign(document.createElement("span"), { className: "who" });
76
+ // each face as they've answered: keen, asked (and not yet said), or no
77
+ for (const k of el.data.people) {
78
+ const f = face(k, names.get(k) ?? "");
79
+ f.dataset.answer = answerOf(el.data, k);
80
+ faces.append(f);
81
+ }
82
+ card.append(faces);
83
+ card.addEventListener("click", () => pick(el));
84
+ return card;
85
+ }
86
+
87
+ /** A terminus: where the line begins, and where it ends. */
88
+ export function end(which: "begins" | "ends") {
89
+ const li = Object.assign(document.createElement("li"), { className: `end ${which}` });
90
+ li.append(Object.assign(document.createElement("span"), { className: "bead terminus" }));
91
+ return li;
92
+ }
@@ -0,0 +1,79 @@
1
+ // What an event says on the line (./line.ts) to its reader: who's on it, said only when it isn't everyone and in the
2
+ // second person ("you and Kenji", "without you"); whether the reader goes, and their answer; who comes and goes
3
+ // there ("you arrive", "Kenji leaves"). And a day's events in groups: those at one time together, in lanes.
4
+
5
+ import type { JEvent } from "./generated/elements.ts";
6
+ import { answerOf } from "./answers.ts";
7
+ import { seconds, wall } from "./time.ts";
8
+ import { and } from "./words.ts";
9
+
10
+ /** What an event says to the line's reader. */
11
+ export type Said = {
12
+ title: string;
13
+ start: string;
14
+ duration: string;
15
+ location?: string;
16
+ party: string;
17
+ mine: boolean;
18
+ answer: string;
19
+ picked: boolean;
20
+ answers: (string | undefined)[][];
21
+ gates: string;
22
+ lands: boolean;
23
+ home: boolean;
24
+ };
25
+ /** Who's reading (a person's key, or none signed in), and the people's names by key. */
26
+ type Reading = { reader: number | null; names: Map<number, string> };
27
+
28
+ /** A day's events in groups: one after another alone, those at one time (each starting before the last ends) together. */
29
+ export const whiles = (events: JEvent[]) => {
30
+ const groups: JEvent[][] = [];
31
+ let ends = -Infinity;
32
+ for (const el of events) {
33
+ const from = wall(el.data.start),
34
+ to = from + seconds(el.data.duration) * 1000;
35
+ if (from < ends) groups.at(-1)!.push(el);
36
+ else groups.push([el]);
37
+ ends = Math.max(from < ends ? ends : -Infinity, to);
38
+ }
39
+ return groups;
40
+ };
41
+
42
+ /** Who's on an event, as the reader reads it: nothing when it's everyone; else in the second person. */
43
+ const party = (people: readonly number[], { reader, names }: Reading) => {
44
+ if (people.length && people.length === names.size) return "";
45
+ if (reader === null) return and(people.map((k) => names.get(k) ?? "someone"));
46
+ if (!people.includes(reader)) return "without you";
47
+ const others = people.filter((k) => k !== reader).map((k) => names.get(k) ?? "someone");
48
+ return others.length ? and(["you", ...others]) : "just you";
49
+ };
50
+
51
+ /** Who comes or goes at an event, in the reader's words: "you arrive", "Kenji leaves", "Daisy and Willem leave". */
52
+ const gate = (keys: readonly number[], verb: string, { reader, names }: Reading) => {
53
+ if (!keys.length) return "";
54
+ const you = reader !== null && keys.includes(reader);
55
+ const others = keys.filter((k) => k !== reader).map((k) => names.get(k) ?? "someone");
56
+ const who = and([...(you ? ["you"] : []), ...others]);
57
+ return `${who} ${!you && others.length === 1 ? `${verb}s` : verb}`;
58
+ };
59
+
60
+ /** What an event says to the reader: who's going, whether they are and their answer, who comes and goes there. */
61
+ export const saidOf = (el: JEvent, picked: boolean, reading: Reading): Said => {
62
+ const { reader, names } = reading,
63
+ { people, arrives = [], leaves = [] } = el.data;
64
+ const going = people.filter((k) => answerOf(el.data, k) !== "declined");
65
+ return {
66
+ title: el.data.title,
67
+ start: el.data.start,
68
+ duration: el.data.duration,
69
+ location: el.data.location,
70
+ party: party(going, reading),
71
+ mine: reader === null || going.includes(reader),
72
+ answer: reader === null ? "yes" : answerOf(el.data, reader),
73
+ picked,
74
+ answers: people.map((k) => [names.get(k), answerOf(el.data, k)]),
75
+ gates: [gate(arrives, "arrive", reading), gate(leaves, "leave", reading)].filter(Boolean).join(" · "),
76
+ lands: reader !== null && arrives.includes(reader),
77
+ home: reader !== null && leaves.includes(reader),
78
+ };
79
+ };
@@ -0,0 +1,121 @@
1
+ // The line: the week's events read as one line down its days (Can You's line, japan-eta's LINE-UX), drawn by
2
+ // <calendar-map> in place of its calendar, beside the same map. Each event is a bead on the line and a card beside
3
+ // it, drawn as ./line-stops.ts says, from what the event says to the reader (./line-words.ts). The reader is
4
+ // whoever is signed in, as a person of the same name; a tap on a face reads the line as theirs. A tap on a card picks
5
+ // its event, as a block or a pin does, and opens it in the display's drawer.
6
+
7
+ import type { JEvent, JStay } from "./generated/elements.ts";
8
+ import type { JPerson } from "../people/generated/elements.ts";
9
+ import { hueOf } from "joined/hues";
10
+ import { keep, type Row } from "joined/keep";
11
+ import { face } from "joined/parts";
12
+ import { members, signedIn } from "joined/panel";
13
+ import { end, station, stop } from "./line-stops.ts";
14
+ import { saidOf, whiles } from "./line-words.ts";
15
+ import { dated, dayOf, stayed } from "./time.ts";
16
+
17
+ /** What the line reads from its display: its events, the people by key and as elements, the event picked, how to pick
18
+ * one, the stays, and the week shown. */
19
+ type From = {
20
+ events: () => JEvent[];
21
+ people: () => Map<number, string>;
22
+ persons: () => Iterable<JPerson>;
23
+ picked: () => JEvent | null;
24
+ pick: (el: JEvent) => void;
25
+ stays: () => JStay[];
26
+ week: () => number;
27
+ };
28
+
29
+ export class Line {
30
+ #kept = { faces: new Map(), line: new Map() } as Record<string, Map<string, { shows: string; el: HTMLElement }>>;
31
+ #me: number | null = null; // the person who's the signed-in member: said to be them, or of their name
32
+ #member: number | null = null; // who's signed in
33
+ #reader: number | null = null; // whose line it is: the reader's, or a face tapped
34
+ #faces: HTMLElement;
35
+ #line: HTMLElement;
36
+ #from: From;
37
+
38
+ /** Drawn in `faces` and `line`, from its display; it listens for who's signed in until `signal` lets it go. */
39
+ constructor(faces: HTMLElement, line: HTMLElement, from: From, signal?: AbortSignal) {
40
+ [this.#faces, this.#line, this.#from] = [faces, line, from];
41
+ signedIn((me) => ((this.#member = me), this.draw()), signal);
42
+ }
43
+
44
+ /** The person who's whoever is signed in: the one they've said is them, else the one with their name. */
45
+ #meOf() {
46
+ if (this.#member === null) return null;
47
+ const said = [...this.#from.persons()].find((p) => p.data.member === this.#member);
48
+ if (said) return said.key;
49
+ const name = [...members].find((m) => m.key === this.#member)?.data.name.toLowerCase();
50
+ return [...this.#from.people()].find(([, n]) => n.toLowerCase() === name)?.[0] ?? null;
51
+ }
52
+ draw() {
53
+ const was = this.#me;
54
+ this.#me = this.#meOf();
55
+ // the reader follows you, unless a face was tapped
56
+ if (this.#reader === null || this.#reader === was) this.#reader = this.#me;
57
+ const names = this.#from.people();
58
+ // the faces: a person each, the line's reader pressed
59
+ keep(
60
+ this.#faces,
61
+ this.#kept.faces!,
62
+ [...names].map(([key, name]) => ({
63
+ key: String(key),
64
+ shows: JSON.stringify([name, key === this.#reader, key === this.#me]),
65
+ make: () => {
66
+ const b = Object.assign(document.createElement("button"), { type: "button" });
67
+ b.ariaPressed = String(key === this.#reader);
68
+ b.dataset.key = String(key);
69
+ b.title = key === this.#me ? `${name}: you` : `The line as ${name}'s`;
70
+ b.style.setProperty("--hue", hueOf(key));
71
+ b.append(face(key, name), name);
72
+ b.addEventListener("click", () => ((this.#reader = key === this.#reader ? this.#me : key), this.draw()));
73
+ return b;
74
+ },
75
+ })),
76
+ );
77
+ // the line: a day a station (each with an event, or a stay beginning), an event a stop, in the order they
78
+ // happen; each the colour of the stay that night, from its first to its last
79
+ const events = this.#from.events().sort((a, b) => a.data.start.localeCompare(b.data.start));
80
+ const stays = this.#from.stays().sort((a, b) => a.data.from.localeCompare(b.data.from)),
81
+ week = this.#from.week();
82
+ const stayOn = (d: number) => stays.find((s) => dayOf(s.data.from) <= d && d < dayOf(s.data.until)) ?? null;
83
+ const days = [
84
+ ...new Set([
85
+ ...events.map((el) => dayOf(el.data.start)),
86
+ ...stays.map((s) => dayOf(s.data.from)).filter((d) => d >= week && d < week + 7),
87
+ ]),
88
+ ].sort((a, b) => a - b);
89
+ const reading = { reader: this.#reader, names },
90
+ picked = this.#from.picked();
91
+ const rows: Row[] = [{ key: "begins", shows: "", make: () => end("begins") }];
92
+ for (const [i, d] of days.entries()) {
93
+ const words = dated(
94
+ d,
95
+ i === 0 ? { weekday: "short", day: "numeric", month: "short" } : { weekday: "short", day: "numeric" },
96
+ );
97
+ // the stay that night: said where it begins, its change from the night before an interchange
98
+ const stay = stayOn(d),
99
+ begins = stay && dayOf(stay.data.from) === d ? stay : null,
100
+ before = stayOn(d - 1);
101
+ const change = !!begins && !!before && before !== begins;
102
+ rows.push({
103
+ key: `day ${d}`,
104
+ shows: JSON.stringify([words, stay?.key, begins && [begins.data.name, stayed(begins.data)], change]),
105
+ make: () => station(words, stay, begins, change),
106
+ });
107
+ // its events, one after another; those at one time side by side, the group in lanes for a while: a stop kept
108
+ // while what it says is as it was
109
+ for (const group of whiles(events.filter((e) => dayOf(e.data.start) === d))) {
110
+ const said = group.map((el) => saidOf(el, el === picked, reading));
111
+ rows.push({
112
+ key: `event ${group.map((el) => el.key).join(" ")}`,
113
+ shows: JSON.stringify([said, stay?.key]),
114
+ make: () => stop(group, said, names, stay, (el) => this.#from.pick(el)),
115
+ });
116
+ }
117
+ }
118
+ rows.push({ key: "ends", shows: "", make: () => end("ends") });
119
+ keep(this.#line, this.#kept.line!, rows);
120
+ }
121
+ }