meowjsx 0.2.0-alpha.0 → 0.3.0-alpha.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/JSON.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  ```ts
6
6
  import { createJsonView, defineJsonComponent, jsonSchema, parseJsonView } from "meowjsx/json";
7
- import { h, signal, type MaybeSignal } from "meowjsx";
7
+ import { h } from "meowjsx";
8
+ import { signal, type MaybeSignal } from "meowjsx/signal";
8
9
 
9
10
  const Label = (props: { text: MaybeSignal<string> }) => h("span", null, props.text);
10
11
  const catalog = new Map([
package/README.md CHANGED
@@ -16,6 +16,18 @@ Synchronous HTML output follows the same ancestor rule, but still does not suppo
16
16
  It is called in the order `pre`, normal, `post`, and within each group's registration order; the first non-`undefined` result wins, and returning the original function also stops resolution; the result is not resolved recursively. Selection happens before the lifecycle scope is created, and the selected component uses its own metadata, parts and cleanup logic while the original component does not execute. `props` is a read-only typed view and does not copy or freeze the object.
17
17
 
18
18
  This hook belongs to the execution runtime: pre-created VNodes, Signal/Promise deferred mounts and synchronous HTML all apply. The cleanup returned by `runtime.use()` unmounts rules and does not rewrite already mounted instances; other runtimes are unaffected.
19
+
20
+ `RuntimePlugin.prepareContainer({ runtime, container, target })` prepares a container before a target
21
+ renderer mounts into it, such as delivering a stylesheet to its document, and returns the cleanup.
22
+ The core types the container as `unknown`; the plugin narrows it by `target` (`"web"` passes the
23
+ container Element). `runtime.targetHooks.prepareContainer(container, target)` runs the hooks in
24
+ `pre`, normal, `post` order and returns one cleanup that releases them in reverse; a target calls it,
25
+ hosts do not. `meowjsx/web` `render` prepares the container before the tree mounts and releases it
26
+ after `unmount()` removes the tree. If a hook or the synchronous first render throws, what was
27
+ acquired is released and the error propagates; asynchronous render failures go to `onError` and
28
+ release nothing early. Release continues past a failing cleanup and rethrows the first error.
29
+ `renderToHtml` runs no hook. Uninstalling a plugin releases the containers it prepared, and a plugin
30
+ installed after a render reaches only later renders.
19
31
  It does not intercept module side effects or direct function calls, and does not change the meaning of the `create` / `render` hooks.
20
32
 
21
33
  ## Development metadata and instance observation
@@ -79,9 +91,12 @@ meowjsx (this package: core + JSX contract)
79
91
 
80
92
  ## Exports
81
93
 
82
- - `.`, `./runtime`: `h`, `Fragment`, `raw`, `signal`/`batch`/`mapSignal`/`derived`,
83
- `createRuntime`, `defaultRuntime`, `defineShadow`, `createThemePlugin`, part descriptor helpers,
84
- plus VNode/Signal/metadata, `Context` and generic ref types.
94
+ - `.`, `./runtime`: `h`, `Fragment`, `raw`, `createRuntime`, `defaultRuntime`, `defineShadow`,
95
+ `createThemePlugin`, part descriptor helpers, plus VNode/metadata, `Context` and generic ref types.
96
+ Existing reactive exports remain available and share the implementation below.
97
+ - `./signal`: `signal`, `batch`, `mapSignal`, `derived`, `isSignal`, `unwrap`, and the
98
+ `ReadableSignal`, `WritableSignal`, `Signal` and `MaybeSignal` types. This DOM-free entry loads
99
+ the reactive implementation without creating a runtime or renderer.
85
100
  - `./renderer`: `RenderStrategy<TNode>`, `createRenderer()`, `Renderer`/`Rendered`/
86
101
  `RendererOptions`, `ComponentObserver`/`ObservedComponent` and other target-seam types. `createRenderer()` injects component lifecycle,
87
102
  render hooks, overrides and `key`/`componentPart` identity; the target only implements node and attribute placement.
@@ -95,6 +110,16 @@ meowjsx (this package: core + JSX contract)
95
110
  The core root has no `render`/`renderToHtml`: `render(node, Element)` and HTML serialization are imported from
96
111
  `meowjsx/web`. The root does not import Web back; both use the same core module, and multiple explicit Runtimes can still be created independently.
97
112
 
113
+ ### API migration
114
+
115
+ - Use `defineShadow(component, part, setup)` in place of the removed `shadow` alias. It creates a
116
+ definition; register it through `createRuntime({ shadows: [...] })` or a runtime plugin. Setup runs
117
+ when the target mounts the matching part. Core keeps the host handle generic; `meowjsx/web` types
118
+ it as `Element`.
119
+ - Use `renderer.render(node, parent, before?)` on the target-neutral renderer and
120
+ `web.render(node, container)` on the Web renderer. Both return an `unmount()` handle. The `mount`
121
+ methods and top-level Web `mount` export are removed; static output remains `renderToHtml`.
122
+
98
123
  ## Invariant: core contains no platform
99
124
 
100
125
  The core source (including types) does not contain `document`, `window`, DOM `Element`/`HTMLElement`,
@@ -119,6 +144,9 @@ empty strings. They do not merge conflicting classes or interpret objects as cla
119
144
  The native `class` attribute follows the same runtime normalization.
120
145
 
121
146
  ```tsx
147
+ import { h } from "meowjsx";
148
+ import { signal } from "meowjsx/signal";
149
+
122
150
  const stateClass = signal("is-idle");
123
151
  <div className={["panel", [false, stateClass], "host-panel"]} />;
124
152
  stateClass.value = "is-active";
@@ -134,7 +162,11 @@ public `ClassValue` type is available to components that forward `className`.
134
162
  Components are ordinary functions. A static `meta` declares their stable name and finite parts;
135
163
  `Context<typeof Component>` supplies the lifecycle and a typed `parts` map. Use
136
164
  `Context<typeof Component, ComponentProps>` when setup also needs the declared types of
137
- `context.props`. Setup runs once per mount, and Signals carry later changes.
165
+ `context.props`. Setup runs once per mount, and Signals carry later changes. Import `signal`
166
+ directly from `meowjsx/signal` and create local state inside setup; each mount creates its own Signals.
167
+ `context.effect` and `context.onCleanup` manage effects and cleanup for that mount. Signals have no
168
+ dispose operation; the renderer releases its binding subscriptions on unmount. Register any manual
169
+ subscription's unsubscribe function with `context.onCleanup`.
138
170
 
139
171
  ```tsx
140
172
  import { h, type Context, type Props } from "meowjsx";
@@ -200,6 +232,36 @@ its lifecycle is managed by the consumer, and no global observation tree is crea
200
232
  Public JS artifacts preserve module relationships: the root, runtime, automatic JSX and Web entries reference the same core.
201
233
  Release builds must not copy a defaultRuntime, Context or reactive scheduler per entry.
202
234
 
235
+ ## Signal interoperability
236
+
237
+ Import reactive functions and types from `meowjsx/signal`:
238
+
239
+ ```ts
240
+ import { signal, mapSignal, derived, batch, type ReadableSignal } from "meowjsx/signal";
241
+ ```
242
+
243
+ The renderer's `SignalLike<T>` type from `meowjsx/renderer` describes its structural input protocol.
244
+ MeowJSX's `ReadableSignal<T>` and compatible external implementations satisfy that protocol. JSX
245
+ bindings accept any object with this shape; no MeowJSX constructor or brand is required:
246
+
247
+ ```ts
248
+ interface SignalLike<T> {
249
+ readonly value: T;
250
+ subscribe(listener: (value: T) => void): () => void;
251
+ }
252
+ ```
253
+
254
+ `value` returns the current value. `subscribe` reports changed values and returns an unsubscribe
255
+ function. The renderer reads the initial value, subscribes for updates and unsubscribes on unmount.
256
+ `mapSignal(source, map)` also subscribes explicitly, so it works with external implementations.
257
+ A third-party API with a different shape needs an adapter to this contract.
258
+
259
+ Automatic dependency tracking in `context.effect` and `derived` requires getters from the shared
260
+ MeowJSX reactive implementation. Reading an external Signal's `.value` alone does not register it as
261
+ a dependency; this also applies to component logic that uses those computations. Use `mapSignal`
262
+ for an explicit source, or subscribe directly and register the unsubscribe function with
263
+ `context.onCleanup`. The root, runtime and signal entries share one reactive module and scheduler.
264
+
203
265
  ## Derived signals
204
266
 
205
267
  `derived(read)` is a read-only signal. `read` runs again when any signal it read changes, and subscribers hear the value when `Object.is` says it changed. `read` must not write signals. One source can also use `mapSignal`. A computation is not stored by writing another signal from `effect`.
@@ -210,6 +272,9 @@ Release builds must not copy a defaultRuntime, Context or reactive scheduler per
210
272
  a deletion releases that row's lifecycle, and reordering moves the existing range. Whole-replacement semantics for plain arrays and Signals are unchanged.
211
273
 
212
274
  ```ts
275
+ import { h, keyed } from "meowjsx";
276
+ import { mapSignal, signal } from "meowjsx/signal";
277
+
213
278
  const items = signal([{ id: "one", label: "First" }]);
214
279
  const rows = keyed(
215
280
  items,
@@ -1,8 +1,8 @@
1
1
  import type { Cleanup, LifecycleScope, Runtime } from "./types.js";
2
2
  /**
3
3
  * Create a lifecycle scope. Components receive one per invocation; a target
4
- * that mounts a shadow uses the same primitive so signals, effects, and
5
- * cleanups follow one ownership rule.
4
+ * that mounts a shadow uses the same primitive so effects and cleanups follow
5
+ * one ownership rule.
6
6
  */
7
7
  export declare function createLifecycleScope(runtime: Runtime): LifecycleScope & {
8
8
  dispose(): void;
@@ -1,8 +1,8 @@
1
- import { createReactiveEffect, signal } from "./reactive.js";
1
+ import { createReactiveEffect } from "./reactive.js";
2
2
  /**
3
3
  * Create a lifecycle scope. Components receive one per invocation; a target
4
- * that mounts a shadow uses the same primitive so signals, effects, and
5
- * cleanups follow one ownership rule.
4
+ * that mounts a shadow uses the same primitive so effects and cleanups follow
5
+ * one ownership rule.
6
6
  */
7
7
  export function createLifecycleScope(runtime) {
8
8
  let active = true;
@@ -23,7 +23,6 @@ export function createLifecycleScope(runtime) {
23
23
  };
24
24
  return {
25
25
  runtime,
26
- signal,
27
26
  effect(run) {
28
27
  const stop = createReactiveEffect(run);
29
28
  onCleanup(stop);
@@ -1,4 +1,4 @@
1
- import type { AnyShadowDefinition, Child, Cleanup, Component, ComponentMeta, ComponentRegistry, ComponentRenderContext, CreateContext, CreateHook, LifecycleScope, Props, RegisteredComponent, RenderHook, ResolveComponentHook, Runtime, RuntimePluginEnforce, ShadowRegistry, VNode } from "./types.js";
1
+ import type { AnyShadowDefinition, Child, Cleanup, Component, ComponentMeta, ComponentRegistry, ComponentRenderContext, CreateContext, CreateHook, LifecycleScope, Props, RegisteredComponent, RenderHook, ResolveComponentHook, PrepareContainerHook, Runtime, RuntimePluginEnforce, ShadowRegistry, VNode } from "./types.js";
2
2
  import { type ContextScope } from "./context.js";
3
3
  export interface HookEntry<Hook> {
4
4
  readonly handler: Hook;
@@ -8,6 +8,7 @@ export interface RuntimeState {
8
8
  createHooks: HookEntry<CreateHook>[];
9
9
  renderHooks: HookEntry<RenderHook>[];
10
10
  resolveComponentHooks: HookEntry<ResolveComponentHook>[];
11
+ containerHooks: HookEntry<PrepareContainerHook>[];
11
12
  shadowRegistry: ShadowRegistry;
12
13
  overrides: Map<string, Component<any>>;
13
14
  }
@@ -116,7 +116,6 @@ export interface Renderer<TNode> {
116
116
  insert(parent: TNode, node: TNode, before?: TNode | null): void;
117
117
  remove(node: TNode): void;
118
118
  setProperty(node: TNode, name: string, value: unknown): void | RendererCleanup;
119
- mount(node: RenderableChild, parent: TNode, before?: TNode | null): Rendered<TNode>;
120
119
  render(node: RenderableChild, parent: TNode, before?: TNode | null): Rendered<TNode>;
121
120
  }
122
121
  /**
@@ -1,5 +1,5 @@
1
1
  import { isKeyedChild, readKeyedEntries } from "./keyed.js";
2
- import { signal } from "./reactive.js";
2
+ import { isAsyncIterable, isPromiseLike, isSignal, signal } from "./reactive.js";
3
3
  import { normalizeClassName } from "./style.js";
4
4
  import { isNormalizedRef, mountRefBindings } from "./parts.js";
5
5
  export { createComponentObservation, } from "./observation.js";
@@ -34,23 +34,6 @@ function tryCleanups(cleanups) {
34
34
  function isRecord(value) {
35
35
  return typeof value === "object" && value !== null;
36
36
  }
37
- function isSignal(value) {
38
- return ((typeof value === "object" || typeof value === "function") &&
39
- value !== null &&
40
- "value" in value &&
41
- "subscribe" in value &&
42
- typeof value.subscribe === "function");
43
- }
44
- function isPromiseLike(value) {
45
- return ((typeof value === "object" || typeof value === "function") &&
46
- value !== null &&
47
- typeof value.then === "function");
48
- }
49
- function isAsyncIterable(value) {
50
- return ((typeof value === "object" || typeof value === "function") &&
51
- value !== null &&
52
- typeof value[Symbol.asyncIterator] === "function");
53
- }
54
37
  function isVNode(value) {
55
38
  if (!isRecord(value) || !("type" in value) || !("props" in value))
56
39
  return false;
@@ -576,7 +559,7 @@ export function createRenderer(strategy, options = {}) {
576
559
  throw error;
577
560
  }
578
561
  }
579
- const mount = (node, parent, before = null) => {
562
+ const render = (node, parent, before = null) => {
580
563
  const mounted = mountChild(node, parent, before);
581
564
  return {
582
565
  nodes: mounted.nodes,
@@ -592,7 +575,6 @@ export function createRenderer(strategy, options = {}) {
592
575
  insert: (parent, node, before) => strategy.insert(parent, node, before),
593
576
  remove: (node) => strategy.remove(node),
594
577
  setProperty: (node, name, value) => strategy.setProperty(node, name, value),
595
- mount,
596
- render: mount,
578
+ render,
597
579
  };
598
580
  }
@@ -3,14 +3,13 @@ export { keyed, type KeyedChild } from "./keyed.js";
3
3
  export { createPartDescriptor, isPartDescriptor } from "./parts.js";
4
4
  export type { PartDescriptor, RefBinding, RefCallback, RefCleanup } from "./parts.js";
5
5
  import type { Child, Cleanup, ComponentMeta, Component, HFactory, ShadowDefinition, ShadowSetup, FragmentComponent, Props, Runtime, RuntimeOptions, RuntimePluginOption, VNode } from "./types.js";
6
- export type { Child, ClassValue, Cleanup, Component, ComponentMeta, ComponentMetadata, ComponentPartRef, ComponentRegistry, ComponentRegistryMap, ComponentRenderContext, Context, CreateContext, CreateHook, Effect, ElementType, FragmentComponent, Key, LifecycleScope, MaybeSignal, MountResult, Props, ReadableSignal, RegisteredComponent, RegisteredComponentName, RegisteredComponentPart, RenderContext, RenderHook, ResolveComponentContext, ResolveComponentHook, Runtime, RuntimeOptions, RuntimePlugin, RuntimePluginContext, RuntimePluginEnforce, RuntimePluginOption, RuntimePluginSetup, RuntimeRendererOptions, RuntimeTargetHooks, ShadowContext, ShadowDefinition, ShadowRegistry, ShadowSetup, Signal, StyleObject, StyleScalar, StyleValue, Theme, ThemeContext, ThemeRule, ThemeRules, ThemeStyle, VNode, WritableSignal, } from "./types.js";
6
+ export type { Child, ClassValue, Cleanup, Component, ComponentMeta, ComponentMetadata, ComponentPartRef, ComponentRegistry, ComponentRegistryMap, ComponentRenderContext, Context, CreateContext, CreateHook, Effect, ElementType, FragmentComponent, Key, LifecycleScope, MaybeSignal, MountResult, PrepareContainerHook, Props, ReadableSignal, RegisteredComponent, RegisteredComponentName, RegisteredComponentPart, RenderContext, RenderHook, ResolveComponentContext, ResolveComponentHook, Runtime, ContainerContext, RuntimeOptions, RuntimePlugin, RuntimePluginContext, RuntimePluginEnforce, RuntimePluginOption, RuntimePluginSetup, RuntimeRendererOptions, RuntimeTargetHooks, ShadowContext, ShadowDefinition, ShadowRegistry, ShadowSetup, Signal, StyleObject, StyleScalar, StyleValue, Theme, ThemeContext, ThemeRule, ThemeRules, ThemeStyle, VNode, WritableSignal, } from "./types.js";
7
7
  export { batch, isAsyncIterable, isPromiseLike, derived, isSignal, mapSignal, signal, unwrap, } from "./reactive.js";
8
8
  export { createLifecycleScope } from "./lifecycle.js";
9
9
  export { createThemePlugin, styleText } from "./style.js";
10
10
  export declare function defineShadow<C extends Component<any, any> & {
11
11
  readonly meta: ComponentMeta;
12
12
  }, Part extends C["meta"]["parts"][number], TNode = unknown>(component: C, part: Part, setup: ShadowSetup<Parameters<C>[0], C["meta"]["name"], Part, TNode>): ShadowDefinition<Parameters<C>[0], C["meta"]["name"], C["meta"]["parts"][number], Part, TNode>;
13
- export declare const shadow: typeof defineShadow;
14
13
  export declare function createRuntime(options?: RuntimeOptions): Runtime;
15
14
  export declare const defaultRuntime: Runtime;
16
15
  export declare const registry: import("./types.js").ComponentRegistry;
@@ -28,17 +28,19 @@ export function defineShadow(component, part, setup) {
28
28
  setup,
29
29
  };
30
30
  }
31
- export const shadow = defineShadow;
32
31
  export function createRuntime(options = {}) {
33
32
  const state = {
34
33
  createHooks: [],
35
34
  renderHooks: [],
36
35
  resolveComponentHooks: [],
36
+ containerHooks: [],
37
37
  shadowRegistry: createShadowRegistry(options.shadows),
38
38
  overrides: new Map(Object.entries(options.overrides ?? {})),
39
39
  };
40
40
  const registry = createComponentRegistry(options.components ?? []);
41
41
  const runtime = {};
42
+ // The cleanups each mount hook still owes, so uninstalling its plugin can release them.
43
+ const activeMounts = new Map();
42
44
  const installPlugin = (plugin) => {
43
45
  let createEntry;
44
46
  let renderEntry;
@@ -88,6 +90,17 @@ export function createRuntime(options = {}) {
88
90
  renderEntry = addHook(state.renderHooks, plugin.render, plugin.enforce);
89
91
  contributionCleanups.push(() => removeHook(state.renderHooks, renderEntry));
90
92
  }
93
+ if (plugin.prepareContainer) {
94
+ const entry = addHook(state.containerHooks, plugin.prepareContainer, plugin.enforce);
95
+ const owed = new Set();
96
+ activeMounts.set(entry, owed);
97
+ contributionCleanups.push(() => {
98
+ removeHook(state.containerHooks, entry);
99
+ activeMounts.delete(entry);
100
+ });
101
+ // Runs before the hook is removed: a mount the plugin prepared does not outlive it.
102
+ contributionCleanups.push(() => disposeCleanups([...owed]));
103
+ }
91
104
  if (plugin.resolveComponent) {
92
105
  const entry = addHook(state.resolveComponentHooks, plugin.resolveComponent, plugin.enforce);
93
106
  contributionCleanups.push(() => removeHook(state.resolveComponentHooks, entry));
@@ -196,6 +209,43 @@ export function createRuntime(options = {}) {
196
209
  },
197
210
  transformVNode: (vnode) => runRenderHooks(state, runtime, vnode),
198
211
  replacementFor: (vnode) => replacementFor(state, vnode),
212
+ prepareContainer(container, target) {
213
+ const acquired = [];
214
+ try {
215
+ for (const entry of state.containerHooks.slice()) {
216
+ const cleanup = entry.handler({ runtime, container, target });
217
+ if (typeof cleanup !== "function")
218
+ continue;
219
+ const owed = activeMounts.get(entry);
220
+ let released = false;
221
+ const once = () => {
222
+ if (released)
223
+ return;
224
+ released = true;
225
+ owed?.delete(once);
226
+ cleanup();
227
+ };
228
+ owed?.add(once);
229
+ acquired.push(once);
230
+ }
231
+ }
232
+ catch (error) {
233
+ try {
234
+ disposeCleanups(acquired);
235
+ }
236
+ catch {
237
+ // Preserve the mount hook's error; rollback is best-effort.
238
+ }
239
+ throw error;
240
+ }
241
+ let active = true;
242
+ return () => {
243
+ if (!active)
244
+ return;
245
+ active = false;
246
+ disposeCleanups(acquired);
247
+ };
248
+ },
199
249
  };
200
250
  const createRenderer = (strategy, rendererOptions = {}) => {
201
251
  const defaultOnMount = (vnode) => {
@@ -0,0 +1,2 @@
1
+ export { batch, derived, isSignal, mapSignal, signal, unwrap } from "./reactive.js";
2
+ export type { MaybeSignal, ReadableSignal, Signal, WritableSignal } from "./types.js";
@@ -0,0 +1 @@
1
+ export { batch, derived, isSignal, mapSignal, signal, unwrap } from "./reactive.js";
@@ -49,7 +49,6 @@ export interface ComponentRegistry {
49
49
  }
50
50
  export interface LifecycleScope {
51
51
  readonly runtime: Runtime;
52
- signal<T>(initialValue: T): WritableSignal<T>;
53
52
  effect(run: Effect): Cleanup;
54
53
  onCleanup(cleanup: Cleanup): void;
55
54
  }
@@ -151,6 +150,19 @@ export interface RuntimePluginContext {
151
150
  onCleanup(cleanup: Cleanup): void;
152
151
  }
153
152
  export type RuntimePluginSetup = (context: RuntimePluginContext) => void | Cleanup;
153
+ /** What a target renderer hands a plugin when it prepares a container for a mount. */
154
+ export interface ContainerContext {
155
+ readonly runtime: Runtime;
156
+ /** The node the target renders into; meowjsx/web passes the container Element. */
157
+ readonly container: unknown;
158
+ /** The target that mounts, such as "web"; a plugin narrows `container` by it. */
159
+ readonly target: string;
160
+ }
161
+ /**
162
+ * Prepares a container before a target renders into it, such as delivering a stylesheet to its
163
+ * document. The returned cleanup runs after that mount's tree is removed.
164
+ */
165
+ export type PrepareContainerHook = (context: ContainerContext) => void | Cleanup;
154
166
  export type RuntimePlugin = {
155
167
  name?: string;
156
168
  enforce?: RuntimePluginEnforce;
@@ -158,6 +170,8 @@ export type RuntimePlugin = {
158
170
  create?: CreateHook;
159
171
  render?: RenderHook;
160
172
  resolveComponent?: ResolveComponentHook;
173
+ /** Runs when a target renderer mounts into a container; not for static output. */
174
+ prepareContainer?: PrepareContainerHook;
161
175
  shadows?: readonly AnyShadowDefinition[];
162
176
  overrides?: Record<string, Component<any>>;
163
177
  components?: readonly RegisteredComponent[];
@@ -183,6 +197,12 @@ export interface RuntimeTargetHooks {
183
197
  };
184
198
  transformVNode(vnode: VNode): VNode;
185
199
  replacementFor(vnode: VNode): Component<any, any> | undefined;
200
+ /**
201
+ * Runs the installed plugins' `prepareContainer` hooks for one container, in plugin order, and returns
202
+ * the cleanup that releases them in reverse. A target renderer calls it before rendering into
203
+ * the container and calls the cleanup after the tree is removed.
204
+ */
205
+ prepareContainer(container: unknown, target: string): Cleanup;
186
206
  }
187
207
  export type FragmentComponent = (props: {
188
208
  children?: Child;
@@ -1,5 +1,5 @@
1
1
  export type { WebRef, WebRefCallback, WebRefCleanup, WebHostProps, WebIntrinsicElements, } from "./types.js";
2
- export { createWebRenderer, defaultWebRenderer, mount, render, renderToHtml, type WebRenderer, type WebRendererOptions, } from "./render.js";
2
+ export { createWebRenderer, defaultWebRenderer, render, renderToHtml, type WebRenderer, type WebRendererOptions, } from "./render.js";
3
3
  export { renderToHtmlWithRuntime } from "./html.js";
4
4
  export { useWebObservation } from "./observation.js";
5
5
  export { createDomStrategy, setDOMProperty, type DomNode } from "./strategy.js";
package/dist/web/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createWebRenderer, defaultWebRenderer, mount, render, renderToHtml, } from "./render.js";
1
+ export { createWebRenderer, defaultWebRenderer, render, renderToHtml, } from "./render.js";
2
2
  export { renderToHtmlWithRuntime } from "./html.js";
3
3
  export { useWebObservation } from "./observation.js";
4
4
  export { createDomStrategy, setDOMProperty } from "./strategy.js";
@@ -9,7 +9,6 @@ import { type DomNode } from "./strategy.js";
9
9
  export interface WebRenderer {
10
10
  readonly runtime: Runtime;
11
11
  readonly render: (node: Child, container: Element) => MountResult;
12
- readonly mount: (node: Child, container: Element) => MountResult;
13
12
  readonly renderToHtml: (node: Child) => string;
14
13
  }
15
14
  export type WebRendererOptions = Pick<RendererOptions<DomNode>, "onError" | "observer"> & {
@@ -19,5 +18,4 @@ export declare function createWebRenderer(runtime?: Runtime, options?: WebRender
19
18
  /** The default runtime's Web renderer; apps that install into it use this one. */
20
19
  export declare const defaultWebRenderer: WebRenderer;
21
20
  export declare const render: (node: Child, container: Element) => MountResult;
22
- export declare const mount: (node: Child, container: Element) => MountResult;
23
21
  export declare const renderToHtml: (node: Child) => string;
@@ -25,13 +25,36 @@ export function createWebRenderer(runtime = defaultRuntime, options = {}) {
25
25
  const child = options.observation
26
26
  ? h(WebObservationContext.Provider, { value: options.observation }, node)
27
27
  : node;
28
- const mounted = renderer.mount(child, container, null);
29
- return { unmount: () => mounted.unmount() };
28
+ // Plugins prepare the container first, so a stylesheet or theme root exists when component
29
+ // setup and refs run; they are released after the tree is gone.
30
+ const release = runtime.targetHooks.prepareContainer(container, "web");
31
+ let mounted;
32
+ try {
33
+ mounted = renderer.render(child, container, null);
34
+ }
35
+ catch (error) {
36
+ try {
37
+ release();
38
+ }
39
+ catch {
40
+ // Preserve the render error; the release is best-effort.
41
+ }
42
+ throw error;
43
+ }
44
+ return {
45
+ unmount: () => {
46
+ try {
47
+ mounted.unmount();
48
+ }
49
+ finally {
50
+ release();
51
+ }
52
+ },
53
+ };
30
54
  };
31
55
  return {
32
56
  runtime,
33
57
  render,
34
- mount: render,
35
58
  renderToHtml: (node) => renderToHtmlWithRuntime(runtime, node),
36
59
  };
37
60
  }
@@ -43,5 +66,4 @@ function defaultMember(key) {
43
66
  return defaultWebRenderer[key];
44
67
  }
45
68
  export const render = /* @__PURE__ */ defaultMember("render");
46
- export const mount = /* @__PURE__ */ defaultMember("mount");
47
69
  export const renderToHtml = /* @__PURE__ */ defaultMember("renderToHtml");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meowjsx",
3
- "version": "0.2.0-alpha.0",
3
+ "version": "0.3.0-alpha.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/src/runtime.d.ts",
26
26
  "import": "./dist/src/runtime.js"
27
27
  },
28
+ "./signal": {
29
+ "types": "./dist/src/signal.d.ts",
30
+ "import": "./dist/src/signal.js"
31
+ },
28
32
  "./renderer": {
29
33
  "types": "./dist/src/renderer.d.ts",
30
34
  "import": "./dist/src/renderer.js"