@lifeart/async-dom 2.0.0-alpha.3
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/LICENSE +21 -0
- package/README.md +623 -0
- package/dist/base.d.cts +398 -0
- package/dist/base.d.cts.map +1 -0
- package/dist/base.d.ts +398 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/cli.cjs +528 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +493 -0
- package/dist/cli.js.map +1 -0
- package/dist/debug.d.cts +145 -0
- package/dist/debug.d.cts.map +1 -0
- package/dist/debug.d.ts +145 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index2.d.cts +5 -0
- package/dist/index2.d.ts +5 -0
- package/dist/index3.d.cts +882 -0
- package/dist/index3.d.cts.map +1 -0
- package/dist/index3.d.ts +882 -0
- package/dist/index3.d.ts.map +1 -0
- package/dist/main-thread.cjs +5459 -0
- package/dist/main-thread.cjs.map +1 -0
- package/dist/main-thread.js +5429 -0
- package/dist/main-thread.js.map +1 -0
- package/dist/react.cjs +116 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +91 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +91 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +113 -0
- package/dist/react.js.map +1 -0
- package/dist/resolve-debug.cjs +24 -0
- package/dist/resolve-debug.cjs.map +1 -0
- package/dist/resolve-debug.js +19 -0
- package/dist/resolve-debug.js.map +1 -0
- package/dist/server.cjs +250 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +127 -0
- package/dist/server.d.cts.map +1 -0
- package/dist/server.d.ts +127 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +245 -0
- package/dist/server.js.map +1 -0
- package/dist/svelte.cjs +48 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +38 -0
- package/dist/svelte.d.cts.map +1 -0
- package/dist/svelte.d.ts +38 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +47 -0
- package/dist/svelte.js.map +1 -0
- package/dist/sync-channel.cjs +532 -0
- package/dist/sync-channel.cjs.map +1 -0
- package/dist/sync-channel.js +425 -0
- package/dist/sync-channel.js.map +1 -0
- package/dist/transport.cjs +213 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +79 -0
- package/dist/transport.d.cts.map +1 -0
- package/dist/transport.d.ts +79 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +202 -0
- package/dist/transport.js.map +1 -0
- package/dist/vite-plugin.cjs +112 -0
- package/dist/vite-plugin.cjs.map +1 -0
- package/dist/vite-plugin.d.cts +39 -0
- package/dist/vite-plugin.d.cts.map +1 -0
- package/dist/vite-plugin.d.ts +39 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +107 -0
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vue.cjs +123 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +126 -0
- package/dist/vue.d.cts.map +1 -0
- package/dist/vue.d.ts +126 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +120 -0
- package/dist/vue.js.map +1 -0
- package/dist/worker-thread.cjs +2751 -0
- package/dist/worker-thread.cjs.map +1 -0
- package/dist/worker-thread.js +2692 -0
- package/dist/worker-thread.js.map +1 -0
- package/dist/worker-transport.cjs +136 -0
- package/dist/worker-transport.cjs.map +1 -0
- package/dist/worker-transport.d.cts +162 -0
- package/dist/worker-transport.d.cts.map +1 -0
- package/dist/worker-transport.d.ts +162 -0
- package/dist/worker-transport.d.ts.map +1 -0
- package/dist/worker-transport.js +125 -0
- package/dist/worker-transport.js.map +1 -0
- package/dist/worker.cjs +12 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +2 -0
- package/dist/ws-server-transport.cjs +147 -0
- package/dist/ws-server-transport.cjs.map +1 -0
- package/dist/ws-server-transport.d.cts +64 -0
- package/dist/ws-server-transport.d.cts.map +1 -0
- package/dist/ws-server-transport.d.ts +64 -0
- package/dist/ws-server-transport.d.ts.map +1 -0
- package/dist/ws-server-transport.js +142 -0
- package/dist/ws-server-transport.js.map +1 -0
- package/dist/ws-transport.cjs +954 -0
- package/dist/ws-transport.cjs.map +1 -0
- package/dist/ws-transport.js +913 -0
- package/dist/ws-transport.js.map +1 -0
- package/package.json +145 -0
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_resolve_debug = require("./resolve-debug.cjs");
|
|
3
|
+
require("./cli.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
//#region src/react/use-async-dom.ts
|
|
6
|
+
/**
|
|
7
|
+
* React hook that creates and manages an async-dom instance.
|
|
8
|
+
*
|
|
9
|
+
* Attaches an async-dom worker to the container element referenced by
|
|
10
|
+
* `containerRef`. The instance is created on mount and destroyed on unmount.
|
|
11
|
+
*
|
|
12
|
+
* @param options - Configuration for the async-dom instance.
|
|
13
|
+
* @returns An object containing the container ref and the instance (null until ready).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* function MyComponent() {
|
|
18
|
+
* const { containerRef, instance } = useAsyncDom({
|
|
19
|
+
* worker: "./my-worker.ts",
|
|
20
|
+
* onReady: (inst) => console.log("Ready!", inst),
|
|
21
|
+
* });
|
|
22
|
+
* return <div ref={containerRef} />;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function useAsyncDom(options) {
|
|
27
|
+
const containerRef = (0, react.useRef)(null);
|
|
28
|
+
const [instance, setInstance] = (0, react.useState)(null);
|
|
29
|
+
const instanceRef = (0, react.useRef)(null);
|
|
30
|
+
const workerRef = (0, react.useRef)(options.worker);
|
|
31
|
+
workerRef.current = options.worker;
|
|
32
|
+
const onReadyRef = (0, react.useRef)(options.onReady);
|
|
33
|
+
onReadyRef.current = options.onReady;
|
|
34
|
+
const onErrorRef = (0, react.useRef)(options.onError);
|
|
35
|
+
onErrorRef.current = options.onError;
|
|
36
|
+
const debugRef = (0, react.useRef)(options.debug);
|
|
37
|
+
debugRef.current = options.debug;
|
|
38
|
+
const schedulerRef = (0, react.useRef)(options.scheduler);
|
|
39
|
+
schedulerRef.current = options.scheduler;
|
|
40
|
+
(0, react.useEffect)(() => {
|
|
41
|
+
const el = containerRef.current;
|
|
42
|
+
if (!el) return;
|
|
43
|
+
let cancelled = false;
|
|
44
|
+
const workerProp = workerRef.current;
|
|
45
|
+
const worker = typeof workerProp === "string" ? new Worker(new URL(workerProp, require("url").pathToFileURL(__filename).href), { type: "module" }) : workerProp();
|
|
46
|
+
Promise.resolve().then(() => require("./main-thread.cjs")).then((n) => n.main_thread_exports).then(({ createAsyncDom }) => {
|
|
47
|
+
if (cancelled) {
|
|
48
|
+
worker.terminate();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const inst = createAsyncDom({
|
|
52
|
+
target: el,
|
|
53
|
+
worker,
|
|
54
|
+
scheduler: schedulerRef.current,
|
|
55
|
+
debug: require_resolve_debug.resolveDebugOption(debugRef.current)
|
|
56
|
+
});
|
|
57
|
+
inst.start();
|
|
58
|
+
instanceRef.current = inst;
|
|
59
|
+
setInstance(inst);
|
|
60
|
+
onReadyRef.current?.(inst);
|
|
61
|
+
});
|
|
62
|
+
return () => {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
instanceRef.current?.destroy();
|
|
65
|
+
instanceRef.current = null;
|
|
66
|
+
setInstance(null);
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
return {
|
|
70
|
+
containerRef,
|
|
71
|
+
instance
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/react/async-dom-component.ts
|
|
76
|
+
/**
|
|
77
|
+
* React component that renders an async-dom worker application.
|
|
78
|
+
*
|
|
79
|
+
* Wraps {@link useAsyncDom} in a self-contained component with a container div.
|
|
80
|
+
* Supports a `fallback` prop for loading state, and passes through `className`
|
|
81
|
+
* and `style` to the container element.
|
|
82
|
+
*
|
|
83
|
+
* @param props - Component props.
|
|
84
|
+
* @returns A React element containing the async-dom container.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* <AsyncDom
|
|
89
|
+
* worker="./app.worker.ts"
|
|
90
|
+
* fallback={<p>Loading...</p>}
|
|
91
|
+
* onReady={(instance) => console.log("ready", instance)}
|
|
92
|
+
* />
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
function AsyncDom(props) {
|
|
96
|
+
const { containerRef, instance } = useAsyncDom({
|
|
97
|
+
worker: props.worker,
|
|
98
|
+
scheduler: props.scheduler,
|
|
99
|
+
debug: props.debug,
|
|
100
|
+
onReady: props.onReady,
|
|
101
|
+
onError: props.onError
|
|
102
|
+
});
|
|
103
|
+
if (typeof window === "undefined") return (0, react.createElement)("div", {
|
|
104
|
+
className: props.className,
|
|
105
|
+
style: props.style
|
|
106
|
+
});
|
|
107
|
+
return (0, react.createElement)("div", {
|
|
108
|
+
className: props.className,
|
|
109
|
+
style: props.style
|
|
110
|
+
}, !instance && props.fallback ? props.fallback : null, (0, react.createElement)("div", { ref: containerRef }));
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
exports.AsyncDom = AsyncDom;
|
|
114
|
+
exports.useAsyncDom = useAsyncDom;
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.cjs","names":["resolveDebugOption"],"sources":["../src/react/use-async-dom.ts","../src/react/async-dom-component.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { DebugOptions, SchedulerConfig, SerializedError } from \"../index.ts\";\nimport type { AsyncDomInstance } from \"../main-thread/index.ts\";\nimport { resolveDebugOption } from \"../shared/resolve-debug.ts\";\n\nexport interface UseAsyncDomOptions {\n\t/** Worker script path or factory function */\n\tworker: string | (() => Worker);\n\t/** Scheduler configuration */\n\tscheduler?: SchedulerConfig;\n\t/** Debug options (pass `true` for sensible defaults, or a `DebugOptions` object) */\n\tdebug?: DebugOptions | boolean;\n\t/** Called when the async-dom instance is ready */\n\tonReady?: (instance: AsyncDomInstance) => void;\n\t/** Called when a worker error occurs */\n\tonError?: (error: SerializedError) => void;\n}\n\nexport interface UseAsyncDomResult {\n\t/** Ref to attach to the container element */\n\tcontainerRef: React.RefObject<HTMLDivElement | null>;\n\t/** The async-dom instance (null until ready) */\n\tinstance: AsyncDomInstance | null;\n}\n\n/**\n * React hook that creates and manages an async-dom instance.\n *\n * Attaches an async-dom worker to the container element referenced by\n * `containerRef`. The instance is created on mount and destroyed on unmount.\n *\n * @param options - Configuration for the async-dom instance.\n * @returns An object containing the container ref and the instance (null until ready).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { containerRef, instance } = useAsyncDom({\n * worker: \"./my-worker.ts\",\n * onReady: (inst) => console.log(\"Ready!\", inst),\n * });\n * return <div ref={containerRef} />;\n * }\n * ```\n */\nexport function useAsyncDom(options: UseAsyncDomOptions): UseAsyncDomResult {\n\tconst containerRef = useRef<HTMLDivElement | null>(null);\n\tconst [instance, setInstance] = useState<AsyncDomInstance | null>(null);\n\tconst instanceRef = useRef<AsyncDomInstance | null>(null);\n\n\t// Stabilize callback refs to prevent re-creation on re-renders\n\tconst workerRef = useRef(options.worker);\n\tworkerRef.current = options.worker;\n\n\tconst onReadyRef = useRef(options.onReady);\n\tonReadyRef.current = options.onReady;\n\n\tconst onErrorRef = useRef(options.onError);\n\tonErrorRef.current = options.onError;\n\n\tconst debugRef = useRef(options.debug);\n\tdebugRef.current = options.debug;\n\n\tconst schedulerRef = useRef(options.scheduler);\n\tschedulerRef.current = options.scheduler;\n\n\tuseEffect(() => {\n\t\tconst el = containerRef.current;\n\t\tif (!el) return;\n\n\t\tlet cancelled = false;\n\t\tconst workerProp = workerRef.current;\n\t\tconst worker =\n\t\t\ttypeof workerProp === \"string\"\n\t\t\t\t? new Worker(new URL(workerProp, import.meta.url), { type: \"module\" })\n\t\t\t\t: workerProp();\n\n\t\t// Dynamic import to avoid pulling main-thread code into SSR bundles\n\t\timport(\"../main-thread/index.ts\").then(({ createAsyncDom }) => {\n\t\t\tif (cancelled) {\n\t\t\t\tworker.terminate();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst inst = createAsyncDom({\n\t\t\t\ttarget: el,\n\t\t\t\tworker,\n\t\t\t\tscheduler: schedulerRef.current,\n\t\t\t\tdebug: resolveDebugOption(debugRef.current),\n\t\t\t});\n\t\t\tinst.start();\n\t\t\tinstanceRef.current = inst;\n\t\t\tsetInstance(inst);\n\t\t\tonReadyRef.current?.(inst);\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tinstanceRef.current?.destroy();\n\t\t\tinstanceRef.current = null;\n\t\t\tsetInstance(null);\n\t\t};\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, []);\n\n\treturn { containerRef, instance };\n}\n","import { createElement, type ReactNode } from \"react\";\nimport type { DebugOptions, SchedulerConfig, SerializedError } from \"../index.ts\";\nimport type { AsyncDomInstance } from \"../main-thread/index.ts\";\nimport { useAsyncDom } from \"./use-async-dom.ts\";\n\nexport interface AsyncDomProps {\n\t/** Worker script path or factory function */\n\tworker: string | (() => Worker);\n\t/** Scheduler configuration */\n\tscheduler?: SchedulerConfig;\n\t/** Enable debug mode (true for defaults, or pass DebugOptions) */\n\tdebug?: DebugOptions | boolean;\n\t/** Fallback content shown while loading */\n\tfallback?: ReactNode;\n\t/** Called when the async-dom instance is ready */\n\tonReady?: (instance: AsyncDomInstance) => void;\n\t/** Called when a worker error occurs */\n\tonError?: (error: SerializedError) => void;\n\t/** CSS class name for the container div */\n\tclassName?: string;\n\t/** Inline styles for the container div */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * React component that renders an async-dom worker application.\n *\n * Wraps {@link useAsyncDom} in a self-contained component with a container div.\n * Supports a `fallback` prop for loading state, and passes through `className`\n * and `style` to the container element.\n *\n * @param props - Component props.\n * @returns A React element containing the async-dom container.\n *\n * @example\n * ```tsx\n * <AsyncDom\n * worker=\"./app.worker.ts\"\n * fallback={<p>Loading...</p>}\n * onReady={(instance) => console.log(\"ready\", instance)}\n * />\n * ```\n */\nexport function AsyncDom(props: AsyncDomProps): ReactNode {\n\tconst { containerRef, instance } = useAsyncDom({\n\t\tworker: props.worker,\n\t\tscheduler: props.scheduler,\n\t\tdebug: props.debug,\n\t\tonReady: props.onReady,\n\t\tonError: props.onError,\n\t});\n\n\t// SSR guard: render only the container div\n\tif (typeof window === \"undefined\") {\n\t\treturn createElement(\"div\", {\n\t\t\tclassName: props.className,\n\t\t\tstyle: props.style,\n\t\t});\n\t}\n\n\t// Fallback is rendered as a sibling before the container to avoid\n\t// conflicting with createAsyncDom's DOM manipulation of the target element.\n\treturn createElement(\n\t\t\"div\",\n\t\t{ className: props.className, style: props.style },\n\t\t!instance && props.fallback ? props.fallback : null,\n\t\tcreateElement(\"div\", { ref: containerRef }),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,YAAY,SAAgD;CAC3E,MAAM,gBAAA,GAAA,MAAA,QAA6C,KAAK;CACxD,MAAM,CAAC,UAAU,gBAAA,GAAA,MAAA,UAAiD,KAAK;CACvE,MAAM,eAAA,GAAA,MAAA,QAA8C,KAAK;CAGzD,MAAM,aAAA,GAAA,MAAA,QAAmB,QAAQ,OAAO;AACxC,WAAU,UAAU,QAAQ;CAE5B,MAAM,cAAA,GAAA,MAAA,QAAoB,QAAQ,QAAQ;AAC1C,YAAW,UAAU,QAAQ;CAE7B,MAAM,cAAA,GAAA,MAAA,QAAoB,QAAQ,QAAQ;AAC1C,YAAW,UAAU,QAAQ;CAE7B,MAAM,YAAA,GAAA,MAAA,QAAkB,QAAQ,MAAM;AACtC,UAAS,UAAU,QAAQ;CAE3B,MAAM,gBAAA,GAAA,MAAA,QAAsB,QAAQ,UAAU;AAC9C,cAAa,UAAU,QAAQ;AAE/B,EAAA,GAAA,MAAA,iBAAgB;EACf,MAAM,KAAK,aAAa;AACxB,MAAI,CAAC,GAAI;EAET,IAAI,YAAY;EAChB,MAAM,aAAa,UAAU;EAC7B,MAAM,SACL,OAAO,eAAe,WACnB,IAAI,OAAO,IAAI,IAAI,YAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,KAA4B,EAAE,EAAE,MAAM,UAAU,CAAC,GACpE,YAAY;AAGhB,UAAA,SAAA,CAAA,WAAA,QAAA,oBAAA,CAAA,CAAA,MAAA,MAAA,EAAA,oBAAA,CAAkC,MAAM,EAAE,qBAAqB;AAC9D,OAAI,WAAW;AACd,WAAO,WAAW;AAClB;;GAGD,MAAM,OAAO,eAAe;IAC3B,QAAQ;IACR;IACA,WAAW,aAAa;IACxB,OAAOA,sBAAAA,mBAAmB,SAAS,QAAQ;IAC3C,CAAC;AACF,QAAK,OAAO;AACZ,eAAY,UAAU;AACtB,eAAY,KAAK;AACjB,cAAW,UAAU,KAAK;IACzB;AAEF,eAAa;AACZ,eAAY;AACZ,eAAY,SAAS,SAAS;AAC9B,eAAY,UAAU;AACtB,eAAY,KAAK;;IAGhB,EAAE,CAAC;AAEN,QAAO;EAAE;EAAc;EAAU;;;;;;;;;;;;;;;;;;;;;;;AC9DlC,SAAgB,SAAS,OAAiC;CACzD,MAAM,EAAE,cAAc,aAAa,YAAY;EAC9C,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,OAAO,MAAM;EACb,SAAS,MAAM;EACf,SAAS,MAAM;EACf,CAAC;AAGF,KAAI,OAAO,WAAW,YACrB,SAAA,GAAA,MAAA,eAAqB,OAAO;EAC3B,WAAW,MAAM;EACjB,OAAO,MAAM;EACb,CAAC;AAKH,SAAA,GAAA,MAAA,eACC,OACA;EAAE,WAAW,MAAM;EAAW,OAAO,MAAM;EAAO,EAClD,CAAC,YAAY,MAAM,WAAW,MAAM,WAAW,OAAA,GAAA,MAAA,eACjC,OAAO,EAAE,KAAK,cAAc,CAAC,CAC3C"}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { v as SerializedError } from "./base.cjs";
|
|
2
|
+
import { n as DebugOptions } from "./debug.cjs";
|
|
3
|
+
import { g as SchedulerConfig, r as AsyncDomInstance } from "./index.cjs";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/react/async-dom-component.d.ts
|
|
7
|
+
interface AsyncDomProps {
|
|
8
|
+
/** Worker script path or factory function */
|
|
9
|
+
worker: string | (() => Worker);
|
|
10
|
+
/** Scheduler configuration */
|
|
11
|
+
scheduler?: SchedulerConfig;
|
|
12
|
+
/** Enable debug mode (true for defaults, or pass DebugOptions) */
|
|
13
|
+
debug?: DebugOptions | boolean;
|
|
14
|
+
/** Fallback content shown while loading */
|
|
15
|
+
fallback?: ReactNode;
|
|
16
|
+
/** Called when the async-dom instance is ready */
|
|
17
|
+
onReady?: (instance: AsyncDomInstance) => void;
|
|
18
|
+
/** Called when a worker error occurs */
|
|
19
|
+
onError?: (error: SerializedError) => void;
|
|
20
|
+
/** CSS class name for the container div */
|
|
21
|
+
className?: string;
|
|
22
|
+
/** Inline styles for the container div */
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* React component that renders an async-dom worker application.
|
|
27
|
+
*
|
|
28
|
+
* Wraps {@link useAsyncDom} in a self-contained component with a container div.
|
|
29
|
+
* Supports a `fallback` prop for loading state, and passes through `className`
|
|
30
|
+
* and `style` to the container element.
|
|
31
|
+
*
|
|
32
|
+
* @param props - Component props.
|
|
33
|
+
* @returns A React element containing the async-dom container.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <AsyncDom
|
|
38
|
+
* worker="./app.worker.ts"
|
|
39
|
+
* fallback={<p>Loading...</p>}
|
|
40
|
+
* onReady={(instance) => console.log("ready", instance)}
|
|
41
|
+
* />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function AsyncDom(props: AsyncDomProps): ReactNode;
|
|
45
|
+
//# sourceMappingURL=async-dom-component.d.ts.map
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/react/use-async-dom.d.ts
|
|
48
|
+
interface UseAsyncDomOptions {
|
|
49
|
+
/** Worker script path or factory function */
|
|
50
|
+
worker: string | (() => Worker);
|
|
51
|
+
/** Scheduler configuration */
|
|
52
|
+
scheduler?: SchedulerConfig;
|
|
53
|
+
/** Debug options (pass `true` for sensible defaults, or a `DebugOptions` object) */
|
|
54
|
+
debug?: DebugOptions | boolean;
|
|
55
|
+
/** Called when the async-dom instance is ready */
|
|
56
|
+
onReady?: (instance: AsyncDomInstance) => void;
|
|
57
|
+
/** Called when a worker error occurs */
|
|
58
|
+
onError?: (error: SerializedError) => void;
|
|
59
|
+
}
|
|
60
|
+
interface UseAsyncDomResult {
|
|
61
|
+
/** Ref to attach to the container element */
|
|
62
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
63
|
+
/** The async-dom instance (null until ready) */
|
|
64
|
+
instance: AsyncDomInstance | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* React hook that creates and manages an async-dom instance.
|
|
68
|
+
*
|
|
69
|
+
* Attaches an async-dom worker to the container element referenced by
|
|
70
|
+
* `containerRef`. The instance is created on mount and destroyed on unmount.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Configuration for the async-dom instance.
|
|
73
|
+
* @returns An object containing the container ref and the instance (null until ready).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* function MyComponent() {
|
|
78
|
+
* const { containerRef, instance } = useAsyncDom({
|
|
79
|
+
* worker: "./my-worker.ts",
|
|
80
|
+
* onReady: (inst) => console.log("Ready!", inst),
|
|
81
|
+
* });
|
|
82
|
+
* return <div ref={containerRef} />;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useAsyncDom(options: UseAsyncDomOptions): UseAsyncDomResult;
|
|
87
|
+
//# sourceMappingURL=use-async-dom.d.ts.map
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { AsyncDom, type AsyncDomInstance, type AsyncDomProps, type DebugOptions, type SchedulerConfig, type SerializedError, type UseAsyncDomOptions, type UseAsyncDomResult, useAsyncDom };
|
|
91
|
+
//# sourceMappingURL=react.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.cts","names":[],"sources":["../src/react/async-dom-component.ts","../src/react/use-async-dom.ts"],"sourcesContent":[],"mappings":";;;;;;UAKiB,aAAA;;0BAEQ;EAFR;EAAa,SAAA,CAAA,EAIjB,eAJiB;;OAIjB,CAAA,EAEJ,YAFI,GAAA,OAAA;;UAID,CAAA,EAAA,SAAA;;SAIO,CAAA,EAAA,CAAA,QAAA,EAFG,gBAEH,EAAA,GAAA,IAAA;;EAIS,OAAA,CAAA,EAAA,CAAA,KAAA,EAJT,eAIS,EAAA,GAAA,IAAA;EAsBZ;EAAQ,SAAA,CAAA,EAAA,MAAA;;OAAwB,CAAA,EAtBvC,KAAA,CAAM,aAsBiC;;;;;ACtChD;;;;;;;;AAaA;;;;;;AA2BA;;AAAqC,iBDFrB,QAAA,CCEqB,KAAA,EDFL,aCEK,CAAA,EDFW,SCEX;;;;UAxCpB,kBAAA;;0BAEQ;;EDFR,SAAA,CAAA,ECIJ,eDJiB;EAAA;OAEL,CAAA,ECIhB,YDJgB,GAAA,OAAA;;SAIhB,CAAA,EAAA,CAAA,QAAA,ECEa,gBDFb,EAAA,GAAA,IAAA;;SAIa,CAAA,EAAA,CAAA,KAAA,ECAH,eDAG,EAAA,GAAA,IAAA;;AAMb,UCHQ,iBAAA,CDGF;EAAa;EAsBZ,YAAQ,ECvBT,KAAA,CAAM,SDuBG,CCvBO,cDuBP,GAAA,IAAA,CAAA;EAAA;UAAQ,ECrBrB,gBDqBqB,GAAA,IAAA;;;;;;ACtChC;;;;;;;;AAaA;;;;;;AA2BA;;AAAqC,iBAArB,WAAA,CAAqB,OAAA,EAAA,kBAAA,CAAA,EAAqB,iBAArB"}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { v as SerializedError } from "./base.js";
|
|
2
|
+
import { n as DebugOptions } from "./debug.js";
|
|
3
|
+
import { g as SchedulerConfig, r as AsyncDomInstance } from "./index.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/react/async-dom-component.d.ts
|
|
7
|
+
interface AsyncDomProps {
|
|
8
|
+
/** Worker script path or factory function */
|
|
9
|
+
worker: string | (() => Worker);
|
|
10
|
+
/** Scheduler configuration */
|
|
11
|
+
scheduler?: SchedulerConfig;
|
|
12
|
+
/** Enable debug mode (true for defaults, or pass DebugOptions) */
|
|
13
|
+
debug?: DebugOptions | boolean;
|
|
14
|
+
/** Fallback content shown while loading */
|
|
15
|
+
fallback?: ReactNode;
|
|
16
|
+
/** Called when the async-dom instance is ready */
|
|
17
|
+
onReady?: (instance: AsyncDomInstance) => void;
|
|
18
|
+
/** Called when a worker error occurs */
|
|
19
|
+
onError?: (error: SerializedError) => void;
|
|
20
|
+
/** CSS class name for the container div */
|
|
21
|
+
className?: string;
|
|
22
|
+
/** Inline styles for the container div */
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* React component that renders an async-dom worker application.
|
|
27
|
+
*
|
|
28
|
+
* Wraps {@link useAsyncDom} in a self-contained component with a container div.
|
|
29
|
+
* Supports a `fallback` prop for loading state, and passes through `className`
|
|
30
|
+
* and `style` to the container element.
|
|
31
|
+
*
|
|
32
|
+
* @param props - Component props.
|
|
33
|
+
* @returns A React element containing the async-dom container.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <AsyncDom
|
|
38
|
+
* worker="./app.worker.ts"
|
|
39
|
+
* fallback={<p>Loading...</p>}
|
|
40
|
+
* onReady={(instance) => console.log("ready", instance)}
|
|
41
|
+
* />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function AsyncDom(props: AsyncDomProps): ReactNode;
|
|
45
|
+
//# sourceMappingURL=async-dom-component.d.ts.map
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/react/use-async-dom.d.ts
|
|
48
|
+
interface UseAsyncDomOptions {
|
|
49
|
+
/** Worker script path or factory function */
|
|
50
|
+
worker: string | (() => Worker);
|
|
51
|
+
/** Scheduler configuration */
|
|
52
|
+
scheduler?: SchedulerConfig;
|
|
53
|
+
/** Debug options (pass `true` for sensible defaults, or a `DebugOptions` object) */
|
|
54
|
+
debug?: DebugOptions | boolean;
|
|
55
|
+
/** Called when the async-dom instance is ready */
|
|
56
|
+
onReady?: (instance: AsyncDomInstance) => void;
|
|
57
|
+
/** Called when a worker error occurs */
|
|
58
|
+
onError?: (error: SerializedError) => void;
|
|
59
|
+
}
|
|
60
|
+
interface UseAsyncDomResult {
|
|
61
|
+
/** Ref to attach to the container element */
|
|
62
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
63
|
+
/** The async-dom instance (null until ready) */
|
|
64
|
+
instance: AsyncDomInstance | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* React hook that creates and manages an async-dom instance.
|
|
68
|
+
*
|
|
69
|
+
* Attaches an async-dom worker to the container element referenced by
|
|
70
|
+
* `containerRef`. The instance is created on mount and destroyed on unmount.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Configuration for the async-dom instance.
|
|
73
|
+
* @returns An object containing the container ref and the instance (null until ready).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* function MyComponent() {
|
|
78
|
+
* const { containerRef, instance } = useAsyncDom({
|
|
79
|
+
* worker: "./my-worker.ts",
|
|
80
|
+
* onReady: (inst) => console.log("Ready!", inst),
|
|
81
|
+
* });
|
|
82
|
+
* return <div ref={containerRef} />;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useAsyncDom(options: UseAsyncDomOptions): UseAsyncDomResult;
|
|
87
|
+
//# sourceMappingURL=use-async-dom.d.ts.map
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { AsyncDom, type AsyncDomInstance, type AsyncDomProps, type DebugOptions, type SchedulerConfig, type SerializedError, type UseAsyncDomOptions, type UseAsyncDomResult, useAsyncDom };
|
|
91
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","names":[],"sources":["../src/react/async-dom-component.ts","../src/react/use-async-dom.ts"],"sourcesContent":[],"mappings":";;;;;;UAKiB,aAAA;;0BAEQ;EAFR;EAAa,SAAA,CAAA,EAIjB,eAJiB;;OAIjB,CAAA,EAEJ,YAFI,GAAA,OAAA;;UAID,CAAA,EAAA,SAAA;;SAIO,CAAA,EAAA,CAAA,QAAA,EAFG,gBAEH,EAAA,GAAA,IAAA;;EAIS,OAAA,CAAA,EAAA,CAAA,KAAA,EAJT,eAIS,EAAA,GAAA,IAAA;EAsBZ;EAAQ,SAAA,CAAA,EAAA,MAAA;;OAAwB,CAAA,EAtBvC,KAAA,CAAM,aAsBiC;;;;;ACtChD;;;;;;;;AAaA;;;;;;AA2BA;;AAAqC,iBDFrB,QAAA,CCEqB,KAAA,EDFL,aCEK,CAAA,EDFW,SCEX;;;;UAxCpB,kBAAA;;0BAEQ;;EDFR,SAAA,CAAA,ECIJ,eDJiB;EAAA;OAEL,CAAA,ECIhB,YDJgB,GAAA,OAAA;;SAIhB,CAAA,EAAA,CAAA,QAAA,ECEa,gBDFb,EAAA,GAAA,IAAA;;SAIa,CAAA,EAAA,CAAA,KAAA,ECAH,eDAG,EAAA,GAAA,IAAA;;AAMb,UCHQ,iBAAA,CDGF;EAAa;EAsBZ,YAAQ,ECvBT,KAAA,CAAM,SDuBG,CCvBO,cDuBP,GAAA,IAAA,CAAA;EAAA;UAAQ,ECrBrB,gBDqBqB,GAAA,IAAA;;;;;;ACtChC;;;;;;;;AAaA;;;;;;AA2BA;;AAAqC,iBAArB,WAAA,CAAqB,OAAA,EAAA,kBAAA,CAAA,EAAqB,iBAArB"}
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { t as resolveDebugOption } from "./resolve-debug.js";
|
|
2
|
+
import { createElement, useEffect, useRef, useState } from "react";
|
|
3
|
+
//#region src/react/use-async-dom.ts
|
|
4
|
+
/**
|
|
5
|
+
* React hook that creates and manages an async-dom instance.
|
|
6
|
+
*
|
|
7
|
+
* Attaches an async-dom worker to the container element referenced by
|
|
8
|
+
* `containerRef`. The instance is created on mount and destroyed on unmount.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Configuration for the async-dom instance.
|
|
11
|
+
* @returns An object containing the container ref and the instance (null until ready).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function MyComponent() {
|
|
16
|
+
* const { containerRef, instance } = useAsyncDom({
|
|
17
|
+
* worker: "./my-worker.ts",
|
|
18
|
+
* onReady: (inst) => console.log("Ready!", inst),
|
|
19
|
+
* });
|
|
20
|
+
* return <div ref={containerRef} />;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function useAsyncDom(options) {
|
|
25
|
+
const containerRef = useRef(null);
|
|
26
|
+
const [instance, setInstance] = useState(null);
|
|
27
|
+
const instanceRef = useRef(null);
|
|
28
|
+
const workerRef = useRef(options.worker);
|
|
29
|
+
workerRef.current = options.worker;
|
|
30
|
+
const onReadyRef = useRef(options.onReady);
|
|
31
|
+
onReadyRef.current = options.onReady;
|
|
32
|
+
const onErrorRef = useRef(options.onError);
|
|
33
|
+
onErrorRef.current = options.onError;
|
|
34
|
+
const debugRef = useRef(options.debug);
|
|
35
|
+
debugRef.current = options.debug;
|
|
36
|
+
const schedulerRef = useRef(options.scheduler);
|
|
37
|
+
schedulerRef.current = options.scheduler;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const el = containerRef.current;
|
|
40
|
+
if (!el) return;
|
|
41
|
+
let cancelled = false;
|
|
42
|
+
const workerProp = workerRef.current;
|
|
43
|
+
const worker = typeof workerProp === "string" ? new Worker(new URL(workerProp, import.meta.url), { type: "module" }) : workerProp();
|
|
44
|
+
import("./main-thread.js").then((n) => n.n).then(({ createAsyncDom }) => {
|
|
45
|
+
if (cancelled) {
|
|
46
|
+
worker.terminate();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const inst = createAsyncDom({
|
|
50
|
+
target: el,
|
|
51
|
+
worker,
|
|
52
|
+
scheduler: schedulerRef.current,
|
|
53
|
+
debug: resolveDebugOption(debugRef.current)
|
|
54
|
+
});
|
|
55
|
+
inst.start();
|
|
56
|
+
instanceRef.current = inst;
|
|
57
|
+
setInstance(inst);
|
|
58
|
+
onReadyRef.current?.(inst);
|
|
59
|
+
});
|
|
60
|
+
return () => {
|
|
61
|
+
cancelled = true;
|
|
62
|
+
instanceRef.current?.destroy();
|
|
63
|
+
instanceRef.current = null;
|
|
64
|
+
setInstance(null);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
return {
|
|
68
|
+
containerRef,
|
|
69
|
+
instance
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/react/async-dom-component.ts
|
|
74
|
+
/**
|
|
75
|
+
* React component that renders an async-dom worker application.
|
|
76
|
+
*
|
|
77
|
+
* Wraps {@link useAsyncDom} in a self-contained component with a container div.
|
|
78
|
+
* Supports a `fallback` prop for loading state, and passes through `className`
|
|
79
|
+
* and `style` to the container element.
|
|
80
|
+
*
|
|
81
|
+
* @param props - Component props.
|
|
82
|
+
* @returns A React element containing the async-dom container.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* <AsyncDom
|
|
87
|
+
* worker="./app.worker.ts"
|
|
88
|
+
* fallback={<p>Loading...</p>}
|
|
89
|
+
* onReady={(instance) => console.log("ready", instance)}
|
|
90
|
+
* />
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function AsyncDom(props) {
|
|
94
|
+
const { containerRef, instance } = useAsyncDom({
|
|
95
|
+
worker: props.worker,
|
|
96
|
+
scheduler: props.scheduler,
|
|
97
|
+
debug: props.debug,
|
|
98
|
+
onReady: props.onReady,
|
|
99
|
+
onError: props.onError
|
|
100
|
+
});
|
|
101
|
+
if (typeof window === "undefined") return createElement("div", {
|
|
102
|
+
className: props.className,
|
|
103
|
+
style: props.style
|
|
104
|
+
});
|
|
105
|
+
return createElement("div", {
|
|
106
|
+
className: props.className,
|
|
107
|
+
style: props.style
|
|
108
|
+
}, !instance && props.fallback ? props.fallback : null, createElement("div", { ref: containerRef }));
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { AsyncDom, useAsyncDom };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","names":[],"sources":["../src/react/use-async-dom.ts","../src/react/async-dom-component.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { DebugOptions, SchedulerConfig, SerializedError } from \"../index.ts\";\nimport type { AsyncDomInstance } from \"../main-thread/index.ts\";\nimport { resolveDebugOption } from \"../shared/resolve-debug.ts\";\n\nexport interface UseAsyncDomOptions {\n\t/** Worker script path or factory function */\n\tworker: string | (() => Worker);\n\t/** Scheduler configuration */\n\tscheduler?: SchedulerConfig;\n\t/** Debug options (pass `true` for sensible defaults, or a `DebugOptions` object) */\n\tdebug?: DebugOptions | boolean;\n\t/** Called when the async-dom instance is ready */\n\tonReady?: (instance: AsyncDomInstance) => void;\n\t/** Called when a worker error occurs */\n\tonError?: (error: SerializedError) => void;\n}\n\nexport interface UseAsyncDomResult {\n\t/** Ref to attach to the container element */\n\tcontainerRef: React.RefObject<HTMLDivElement | null>;\n\t/** The async-dom instance (null until ready) */\n\tinstance: AsyncDomInstance | null;\n}\n\n/**\n * React hook that creates and manages an async-dom instance.\n *\n * Attaches an async-dom worker to the container element referenced by\n * `containerRef`. The instance is created on mount and destroyed on unmount.\n *\n * @param options - Configuration for the async-dom instance.\n * @returns An object containing the container ref and the instance (null until ready).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { containerRef, instance } = useAsyncDom({\n * worker: \"./my-worker.ts\",\n * onReady: (inst) => console.log(\"Ready!\", inst),\n * });\n * return <div ref={containerRef} />;\n * }\n * ```\n */\nexport function useAsyncDom(options: UseAsyncDomOptions): UseAsyncDomResult {\n\tconst containerRef = useRef<HTMLDivElement | null>(null);\n\tconst [instance, setInstance] = useState<AsyncDomInstance | null>(null);\n\tconst instanceRef = useRef<AsyncDomInstance | null>(null);\n\n\t// Stabilize callback refs to prevent re-creation on re-renders\n\tconst workerRef = useRef(options.worker);\n\tworkerRef.current = options.worker;\n\n\tconst onReadyRef = useRef(options.onReady);\n\tonReadyRef.current = options.onReady;\n\n\tconst onErrorRef = useRef(options.onError);\n\tonErrorRef.current = options.onError;\n\n\tconst debugRef = useRef(options.debug);\n\tdebugRef.current = options.debug;\n\n\tconst schedulerRef = useRef(options.scheduler);\n\tschedulerRef.current = options.scheduler;\n\n\tuseEffect(() => {\n\t\tconst el = containerRef.current;\n\t\tif (!el) return;\n\n\t\tlet cancelled = false;\n\t\tconst workerProp = workerRef.current;\n\t\tconst worker =\n\t\t\ttypeof workerProp === \"string\"\n\t\t\t\t? new Worker(new URL(workerProp, import.meta.url), { type: \"module\" })\n\t\t\t\t: workerProp();\n\n\t\t// Dynamic import to avoid pulling main-thread code into SSR bundles\n\t\timport(\"../main-thread/index.ts\").then(({ createAsyncDom }) => {\n\t\t\tif (cancelled) {\n\t\t\t\tworker.terminate();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst inst = createAsyncDom({\n\t\t\t\ttarget: el,\n\t\t\t\tworker,\n\t\t\t\tscheduler: schedulerRef.current,\n\t\t\t\tdebug: resolveDebugOption(debugRef.current),\n\t\t\t});\n\t\t\tinst.start();\n\t\t\tinstanceRef.current = inst;\n\t\t\tsetInstance(inst);\n\t\t\tonReadyRef.current?.(inst);\n\t\t});\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tinstanceRef.current?.destroy();\n\t\t\tinstanceRef.current = null;\n\t\t\tsetInstance(null);\n\t\t};\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, []);\n\n\treturn { containerRef, instance };\n}\n","import { createElement, type ReactNode } from \"react\";\nimport type { DebugOptions, SchedulerConfig, SerializedError } from \"../index.ts\";\nimport type { AsyncDomInstance } from \"../main-thread/index.ts\";\nimport { useAsyncDom } from \"./use-async-dom.ts\";\n\nexport interface AsyncDomProps {\n\t/** Worker script path or factory function */\n\tworker: string | (() => Worker);\n\t/** Scheduler configuration */\n\tscheduler?: SchedulerConfig;\n\t/** Enable debug mode (true for defaults, or pass DebugOptions) */\n\tdebug?: DebugOptions | boolean;\n\t/** Fallback content shown while loading */\n\tfallback?: ReactNode;\n\t/** Called when the async-dom instance is ready */\n\tonReady?: (instance: AsyncDomInstance) => void;\n\t/** Called when a worker error occurs */\n\tonError?: (error: SerializedError) => void;\n\t/** CSS class name for the container div */\n\tclassName?: string;\n\t/** Inline styles for the container div */\n\tstyle?: React.CSSProperties;\n}\n\n/**\n * React component that renders an async-dom worker application.\n *\n * Wraps {@link useAsyncDom} in a self-contained component with a container div.\n * Supports a `fallback` prop for loading state, and passes through `className`\n * and `style` to the container element.\n *\n * @param props - Component props.\n * @returns A React element containing the async-dom container.\n *\n * @example\n * ```tsx\n * <AsyncDom\n * worker=\"./app.worker.ts\"\n * fallback={<p>Loading...</p>}\n * onReady={(instance) => console.log(\"ready\", instance)}\n * />\n * ```\n */\nexport function AsyncDom(props: AsyncDomProps): ReactNode {\n\tconst { containerRef, instance } = useAsyncDom({\n\t\tworker: props.worker,\n\t\tscheduler: props.scheduler,\n\t\tdebug: props.debug,\n\t\tonReady: props.onReady,\n\t\tonError: props.onError,\n\t});\n\n\t// SSR guard: render only the container div\n\tif (typeof window === \"undefined\") {\n\t\treturn createElement(\"div\", {\n\t\t\tclassName: props.className,\n\t\t\tstyle: props.style,\n\t\t});\n\t}\n\n\t// Fallback is rendered as a sibling before the container to avoid\n\t// conflicting with createAsyncDom's DOM manipulation of the target element.\n\treturn createElement(\n\t\t\"div\",\n\t\t{ className: props.className, style: props.style },\n\t\t!instance && props.fallback ? props.fallback : null,\n\t\tcreateElement(\"div\", { ref: containerRef }),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,YAAY,SAAgD;CAC3E,MAAM,eAAe,OAA8B,KAAK;CACxD,MAAM,CAAC,UAAU,eAAe,SAAkC,KAAK;CACvE,MAAM,cAAc,OAAgC,KAAK;CAGzD,MAAM,YAAY,OAAO,QAAQ,OAAO;AACxC,WAAU,UAAU,QAAQ;CAE5B,MAAM,aAAa,OAAO,QAAQ,QAAQ;AAC1C,YAAW,UAAU,QAAQ;CAE7B,MAAM,aAAa,OAAO,QAAQ,QAAQ;AAC1C,YAAW,UAAU,QAAQ;CAE7B,MAAM,WAAW,OAAO,QAAQ,MAAM;AACtC,UAAS,UAAU,QAAQ;CAE3B,MAAM,eAAe,OAAO,QAAQ,UAAU;AAC9C,cAAa,UAAU,QAAQ;AAE/B,iBAAgB;EACf,MAAM,KAAK,aAAa;AACxB,MAAI,CAAC,GAAI;EAET,IAAI,YAAY;EAChB,MAAM,aAAa,UAAU;EAC7B,MAAM,SACL,OAAO,eAAe,WACnB,IAAI,OAAO,IAAI,IAAI,YAAY,OAAO,KAAK,IAAI,EAAE,EAAE,MAAM,UAAU,CAAC,GACpE,YAAY;AAGhB,SAAO,oBAAA,MAAA,MAAA,EAAA,EAAA,CAA2B,MAAM,EAAE,qBAAqB;AAC9D,OAAI,WAAW;AACd,WAAO,WAAW;AAClB;;GAGD,MAAM,OAAO,eAAe;IAC3B,QAAQ;IACR;IACA,WAAW,aAAa;IACxB,OAAO,mBAAmB,SAAS,QAAQ;IAC3C,CAAC;AACF,QAAK,OAAO;AACZ,eAAY,UAAU;AACtB,eAAY,KAAK;AACjB,cAAW,UAAU,KAAK;IACzB;AAEF,eAAa;AACZ,eAAY;AACZ,eAAY,SAAS,SAAS;AAC9B,eAAY,UAAU;AACtB,eAAY,KAAK;;IAGhB,EAAE,CAAC;AAEN,QAAO;EAAE;EAAc;EAAU;;;;;;;;;;;;;;;;;;;;;;;AC9DlC,SAAgB,SAAS,OAAiC;CACzD,MAAM,EAAE,cAAc,aAAa,YAAY;EAC9C,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,OAAO,MAAM;EACb,SAAS,MAAM;EACf,SAAS,MAAM;EACf,CAAC;AAGF,KAAI,OAAO,WAAW,YACrB,QAAO,cAAc,OAAO;EAC3B,WAAW,MAAM;EACjB,OAAO,MAAM;EACb,CAAC;AAKH,QAAO,cACN,OACA;EAAE,WAAW,MAAM;EAAW,OAAO,MAAM;EAAO,EAClD,CAAC,YAAY,MAAM,WAAW,MAAM,WAAW,MAC/C,cAAc,OAAO,EAAE,KAAK,cAAc,CAAC,CAC3C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/shared/resolve-debug.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a `debug` option that can be `true`, a `DebugOptions` object, or `undefined`.
|
|
4
|
+
* `true` expands to sensible defaults; falsy values resolve to `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* Shared across all framework adapters to avoid logic drift.
|
|
7
|
+
*/
|
|
8
|
+
function resolveDebugOption(debug) {
|
|
9
|
+
if (debug === true) return {
|
|
10
|
+
logMutations: true,
|
|
11
|
+
logEvents: true,
|
|
12
|
+
exposeDevtools: true
|
|
13
|
+
};
|
|
14
|
+
return debug || void 0;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
Object.defineProperty(exports, "resolveDebugOption", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return resolveDebugOption;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=resolve-debug.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-debug.cjs","names":[],"sources":["../src/shared/resolve-debug.ts"],"sourcesContent":["import type { DebugOptions } from \"../core/debug.ts\";\n\n/**\n * Resolves a `debug` option that can be `true`, a `DebugOptions` object, or `undefined`.\n * `true` expands to sensible defaults; falsy values resolve to `undefined`.\n *\n * Shared across all framework adapters to avoid logic drift.\n */\nexport function resolveDebugOption(\n\tdebug: DebugOptions | boolean | undefined,\n): DebugOptions | undefined {\n\tif (debug === true) {\n\t\treturn { logMutations: true, logEvents: true, exposeDevtools: true };\n\t}\n\treturn debug || undefined;\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,mBACf,OAC2B;AAC3B,KAAI,UAAU,KACb,QAAO;EAAE,cAAc;EAAM,WAAW;EAAM,gBAAgB;EAAM;AAErE,QAAO,SAAS,KAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/shared/resolve-debug.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a `debug` option that can be `true`, a `DebugOptions` object, or `undefined`.
|
|
4
|
+
* `true` expands to sensible defaults; falsy values resolve to `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* Shared across all framework adapters to avoid logic drift.
|
|
7
|
+
*/
|
|
8
|
+
function resolveDebugOption(debug) {
|
|
9
|
+
if (debug === true) return {
|
|
10
|
+
logMutations: true,
|
|
11
|
+
logEvents: true,
|
|
12
|
+
exposeDevtools: true
|
|
13
|
+
};
|
|
14
|
+
return debug || void 0;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { resolveDebugOption as t };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=resolve-debug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-debug.js","names":[],"sources":["../src/shared/resolve-debug.ts"],"sourcesContent":["import type { DebugOptions } from \"../core/debug.ts\";\n\n/**\n * Resolves a `debug` option that can be `true`, a `DebugOptions` object, or `undefined`.\n * `true` expands to sensible defaults; falsy values resolve to `undefined`.\n *\n * Shared across all framework adapters to avoid logic drift.\n */\nexport function resolveDebugOption(\n\tdebug: DebugOptions | boolean | undefined,\n): DebugOptions | undefined {\n\tif (debug === true) {\n\t\treturn { logMutations: true, logEvents: true, exposeDevtools: true };\n\t}\n\treturn debug || undefined;\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,mBACf,OAC2B;AAC3B,KAAI,UAAU,KACb,QAAO;EAAE,cAAc;EAAM,WAAW;EAAM,gBAAgB;EAAM;AAErE,QAAO,SAAS,KAAA"}
|