incajs 0.0.13 → 0.0.14

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
@@ -12,7 +12,7 @@ framework. No Chromium, no DOM: UI renders directly on the GPU via
12
12
 
13
13
  ## How it works
14
14
 
15
- - The root `incajs` export is types only.
15
+ - The root `incajs` export is the `window` event target and the public types.
16
16
  - `incajs/vue` is a custom renderer mapping Vue 3's `createRenderer`
17
17
  lifecycle onto the native host bridge. `createIncaApp(rootComponent,
18
18
  rootProps?)` creates a Vue app whose root mounts against the host's
@@ -0,0 +1,125 @@
1
+ //#region src/native.mts
2
+ function e() {
3
+ return globalThis.__inca_native__;
4
+ }
5
+ //#endregion
6
+ //#region src/events.mts
7
+ function t() {
8
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = 0, r = () => globalThis.__inca_callbacks__ ??= {};
9
+ return {
10
+ add(i, a, o) {
11
+ let s = n++;
12
+ r()[s] = o;
13
+ let c = e.get(i);
14
+ return c || e.set(i, c = /* @__PURE__ */ new Map()), c.set(a, s), t.set(s, {
15
+ group: i,
16
+ listener: a
17
+ }), s;
18
+ },
19
+ idFor(t, n) {
20
+ return e.get(t)?.get(n);
21
+ },
22
+ release(n) {
23
+ delete r()[n];
24
+ let i = t.get(n);
25
+ if (i === void 0) return;
26
+ t.delete(n);
27
+ let a = e.get(i.group);
28
+ a?.delete(i.listener), a?.size === 0 && e.delete(i.group);
29
+ },
30
+ groupCount: () => e.size
31
+ };
32
+ }
33
+ var n = t(), r = (e, t, n) => `${e}:${t}:${n === !0}`, i = 0;
34
+ function a() {
35
+ return i;
36
+ }
37
+ function o(e) {
38
+ return (...t) => {
39
+ let n = t[0]?.eventId;
40
+ return typeof n == "number" && n > i && (i = n), e(...t);
41
+ };
42
+ }
43
+ function s(e) {
44
+ for (let t of e) n.release(t);
45
+ }
46
+ function c(t, i, a, s = {}) {
47
+ if (a == null) return;
48
+ let c = r(t, i, s.capture);
49
+ if (n.idFor(c, a) !== void 0) return;
50
+ let u = (...e) => typeof a == "function" ? a(...e) : a.handleEvent.apply(a, e), d = s.once ? (...e) => (l(t, i, a, s), u(...e)) : u, f = n.add(c, a, o(d));
51
+ try {
52
+ e().addEventListener(t, i, f, s.capture === !0, s.passive === !0);
53
+ } catch (e) {
54
+ throw n.release(f), e;
55
+ }
56
+ }
57
+ function l(t, i, a, o = {}) {
58
+ if (a == null) return;
59
+ let s = n.idFor(r(t, i, o.capture), a);
60
+ s !== void 0 && (e().removeEventListener(t, i, s), n.release(s));
61
+ }
62
+ function u(t, n) {
63
+ return e().dispatchEvent(t, n);
64
+ }
65
+ function d(t) {
66
+ e().click(t);
67
+ }
68
+ function f(t) {
69
+ e().focusNode(t);
70
+ }
71
+ function p(t) {
72
+ e().blurNode(t);
73
+ }
74
+ //#endregion
75
+ //#region src/createEventTarget.mts
76
+ function m(e, t = []) {
77
+ return {
78
+ addEventListener(n, r, i) {
79
+ let a = typeof i == "boolean" ? { capture: i } : i ?? {};
80
+ c(e(), n, r, {
81
+ ...a,
82
+ passive: a.passive ?? t.includes(n)
83
+ });
84
+ },
85
+ removeEventListener(t, n, r) {
86
+ let i = typeof r == "boolean" ? r : r?.capture;
87
+ l(e(), t, n, { capture: i });
88
+ },
89
+ dispatchEvent: (t) => u(e(), t)
90
+ };
91
+ }
92
+ //#endregion
93
+ //#region src/tree.mts
94
+ function h() {
95
+ return e().rootNodeId();
96
+ }
97
+ function g(t) {
98
+ return e().createNode(t);
99
+ }
100
+ function _(t, n) {
101
+ e().appendChild(t, n);
102
+ }
103
+ function v(t, n, r) {
104
+ e().insertBefore(t, n, r);
105
+ }
106
+ function y(t, n) {
107
+ e().removeChild(t, n);
108
+ }
109
+ function b(t) {
110
+ s(e().destroyNode(t));
111
+ }
112
+ function x(t, n, r) {
113
+ e().setAttribute(t, n, r);
114
+ }
115
+ function S(t, n) {
116
+ e().removeAttribute(t, n);
117
+ }
118
+ function C(t, n, r) {
119
+ e().setStyle(t, n, r);
120
+ }
121
+ function w(t, n) {
122
+ e().removeStyle(t, n);
123
+ }
124
+ //#endregion
125
+ export { a as _, S as a, h as c, m as d, c as f, f as g, u as h, v as i, x as l, d as m, g as n, y as o, p, b as r, w as s, _ as t, C as u, l as v };
@@ -0,0 +1,10 @@
1
+ import { IncaEventTarget, NodeId } from './types.mts';
2
+ /**
3
+ * Builds the listener methods of an event target that stands for one node.
4
+ * @param nodeId - resolves the node when a method runs
5
+ * @param passiveByDefault - event names whose listeners are passive unless
6
+ * their options say `passive: false`
7
+ * @returns the target's `addEventListener`, `removeEventListener` and
8
+ * `dispatchEvent`
9
+ */
10
+ export declare function createEventTarget(nodeId: () => NodeId, passiveByDefault?: readonly string[]): IncaEventTarget;
package/dist/events.d.mts CHANGED
@@ -1,8 +1,13 @@
1
- import { CallbackId, EventListener, NodeId } from './types.mts';
1
+ import { CallbackId, EventLike, EventListenerOrObject, ListenerOptions, NodeId } from './types.mts';
2
+ /**
3
+ * @returns how many `(nodeId, event, capture)` groups hold a registration
4
+ * @internal
5
+ */
6
+ export declare function registeredGroupCount(): number;
2
7
  /**
3
8
  * @returns the `eventId` of the newest event any registered listener has
4
- * received, or 0 before the first. Ids grow with each input event, and every
5
- * node dispatch of one event carries the same id.
9
+ * received, or 0 before the first. Ids grow with each event, and every
10
+ * listener of one event receives the same id.
6
11
  */
7
12
  export declare function latestEventId(): number;
8
13
  /**
@@ -13,33 +18,55 @@ export declare function latestEventId(): number;
13
18
  */
14
19
  export declare function releaseCallbacks(callbackIds: readonly CallbackId[]): void;
15
20
  /**
16
- * Makes `listener` the one thing that runs when `event` fires on `nodeId`,
17
- * replacing whatever was registered for that pair before.
21
+ * Registers `listener` for `event` on `nodeId`. Registering the same listener
22
+ * for the same node, event and `capture` again changes nothing, and the first
23
+ * registration keeps its other options. A `null` listener is ignored.
18
24
  *
19
- * The host holds a list per `(nodeId, event)` and dispatches to all of it;
20
- * this wrapper keeps one, the way a framework adapter composes its own
21
- * handlers into a single callback. See {@link EventListener} for which
22
- * event names are wired to real native input today; other names are
23
- * accepted but never fire.
25
+ * Any event name is accepted, and it fires when the host dispatches that name.
26
+ * See the `EventListener` type for the fields an event carries.
24
27
  * @param nodeId - the node to listen on
25
28
  * @param event - the event name (e.g. `"click"`)
26
- * @param listener - called when the event fires
29
+ * @param listener - a function, or an object whose `handleEvent` method is
30
+ * called with the object as `this` when the event fires
31
+ * @param options - `capture` listens while the event travels down to the
32
+ * target, `passive` ignores `preventDefault()` calls in `listener`, and
33
+ * `once` removes the listener before it first runs
34
+ * @throws TypeError when `nodeId` is malformed
35
+ * @throws TypeError when `nodeId` names no node
27
36
  */
28
- export declare function setEventListener(nodeId: NodeId, event: string, listener: EventListener): void;
37
+ export declare function addEventListener(nodeId: NodeId, event: string, listener: EventListenerOrObject | null, options?: ListenerOptions): void;
29
38
  /**
30
- * Drops whatever {@link setEventListener} registered for `(nodeId, event)`,
31
- * on both the native and the JS side. A no-op if nothing is registered.
39
+ * Drops the registration {@link addEventListener} made for `listener` on
40
+ * `nodeId` with the same `event` and `capture`. A no-op if there is none.
32
41
  * @param nodeId - the node to stop listening on
33
42
  * @param event - the event name
43
+ * @param listener - the listener that was registered
44
+ * @param options - `capture` of the registration to drop
45
+ */
46
+ export declare function removeEventListener(nodeId: NodeId, event: string, listener: EventListenerOrObject | null, options?: Pick<ListenerOptions, "capture">): void;
47
+ /**
48
+ * Dispatches `event` at `nodeId` along the path to the root.
49
+ * @param nodeId - the node to dispatch at
50
+ * @param event - the event to dispatch
51
+ * @returns `false` when a listener canceled a cancelable event, else `true`
52
+ * @throws TypeError when `nodeId` is malformed
53
+ * @throws TypeError when `nodeId` names no node
54
+ * @throws TypeError when `event` is not an `Event` or `CustomEvent`
55
+ * @throws DOMException named `InvalidStateError` when `event` is being dispatched
56
+ */
57
+ export declare function dispatchEvent(nodeId: NodeId, event: EventLike): boolean;
58
+ /**
59
+ * Fires an untrusted `click` at `nodeId`. A disabled `button`, a node whose
60
+ * own click is still running and an unknown node ignore the call.
61
+ * @param nodeId - the node to click
62
+ * @throws TypeError when `nodeId` is malformed
34
63
  */
35
- export declare function removeEventListener(nodeId: NodeId, event: string): void;
64
+ export declare function click(nodeId: NodeId): void;
36
65
  /**
37
66
  * Requests that `nodeId` become focused. Takes effect on the next frame,
38
- * dispatching `"blur"`/`"focus"` for whatever actually changed — `nodeId`
39
- * doesn't need a `"focus"`/`"blur"` listener registered for this to work,
40
- * the same way `element.focus()` works on any focusable DOM element
41
- * regardless of whether it's being listened to. The node needs a `tabindex`
42
- * attribute to take focus.
67
+ * dispatching `"blur"`/`"focus"` for whatever actually changed. The node
68
+ * needs a `tabindex` attribute to take focus, and a listener for either event
69
+ * is optional.
43
70
  * @param nodeId - the node to focus
44
71
  */
45
72
  export declare function focus(nodeId: NodeId): void;
package/dist/index.d.mts CHANGED
@@ -1 +1,2 @@
1
- export type { AttributeValue, CallbackId, EventListener, NodeId, StyleProps, TagName, } from './types.mts';
1
+ export { window } from './window.mts';
2
+ export type { AttributeValue, CallbackId, EventLike, EventListener, EventListenerObject, EventListenerOrObject, IncaEventTarget, ListenerOptions, NodeId, StyleProps, TagName, } from './types.mts';
package/dist/index.js CHANGED
@@ -0,0 +1,5 @@
1
+ import { c as e, d as t } from "./chunks/tree-BQ6ux0tE.js";
2
+ //#region src/window.mts
3
+ var n = /* @__PURE__ */ t(e, ["wheel"]);
4
+ //#endregion
5
+ export { n as window };
package/dist/native.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AttributeValue, CallbackId, EventListener, NodeId } from './types.mts';
1
+ import { AttributeValue, CallbackId, EventLike, NodeId } from './types.mts';
2
2
  /** The host-injected object every wrapper in this package forwards to. Not part of the public surface — reach it through the wrappers instead. */
3
3
  interface IncaNative {
4
4
  rootNodeId(): NodeId;
@@ -10,15 +10,19 @@ interface IncaNative {
10
10
  removeAttribute(nodeId: NodeId, key: string): void;
11
11
  setStyle(nodeId: NodeId, key: string, value: AttributeValue): void;
12
12
  removeStyle(nodeId: NodeId, key: string): void;
13
- addEventListener(nodeId: NodeId, event: string, callbackId: CallbackId): void;
13
+ addEventListener(nodeId: NodeId, event: string, callbackId: CallbackId, capture?: boolean, passive?: boolean): void;
14
14
  removeEventListener(nodeId: NodeId, event: string, callbackId: CallbackId): boolean;
15
15
  destroyNode(nodeId: NodeId): CallbackId[];
16
16
  focusNode(nodeId: NodeId): void;
17
17
  blurNode(nodeId: NodeId): void;
18
+ dispatchEvent(nodeId: NodeId, event: EventLike): boolean;
19
+ click(nodeId: NodeId): void;
18
20
  }
21
+ /** What the host calls: it passes the event object as the first argument. */
22
+ export type HostCallback = (...args: unknown[]) => void;
19
23
  declare global {
20
24
  var __inca_native__: IncaNative;
21
- var __inca_callbacks__: Record<CallbackId, EventListener>;
25
+ var __inca_callbacks__: Record<CallbackId, HostCallback>;
22
26
  }
23
27
  export declare function native(): IncaNative;
24
28
  export {};
@@ -1,5 +1,7 @@
1
- export { setEventListener, removeEventListener, latestEventId, focus, blur } from './events.mts';
1
+ export { createEventTarget } from './createEventTarget.mts';
2
+ export { addEventListener, removeEventListener, latestEventId, focus, blur, dispatchEvent, click, } from './events.mts';
2
3
  export { appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, removeAttribute, setStyle, removeStyle, } from './tree.mts';
4
+ export type * from './types.mts';
3
5
  /**
4
6
  * The tree/event primitives a custom renderer (`incajs/vue`) drives the
5
7
  * native tree through.
@@ -1 +1,31 @@
1
- export { n as appendChild, f as blur, r as createNode, i as destroyNode, p as focus, a as insertBefore, m as latestEventId, o as removeAttribute, s as removeChild, h as removeEventListener, c as removeStyle, l as rootNodeId, u as setAttribute, g as setEventListener, d as setStyle } from "./chunks/rendererCore-vR5RIa7d.js";
1
+ import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _ } from "./chunks/tree-BQ6ux0tE.js";
2
+ //#region \0rolldown/runtime.js
3
+ var v = Object.defineProperty, y = /* @__PURE__ */ ((e, t) => {
4
+ let n = {};
5
+ for (var r in e) v(n, r, {
6
+ get: e[r],
7
+ enumerable: !0
8
+ });
9
+ return t || v(n, Symbol.toStringTag, { value: "Module" }), n;
10
+ })({
11
+ addEventListener: () => i,
12
+ appendChild: () => h,
13
+ blur: () => f,
14
+ click: () => l,
15
+ createEventTarget: () => r,
16
+ createNode: () => u,
17
+ destroyNode: () => p,
18
+ dispatchEvent: () => o,
19
+ focus: () => a,
20
+ insertBefore: () => s,
21
+ latestEventId: () => e,
22
+ removeAttribute: () => t,
23
+ removeChild: () => d,
24
+ removeEventListener: () => _,
25
+ removeStyle: () => m,
26
+ rootNodeId: () => n,
27
+ setAttribute: () => c,
28
+ setStyle: () => g
29
+ });
30
+ //#endregion
31
+ export { i as addEventListener, h as appendChild, f as blur, l as click, r as createEventTarget, u as createNode, p as destroyNode, o as dispatchEvent, a as focus, s as insertBefore, e as latestEventId, t as removeAttribute, d as removeChild, _ as removeEventListener, m as removeStyle, n as rootNodeId, c as setAttribute, g as setStyle, y as t };
package/dist/types.d.mts CHANGED
@@ -5,7 +5,7 @@
5
5
  export type NodeId = number;
6
6
  /**
7
7
  * Id assigned to one registered event listener. Managed internally by
8
- * `setEventListener`/`removeEventListener`/`destroyNode` — callers never see or
8
+ * `addEventListener`/`removeEventListener`/`destroyNode` — callers never see or
9
9
  * pass one directly.
10
10
  */
11
11
  export type CallbackId = number;
@@ -106,7 +106,62 @@ export interface StyleProps {
106
106
  max_height?: number | "auto";
107
107
  }
108
108
  /**
109
- * Signature of a callback registered via `setEventListener`.
109
+ * An `Event` or `CustomEvent` built in this runtime. The host throws a
110
+ * `TypeError` for any other value.
111
+ */
112
+ export interface EventLike {
113
+ readonly type: string;
114
+ }
115
+ /**
116
+ * How a listener registered via `addEventListener` takes part in an event.
117
+ */
118
+ export interface ListenerOptions {
119
+ /** Listen while the event travels from the root down to the target. The default listens while it travels back up. */
120
+ capture?: boolean;
121
+ /** `preventDefault()` calls inside the listener are ignored. */
122
+ passive?: boolean;
123
+ /** The listener is removed before it first runs. */
124
+ once?: boolean;
125
+ }
126
+ /**
127
+ * The listener methods of an object that receives events, such as the
128
+ * `window` export and a template `ref`. A registration is identified by the
129
+ * event name, the listener and `capture`. `removeEventListener` takes the
130
+ * same listener that `addEventListener` received.
131
+ */
132
+ export interface IncaEventTarget {
133
+ /**
134
+ * Registers `listener` for `type`. Registering the same listener for the
135
+ * same `type` and `capture` again changes nothing. A `null` listener is
136
+ * ignored.
137
+ * @param type - the event name (e.g. `"keydown"`)
138
+ * @param listener - a function, or an object whose `handleEvent` method is
139
+ * called when the event fires
140
+ * @param options - a {@link ListenerOptions}, or a boolean for `capture`
141
+ * @throws TypeError when the target's node was destroyed
142
+ */
143
+ addEventListener(type: string, listener: EventListenerOrObject | null, options?: boolean | ListenerOptions): void;
144
+ /**
145
+ * Drops the registration of `listener` for `type` with the same `capture`.
146
+ * A call that matches no registration changes nothing.
147
+ * @param type - the event name
148
+ * @param listener - the listener that was registered
149
+ * @param options - an object with `capture`, or a boolean for `capture`
150
+ */
151
+ removeEventListener(type: string, listener: EventListenerOrObject | null, options?: boolean | Pick<ListenerOptions, "capture">): void;
152
+ /**
153
+ * Dispatches an `Event` or `CustomEvent` at the target.
154
+ * @param event - the event to dispatch
155
+ * @returns `false` when a listener canceled a cancelable event, else `true`
156
+ * @throws TypeError when the target's node was destroyed
157
+ * @throws TypeError when `event` is not an `Event` or `CustomEvent`
158
+ * @throws DOMException named `InvalidStateError` when `event` is being dispatched
159
+ */
160
+ dispatchEvent(event: EventLike): boolean;
161
+ }
162
+ /**
163
+ * Signature of a callback registered via `addEventListener`. Declare its
164
+ * parameter as the event object, such as `(event: { key: string }) => void`.
110
165
  *
111
166
  * The native host calls it with one argument, an object with:
112
167
  * - `type`: the event's name.
@@ -114,19 +169,35 @@ export interface StyleProps {
114
169
  * under the pointer for pointer events, the nearest common ancestor of the
115
170
  * press and the release for `click`, `dblclick` and `auxclick`, and the
116
171
  * focused node (the root when nothing is focused) for key events.
117
- * - `currentTarget`: the {@link NodeId} whose listener is running.
172
+ * - `currentTarget`: the {@link NodeId} whose listener is running, and
173
+ * `null` once the event has been handled.
118
174
  * - `bubbles`, `cancelable` and `composed`: fixed per event name.
119
175
  * - `defaultPrevented`: `true` once a listener called `preventDefault()` on a
120
176
  * cancelable event.
121
- * - `eventPhase`: 2 where `currentTarget` is `target`, 3 on its ancestors.
122
- * - `isTrusted`: always `true`.
177
+ * - `eventPhase`: 1 on the ancestors of `target` while the event travels
178
+ * down, 2 where `currentTarget` is `target`, 3 on the ancestors while it
179
+ * travels up, and 0 once the event has been handled.
180
+ * - `isTrusted`: `true` for events the host dispatches and `false` for events a
181
+ * script dispatches.
123
182
  * - `timeStamp`: milliseconds since the host started, as a number.
124
183
  * - `eventId`: a number that grows with each event and is the same on every
125
184
  * node that event reaches.
126
185
  * - `stopPropagation()`, `stopImmediatePropagation()` and `preventDefault()`.
127
186
  * - the fields that event kind carries.
128
187
  *
129
- * See https://incajs.tom96da.com/reference/events for the full list of wired
130
- * event names and their fields.
188
+ * See https://incajs.tom96da.com/reference/events for the event names the
189
+ * host dispatches and their fields.
190
+ */
191
+ export type EventListener = (...args: never[]) => void;
192
+ /**
193
+ * An object whose `handleEvent` method receives the events, called with the
194
+ * object as `this`. It takes the arguments of an {@link EventListener}.
195
+ */
196
+ export interface EventListenerObject {
197
+ handleEvent: EventListener;
198
+ }
199
+ /**
200
+ * What `addEventListener` accepts as a listener: an {@link EventListener} or
201
+ * an {@link EventListenerObject}.
131
202
  */
132
- export type EventListener = (...args: unknown[]) => void;
203
+ export type EventListenerOrObject = EventListener | EventListenerObject;
@@ -1,9 +1,9 @@
1
- import { IncaCore } from '../rendererCore.mts';
2
- import { NodeId, TagName } from '../types.mts';
1
+ import { IncaCore, NodeId, TagName } from '../rendererCore.mts';
3
2
  import { IncaElement } from './nodeOps.mts';
4
3
  /**
5
4
  * Builds the {@link IncaElement} handle for a native node: parentless,
6
- * childless, with `focus()`, `blur()` and `tabIndex` wired to `core`.
5
+ * childless, with `focus()`, `blur()`, `click()`, the listener methods of an
6
+ * event target and `tabIndex`, all driven through `core`.
7
7
  * @param core - the incajs bindings the handle drives
8
8
  * @param id - the native node's id
9
9
  * @param kind - whether the node is an element or a comment stand-in
@@ -1,6 +1,5 @@
1
1
  import { RendererOptions } from '@vue/runtime-core';
2
- import { IncaCore } from '../rendererCore.mts';
3
- import { NodeId } from '../types.mts';
2
+ import { IncaCore, IncaEventTarget, NodeId } from '../rendererCore.mts';
4
3
  /**
5
4
  * A container host node: either a real element or the hidden stand-in
6
5
  * {@link NodeOps.createComment} uses. Also `@vue/runtime-core`'s
@@ -11,7 +10,7 @@ import { NodeId } from '../types.mts';
11
10
  * JS-side shadow of the tree, kept in sync by {@link NodeOps.insert}/
12
11
  * {@link NodeOps.remove}.
13
12
  */
14
- export interface IncaElement {
13
+ export interface IncaElement extends IncaEventTarget {
15
14
  /**
16
15
  * The underlying native node's id — the only part of this object the native
17
16
  * tree itself knows about.
@@ -31,6 +30,11 @@ export interface IncaElement {
31
30
  focus(): void;
32
31
  /** Unfocuses this node next frame, if it is the focused one. */
33
32
  blur(): void;
33
+ /**
34
+ * Fires an untrusted `click` at this node. A disabled `button`, a node whose
35
+ * own click is still running and an unknown node ignore the call.
36
+ */
37
+ click(): void;
34
38
  /**
35
39
  * Assigning sets the `tabindex` attribute to the integer part of the
36
40
  * value. Reading returns the last value assigned, or `-1` (`0` for a
@@ -24,20 +24,26 @@ import { IncaElement } from './nodeOps.mts';
24
24
  * The key registers `nextValue` as a listener for `xxx`, taking a function
25
25
  * or an array of them, and unbinds that key's listener for anything else.
26
26
  * - Order: each distinct key (`onClick`, `onClickOnce`) is its own listener.
27
- * They run in the order first registered, a re-patch keeps its place, and
28
- * the host sees one registration per element and event.
27
+ * Keys that share the event, phase and passivity run in the order first
28
+ * registered, a re-patch keeps its place, and the host sees one registration
29
+ * per element, event, phase and passivity. Capture registrations run before
30
+ * every bubble registration, also on the target. Within a pass,
31
+ * registrations run in the order the host registered them.
29
32
  * - Propagation: `stopImmediatePropagation()` stops the listeners after it.
30
33
  * - Timing: a listener attached while an event is being handled first runs
31
34
  * for the next event; events are told apart by the `eventId` the host puts
32
35
  * on each one.
33
36
  * - Modifiers: a trailing `Once`/`Passive`/`Capture` suffix (from Vue's
34
37
  * `.once`/`.passive`/`.capture` modifiers) is stripped first. `.once`
35
- * really removes the listener after it fires once, and a listener that has
36
- * fired stays spent until its key is removed. `.passive`/`.capture` bind
37
- * as an ordinary listener with no native passive/capture-phase support
38
- * yet.
39
- * - Event names: see {@link EventListener} for which names are wired to real
40
- * input by the native host today; other names are accepted but never fire.
38
+ * removes the listener after it fires once, and a listener that has fired
39
+ * stays spent until its key is removed. `.capture` registers the listener
40
+ * for the phase in which the event travels down to the target, and
41
+ * `.passive` ignores `preventDefault()` calls inside it.
42
+ * - Event names: `onXxx` listens for the hyphenated name (`onMyEvent` listens
43
+ * for `my-event`), and `on:xxx` listens for the name after the colon as
44
+ * written (`on:myEvent` listens for `myEvent`). The listener runs when the
45
+ * host dispatches that name. See {@link EventListener} for the fields an
46
+ * event carries.
41
47
  * - Errors: an error a handler throws, or a rejection of an async handler,
42
48
  * goes to the `onErrorCaptured` hooks and the app's `errorHandler`. Every
43
49
  * handler of an event runs even when an earlier one fails, until one calls
package/dist/vue.js CHANGED
@@ -1,4 +1,5 @@
1
- import { l as e, t } from "./chunks/rendererCore-vR5RIa7d.js";
1
+ import { c as e } from "./chunks/tree-BQ6ux0tE.js";
2
+ import { t } from "./rendererCore.js";
2
3
  import { ErrorCodes as n, callWithAsyncErrorHandling as r, createRenderer as i } from "@vue/runtime-core";
3
4
  //#region src/vue/createElement.mts
4
5
  function a(e, t, n, r) {
@@ -10,6 +11,8 @@ function a(e, t, n, r) {
10
11
  children: [],
11
12
  focus: () => e.focus(t),
12
13
  blur: () => e.blur(t),
14
+ click: () => e.click(t),
15
+ ...e.createEventTarget(() => t),
13
16
  get tabIndex() {
14
17
  return i;
15
18
  },
@@ -79,28 +82,30 @@ function o(e) {
79
82
  }
80
83
  //#endregion
81
84
  //#region src/vue/patchProp.mts
82
- var s = (e) => /^on[A-Z]/.test(e) && !e.startsWith("onUpdate:"), c = /(?:Once|Passive|Capture)$/;
83
- function l(e) {
84
- let t = e, n = !1, r;
85
- for (; r = t.match(c);) t = t.slice(0, -r[0].length), r[0] === "Once" && (n = !0);
86
- return {
87
- event: t.slice(2).toLowerCase(),
88
- once: n
89
- };
85
+ var s = (e) => /^on[^a-z]/.test(e) && !e.startsWith("onUpdate:"), c = /(?:Once|Passive|Capture)$/, l = /^on:?(?:Once|Passive|Capture)$/, u = (e) => e.replace(/\B([A-Z])/g, "-$1").toLowerCase();
86
+ function d(e) {
87
+ let t = e, n = {
88
+ event: "",
89
+ once: !1,
90
+ capture: !1,
91
+ passive: !1
92
+ }, r;
93
+ for (; (r = t.match(c)) && !l.test(t);) t = t.slice(0, -r[0].length), r[0] === "Once" ? n.once = !0 : r[0] === "Capture" ? n.capture = !0 : n.passive = !0;
94
+ return n.event = t[2] === ":" ? t.slice(3) : u(t.slice(2)), n;
90
95
  }
91
- var u = (e) => typeof e == "string" || typeof e == "number", d = /* @__PURE__ */ new WeakMap();
92
- function f(e, t, n) {
93
- let r = typeof n == "object" && n ? n : {}, i = d.get(t);
94
- i || d.set(t, i = /* @__PURE__ */ new Map());
96
+ var f = (e) => typeof e == "string" || typeof e == "number", p = /* @__PURE__ */ new WeakMap();
97
+ function m(e, t, n) {
98
+ let r = typeof n == "object" && n ? n : {}, i = p.get(t);
99
+ i || p.set(t, i = /* @__PURE__ */ new Map());
95
100
  let a = !1;
96
- for (let n of i.keys()) u(r[n]) || (e.removeStyle(t.id, n), i.delete(n), a = !0);
97
- for (let [n, o] of Object.entries(r)) u(o) && (a || i.get(n) !== o) && (e.setStyle(t.id, n, o), i.set(n, o));
101
+ for (let n of i.keys()) f(r[n]) || (e.removeStyle(t.id, n), i.delete(n), a = !0);
102
+ for (let [n, o] of Object.entries(r)) f(o) && (a || i.get(n) !== o) && (e.setStyle(t.id, n, o), i.set(n, o));
98
103
  }
99
- function p(e) {
104
+ function h(e) {
100
105
  let t = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "function");
101
106
  return t.length === 0 ? null : t;
102
107
  }
103
- function m(e, t) {
108
+ function g(e, t) {
104
109
  let n = e[0];
105
110
  if (typeof n != "object" || !n) return t(() => !1);
106
111
  let r = n.stopImmediatePropagation;
@@ -117,89 +122,94 @@ function m(e, t) {
117
122
  i ? n.stopImmediatePropagation = r : delete n.stopImmediatePropagation;
118
123
  }
119
124
  }
120
- var h = /* @__PURE__ */ new WeakMap();
121
- function g(e, t, n, r) {
125
+ var _ = /* @__PURE__ */ new WeakMap(), v = ({ event: e, capture: t, passive: n }) => `${e}:${t === !0}:${n === !0}`;
126
+ function y(e, t, n, r) {
122
127
  let i = Array.from(r.slots.values()).some((e) => !e.fired);
123
- i && !r.registered ? (e.setEventListener(t.id, n, r.dispatcher), r.registered = !0) : !i && r.registered && (r.registered = !1, e.removeEventListener(t.id, n)), r.slots.size === 0 && h.get(t)?.delete(n);
128
+ 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 && _.get(t)?.delete(n);
124
129
  }
125
- function _(e, t, i) {
126
- let a = {
130
+ function b(e, t, i, { event: a, capture: o, passive: s }) {
131
+ let c = {
132
+ event: a,
133
+ options: {
134
+ capture: o,
135
+ passive: s
136
+ },
127
137
  slots: /* @__PURE__ */ new Map(),
128
138
  registered: !1,
129
- dispatcher: (...o) => {
130
- let s = [], c = o[0]?.eventId;
131
- m(o, (l) => {
132
- for (let u of Array.from(a.slots.keys())) {
139
+ dispatcher: (...a) => {
140
+ let o = [], s = a[0]?.eventId;
141
+ g(a, (l) => {
142
+ for (let u of Array.from(c.slots.keys())) {
133
143
  if (l()) break;
134
- let d = a.slots.get(u);
135
- if (d && !d.fired && !(typeof c == "number" && d.attachedAt >= c)) {
136
- d.once && (d.fired = !0, g(e, t, i, a));
144
+ let d = c.slots.get(u);
145
+ if (d && !d.fired && !(typeof s == "number" && d.attachedAt >= s)) {
146
+ d.once && (d.fired = !0, y(e, t, i, c));
137
147
  for (let e of d.handlers) {
138
148
  if (l()) break;
139
149
  try {
140
- r(e, d.instance, n.NATIVE_EVENT_HANDLER, o);
150
+ r(e, d.instance, n.NATIVE_EVENT_HANDLER, a);
141
151
  } catch (e) {
142
- s.push(e);
152
+ o.push(e);
143
153
  }
144
154
  }
145
155
  }
146
156
  }
147
157
  });
148
- for (let e of s.slice(1)) Promise.reject(e);
149
- if (s.length > 0) throw s[0];
158
+ for (let e of o.slice(1)) Promise.reject(e);
159
+ if (o.length > 0) throw o[0];
150
160
  }
151
161
  };
152
- return a;
162
+ return c;
153
163
  }
154
- function v(e, t, n, r) {
155
- let i = h.get(t)?.get(n);
156
- i?.slots.delete(r) && g(e, t, n, i);
164
+ function x(e, t, n, r) {
165
+ let i = v(n), a = _.get(t)?.get(i);
166
+ a?.slots.delete(r) && y(e, t, i, a);
157
167
  }
158
- function y(e, t, n, r, i) {
159
- let { event: a, once: o } = l(n), s = p(r);
160
- if (!s) {
161
- v(e, t, a, n);
168
+ function S(e, t, n, r, i) {
169
+ let a = d(n), o = h(r);
170
+ if (!o) {
171
+ x(e, t, a, n);
162
172
  return;
163
173
  }
164
- let c = h.get(t);
165
- c || h.set(t, c = /* @__PURE__ */ new Map());
166
- let u = c.get(a);
167
- u || c.set(a, u = _(e, t, a));
168
- let d = u.slots.get(n);
169
- if (d) d.handlers = s, d.instance = i;
174
+ let s = v(a), c = _.get(t);
175
+ c || _.set(t, c = /* @__PURE__ */ new Map());
176
+ let l = c.get(s);
177
+ l || c.set(s, l = b(e, t, s, a));
178
+ let u = l.slots.get(n);
179
+ if (u) u.handlers = o, u.instance = i;
170
180
  else {
171
- u.slots.set(n, {
181
+ l.slots.set(n, {
172
182
  attachedAt: e.latestEventId(),
173
- handlers: s,
183
+ handlers: o,
174
184
  instance: i,
175
- once: o,
185
+ once: a.once,
176
186
  fired: !1
177
187
  });
178
188
  try {
179
- g(e, t, a, u);
189
+ y(e, t, s, l);
180
190
  } catch (e) {
181
- throw u.slots.delete(n), u.slots.size === 0 && c.delete(a), e;
191
+ throw l.slots.delete(n), l.slots.size === 0 && c.delete(s), e;
182
192
  }
183
193
  }
184
194
  }
185
- var b = /* @__PURE__ */ new Set([
195
+ var C = /* @__PURE__ */ new Set([
186
196
  "disabled",
187
197
  "hidden",
188
198
  "inert"
189
199
  ]);
190
- function x(e) {
200
+ function w(e) {
191
201
  return (t, n, r, i, a, o) => {
192
- n === "style" ? f(e, t, i) : s(n) ? y(e, t, n, i, o ?? null) : b.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));
202
+ n === "style" ? m(e, t, i) : s(n) ? S(e, t, n, i, o ?? null) : C.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));
193
203
  };
194
204
  }
195
205
  //#endregion
196
206
  //#region src/vue/createApp.mts
197
- function S(n, r) {
207
+ function T(n, r) {
198
208
  let s = i({
199
209
  ...o(t),
200
- patchProp: x(t)
210
+ patchProp: w(t)
201
211
  }).createApp(n, r), c = s.mount.bind(s);
202
212
  return Object.assign(s, { mount: (n) => c(n ?? a(t, e(), "element")) });
203
213
  }
204
214
  //#endregion
205
- export { S as createIncaApp };
215
+ export { T as createIncaApp };
@@ -0,0 +1,11 @@
1
+ /**
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
6
+ * `passive: false`.
7
+ *
8
+ * It has the listener methods `addEventListener`, `removeEventListener` and
9
+ * `dispatchEvent`.
10
+ */
11
+ export declare const window: import('./types.mts').IncaEventTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incajs",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "A GPU-native, Webview-free desktop app framework built on GPUI and QuickJS.",
5
5
  "keywords": [
6
6
  "cross-platform",
@@ -1,118 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.defineProperty, t = (t, n) => {
3
- let r = {};
4
- for (var i in t) e(r, i, {
5
- get: t[i],
6
- enumerable: !0
7
- });
8
- return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
- };
10
- //#endregion
11
- //#region src/native.mts
12
- function n() {
13
- return globalThis.__inca_native__;
14
- }
15
- //#endregion
16
- //#region src/events.mts
17
- function r() {
18
- let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = 0, r = (e, t) => `${e}:${t}`, i = () => globalThis.__inca_callbacks__ ??= {};
19
- return {
20
- add(a, o, s) {
21
- let c = n++;
22
- return i()[c] = s, e.set(r(a, o), c), t.set(c, r(a, o)), c;
23
- },
24
- idFor(t, n) {
25
- return e.get(r(t, n));
26
- },
27
- release(n) {
28
- delete i()[n];
29
- let r = t.get(n);
30
- r !== void 0 && (t.delete(n), e.delete(r));
31
- }
32
- };
33
- }
34
- var i = r(), a = 0;
35
- function o() {
36
- return a;
37
- }
38
- function s(e) {
39
- return (...t) => {
40
- let n = t[0]?.eventId;
41
- return typeof n == "number" && n > a && (a = n), e(...t);
42
- };
43
- }
44
- function c(e) {
45
- for (let t of e) i.release(t);
46
- }
47
- function l(e, t, r) {
48
- u(e, t);
49
- let a = i.add(e, t, s(r));
50
- try {
51
- n().addEventListener(e, t, a);
52
- } catch (e) {
53
- throw i.release(a), e;
54
- }
55
- }
56
- function u(e, t) {
57
- let r = i.idFor(e, t);
58
- r !== void 0 && (n().removeEventListener(e, t, r), i.release(r));
59
- }
60
- function d(e) {
61
- n().focusNode(e);
62
- }
63
- function f(e) {
64
- n().blurNode(e);
65
- }
66
- //#endregion
67
- //#region src/tree.mts
68
- function p() {
69
- return n().rootNodeId();
70
- }
71
- function m(e) {
72
- return n().createNode(e);
73
- }
74
- function h(e, t) {
75
- n().appendChild(e, t);
76
- }
77
- function g(e, t, r) {
78
- n().insertBefore(e, t, r);
79
- }
80
- function _(e, t) {
81
- n().removeChild(e, t);
82
- }
83
- function v(e) {
84
- c(n().destroyNode(e));
85
- }
86
- function y(e, t, r) {
87
- n().setAttribute(e, t, r);
88
- }
89
- function b(e, t) {
90
- n().removeAttribute(e, t);
91
- }
92
- function x(e, t, r) {
93
- n().setStyle(e, t, r);
94
- }
95
- function S(e, t) {
96
- n().removeStyle(e, t);
97
- }
98
- //#endregion
99
- //#region src/rendererCore.mts
100
- var C = /* @__PURE__ */ t({
101
- appendChild: () => h,
102
- blur: () => f,
103
- createNode: () => m,
104
- destroyNode: () => v,
105
- focus: () => d,
106
- insertBefore: () => g,
107
- latestEventId: () => o,
108
- removeAttribute: () => b,
109
- removeChild: () => _,
110
- removeEventListener: () => u,
111
- removeStyle: () => S,
112
- rootNodeId: () => p,
113
- setAttribute: () => y,
114
- setEventListener: () => l,
115
- setStyle: () => x
116
- });
117
- //#endregion
118
- export { g as a, S as c, x as d, f, l as g, u as h, v as i, p as l, o as m, h as n, b as o, d as p, m as r, _ as s, C as t, y as u };