incajs 0.0.4 → 0.0.6

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
@@ -8,22 +8,18 @@ SPDX-License-Identifier: MIT OR Apache-2.0
8
8
  **Incarnative.js** — a GPU-native, Webview-free desktop application
9
9
  framework. No Chromium, no DOM: UI renders directly on the GPU via
10
10
  [GPUI](https://www.gpui.rs/), driven by an embedded QuickJS runtime
11
- ([`rquickjs`](https://github.com/DelSkayn/rquickjs)) with sub-second
12
- startup.
13
-
14
- ## Features
15
-
16
- - Framework-agnostic core, with first-class Vue 3 support via the
17
- `incajs/vue` subpath (`@vue/runtime-core` is an optional peer
18
- dependency — only needed if you import `incajs/vue`)
19
- - Direct GPU rendering — no Chromium, no DOM
20
- - Embedded QuickJS runtime for sub-second startup and a minimal memory
21
- footprint
11
+ ([`rquickjs`](https://github.com/DelSkayn/rquickjs)).
22
12
 
23
13
  ## How it works
24
14
 
25
- `incajs` is a thin, typed wrapper around the native host bridge.
26
- `incajs/vue` is a custom renderer mapping Vue's `createRenderer`
27
- lifecycle onto those calls.
15
+ - The root `incajs` export is types only.
16
+ - `incajs/vue` is a custom renderer mapping Vue 3's `createRenderer`
17
+ lifecycle onto the native host bridge. `createIncaApp(rootComponent,
18
+ rootProps?)` creates a Vue app whose root mounts against the host's
19
+ own root container instead of a DOM element; `app.mount()` with no
20
+ argument targets it, and `app.unmount`, `app.use`, etc. behave exactly
21
+ as `@vue/runtime-core` documents them.
22
+ - `@vue/runtime-core` is an optional peer dependency, needed only when
23
+ you use `incajs/vue`.
28
24
 
29
25
  Part of [tom96da/incajs](https://github.com/tom96da/incajs).
@@ -75,7 +75,7 @@ function _(e, t, r) {
75
75
  n().setStyle(e, t, r);
76
76
  }
77
77
  //#endregion
78
- //#region src/index.mts
78
+ //#region src/rendererCore.mts
79
79
  var v = /* @__PURE__ */ t({
80
80
  appendChild: () => f,
81
81
  blur: () => l,
package/dist/events.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CallbackId, EventListener, NodeId } from './types.mts';
2
2
  /**
3
3
  * Drops the JS half of every registration in `callbackIds`. The native half
4
- * is already gone by the time this runs — {@link destroyNode} takes both.
4
+ * is already gone by the time this runs — `destroyNode` takes both.
5
5
  * @param callbackIds - ids the host reported as released
6
6
  * @internal
7
7
  */
@@ -12,10 +12,9 @@ export declare function releaseCallbacks(callbackIds: readonly CallbackId[]): vo
12
12
  *
13
13
  * The host holds a list per `(nodeId, event)` and dispatches to all of it;
14
14
  * this wrapper keeps one, the way a framework adapter composes its own
15
- * handlers into a single callback. `"click"`/`"mousedown"`/`"mouseup"`/
16
- * `"mousemove"`/`"wheel"`/`"mouseenter"`/`"mouseleave"`/`"focus"`/`"blur"`
17
- * are wired to real native input today; other event names are accepted but
18
- * never fire.
15
+ * handlers into a single callback. See {@link EventListener} for which
16
+ * event names are wired to real native input today; other names are
17
+ * accepted but never fire.
19
18
  * @param nodeId - the node to listen on
20
19
  * @param event - the event name (e.g. `"click"`)
21
20
  * @param listener - called when the event fires
package/dist/index.d.mts CHANGED
@@ -1,3 +1 @@
1
- export { blur, focus, removeEventListener, setEventListener } from './events.mts';
2
- export { appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, setStyle, } from './tree.mts';
3
1
  export type { AttributeValue, CallbackId, EventListener, NodeId, StyleProps, TagName, } from './types.mts';
package/dist/index.js CHANGED
@@ -1,2 +0,0 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, u as d } from "./chunks/src-SeArA65c.js";
2
- export { o as appendChild, d as blur, l as createNode, i as destroyNode, n as focus, e as insertBefore, s as removeChild, r as removeEventListener, u as rootNodeId, t as setAttribute, c as setEventListener, a as setStyle };
@@ -1,10 +1,10 @@
1
+ export { setEventListener, removeEventListener, focus, blur } from './events.mts';
2
+ export { appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, setStyle, } from './tree.mts';
1
3
  /**
2
- * The subset of `incajs`'s own API a custom renderer (`incajs/vue`, and any
3
- * future framework adapter alongside it) drives the native tree through —
4
- * derived from `index.mts`'s real exports, so this contract can't drift out
5
- * of sync with them.
4
+ * The tree/event primitives a custom renderer (`incajs/vue`) drives the
5
+ * native tree through.
6
6
  *
7
7
  * Also the seam a renderer's own tests mock against, in place of a real
8
8
  * `globalThis.__inca_native__`.
9
9
  */
10
- export type IncaCore = Pick<typeof import("./index.mts"), "rootNodeId" | "createNode" | "appendChild" | "insertBefore" | "removeChild" | "destroyNode" | "setAttribute" | "setStyle" | "setEventListener" | "removeEventListener">;
10
+ export type IncaCore = typeof import("./rendererCore.mts");
@@ -0,0 +1,2 @@
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, u as d } from "./chunks/rendererCore-Kxb_fevG.js";
2
+ export { o as appendChild, d as blur, l as createNode, i as destroyNode, n as focus, e as insertBefore, s as removeChild, r as removeEventListener, u as rootNodeId, t as setAttribute, c as setEventListener, a as setStyle };
package/dist/types.d.mts CHANGED
@@ -1,11 +1,21 @@
1
- /** Stable handle to a node in the native retained tree, returned by {@link createNode} and used in every later call that touches that node. */
1
+ /**
2
+ * Stable handle to a node in the native retained tree, returned by `createNode`
3
+ * and used in every later call that touches that node.
4
+ */
2
5
  export type NodeId = number;
3
- /** Id assigned to one registered event listener. Managed internally by {@link setEventListener}/{@link removeEventListener}/{@link destroyNode} — callers never see or pass one directly. */
6
+ /**
7
+ * Id assigned to one registered event listener. Managed internally by
8
+ * `setEventListener`/`removeEventListener`/`destroyNode` — callers never see or
9
+ * pass one directly.
10
+ */
4
11
  export type CallbackId = number;
5
- /** A value {@link setAttribute}/{@link setStyle} can take. Anything else raises a catchable exception rather than being silently coerced. */
12
+ /**
13
+ * A value `setAttribute`/`setStyle` can take. Anything else raises a catchable
14
+ * exception rather than being silently coerced.
15
+ */
6
16
  export type AttributeValue = string | number | boolean;
7
17
  /**
8
- * Element kind passed to {@link createNode}. `"text"` is the only tag with
18
+ * Element kind passed to `createNode`. `"text"` is the only tag with
9
19
  * dedicated rendering behavior — a leaf that renders its `"value"`
10
20
  * attribute's string content. Any other string is a generic styled
11
21
  * container; the `string & {}` half of this type keeps `"text"`'s
@@ -13,7 +23,7 @@ export type AttributeValue = string | number | boolean;
13
23
  */
14
24
  export type TagName = "text" | (string & {});
15
25
  /**
16
- * Style properties recognized by {@link setStyle}'s typed overload. A
26
+ * Style properties recognized by `setStyle`'s typed overload. A
17
27
  * deliberately incomplete, v1 layout/paint vocabulary — an unrecognized key
18
28
  * or a value shape that doesn't parse (e.g. a malformed enum string) is
19
29
  * ignored by the renderer rather than applied or thrown.
@@ -47,25 +57,12 @@ export interface StyleProps {
47
57
  text_size?: number;
48
58
  }
49
59
  /**
50
- * Signature of a callback registered via {@link setEventListener}. The
60
+ * Signature of a callback registered via `setEventListener`. The
51
61
  * native host calls it with one argument, an object with `type` (the
52
62
  * event's name), `target`/`currentTarget` (both the {@link NodeId} it fired
53
63
  * on), `stopPropagation`/`stopImmediatePropagation`/`preventDefault`
54
- * methods, plus whatever fields that event kind carries.
55
- *
56
- * `"mousedown"`/`"mouseup"`/`"mousemove"`/`"mouseenter"`/`"mouseleave"`
57
- * carry `clientX`, `clientY`, `button`, `buttons`, `detail`, and
58
- * `ctrlKey`/`shiftKey`/`altKey`/`metaKey`, DOM-`MouseEvent`-named.
59
- * `"wheel"` carries those same fields plus `deltaX`/`deltaY`/`deltaZ`/
60
- * `deltaMode`, DOM-`WheelEvent`-named (`deltaMode` is `0` or `1`; `deltaZ`
61
- * is always `0`). `"keydown"`/`"keyup"` carry `key`, `repeat`, and
62
- * `ctrlKey`/`shiftKey`/`altKey`/`metaKey`, DOM-`KeyboardEvent`-named, and
63
- * fire on whichever node is currently focused, bubbling to its ancestors;
64
- * with nothing focused, neither reaches any node. `"click"`/`"focus"`/
65
- * `"blur"` carry none of their own.
66
- *
67
- * An element already under the pointer when it mounts gets a
68
- * `"mouseenter"` the first time its hover state is checked, with no
69
- * pointer movement involved.
64
+ * methods, plus whatever fields that event kind carries — see
65
+ * https://tom96da.github.io/incajs/reference/events for the full list of
66
+ * wired event names and their fields.
70
67
  */
71
68
  export type EventListener = (...args: unknown[]) => void;
@@ -3,23 +3,34 @@ import { IncaCore } from '../rendererCore.mts';
3
3
  import { NodeId } from '../types.mts';
4
4
  /**
5
5
  * A container host node: either a real element or the hidden stand-in
6
- * {@link nodeOps.createComment} uses. Also `@vue/runtime-core`'s
6
+ * {@link NodeOps.createComment} uses. Also `@vue/runtime-core`'s
7
7
  * `HostElement` — the only host node type that can act as a parent.
8
8
  *
9
9
  * `inca`'s native tree has no parent pointers and no way to list a
10
10
  * node's children, so `parent`/`children` are maintained here as a
11
- * JS-side shadow of the tree, kept in sync by {@link nodeOps.insert}/
12
- * {@link nodeOps.remove}.
11
+ * JS-side shadow of the tree, kept in sync by {@link NodeOps.insert}/
12
+ * {@link NodeOps.remove}.
13
13
  */
14
14
  export interface IncaElement {
15
- /** The underlying native node's id — the only part of this object the native tree itself knows about. */
15
+ /**
16
+ * The underlying native node's id — the only part of this object the native
17
+ * tree itself knows about.
18
+ */
16
19
  readonly id: NodeId;
17
- /** `"comment"` for the hidden stand-in {@link nodeOps.createComment} produces; `"element"` for every other container. Purely informational — both render identically once created. */
20
+ /**
21
+ * `"comment"` for the hidden stand-in {@link NodeOps.createComment}
22
+ * produces; `"element"` for every other container. Purely
23
+ * informational — both render identically once created.
24
+ */
18
25
  readonly kind: "element" | "comment";
19
26
  /** The current parent, or `null` if this node isn't attached to the tree. */
20
27
  parent: IncaElement | null;
21
28
  /** This node's children, in render order. */
22
29
  children: IncaNode[];
30
+ /** Focuses this node next frame. */
31
+ focus(): void;
32
+ /** Unfocuses whatever's focused, next frame. */
33
+ blur(): void;
23
34
  }
24
35
  /** A text leaf host node — `@vue/runtime-core`'s `HostNode` for text. */
25
36
  export interface IncaText {
@@ -29,16 +40,21 @@ export interface IncaText {
29
40
  readonly kind: "text";
30
41
  /** The current parent, or `null` if this node isn't attached to the tree. */
31
42
  parent: IncaElement | null;
32
- /** The text content, mirroring what's been pushed to the native node via {@link setAttribute}. */
43
+ /**
44
+ * The text content, mirroring what's been pushed to the native node via
45
+ * {@link IncaCore.setAttribute}.
46
+ */
33
47
  text: string;
34
48
  }
35
- /** Any host node {@link nodeOps} can produce: an element, comment, or text leaf. */
49
+ /** Any host node {@link NodeOps} can produce: an element, comment, or text leaf. */
36
50
  export type IncaNode = IncaElement | IncaText;
51
+ /** {@link createNodeOps}'s return shape. */
52
+ export type NodeOps = Omit<RendererOptions<IncaNode, IncaElement>, "patchProp">;
37
53
  /**
38
54
  * `@vue/runtime-core`'s {@link RendererOptions}`<IncaNode, IncaElement>`,
39
- * minus `patchProp` (see `./patchProp.mts`) — the host-node lifecycle half
40
- * of `incajs/vue`'s custom renderer, built entirely on the injected
41
- * {@link IncaCore}, never on the native bridge directly.
55
+ * minus `patchProp` — the host-node lifecycle half of `incajs/vue`'s custom
56
+ * renderer, built entirely on the injected {@link IncaCore}, never on the
57
+ * native bridge directly.
42
58
  * @param core - the incajs bindings to drive the native tree through
43
59
  */
44
- export declare function createNodeOps(core: IncaCore): Omit<RendererOptions<IncaNode, IncaElement>, "patchProp">;
60
+ export declare function createNodeOps(core: IncaCore): NodeOps;
@@ -9,11 +9,14 @@ import { IncaElement } from './nodeOps.mts';
9
9
  * `core.setStyle` call per entry; an entry whose value isn't a
10
10
  * string/number is skipped.
11
11
  * - An `onXxx` key registers `nextValue` as the listener for `xxx`, taking a
12
- * function or an array of them, and unbinds `xxx` for anything else — only
13
- * `"click"`/`"mousedown"`/`"mouseup"`/`"mousemove"`/`"wheel"`/
14
- * `"mouseenter"`/`"mouseleave"`/`"focus"`/`"blur"`/`"keydown"`/`"keyup"`
15
- * are wired to real input by the native host today, other event names
16
- * are accepted but never fire.
12
+ * function or an array of them, and unbinds `xxx` for anything else. A
13
+ * trailing `Once`/`Passive`/`Capture` suffix (from Vue's `.once`/
14
+ * `.passive`/`.capture` modifiers) is stripped first; `.once` really
15
+ * removes the listener after it fires once, while `.passive`/`.capture`
16
+ * bind as an ordinary listener with no native passive/capture-phase
17
+ * support yet. See {@link EventListener} for which event names are wired
18
+ * to real input by the native host today; other names are accepted but
19
+ * never fire.
17
20
  * - Everything else falls through to `core.setAttribute`, again skipping
18
21
  * a non-string/number/boolean value rather than passing it through.
19
22
  *
package/dist/vue.js CHANGED
@@ -1,7 +1,7 @@
1
- import { s as e, t } from "./chunks/src-SeArA65c.js";
2
- import { createRenderer as n } from "@vue/runtime-core";
1
+ import { d as e, s as t, t as n, u as r } from "./chunks/rendererCore-Kxb_fevG.js";
2
+ import { createRenderer as i } from "@vue/runtime-core";
3
3
  //#region src/vue/nodeOps.mts
4
- function r(e) {
4
+ function a(e) {
5
5
  function t(t) {
6
6
  let n = e.createNode("text");
7
7
  return e.setAttribute(n, "value", t), {
@@ -20,13 +20,21 @@ function r(e) {
20
20
  function r(t) {
21
21
  t.parent && e.removeChild(t.parent.id, t.id), n(t);
22
22
  }
23
+ function i(t) {
24
+ return {
25
+ focus: () => e.focus(t),
26
+ blur: () => e.blur()
27
+ };
28
+ }
23
29
  return {
24
30
  createElement(t) {
31
+ let n = e.createNode(t);
25
32
  return {
26
- id: e.createNode(t),
33
+ id: n,
27
34
  kind: "element",
28
35
  parent: null,
29
- children: []
36
+ children: [],
37
+ ...i(n)
30
38
  };
31
39
  },
32
40
  createText: t,
@@ -36,7 +44,8 @@ function r(e) {
36
44
  id: n,
37
45
  kind: "comment",
38
46
  parent: null,
39
- children: []
47
+ children: [],
48
+ ...i(n)
40
49
  };
41
50
  },
42
51
  setText(t, n) {
@@ -69,11 +78,19 @@ function r(e) {
69
78
  }
70
79
  //#endregion
71
80
  //#region src/vue/patchProp.mts
72
- var i = (e) => /^on[A-Z]/.test(e);
73
- function a(e, t, n) {
81
+ var o = (e) => /^on[A-Z]/.test(e), s = /(?:Once|Passive|Capture)$/;
82
+ function c(e) {
83
+ let t = e, n = !1, r;
84
+ for (; r = t.match(s);) t = t.slice(0, -r[0].length), r[0] === "Once" && (n = !0);
85
+ return {
86
+ event: t.slice(2).toLowerCase(),
87
+ once: n
88
+ };
89
+ }
90
+ function l(e, t, n) {
74
91
  if (typeof n == "object" && n) for (let [r, i] of Object.entries(n)) (typeof i == "string" || typeof i == "number") && e.setStyle(t.id, r, i);
75
92
  }
76
- function o(e) {
93
+ function u(e) {
77
94
  if (typeof e == "function") return e;
78
95
  if (!Array.isArray(e)) return null;
79
96
  let t = e.filter((e) => typeof e == "function");
@@ -81,28 +98,44 @@ function o(e) {
81
98
  for (let n of t) n(...e);
82
99
  };
83
100
  }
84
- function s(e, t, n, r) {
85
- let i = n.slice(2).toLowerCase(), a = o(r);
86
- a ? e.setEventListener(t.id, i, a) : e.removeEventListener(t.id, i);
101
+ function d(e, t, n, r) {
102
+ let { event: i, once: a } = c(n), o = u(r);
103
+ if (!o) {
104
+ e.removeEventListener(t.id, i);
105
+ return;
106
+ }
107
+ if (!a) {
108
+ e.setEventListener(t.id, i, o);
109
+ return;
110
+ }
111
+ e.setEventListener(t.id, i, (...n) => {
112
+ e.removeEventListener(t.id, i), o(...n);
113
+ });
87
114
  }
88
- function c(e) {
89
- return (t, n, r, o) => {
90
- n === "style" ? a(e, t, o) : i(n) ? s(e, t, n, o) : (typeof o == "string" || typeof o == "number" || typeof o == "boolean") && e.setAttribute(t.id, n, o);
115
+ function f(e) {
116
+ return (t, n, r, i) => {
117
+ n === "style" ? l(e, t, i) : o(n) ? d(e, t, n, i) : (typeof i == "string" || typeof i == "number" || typeof i == "boolean") && e.setAttribute(t.id, n, i);
91
118
  };
92
119
  }
93
120
  //#endregion
94
121
  //#region src/vue/createApp.mts
95
- function l(i, a) {
96
- let o = n({
97
- ...r(t),
98
- patchProp: c(t)
99
- }).createApp(i, a), s = o.mount.bind(o);
100
- return Object.assign(o, { mount: (t) => s(t ?? {
101
- id: e(),
102
- kind: "element",
103
- parent: null,
104
- children: []
105
- }) });
122
+ function p(o, s) {
123
+ let c = i({
124
+ ...a(n),
125
+ patchProp: f(n)
126
+ }).createApp(o, s), l = c.mount.bind(c);
127
+ function u() {
128
+ let n = t();
129
+ return {
130
+ id: n,
131
+ kind: "element",
132
+ parent: null,
133
+ children: [],
134
+ focus: () => e(n),
135
+ blur: () => r()
136
+ };
137
+ }
138
+ return Object.assign(c, { mount: (e) => l(e ?? u()) });
106
139
  }
107
140
  //#endregion
108
- export { l as createIncaApp };
141
+ export { p as createIncaApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incajs",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A GPU-native, Webview-free desktop app framework built on GPUI and QuickJS.",
5
5
  "keywords": [
6
6
  "cross-platform",