zenith 1.0.0-beta.15 → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # Zenith
2
2
 
3
- Zenith is a tiny reactive JavaScript framework with a virtual DOM, keyed reconciliation, and targeted component redraws. Its rendering model can update an entire application or a specific component, which is useful when parts of a page manage their own content, such as canvas, WebGL, and SVG interfaces.
3
+ Zenith is a tiny JavaScript virtual DOM framework with keyed reconciliation and targeted component redraws. Its rendering model can update an entire application or a specific component, making it easy to integrate independently managed content such as canvas, WebGL, and SVG interfaces.
4
4
 
5
5
  Zenith supports component lifecycle hooks, memoization, DOM events, SVG and MathML, and optional helpers. It is inspired by [Mithril.js](https://github.com/MithrilJS/mithril.js).
6
6
 
7
- **Status:** Zenith is currently in beta. We aim to keep the API stable through 1.0.0, but breaking changes may still occur during the beta period.
7
+ **Status:** Zenith 1.0.0 is currently in release candidate. The API is expected to remain stable through the final 1.0 release, with changes focused primarily on bug fixes.
8
8
 
9
9
  ## Installation
10
10
 
11
- Install the beta package:
11
+ Install the release candidate:
12
12
 
13
13
  ```sh
14
- npm install zenith@beta
14
+ npm install zenith@rc
15
15
  ```
16
16
 
17
17
  Import the functions you need:
@@ -20,7 +20,7 @@ Import the functions you need:
20
20
  import { bind, comp, compDef, elem } from 'zenith';
21
21
  ```
22
22
 
23
- Prebuilt browser files are also included in `dist/`. The `zenith.global.js` build is intended for direct browser use; the `zenith.js` build is an ES module.
23
+ Prebuilt browser files are also included in `dist/`. The `zenith.js` build is an ES module, while `zenith.global.js` exposes the Zenith API through window.z for direct browser use.
24
24
 
25
25
  ## Example: counter
26
26
 
@@ -50,14 +50,14 @@ Prebuilt browser files are also included in `dist/`. The `zenith.global.js` buil
50
50
  </html>
51
51
  ```
52
52
 
53
- The example assumes an environment that resolves npm package imports, such as a bundler or development server. Event handlers automatically schedule a redraw unless the event's `draw` property is set to `false`.
53
+ The example assumes an environment that resolves npm package imports, such as a bundler or development server. Event handlers automatically schedule a redraw unless the event's `redraw` property is set to `false`.
54
54
 
55
55
  ## Components and redraws
56
56
 
57
- Create components with `compDef()` and `comp()`, then mount them using `bind()`. Call `draw()` when external state changes outside an event handler:
57
+ Create components with `compDef()` and `comp()`, then mount them using `bind()`. Call `redraw()` when application state changes outside an event handler:
58
58
 
59
59
  ```js
60
- import { bind, comp, compDef, draw, elem } from 'zenith';
60
+ import { bind, comp, compDef, redraw, elem } from 'zenith';
61
61
 
62
62
  let message = 'Hello';
63
63
 
@@ -69,19 +69,21 @@ const view = comp(Message);
69
69
  bind(document.querySelector('#app'), view);
70
70
 
71
71
  message = 'Updated';
72
- draw(view);
72
+ redraw(view);
73
73
  ```
74
74
 
75
- Redraws are scheduled in a microtask. Call `sync()` if you need to apply queued redraws immediately. `draw(view, true)` requests a targeted redraw of a component.
75
+ Redraws are batched and scheduled in a microtask. Call `sync()` to apply queued redraws immediately. Use `redraw(view, true)` to redraw only the specified component subtree.
76
76
 
77
- Component definitions can use `init`, `draw`, `drawn`, `remove`, and `removed` lifecycle hooks. `remove` may return a Promise to defer removal. Components also support optional memoization through `$memo`.
77
+ Component definitions support `init`, `draw`, `drawn`, `remove`, and `removed` lifecycle hooks. The `remove` hook may return a Promise to defer removal; deferred removal requires keyed components. Components also support optional memoization through `$memo`.
78
+
79
+ Zenith does not manage application state or automatically track dependencies. State can be stored and updated using ordinary JavaScript, external state managers, or optional helpers.
78
80
 
79
81
  ## Package builds
80
82
 
81
83
  The npm package includes prebuilt files under `dist/`, including:
82
84
 
83
85
  - `zenith.js` — ES module
84
- - `zenith.global.js` — global browser build
86
+ - `zenith.global.js` — browser build exposing window.z
85
87
  - `zenith.development.js` — development build
86
88
  - `zenith-helpers.js` — optional helpers (import from `zenith/helpers`)
87
89
 
@@ -89,7 +91,7 @@ The library is designed for a very small compressed footprint; actual size depen
89
91
 
90
92
  ## Documentation
91
93
 
92
- Additional information: [Zenith website](https://aleph-1.com/zenith) (work in progress).
94
+ Additional information: [Zenith website](https://aleph-1.com/zenith).
93
95
 
94
96
  Report bugs and request features through [GitHub Issues](https://github.com/aleph1/Zenith/issues).
95
97
 
@@ -16,4 +16,6 @@ export interface DerivedSignal<T> extends Signal<T> {
16
16
  * // In component cleanup:
17
17
  * removed: () => fullName.destroy()
18
18
  */
19
- export declare const derived: <T>(fn: () => T, deps: Signal<any>[]) => DerivedSignal<T>;
19
+ export declare const derived: <T>(fn: () => T, deps: {
20
+ sub(fn: () => void): () => void;
21
+ }[]) => DerivedSignal<T>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Renders children into another DOM location using an independent
3
+ * Zenith root. Useful for modals, popovers, and overlays.
4
+ *
5
+ * Unlike native portals:
6
+ * - Children do not inherit the originating component's ancestry
7
+ * or injected context.
8
+ * - Events follow the destination DOM tree.
9
+ * - An extra wrapper <div> is inserted into the target.
10
+ * - Rendering into the target is deferred to a microtask.
11
+ *
12
+ * The helper manages mounting, updates, and cleanup, but not
13
+ * stacking, positioning, focus, or accessibility.
14
+ *
15
+ * @example
16
+ * comp(DetachedRoot, {
17
+ * to: document.body, // Or a CSS selector such as '#modals'
18
+ * children: comp(Modal)
19
+ * });
20
+ */
21
+ import type { VNodeCompAttributes, VNodeCompDefinition, VNodeAny, VNodeArray } from '../vnode.defs';
22
+ interface DetachedRootAttrs extends VNodeCompAttributes {
23
+ to: string | Element;
24
+ children: VNodeAny | VNodeArray;
25
+ }
26
+ declare const definition: VNodeCompDefinition<DetachedRootAttrs>;
27
+ export declare const DetachedRoot: typeof definition;
28
+ export {};
@@ -10,4 +10,4 @@ export type { Signal } from './signal';
10
10
  export { derived } from './derived';
11
11
  export type { DerivedSignal } from './derived';
12
12
  export { router } from './router';
13
- export { Portal } from './portal';
13
+ export { DetachedRoot } from './detached-root';
@@ -15,7 +15,10 @@ export declare const diff: {
15
15
  all: number;
16
16
  };
17
17
  export declare const sync: () => void;
18
- export declare const draw: (vNode: VNodeContainer, surgical?: boolean) => void;
18
+ export declare const redraw: {
19
+ (vNode: VNodeContainer, surgical?: false): void;
20
+ (vNode: VNodeComp, surgical: true): void;
21
+ };
19
22
  export declare const elem: {
20
23
  (tag: string): VNodeElem;
21
24
  (tag: string, attrs: VNodeElemAttributes, ...args: VNodeArray): VNodeElem;
@@ -1,8 +1,9 @@
1
1
  export declare const VNODE_ELEM = 1;
2
2
  export declare const VNODE_TEXT = 2;
3
- export declare const VNODE_COMP = 3;
4
- export declare const VNODE_NODE = 4;
5
- export declare const VNODE_COMPDEF = 5;
3
+ export declare const VNODE_COMP = 4;
4
+ export declare const VNODE_NODE = 8;
5
+ export declare const VNODE_COMPDEF = 16;
6
+ export declare const VNODE_TYPE_MASK = 31;
6
7
  export interface VNodeElemAttributes {
7
8
  class?: string | string[];
8
9
  style?: string | Record<string, string | number | null | undefined>;
@@ -16,15 +17,11 @@ export interface VNodeElemAttributes {
16
17
  export interface VNodeCompAttributes {
17
18
  $key?: string | number;
18
19
  $remove?: boolean;
19
- to?: string | Element;
20
20
  [property: string]: any;
21
21
  }
22
22
  export type VNodeAttrs = VNodeElemAttributes | VNodeCompAttributes;
23
- export interface VNodeNodeAttributes {
24
- [property: string]: any;
25
- }
26
23
  export interface VNodeCompDefinition<A extends VNodeCompAttributes = VNodeCompAttributes> {
27
- $tag?: number;
24
+ $t?: number;
28
25
  init?: (vNode: VNodeComp<A>) => void;
29
26
  draw: (vNode: VNodeComp<A>, oldChildren?: VNodeFlatArray) => VNodeAnyOrArray;
30
27
  drawn?: (vNode: VNodeComp<A>, isFirstDraw?: boolean) => void;
@@ -34,36 +31,39 @@ export interface VNodeCompDefinition<A extends VNodeCompAttributes = VNodeCompAt
34
31
  }
35
32
  interface VNodeBase {
36
33
  $h?: boolean;
37
- up: VNodeContainer | null;
34
+ $p: VNodeContainer | null;
38
35
  nodes: VNodeFlatArray | null;
39
36
  el: any;
40
37
  }
41
38
  export interface VNodeElem extends VNodeBase {
42
39
  is: typeof VNODE_ELEM;
43
- $tag: string;
44
- $def: null;
40
+ $t: string;
41
+ $d: null;
45
42
  attrs: VNodeElemAttributes;
46
43
  nodes: VNodeFlatArray;
47
44
  }
48
45
  export interface VNodeText extends VNodeBase {
49
46
  is: typeof VNODE_TEXT;
50
- $tag: string;
51
- $def: null;
47
+ $t: string;
48
+ $d: null;
52
49
  attrs: null;
53
50
  nodes: null;
54
51
  }
55
52
  export interface VNodeComp<A extends VNodeCompAttributes = VNodeCompAttributes> extends VNodeBase {
56
53
  is: typeof VNODE_COMP;
57
- $tag: number;
58
- $def: VNodeCompDefinition;
54
+ $t: number;
55
+ $d: VNodeCompDefinition;
56
+ $r?: object | null;
59
57
  attrs: A;
60
58
  nodes: VNodeFlatArray;
61
59
  provide?: Record<string, any>;
60
+ /** Optional, application-managed instance state. */
61
+ state?: Record<string, any>;
62
62
  }
63
63
  export interface VNodeNode extends VNodeBase {
64
64
  is: typeof VNODE_NODE;
65
- $tag: number;
66
- $def: null;
65
+ $t: number;
66
+ $d: null;
67
67
  attrs: null;
68
68
  nodes: null;
69
69
  }
@@ -77,6 +77,6 @@ export type VNodeChild = VNodeAny | string | number | boolean | null | undefined
77
77
  export type VNodeArray = Array<VNodeChild | VNodeArray>;
78
78
  export type VNodeAnyOrArray = VNodeChild | VNodeArray;
79
79
  export interface VNodeFlatArray extends Array<VNodeAny> {
80
- $keys?: Map<any, any> | null;
80
+ $keys?: boolean;
81
81
  }
82
82
  export {};