@agentshouse/mdruntime 0.1.0-c850521dcad03 → 0.1.0-c8aadbf0beec5

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 (293) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +0 -3
  3. package/dist/acceptance.d.ts.map +1 -1
  4. package/dist/acceptance.js +75 -165
  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 +8 -2
  9. package/dist/actions.d.ts.map +1 -1
  10. package/dist/actions.js +143 -72
  11. package/dist/adapter.d.ts +113 -57
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +0 -1
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +0 -5
  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 +1 -1
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +6 -18
  22. package/dist/change-set.d.ts +4 -0
  23. package/dist/change-set.d.ts.map +1 -1
  24. package/dist/change-set.js +6 -0
  25. package/dist/change.d.ts +4 -0
  26. package/dist/change.d.ts.map +1 -1
  27. package/dist/change.js +7 -2
  28. package/dist/chat-types.d.ts +0 -2
  29. package/dist/chat-types.d.ts.map +1 -1
  30. package/dist/chat-types.js +0 -2
  31. package/dist/client.d.ts +19 -21
  32. package/dist/client.d.ts.map +1 -1
  33. package/dist/client.js +45 -58
  34. package/dist/collection.d.ts +26 -4
  35. package/dist/collection.d.ts.map +1 -1
  36. package/dist/collection.js +28 -10
  37. package/dist/column.d.ts +5 -0
  38. package/dist/column.d.ts.map +1 -0
  39. package/dist/column.js +9 -0
  40. package/dist/compile.d.ts +2 -0
  41. package/dist/compile.d.ts.map +1 -1
  42. package/dist/compile.js +31 -25
  43. package/dist/connection.d.ts +1 -1
  44. package/dist/connection.d.ts.map +1 -1
  45. package/dist/connection.js +39 -27
  46. package/dist/context.d.ts.map +1 -1
  47. package/dist/context.js +1 -1
  48. package/dist/conversation-live.d.ts +152 -0
  49. package/dist/conversation-live.d.ts.map +1 -0
  50. package/dist/conversation-live.js +261 -0
  51. package/dist/conversation-row.d.ts +8 -1
  52. package/dist/conversation-row.d.ts.map +1 -1
  53. package/dist/conversation-row.js +20 -7
  54. package/dist/conversation.d.ts +55 -45
  55. package/dist/conversation.d.ts.map +1 -1
  56. package/dist/conversation.js +976 -1033
  57. package/dist/declaration.d.ts +10 -0
  58. package/dist/declaration.d.ts.map +1 -0
  59. package/dist/declaration.js +24 -0
  60. package/dist/discovery.d.ts +3 -1
  61. package/dist/discovery.d.ts.map +1 -1
  62. package/dist/discovery.js +47 -47
  63. package/dist/download.d.ts +6 -0
  64. package/dist/download.d.ts.map +1 -0
  65. package/dist/download.js +42 -0
  66. package/dist/durability.d.ts +5 -0
  67. package/dist/durability.d.ts.map +1 -1
  68. package/dist/durability.js +7 -0
  69. package/dist/entry.d.ts +6 -0
  70. package/dist/entry.d.ts.map +1 -1
  71. package/dist/entry.js +24 -12
  72. package/dist/expectation.d.ts +26 -13
  73. package/dist/expectation.d.ts.map +1 -1
  74. package/dist/expectation.js +72 -19
  75. package/dist/failure.d.ts +3 -0
  76. package/dist/failure.d.ts.map +1 -1
  77. package/dist/failure.js +8 -0
  78. package/dist/figures.d.ts +1 -0
  79. package/dist/figures.d.ts.map +1 -1
  80. package/dist/figures.js +6 -4
  81. package/dist/file.d.ts +1 -1
  82. package/dist/file.d.ts.map +1 -1
  83. package/dist/file.js +3 -2
  84. package/dist/host.d.ts +23 -4
  85. package/dist/host.d.ts.map +1 -1
  86. package/dist/host.js +83 -19
  87. package/dist/house-query.d.ts +21 -0
  88. package/dist/house-query.d.ts.map +1 -0
  89. package/dist/house-query.js +41 -0
  90. package/dist/index.d.ts +21 -10
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +16 -6
  93. package/dist/install.d.ts +10 -6
  94. package/dist/install.d.ts.map +1 -1
  95. package/dist/install.js +93 -116
  96. package/dist/lifecycle.d.ts +2 -2
  97. package/dist/lifecycle.d.ts.map +1 -1
  98. package/dist/lifecycle.js +79 -56
  99. package/dist/listing.d.ts +29 -22
  100. package/dist/listing.d.ts.map +1 -1
  101. package/dist/listing.js +71 -78
  102. package/dist/live.d.ts +5 -3
  103. package/dist/live.d.ts.map +1 -1
  104. package/dist/live.js +74 -33
  105. package/dist/loaded.d.ts +5 -0
  106. package/dist/loaded.d.ts.map +1 -0
  107. package/dist/loaded.js +40 -0
  108. package/dist/locks.d.ts +2 -4
  109. package/dist/locks.d.ts.map +1 -1
  110. package/dist/locks.js +12 -39
  111. package/dist/lost.d.ts.map +1 -1
  112. package/dist/lost.js +11 -23
  113. package/dist/media.d.ts +19 -2
  114. package/dist/media.d.ts.map +1 -1
  115. package/dist/media.js +105 -27
  116. package/dist/memory.d.ts +9 -3
  117. package/dist/memory.d.ts.map +1 -1
  118. package/dist/memory.js +94 -32
  119. package/dist/messages.d.ts +12 -6
  120. package/dist/messages.d.ts.map +1 -1
  121. package/dist/messages.js +34 -38
  122. package/dist/modal.d.ts +2 -0
  123. package/dist/modal.d.ts.map +1 -0
  124. package/dist/modal.js +11 -0
  125. package/dist/model.d.ts +4 -3
  126. package/dist/model.d.ts.map +1 -1
  127. package/dist/model.js +6 -5
  128. package/dist/models.d.ts +4 -8
  129. package/dist/models.d.ts.map +1 -1
  130. package/dist/models.js +97 -137
  131. package/dist/observation.d.ts +29 -12
  132. package/dist/observation.d.ts.map +1 -1
  133. package/dist/observation.js +217 -85
  134. package/dist/online.d.ts +7 -0
  135. package/dist/online.d.ts.map +1 -0
  136. package/dist/online.js +29 -0
  137. package/dist/opened.d.ts +1 -1
  138. package/dist/opened.d.ts.map +1 -1
  139. package/dist/opened.js +5 -5
  140. package/dist/opening.d.ts.map +1 -1
  141. package/dist/opening.js +24 -11
  142. package/dist/outcome.d.ts +13 -1
  143. package/dist/outcome.d.ts.map +1 -1
  144. package/dist/outcome.js +32 -2
  145. package/dist/overlay.d.ts +6 -2
  146. package/dist/overlay.d.ts.map +1 -1
  147. package/dist/overlay.js +37 -24
  148. package/dist/page-metadata.d.ts +8 -0
  149. package/dist/page-metadata.d.ts.map +1 -0
  150. package/dist/page-metadata.js +19 -0
  151. package/dist/parts.d.ts +5 -58
  152. package/dist/parts.d.ts.map +1 -1
  153. package/dist/parts.js +28 -110
  154. package/dist/paths.d.ts +1 -0
  155. package/dist/paths.d.ts.map +1 -1
  156. package/dist/paths.js +22 -0
  157. package/dist/preparation.d.ts +32 -7
  158. package/dist/preparation.d.ts.map +1 -1
  159. package/dist/preparation.js +201 -92
  160. package/dist/presence.d.ts +58 -0
  161. package/dist/presence.d.ts.map +1 -0
  162. package/dist/presence.js +231 -0
  163. package/dist/queries.d.ts +2 -2
  164. package/dist/queries.d.ts.map +1 -1
  165. package/dist/queries.js +86 -71
  166. package/dist/query.d.ts +0 -1
  167. package/dist/query.d.ts.map +1 -1
  168. package/dist/questions.d.ts +1 -5
  169. package/dist/questions.d.ts.map +1 -1
  170. package/dist/questions.js +1 -7
  171. package/dist/queue.d.ts +40 -0
  172. package/dist/queue.d.ts.map +1 -0
  173. package/dist/queue.js +480 -0
  174. package/dist/reach.d.ts +14 -6
  175. package/dist/reach.d.ts.map +1 -1
  176. package/dist/reach.js +164 -33
  177. package/dist/react.d.ts +15 -1
  178. package/dist/react.d.ts.map +1 -1
  179. package/dist/react.js +33 -1
  180. package/dist/readiness.d.ts +16 -5
  181. package/dist/readiness.d.ts.map +1 -1
  182. package/dist/readiness.js +10 -10
  183. package/dist/reads.d.ts +5 -2
  184. package/dist/reads.d.ts.map +1 -1
  185. package/dist/reads.js +49 -7
  186. package/dist/recovery.d.ts +4 -1
  187. package/dist/recovery.d.ts.map +1 -1
  188. package/dist/recovery.js +31 -8
  189. package/dist/refresh.js +2 -2
  190. package/dist/refusal.d.ts.map +1 -1
  191. package/dist/refusal.js +5 -6
  192. package/dist/replica.d.ts +5 -10
  193. package/dist/replica.d.ts.map +1 -1
  194. package/dist/replica.js +17 -18
  195. package/dist/retried.d.ts +30 -0
  196. package/dist/retried.d.ts.map +1 -0
  197. package/dist/retried.js +72 -0
  198. package/dist/room-draft.d.ts +31 -8
  199. package/dist/room-draft.d.ts.map +1 -1
  200. package/dist/room-draft.js +273 -66
  201. package/dist/room-drafts.d.ts.map +1 -1
  202. package/dist/room-drafts.js +22 -18
  203. package/dist/room-list.d.ts +10 -0
  204. package/dist/room-list.d.ts.map +1 -0
  205. package/dist/room-list.js +45 -0
  206. package/dist/rows.d.ts +2 -1
  207. package/dist/rows.d.ts.map +1 -1
  208. package/dist/rows.js +9 -10
  209. package/dist/running.d.ts +5 -0
  210. package/dist/running.d.ts.map +1 -0
  211. package/dist/running.js +10 -0
  212. package/dist/runtime.d.ts +13 -20
  213. package/dist/runtime.d.ts.map +1 -1
  214. package/dist/save.d.ts +42 -86
  215. package/dist/save.d.ts.map +1 -1
  216. package/dist/save.js +326 -225
  217. package/dist/saves.d.ts +4 -40
  218. package/dist/saves.d.ts.map +1 -1
  219. package/dist/saves.js +143 -710
  220. package/dist/seed.d.ts.map +1 -1
  221. package/dist/seed.js +4 -5
  222. package/dist/shared.d.ts +1 -6
  223. package/dist/shared.d.ts.map +1 -1
  224. package/dist/shared.js +13 -95
  225. package/dist/shown.d.ts +9 -5
  226. package/dist/shown.d.ts.map +1 -1
  227. package/dist/shown.js +99 -67
  228. package/dist/socket/lanes.d.ts +12 -4
  229. package/dist/socket/lanes.d.ts.map +1 -1
  230. package/dist/socket/lanes.js +34 -8
  231. package/dist/socket/session.d.ts +4 -2
  232. package/dist/socket/session.d.ts.map +1 -1
  233. package/dist/socket/session.js +3 -0
  234. package/dist/socket.d.ts +4 -6
  235. package/dist/socket.d.ts.map +1 -1
  236. package/dist/socket.js +6 -16
  237. package/dist/source.d.ts +5 -7
  238. package/dist/source.d.ts.map +1 -1
  239. package/dist/source.js +18 -6
  240. package/dist/store/installs.d.ts +2 -2
  241. package/dist/store/installs.d.ts.map +1 -1
  242. package/dist/store/installs.js +10 -4
  243. package/dist/store/readiness.d.ts +5 -4
  244. package/dist/store/readiness.d.ts.map +1 -1
  245. package/dist/store/readiness.js +28 -12
  246. package/dist/store/records.d.ts +23 -8
  247. package/dist/store/records.d.ts.map +1 -1
  248. package/dist/store/records.js +84 -24
  249. package/dist/store/rooms-shown.d.ts +8 -0
  250. package/dist/store/rooms-shown.d.ts.map +1 -0
  251. package/dist/store/rooms-shown.js +13 -0
  252. package/dist/store/space.d.ts +1 -1
  253. package/dist/store/space.d.ts.map +1 -1
  254. package/dist/store/space.js +0 -2
  255. package/dist/store/watchers.js +1 -2
  256. package/dist/store.d.ts +26 -16
  257. package/dist/store.d.ts.map +1 -1
  258. package/dist/store.js +50 -18
  259. package/dist/stored.d.ts +26 -14
  260. package/dist/stored.d.ts.map +1 -1
  261. package/dist/stored.js +101 -36
  262. package/dist/surface.d.ts +13 -7
  263. package/dist/surface.d.ts.map +1 -1
  264. package/dist/surface.js +70 -37
  265. package/dist/sync.d.ts +4 -3
  266. package/dist/sync.d.ts.map +1 -1
  267. package/dist/sync.js +135 -109
  268. package/dist/tables.d.ts +19 -58
  269. package/dist/tables.d.ts.map +1 -1
  270. package/dist/tables.js +91 -332
  271. package/dist/tallies.d.ts.map +1 -1
  272. package/dist/tallies.js +6 -7
  273. package/dist/validation.d.ts.map +1 -1
  274. package/dist/validation.js +4 -10
  275. package/dist/wire.d.ts +66 -7
  276. package/dist/wire.d.ts.map +1 -1
  277. package/dist/wire.js +25 -9
  278. package/package.json +3 -2
  279. package/dist/attempt.d.ts +0 -16
  280. package/dist/attempt.d.ts.map +0 -1
  281. package/dist/attempt.js +0 -70
  282. package/dist/job.d.ts +0 -33
  283. package/dist/job.d.ts.map +0 -1
  284. package/dist/job.js +0 -54
  285. package/dist/log.d.ts +0 -6
  286. package/dist/log.d.ts.map +0 -1
  287. package/dist/log.js +0 -14
  288. package/dist/socket/rooms.d.ts +0 -43
  289. package/dist/socket/rooms.d.ts.map +0 -1
  290. package/dist/socket/rooms.js +0 -90
  291. package/dist/store/fences.d.ts +0 -16
  292. package/dist/store/fences.d.ts.map +0 -1
  293. package/dist/store/fences.js +0 -26
package/dist/live.js CHANGED
@@ -1,26 +1,25 @@
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));
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));
18
17
  }
19
- function affected(plan, set) {
20
- if (set.rooms.some((locator) => reads(plan, locator)))
18
+ function affected({ plan, reads }, set) {
19
+ if (set.rooms.some(reads))
21
20
  return true;
22
21
  const paths = narrowed(plan) ? new Set(plan.paths) : null;
23
- 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)));
24
23
  }
25
24
  function shown(entry, held) {
26
25
  const cover = entry.cover(held);
@@ -29,11 +28,13 @@ function shown(entry, held) {
29
28
  export function createLiveQueries(run, holding) {
30
29
  const entries = new Map();
31
30
  let closed = false;
32
- let recovering = false;
33
- let recoverAgain = false;
31
+ let recoveringNow = false;
32
+ let recoveringAll = false;
33
+ const recovering = new Set();
34
34
  function deliver(entry, next) {
35
35
  const previous = entry.digest;
36
36
  entry.digest = digestOf(next);
37
+ entry.pending = 'pending' in entry.digest ? entry.digest.pending : null;
37
38
  entry.covered = JSON.stringify('pending' in next.result ? next.result : next.result.coverage);
38
39
  const change = previous === undefined ? null : changeOf(previous, next);
39
40
  if (change !== null) {
@@ -76,7 +77,6 @@ export function createLiveQueries(run, holding) {
76
77
  }
77
78
  }
78
79
  catch (error) {
79
- entry.dirty = false;
80
80
  const unanswered = [...entry.fresh.values()];
81
81
  entry.fresh.clear();
82
82
  for (const failed of unanswered)
@@ -87,58 +87,99 @@ export function createLiveQueries(run, holding) {
87
87
  }
88
88
  })();
89
89
  }
90
- function recovered() {
91
- if (recovering) {
92
- recoverAgain = true;
93
- return;
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
94
  }
95
- recovering = true;
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;
96
116
  void (async () => {
97
117
  try {
98
- do {
99
- recoverAgain = false;
100
- for (const entry of entries.values()) {
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) {
101
125
  if (entry.running)
102
126
  entry.dirty = true;
103
127
  }
104
- const waiting = [...entries.values()].filter((entry) => !entry.running);
105
- if (waiting.length === 0 || closed)
128
+ const waiting = reached.filter((entry) => !entry.running);
129
+ if (waiting.length === 0)
106
130
  continue;
107
131
  const held = await holding();
108
132
  for (const entry of waiting) {
109
133
  if (entry.running)
110
134
  continue;
135
+ const read = all ? [] : touched.filter(entry.reads);
136
+ if (read.length > 0 && pendingMoved(entry, held, read))
137
+ continue;
111
138
  if (entry.digest === undefined || shown(entry, held) !== entry.covered)
112
139
  schedule(entry);
113
140
  }
114
- } while (recoverAgain && !closed);
141
+ }
115
142
  }
116
- catch {
117
- recoverAgain = false;
143
+ catch (error) {
144
+ uncaught(error);
118
145
  }
119
146
  finally {
120
- recovering = false;
147
+ recoveringNow = false;
121
148
  }
122
149
  })();
123
150
  }
124
151
  return {
125
152
  touched(set) {
153
+ const pending = new Set();
126
154
  for (const entry of entries.values()) {
127
- if (affected(entry.plan, set))
155
+ if (!affected(entry, set))
156
+ continue;
157
+ if (entry.pending === null || entry.running) {
128
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);
129
165
  }
166
+ if (pending.size > 0)
167
+ recovered([...pending]);
130
168
  },
131
169
  recover: recovered,
132
- watch(plan, identity, cover, listener, failed) {
170
+ watch(plan, identity, cover, pendingAt, listener, failed) {
133
171
  let entry = entries.get(identity);
134
172
  if (entry === undefined) {
135
173
  entry = {
136
174
  plan,
175
+ reads: readerOf(plan),
137
176
  cover,
177
+ pendingAt,
138
178
  listeners: new Set(),
139
179
  fresh: new Map(),
140
180
  ready: new Set(),
141
181
  digest: undefined,
182
+ pending: null,
142
183
  covered: '',
143
184
  dirty: false,
144
185
  running: false,
@@ -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
+ }
package/dist/locks.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import type { DiscoveredRoom } from './adapter.js';
2
1
  import type { Runtime } from './runtime.js';
3
- export declare function locked({ store, socket }: Runtime, locator: string): Promise<boolean>;
4
- export declare function lockedRooms(runtime: Runtime): Promise<readonly string[]>;
2
+ export declare function locked({ store, presence }: Runtime, locator: string): Promise<boolean>;
3
+ export declare function lockedRooms({ store, presence }: Runtime): Promise<readonly string[]>;
5
4
  export declare function relocked(runtime: Runtime, before: readonly string[]): Promise<void>;
6
- export declare function confirmLocks({ socket }: Runtime, listed: readonly DiscoveredRoom[]): void;
7
5
  export declare function connectionLost(runtime: Runtime): void;
8
6
  export declare function watchLocks({ store }: Runtime, notify: () => void): () => void;
9
7
  //# sourceMappingURL=locks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAa5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK1F;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAW9E;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAMzE;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,cAAc,EAAE,QAOlF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAa9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
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 CHANGED
@@ -1,59 +1,32 @@
1
+ import { uncaught } from './failure.js';
1
2
  import { emitRooms, LOCKS_TOPIC } from './shown.js';
2
- async function offlineModes({ store, socket }) {
3
- const modes = new Map();
4
- for (const [locator, { room }] of socket.rooms.declarations()) {
5
- const declaration = room ?? socket.rooms.discovered(locator);
6
- if (declaration !== undefined)
7
- modes.set(locator, declaration.replica.offline);
8
- }
9
- for (const [locator, { offline }] of (await store.covering()).rooms)
10
- modes.set(locator, offline);
11
- return modes;
3
+ export async function locked({ store, presence }, locator) {
4
+ return presence.locked(locator, async () => (await store.open()).offline(locator));
12
5
  }
13
- export async function locked({ store, socket }, locator) {
14
- if (store.fences.has(locator) || socket.rooms.standing(locator).confirmed)
15
- return false;
16
- const held = socket.rooms.declared(locator)?.room ?? socket.rooms.discovered(locator);
17
- const mode = (await (await store.open()).offline(locator)) ?? held?.replica.offline;
18
- return mode === 'locked';
19
- }
20
- export async function lockedRooms(runtime) {
21
- const { store, socket } = runtime;
22
- return [...(await offlineModes(runtime))]
23
- .filter(([locator, mode]) => mode === 'locked' &&
24
- !socket.rooms.standing(locator).confirmed &&
25
- !store.fences.has(locator))
26
- .map(([locator]) => locator)
27
- .sort();
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);
28
11
  }
29
12
  export async function relocked(runtime, before) {
30
13
  const after = await lockedRooms(runtime);
31
14
  if (JSON.stringify(after) === JSON.stringify(before))
32
15
  return;
33
- runtime.journal.record(`locked ${after.length}`);
34
16
  emitRooms(runtime);
35
17
  runtime.store.tell(LOCKS_TOPIC, undefined);
36
18
  }
37
- export function confirmLocks({ socket }, listed) {
38
- if (!socket.isOpen())
39
- return;
40
- for (const room of listed) {
41
- if (room.replica.admission === 'admitted') {
42
- socket.rooms.stand(room.locator, { confirmed: true });
43
- }
44
- }
45
- }
46
19
  export function connectionLost(runtime) {
47
- const { socket } = runtime;
20
+ const { socket, presence } = runtime;
48
21
  if (socket.closed())
49
22
  return;
50
- socket.rooms.connectionLost(() => {
23
+ presence.connectionLost(() => {
51
24
  if (socket.isOpen() || socket.closed())
52
25
  return;
53
26
  void lockedRooms(runtime).then((before) => {
54
- socket.rooms.standAll({ confirmed: false });
27
+ presence.lapse();
55
28
  return relocked(runtime, before);
56
- }, () => { });
29
+ }, uncaught);
57
30
  });
58
31
  }
59
32
  export function watchLocks({ store }, notify) {
@@ -1 +1 @@
1
- {"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAU5C,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,QAOtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAqC5E"}
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 CHANGED
@@ -1,12 +1,8 @@
1
1
  import { changeSet, mergeChangeSets } from './change-set.js';
2
- import { ERASE_BATCH, forgetInstall } from './install.js';
3
- import { recoverReads, statusShown } from './shown.js';
2
+ import { ERASE_BATCH } from './install.js';
3
+ import { unpair } from './queue.js';
4
+ import { recoverReads } from './shown.js';
4
5
  import { yielded } from './turn.js';
5
- function forget({ store, socket }, locator) {
6
- forgetInstall(store, locator);
7
- socket.rooms.forget(locator);
8
- store.forget(locator);
9
- }
10
6
  export async function eraseFenced({ store }, locators) {
11
7
  for (const locator of locators) {
12
8
  while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
@@ -14,24 +10,17 @@ export async function eraseFenced({ store }, locators) {
14
10
  }
15
11
  }
16
12
  export function fenceLive(runtime, locators) {
17
- const { store, socket, journal } = runtime;
13
+ const { store, socket, presence } = runtime;
18
14
  for (const locator of new Set(locators)) {
19
- if (!store.fences.raise(locator, socket.session.now().discoveries))
15
+ if (!presence.lose(locator, socket.session.now().discoveries))
20
16
  continue;
21
- forget(runtime, locator);
22
- journal.record(`room lost ${locator}`);
17
+ store.forget(locator);
23
18
  }
24
19
  }
25
20
  export async function loseRooms(runtime, locators) {
26
- const { store } = runtime;
21
+ const { store, presence } = runtime;
27
22
  fenceLive(runtime, locators);
28
- const fresh = [...new Set(locators)].filter((locator) => {
29
- const fence = store.fences.of(locator);
30
- if (fence === undefined || fence.written)
31
- return false;
32
- store.fences.mark(locator, true);
33
- return true;
34
- });
23
+ const fresh = [...new Set(locators)].filter((locator) => presence.writing(locator));
35
24
  if (fresh.length === 0)
36
25
  return;
37
26
  let held = [];
@@ -43,7 +32,7 @@ export async function loseRooms(runtime, locators) {
43
32
  }
44
33
  catch (error) {
45
34
  for (const locator of fresh)
46
- store.fences.mark(locator, false);
35
+ presence.unwritten(locator);
47
36
  throw error;
48
37
  }
49
38
  finally {
@@ -53,9 +42,8 @@ export async function loseRooms(runtime, locators) {
53
42
  queue: true,
54
43
  drafts: held.filter((draft) => draft.locator === locator).map(({ path }) => path),
55
44
  }))));
56
- recoverReads(runtime);
57
- statusShown(runtime);
45
+ recoverReads(runtime, fresh);
58
46
  }
59
- await store.durably((local) => runtime.unpair(local));
47
+ await unpair(runtime);
60
48
  await eraseFenced(runtime, fresh);
61
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,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,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,CA0LN"}
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;AA4BD,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,7 +1,18 @@
1
- import { UNCERTAIN } from './outcome.js';
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';
2
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"]';
3
13
  const ATTRIBUTES = ['room', 'path', 'revision', 'width', 'height', 'alt'];
4
- const LOADING = new Set(['room', 'path', 'revision']);
14
+ const KEYED_ATTRIBUTES = ['link', 'alt'];
15
+ const LOADING = new Set(['link', 'room', 'path', 'revision']);
5
16
  const NEARING = '600px 0px';
6
17
  const RELINKS = 2;
7
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.
@@ -10,12 +21,42 @@ const SHAPE = '16 / 9';
10
21
  const STYLE = `:host{display:block}
11
22
  [part=box]{position:relative;overflow:hidden}
12
23
  [part=box]>img,[part=box]>video,[part=box]>audio{display:block;width:100%;height:100%;object-fit:contain}
13
- [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}`;
14
28
  const shows = new WeakMap();
15
29
  export function shownBy(show, client) {
16
30
  shows.set(client, show);
17
31
  return client;
18
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
+ }
19
60
  function ratioOf(width, height) {
20
61
  const across = Number(width);
21
62
  const down = Number(height);
@@ -29,23 +70,62 @@ function refusedForGood(shown) {
29
70
  return (shown.kind === 'rejected' || shown.kind === 'scoped-refusal') && !shown.retryable;
30
71
  }
31
72
  function drawnFor(mediaType) {
32
- if (mediaType.startsWith('image/'))
73
+ if (isImageType(mediaType))
33
74
  return 'img';
34
- if (mediaType.startsWith('video/'))
75
+ if (isVideoType(mediaType))
35
76
  return 'video';
36
- if (mediaType.startsWith('audio/'))
77
+ if (isAudioType(mediaType))
37
78
  return 'audio';
38
79
  return null;
39
80
  }
40
- export function defineRoomMedia(client, registry = customElements) {
41
- 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) {
92
+ void loaded(client.buildFile, VIEWER).then((file) => file?.openViewer({
93
+ opener,
94
+ alone,
95
+ download: (at) => void downloadAt(client, at),
96
+ }));
97
+ }
98
+ function pressed(client) {
99
+ return (event) => {
100
+ if (event.defaultPrevented || event.detail > 1)
101
+ return;
102
+ for (const node of event.composedPath()) {
103
+ if (!(node instanceof Element))
104
+ continue;
105
+ if (viewable(node)) {
106
+ event.preventDefault();
107
+ void client.then((one) => viewed(one, node, !rendered(node)));
108
+ return;
109
+ }
110
+ if (node.matches(PRESSED_ELSEWHERE))
111
+ return;
112
+ }
113
+ };
114
+ }
115
+ export function viewFile(client, media) {
116
+ viewed(client, media, true);
117
+ }
118
+ export function defineRoomMedia(client) {
119
+ if (customElements.get(ROOM_MEDIA) !== undefined)
42
120
  return;
43
121
  const connected = Promise.resolve(client);
122
+ document.addEventListener('click', pressed(connected));
44
123
  class RoomMedia extends HTMLElement {
45
124
  static observedAttributes = ATTRIBUTES;
46
125
  #root = this.attachShadow({ mode: 'open' });
47
126
  #box = document.createElement('div');
48
127
  #fallback = document.createElement('slot');
128
+ #play = document.createElement('span');
49
129
  #watching = null;
50
130
  #near = false;
51
131
  #asked = 0;
@@ -56,6 +136,7 @@ export function defineRoomMedia(client, registry = customElements) {
56
136
  constructor() {
57
137
  super();
58
138
  this.#box.setAttribute('part', 'box');
139
+ this.#play.setAttribute('part', 'play');
59
140
  this.#root.append(Object.assign(document.createElement('style'), { textContent: STYLE }), this.#box);
60
141
  this.#shape();
61
142
  }
@@ -107,15 +188,8 @@ export function defineRoomMedia(client, registry = customElements) {
107
188
  async #load() {
108
189
  const asked = (this.#asked += 1);
109
190
  this.#loaded = false;
110
- const room = this.getAttribute('room');
111
- const path = this.getAttribute('path');
112
- const revision = this.getAttribute('revision') ?? undefined;
113
- if (room === null || path === null) {
114
- this.#unreadable();
115
- return;
116
- }
117
- const show = shows.get(await connected);
118
- const shown = show === undefined ? null : await show(room, path, revision).catch(() => UNCERTAIN);
191
+ const showing = shownAt(await connected, mediaAt(this));
192
+ const shown = showing === null ? null : await showing.catch(() => UNCERTAIN);
119
193
  if (asked !== this.#asked)
120
194
  return;
121
195
  if (shown?.kind === 'link') {
@@ -129,11 +203,7 @@ export function defineRoomMedia(client, registry = customElements) {
129
203
  this.#unshown(asked);
130
204
  return;
131
205
  }
132
- const copy = await new Response(shown.stream, {
133
- headers: { 'content-type': shown.mediaType },
134
- })
135
- .blob()
136
- .catch(() => null);
206
+ const copy = await blobOf(shown).catch(() => null);
137
207
  if (asked !== this.#asked)
138
208
  return;
139
209
  if (copy === null)
@@ -157,7 +227,9 @@ export function defineRoomMedia(client, registry = customElements) {
157
227
  if (content === null)
158
228
  this.#box.replaceChildren();
159
229
  else if (content.parentNode !== this.#box)
160
- this.#box.replaceChildren(content);
230
+ this.#box.replaceChildren(...(content instanceof HTMLVideoElement && !content.controls
231
+ ? [content, this.#play]
232
+ : [content]));
161
233
  this.#label();
162
234
  }
163
235
  #unreadable() {
@@ -174,13 +246,16 @@ export function defineRoomMedia(client, registry = customElements) {
174
246
  const kept = this.#drawn?.localName === tag ? this.#drawn : null;
175
247
  const drawn = kept ?? document.createElement(tag);
176
248
  if (kept === null) {
249
+ const plays = !(drawn instanceof HTMLVideoElement) || this.closest(`.${VIEWING}`) !== null;
177
250
  if (drawn instanceof HTMLImageElement)
178
251
  drawn.decoding = 'async';
179
252
  if (drawn instanceof HTMLMediaElement) {
180
- drawn.controls = true;
181
253
  drawn.preload = 'metadata';
182
- if (drawn instanceof HTMLVideoElement)
183
- drawn.playsInline = true;
254
+ drawn.controls = plays;
255
+ }
256
+ if (drawn instanceof HTMLVideoElement && plays) {
257
+ drawn.autoplay = true;
258
+ drawn.setAttribute('playsinline', '');
184
259
  }
185
260
  drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
186
261
  if (drawn !== this.#drawn)
@@ -214,5 +289,8 @@ export function defineRoomMedia(client, registry = customElements) {
214
289
  void this.#load();
215
290
  }
216
291
  }
217
- registry.define(ROOM_MEDIA, RoomMedia);
292
+ customElements.define(ROOM_MEDIA, RoomMedia);
293
+ customElements.define(KEYED_MEDIA, class extends RoomMedia {
294
+ static observedAttributes = KEYED_ATTRIBUTES;
295
+ });
218
296
  }