incajs 0.0.16 → 0.0.17

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.
@@ -1,29 +1,25 @@
1
- import { IncaEventTarget, NodeId } from '../rendererCore.mts';
1
+ import { IncaEventTarget } from '../types.mts';
2
2
  import { RectLike } from './geometry.mts';
3
3
  import { ScrollIntoViewOptions, ScrollOptions } from './scroll.mts';
4
4
  /**
5
5
  * A container node: either a real element or the hidden stand-in that
6
6
  * `createCommentNode` makes. It is the only node type that can act as a
7
- * parent.
8
- *
9
- * `inca`'s native tree has no parent pointers and no way to list a
10
- * node's children, so `parent`/`children` are maintained here as a
11
- * JS-side shadow of the tree, kept in sync by `insert` and
12
- * `remove`.
7
+ * parent. `parent` and `children` read the node's current position in the
8
+ * tree.
13
9
  *
14
10
  * After the node is removed, `addEventListener()` and `removeEventListener()`
15
11
  * ignore the call, and `dispatchEvent()` returns `true`.
16
12
  */
17
13
  export interface IncaElement extends IncaEventTarget {
18
14
  /**
19
- * The underlying native node's id, the only part of this object the native
20
- * tree itself knows about.
15
+ * The `id` attribute, or an empty string when it is unset. Assigning sets
16
+ * the attribute to the value as a string. After the node is removed,
17
+ * reading gives an empty string and assigning does nothing.
21
18
  */
22
- readonly id: NodeId;
19
+ id: string;
23
20
  /**
24
- * `"comment"` for the hidden stand-in `createCommentNode`
25
- * makes; `"element"` for every other container. Purely
26
- * informational: both render identically once created.
21
+ * `"comment"` for the hidden stand-in `createCommentNode` makes;
22
+ * `"element"` for every other container.
27
23
  */
28
24
  readonly kind: "element" | "comment";
29
25
  /** The current parent, or `null` if this node isn't attached to the tree. */
@@ -45,6 +41,13 @@ export interface IncaElement extends IncaEventTarget {
45
41
  * own click is still running and an unknown node ignore the call.
46
42
  */
47
43
  click(): void;
44
+ /**
45
+ * Whether `other` is this node or one of its descendants in the tree as
46
+ * rendered. `null` and `undefined` give `false`, and any other value that is
47
+ * not a node throws a `TypeError`. After the node is removed, it still answers
48
+ * for the subtree it keeps.
49
+ */
50
+ contains(other: IncaNode | null): boolean;
48
51
  /**
49
52
  * Assigning sets the `tabindex` attribute to the value's integer part,
50
53
  * wrapped to 32 bits. Reading returns the `tabindex` attribute as an
@@ -104,8 +107,6 @@ export interface IncaElement extends IncaEventTarget {
104
107
  }
105
108
  /** A text leaf node. */
106
109
  export interface IncaText {
107
- /** The underlying native node's id. */
108
- readonly id: NodeId;
109
110
  /** Discriminates this node within the {@link IncaNode} union. */
110
111
  readonly kind: "text";
111
112
  /** The current parent, or `null` if this node isn't attached to the tree. */
package/dist/events.d.mts CHANGED
@@ -14,8 +14,9 @@ export declare function latestEventId(): number;
14
14
  * See the `EventListener` type for the fields an event carries.
15
15
  * @param nodeId - the node to listen on
16
16
  * @param event - the event name (e.g. `"click"`)
17
- * @param listener - a function, or an object whose `handleEvent` method is
18
- * called with the object as `this` when the event fires
17
+ * @param listener - a function, called with the event's `currentTarget` as
18
+ * `this`, or an object whose `handleEvent` method is called with the object
19
+ * as `this` when the event fires
19
20
  * @param options - `capture` listens while the event travels down to the
20
21
  * target, `passive` ignores `preventDefault()` calls in `listener`, and
21
22
  * `once` removes the listener before it first runs
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- import { f as e, v as t } from "./chunks/rendererCore-U_s1R1v7.js";
2
- import { t as n } from "./chunks/handle-B1h0qxex.js";
3
- //#region src/window.mts
4
- var r = /* @__PURE__ */ t(e, ["wheel"]);
5
- //#endregion
6
- export { n as activeElement, r as window };
1
+ import { t as e } from "./chunks/hooks-BgB7lzTv.js";
2
+ import { t } from "./chunks/handle-SWQTonXe.js";
3
+ export { t as activeElement, e as window };
package/dist/native.d.mts CHANGED
@@ -17,6 +17,8 @@ interface IncaNative {
17
17
  addEventListener(nodeId: NodeId, event: string, capture?: boolean, passive?: boolean): CallbackId;
18
18
  removeEventListener(nodeId: NodeId, event: string, callbackId: CallbackId): boolean;
19
19
  destroyNode(nodeId: NodeId): CallbackId[];
20
+ holdNode(nodeId: NodeId): void;
21
+ releaseNode(nodeId: NodeId): void;
20
22
  focusNode(nodeId: NodeId, preventScroll?: boolean): void;
21
23
  blurNode(nodeId: NodeId): void;
22
24
  focusedNode(): NodeId | null;
@@ -32,6 +34,8 @@ export type HostCallback = (...args: unknown[]) => void;
32
34
  declare global {
33
35
  var __inca_native__: IncaNative;
34
36
  var __inca_callbacks__: Record<CallbackId, HostCallback>;
37
+ var __inca_released__: (nodeIds: NodeId[], callbackIds: CallbackId[]) => void;
38
+ var __inca_targets__: (nodeIds: NodeId[]) => unknown[];
35
39
  }
36
40
  export declare function native(): IncaNative;
37
41
  export {};
@@ -1,12 +1,14 @@
1
1
  export { createEventTarget } from './eventTarget.mts';
2
+ export { window } from './window.mts';
2
3
  export { addEventListener, removeEventListener, latestEventId, focus, blur, dispatchEvent, click, } from './events.mts';
3
- export { focusedNode, appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, getAttribute, layoutOf, scrollOf, scrollNode, scrollIntoViewNode, removeAttribute, setStyle, removeStyle, } from './tree.mts';
4
+ export { focusedNode, appendChild, createNode, destroyNode, holdNode, releaseNode, insertBefore, removeChild, rootNodeId, setAttribute, getAttribute, layoutOf, scrollOf, scrollNode, scrollIntoViewNode, removeAttribute, setStyle, removeStyle, } from './tree.mts';
5
+ export { createIncaElement } from './element/handle.mts';
6
+ export { isDestroyed } from './element/lifecycle.mts';
7
+ export { createCommentNode, createElementNode, createTextNode, insert, nextSibling, parentNode, remove, setElementText, setText, } from './element/shadowTree.mts';
4
8
  export type * from './types.mts';
9
+ export type * from './element/types.mts';
5
10
  /**
6
- * The tree/event primitives a custom renderer (`incajs/vue`) drives the
7
- * native tree through.
8
- *
9
- * Also the seam a renderer's own tests mock against, in place of a real
10
- * `globalThis.__inca_native__`.
11
+ * What a custom renderer (`incajs/vue`) drives the host through: the tree and
12
+ * event calls, the element handles and the shadow tree.
11
13
  */
12
14
  export type IncaCore = typeof import('./rendererCore.mts');
@@ -1 +1,4 @@
1
- export { y as addEventListener, n as appendChild, b as blur, x as click, v as createEventTarget, r as createNode, i as destroyNode, S as dispatchEvent, C as focus, a as focusedNode, o as getAttribute, s as insertBefore, w as latestEventId, c as layoutOf, l as removeAttribute, u as removeChild, T as removeEventListener, d as removeStyle, f as rootNodeId, p as scrollIntoViewNode, m as scrollNode, h as scrollOf, g as setAttribute, _ as setStyle } from "./chunks/rendererCore-U_s1R1v7.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, u as c } from "./chunks/rendererCore-BWT8KFVJ.js";
2
+ import { C as l, D as u, E as d, N as f, S as p, T as m, _ as h, a as g, b as _, c as v, d as y, f as b, g as x, h as S, i as C, k as w, l as T, m as E, n as D, o as O, p as k, r as A, s as j, t as M, u as N, v as P, w as F, x as I, y as L } from "./chunks/hooks-BgB7lzTv.js";
3
+ import { n as R } from "./chunks/handle-SWQTonXe.js";
4
+ export { I as addEventListener, D as appendChild, p as blur, l as click, i as createCommentNode, o as createElementNode, _ as createEventTarget, R as createIncaElement, A as createNode, n as createTextNode, C as destroyNode, F as dispatchEvent, m as focus, g as focusedNode, O as getAttribute, j as holdNode, e as insert, v as insertBefore, w as isDestroyed, d as latestEventId, T as layoutOf, a as nextSibling, s as parentNode, N as releaseNode, f as releaseWhenCollected, t as remove, y as removeAttribute, b as removeChild, u as removeEventListener, k as removeStyle, E as rootNodeId, S as scrollIntoViewNode, x as scrollNode, h as scrollOf, P as setAttribute, r as setElementText, L as setStyle, c as setText, M as window };
@@ -0,0 +1 @@
1
+ export {};
package/dist/tree.d.mts CHANGED
@@ -8,7 +8,9 @@ import { AttributeValue, NodeId, ScrollAlignment, StyleProps, TagName } from './
8
8
  export declare function rootNodeId(): NodeId;
9
9
  /**
10
10
  * Allocates a new node of kind `tag` in the native tree. The node starts out
11
- * detached. Attach it with {@link appendChild}/{@link insertBefore}.
11
+ * detached. Attach it with {@link appendChild}/{@link insertBefore}. The host
12
+ * frees the node at the start of the next frame unless it is inserted or held
13
+ * with {@link holdNode} by then.
12
14
  * @param tag - the node's element kind
13
15
  * @returns the new node's id
14
16
  */
@@ -24,17 +26,16 @@ export declare function appendChild(parentId: NodeId, childId: NodeId): void;
24
26
  * Attaches `childId` as a child of `parentId`, positioned before `anchorId`
25
27
  * (or at the end, if `anchorId` is `null`). If `anchorId` names a real node
26
28
  * that just isn't currently a child of `parentId`, this falls back to
27
- * appending at the end instead of throwing. Only a wholly unknown
28
- * `anchorId` raises.
29
+ * appending at the end. Only a wholly unknown `anchorId` raises.
29
30
  * @param parentId - the container to attach to
30
31
  * @param childId - the node being attached
31
32
  * @param anchorId - the sibling to insert before, or `null` to append at the end
32
33
  */
33
34
  export declare function insertBefore(parentId: NodeId, childId: NodeId, anchorId: NodeId | null): void;
34
35
  /**
35
- * Detaches `childId` from `parentId`. The detached node stays alive and keeps
36
- * its own children, so it can be re-attached elsewhere. Use
37
- * {@link destroyNode} for a node that isn't coming back.
36
+ * Detaches `childId` from `parentId`. The detached node keeps its own children
37
+ * and is freed at the start of the next frame unless it is inserted or held
38
+ * with {@link holdNode} by then. Use {@link destroyNode} to free it at once.
38
39
  * @param parentId - the current container
39
40
  * @param childId - the node being detached
40
41
  */
@@ -44,11 +45,24 @@ export declare function removeChild(parentId: NodeId, childId: NodeId): void;
44
45
  * event listener registered anywhere in it. Destroying an already-destroyed
45
46
  * node does nothing. The host's own root cannot be destroyed and raises.
46
47
  *
47
- * Nothing else frees a node: a subtree dropped with {@link removeChild}
48
- * alone stays allocated for the life of the engine.
48
+ * Also drops the hold of {@link holdNode}.
49
49
  * @param nodeId - the node that isn't coming back
50
50
  */
51
51
  export declare function destroyNode(nodeId: NodeId): void;
52
+ /**
53
+ * Keeps `nodeId` and its subtree alive while it has no parent. The host frees
54
+ * a parentless node that is neither held nor inserted by the start of the next
55
+ * frame. Holding a held or attached node changes nothing visible.
56
+ * @param nodeId - the node to keep
57
+ * @throws {TypeError} when `nodeId` names no node
58
+ */
59
+ export declare function holdNode(nodeId: NodeId): void;
60
+ /**
61
+ * Ends the hold of {@link holdNode}. A node with no parent is freed at the
62
+ * start of the next frame. An unknown id does nothing.
63
+ * @param nodeId - the node to let go
64
+ */
65
+ export declare function releaseNode(nodeId: NodeId): void;
52
66
  /**
53
67
  * Sets a non-style attribute/prop on `nodeId`. See {@link setStyle} for
54
68
  * layout/paint properties, which live in a separate map.
package/dist/types.d.mts CHANGED
@@ -9,8 +9,8 @@ export type NodeId = number;
9
9
  */
10
10
  export type CallbackId = number;
11
11
  /**
12
- * A value `setAttribute`/`setStyle` can take. Anything else raises a catchable
13
- * exception rather than being silently coerced.
12
+ * A value `setAttribute`/`setStyle` can take. Any other value raises a catchable
13
+ * exception.
14
14
  */
15
15
  export type AttributeValue = string | number | boolean;
16
16
  /**
@@ -28,7 +28,7 @@ export type ScrollAlignment = "start" | "center" | "end" | "nearest";
28
28
  * overload checks. A deliberately incomplete, v1 layout/paint vocabulary. The
29
29
  * renderer also reads the camelCase and kebab-case spellings. An unrecognized
30
30
  * key or a value shape that doesn't parse (e.g. a malformed enum string) is
31
- * ignored by the renderer rather than applied or thrown.
31
+ * ignored by the renderer.
32
32
  */
33
33
  export interface StyleProps {
34
34
  /** Layout mode for this node's children. `"none"` skips both layout and rendering for the whole subtree. */
@@ -136,8 +136,9 @@ export interface IncaEventTarget {
136
136
  * same `type` and `capture` again changes nothing. A `null` listener is
137
137
  * ignored.
138
138
  * @param type - the event name (e.g. `"keydown"`)
139
- * @param listener - a function, or an object whose `handleEvent` method is
140
- * called when the event fires
139
+ * @param listener - a function, called with the event's `currentTarget` as
140
+ * `this`, or an object whose `handleEvent` method is called with the object
141
+ * as `this` when the event fires
141
142
  * @param options - a {@link ListenerOptions}, or a boolean for `capture`
142
143
  */
143
144
  addEventListener(type: string, listener: EventListenerOrObject | null, options?: boolean | ListenerOptions): void;
@@ -164,12 +165,15 @@ export interface IncaEventTarget {
164
165
  *
165
166
  * The native host calls it with one argument, an object with:
166
167
  * - `type`: the event's name.
167
- * - `target`: the {@link NodeId} the event is about. It is the deepest node
168
- * under the pointer for pointer events, the nearest common ancestor of the
169
- * press and the release for `click`, `dblclick` and `auxclick`, and the
170
- * focused node (the root when nothing is focused) for key events.
171
- * - `currentTarget`: the {@link NodeId} whose listener is running, and
172
- * `null` once the event has been handled.
168
+ * - `target`: the element the event is about, or `window`. It is the deepest
169
+ * element under the pointer for pointer events, the nearest common ancestor
170
+ * of the press and the release for `click`, `dblclick` and `auxclick`, and
171
+ * the focused element for key events. With no such element it is `window`.
172
+ * - `currentTarget`: the element or `window` whose listener is running, and
173
+ * `null` once the event has been handled. A listener function runs with it
174
+ * as `this`.
175
+ * - `composedPath()`: `target` and its ancestors, ending with `window`, and an
176
+ * empty array once the event has been handled.
173
177
  * - `bubbles`, `cancelable` and `composed`: fixed per event name.
174
178
  * - `defaultPrevented`: `true` once a listener called `preventDefault()` on a
175
179
  * cancelable event.
@@ -1,19 +1,18 @@
1
1
  import { App, Component, ComponentPublicInstance } from '@vue/runtime-core';
2
- import { IncaElement } from '../element/types.mts';
2
+ import { IncaElement } from '../rendererCore.mts';
3
3
  /**
4
- * `@vue/runtime-core`'s `App`, with `mount` additionally callable with no
5
- * argument to target the host's own root container. An intersection rather
6
- * than an `Omit`: `App`'s `this`-returning methods (`use`, `mixin`,
7
- * `component`, `directive`) have to keep this wider `mount` when chained.
4
+ * `@vue/runtime-core`'s `App`, with `mount` also callable with no argument
5
+ * to target the host's own root container. `use`, `mixin`, `component` and
6
+ * `directive` return an `IncaApp`.
8
7
  */
9
8
  export type IncaApp = App<IncaElement> & {
10
9
  mount: (rootContainer?: IncaElement) => ComponentPublicInstance;
11
10
  };
12
11
  /**
13
- * Creates a Vue app whose root mounts against a {@link IncaElement} host
14
- * handle instead of a DOM element. `app.mount()` with no argument targets
15
- * the host's root container; `app.unmount`, `app.use`, etc. all behave
16
- * exactly as `@vue/runtime-core` itself documents them.
12
+ * Creates a Vue app whose root mounts on an {@link IncaElement} host
13
+ * handle. `app.mount()` with no argument targets the host's root
14
+ * container and returns the root component instance. `app.unmount`,
15
+ * `app.use` and the rest behave as `@vue/runtime-core` documents them.
17
16
  * @param rootComponent - the component to mount as the app's root
18
17
  * @param rootProps - props to pass to that root component
19
18
  * @returns the created app
@@ -1,6 +1,5 @@
1
1
  import { RendererOptions } from '@vue/runtime-core';
2
- import { IncaElement, IncaNode } from '../element/types.mts';
3
- import { IncaCore } from '../rendererCore.mts';
2
+ import { IncaCore, IncaElement, IncaNode } from '../rendererCore.mts';
4
3
  /**
5
4
  * Marks `handle` so that Vue's `reactive()` and `ref()` keep the object itself.
6
5
  * A template ref then holds the same object the application receives from
@@ -18,3 +17,13 @@ export type NodeOps = Omit<RendererOptions<IncaNode, IncaElement>, "patchProp">;
18
17
  * @param core - the incajs bindings to drive the native tree through
19
18
  */
20
19
  export declare function createNodeOps(core: IncaCore): NodeOps;
20
+ type Creators = Pick<NodeOps, "createElement" | "createText">;
21
+ /**
22
+ * The creators of `ops` that hold the node they create and release the hold
23
+ * once the returned handle is collected.
24
+ * @param core - the incajs bindings the holds go through
25
+ * @param ops - the creators to wrap
26
+ * @returns held versions of `createElement` and `createText`
27
+ */
28
+ export declare function createHeldNodeOps(core: IncaCore, ops: Creators): Creators;
29
+ export {};
@@ -1,6 +1,5 @@
1
1
  import { RendererOptions } from '@vue/runtime-core';
2
- import { IncaElement } from '../element/types.mts';
3
- import { IncaCore } from '../rendererCore.mts';
2
+ import { IncaCore, IncaElement } from '../rendererCore.mts';
4
3
  /**
5
4
  * {@link RendererOptions.patchProp} applies one changed `v-bind`/
6
5
  * attribute/event prop to a host element.
package/dist/vue.js CHANGED
@@ -1,104 +1,57 @@
1
- import { f as e, t } from "./chunks/rendererCore-U_s1R1v7.js";
2
- import { n, r } from "./chunks/handle-B1h0qxex.js";
3
- import { ErrorCodes as i, callWithAsyncErrorHandling as a, createRenderer as o } from "@vue/runtime-core";
4
- //#region src/element/shadowTree.mts
5
- function s(e, t) {
6
- let r = e.createNode(t);
7
- return n(e, r, "element", t);
8
- }
9
- function c(e, t) {
10
- let n = e.createNode("text");
11
- return e.setAttribute(n, "value", t), {
12
- id: n,
13
- kind: "text",
14
- parent: null,
15
- text: t
16
- };
17
- }
18
- function l(e) {
19
- let t = e.createNode("div");
20
- return e.setStyle(t, "display", "none"), n(e, t, "comment");
21
- }
22
- function u(e, t, n) {
23
- e.setAttribute(t.id, "value", n), t.text = n;
24
- }
25
- function d(e, t, n) {
26
- for (let n of t.children.splice(0)) e.destroyNode(n.id), r(n), n.parent = null;
27
- if (!n) return;
28
- let i = c(e, n);
29
- e.appendChild(t.id, i.id), i.parent = t, t.children.push(i);
30
- }
31
- function f(e) {
32
- let t = e.parent;
33
- if (!t) return;
34
- let n = t.children.indexOf(e);
35
- n !== -1 && t.children.splice(n, 1), e.parent = null;
36
- }
37
- function p(e, t) {
38
- t.parent && e.removeChild(t.parent.id, t.id), f(t);
39
- }
40
- function m(e, t, n, r) {
41
- if (r === t && t.parent === n) return;
42
- p(e, t);
43
- let i = r ? n.children.indexOf(r) : -1;
44
- e.insertBefore(n.id, t.id, r && i !== -1 ? r.id : null), i === -1 ? n.children.push(t) : n.children.splice(i, 0, t), t.parent = n;
45
- }
46
- function h(e, t) {
47
- f(t), e.destroyNode(t.id), r(t);
48
- }
49
- function g(e) {
50
- return e.parent;
51
- }
52
- function _(e) {
53
- let t = e.parent;
54
- if (!t) return null;
55
- let n = t.children.indexOf(e);
56
- return t.children[n + 1] ?? null;
57
- }
58
- //#endregion
1
+ import { t as e } from "./chunks/rendererCore-BWT8KFVJ.js";
2
+ import { m as t } from "./chunks/hooks-BgB7lzTv.js";
3
+ import { n } from "./chunks/handle-SWQTonXe.js";
4
+ import { ErrorCodes as r, callWithAsyncErrorHandling as i, createRenderer as a } from "@vue/runtime-core";
59
5
  //#region src/vue/nodeOps.mts
60
- function v(e) {
6
+ function o(e) {
61
7
  return Object.defineProperty(e, "__v_skip", { value: !0 }), e;
62
8
  }
63
- function y(e) {
9
+ function s(e) {
64
10
  return {
65
- createElement: (t) => v(s(e, t)),
66
- createText: (t) => v(c(e, t)),
67
- createComment: (t) => v(l(e)),
68
- setText: (t, n) => u(e, t, n),
69
- setElementText: (t, n) => d(e, t, n),
70
- insert: (t, n, r) => m(e, t, n, r),
71
- remove: (t) => h(e, t),
72
- parentNode: g,
73
- nextSibling: _
11
+ createElement: (t) => o(e.createElementNode(t)),
12
+ createText: (t) => o(e.createTextNode(t)),
13
+ createComment: (t) => o(e.createCommentNode()),
14
+ setText: (t, n) => e.setText(t, n),
15
+ setElementText: (t, n) => e.setElementText(t, n),
16
+ insert: (t, n, r) => e.insert(t, n, r),
17
+ remove: (t) => e.remove(t),
18
+ parentNode: e.parentNode,
19
+ nextSibling: e.nextSibling
20
+ };
21
+ }
22
+ function c(e, t) {
23
+ let n = (t) => (e.holdNode(t.__node_id), e.releaseWhenCollected(t), t), { createElement: r, createText: i } = t;
24
+ return {
25
+ createElement: (e) => n(r(e)),
26
+ createText: (e) => n(i(e))
74
27
  };
75
28
  }
76
29
  //#endregion
77
30
  //#region src/vue/patchProp.mts
78
- var b = (e) => /^on[^a-z]/.test(e) && !e.startsWith("onUpdate:"), x = /(?:Once|Passive|Capture)$/, S = /^on:?(?:Once|Passive|Capture)$/, C = (e) => e.replace(/\B([A-Z])/g, "-$1").toLowerCase();
79
- function w(e) {
31
+ var l = (e) => /^on[^a-z]/.test(e) && !e.startsWith("onUpdate:"), u = /(?:Once|Passive|Capture)$/, d = /^on:?(?:Once|Passive|Capture)$/, f = (e) => e.replace(/\B([A-Z])/g, "-$1").toLowerCase();
32
+ function p(e) {
80
33
  let t = e, n = {
81
34
  event: "",
82
35
  once: !1,
83
36
  capture: !1,
84
37
  passive: !1
85
38
  }, r;
86
- for (; (r = t.match(x)) && !S.test(t);) t = t.slice(0, -r[0].length), r[0] === "Once" ? n.once = !0 : r[0] === "Capture" ? n.capture = !0 : n.passive = !0;
87
- return n.event = t[2] === ":" ? t.slice(3) : C(t.slice(2)), n;
39
+ for (; (r = t.match(u)) && !d.test(t);) t = t.slice(0, -r[0].length), r[0] === "Once" ? n.once = !0 : r[0] === "Capture" ? n.capture = !0 : n.passive = !0;
40
+ return n.event = t[2] === ":" ? t.slice(3) : f(t.slice(2)), n;
88
41
  }
89
- var T = (e) => typeof e == "string" || typeof e == "number", E = /* @__PURE__ */ new WeakMap();
90
- function D(e, t, n) {
91
- let r = typeof n == "object" && n ? n : {}, i = E.get(t);
92
- i || E.set(t, i = /* @__PURE__ */ new Map());
42
+ var m = (e) => typeof e == "string" || typeof e == "number", h = /* @__PURE__ */ new WeakMap();
43
+ function g(e, t, n) {
44
+ let r = typeof n == "object" && n ? n : {}, i = h.get(t);
45
+ i || h.set(t, i = /* @__PURE__ */ new Map());
93
46
  let a = !1;
94
- for (let n of i.keys()) T(r[n]) || (e.removeStyle(t.id, n), i.delete(n), a = !0);
95
- for (let [n, o] of Object.entries(r)) T(o) && (a || i.get(n) !== o) && (e.setStyle(t.id, n, o), i.set(n, o));
47
+ for (let n of i.keys()) m(r[n]) || (e.removeStyle(t.__node_id, n), i.delete(n), a = !0);
48
+ for (let [n, o] of Object.entries(r)) m(o) && (a || i.get(n) !== o) && (e.setStyle(t.__node_id, n, o), i.set(n, o));
96
49
  }
97
- function O(e) {
50
+ function _(e) {
98
51
  let t = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "function");
99
52
  return t.length === 0 ? null : t;
100
53
  }
101
- function k(e, t) {
54
+ function v(e, t) {
102
55
  let n = e[0];
103
56
  if (typeof n != "object" || !n) return t(() => !1);
104
57
  let r = n.stopImmediatePropagation;
@@ -115,32 +68,32 @@ function k(e, t) {
115
68
  i ? n.stopImmediatePropagation = r : delete n.stopImmediatePropagation;
116
69
  }
117
70
  }
118
- var A = /* @__PURE__ */ new WeakMap(), j = ({ event: e, capture: t, passive: n }) => `${e}:${t === !0}:${n === !0}`;
119
- function M(e, t, n, r) {
71
+ var y = /* @__PURE__ */ new WeakMap(), b = ({ event: e, capture: t, passive: n }) => `${e}:${t === !0}:${n === !0}`;
72
+ function x(e, t, n, r) {
120
73
  let i = Array.from(r.slots.values()).some((e) => !e.fired);
121
- i && !r.registered ? (e.addEventListener(t.id, r.event, r.dispatcher, r.options), r.registered = !0) : !i && r.registered && (r.registered = !1, e.removeEventListener(t.id, r.event, r.dispatcher, r.options)), r.slots.size === 0 && A.get(t)?.delete(n);
74
+ i && !r.registered && !e.isDestroyed(t) ? (e.addEventListener(t.__node_id, r.event, r.dispatcher, r.options), r.registered = !0) : !i && r.registered && (r.registered = !1, e.removeEventListener(t.__node_id, r.event, r.dispatcher, r.options)), r.slots.size === 0 && y.get(t)?.delete(n);
122
75
  }
123
- function N(e, t, n, { event: r, capture: o, passive: s }) {
76
+ function S(e, t, n, { event: a, capture: o, passive: s }) {
124
77
  let c = {
125
- event: r,
78
+ event: a,
126
79
  options: {
127
80
  capture: o,
128
81
  passive: s
129
82
  },
130
83
  slots: /* @__PURE__ */ new Map(),
131
84
  registered: !1,
132
- dispatcher: (...r) => {
133
- let o = [], s = r[0]?.eventId;
134
- k(r, (l) => {
85
+ dispatcher: (...a) => {
86
+ let o = [], s = a[0]?.eventId;
87
+ v(a, (l) => {
135
88
  for (let u of Array.from(c.slots.keys())) {
136
89
  if (l()) break;
137
90
  let d = c.slots.get(u);
138
91
  if (d && !d.fired && !(typeof s == "number" && d.attachedAt >= s)) {
139
- d.once && (d.fired = !0, M(e, t, n, c));
92
+ d.once && (d.fired = !0, x(e, t, n, c));
140
93
  for (let e of d.handlers) {
141
94
  if (l()) break;
142
95
  try {
143
- a(e, d.instance, i.NATIVE_EVENT_HANDLER, r);
96
+ i(e, d.instance, r.NATIVE_EVENT_HANDLER, a);
144
97
  } catch (e) {
145
98
  o.push(e);
146
99
  }
@@ -154,20 +107,20 @@ function N(e, t, n, { event: r, capture: o, passive: s }) {
154
107
  };
155
108
  return c;
156
109
  }
157
- function P(e, t, n, r) {
158
- let i = j(n), a = A.get(t)?.get(i);
159
- a?.slots.delete(r) && M(e, t, i, a);
110
+ function C(e, t, n, r) {
111
+ let i = b(n), a = y.get(t)?.get(i);
112
+ a?.slots.delete(r) && x(e, t, i, a);
160
113
  }
161
- function F(e, t, n, r, i) {
162
- let a = w(n), o = O(r);
114
+ function w(e, t, n, r, i) {
115
+ let a = p(n), o = _(r);
163
116
  if (!o) {
164
- P(e, t, a, n);
117
+ C(e, t, a, n);
165
118
  return;
166
119
  }
167
- let s = j(a), c = A.get(t);
168
- c || A.set(t, c = /* @__PURE__ */ new Map());
120
+ let s = b(a), c = y.get(t);
121
+ c || y.set(t, c = /* @__PURE__ */ new Map());
169
122
  let l = c.get(s);
170
- l || c.set(s, l = N(e, t, s, a));
123
+ l || c.set(s, l = S(e, t, s, a));
171
124
  let u = l.slots.get(n);
172
125
  if (u) u.handlers = o, u.instance = i;
173
126
  else {
@@ -179,30 +132,41 @@ function F(e, t, n, r, i) {
179
132
  fired: !1
180
133
  });
181
134
  try {
182
- M(e, t, s, l);
135
+ x(e, t, s, l);
183
136
  } catch (e) {
184
137
  throw l.slots.delete(n), l.slots.size === 0 && c.delete(s), e;
185
138
  }
186
139
  }
187
140
  }
188
- var I = /* @__PURE__ */ new Set([
141
+ var T = /* @__PURE__ */ new Set([
189
142
  "disabled",
190
143
  "hidden",
191
144
  "inert"
192
145
  ]);
193
- function L(e) {
146
+ function E(e) {
194
147
  return (t, n, r, i, a, o) => {
195
- n === "style" ? D(e, t, i) : b(n) ? F(e, t, n, i, o ?? null) : I.has(n) && i === !1 ? e.removeAttribute(t.id, n) : typeof i == "string" || typeof i == "number" || typeof i == "boolean" ? e.setAttribute(t.id, n, i) : i == null ? e.removeAttribute(t.id, n) : n.startsWith("onUpdate:") || e.setAttribute(t.id, n, String(i));
148
+ n === "style" ? g(e, t, i) : l(n) ? w(e, t, n, i, o ?? null) : T.has(n) && i === !1 ? e.removeAttribute(t.__node_id, n) : typeof i == "string" || typeof i == "number" || typeof i == "boolean" ? e.setAttribute(t.__node_id, n, i) : i == null ? e.removeAttribute(t.__node_id, n) : n.startsWith("onUpdate:") || e.setAttribute(t.__node_id, n, String(i));
196
149
  };
197
150
  }
198
151
  //#endregion
199
152
  //#region src/vue/createApp.mts
200
- function R(r, i) {
201
- let a = o({
202
- ...y(t),
203
- patchProp: L(t)
204
- }).createApp(r, i), s = a.mount.bind(a);
205
- return Object.assign(a, { mount: (r) => s(r ?? v(n(t, e(), "element"))) });
153
+ var D = /* @__PURE__ */ new Set();
154
+ function O(r, i) {
155
+ let l = {
156
+ ...s(e),
157
+ patchProp: E(e)
158
+ }, u = a(l);
159
+ Object.assign(l, c(e, l));
160
+ let d = u.createApp(r, i), f = d.mount.bind(d), p = d.unmount.bind(d);
161
+ return Object.assign(d, {
162
+ mount: (e) => {
163
+ let r = f(e ?? o(n(t(), "element")));
164
+ return D.add(d), r;
165
+ },
166
+ unmount: () => {
167
+ p(), D.delete(d);
168
+ }
169
+ });
206
170
  }
207
171
  //#endregion
208
- export { R as createIncaApp };
172
+ export { O as createIncaApp };
package/dist/window.d.mts CHANGED
@@ -1,11 +1,13 @@
1
+ import { IncaEventTarget } from './types.mts';
1
2
  /**
2
- * The event target at the top of the app. Bubble listeners on it run for
3
- * every bubbling event, and capture listeners run for every event dispatched
4
- * in the app, including events that do not bubble. Key events reach it while
5
- * nothing is focused. A `wheel` listener is passive unless its options say
3
+ * The event target at the top of the app. Every event path ends at it.
4
+ * Bubble listeners on it run for every bubbling event, and capture listeners
5
+ * run for every event dispatched in the app, including events that do not
6
+ * bubble. Key events reach it while nothing is focused, with `window` as
7
+ * `target`. A `wheel` listener is passive unless its options say
6
8
  * `passive: false`.
7
9
  *
8
10
  * It has the listener methods `addEventListener`, `removeEventListener` and
9
11
  * `dispatchEvent`.
10
12
  */
11
- export declare const window: import('./types.mts').IncaEventTarget;
13
+ export declare const window: IncaEventTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incajs",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "A GPU-native, Webview-free desktop app framework built on GPUI and QuickJS.",
5
5
  "keywords": [
6
6
  "cross-platform",
@@ -30,7 +30,11 @@
30
30
  "dist"
31
31
  ],
32
32
  "type": "module",
33
- "sideEffects": false,
33
+ "sideEffects": [
34
+ "src/callbacks.mts",
35
+ "src/targets.mts",
36
+ "dist/chunks/hooks-*.js"
37
+ ],
34
38
  "main": "./dist/index.js",
35
39
  "types": "./dist/index.d.mts",
36
40
  "exports": {