incajs 0.0.5 → 0.0.7

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,15 +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.
11
+ ([`rquickjs`](https://github.com/DelSkayn/rquickjs)).
13
12
 
14
13
  ## How it works
15
14
 
16
- - `incajs` is a thin, typed wrapper around the native host bridge
17
- - Vue 3 support is a custom renderer mapping Vue's `createRenderer`
18
- 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.
19
22
  - `@vue/runtime-core` is an optional peer dependency, needed only when
20
- you use it
23
+ you use `incajs/vue`.
21
24
 
22
25
  Part of [tom96da/incajs](https://github.com/tom96da/incajs).
@@ -36,7 +36,13 @@ function a(e) {
36
36
  for (let t of e) i.release(t);
37
37
  }
38
38
  function o(e, t, r) {
39
- s(e, t), n().addEventListener(e, t, i.add(e, t, r));
39
+ s(e, t);
40
+ let a = i.add(e, t, r);
41
+ try {
42
+ n().addEventListener(e, t, a);
43
+ } catch (e) {
44
+ throw i.release(a), e;
45
+ }
40
46
  }
41
47
  function s(e, t) {
42
48
  let r = i.idFor(e, t);
@@ -45,8 +51,8 @@ function s(e, t) {
45
51
  function c(e) {
46
52
  n().focusNode(e);
47
53
  }
48
- function l() {
49
- n().blurNode();
54
+ function l(e) {
55
+ n().blurNode(e);
50
56
  }
51
57
  //#endregion
52
58
  //#region src/tree.mts
@@ -74,9 +80,12 @@ function g(e, t, r) {
74
80
  function _(e, t, r) {
75
81
  n().setStyle(e, t, r);
76
82
  }
83
+ function v(e, t) {
84
+ n().removeStyle(e, t);
85
+ }
77
86
  //#endregion
78
87
  //#region src/rendererCore.mts
79
- var v = /* @__PURE__ */ t({
88
+ var y = /* @__PURE__ */ t({
80
89
  appendChild: () => f,
81
90
  blur: () => l,
82
91
  createNode: () => d,
@@ -85,10 +94,11 @@ var v = /* @__PURE__ */ t({
85
94
  insertBefore: () => p,
86
95
  removeChild: () => m,
87
96
  removeEventListener: () => s,
97
+ removeStyle: () => v,
88
98
  rootNodeId: () => u,
89
99
  setAttribute: () => g,
90
100
  setEventListener: () => o,
91
101
  setStyle: () => _
92
102
  });
93
103
  //#endregion
94
- export { p as a, g as c, c as d, s as f, h as i, _ as l, f as n, m as o, o as p, d as r, u as s, v as t, l as u };
104
+ export { p as a, u as c, l as d, c as f, h as i, g as l, o as m, f as n, m as o, s as p, d as r, v as s, y as t, _ as u };
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
  */
@@ -37,7 +37,9 @@ export declare function removeEventListener(nodeId: NodeId, event: string): void
37
37
  */
38
38
  export declare function focus(nodeId: NodeId): void;
39
39
  /**
40
- * Requests that whatever is focused become unfocused. Takes effect on the
41
- * next frame; a no-op if nothing is focused when it runs.
40
+ * Requests that `nodeId` become unfocused, the way `element.blur()` does.
41
+ * Takes effect on the next frame; a no-op if `nodeId` isn't the focused node
42
+ * when it runs.
43
+ * @param nodeId - the node to unfocus
42
44
  */
43
- export declare function blur(): void;
45
+ export declare function blur(nodeId: NodeId): void;
package/dist/native.d.mts CHANGED
@@ -8,11 +8,12 @@ interface IncaNative {
8
8
  removeChild(parentId: NodeId, childId: NodeId): void;
9
9
  setAttribute(nodeId: NodeId, key: string, value: AttributeValue): void;
10
10
  setStyle(nodeId: NodeId, key: string, value: AttributeValue): void;
11
+ removeStyle(nodeId: NodeId, key: string): void;
11
12
  addEventListener(nodeId: NodeId, event: string, callbackId: CallbackId): void;
12
13
  removeEventListener(nodeId: NodeId, event: string, callbackId: CallbackId): boolean;
13
14
  destroyNode(nodeId: NodeId): CallbackId[];
14
15
  focusNode(nodeId: NodeId): void;
15
- blurNode(): void;
16
+ blurNode(nodeId: NodeId): void;
16
17
  }
17
18
  declare global {
18
19
  var __inca_native__: IncaNative;
@@ -1,8 +1,8 @@
1
1
  export { setEventListener, removeEventListener, focus, blur } from './events.mts';
2
- export { appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, setStyle, } from './tree.mts';
2
+ export { appendChild, createNode, destroyNode, insertBefore, removeChild, rootNodeId, setAttribute, setStyle, removeStyle, } from './tree.mts';
3
3
  /**
4
- * The subset of `incajs`'s own API a custom renderer (`incajs/vue`, and any
5
- * future framework adapter alongside it) drives the native tree through.
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__`.
@@ -1,2 +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 };
1
+ import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, u as f } from "./chunks/rendererCore-BmtunkdP.js";
2
+ export { s as appendChild, n as blur, u as createNode, i as destroyNode, r as focus, e as insertBefore, c as removeChild, l as removeEventListener, d as removeStyle, t as rootNodeId, a as setAttribute, o as setEventListener, f as setStyle };
package/dist/tree.d.mts CHANGED
@@ -69,3 +69,10 @@ export declare function setAttribute(nodeId: NodeId, key: string, value: Attribu
69
69
  */
70
70
  export declare function setStyle<K extends keyof StyleProps>(nodeId: NodeId, key: K, value: NonNullable<StyleProps[K]>): void;
71
71
  export declare function setStyle(nodeId: NodeId, key: string, value: AttributeValue): void;
72
+ /**
73
+ * Removes a style property from `nodeId`, so it renders as if never set.
74
+ * Removing a property that isn't set does nothing.
75
+ * @param nodeId - the node to update
76
+ * @param key - the style property name
77
+ */
78
+ export declare function removeStyle(nodeId: NodeId, key: string): void;
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,7 +57,7 @@ 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`
@@ -29,7 +29,7 @@ export interface IncaElement {
29
29
  children: IncaNode[];
30
30
  /** Focuses this node next frame. */
31
31
  focus(): void;
32
- /** Unfocuses whatever's focused, next frame. */
32
+ /** Unfocuses this node next frame, if it is the focused one. */
33
33
  blur(): void;
34
34
  }
35
35
  /** A text leaf host node — `@vue/runtime-core`'s `HostNode` for text. */
@@ -40,7 +40,10 @@ export interface IncaText {
40
40
  readonly kind: "text";
41
41
  /** The current parent, or `null` if this node isn't attached to the tree. */
42
42
  parent: IncaElement | null;
43
- /** 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
+ */
44
47
  text: string;
45
48
  }
46
49
  /** Any host node {@link NodeOps} can produce: an element, comment, or text leaf. */
@@ -49,9 +52,9 @@ export type IncaNode = IncaElement | IncaText;
49
52
  export type NodeOps = Omit<RendererOptions<IncaNode, IncaElement>, "patchProp">;
50
53
  /**
51
54
  * `@vue/runtime-core`'s {@link RendererOptions}`<IncaNode, IncaElement>`,
52
- * minus `patchProp` (see `./patchProp.mts`) — the host-node lifecycle half
53
- * of `incajs/vue`'s custom renderer, built entirely on the injected
54
- * {@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.
55
58
  * @param core - the incajs bindings to drive the native tree through
56
59
  */
57
60
  export declare function createNodeOps(core: IncaCore): NodeOps;
@@ -5,18 +5,26 @@ import { IncaElement } from './nodeOps.mts';
5
5
  * {@link RendererOptions.patchProp} — applies one changed `v-bind`/
6
6
  * attribute/event prop to a host element:
7
7
  *
8
- * - `style` (an object, per `:style="{...}"`) fans out to one
9
- * `core.setStyle` call per entry; an entry whose value isn't a
10
- * string/number is skipped.
8
+ * - `style` (an object, per `:style="{...}"`) is diffed against the entries
9
+ * already sent for this element. `core.setStyle` runs for each entry that
10
+ * is new or changed. `core.removeStyle` runs for each sent entry that is now
11
+ * absent, `null`, or not a string/number. A string or `null` `style`
12
+ * removes every entry.
11
13
  * - 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 — see
13
- * {@link EventListener} for which event names are wired to real input by
14
- * the native host today; other names are accepted but never fire.
14
+ * function or an array of them, and unbinds `xxx` for anything else. A
15
+ * trailing `Once`/`Passive`/`Capture` suffix (from Vue's `.once`/
16
+ * `.passive`/`.capture` modifiers) is stripped first; `.once` really
17
+ * removes the listener after it fires once, while `.passive`/`.capture`
18
+ * bind as an ordinary listener with no native passive/capture-phase
19
+ * support yet. See {@link EventListener} for which event names are wired
20
+ * to real input by the native host today; other names are accepted but
21
+ * never fire. An error a handler throws synchronously goes to the app's
22
+ * `errorHandler` and `onErrorCaptured` hooks; with no `errorHandler` it is
23
+ * also rethrown to the host's error report.
15
24
  * - Everything else falls through to `core.setAttribute`, again skipping
16
25
  * a non-string/number/boolean value rather than passing it through.
17
26
  *
18
- * There is no native "unset" call, so a prop that's removed entirely (a
19
- * `null`/`undefined` `nextValue`) is left as-is rather than cleared.
27
+ * Removing any other prop (a `null`/`undefined` `nextValue`) leaves it as-is.
20
28
  * @param core - the incajs bindings to drive the native tree through
21
29
  */
22
30
  export declare function createPatchProp(core: IncaCore): RendererOptions<unknown, IncaElement>["patchProp"];
package/dist/vue.js CHANGED
@@ -1,7 +1,7 @@
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";
1
+ import { c as e, d as t, f as n, t as r } from "./chunks/rendererCore-BmtunkdP.js";
2
+ import { ErrorCodes as i, callWithAsyncErrorHandling as a, createRenderer as o } from "@vue/runtime-core";
3
3
  //#region src/vue/nodeOps.mts
4
- function a(e) {
4
+ function s(e) {
5
5
  function t(t) {
6
6
  let n = e.createNode("text");
7
7
  return e.setAttribute(n, "value", t), {
@@ -23,7 +23,7 @@ function a(e) {
23
23
  function i(t) {
24
24
  return {
25
25
  focus: () => e.focus(t),
26
- blur: () => e.blur()
26
+ blur: () => e.blur(t)
27
27
  };
28
28
  }
29
29
  return {
@@ -58,6 +58,7 @@ function a(e) {
58
58
  e.appendChild(n.id, i.id), i.parent = n, n.children.push(i);
59
59
  },
60
60
  insert(t, n, i) {
61
+ if (i === t && t.parent === n) return;
61
62
  r(t);
62
63
  let a = i ? n.children.indexOf(i) : -1;
63
64
  e.insertBefore(n.id, t.id, i && a !== -1 ? i.id : null), a === -1 ? n.children.push(t) : n.children.splice(a, 0, t), t.parent = n;
@@ -78,46 +79,83 @@ function a(e) {
78
79
  }
79
80
  //#endregion
80
81
  //#region src/vue/patchProp.mts
81
- var o = (e) => /^on[A-Z]/.test(e);
82
- function s(e, t, n) {
83
- 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);
82
+ var c = (e) => /^on[A-Z]/.test(e), l = /(?:Once|Passive|Capture)$/;
83
+ function u(e) {
84
+ let t = e, n = !1, r;
85
+ for (; r = t.match(l);) t = t.slice(0, -r[0].length), r[0] === "Once" && (n = !0);
86
+ return {
87
+ event: t.slice(2).toLowerCase(),
88
+ once: n
89
+ };
84
90
  }
85
- function c(e) {
86
- if (typeof e == "function") return e;
87
- if (!Array.isArray(e)) return null;
88
- let t = e.filter((e) => typeof e == "function");
89
- return t.length === 0 ? null : (...e) => {
90
- for (let n of t) n(...e);
91
+ var d = (e) => typeof e == "string" || typeof e == "number", f = /* @__PURE__ */ new WeakMap();
92
+ function p(e, t, n) {
93
+ let r = typeof n == "object" && n ? n : {}, i = f.get(t);
94
+ i || f.set(t, i = /* @__PURE__ */ new Map());
95
+ for (let n of i.keys()) d(r[n]) || (e.removeStyle(t.id, n), i.delete(n));
96
+ for (let [n, a] of Object.entries(r)) d(a) && i.get(n) !== a && (e.setStyle(t.id, n, a), i.set(n, a));
97
+ }
98
+ var m = (() => {
99
+ try {
100
+ return process.env.NODE_ENV === "production";
101
+ } catch {
102
+ return !1;
103
+ }
104
+ })(), h = (e) => e != null && typeof e.then == "function";
105
+ function g(e, t) {
106
+ let n = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "function");
107
+ return n.length === 0 ? null : (...e) => {
108
+ let r, o = n.map((e) => (...n) => {
109
+ try {
110
+ let r = e(...n);
111
+ return m && h(r) && r.then(void 0, (e) => {
112
+ if (!t?.appContext.config.errorHandler) throw e;
113
+ }), r;
114
+ } catch (e) {
115
+ throw r ??= { error: e }, e;
116
+ }
117
+ });
118
+ if (a(o, t, i.NATIVE_EVENT_HANDLER, e), r && !t?.appContext.config.errorHandler) throw r.error;
91
119
  };
92
120
  }
93
- function l(e, t, n, r) {
94
- let i = n.slice(2).toLowerCase(), a = c(r);
95
- a ? e.setEventListener(t.id, i, a) : e.removeEventListener(t.id, i);
121
+ function _(e, t, n, r, i) {
122
+ let { event: a, once: o } = u(n), s = g(r, i);
123
+ if (!s) {
124
+ e.removeEventListener(t.id, a);
125
+ return;
126
+ }
127
+ if (!o) {
128
+ e.setEventListener(t.id, a, s);
129
+ return;
130
+ }
131
+ e.setEventListener(t.id, a, (...n) => {
132
+ e.removeEventListener(t.id, a), s(...n);
133
+ });
96
134
  }
97
- function u(e) {
98
- return (t, n, r, i) => {
99
- n === "style" ? s(e, t, i) : o(n) ? l(e, t, n, i) : (typeof i == "string" || typeof i == "number" || typeof i == "boolean") && e.setAttribute(t.id, n, i);
135
+ function v(e) {
136
+ return (t, n, r, i, a, o) => {
137
+ n === "style" ? p(e, t, i) : c(n) ? _(e, t, n, i, o ?? null) : (typeof i == "string" || typeof i == "number" || typeof i == "boolean") && e.setAttribute(t.id, n, i);
100
138
  };
101
139
  }
102
140
  //#endregion
103
141
  //#region src/vue/createApp.mts
104
- function d(o, s) {
105
- let c = i({
106
- ...a(n),
107
- patchProp: u(n)
108
- }).createApp(o, s), l = c.mount.bind(c);
109
- function d() {
110
- let n = t();
142
+ function y(i, a) {
143
+ let c = o({
144
+ ...s(r),
145
+ patchProp: v(r)
146
+ }).createApp(i, a), l = c.mount.bind(c);
147
+ function u() {
148
+ let r = e();
111
149
  return {
112
- id: n,
150
+ id: r,
113
151
  kind: "element",
114
152
  parent: null,
115
153
  children: [],
116
- focus: () => e(n),
117
- blur: () => r()
154
+ focus: () => n(r),
155
+ blur: () => t(r)
118
156
  };
119
157
  }
120
- return Object.assign(c, { mount: (e) => l(e ?? d()) });
158
+ return Object.assign(c, { mount: (e) => l(e ?? u()) });
121
159
  }
122
160
  //#endregion
123
- export { d as createIncaApp };
161
+ export { y as createIncaApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incajs",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A GPU-native, Webview-free desktop app framework built on GPUI and QuickJS.",
5
5
  "keywords": [
6
6
  "cross-platform",