@iota-uz/sdk 0.3.4 → 0.4.8

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 (66) hide show
  1. package/README.md +117 -0
  2. package/dist/applet/core.cjs +251 -0
  3. package/dist/applet/core.cjs.map +1 -0
  4. package/dist/applet/core.d.cts +172 -0
  5. package/dist/applet/core.d.ts +172 -0
  6. package/dist/applet/core.mjs +237 -0
  7. package/dist/applet/core.mjs.map +1 -0
  8. package/dist/applet/devtools.cjs +131 -0
  9. package/dist/applet/devtools.cjs.map +1 -0
  10. package/dist/applet/devtools.d.cts +7 -0
  11. package/dist/applet/devtools.d.ts +7 -0
  12. package/dist/applet/devtools.mjs +128 -0
  13. package/dist/applet/devtools.mjs.map +1 -0
  14. package/dist/applet/host.cjs +256 -0
  15. package/dist/applet/host.cjs.map +1 -0
  16. package/dist/applet/host.d.cts +62 -0
  17. package/dist/applet/host.d.ts +62 -0
  18. package/dist/applet/host.mjs +251 -0
  19. package/dist/applet/host.mjs.map +1 -0
  20. package/dist/bichat/index.cjs +352 -409
  21. package/dist/bichat/index.cjs.map +1 -1
  22. package/dist/bichat/index.d.cts +8 -116
  23. package/dist/bichat/index.d.ts +8 -116
  24. package/dist/bichat/index.mjs +354 -403
  25. package/dist/bichat/index.mjs.map +1 -1
  26. package/dist/fonts/Actay/Actay-Regular.otf +0 -0
  27. package/dist/fonts/Actay/Actay-RegularItalic.otf +0 -0
  28. package/dist/fonts/Actay/ActayCondensed-Thin.otf +0 -0
  29. package/dist/fonts/Actay/ActayCondensed-ThinItalic.otf +0 -0
  30. package/dist/fonts/Actay/ActayWide-Bold.otf +0 -0
  31. package/dist/fonts/Actay/ActayWide-BoldItalic.otf +0 -0
  32. package/dist/fonts/Gilroy/Gilroy-Black.woff2 +0 -0
  33. package/dist/fonts/Gilroy/Gilroy-BlackItalic.woff2 +0 -0
  34. package/dist/fonts/Gilroy/Gilroy-Bold.woff2 +0 -0
  35. package/dist/fonts/Gilroy/Gilroy-BoldItalic.woff2 +0 -0
  36. package/dist/fonts/Gilroy/Gilroy-Extrabold.woff2 +0 -0
  37. package/dist/fonts/Gilroy/Gilroy-ExtraboldItalic.woff2 +0 -0
  38. package/dist/fonts/Gilroy/Gilroy-Heavy.woff2 +0 -0
  39. package/dist/fonts/Gilroy/Gilroy-HeavyItalic.woff2 +0 -0
  40. package/dist/fonts/Gilroy/Gilroy-Light.woff2 +0 -0
  41. package/dist/fonts/Gilroy/Gilroy-LightItalic.woff2 +0 -0
  42. package/dist/fonts/Gilroy/Gilroy-Medium.woff2 +0 -0
  43. package/dist/fonts/Gilroy/Gilroy-MediumItalic.woff2 +0 -0
  44. package/dist/fonts/Gilroy/Gilroy-Regular.woff2 +0 -0
  45. package/dist/fonts/Gilroy/Gilroy-RegularItalic.woff2 +0 -0
  46. package/dist/fonts/Gilroy/Gilroy-Semibold.woff2 +0 -0
  47. package/dist/fonts/Gilroy/Gilroy-SemiboldItalic.woff2 +0 -0
  48. package/dist/fonts/Gilroy/Gilroy-Thin.woff2 +0 -0
  49. package/dist/fonts/Gilroy/Gilroy-ThinItalic.woff2 +0 -0
  50. package/dist/fonts/Gilroy/Gilroy-UltraLight.woff2 +0 -0
  51. package/dist/fonts/Gilroy/Gilroy-UltraLightItalic.woff2 +0 -0
  52. package/dist/fonts/Inter.var.woff2 +0 -0
  53. package/dist/{index-B73-BCi-.d.cts → index-Cs_xWkhC.d.cts} +1 -1
  54. package/dist/{index-B73-BCi-.d.ts → index-Cs_xWkhC.d.ts} +1 -1
  55. package/dist/index.cjs +52 -4
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +6 -232
  58. package/dist/index.d.ts +6 -232
  59. package/dist/index.mjs +52 -4
  60. package/dist/index.mjs.map +1 -1
  61. package/package.json +45 -14
  62. package/tailwind/compiled.css +1 -1
  63. package/tailwind/create-config.cjs +16 -135
  64. package/tailwind/sdk-theme.cjs +99 -0
  65. package/LICENSE +0 -201
  66. package/README.MD +0 -166
@@ -0,0 +1,128 @@
1
+ import { createContext, useState, useEffect, useMemo, useContext } from 'react';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+
4
+ // ui/src/applet-devtools/enabled.ts
5
+ function shouldEnableAppletDevtools() {
6
+ if (typeof window === "undefined") return false;
7
+ const url = new URL(window.location.href);
8
+ if (url.searchParams.get("appletDebug") === "1") return true;
9
+ try {
10
+ return window.localStorage.getItem("iotaAppletDevtools") === "1";
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+ var AppletContext = createContext(null);
16
+ function useAppletContext() {
17
+ const context = useContext(AppletContext);
18
+ if (!context) {
19
+ throw new Error("useAppletContext must be used within AppletProvider");
20
+ }
21
+ return context;
22
+ }
23
+
24
+ // ui/src/applet-core/hooks/useConfig.ts
25
+ function useConfig() {
26
+ const { config } = useAppletContext();
27
+ return config;
28
+ }
29
+
30
+ // ui/src/applet-core/hooks/useAppletRuntime.ts
31
+ function useAppletRuntime() {
32
+ const config = useConfig();
33
+ const basePath = config.basePath ?? "";
34
+ const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
35
+ const assetsBasePath = config.assetsBasePath ?? `${normalizedBasePath || ""}/assets`;
36
+ const rpcEndpoint = config.rpcUIEndpoint;
37
+ const shellMode = config.shellMode;
38
+ return { basePath: normalizedBasePath, assetsBasePath, rpcEndpoint, shellMode };
39
+ }
40
+ function AppletDevtoolsOverlay() {
41
+ const ctx = useAppletContext();
42
+ const runtime = useAppletRuntime();
43
+ const [rpcEvents, setRPCEvents] = useState([]);
44
+ useEffect(() => {
45
+ const onEvent = (e) => {
46
+ if (!(e instanceof CustomEvent)) return;
47
+ const detail = e.detail;
48
+ if (!detail) return;
49
+ setRPCEvents((prev) => [detail, ...prev].slice(0, 50));
50
+ };
51
+ window.addEventListener("iota:applet-rpc", onEvent);
52
+ return () => window.removeEventListener("iota:applet-rpc", onEvent);
53
+ }, []);
54
+ const summary = useMemo(() => {
55
+ return {
56
+ basePath: runtime.basePath,
57
+ assetsBasePath: runtime.assetsBasePath,
58
+ rpcEndpoint: runtime.rpcEndpoint,
59
+ shellMode: runtime.shellMode,
60
+ route: ctx.route,
61
+ user: { id: ctx.user.id, email: ctx.user.email },
62
+ tenant: ctx.tenant
63
+ };
64
+ }, [ctx.route, ctx.tenant, ctx.user.email, ctx.user.id, runtime.assetsBasePath, runtime.basePath, runtime.rpcEndpoint, runtime.shellMode]);
65
+ return /* @__PURE__ */ jsxs(
66
+ "div",
67
+ {
68
+ style: {
69
+ position: "fixed",
70
+ right: 12,
71
+ bottom: 12,
72
+ width: 420,
73
+ maxHeight: "60vh",
74
+ overflow: "auto",
75
+ background: "rgba(17, 24, 39, 0.92)",
76
+ color: "#E5E7EB",
77
+ border: "1px solid rgba(255,255,255,0.12)",
78
+ borderRadius: 10,
79
+ padding: 12,
80
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
81
+ fontSize: 12,
82
+ zIndex: 2147483647
83
+ },
84
+ children: [
85
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }, children: [
86
+ /* @__PURE__ */ jsx("div", { style: { fontWeight: 700 }, children: "Applet Devtools" }),
87
+ /* @__PURE__ */ jsx("div", { style: { opacity: 0.7 }, children: runtime.shellMode ?? "unknown" })
88
+ ] }),
89
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: 10 }, children: [
90
+ /* @__PURE__ */ jsx("div", { style: { opacity: 0.85, marginBottom: 4 }, children: "Context" }),
91
+ /* @__PURE__ */ jsx("pre", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: JSON.stringify(summary, null, 2) })
92
+ ] }),
93
+ /* @__PURE__ */ jsxs("div", { children: [
94
+ /* @__PURE__ */ jsx("div", { style: { opacity: 0.85, marginBottom: 4 }, children: "RPC" }),
95
+ rpcEvents.length === 0 ? /* @__PURE__ */ jsx("div", { style: { opacity: 0.7 }, children: "No calls yet" }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: rpcEvents.map((ev) => /* @__PURE__ */ jsxs("div", { style: { padding: 8, border: "1px solid rgba(255,255,255,0.08)", borderRadius: 8 }, children: [
96
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
97
+ /* @__PURE__ */ jsx("div", { children: ev.method }),
98
+ /* @__PURE__ */ jsxs("div", { style: { opacity: 0.8 }, children: [
99
+ ev.status,
100
+ typeof ev.durationMs === "number" ? ` (${ev.durationMs}ms)` : ""
101
+ ] })
102
+ ] }),
103
+ ev.status === "error" ? /* @__PURE__ */ jsx("pre", { style: { margin: "6px 0 0", opacity: 0.8, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: JSON.stringify(serializeError(ev.error) ?? {}, null, 2) }) : null
104
+ ] }, `${ev.id}:${ev.status}`)) })
105
+ ] })
106
+ ]
107
+ }
108
+ );
109
+ }
110
+ function serializeError(err) {
111
+ if (err instanceof Error) {
112
+ const anyErr = err;
113
+ const out = {
114
+ name: err.name,
115
+ message: err.message
116
+ };
117
+ if (err.stack) out.stack = err.stack;
118
+ if (typeof anyErr.code === "string") out.code = anyErr.code;
119
+ if (anyErr.details !== void 0) out.details = anyErr.details;
120
+ if (anyErr.cause !== void 0) out.cause = anyErr.cause;
121
+ return out;
122
+ }
123
+ return err;
124
+ }
125
+
126
+ export { AppletDevtoolsOverlay, shouldEnableAppletDevtools };
127
+ //# sourceMappingURL=devtools.mjs.map
128
+ //# sourceMappingURL=devtools.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../ui/src/applet-devtools/enabled.ts","../../ui/src/applet-core/context/AppletContext.tsx","../../ui/src/applet-core/hooks/useConfig.ts","../../ui/src/applet-core/hooks/useAppletRuntime.ts","../../ui/src/applet-devtools/overlay.tsx"],"names":["jsx"],"mappings":";;;;AAAO,SAAS,0BAAA,GAAsC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AQ,MAAA,CAAO,KAAA;AACnD,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,OAAO,GAAA;AACT","file":"devtools.mjs","sourcesContent":["export function shouldEnableAppletDevtools(): boolean {\n if (typeof window === 'undefined') return false\n\n const url = new URL(window.location.href)\n if (url.searchParams.get('appletDebug') === '1') return true\n\n try {\n return window.localStorage.getItem('iotaAppletDevtools') === '1'\n } catch {\n return false\n }\n}\n\n","import { createContext, useContext, ReactNode } from 'react'\nimport type { InitialContext } from '../types'\n\n/**\n * AppletContext provides access to the global context injected by the backend.\n * The context is read from window.__*_CONTEXT__ (configured via windowKey).\n */\nconst AppletContext = createContext<InitialContext | null>(null)\n\nconst REQUIRED_KEYS: Array<keyof InitialContext> = ['user', 'tenant', 'locale', 'config', 'route', 'session']\n\nfunction validateInitialContext(value: unknown, windowKey: string): InitialContext {\n if (!value || typeof value !== 'object') {\n throw new Error(`${windowKey}: expected an object, got ${typeof value}`)\n }\n const obj = value as Record<string, unknown>\n const missing = REQUIRED_KEYS.filter((k) => !(k in obj))\n if (missing.length > 0) {\n throw new Error(`${windowKey}: missing required keys: ${missing.join(', ')}`)\n }\n\n // Deep validation for nested required fields\n const user = obj.user as Record<string, unknown> | undefined\n if (!user || typeof user !== 'object') {\n throw new Error(`${windowKey}.user: expected an object, got ${typeof user}`)\n }\n if (typeof user.id !== 'number') {\n throw new Error(`${windowKey}.user.id: expected number, got ${typeof user.id}`)\n }\n if (!Array.isArray(user.permissions)) {\n throw new Error(`${windowKey}.user.permissions: expected array, got ${typeof user.permissions}`)\n }\n\n const tenant = obj.tenant as Record<string, unknown> | undefined\n if (!tenant || typeof tenant !== 'object') {\n throw new Error(`${windowKey}.tenant: expected an object, got ${typeof tenant}`)\n }\n if (typeof tenant.id !== 'string') {\n throw new Error(`${windowKey}.tenant.id: expected string, got ${typeof tenant.id}`)\n }\n\n const session = obj.session as Record<string, unknown> | undefined\n if (!session || typeof session !== 'object') {\n throw new Error(`${windowKey}.session: expected an object, got ${typeof session}`)\n }\n if (typeof session.csrfToken !== 'string') {\n throw new Error(`${windowKey}.session.csrfToken: expected string, got ${typeof session.csrfToken}`)\n }\n if (typeof session.expiresAt !== 'number') {\n throw new Error(`${windowKey}.session.expiresAt: expected number, got ${typeof session.expiresAt}`)\n }\n if (typeof session.refreshURL !== 'string') {\n throw new Error(`${windowKey}.session.refreshURL: expected string, got ${typeof session.refreshURL}`)\n }\n\n const config = obj.config\n if (!config || typeof config !== 'object') {\n throw new Error(`${windowKey}.config: expected object, got ${typeof config}`)\n }\n\n return value as InitialContext\n}\n\nexport interface AppletProviderProps {\n children: ReactNode\n windowKey: string\n context?: InitialContext\n}\n\n/**\n * AppletProvider reads context from window global and provides it to hooks.\n *\n * Usage:\n * <AppletProvider windowKey=\"__BICHAT_CONTEXT__\">\n * <App />\n * </AppletProvider>\n */\nexport function AppletProvider({ children, windowKey, context }: AppletProviderProps) {\n // Use provided context or read from window global\n const raw = context ?? (window as any)[windowKey]\n\n if (!raw) {\n throw new Error(`${windowKey} not found on window. Ensure backend context injection is working.`)\n }\n\n const initialContext = validateInitialContext(raw, windowKey)\n\n return (\n <AppletContext.Provider value={initialContext}>\n {children}\n </AppletContext.Provider>\n )\n}\n\n/**\n * useAppletContext provides access to the full applet context.\n * Use specialized hooks (useUser, useConfig, etc.) for specific context parts.\n */\nexport function useAppletContext<T = InitialContext>(): T {\n const context = useContext(AppletContext)\n if (!context) {\n throw new Error('useAppletContext must be used within AppletProvider')\n }\n return context as T\n}\n","import { useAppletContext } from '../context/AppletContext'\nimport type { AppConfig } from '../types'\n\n/**\n * useConfig provides access to applet configuration (endpoints, etc.)\n *\n * Usage:\n * const { graphQLEndpoint, streamEndpoint } = useConfig()\n */\nexport function useConfig(): AppConfig {\n const { config } = useAppletContext()\n return config\n}\n","import { useConfig } from './useConfig'\n\nexport type ShellMode = 'embedded' | 'standalone'\n\nexport interface AppletRuntime {\n basePath: string\n assetsBasePath: string\n rpcEndpoint?: string\n shellMode?: ShellMode\n}\n\nexport function useAppletRuntime(): AppletRuntime {\n const config = useConfig()\n\n const basePath = config.basePath ?? ''\n const normalizedBasePath = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath\n const assetsBasePath = config.assetsBasePath ?? `${normalizedBasePath || ''}/assets`\n const rpcEndpoint = config.rpcUIEndpoint\n const shellMode = config.shellMode\n\n return { basePath: normalizedBasePath, assetsBasePath, rpcEndpoint, shellMode }\n}\n","import { useEffect, useMemo, useState } from 'react'\nimport { useAppletContext } from '../applet-core/context/AppletContext'\nimport { useAppletRuntime } from '../applet-core/hooks/useAppletRuntime'\n\ntype RPCEvent = {\n id: string\n method: string\n status: 'start' | 'success' | 'error'\n durationMs?: number\n error?: unknown\n}\n\nexport function AppletDevtoolsOverlay() {\n const ctx = useAppletContext()\n const runtime = useAppletRuntime()\n const [rpcEvents, setRPCEvents] = useState<RPCEvent[]>([])\n\n useEffect(() => {\n const onEvent = (e: Event) => {\n if (!(e instanceof CustomEvent)) return\n const detail = (e as CustomEvent<RPCEvent>).detail\n if (!detail) return\n setRPCEvents((prev) => [detail, ...prev].slice(0, 50))\n }\n window.addEventListener('iota:applet-rpc', onEvent as EventListener)\n return () => window.removeEventListener('iota:applet-rpc', onEvent as EventListener)\n }, [])\n\n const summary = useMemo(() => {\n return {\n basePath: runtime.basePath,\n assetsBasePath: runtime.assetsBasePath,\n rpcEndpoint: runtime.rpcEndpoint,\n shellMode: runtime.shellMode,\n route: ctx.route,\n user: { id: ctx.user.id, email: ctx.user.email },\n tenant: ctx.tenant,\n }\n }, [ctx.route, ctx.tenant, ctx.user.email, ctx.user.id, runtime.assetsBasePath, runtime.basePath, runtime.rpcEndpoint, runtime.shellMode])\n\n return (\n <div\n style={{\n position: 'fixed',\n right: 12,\n bottom: 12,\n width: 420,\n maxHeight: '60vh',\n overflow: 'auto',\n background: 'rgba(17, 24, 39, 0.92)',\n color: '#E5E7EB',\n border: '1px solid rgba(255,255,255,0.12)',\n borderRadius: 10,\n padding: 12,\n fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace',\n fontSize: 12,\n zIndex: 2147483647,\n }}\n >\n <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>\n <div style={{ fontWeight: 700 }}>Applet Devtools</div>\n <div style={{ opacity: 0.7 }}>{runtime.shellMode ?? 'unknown'}</div>\n </div>\n\n <div style={{ marginBottom: 10 }}>\n <div style={{ opacity: 0.85, marginBottom: 4 }}>Context</div>\n <pre style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>{JSON.stringify(summary, null, 2)}</pre>\n </div>\n\n <div>\n <div style={{ opacity: 0.85, marginBottom: 4 }}>RPC</div>\n {rpcEvents.length === 0 ? (\n <div style={{ opacity: 0.7 }}>No calls yet</div>\n ) : (\n <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>\n {rpcEvents.map((ev) => (\n <div key={`${ev.id}:${ev.status}`} style={{ padding: 8, border: '1px solid rgba(255,255,255,0.08)', borderRadius: 8 }}>\n <div style={{ display: 'flex', justifyContent: 'space-between' }}>\n <div>{ev.method}</div>\n <div style={{ opacity: 0.8 }}>\n {ev.status}\n {typeof ev.durationMs === 'number' ? ` (${ev.durationMs}ms)` : ''}\n </div>\n </div>\n {ev.status === 'error' ? (\n <pre style={{ margin: '6px 0 0', opacity: 0.8, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>\n {JSON.stringify(serializeError(ev.error) ?? {}, null, 2)}\n </pre>\n ) : null}\n </div>\n ))}\n </div>\n )}\n </div>\n </div>\n )\n}\n\nfunction serializeError(err: unknown): unknown {\n if (err instanceof Error) {\n const anyErr = err as any\n const out: Record<string, unknown> = {\n name: err.name,\n message: err.message,\n }\n if (err.stack) out.stack = err.stack\n if (typeof anyErr.code === 'string') out.code = anyErr.code\n if (anyErr.details !== undefined) out.details = anyErr.details\n if (anyErr.cause !== undefined) out.cause = anyErr.cause\n return out\n }\n return err\n}\n"]}
@@ -0,0 +1,256 @@
1
+ 'use strict';
2
+
3
+ var client = require('react-dom/client');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // ui/src/applet-host/react-element.ts
7
+ function defineReactAppletElement(options) {
8
+ const tagName = options.tagName.toLowerCase();
9
+ const registry = getRegistry();
10
+ const existing = registry.get(tagName);
11
+ if (existing) {
12
+ existing.options = options;
13
+ for (const a of options.observedAttributes ?? []) existing.observed.add(a);
14
+ } else {
15
+ const observed = /* @__PURE__ */ new Set(["base-path", "shell-mode", "router-mode"]);
16
+ for (const a of options.observedAttributes ?? []) observed.add(a);
17
+ registry.set(tagName, { options, observed });
18
+ }
19
+ if (customElements.get(tagName)) {
20
+ if (typeof window !== "undefined") {
21
+ window.dispatchEvent(new CustomEvent("iota:applet-host-update", { detail: { tagName } }));
22
+ }
23
+ return;
24
+ }
25
+ function getEntry() {
26
+ const entry = getRegistry().get(tagName);
27
+ if (!entry) throw new Error(`[${tagName}] applet host registry entry missing`);
28
+ return entry;
29
+ }
30
+ class ReactAppletElement extends HTMLElement {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.reactRoot = null;
34
+ this.container = null;
35
+ this.darkModeObserver = null;
36
+ this.styleEl = null;
37
+ this.updateListener = null;
38
+ }
39
+ static get observedAttributes() {
40
+ return Array.from(getEntry().observed);
41
+ }
42
+ connectedCallback() {
43
+ const shadowRoot = this.shadowRoot ?? this.attachShadow({ mode: "open" });
44
+ if (!this.container) {
45
+ this.container = document.createElement("div");
46
+ this.container.id = "react-root";
47
+ this.container.style.display = "flex";
48
+ this.container.style.flexDirection = "column";
49
+ this.container.style.flex = "1";
50
+ this.container.style.minHeight = "0";
51
+ this.container.style.height = "100%";
52
+ this.container.style.width = "100%";
53
+ }
54
+ const existingContainer = shadowRoot.querySelector("#react-root");
55
+ if (!existingContainer) {
56
+ if (this.styleEl) shadowRoot.appendChild(this.styleEl);
57
+ shadowRoot.appendChild(this.container);
58
+ } else if (existingContainer !== this.container) {
59
+ this.container = existingContainer;
60
+ }
61
+ this.syncFromRegistry();
62
+ this.updateListener ?? (this.updateListener = (e) => {
63
+ if (!(e instanceof CustomEvent)) return;
64
+ const detail = e.detail;
65
+ if (!detail || detail.tagName !== tagName) return;
66
+ this.syncFromRegistry();
67
+ this.renderReact();
68
+ });
69
+ window.addEventListener("iota:applet-host-update", this.updateListener);
70
+ this.renderReact();
71
+ }
72
+ disconnectedCallback() {
73
+ if (this.updateListener) {
74
+ window.removeEventListener("iota:applet-host-update", this.updateListener);
75
+ }
76
+ this.darkModeObserver?.disconnect();
77
+ this.darkModeObserver = null;
78
+ this.reactRoot?.unmount();
79
+ this.reactRoot = null;
80
+ }
81
+ attributeChangedCallback(_name, oldValue, newValue) {
82
+ if (oldValue === newValue) return;
83
+ if (this.container) this.renderReact();
84
+ }
85
+ getHostConfig() {
86
+ const attrs = {};
87
+ for (const { name, value } of Array.from(this.attributes)) {
88
+ attrs[name] = value;
89
+ }
90
+ const basePath = this.getAttribute("base-path") ?? "";
91
+ const shellMode = this.getAttribute("shell-mode") ?? void 0;
92
+ const routerMode = this.getAttribute("router-mode") ?? "url";
93
+ return { basePath, shellMode, routerMode, attrs };
94
+ }
95
+ renderReact() {
96
+ if (!this.container) return;
97
+ if (!this.reactRoot) {
98
+ this.reactRoot = client.createRoot(this.container);
99
+ }
100
+ try {
101
+ this.reactRoot.render(getEntry().options.render(this.getHostConfig()));
102
+ } catch (err) {
103
+ console.error(`[${tagName}] failed to mount React app:`, err);
104
+ }
105
+ }
106
+ syncFromRegistry() {
107
+ const entry = getEntry();
108
+ const styles = typeof entry.options.styles === "function" ? entry.options.styles() : entry.options.styles;
109
+ if (styles) {
110
+ this.styleEl ?? (this.styleEl = document.createElement("style"));
111
+ this.styleEl.textContent = styles;
112
+ if (this.shadowRoot && !this.shadowRoot.contains(this.styleEl)) {
113
+ this.shadowRoot.insertBefore(this.styleEl, this.shadowRoot.firstChild);
114
+ }
115
+ } else if (this.styleEl) {
116
+ this.styleEl.remove();
117
+ this.styleEl = null;
118
+ }
119
+ if (entry.options.observeDarkMode !== false) {
120
+ this.darkModeObserver ?? (this.darkModeObserver = this.syncDarkMode());
121
+ } else if (this.darkModeObserver) {
122
+ this.darkModeObserver.disconnect();
123
+ this.darkModeObserver = null;
124
+ }
125
+ }
126
+ syncDarkMode() {
127
+ const root = this.container;
128
+ if (!root) throw new Error("react root container not found");
129
+ const apply = () => {
130
+ if (document.documentElement.classList.contains("dark")) root.classList.add("dark");
131
+ else root.classList.remove("dark");
132
+ };
133
+ apply();
134
+ const observer = new MutationObserver(apply);
135
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
136
+ return observer;
137
+ }
138
+ }
139
+ customElements.define(tagName, ReactAppletElement);
140
+ }
141
+ function getRegistry() {
142
+ const anyGlobal = globalThis;
143
+ anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ ?? (anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ = /* @__PURE__ */ new Map());
144
+ return anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__;
145
+ }
146
+
147
+ // ui/src/applet-devtools/enabled.ts
148
+ function shouldEnableAppletDevtools() {
149
+ if (typeof window === "undefined") return false;
150
+ const url = new URL(window.location.href);
151
+ if (url.searchParams.get("appletDebug") === "1") return true;
152
+ try {
153
+ return window.localStorage.getItem("iotaAppletDevtools") === "1";
154
+ } catch {
155
+ return false;
156
+ }
157
+ }
158
+
159
+ // ui/src/applet-host/rpc.ts
160
+ var AppletRPCException = class extends Error {
161
+ constructor(args) {
162
+ super(args.message);
163
+ this.name = "AppletRPCException";
164
+ this.code = args.code;
165
+ this.details = args.details;
166
+ this.cause = args.cause;
167
+ }
168
+ };
169
+ function createAppletRPCClient(options) {
170
+ const fetcher = options.fetcher ?? fetch;
171
+ async function call(method, params) {
172
+ const req = { id: crypto.randomUUID(), method, params };
173
+ const startedAt = typeof performance !== "undefined" ? performance.now() : Date.now();
174
+ maybeDispatchRPCEvent({
175
+ id: req.id,
176
+ method: req.method,
177
+ status: "start"
178
+ });
179
+ try {
180
+ const resp = await fetcher(options.endpoint, {
181
+ method: "POST",
182
+ headers: { "Content-Type": "application/json" },
183
+ body: JSON.stringify(req)
184
+ });
185
+ if (!resp.ok) {
186
+ throw new AppletRPCException({
187
+ code: "http_error",
188
+ message: `HTTP ${resp.status}`,
189
+ details: { status: resp.status }
190
+ });
191
+ }
192
+ const json = await resp.json();
193
+ if (json.error) {
194
+ throw new AppletRPCException({
195
+ code: json.error.code,
196
+ message: json.error.message,
197
+ details: json.error.details
198
+ });
199
+ }
200
+ if (json.result === void 0) {
201
+ throw new AppletRPCException({
202
+ code: "invalid_response",
203
+ message: "Missing result in successful response"
204
+ });
205
+ }
206
+ maybeDispatchRPCEvent({
207
+ id: req.id,
208
+ method: req.method,
209
+ status: "success",
210
+ durationMs: elapsedMs(startedAt)
211
+ });
212
+ return json.result;
213
+ } catch (err) {
214
+ maybeDispatchRPCEvent({
215
+ id: req.id,
216
+ method: req.method,
217
+ status: "error",
218
+ durationMs: elapsedMs(startedAt),
219
+ error: err
220
+ });
221
+ throw err;
222
+ }
223
+ }
224
+ async function callTyped(method, params) {
225
+ return call(method, params);
226
+ }
227
+ return { call, callTyped };
228
+ }
229
+ function maybeDispatchRPCEvent(detail) {
230
+ if (typeof window === "undefined") return;
231
+ if (!shouldEnableAppletDevtools()) return;
232
+ window.dispatchEvent(new CustomEvent("iota:applet-rpc", { detail }));
233
+ }
234
+ function elapsedMs(startedAt) {
235
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
236
+ return Math.max(0, Math.round(now - startedAt));
237
+ }
238
+ function createAppletRouter(options) {
239
+ const basePath = options.basePath ?? "";
240
+ const Router = ({ children }) => {
241
+ if (options.mode === "memory") {
242
+ const MemoryRouter = options.MemoryRouter;
243
+ return /* @__PURE__ */ jsxRuntime.jsx(MemoryRouter, { children });
244
+ }
245
+ const BrowserRouter = options.BrowserRouter;
246
+ return /* @__PURE__ */ jsxRuntime.jsx(BrowserRouter, { basename: basePath, children });
247
+ };
248
+ return { Router };
249
+ }
250
+
251
+ exports.AppletRPCException = AppletRPCException;
252
+ exports.createAppletRPCClient = createAppletRPCClient;
253
+ exports.createAppletRouter = createAppletRouter;
254
+ exports.defineReactAppletElement = defineReactAppletElement;
255
+ //# sourceMappingURL=host.cjs.map
256
+ //# sourceMappingURL=host.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../ui/src/applet-host/react-element.ts","../../ui/src/applet-devtools/enabled.ts","../../ui/src/applet-host/rpc.ts","../../ui/src/applet-host/router.tsx"],"names":["createRoot","jsx"],"mappings":";;;;;;AA0BO,SAAS,yBAAyB,OAAA,EAAgD;AACvF,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,WAAA,EAAY;AAE5C,EAAA,MAAM,WAAW,WAAA,EAAY;AAC7B,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AACrC,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AACnB,IAAA,KAAA,MAAW,CAAA,IAAK,QAAQ,kBAAA,IAAsB,IAAI,QAAA,CAAS,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,EAC3E,CAAA,MAAO;AACL,IAAA,MAAM,2BAAW,IAAI,GAAA,CAAY,CAAC,WAAA,EAAa,YAAA,EAAc,aAAa,CAAC,CAAA;AAC3E,IAAA,KAAA,MAAW,KAAK,OAAA,CAAQ,kBAAA,IAAsB,EAAC,EAAG,QAAA,CAAS,IAAI,CAAC,CAAA;AAChE,IAAA,QAAA,CAAS,GAAA,CAAI,OAAA,EAAS,EAAE,OAAA,EAAS,UAAU,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA,EAAG;AAC/B,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,MAAA,MAAA,CAAO,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'\n\nexport type RouterMode = 'url' | 'memory'\nexport type ShellMode = 'embedded' | 'standalone'\n\ntype RegistryEntry = {\n options: DefineReactAppletElementOptions\n observed: Set<string>\n}\n\nexport interface AppletHostConfig {\n basePath: string\n shellMode?: ShellMode\n routerMode: RouterMode\n attrs: Record<string, string>\n}\n\nexport interface DefineReactAppletElementOptions {\n tagName: string\n styles?: string | (() => string)\n render: (host: AppletHostConfig) => React.ReactElement\n observedAttributes?: string[]\n observeDarkMode?: boolean\n}\n\nexport function defineReactAppletElement(options: DefineReactAppletElementOptions): void {\n const tagName = options.tagName.toLowerCase()\n\n const registry = getRegistry()\n const existing = registry.get(tagName)\n if (existing) {\n existing.options = options\n for (const a of options.observedAttributes ?? []) existing.observed.add(a)\n } else {\n const observed = new Set<string>(['base-path', 'shell-mode', 'router-mode'])\n for (const a of options.observedAttributes ?? []) observed.add(a)\n registry.set(tagName, { options, observed })\n }\n\n if (customElements.get(tagName)) {\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent('iota:applet-host-update', { detail: { tagName } }))\n }\n return\n }\n\n function getEntry(): RegistryEntry {\n const entry = getRegistry().get(tagName)\n if (!entry) throw new Error(`[${tagName}] applet host registry entry missing`)\n return entry\n }\n\n class ReactAppletElement extends HTMLElement {\n private reactRoot: Root | null = null\n private container: HTMLDivElement | null = null\n private darkModeObserver: MutationObserver | null = null\n private styleEl: HTMLStyleElement | null = null\n private updateListener: ((e: Event) => void) | null = null\n\n static get observedAttributes(): string[] {\n return Array.from(getEntry().observed)\n }\n\n connectedCallback(): void {\n const shadowRoot = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n\n if (!this.container) {\n this.container = document.createElement('div')\n this.container.id = 'react-root'\n this.container.style.display = 'flex'\n this.container.style.flexDirection = 'column'\n this.container.style.flex = '1'\n this.container.style.minHeight = '0'\n this.container.style.height = '100%'\n this.container.style.width = '100%'\n }\n\n const existingContainer = shadowRoot.querySelector('#react-root')\n if (!existingContainer) {\n if (this.styleEl) shadowRoot.appendChild(this.styleEl)\n shadowRoot.appendChild(this.container)\n } else if (existingContainer !== this.container) {\n this.container = existingContainer as HTMLDivElement\n }\n\n this.syncFromRegistry()\n\n this.updateListener ??= (e: Event) => {\n if (!(e instanceof CustomEvent)) return\n const detail = (e as CustomEvent<{ tagName?: string }>).detail\n if (!detail || detail.tagName !== tagName) return\n this.syncFromRegistry()\n this.renderReact()\n }\n window.addEventListener('iota:applet-host-update', this.updateListener as EventListener)\n\n this.renderReact()\n }\n\n disconnectedCallback(): void {\n if (this.updateListener) {\n window.removeEventListener('iota:applet-host-update', this.updateListener as EventListener)\n }\n\n this.darkModeObserver?.disconnect()\n this.darkModeObserver = null\n\n this.reactRoot?.unmount()\n this.reactRoot = null\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue) return\n if (this.container) this.renderReact()\n }\n\n private getHostConfig(): AppletHostConfig {\n const attrs: Record<string, string> = {}\n for (const { name, value } of Array.from(this.attributes)) {\n attrs[name] = value\n }\n\n const basePath = this.getAttribute('base-path') ?? ''\n const shellMode = (this.getAttribute('shell-mode') as ShellMode | null) ?? undefined\n const routerMode = (this.getAttribute('router-mode') as RouterMode | null) ?? 'url'\n\n return { basePath, shellMode, routerMode, attrs }\n }\n\n private renderReact(): void {\n if (!this.container) return\n\n if (!this.reactRoot) {\n this.reactRoot = createRoot(this.container)\n }\n\n try {\n this.reactRoot.render(getEntry().options.render(this.getHostConfig()))\n } catch (err) {\n console.error(`[${tagName}] failed to mount React app:`, err)\n }\n }\n\n private syncFromRegistry(): void {\n const entry = getEntry()\n\n const styles = typeof entry.options.styles === 'function' ? entry.options.styles() : entry.options.styles\n if (styles) {\n this.styleEl ??= document.createElement('style')\n this.styleEl.textContent = styles\n if (this.shadowRoot && !this.shadowRoot.contains(this.styleEl)) {\n this.shadowRoot.insertBefore(this.styleEl, this.shadowRoot.firstChild)\n }\n } else if (this.styleEl) {\n this.styleEl.remove()\n this.styleEl = null\n }\n\n if (entry.options.observeDarkMode !== false) {\n this.darkModeObserver ??= this.syncDarkMode()\n } else if (this.darkModeObserver) {\n this.darkModeObserver.disconnect()\n this.darkModeObserver = null\n }\n }\n\n private syncDarkMode(): MutationObserver {\n const root = this.container\n if (!root) throw new Error('react root container not found')\n\n const apply = () => {\n if (document.documentElement.classList.contains('dark')) root.classList.add('dark')\n else root.classList.remove('dark')\n }\n\n apply()\n\n const observer = new MutationObserver(apply)\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })\n return observer\n }\n }\n\n customElements.define(tagName, ReactAppletElement)\n}\n\nfunction getRegistry(): Map<string, RegistryEntry> {\n const anyGlobal = globalThis as any\n anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ ??= new Map<string, RegistryEntry>()\n return anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ as Map<string, RegistryEntry>\n}\n","export function shouldEnableAppletDevtools(): boolean {\n if (typeof window === 'undefined') return false\n\n const url = new URL(window.location.href)\n if (url.searchParams.get('appletDebug') === '1') return true\n\n try {\n return window.localStorage.getItem('iotaAppletDevtools') === '1'\n } catch {\n return false\n }\n}\n\n","import { shouldEnableAppletDevtools } from '../applet-devtools/enabled'\n\nexport interface AppletRPCError {\n code: string\n message: string\n details?: unknown\n}\n\nexport class AppletRPCException extends Error {\n code: string\n details?: unknown\n cause?: unknown\n\n constructor(args: { code: string; message: string; details?: unknown; cause?: unknown }) {\n super(args.message)\n this.name = 'AppletRPCException'\n this.code = args.code\n this.details = args.details\n this.cause = args.cause\n }\n}\n\nexport type AppletRPCSchema = Record<string, { params: unknown; result: unknown }>\n\ninterface RPCRequest {\n id: string\n method: string\n params: unknown\n}\n\ninterface RPCResponse<TResult> {\n id: string\n result?: TResult\n error?: AppletRPCError\n}\n\nexport interface CreateAppletRPCClientOptions {\n endpoint: string\n fetcher?: typeof fetch\n}\n\nexport function createAppletRPCClient(options: CreateAppletRPCClientOptions) {\n const fetcher = options.fetcher ?? fetch\n\n async function call<TParams, TResult>(method: string, params: TParams): Promise<TResult> {\n const req: RPCRequest = { id: crypto.randomUUID(), method, params }\n const startedAt = typeof performance !== 'undefined' ? performance.now() : Date.now()\n maybeDispatchRPCEvent({\n id: req.id,\n method: req.method,\n status: 'start',\n })\n\n try {\n const resp = await fetcher(options.endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(req),\n })\n\n if (!resp.ok) {\n throw new AppletRPCException({\n code: 'http_error',\n message: `HTTP ${resp.status}`,\n details: { status: resp.status },\n })\n }\n\n const json = (await resp.json()) as RPCResponse<TResult>\n if (json.error) {\n throw new AppletRPCException({\n code: json.error.code,\n message: json.error.message,\n details: json.error.details,\n })\n }\n\n if (json.result === undefined) {\n throw new AppletRPCException({\n code: 'invalid_response',\n message: 'Missing result in successful response',\n })\n }\n\n maybeDispatchRPCEvent({\n id: req.id,\n method: req.method,\n status: 'success',\n durationMs: elapsedMs(startedAt),\n })\n\n return json.result as TResult\n } catch (err) {\n maybeDispatchRPCEvent({\n id: req.id,\n method: req.method,\n status: 'error',\n durationMs: elapsedMs(startedAt),\n error: err,\n })\n throw err\n }\n }\n\n async function callTyped<\n TRouter extends AppletRPCSchema,\n TMethod extends keyof TRouter & string,\n >(method: TMethod, params: TRouter[TMethod]['params']): Promise<TRouter[TMethod]['result']> {\n return call(method, params) as Promise<TRouter[TMethod]['result']>\n }\n\n return { call, callTyped }\n}\n\ntype RPCDevEvent = {\n id: string\n method: string\n status: 'start' | 'success' | 'error'\n durationMs?: number\n error?: unknown\n}\n\nfunction maybeDispatchRPCEvent(detail: RPCDevEvent) {\n if (typeof window === 'undefined') return\n\n if (!shouldEnableAppletDevtools()) return\n\n window.dispatchEvent(new CustomEvent('iota:applet-rpc', { detail }))\n}\n\nfunction elapsedMs(startedAt: number): number {\n const now = typeof performance !== 'undefined' ? performance.now() : Date.now()\n return Math.max(0, Math.round(now - startedAt))\n}\n","import type React from 'react'\n\nexport type RouterMode = 'url' | 'memory'\n\nexport interface CreateAppletRouterOptions {\n mode: RouterMode\n basePath?: string\n BrowserRouter: React.ComponentType<any>\n MemoryRouter: React.ComponentType<any>\n}\n\nexport function createAppletRouter(options: CreateAppletRouterOptions) {\n const basePath = options.basePath ?? ''\n\n const Router: React.FC<React.PropsWithChildren> = ({ children }) => {\n if (options.mode === 'memory') {\n const MemoryRouter = options.MemoryRouter\n return <MemoryRouter>{children}</MemoryRouter>\n }\n\n const BrowserRouter = options.BrowserRouter\n return <BrowserRouter basename={basePath}>{children}</BrowserRouter>\n }\n\n return { Router }\n}\n\n"]}
@@ -0,0 +1,62 @@
1
+ import react__default from 'react';
2
+
3
+ type RouterMode$1 = 'url' | 'memory';
4
+ type ShellMode = 'embedded' | 'standalone';
5
+ interface AppletHostConfig {
6
+ basePath: string;
7
+ shellMode?: ShellMode;
8
+ routerMode: RouterMode$1;
9
+ attrs: Record<string, string>;
10
+ }
11
+ interface DefineReactAppletElementOptions {
12
+ tagName: string;
13
+ styles?: string | (() => string);
14
+ render: (host: AppletHostConfig) => react__default.ReactElement;
15
+ observedAttributes?: string[];
16
+ observeDarkMode?: boolean;
17
+ }
18
+ declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
19
+
20
+ interface AppletRPCError {
21
+ code: string;
22
+ message: string;
23
+ details?: unknown;
24
+ }
25
+ declare class AppletRPCException extends Error {
26
+ code: string;
27
+ details?: unknown;
28
+ cause?: unknown;
29
+ constructor(args: {
30
+ code: string;
31
+ message: string;
32
+ details?: unknown;
33
+ cause?: unknown;
34
+ });
35
+ }
36
+ type AppletRPCSchema = Record<string, {
37
+ params: unknown;
38
+ result: unknown;
39
+ }>;
40
+ interface CreateAppletRPCClientOptions {
41
+ endpoint: string;
42
+ fetcher?: typeof fetch;
43
+ }
44
+ declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
45
+ call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
46
+ callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
47
+ };
48
+
49
+ type RouterMode = 'url' | 'memory';
50
+ interface CreateAppletRouterOptions {
51
+ mode: RouterMode;
52
+ basePath?: string;
53
+ BrowserRouter: react__default.ComponentType<any>;
54
+ MemoryRouter: react__default.ComponentType<any>;
55
+ }
56
+ declare function createAppletRouter(options: CreateAppletRouterOptions): {
57
+ Router: react__default.FC<{
58
+ children?: react__default.ReactNode | undefined;
59
+ }>;
60
+ };
61
+
62
+ export { type AppletRPCError, AppletRPCException, type AppletRPCSchema, type RouterMode, createAppletRPCClient, createAppletRouter, defineReactAppletElement };
@@ -0,0 +1,62 @@
1
+ import react__default from 'react';
2
+
3
+ type RouterMode$1 = 'url' | 'memory';
4
+ type ShellMode = 'embedded' | 'standalone';
5
+ interface AppletHostConfig {
6
+ basePath: string;
7
+ shellMode?: ShellMode;
8
+ routerMode: RouterMode$1;
9
+ attrs: Record<string, string>;
10
+ }
11
+ interface DefineReactAppletElementOptions {
12
+ tagName: string;
13
+ styles?: string | (() => string);
14
+ render: (host: AppletHostConfig) => react__default.ReactElement;
15
+ observedAttributes?: string[];
16
+ observeDarkMode?: boolean;
17
+ }
18
+ declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
19
+
20
+ interface AppletRPCError {
21
+ code: string;
22
+ message: string;
23
+ details?: unknown;
24
+ }
25
+ declare class AppletRPCException extends Error {
26
+ code: string;
27
+ details?: unknown;
28
+ cause?: unknown;
29
+ constructor(args: {
30
+ code: string;
31
+ message: string;
32
+ details?: unknown;
33
+ cause?: unknown;
34
+ });
35
+ }
36
+ type AppletRPCSchema = Record<string, {
37
+ params: unknown;
38
+ result: unknown;
39
+ }>;
40
+ interface CreateAppletRPCClientOptions {
41
+ endpoint: string;
42
+ fetcher?: typeof fetch;
43
+ }
44
+ declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
45
+ call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
46
+ callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
47
+ };
48
+
49
+ type RouterMode = 'url' | 'memory';
50
+ interface CreateAppletRouterOptions {
51
+ mode: RouterMode;
52
+ basePath?: string;
53
+ BrowserRouter: react__default.ComponentType<any>;
54
+ MemoryRouter: react__default.ComponentType<any>;
55
+ }
56
+ declare function createAppletRouter(options: CreateAppletRouterOptions): {
57
+ Router: react__default.FC<{
58
+ children?: react__default.ReactNode | undefined;
59
+ }>;
60
+ };
61
+
62
+ export { type AppletRPCError, AppletRPCException, type AppletRPCSchema, type RouterMode, createAppletRPCClient, createAppletRouter, defineReactAppletElement };