@blueshed/joined 0.0.0-stage → 0.1.19

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 +51 -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
package/src/parts.css ADDED
@@ -0,0 +1,471 @@
1
+ /* joined's parts, once: fewer's tool, field, label, drawer, modal and sheet (docs/design.md, "The parts").
2
+ Adopted by the page and by every display's shadow (src/parts.ts), so a part looks the same wherever
3
+ it's drawn; never linked, and never a part's look written beside it (its own sheet says only how it
4
+ sits, or what it alone has). Its colours are src/tokens.css's.
5
+
6
+ .act a button with words, its icon before them: 13px, 32px tall (44px under a finger)
7
+ .ink the one that makes or keeps (Add, Save)
8
+ .danger the one that takes away: its words red; in a dialog, the answer, filled
9
+ .quiet a way out, its words alone (Sign out)
10
+ .icon-only a harmless action, its icon alone, its words its label (src/icons.ts)
11
+ .small a lesser tool among words, its words small
12
+ .j-tabs one of a few, side by side
13
+ .j-choices a list to pick one from, each a row
14
+ .j-face a person: their initial in their hue; empty, their dot
15
+ .j-chips people as chips, a face and a name each; a button one toggles (.j-chip, one shown)
16
+ .j-file a file field: its picture or its PDF's link, a way to choose one, and to take it off
17
+ a field every input and select (a box to tick aside), as tall as a tool beside it, its words 16px
18
+ (or a phone zooms in); a textarea the same, taller. A field drawn otherwise (a name changed
19
+ in place) says so in its own sheet: these weigh nothing, so any rule there wins.
20
+ a label over its field: 13px, 600, in plain case
21
+ .drawer where a thing is changed: docked at the right, 320px; on a phone a sheet from the foot.
22
+ Its head the thing's name (h2, 17px) and its ×; its deeds at its foot, removing first.
23
+ dialog a modal, new or delete: its title (h2, 17px) and its × if it has one, a line saying what
24
+ follows, its deeds. A drawer rises in 200ms, a modal in 160ms; under reduced motion, neither
25
+ .sheet a popover that holds a list (the group, People): its head a title and its ×; on a phone,
26
+ a sheet from the foot */
27
+
28
+ .act {
29
+ box-sizing: border-box;
30
+ min-height: 32px;
31
+ display: inline-flex;
32
+ align-items: center;
33
+ justify-content: center;
34
+ gap: 6px;
35
+ padding: 0 12px;
36
+ border: 1px solid var(--ink);
37
+ border-radius: 4px;
38
+ background: var(--card);
39
+ color: var(--ink);
40
+ font: var(--font-tool);
41
+ white-space: nowrap;
42
+ cursor: pointer;
43
+ }
44
+ .act.ink {
45
+ border-color: var(--add);
46
+ background: var(--add);
47
+ color: var(--add-ink);
48
+ }
49
+ .act.ink:hover {
50
+ background: var(--add-hover);
51
+ }
52
+ .act.danger {
53
+ border-color: var(--danger);
54
+ color: var(--danger);
55
+ }
56
+ dialog .act.danger {
57
+ background: var(--danger);
58
+ color: var(--danger-ink);
59
+ }
60
+ /* what is open (a popover, a sheet), or chosen of a pair (a view), fills with accent, its words in card, while it is */
61
+ .act:is([aria-expanded="true"], [aria-pressed="true"]) {
62
+ border-color: var(--accent);
63
+ background: var(--accent);
64
+ color: var(--card);
65
+ }
66
+ .act.quiet {
67
+ border-color: transparent;
68
+ background: none;
69
+ padding: 0 4px;
70
+ color: var(--muted);
71
+ }
72
+ .icon-only {
73
+ box-sizing: border-box;
74
+ width: 32px;
75
+ height: 32px;
76
+ display: inline-flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ flex: none;
80
+ padding: 0;
81
+ border: 0;
82
+ border-radius: 4px;
83
+ background: none;
84
+ color: var(--muted);
85
+ cursor: pointer;
86
+ }
87
+ .icon-only:hover,
88
+ .icon-only:focus-visible {
89
+ color: var(--ink);
90
+ background: color-mix(in srgb, var(--ink) 6%, transparent);
91
+ }
92
+ /* a tool that is its icon alone, filled (the group's Invite) */
93
+ .act.icon-only {
94
+ min-height: 0;
95
+ padding: 0;
96
+ }
97
+ .act.ink.icon-only {
98
+ color: var(--add-ink);
99
+ }
100
+ /* chosen, it stays filled under the pointer and the keys (the group's invite, read-only) */
101
+ .act.icon-only[aria-pressed="true"] {
102
+ background: var(--accent);
103
+ color: var(--card);
104
+ }
105
+ :is(.act, .icon-only) > svg.icon {
106
+ margin: 0;
107
+ }
108
+ :is(.act, .icon-only):disabled {
109
+ opacity: 0.45;
110
+ cursor: default;
111
+ }
112
+ /* a lesser tool among words, its words small: a way to what links here, to another week */
113
+ .act.small {
114
+ min-height: 24px;
115
+ padding: 0 8px;
116
+ border-color: var(--control-edge);
117
+ font: var(--font-small);
118
+ }
119
+ .act.small:hover {
120
+ background: var(--card-hover);
121
+ }
122
+
123
+ /* .j-tabs: one of a few, side by side in a well, the chosen raised on card (the group's People and Agents) */
124
+ .j-tabs {
125
+ display: flex;
126
+ gap: 4px;
127
+ padding: 2px;
128
+ border: 1px solid var(--edge);
129
+ border-radius: 4px;
130
+ background: var(--paper);
131
+ }
132
+ .j-tabs > button {
133
+ flex: 1;
134
+ display: inline-flex;
135
+ align-items: center;
136
+ justify-content: center;
137
+ min-height: 28px;
138
+ border: 0;
139
+ border-radius: 3px;
140
+ background: none;
141
+ color: var(--muted);
142
+ font: var(--font-small);
143
+ cursor: pointer;
144
+ }
145
+ .j-tabs > [aria-selected="true"] {
146
+ background: var(--card);
147
+ color: var(--ink);
148
+ font-weight: 600;
149
+ box-shadow: 0 0 0 1px var(--edge);
150
+ }
151
+
152
+ /* .j-choices: a list to pick one from, each a row's words, tinted under the pointer (places found, a row's
153
+ menu); the one that takes away last, apart, in red */
154
+ .j-choices {
155
+ display: grid;
156
+ }
157
+ /* a list in a popover (a row's menu) shows only while it's open */
158
+ .j-choices[popover]:not(:popover-open) {
159
+ display: none;
160
+ }
161
+ .j-choices > button {
162
+ box-sizing: border-box;
163
+ min-height: 32px;
164
+ display: flex;
165
+ align-items: center;
166
+ gap: 6px;
167
+ padding: 4px 8px;
168
+ border: 0;
169
+ border-radius: 3px;
170
+ background: none;
171
+ color: var(--ink);
172
+ font: var(--font-row);
173
+ text-align: left;
174
+ cursor: pointer;
175
+ }
176
+ .j-choices > button:is(:hover, :focus-visible) {
177
+ background: color-mix(in srgb, var(--ink) 6%, transparent);
178
+ }
179
+ .j-choices > button.danger {
180
+ margin-top: 4px;
181
+ border-top: 1px solid var(--line);
182
+ border-radius: 0 0 3px 3px;
183
+ color: var(--danger);
184
+ }
185
+
186
+ /* a person (Identity): their face, their initial on a tint of their hue in a ring of it; with no initial, their
187
+ dot (on an event's block). A chip is a face and a name: on (the event's, the line's reader) a tint of the hue
188
+ over card and a 3px stripe of it, words in ink; off, a plain control. Never solid with white words. */
189
+ .j-face {
190
+ box-sizing: border-box;
191
+ flex: none;
192
+ display: inline-grid;
193
+ place-items: center;
194
+ width: 22px;
195
+ height: 22px;
196
+ border: 2px solid var(--hue);
197
+ border-radius: 50%;
198
+ background: color-mix(in srgb, var(--hue) var(--tint-strong), var(--card));
199
+ color: var(--ink);
200
+ font: var(--font-tiny);
201
+ font-weight: 600;
202
+ font-style: normal;
203
+ }
204
+ .j-face::before {
205
+ content: attr(data-initial);
206
+ }
207
+ .j-face:not([data-initial]) {
208
+ width: 7px;
209
+ height: 7px;
210
+ border: 0;
211
+ background: var(--hue);
212
+ }
213
+ .j-chips {
214
+ display: flex;
215
+ flex-wrap: wrap;
216
+ align-items: center;
217
+ gap: 6px;
218
+ }
219
+ :is(.j-chip, .j-chips > button) {
220
+ box-sizing: border-box;
221
+ display: inline-flex;
222
+ align-items: center;
223
+ gap: 6px;
224
+ min-height: 32px;
225
+ padding: 0 10px 0 4px;
226
+ border: 1px solid var(--control-edge);
227
+ border-radius: 4px;
228
+ background: var(--card);
229
+ color: var(--muted);
230
+ font: var(--font-tool);
231
+ }
232
+ .j-chips > button {
233
+ cursor: pointer;
234
+ }
235
+ /* one that can be taken off: its × at its end */
236
+ .j-chip > .icon-only {
237
+ width: 24px;
238
+ height: 24px;
239
+ margin-right: -6px;
240
+ }
241
+ :is(.j-chip, .j-chips > button[aria-pressed="true"]) {
242
+ border-color: transparent;
243
+ border-left: 3px solid var(--hue);
244
+ background: color-mix(in srgb, var(--hue) var(--tint), var(--card));
245
+ color: var(--ink);
246
+ }
247
+ .j-chips > button[aria-pressed="true"]:hover {
248
+ background: color-mix(in srgb, var(--hue) var(--tint-strong), var(--card));
249
+ }
250
+
251
+ :where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"]), select, textarea) {
252
+ box-sizing: border-box;
253
+ min-height: 32px;
254
+ min-width: 0;
255
+ padding: 0 10px;
256
+ border: 1px solid var(--control-edge);
257
+ border-radius: 4px;
258
+ background: var(--card);
259
+ color: var(--ink);
260
+ font: var(--font-field);
261
+ }
262
+ :where(textarea) {
263
+ min-height: 4.5rem;
264
+ padding: 8px 10px;
265
+ resize: vertical;
266
+ }
267
+ :where(form, dialog) label {
268
+ display: grid;
269
+ gap: 4px;
270
+ font: var(--font-label);
271
+ }
272
+
273
+ /* a request's refusal, said beside what sent it (Said): its why in danger; nothing while there's none */
274
+ .said {
275
+ margin: 0;
276
+ font: var(--font-small);
277
+ color: var(--danger);
278
+ }
279
+ .said:empty {
280
+ display: none;
281
+ }
282
+
283
+ /* .j-file: a file field (Attachment, src/attachment.ts): its picture, the width of what holds it, or a link to its
284
+ PDF; then a small tool to choose one, its file input inside it, and the × that takes it off */
285
+ .j-file {
286
+ display: flex;
287
+ flex-wrap: wrap;
288
+ align-items: center;
289
+ gap: 8px;
290
+ }
291
+ .j-file > [hidden] {
292
+ display: none;
293
+ }
294
+ .j-file > a.act {
295
+ text-decoration: none;
296
+ }
297
+ .j-file-picture {
298
+ flex: 1 0 100%;
299
+ display: block;
300
+ }
301
+ .j-file-picture > img {
302
+ display: block;
303
+ box-sizing: border-box;
304
+ width: 100%;
305
+ max-height: 240px;
306
+ object-fit: cover;
307
+ border: 1px solid var(--edge);
308
+ border-radius: 4px;
309
+ }
310
+ .j-file label {
311
+ position: relative;
312
+ }
313
+ .j-file label:focus-within {
314
+ outline: 2px solid var(--accent);
315
+ }
316
+ .j-file input[type="file"] {
317
+ position: absolute;
318
+ width: 1px;
319
+ height: 1px;
320
+ opacity: 0;
321
+ }
322
+
323
+ /* the surfaces: the drawer, the modal and the sheet, each a card in a 1px edge, 4px corners, no shadow */
324
+ :where(.drawer, dialog, .sheet) {
325
+ box-sizing: border-box;
326
+ border: 1px solid var(--edge);
327
+ border-radius: 4px;
328
+ background: var(--card);
329
+ color: var(--ink);
330
+ font: var(--font-row);
331
+ }
332
+ :where(.drawer, .sheet, dialog) h2 {
333
+ flex: 1;
334
+ margin: 0;
335
+ font: var(--font-title);
336
+ }
337
+ :where(.drawer, .sheet, dialog) header {
338
+ display: flex;
339
+ align-items: center;
340
+ gap: 8px;
341
+ }
342
+ /* its head and its foot always show, what it is and what you may do: only what's between them scrolls (each to its
343
+ surface's edge, over what scrolls under it, a band of its card between; held past its padding, which a held thing
344
+ stops at, its foot past --pad-end, the padding at its foot where that's more) */
345
+ :where(.drawer, .sheet, dialog) > :is(header, h2):first-child,
346
+ :where(.drawer, .sheet, dialog) > form > header:first-child {
347
+ position: sticky;
348
+ top: calc(-1 * var(--pad));
349
+ z-index: 1;
350
+ margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) 0;
351
+ padding: var(--pad) var(--pad) var(--space-8);
352
+ background: var(--card);
353
+ }
354
+ :where(.drawer, .sheet, dialog) footer {
355
+ position: sticky;
356
+ bottom: calc(-1 * var(--pad-end, var(--pad)));
357
+ z-index: 1;
358
+ margin: 0 calc(-1 * var(--pad)) calc(-1 * var(--pad-end, var(--pad)));
359
+ padding: var(--space-8) var(--pad) var(--pad-end, var(--pad));
360
+ background: var(--card);
361
+ display: flex;
362
+ flex-wrap: wrap;
363
+ justify-content: flex-end;
364
+ gap: 8px;
365
+ }
366
+ /* removing stands apart, first at the foot */
367
+ :where(.drawer, .sheet, dialog) footer > .danger:first-child {
368
+ margin-right: auto;
369
+ }
370
+ .drawer {
371
+ position: fixed;
372
+ inset: 0 0 0 auto;
373
+ z-index: 15;
374
+ width: min(320px, 100vw);
375
+ overflow: auto;
376
+ --pad: 14px;
377
+ padding: var(--pad);
378
+ border-width: 0 0 0 1px;
379
+ border-radius: 0;
380
+ }
381
+ /* its one column no wider than it, where a scrollbar takes room too (Windows, Linux): a field's least width would
382
+ push it sideways */
383
+ :where(.drawer, .sheet, dialog) form {
384
+ display: grid;
385
+ grid-template-columns: minmax(0, 1fr);
386
+ gap: 12px;
387
+ }
388
+ dialog {
389
+ width: min(25rem, calc(100vw - 2rem));
390
+ --pad: 20px;
391
+ padding: var(--pad);
392
+ }
393
+ dialog[open] {
394
+ display: grid;
395
+ gap: 14px;
396
+ }
397
+ dialog::backdrop {
398
+ background: var(--scrim);
399
+ }
400
+ dialog p {
401
+ margin: 0;
402
+ font: var(--font-small);
403
+ color: var(--muted);
404
+ }
405
+ .sheet {
406
+ width: min(22rem, calc(100vw - 2rem));
407
+ max-height: calc(100dvh - 2rem);
408
+ overflow: auto;
409
+ --pad: 12px;
410
+ padding: var(--pad);
411
+ /* its one column no wider than it: a field (your name, changed in place) would stretch it past its edge */
412
+ grid-template-columns: minmax(0, 1fr);
413
+ }
414
+ .sheet:popover-open {
415
+ display: grid;
416
+ gap: 10px;
417
+ }
418
+
419
+ /* motion: a drawer rises into place in 200ms, a modal in 160ms; nothing else moves, and under
420
+ prefers-reduced-motion nothing does */
421
+ @media (prefers-reduced-motion: no-preference) {
422
+ .drawer {
423
+ animation: rise 200ms ease-out;
424
+ }
425
+ dialog[open] {
426
+ animation: rise 160ms ease-out;
427
+ }
428
+ }
429
+ @keyframes rise {
430
+ from {
431
+ opacity: 0;
432
+ transform: translateY(8px);
433
+ }
434
+ }
435
+
436
+ /* on a phone: the drawer and a sheet rise from the foot, the width of the screen */
437
+ @media (max-width: 40rem) {
438
+ :is(.drawer, .sheet) {
439
+ inset: auto 0 0;
440
+ width: auto;
441
+ max-height: 85dvh;
442
+ overflow: auto;
443
+ margin: 0;
444
+ border-width: 1px 0 0;
445
+ border-radius: 4px 4px 0 0;
446
+ --pad-end: calc(14px + env(safe-area-inset-bottom));
447
+ padding-bottom: var(--pad-end);
448
+ }
449
+ .drawer {
450
+ max-height: 70dvh;
451
+ }
452
+ }
453
+ @media (max-width: 40rem), (pointer: coarse) {
454
+ .act,
455
+ :where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"]), select) {
456
+ min-height: 44px;
457
+ }
458
+ .icon-only {
459
+ width: 44px;
460
+ height: 44px;
461
+ }
462
+ :is(.j-choices, .j-chips) > button,
463
+ .j-chip:has(> .icon-only) {
464
+ min-height: 44px;
465
+ }
466
+ .j-chip > .icon-only {
467
+ width: 44px;
468
+ height: 44px;
469
+ margin-right: -10px;
470
+ }
471
+ }
package/src/parts.ts ADDED
@@ -0,0 +1,152 @@
1
+ // joined's parts (src/parts.css), one sheet: the page adopts it as this is first imported, and a
2
+ // display adopts it in its shadow, before its own. A display or the group imports this; a page holding the group
3
+ // needn't, unless it wants a part's behaviour (the page's line said, a modal that asks first, a button showing it's
4
+ // open), and a page without one (anonymous: hello) imports it for the look.
5
+
6
+ import STYLE from "./parts.css" with { type: "text" };
7
+ import { hueOf } from "./hues.ts";
8
+ import { keep } from "./keep.ts";
9
+ import type { Answer } from "./page.ts";
10
+
11
+ export const PARTS = new CSSStyleSheet();
12
+ PARTS.replaceSync(STYLE);
13
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, PARTS];
14
+
15
+ /** A person's face (Identity): their initial in their hue, their name its title; or, where there's no room (an
16
+ * event's block), their dot. */
17
+ export function face(key: number, name: string, dot = false) {
18
+ const i = Object.assign(document.createElement("i"), { className: "j-face", title: name });
19
+ // its initial drawn, not written: a chip's words are its name alone, as a reader would say it
20
+ if (!dot) i.dataset.initial = name.slice(0, 1);
21
+ i.style.setProperty("--hue", hueOf(key));
22
+ return i;
23
+ }
24
+
25
+ /** A person as a chip (People chips, Identity): a tint and a stripe of their hue, their face, and words: their name,
26
+ * or what's said of them ("You, organising"). */
27
+ export function chip(key: number, name: string, words = name) {
28
+ const c = Object.assign(document.createElement("span"), { className: "j-chip" });
29
+ c.style.setProperty("--hue", hueOf(key));
30
+ c.append(face(key, name), words);
31
+ return c;
32
+ }
33
+
34
+ /** A line for a request's refusal (Said): emptied as it's sent, its why if it's refused. It returns the
35
+ * refusal, if there was one; done is nothing to say, what it did showing as its change. */
36
+ export async function said(line: Element, request: Promise<Answer>) {
37
+ line.textContent = "";
38
+ const why = await request;
39
+ if (why) line.textContent = `Refused: ${why}`;
40
+ return why;
41
+ }
42
+
43
+ /** A modal that asks first (Modal): its question in its h2, then Never mind (keep) or the deed (sure). What it
44
+ * returns asks it: the question, and what the deed does. */
45
+ export function askFirst(dialog: HTMLDialogElement) {
46
+ let deed = () => {};
47
+ dialog.querySelector("[name=keep]")!.addEventListener("click", () => dialog.close());
48
+ dialog.querySelector("[name=sure]")!.addEventListener("click", () => (dialog.close(), deed()));
49
+ return (question: string, then: () => void) => {
50
+ dialog.querySelector("h2")!.textContent = question;
51
+ deed = then;
52
+ dialog.showModal();
53
+ };
54
+ }
55
+
56
+ /** Each button in root that opens a popover says so while it's open (aria-expanded), and is drawn
57
+ * pressed: a sheet that covers the page is never open with nothing to say what opened it. */
58
+ export function showsOpen(root: ParentNode) {
59
+ for (const b of root.querySelectorAll<HTMLButtonElement>("[popovertarget]:not([popovertargetaction=hide])"))
60
+ b.popoverTargetElement?.addEventListener("toggle", (e) =>
61
+ b.setAttribute("aria-expanded", String((e as ToggleEvent).newState === "open")),
62
+ );
63
+ }
64
+
65
+ /** What a display has open, in the URL's hash (`#event=2`), so Back closes it and a link opens it again (design.md,
66
+ * "What a tap does"): `mark(key)` as one is opened, a step Back takes back (another opened, in its place), or closed,
67
+ * that step taken back (or, opened by a link, the hash taken off). With Back, Forward or a link, what the hash names is
68
+ * shown (`show`, of the display's `items`; none named, null); one not on the page yet is shown once it is (`again`,
69
+ * as the display's items change). `picked` is what's open now. */
70
+ export function inHash<T extends { key: number }>(
71
+ name: string,
72
+ items: () => T[],
73
+ picked: () => T | null,
74
+ show: (el: T | null) => void,
75
+ /** let go with: what it listens to (Back, Forward, a link) is let go when it aborts */
76
+ signal?: AbortSignal,
77
+ ) {
78
+ let leaving = false; // Back taken for a close: the step it comes back with isn't a person's Back
79
+ const key = () => {
80
+ const [, k] = new RegExp(`^#${name}=(\\d+)$`).exec(location.hash) ?? [];
81
+ return k === undefined ? null : Number(k);
82
+ };
83
+ let wanted = key();
84
+ /** What the hash names, shown, or (none named) none; kept until it's on the page. */
85
+ const open = () => {
86
+ const k = key(),
87
+ el = items().find((e) => e.key === k) ?? null;
88
+ wanted = el || k === null ? null : k;
89
+ if (el !== picked() && (el || k === null)) show(el);
90
+ };
91
+ const mark = (k: number | null) => {
92
+ const hash = k === null ? "" : `#${name}=${k}`;
93
+ // while Back is taken for a close, what's opened meanwhile is marked once it's done
94
+ if (leaving || location.hash === hash) return;
95
+ if (k !== null) history[key() === null ? "pushState" : "replaceState"]({ open: true }, "", hash);
96
+ else if (history.state?.open) ((leaving = true), history.back());
97
+ else history.replaceState(null, "", location.pathname + location.search);
98
+ };
99
+ const moved = () => {
100
+ if (leaving) return void ((leaving = false), mark(picked()?.key ?? null));
101
+ open();
102
+ // opened by a link on the page: a step Back closes, as one opened here is
103
+ if (picked() && !history.state?.open) history.replaceState({ open: true }, "");
104
+ };
105
+ addEventListener("popstate", moved, { signal });
106
+ addEventListener("hashchange", moved, { signal });
107
+ return { mark, again: () => void (wanted !== null && open()) };
108
+ }
109
+
110
+ /** A typeahead (Choosing: more than six): what's typed in `field` matched against what may be chosen, the matches
111
+ * offered beneath it in `list` (the first eight), a list of choices; one tapped, or the first on Enter, is chosen
112
+ * and the field emptied, and Escape lets them go, leaving what's typed. An underscore is read as a space
113
+ * (America/New_York, typed "new york"). It returns its offer, to call again when what may be chosen changes. */
114
+ export function typeahead(
115
+ field: HTMLInputElement,
116
+ list: HTMLElement,
117
+ options: () => [key: number, words: string][],
118
+ choose: (key: number) => void,
119
+ ) {
120
+ const kept = new Map<string, { shows: string; el: HTMLElement }>();
121
+ const offer = () => {
122
+ const said = (s: string) => s.toLowerCase().replaceAll("_", " "),
123
+ q = said(field.value.trim()),
124
+ found = q
125
+ ? options()
126
+ .filter(([, words]) => said(words).includes(q))
127
+ .slice(0, 8)
128
+ : [];
129
+ list.hidden = !found.length;
130
+ keep(
131
+ list,
132
+ kept,
133
+ found.map(([key, words]) => ({
134
+ key: String(key),
135
+ shows: words,
136
+ make: () => {
137
+ const b = Object.assign(document.createElement("button"), { type: "button", textContent: words });
138
+ b.setAttribute("role", "option");
139
+ b.addEventListener("click", () => ((field.value = ""), offer(), choose(key), field.focus()));
140
+ return b;
141
+ },
142
+ })),
143
+ );
144
+ };
145
+ field.addEventListener("input", offer);
146
+ field.addEventListener("keydown", (e) => {
147
+ const first = list.hidden ? null : list.querySelector("button");
148
+ if (e.key === "Enter") (e.preventDefault(), first?.click()); // never the form's Save
149
+ if (e.key === "Escape" && !list.hidden) (e.preventDefault(), (list.hidden = true));
150
+ });
151
+ return offer;
152
+ }