@inflatable-cookie/longhorn-poodle-svelte 0.7.0 → 0.7.1

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 (259) hide show
  1. package/README.md +3 -2
  2. package/dist/bindings/drop-target.d.ts +13 -0
  3. package/dist/bindings/drop-target.js +26 -0
  4. package/dist/bindings/element-geometry.d.ts +2 -0
  5. package/dist/bindings/element-geometry.js +10 -0
  6. package/dist/bindings/freeze-projection.d.ts +1 -0
  7. package/dist/bindings/freeze-projection.js +11 -0
  8. package/dist/bindings/index.d.ts +4 -0
  9. package/dist/bindings/index.js +4 -0
  10. package/dist/bindings/layout.svelte.d.ts +30 -0
  11. package/dist/bindings/layout.svelte.js +98 -0
  12. package/dist/bindings/lifecycle.svelte.d.ts +59 -0
  13. package/dist/bindings/lifecycle.svelte.js +154 -0
  14. package/dist/bindings/mount.d.ts +2 -0
  15. package/dist/bindings/mount.js +11 -0
  16. package/dist/bindings/optimistic.svelte.d.ts +20 -0
  17. package/dist/bindings/optimistic.svelte.js +67 -0
  18. package/dist/bindings/sample-controller.svelte.d.ts +4 -0
  19. package/dist/bindings/sample-controller.svelte.js +12 -0
  20. package/dist/bindings/scheduler.d.ts +5 -0
  21. package/dist/bindings/scheduler.js +9 -0
  22. package/dist/bindings/session-projection.svelte.d.ts +21 -0
  23. package/dist/bindings/session-projection.svelte.js +80 -0
  24. package/dist/bindings/start-stop.d.ts +6 -0
  25. package/dist/bindings/start-stop.js +61 -0
  26. package/dist/bindings/surface-transfer-actions.d.ts +27 -0
  27. package/dist/bindings/surface-transfer-actions.js +172 -0
  28. package/dist/bindings/surface-transfer.svelte.d.ts +47 -0
  29. package/dist/bindings/surface-transfer.svelte.js +164 -0
  30. package/dist/bindings/surfaces.svelte.d.ts +33 -0
  31. package/dist/bindings/surfaces.svelte.js +130 -0
  32. package/dist/bindings/teardown.d.ts +1 -0
  33. package/dist/bindings/teardown.js +16 -0
  34. package/dist/bindings/transfer-actions.d.ts +34 -0
  35. package/dist/bindings/transfer-actions.js +195 -0
  36. package/dist/bindings/transfer-model.d.ts +101 -0
  37. package/dist/bindings/transfer-model.js +24 -0
  38. package/dist/bindings/transfer.svelte.d.ts +26 -0
  39. package/dist/bindings/transfer.svelte.js +340 -0
  40. package/dist/bindings/window-chrome.d.ts +24 -0
  41. package/{src/bindings/window-chrome.ts → dist/bindings/window-chrome.js} +8 -18
  42. package/dist/bindings/window-drag.d.ts +32 -0
  43. package/dist/bindings/window-drag.js +121 -0
  44. package/{src → dist}/commands/poodle/CommandPaletteBinding.svelte +2 -2
  45. package/dist/commands/poodle/CommandPaletteBinding.svelte.d.ts +12 -0
  46. package/{src → dist}/commands/poodle/KeybindingSettings.svelte +1 -1
  47. package/dist/commands/poodle/KeybindingSettings.svelte.d.ts +22 -0
  48. package/dist/commands/poodle/projectors.d.ts +5 -0
  49. package/dist/commands/poodle/projectors.js +23 -0
  50. package/dist/commands/poodle.d.ts +5 -0
  51. package/dist/commands/poodle.js +4 -0
  52. package/dist/commands/svelte/lifecycle.d.ts +2 -0
  53. package/dist/commands/svelte/lifecycle.js +4 -0
  54. package/dist/commands/svelte/session.svelte.d.ts +48 -0
  55. package/dist/commands/svelte/session.svelte.js +142 -0
  56. package/dist/commands/svelte.d.ts +2 -0
  57. package/dist/commands/svelte.js +2 -0
  58. package/{src → dist}/config/poodle/BackupSettingsPage.svelte +3 -3
  59. package/dist/config/poodle/BackupSettingsPage.svelte.d.ts +4 -0
  60. package/dist/config/poodle/ConfigSnapshotState.svelte.d.ts +8 -0
  61. package/{src → dist}/config/poodle/RestoreSettingsPage.svelte +5 -5
  62. package/dist/config/poodle/RestoreSettingsPage.svelte.d.ts +4 -0
  63. package/{src → dist}/config/poodle/StorageSettingsPage.svelte +2 -2
  64. package/dist/config/poodle/StorageSettingsPage.svelte.d.ts +4 -0
  65. package/dist/config/poodle/format.d.ts +6 -0
  66. package/dist/config/poodle/format.js +15 -0
  67. package/dist/config/poodle/page-state.svelte.d.ts +18 -0
  68. package/dist/config/poodle/page-state.svelte.js +67 -0
  69. package/dist/config/poodle/restore-model.d.ts +28 -0
  70. package/dist/config/poodle/restore-model.js +97 -0
  71. package/dist/config/poodle/types.d.ts +7 -0
  72. package/dist/config/poodle/types.js +1 -0
  73. package/dist/config/poodle.d.ts +7 -0
  74. package/{src/config/poodle.ts → dist/config/poodle.js} +0 -2
  75. package/dist/failures.d.ts +8 -0
  76. package/dist/failures.js +13 -0
  77. package/dist/history/svelte/lifecycle.d.ts +2 -0
  78. package/dist/history/svelte/lifecycle.js +4 -0
  79. package/dist/history/svelte/session.svelte.d.ts +40 -0
  80. package/dist/history/svelte/session.svelte.js +100 -0
  81. package/dist/history/svelte.d.ts +2 -0
  82. package/dist/history/svelte.js +2 -0
  83. package/dist/history-tree/svelte/lifecycle.d.ts +2 -0
  84. package/dist/history-tree/svelte/lifecycle.js +4 -0
  85. package/dist/history-tree/svelte/session.svelte.d.ts +46 -0
  86. package/dist/history-tree/svelte/session.svelte.js +104 -0
  87. package/dist/history-tree/svelte.d.ts +3 -0
  88. package/dist/history-tree/svelte.js +2 -0
  89. package/{src → dist}/licence/poodle/LicenceActivation.svelte +1 -1
  90. package/dist/licence/poodle/LicenceActivation.svelte.d.ts +18 -0
  91. package/{src → dist}/licence/poodle/LicenceSeats.svelte +1 -1
  92. package/dist/licence/poodle/LicenceSeats.svelte.d.ts +20 -0
  93. package/{src → dist}/licence/poodle/LicenceStatus.svelte +1 -1
  94. package/dist/licence/poodle/LicenceStatus.svelte.d.ts +15 -0
  95. package/dist/licence/poodle/LicenceSurface.svelte.d.ts +14 -0
  96. package/dist/licence/poodle/LicenceSurface.svelte.js +39 -0
  97. package/dist/licence/poodle.js +3 -0
  98. package/dist/native-content/index.d.ts +4 -0
  99. package/dist/native-content/index.js +4 -0
  100. package/dist/native-content/lifecycle.d.ts +2 -0
  101. package/dist/native-content/lifecycle.js +4 -0
  102. package/dist/native-content/session.svelte.d.ts +62 -0
  103. package/dist/native-content/session.svelte.js +396 -0
  104. package/dist/native-content/viewport.d.ts +7 -0
  105. package/dist/native-content/viewport.js +18 -0
  106. package/dist/native-content/visibility.d.ts +7 -0
  107. package/dist/native-content/visibility.js +7 -0
  108. package/{src → dist}/notifications/poodle/NotificationPanel.svelte +3 -3
  109. package/dist/notifications/poodle/NotificationPanel.svelte.d.ts +12 -0
  110. package/{src → dist}/notifications/poodle/NotificationToastHost.svelte +2 -2
  111. package/dist/notifications/poodle/NotificationToastHost.svelte.d.ts +11 -0
  112. package/{src → dist}/notifications/poodle/NotificationToastStack.svelte +2 -2
  113. package/dist/notifications/poodle/NotificationToastStack.svelte.d.ts +7 -0
  114. package/dist/notifications/poodle/projectors.d.ts +16 -0
  115. package/dist/notifications/poodle/projectors.js +20 -0
  116. package/dist/notifications/poodle/toasts.d.ts +11 -0
  117. package/dist/notifications/poodle/toasts.js +28 -0
  118. package/{src/notifications/poodle.ts → dist/notifications/poodle.d.ts} +1 -1
  119. package/dist/notifications/poodle.js +4 -0
  120. package/dist/notifications/svelte/lifecycle.d.ts +2 -0
  121. package/dist/notifications/svelte/lifecycle.js +4 -0
  122. package/dist/notifications/svelte/session.svelte.d.ts +50 -0
  123. package/dist/notifications/svelte/session.svelte.js +97 -0
  124. package/dist/notifications/svelte.d.ts +2 -0
  125. package/dist/notifications/svelte.js +2 -0
  126. package/{src → dist}/operation/poodle/OperationPanel.svelte +3 -3
  127. package/dist/operation/poodle/OperationPanel.svelte.d.ts +15 -0
  128. package/dist/operation/poodle/projectors.d.ts +17 -0
  129. package/dist/operation/poodle/projectors.js +45 -0
  130. package/{src/operation/poodle.ts → dist/operation/poodle.d.ts} +1 -1
  131. package/dist/operation/poodle.js +2 -0
  132. package/dist/operation/svelte/lifecycle.d.ts +2 -0
  133. package/dist/operation/svelte/lifecycle.js +4 -0
  134. package/dist/operation/svelte/session.svelte.d.ts +39 -0
  135. package/dist/operation/svelte/session.svelte.js +83 -0
  136. package/dist/operation/svelte.d.ts +2 -0
  137. package/dist/operation/svelte.js +2 -0
  138. package/{src → dist}/poodle/LayoutDockRegion.svelte +2 -2
  139. package/dist/poodle/LayoutDockRegion.svelte.d.ts +34 -0
  140. package/{src → dist}/poodle/LayoutSplitView.svelte +1 -1
  141. package/dist/poodle/LayoutSplitView.svelte.d.ts +28 -0
  142. package/{src → dist}/poodle/LayoutTabs.svelte +2 -2
  143. package/dist/poodle/LayoutTabs.svelte.d.ts +26 -0
  144. package/dist/poodle/binding.d.ts +23 -0
  145. package/dist/poodle/binding.js +234 -0
  146. package/dist/poodle/document.d.ts +12 -0
  147. package/dist/poodle/document.js +61 -0
  148. package/{src/poodle/index.ts → dist/poodle/index.d.ts} +2 -2
  149. package/dist/poodle/index.js +5 -0
  150. package/dist/poodle/projectors.d.ts +9 -0
  151. package/dist/poodle/projectors.js +58 -0
  152. package/dist/poodle/transfer.d.ts +29 -0
  153. package/dist/poodle/transfer.js +87 -0
  154. package/dist/poodle/types.d.ts +50 -0
  155. package/dist/poodle/types.js +18 -0
  156. package/{src → dist}/settings/poodle/SettingsShell.svelte +3 -3
  157. package/dist/settings/poodle/SettingsShell.svelte.d.ts +33 -0
  158. package/{src/settings/poodle.ts → dist/settings/poodle.d.ts} +1 -1
  159. package/dist/settings/poodle.js +2 -0
  160. package/dist/settings/svelte/context.d.ts +10 -0
  161. package/dist/settings/svelte/context.js +25 -0
  162. package/dist/settings/svelte/document.svelte.d.ts +30 -0
  163. package/dist/settings/svelte/document.svelte.js +175 -0
  164. package/dist/settings/svelte/errors.d.ts +35 -0
  165. package/dist/settings/svelte/errors.js +68 -0
  166. package/dist/settings/svelte/lifecycle.d.ts +3 -0
  167. package/dist/settings/svelte/lifecycle.js +12 -0
  168. package/dist/settings/svelte/page.svelte.d.ts +26 -0
  169. package/dist/settings/svelte/page.svelte.js +203 -0
  170. package/dist/settings/svelte/runtime.svelte.d.ts +19 -0
  171. package/dist/settings/svelte/runtime.svelte.js +220 -0
  172. package/dist/settings/svelte/scope.svelte.d.ts +22 -0
  173. package/dist/settings/svelte/scope.svelte.js +86 -0
  174. package/dist/settings/svelte/session.svelte.d.ts +57 -0
  175. package/dist/settings/svelte/session.svelte.js +215 -0
  176. package/dist/settings/svelte/types.d.ts +81 -0
  177. package/dist/settings/svelte/types.js +1 -0
  178. package/dist/settings/svelte.d.ts +6 -0
  179. package/dist/settings/svelte.js +6 -0
  180. package/{src → dist}/update/poodle/UpdateCentre.svelte +1 -1
  181. package/dist/update/poodle/UpdateCentre.svelte.d.ts +17 -0
  182. package/{src → dist}/update/poodle/UpdateSettings.svelte +1 -1
  183. package/dist/update/poodle/UpdateSettings.svelte.d.ts +16 -0
  184. package/{src → dist}/update/poodle/UpdateStatus.svelte +1 -1
  185. package/dist/update/poodle/UpdateStatus.svelte.d.ts +16 -0
  186. package/dist/update/poodle/UpdateSurface.svelte.d.ts +77 -0
  187. package/dist/update/poodle/UpdateSurface.svelte.js +119 -0
  188. package/dist/update/poodle.js +3 -0
  189. package/package.json +95 -92
  190. package/src/bindings/drop-target.ts +0 -39
  191. package/src/bindings/element-geometry.ts +0 -10
  192. package/src/bindings/freeze-projection.ts +0 -11
  193. package/src/bindings/index.ts +0 -4
  194. package/src/bindings/layout.svelte.ts +0 -140
  195. package/src/bindings/lifecycle.svelte.ts +0 -218
  196. package/src/bindings/mount.ts +0 -18
  197. package/src/bindings/optimistic.svelte.ts +0 -86
  198. package/src/bindings/sample-controller.svelte.ts +0 -19
  199. package/src/bindings/scheduler.ts +0 -15
  200. package/src/bindings/session-projection.svelte.ts +0 -98
  201. package/src/bindings/start-stop.ts +0 -64
  202. package/src/bindings/surface-transfer-actions.ts +0 -230
  203. package/src/bindings/surface-transfer.svelte.ts +0 -224
  204. package/src/bindings/surfaces.svelte.ts +0 -182
  205. package/src/bindings/teardown.ts +0 -16
  206. package/src/bindings/transfer-actions.ts +0 -246
  207. package/src/bindings/transfer-model.ts +0 -112
  208. package/src/bindings/transfer.svelte.ts +0 -416
  209. package/src/bindings/window-drag.ts +0 -169
  210. package/src/commands/poodle/projectors.ts +0 -36
  211. package/src/commands/poodle.ts +0 -9
  212. package/src/commands/svelte/lifecycle.ts +0 -6
  213. package/src/commands/svelte/session.svelte.ts +0 -202
  214. package/src/commands/svelte.ts +0 -2
  215. package/src/config/poodle/format.ts +0 -15
  216. package/src/config/poodle/page-state.svelte.ts +0 -81
  217. package/src/config/poodle/restore-model.ts +0 -130
  218. package/src/config/poodle/types.ts +0 -11
  219. package/src/failures.ts +0 -14
  220. package/src/history/svelte/lifecycle.ts +0 -6
  221. package/src/history/svelte/session.svelte.ts +0 -134
  222. package/src/history/svelte.ts +0 -2
  223. package/src/history-tree/svelte/lifecycle.ts +0 -6
  224. package/src/history-tree/svelte/session.svelte.ts +0 -129
  225. package/src/history-tree/svelte.ts +0 -6
  226. package/src/licence/poodle/LicenceSurface.svelte.ts +0 -42
  227. package/src/native-content/index.ts +0 -4
  228. package/src/native-content/lifecycle.ts +0 -6
  229. package/src/native-content/session.svelte.ts +0 -491
  230. package/src/native-content/viewport.ts +0 -29
  231. package/src/native-content/visibility.ts +0 -19
  232. package/src/notifications/poodle/projectors.ts +0 -32
  233. package/src/notifications/poodle/toasts.ts +0 -34
  234. package/src/notifications/svelte/lifecycle.ts +0 -6
  235. package/src/notifications/svelte/session.svelte.ts +0 -123
  236. package/src/notifications/svelte.ts +0 -2
  237. package/src/operation/poodle/projectors.ts +0 -68
  238. package/src/operation/svelte/lifecycle.ts +0 -6
  239. package/src/operation/svelte/session.svelte.ts +0 -113
  240. package/src/operation/svelte.ts +0 -2
  241. package/src/poodle/binding.ts +0 -360
  242. package/src/poodle/document.ts +0 -96
  243. package/src/poodle/projectors.ts +0 -99
  244. package/src/poodle/transfer.ts +0 -137
  245. package/src/poodle/types.ts +0 -82
  246. package/src/settings/svelte/context.ts +0 -54
  247. package/src/settings/svelte/document.svelte.ts +0 -234
  248. package/src/settings/svelte/errors.ts +0 -81
  249. package/src/settings/svelte/lifecycle.ts +0 -20
  250. package/src/settings/svelte/page.svelte.ts +0 -260
  251. package/src/settings/svelte/runtime.svelte.ts +0 -267
  252. package/src/settings/svelte/scope.svelte.ts +0 -114
  253. package/src/settings/svelte/session.svelte.ts +0 -294
  254. package/src/settings/svelte/types.ts +0 -84
  255. package/src/settings/svelte.ts +0 -6
  256. package/src/update/poodle/UpdateSurface.svelte.ts +0 -128
  257. /package/{src → dist}/config/poodle/ConfigSnapshotState.svelte +0 -0
  258. /package/{src/licence/poodle.ts → dist/licence/poodle.d.ts} +0 -0
  259. /package/{src/update/poodle.ts → dist/update/poodle.d.ts} +0 -0
package/README.md CHANGED
@@ -10,8 +10,9 @@ effigy check:svelte
10
10
  effigy test:vitest
11
11
  ```
12
12
 
13
- The root exports the framework-agnostic reactive state — layout, surfaces,
14
- transfer, and surface transfer — as `.svelte.ts` runes modules:
13
+ The root exports the framework-agnostic reactive state. Layout, surfaces,
14
+ transfer, and surface transfer have their own subpaths. These are runes modules,
15
+ published as `.svelte.js` with declarations:
15
16
 
16
17
  - `@inflatable-cookie/longhorn-poodle-svelte` — lifecycle, client status, scheduler
17
18
  - `/layout`, `/surfaces`, `/transfer`, `/surface-transfer`
@@ -0,0 +1,13 @@
1
+ import type { TransferCommitSelector } from "@inflatable-cookie/longhorn/transfer";
2
+ export type DropSelector = {
3
+ readonly kind: "explicit_zone";
4
+ readonly dropZoneId: string;
5
+ } | {
6
+ readonly kind: "screen_point";
7
+ };
8
+ export declare function resolveDropSelector(selector: DropSelector, screenPoint: (() => {
9
+ readonly x: number;
10
+ readonly y: number;
11
+ }) | undefined): TransferCommitSelector;
12
+ export declare function reportError(reporter: (error: unknown) => void, error: unknown): void;
13
+ export declare function notify<Value>(listener: ((value: Value) => void) | undefined, value: Value, reporter: (error: unknown) => void): void;
@@ -0,0 +1,26 @@
1
+ export function resolveDropSelector(selector, screenPoint) {
2
+ if (selector.kind === "explicit_zone") {
3
+ return { kind: "explicit_zone", drop_zone_id: selector.dropZoneId };
4
+ }
5
+ const point = screenPoint?.();
6
+ if (point === undefined || !Number.isSafeInteger(point.x) || !Number.isSafeInteger(point.y)) {
7
+ throw new RangeError("drop screen point must use integer screen DIPs");
8
+ }
9
+ return { kind: "screen_point", point: { x: point.x, y: point.y } };
10
+ }
11
+ export function reportError(reporter, error) {
12
+ try {
13
+ reporter(error);
14
+ }
15
+ catch {
16
+ // Reporting failure must not escape an event callback.
17
+ }
18
+ }
19
+ export function notify(listener, value, reporter) {
20
+ try {
21
+ listener?.(value);
22
+ }
23
+ catch (error) {
24
+ reportError(reporter, error);
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ /** Client rect origins can move when the window or a nested scroller scrolls. */
2
+ export declare function observeViewportMovement(node: HTMLElement, changed: () => void): () => void;
@@ -0,0 +1,10 @@
1
+ /** Client rect origins can move when the window or a nested scroller scrolls. */
2
+ export function observeViewportMovement(node, changed) {
3
+ const view = node.ownerDocument.defaultView;
4
+ view?.addEventListener("scroll", changed, { capture: true, passive: true });
5
+ view?.addEventListener("resize", changed);
6
+ return () => {
7
+ view?.removeEventListener("scroll", changed, true);
8
+ view?.removeEventListener("resize", changed);
9
+ };
10
+ }
@@ -0,0 +1 @@
1
+ export declare function freezeProjection<Value>(value: Value): Value;
@@ -0,0 +1,11 @@
1
+ // Only call this on owned protocol data. Errors and other caller values stay opaque.
2
+ export function freezeProjection(value) {
3
+ if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
4
+ Object.freeze(value);
5
+ const children = Object.values(value);
6
+ for (const child of children) {
7
+ freezeProjection(child);
8
+ }
9
+ }
10
+ return value;
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./lifecycle.svelte.js";
2
+ export * from "./optimistic.svelte.js";
3
+ export * from "./window-chrome.js";
4
+ export * from "./window-drag.js";
@@ -0,0 +1,4 @@
1
+ export * from "./lifecycle.svelte.js";
2
+ export * from "./optimistic.svelte.js";
3
+ export * from "./window-chrome.js";
4
+ export * from "./window-drag.js";
@@ -0,0 +1,30 @@
1
+ import type { LayoutMutationRejection, LayoutMutationRequest, LayoutMutationReceipt } from "@inflatable-cookie/longhorn/layout";
2
+ import type { SurfaceDocument } from "@inflatable-cookie/longhorn/surfaces";
3
+ import type { ClientStatus, OptimisticProjector } from "./index.js";
4
+ export type LayoutDispatchResult = {
5
+ readonly status: "committed";
6
+ readonly receipt: LayoutMutationReceipt;
7
+ } | {
8
+ readonly status: "rejected";
9
+ readonly rejection: LayoutMutationRejection;
10
+ };
11
+ export type LayoutDispatcher = (request: LayoutMutationRequest) => Promise<LayoutDispatchResult>;
12
+ export interface LayoutStateOptions {
13
+ readonly dispatch?: LayoutDispatcher;
14
+ readonly unsupportedReason?: string;
15
+ }
16
+ export declare class LayoutState {
17
+ #private;
18
+ constructor(options: LayoutStateOptions);
19
+ get status(): ClientStatus;
20
+ get authoritative(): SurfaceDocument | undefined;
21
+ get projected(): SurfaceDocument | undefined;
22
+ get pendingRequestIds(): ReadonlyArray<string>;
23
+ start(): Promise<void>;
24
+ accept(document: SurfaceDocument): boolean;
25
+ reconnecting(): void;
26
+ dispatch(request: LayoutMutationRequest, project: OptimisticProjector<SurfaceDocument>): Promise<LayoutDispatchResult>;
27
+ cancel(requestId: string): void;
28
+ stop(): Promise<void>;
29
+ destroy(): Promise<void>;
30
+ }
@@ -0,0 +1,98 @@
1
+ import { OptimisticProjectionState, UnsupportedCapabilityError } from "./index.js";
2
+ export class LayoutState {
3
+ #options;
4
+ #projection = new OptimisticProjectionState((document) => document.revision);
5
+ #status = $state.raw({ kind: "idle" });
6
+ #destroyed = false;
7
+ #generation = 0;
8
+ constructor(options) {
9
+ this.#options = options;
10
+ }
11
+ get status() {
12
+ return this.#status;
13
+ }
14
+ get authoritative() {
15
+ return this.#projection.authoritative;
16
+ }
17
+ get projected() {
18
+ return this.#projection.projected;
19
+ }
20
+ get pendingRequestIds() {
21
+ return this.#projection.pendingRequestIds;
22
+ }
23
+ async start() {
24
+ this.#assertAlive();
25
+ this.#status =
26
+ this.#options.dispatch === undefined
27
+ ? {
28
+ kind: "unsupported",
29
+ reason: this.#options.unsupportedReason ?? "layout dispatch is unavailable",
30
+ }
31
+ : { kind: "loading" };
32
+ }
33
+ accept(document) {
34
+ this.#assertAlive();
35
+ const accepted = this.#projection.accept(document);
36
+ if (accepted && this.#status.kind !== "unsupported") {
37
+ this.#status = { kind: "ready" };
38
+ }
39
+ return accepted;
40
+ }
41
+ reconnecting() {
42
+ this.#assertAlive();
43
+ if (this.#status.kind === "unsupported") {
44
+ return;
45
+ }
46
+ this.#status =
47
+ this.#projection.authoritative === undefined ? { kind: "loading" } : { kind: "reconnecting" };
48
+ }
49
+ async dispatch(request, project) {
50
+ this.#assertAlive();
51
+ const dispatch = this.#options.dispatch;
52
+ if (dispatch === undefined) {
53
+ const reason = this.#options.unsupportedReason ?? "layout dispatch is unavailable";
54
+ this.#status = { kind: "unsupported", reason };
55
+ throw new UnsupportedCapabilityError(reason);
56
+ }
57
+ const generation = this.#generation;
58
+ this.#projection.begin(request.request_id, project);
59
+ try {
60
+ const result = await dispatch(request);
61
+ if (generation !== this.#generation) {
62
+ return result;
63
+ }
64
+ const document = result.status === "committed"
65
+ ? result.receipt.authoritative_document
66
+ : result.rejection.authoritative_document;
67
+ this.#projection.settle(request.request_id, document);
68
+ this.#status = { kind: "ready" };
69
+ return result;
70
+ }
71
+ catch (error) {
72
+ if (generation === this.#generation) {
73
+ this.#projection.cancel(request.request_id);
74
+ this.#status = { kind: "failed", error };
75
+ }
76
+ throw error;
77
+ }
78
+ }
79
+ cancel(requestId) {
80
+ this.#projection.cancel(requestId);
81
+ }
82
+ async stop() {
83
+ ++this.#generation;
84
+ this.#projection.clear();
85
+ this.#status = { kind: "idle" };
86
+ }
87
+ async destroy() {
88
+ if (!this.#destroyed) {
89
+ await this.stop();
90
+ this.#destroyed = true;
91
+ }
92
+ }
93
+ #assertAlive() {
94
+ if (this.#destroyed) {
95
+ throw new Error("layout state has been destroyed");
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,59 @@
1
+ import type { ConnectionFailure, ConnectionFailureReporter } from "@inflatable-cookie/longhorn/core";
2
+ export type ClientStatus = {
3
+ readonly kind: "idle";
4
+ } | {
5
+ readonly kind: "loading";
6
+ } | {
7
+ readonly kind: "ready";
8
+ } | {
9
+ readonly kind: "reconnecting";
10
+ } | {
11
+ readonly kind: "unsupported";
12
+ readonly reason: string;
13
+ } | {
14
+ readonly kind: "failed";
15
+ readonly error: unknown;
16
+ };
17
+ export interface ReactiveConnection<Snapshot> {
18
+ readonly ready: Promise<unknown>;
19
+ current(): Snapshot | undefined;
20
+ dispose(): Promise<void>;
21
+ }
22
+ export type ReactiveConnectionFactory<Snapshot> = (listener: (snapshot: Snapshot) => void, onFailure: ConnectionFailureReporter) => ReactiveConnection<Snapshot>;
23
+ export type ClientCapability<Snapshot> = {
24
+ readonly kind: "supported";
25
+ readonly connect: ReactiveConnectionFactory<Snapshot>;
26
+ } | {
27
+ readonly kind: "unsupported";
28
+ readonly reason: string;
29
+ };
30
+ export interface ReactiveClientStateOptions<Snapshot> {
31
+ readonly capability: ClientCapability<Snapshot>;
32
+ readonly onSnapshot?: (snapshot: Snapshot) => void;
33
+ readonly onFailure?: (failure: ConnectionFailure) => void;
34
+ }
35
+ export interface StartableClientState {
36
+ start(): Promise<void>;
37
+ stop(): Promise<void>;
38
+ }
39
+ export declare class ReactiveClientState<Snapshot> implements StartableClientState {
40
+ #private;
41
+ constructor(options: ReactiveClientStateOptions<Snapshot>);
42
+ get status(): ClientStatus;
43
+ get snapshot(): Snapshot | undefined;
44
+ start(): Promise<void>;
45
+ reconnect(): Promise<void>;
46
+ stop(): Promise<void>;
47
+ destroy(): Promise<void>;
48
+ fail(error: unknown): void;
49
+ }
50
+ export declare class ClientStateDestroyedError extends Error {
51
+ constructor();
52
+ }
53
+ export declare class ClientSnapshotUnavailableError extends Error {
54
+ constructor();
55
+ }
56
+ export declare class UnsupportedCapabilityError extends Error {
57
+ constructor(reason: string);
58
+ }
59
+ export declare function useClientState(state: StartableClientState, reportFailure?: (error: unknown) => void): void;
@@ -0,0 +1,154 @@
1
+ import { useSessionLifecycle } from "./mount.js";
2
+ import { StartStop } from "./start-stop.js";
3
+ export class ReactiveClientState {
4
+ #options;
5
+ #status = $state.raw({ kind: "idle" });
6
+ #snapshot = $state.raw(undefined);
7
+ #connection;
8
+ #lifecycle = new StartStop();
9
+ #destroyed = false;
10
+ constructor(options) {
11
+ this.#options = options;
12
+ }
13
+ get status() {
14
+ return this.#status;
15
+ }
16
+ get snapshot() {
17
+ return this.#snapshot;
18
+ }
19
+ start() {
20
+ if (this.#destroyed) {
21
+ return Promise.reject(new ClientStateDestroyedError());
22
+ }
23
+ return this.#lifecycle.start((generation) => this.#begin(generation, false), true);
24
+ }
25
+ reconnect() {
26
+ if (this.#destroyed) {
27
+ return Promise.reject(new ClientStateDestroyedError());
28
+ }
29
+ if (this.#status.kind === "unsupported") {
30
+ return Promise.resolve();
31
+ }
32
+ void this.#stop(false).catch(() => undefined);
33
+ return this.#lifecycle.start((generation) => this.#begin(generation, true), true);
34
+ }
35
+ stop() {
36
+ return this.#stop(true);
37
+ }
38
+ async destroy() {
39
+ this.#destroyed = true;
40
+ await this.#stop(true);
41
+ }
42
+ fail(error) {
43
+ if (!this.#destroyed) {
44
+ this.#status = { kind: "failed", error };
45
+ }
46
+ }
47
+ async #begin(generation, reconnecting) {
48
+ const capability = this.#options.capability;
49
+ if (capability.kind === "unsupported") {
50
+ this.#status = {
51
+ kind: "unsupported",
52
+ reason: capability.reason,
53
+ };
54
+ return;
55
+ }
56
+ this.#status =
57
+ reconnecting || this.#snapshot !== undefined ? { kind: "reconnecting" } : { kind: "loading" };
58
+ let connection;
59
+ try {
60
+ connection = capability.connect((snapshot) => {
61
+ if (generation === this.#lifecycle.generation && !this.#destroyed) {
62
+ this.#accept(snapshot);
63
+ }
64
+ }, (failure) => {
65
+ if (generation === this.#lifecycle.generation && !this.#destroyed) {
66
+ this.#status = { kind: "failed", error: failure.error };
67
+ this.#options.onFailure?.(failure);
68
+ }
69
+ });
70
+ }
71
+ catch (error) {
72
+ if (generation === this.#lifecycle.generation) {
73
+ this.#status = { kind: "failed", error };
74
+ }
75
+ throw error;
76
+ }
77
+ this.#connection = connection;
78
+ try {
79
+ await connection.ready;
80
+ if (generation !== this.#lifecycle.generation || this.#destroyed) {
81
+ return;
82
+ }
83
+ const snapshot = connection.current();
84
+ if (snapshot === undefined) {
85
+ throw new ClientSnapshotUnavailableError();
86
+ }
87
+ if (this.#snapshot !== snapshot) {
88
+ this.#accept(snapshot);
89
+ }
90
+ else {
91
+ this.#status = { kind: "ready" };
92
+ }
93
+ }
94
+ catch (error) {
95
+ if (generation === this.#lifecycle.generation) {
96
+ this.#status = { kind: "failed", error };
97
+ this.#connection = undefined;
98
+ try {
99
+ await connection.dispose();
100
+ }
101
+ catch {
102
+ // The connection retains exact teardown failure evidence.
103
+ }
104
+ }
105
+ throw error;
106
+ }
107
+ }
108
+ #accept(snapshot) {
109
+ this.#snapshot = snapshot;
110
+ this.#status = { kind: "ready" };
111
+ this.#options.onSnapshot?.(snapshot);
112
+ }
113
+ #stop(clearSnapshot) {
114
+ if (clearSnapshot) {
115
+ this.#snapshot = undefined;
116
+ }
117
+ this.#status = { kind: clearSnapshot ? "idle" : "reconnecting" };
118
+ return this.#lifecycle.stop(async () => {
119
+ // A synchronous connect callback can call stop before connect returns.
120
+ // Capture its connection after that call has finished publishing it.
121
+ await Promise.resolve();
122
+ const connection = this.#connection;
123
+ this.#connection = undefined;
124
+ try {
125
+ await connection?.dispose();
126
+ }
127
+ catch (error) {
128
+ this.#status = { kind: "failed", error };
129
+ throw error;
130
+ }
131
+ });
132
+ }
133
+ }
134
+ export class ClientStateDestroyedError extends Error {
135
+ constructor() {
136
+ super("client state has been destroyed");
137
+ this.name = "ClientStateDestroyedError";
138
+ }
139
+ }
140
+ export class ClientSnapshotUnavailableError extends Error {
141
+ constructor() {
142
+ super("client connection became ready without a snapshot");
143
+ this.name = "ClientSnapshotUnavailableError";
144
+ }
145
+ }
146
+ export class UnsupportedCapabilityError extends Error {
147
+ constructor(reason) {
148
+ super(`capability is unsupported: ${reason}`);
149
+ this.name = "UnsupportedCapabilityError";
150
+ }
151
+ }
152
+ export function useClientState(state, reportFailure) {
153
+ useSessionLifecycle(() => state, reportFailure, reportFailure);
154
+ }
@@ -0,0 +1,2 @@
1
+ import type { StartableClientState } from "./lifecycle.svelte.js";
2
+ export declare function useSessionLifecycle(getSession: () => StartableClientState, onStartFailure?: (error: unknown) => void, onStopFailure?: (error: unknown) => void): void;
@@ -0,0 +1,11 @@
1
+ import { onMount } from "svelte";
2
+ import { reportFailure } from "../failures.js";
3
+ export function useSessionLifecycle(getSession, onStartFailure = () => undefined, onStopFailure = reportFailure) {
4
+ onMount(() => {
5
+ const session = getSession();
6
+ void session.start().catch(onStartFailure);
7
+ return () => {
8
+ void session.stop().catch(onStopFailure);
9
+ };
10
+ });
11
+ }
@@ -0,0 +1,20 @@
1
+ export type RevisionOf<Document> = (document: Document) => number;
2
+ export type OptimisticProjector<Document> = (authoritative: Document) => Document;
3
+ export declare class OptimisticProjectionState<Document> {
4
+ #private;
5
+ constructor(revisionOf: RevisionOf<Document>);
6
+ get authoritative(): Document | undefined;
7
+ get projected(): Document | undefined;
8
+ get pendingRequestIds(): ReadonlyArray<string>;
9
+ accept(document: Document): boolean;
10
+ begin(requestId: string, project: OptimisticProjector<Document>): void;
11
+ settle(requestId: string, document: Document): boolean;
12
+ cancel(requestId: string): void;
13
+ clear(): void;
14
+ }
15
+ export declare class DuplicateOptimisticRequestError extends Error {
16
+ constructor(requestId: string);
17
+ }
18
+ export declare class MissingAuthoritativeDocumentError extends Error {
19
+ constructor();
20
+ }
@@ -0,0 +1,67 @@
1
+ export class OptimisticProjectionState {
2
+ #revisionOf;
3
+ #authoritative = $state.raw(undefined);
4
+ #pending = $state.raw([]);
5
+ constructor(revisionOf) {
6
+ this.#revisionOf = revisionOf;
7
+ }
8
+ get authoritative() {
9
+ return this.#authoritative;
10
+ }
11
+ get projected() {
12
+ let document = this.#authoritative;
13
+ if (document === undefined) {
14
+ return undefined;
15
+ }
16
+ for (const pending of this.#pending) {
17
+ document = pending.project(document);
18
+ }
19
+ return document;
20
+ }
21
+ get pendingRequestIds() {
22
+ return this.#pending.map(({ requestId }) => requestId);
23
+ }
24
+ accept(document) {
25
+ const current = this.#authoritative;
26
+ if (current !== undefined && this.#revisionOf(document) < this.#revisionOf(current)) {
27
+ return false;
28
+ }
29
+ this.#authoritative = document;
30
+ return true;
31
+ }
32
+ begin(requestId, project) {
33
+ if (this.#pending.some((pending) => pending.requestId === requestId)) {
34
+ throw new DuplicateOptimisticRequestError(requestId);
35
+ }
36
+ const current = this.projected;
37
+ if (current === undefined) {
38
+ throw new MissingAuthoritativeDocumentError();
39
+ }
40
+ project(current);
41
+ this.#pending = [...this.#pending, { requestId, project }];
42
+ }
43
+ settle(requestId, document) {
44
+ const accepted = this.accept(document);
45
+ this.cancel(requestId);
46
+ return accepted;
47
+ }
48
+ cancel(requestId) {
49
+ this.#pending = this.#pending.filter((pending) => pending.requestId !== requestId);
50
+ }
51
+ clear() {
52
+ this.#authoritative = undefined;
53
+ this.#pending = [];
54
+ }
55
+ }
56
+ export class DuplicateOptimisticRequestError extends Error {
57
+ constructor(requestId) {
58
+ super(`optimistic request is already pending: ${requestId}`);
59
+ this.name = "DuplicateOptimisticRequestError";
60
+ }
61
+ }
62
+ export class MissingAuthoritativeDocumentError extends Error {
63
+ constructor() {
64
+ super("optimistic projection requires an authoritative document");
65
+ this.name = "MissingAuthoritativeDocumentError";
66
+ }
67
+ }
@@ -0,0 +1,4 @@
1
+ /** Track reads from a plain controller. The owner manages its start and stop. */
2
+ export declare function sampleController<Controller extends {
3
+ observe(callback: () => void): () => void;
4
+ }>(getController: () => Controller): () => Controller;
@@ -0,0 +1,12 @@
1
+ import { untrack } from "svelte";
2
+ /** Track reads from a plain controller. The owner manages its start and stop. */
3
+ export function sampleController(getController) {
4
+ let revision = $state(0);
5
+ $effect(() => getController().observe(() => {
6
+ revision = untrack(() => revision) + 1;
7
+ }));
8
+ return () => {
9
+ void revision;
10
+ return getController();
11
+ };
12
+ }
@@ -0,0 +1,5 @@
1
+ export interface TimerScheduler {
2
+ set(delayMs: number, callback: () => void): unknown;
3
+ clear(handle: unknown): void;
4
+ }
5
+ export declare const systemTimerScheduler: TimerScheduler;
@@ -0,0 +1,9 @@
1
+ export const systemTimerScheduler = {
2
+ set(delayMs, callback) {
3
+ return globalThis.setTimeout(callback, delayMs);
4
+ },
5
+ clear(handle) {
6
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- systemTimerScheduler clears handles from its own setTimeout call.
7
+ globalThis.clearTimeout(handle);
8
+ },
9
+ };
@@ -0,0 +1,21 @@
1
+ interface ObservableController {
2
+ observe(listener: () => void): () => void;
3
+ start(): Promise<void>;
4
+ stop(): Promise<void>;
5
+ restart(): Promise<void>;
6
+ }
7
+ export declare class SessionProjection<Projection> {
8
+ #private;
9
+ constructor(controller: ObservableController, project: () => Projection);
10
+ get current(): Projection;
11
+ get retryFailure(): {
12
+ readonly kind: "failed";
13
+ readonly error: unknown;
14
+ } | undefined;
15
+ observe(observer: () => void): () => void;
16
+ start(): Promise<void>;
17
+ stop(): Promise<void>;
18
+ retry(previousError: unknown): Promise<void>;
19
+ dispose(): Promise<void>;
20
+ }
21
+ export {};