@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,234 @@
1
+ // The map, drawn by <calendar-map>: OpenStreetMap's tiles for its view, and a pin for each event at its place, made
2
+ // once, then only moved. Its view holds the places shown (the week's, or a phone's day's) at the closest zoom with
3
+ // room round the edge, until a person moves it, which is kept while that week is shown: dragged, it pans; it comes
4
+ // nearer and farther by its buttons, a pinch, or a trackpad's (the wheel with ctrl: the wheel alone scrolls the page).
5
+ // A press on a pin picks its event (on a phone, peeks it: ./peek.ts), a drag moves it (./drags.ts), and a press on
6
+ // its ground that isn't a drag is a tap there.
7
+
8
+ import type { JEvent } from "./generated/elements.ts";
9
+ import type { Drags } from "./drags.ts";
10
+ import type { Drawer } from "./drawer.ts";
11
+ import type { Peek } from "./peek.ts";
12
+ import type { Part } from "./shell.ts";
13
+ import { follow, held } from "joined/follow";
14
+ import { hueOf } from "joined/hues";
15
+ import { bounds, geo, placeAt, TILE, tileAt, world } from "./mercator.ts";
16
+
17
+ export const MAP_H = 320; // the map's least height: beside the calendar it's as tall as it
18
+ /** Where the map looks: its zoom, and the world's pixel at its top left. */
19
+ export type View = { z: number; x: number; y: number };
20
+ type Point = { x: number; y: number };
21
+
22
+ /** What the map reads from its display: the week and its view and size as drawn, and where a person moved it; the
23
+ * frame said again once they have; what a press does; and the drawer, whose events it draws as the form has them. */
24
+ type From = {
25
+ at: () => { week: number; view: View; W: number; H: number };
26
+ chose: { looked: { week: number; view: View } | null };
27
+ reframe: () => void;
28
+ phone: () => boolean;
29
+ pick: (el: JEvent) => void;
30
+ drags: () => Drags;
31
+ peek: () => Peek;
32
+ drawer: () => Drawer;
33
+ };
34
+
35
+ export class MapView {
36
+ readonly el: HTMLElement;
37
+ #pins = new Map<JEvent, HTMLElement>();
38
+ #tiles: HTMLElement;
39
+ #from: From;
40
+ #fingers = new Map<number, { clientX: number; clientY: number }>(); // on the map's ground, while it's pressed
41
+ #apart = 0; // how far apart two fingers were, at the pinch's last step
42
+
43
+ /** Drawn in its parts: its tiles, and its buttons nearer and farther. */
44
+ constructor($: Part, from: From) {
45
+ [this.el, this.#tiles, this.#from] = [$(".map"), $(".tiles"), from];
46
+ this.el.addEventListener(
47
+ "pointerdown",
48
+ (e) => !(e.target as Element).closest(".pin, a, button, .peek") && (from.peek().show(null), this.#ground(e)),
49
+ );
50
+ // nearer and farther: its buttons, a pinch, or a trackpad's (the wheel with ctrl); the wheel alone scrolls the page
51
+ $("[name=nearer]").addEventListener("click", () => this.#zoom(1));
52
+ $("[name=farther]").addEventListener("click", () => this.#zoom(-1));
53
+ let wheel = 0;
54
+ this.el.addEventListener(
55
+ "wheel",
56
+ (e) => {
57
+ if (!e.ctrlKey) return;
58
+ e.preventDefault();
59
+ wheel += e.deltaY;
60
+ if (Math.abs(wheel) < 40) return;
61
+ this.#zoom(wheel < 0 ? 1 : -1, this.#offset(e));
62
+ wheel = 0;
63
+ },
64
+ { passive: false },
65
+ );
66
+ }
67
+
68
+ /** Its view for a week: where a person moved it on that week; else the closest zoom that holds every place shown
69
+ * (or, none, the week's), with room round the edge: a place alone, its neighbourhood; none, where it was. */
70
+ fit(shown: JEvent[], events: JEvent[], week: number) {
71
+ const places = [shown, events]
72
+ .map((els) => els.map((el) => geo(el.data.coordinates)).filter((p) => p !== null))
73
+ .find((ps) => ps.length);
74
+ const W = this.el.clientWidth || 480,
75
+ H = this.el.clientHeight || MAP_H,
76
+ { view: was } = this.#from.at(),
77
+ { looked } = this.#from.chose;
78
+ let view: View = was.z ? was : { z: 2, x: 0, y: 0 };
79
+ if (looked?.week === week) view = looked.view;
80
+ else if (places)
81
+ for (let z = 13; z >= 1; z--) {
82
+ const pts = places.map((p) => world(p.lat, p.lng, z));
83
+ const [x0, x1, y0, y1] = bounds(pts);
84
+ view = { z, x: (x0 + x1) / 2 - W / 2, y: (y0 + y1) / 2 - H / 2 };
85
+ if (x1 - x0 <= W - 60 && y1 - y0 <= H - 60) break;
86
+ }
87
+ return { view, W, H };
88
+ }
89
+ /** Its tiles, for its view. */
90
+ draw() {
91
+ const { view, W, H } = this.#from.at();
92
+ const n = 2 ** view.z,
93
+ tiles: HTMLImageElement[] = [];
94
+ for (let tx = Math.floor(view.x / TILE); tx * TILE < view.x + W; tx++)
95
+ for (let ty = Math.max(0, Math.floor(view.y / TILE)); ty * TILE < view.y + H && ty < n; ty++) {
96
+ const img = Object.assign(document.createElement("img"), {
97
+ alt: "",
98
+ draggable: false,
99
+ src: tileAt(view.z, tx, ty),
100
+ });
101
+ img.style.left = `${tx * TILE - view.x}px`;
102
+ img.style.top = `${ty * TILE - view.y}px`;
103
+ tiles.push(img);
104
+ }
105
+ this.#tiles.replaceChildren(...tiles);
106
+ }
107
+
108
+ /** An event's pin at its place: made once, then only moved. */
109
+ place(el: JEvent, title: string, coordinates?: string) {
110
+ let pin = this.#pins.get(el);
111
+ if (!pin) {
112
+ const made = (pin = Object.assign(document.createElement("button"), { className: "pin", type: "button" }));
113
+ made.addEventListener("pointerdown", (e) =>
114
+ held(
115
+ e,
116
+ () => this.#from.drags().pin(el, e),
117
+ () => this.#ground(e, false),
118
+ () => (this.#from.phone() ? this.#from.peek().show(el) : this.#from.pick(el)),
119
+ ),
120
+ );
121
+ this.#pins.set(el, made);
122
+ }
123
+ pin.style.setProperty("--hue", hueOf(el.key));
124
+ pin.ariaLabel = title;
125
+ this.pinAt(pin, coordinates);
126
+ }
127
+ /** A pin at a place, as the map is drawn; no place, no pin. */
128
+ pinAt(pin: HTMLElement, coordinates?: string) {
129
+ const at = geo(coordinates);
130
+ if (at) this.where(pin, world(at.lat, at.lng, this.view.z));
131
+ else pin.remove();
132
+ }
133
+ /** A pin at a point in the world. */
134
+ where(pin: HTMLElement, p: Point) {
135
+ const { view } = this;
136
+ pin.style.left = `${p.x - view.x}px`;
137
+ pin.style.top = `${p.y - view.y}px`;
138
+ if (pin.parentNode !== this.el) this.el.append(pin);
139
+ }
140
+
141
+ /** Where it looks, as drawn. */
142
+ get view() {
143
+ return this.#from.at().view;
144
+ }
145
+ /** The point in the world under a pointer on the map. */
146
+ pointAt(e: PointerEvent) {
147
+ const r = this.el.getBoundingClientRect(),
148
+ { view } = this;
149
+ return { x: e.clientX - r.left + view.x, y: e.clientY - r.top + view.y };
150
+ }
151
+ /** The place at a point in the world, a geo: URI. */
152
+ placeOf = (p: Point) => placeAt(p.x, p.y, this.view.z);
153
+ /** The place at its middle, a typed place's search is near. */
154
+ near() {
155
+ const { view } = this;
156
+ return geo(placeAt(view.x + this.el.clientWidth / 2, view.y + this.el.clientHeight / 2, view.z))!;
157
+ }
158
+
159
+ /** The map's ground pressed: dragged, it pans; let go where it was pressed, it's a tap there (given one). A second
160
+ * finger down makes it a pinch, nearer as they part, farther as they close. */
161
+ #ground(down: PointerEvent, tap = true) {
162
+ this.#fingers.set(down.pointerId, down);
163
+ const [first, second] = [...this.#fingers.values()];
164
+ // a second finger: how far apart they came down, for the pinch the first finger's press follows
165
+ if (second)
166
+ return void (this.#apart = Math.hypot(first!.clientX - second.clientX, first!.clientY - second.clientY));
167
+ const was = { ...this.view };
168
+ let moved = false;
169
+ follow(
170
+ down,
171
+ (e) => {
172
+ if (!this.#fingers.has(e.pointerId)) return;
173
+ this.#fingers.set(e.pointerId, e);
174
+ const [a, b] = [...this.#fingers.values()];
175
+ if (b) {
176
+ // a pinch: a step nearer or farther each time the fingers part or close by half again
177
+ moved = true;
178
+ const d = Math.hypot(a!.clientX - b.clientX, a!.clientY - b.clientY);
179
+ if (d > this.#apart * 1.5 || d < this.#apart / 1.5) {
180
+ const mid = { clientX: (a!.clientX + b.clientX) / 2, clientY: (a!.clientY + b.clientY) / 2 };
181
+ this.#zoom(d > this.#apart ? 1 : -1, this.#offset(mid));
182
+ this.#apart = d;
183
+ }
184
+ return;
185
+ }
186
+ const dx = e.clientX - down.clientX,
187
+ dy = e.clientY - down.clientY;
188
+ if (!moved && Math.hypot(dx, dy) < 4) return;
189
+ moved = true;
190
+ this.look({ ...was, x: was.x - dx, y: was.y - dy });
191
+ },
192
+ (e) => {
193
+ this.#fingers.clear();
194
+ if (e && !moved && tap) this.#from.drags().tap(down);
195
+ },
196
+ );
197
+ }
198
+ /** Where a pointer is on the map. */
199
+ #offset(e: { clientX: number; clientY: number }) {
200
+ const r = this.el.getBoundingClientRect();
201
+ return { x: e.clientX - r.left, y: e.clientY - r.top };
202
+ }
203
+ /** The map a step nearer or farther, about a point on it (its middle, from its buttons). */
204
+ #zoom(by: 1 | -1, at = { x: this.el.clientWidth / 2, y: this.el.clientHeight / 2 }) {
205
+ const { view } = this,
206
+ z = Math.max(2, Math.min(18, view.z + by)),
207
+ k = 2 ** (z - view.z);
208
+ if (z !== view.z) this.look({ z, x: (view.x + at.x) * k - at.x, y: (view.y + at.y) * k - at.y });
209
+ }
210
+ /** The map where a person moved it: its tiles and its pins there, kept while this week is shown. */
211
+ look(view: View) {
212
+ this.#from.chose.looked = { week: this.#from.at().week, view };
213
+ this.#from.reframe();
214
+ this.draw();
215
+ const drawer = this.#from.drawer();
216
+ for (const [el, pin] of this.#pins) this.pinAt(pin, drawer.shown(el).coordinates);
217
+ drawer.repin();
218
+ }
219
+
220
+ /** An event's pin, if it's drawn. */
221
+ pinOf = (el: JEvent) => this.#pins.get(el);
222
+ /** The picked event's pin marked, the others not. */
223
+ mark(picked: JEvent | null) {
224
+ for (const [e, pin] of this.#pins) pin.toggleAttribute("picked", e === picked);
225
+ }
226
+ /** The peeked event's pin marked, the others not. */
227
+ peeked(el: JEvent | null) {
228
+ for (const [e, pin] of this.#pins) pin.toggleAttribute("peeked", e === el);
229
+ }
230
+ /** The pins of events no longer in `list` (gone, or on another week) taken away. */
231
+ drop(list: Node | null) {
232
+ for (const [el, pin] of this.#pins) if (el.parentNode !== list) (pin.remove(), this.#pins.delete(el));
233
+ }
234
+ }
@@ -0,0 +1,28 @@
1
+ // The trip's places: a geo: URI (geo:35.68,139.76), and Web Mercator, a place as pixels in the world drawn
2
+ // at zoom z in OpenStreetMap's 256px tiles, and back.
3
+
4
+ export const TILE = 256;
5
+
6
+ export const geo = (c?: string) => {
7
+ const m = /^geo:(-?[\d.]+),(-?[\d.]+)/.exec(c ?? "");
8
+ return m ? { lat: Number(m[1]), lng: Number(m[2]) } : null;
9
+ };
10
+ export const world = (lat: number, lng: number, z: number) => {
11
+ const size = TILE * 2 ** z,
12
+ sin = Math.sin((lat * Math.PI) / 180);
13
+ return { x: ((lng + 180) / 360) * size, y: (0.5 - Math.log((1 + sin) / (1 - sin)) / (4 * Math.PI)) * size };
14
+ };
15
+ export const placeAt = (x: number, y: number, z: number) => {
16
+ const size = TILE * 2 ** z,
17
+ lat = (Math.atan(Math.sinh(Math.PI * (1 - (2 * y) / size))) * 180) / Math.PI;
18
+ return `geo:${lat.toFixed(4)},${((x / size) * 360 - 180).toFixed(4)}`;
19
+ };
20
+ /** The box round some points, its least and most x and y: by a loop, as a spread of very many overflows the stack. */
21
+ export const bounds = (pts: { x: number; y: number }[]) => {
22
+ let [x0, x1, y0, y1] = [Infinity, -Infinity, Infinity, -Infinity];
23
+ for (const { x, y } of pts) [x0, x1, y0, y1] = [Math.min(x0, x), Math.max(x1, x), Math.min(y0, y), Math.max(y1, y)];
24
+ return [x0, x1, y0, y1] as const;
25
+ };
26
+ /** OpenStreetMap's tile at zoom z, column x (wrapped round the world, east and west) and row y. */
27
+ export const tileAt = (z: number, x: number, y: number) =>
28
+ `https://tile.openstreetmap.org/${z}/${((x % 2 ** z) + 2 ** z) % 2 ** z}/${y}.png`;
@@ -0,0 +1,7 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ createTable("events", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, start: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "start is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, duration: { type: "text", is: { type: "form", form: "^P(?=\\d|T\\d)(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?$", said: "duration is a length of time (PT2H30M)" } }, location: { type: "text", nullable: true, is: { type: "string", said: "location is a string" } }, coordinates: { type: "text", nullable: true, is: { type: "form", form: "^geo:-?(90(\\.0+)?|[1-8]?\\d(\\.\\d+)?),-?(180(\\.0+)?|(1[0-7]\\d|[1-9]?\\d)(\\.\\d+)?)$", said: "coordinates is a place (geo:lat,lon)" } }, trip: { type: "integer", to: { table: "trips", said: "trip is one of trips", held: ["event in trip links to it", "events in trip link to it"] } } }, strict: true, needs: { columns: ["title", "start", "duration"], said: "an event needs title (string), start (date-time), duration (duration); may have location (string), coordinates (place), people (ids in people)" } }),
6
+ createTable("events_people", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, people: { type: "integer", to: { table: "people", said: "people links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "people"]], strict: true, once: "people links to {people} already" }),
7
+ ];
@@ -0,0 +1,7 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { addColumn, guardTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ addColumn("events", "zone", { type: "text", nullable: true, is: { type: "form", form: "^(UTC|(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)(\\/[A-Za-z][A-Za-z0-9_+-]*){1,2})$", said: "zone is a time zone (Asia/Tokyo)" } }),
6
+ guardTable("events", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, start: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "start is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, duration: { type: "text", is: { type: "form", form: "^P(?=\\d|T\\d)(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?$", said: "duration is a length of time (PT2H30M)" } }, location: { type: "text", is: { type: "string", said: "location is a string" }, nullable: true }, coordinates: { type: "text", is: { type: "form", form: "^geo:-?(90(\\.0+)?|[1-8]?\\d(\\.\\d+)?),-?(180(\\.0+)?|(1[0-7]\\d|[1-9]?\\d)(\\.\\d+)?)$", said: "coordinates is a place (geo:lat,lon)" }, nullable: true }, zone: { type: "text", is: { type: "form", form: "^(UTC|(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)(\\/[A-Za-z][A-Za-z0-9_+-]*){1,2})$", said: "zone is a time zone (Asia/Tokyo)" }, nullable: true }, trip: { type: "integer", to: { table: "trips", said: "trip is one of trips", held: ["event in trip links to it", "events in trip link to it"] } } }, strict: true, needs: { columns: ["title", "start", "duration"], said: "an event needs title (string), start (date-time), duration (duration); may have location (string), coordinates (place), people (ids in people), zone (zone)" } }),
7
+ ];
@@ -0,0 +1,9 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable, guardTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ guardTable("events", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, start: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "start is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, duration: { type: "text", is: { type: "form", form: "^P(?=\\d|T\\d)(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?$", said: "duration is a length of time (PT2H30M)" } }, location: { type: "text", is: { type: "string", said: "location is a string" }, nullable: true }, coordinates: { type: "text", is: { type: "form", form: "^geo:-?(90(\\.0+)?|[1-8]?\\d(\\.\\d+)?),-?(180(\\.0+)?|(1[0-7]\\d|[1-9]?\\d)(\\.\\d+)?)$", said: "coordinates is a place (geo:lat,lon)" }, nullable: true }, zone: { type: "text", is: { type: "form", form: "^(UTC|(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)(\\/[A-Za-z][A-Za-z0-9_+-]*){1,2})$", said: "zone is a time zone (Asia/Tokyo)" }, nullable: true }, trip: { type: "integer", to: { table: "trips", said: "trip is one of trips", held: ["event in trip links to it", "events in trip link to it"] } } }, strict: true, needs: { columns: ["title", "start", "duration"], said: "an event needs title (string), start (date-time), duration (duration); may have location (string), coordinates (place), people (ids in people), zone (zone), asked (ids in people), keen (ids in people), declined (ids in people)" } }),
6
+ createTable("events_asked", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, asked: { type: "integer", to: { table: "people", said: "asked links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "asked"]], strict: true, once: "asked links to {asked} already" }),
7
+ createTable("events_declined", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, declined: { type: "integer", to: { table: "people", said: "declined links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "declined"]], strict: true, once: "declined links to {declined} already" }),
8
+ createTable("events_keen", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, keen: { type: "integer", to: { table: "people", said: "keen links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "keen"]], strict: true, once: "keen links to {keen} already" }),
9
+ ];
@@ -0,0 +1,6 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ createTable("stays", { columns: { name: { type: "text", is: { type: "string", said: "name is a string" } }, from: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "from is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, until: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "until is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, location: { type: "text", nullable: true, is: { type: "string", said: "location is a string" } }, coordinates: { type: "text", nullable: true, is: { type: "form", form: "^geo:-?(90(\\.0+)?|[1-8]?\\d(\\.\\d+)?),-?(180(\\.0+)?|(1[0-7]\\d|[1-9]?\\d)(\\.\\d+)?)$", said: "coordinates is a place (geo:lat,lon)" } }, trip: { type: "integer", to: { table: "trips", said: "trip is one of trips", held: ["stay in trip links to it", "stays in trip link to it"] } } }, strict: true, needs: { columns: ["name", "from", "until"], said: "a stay needs name (string), from (date-time), until (date-time); may have location (string), coordinates (place)" } }),
6
+ ];
@@ -0,0 +1,8 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable, guardTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ guardTable("events", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, start: { type: "text", is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "start is a date and time (YYYY-MM-DDTHH:MM:SS)" } }, duration: { type: "text", is: { type: "form", form: "^P(?=\\d|T\\d)(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?$", said: "duration is a length of time (PT2H30M)" } }, location: { type: "text", is: { type: "string", said: "location is a string" }, nullable: true }, coordinates: { type: "text", is: { type: "form", form: "^geo:-?(90(\\.0+)?|[1-8]?\\d(\\.\\d+)?),-?(180(\\.0+)?|(1[0-7]\\d|[1-9]?\\d)(\\.\\d+)?)$", said: "coordinates is a place (geo:lat,lon)" }, nullable: true }, zone: { type: "text", is: { type: "form", form: "^(UTC|(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)(\\/[A-Za-z][A-Za-z0-9_+-]*){1,2})$", said: "zone is a time zone (Asia/Tokyo)" }, nullable: true }, trip: { type: "integer", to: { table: "trips", said: "trip is one of trips", held: ["event in trip links to it", "events in trip link to it"] } } }, strict: true, needs: { columns: ["title", "start", "duration"], said: "an event needs title (string), start (date-time), duration (duration); may have location (string), coordinates (place), people (ids in people), zone (zone), asked (ids in people), keen (ids in people), declined (ids in people), arrives (ids in people), leaves (ids in people)" } }),
6
+ createTable("events_arrives", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, arrives: { type: "integer", to: { table: "people", said: "arrives links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "arrives"]], strict: true, once: "arrives links to {arrives} already" }),
7
+ createTable("events_leaves", { columns: { events: { type: "integer", to: { table: "events", said: "events is one of events", onDelete: "cascade" } }, leaves: { type: "integer", to: { table: "people", said: "leaves links only to people the people document holds", held: ["event in trip links to it", "events in trip link to it"] } } }, unique: [["events", "leaves"]], strict: true, once: "leaves links to {leaves} already" }),
8
+ ];
@@ -0,0 +1,87 @@
1
+ // The trip read as a month, drawn by <calendar-map> (view="month") beside its map: a grid of the month's six weeks,
2
+ // held as one window of the trip's events, the month's own days in ink and the rest muted; on each day its events by
3
+ // when they start, a chip each (its time and title, its hue), a tap picking it. On a phone, too narrow for its events'
4
+ // words, a tap on a day opens that day in the calendar. A day is made again only when what it shows has changed.
5
+
6
+ import type { JEvent } from "./generated/elements.ts";
7
+ import type { Part } from "./shell.ts";
8
+ import { keep } from "joined/keep";
9
+ import { hueOf } from "joined/hues";
10
+ import { DAY, dated, dayOf, firstOf, hhmm, mondayOf, wall } from "./time.ts";
11
+
12
+ /** What the month reads from its display: the Monday its grid starts on, its events and the one picked, how to pick
13
+ * one, whether it's on a phone and the day a phone's calendar shows; and how to read a week as a calendar instead. */
14
+ type From = {
15
+ at: () => { week: number };
16
+ events: () => JEvent[];
17
+ picked: () => JEvent | null;
18
+ pick: (el: JEvent) => void;
19
+ phone: () => boolean;
20
+ chose: { day: number; dayWeek: number | null };
21
+ readAs: (view: "calendar") => void;
22
+ hold: (by: "week" | "month", day: number) => void;
23
+ };
24
+
25
+ export class Month {
26
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
27
+ #cells: HTMLElement;
28
+ #from: From;
29
+
30
+ /** Drawn in its cells, a day each. */
31
+ constructor($: Part, from: From) {
32
+ [this.#cells, this.#from] = [$(".month .cells"), from];
33
+ }
34
+
35
+ draw() {
36
+ const { week } = this.#from.at(),
37
+ picked = this.#from.picked(),
38
+ first = firstOf(week + 7),
39
+ month = new Date(first * DAY).getUTCMonth(),
40
+ byDay = new Map<number, JEvent[]>();
41
+ for (const el of this.#from.events()) {
42
+ const d = dayOf(el.data.start);
43
+ (byDay.get(d) ?? byDay.set(d, []).get(d)!).push(el);
44
+ }
45
+ keep(
46
+ this.#cells,
47
+ this.#kept,
48
+ Array.from({ length: 42 }, (_, i) => {
49
+ const day = week + i,
50
+ ours = new Date(day * DAY).getUTCMonth() === month,
51
+ theirs = (byDay.get(day) ?? []).sort((a, b) => a.data.start.localeCompare(b.data.start));
52
+ const said = theirs.map((el) => [el.key, hhmm(wall(el.data.start)), el.data.title, el === picked]);
53
+ return {
54
+ key: String(day),
55
+ shows: JSON.stringify([ours, said]),
56
+ make: () => {
57
+ const cell = Object.assign(document.createElement("div"), { className: ours ? "day" : "day other" });
58
+ // on a phone, too narrow for its events' words: a tap on a day is that day, in the calendar
59
+ cell.addEventListener("click", () => this.#from.phone() && this.#open(day));
60
+ cell.append(Object.assign(document.createElement("span"), { textContent: dated(day, { day: "numeric" }) }));
61
+ for (const el of theirs) {
62
+ const b = Object.assign(document.createElement("button"), {
63
+ type: "button",
64
+ className: "entry",
65
+ textContent: `${hhmm(wall(el.data.start))} ${el.data.title}`,
66
+ });
67
+ b.style.setProperty("--hue", hueOf(el.key));
68
+ b.toggleAttribute("picked", el === picked);
69
+ b.addEventListener("click", () => this.#from.pick(el));
70
+ cell.append(b);
71
+ }
72
+ return cell;
73
+ },
74
+ };
75
+ }),
76
+ );
77
+ }
78
+
79
+ /** A day of the month opened, on a phone: the calendar of its week, on that day. */
80
+ #open(day: number) {
81
+ const week = mondayOf(day),
82
+ { chose } = this.#from;
83
+ [chose.day, chose.dayWeek] = [day - week, week];
84
+ this.#from.readAs("calendar");
85
+ this.#from.hold("week", week);
86
+ }
87
+ }
@@ -0,0 +1,67 @@
1
+ // The trip's other weeks, beneath <calendar-map>'s week: how many events they hold, and a way to each, from its
2
+ // <j-weeks> (../weeks), a live list. Hidden when there are none, and when it's read as a month, which shows them.
3
+
4
+ import type { JWeek } from "../weeks/generated/elements.ts";
5
+ import type { Part } from "./shell.ts";
6
+ import { keep, type Row } from "joined/keep";
7
+ import { collections as weeks } from "../weeks/generated/rules.ts";
8
+ import { DAY, dated, dayOf, local } from "./time.ts";
9
+
10
+ /** What it reads from its display: the trip held, the week shown, whether it's read as a month, and how to go to a
11
+ * week. */
12
+ type From = {
13
+ held: () => { trip: number };
14
+ at: () => { week: number };
15
+ monthly: () => boolean;
16
+ go: (week: number) => void;
17
+ };
18
+
19
+ export class OtherWeeks {
20
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
21
+ #weeks: HTMLCollectionOf<JWeek>;
22
+ #p: HTMLElement;
23
+ #from: From;
24
+
25
+ /** Drawn in its paragraph, from the weeks `host` holds. */
26
+ constructor(host: HTMLElement, $: Part, from: From) {
27
+ this.#weeks = host.getElementsByTagName(weeks.weeks.tag) as HTMLCollectionOf<JWeek>;
28
+ [this.#p, this.#from] = [$(".others"), from];
29
+ }
30
+
31
+ draw() {
32
+ const p = this.#p,
33
+ { trip } = this.#from.held(),
34
+ { week } = this.#from.at(),
35
+ shown = local(week * DAY).slice(0, 10),
36
+ year = dated(week, { year: "numeric" });
37
+ const held = [...this.#weeks].map((w) => w.data).filter((w) => w.trip === trip && w.week !== shown);
38
+ const n = held.reduce((sum, w) => sum + w.events, 0);
39
+ p.hidden = !n || this.#from.monthly(); // a month's are on it
40
+ const rows: Row[] = held.map((w) => {
41
+ const monday = dayOf(w.week),
42
+ on = dated(monday, { year: "numeric" }) === year ? {} : { year: "numeric" as const },
43
+ says = `${dated(monday, { day: "numeric", month: "short", ...on })} (${w.events})`;
44
+ return {
45
+ key: w.week,
46
+ shows: says,
47
+ make: () => {
48
+ const go = Object.assign(document.createElement("button"), {
49
+ type: "button",
50
+ className: "act small",
51
+ textContent: says,
52
+ });
53
+ go.ariaLabel = `The week of ${dated(monday, { day: "numeric", month: "long", year: "numeric" })}`;
54
+ go.addEventListener("click", () => this.#from.go(monday));
55
+ return go;
56
+ },
57
+ };
58
+ });
59
+ const says = `${n} ${n === 1 ? "event" : "events"} in ${held.length === 1 ? "another week" : "other weeks"}: `;
60
+ const said = {
61
+ key: "said",
62
+ shows: says,
63
+ make: () => Object.assign(document.createElement("span"), { textContent: says }),
64
+ };
65
+ keep(p, this.#kept, n ? [said, ...rows] : []);
66
+ }
67
+ }
@@ -0,0 +1,121 @@
1
+ // A trip's page, at /trip/<key>: it holds its documents by having their collections on it: a week of the trip's
2
+ // events, <j-events>, and its weeks, <j-weeks> (../weeks), inside <calendar-map>, which draws them, the week as a
3
+ // calendar, a line (?view=line) or a month (?view=month) beside a map; and <j-people>, in a sheet, whose <j-person>s draw themselves (the
4
+ // people's own view, ../people/view.ts). The events are the trip's own, trip:<key>, one of the trips (../trips), a
5
+ // week of it: trip:1?week=2026-11-02, the week its address names (?week=), or, none named, the week with today in it
6
+ // while the trip is on, else its first; another week, as the calendar asks (a "week" event), is held in place of it.
7
+ // An event links to people by their keys. A .ics file coming in is events to add, sent as any other write; the whole
8
+ // trip goes out as /trip/<key>/trip.ics. The trips (../trips) are held too, for this trip's name, the page's.
9
+
10
+ import { fromIcs } from "./ics.ts";
11
+ import "../people/view.ts";
12
+ import { addingPeople } from "../people/adding.ts";
13
+ import { booking } from "./stays.ts";
14
+ import "./calendar-map.ts";
15
+ import "joined/panel";
16
+ import "joined/toast";
17
+ import { iconify } from "joined/icons";
18
+ import { said, showsOpen } from "joined/parts";
19
+ import { JWeek } from "../weeks/generated/elements.ts";
20
+ import { JEvent, type JEvents } from "./generated/elements.ts";
21
+ import { JTrip } from "../trips/generated/elements.ts";
22
+ import * as trips from "../trips/generated/rules.ts";
23
+ import * as trip from "./generated/rules.ts";
24
+ import * as weeks from "../weeks/generated/rules.ts";
25
+ import { DAY, dayOf, gridOf, local, now, wall, weekOf } from "./time.ts";
26
+
27
+ const key = location.pathname.split("/").filter(Boolean).at(-1);
28
+ document.querySelector<HTMLAnchorElement>("a[download]")!.href = `/trip/${key}/trip.ics`;
29
+
30
+ const cal = document.querySelector("calendar-map")!;
31
+ /** What the page's address says: the week held, and how it's read (a calendar, ?view=line or ?view=month); and what
32
+ * it no longer says, taken off. */
33
+ function address(name: string, value: string, off?: string) {
34
+ const url = new URL(location.href);
35
+ url.searchParams.set(name, value);
36
+ if (off) url.searchParams.delete(off);
37
+ history.replaceState(history.state, "", url);
38
+ }
39
+ /** A week of the trip held, or a month (six weeks from the Monday its grid starts on), in place of what was held
40
+ * before, and named in the page's address. */
41
+ function hold(by: "week" | "month", day: string) {
42
+ const events = document.createElement(trip.collections.events.place);
43
+ events.setAttribute("doc", `trip:${key}?${by}=${day}`);
44
+ const was = cal.querySelector(trip.collections.events.place);
45
+ if (was) was.replaceWith(events);
46
+ else cal.append(events);
47
+ // its stays, all of them, held as the same document: its window is the events'
48
+ const stays = document.createElement(trip.collections.stays.place);
49
+ stays.setAttribute("doc", `trip:${key}?${by}=${day}`);
50
+ const had = document.querySelector(trip.collections.stays.place);
51
+ if (had) had.replaceWith(stays);
52
+ else document.querySelector("#stays header")!.after(stays);
53
+ address(by, day, by === "week" ? "month" : "week");
54
+ }
55
+ /** A week held as the page reads it: as a month, the month it's in. */
56
+ const holdWeek = (week: string) =>
57
+ cal.getAttribute("view") === "month"
58
+ ? hold("month", local(gridOf(dayOf(week) + 3) * DAY).slice(0, 10))
59
+ : hold("week", week);
60
+ cal.addEventListener("week", (e) => hold("week", (e as CustomEvent<string>).detail));
61
+ cal.addEventListener("month", (e) => hold("month", (e as CustomEvent<string>).detail));
62
+ // the week read as a line or the month, if its address says so; another reading chosen, said there
63
+ const view = new URLSearchParams(location.search).get("view");
64
+ if (view === "line" || view === "month") cal.setAttribute("view", view);
65
+ cal.addEventListener("view", (e) => address("view", (e as CustomEvent<string>).detail));
66
+ const params = new URLSearchParams(location.search),
67
+ asked = params.get("week") ?? params.get("month") ?? "";
68
+ if (/^\d{4}-\d{2}-\d{2}$/.test(asked) && Number.isFinite(wall(`${asked}T00:00:00`)))
69
+ // a month is named by the Monday its grid starts on, which may be the month before's: a week on, it's the month's
70
+ params.has("month") && cal.getAttribute("view") === "month"
71
+ ? hold("month", local(gridOf(dayOf(asked) + 7) * DAY).slice(0, 10))
72
+ : holdWeek(weekOf(asked));
73
+ else {
74
+ // none named: once the trip's weeks are here, today's (where the person is) while the trip is on, else its first;
75
+ // no weeks, today's
76
+ const opening = () => {
77
+ const today = weekOf(now()),
78
+ held = [...document.getElementsByTagName(weeks.collections.weeks.tag)]
79
+ .map((w) => (w as JWeek).data)
80
+ .filter((w) => String(w.trip) === key);
81
+ holdWeek(held.length && !(today >= held[0]!.week && today <= held.at(-1)!.week) ? held[0]!.week : today);
82
+ };
83
+ if (document.body.dataset.weeks !== undefined) opening();
84
+ else
85
+ new MutationObserver((_, seen) => {
86
+ if (document.body.dataset.weeks === undefined) return;
87
+ seen.disconnect();
88
+ opening();
89
+ }).observe(document.body, { attributeFilter: ["data-weeks"] });
90
+ }
91
+ iconify();
92
+ showsOpen(document);
93
+
94
+ const line = document.querySelector("#said")!;
95
+ const file = document.querySelector<HTMLInputElement>("input[type=file]")!;
96
+ file.addEventListener("change", async () => {
97
+ const events = fromIcs((await file.files?.[0]?.text()) ?? "");
98
+ if (events.length) said(line, document.querySelector<JEvents>(trip.collections.events.place)!.add(...events));
99
+ else line.textContent = "No events in that file.";
100
+ file.value = "";
101
+ });
102
+ addingPeople(document.querySelector("#people form")!);
103
+ booking(document.querySelector("#stays form")!);
104
+
105
+ // defined last, once all they draw with is made
106
+ customElements.define(trip.collections.events.tag, JEvent);
107
+ customElements.define(weeks.collections.weeks.tag, JWeek);
108
+ // this trip, of the trips: its name is the page's
109
+ customElements.define(
110
+ trips.collections.trips.tag,
111
+ class extends JTrip {
112
+ connectedCallback() {
113
+ this.draw();
114
+ }
115
+ draw() {
116
+ if (String(this.key) !== key) return;
117
+ document.querySelector(".trip-name")!.textContent = this.data.name;
118
+ document.title = `${this.data.name}: joined`;
119
+ }
120
+ },
121
+ );