incajs 0.0.11 → 0.0.13

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/dist/events.d.mts CHANGED
@@ -38,7 +38,8 @@ export declare function removeEventListener(nodeId: NodeId, event: string): void
38
38
  * dispatching `"blur"`/`"focus"` for whatever actually changed — `nodeId`
39
39
  * doesn't need a `"focus"`/`"blur"` listener registered for this to work,
40
40
  * the same way `element.focus()` works on any focusable DOM element
41
- * regardless of whether it's being listened to.
41
+ * regardless of whether it's being listened to. The node needs a `tabindex`
42
+ * attribute to take focus.
42
43
  * @param nodeId - the node to focus
43
44
  */
44
45
  export declare function focus(nodeId: NodeId): void;
@@ -1,2 +1 @@
1
- import { a as e, c as t, d as n, f as r, g as i, h as a, i as o, l as s, m as c, n as l, o as u, p as d, r as f, s as p, u as m } from "./chunks/rendererCore-vR5RIa7d.js";
2
- export { l as appendChild, r as blur, f as createNode, o as destroyNode, d as focus, e as insertBefore, c as latestEventId, u as removeAttribute, p as removeChild, a as removeEventListener, t as removeStyle, s as rootNodeId, m as setAttribute, i as setEventListener, n as setStyle };
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";
package/dist/tree.d.mts CHANGED
@@ -65,21 +65,26 @@ export declare function setAttribute(nodeId: NodeId, key: string, value: Attribu
65
65
  */
66
66
  export declare function removeAttribute(nodeId: NodeId, key: string): void;
67
67
  /**
68
- * Sets a style property on `nodeId` — the only way to reach {@link setAttribute}'s
69
- * counterpart style map. A key from {@link StyleProps} gets compile-time
70
- * checking on its value's shape; any other string key still forwards as a
71
- * raw {@link AttributeValue}, for style properties this package's types
72
- * haven't caught up with yet.
68
+ * Sets a style property on `nodeId`. A snake_case key from {@link StyleProps}
69
+ * gets compile-time checking on its value's shape. Any other string key, such
70
+ * as a camelCase or kebab-case spelling or a property the types do not list,
71
+ * forwards as a raw {@link AttributeValue}.
72
+ *
73
+ * A key takes any of three spellings: kebab-case (`flex-direction`),
74
+ * camelCase (`flexDirection`) or snake_case (`flex_direction`). All three
75
+ * name the same property, and the value set most recently applies.
73
76
  * @param nodeId - the node to update
74
- * @param key - the style property name
77
+ * @param key - the style property name in any of the three spellings
75
78
  * @param value - the style property value
76
79
  */
77
80
  export declare function setStyle<K extends keyof StyleProps>(nodeId: NodeId, key: K, value: NonNullable<StyleProps[K]>): void;
78
81
  export declare function setStyle(nodeId: NodeId, key: string, value: AttributeValue): void;
79
82
  /**
80
83
  * Removes a style property from `nodeId`, so it renders as if never set.
81
- * Removing a property that isn't set does nothing.
84
+ * Removing a property that isn't set does nothing. The key takes any of the
85
+ * three spellings {@link setStyle} accepts, and removes the property whichever
86
+ * spelling set it.
82
87
  * @param nodeId - the node to update
83
- * @param key - the style property name
88
+ * @param key - the style property name in any of the three spellings
84
89
  */
85
90
  export declare function removeStyle(nodeId: NodeId, key: string): void;
package/dist/types.d.mts CHANGED
@@ -23,9 +23,10 @@ export type AttributeValue = string | number | boolean;
23
23
  */
24
24
  export type TagName = "text" | (string & {});
25
25
  /**
26
- * Style properties recognized by `setStyle`'s typed overload. A
27
- * deliberately incomplete, v1 layout/paint vocabulary — an unrecognized key
28
- * or a value shape that doesn't parse (e.g. a malformed enum string) is
26
+ * Style properties, in their snake_case spelling, that `setStyle`'s typed
27
+ * overload checks. A deliberately incomplete, v1 layout/paint vocabulary. The
28
+ * renderer also reads the camelCase and kebab-case spellings. An unrecognized
29
+ * key or a value shape that doesn't parse (e.g. a malformed enum string) is
29
30
  * ignored by the renderer rather than applied or thrown.
30
31
  */
31
32
  export interface StyleProps {
@@ -109,7 +110,17 @@ export interface StyleProps {
109
110
  *
110
111
  * The native host calls it with one argument, an object with:
111
112
  * - `type`: the event's name.
112
- * - `target` and `currentTarget`: both the {@link NodeId} the event fired on.
113
+ * - `target`: the {@link NodeId} the event is about. It is the deepest node
114
+ * under the pointer for pointer events, the nearest common ancestor of the
115
+ * press and the release for `click`, `dblclick` and `auxclick`, and the
116
+ * focused node (the root when nothing is focused) for key events.
117
+ * - `currentTarget`: the {@link NodeId} whose listener is running.
118
+ * - `bubbles`, `cancelable` and `composed`: fixed per event name.
119
+ * - `defaultPrevented`: `true` once a listener called `preventDefault()` on a
120
+ * cancelable event.
121
+ * - `eventPhase`: 2 where `currentTarget` is `target`, 3 on its ancestors.
122
+ * - `isTrusted`: always `true`.
123
+ * - `timeStamp`: milliseconds since the host started, as a number.
113
124
  * - `eventId`: a number that grows with each event and is the same on every
114
125
  * node that event reaches.
115
126
  * - `stopPropagation()`, `stopImmediatePropagation()` and `preventDefault()`.
@@ -0,0 +1,13 @@
1
+ import { IncaCore } from '../rendererCore.mts';
2
+ import { NodeId, TagName } from '../types.mts';
3
+ import { IncaElement } from './nodeOps.mts';
4
+ /**
5
+ * Builds the {@link IncaElement} handle for a native node: parentless,
6
+ * childless, with `focus()`, `blur()` and `tabIndex` wired to `core`.
7
+ * @param core - the incajs bindings the handle drives
8
+ * @param id - the native node's id
9
+ * @param kind - whether the node is an element or a comment stand-in
10
+ * @param tag - the node's element kind, if it has one; a `button` starts at tab index `0`
11
+ * @returns the new handle
12
+ */
13
+ export declare function createIncaElement(core: IncaCore, id: NodeId, kind: IncaElement["kind"], tag?: TagName): IncaElement;
@@ -27,10 +27,16 @@ export interface IncaElement {
27
27
  parent: IncaElement | null;
28
28
  /** This node's children, in render order. */
29
29
  children: IncaNode[];
30
- /** Focuses this node next frame. */
30
+ /** Focuses this node next frame. The node needs a `tabindex` attribute. */
31
31
  focus(): void;
32
32
  /** Unfocuses this node next frame, if it is the focused one. */
33
33
  blur(): void;
34
+ /**
35
+ * Assigning sets the `tabindex` attribute to the integer part of the
36
+ * value. Reading returns the last value assigned, or `-1` (`0` for a
37
+ * `button`).
38
+ */
39
+ tabIndex: number;
34
40
  }
35
41
  /** A text leaf host node — `@vue/runtime-core`'s `HostNode` for text. */
36
42
  export interface IncaText {
@@ -11,8 +11,13 @@ import { IncaElement } from './nodeOps.mts';
11
11
  * sent for this element.
12
12
  * - `core.setStyle` runs for each entry that is new or changed.
13
13
  * - `core.removeStyle` runs for each sent entry that is now absent, `null`,
14
- * or not a string/number.
14
+ * or not a string/number. After a removal, `core.setStyle` runs again for
15
+ * every remaining string/number entry.
15
16
  * - A string or `null` `style` removes every entry.
17
+ * - A key takes any of three spellings: kebab-case (`flex-direction`),
18
+ * camelCase (`flexDirection`) or snake_case (`flex_direction`). If an
19
+ * object names one property in two spellings, the value set most recently
20
+ * applies.
16
21
  *
17
22
  * ### `onXxx`
18
23
  *
@@ -45,9 +50,10 @@ import { IncaElement } from './nodeOps.mts';
45
50
  * ### Other props
46
51
  *
47
52
  * A string, number or boolean `nextValue` goes to `core.setAttribute` as it
48
- * is. A `null` or `undefined` `nextValue`, which includes a prop that is
49
- * absent from the new vnode, goes to `core.removeAttribute`. Any other value
50
- * (an object, array, function or symbol) goes to `core.setAttribute` as
53
+ * is. A `disabled`, `hidden` or `inert` set to `false` goes to
54
+ * `core.removeAttribute`, as does a `null` or `undefined` `nextValue`, which
55
+ * includes a prop that is absent from the new vnode. Any other value (an
56
+ * object, array, function or symbol) goes to `core.setAttribute` as
51
57
  * `String(nextValue)`. An `onUpdate:` key is a component event and sets
52
58
  * nothing.
53
59
  *
@@ -1,3 +1,2 @@
1
- import { withKeys as e, withModifiers as t } from "@vue/runtime-dom";
1
+ export { withKeys, withModifiers } from "@vue/runtime-dom";
2
2
  export * from "@vue/runtime-core";
3
- export { e as withKeys, t as withModifiers };
package/dist/vue.js CHANGED
@@ -1,7 +1,26 @@
1
- import { f as e, l as t, p as n, t as r } from "./chunks/rendererCore-vR5RIa7d.js";
2
- import { ErrorCodes as i, callWithAsyncErrorHandling as a, createRenderer as o } from "@vue/runtime-core";
1
+ import { l as e, t } from "./chunks/rendererCore-vR5RIa7d.js";
2
+ import { ErrorCodes as n, callWithAsyncErrorHandling as r, createRenderer as i } from "@vue/runtime-core";
3
+ //#region src/vue/createElement.mts
4
+ function a(e, t, n, r) {
5
+ let i = r === "button" ? 0 : -1;
6
+ return {
7
+ id: t,
8
+ kind: n,
9
+ parent: null,
10
+ children: [],
11
+ focus: () => e.focus(t),
12
+ blur: () => e.blur(t),
13
+ get tabIndex() {
14
+ return i;
15
+ },
16
+ set tabIndex(n) {
17
+ i = Math.trunc(n), e.setAttribute(t, "tabindex", i);
18
+ }
19
+ };
20
+ }
21
+ //#endregion
3
22
  //#region src/vue/nodeOps.mts
4
- function s(e) {
23
+ function o(e) {
5
24
  function t(t) {
6
25
  let n = e.createNode("text");
7
26
  return e.setAttribute(n, "value", t), {
@@ -20,33 +39,14 @@ function s(e) {
20
39
  function r(t) {
21
40
  t.parent && e.removeChild(t.parent.id, t.id), n(t);
22
41
  }
23
- function i(t) {
24
- return {
25
- focus: () => e.focus(t),
26
- blur: () => e.blur(t)
27
- };
28
- }
29
42
  return {
30
43
  createElement(t) {
31
- let n = e.createNode(t);
32
- return {
33
- id: n,
34
- kind: "element",
35
- parent: null,
36
- children: [],
37
- ...i(n)
38
- };
44
+ return a(e, e.createNode(t), "element", t);
39
45
  },
40
46
  createText: t,
41
47
  createComment(t) {
42
48
  let n = e.createNode("div");
43
- return e.setStyle(n, "display", "none"), {
44
- id: n,
45
- kind: "comment",
46
- parent: null,
47
- children: [],
48
- ...i(n)
49
- };
49
+ return e.setStyle(n, "display", "none"), a(e, n, "comment");
50
50
  },
51
51
  setText(t, n) {
52
52
  e.setAttribute(t.id, "value", n), t.text = n;
@@ -79,27 +79,28 @@ function s(e) {
79
79
  }
80
80
  //#endregion
81
81
  //#region src/vue/patchProp.mts
82
- var c = (e) => /^on[A-Z]/.test(e) && !e.startsWith("onUpdate:"), l = /(?:Once|Passive|Capture)$/;
83
- function u(e) {
82
+ var s = (e) => /^on[A-Z]/.test(e) && !e.startsWith("onUpdate:"), c = /(?:Once|Passive|Capture)$/;
83
+ function l(e) {
84
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);
85
+ for (; r = t.match(c);) t = t.slice(0, -r[0].length), r[0] === "Once" && (n = !0);
86
86
  return {
87
87
  event: t.slice(2).toLowerCase(),
88
88
  once: n
89
89
  };
90
90
  }
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));
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());
95
+ 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));
97
98
  }
98
- function m(e) {
99
+ function p(e) {
99
100
  let t = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "function");
100
101
  return t.length === 0 ? null : t;
101
102
  }
102
- function h(e, t) {
103
+ function m(e, t) {
103
104
  let n = e[0];
104
105
  if (typeof n != "object" || !n) return t(() => !1);
105
106
  let r = n.stopImmediatePropagation;
@@ -116,27 +117,27 @@ function h(e, t) {
116
117
  i ? n.stopImmediatePropagation = r : delete n.stopImmediatePropagation;
117
118
  }
118
119
  }
119
- var g = /* @__PURE__ */ new WeakMap();
120
- function _(e, t, n, r) {
120
+ var h = /* @__PURE__ */ new WeakMap();
121
+ function g(e, t, n, r) {
121
122
  let i = Array.from(r.slots.values()).some((e) => !e.fired);
122
- 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 && g.get(t)?.delete(n);
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);
123
124
  }
124
- function v(e, t, n) {
125
- let r = {
125
+ function _(e, t, i) {
126
+ let a = {
126
127
  slots: /* @__PURE__ */ new Map(),
127
128
  registered: !1,
128
129
  dispatcher: (...o) => {
129
130
  let s = [], c = o[0]?.eventId;
130
- h(o, (l) => {
131
- for (let u of Array.from(r.slots.keys())) {
131
+ m(o, (l) => {
132
+ for (let u of Array.from(a.slots.keys())) {
132
133
  if (l()) break;
133
- let d = r.slots.get(u);
134
+ let d = a.slots.get(u);
134
135
  if (d && !d.fired && !(typeof c == "number" && d.attachedAt >= c)) {
135
- d.once && (d.fired = !0, _(e, t, n, r));
136
+ d.once && (d.fired = !0, g(e, t, i, a));
136
137
  for (let e of d.handlers) {
137
138
  if (l()) break;
138
139
  try {
139
- a(e, d.instance, i.NATIVE_EVENT_HANDLER, o);
140
+ r(e, d.instance, n.NATIVE_EVENT_HANDLER, o);
140
141
  } catch (e) {
141
142
  s.push(e);
142
143
  }
@@ -148,64 +149,57 @@ function v(e, t, n) {
148
149
  if (s.length > 0) throw s[0];
149
150
  }
150
151
  };
151
- return r;
152
+ return a;
152
153
  }
153
- function y(e, t, n, r) {
154
- let i = g.get(t)?.get(n);
155
- i?.slots.delete(r) && _(e, t, n, i);
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);
156
157
  }
157
- function b(e, t, n, r, i) {
158
- let { event: a, once: o } = u(n), s = m(r);
158
+ function y(e, t, n, r, i) {
159
+ let { event: a, once: o } = l(n), s = p(r);
159
160
  if (!s) {
160
- y(e, t, a, n);
161
+ v(e, t, a, n);
161
162
  return;
162
163
  }
163
- let c = g.get(t);
164
- c || g.set(t, c = /* @__PURE__ */ new Map());
165
- let l = c.get(a);
166
- l || c.set(a, l = v(e, t, a));
167
- let d = l.slots.get(n);
168
- if (d) {
169
- d.handlers = s, d.instance = i;
170
- return;
171
- }
172
- l.slots.set(n, {
173
- attachedAt: e.latestEventId(),
174
- handlers: s,
175
- instance: i,
176
- once: o,
177
- fired: !1
178
- });
179
- try {
180
- _(e, t, a, l);
181
- } catch (e) {
182
- throw l.slots.delete(n), l.slots.size === 0 && c.delete(a), e;
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;
170
+ else {
171
+ u.slots.set(n, {
172
+ attachedAt: e.latestEventId(),
173
+ handlers: s,
174
+ instance: i,
175
+ once: o,
176
+ fired: !1
177
+ });
178
+ try {
179
+ g(e, t, a, u);
180
+ } catch (e) {
181
+ throw u.slots.delete(n), u.slots.size === 0 && c.delete(a), e;
182
+ }
183
183
  }
184
184
  }
185
+ var b = /* @__PURE__ */ new Set([
186
+ "disabled",
187
+ "hidden",
188
+ "inert"
189
+ ]);
185
190
  function x(e) {
186
191
  return (t, n, r, i, a, o) => {
187
- n === "style" ? p(e, t, i) : c(n) ? b(e, t, n, i, o ?? null) : 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));
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));
188
193
  };
189
194
  }
190
195
  //#endregion
191
196
  //#region src/vue/createApp.mts
192
- function S(i, a) {
193
- let c = o({
194
- ...s(r),
195
- patchProp: x(r)
196
- }).createApp(i, a), l = c.mount.bind(c);
197
- function u() {
198
- let r = t();
199
- return {
200
- id: r,
201
- kind: "element",
202
- parent: null,
203
- children: [],
204
- focus: () => n(r),
205
- blur: () => e(r)
206
- };
207
- }
208
- return Object.assign(c, { mount: (e) => l(e ?? u()) });
197
+ function S(n, r) {
198
+ let s = i({
199
+ ...o(t),
200
+ patchProp: x(t)
201
+ }).createApp(n, r), c = s.mount.bind(s);
202
+ return Object.assign(s, { mount: (n) => c(n ?? a(t, e(), "element")) });
209
203
  }
210
204
  //#endregion
211
205
  export { S as createIncaApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incajs",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "A GPU-native, Webview-free desktop app framework built on GPUI and QuickJS.",
5
5
  "keywords": [
6
6
  "cross-platform",
@@ -53,8 +53,8 @@
53
53
  "devDependencies": {
54
54
  "@vue/runtime-core": "^3.5.43",
55
55
  "@vue/runtime-dom": "^3.5.43",
56
- "oxfmt": "^0.71.0",
57
- "oxlint": "^1.86.0"
56
+ "oxfmt": "^0.72.0",
57
+ "oxlint": "^1.87.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@vue/runtime-core": "^3.5.43",