@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,71 @@
1
+ // A pin peeked, on a phone, in <calendar-map>'s map (./map.ts): a card by it saying what, when, where and who, to grow
2
+ // into the drawer, or to close (its Close, Escape, or a tap on the map). Under its pin, or over it where there's no
3
+ // room below, within the map's sides; with room for it neither way, the map moves.
4
+
5
+ import type { JEvent } from "./generated/elements.ts";
6
+ import type { MapView } from "./map.ts";
7
+ import type { Part } from "./shell.ts";
8
+ import { hueOf } from "joined/hues";
9
+ import { DAY, dated, hours, wall } from "./time.ts";
10
+
11
+ /** What the card reads from its display: the people by key, and how to pick an event. */
12
+ type From = { people: () => Map<number, string>; pick: (el: JEvent) => void };
13
+
14
+ export class Peek {
15
+ /** The event peeked, or none. */
16
+ peeked: JEvent | null = null;
17
+ #card: HTMLElement;
18
+ #map: MapView;
19
+ #from: From;
20
+
21
+ /** The card, in the map; it listens for Escape in `root` until `signal` lets it go. */
22
+ constructor($: Part, map: MapView, from: From, root: ShadowRoot, signal: AbortSignal) {
23
+ [this.#card, this.#map, this.#from] = [$(".peek"), map, from];
24
+ // grown into the drawer, or closed
25
+ $("[name=grow]").addEventListener("click", () => {
26
+ const el = this.peeked;
27
+ this.show(null);
28
+ if (el) from.pick(el);
29
+ });
30
+ $("[name=unpeek]").addEventListener("click", () => this.show(null));
31
+ root.addEventListener("keydown", (e) => (e as KeyboardEvent).key === "Escape" && this.peeked && this.show(null), {
32
+ signal,
33
+ });
34
+ }
35
+
36
+ /** An event's card shown by its pin; null closes it. */
37
+ show(el: JEvent | null) {
38
+ const card = this.#card;
39
+ this.#map.peeked(el);
40
+ this.peeked = el;
41
+ card.hidden = !el;
42
+ if (!el) return;
43
+ const { title, start, duration, location, people = [] } = el.data,
44
+ names = this.#from.people(),
45
+ at = wall(start),
46
+ who = people.map((k) => names.get(k)).filter(Boolean) as string[];
47
+ card.style.setProperty("--hue", hueOf(el.key));
48
+ card.ariaLabel = title;
49
+ card.querySelector("b")!.textContent = title;
50
+ card.querySelector(".when")!.textContent =
51
+ `${dated(Math.floor(at / DAY), { weekday: "short", day: "numeric", month: "short" })} · ${hours(start, duration)}`;
52
+ card.querySelector(".where")!.textContent = location ?? "";
53
+ card.querySelector(".who")!.textContent = who.join(", ");
54
+ // under its pin, or over it where there's no room below; within the map's sides
55
+ const map = this.#map,
56
+ pin = map.pinOf(el)!,
57
+ w = card.offsetWidth,
58
+ h = card.offsetHeight,
59
+ W = map.el.clientWidth,
60
+ H = map.el.clientHeight;
61
+ // no room above it or below: the map moves, the pin near its top, the card under it
62
+ if (pin.offsetTop + 18 + h > H && pin.offsetTop - 18 - h < 8)
63
+ map.look({ ...map.view, y: map.view.y + pin.offsetTop - 30 });
64
+ const x = pin.offsetLeft,
65
+ y = pin.offsetTop,
66
+ below = y + 18 + h <= H;
67
+ card.style.left = `${Math.max(8, Math.min(W - w - 8, x - w / 2))}px`;
68
+ card.style.top = `${Math.max(8, Math.min(H - h - 8, below ? y + 18 : y - 18 - h))}px`;
69
+ card.querySelector<HTMLButtonElement>("[name=grow]")!.focus();
70
+ }
71
+ }
@@ -0,0 +1,74 @@
1
+ // The people on an event, in its form (docs/design.md, "Choosing"): six or fewer, a chip each to press, pressed where
2
+ // the event links to them, a press linking or unlinking; more, a chip each for those it links to, its × to take them
3
+ // off, and the rest found by typing. A press changes who the form has chosen, not the event, until Save.
4
+
5
+ import { iconButton } from "joined/icons";
6
+ import { hueOf } from "joined/hues";
7
+ import { keep } from "joined/keep";
8
+ import { chip, face, typeahead } from "joined/parts";
9
+
10
+ const MANY = 6; // more people than this, and they're found by typing
11
+
12
+ /** What the chips ask of their form: who may be chosen, who is, and how to choose. */
13
+ type Of = { people(): Map<number, string>; chosen(): readonly number[]; choose(chosen: number[]): void };
14
+
15
+ export class PeopleChips {
16
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
17
+ #chips: HTMLElement;
18
+ #someone: HTMLElement;
19
+ #ask: () => void;
20
+
21
+ /** Drawn in the form's `.j-chips`; past six people, typed for in its `.someone`. */
22
+ constructor(
23
+ form: HTMLElement,
24
+ readonly of: Of,
25
+ ) {
26
+ this.#chips = form.querySelector(".j-chips")!;
27
+ this.#someone = form.querySelector(".someone")!;
28
+ // past six people, who isn't on it yet, found by typing
29
+ this.#ask = typeahead(
30
+ this.#someone.querySelector("input")!,
31
+ this.#someone.querySelector<HTMLElement>(".j-choices")!,
32
+ () => [...of.people()].filter(([key]) => !of.chosen().includes(key)),
33
+ (key) => of.choose([...of.chosen(), key]),
34
+ );
35
+ }
36
+
37
+ /** The chips for `people`, as the form has them chosen: a chip made again only as its name or its press changes. */
38
+ draw(people: Map<number, string>) {
39
+ const many = people.size > MANY;
40
+ // who's chosen is read when a chip is pressed: a chip is kept while its name and its press are
41
+ const chosen = () => this.of.chosen();
42
+ this.#someone.hidden = !many;
43
+ if (many) this.#ask();
44
+ keep(
45
+ this.#chips,
46
+ this.#kept,
47
+ [...people]
48
+ .filter(([key]) => !many || chosen().includes(key))
49
+ .map(([key, name]) => ({
50
+ key: String(key),
51
+ shows: `${name} ${chosen().includes(key)} ${many}`,
52
+ make: () => {
53
+ if (many) {
54
+ const one = chip(key, name);
55
+ one.append(
56
+ iconButton("close", `Take ${name} off`, () => this.of.choose(chosen().filter((k) => k !== key))),
57
+ );
58
+ return one;
59
+ }
60
+ // six or fewer: each a chip to press (People chips), pressed where they're on it
61
+ const press = Object.assign(document.createElement("button"), { type: "button" });
62
+ press.style.setProperty("--hue", hueOf(key));
63
+ press.append(face(key, name), name);
64
+ press.setAttribute("aria-pressed", String(chosen().includes(key)));
65
+ press.addEventListener("click", () => {
66
+ const now = chosen();
67
+ this.of.choose(now.includes(key) ? now.filter((k) => k !== key) : [...now, key]);
68
+ });
69
+ return press;
70
+ },
71
+ })),
72
+ );
73
+ }
74
+ }
@@ -0,0 +1,51 @@
1
+ // The place search in an event's form: what's typed as its place, asked of Photon (./places.ts) near the map's
2
+ // middle a moment after the typing stops, and the places found offered beneath it to pick from. An answer to a
3
+ // search typed past since is let go, so what's offered is always what's typed.
4
+
5
+ import { keep } from "joined/keep";
6
+ import { find, type Place } from "./places.ts";
7
+
8
+ export class PlaceSearch {
9
+ #asked = 0; // the last search asked: an answer to an older one is let go
10
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
11
+
12
+ /** Offered in `list`; the one picked is told to `pick`, and the offer let go. */
13
+ constructor(
14
+ readonly list: HTMLElement,
15
+ readonly pick: (place: Place) => void,
16
+ ) {}
17
+
18
+ /** Places called `q`, near the point `near` gives, offered to pick from; under three letters, none. */
19
+ search(q: string, near: () => { lat: number; lng: number }) {
20
+ const asked = ++this.#asked;
21
+ if (q.length < 3) return this.found([]);
22
+ const at = near();
23
+ setTimeout(async () => {
24
+ if (asked !== this.#asked) return;
25
+ const places = await find(q, at);
26
+ if (asked === this.#asked) this.found(places);
27
+ }, 300);
28
+ }
29
+
30
+ /** The places offered: a button each, kept by where it is; none, the list hidden. */
31
+ found(places: Place[]) {
32
+ this.list.hidden = !places.length;
33
+ keep(
34
+ this.list,
35
+ this.#kept,
36
+ places.map((place) => ({
37
+ key: place.coordinates,
38
+ shows: place.name,
39
+ make: () => {
40
+ const b = Object.assign(document.createElement("button"), { type: "button", textContent: place.name });
41
+ b.setAttribute("role", "option");
42
+ b.addEventListener("click", () => {
43
+ this.pick(place);
44
+ this.found([]);
45
+ });
46
+ return b;
47
+ },
48
+ })),
49
+ );
50
+ }
51
+ }
@@ -0,0 +1,34 @@
1
+ // Places by name, and the name of a point: Photon, komoot's search over OpenStreetMap, open to all and
2
+ // asked from the page, as the map's tiles are. Nothing found, or Photon away, is no place: the form
3
+ // keeps what it had.
4
+
5
+ const PHOTON = "https://photon.komoot.io";
6
+ export type Place = { name: string; coordinates: string };
7
+ type Feature = {
8
+ geometry: { coordinates: [number, number] };
9
+ properties: Partial<Record<"name" | "street" | "district" | "city" | "county" | "state", string>>;
10
+ };
11
+
12
+ // a place's name, its district and its city: enough to tell one Ginza from another
13
+ const placeOf = ({ geometry, properties: p }: Feature): Place => {
14
+ const [lng, lat] = geometry.coordinates;
15
+ const name = [...new Set([p.name ?? p.street, p.district, p.city ?? p.county ?? p.state])].filter(Boolean).join(", ");
16
+ return { name, coordinates: `geo:${lat.toFixed(4)},${lng.toFixed(4)}` };
17
+ };
18
+ const ask = async (path: string): Promise<Place[]> => {
19
+ try {
20
+ const r = await fetch(`${PHOTON}${path}`);
21
+ if (!r.ok) return [];
22
+ const places = ((await r.json()) as { features: Feature[] }).features.map(placeOf);
23
+ return places.filter((p, i) => p.name && places.findIndex((q) => q.name === p.name) === i);
24
+ } catch {
25
+ return [];
26
+ }
27
+ };
28
+
29
+ /** Places called this, those near a point first. */
30
+ export const find = (q: string, near: { lat: number; lng: number }) =>
31
+ ask(`/api/?q=${encodeURIComponent(q)}&limit=5&lang=en&lat=${near.lat}&lon=${near.lng}`);
32
+ /** The name of the place at a point, or none. */
33
+ export const nameOf = async ({ lat, lng }: { lat: number; lng: number }) =>
34
+ (await ask(`/reverse?lat=${lat}&lon=${lng}&lang=en`))[0]?.name ?? null;
@@ -0,0 +1,27 @@
1
+ // A trip: its document, one for each of the trips (../trips: trip:1 Japan, trip:2 Hokkaido), its page at /trip/<key>,
2
+ // and the trip going out as .ics, which reads the document as it is now, as whoever asks sees it: a trip they're
3
+ // not on is none of theirs.
4
+
5
+ import type { Read } from "joined/server";
6
+ import { toIcs, type IcsEvent } from "./ics.ts";
7
+ import page from "./index.html";
8
+
9
+ export * as document from "./generated/rules.ts";
10
+ /** The trip's own rule: an answer is from someone on the event, one each (./trust.ts). */
11
+ export { trust } from "./trust.ts";
12
+ /** What an agent is told at the MCP door, of the trips' events (src/mcp.ts). */
13
+ export const instructions =
14
+ "A trip (trip:<key>, its key a trip's id in trips) holds its events: a start is a wall clock where it happens, its zone (Asia/Tokyo) where it's said, a length ISO 8601 (PT2H), a place geo:lat,lng. Read the trip before changing it, and say why in a few words.";
15
+ export const routes = (read: Read) => ({
16
+ "/trip/:n": page,
17
+ "/trip/:n/trip.ics": (req: Request & { params: { n: string } }, who?: { member: number }) => {
18
+ const trips = read("trips", who?.member).trips as { id: number; name: string }[];
19
+ const trip = trips.find((t) => String(t.id) === req.params.n);
20
+ if (!trip) return new Response("no trip of yours", { status: 404 });
21
+ const events = read(`trip:${trip.id}`, who?.member).events as (IcsEvent & { id: number })[];
22
+ const people = read("people", who?.member).people as { id: number; name: string }[];
23
+ return new Response(toIcs(events, trip.name, new Map(people.map((p) => [p.id, p.name]))), {
24
+ headers: { "content-type": "text/calendar; charset=utf-8" },
25
+ });
26
+ },
27
+ });
@@ -0,0 +1,39 @@
1
+ // The shadow <calendar-map> draws in: its look (./calendar-map.css, one sheet shared by every calendar on the page,
2
+ // over joined's parts), the sizes its stylesheet draws by, and its parts, each found once by the one that draws it:
3
+ // the bar, a phone's strip of the week's days, the map (its tiles, a peeked pin's card, nearer and farther), the
4
+ // calendar (its ruler and days), the line, the month, the other weeks, the drawer, the modal, and the modal that asks
5
+ // before Remove.
6
+
7
+ import { PARTS } from "joined/parts";
8
+ import { HOUR } from "./week.ts";
9
+ import { MAP_H } from "./map.ts";
10
+ import { TILE } from "./mercator.ts";
11
+ import STYLE from "./calendar-map.css" with { type: "text" };
12
+
13
+ /** One of the shadow's parts, found once (the display keeps them): its parts are found by it, never searched for on
14
+ * a change. */
15
+ export type Part = (selector: string) => HTMLElement;
16
+
17
+ const SHEET = new CSSStyleSheet();
18
+ SHEET.replaceSync(STYLE);
19
+ const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
20
+ const HTML = `
21
+ <div class="top"><button type="button" class="icon-only" name="back" title="The week before" aria-label="The week before" data-icon="back"></button><h2 class="week"></h2><button type="button" class="icon-only" name="on" title="The week after" aria-label="The week after" data-icon="on"></button><span class="views" role="group" aria-label="Read as"><button type="button" class="act" name="calendar" data-icon="calendar">Calendar</button><button type="button" class="act" name="line" data-icon="line">Line</button><button type="button" class="act" name="month" data-icon="month">Month</button></span><button type="button" class="act ink" name="new" data-icon="add">Add</button></div>
22
+ <div class="strip" role="group" aria-label="The week's days"></div>
23
+ <div class="map"><div class="tiles"></div><div class="peek" role="dialog" hidden><header><b></b></header><p class="when"></p><p class="where"></p><p class="who"></p><footer><button type="button" class="act quiet" name="grow" data-icon="grow">Grow</button><button type="button" class="act quiet" name="unpeek" data-icon="close">Close</button></footer></div><div class="zoom"><button type="button" class="icon-only" name="nearer" data-icon="zoom-in" title="Nearer" aria-label="Nearer"></button><button type="button" class="icon-only" name="farther" data-icon="zoom-out" title="Farther" aria-label="Farther"></button></div><small>© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a></small></div>
24
+ <div class="when"><div class="cal"><div class="ruler"></div><div class="days"></div></div><div class="reading" hidden><div class="faces j-chips" role="group" aria-label="Whose line"></div><ol class="line" aria-label="The week, day by day"></ol></div><div class="month" hidden><div class="names">${DAYS.map((d) => `<span>${d}</span>`).join("")}</div><div class="cells"></div></div><p class="others" hidden></p></div>
25
+ <aside class="drawer" hidden></aside>
26
+ <dialog class="modal"></dialog>
27
+ <dialog class="modal ask"><h2></h2><footer><button type="button" class="act" name="keep">Never mind</button><button type="button" class="act danger" name="sure" data-icon="remove">Remove</button></footer></dialog>`;
28
+
29
+ /** The display's shadow made afresh: its look, its sizes, and its parts, empty until they're drawn. */
30
+ export function shell(host: HTMLElement, root: ShadowRoot) {
31
+ root.adoptedStyleSheets = [PARTS, SHEET];
32
+ for (const [name, px] of [
33
+ ["--hour", HOUR],
34
+ ["--tile", TILE],
35
+ ["--map-h", MAP_H],
36
+ ] as const)
37
+ host.style.setProperty(name, `${px}px`);
38
+ root.innerHTML = HTML;
39
+ }
@@ -0,0 +1,51 @@
1
+ /* The trip's stays, in their sheet: each its hue a stripe, its name changed where it is, its nights and place under it,
2
+ its cancel at the end; the booking form at the foot: where, the whole width, and under it the night it starts, how
3
+ many, and Book. */
4
+ j-stays {
5
+ display: grid;
6
+ gap: var(--space-12);
7
+ }
8
+ j-stay {
9
+ display: grid;
10
+ grid-template-columns: auto minmax(0, 1fr) auto;
11
+ gap: 2px var(--space-8);
12
+ align-items: center;
13
+ }
14
+ j-stay .stripe {
15
+ width: 3px;
16
+ align-self: stretch;
17
+ grid-row: span 2;
18
+ border-radius: 2px;
19
+ background: var(--hue);
20
+ }
21
+ j-stay input {
22
+ border: 0;
23
+ border-bottom: 1px solid var(--line);
24
+ padding: 2px 0;
25
+ }
26
+ j-stay .when,
27
+ j-stay .said {
28
+ grid-column: 2 / -1;
29
+ margin: 0;
30
+ font: var(--font-small);
31
+ color: var(--muted);
32
+ }
33
+ j-stay .said {
34
+ color: var(--danger);
35
+ }
36
+ form.add.book {
37
+ display: grid;
38
+ grid-template-columns: minmax(0, 1fr) auto auto;
39
+ align-items: end;
40
+ }
41
+ form.add.book :is([name="name"], .said) {
42
+ grid-column: 1 / -1;
43
+ }
44
+ form.book label {
45
+ display: grid;
46
+ gap: var(--space-4);
47
+ font: var(--font-label);
48
+ }
49
+ form.book input[type="number"] {
50
+ width: 4.5rem;
51
+ }
@@ -0,0 +1,68 @@
1
+ // The trip's stays, where it sleeps: <j-stay>, in a sheet beside the people. Each its hue, its name to change where
2
+ // it is, its nights and its place in words, and a way to cancel it (asking nothing: it's one row, put back by
3
+ // booking it again). A form books one: its name, the night it starts and how many. Two stays never share a night
4
+ // (the stories' noOverlap): refused, why is said under the form.
5
+
6
+ import { iconButton } from "joined/icons";
7
+ import { hueOf } from "joined/hues";
8
+ import { said } from "joined/parts";
9
+ import { JStay, type JStays } from "./generated/elements.ts";
10
+ import { collections } from "./generated/rules.ts";
11
+ import { DAY, dayOf, local, stayed } from "./time.ts";
12
+
13
+ export class Stay extends JStay {
14
+ #name = Object.assign(document.createElement("input"), { ariaLabel: "Name" });
15
+ #when = Object.assign(document.createElement("p"), { className: "when" });
16
+ #said = Object.assign(document.createElement("p"), { className: "said", role: "status" });
17
+ #gone = iconButton("remove", "", () => said(this.#said, this.removeItem()));
18
+ connectedCallback() {
19
+ if (this.childElementCount) return this.draw();
20
+ this.#name.addEventListener(
21
+ "change",
22
+ async () =>
23
+ this.#name.value.trim() &&
24
+ (await said(this.#said, this.replace({ name: this.#name.value.trim() }))) &&
25
+ this.draw(),
26
+ );
27
+ this.#gone.classList.add("gone");
28
+ this.append(
29
+ Object.assign(document.createElement("i"), { className: "stripe" }),
30
+ this.#name,
31
+ this.#gone,
32
+ this.#when,
33
+ this.#said,
34
+ );
35
+ this.draw();
36
+ }
37
+ /** Its name, unless it's being changed, its nights and its place; only what's changed. */
38
+ draw() {
39
+ if (!this.isConnected) return;
40
+ const hue = hueOf(this.key);
41
+ if (this.style.getPropertyValue("--hue") !== hue) this.style.setProperty("--hue", hue);
42
+ if (this.#name !== document.activeElement && this.#name.value !== this.data.name) this.#name.value = this.data.name;
43
+ const cancel = `Cancel ${this.data.name}`;
44
+ if (this.#gone.ariaLabel !== cancel) Object.assign(this.#gone, { ariaLabel: cancel, title: cancel });
45
+ const when = [stayed(this.data), this.data.location].filter(Boolean).join(" · ");
46
+ if (this.#when.textContent !== when) this.#when.textContent = when;
47
+ }
48
+ }
49
+
50
+ /** A form that books a stay: its name, the night it starts (in at three, out at ten) and how many nights. */
51
+ export function booking(form: HTMLFormElement) {
52
+ form.addEventListener("submit", (e) => {
53
+ e.preventDefault();
54
+ const field = (n: string) => (form.elements.namedItem(n) as HTMLInputElement).value.trim();
55
+ const [name, day, n] = [field("name"), field("day"), Number(field("nights")) || 1];
56
+ if (!name || !day) return;
57
+ const until = local((dayOf(day) + n) * DAY).slice(0, 10);
58
+ // refused, what was typed stays, and why is said under it
59
+ said(
60
+ form.querySelector(".said")!,
61
+ document
62
+ .querySelector<JStays>(collections.stays.place)!
63
+ .add({ name, from: `${day}T15:00:00`, until: `${until}T10:00:00` }),
64
+ ).then((why) => why || form.reset());
65
+ });
66
+ }
67
+ // defined last, once all it draws with is made
68
+ customElements.define(collections.stays.tag, Stay);
@@ -0,0 +1,72 @@
1
+ {"cast":{"phone":"peter","stranger":null}}
2
+ {"kind":{"root":"trips"}}
3
+ {"roles":{"organiser":"@organisers","traveller":"@travellers"}}
4
+ {"owns":"organiser | traveller"}
5
+ {"window":{"events":{"week":{"from":"start","for":"P7D","length":"duration"},"month":{"from":"start","for":"P42D","length":"duration"}}}}
6
+ {"links":{"keen":"people","asked":"people","declined":"people","arrives":"people","leaves":"people"}}
7
+ {"noOverlap":{"stays":{"range":["from","until"]}}}
8
+ {"story":"Nora adds dinner in Gion, and Peter's phone shows it on the calendar and on the map","as":"nora","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/-","value":{"title":"Dinner in Gion","start":"2026-11-07T19:00:00","duration":"PT2H","location":"Gion, Kyoto","coordinates":"geo:35.0037,135.7788","people":[1,2]}}]},"seen":["peter","phone","nick","nora"],"unseen":["dev"]}
9
+ {"story":"Peter adds a day to rest: with no place yet, it is on the calendar alone","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/-","value":{"title":"A day to rest","start":"2026-11-05T10:00:00","duration":"PT6H"}}]},"seen":["peter","phone","nora"]}
10
+ {"story":"The shinkansen leaves an hour later: Nick moves it, and it moves on every calendar","as":"nick","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/3/start","value":"2026-11-06T10:00:00"}]},"seen":["peter","phone","nick"]}
11
+ {"story":"Nick renames the dinner","as":"nick","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/title","value":"Dinner with friends"}]},"seen":["peter","phone","nick"]}
12
+ {"story":"The dinner runs longer, Nora says","as":"nora","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/duration","value":"PT3H"}]},"seen":["peter","nora"]}
13
+ {"story":"Nora moves the dinner to Shibuya: its pin moves on every map","as":"nora","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/location","value":"Shibuya, Tokyo"},{"op":"replace","path":"/events/2/coordinates","value":"geo:35.6580,139.7016"}]},"seen":["peter","phone","nora"]}
14
+ {"story":"The flight lands at Narita instead: Peter's phone renames it, gives it longer, and moves its pin","as":"phone","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/title","value":"Land at Narita"},{"op":"replace","path":"/events/1/duration","value":"PT2H"},{"op":"replace","path":"/events/1/location","value":"Narita Airport"},{"op":"replace","path":"/events/1/coordinates","value":"geo:35.7720,140.3929"}]},"seen":["peter","phone","nick"]}
15
+ {"story":"The flight from London lands at Haneda at 17:00 Tokyo time: Peter says so, and any calendar puts it there","as":"peter","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/zone","value":"Asia/Tokyo"}]},"seen":["peter","phone","nick"]}
16
+ {"story":"Not in Tokyo after all: Peter clears the dinner's zone, and it floats, at 19:00 wherever the calendar is","as":"peter","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/zone"}]},"seen":["peter","phone","nick"]}
17
+ {"story":"The dinner's place isn't settled yet: Peter clears it, and its pin leaves every map","as":"peter","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/location"},{"op":"remove","path":"/events/2/coordinates"}]},"seen":["peter","phone","nora"]}
18
+ {"story":"Only an organiser clears a place: Nora can't","as":"nora","cannot":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/1/location"}]},"refused":"you may not remove at /events/1/location"}
19
+ {"story":"Peter drops the early visit to Fushimi Inari","as":"peter","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/4"}]},"seen":["peter","phone","nick"]}
20
+ {"story":"Only an organiser drops an event: Nick can't","as":"nick","cannot":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/1"}]},"refused":"you may not remove at /events/1"}
21
+ {"story":"Peter asks Aiko to the dinner too: it links to the three of them","as":"peter","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/people","value":[1,2,3]}]},"seen":["peter","phone"]}
22
+ {"story":"Nora asks Yuki in Kenji's place: the dinner links to Peter and Yuki","as":"nora","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/people","value":[1,4]}]},"seen":["peter","nora"]}
23
+ {"story":"An event cannot link to someone who is not in the people","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/people","value":[1,9]}]}}
24
+ {"story":"An event names a person once","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/people","value":[1,1]}]}}
25
+ {"story":"Peter's phone asks Aiko and Nick asks Yuki to the dinner at once: an id each, added, so both land","as":"nick","premise":{"phone":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3}]}]},"does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":4}]},"seen":["peter","phone","nick"]}
26
+ {"story":"Kenji can't come to the dinner after all, Nora says: his id is taken, the rest as they were","as":"nora","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/people/2"}]},"seen":["peter","nora"]}
27
+ {"story":"Peter asks Aiko to the dinner, and she's yet to say: on it, and asked","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3},{"op":"add","path":"/events/2/asked/-","value":3}]},"seen":["peter","phone","nick"]}
28
+ {"story":"Aiko's keen, Nick says: asked no longer, keen","as":"nick","premise":{"peter":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3},{"op":"add","path":"/events/2/asked/-","value":3}]}]},"does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/asked/3"},{"op":"add","path":"/events/2/keen/-","value":3}]},"seen":["peter","nick"]}
29
+ {"story":"Kenji can't make the dinner after all: he says no, and stays on it, saying so","as":"nora","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/declined/-","value":2}]},"seen":["peter","nora"]}
30
+ {"story":"Kenji can come after all: his no taken back, he's a yes","as":"peter","premise":{"nora":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/declined/-","value":2}]}]},"does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/declined/2"}]},"seen":["peter","nora"]}
31
+ {"story":"Aiko's keen no more, just a yes","as":"nick","premise":{"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3},{"op":"add","path":"/events/2/keen/-","value":3}]}]},"does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/keen/3"}]},"seen":["peter","nick"]}
32
+ {"story":"Peter says the dinner's answers at once, from his drawer: Aiko keen now, and Kenji coming after all","as":"peter","premise":{"peter":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3},{"op":"add","path":"/events/2/asked/-","value":3}]}],"nora":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/declined/-","value":2}]}],"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/keen/-","value":1}]}]},"does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/keen","value":[1,3]},{"op":"remove","path":"/events/2/asked"},{"op":"remove","path":"/events/2/declined"}]},"seen":["peter","phone","nick"]}
33
+ {"story":"And again, from his drawer: Kenji says no, Aiko's asked, and nobody's keen","as":"peter","premise":{"peter":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":3}]}],"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/keen/-","value":1}]}]},"does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/declined","value":[2]},{"op":"replace","path":"/events/2/asked","value":[3]},{"op":"remove","path":"/events/2/keen"}]},"seen":["peter","phone","nick"]}
34
+ {"story":"Peter's keen on the dinner himself, and says Kenji can't come","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/keen/-","value":1},{"op":"add","path":"/events/2/declined/-","value":2}]},"seen":["peter","phone","nick"]}
35
+ {"story":"Nick asks Yuki to the dinner, and she's yet to say","as":"nick","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":4},{"op":"add","path":"/events/2/asked/-","value":4}]},"seen":["peter","nick"]}
36
+ {"story":"Nick says the dinner's answers from his drawer: Yuki keen, and no one asked or saying no","as":"nick","premise":{"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":4},{"op":"add","path":"/events/2/asked/-","value":4},{"op":"add","path":"/events/2/keen/-","value":1}]}],"nora":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/declined/-","value":2}]}]},"does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/keen","value":[1,4]},{"op":"remove","path":"/events/2/asked"},{"op":"remove","path":"/events/2/declined"}]},"seen":["peter","nick"]}
37
+ {"story":"And Nick again: Kenji says no, Yuki's asked, nobody's keen","as":"nick","premise":{"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":4},{"op":"add","path":"/events/2/keen/-","value":1}]}]},"does":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/declined","value":[2]},{"op":"replace","path":"/events/2/asked","value":[4]},{"op":"remove","path":"/events/2/keen"}]},"seen":["peter","nick"]}
38
+ {"story":"Only someone on an event answers it: Yuki isn't on the dinner","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/keen/-","value":4}]},"refused":"an answer is from someone on the event"}
39
+ {"story":"One answer each: Kenji can't say no and be keen","as":"peter","premise":{"nora":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/declined/-","value":2}]}]},"cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/keen/-","value":2}]},"refused":"one answer each"}
40
+ {"story":"Peter takes Kenji off the dinner and asks Aiko instead: an id taken, and one added","as":"peter","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/people/2"},{"op":"add","path":"/events/2/people/-","value":3}]},"seen":["peter","phone"]}
41
+ {"story":"An event links to someone once","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":1}]},"refused":"people links to 1 already"}
42
+ {"story":"Nobody is taken from an event they aren't on","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/people/4"}]},"refused":"people doesn't link to 4"}
43
+ {"story":"An id added must be someone in the people","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/people/-","value":9}]},"refused":"people links only to people the people document holds"}
44
+ {"story":"An event needs a start","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/-","value":{"title":"Sometime","duration":"PT1H"}}]}}
45
+ {"story":"A start is a date and time, not a number","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/start","value":9}]}}
46
+ {"story":"A start is a date and time, not a banana","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/start","value":"banana"}]},"refused":"start is a date and time (YYYY-MM-DDTHH:MM:SS)"}
47
+ {"story":"A duration is so long, not forever","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/duration","value":"forever"}]},"refused":"duration is a length of time (PT2H30M)"}
48
+ {"story":"A place is where it is on the map, not its name","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/coordinates","value":"Gion"}]},"refused":"coordinates is a place (geo:lat,lon)"}
49
+ {"story":"A time zone is one the world names, not Narnia","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/zone","value":"Narnia"}]},"refused":"zone is a time zone (Asia/Tokyo)"}
50
+ {"story":"An event has no colour to change","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/1/colour","value":"red"}]}}
51
+ {"story":"Japan's events aren't Hokkaido's: Peter can't rename one through it","as":"peter","cannot":{"doc":"trip:2","ops":[{"op":"replace","path":"/events/1/title","value":"Nonsense"}]},"refused":"no j-event at /events/1/title"}
52
+ {"story":"Hokkaido's first event is its own: Nora and Dev, not on that trip, aren't told of it","as":"peter","does":{"doc":"trip:2","ops":[{"op":"add","path":"/events/-","value":{"title":"Land at Chitose","start":"2027-02-10T12:00:00","duration":"PT1H"}}]},"seen":["peter","phone","nick"],"unseen":["nora","dev"]}
53
+ {"story":"Dev isn't on the Japan trip, so he can't change it","as":"dev","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/3/title","value":"Nonsense"}]},"refused":"you may not replace at /events/3/title"}
54
+ {"story":"A stranger can't change the trip","as":"stranger","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/events/3/title","value":"Nonsense"}]}}
55
+ {"story":"On the week of 2 November, Peter's phone shows the dinner moved to the Thursday of it","as":"peter","does":{"doc":"trip:1?week=2026-11-02","ops":[{"op":"replace","path":"/events/2/start","value":"2026-11-05T19:00:00"}]},"seen":["peter","phone"]}
56
+ {"story":"On the week of 9 November, the dinner on its Monday: moved to Sunday the 8th at ten for four hours, it runs into the week, and Peter's phone still shows it","as":"peter","does":{"doc":"trip:1?week=2026-11-09","ops":[{"op":"replace","path":"/events/2/start","value":"2026-11-08T22:00:00"},{"op":"replace","path":"/events/2/duration","value":"PT4H"}]},"seen":["peter","phone"],"premise":{"peter":[{"doc":"trip:1","ops":[{"op":"replace","path":"/events/2/start","value":"2026-11-09T19:00:00"}]}]}}
57
+ {"story":"On the month of November, its six weeks from Monday 26 October, Peter's phone shows the dinner moved to the 12th","as":"peter","does":{"doc":"trip:1?month=2026-10-26","ops":[{"op":"replace","path":"/events/2/start","value":"2026-11-12T19:00:00"}]},"seen":["peter","phone"]}
58
+ {"story":"Peter books a night in a capsule in Kyoto after the ryokan: the line's stays go on a night","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/stays/-","value":{"name":"Capsule in Kyoto","from":"2026-11-09T15:00:00","until":"2026-11-10T10:00:00","location":"Kyoto Station","coordinates":"geo:34.9858,135.7588"}}]},"seen":["peter","phone","nick"]}
59
+ {"story":"Nick books it too, travelling","as":"nick","does":{"doc":"trip:1","ops":[{"op":"add","path":"/stays/-","value":{"name":"Capsule in Kyoto","from":"2026-11-09T15:00:00","until":"2026-11-10T10:00:00","location":"Kyoto Station","coordinates":"geo:34.9858,135.7588"}}]},"seen":["peter","nick"]}
60
+ {"story":"Peter books a night in Osaka, where not yet settled","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/stays/-","value":{"name":"Somewhere in Osaka","from":"2026-11-10T15:00:00","until":"2026-11-11T10:00:00"}}]},"seen":["peter","phone","nick"]}
61
+ {"story":"Nora renames the ryokan","as":"nora","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/stays/2/name","value":"Ryokan Gion Hatanaka"}]},"seen":["peter","nora"]}
62
+ {"story":"The Gracery for a night less, Peter says: the ryokan stays as it was","as":"peter","does":{"doc":"trip:1","ops":[{"op":"replace","path":"/stays/1/until","value":"2026-11-05T10:00:00"}]},"seen":["peter","phone","nick"]}
63
+ {"story":"The ryokan a night sooner, after it","as":"peter","premise":{"peter":[{"doc":"trip:1","ops":[{"op":"replace","path":"/stays/1/until","value":"2026-11-05T10:00:00"}]}]},"does":{"doc":"trip:1","ops":[{"op":"replace","path":"/stays/2/from","value":"2026-11-05T15:00:00"}]},"seen":["peter","phone","nick"]}
64
+ {"story":"Peter cancels the ryokan","as":"peter","does":{"doc":"trip:1","ops":[{"op":"remove","path":"/stays/2"}]},"seen":["peter","phone","nick"]}
65
+ {"story":"Two stays don't share a night: the ryokan can't start while the Gracery has them","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"replace","path":"/stays/2/from","value":"2026-11-05T15:00:00"}]}}
66
+ {"story":"A stay has its name, and when","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/stays/-","value":{"name":"Somewhere"}}]}}
67
+ {"story":"Dev isn't on the trip: he books nothing on it","as":"dev","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/stays/-","value":{"name":"Capsule in Kyoto","from":"2026-11-09T15:00:00","until":"2026-11-10T10:00:00","location":"Kyoto Station","coordinates":"geo:34.9858,135.7588"}}]},"refused":"you may not add at /stays/-"}
68
+ {"story":"Kenji joins the trip at the dinner and goes home after it, Peter says: the line lands him there, and sends him home","as":"peter","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/arrives/-","value":2},{"op":"add","path":"/events/2/leaves/-","value":2}]},"seen":["peter","phone","nick"]}
69
+ {"story":"Nick says Aiko comes for Fushimi Inari alone: she arrives and leaves there","as":"nick","does":{"doc":"trip:1","ops":[{"op":"add","path":"/events/4/arrives/-","value":3},{"op":"add","path":"/events/4/leaves/-","value":3}]},"seen":["peter","nick"]}
70
+ {"story":"Kenji stays on after all, Peter says: he no longer leaves at the dinner, and lands there still","as":"peter","premise":{"peter":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/arrives/-","value":2},{"op":"add","path":"/events/2/leaves/-","value":2}]}]},"does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/2/leaves/2"},{"op":"remove","path":"/events/2/arrives/2"}]},"seen":["peter","phone","nick"]}
71
+ {"story":"Nick takes back Aiko's coming and going","as":"nick","premise":{"nick":[{"doc":"trip:1","ops":[{"op":"add","path":"/events/4/arrives/-","value":3},{"op":"add","path":"/events/4/leaves/-","value":3}]}]},"does":{"doc":"trip:1","ops":[{"op":"remove","path":"/events/4/arrives/3"},{"op":"remove","path":"/events/4/leaves/3"}]},"seen":["peter","nick"]}
72
+ {"story":"Only someone on an event comes or goes there: Yuki isn't at the dinner","as":"peter","cannot":{"doc":"trip:1","ops":[{"op":"add","path":"/events/2/arrives/-","value":4}]},"refused":"who comes or goes at an event is on it"}
@@ -0,0 +1,46 @@
1
+ // The trip's time: a start is a wall clock (floating time, kept as if UTC), a length an ISO 8601 duration
2
+ // (PT1H30M), a day a count from 1 January 1970.
3
+
4
+ export const DAY = 86_400_000,
5
+ MIN = 60_000,
6
+ SNAP = 15; // minutes: a drag moves in steps of a quarter hour
7
+
8
+ export const wall = (local: string) => Date.parse(`${local}Z`); // a wall clock, kept as if UTC
9
+ export const local = (ms: number) => new Date(ms).toISOString().slice(0, 19);
10
+ export const hhmm = (ms: number) => local(ms).slice(11, 16);
11
+ export const minutes = (t: string) => Number(t.slice(0, 2)) * 60 + Number(t.slice(3, 5));
12
+ export const snap = (ms: number) => Math.round(ms / (SNAP * MIN)) * SNAP * MIN;
13
+ export const mondayOf = (day: number) => day - ((day + 3) % 7); // day 0, 1 January 1970, was a Thursday
14
+ export const dayOf = (when: string) => Date.parse(when.slice(0, 10)) / DAY; // a start's day, or a date's (2026-11-02)
15
+ export const weekOf = (when: string) => local(mondayOf(dayOf(when)) * DAY).slice(0, 10); // its week, by its Monday
16
+ export const dated = (day: number, how: Intl.DateTimeFormatOptions) =>
17
+ new Date(day * DAY).toLocaleDateString("en-GB", { ...how, timeZone: "UTC" });
18
+ /** The wall clock where the person is, now: 2026-11-03T14:05:00 (its date, today: now().slice(0, 10)). */
19
+ export const now = () => new Date().toLocaleString("sv").replace(" ", "T");
20
+ /** A stay's nights in words: 3–6 Nov, 3 nights. */
21
+ export const stayed = (s: { from: string; until: string }) => {
22
+ const n = dayOf(s.until) - dayOf(s.from);
23
+ return `${dated(dayOf(s.from), { day: "numeric", month: "short" })}–${dated(dayOf(s.until), { day: "numeric", month: "short" })}, ${n} ${n === 1 ? "night" : "nights"}`;
24
+ };
25
+ /** An event's hours, from its start for its length: 09:00–10:30. */
26
+ export const hours = (start: string, duration: string) =>
27
+ `${hhmm(wall(start))}–${hhmm(wall(start) + seconds(duration) * 1000)}`;
28
+ export const seconds = (d: string) => {
29
+ const [days = 0, h = 0, m = 0] = (/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?)?$/.exec(d) ?? [])
30
+ .slice(1)
31
+ .map((n) => Number(n ?? 0));
32
+ return ((days * 24 + h) * 60 + m) * 60;
33
+ };
34
+ /** The first of a day's month, and the Monday a month's grid starts on (its six weeks hold the whole month). */
35
+ export const firstOf = (day: number) => {
36
+ const d = new Date(day * DAY);
37
+ return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1) / DAY;
38
+ };
39
+ export const gridOf = (day: number) => mondayOf(firstOf(day));
40
+ /** Whether an event is on a day: it starts on it, or runs into it from before. */
41
+ export const on = (e: { start: string; duration: string }, day: number) => {
42
+ const from = wall(e.start);
43
+ return Math.floor(from / DAY) <= day && day * DAY < from + Math.max(1, seconds(e.duration)) * 1000;
44
+ };
45
+ export const iso = (mins: number) =>
46
+ `PT${Math.floor(mins / 60) ? `${Math.floor(mins / 60)}H` : ""}${mins % 60 ? `${mins % 60}M` : ""}`;