@xenolithengine/graph-core 0.7.0-beta.0

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -0
  3. package/dist/command-bus.d.ts +56 -0
  4. package/dist/command-bus.d.ts.map +1 -0
  5. package/dist/command-bus.js +180 -0
  6. package/dist/command-bus.js.map +1 -0
  7. package/dist/commands-comment.d.ts +52 -0
  8. package/dist/commands-comment.d.ts.map +1 -0
  9. package/dist/commands-comment.js +92 -0
  10. package/dist/commands-comment.js.map +1 -0
  11. package/dist/commands-mut.d.ts +58 -0
  12. package/dist/commands-mut.d.ts.map +1 -0
  13. package/dist/commands-mut.js +119 -0
  14. package/dist/commands-mut.js.map +1 -0
  15. package/dist/commands.d.ts +36 -0
  16. package/dist/commands.d.ts.map +1 -0
  17. package/dist/commands.js +72 -0
  18. package/dist/commands.js.map +1 -0
  19. package/dist/comment-spatial.d.ts +20 -0
  20. package/dist/comment-spatial.d.ts.map +1 -0
  21. package/dist/comment-spatial.js +21 -0
  22. package/dist/comment-spatial.js.map +1 -0
  23. package/dist/event-emitter.d.ts +15 -0
  24. package/dist/event-emitter.d.ts.map +1 -0
  25. package/dist/event-emitter.js +55 -0
  26. package/dist/event-emitter.js.map +1 -0
  27. package/dist/fuzzy.d.ts +17 -0
  28. package/dist/fuzzy.d.ts.map +1 -0
  29. package/dist/fuzzy.js +55 -0
  30. package/dist/fuzzy.js.map +1 -0
  31. package/dist/graph.d.ts +108 -0
  32. package/dist/graph.d.ts.map +1 -0
  33. package/dist/graph.js +141 -0
  34. package/dist/graph.js.map +1 -0
  35. package/dist/ids.d.ts +28 -0
  36. package/dist/ids.d.ts.map +1 -0
  37. package/dist/ids.js +31 -0
  38. package/dist/ids.js.map +1 -0
  39. package/dist/index.d.ts +35 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +20 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/macro.d.ts +120 -0
  44. package/dist/macro.d.ts.map +1 -0
  45. package/dist/macro.js +226 -0
  46. package/dist/macro.js.map +1 -0
  47. package/dist/node-registry.d.ts +101 -0
  48. package/dist/node-registry.d.ts.map +1 -0
  49. package/dist/node-registry.js +96 -0
  50. package/dist/node-registry.js.map +1 -0
  51. package/dist/reroute.d.ts +21 -0
  52. package/dist/reroute.d.ts.map +1 -0
  53. package/dist/reroute.js +40 -0
  54. package/dist/reroute.js.map +1 -0
  55. package/dist/selection.d.ts +17 -0
  56. package/dist/selection.d.ts.map +1 -0
  57. package/dist/selection.js +56 -0
  58. package/dist/selection.js.map +1 -0
  59. package/dist/template-def.d.ts +113 -0
  60. package/dist/template-def.d.ts.map +1 -0
  61. package/dist/template-def.js +0 -0
  62. package/dist/template-def.js.map +1 -0
  63. package/dist/template-flatten.d.ts +38 -0
  64. package/dist/template-flatten.d.ts.map +1 -0
  65. package/dist/template-flatten.js +157 -0
  66. package/dist/template-flatten.js.map +1 -0
  67. package/dist/traversal.d.ts +27 -0
  68. package/dist/traversal.d.ts.map +1 -0
  69. package/dist/traversal.js +119 -0
  70. package/dist/traversal.js.map +1 -0
  71. package/dist/types-registry.d.ts +41 -0
  72. package/dist/types-registry.d.ts.map +1 -0
  73. package/dist/types-registry.js +60 -0
  74. package/dist/types-registry.js.map +1 -0
  75. package/dist/widget.d.ts +141 -0
  76. package/dist/widget.d.ts.map +1 -0
  77. package/dist/widget.js +112 -0
  78. package/dist/widget.js.map +1 -0
  79. package/package.json +55 -0
package/dist/widget.js ADDED
@@ -0,0 +1,112 @@
1
+ export function comboOptions(spec) {
2
+ return spec.values.map((o) => typeof o === 'object' ? { label: o.label, value: o.value } : { label: o, value: o });
3
+ }
4
+ export function defaultWidgetValue(spec) {
5
+ switch (spec.type) {
6
+ case 'number': return spec.min ?? 0;
7
+ case 'slider': return spec.min;
8
+ case 'combo': return comboOptions(spec)[0]?.value;
9
+ case 'text': return '';
10
+ case 'toggle': return false;
11
+ case 'color': return '#6c8ebf';
12
+ case 'button':
13
+ case 'custom': return undefined;
14
+ }
15
+ }
16
+ const HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
17
+ /** Normalise a colour to a 6-digit lowercase hex (`#rrggbb`), expanding 3-digit shorthand. */
18
+ function normalizeHex(raw) {
19
+ if (typeof raw !== 'string')
20
+ return null;
21
+ const s = raw.trim();
22
+ if (!HEX_RE.test(s))
23
+ return null;
24
+ const body = s.slice(1);
25
+ const full = body.length === 3 ? body.split('').map((ch) => ch + ch).join('') : body;
26
+ return `#${full.toLowerCase()}`;
27
+ }
28
+ function quantize(value, min, step) {
29
+ const snapped = min + Math.round((value - min) / step) * step;
30
+ // Kill floating-point dust from the multiply (e.g. 0.30000000000000004).
31
+ return Number(snapped.toFixed(10));
32
+ }
33
+ export function clampWidgetValue(spec, raw) {
34
+ switch (spec.type) {
35
+ case 'number': {
36
+ let v = typeof raw === 'number' ? raw : Number(raw);
37
+ if (!Number.isFinite(v))
38
+ return defaultWidgetValue(spec);
39
+ const min = spec.min ?? -Infinity;
40
+ const max = spec.max ?? Infinity;
41
+ v = Math.min(max, Math.max(min, v));
42
+ if (spec.step && spec.step > 0)
43
+ v = Math.min(max, Math.max(min, quantize(v, Number.isFinite(min) ? min : 0, spec.step)));
44
+ if (spec.precision !== undefined)
45
+ v = Number(v.toFixed(spec.precision));
46
+ return v;
47
+ }
48
+ case 'slider': {
49
+ let v = typeof raw === 'number' ? raw : Number(raw);
50
+ if (!Number.isFinite(v))
51
+ return defaultWidgetValue(spec);
52
+ v = Math.min(spec.max, Math.max(spec.min, v));
53
+ if (spec.step && spec.step > 0)
54
+ v = Math.min(spec.max, Math.max(spec.min, quantize(v, spec.min, spec.step)));
55
+ return v;
56
+ }
57
+ case 'combo': {
58
+ const opts = comboOptions(spec);
59
+ return opts.some((o) => o.value === raw) ? raw : opts[0]?.value;
60
+ }
61
+ case 'text': {
62
+ let s = String(raw ?? '');
63
+ if (spec.maxLength !== undefined)
64
+ s = s.slice(0, spec.maxLength);
65
+ return s;
66
+ }
67
+ case 'toggle':
68
+ return Boolean(raw);
69
+ case 'color':
70
+ return normalizeHex(raw) ?? defaultWidgetValue(spec);
71
+ case 'button':
72
+ return undefined;
73
+ case 'custom':
74
+ return raw;
75
+ }
76
+ }
77
+ /** Current value of a widget on a node: the clamped `node.state[key]`, or its default. */
78
+ export function widgetValue(node, spec) {
79
+ if (spec.key === undefined)
80
+ return defaultWidgetValue(spec);
81
+ const stored = node.state[spec.key];
82
+ return stored === undefined ? defaultWidgetValue(spec) : clampWidgetValue(spec, stored);
83
+ }
84
+ /** Effective widget visibility policy. ALL widget types default to `'whenDisconnected'` — they're
85
+ * input controls that the user sets a value for, and connecting a wire makes the widget's value
86
+ * redundant. Display/preview widgets (e.g. an Output node's value readout) opt into `'always'`
87
+ * explicitly. `button` widgets aren't pin-bound — they live in the actions row. */
88
+ export function widgetVisibility(spec) {
89
+ return spec.visibility ?? 'whenDisconnected';
90
+ }
91
+ /** Resolve `displayOptions.show(state)` against a node — true (visible) unless the callback exists
92
+ * and explicitly returns false. Defensive: a throwing callback fails OPEN so a schema bug doesn't
93
+ * blank the node entirely. */
94
+ export function widgetIsVisible(spec, node) {
95
+ const show = spec.displayOptions?.show;
96
+ if (!show)
97
+ return true;
98
+ try {
99
+ return show(node.state) !== false;
100
+ }
101
+ catch {
102
+ return true;
103
+ }
104
+ }
105
+ /** The lookup key used to bind a widget to its pin: explicit `pinKey`, else the widget's `key`.
106
+ * Returns undefined for widgets that don't bind to a pin (`button` — actions, not values). */
107
+ export function widgetBindKey(spec) {
108
+ if (spec.type === 'button')
109
+ return undefined;
110
+ return spec.pinKey ?? spec.key;
111
+ }
112
+ //# sourceMappingURL=widget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AA4FA,MAAM,UAAU,YAAY,CAAC,IAA4C;IACvE,OAAO,IAAI,CAAC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,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,CAAA;IACtC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IACtB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAA;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED;+FAC+F;AAC/F,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAC5C,OAAO,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAA;AAChC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@xenolithengine/graph-core",
3
+ "version": "0.7.0-beta.0",
4
+ "description": "Headless graph model, type system, command bus, and event emitter for XenolithGraph. Zero runtime dependencies.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "sideEffects": false,
21
+ "devDependencies": {
22
+ "typescript": "^5.7.0",
23
+ "vitest": "^3.0.0"
24
+ },
25
+ "keywords": [
26
+ "node-editor",
27
+ "node-graph",
28
+ "graph",
29
+ "blueprint",
30
+ "headless",
31
+ "zero-dep",
32
+ "typescript"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/XenolithEngine/xenolith-graph.git",
40
+ "directory": "packages/core"
41
+ },
42
+ "homepage": "https://xenolithengine.github.io/xenolith-graph/",
43
+ "bugs": {
44
+ "url": "https://github.com/XenolithEngine/xenolith-graph/issues"
45
+ },
46
+ "author": "XenolithEngine",
47
+ "scripts": {
48
+ "build": "tsc -b",
49
+ "dev": "tsc -b --watch",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest",
52
+ "lint": "eslint src",
53
+ "typecheck": "tsc --noEmit"
54
+ }
55
+ }