@runic-artifex/svelte 0.1.0-preview.14.1 → 0.2.0-preview.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.
- package/README.md +194 -79
- package/dist/bridge.svelte.d.ts +4 -4
- package/dist/bridge.svelte.js +92 -26
- package/dist/context.svelte.d.ts +5 -5
- package/dist/effect-action.svelte.d.ts +3 -3
- package/dist/effect-action.svelte.js +2 -2
- package/dist/effect-bridge.svelte.d.ts +8 -8
- package/dist/hosted.svelte.d.ts +13 -0
- package/dist/hosted.svelte.js +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/translations/testing.d.ts +38 -0
- package/dist/translations/testing.js +68 -0
- package/dist/types.d.ts +21 -31
- package/dist/vite.d.ts +8 -0
- package/dist/vite.js +13 -0
- package/package.json +63 -10
package/README.md
CHANGED
|
@@ -1,127 +1,242 @@
|
|
|
1
1
|
# `@runic-artifex/svelte`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Make one Runic Toolkit Application Bridge controller feel native in a Svelte 5
|
|
4
|
+
application. This package owns Svelte lifecycle, context, and rune projection
|
|
5
|
+
while the controller remains authoritative for its snapshots, transport,
|
|
6
|
+
commands, reconnect, and events.
|
|
5
7
|
|
|
6
|
-
##
|
|
8
|
+
## Install
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
```sh
|
|
11
|
+
npm install @runic-artifex/application-bridge@preview @runic-artifex/svelte@preview
|
|
12
|
+
```
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
`@runic-artifex/svelte` is a public npm preview. The `preview` tag follows the
|
|
15
|
+
current preview release without pinning a stale version.
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
| Requirement | Supported range |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Svelte | `>=5.46.4 <6` |
|
|
20
|
+
| Effect | `4.0.0-rc.112` |
|
|
21
|
+
| Runic Toolkit Application Bridge | `>=0.1.0-preview.30.1 <1` (optional peer; required by the root and `/bridge` entries) |
|
|
22
|
+
| Runic Vite integration | `>=0.2.0-preview.1 <1` (optional peer; required only by `/vite`) |
|
|
23
|
+
|
|
24
|
+
Svelte 4 and legacy stores are not supported.
|
|
25
|
+
|
|
26
|
+
### Public contract boundary
|
|
27
|
+
|
|
28
|
+
This adapter follows the released Application Bridge controller: failures are
|
|
29
|
+
the generated `BridgeError` union and Effect programs use its owned service.
|
|
30
|
+
It does not retain adapter-local failure or runtime generics. The released
|
|
31
|
+
local host boundary is the structural Application Bridge `FrameChannel`
|
|
32
|
+
contract; Svelte neither creates a frame channel nor owns transport,
|
|
33
|
+
reconnect, protocol, revision, or controller lifetime. The optional `/vite`
|
|
34
|
+
entry covers the released Vite resource lifecycle; authentication, remote
|
|
35
|
+
service transport, deployment, SSR, hydration, and rollout remain outside this
|
|
36
|
+
adapter.
|
|
37
|
+
|
|
38
|
+
## Use an Application Bridge in Svelte 5
|
|
39
|
+
|
|
40
|
+
`@runic-artifex/svelte/translations` is deliberately independent of the
|
|
41
|
+
Application Bridge peer, so translation-only apps can install and render it
|
|
42
|
+
without a bridge package. The package root and the additive
|
|
43
|
+
`@runic-artifex/svelte/bridge` entry point load bridge support; if the optional
|
|
44
|
+
peer is absent, they report the exact `npm install
|
|
45
|
+
@runic-artifex/application-bridge@preview` remediation.
|
|
46
|
+
|
|
47
|
+
Use `@runic-artifex/svelte/vite` only when registering Runic Vite
|
|
48
|
+
DevTools. It supplies the typed observer and HMR resource helpers without
|
|
49
|
+
making the root bridge entry depend on Vite.
|
|
50
|
+
|
|
51
|
+
Create the controller with `@runic-artifex/application-bridge`, then create one
|
|
52
|
+
Svelte projection and one typed context for the component tree. `provide()`
|
|
53
|
+
starts the bridge after the first browser mount by default; it initializes the
|
|
54
|
+
snapshot, then calls `uiReady()` and `uiRendered()`. It disposes the bridge on
|
|
55
|
+
unmount by default.
|
|
56
|
+
|
|
57
|
+
For a Runic Desktop application, compose the transport before constructing the
|
|
58
|
+
Svelte projection. The generated contract is unchanged:
|
|
17
59
|
|
|
18
|
-
|
|
19
|
-
|
|
60
|
+
```ts
|
|
61
|
+
import { createDesktopFrameChannel } from "@runic-artifex/desktop";
|
|
62
|
+
import {
|
|
63
|
+
ApplicationBridgeLive,
|
|
64
|
+
createApplicationBridgeController,
|
|
65
|
+
} from "@runic-artifex/application-bridge";
|
|
66
|
+
import { SetupContract } from "./generated/setup-contract";
|
|
67
|
+
|
|
68
|
+
export const controller = createApplicationBridgeController(
|
|
69
|
+
SetupContract,
|
|
70
|
+
ApplicationBridgeLive(SetupContract, createDesktopFrameChannel()),
|
|
71
|
+
);
|
|
20
72
|
```
|
|
21
73
|
|
|
22
|
-
|
|
23
|
-
|
|
74
|
+
The controller's Effect scope connects and closes the Desktop channel. Svelte
|
|
75
|
+
mounting owns only its subscription and projection; dispose the controller once
|
|
76
|
+
at the application-composition boundary after the Svelte root is unmounted.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// src/lib/setup-bridge.svelte.ts
|
|
80
|
+
import {
|
|
81
|
+
createApplicationBridgeContext,
|
|
82
|
+
createSvelteApplicationBridge,
|
|
83
|
+
} from "@runic-artifex/svelte";
|
|
84
|
+
import { controller } from "./setup-controller";
|
|
85
|
+
|
|
86
|
+
export const setupBridge = createSvelteApplicationBridge(controller, {
|
|
87
|
+
reduce: (snapshot, event) =>
|
|
88
|
+
event._tag === "SnapshotReplaced" ? event.snapshot : snapshot,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const setupBridgeContext = createApplicationBridgeContext();
|
|
92
|
+
```
|
|
24
93
|
|
|
25
94
|
```svelte
|
|
95
|
+
<!-- src/routes/+page.svelte -->
|
|
26
96
|
<script lang="ts">
|
|
27
|
-
import {
|
|
28
|
-
import { localeContext } from "$lib/locale-context";
|
|
97
|
+
import { setupBridge, setupBridgeContext } from "$lib/setup-bridge.svelte";
|
|
29
98
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
99
|
+
const bridge = setupBridgeContext.provide(setupBridge);
|
|
100
|
+
let snapshot = $derived(bridge.snapshot);
|
|
101
|
+
|
|
102
|
+
async function refresh() {
|
|
103
|
+
await bridge.dispatch({ _tag: "Refresh" });
|
|
104
|
+
}
|
|
33
105
|
</script>
|
|
34
106
|
|
|
35
|
-
{
|
|
107
|
+
<p>{bridge.status}</p>
|
|
108
|
+
{#if snapshot}
|
|
109
|
+
<button onclick={refresh}>Refresh</button>
|
|
110
|
+
{/if}
|
|
36
111
|
```
|
|
37
112
|
|
|
38
|
-
|
|
39
|
-
the
|
|
113
|
+
Keep transient presentation state in Svelte. Supply `reduce` when bridge events
|
|
114
|
+
produce a newer snapshot; otherwise the initial/reconnect snapshots remain the
|
|
115
|
+
projection's state. Call `bridge.cancel(operationId)` to request an explicit
|
|
116
|
+
backend operation cancellation. Disposing a component is not a cancellation
|
|
117
|
+
command.
|
|
118
|
+
|
|
119
|
+
## Optional: Runic Translations
|
|
120
|
+
|
|
121
|
+
The `@runic-artifex/svelte/translations` subpath adapts a generated Runic
|
|
122
|
+
Translations `LocaleSource` without making the generated catalog a runtime
|
|
123
|
+
dependency. Install and configure the Runic Translations Vite plugin that
|
|
124
|
+
provides your `virtual:runic-translations/...` modules, then create one locale
|
|
125
|
+
context and provide a source per browser root or SSR component tree.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
// src/lib/locale-context.svelte.ts
|
|
129
|
+
import { createLocaleContext } from "@runic-artifex/svelte/translations";
|
|
130
|
+
|
|
131
|
+
export const localeContext = createLocaleContext<"en" | "de">();
|
|
132
|
+
```
|
|
40
133
|
|
|
41
134
|
```svelte
|
|
42
135
|
<script lang="ts">
|
|
43
|
-
import {
|
|
44
|
-
import { localeContext } from "$lib/locale-context";
|
|
136
|
+
import { createLocaleSource } from "virtual:runic-translations/app/runtime";
|
|
137
|
+
import { localeContext } from "$lib/locale-context.svelte";
|
|
45
138
|
|
|
46
|
-
|
|
139
|
+
let { data, children } = $props();
|
|
140
|
+
const source = createLocaleSource({ initialLocale: data.locale });
|
|
141
|
+
const locale = localeContext.provide(source);
|
|
47
142
|
</script>
|
|
48
143
|
|
|
49
|
-
<h1>{m["Common.Hello"]({ name: "Ada" }, locale.messageOptions)}</h1>
|
|
50
144
|
<button onclick={() => locale.setLocale("de")}>Deutsch</button>
|
|
145
|
+
{@render children()}
|
|
51
146
|
```
|
|
52
147
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
148
|
+
A mutable source is updated directly. If navigation or application settings are
|
|
149
|
+
authoritative, pass `requestLocale` to `provide()` and update the source through
|
|
150
|
+
that callback. Initialize the client source from the root server load for
|
|
151
|
+
deterministic hydration. For URL routing, use
|
|
152
|
+
[`@runic-artifex/sveltekit/translations`](https://www.npmjs.com/package/@runic-artifex/sveltekit).
|
|
57
153
|
|
|
58
|
-
|
|
59
|
-
unsubscribe in `onDestroy`. Context makes each render request-scoped; no global
|
|
60
|
-
generated resolver is configured. Nested providers shadow their parent and
|
|
61
|
-
dispose only their own subscription. Pass `dispose: false` only when the caller
|
|
62
|
-
owns a longer-lived state. Hydration is deterministic when the client source is
|
|
63
|
-
initialized from the locale returned by the root server load.
|
|
154
|
+
### Localization and visual-accessibility regression cases
|
|
64
155
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
156
|
+
`@runic-artifex/svelte/translations/testing` provides framework-neutral data
|
|
157
|
+
for a UI regression matrix. Mount each `localizationStressCases` entry with its
|
|
158
|
+
`localizationStressAttributes`, render every `pluralStressCounts` value, and
|
|
159
|
+
exercise each `visualAccessibilityStressScenarios` media query in the
|
|
160
|
+
application's own browser harness. The fixtures include an expanded pseudo
|
|
161
|
+
locale, an RTL string with a bidi-isolated identifier, and explicit forced
|
|
162
|
+
colors, high-contrast, and reduced-motion checks. They deliberately do not
|
|
163
|
+
prescribe application styling or replace real localized content.
|
|
68
164
|
|
|
69
|
-
|
|
165
|
+
```ts
|
|
166
|
+
import {
|
|
167
|
+
localizationStressCases,
|
|
168
|
+
pluralStressCounts,
|
|
169
|
+
visualAccessibilityStressScenarios,
|
|
170
|
+
} from "@runic-artifex/svelte/translations/testing";
|
|
171
|
+
|
|
172
|
+
for (const stressCase of localizationStressCases) {
|
|
173
|
+
// Mount this exact text in your app's visual test with lang/dir attributes.
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (const count of pluralStressCounts) {
|
|
177
|
+
// Render a real pluralized message for each count.
|
|
178
|
+
}
|
|
179
|
+
```
|
|
70
180
|
|
|
71
|
-
|
|
72
|
-
layout/component, and consume the same context below that boundary. State uses
|
|
73
|
-
Svelte 5 runes and immutable snapshots use `$state.raw`.
|
|
181
|
+
## Hosted browser bootstrap
|
|
74
182
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
183
|
+
For the hosted SSR profile, render the server-provided bootstrap fingerprint in
|
|
184
|
+
`<meta name="runic-hosted-bootstrap">`, then call
|
|
185
|
+
`startRunicHostedBridgeAfterBootstrap` inside `onMount`. A matching marker starts
|
|
186
|
+
the supplied bridge; a mismatch records a fail-closed hydration state and leaves
|
|
187
|
+
the bridge stopped. The marker guards render consistency only—it is not an
|
|
188
|
+
authorization credential.
|
|
189
|
+
|
|
190
|
+
```svelte
|
|
191
|
+
<script lang="ts">
|
|
192
|
+
import { onMount } from "svelte";
|
|
193
|
+
import { startRunicHostedBridgeAfterBootstrap } from "@runic-artifex/svelte/hosted";
|
|
78
194
|
|
|
79
|
-
|
|
80
|
-
runtime. It owns only Svelte lifecycle and projection concerns.
|
|
195
|
+
let { data, bridge } = $props();
|
|
81
196
|
|
|
82
|
-
|
|
197
|
+
onMount(() => {
|
|
198
|
+
if (!startRunicHostedBridgeAfterBootstrap(data.bootstrap, bridge)) return;
|
|
199
|
+
return () => { void bridge.dispose(); };
|
|
200
|
+
});
|
|
201
|
+
</script>
|
|
83
202
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
203
|
+
<svelte:head>
|
|
204
|
+
<meta name="runic-hosted-bootstrap" content={data.bootstrap.fingerprint} />
|
|
205
|
+
</svelte:head>
|
|
206
|
+
```
|
|
88
207
|
|
|
89
|
-
The
|
|
208
|
+
This does not create a new transport or authorization path. The existing bridge
|
|
209
|
+
remains controller-only; the W20 local FrameChannel/WebSocket boundary is not a
|
|
210
|
+
hosted service route.
|
|
90
211
|
|
|
91
|
-
|
|
92
|
-
lifecycle, and event Stream programs;
|
|
93
|
-
- `run` and `runExit`, which execute a composed program in the controller's
|
|
94
|
-
existing `ManagedRuntime`;
|
|
95
|
-
- `createAction`, which projects one latest-wins Fiber into Svelte-native
|
|
96
|
-
`status`, `value`, `error`, `cause`, and `exit` state.
|
|
212
|
+
## Optional: Effect workflows
|
|
97
213
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
214
|
+
If your controller exposes the Effect-aware Application Bridge contract, use
|
|
215
|
+
`createEffectSvelteApplicationBridge`. It retains the ordinary Promise methods
|
|
216
|
+
and exposes `effects`, `run`, `runExit`, and `createAction` over the controller's
|
|
217
|
+
existing managed runtime—no renderer-owned Effect runtime is created.
|
|
102
218
|
|
|
103
219
|
```ts
|
|
104
220
|
import { Effect } from "effect";
|
|
105
221
|
import { createEffectSvelteApplicationBridge } from "@runic-artifex/svelte";
|
|
106
222
|
|
|
107
223
|
const bridge = createEffectSvelteApplicationBridge(controller);
|
|
108
|
-
const
|
|
109
|
-
effects.dispatch(
|
|
110
|
-
Effect.retry({ times: 2 }),
|
|
111
|
-
)
|
|
224
|
+
const refresh = bridge.createAction((_input, effects) =>
|
|
225
|
+
effects.dispatch({ _tag: "Refresh" }).pipe(Effect.asVoid),
|
|
112
226
|
);
|
|
113
227
|
|
|
114
|
-
|
|
115
|
-
void install.run({ _tag: "StartInstallation", selectionId });
|
|
116
|
-
|
|
117
|
-
// Simple calls stay simple.
|
|
118
|
-
await bridge.dispatch({ _tag: "Navigate", target: "Summary" });
|
|
228
|
+
void refresh.run(undefined);
|
|
119
229
|
```
|
|
120
230
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
231
|
+
An action is latest-wins: beginning another invocation interrupts its preceding
|
|
232
|
+
Fiber, and disposing the bridge interrupts its actions. That interruption only
|
|
233
|
+
stops frontend work; use `cancel(operationId)` when the host operation itself
|
|
234
|
+
must be cancelled.
|
|
235
|
+
|
|
236
|
+
## Links, status, and support
|
|
124
237
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
238
|
+
- [Application Bridge guide](https://docs.runic-artifex.eu/application-bridge)
|
|
239
|
+
- [Package catalog and release status](https://docs.runic-artifex.eu/packages)
|
|
240
|
+
- [SvelteKit reference application](https://github.com/Runic-Artifex/runic-sdk/tree/main/apps/translations-editor/Frontend)
|
|
241
|
+
- [Issues and support](https://github.com/Runic-Artifex/runic-sdk/issues)
|
|
242
|
+
- [MIT License](https://github.com/Runic-Artifex/runic-sdk/blob/main/LICENSE)
|
package/dist/bridge.svelte.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ApplicationBridgeController, ApplicationBridgeStatus, SvelteApplicationBridgeOptions } from "./types.js";
|
|
2
|
-
export declare class SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
2
|
+
export declare class SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot> {
|
|
3
3
|
#private;
|
|
4
4
|
snapshot: Snapshot | undefined;
|
|
5
5
|
lastEvent: HostEvent | undefined;
|
|
6
|
-
error:
|
|
6
|
+
error: import("@runic-artifex/application-bridge").TransportUnavailable | import("@runic-artifex/application-bridge").TransportClosed | import("@runic-artifex/application-bridge").ProtocolVersionMismatch | import("@runic-artifex/application-bridge").ProtocolDecodeError | import("@runic-artifex/application-bridge").CommandRejected | import("@runic-artifex/application-bridge").StaleRevision | import("@runic-artifex/application-bridge").OperationFailed | import("@runic-artifex/application-bridge").OperationCancelled | import("@runic-artifex/application-bridge").OperationTimedOut | undefined;
|
|
7
7
|
status: ApplicationBridgeStatus;
|
|
8
|
-
constructor(controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot
|
|
8
|
+
constructor(controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot>, options?: SvelteApplicationBridgeOptions<HostEvent, Snapshot>);
|
|
9
9
|
start(): Promise<Snapshot>;
|
|
10
10
|
dispatch(command: Command): Promise<Receipt>;
|
|
11
11
|
cancel(operationId: string): Promise<void>;
|
|
@@ -15,4 +15,4 @@ export declare class SvelteApplicationBridge<Command, Receipt, HostEvent, Snapsh
|
|
|
15
15
|
clearError(): void;
|
|
16
16
|
dispose(): Promise<void>;
|
|
17
17
|
}
|
|
18
|
-
export declare function createSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
18
|
+
export declare function createSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>(controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot>, options?: SvelteApplicationBridgeOptions<HostEvent, Snapshot>): SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>;
|
package/dist/bridge.svelte.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// Keep the Application Bridge peer optional for translations-only applications,
|
|
2
|
+
// while making bridge entry points fail with an actionable error when selected.
|
|
3
|
+
await import("@runic-artifex/application-bridge").catch(() => {
|
|
4
|
+
throw new Error("@runic-artifex/svelte bridge support requires @runic-artifex/application-bridge. "
|
|
5
|
+
+ "Install a compatible preview with `npm install @runic-artifex/application-bridge@preview`.");
|
|
6
|
+
});
|
|
1
7
|
export class SvelteApplicationBridge {
|
|
2
8
|
snapshot = $state.raw(undefined);
|
|
3
9
|
lastEvent = $state.raw(undefined);
|
|
@@ -9,6 +15,8 @@ export class SvelteApplicationBridge {
|
|
|
9
15
|
#inspectSnapshot;
|
|
10
16
|
#unsubscribe;
|
|
11
17
|
#start;
|
|
18
|
+
#dispose;
|
|
19
|
+
#disposed = false;
|
|
12
20
|
constructor(controller, options = {}) {
|
|
13
21
|
this.#controller = controller;
|
|
14
22
|
this.#reduce = options.reduce;
|
|
@@ -16,95 +24,124 @@ export class SvelteApplicationBridge {
|
|
|
16
24
|
this.#inspectSnapshot = options.inspectSnapshot;
|
|
17
25
|
}
|
|
18
26
|
start() {
|
|
19
|
-
if (this
|
|
20
|
-
return Promise.reject(
|
|
27
|
+
if (this.#disposed)
|
|
28
|
+
return Promise.reject(disposedError());
|
|
21
29
|
if (this.#start)
|
|
22
30
|
return this.#start;
|
|
23
31
|
this.status = "connecting";
|
|
24
32
|
this.error = undefined;
|
|
25
33
|
this.#reportConnection("connecting");
|
|
26
34
|
this.#unsubscribe ??= this.#controller.subscribe((event) => {
|
|
35
|
+
if (this.#disposed)
|
|
36
|
+
return;
|
|
27
37
|
this.lastEvent = event;
|
|
28
38
|
this.snapshot = this.#reduce?.(this.snapshot, event) ?? this.snapshot;
|
|
29
39
|
this.#observer?.trace({ kind: "event", label: tagOf(event) });
|
|
30
40
|
this.#reportConnection("connected");
|
|
31
|
-
}, (failure) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.snapshot = snapshot;
|
|
35
|
-
this.status = "connected";
|
|
36
|
-
this.#reportSnapshot(snapshot, "connected");
|
|
37
|
-
await this.#controller.uiReady();
|
|
38
|
-
await this.#controller.uiRendered();
|
|
39
|
-
this.#observer?.trace({ kind: "connection", label: "ui-rendered" });
|
|
40
|
-
return snapshot;
|
|
41
|
-
})
|
|
42
|
-
.catch((failure) => {
|
|
43
|
-
this.#start = undefined;
|
|
44
|
-
this.#fail(failure);
|
|
45
|
-
throw failure;
|
|
41
|
+
}, (failure) => {
|
|
42
|
+
if (!this.#disposed)
|
|
43
|
+
this.#fail(failure);
|
|
46
44
|
});
|
|
45
|
+
this.#start = this.#startController();
|
|
47
46
|
return this.#start;
|
|
48
47
|
}
|
|
49
48
|
async dispatch(command) {
|
|
49
|
+
this.#assertActive();
|
|
50
50
|
this.#observer?.trace({ kind: "command", label: tagOf(command) });
|
|
51
51
|
try {
|
|
52
52
|
const receipt = await this.#controller.dispatch(command);
|
|
53
|
+
this.#assertActive();
|
|
53
54
|
this.#observer?.trace({ kind: "receipt", label: tagOf(receipt) });
|
|
54
55
|
return receipt;
|
|
55
56
|
}
|
|
56
57
|
catch (failure) {
|
|
58
|
+
if (this.#disposed)
|
|
59
|
+
throw disposedError();
|
|
57
60
|
this.#failUnknown(failure);
|
|
58
61
|
throw failure;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
async cancel(operationId) {
|
|
65
|
+
this.#assertActive();
|
|
62
66
|
this.#observer?.trace({ kind: "operation", label: "CancelOperation", detail: { operationId } });
|
|
63
67
|
try {
|
|
64
68
|
await this.#controller.cancel(operationId);
|
|
69
|
+
this.#assertActive();
|
|
65
70
|
}
|
|
66
71
|
catch (failure) {
|
|
72
|
+
if (this.#disposed)
|
|
73
|
+
throw disposedError();
|
|
67
74
|
this.#failUnknown(failure);
|
|
68
75
|
throw failure;
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
async reconnect() {
|
|
79
|
+
this.#assertActive();
|
|
72
80
|
this.status = "reconnecting";
|
|
73
81
|
this.error = undefined;
|
|
74
82
|
this.#reportConnection("connecting");
|
|
75
83
|
try {
|
|
76
84
|
const snapshot = await this.#controller.reconnect();
|
|
85
|
+
this.#assertActive();
|
|
77
86
|
this.snapshot = snapshot;
|
|
78
87
|
this.status = "connected";
|
|
79
88
|
this.#reportSnapshot(snapshot, "connected");
|
|
80
89
|
return snapshot;
|
|
81
90
|
}
|
|
82
91
|
catch (failure) {
|
|
92
|
+
if (this.#disposed)
|
|
93
|
+
throw disposedError();
|
|
83
94
|
this.#failUnknown(failure);
|
|
84
95
|
throw failure;
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
|
-
uiReady() {
|
|
88
|
-
|
|
98
|
+
async uiReady() {
|
|
99
|
+
this.#assertActive();
|
|
100
|
+
try {
|
|
101
|
+
await this.#controller.uiReady();
|
|
102
|
+
this.#assertActive();
|
|
103
|
+
}
|
|
104
|
+
catch (failure) {
|
|
105
|
+
if (this.#disposed)
|
|
106
|
+
throw disposedError();
|
|
107
|
+
this.#failUnknown(failure);
|
|
108
|
+
throw failure;
|
|
109
|
+
}
|
|
89
110
|
}
|
|
90
|
-
uiRendered() {
|
|
91
|
-
|
|
111
|
+
async uiRendered() {
|
|
112
|
+
this.#assertActive();
|
|
113
|
+
try {
|
|
114
|
+
await this.#controller.uiRendered();
|
|
115
|
+
this.#assertActive();
|
|
116
|
+
}
|
|
117
|
+
catch (failure) {
|
|
118
|
+
if (this.#disposed)
|
|
119
|
+
throw disposedError();
|
|
120
|
+
this.#failUnknown(failure);
|
|
121
|
+
throw failure;
|
|
122
|
+
}
|
|
92
123
|
}
|
|
93
124
|
clearError() {
|
|
125
|
+
if (this.#disposed)
|
|
126
|
+
return;
|
|
94
127
|
this.error = undefined;
|
|
95
128
|
if (this.status === "error")
|
|
96
129
|
this.status = this.snapshot === undefined ? "idle" : "connected";
|
|
97
130
|
}
|
|
98
131
|
async dispose() {
|
|
99
|
-
if (this
|
|
100
|
-
return;
|
|
132
|
+
if (this.#dispose)
|
|
133
|
+
return this.#dispose;
|
|
134
|
+
this.#disposed = true;
|
|
135
|
+
this.status = "disposed";
|
|
101
136
|
this.#unsubscribe?.();
|
|
102
137
|
this.#unsubscribe = undefined;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.#
|
|
138
|
+
this.#dispose = Promise.resolve()
|
|
139
|
+
.finally(() => this.#reportConnection("closed"));
|
|
140
|
+
return this.#dispose;
|
|
106
141
|
}
|
|
107
142
|
#fail(failure) {
|
|
143
|
+
if (this.#disposed)
|
|
144
|
+
return;
|
|
108
145
|
this.error = failure;
|
|
109
146
|
this.status = "error";
|
|
110
147
|
this.#observer?.trace({ kind: "error", label: errorLabel(failure) });
|
|
@@ -114,6 +151,32 @@ export class SvelteApplicationBridge {
|
|
|
114
151
|
// Promise does not encode its rejection type; the controller contract does.
|
|
115
152
|
this.#fail(failure);
|
|
116
153
|
}
|
|
154
|
+
async #startController() {
|
|
155
|
+
try {
|
|
156
|
+
const snapshot = await this.#controller.initialize();
|
|
157
|
+
this.#assertActive();
|
|
158
|
+
this.snapshot = snapshot;
|
|
159
|
+
this.status = "connected";
|
|
160
|
+
this.#reportSnapshot(snapshot, "connected");
|
|
161
|
+
await this.#controller.uiReady();
|
|
162
|
+
this.#assertActive();
|
|
163
|
+
await this.#controller.uiRendered();
|
|
164
|
+
this.#assertActive();
|
|
165
|
+
this.#observer?.trace({ kind: "connection", label: "ui-rendered" });
|
|
166
|
+
return snapshot;
|
|
167
|
+
}
|
|
168
|
+
catch (failure) {
|
|
169
|
+
if (this.#disposed)
|
|
170
|
+
throw disposedError();
|
|
171
|
+
this.#start = undefined;
|
|
172
|
+
this.#failUnknown(failure);
|
|
173
|
+
throw failure;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
#assertActive() {
|
|
177
|
+
if (this.#disposed)
|
|
178
|
+
throw disposedError();
|
|
179
|
+
}
|
|
117
180
|
#reportSnapshot(snapshot, state) {
|
|
118
181
|
const inspected = this.#inspectSnapshot?.(snapshot) ?? {};
|
|
119
182
|
this.#observer?.state({
|
|
@@ -145,3 +208,6 @@ function errorLabel(failure) {
|
|
|
145
208
|
return tagOf(failure);
|
|
146
209
|
return failure instanceof Error ? failure.name.slice(0, 128) : "ApplicationBridgeError";
|
|
147
210
|
}
|
|
211
|
+
function disposedError() {
|
|
212
|
+
return new Error("The Svelte Application Bridge is disposed.");
|
|
213
|
+
}
|
package/dist/context.svelte.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SvelteApplicationBridge } from "./bridge.svelte.js";
|
|
2
|
-
export interface ApplicationBridgeContext<Command, Receipt, HostEvent, Snapshot
|
|
3
|
-
provide(bridge: SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
2
|
+
export interface ApplicationBridgeContext<Command, Receipt, HostEvent, Snapshot> {
|
|
3
|
+
provide(bridge: SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>, options?: Readonly<{
|
|
4
4
|
start?: boolean;
|
|
5
5
|
dispose?: boolean;
|
|
6
|
-
}>): SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
7
|
-
use(): SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
6
|
+
}>): SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>;
|
|
7
|
+
use(): SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>;
|
|
8
8
|
}
|
|
9
|
-
export declare function createApplicationBridgeContext<Command, Receipt, HostEvent, Snapshot
|
|
9
|
+
export declare function createApplicationBridgeContext<Command, Receipt, HostEvent, Snapshot>(): ApplicationBridgeContext<Command, Receipt, HostEvent, Snapshot>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Cause, Effect, Exit } from "effect";
|
|
2
|
-
import type { EffectActionStatus, EffectRunner } from "./types.js";
|
|
2
|
+
import type { ApplicationBridgeService, EffectActionStatus, EffectRunner } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Projects one latest-wins Effect workflow into Svelte-native reactive state.
|
|
5
5
|
* The supplied runner owns the Fiber; this class never creates an Effect runtime.
|
|
6
6
|
*/
|
|
7
|
-
export declare class SvelteEffectAction<Input, Success, Failure
|
|
7
|
+
export declare class SvelteEffectAction<Input, Success, Failure> {
|
|
8
8
|
#private;
|
|
9
9
|
status: EffectActionStatus;
|
|
10
10
|
value: Success | undefined;
|
|
11
11
|
error: Failure | undefined;
|
|
12
12
|
cause: Cause.Cause<Failure> | undefined;
|
|
13
13
|
exit: Exit.Exit<Success, Failure> | undefined;
|
|
14
|
-
constructor(runner: EffectRunner
|
|
14
|
+
constructor(runner: EffectRunner, program: (input: Input) => Effect.Effect<Success, Failure, ApplicationBridgeService>, onDispose?: () => void);
|
|
15
15
|
get running(): boolean;
|
|
16
16
|
/** Runs the workflow, interrupting an older invocation owned by this action. */
|
|
17
17
|
run(input: Input): Promise<Exit.Exit<Success, Failure>>;
|
|
@@ -93,7 +93,7 @@ export class SvelteEffectAction {
|
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
this.cause = exit.cause;
|
|
96
|
-
this.error = Option.getOrUndefined(Cause.
|
|
97
|
-
this.status = Cause.
|
|
96
|
+
this.error = Option.getOrUndefined(Cause.findErrorOption(exit.cause));
|
|
97
|
+
this.status = Cause.hasInterruptsOnly(exit.cause) ? "interrupted" : "failure";
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Effect, Exit } from "effect";
|
|
2
2
|
import { SvelteApplicationBridge } from "./bridge.svelte.js";
|
|
3
3
|
import { SvelteEffectAction } from "./effect-action.svelte.js";
|
|
4
|
-
import type { ApplicationBridgeEffects,
|
|
4
|
+
import type { ApplicationBridgeController, ApplicationBridgeEffects, ApplicationBridgeService, SvelteApplicationBridgeOptions } from "./types.js";
|
|
5
5
|
/** Opt-in Effect surface backed by the Application Bridge's owned runtime. */
|
|
6
|
-
export declare class EffectSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
6
|
+
export declare class EffectSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot> extends SvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot> {
|
|
7
7
|
#private;
|
|
8
|
-
readonly effects: ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot
|
|
9
|
-
constructor(controller:
|
|
10
|
-
run<A, E>(program: Effect.Effect<A, E,
|
|
11
|
-
runExit<A, E>(program: Effect.Effect<A, E,
|
|
8
|
+
readonly effects: ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot>;
|
|
9
|
+
constructor(controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot>, options?: SvelteApplicationBridgeOptions<HostEvent, Snapshot>);
|
|
10
|
+
run<A, E>(program: Effect.Effect<A, E, ApplicationBridgeService>): Promise<A>;
|
|
11
|
+
runExit<A, E>(program: Effect.Effect<A, E, ApplicationBridgeService>): Promise<Exit.Exit<A, E>>;
|
|
12
12
|
/**
|
|
13
13
|
* Creates a latest-wins action whose Fiber is interrupted when superseded or
|
|
14
14
|
* when this application bridge is disposed.
|
|
15
15
|
*/
|
|
16
|
-
createAction<Input, Success, Error>(program: (input: Input, effects: ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot
|
|
16
|
+
createAction<Input, Success, Error>(program: (input: Input, effects: ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot>) => Effect.Effect<Success, Error, ApplicationBridgeService>): SvelteEffectAction<Input, Success, Error>;
|
|
17
17
|
dispose(): Promise<void>;
|
|
18
18
|
}
|
|
19
|
-
export declare function createEffectSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot
|
|
19
|
+
export declare function createEffectSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>(controller: ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot>, options?: SvelteApplicationBridgeOptions<HostEvent, Snapshot>): EffectSvelteApplicationBridge<Command, Receipt, HostEvent, Snapshot>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface RunicHostedBrowserBootstrap {
|
|
2
|
+
readonly schema: "runic.hosted-bootstrap/1";
|
|
3
|
+
readonly fingerprint: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RunicHostedBrowserBridge {
|
|
6
|
+
start(): Promise<unknown>;
|
|
7
|
+
dispose(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Starts a browser bridge only after the SSR bootstrap marker has been checked.
|
|
11
|
+
* The marker is a hydration-consistency guard, not an authorization credential.
|
|
12
|
+
*/
|
|
13
|
+
export declare function startRunicHostedBridgeAfterBootstrap(bootstrap: RunicHostedBrowserBootstrap, bridge: RunicHostedBrowserBridge): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starts a browser bridge only after the SSR bootstrap marker has been checked.
|
|
3
|
+
* The marker is a hydration-consistency guard, not an authorization credential.
|
|
4
|
+
*/
|
|
5
|
+
export function startRunicHostedBridgeAfterBootstrap(bootstrap, bridge) {
|
|
6
|
+
if (bootstrap?.schema !== "runic.hosted-bootstrap/1" || !isFingerprint(bootstrap.fingerprint)) {
|
|
7
|
+
throw new TypeError("The Runic hosted browser bootstrap is malformed.");
|
|
8
|
+
}
|
|
9
|
+
if (!bridge || typeof bridge.start !== "function" || typeof bridge.dispose !== "function") {
|
|
10
|
+
throw new TypeError("The Runic hosted browser bridge is malformed.");
|
|
11
|
+
}
|
|
12
|
+
const marker = document.querySelector('meta[name="runic-hosted-bootstrap"]');
|
|
13
|
+
if (!(marker instanceof HTMLMetaElement) || marker.content !== bootstrap.fingerprint) {
|
|
14
|
+
document.documentElement.dataset.runicHostedHydration = "mismatch";
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
delete document.documentElement.dataset.runicHostedHydration;
|
|
18
|
+
void bridge.start().catch(() => undefined);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function isFingerprint(value) {
|
|
22
|
+
return typeof value === "string" && /^runic-hosted-[a-f0-9]{8}$/.test(value);
|
|
23
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, framework-neutral presentation cases for exercising a localized
|
|
3
|
+
* Runic application. They intentionally contain no renderer, catalog, or
|
|
4
|
+
* application state: a consumer mounts these values in its own UI tests.
|
|
5
|
+
*/
|
|
6
|
+
export type LocalizationStressDirection = "ltr" | "rtl";
|
|
7
|
+
export interface LocalizationStressCase {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly locale: string;
|
|
10
|
+
readonly direction: LocalizationStressDirection;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly checks: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export interface VisualAccessibilityStressScenario {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly mediaQuery: string;
|
|
17
|
+
readonly checks: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const pluralStressCounts: readonly [0, 1, 2, 5, 11, 21, 101, 1000];
|
|
20
|
+
/** Wraps a value in a first-strong isolate so mixed-direction identifiers stay ordered. */
|
|
21
|
+
export declare function isolateBidi(text: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Produces an intentionally expanded pseudo-locale while leaving `{placeholders}`
|
|
24
|
+
* byte-for-byte intact. Use it to expose clipped labels and hard-coded strings.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pseudoLocalize(text: string): string;
|
|
27
|
+
/** Attributes to apply when mounting a case in DOM-oriented test harnesses. */
|
|
28
|
+
export declare function localizationStressAttributes(stressCase: LocalizationStressCase): Readonly<{
|
|
29
|
+
lang: string;
|
|
30
|
+
dir: LocalizationStressDirection;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const localizationStressCases: readonly LocalizationStressCase[];
|
|
33
|
+
/**
|
|
34
|
+
* These browser media queries are the canonical minimum visual regression
|
|
35
|
+
* matrix. Consumers assert the named properties in their own design system;
|
|
36
|
+
* this package cannot author their colors or animation policy for them.
|
|
37
|
+
*/
|
|
38
|
+
export declare const visualAccessibilityStressScenarios: readonly VisualAccessibilityStressScenario[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const pluralStressCounts = [0, 1, 2, 5, 11, 21, 101, 1000];
|
|
2
|
+
const pseudoCharacters = {
|
|
3
|
+
A: "ÅÅ", B: "ß", C: "Ç", D: "Ð", E: "ÉÉ", F: "Ƒ", G: "Ğ", H: "Ħ", I: "ÏÏ", J: "Ĵ", K: "Ķ", L: "Ŀ", M: "Ḿ", N: "Ń", O: "ØØ", P: "Þ", Q: "Ǫ", R: "Ŕ", S: "Š", T: "Ŧ", U: "ÜÜ", V: "Ṽ", W: "Ŵ", X: "Ẋ", Y: "Ý", Z: "Ž",
|
|
4
|
+
a: "áá", b: "ƀ", c: "ç", d: "đ", e: "éé", f: "ƒ", g: "ğ", h: "ħ", i: "ïï", j: "ĵ", k: "ķ", l: "ŀ", m: "ḿ", n: "ń", o: "øø", p: "þ", q: "ǫ", r: "ŕ", s: "š", t: "ŧ", u: "üü", v: "ṽ", w: "ŵ", x: "ẋ", y: "ý", z: "ž",
|
|
5
|
+
};
|
|
6
|
+
/** Wraps a value in a first-strong isolate so mixed-direction identifiers stay ordered. */
|
|
7
|
+
export function isolateBidi(text) {
|
|
8
|
+
return `\u2068${text}\u2069`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Produces an intentionally expanded pseudo-locale while leaving `{placeholders}`
|
|
12
|
+
* byte-for-byte intact. Use it to expose clipped labels and hard-coded strings.
|
|
13
|
+
*/
|
|
14
|
+
export function pseudoLocalize(text) {
|
|
15
|
+
return `[${text.split(/(\{[^{}]*\})/u).map((part) => part.startsWith("{") && part.endsWith("}") ? part : pseudoLocalizeLiteral(part)).join("")}~]`;
|
|
16
|
+
}
|
|
17
|
+
/** Attributes to apply when mounting a case in DOM-oriented test harnesses. */
|
|
18
|
+
export function localizationStressAttributes(stressCase) {
|
|
19
|
+
return { lang: stressCase.locale, dir: stressCase.direction };
|
|
20
|
+
}
|
|
21
|
+
export const localizationStressCases = [
|
|
22
|
+
{
|
|
23
|
+
id: "pseudo-locale-long-action",
|
|
24
|
+
locale: "en-XA",
|
|
25
|
+
direction: "ltr",
|
|
26
|
+
text: pseudoLocalize("Synchronize the selected documents before you close this window."),
|
|
27
|
+
checks: ["text wraps without clipping", "actions remain identifiable", "no literal bypasses localization"],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "plural-boundaries",
|
|
31
|
+
locale: "en-XA",
|
|
32
|
+
direction: "ltr",
|
|
33
|
+
text: pseudoLocalize("{count} selected documents still need your review."),
|
|
34
|
+
checks: ["render every pluralStressCounts value", "plural output stays readable at extreme counts"],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "rtl-mixed-identifier",
|
|
38
|
+
locale: "ar-XB",
|
|
39
|
+
direction: "rtl",
|
|
40
|
+
text: `تم حفظ ${isolateBidi("Setup-2026-08-30.json")} بنجاح.`,
|
|
41
|
+
checks: ["mixed-direction identifiers retain order", "layout mirrors without changing semantic order"],
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* These browser media queries are the canonical minimum visual regression
|
|
46
|
+
* matrix. Consumers assert the named properties in their own design system;
|
|
47
|
+
* this package cannot author their colors or animation policy for them.
|
|
48
|
+
*/
|
|
49
|
+
export const visualAccessibilityStressScenarios = [
|
|
50
|
+
{
|
|
51
|
+
id: "forced-colors",
|
|
52
|
+
mediaQuery: "(forced-colors: active)",
|
|
53
|
+
checks: ["controls remain visible", "focus indicator remains visible", "meaning is not color-only"],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "high-contrast",
|
|
57
|
+
mediaQuery: "(prefers-contrast: more)",
|
|
58
|
+
checks: ["text and control boundaries remain distinguishable", "status is not color-only"],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "reduced-motion",
|
|
62
|
+
mediaQuery: "(prefers-reduced-motion: reduce)",
|
|
63
|
+
checks: ["non-essential animation is removed or shortened", "state changes remain understandable"],
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
function pseudoLocalizeLiteral(text) {
|
|
67
|
+
return text.replace(/[A-Za-z]/gu, (character) => pseudoCharacters[character] ?? character);
|
|
68
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
uiRendered(): Promise<void>;
|
|
9
|
-
subscribe(onEvent: (event: HostEvent) => void, onError?: (error: Failure) => void): () => void;
|
|
10
|
-
dispose(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export interface ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot, Failure, Requirements> {
|
|
13
|
-
readonly initialize: Effect.Effect<Snapshot, Failure, Requirements>;
|
|
14
|
-
readonly dispatch: (command: Command) => Effect.Effect<Receipt, Failure, Requirements>;
|
|
15
|
-
readonly cancel: (operationId: string) => Effect.Effect<void, Failure, Requirements>;
|
|
16
|
-
readonly reconnect: Effect.Effect<Snapshot, Failure, Requirements>;
|
|
17
|
-
readonly uiReady: Effect.Effect<void, Failure, Requirements>;
|
|
18
|
-
readonly uiRendered: Effect.Effect<void, Failure, Requirements>;
|
|
19
|
-
readonly events: Stream.Stream<HostEvent, Failure, Requirements>;
|
|
20
|
-
}
|
|
21
|
-
export interface EffectRunner<Requirements> {
|
|
22
|
-
run<A, E>(program: Effect.Effect<A, E, Requirements>): Promise<A>;
|
|
23
|
-
runExit<A, E>(program: Effect.Effect<A, E, Requirements>): Promise<Exit.Exit<A, E>>;
|
|
24
|
-
fork<A, E>(program: Effect.Effect<A, E, Requirements>): Fiber.RuntimeFiber<A, E>;
|
|
25
|
-
await<A, E>(fiber: Fiber.RuntimeFiber<A, E>): Promise<Exit.Exit<A, E>>;
|
|
26
|
-
interrupt<A, E>(fiber: Fiber.RuntimeFiber<A, E>): Promise<Exit.Exit<A, E>>;
|
|
27
|
-
}
|
|
28
|
-
export interface EffectApplicationBridgeController<Command, Receipt, HostEvent, Snapshot, Failure, Requirements> extends ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot, Failure>, EffectRunner<Requirements> {
|
|
29
|
-
readonly effects: ApplicationBridgeEffects<Command, Receipt, HostEvent, Snapshot, Failure, Requirements>;
|
|
30
|
-
}
|
|
1
|
+
import type { ApplicationBridgeController, ApplicationBridgeEffects, ApplicationBridgeService, BridgeError } from "@runic-artifex/application-bridge";
|
|
2
|
+
/** Public Application Bridge contracts, re-exported without a renderer-owned copy. */
|
|
3
|
+
export type { ApplicationBridgeController, ApplicationBridgeEffects, ApplicationBridgeService, BridgeError, };
|
|
4
|
+
/** @deprecated Application Bridge controllers already expose the Effect surface. */
|
|
5
|
+
export type EffectApplicationBridgeController<Command, Receipt, HostEvent, Snapshot> = ApplicationBridgeController<Command, Receipt, HostEvent, Snapshot>;
|
|
6
|
+
/** @deprecated Use ApplicationBridgeController directly. */
|
|
7
|
+
export type EffectRunner = Pick<ApplicationBridgeController<unknown, unknown, unknown, unknown>, "run" | "runExit" | "fork" | "await" | "interrupt">;
|
|
31
8
|
export type ApplicationBridgeStatus = "idle" | "connecting" | "connected" | "reconnecting" | "error" | "disposed";
|
|
32
9
|
export type EffectActionStatus = "idle" | "running" | "success" | "failure" | "interrupted" | "disposed";
|
|
10
|
+
/**
|
|
11
|
+
* Optional callbacks emitted by the Svelte projection. This deliberately stays
|
|
12
|
+
* independent of any Vite implementation; use the `/vite` entry point to
|
|
13
|
+
* connect it to Runic Toolkit DevTools.
|
|
14
|
+
*/
|
|
33
15
|
export interface ApplicationBridgeObserver {
|
|
34
|
-
state(state: Readonly<
|
|
16
|
+
state(state: Readonly<{
|
|
17
|
+
connection?: Readonly<{
|
|
18
|
+
state?: "connecting" | "connected" | "disconnected" | "closed";
|
|
19
|
+
transport?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
revision?: number;
|
|
22
|
+
sequence?: number;
|
|
23
|
+
}>;
|
|
24
|
+
}>): void;
|
|
35
25
|
trace(entry: Readonly<{
|
|
36
26
|
kind: "command" | "receipt" | "event" | "operation" | "connection" | "error";
|
|
37
27
|
label: string;
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RunicDevtoolsObserver } from "@runic-artifex/vite-plugin-runic/client";
|
|
2
|
+
export type { RunicDevtoolsObserver } from "@runic-artifex/vite-plugin-runic/client";
|
|
3
|
+
/** Connects a Svelte bridge projection to the optional Runic Vite client. */
|
|
4
|
+
export declare function createViteApplicationBridgeObserver(): RunicDevtoolsObserver;
|
|
5
|
+
/** Preserves one application-owned resource across a Vite hot replacement. */
|
|
6
|
+
export declare function preserveViteHmrResource<T>(key: string, create: () => T): T;
|
|
7
|
+
/** Explicitly releases a resource preserved for Vite hot replacement. */
|
|
8
|
+
export declare function disposeViteHmrResource(key: string, dispose?: (resource: unknown) => void | Promise<void>): Promise<void>;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRunicDevtoolsObserver, disposeRunicHmrResource, preserveRunicHmrResource, } from "@runic-artifex/vite-plugin-runic/client";
|
|
2
|
+
/** Connects a Svelte bridge projection to the optional Runic Vite client. */
|
|
3
|
+
export function createViteApplicationBridgeObserver() {
|
|
4
|
+
return createRunicDevtoolsObserver();
|
|
5
|
+
}
|
|
6
|
+
/** Preserves one application-owned resource across a Vite hot replacement. */
|
|
7
|
+
export function preserveViteHmrResource(key, create) {
|
|
8
|
+
return preserveRunicHmrResource(key, create);
|
|
9
|
+
}
|
|
10
|
+
/** Explicitly releases a resource preserved for Vite hot replacement. */
|
|
11
|
+
export function disposeViteHmrResource(key, dispose) {
|
|
12
|
+
return disposeRunicHmrResource(key, dispose);
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-preview.1",
|
|
4
4
|
"description": "Svelte 5 integration for the Runic Toolkit Application Bridge",
|
|
5
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/svelte#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"runic-artifex",
|
|
11
|
+
"runic-toolkit",
|
|
12
|
+
"application-bridge",
|
|
13
|
+
"svelte",
|
|
14
|
+
"svelte-5"
|
|
15
|
+
],
|
|
5
16
|
"license": "MIT",
|
|
6
17
|
"type": "module",
|
|
7
18
|
"svelte": "./dist/index.js",
|
|
@@ -16,6 +27,24 @@
|
|
|
16
27
|
"types": "./dist/translations/index.d.ts",
|
|
17
28
|
"svelte": "./dist/translations/index.js",
|
|
18
29
|
"import": "./dist/translations/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./translations/testing": {
|
|
32
|
+
"types": "./dist/translations/testing.d.ts",
|
|
33
|
+
"import": "./dist/translations/testing.js"
|
|
34
|
+
},
|
|
35
|
+
"./bridge": {
|
|
36
|
+
"types": "./dist/bridge.svelte.d.ts",
|
|
37
|
+
"svelte": "./dist/bridge.svelte.js",
|
|
38
|
+
"import": "./dist/bridge.svelte.js"
|
|
39
|
+
},
|
|
40
|
+
"./hosted": {
|
|
41
|
+
"types": "./dist/hosted.svelte.d.ts",
|
|
42
|
+
"svelte": "./dist/hosted.svelte.js",
|
|
43
|
+
"import": "./dist/hosted.svelte.js"
|
|
44
|
+
},
|
|
45
|
+
"./vite": {
|
|
46
|
+
"types": "./dist/vite.d.ts",
|
|
47
|
+
"import": "./dist/vite.js"
|
|
19
48
|
}
|
|
20
49
|
},
|
|
21
50
|
"files": [
|
|
@@ -26,27 +55,51 @@
|
|
|
26
55
|
"scripts": {
|
|
27
56
|
"build": "svelte-package -i src -o dist",
|
|
28
57
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
29
|
-
"test": "
|
|
30
|
-
"pack:check": "
|
|
58
|
+
"test": "bun run --bun build && vitest run",
|
|
59
|
+
"pack:check": "bun pm pack --dry-run"
|
|
31
60
|
},
|
|
32
61
|
"peerDependencies": {
|
|
33
|
-
"@runic-artifex/application-bridge": "
|
|
34
|
-
"
|
|
35
|
-
"
|
|
62
|
+
"@runic-artifex/application-bridge": "0.2.0-preview.1",
|
|
63
|
+
"@runic-artifex/vite-plugin-runic": "0.2.0-preview.1",
|
|
64
|
+
"effect": "4.0.0-rc.112",
|
|
65
|
+
"svelte": ">=5.46.4 <6"
|
|
36
66
|
},
|
|
37
67
|
"peerDependenciesMeta": {
|
|
38
68
|
"@runic-artifex/application-bridge": {
|
|
39
69
|
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@runic-artifex/vite-plugin-runic": {
|
|
72
|
+
"optional": true
|
|
40
73
|
}
|
|
41
74
|
},
|
|
42
75
|
"publishConfig": {
|
|
43
76
|
"access": "public",
|
|
44
|
-
"
|
|
77
|
+
"tag": "preview"
|
|
45
78
|
},
|
|
46
79
|
"repository": {
|
|
47
80
|
"type": "git",
|
|
48
|
-
"url": "git+https://github.com/Runic-Artifex/runic-
|
|
49
|
-
"directory": "packages/svelte"
|
|
81
|
+
"url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
|
|
82
|
+
"directory": "packages/web/svelte"
|
|
83
|
+
},
|
|
84
|
+
"packageManager": "bun@1.4.2",
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=24.18.0 <25"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@runic-artifex/application-bridge": "0.2.0-preview.1",
|
|
90
|
+
"@runic-artifex/vite-plugin-runic": "0.2.0-preview.1",
|
|
91
|
+
"@sveltejs/adapter-static": "3.0.10",
|
|
92
|
+
"@sveltejs/kit": "2.70.3",
|
|
93
|
+
"@sveltejs/package": "2.5.8",
|
|
94
|
+
"@sveltejs/vite-plugin-svelte": "7.3.0",
|
|
95
|
+
"@types/node": "24.13.3",
|
|
96
|
+
"effect": "4.0.0-rc.112",
|
|
97
|
+
"happy-dom": "^20.14.0",
|
|
98
|
+
"svelte": "5.57.0",
|
|
99
|
+
"svelte-check": "4.7.6",
|
|
100
|
+
"typescript": "6.0.3",
|
|
101
|
+
"vitest": "5.0.0",
|
|
102
|
+
"vite": "8.2.2"
|
|
50
103
|
},
|
|
51
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "c9d444a218cc3fdda190c02af41e91d6c53b2641"
|
|
52
105
|
}
|