@runic-artifex/svelte 0.3.0-preview.1 → 0.4.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 CHANGED
@@ -45,7 +45,7 @@ peer is absent, they report the exact `npm install
45
45
  @runic-artifex/application-bridge@preview` remediation.
46
46
 
47
47
  Use `@runic-artifex/svelte/vite` only when registering Runic Vite
48
- DevTools. It supplies the typed observer and HMR resource helpers without
48
+ DevTools. It supplies the bounded diagnostic observer and HMR resource helpers without
49
49
  making the root bridge entry depend on Vite.
50
50
 
51
51
  Create the controller with `@runic-artifex/application-bridge`, then create one
@@ -240,3 +240,23 @@ must be cancelled.
240
240
  - [SvelteKit reference application](https://github.com/Runic-Artifex/runic-sdk/tree/main/apps/translations-editor/Frontend)
241
241
  - [Issues and support](https://github.com/Runic-Artifex/runic-sdk/issues)
242
242
  - [MIT License](https://github.com/Runic-Artifex/runic-sdk/blob/main/LICENSE)
243
+
244
+ ## RMF2 inline content
245
+
246
+ The optional `@runic-artifex/svelte/inline` entry point exports `inlineFactory`
247
+ and `LocalizedInline`. Pass the factory to the catalog-generated
248
+ `createInlineRenderer`, link custom contracts with `bindMarkup`, then supply its
249
+ validated result to `<LocalizedInline nodes={nodes} custom={snippets} />`.
250
+ Custom snippets are keyed by canonical names such as `shop:badge`. A custom
251
+ binding can return its semantic node unchanged for the Svelte snippet to render.
252
+
253
+ Use application-owned link/action/icon bindings from the generated runtime.
254
+ Icons accept text or a Svelte snippet; meaningful icons need a localized
255
+ accessible name. The adapter uses ordinary anchors and buttons, and leaves
256
+ navigation and actions to those bindings. It never interprets localized text as
257
+ HTML. Keep the linked renderer and slot bindings scoped to their application or
258
+ request; SSR must not capture another request's callbacks.
259
+
260
+ `bun run test:inline-browser` exercises SSR/hydration in the locked development
261
+ shell's Chromium, including DOM identity, callback teardown, escaping and custom
262
+ badge/icon semantics. The fixture is `test/InlineHydrationFixture.svelte`.
@@ -1,5 +1,6 @@
1
1
  import { Cause, Effect, Exit } from "effect";
2
- import type { ApplicationBridgeService, EffectActionStatus, EffectRunner } from "./types.js";
2
+ import type { ApplicationBridgeController, ApplicationBridgeService, EffectActionStatus } from "./types.js";
3
+ type EffectRunner = Pick<ApplicationBridgeController<unknown, unknown, unknown, unknown>, "fork" | "await" | "interrupt">;
3
4
  /**
4
5
  * Projects one latest-wins Effect workflow into Svelte-native reactive state.
5
6
  * The supplied runner owns the Fiber; this class never creates an Effect runtime.
@@ -20,3 +21,4 @@ export declare class SvelteEffectAction<Input, Success, Failure> {
20
21
  reset(): void;
21
22
  dispose(): Promise<void>;
22
23
  }
24
+ export {};
@@ -0,0 +1,61 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { InlineNode, InlineElement, InlineSnippets } from "./types.js";
4
+ let { nodes, custom = {} }: { nodes: readonly InlineNode[]; custom?: InlineSnippets } = $props();
5
+ const iconLabels = new WeakMap<InlineElement, string>();
6
+ function snippet(name: string): Snippet<[InlineElement]> {
7
+ const render = custom[name];
8
+ if (!render) throw new TypeError(`No Svelte snippet linked for '${name}'.`);
9
+ return render;
10
+ }
11
+ function icon(value: unknown): Snippet {
12
+ if (typeof value !== "function") throw new TypeError("Svelte icon assets must be text or snippets.");
13
+ return value as Snippet;
14
+ }
15
+ function iconLabel(node: InlineElement): string | undefined {
16
+ if (node.binding?.kind !== "runic:icon" || node.binding.decorative) return undefined;
17
+ const cached = iconLabels.get(node);
18
+ if (cached !== undefined) return cached;
19
+ const label = node.binding.accessibleName?.(node.locale);
20
+ if (typeof label !== "string" || !label.trim()) throw new TypeError("Meaningful icon alternate text is empty.");
21
+ iconLabels.set(node, label);
22
+ return label;
23
+ }
24
+ </script>
25
+
26
+ {#snippet renderNodes(items: readonly InlineNode[])}
27
+ {#each items as node (node.kind === "text" ? node : node.occurrence)}
28
+ {#if node.kind === "text"}
29
+ {node.value}
30
+ {:else if node.name === "runic:strong"}
31
+ <strong data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</strong>
32
+ {:else if node.name === "runic:em"}
33
+ <em data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</em>
34
+ {:else if node.name === "runic:bold" || node.name === "runic:italic"}
35
+ <span class={{ bold: node.name === "runic:bold", italic: node.name === "runic:italic" }} data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</span>
36
+ {:else if node.name === "runic:code"}
37
+ <code data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</code>
38
+ {:else if node.name === "runic:br"}
39
+ <br data-runic-occurrence={node.occurrence} />
40
+ {:else if node.binding?.kind === "runic:link"}
41
+ <a href={node.binding.href} data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</a>
42
+ {:else if node.binding?.kind === "runic:action"}
43
+ <button type="button" onclick={node.binding.onActivate} data-runic-occurrence={node.occurrence}>{@render renderNodes(node.children)}</button>
44
+ {:else if node.binding?.kind === "runic:icon"}
45
+ <span role={node.binding.decorative ? undefined : "img"} aria-hidden={node.binding.decorative ? "true" : undefined} aria-label={iconLabel(node)} data-runic-occurrence={node.occurrence}>
46
+ {#if typeof node.binding.asset === "string"}{node.binding.asset}{:else}{@render icon(node.binding.asset)()}{/if}
47
+ </span>
48
+ {:else}
49
+ {@render snippet(node.name)(node)}
50
+ {/if}
51
+ {/each}
52
+ {/snippet}
53
+
54
+ {@render renderNodes(nodes)}
55
+
56
+ <style>
57
+ .bold { font-weight: var(--runic-inline-bold-weight, bold); }
58
+ .italic { font-style: italic; }
59
+ a { color: var(--runic-inline-link-color, LinkText); }
60
+ button { font: inherit; }
61
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { InlineNode, InlineSnippets } from "./types.js";
2
+ type $$ComponentProps = {
3
+ nodes: readonly InlineNode[];
4
+ custom?: InlineSnippets;
5
+ };
6
+ declare const LocalizedInline: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type LocalizedInline = ReturnType<typeof LocalizedInline>;
8
+ export default LocalizedInline;
@@ -0,0 +1,3 @@
1
+ export { default as LocalizedInline } from "./LocalizedInline.svelte";
2
+ export { inlineFactory } from "./types.js";
3
+ export type { InlineBinding, InlineElement, InlineNode, InlineSnippets } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { default as LocalizedInline } from "./LocalizedInline.svelte";
2
+ export { inlineFactory } from "./types.js";
@@ -0,0 +1,34 @@
1
+ import type { Snippet } from "svelte";
2
+ export type InlineBinding = Readonly<{
3
+ kind: "runic:link";
4
+ href: string;
5
+ }> | Readonly<{
6
+ kind: "runic:action";
7
+ onActivate: () => void;
8
+ }> | Readonly<{
9
+ kind: "runic:icon";
10
+ asset: unknown;
11
+ decorative: boolean;
12
+ accessibleName?: (locale: string) => string;
13
+ }>;
14
+ export interface InlineElement {
15
+ readonly name: string;
16
+ readonly children: readonly InlineNode[];
17
+ readonly options: Readonly<Record<string, string>>;
18
+ readonly binding?: InlineBinding;
19
+ readonly occurrence: string;
20
+ readonly locale: string;
21
+ readonly standalone?: boolean;
22
+ }
23
+ export type InlineNode = Readonly<{
24
+ kind: "text";
25
+ value: string;
26
+ }> | Readonly<InlineElement & {
27
+ kind: "element";
28
+ }>;
29
+ export type InlineSnippets = Readonly<Record<string, Snippet<[InlineElement]>>>;
30
+ /** Pass this factory to the catalog-generated createInlineRenderer once per application/feature. */
31
+ export declare const inlineFactory: Readonly<{
32
+ text: (value: string) => InlineNode;
33
+ element: (element: InlineElement) => InlineNode;
34
+ }>;
@@ -0,0 +1,5 @@
1
+ /** Pass this factory to the catalog-generated createInlineRenderer once per application/feature. */
2
+ export const inlineFactory = Object.freeze({
3
+ text: (value) => Object.freeze({ kind: "text", value }),
4
+ element: (element) => Object.freeze({ ...element, kind: "element" }),
5
+ });
package/dist/types.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import type { ApplicationBridgeController, ApplicationBridgeEffects, ApplicationBridgeService, BridgeError } from "@runic-artifex/application-bridge";
2
2
  /** Public Application Bridge contracts, re-exported without a renderer-owned copy. */
3
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">;
8
4
  export type ApplicationBridgeStatus = "idle" | "connecting" | "connected" | "reconnecting" | "error" | "disposed";
9
5
  export type EffectActionStatus = "idle" | "running" | "success" | "failure" | "interrupted" | "disposed";
10
6
  /**
package/dist/vite.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { RunicDevtoolsObserver } from "@runic-artifex/vite-plugin-runic/client";
2
- export type { RunicDevtoolsObserver } from "@runic-artifex/vite-plugin-runic/client";
1
+ import type { ApplicationBridgeObserver } from "./types.js";
3
2
  /** Connects a Svelte bridge projection to the optional Runic Vite client. */
4
- export declare function createViteApplicationBridgeObserver(): RunicDevtoolsObserver;
3
+ export declare function createViteApplicationBridgeObserver(): ApplicationBridgeObserver;
5
4
  /** Preserves one application-owned resource across a Vite hot replacement. */
6
5
  export declare function preserveViteHmrResource<T>(key: string, create: () => T): T;
7
6
  /** Explicitly releases a resource preserved for Vite hot replacement. */
package/dist/vite.js CHANGED
@@ -1,7 +1,33 @@
1
- import { createRunicDevtoolsObserver, disposeRunicHmrResource, preserveRunicHmrResource, } from "@runic-artifex/vite-plugin-runic/client";
1
+ import { createRunicDiagnosticReporter, disposeRunicHmrResource, preserveRunicHmrResource, reportRunicState, } from "@runic-artifex/vite-plugin-runic/client";
2
2
  /** Connects a Svelte bridge projection to the optional Runic Vite client. */
3
3
  export function createViteApplicationBridgeObserver() {
4
- return createRunicDevtoolsObserver();
4
+ const reporter = createRunicDiagnosticReporter("application-bridge");
5
+ return {
6
+ state: (state) => reportRunicState(state),
7
+ trace: (entry) => {
8
+ const detail = boundedDetail(entry.detail);
9
+ reporter.report({
10
+ kind: entry.kind,
11
+ label: entry.label,
12
+ ...(detail === undefined ? {} : { detail }),
13
+ });
14
+ },
15
+ };
16
+ }
17
+ function boundedDetail(detail) {
18
+ if (detail === undefined)
19
+ return undefined;
20
+ const result = {};
21
+ let count = 0;
22
+ for (const [key, value] of Object.entries(detail)) {
23
+ if (count === 12)
24
+ break;
25
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
26
+ result[key] = value;
27
+ count += 1;
28
+ }
29
+ }
30
+ return count === 0 ? undefined : result;
5
31
  }
6
32
  /** Preserves one application-owned resource across a Vite hot replacement. */
7
33
  export function preserveViteHmrResource(key, create) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runic-artifex/svelte",
3
- "version": "0.3.0-preview.1",
3
+ "version": "0.4.0-preview.1",
4
4
  "description": "Svelte 5 integration for the Runic Toolkit Application Bridge",
5
5
  "homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/svelte#readme",
6
6
  "bugs": {
@@ -45,6 +45,11 @@
45
45
  "./vite": {
46
46
  "types": "./dist/vite.d.ts",
47
47
  "import": "./dist/vite.js"
48
+ },
49
+ "./inline": {
50
+ "types": "./dist/inline/index.d.ts",
51
+ "svelte": "./dist/inline/index.js",
52
+ "import": "./dist/inline/index.js"
48
53
  }
49
54
  },
50
55
  "files": [
@@ -55,12 +60,13 @@
55
60
  "scripts": {
56
61
  "build": "svelte-package -i src -o dist",
57
62
  "check": "svelte-check --tsconfig ./tsconfig.json",
58
- "test": "bun run --bun build && vitest run",
59
- "pack:check": "bun pm pack --dry-run"
63
+ "test": "bun run --bun build && vitest run && node test/verify-inline-ssr.mjs",
64
+ "pack:check": "bun pm pack --dry-run",
65
+ "test:inline-browser": "node test/verify-inline-ssr.mjs && node test/verify-inline-hydration.mjs"
60
66
  },
61
67
  "peerDependencies": {
62
- "@runic-artifex/application-bridge": "0.3.0-preview.1",
63
- "@runic-artifex/vite-plugin-runic": "0.3.0-preview.1",
68
+ "@runic-artifex/application-bridge": "0.4.0-preview.1",
69
+ "@runic-artifex/vite-plugin-runic": "0.4.0-preview.1",
64
70
  "effect": "4.0.0-rc.112",
65
71
  "svelte": ">=5.46.4 <6"
66
72
  },
@@ -86,8 +92,8 @@
86
92
  "node": ">=24.18.0 <25"
87
93
  },
88
94
  "devDependencies": {
89
- "@runic-artifex/application-bridge": "0.3.0-preview.1",
90
- "@runic-artifex/vite-plugin-runic": "0.3.0-preview.1",
95
+ "@runic-artifex/application-bridge": "0.4.0-preview.1",
96
+ "@runic-artifex/vite-plugin-runic": "0.4.0-preview.1",
91
97
  "@sveltejs/adapter-static": "3.0.10",
92
98
  "@sveltejs/kit": "2.70.3",
93
99
  "@sveltejs/package": "2.5.8",
@@ -101,5 +107,5 @@
101
107
  "vitest": "5.0.0",
102
108
  "vite": "8.2.2"
103
109
  },
104
- "gitHead": "92e75481565ea1b8a4c579ec1d2e27f3384aa9aa"
110
+ "gitHead": "25c8895a9a693da3d6e1a075c6bc503a56c26399"
105
111
  }