@agentshouse/mdruntime 0.1.0-c1e8a8738a009 → 0.1.0-c1ea23b9ca7c6

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 (347) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +299 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +321 -0
  11. package/dist/adapter.d.ts +192 -109
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +3 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +20 -60
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +345 -0
  19. package/dist/bootstrap.d.ts +12 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +213 -89
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +2 -1
  26. package/dist/chain.d.ts.map +1 -1
  27. package/dist/change-set.d.ts +4 -0
  28. package/dist/change-set.d.ts.map +1 -1
  29. package/dist/change-set.js +6 -0
  30. package/dist/change.d.ts +5 -0
  31. package/dist/change.d.ts.map +1 -1
  32. package/dist/change.js +7 -2
  33. package/dist/chat-types.d.ts +3 -0
  34. package/dist/chat-types.d.ts.map +1 -0
  35. package/dist/chat-types.js +11 -0
  36. package/dist/client.d.ts +37 -24
  37. package/dist/client.d.ts.map +1 -1
  38. package/dist/client.js +48 -59
  39. package/dist/collection.d.ts +27 -7
  40. package/dist/collection.d.ts.map +1 -1
  41. package/dist/collection.js +29 -27
  42. package/dist/column.d.ts +5 -0
  43. package/dist/column.d.ts.map +1 -0
  44. package/dist/column.js +9 -0
  45. package/dist/compile.d.ts +8 -6
  46. package/dist/compile.d.ts.map +1 -1
  47. package/dist/compile.js +287 -335
  48. package/dist/connection.d.ts +6 -144
  49. package/dist/connection.d.ts.map +1 -1
  50. package/dist/connection.js +114 -5246
  51. package/dist/context.d.ts +2 -0
  52. package/dist/context.d.ts.map +1 -0
  53. package/dist/context.js +7 -0
  54. package/dist/conversation-live.d.ts +152 -0
  55. package/dist/conversation-live.d.ts.map +1 -0
  56. package/dist/conversation-live.js +261 -0
  57. package/dist/conversation-row.d.ts +40 -0
  58. package/dist/conversation-row.d.ts.map +1 -0
  59. package/dist/conversation-row.js +66 -0
  60. package/dist/conversation.d.ts +72 -52
  61. package/dist/conversation.d.ts.map +1 -1
  62. package/dist/conversation.js +1007 -906
  63. package/dist/declaration.d.ts +10 -0
  64. package/dist/declaration.d.ts.map +1 -0
  65. package/dist/declaration.js +24 -0
  66. package/dist/discovery.d.ts +12 -0
  67. package/dist/discovery.d.ts.map +1 -0
  68. package/dist/discovery.js +175 -0
  69. package/dist/download.d.ts +6 -0
  70. package/dist/download.d.ts.map +1 -0
  71. package/dist/download.js +42 -0
  72. package/dist/durability.d.ts +20 -1
  73. package/dist/durability.d.ts.map +1 -1
  74. package/dist/durability.js +7 -0
  75. package/dist/entry.d.ts +16 -2
  76. package/dist/entry.d.ts.map +1 -1
  77. package/dist/entry.js +60 -21
  78. package/dist/expectation.d.ts +26 -13
  79. package/dist/expectation.d.ts.map +1 -1
  80. package/dist/expectation.js +72 -19
  81. package/dist/failure.d.ts +3 -0
  82. package/dist/failure.d.ts.map +1 -1
  83. package/dist/failure.js +8 -0
  84. package/dist/figures.d.ts +49 -0
  85. package/dist/figures.d.ts.map +1 -0
  86. package/dist/figures.js +199 -0
  87. package/dist/file.d.ts +1 -1
  88. package/dist/file.d.ts.map +1 -1
  89. package/dist/file.js +3 -2
  90. package/dist/holdings.d.ts +29 -0
  91. package/dist/holdings.d.ts.map +1 -0
  92. package/dist/holdings.js +95 -0
  93. package/dist/host.d.ts +24 -8
  94. package/dist/host.d.ts.map +1 -1
  95. package/dist/host.js +105 -43
  96. package/dist/house-query.d.ts +15 -0
  97. package/dist/house-query.d.ts.map +1 -0
  98. package/dist/house-query.js +43 -0
  99. package/dist/identity.d.ts +0 -1
  100. package/dist/identity.d.ts.map +1 -1
  101. package/dist/identity.js +0 -3
  102. package/dist/index.d.ts +41 -14
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +20 -5
  105. package/dist/install.d.ts +60 -0
  106. package/dist/install.d.ts.map +1 -0
  107. package/dist/install.js +537 -0
  108. package/dist/lifecycle.d.ts +7 -0
  109. package/dist/lifecycle.d.ts.map +1 -0
  110. package/dist/lifecycle.js +290 -0
  111. package/dist/listing.d.ts +60 -0
  112. package/dist/listing.d.ts.map +1 -0
  113. package/dist/listing.js +168 -0
  114. package/dist/live.d.ts +9 -6
  115. package/dist/live.d.ts.map +1 -1
  116. package/dist/live.js +118 -36
  117. package/dist/loaded.d.ts +5 -0
  118. package/dist/loaded.d.ts.map +1 -0
  119. package/dist/loaded.js +40 -0
  120. package/dist/locks.d.ts +7 -0
  121. package/dist/locks.d.ts.map +1 -0
  122. package/dist/locks.js +34 -0
  123. package/dist/lost.d.ts +5 -0
  124. package/dist/lost.d.ts.map +1 -0
  125. package/dist/lost.js +49 -0
  126. package/dist/media.d.ts +19 -2
  127. package/dist/media.d.ts.map +1 -1
  128. package/dist/media.js +131 -31
  129. package/dist/memory.d.ts +20 -7
  130. package/dist/memory.d.ts.map +1 -1
  131. package/dist/memory.js +257 -104
  132. package/dist/messages.d.ts +35 -5
  133. package/dist/messages.d.ts.map +1 -1
  134. package/dist/messages.js +113 -39
  135. package/dist/modal.d.ts +2 -0
  136. package/dist/modal.d.ts.map +1 -0
  137. package/dist/modal.js +11 -0
  138. package/dist/model.d.ts +6 -13
  139. package/dist/model.d.ts.map +1 -1
  140. package/dist/model.js +6 -23
  141. package/dist/models.d.ts +10 -0
  142. package/dist/models.d.ts.map +1 -0
  143. package/dist/models.js +153 -0
  144. package/dist/observation.d.ts +30 -13
  145. package/dist/observation.d.ts.map +1 -1
  146. package/dist/observation.js +218 -81
  147. package/dist/online.d.ts +7 -0
  148. package/dist/online.d.ts.map +1 -0
  149. package/dist/online.js +29 -0
  150. package/dist/opened.d.ts +1 -1
  151. package/dist/opened.d.ts.map +1 -1
  152. package/dist/opened.js +5 -5
  153. package/dist/opening.d.ts +4 -0
  154. package/dist/opening.d.ts.map +1 -0
  155. package/dist/opening.js +69 -0
  156. package/dist/outcome.d.ts +17 -5
  157. package/dist/outcome.d.ts.map +1 -1
  158. package/dist/outcome.js +35 -2
  159. package/dist/overlay.d.ts +7 -2
  160. package/dist/overlay.d.ts.map +1 -1
  161. package/dist/overlay.js +48 -24
  162. package/dist/page-metadata.d.ts +8 -0
  163. package/dist/page-metadata.d.ts.map +1 -0
  164. package/dist/page-metadata.js +19 -0
  165. package/dist/parts.d.ts +6 -0
  166. package/dist/parts.d.ts.map +1 -0
  167. package/dist/parts.js +36 -0
  168. package/dist/paths.d.ts +1 -0
  169. package/dist/paths.d.ts.map +1 -1
  170. package/dist/paths.js +22 -0
  171. package/dist/preparation.d.ts +45 -0
  172. package/dist/preparation.d.ts.map +1 -0
  173. package/dist/preparation.js +335 -0
  174. package/dist/presence.d.ts +58 -0
  175. package/dist/presence.d.ts.map +1 -0
  176. package/dist/presence.js +231 -0
  177. package/dist/queries.d.ts +16 -0
  178. package/dist/queries.d.ts.map +1 -0
  179. package/dist/queries.js +287 -0
  180. package/dist/query.d.ts +14 -210
  181. package/dist/query.d.ts.map +1 -1
  182. package/dist/query.js +3 -505
  183. package/dist/questions.d.ts +30 -0
  184. package/dist/questions.d.ts.map +1 -0
  185. package/dist/questions.js +117 -0
  186. package/dist/queue.d.ts +40 -0
  187. package/dist/queue.d.ts.map +1 -0
  188. package/dist/queue.js +480 -0
  189. package/dist/reach.d.ts +25 -15
  190. package/dist/reach.d.ts.map +1 -1
  191. package/dist/reach.js +329 -152
  192. package/dist/react.d.ts +21 -3
  193. package/dist/react.d.ts.map +1 -1
  194. package/dist/react.js +33 -1
  195. package/dist/read.d.ts +7 -0
  196. package/dist/read.d.ts.map +1 -0
  197. package/dist/read.js +17 -0
  198. package/dist/readiness.d.ts +18 -20
  199. package/dist/readiness.d.ts.map +1 -1
  200. package/dist/readiness.js +14 -20
  201. package/dist/reads.d.ts +38 -10
  202. package/dist/reads.d.ts.map +1 -1
  203. package/dist/reads.js +164 -77
  204. package/dist/recovery.d.ts +4 -0
  205. package/dist/recovery.d.ts.map +1 -1
  206. package/dist/recovery.js +59 -2
  207. package/dist/refresh.d.ts +7 -5
  208. package/dist/refresh.d.ts.map +1 -1
  209. package/dist/refresh.js +35 -7
  210. package/dist/refusal.d.ts +5 -0
  211. package/dist/refusal.d.ts.map +1 -0
  212. package/dist/refusal.js +55 -0
  213. package/dist/replica.d.ts +11 -17
  214. package/dist/replica.d.ts.map +1 -1
  215. package/dist/replica.js +66 -36
  216. package/dist/retried.d.ts +30 -0
  217. package/dist/retried.d.ts.map +1 -0
  218. package/dist/retried.js +72 -0
  219. package/dist/room-draft.d.ts +34 -10
  220. package/dist/room-draft.d.ts.map +1 -1
  221. package/dist/room-draft.js +331 -111
  222. package/dist/room-drafts.d.ts +24 -0
  223. package/dist/room-drafts.d.ts.map +1 -0
  224. package/dist/room-drafts.js +220 -0
  225. package/dist/room-list.d.ts +10 -0
  226. package/dist/room-list.d.ts.map +1 -0
  227. package/dist/room-list.js +45 -0
  228. package/dist/rows.d.ts +16 -22
  229. package/dist/rows.d.ts.map +1 -1
  230. package/dist/rows.js +49 -186
  231. package/dist/running.d.ts +5 -0
  232. package/dist/running.d.ts.map +1 -0
  233. package/dist/running.js +10 -0
  234. package/dist/runtime.d.ts +35 -0
  235. package/dist/runtime.d.ts.map +1 -0
  236. package/dist/runtime.js +1 -0
  237. package/dist/save.d.ts +42 -86
  238. package/dist/save.d.ts.map +1 -1
  239. package/dist/save.js +332 -228
  240. package/dist/saves.d.ts +34 -0
  241. package/dist/saves.d.ts.map +1 -0
  242. package/dist/saves.js +437 -0
  243. package/dist/search.d.ts +12 -63
  244. package/dist/search.d.ts.map +1 -1
  245. package/dist/search.js +9 -52
  246. package/dist/seed.d.ts +11 -2
  247. package/dist/seed.d.ts.map +1 -1
  248. package/dist/seed.js +71 -1
  249. package/dist/shared.d.ts +1 -7
  250. package/dist/shared.d.ts.map +1 -1
  251. package/dist/shared.js +13 -105
  252. package/dist/shown.d.ts +35 -0
  253. package/dist/shown.d.ts.map +1 -0
  254. package/dist/shown.js +326 -0
  255. package/dist/socket/admission.d.ts +7 -0
  256. package/dist/socket/admission.d.ts.map +1 -0
  257. package/dist/socket/admission.js +39 -0
  258. package/dist/socket/answers.d.ts +6 -0
  259. package/dist/socket/answers.d.ts.map +1 -0
  260. package/dist/socket/answers.js +20 -0
  261. package/dist/socket/lanes.d.ts +28 -0
  262. package/dist/socket/lanes.d.ts.map +1 -0
  263. package/dist/socket/lanes.js +103 -0
  264. package/dist/socket/reads.d.ts +10 -0
  265. package/dist/socket/reads.d.ts.map +1 -0
  266. package/dist/socket/reads.js +31 -0
  267. package/dist/socket/session.d.ts +41 -0
  268. package/dist/socket/session.d.ts.map +1 -0
  269. package/dist/socket/session.js +26 -0
  270. package/dist/socket.d.ts +68 -0
  271. package/dist/socket.d.ts.map +1 -0
  272. package/dist/socket.js +165 -0
  273. package/dist/source.d.ts +59 -0
  274. package/dist/source.d.ts.map +1 -0
  275. package/dist/source.js +93 -0
  276. package/dist/status.d.ts +0 -6
  277. package/dist/status.d.ts.map +1 -1
  278. package/dist/status.js +0 -6
  279. package/dist/store/installs.d.ts +30 -0
  280. package/dist/store/installs.d.ts.map +1 -0
  281. package/dist/store/installs.js +40 -0
  282. package/dist/store/readiness.d.ts +11 -0
  283. package/dist/store/readiness.d.ts.map +1 -0
  284. package/dist/store/readiness.js +68 -0
  285. package/dist/store/records.d.ts +227 -0
  286. package/dist/store/records.d.ts.map +1 -0
  287. package/dist/store/records.js +468 -0
  288. package/dist/store/room-held.d.ts +8 -0
  289. package/dist/store/room-held.d.ts.map +1 -0
  290. package/dist/store/room-held.js +17 -0
  291. package/dist/store/rooms-shown.d.ts +8 -0
  292. package/dist/store/rooms-shown.d.ts.map +1 -0
  293. package/dist/store/rooms-shown.js +13 -0
  294. package/dist/store/space.d.ts +11 -0
  295. package/dist/store/space.d.ts.map +1 -0
  296. package/dist/store/space.js +41 -0
  297. package/dist/store/watchers.d.ts +17 -0
  298. package/dist/store/watchers.d.ts.map +1 -0
  299. package/dist/store/watchers.js +56 -0
  300. package/dist/store/writes.d.ts +24 -0
  301. package/dist/store/writes.d.ts.map +1 -0
  302. package/dist/store/writes.js +125 -0
  303. package/dist/store.d.ts +116 -156
  304. package/dist/store.d.ts.map +1 -1
  305. package/dist/store.js +174 -394
  306. package/dist/stored.d.ts +80 -41
  307. package/dist/stored.d.ts.map +1 -1
  308. package/dist/stored.js +437 -220
  309. package/dist/surface.d.ts +94 -0
  310. package/dist/surface.d.ts.map +1 -0
  311. package/dist/surface.js +255 -0
  312. package/dist/sync.d.ts +21 -0
  313. package/dist/sync.d.ts.map +1 -0
  314. package/dist/sync.js +557 -0
  315. package/dist/tables.d.ts +118 -94
  316. package/dist/tables.d.ts.map +1 -1
  317. package/dist/tables.js +199 -321
  318. package/dist/tallies.d.ts +18 -0
  319. package/dist/tallies.d.ts.map +1 -0
  320. package/dist/tallies.js +128 -0
  321. package/dist/transfer.d.ts +0 -5
  322. package/dist/transfer.d.ts.map +1 -1
  323. package/dist/validation.d.ts +3 -4
  324. package/dist/validation.d.ts.map +1 -1
  325. package/dist/validation.js +42 -106
  326. package/dist/windows.d.ts +1 -12
  327. package/dist/windows.d.ts.map +1 -1
  328. package/dist/windows.js +2 -75
  329. package/dist/wire.d.ts +80 -9
  330. package/dist/wire.d.ts.map +1 -1
  331. package/dist/wire.js +32 -10
  332. package/package.json +3 -2
  333. package/dist/attempt.d.ts +0 -16
  334. package/dist/attempt.d.ts.map +0 -1
  335. package/dist/attempt.js +0 -70
  336. package/dist/fence.d.ts +0 -6
  337. package/dist/fence.d.ts.map +0 -1
  338. package/dist/fence.js +0 -10
  339. package/dist/fulltext.d.ts +0 -27
  340. package/dist/fulltext.d.ts.map +0 -1
  341. package/dist/fulltext.js +0 -370
  342. package/dist/log.d.ts +0 -5
  343. package/dist/log.d.ts.map +0 -1
  344. package/dist/log.js +0 -14
  345. package/dist/words.d.ts +0 -19
  346. package/dist/words.d.ts.map +0 -1
  347. package/dist/words.js +0 -156
package/dist/live.js CHANGED
@@ -1,50 +1,59 @@
1
- import { changeOf, digestOf, } from './observation.js';
2
- import { roomOfKey } from './rows.js';
1
+ import { changeOf, digestOf, keyedAt, keyedInto, samePending, unchanged, } from './observation.js';
2
+ import { uncaught } from './failure.js';
3
+ import { roomsOfReach } from './rows.js';
3
4
  function narrowed(plan) {
4
5
  return (plan.paths !== null &&
5
6
  plan.hop === null &&
6
7
  plan.backlinks === null &&
7
8
  !(plan.shape.kind === 'documents' && plan.shape.backlinks));
8
9
  }
9
- function reads(plan, locator) {
10
- if (plan.locked.includes(locator))
11
- return false;
12
- if (plan.rooms !== null && !plan.rooms.includes(locator))
13
- return false;
14
- if (plan.reach === null)
15
- return true;
16
- return (plan.reach.rooms.includes(locator) ||
17
- plan.reach.documents.some((document) => roomOfKey(document) === locator) ||
18
- plan.reach.areas.some((area) => area.room === locator && area.types.length > 0));
10
+ export function readerOf(plan) {
11
+ const locked = new Set(plan.locked);
12
+ const named = plan.rooms === null ? null : new Set(plan.rooms);
13
+ const reached = plan.reach === null ? null : roomsOfReach(plan.reach);
14
+ return (locator) => !locked.has(locator) &&
15
+ (named === null || named.has(locator)) &&
16
+ (reached === null || reached.has(locator));
19
17
  }
20
- function affected(plan, set) {
21
- if (set.rooms.some((locator) => reads(plan, locator)))
18
+ function affected({ plan, reads }, set) {
19
+ if (set.rooms.some(reads))
22
20
  return true;
23
21
  const paths = narrowed(plan) ? new Set(plan.paths) : null;
24
- return set.documents.some(({ locator, path }) => reads(plan, locator) && (paths === null || path === null || paths.has(path)));
22
+ return set.documents.some(({ locator, path }) => reads(locator) && (paths === null || path === null || paths.has(path)));
25
23
  }
26
- function shown(entry) {
27
- const cover = entry.cover();
24
+ function shown(entry, held) {
25
+ const cover = entry.cover(held);
28
26
  return JSON.stringify('pending' in cover ? cover : cover.coverage);
29
27
  }
30
- export function createLiveQueries(run) {
28
+ export function createLiveQueries(run, holding) {
31
29
  const entries = new Map();
32
30
  let closed = false;
31
+ let recoveringNow = false;
32
+ let recoveringAll = false;
33
+ const recovering = new Set();
33
34
  function deliver(entry, next) {
34
35
  const previous = entry.digest;
35
36
  entry.digest = digestOf(next);
37
+ entry.pending = 'pending' in entry.digest ? entry.digest.pending : null;
36
38
  entry.covered = JSON.stringify('pending' in next.result ? next.result : next.result.coverage);
37
39
  const change = previous === undefined ? null : changeOf(previous, next);
38
40
  if (change !== null) {
39
41
  for (const listener of entry.ready)
40
42
  listener(change);
41
43
  }
42
- for (const listener of entry.fresh) {
44
+ for (const listener of entry.fresh.keys()) {
43
45
  entry.ready.add(listener);
44
46
  listener(next);
45
47
  }
46
48
  entry.fresh.clear();
47
49
  }
50
+ async function delivered(entry) {
51
+ const { current, ...next } = await run(entry.plan, async () => entry.cover(await holding()));
52
+ if (closed || entry.listeners.size === 0)
53
+ return null;
54
+ deliver(entry, next);
55
+ return current;
56
+ }
48
57
  function schedule(entry) {
49
58
  if (closed || entry.listeners.size === 0)
50
59
  return;
@@ -57,47 +66,120 @@ export function createLiveQueries(run) {
57
66
  try {
58
67
  for (;;) {
59
68
  entry.dirty = false;
60
- const { current, ...next } = await run(entry.plan, entry.cover);
61
- if (closed || entry.listeners.size === 0)
69
+ const current = await delivered(entry);
70
+ if (current === null)
62
71
  return;
63
- deliver(entry, next);
64
- if (!(entry.dirty && !current()) && shown(entry) === entry.covered)
72
+ const held = await holding();
73
+ if (entry.fresh.size > 0 || (entry.dirty && !current()))
74
+ continue;
75
+ if (shown(entry, held) === entry.covered)
65
76
  break;
66
77
  }
67
78
  }
68
- catch {
69
- entry.dirty = false;
79
+ catch (error) {
80
+ const unanswered = [...entry.fresh.values()];
81
+ entry.fresh.clear();
82
+ for (const failed of unanswered)
83
+ failed(error);
70
84
  }
71
85
  finally {
72
86
  entry.running = false;
73
87
  }
74
88
  })();
75
89
  }
90
+ function pendingMoved(entry, held, rooms) {
91
+ const { pending } = entry;
92
+ if (pending === null || pending.size === 0 || entry.running || entry.fresh.size > 0) {
93
+ return false;
94
+ }
95
+ const at = entry.pendingAt(held, rooms);
96
+ const change = at === null ? null : keyedAt(pending, at, samePending);
97
+ if (change === null || change.removed.length === pending.size)
98
+ return false;
99
+ keyedInto(pending, change);
100
+ entry.covered = '';
101
+ if (unchanged(change))
102
+ return true;
103
+ for (const listener of entry.ready)
104
+ listener({ pending: change });
105
+ return true;
106
+ }
107
+ function recovered(locators) {
108
+ if (locators === undefined)
109
+ recoveringAll = true;
110
+ else
111
+ for (const locator of locators)
112
+ recovering.add(locator);
113
+ if (recoveringNow)
114
+ return;
115
+ recoveringNow = true;
116
+ void (async () => {
117
+ try {
118
+ while ((recoveringAll || recovering.size > 0) && !closed) {
119
+ const all = recoveringAll;
120
+ const touched = [...recovering];
121
+ recoveringAll = false;
122
+ recovering.clear();
123
+ const reached = [...entries.values()].filter((entry) => all || touched.some(entry.reads));
124
+ for (const entry of reached) {
125
+ if (entry.running)
126
+ entry.dirty = true;
127
+ }
128
+ const waiting = reached.filter((entry) => !entry.running);
129
+ if (waiting.length === 0)
130
+ continue;
131
+ const held = await holding();
132
+ for (const entry of waiting) {
133
+ if (entry.running)
134
+ continue;
135
+ const read = all ? [] : touched.filter(entry.reads);
136
+ if (read.length > 0 && pendingMoved(entry, held, read))
137
+ continue;
138
+ if (entry.digest === undefined || shown(entry, held) !== entry.covered)
139
+ schedule(entry);
140
+ }
141
+ }
142
+ }
143
+ catch (error) {
144
+ uncaught(error);
145
+ }
146
+ finally {
147
+ recoveringNow = false;
148
+ }
149
+ })();
150
+ }
76
151
  return {
77
152
  touched(set) {
153
+ const pending = new Set();
78
154
  for (const entry of entries.values()) {
79
- if (affected(entry.plan, set))
80
- schedule(entry);
81
- }
82
- },
83
- recover() {
84
- for (const entry of entries.values()) {
85
- if (entry.running)
155
+ if (!affected(entry, set))
86
156
  continue;
87
- if (entry.digest === undefined || shown(entry) !== entry.covered)
157
+ if (entry.pending === null || entry.running) {
88
158
  schedule(entry);
159
+ continue;
160
+ }
161
+ for (const locator of set.rooms)
162
+ pending.add(locator);
163
+ for (const { locator } of set.documents)
164
+ pending.add(locator);
89
165
  }
166
+ if (pending.size > 0)
167
+ recovered([...pending]);
90
168
  },
91
- watch(plan, identity, cover, listener) {
169
+ recover: recovered,
170
+ watch(plan, identity, cover, pendingAt, listener, failed) {
92
171
  let entry = entries.get(identity);
93
172
  if (entry === undefined) {
94
173
  entry = {
95
174
  plan,
175
+ reads: readerOf(plan),
96
176
  cover,
177
+ pendingAt,
97
178
  listeners: new Set(),
98
- fresh: new Set(),
179
+ fresh: new Map(),
99
180
  ready: new Set(),
100
181
  digest: undefined,
182
+ pending: null,
101
183
  covered: '',
102
184
  dirty: false,
103
185
  running: false,
@@ -106,7 +188,7 @@ export function createLiveQueries(run) {
106
188
  }
107
189
  const held = entry;
108
190
  held.listeners.add(listener);
109
- held.fresh.add(listener);
191
+ held.fresh.set(listener, failed);
110
192
  schedule(held);
111
193
  return () => {
112
194
  held.listeners.delete(listener);
@@ -0,0 +1,5 @@
1
+ import type { BuildFile } from './client.js';
2
+ export declare function parsed(file: Blob | null): Promise<unknown>;
3
+ export declare function perBuild<T>(buildFile: BuildFile, key: string, make: () => Promise<T>): Promise<T>;
4
+ export declare function loaded<T>(buildFile: BuildFile, name: string, read?: (file: Blob | null) => Promise<unknown>): Promise<T | null>;
5
+ //# sourceMappingURL=loaded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loaded.d.ts","sourceRoot":"","sources":["../src/loaded.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAc7C,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAEhE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYjG;AAED,wBAAgB,MAAM,CAAC,CAAC,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC,OAAO,CAAY,GACvD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAEnB"}
package/dist/loaded.js ADDED
@@ -0,0 +1,40 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ const holdings = new WeakMap();
10
+ async function imported(file) {
11
+ if (file === null)
12
+ return null;
13
+ const address = URL.createObjectURL(file);
14
+ try {
15
+ return await import(__rewriteRelativeImportExtension(address));
16
+ }
17
+ finally {
18
+ URL.revokeObjectURL(address);
19
+ }
20
+ }
21
+ export async function parsed(file) {
22
+ return file === null ? null : JSON.parse(await file.text());
23
+ }
24
+ export function perBuild(buildFile, key, make) {
25
+ let named = holdings.get(buildFile);
26
+ if (named === undefined) {
27
+ named = new Map();
28
+ holdings.set(buildFile, named);
29
+ }
30
+ const holding = named.get(key);
31
+ if (holding !== undefined)
32
+ return holding;
33
+ const making = make();
34
+ named.set(key, making);
35
+ making.catch(() => named.delete(key));
36
+ return making;
37
+ }
38
+ export function loaded(buildFile, name, read = imported) {
39
+ return perBuild(buildFile, name, () => buildFile(name).then(read));
40
+ }
@@ -0,0 +1,7 @@
1
+ import type { Runtime } from './runtime.js';
2
+ export declare function locked({ store, presence }: Runtime, locator: string): Promise<boolean>;
3
+ export declare function lockedRooms({ store, presence }: Runtime): Promise<readonly string[]>;
4
+ export declare function relocked(runtime: Runtime, before: readonly string[]): Promise<void>;
5
+ export declare function connectionLost(runtime: Runtime): void;
6
+ export declare function watchLocks({ store }: Runtime, notify: () => void): () => void;
7
+ //# sourceMappingURL=locks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5F;AAED,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAI1F;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAKzE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAU9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
package/dist/locks.js ADDED
@@ -0,0 +1,34 @@
1
+ import { uncaught } from './failure.js';
2
+ import { emitRooms, LOCKS_TOPIC } from './shown.js';
3
+ export async function locked({ store, presence }, locator) {
4
+ return presence.locked(locator, async () => (await store.open()).offline(locator));
5
+ }
6
+ export async function lockedRooms({ store, presence }) {
7
+ if (!store.needed())
8
+ return [];
9
+ const { rooms, locking } = await store.covering();
10
+ return presence.lockedAmong(rooms, locking);
11
+ }
12
+ export async function relocked(runtime, before) {
13
+ const after = await lockedRooms(runtime);
14
+ if (JSON.stringify(after) === JSON.stringify(before))
15
+ return;
16
+ emitRooms(runtime);
17
+ runtime.store.tell(LOCKS_TOPIC, undefined);
18
+ }
19
+ export function connectionLost(runtime) {
20
+ const { socket, presence } = runtime;
21
+ if (socket.closed())
22
+ return;
23
+ presence.connectionLost(() => {
24
+ if (socket.isOpen() || socket.closed())
25
+ return;
26
+ void lockedRooms(runtime).then((before) => {
27
+ presence.lapse();
28
+ return relocked(runtime, before);
29
+ }, uncaught);
30
+ });
31
+ }
32
+ export function watchLocks({ store }, notify) {
33
+ return store.watch(LOCKS_TOPIC, notify).stop;
34
+ }
package/dist/lost.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Runtime } from './runtime.js';
2
+ export declare function eraseFenced({ store }: Runtime, locators: readonly string[]): Promise<void>;
3
+ export declare function fenceLive(runtime: Runtime, locators: readonly string[]): void;
4
+ export declare function loseRooms(runtime: Runtime, locators: readonly string[]): Promise<void>;
5
+ //# sourceMappingURL=lost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAIhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,QAMtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBA+B5E"}
package/dist/lost.js ADDED
@@ -0,0 +1,49 @@
1
+ import { changeSet, mergeChangeSets } from './change-set.js';
2
+ import { ERASE_BATCH } from './install.js';
3
+ import { unpair } from './queue.js';
4
+ import { recoverReads } from './shown.js';
5
+ import { yielded } from './turn.js';
6
+ export async function eraseFenced({ store }, locators) {
7
+ for (const locator of locators) {
8
+ while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
9
+ await yielded();
10
+ }
11
+ }
12
+ export function fenceLive(runtime, locators) {
13
+ const { store, socket, presence } = runtime;
14
+ for (const locator of new Set(locators)) {
15
+ if (!presence.lose(locator, socket.session.now().discoveries))
16
+ continue;
17
+ store.forget(locator);
18
+ }
19
+ }
20
+ export async function loseRooms(runtime, locators) {
21
+ const { store, presence } = runtime;
22
+ fenceLive(runtime, locators);
23
+ const fresh = [...new Set(locators)].filter((locator) => presence.writing(locator));
24
+ if (fresh.length === 0)
25
+ return;
26
+ let held = [];
27
+ try {
28
+ await store.durably(async (local) => {
29
+ held = await local.roomDrafts();
30
+ await local.fence(fresh);
31
+ });
32
+ }
33
+ catch (error) {
34
+ for (const locator of fresh)
35
+ presence.unwritten(locator);
36
+ throw error;
37
+ }
38
+ finally {
39
+ store.changed(mergeChangeSets(fresh.map((locator) => changeSet(locator, {
40
+ documents: null,
41
+ room: true,
42
+ queue: true,
43
+ drafts: held.filter((draft) => draft.locator === locator).map(({ path }) => path),
44
+ }))));
45
+ recoverReads(runtime, fresh);
46
+ }
47
+ await unpair(runtime);
48
+ await eraseFenced(runtime, fresh);
49
+ }
package/dist/media.d.ts CHANGED
@@ -1,8 +1,25 @@
1
1
  import type { MdRuntimeClient } from './client.js';
2
- import type { ShownAnswer } from './outcome.js';
2
+ import { type DownloadAnswer, type ShownAnswer } from './outcome.js';
3
3
  export declare const ROOM_MEDIA = "room-media";
4
+ export declare const KEYED_MEDIA = "ahc-attachment";
5
+ export declare const MEDIA = "room-media, ahc-attachment";
6
+ export declare const DIAGRAM = "md-diagram";
7
+ export declare const VIEWING = "ahc-viewer";
4
8
  type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
9
+ export type MediaAt = {
10
+ readonly link: string;
11
+ } | {
12
+ readonly room: string;
13
+ readonly path: string;
14
+ readonly revision: string | undefined;
15
+ };
5
16
  export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
6
- export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient, registry?: CustomElementRegistry): void;
17
+ export declare function mediaAt(media: Element): MediaAt | null;
18
+ export declare function mediaTag(at: MediaAt): string;
19
+ export declare function downloadAt(client: MdRuntimeClient, at: MediaAt): Promise<DownloadAnswer>;
20
+ export declare function rendered(element: Element): boolean;
21
+ export declare function viewable(element: Element): boolean;
22
+ export declare function viewFile(client: MdRuntimeClient, media: Element): void;
23
+ export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient): void;
7
24
  export {};
8
25
  //# sourceMappingURL=media.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,EAClD,QAAQ,GAAE,qBAAsC,GAC/C,IAAI,CAkLN"}
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAqB,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAExF,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C,eAAO,MAAM,KAAK,+BAAkC,CAAC;AAMrD,eAAO,MAAM,OAAO,eAAe,CAAC;AAEpC,eAAO,MAAM,OAAO,eAAe,CAAC;AAgCpC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAEpF,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAI5F,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAUtD;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAE5C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAIxF;AA6BD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMlD;AA0CD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEtE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,IAAI,CAgMxF"}
package/dist/media.js CHANGED
@@ -1,6 +1,18 @@
1
+ import { isAudioType, isImageType, isVideoType } from '@agentshouse/mdmodel';
2
+ import { loaded } from './loaded.js';
3
+ import { downloadAttachment } from './download.js';
4
+ import { blobOf, UNCERTAIN } from './outcome.js';
1
5
  export const ROOM_MEDIA = 'room-media';
6
+ export const KEYED_MEDIA = 'ahc-attachment';
7
+ export const MEDIA = `${ROOM_MEDIA}, ${KEYED_MEDIA}`;
8
+ const VIEWER = 'viewer';
9
+ const RENDERED = '.ahc, .ahc-markdown';
10
+ export const DIAGRAM = 'md-diagram';
11
+ export const VIEWING = 'ahc-viewer';
12
+ const PRESSED_ELSEWHERE = 'a[href], button, input, select, textarea, summary, label, [role="button"], [role="link"]';
2
13
  const ATTRIBUTES = ['room', 'path', 'revision', 'width', 'height', 'alt'];
3
- const LOADING = new Set(['room', 'path', 'revision']);
14
+ const KEYED_ATTRIBUTES = ['link', 'alt'];
15
+ const LOADING = new Set(['link', 'room', 'path', 'revision']);
4
16
  const NEARING = '600px 0px';
5
17
  const RELINKS = 2;
6
18
  // The Room's stream brings a file seconds after the text that links it, minutes after on a first open, and a page's reach of its Rooms settles seconds after it opens, so a file not shown yet is asked for again every three seconds.
@@ -9,12 +21,42 @@ const SHAPE = '16 / 9';
9
21
  const STYLE = `:host{display:block}
10
22
  [part=box]{position:relative;overflow:hidden}
11
23
  [part=box]>img,[part=box]>video,[part=box]>audio{display:block;width:100%;height:100%;object-fit:contain}
12
- [part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}`;
24
+ [part=box]>video:not([controls]){cursor:pointer}
25
+ [part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}
26
+ [part=play]{position:absolute;top:50%;left:50%;width:56px;height:56px;margin:-28px 0 0 -28px;border-radius:50%;background:rgb(0 0 0/.6);pointer-events:none}
27
+ [part=play]::before{content:"";position:absolute;top:18px;left:22px;border-style:solid;border-width:10px 0 10px 16px;border-color:transparent transparent transparent #fff}`;
13
28
  const shows = new WeakMap();
14
29
  export function shownBy(show, client) {
15
30
  shows.set(client, show);
16
31
  return client;
17
32
  }
33
+ export function mediaAt(media) {
34
+ if (media.localName === KEYED_MEDIA) {
35
+ const link = media.getAttribute('link');
36
+ return link === null ? null : { link };
37
+ }
38
+ const room = media.getAttribute('room');
39
+ const path = media.getAttribute('path');
40
+ return room === null || path === null
41
+ ? null
42
+ : { room, path, revision: media.getAttribute('revision') ?? undefined };
43
+ }
44
+ export function mediaTag(at) {
45
+ return 'link' in at ? KEYED_MEDIA : ROOM_MEDIA;
46
+ }
47
+ export function downloadAt(client, at) {
48
+ return 'link' in at
49
+ ? downloadAttachment(client, at.link)
50
+ : client.binaryFile.download(at.room, at.path, at.revision);
51
+ }
52
+ function shownAt(client, at) {
53
+ if (at === null)
54
+ return null;
55
+ if ('link' in at)
56
+ return client.conversation.attachment(at.link);
57
+ const show = shows.get(client);
58
+ return show === undefined ? null : show(at.room, at.path, at.revision);
59
+ }
18
60
  function ratioOf(width, height) {
19
61
  const across = Number(width);
20
62
  const down = Number(height);
@@ -28,23 +70,74 @@ function refusedForGood(shown) {
28
70
  return (shown.kind === 'rejected' || shown.kind === 'scoped-refusal') && !shown.retryable;
29
71
  }
30
72
  function drawnFor(mediaType) {
31
- if (mediaType.startsWith('image/'))
73
+ if (isImageType(mediaType))
32
74
  return 'img';
33
- if (mediaType.startsWith('video/'))
75
+ if (isVideoType(mediaType))
34
76
  return 'video';
35
- if (mediaType.startsWith('audio/'))
77
+ if (isAudioType(mediaType))
36
78
  return 'audio';
37
79
  return null;
38
80
  }
39
- export function defineRoomMedia(client, registry = customElements) {
40
- if (registry.get(ROOM_MEDIA) !== undefined)
81
+ export function rendered(element) {
82
+ return element.closest(RENDERED) !== null;
83
+ }
84
+ export function viewable(element) {
85
+ if (element.localName === 'figure')
86
+ return element.classList.contains(DIAGRAM);
87
+ if (!element.matches(MEDIA) || element.closest(`.${VIEWING}`) !== null)
88
+ return false;
89
+ return (rendered(element) || (element.shadowRoot?.querySelector('[part=box] > video') ?? null) !== null);
90
+ }
91
+ function viewed(client, opener, alone, taken = () => true) {
92
+ void loaded(client.buildFile, VIEWER).then((file) => {
93
+ if (!opener.isConnected || !taken())
94
+ return;
95
+ file?.openViewer({
96
+ opener,
97
+ alone,
98
+ download: (at) => void downloadAt(client, at),
99
+ });
100
+ });
101
+ }
102
+ function pressed(client) {
103
+ let latest = null;
104
+ const taken = (opener) => () => {
105
+ if (latest !== opener)
106
+ return false;
107
+ latest = null;
108
+ return true;
109
+ };
110
+ return (event) => {
111
+ if (event.defaultPrevented || event.detail > 1)
112
+ return;
113
+ for (const node of event.composedPath()) {
114
+ if (!(node instanceof Element))
115
+ continue;
116
+ if (viewable(node)) {
117
+ event.preventDefault();
118
+ latest = node;
119
+ void client.then((one) => viewed(one, node, !rendered(node), taken(node)));
120
+ return;
121
+ }
122
+ if (node.matches(PRESSED_ELSEWHERE))
123
+ return;
124
+ }
125
+ };
126
+ }
127
+ export function viewFile(client, media) {
128
+ viewed(client, media, true);
129
+ }
130
+ export function defineRoomMedia(client) {
131
+ if (customElements.get(ROOM_MEDIA) !== undefined)
41
132
  return;
42
133
  const connected = Promise.resolve(client);
134
+ document.addEventListener('click', pressed(connected));
43
135
  class RoomMedia extends HTMLElement {
44
136
  static observedAttributes = ATTRIBUTES;
45
137
  #root = this.attachShadow({ mode: 'open' });
46
138
  #box = document.createElement('div');
47
139
  #fallback = document.createElement('slot');
140
+ #play = document.createElement('span');
48
141
  #watching = null;
49
142
  #near = false;
50
143
  #asked = 0;
@@ -55,6 +148,7 @@ export function defineRoomMedia(client, registry = customElements) {
55
148
  constructor() {
56
149
  super();
57
150
  this.#box.setAttribute('part', 'box');
151
+ this.#play.setAttribute('part', 'play');
58
152
  this.#root.append(Object.assign(document.createElement('style'), { textContent: STYLE }), this.#box);
59
153
  this.#shape();
60
154
  }
@@ -106,15 +200,8 @@ export function defineRoomMedia(client, registry = customElements) {
106
200
  async #load() {
107
201
  const asked = (this.#asked += 1);
108
202
  this.#loaded = false;
109
- const room = this.getAttribute('room');
110
- const path = this.getAttribute('path');
111
- const revision = this.getAttribute('revision') ?? undefined;
112
- if (room === null || path === null) {
113
- this.#unreadable();
114
- return;
115
- }
116
- const show = shows.get(await connected);
117
- const shown = show === undefined ? null : await show(room, path, revision);
203
+ const showing = shownAt(await connected, mediaAt(this));
204
+ const shown = showing === null ? null : await showing.catch(() => UNCERTAIN);
118
205
  if (asked !== this.#asked)
119
206
  return;
120
207
  if (shown?.kind === 'link') {
@@ -122,21 +209,26 @@ export function defineRoomMedia(client, registry = customElements) {
122
209
  return;
123
210
  }
124
211
  if (shown?.kind !== 'binary') {
125
- this.#unreadable();
126
212
  if (shown === null || refusedForGood(shown))
127
- return;
128
- setTimeout(() => {
129
- if (asked === this.#asked && this.#near)
130
- void this.#load();
131
- }, UNSHOWN_MS);
213
+ this.#unreadable();
214
+ else
215
+ this.#unshown(asked);
132
216
  return;
133
217
  }
134
- const copy = await new Response(shown.stream, {
135
- headers: { 'content-type': shown.mediaType },
136
- }).blob();
218
+ const copy = await blobOf(shown).catch(() => null);
137
219
  if (asked !== this.#asked)
138
220
  return;
139
- this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
221
+ if (copy === null)
222
+ this.#unshown(asked);
223
+ else
224
+ this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
225
+ }
226
+ #unshown(asked) {
227
+ this.#unreadable();
228
+ setTimeout(() => {
229
+ if (asked === this.#asked && this.#near)
230
+ void this.#load();
231
+ }, UNSHOWN_MS);
140
232
  }
141
233
  #show(shown, content = null) {
142
234
  if (this.#shown?.copy === true)
@@ -147,7 +239,9 @@ export function defineRoomMedia(client, registry = customElements) {
147
239
  if (content === null)
148
240
  this.#box.replaceChildren();
149
241
  else if (content.parentNode !== this.#box)
150
- this.#box.replaceChildren(content);
242
+ this.#box.replaceChildren(...(content instanceof HTMLVideoElement && !content.controls
243
+ ? [content, this.#play]
244
+ : [content]));
151
245
  this.#label();
152
246
  }
153
247
  #unreadable() {
@@ -164,13 +258,16 @@ export function defineRoomMedia(client, registry = customElements) {
164
258
  const kept = this.#drawn?.localName === tag ? this.#drawn : null;
165
259
  const drawn = kept ?? document.createElement(tag);
166
260
  if (kept === null) {
261
+ const plays = !(drawn instanceof HTMLVideoElement) || this.closest(`.${VIEWING}`) !== null;
167
262
  if (drawn instanceof HTMLImageElement)
168
263
  drawn.decoding = 'async';
169
264
  if (drawn instanceof HTMLMediaElement) {
170
- drawn.controls = true;
171
265
  drawn.preload = 'metadata';
172
- if (drawn instanceof HTMLVideoElement)
173
- drawn.playsInline = true;
266
+ drawn.controls = plays;
267
+ }
268
+ if (drawn instanceof HTMLVideoElement && plays) {
269
+ drawn.autoplay = true;
270
+ drawn.setAttribute('playsinline', '');
174
271
  }
175
272
  drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
176
273
  if (drawn !== this.#drawn)
@@ -204,5 +301,8 @@ export function defineRoomMedia(client, registry = customElements) {
204
301
  void this.#load();
205
302
  }
206
303
  }
207
- registry.define(ROOM_MEDIA, RoomMedia);
304
+ customElements.define(ROOM_MEDIA, RoomMedia);
305
+ customElements.define(KEYED_MEDIA, class extends RoomMedia {
306
+ static observedAttributes = KEYED_ATTRIBUTES;
307
+ });
208
308
  }