@bian-womp/spark-graph 0.2.1 → 0.2.3
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/lib/cjs/index.cjs +53 -31
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/misc/base.d.ts.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/index.js +53 -31
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/misc/base.d.ts.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/index.cjs
CHANGED
|
@@ -803,6 +803,10 @@ class GraphRuntime {
|
|
|
803
803
|
propagate(srcNodeId, srcHandle, value) {
|
|
804
804
|
// set source output
|
|
805
805
|
const srcNode = this.nodes.get(srcNodeId);
|
|
806
|
+
if (!srcNode) {
|
|
807
|
+
// Node was removed (e.g., graph updated) but an async emit arrived late; ignore
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
806
810
|
srcNode.outputs[srcHandle] = value;
|
|
807
811
|
this.emit("value", {
|
|
808
812
|
nodeId: srcNodeId,
|
|
@@ -2008,35 +2012,38 @@ function setupBasicGraphRegistry() {
|
|
|
2008
2012
|
registry.registerCoercion("base.string", "base.float", (v) => Number(v));
|
|
2009
2013
|
// Object <-> String
|
|
2010
2014
|
registry.registerCoercion("base.string", "base.object", (v) => {
|
|
2011
|
-
|
|
2012
|
-
return JSON.parse(String(v));
|
|
2013
|
-
}
|
|
2014
|
-
catch {
|
|
2015
|
-
return undefined;
|
|
2016
|
-
}
|
|
2015
|
+
return v;
|
|
2017
2016
|
});
|
|
2018
2017
|
registry.registerCoercion("base.object", "base.string", (v) => {
|
|
2019
|
-
|
|
2020
|
-
return
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2018
|
+
if (typeof v === "string")
|
|
2019
|
+
return v;
|
|
2020
|
+
return undefined;
|
|
2021
|
+
});
|
|
2022
|
+
registry.registerCoercion("base.bool", "base.object", (v) => {
|
|
2023
|
+
return v;
|
|
2024
|
+
});
|
|
2025
|
+
registry.registerCoercion("base.object", "base.bool", (v) => {
|
|
2026
|
+
if (typeof v === "boolean")
|
|
2027
|
+
return v;
|
|
2028
|
+
return undefined;
|
|
2029
|
+
});
|
|
2030
|
+
registry.registerCoercion("base.float", "base.object", (v) => {
|
|
2031
|
+
return v;
|
|
2032
|
+
});
|
|
2033
|
+
registry.registerCoercion("base.object", "base.float", (v) => {
|
|
2034
|
+
if (typeof v === "number")
|
|
2035
|
+
return v;
|
|
2036
|
+
return undefined;
|
|
2025
2037
|
});
|
|
2026
2038
|
registry.registerCoercion("base.vec3", "base.object", (v) => {
|
|
2027
|
-
|
|
2028
|
-
return v ? JSON.stringify(v) : undefined;
|
|
2029
|
-
}
|
|
2030
|
-
catch {
|
|
2031
|
-
return undefined;
|
|
2032
|
-
}
|
|
2039
|
+
return v;
|
|
2033
2040
|
});
|
|
2034
2041
|
registry.registerCoercion("base.object", "base.vec3", (v) => {
|
|
2035
2042
|
try {
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
return
|
|
2043
|
+
if (Array.isArray(v) &&
|
|
2044
|
+
v.length === 3 &&
|
|
2045
|
+
v.every((x) => typeof x === "number")) {
|
|
2046
|
+
return v;
|
|
2040
2047
|
}
|
|
2041
2048
|
return undefined;
|
|
2042
2049
|
}
|
|
@@ -2117,6 +2124,20 @@ function setupBasicGraphRegistry() {
|
|
|
2117
2124
|
outputs: { Result: "base.float" },
|
|
2118
2125
|
impl: (ins) => ({ Result: Number(ins.Value) }),
|
|
2119
2126
|
});
|
|
2127
|
+
registry.registerNode({
|
|
2128
|
+
id: "base.string",
|
|
2129
|
+
categoryId: "compute",
|
|
2130
|
+
inputs: { Value: "base.string" },
|
|
2131
|
+
outputs: { Result: "base.string" },
|
|
2132
|
+
impl: (ins) => ({ Result: String(ins.Value) }),
|
|
2133
|
+
});
|
|
2134
|
+
registry.registerNode({
|
|
2135
|
+
id: "base.bool",
|
|
2136
|
+
categoryId: "compute",
|
|
2137
|
+
inputs: { Value: "base.bool" },
|
|
2138
|
+
outputs: { Result: "base.bool" },
|
|
2139
|
+
impl: (ins) => ({ Result: Boolean(ins.Value) }),
|
|
2140
|
+
});
|
|
2120
2141
|
// Integer
|
|
2121
2142
|
registry.registerNode({
|
|
2122
2143
|
id: "base.int",
|
|
@@ -2129,7 +2150,7 @@ function setupBasicGraphRegistry() {
|
|
|
2129
2150
|
});
|
|
2130
2151
|
// JSON parser node: base.stringToObject
|
|
2131
2152
|
registry.registerNode({
|
|
2132
|
-
id: "base.
|
|
2153
|
+
id: "base.string.toObject",
|
|
2133
2154
|
categoryId: "compute",
|
|
2134
2155
|
inputs: { Text: "base.string" },
|
|
2135
2156
|
outputs: { Object: "base.object" },
|
|
@@ -2144,13 +2165,14 @@ function setupBasicGraphRegistry() {
|
|
|
2144
2165
|
}
|
|
2145
2166
|
},
|
|
2146
2167
|
});
|
|
2147
|
-
// Number to String
|
|
2148
2168
|
registry.registerNode({
|
|
2149
|
-
id: "base.
|
|
2169
|
+
id: "base.object.toString",
|
|
2150
2170
|
categoryId: "compute",
|
|
2151
|
-
inputs: {
|
|
2171
|
+
inputs: { Object: "base.object" },
|
|
2152
2172
|
outputs: { Text: "base.string" },
|
|
2153
|
-
impl: (ins) =>
|
|
2173
|
+
impl: (ins) => {
|
|
2174
|
+
return { Text: JSON.stringify(ins.Object) };
|
|
2175
|
+
},
|
|
2154
2176
|
});
|
|
2155
2177
|
// Clamp
|
|
2156
2178
|
registry.registerNode({
|
|
@@ -2234,7 +2256,7 @@ function setupBasicGraphRegistry() {
|
|
|
2234
2256
|
impl: (ins) => {
|
|
2235
2257
|
const a = asArray(ins.A ?? []);
|
|
2236
2258
|
const b = asArray(ins.B ?? []);
|
|
2237
|
-
const op = Number(ins.Operation ??
|
|
2259
|
+
const op = Number(ins.Operation ?? BaseMathOperation.Add);
|
|
2238
2260
|
const unaryByOp = {
|
|
2239
2261
|
[BaseMathOperation.Round]: (x) => Math.round(x),
|
|
2240
2262
|
[BaseMathOperation.Floor]: (x) => Math.floor(x),
|
|
@@ -2295,7 +2317,7 @@ function setupBasicGraphRegistry() {
|
|
|
2295
2317
|
outputs: { Result: "base.bool[]" },
|
|
2296
2318
|
impl: (ins) => {
|
|
2297
2319
|
const [a, b] = broadcast(ins.A, ins.B);
|
|
2298
|
-
const op = Number(ins.Operation ?? BaseCompareOperation.Equal)
|
|
2320
|
+
const op = Number(ins.Operation ?? BaseCompareOperation.Equal);
|
|
2299
2321
|
const compareByOp = {
|
|
2300
2322
|
[BaseCompareOperation.LessThan]: (x, y) => x < y,
|
|
2301
2323
|
[BaseCompareOperation.LessThanOrEqual]: (x, y) => x <= y,
|
|
@@ -2320,7 +2342,7 @@ function setupBasicGraphRegistry() {
|
|
|
2320
2342
|
outputs: { Result: "base.bool[]" },
|
|
2321
2343
|
inputDefaults: { Operation: BaseLogicOperation.Not },
|
|
2322
2344
|
impl: (ins) => {
|
|
2323
|
-
const op = Number(ins.Operation ?? BaseLogicOperation.Not)
|
|
2345
|
+
const op = Number(ins.Operation ?? BaseLogicOperation.Not);
|
|
2324
2346
|
if (op === BaseLogicOperation.Not) {
|
|
2325
2347
|
const a = asBoolArray(ins.A ?? []);
|
|
2326
2348
|
return { Result: a.map((x) => !x) };
|
|
@@ -2980,7 +3002,7 @@ function createValidationGraphDef() {
|
|
|
2980
3002
|
{ nodeId: "nA", typeId: "base.number" },
|
|
2981
3003
|
{ nodeId: "nB", typeId: "base.number" },
|
|
2982
3004
|
{ nodeId: "nC", typeId: "base.math" },
|
|
2983
|
-
{ nodeId: "s1", typeId: "base.
|
|
3005
|
+
{ nodeId: "s1", typeId: "base.object.toString" },
|
|
2984
3006
|
{ nodeId: "cmp", typeId: "base.compare" },
|
|
2985
3007
|
// Global validation issue: unknown node type (no nodeId/edgeId in data)
|
|
2986
3008
|
{ nodeId: "bad", typeId: "unknownType" },
|