@openrails/contentkit-ui 0.0.0-placeholder → 0.68.0

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 (367) hide show
  1. package/README.md +424 -1
  2. package/dist/appearance.d.ts +38 -0
  3. package/dist/appearance.js +15 -0
  4. package/dist/appearance.js.map +1 -0
  5. package/dist/assets/hash.worker-BYfo-7MQ.js.map +1 -0
  6. package/dist/client/aspect.d.ts +6 -0
  7. package/dist/client/aspect.js +17 -0
  8. package/dist/client/aspect.js.map +1 -0
  9. package/dist/client/client.d.ts +51 -0
  10. package/dist/client/client.js +35 -0
  11. package/dist/client/client.js.map +1 -0
  12. package/dist/client/codes.d.ts +12 -0
  13. package/dist/client/codes.js +19 -0
  14. package/dist/client/codes.js.map +1 -0
  15. package/dist/client/content/bans.d.ts +15 -0
  16. package/dist/client/content/bans.js +40 -0
  17. package/dist/client/content/bans.js.map +1 -0
  18. package/dist/client/content/comments.d.ts +36 -0
  19. package/dist/client/content/comments.js +93 -0
  20. package/dist/client/content/comments.js.map +1 -0
  21. package/dist/client/content/favorites.d.ts +14 -0
  22. package/dist/client/content/favorites.js +42 -0
  23. package/dist/client/content/favorites.js.map +1 -0
  24. package/dist/client/content/moderation.d.ts +18 -0
  25. package/dist/client/content/moderation.js +37 -0
  26. package/dist/client/content/moderation.js.map +1 -0
  27. package/dist/client/content/polls.d.ts +47 -0
  28. package/dist/client/content/polls.js +148 -0
  29. package/dist/client/content/polls.js.map +1 -0
  30. package/dist/client/content/posts.d.ts +44 -0
  31. package/dist/client/content/posts.js +91 -0
  32. package/dist/client/content/posts.js.map +1 -0
  33. package/dist/client/content/reactions.d.ts +12 -0
  34. package/dist/client/content/reactions.js +36 -0
  35. package/dist/client/content/reactions.js.map +1 -0
  36. package/dist/client/content/types.d.ts +91 -0
  37. package/dist/client/content/types.js +8 -0
  38. package/dist/client/content/types.js.map +1 -0
  39. package/dist/client/crop.d.ts +32 -0
  40. package/dist/client/crop.js +103 -0
  41. package/dist/client/crop.js.map +1 -0
  42. package/dist/client/errors.d.ts +54 -0
  43. package/dist/client/errors.js +80 -0
  44. package/dist/client/errors.js.map +1 -0
  45. package/dist/client/gallery.d.ts +43 -0
  46. package/dist/client/gallery.js +86 -0
  47. package/dist/client/gallery.js.map +1 -0
  48. package/dist/client/generated/error-codes.d.ts +5 -0
  49. package/dist/client/generated/error-codes.js +131 -0
  50. package/dist/client/generated/error-codes.js.map +1 -0
  51. package/dist/client/generated/routes.d.ts +1086 -0
  52. package/dist/client/generated/routes.js +1400 -0
  53. package/dist/client/generated/routes.js.map +1 -0
  54. package/dist/client/generated/wire.d.ts +630 -0
  55. package/dist/client/generated/wire.js +6 -0
  56. package/dist/client/generated/wire.js.map +1 -0
  57. package/dist/client/http.d.ts +79 -0
  58. package/dist/client/http.js +74 -0
  59. package/dist/client/http.js.map +1 -0
  60. package/dist/client/image.d.ts +24 -0
  61. package/dist/client/image.js +65 -0
  62. package/dist/client/image.js.map +1 -0
  63. package/dist/client/index.d.ts +33 -0
  64. package/dist/client/media/api.d.ts +36 -0
  65. package/dist/client/media/api.js +61 -0
  66. package/dist/client/media/api.js.map +1 -0
  67. package/dist/client/media/client.d.ts +247 -0
  68. package/dist/client/media/client.js +407 -0
  69. package/dist/client/media/client.js.map +1 -0
  70. package/dist/client/media/encode.d.ts +3 -0
  71. package/dist/client/media/encode.js +8 -0
  72. package/dist/client/media/encode.js.map +1 -0
  73. package/dist/client/media/hash-stream.d.ts +6 -0
  74. package/dist/client/media/hash-stream.js +16 -0
  75. package/dist/client/media/hash-stream.js.map +1 -0
  76. package/dist/client/media/hash.d.ts +12 -0
  77. package/dist/client/media/hash.js +48 -0
  78. package/dist/client/media/hash.js.map +1 -0
  79. package/dist/client/media/hash.worker-inline.js +18 -0
  80. package/dist/client/media/hash.worker-inline.js.map +1 -0
  81. package/dist/client/media/pacer.d.ts +21 -0
  82. package/dist/client/media/pacer.js +25 -0
  83. package/dist/client/media/pacer.js.map +1 -0
  84. package/dist/client/media/queue.d.ts +112 -0
  85. package/dist/client/media/queue.js +274 -0
  86. package/dist/client/media/queue.js.map +1 -0
  87. package/dist/client/media/ref.d.ts +6 -0
  88. package/dist/client/media/ref.js +10 -0
  89. package/dist/client/media/ref.js.map +1 -0
  90. package/dist/client/media/rules.d.ts +52 -0
  91. package/dist/client/media/rules.js +139 -0
  92. package/dist/client/media/rules.js.map +1 -0
  93. package/dist/client/media/transport.d.ts +13 -0
  94. package/dist/client/media/transport.js +33 -0
  95. package/dist/client/media/transport.js.map +1 -0
  96. package/dist/client/media/windows.d.ts +15 -0
  97. package/dist/client/media/windows.js +39 -0
  98. package/dist/client/media/windows.js.map +1 -0
  99. package/dist/client/playback.d.ts +200 -0
  100. package/dist/client/playback.js +142 -0
  101. package/dist/client/playback.js.map +1 -0
  102. package/dist/client/player.d.ts +102 -0
  103. package/dist/client/player.js +155 -0
  104. package/dist/client/player.js.map +1 -0
  105. package/dist/client/public.d.ts +25 -0
  106. package/dist/client/public.js +18 -0
  107. package/dist/client/public.js.map +1 -0
  108. package/dist/client/rendition.d.ts +19 -0
  109. package/dist/client/rendition.js +16 -0
  110. package/dist/client/rendition.js.map +1 -0
  111. package/dist/client/route.d.ts +39 -0
  112. package/dist/client/route.js +31 -0
  113. package/dist/client/route.js.map +1 -0
  114. package/dist/client/taxonomy.d.ts +30 -0
  115. package/dist/client/taxonomy.js +77 -0
  116. package/dist/client/taxonomy.js.map +1 -0
  117. package/dist/client.js +33 -0
  118. package/dist/components/encode-progress.d.ts +15 -0
  119. package/dist/components/encode-progress.js +49 -0
  120. package/dist/components/encode-progress.js.map +1 -0
  121. package/dist/components/hover-preview.d.ts +29 -0
  122. package/dist/components/hover-preview.js +49 -0
  123. package/dist/components/hover-preview.js.map +1 -0
  124. package/dist/components/image-crop-dialog.d.ts +48 -0
  125. package/dist/components/image-crop-dialog.js +359 -0
  126. package/dist/components/image-crop-dialog.js.map +1 -0
  127. package/dist/components/lazy-mount.d.ts +10 -0
  128. package/dist/components/lazy-mount.js +22 -0
  129. package/dist/components/lazy-mount.js.map +1 -0
  130. package/dist/components/media-folder-editor.d.ts +45 -0
  131. package/dist/components/media-folder-editor.js +564 -0
  132. package/dist/components/media-folder-editor.js.map +1 -0
  133. package/dist/components/media-gallery.d.ts +54 -0
  134. package/dist/components/media-gallery.js +597 -0
  135. package/dist/components/media-gallery.js.map +1 -0
  136. package/dist/components/media-readiness-notice.d.ts +24 -0
  137. package/dist/components/media-readiness-notice.js +61 -0
  138. package/dist/components/media-readiness-notice.js.map +1 -0
  139. package/dist/components/player-controls.d.ts +71 -0
  140. package/dist/components/player-controls.js +264 -0
  141. package/dist/components/player-controls.js.map +1 -0
  142. package/dist/components/progress.d.ts +5 -0
  143. package/dist/components/progress.js +14 -0
  144. package/dist/components/progress.js.map +1 -0
  145. package/dist/components/rendition-img.d.ts +34 -0
  146. package/dist/components/rendition-img.js +78 -0
  147. package/dist/components/rendition-img.js.map +1 -0
  148. package/dist/components/slot-editor.d.ts +95 -0
  149. package/dist/components/slot-editor.js +182 -0
  150. package/dist/components/slot-editor.js.map +1 -0
  151. package/dist/components/slot-image.d.ts +23 -0
  152. package/dist/components/slot-image.js +48 -0
  153. package/dist/components/slot-image.js.map +1 -0
  154. package/dist/components/slot-upload.d.ts +41 -0
  155. package/dist/components/slot-upload.js +213 -0
  156. package/dist/components/slot-upload.js.map +1 -0
  157. package/dist/components/social/bans.d.ts +42 -0
  158. package/dist/components/social/bans.js +300 -0
  159. package/dist/components/social/bans.js.map +1 -0
  160. package/dist/components/social/comments.d.ts +42 -0
  161. package/dist/components/social/comments.js +517 -0
  162. package/dist/components/social/comments.js.map +1 -0
  163. package/dist/components/social/engagement.d.ts +45 -0
  164. package/dist/components/social/engagement.js +129 -0
  165. package/dist/components/social/engagement.js.map +1 -0
  166. package/dist/components/social/index.d.ts +6 -0
  167. package/dist/components/social/moderation.d.ts +32 -0
  168. package/dist/components/social/moderation.js +383 -0
  169. package/dist/components/social/moderation.js.map +1 -0
  170. package/dist/components/social/parts.d.ts +50 -0
  171. package/dist/components/social/parts.js +106 -0
  172. package/dist/components/social/parts.js.map +1 -0
  173. package/dist/components/social/poll-editor.d.ts +34 -0
  174. package/dist/components/social/poll-editor.js +567 -0
  175. package/dist/components/social/poll-editor.js.map +1 -0
  176. package/dist/components/social/poll.d.ts +30 -0
  177. package/dist/components/social/poll.js +252 -0
  178. package/dist/components/social/poll.js.map +1 -0
  179. package/dist/components/sortable-list.d.ts +29 -0
  180. package/dist/components/sortable-list.js +121 -0
  181. package/dist/components/sortable-list.js.map +1 -0
  182. package/dist/components/video-mini-player.d.ts +35 -0
  183. package/dist/components/video-mini-player.js +236 -0
  184. package/dist/components/video-mini-player.js.map +1 -0
  185. package/dist/components/video-player.d.ts +146 -0
  186. package/dist/components/video-player.js +630 -0
  187. package/dist/components/video-player.js.map +1 -0
  188. package/dist/components/video-poster-picker.d.ts +59 -0
  189. package/dist/components/video-poster-picker.js +335 -0
  190. package/dist/components/video-poster-picker.js.map +1 -0
  191. package/dist/components/video-poster.d.ts +24 -0
  192. package/dist/components/video-poster.js +46 -0
  193. package/dist/components/video-poster.js.map +1 -0
  194. package/dist/i18n/context.d.ts +4 -0
  195. package/dist/i18n/context.js +11 -0
  196. package/dist/i18n/context.js.map +1 -0
  197. package/dist/i18n/messages.d.ts +40 -0
  198. package/dist/i18n/messages.js +94 -0
  199. package/dist/i18n/messages.js.map +1 -0
  200. package/dist/index.d.ts +23 -0
  201. package/dist/index.js +41 -0
  202. package/dist/locales/de.d.ts +2 -0
  203. package/dist/locales/de.js +271 -0
  204. package/dist/locales/de.js.map +1 -0
  205. package/dist/locales/en.d.ts +457 -0
  206. package/dist/locales/en.js +271 -0
  207. package/dist/locales/en.js.map +1 -0
  208. package/dist/locales/es.d.ts +2 -0
  209. package/dist/locales/es.js +271 -0
  210. package/dist/locales/es.js.map +1 -0
  211. package/dist/locales/ja.d.ts +2 -0
  212. package/dist/locales/ja.js +271 -0
  213. package/dist/locales/ja.js.map +1 -0
  214. package/dist/locales/ko.d.ts +2 -0
  215. package/dist/locales/ko.js +271 -0
  216. package/dist/locales/ko.js.map +1 -0
  217. package/dist/locales/social/de.d.ts +2 -0
  218. package/dist/locales/social/de.js +198 -0
  219. package/dist/locales/social/de.js.map +1 -0
  220. package/dist/locales/social/en.d.ts +195 -0
  221. package/dist/locales/social/en.js +198 -0
  222. package/dist/locales/social/en.js.map +1 -0
  223. package/dist/locales/social/es.d.ts +2 -0
  224. package/dist/locales/social/es.js +198 -0
  225. package/dist/locales/social/es.js.map +1 -0
  226. package/dist/locales/social/ja.d.ts +2 -0
  227. package/dist/locales/social/ja.js +198 -0
  228. package/dist/locales/social/ja.js.map +1 -0
  229. package/dist/locales/social/ko.d.ts +2 -0
  230. package/dist/locales/social/ko.js +198 -0
  231. package/dist/locales/social/ko.js.map +1 -0
  232. package/dist/locales/social/zh.d.ts +2 -0
  233. package/dist/locales/social/zh.js +198 -0
  234. package/dist/locales/social/zh.js.map +1 -0
  235. package/dist/locales/zh.d.ts +2 -0
  236. package/dist/locales/zh.js +271 -0
  237. package/dist/locales/zh.js.map +1 -0
  238. package/dist/provider.d.ts +22 -0
  239. package/dist/provider.js +59 -0
  240. package/dist/provider.js.map +1 -0
  241. package/dist/react/canonical.d.ts +33 -0
  242. package/dist/react/canonical.js +88 -0
  243. package/dist/react/canonical.js.map +1 -0
  244. package/dist/react/comments.d.ts +82 -0
  245. package/dist/react/comments.js +147 -0
  246. package/dist/react/comments.js.map +1 -0
  247. package/dist/react/config.d.ts +13 -0
  248. package/dist/react/config.js +14 -0
  249. package/dist/react/config.js.map +1 -0
  250. package/dist/react/context.d.ts +48 -0
  251. package/dist/react/context.js +37 -0
  252. package/dist/react/context.js.map +1 -0
  253. package/dist/react/crop.d.ts +49 -0
  254. package/dist/react/crop.js +107 -0
  255. package/dist/react/crop.js.map +1 -0
  256. package/dist/react/engagement.d.ts +38 -0
  257. package/dist/react/engagement.js +88 -0
  258. package/dist/react/engagement.js.map +1 -0
  259. package/dist/react/folder.d.ts +83 -0
  260. package/dist/react/folder.js +183 -0
  261. package/dist/react/folder.js.map +1 -0
  262. package/dist/react/gallery.d.ts +140 -0
  263. package/dist/react/gallery.js +477 -0
  264. package/dist/react/gallery.js.map +1 -0
  265. package/dist/react/index.d.ts +21 -0
  266. package/dist/react/inline-preview.d.ts +24 -0
  267. package/dist/react/inline-preview.js +76 -0
  268. package/dist/react/inline-preview.js.map +1 -0
  269. package/dist/react/player.d.ts +70 -0
  270. package/dist/react/player.js +214 -0
  271. package/dist/react/player.js.map +1 -0
  272. package/dist/react/polls.d.ts +74 -0
  273. package/dist/react/polls.js +176 -0
  274. package/dist/react/polls.js.map +1 -0
  275. package/dist/react/posts.d.ts +59 -0
  276. package/dist/react/posts.js +149 -0
  277. package/dist/react/posts.js.map +1 -0
  278. package/dist/react/provider.d.ts +23 -0
  279. package/dist/react/provider.js +35 -0
  280. package/dist/react/provider.js.map +1 -0
  281. package/dist/react/public.d.ts +39 -0
  282. package/dist/react/public.js +70 -0
  283. package/dist/react/public.js.map +1 -0
  284. package/dist/react/read.d.ts +52 -0
  285. package/dist/react/read.js +143 -0
  286. package/dist/react/read.js.map +1 -0
  287. package/dist/react/resources.d.ts +70 -0
  288. package/dist/react/resources.js +247 -0
  289. package/dist/react/resources.js.map +1 -0
  290. package/dist/react/slot.d.ts +102 -0
  291. package/dist/react/slot.js +181 -0
  292. package/dist/react/slot.js.map +1 -0
  293. package/dist/react/store.d.ts +51 -0
  294. package/dist/react/store.js +164 -0
  295. package/dist/react/store.js.map +1 -0
  296. package/dist/react/upload.d.ts +85 -0
  297. package/dist/react/upload.js +150 -0
  298. package/dist/react/upload.js.map +1 -0
  299. package/dist/react/use-resource.d.ts +43 -0
  300. package/dist/react/use-resource.js +66 -0
  301. package/dist/react/use-resource.js.map +1 -0
  302. package/dist/react/video.d.ts +118 -0
  303. package/dist/react/video.js +184 -0
  304. package/dist/react/video.js.map +1 -0
  305. package/dist/react/viewport.d.ts +19 -0
  306. package/dist/react/viewport.js +30 -0
  307. package/dist/react/viewport.js.map +1 -0
  308. package/dist/react.js +21 -0
  309. package/dist/scope.d.ts +14 -0
  310. package/dist/scope.js +30 -0
  311. package/dist/scope.js.map +1 -0
  312. package/dist/styles.css +3 -0
  313. package/dist/ui/alert-dialog.d.ts +18 -0
  314. package/dist/ui/alert-dialog.js +86 -0
  315. package/dist/ui/alert-dialog.js.map +1 -0
  316. package/dist/ui/alert.d.ts +10 -0
  317. package/dist/ui/alert.js +38 -0
  318. package/dist/ui/alert.js.map +1 -0
  319. package/dist/ui/avatar.d.ts +11 -0
  320. package/dist/ui/avatar.js +31 -0
  321. package/dist/ui/avatar.js.map +1 -0
  322. package/dist/ui/badge.d.ts +7 -0
  323. package/dist/ui/badge.js +31 -0
  324. package/dist/ui/badge.js.map +1 -0
  325. package/dist/ui/button.d.ts +8 -0
  326. package/dist/ui/button.js +46 -0
  327. package/dist/ui/button.js.map +1 -0
  328. package/dist/ui/dialog.d.ts +17 -0
  329. package/dist/ui/dialog.js +91 -0
  330. package/dist/ui/dialog.js.map +1 -0
  331. package/dist/ui/dropdown-menu.d.ts +15 -0
  332. package/dist/ui/dropdown-menu.js +105 -0
  333. package/dist/ui/dropdown-menu.js.map +1 -0
  334. package/dist/ui/input.d.ts +3 -0
  335. package/dist/ui/input.js +17 -0
  336. package/dist/ui/input.js.map +1 -0
  337. package/dist/ui/label.d.ts +3 -0
  338. package/dist/ui/label.js +15 -0
  339. package/dist/ui/label.js.map +1 -0
  340. package/dist/ui/progress.d.ts +7 -0
  341. package/dist/ui/progress.js +31 -0
  342. package/dist/ui/progress.js.map +1 -0
  343. package/dist/ui/select.d.ts +15 -0
  344. package/dist/ui/select.js +98 -0
  345. package/dist/ui/select.js.map +1 -0
  346. package/dist/ui/skeleton.d.ts +2 -0
  347. package/dist/ui/skeleton.js +14 -0
  348. package/dist/ui/skeleton.js.map +1 -0
  349. package/dist/ui/slider.d.ts +3 -0
  350. package/dist/ui/slider.js +35 -0
  351. package/dist/ui/slider.js.map +1 -0
  352. package/dist/ui/switch.d.ts +5 -0
  353. package/dist/ui/switch.js +20 -0
  354. package/dist/ui/switch.js.map +1 -0
  355. package/dist/ui/tabs.d.ts +10 -0
  356. package/dist/ui/tabs.js +47 -0
  357. package/dist/ui/tabs.js.map +1 -0
  358. package/dist/ui/textarea.d.ts +3 -0
  359. package/dist/ui/textarea.js +15 -0
  360. package/dist/ui/textarea.js.map +1 -0
  361. package/dist/ui/toggle-group.d.ts +5 -0
  362. package/dist/ui/toggle-group.js +23 -0
  363. package/dist/ui/toggle-group.js.map +1 -0
  364. package/dist/urls/index.d.ts +100 -0
  365. package/dist/urls.js +118 -0
  366. package/dist/urls.js.map +1 -0
  367. package/package.json +113 -3
@@ -0,0 +1,70 @@
1
+ import { defaultImage as e, isPattern as t, ruleDir as n } from "../client/media/rules.js";
2
+ import { useOptionalContentKitClient as r } from "./context.js";
3
+ import { useMediaRead as i } from "./read.js";
4
+ import { useEffect as a, useMemo as o, useState as s } from "react";
5
+ //#region src/react/public.ts
6
+ var c = /* @__PURE__ */ new WeakMap();
7
+ function l(e = {}) {
8
+ let t = r(e.client), [, n] = s(0), i = t ? c.get(t) : void 0;
9
+ return a(() => {
10
+ if (!t || c.has(t)) return;
11
+ let e = !0;
12
+ return t.media.presets().then((e) => c.set(t, { presets: e }), (e) => c.set(t, {
13
+ presets: [],
14
+ error: e
15
+ })).finally(() => e && n((e) => e + 1)), () => {
16
+ e = !1;
17
+ };
18
+ }, [t]), {
19
+ presets: i?.presets ?? [],
20
+ loaded: !!i || !t,
21
+ error: i?.error
22
+ };
23
+ }
24
+ function u(a, s, c, u = {}) {
25
+ let d = r(u.client), { presets: f, loaded: p } = l({ client: d }), m = f.find((e) => e.kind === a && e.name === c), h = u.image !== void 0, g = m ? t(m.from) ? n(m.from) : m.from : void 0, _ = i({
26
+ kind: a,
27
+ id: s
28
+ }, {
29
+ prefix: g,
30
+ read: h || !p ? null : u.read,
31
+ client: d
32
+ });
33
+ return {
34
+ ...o(() => {
35
+ let t = h ? u.image : _.read?.public?.find((e) => e.preset === c);
36
+ return t && t.renditions.length ? {
37
+ image: {
38
+ preset: c,
39
+ renditions: t.renditions,
40
+ aspect: "aspect" in t && t.aspect || m?.aspect
41
+ },
42
+ isDefault: !1
43
+ } : !h && !_.read ? {
44
+ image: null,
45
+ isDefault: !1
46
+ } : m ? {
47
+ image: e(m, s),
48
+ isDefault: !0
49
+ } : {
50
+ image: null,
51
+ isDefault: !1
52
+ };
53
+ }, [
54
+ h,
55
+ u.image,
56
+ _.read,
57
+ c,
58
+ m,
59
+ s
60
+ ]),
61
+ rule: m,
62
+ loading: !p || _.loading,
63
+ error: _.error,
64
+ reload: _.reload
65
+ };
66
+ }
67
+ //#endregion
68
+ export { l as usePresets, u as usePublicImage };
69
+
70
+ //# sourceMappingURL=public.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.js","names":[],"sources":["../../src/react/public.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type { ReadResult } from \"../client/generated/wire.js\";\nimport type { PresetRule } from \"../client/generated/wire.js\";\nimport { defaultImage, isPattern, ruleDir } from \"../client/media/rules.js\";\nimport type { PublicPreset } from \"../client/public.js\";\nimport { useOptionalContentKitClient } from \"./context.js\";\nimport { useMediaRead } from \"./read.js\";\n\nexport interface UsePresets {\n /** Every kind's public presets; empty until they load (or when the server has none). */\n presets: PresetRule[];\n loaded: boolean;\n error?: ContentKitError;\n}\n\nconst settled = new WeakMap<ContentKitClient, { presets: PresetRule[]; error?: ContentKitError }>();\n\n/** The public presets (`GET /media/presets`), fetched once per client. */\nexport function usePresets(o: { client?: ContentKitClient | null } = {}): UsePresets {\n const client = useOptionalContentKitClient(o.client);\n const [, rerender] = useState(0);\n const done = client ? settled.get(client) : undefined;\n useEffect(() => {\n if (!client || settled.has(client)) return;\n let live = true;\n client.media.presets().then(\n (presets) => settled.set(client, { presets }),\n (error: ContentKitError) => settled.set(client, { presets: [], error }),\n ).finally(() => live && rerender((n) => n + 1));\n return () => {\n live = false;\n };\n }, [client]);\n return { presets: done?.presets ?? [], loaded: !!done || !client, error: done?.error };\n}\n\nexport interface PublicImageOptions {\n /** The host's listing of the item's image (its API's): shown without a read. */\n image?: PublicPreset | null;\n /** A read of the item the host already has. */\n read?: ReadResult | null;\n /** Overrides the provider's client. */\n client?: ContentKitClient | null;\n}\n\nexport interface UsePublicImage {\n /** The item's current renditions; the kind's default image when it has none; null while unknown. */\n image: PublicPreset | null;\n /** The preset's rules (aspect, widths, min_width) once the presets load. */\n rule?: PresetRule;\n /** image is the kind's default, not the item's own. */\n isDefault: boolean;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/**\n * An item's public image for a preset (\"avatar\", \"cover\"): the exact\n * renditions from a read's `public` (or the host's listing), else the kind's\n * default image. Reads refresh after commits through the same client.\n */\nexport function usePublicImage(kind: string, id: string, preset: string, o: PublicImageOptions = {}): UsePublicImage {\n const client = useOptionalContentKitClient(o.client);\n const { presets, loaded } = usePresets({ client });\n const rule = presets.find((p) => p.kind === kind && p.name === preset);\n const listed = o.image !== undefined;\n // The read waits for the presets, so it lists only the preset's upload.\n const prefix = rule ? (isPattern(rule.from) ? ruleDir(rule.from) : rule.from) : undefined;\n const r = useMediaRead({ kind, id }, { prefix, read: listed || !loaded ? null : o.read, client });\n const image = useMemo((): { image: PublicPreset | null; isDefault: boolean } => {\n const own = listed ? o.image : r.read?.public?.find((p) => p.preset === preset);\n if (own && own.renditions.length) return { image: { preset, renditions: own.renditions, aspect: (\"aspect\" in own && own.aspect) || rule?.aspect }, isDefault: false };\n if (!listed && !r.read) return { image: null, isDefault: false };\n return rule ? { image: defaultImage(rule, id), isDefault: true } : { image: null, isDefault: false };\n }, [listed, o.image, r.read, preset, rule, id]);\n return { ...image, rule, loading: !loaded || r.loading, error: r.error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M,MAAM,EAAE,WAAW,CAAM;GAG9E,OAFI,KAAO,EAAI,WAAW,SAAe;IAAE,OAAO;KAAE;KAAQ,YAAY,EAAI;KAAY,QAAS,YAAY,KAAO,EAAI,UAAW,GAAM;IAAO;IAAG,WAAW;GAAM,IAChK,CAAC,KAAU,CAAC,EAAE,OAAa;IAAE,OAAO;IAAM,WAAW;GAAM,IACxD,IAAO;IAAE,OAAO,EAAa,GAAM,CAAE;IAAG,WAAW;GAAK,IAAI;IAAE,OAAO;IAAM,WAAW;GAAM;EACrG,GAAG;GAAC;GAAQ,EAAE;GAAO,EAAE;GAAM;GAAQ;GAAM;EAAE,CACjC;EAAO;EAAM,SAAS,CAAC,KAAU,EAAE;EAAS,OAAO,EAAE;EAAO,QAAQ,EAAE;CAAO;AAC3F"}
@@ -0,0 +1,52 @@
1
+ import { ContentKitClient } from '../client/client.js';
2
+ import { ContentKitError } from '../client/errors.js';
3
+ import { ReadResult, RefBody } from '../client/generated/wire.js';
4
+ import { ReadOptions } from '../client/media/api.js';
5
+ /** Files [start, end) get URLs. */
6
+ export interface ReadWindow {
7
+ start: number;
8
+ end: number;
9
+ /** Files per read. Default 50. */
10
+ chunk?: number;
11
+ }
12
+ export interface MediaReadOptions extends Omit<ReadOptions, "offset" | "limit"> {
13
+ /**
14
+ * Read in windows of `chunk` files and merge them: the files in
15
+ * [start, end) get URLs, and windows once read stay loaded (and refreshed)
16
+ * until the item or options change. Without it, one read of the server's
17
+ * default range (or offset and limit).
18
+ */
19
+ window?: ReadWindow;
20
+ offset?: number;
21
+ limit?: number;
22
+ /** Poll at this interval (ms) while uploads process. Default 2500 for editor reads, else off. */
23
+ poll?: number | false;
24
+ /** Read again shortly before the URLs expire. Default true. */
25
+ refresh?: boolean;
26
+ /** A read the host already has: shown until reload() or set(). */
27
+ read?: ReadResult | null;
28
+ /** Overrides the provider's client. */
29
+ client?: ContentKitClient | null;
30
+ }
31
+ export interface UseMediaRead {
32
+ /** The read (windows merged); null until it loads or when it failed. */
33
+ read: ReadResult | null;
34
+ loading: boolean;
35
+ error?: ContentKitError;
36
+ /** Uploads are still processing (editor reads). */
37
+ processing: boolean;
38
+ /** Reads again now, restarting a read in flight. */
39
+ reload: () => void;
40
+ /** Reads again unless a read is in flight: a player's grant refresh. */
41
+ refresh: () => void;
42
+ /** Replaces the read without refetching, for every hook showing it. */
43
+ set: (r: ReadResult) => void;
44
+ }
45
+ /**
46
+ * A read of the item, shared with every hook reading the same item and
47
+ * options: refreshed before its URLs expire, retried after a read rate limit,
48
+ * polled while uploads process, reloaded after a commit through the client.
49
+ * A window splits it into merged reads. Without a client (none passed, no
50
+ * provider) it only shows a supplied read.
51
+ */
52
+ export declare function useMediaRead(ref: RefBody, o?: MediaReadOptions): UseMediaRead;
@@ -0,0 +1,143 @@
1
+ import { useOptionalContentKitClient as e } from "./context.js";
2
+ import { chunkOffsets as t, mergeReads as n, processing as ee } from "../client/media/windows.js";
3
+ import { readKey as r, storeFor as i } from "./store.js";
4
+ import { useCallback as a, useEffect as o, useMemo as s, useRef as c, useState as l, useSyncExternalStore as u } from "react";
5
+ //#region src/react/read.ts
6
+ var d = 2500, f = [];
7
+ function p(p, m = {}) {
8
+ let { read: h, client: te, prefix: g, offset: _, limit: v, download: y, editor: b, window: x, refresh: S = !0 } = m, C = m.poll ?? (b ? d : !1), w = e(te), T = w ? i(w) : null, E = x?.chunk ?? 50, D = r(p, {
9
+ prefix: g,
10
+ download: y,
11
+ editor: b
12
+ }) + (x ? `#${E}` : `#${_ ?? 0}:${v ?? 0}`), [O, ne] = l({ base: D }), k = O.base === D ? O.n : void 0, A = x ? t(x.start, x.end, k ?? x.start + 1, E) : [], [j, M] = l({
13
+ base: D,
14
+ offsets: []
15
+ }), N = j.base === D ? j.offsets : [];
16
+ x && (j.base !== D || A.some((e) => !N.includes(e))) && M({
17
+ base: D,
18
+ offsets: [.../* @__PURE__ */ new Set([...N, ...A])].sort((e, t) => e - t)
19
+ });
20
+ let P = x ? N.length ? N : A.length ? A : [0] : [_ ?? 0], F = s(() => P.map((e) => ({
21
+ offset: e,
22
+ limit: x ? E : v
23
+ })), [P.join(","), x ? E : v]), I = s(() => F.map((e) => r(p, {
24
+ prefix: g,
25
+ download: y,
26
+ editor: b,
27
+ offset: e.offset,
28
+ limit: e.limit
29
+ })), [
30
+ F,
31
+ p.kind,
32
+ p.id,
33
+ g,
34
+ y,
35
+ b
36
+ ]), [L, R] = l(null), [z, B] = l(null), V = L?.base === D && L.given === h ? L : null, H = !!T && (h === void 0 || !!V), U = a((e) => {
37
+ if (!T || !H) return () => {};
38
+ let t = I.map((t, n) => T.subscribe(t, {
39
+ kind: p.kind,
40
+ id: p.id
41
+ }, {
42
+ prefix: g,
43
+ download: y,
44
+ editor: b,
45
+ ...F[n]
46
+ }, e, {
47
+ poll: C,
48
+ refresh: S
49
+ }));
50
+ return () => t.forEach((e) => e());
51
+ }, [
52
+ T,
53
+ H,
54
+ I,
55
+ C,
56
+ S
57
+ ]), W = c(f), G = a(() => {
58
+ if (!T || !H) return f;
59
+ let e = I.map((e) => T.snapshot(e)), t = W.current;
60
+ return t.length === e.length && t.every((t, n) => t === e[n]) ? t : W.current = e;
61
+ }, [
62
+ T,
63
+ H,
64
+ I
65
+ ]), K = u(U, G, G);
66
+ o(() => {
67
+ if (T && H) for (let e of I) T.load(e, V ? "reload" : "initial");
68
+ }, [
69
+ T,
70
+ H,
71
+ I,
72
+ V
73
+ ]);
74
+ let q = s(() => n(K.map((e) => e.read)), [K]);
75
+ o(() => {
76
+ x && q && q.total !== k && ne({
77
+ base: D,
78
+ n: q.total
79
+ });
80
+ }, [
81
+ x,
82
+ q,
83
+ k,
84
+ D
85
+ ]);
86
+ let J = a(() => {
87
+ if (h !== void 0) R({
88
+ base: D,
89
+ given: h
90
+ });
91
+ else if (T) for (let e of I) T.load(e, "reload");
92
+ B(null);
93
+ }, [
94
+ T,
95
+ I,
96
+ D,
97
+ h
98
+ ]), Y = a(() => {
99
+ if (h !== void 0 && !V) R({
100
+ base: D,
101
+ given: h
102
+ });
103
+ else if (T) for (let e of I) T.load(e, "refresh");
104
+ }, [
105
+ T,
106
+ I,
107
+ D,
108
+ h,
109
+ V
110
+ ]), X = a((e) => {
111
+ if (T && H) for (let t of I) T.set(t, e);
112
+ else B({
113
+ base: D,
114
+ given: h,
115
+ read: e
116
+ });
117
+ }, [
118
+ T,
119
+ H,
120
+ I,
121
+ D,
122
+ h
123
+ ]), Z, Q = !1, $;
124
+ if (z && z.base === D && z.given === h) Z = z.read;
125
+ else if (!K.length) Z = h ?? null;
126
+ else {
127
+ let e = K.every((e) => e.loaded);
128
+ Z = q ?? (e ? null : h ?? null), Q = K.some((e) => e.loading || !e.loaded), $ = K.find((e) => e.error)?.error;
129
+ }
130
+ return {
131
+ read: Z,
132
+ loading: Q,
133
+ error: $,
134
+ processing: ee(Z),
135
+ reload: J,
136
+ refresh: Y,
137
+ set: X
138
+ };
139
+ }
140
+ //#endregion
141
+ export { p as useMediaRead };
142
+
143
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.js","names":[],"sources":["../../src/react/read.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type { ReadResult, RefBody } from \"../client/generated/wire.js\";\nimport type { ReadOptions } from \"../client/media/api.js\";\nimport { chunkOffsets, mergeReads, processing as isProcessing, READ_CHUNK } from \"../client/media/windows.js\";\nimport { useOptionalContentKitClient } from \"./context.js\";\nimport { readKey, storeFor, type ReadEntry } from \"./store.js\";\n\n/** Files [start, end) get URLs. */\nexport interface ReadWindow {\n start: number;\n end: number;\n /** Files per read. Default 50. */\n chunk?: number;\n}\n\nexport interface MediaReadOptions extends Omit<ReadOptions, \"offset\" | \"limit\"> {\n /**\n * Read in windows of `chunk` files and merge them: the files in\n * [start, end) get URLs, and windows once read stay loaded (and refreshed)\n * until the item or options change. Without it, one read of the server's\n * default range (or offset and limit).\n */\n window?: ReadWindow;\n offset?: number;\n limit?: number;\n /** Poll at this interval (ms) while uploads process. Default 2500 for editor reads, else off. */\n poll?: number | false;\n /** Read again shortly before the URLs expire. Default true. */\n refresh?: boolean;\n /** A read the host already has: shown until reload() or set(). */\n read?: ReadResult | null;\n /** Overrides the provider's client. */\n client?: ContentKitClient | null;\n}\n\nexport interface UseMediaRead {\n /** The read (windows merged); null until it loads or when it failed. */\n read: ReadResult | null;\n loading: boolean;\n error?: ContentKitError;\n /** Uploads are still processing (editor reads). */\n processing: boolean;\n /** Reads again now, restarting a read in flight. */\n reload: () => void;\n /** Reads again unless a read is in flight: a player's grant refresh. */\n refresh: () => void;\n /** Replaces the read without refetching, for every hook showing it. */\n set: (r: ReadResult) => void;\n}\n\nconst POLL = 2500;\nconst NONE: readonly ReadEntry[] = [];\n\n/**\n * A read of the item, shared with every hook reading the same item and\n * options: refreshed before its URLs expire, retried after a read rate limit,\n * polled while uploads process, reloaded after a commit through the client.\n * A window splits it into merged reads. Without a client (none passed, no\n * provider) it only shows a supplied read.\n */\nexport function useMediaRead(ref: RefBody, o: MediaReadOptions = {}): UseMediaRead {\n const { read: given, client: own, prefix, offset, limit, download, editor, window, refresh: refreshing = true } = o;\n const poll = o.poll ?? (editor ? POLL : false);\n const client = useOptionalContentKitClient(own);\n const store = client ? storeFor(client) : null;\n const chunk = window?.chunk ?? READ_CHUNK;\n const base = readKey(ref, { prefix, download, editor }) + (window ? `#${chunk}` : `#${offset ?? 0}:${limit ?? 0}`);\n\n // Windows once wanted stay loaded until the item or options change.\n const [total, setTotal] = useState<{ base: string; n?: number }>({ base });\n const known = total.base === base ? total.n : undefined;\n // Until the first read states the total, only the window's first chunk.\n const wanted = window ? chunkOffsets(window.start, window.end, known ?? window.start + 1, chunk) : [];\n const [kept, setKept] = useState<{ base: string; offsets: number[] }>({ base, offsets: [] });\n const prior = kept.base === base ? kept.offsets : [];\n if (window && (kept.base !== base || wanted.some((w) => !prior.includes(w)))) {\n setKept({ base, offsets: [...new Set([...prior, ...wanted])].sort((a, b) => a - b) });\n }\n const offsets = window ? (prior.length ? prior : wanted.length ? wanted : [0]) : [offset ?? 0];\n const windows = useMemo(\n () => offsets.map((off) => ({ offset: off, limit: window ? chunk : limit })),\n // offsets is derived from the stable kept list\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [offsets.join(\",\"), window ? chunk : limit],\n );\n const keys = useMemo(() => windows.map((w) => readKey(ref, { prefix, download, editor, offset: w.offset, limit: w.limit })), [windows, ref.kind, ref.id, prefix, download, editor]); // eslint-disable-line react-hooks/exhaustive-deps\n\n // A supplied read is shown until reload() asks the server or set() replaces it.\n const [requested, setRequested] = useState<{ base: string; given?: ReadResult | null } | null>(null);\n const [local, setLocal] = useState<{ base: string; given?: ReadResult | null; read: ReadResult } | null>(null);\n const asked = requested?.base === base && requested.given === given ? requested : null;\n const fetching = !!store && (given === undefined || !!asked);\n\n const subscribe = useCallback(\n (l: () => void) => {\n if (!store || !fetching) return () => {};\n const offs = keys.map((key, i) => store.subscribe(key, { kind: ref.kind, id: ref.id }, { prefix, download, editor, ...windows[i] }, l, { poll, refresh: refreshing }));\n return () => offs.forEach((off) => off());\n },\n // ref and options are in keys.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [store, fetching, keys, poll, refreshing],\n );\n const last = useRef<readonly ReadEntry[]>(NONE);\n const snapshot = useCallback(() => {\n if (!store || !fetching) return NONE;\n const next = keys.map((k) => store.snapshot(k));\n const prev = last.current;\n if (prev.length === next.length && prev.every((e, i) => e === next[i])) return prev;\n return (last.current = next);\n }, [store, fetching, keys]);\n const entries = useSyncExternalStore(subscribe, snapshot, snapshot);\n useEffect(() => {\n if (store && fetching) for (const k of keys) store.load(k, asked ? \"reload\" : \"initial\");\n }, [store, fetching, keys, asked]);\n\n const merged = useMemo(() => mergeReads(entries.map((e) => e.read)), [entries]);\n useEffect(() => {\n if (window && merged && merged.total !== known) setTotal({ base, n: merged.total });\n }, [window, merged, known, base]);\n\n const reload = useCallback(() => {\n if (given !== undefined) setRequested({ base, given });\n else if (store) for (const k of keys) store.load(k, \"reload\");\n setLocal(null);\n }, [store, keys, base, given]);\n const refresh = useCallback(() => {\n if (given !== undefined && !asked) setRequested({ base, given });\n else if (store) for (const k of keys) store.load(k, \"refresh\");\n }, [store, keys, base, given, asked]);\n const set = useCallback(\n (read: ReadResult) => {\n if (store && fetching) for (const k of keys) store.set(k, read);\n else setLocal({ base, given, read });\n },\n [store, fetching, keys, base, given],\n );\n\n let read: ReadResult | null;\n let loading = false;\n let error: ContentKitError | undefined;\n if (local && local.base === base && local.given === given) read = local.read;\n else if (!entries.length) read = given ?? null;\n else {\n const loaded = entries.every((e) => e.loaded);\n read = merged ?? (loaded ? null : (given ?? null));\n loading = entries.some((e) => e.loading || !e.loaded);\n error = entries.find((e) => e.error)?.error;\n }\n return { read, loading, error, processing: isProcessing(read), reload, refresh, set };\n}\n"],"mappings":";;;;;AAoDA,IAAM,IAAO,MACP,IAA6B,CAAC;AASpC,SAAgB,EAAa,GAAc,IAAsB,CAAC,GAAiB;CACjF,IAAM,EAAE,MAAM,GAAO,QAAQ,IAAK,WAAQ,WAAQ,UAAO,aAAU,WAAQ,WAAQ,SAAS,IAAa,OAAS,GAC5G,IAAO,EAAE,SAAS,IAAS,IAAO,KAClC,IAAS,EAA4B,EAAG,GACxC,IAAQ,IAAS,EAAS,CAAM,IAAI,MACpC,IAAQ,GAAQ,SAAA,IAChB,IAAO,EAAQ,GAAK;EAAE;EAAQ;EAAU;CAAO,CAAC,KAAK,IAAS,IAAI,MAAU,IAAI,KAAU,EAAE,GAAG,KAAS,MAGxG,CAAC,GAAO,MAAY,EAAuC,EAAE,QAAK,CAAC,GACnE,IAAQ,EAAM,SAAS,IAAO,EAAM,IAAI,KAAA,GAExC,IAAS,IAAS,EAAa,EAAO,OAAO,EAAO,KAAK,KAAS,EAAO,QAAQ,GAAG,CAAK,IAAI,CAAC,GAC9F,CAAC,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,SAAS;CAC/D,GAAG;EAAC;EAAO;EAAM;EAAM;EAAO;CAAK,CAAC,GAC9B,IAAM,GACT,MAAqB;EACpB,IAAI,KAAS,GAAU,KAAK,IAAM,KAAK,GAAM,EAAM,IAAI,GAAG,CAAI;OACzD,EAAS;GAAE;GAAM;GAAO;EAAK,CAAC;CACrC,GACA;EAAC;EAAO;EAAU;EAAM;EAAM;CAAK,CACrC,GAEI,GACA,IAAU,IACV;CACJ,IAAI,KAAS,EAAM,SAAS,KAAQ,EAAM,UAAU,GAAO,IAAO,EAAM;MACnE,IAAI,CAAC,EAAQ,QAAQ,IAAO,KAAS;MACrC;EACH,IAAM,IAAS,EAAQ,OAAO,MAAM,EAAE,MAAM;EAG5C,AAFA,IAAO,MAAW,IAAS,OAAQ,KAAS,OAC5C,IAAU,EAAQ,MAAM,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GACpD,IAAQ,EAAQ,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE;CACxC;CACA,OAAO;EAAE;EAAM;EAAS;EAAO,YAAY,GAAa,CAAI;EAAG;EAAQ;EAAS;CAAI;AACtF"}
@@ -0,0 +1,70 @@
1
+ import { ContentKitClient } from '../client/client.js';
2
+ import { ContentKitError } from '../client/errors.js';
3
+ import { RefBody } from '../client/generated/wire.js';
4
+ /** One shared read: its data, whether a fetch is in flight, and its last failure. */
5
+ export interface Resource<T> {
6
+ data: T | undefined;
7
+ loading: boolean;
8
+ /** A fetch or set has completed. */
9
+ loaded: boolean;
10
+ /** A list's next page is in flight. */
11
+ loadingMore?: boolean;
12
+ error?: ContentKitError;
13
+ }
14
+ /** A page of a list and how to get the next one (null: no more). */
15
+ export interface Page<T> {
16
+ items: T[];
17
+ next: string | number | null;
18
+ }
19
+ export type Fetcher<T> = (signal: AbortSignal) => Promise<T>;
20
+ /** What a slot holds, for matching changes: its resource type and the ids it depends on. */
21
+ export interface Tag {
22
+ type: string;
23
+ ref?: RefBody;
24
+ id?: string;
25
+ scope?: string;
26
+ }
27
+ interface Slot {
28
+ tag: Tag;
29
+ listeners: Set<() => void>;
30
+ entry: Resource<unknown>;
31
+ fetcher?: Fetcher<unknown>;
32
+ more?: (cursor: string | number, signal: AbortSignal) => Promise<Page<unknown>>;
33
+ ctl?: AbortController;
34
+ moreCtl?: AbortController;
35
+ /** Bumped by mark(): an optimistic write rolls back only if no newer one started. */
36
+ version: number;
37
+ }
38
+ /**
39
+ * The content reads hooks share, per client: one request per key while any
40
+ * hook shows it, optimistic writes with rollback, and every change the client
41
+ * makes applied in place (or refetched) for every hook showing it.
42
+ */
43
+ export declare class ResourceStore {
44
+ private readonly slots;
45
+ constructor(client: ContentKitClient);
46
+ subscribe(key: string, tag: Tag, listener: () => void): () => void;
47
+ snapshot<T>(key: string): Resource<T>;
48
+ /** The latest fetchers of a key: its first read, and a list's next page. */
49
+ bind(key: string, fetcher: Fetcher<unknown>, more?: Slot["more"]): void;
50
+ /** Fetches unless loaded or in flight; force refetches (a list from its first page). */
51
+ load(key: string, force?: boolean): void;
52
+ /** Appends a list's next page; resolves once it landed. */
53
+ loadMore(key: string): Promise<void>;
54
+ /** Replaces a key's data for every hook showing it. */
55
+ set<T>(key: string, data: T | ((prev: T | undefined) => T)): void;
56
+ /** Starts an optimistic write on key: the token rollback() checks. */
57
+ mark(key: string): number;
58
+ /** Restores data unless a newer optimistic write started since mark(). */
59
+ rollback<T>(key: string, token: number, data: T): void;
60
+ /** Applies fn to the data of every slot whose tag matches. */
61
+ patch<T>(match: (tag: Tag) => boolean, fn: (data: T) => T): void;
62
+ /** Refetches every shown slot whose tag matches. */
63
+ invalidate(match: (tag: Tag) => boolean): void;
64
+ private apply;
65
+ private postTotals;
66
+ private update;
67
+ }
68
+ /** The client's shared content store. */
69
+ export declare function resourcesFor(client: ContentKitClient): ResourceStore;
70
+ export {};
@@ -0,0 +1,247 @@
1
+ import { toContentKitError as e } from "../client/errors.js";
2
+ //#region src/react/resources.ts
3
+ var t = {
4
+ data: void 0,
5
+ loading: !1,
6
+ loaded: !1
7
+ }, n = (e, t) => !!e && !!t && e.kind === t.kind && e.id === t.id, r = class {
8
+ slots = /* @__PURE__ */ new Map();
9
+ constructor(e) {
10
+ e.subscribe((e) => this.apply(e));
11
+ }
12
+ subscribe(e, n, r) {
13
+ let i = this.slots.get(e);
14
+ i || this.slots.set(e, i = {
15
+ tag: n,
16
+ listeners: /* @__PURE__ */ new Set(),
17
+ entry: t,
18
+ version: 0
19
+ });
20
+ let a = i;
21
+ return a.listeners.add(r), () => {
22
+ a.listeners.delete(r), queueMicrotask(() => {
23
+ a.listeners.size || this.slots.get(e) !== a || (a.ctl?.abort(), a.moreCtl?.abort(), this.slots.delete(e));
24
+ });
25
+ };
26
+ }
27
+ snapshot(e) {
28
+ return this.slots.get(e)?.entry ?? t;
29
+ }
30
+ bind(e, t, n) {
31
+ let r = this.slots.get(e);
32
+ r && Object.assign(r, {
33
+ fetcher: t,
34
+ more: n
35
+ });
36
+ }
37
+ load(t, n = !1) {
38
+ let r = this.slots.get(t);
39
+ if (!r?.fetcher || !n && (r.entry.loaded || r.ctl)) return;
40
+ r.ctl?.abort(), r.moreCtl?.abort(), r.moreCtl = void 0;
41
+ let i = r.ctl = new AbortController();
42
+ this.update(r, {
43
+ loading: !0,
44
+ loadingMore: !1,
45
+ error: void 0
46
+ }), r.fetcher(i.signal).then((e) => {
47
+ r.ctl === i && (r.ctl = void 0, this.update(r, {
48
+ data: e,
49
+ loading: !1,
50
+ loaded: !0,
51
+ error: void 0
52
+ }));
53
+ }, (t) => {
54
+ if (r.ctl !== i) return;
55
+ r.ctl = void 0;
56
+ let n = e(t);
57
+ n.code !== "aborted" && this.update(r, {
58
+ loading: !1,
59
+ loaded: !0,
60
+ error: n
61
+ });
62
+ });
63
+ }
64
+ async loadMore(t) {
65
+ let n = this.slots.get(t), r = n?.entry.data;
66
+ if (!n?.more || !r || r.next === null || n.moreCtl || n.ctl) return;
67
+ let i = n.moreCtl = new AbortController();
68
+ this.update(n, { loadingMore: !0 });
69
+ try {
70
+ let e = await n.more(r.next, i.signal);
71
+ if (n.moreCtl !== i) return;
72
+ let t = n.entry.data, a = new Set(t.items.map((e) => e.id));
73
+ this.update(n, {
74
+ data: {
75
+ items: [...t.items, ...e.items.filter((e) => !a.has(e.id))],
76
+ next: e.next
77
+ },
78
+ error: void 0
79
+ });
80
+ } catch (t) {
81
+ let r = e(t);
82
+ n.moreCtl === i && r.code !== "aborted" && this.update(n, { error: r });
83
+ } finally {
84
+ n.moreCtl === i && (n.moreCtl = void 0, this.update(n, { loadingMore: !1 }));
85
+ }
86
+ }
87
+ set(e, t) {
88
+ let n = this.slots.get(e);
89
+ if (!n) return;
90
+ let r = typeof t == "function" ? t(n.entry.data) : t;
91
+ this.update(n, {
92
+ data: r,
93
+ loaded: !0,
94
+ error: void 0
95
+ });
96
+ }
97
+ mark(e) {
98
+ let t = this.slots.get(e);
99
+ return t ? ++t.version : 0;
100
+ }
101
+ rollback(e, t, n) {
102
+ let r = this.slots.get(e);
103
+ r && r.version === t && this.update(r, {
104
+ data: n,
105
+ loaded: !0
106
+ });
107
+ }
108
+ patch(e, t) {
109
+ for (let n of this.slots.values()) n.entry.data !== void 0 && e(n.tag) && this.update(n, { data: t(n.entry.data) });
110
+ }
111
+ invalidate(e) {
112
+ for (let [t, n] of this.slots) e(n.tag) && n.listeners.size && this.load(t, !0);
113
+ }
114
+ apply(e) {
115
+ let t = (e, t) => this.patch((t) => e.includes(t.type), (e) => {
116
+ let n = !1, r = [];
117
+ for (let i of e.items) {
118
+ let e = t(i);
119
+ e !== i && (n = !0), e && r.push(e);
120
+ }
121
+ return n ? {
122
+ ...e,
123
+ items: r
124
+ } : e;
125
+ }), r = [
126
+ "comments",
127
+ "replies",
128
+ "latest",
129
+ "admin-comments"
130
+ ];
131
+ switch (e.type) {
132
+ case "comment.created": {
133
+ let r = e.comment.reply_to_id, i = !e.comment.moderation;
134
+ this.patch((t) => r ? t.type === "replies" && t.id === r : t.type === "comments" && n(t.ref, e.ref), (t) => t.items.some((t) => t.id === e.comment.id) ? t : {
135
+ ...t,
136
+ items: r ? [...t.items, e.comment] : [e.comment, ...t.items]
137
+ }), r && i && t(["comments"], (e) => e.id === r ? {
138
+ ...e,
139
+ reply_count: e.reply_count + 1
140
+ } : e), this.invalidate((e) => e.type === "latest" || e.type === "admin-comments");
141
+ break;
142
+ }
143
+ case "comment.updated":
144
+ t(r, (t) => t.id === e.comment.id ? {
145
+ ...t,
146
+ ...e.comment,
147
+ author: e.comment.author ?? t.author
148
+ } : t);
149
+ break;
150
+ case "comment.reacted":
151
+ t(r, (t) => t.id === e.id ? {
152
+ ...t,
153
+ ...e.counts
154
+ } : t);
155
+ break;
156
+ case "comment.deleted": {
157
+ let n;
158
+ t(["comments", "replies"], (t) => t.id !== e.id || t.deleted ? t : (t.moderation || (n = t.reply_to_id), {
159
+ ...t,
160
+ deleted: !0,
161
+ body: "[deleted]",
162
+ author: void 0,
163
+ user_id: void 0,
164
+ anon_name: void 0
165
+ })), n && t(["comments"], (e) => e.id === n ? {
166
+ ...e,
167
+ reply_count: Math.max(0, e.reply_count - 1)
168
+ } : e), t(["latest"], (t) => t.id === e.id ? null : t), t(["admin-comments"], (t) => t.id === e.id ? {
169
+ ...t,
170
+ deleted: !0,
171
+ deleted_at: (/* @__PURE__ */ new Date()).toISOString()
172
+ } : t);
173
+ break;
174
+ }
175
+ case "comment.restored":
176
+ this.invalidate((e) => r.includes(e.type));
177
+ break;
178
+ case "reaction.changed":
179
+ this.patch((t) => t.type === "reaction" && n(t.ref, e.ref), () => e.counts), e.ref.kind === "post" && this.postTotals(e.ref.id, e.counts.likes, e.counts.dislikes);
180
+ break;
181
+ case "favorite.changed":
182
+ this.patch((t) => t.type === "favorite" && n(t.ref, e.ref), () => ({
183
+ favorited: e.favorited,
184
+ count: e.count
185
+ })), this.invalidate((e) => e.type === "favorites");
186
+ break;
187
+ case "post.created":
188
+ this.invalidate((e) => e.type === "posts");
189
+ break;
190
+ case "post.updated":
191
+ this.patch((e) => e.type === "post", (t) => t?.id === e.post.id ? e.post : t), t(["posts"], (t) => t.id === e.post.id ? e.post : t);
192
+ break;
193
+ case "post.changed":
194
+ this.invalidate((t) => t.type === "post" && t.id === e.id || t.type === "posts");
195
+ break;
196
+ case "post.deleted":
197
+ t(["posts"], (t) => t.id === e.id ? null : t), this.invalidate((e) => e.type === "posts" && e.scope === "deleted");
198
+ break;
199
+ case "post.restored":
200
+ this.invalidate((t) => t.type === "post" && t.id === e.post.id || t.type === "posts");
201
+ break;
202
+ case "poll.created":
203
+ this.invalidate((e) => e.type === "polls" || e.type === "poll" && !e.id);
204
+ break;
205
+ case "poll.updated":
206
+ this.patch((e) => e.type === "poll", (t) => t?.id === e.poll.id ? e.poll : t), t(["polls"], (t) => t.id === e.poll.id ? e.poll : t);
207
+ break;
208
+ case "poll.changed":
209
+ this.invalidate((t) => t.type === "poll" && (t.id === e.id || !t.id) || t.type === "polls");
210
+ break;
211
+ case "poll.deleted":
212
+ t(["polls"], (t) => t.id === e.id ? null : t), this.invalidate((e) => e.type === "poll" && !e.id);
213
+ break;
214
+ case "ban.saved":
215
+ case "ban.lifted":
216
+ this.invalidate((t) => t.type === "bans" && t.scope === e.scope || t.type === "standing");
217
+ break;
218
+ case "moderation.resolved": t(["held"], (t) => t.id === e.id ? null : t), e.kind === "comment" ? this.invalidate((e) => r.includes(e.type)) : this.invalidate((t) => t.type === "post" && t.id === e.id || t.type === "posts");
219
+ }
220
+ }
221
+ postTotals(e, t, n) {
222
+ let r = (r) => r.id === e ? {
223
+ ...r,
224
+ total_likes: t,
225
+ total_dislikes: n
226
+ } : r;
227
+ this.patch((t) => t.type === "post" && t.id === e, r), this.patch((e) => e.type === "posts", (e) => ({
228
+ ...e,
229
+ items: e.items.map(r)
230
+ }));
231
+ }
232
+ update(e, t) {
233
+ e.entry = {
234
+ ...e.entry,
235
+ ...t
236
+ };
237
+ for (let t of e.listeners) t();
238
+ }
239
+ }, i = /* @__PURE__ */ new WeakMap();
240
+ function a(e) {
241
+ let t = i.get(e);
242
+ return t || i.set(e, t = new r(e)), t;
243
+ }
244
+ //#endregion
245
+ export { r as ResourceStore, a as resourcesFor };
246
+
247
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","names":[],"sources":["../../src/react/resources.ts"],"sourcesContent":["import type { ContentKitClient } from \"../client/client.js\";\nimport { toContentKitError, type ContentKitError } from \"../client/errors.js\";\nimport type { Comment, Poll, Post, RefBody } from \"../client/generated/wire.js\";\nimport type { ContentKitChange } from \"../client/http.js\";\n\n/** One shared read: its data, whether a fetch is in flight, and its last failure. */\nexport interface Resource<T> {\n data: T | undefined;\n loading: boolean;\n /** A fetch or set has completed. */\n loaded: boolean;\n /** A list's next page is in flight. */\n loadingMore?: boolean;\n error?: ContentKitError;\n}\n\n/** A page of a list and how to get the next one (null: no more). */\nexport interface Page<T> {\n items: T[];\n next: string | number | null;\n}\n\nexport type Fetcher<T> = (signal: AbortSignal) => Promise<T>;\n\n/** What a slot holds, for matching changes: its resource type and the ids it depends on. */\nexport interface Tag {\n type: string;\n ref?: RefBody;\n id?: string;\n scope?: string;\n}\n\ninterface Slot {\n tag: Tag;\n listeners: Set<() => void>;\n entry: Resource<unknown>;\n fetcher?: Fetcher<unknown>;\n more?: (cursor: string | number, signal: AbortSignal) => Promise<Page<unknown>>;\n ctl?: AbortController;\n moreCtl?: AbortController;\n /** Bumped by mark(): an optimistic write rolls back only if no newer one started. */\n version: number;\n}\n\nconst IDLE: Resource<never> = { data: undefined, loading: false, loaded: false };\n\nconst sameRef = (a?: RefBody, b?: RefBody) => !!a && !!b && a.kind === b.kind && a.id === b.id;\n\n/**\n * The content reads hooks share, per client: one request per key while any\n * hook shows it, optimistic writes with rollback, and every change the client\n * makes applied in place (or refetched) for every hook showing it.\n */\nexport class ResourceStore {\n private readonly slots = new Map<string, Slot>();\n\n constructor(client: ContentKitClient) {\n client.subscribe((c) => this.apply(c));\n }\n\n subscribe(key: string, tag: Tag, listener: () => void): () => void {\n let s = this.slots.get(key);\n if (!s) this.slots.set(key, (s = { tag, listeners: new Set(), entry: IDLE, version: 0 }));\n const slot = s;\n slot.listeners.add(listener);\n return () => {\n slot.listeners.delete(listener);\n // Kept across a StrictMode remount; dropped once no hook shows it.\n queueMicrotask(() => {\n if (slot.listeners.size || this.slots.get(key) !== slot) return;\n slot.ctl?.abort();\n slot.moreCtl?.abort();\n this.slots.delete(key);\n });\n };\n }\n\n snapshot<T>(key: string): Resource<T> {\n return (this.slots.get(key)?.entry ?? IDLE) as Resource<T>;\n }\n\n /** The latest fetchers of a key: its first read, and a list's next page. */\n bind(key: string, fetcher: Fetcher<unknown>, more?: Slot[\"more\"]): void {\n const s = this.slots.get(key);\n if (s) Object.assign(s, { fetcher, more });\n }\n\n /** Fetches unless loaded or in flight; force refetches (a list from its first page). */\n load(key: string, force = false): void {\n const s = this.slots.get(key);\n if (!s?.fetcher || (!force && (s.entry.loaded || s.ctl))) return;\n s.ctl?.abort();\n s.moreCtl?.abort();\n s.moreCtl = undefined;\n const ctl = (s.ctl = new AbortController());\n this.update(s, { loading: true, loadingMore: false, error: undefined });\n s.fetcher(ctl.signal).then(\n (data) => {\n if (s.ctl !== ctl) return;\n s.ctl = undefined;\n this.update(s, { data, loading: false, loaded: true, error: undefined });\n },\n (e) => {\n if (s.ctl !== ctl) return;\n s.ctl = undefined;\n const error = toContentKitError(e);\n if (error.code !== \"aborted\") this.update(s, { loading: false, loaded: true, error });\n },\n );\n }\n\n /** Appends a list's next page; resolves once it landed. */\n async loadMore(key: string): Promise<void> {\n const s = this.slots.get(key);\n const page = s?.entry.data as Page<{ id: string }> | undefined;\n if (!s?.more || !page || page.next === null || s.moreCtl || s.ctl) return;\n const ctl = (s.moreCtl = new AbortController());\n this.update(s, { loadingMore: true });\n try {\n const next = (await s.more(page.next, ctl.signal)) as Page<{ id: string }>;\n if (s.moreCtl !== ctl) return;\n const cur = s.entry.data as Page<{ id: string }>;\n const seen = new Set(cur.items.map((x) => x.id));\n this.update(s, { data: { items: [...cur.items, ...next.items.filter((x) => !seen.has(x.id))], next: next.next }, error: undefined });\n } catch (e) {\n const error = toContentKitError(e);\n if (s.moreCtl === ctl && error.code !== \"aborted\") this.update(s, { error });\n } finally {\n if (s.moreCtl === ctl) {\n s.moreCtl = undefined;\n this.update(s, { loadingMore: false });\n }\n }\n }\n\n /** Replaces a key's data for every hook showing it. */\n set<T>(key: string, data: T | ((prev: T | undefined) => T)): void {\n const s = this.slots.get(key);\n if (!s) return;\n const next = typeof data === \"function\" ? (data as (p: T | undefined) => T)(s.entry.data as T | undefined) : data;\n this.update(s, { data: next, loaded: true, error: undefined });\n }\n\n /** Starts an optimistic write on key: the token rollback() checks. */\n mark(key: string): number {\n const s = this.slots.get(key);\n return s ? ++s.version : 0;\n }\n\n /** Restores data unless a newer optimistic write started since mark(). */\n rollback<T>(key: string, token: number, data: T): void {\n const s = this.slots.get(key);\n if (s && s.version === token) this.update(s, { data, loaded: true });\n }\n\n /** Applies fn to the data of every slot whose tag matches. */\n patch<T>(match: (tag: Tag) => boolean, fn: (data: T) => T): void {\n for (const s of this.slots.values()) {\n if (s.entry.data !== undefined && match(s.tag)) this.update(s, { data: fn(s.entry.data as T) });\n }\n }\n\n /** Refetches every shown slot whose tag matches. */\n invalidate(match: (tag: Tag) => boolean): void {\n for (const [key, s] of this.slots) if (match(s.tag) && s.listeners.size) this.load(key, true);\n }\n\n private apply(c: ContentKitChange): void {\n const items = <T extends { id: string }>(types: string[], fn: (item: T) => T | null) =>\n this.patch<Page<T>>(\n (t) => types.includes(t.type),\n (page) => {\n let changed = false;\n const out: T[] = [];\n for (const it of page.items) {\n const next = fn(it);\n if (next !== it) changed = true;\n if (next) out.push(next);\n }\n return changed ? { ...page, items: out } : page;\n },\n );\n const comments = [\"comments\", \"replies\", \"latest\", \"admin-comments\"];\n switch (c.type) {\n case \"comment.created\": {\n const parent = c.comment.reply_to_id;\n const published = !c.comment.moderation;\n const add = (t: Tag) => (parent ? t.type === \"replies\" && t.id === parent : t.type === \"comments\" && sameRef(t.ref, c.ref));\n this.patch<Page<Comment>>(add, (p) => (p.items.some((x) => x.id === c.comment.id) ? p : { ...p, items: parent ? [...p.items, c.comment] : [c.comment, ...p.items] }));\n if (parent && published) items<Comment>([\"comments\"], (x) => (x.id === parent ? { ...x, reply_count: x.reply_count + 1 } : x));\n this.invalidate((t) => t.type === \"latest\" || t.type === \"admin-comments\");\n break;\n }\n case \"comment.updated\":\n items<Comment>(comments, (x) => (x.id === c.comment.id ? { ...x, ...c.comment, author: c.comment.author ?? x.author } : x));\n break;\n case \"comment.reacted\":\n items<Comment>(comments, (x) => (x.id === c.id ? { ...x, ...c.counts } : x));\n break;\n case \"comment.deleted\": {\n let parent: string | undefined;\n items<Comment>([\"comments\", \"replies\"], (x) => {\n if (x.id !== c.id || x.deleted) return x;\n if (!x.moderation) parent = x.reply_to_id;\n return { ...x, deleted: true, body: \"[deleted]\", author: undefined, user_id: undefined, anon_name: undefined };\n });\n if (parent) items<Comment>([\"comments\"], (x) => (x.id === parent ? { ...x, reply_count: Math.max(0, x.reply_count - 1) } : x));\n items<Comment>([\"latest\"], (x) => (x.id === c.id ? null : x));\n items<Comment & { deleted_at?: string }>([\"admin-comments\"], (x) => (x.id === c.id ? { ...x, deleted: true, deleted_at: new Date().toISOString() } : x));\n break;\n }\n case \"comment.restored\":\n this.invalidate((t) => comments.includes(t.type));\n break;\n case \"reaction.changed\":\n this.patch((t) => t.type === \"reaction\" && sameRef(t.ref, c.ref), () => c.counts);\n if (c.ref.kind === \"post\") this.postTotals(c.ref.id, c.counts.likes, c.counts.dislikes);\n break;\n case \"favorite.changed\":\n this.patch((t) => t.type === \"favorite\" && sameRef(t.ref, c.ref), () => ({ favorited: c.favorited, count: c.count }));\n this.invalidate((t) => t.type === \"favorites\");\n break;\n case \"post.created\":\n this.invalidate((t) => t.type === \"posts\");\n break;\n case \"post.updated\":\n this.patch<Post | null>((t) => t.type === \"post\", (p) => (p?.id === c.post.id ? c.post : p));\n items<Post>([\"posts\"], (x) => (x.id === c.post.id ? c.post : x));\n break;\n case \"post.changed\":\n this.invalidate((t) => (t.type === \"post\" && t.id === c.id) || t.type === \"posts\");\n break;\n case \"post.deleted\":\n items<Post>([\"posts\"], (x) => (x.id === c.id ? null : x));\n this.invalidate((t) => t.type === \"posts\" && t.scope === \"deleted\");\n break;\n case \"post.restored\":\n this.invalidate((t) => (t.type === \"post\" && t.id === c.post.id) || t.type === \"posts\");\n break;\n case \"poll.created\":\n this.invalidate((t) => t.type === \"polls\" || (t.type === \"poll\" && !t.id));\n break;\n case \"poll.updated\":\n // A latest-poll slot has no id in its tag: match by the poll it holds.\n this.patch<Poll | null>((t) => t.type === \"poll\", (p) => (p?.id === c.poll.id ? c.poll : p));\n items<Poll>([\"polls\"], (x) => (x.id === c.poll.id ? c.poll : x));\n break;\n case \"poll.changed\":\n this.invalidate((t) => (t.type === \"poll\" && (t.id === c.id || !t.id)) || t.type === \"polls\");\n break;\n case \"poll.deleted\":\n items<Poll>([\"polls\"], (x) => (x.id === c.id ? null : x));\n this.invalidate((t) => t.type === \"poll\" && !t.id);\n break;\n case \"ban.saved\":\n case \"ban.lifted\":\n this.invalidate((t) => (t.type === \"bans\" && t.scope === c.scope) || t.type === \"standing\");\n break;\n case \"moderation.resolved\":\n items<{ id: string }>([\"held\"], (x) => (x.id === c.id ? null : x));\n if (c.kind === \"comment\") this.invalidate((t) => comments.includes(t.type));\n else this.invalidate((t) => (t.type === \"post\" && t.id === c.id) || t.type === \"posts\");\n break;\n }\n }\n\n private postTotals(id: string, likes: number, dislikes: number): void {\n const fn = (p: Post): Post => (p.id === id ? { ...p, total_likes: likes, total_dislikes: dislikes } : p);\n this.patch<Post>((t) => t.type === \"post\" && t.id === id, fn);\n this.patch<Page<Post>>((t) => t.type === \"posts\", (page) => ({ ...page, items: page.items.map(fn) }));\n }\n\n // A new entry per change: useSyncExternalStore compares snapshots by identity.\n private update(s: Slot, patch: Partial<Resource<unknown>>): void {\n s.entry = { ...s.entry, ...patch };\n for (const l of s.listeners) l();\n }\n}\n\nconst stores = new WeakMap<ContentKitClient, ResourceStore>();\n\n/** The client's shared content store. */\nexport function resourcesFor(client: ContentKitClient): ResourceStore {\n let s = stores.get(client);\n if (!s) stores.set(client, (s = new ResourceStore(client)));\n return s;\n}\n"],"mappings":";;AA4CA,IAAM,IAAwB;CAAE,MAAM,KAAA;CAAW,SAAS;CAAO,QAAQ;AAAM,GAEzE,KAAW,GAAa,MAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAO/E,IAAb,MAA2B;CACzB,wBAAyB,IAAI,IAAkB;CAE/C,YAAY,GAA0B;EACpC,EAAO,WAAW,MAAM,KAAK,MAAM,CAAC,CAAC;CACvC;CAEA,UAAU,GAAa,GAAU,GAAkC;EACjE,IAAI,IAAI,KAAK,MAAM,IAAI,CAAG;EAC1B,AAAK,KAAG,KAAK,MAAM,IAAI,GAAM,IAAI;GAAE;GAAK,2BAAW,IAAI,IAAI;GAAG,OAAO;GAAM,SAAS;EAAE,CAAE;EACxF,IAAM,IAAO;EAEb,OADA,EAAK,UAAU,IAAI,CAAQ,SACd;GAGX,AAFA,EAAK,UAAU,OAAO,CAAQ,GAE9B,qBAAqB;IACf,EAAK,UAAU,QAAQ,KAAK,MAAM,IAAI,CAAG,MAAM,MACnD,EAAK,KAAK,MAAM,GAChB,EAAK,SAAS,MAAM,GACpB,KAAK,MAAM,OAAO,CAAG;GACvB,CAAC;EACH;CACF;CAEA,SAAY,GAA0B;EACpC,OAAQ,KAAK,MAAM,IAAI,CAAG,CAAC,EAAE,SAAS;CACxC;CAGA,KAAK,GAAa,GAA2B,GAA2B;EACtE,IAAM,IAAI,KAAK,MAAM,IAAI,CAAG;EAC5B,AAAI,KAAG,OAAO,OAAO,GAAG;GAAE;GAAS;EAAK,CAAC;CAC3C;CAGA,KAAK,GAAa,IAAQ,IAAa;EACr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