blueprintsjs 0.0.0-stage → 0.2.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 (85) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +165 -2
  4. package/dist/blueprintsjs.umd.cjs +325 -0
  5. package/dist/blueprintsjs.umd.cjs.map +1 -0
  6. package/dist/chunks/validate-DHOIGyop.js +860 -0
  7. package/dist/chunks/validate-DHOIGyop.js.map +1 -0
  8. package/dist/chunks/validate-Ddbqd8bD.cjs +859 -0
  9. package/dist/chunks/validate-Ddbqd8bD.cjs.map +1 -0
  10. package/dist/core/build.d.cts +33 -0
  11. package/dist/core/build.d.ts +33 -0
  12. package/dist/core/compile.d.cts +27 -0
  13. package/dist/core/compile.d.ts +27 -0
  14. package/dist/core/helpers.d.cts +13 -0
  15. package/dist/core/helpers.d.ts +13 -0
  16. package/dist/core/layout.d.cts +19 -0
  17. package/dist/core/layout.d.ts +19 -0
  18. package/dist/core/registry.d.cts +23 -0
  19. package/dist/core/registry.d.ts +23 -0
  20. package/dist/core/schema.d.cts +14 -0
  21. package/dist/core/schema.d.ts +14 -0
  22. package/dist/core/types.d.cts +215 -0
  23. package/dist/core/types.d.ts +215 -0
  24. package/dist/core/validate.d.cts +9 -0
  25. package/dist/core/validate.d.ts +9 -0
  26. package/dist/editor/GraphEditor.d.cts +181 -0
  27. package/dist/editor/GraphEditor.d.ts +181 -0
  28. package/dist/editor/details.d.cts +23 -0
  29. package/dist/editor/details.d.ts +23 -0
  30. package/dist/editor/dom.d.cts +20 -0
  31. package/dist/editor/dom.d.ts +20 -0
  32. package/dist/editor/highlight.d.cts +7 -0
  33. package/dist/editor/highlight.d.ts +7 -0
  34. package/dist/editor/index.d.cts +13 -0
  35. package/dist/editor/index.d.ts +13 -0
  36. package/dist/editor/state.d.cts +113 -0
  37. package/dist/editor/state.d.ts +113 -0
  38. package/dist/editor/styles.d.cts +7 -0
  39. package/dist/editor/styles.d.ts +7 -0
  40. package/dist/editor.cjs +2196 -0
  41. package/dist/editor.cjs.map +1 -0
  42. package/dist/editor.js +2196 -0
  43. package/dist/editor.js.map +1 -0
  44. package/dist/index.cjs +1251 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +21 -0
  47. package/dist/index.d.ts +21 -0
  48. package/dist/index.js +1252 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/locales/index.d.cts +15 -0
  51. package/dist/locales/index.d.ts +15 -0
  52. package/dist/locales/ru.d.cts +3 -0
  53. package/dist/locales/ru.d.ts +3 -0
  54. package/dist/locales/uk.d.cts +3 -0
  55. package/dist/locales/uk.d.ts +3 -0
  56. package/dist/locales.cjs +579 -0
  57. package/dist/locales.cjs.map +1 -0
  58. package/dist/locales.js +579 -0
  59. package/dist/locales.js.map +1 -0
  60. package/dist/nodes/data.d.cts +26 -0
  61. package/dist/nodes/data.d.ts +26 -0
  62. package/dist/nodes/dom.d.cts +27 -0
  63. package/dist/nodes/dom.d.ts +27 -0
  64. package/dist/nodes/events.d.cts +11 -0
  65. package/dist/nodes/events.d.ts +11 -0
  66. package/dist/nodes/flow.d.cts +10 -0
  67. package/dist/nodes/flow.d.ts +10 -0
  68. package/dist/nodes/index.d.cts +11 -0
  69. package/dist/nodes/index.d.ts +11 -0
  70. package/dist/nodes/lib.d.cts +7 -0
  71. package/dist/nodes/lib.d.ts +7 -0
  72. package/dist/umd.d.cts +5 -0
  73. package/dist/umd.d.ts +5 -0
  74. package/dist/version.d.cts +2 -0
  75. package/dist/version.d.ts +2 -0
  76. package/docs/compiler.md +149 -0
  77. package/docs/custom-nodes.md +119 -0
  78. package/docs/editor.md +166 -0
  79. package/docs/guide.md +79 -0
  80. package/docs/nodes.md +494 -0
  81. package/docs/nodes.ru.md +494 -0
  82. package/docs/schema.md +64 -0
  83. package/examples/index.html +110 -0
  84. package/package.json +107 -4
  85. package/schema/blueprint.schema.json +102 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,1251 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const validate = require("./chunks/validate-Ddbqd8bD.cjs");
4
+ const EXEC_IN$3 = { id: "exec", type: "exec" };
5
+ const THEN$3 = { id: "then", type: "exec" };
6
+ function literalNode(type, title, def) {
7
+ return validate.defineNode({
8
+ type: `data.${type}`,
9
+ category: "data",
10
+ title,
11
+ description: `A ${type} value.`,
12
+ keywords: ["value", "constant", "literal", type],
13
+ ports: { inputs: [{ id: "value", type, label: "Value", default: def }], outputs: [{ id: "value", type, label: "Value" }] },
14
+ compile(c) {
15
+ return { outputs: { value: c.in("value") } };
16
+ }
17
+ });
18
+ }
19
+ const stringNode = literalNode("string", "Text", "");
20
+ const numberNode = literalNode("number", "Number", 0);
21
+ const booleanNode = literalNode("boolean", "Boolean", false);
22
+ const getVar = validate.defineNode({
23
+ type: "var.get",
24
+ category: "variables",
25
+ title: "Get variable",
26
+ description: "Value of a blueprint variable.",
27
+ keywords: ["variable", "state", "read"],
28
+ props: [{ id: "variable", type: "variable", label: "Variable", required: true }],
29
+ ports: { inputs: [], outputs: [{ id: "value", type: "any", label: "Value" }] },
30
+ compile(c) {
31
+ return { outputs: { value: c.variable(String(c.prop("variable") || "")) } };
32
+ }
33
+ });
34
+ const setVar = validate.defineNode({
35
+ type: "var.set",
36
+ category: "variables",
37
+ title: "Set variable",
38
+ description: "Stores a value in a blueprint variable (kept while the page is open).",
39
+ keywords: ["variable", "state", "write", "assign"],
40
+ props: [{ id: "variable", type: "variable", label: "Variable", required: true }],
41
+ ports: {
42
+ inputs: [EXEC_IN$3, { id: "value", type: "any", label: "Value", default: "" }],
43
+ outputs: [THEN$3, { id: "value", type: "any", label: "Value" }]
44
+ },
45
+ compile(c) {
46
+ const v = c.variable(String(c.prop("variable") || ""));
47
+ return [`${v} = ${c.in("value")};`, c.set("value", v), c.next("then")].filter((s) => s.trim()).join("\n");
48
+ }
49
+ });
50
+ const MATH_OPS = {
51
+ "+": (a, b) => `${a} + ${b}`,
52
+ "-": (a, b) => `${a} - ${b}`,
53
+ "*": (a, b) => `${a} * ${b}`,
54
+ "/": (a, b) => `(${b} === 0 ? 0 : ${a} / ${b})`,
55
+ "%": (a, b) => `(${b} === 0 ? 0 : ${a} % ${b})`,
56
+ min: (a, b) => `Math.min(${a}, ${b})`,
57
+ max: (a, b) => `Math.max(${a}, ${b})`,
58
+ pow: (a, b) => `Math.pow(${a}, ${b})`
59
+ };
60
+ const math = validate.defineNode({
61
+ type: "math.op",
62
+ category: "math",
63
+ title: "Math",
64
+ description: "Arithmetic on two numbers. Division by zero gives 0.",
65
+ keywords: ["add", "plus", "minus", "multiply", "divide", "sum", "min", "max"],
66
+ props: [{ id: "op", type: "select", label: "Operation", default: "+", options: Object.keys(MATH_OPS).map((value) => ({ value })) }],
67
+ ports: {
68
+ inputs: [
69
+ { id: "a", type: "number", label: "A", default: 0 },
70
+ { id: "b", type: "number", label: "B", default: 0 }
71
+ ],
72
+ outputs: [{ id: "result", type: "number", label: "Result" }]
73
+ },
74
+ compile(c) {
75
+ const op = MATH_OPS[String(c.prop("op"))] || MATH_OPS["+"];
76
+ return { outputs: { result: op(`Number(${c.in("a")})`, `Number(${c.in("b")})`) } };
77
+ }
78
+ });
79
+ const CMP_OPS = ["==", "!=", "<", ">", "<=", ">="];
80
+ const compare = validate.defineNode({
81
+ type: "logic.compare",
82
+ category: "logic",
83
+ title: "Compare",
84
+ description: 'Compares two values. "==" compares loosely ("1" equals 1).',
85
+ keywords: ["equal", "equals", "greater", "less", "if", "compare"],
86
+ props: [{ id: "op", type: "select", label: "Operator", default: "==", options: CMP_OPS.map((value) => ({ value })) }],
87
+ ports: {
88
+ inputs: [
89
+ { id: "a", type: "any", label: "A", default: "" },
90
+ { id: "b", type: "any", label: "B", default: "" }
91
+ ],
92
+ outputs: [{ id: "result", type: "boolean", label: "Result" }]
93
+ },
94
+ compile(c) {
95
+ const op = CMP_OPS.includes(String(c.prop("op"))) ? String(c.prop("op")) : "==";
96
+ return { outputs: { result: `${c.in("a")} ${op} ${c.in("b")}` } };
97
+ }
98
+ });
99
+ function logicNode(type, title) {
100
+ return validate.defineNode({
101
+ type: `logic.${type}`,
102
+ category: "logic",
103
+ title,
104
+ description: type === "and" ? "True if both are true." : "True if at least one is true.",
105
+ keywords: [type, "boolean", "logic"],
106
+ ports: {
107
+ inputs: [
108
+ { id: "a", type: "boolean", label: "A", default: false },
109
+ { id: "b", type: "boolean", label: "B", default: false }
110
+ ],
111
+ outputs: [{ id: "result", type: "boolean", label: "Result" }]
112
+ },
113
+ compile(c) {
114
+ return { outputs: { result: `!!(${c.in("a")} ${type === "and" ? "&&" : "||"} ${c.in("b")})` } };
115
+ }
116
+ });
117
+ }
118
+ const and = logicNode("and", "AND");
119
+ const or = logicNode("or", "OR");
120
+ const not = validate.defineNode({
121
+ type: "logic.not",
122
+ category: "logic",
123
+ title: "NOT",
124
+ description: "Inverts a boolean.",
125
+ keywords: ["not", "invert", "negate"],
126
+ ports: { inputs: [{ id: "value", type: "boolean", label: "Value", default: false }], outputs: [{ id: "result", type: "boolean", label: "Result" }] },
127
+ compile(c) {
128
+ return { outputs: { result: `!${c.in("value")}` } };
129
+ }
130
+ });
131
+ const concat = validate.defineNode({
132
+ type: "string.concat",
133
+ category: "data",
134
+ title: "Join text",
135
+ description: "Joins two texts with an optional separator.",
136
+ keywords: ["concat", "join", "string", "text", "append"],
137
+ ports: {
138
+ inputs: [
139
+ { id: "a", type: "string", label: "A", default: "" },
140
+ { id: "b", type: "string", label: "B", default: "" },
141
+ { id: "separator", type: "string", label: "Separator", default: "" }
142
+ ],
143
+ outputs: [{ id: "result", type: "string", label: "Result" }]
144
+ },
145
+ compile(c) {
146
+ return { outputs: { result: `String(${c.in("a")}) + ${c.in("separator")} + String(${c.in("b")})` } };
147
+ }
148
+ });
149
+ const toNumber = validate.defineNode({
150
+ type: "convert.number",
151
+ category: "data",
152
+ title: "To number",
153
+ description: "Converts a value to a number (0 if it is not a number).",
154
+ keywords: ["parse", "number", "convert", "int", "float"],
155
+ ports: { inputs: [{ id: "value", type: "any", label: "Value", default: "" }], outputs: [{ id: "result", type: "number", label: "Number" }] },
156
+ compile(c) {
157
+ return { outputs: { result: `(parseFloat(${c.in("value")}) || 0)` } };
158
+ }
159
+ });
160
+ const toText = validate.defineNode({
161
+ type: "convert.string",
162
+ category: "data",
163
+ title: "To text",
164
+ description: "Converts a value to text (objects as JSON).",
165
+ keywords: ["string", "text", "convert", "json"],
166
+ ports: { inputs: [{ id: "value", type: "any", label: "Value", noLiteral: true }], outputs: [{ id: "result", type: "string", label: "Text" }] },
167
+ compile(c) {
168
+ return {
169
+ outputs: {
170
+ result: `(function (v) { if (v == null) return ''; if (typeof v === 'object') { try { return JSON.stringify(v); } catch (e) { return String(v); } } return String(v); })(${c.in("value")})`
171
+ }
172
+ };
173
+ }
174
+ });
175
+ const storageGet = validate.defineNode({
176
+ type: "storage.get",
177
+ category: "data",
178
+ title: "Read from storage",
179
+ description: "Value saved in the browser (localStorage) under the key; empty text if none.",
180
+ keywords: ["localStorage", "save", "remember", "persist", "cookie"],
181
+ ports: { inputs: [{ id: "key", type: "string", label: "Key", default: "", required: true }], outputs: [{ id: "value", type: "string", label: "Value" }] },
182
+ compile(c) {
183
+ return { outputs: { value: `(${c.h("store")}.get(${c.in("key")}) || '')` } };
184
+ }
185
+ });
186
+ const storageSet = validate.defineNode({
187
+ type: "storage.set",
188
+ category: "data",
189
+ title: "Save to storage",
190
+ description: "Saves a value in the browser (localStorage); it survives reloads.",
191
+ keywords: ["localStorage", "save", "remember", "persist"],
192
+ ports: {
193
+ inputs: [EXEC_IN$3, { id: "key", type: "string", label: "Key", default: "", required: true }, { id: "value", type: "string", label: "Value", default: "" }],
194
+ outputs: [THEN$3]
195
+ },
196
+ compile(c) {
197
+ return [`${c.h("store")}.set(${c.in("key")}, ${c.in("value")});`, c.next("then")].filter((s) => s.trim()).join("\n");
198
+ }
199
+ });
200
+ const param = validate.defineNode({
201
+ type: "component.param",
202
+ category: "variables",
203
+ title: "Component parameter",
204
+ description: "Value of a component parameter (set in the component traits). Component blueprints only.",
205
+ keywords: ["param", "prop", "trait", "option", "setting"],
206
+ props: [{ id: "param", type: "string", label: "Parameter", default: "", required: true }],
207
+ ports: { inputs: [], outputs: [{ id: "value", type: "any", label: "Value" }] },
208
+ compile(c) {
209
+ return { outputs: { value: `params[${c.lit(String(c.prop("param") || ""))}]` } };
210
+ }
211
+ });
212
+ const log = validate.defineNode({
213
+ type: "debug.log",
214
+ category: "debug",
215
+ title: "Print to console",
216
+ description: "Writes a value to the browser console.",
217
+ keywords: ["console", "log", "print", "debug"],
218
+ ports: {
219
+ inputs: [EXEC_IN$3, { id: "label", type: "string", label: "Label", default: "" }, { id: "value", type: "any", label: "Value", default: "" }],
220
+ outputs: [THEN$3]
221
+ },
222
+ compile(c) {
223
+ return [`if (typeof console !== 'undefined') console.log(${c.in("label")}, ${c.in("value")});`, c.next("then")].join("\n");
224
+ }
225
+ });
226
+ function codePins(v, fallback) {
227
+ const list = Array.isArray(v) ? v : fallback;
228
+ const seen = /* @__PURE__ */ new Set();
229
+ const out = [];
230
+ for (const raw of list) {
231
+ const id = String((raw == null ? void 0 : raw.id) || "").trim();
232
+ if (!/^[A-Za-z_$][\w$]*$/.test(id) || seen.has(id) || id === "exec" || id === "then") continue;
233
+ seen.add(id);
234
+ const type = raw.type;
235
+ out.push({ id, type: ["any", "string", "number", "boolean", "element", "elements", "event", "object"].includes(type) ? type : "any", label: raw.label });
236
+ }
237
+ return out;
238
+ }
239
+ const jsCode = validate.defineNode({
240
+ type: "code.js",
241
+ category: "code",
242
+ title: "JavaScript",
243
+ description: 'Your own code. Inputs come in `inputs`, return an object with the outputs (`return { result: 42 };`). `ctx` has `root`, `document`, `window`, `params`. With "Async", return a Promise: the chain continues when it resolves.',
244
+ keywords: ["code", "script", "custom", "javascript", "function"],
245
+ color: "#7a4",
246
+ props: [
247
+ { id: "code", type: "code", label: "Code", default: "return { result: inputs.value };" },
248
+ { id: "inputs", type: "pins", label: "Inputs", default: [{ id: "value", type: "any" }] },
249
+ { id: "outputs", type: "pins", label: "Outputs", default: [{ id: "result", type: "any" }] },
250
+ { id: "async", type: "boolean", label: "Async", default: false }
251
+ ],
252
+ ports: (p) => ({
253
+ inputs: [EXEC_IN$3, ...codePins(p.inputs, [{ id: "value", type: "any" }]).map((x) => ({ ...x, default: x.type === "string" ? "" : void 0 }))],
254
+ outputs: [THEN$3, ...codePins(p.outputs, [{ id: "result", type: "any" }]).map((x) => ({ ...x }))]
255
+ }),
256
+ compile(c) {
257
+ const ins = codePins(c.prop("inputs"), [{ id: "value", type: "any" }]);
258
+ const outs = codePins(c.prop("outputs"), [{ id: "result", type: "any" }]);
259
+ const user = String(c.prop("code") ?? "");
260
+ const fn = c.local("code");
261
+ const r = c.local("r");
262
+ const inputsObj = `{ ${ins.map((p) => `${p.id}: ${c.in(p.id)}`).join(", ")} }`;
263
+ const ctxObj = `{ root: ${c.root}, document: ${c.doc}, window: ${c.win}, params: params }`;
264
+ const assign = outs.map((p) => c.set(p.id, `${r}[${c.lit(p.id)}]`)).filter(Boolean).join("\n");
265
+ const indented = user.split("\n").map((l) => l.trim() ? " " + l : l).join("\n");
266
+ const decl = `var ${fn} = function (inputs, ctx) {
267
+ ${indented}
268
+ };`;
269
+ const next = c.next("then");
270
+ if (c.prop("async")) {
271
+ const tail = [assign, next].filter((s) => s.trim()).join("\n");
272
+ return `${decl}
273
+ Promise.resolve(${fn}(${inputsObj}, ${ctxObj})).then(function (${r}) {
274
+ ${[`${r} = ${r} || {};`, tail].join("\n").split("\n").map((l) => " " + l).join("\n")}
275
+ })['catch'](function (e) { if (typeof console !== 'undefined') console.error(e); });`;
276
+ }
277
+ return [decl, `var ${r} = ${fn}(${inputsObj}, ${ctxObj}) || {};`, assign, next].filter((s) => s.trim()).join("\n");
278
+ }
279
+ });
280
+ const jsExpression = validate.defineNode({
281
+ type: "code.expression",
282
+ category: "code",
283
+ title: "Expression",
284
+ description: "A JavaScript expression of `a` and `b`, e.g. `a * 2 + b` or `a.trim()`.",
285
+ keywords: ["formula", "expression", "calc", "javascript"],
286
+ color: "#7a4",
287
+ props: [{ id: "expression", type: "code", label: "Expression", default: "a" }],
288
+ ports: {
289
+ inputs: [
290
+ { id: "a", type: "any", label: "a", default: "" },
291
+ { id: "b", type: "any", label: "b", default: "" }
292
+ ],
293
+ outputs: [{ id: "result", type: "any", label: "Result" }]
294
+ },
295
+ compile(c) {
296
+ const expr = String(c.prop("expression") || "undefined").replace(/;\s*$/, "");
297
+ return { outputs: { result: `(function (a, b) { return (${expr}); })(${c.in("a")}, ${c.in("b")})` } };
298
+ }
299
+ });
300
+ const DATA_NODES = [
301
+ stringNode,
302
+ numberNode,
303
+ booleanNode,
304
+ getVar,
305
+ setVar,
306
+ param,
307
+ math,
308
+ compare,
309
+ and,
310
+ or,
311
+ not,
312
+ concat,
313
+ toNumber,
314
+ toText,
315
+ storageGet,
316
+ storageSet,
317
+ log,
318
+ jsCode,
319
+ jsExpression
320
+ ];
321
+ const EXEC_IN$2 = { id: "exec", type: "exec" };
322
+ const THEN$2 = { id: "then", type: "exec" };
323
+ const TARGET = { id: "target", type: "elements", label: "Target", default: "", required: true };
324
+ const els = (c, pin = "target") => {
325
+ const v = c.in(pin);
326
+ if (!c.linked(pin)) return v === "null" ? "[]" : v.replace(/^\((.*)\[0\] \|\| null\)$/, "$1");
327
+ return `${c.h("els")}(${c.root}, ${v})`;
328
+ };
329
+ function eachNode(def) {
330
+ return validate.defineNode({
331
+ type: def.type,
332
+ category: "dom",
333
+ title: def.title,
334
+ description: def.description,
335
+ keywords: def.keywords,
336
+ ports: { inputs: [EXEC_IN$2, TARGET, ...def.inputs || []], outputs: [THEN$2] },
337
+ compile(c) {
338
+ return [`${els(c)}.forEach(function (el) { ${def.body(c, "el")} });`, c.next("then")].filter((s) => s.trim()).join("\n");
339
+ }
340
+ });
341
+ }
342
+ const CLASS = { id: "className", type: "string", label: "Class", default: "", required: true };
343
+ const classOp = (c, el, method) => {
344
+ if (!c.linked("className")) {
345
+ const list = String(c.prop("className") ?? "").split(/\s+/).filter(Boolean);
346
+ if (list.length <= 1) return list.length ? `${el}.classList.${method}(${c.lit(list[0])});` : "";
347
+ return `${c.lit(list)}.forEach(function (k) { ${el}.classList.${method}(k); });`;
348
+ }
349
+ return `String(${c.in("className")}).split(/\\s+/).filter(Boolean).forEach(function (k) { ${el}.classList.${method}(k); });`;
350
+ };
351
+ const query = validate.defineNode({
352
+ type: "dom.query",
353
+ category: "dom",
354
+ title: "Find elements",
355
+ description: "Finds elements by a CSS selector: in the whole document (or component), inside the given elements, or the closest ancestor of them.",
356
+ keywords: ["select", "selector", "query", "get", "element", "closest", "find"],
357
+ props: [
358
+ {
359
+ id: "mode",
360
+ type: "select",
361
+ label: "Where",
362
+ default: "all",
363
+ options: [
364
+ { value: "all", label: "Everywhere" },
365
+ { value: "within", label: 'Inside "From"' },
366
+ { value: "closest", label: 'Closest ancestor of "From"' }
367
+ ]
368
+ }
369
+ ],
370
+ ports: {
371
+ inputs: [
372
+ { id: "selector", type: "string", label: "Selector", default: "" },
373
+ { id: "from", type: "elements", label: "From", noLiteral: true }
374
+ ],
375
+ outputs: [
376
+ { id: "result", type: "elements", label: "Elements" },
377
+ { id: "first", type: "element", label: "First" },
378
+ { id: "count", type: "number", label: "Count" }
379
+ ]
380
+ },
381
+ compile(c) {
382
+ const mode = String(c.prop("mode") || "all");
383
+ const from = c.linked("from") ? c.in("from") : "null";
384
+ const q = `${c.h("q")}(${c.root}, ${c.in("selector")}, ${c.lit(mode)}, ${from})`;
385
+ return { outputs: { result: q, first: `${q}[0] || null`, count: `${q}.length` } };
386
+ }
387
+ });
388
+ const rootNode = validate.defineNode({
389
+ type: "dom.root",
390
+ category: "dom",
391
+ title: "Root element",
392
+ description: "The component element (component blueprints) or <html> (page blueprints).",
393
+ keywords: ["self", "this", "component", "root"],
394
+ ports: { inputs: [], outputs: [{ id: "element", type: "element", label: "Element" }] },
395
+ compile(c) {
396
+ return { outputs: { element: `${c.root}.nodeType === 9 ? ${c.root}.documentElement : ${c.root}` } };
397
+ }
398
+ });
399
+ const addClass = eachNode({
400
+ type: "dom.addClass",
401
+ title: "Add class",
402
+ description: "Adds class(es) to the elements. Several classes: separate with spaces.",
403
+ keywords: ["class", "classList", "add", "open", "active"],
404
+ inputs: [CLASS],
405
+ body: (c, el) => classOp(c, el, "add")
406
+ });
407
+ const removeClass = eachNode({
408
+ type: "dom.removeClass",
409
+ title: "Remove class",
410
+ description: "Removes class(es) from the elements.",
411
+ keywords: ["class", "classList", "remove", "close"],
412
+ inputs: [CLASS],
413
+ body: (c, el) => classOp(c, el, "remove")
414
+ });
415
+ const toggleClass = eachNode({
416
+ type: "dom.toggleClass",
417
+ title: "Toggle class",
418
+ description: "Adds the class if it is missing, removes it otherwise.",
419
+ keywords: ["class", "classList", "toggle", "switch"],
420
+ inputs: [CLASS],
421
+ body: (c, el) => classOp(c, el, "toggle")
422
+ });
423
+ const hasClass = validate.defineNode({
424
+ type: "dom.hasClass",
425
+ category: "dom",
426
+ title: "Has class",
427
+ description: "True if any of the elements has the class.",
428
+ keywords: ["class", "contains", "is"],
429
+ ports: { inputs: [TARGET, CLASS], outputs: [{ id: "result", type: "boolean", label: "Result" }] },
430
+ compile(c) {
431
+ return { outputs: { result: `${els(c)}.some(function (el) { return el.classList.contains(String(${c.in("className")}).trim()); })` } };
432
+ }
433
+ });
434
+ const matches = validate.defineNode({
435
+ type: "dom.matches",
436
+ category: "dom",
437
+ title: "Matches selector",
438
+ description: "True if the element matches the CSS selector (e.g. the click was on the backdrop itself).",
439
+ keywords: ["is", "matches", "selector", "check"],
440
+ ports: {
441
+ inputs: [
442
+ { id: "target", type: "element", label: "Element", noLiteral: true },
443
+ { id: "selector", type: "string", label: "Selector", default: "" }
444
+ ],
445
+ outputs: [{ id: "result", type: "boolean", label: "Result" }]
446
+ },
447
+ compile(c) {
448
+ const el = c.in("target");
449
+ return { outputs: { result: `(function (el, s) { try { return !!(el && el.matches && s && el.matches(s)); } catch (e) { return false; } })(${el}, ${c.in("selector")})` } };
450
+ }
451
+ });
452
+ const setAttr = eachNode({
453
+ type: "dom.setAttribute",
454
+ title: "Set attribute",
455
+ description: "Sets an attribute (aria-expanded, data-state…).",
456
+ keywords: ["attribute", "aria", "data"],
457
+ inputs: [
458
+ { id: "name", type: "string", label: "Name", default: "", required: true },
459
+ { id: "value", type: "string", label: "Value", default: "" }
460
+ ],
461
+ body: (c, el) => `${el}.setAttribute(${c.in("name")}, ${c.in("value")});`
462
+ });
463
+ const removeAttr = eachNode({
464
+ type: "dom.removeAttribute",
465
+ title: "Remove attribute",
466
+ description: "Removes an attribute.",
467
+ keywords: ["attribute", "remove"],
468
+ inputs: [{ id: "name", type: "string", label: "Name", default: "", required: true }],
469
+ body: (c, el) => `${el}.removeAttribute(${c.in("name")});`
470
+ });
471
+ const getAttr = validate.defineNode({
472
+ type: "dom.getAttribute",
473
+ category: "dom",
474
+ title: "Get attribute",
475
+ description: "Attribute of the first element (empty string if missing).",
476
+ keywords: ["attribute", "read", "data"],
477
+ ports: {
478
+ inputs: [TARGET, { id: "name", type: "string", label: "Name", default: "", required: true }],
479
+ outputs: [{ id: "value", type: "string", label: "Value" }]
480
+ },
481
+ compile(c) {
482
+ return { outputs: { value: `(function (el) { return (el && el.getAttribute(${c.in("name")})) || ''; })(${els(c)}[0])` } };
483
+ }
484
+ });
485
+ const setStyle = eachNode({
486
+ type: "dom.setStyle",
487
+ title: "Set style",
488
+ description: "Sets an inline CSS property (empty value removes it).",
489
+ keywords: ["css", "style", "color", "display"],
490
+ inputs: [
491
+ { id: "property", type: "string", label: "Property", default: "", required: true },
492
+ { id: "value", type: "string", label: "Value", default: "" }
493
+ ],
494
+ body: (c, el) => `${el}.style.setProperty(${c.in("property")}, ${c.in("value")});`
495
+ });
496
+ const setText = eachNode({
497
+ type: "dom.setText",
498
+ title: "Set text",
499
+ description: "Replaces the text of the elements (safe: no HTML is parsed).",
500
+ keywords: ["text", "content", "label"],
501
+ inputs: [{ id: "text", type: "string", label: "Text", default: "" }],
502
+ body: (c, el) => `${el}.textContent = ${c.in("text")};`
503
+ });
504
+ const getText = validate.defineNode({
505
+ type: "dom.getText",
506
+ category: "dom",
507
+ title: "Get text",
508
+ description: "Text of the first element.",
509
+ keywords: ["text", "content", "read"],
510
+ ports: { inputs: [TARGET], outputs: [{ id: "text", type: "string", label: "Text" }] },
511
+ compile(c) {
512
+ return { outputs: { text: `((${els(c)}[0] || {}).textContent || '')` } };
513
+ }
514
+ });
515
+ const setHtml = eachNode({
516
+ type: "dom.setHtml",
517
+ title: "Set HTML (unsafe)",
518
+ description: 'Replaces the inner HTML. Never pass user input here: it can run scripts (XSS). Prefer "Set text".',
519
+ keywords: ["html", "innerHTML"],
520
+ inputs: [{ id: "html", type: "string", label: "HTML", default: "" }],
521
+ body: (c, el) => `${el}.innerHTML = ${c.in("html")};`
522
+ });
523
+ const getValue = validate.defineNode({
524
+ type: "dom.getValue",
525
+ category: "dom",
526
+ title: "Get value",
527
+ description: "Value of the first form field (checkbox: checked or not).",
528
+ keywords: ["input", "value", "form", "field", "checked"],
529
+ ports: { inputs: [TARGET], outputs: [{ id: "value", type: "any", label: "Value" }] },
530
+ compile(c) {
531
+ return {
532
+ outputs: {
533
+ value: `(function (el) { if (!el) return ''; if (el.type === 'checkbox' || el.type === 'radio') return !!el.checked; return el.value; })(${els(c)}[0])`
534
+ }
535
+ };
536
+ }
537
+ });
538
+ const setValue = eachNode({
539
+ type: "dom.setValue",
540
+ title: "Set value",
541
+ description: "Sets the value of form fields (checkbox: checks when the value is truthy).",
542
+ keywords: ["input", "value", "form", "field"],
543
+ inputs: [{ id: "value", type: "any", label: "Value", default: "" }],
544
+ body: (c, el) => `var v = ${c.in("value")}; if (${el}.type === 'checkbox' || ${el}.type === 'radio') ${el}.checked = !!v; else ${el}.value = v == null ? '' : v;`
545
+ });
546
+ const show = eachNode({
547
+ type: "dom.show",
548
+ title: "Show",
549
+ description: "Makes hidden elements visible (removes display: none / hidden).",
550
+ keywords: ["display", "visible", "open"],
551
+ body: (c, el) => `${c.h("show")}(${el});`
552
+ });
553
+ const hide = eachNode({
554
+ type: "dom.hide",
555
+ title: "Hide",
556
+ description: "Hides the elements (display: none).",
557
+ keywords: ["display", "invisible", "close"],
558
+ body: (c, el) => `${c.h("hide")}(${el});`
559
+ });
560
+ const toggleVisible = eachNode({
561
+ type: "dom.toggleVisible",
562
+ title: "Show / hide",
563
+ description: "Shows hidden elements and hides visible ones.",
564
+ keywords: ["display", "toggle", "visible"],
565
+ body: (c, el) => `if (${c.h("visible")}(${el})) ${c.h("hide")}(${el}); else ${c.h("show")}(${el});`
566
+ });
567
+ const isVisible = validate.defineNode({
568
+ type: "dom.isVisible",
569
+ category: "dom",
570
+ title: "Is visible",
571
+ description: "True if the first element is displayed.",
572
+ keywords: ["display", "visible", "shown"],
573
+ ports: { inputs: [TARGET], outputs: [{ id: "result", type: "boolean", label: "Result" }] },
574
+ compile(c) {
575
+ return { outputs: { result: `${c.h("visible")}(${els(c)}[0])` } };
576
+ }
577
+ });
578
+ const focus = eachNode({
579
+ type: "dom.focus",
580
+ title: "Focus",
581
+ description: "Moves keyboard focus to the element.",
582
+ keywords: ["focus", "keyboard", "input"],
583
+ body: (_c, el) => `if (${el}.focus) { ${el}.focus(); }`
584
+ });
585
+ const scrollTo = eachNode({
586
+ type: "dom.scrollIntoView",
587
+ title: "Scroll to",
588
+ description: "Scrolls the page to the element.",
589
+ keywords: ["scroll", "anchor", "jump"],
590
+ inputs: [{ id: "smooth", type: "boolean", label: "Smooth", default: true }],
591
+ body: (c, el) => `${el}.scrollIntoView({ behavior: ${c.in("smooth")} ? 'smooth' : 'auto', block: 'start' });`
592
+ });
593
+ const dispatch = validate.defineNode({
594
+ type: "dom.dispatch",
595
+ category: "dom",
596
+ title: "Send event",
597
+ description: 'Sends a custom event from the elements (bubbles). Other blueprints catch it with "On custom event". Empty target = blueprint root.',
598
+ keywords: ["emit", "trigger", "custom", "message", "send"],
599
+ ports: {
600
+ inputs: [
601
+ EXEC_IN$2,
602
+ { id: "target", type: "elements", label: "Target", default: "" },
603
+ { id: "name", type: "string", label: "Event name", default: "my-event", required: true },
604
+ { id: "detail", type: "any", label: "Data", noLiteral: true }
605
+ ],
606
+ outputs: [THEN$2]
607
+ },
608
+ compile(c) {
609
+ const hasTarget = c.linked("target") || String(c.prop("target") || "").trim();
610
+ const targets = hasTarget ? els(c) : `[${c.root}]`;
611
+ const detail = c.linked("detail") ? c.in("detail") : "null";
612
+ return [`${targets}.forEach(function (el) { ${c.h("dispatch")}(el, ${c.in("name")}, ${detail}); });`, c.next("then")].filter((s) => s.trim()).join("\n");
613
+ }
614
+ });
615
+ const preventDefault = validate.defineNode({
616
+ type: "event.preventDefault",
617
+ category: "dom",
618
+ title: "Prevent default",
619
+ description: "Stops the browser action of the event (following a link, submitting a form).",
620
+ keywords: ["prevent", "default", "stop", "link", "submit"],
621
+ ports: { inputs: [EXEC_IN$2, { id: "event", type: "event", label: "Event", required: true, noLiteral: true }], outputs: [THEN$2] },
622
+ compile(c) {
623
+ return [`if (${c.in("event")}) ${c.in("event")}.preventDefault();`, c.next("then")].filter((s) => s.trim()).join("\n");
624
+ }
625
+ });
626
+ const eventTarget = validate.defineNode({
627
+ type: "event.target",
628
+ category: "dom",
629
+ title: "Event target",
630
+ description: "The element the event actually happened on (may be a child of the listened element).",
631
+ keywords: ["target", "event", "clicked"],
632
+ ports: {
633
+ inputs: [{ id: "event", type: "event", label: "Event", noLiteral: true, required: true }],
634
+ outputs: [{ id: "target", type: "element", label: "Target" }]
635
+ },
636
+ compile(c) {
637
+ return { outputs: { target: `(${c.in("event")} || {}).target || null` } };
638
+ }
639
+ });
640
+ const DOM_NODES = [
641
+ query,
642
+ rootNode,
643
+ addClass,
644
+ removeClass,
645
+ toggleClass,
646
+ hasClass,
647
+ matches,
648
+ setAttr,
649
+ removeAttr,
650
+ getAttr,
651
+ setStyle,
652
+ setText,
653
+ getText,
654
+ setHtml,
655
+ getValue,
656
+ setValue,
657
+ show,
658
+ hide,
659
+ toggleVisible,
660
+ isVisible,
661
+ focus,
662
+ scrollTo,
663
+ dispatch,
664
+ preventDefault,
665
+ eventTarget
666
+ ];
667
+ const ELEMENT_EVENTS = [
668
+ "click",
669
+ "dblclick",
670
+ "contextmenu",
671
+ "mousedown",
672
+ "mouseup",
673
+ "mouseenter",
674
+ "mouseleave",
675
+ "pointerdown",
676
+ "pointerup",
677
+ "touchstart",
678
+ "touchend",
679
+ "input",
680
+ "change",
681
+ "submit",
682
+ "reset",
683
+ "focus",
684
+ "blur",
685
+ "keydown",
686
+ "keyup",
687
+ "animationend",
688
+ "transitionend"
689
+ ];
690
+ const PAGE_EVENTS = ["load", "scroll", "resize", "hashchange", "popstate", "visibilitychange", "online", "offline", "beforeunload"];
691
+ const opts = (list) => list.map((value) => ({ value }));
692
+ function guards(c, ev) {
693
+ const out = [];
694
+ if (c.prop("once")) {
695
+ const done = c.state("done", "false");
696
+ out.push(`if (${done}) return;`, `${done} = true;`);
697
+ }
698
+ if (c.prop("preventDefault")) out.push(`${ev}.preventDefault();`);
699
+ if (c.prop("stopPropagation")) out.push(`${ev}.stopPropagation();`);
700
+ return out;
701
+ }
702
+ const body = (lines) => lines.filter((l) => l.trim()).join("\n").split("\n").map((l) => l.trim() ? " " + l : l).join("\n");
703
+ const eventElement = validate.defineNode({
704
+ type: "event.element",
705
+ category: "events",
706
+ title: "On element event",
707
+ description: "Runs when an event happens on an element matching the selector — on every page, also for elements added later (the listener is delegated to the document). Without a selector: the blueprint root itself (the component element).",
708
+ event: true,
709
+ color: "#b33",
710
+ keywords: ["click", "trigger", "listener", "event", "on"],
711
+ props: [
712
+ { id: "selector", type: "selector", label: "Selector", default: "" },
713
+ { id: "event", type: "string", label: "Event", default: "click", options: opts(ELEMENT_EVENTS), required: true },
714
+ { id: "preventDefault", type: "boolean", label: "Prevent default", default: false },
715
+ { id: "stopPropagation", type: "boolean", label: "Stop propagation", default: false },
716
+ { id: "once", type: "boolean", label: "Only once", default: false }
717
+ ],
718
+ ports: {
719
+ inputs: [],
720
+ outputs: [
721
+ { id: "then", type: "exec" },
722
+ { id: "self", type: "element", label: "Element" },
723
+ { id: "event", type: "event", label: "Event" }
724
+ ]
725
+ },
726
+ compile(c) {
727
+ const type = String(c.prop("event") || "click").trim();
728
+ const sel = String(c.prop("selector") || "").trim();
729
+ if (!type) c.warn("No event name");
730
+ const lines = [c.set("event", "event"), c.set("self", "self"), ...guards(c, "event"), c.next("then")];
731
+ return `${c.h("delegate")}(__d, ${c.root}, ${c.lit(type)}, ${c.lit(sel)}, function (event, self) {
732
+ ${body(lines)}
733
+ });`;
734
+ }
735
+ });
736
+ const eventStart = validate.defineNode({
737
+ type: "event.start",
738
+ category: "events",
739
+ title: "On start",
740
+ description: "Runs once when the blueprint starts: when the page is ready, or when a component instance appears.",
741
+ event: true,
742
+ order: 100,
743
+ color: "#b33",
744
+ keywords: ["ready", "init", "begin", "mount", "domcontentloaded"],
745
+ ports: {
746
+ inputs: [],
747
+ outputs: [
748
+ { id: "then", type: "exec" },
749
+ { id: "self", type: "element", label: "Root" }
750
+ ]
751
+ },
752
+ compile(c) {
753
+ return [c.set("self", `${c.root}.nodeType === 9 ? ${c.root}.documentElement : ${c.root}`), c.next("then")].filter((s) => s.trim()).join("\n");
754
+ }
755
+ });
756
+ const eventPage = validate.defineNode({
757
+ type: "event.page",
758
+ category: "events",
759
+ title: "On page event",
760
+ description: "Window / document events: load, scroll, resize, hash change, tab visibility…",
761
+ event: true,
762
+ color: "#b33",
763
+ keywords: ["window", "scroll", "resize", "load", "hash"],
764
+ props: [
765
+ { id: "event", type: "string", label: "Event", default: "scroll", options: opts(PAGE_EVENTS), required: true },
766
+ { id: "throttle", type: "number", label: "Throttle, ms", default: 0 }
767
+ ],
768
+ ports: {
769
+ inputs: [],
770
+ outputs: [
771
+ { id: "then", type: "exec" },
772
+ { id: "event", type: "event", label: "Event" }
773
+ ]
774
+ },
775
+ compile(c) {
776
+ const type = String(c.prop("event") || "scroll").trim();
777
+ const target = type === "visibilitychange" ? c.doc : c.win;
778
+ const ms = Math.max(0, Number(c.prop("throttle")) || 0);
779
+ const lines = [];
780
+ if (ms) {
781
+ const last = c.state("last", "0");
782
+ lines.push(`var now = Date.now();`, `if (now - ${last} < ${ms}) return;`, `${last} = now;`);
783
+ }
784
+ lines.push(c.set("event", "event"), c.next("then"));
785
+ return `${c.h("on")}(__d, ${target}, ${c.lit(type)}, function (event) {
786
+ ${body(lines)}
787
+ });`;
788
+ }
789
+ });
790
+ const eventTimer = validate.defineNode({
791
+ type: "event.timer",
792
+ category: "events",
793
+ title: "On timer",
794
+ description: 'Runs after a delay, or every N milliseconds when "Repeat" is on.',
795
+ event: true,
796
+ color: "#b33",
797
+ keywords: ["interval", "timeout", "every", "after", "time"],
798
+ props: [
799
+ { id: "ms", type: "number", label: "Milliseconds", default: 1e3 },
800
+ { id: "repeat", type: "boolean", label: "Repeat", default: false }
801
+ ],
802
+ ports: { inputs: [], outputs: [{ id: "then", type: "exec" }] },
803
+ compile(c) {
804
+ const ms = Math.max(0, Number(c.prop("ms")) || 0);
805
+ const fn = c.prop("repeat") ? "interval" : "timeout";
806
+ return `${c.h(fn)}(__d, function () {
807
+ ${body([c.next("then")])}
808
+ }, ${ms});`;
809
+ }
810
+ });
811
+ const eventKey = validate.defineNode({
812
+ type: "event.key",
813
+ category: "events",
814
+ title: "On key",
815
+ description: "Runs when a key is pressed anywhere on the page (for example Escape). Empty key = any key.",
816
+ event: true,
817
+ color: "#b33",
818
+ keywords: ["keyboard", "escape", "enter", "hotkey", "shortcut"],
819
+ props: [
820
+ { id: "key", type: "string", label: "Key", default: "Escape", options: opts(["Escape", "Enter", " ", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Tab"]) },
821
+ { id: "event", type: "select", label: "Event", default: "keydown", options: opts(["keydown", "keyup"]) },
822
+ { id: "ctrl", type: "boolean", label: "Ctrl / ⌘", default: false },
823
+ { id: "shift", type: "boolean", label: "Shift", default: false },
824
+ { id: "alt", type: "boolean", label: "Alt", default: false },
825
+ { id: "preventDefault", type: "boolean", label: "Prevent default", default: false }
826
+ ],
827
+ ports: {
828
+ inputs: [],
829
+ outputs: [
830
+ { id: "then", type: "exec" },
831
+ { id: "event", type: "event", label: "Event" }
832
+ ]
833
+ },
834
+ compile(c) {
835
+ const key = String(c.prop("key") ?? "");
836
+ const conds = [];
837
+ if (key) conds.push(`event.key !== ${c.lit(key)}`);
838
+ if (c.prop("ctrl")) conds.push("!(event.ctrlKey || event.metaKey)");
839
+ if (c.prop("shift")) conds.push("!event.shiftKey");
840
+ if (c.prop("alt")) conds.push("!event.altKey");
841
+ const lines = [conds.length ? `if (${conds.join(" || ")}) return;` : "", ...guards(c, "event"), c.set("event", "event"), c.next("then")];
842
+ return `${c.h("on")}(__d, ${c.doc}, ${c.lit(c.prop("event") === "keyup" ? "keyup" : "keydown")}, function (event) {
843
+ ${body(lines)}
844
+ });`;
845
+ }
846
+ });
847
+ const eventCustom = validate.defineNode({
848
+ type: "event.custom",
849
+ category: "events",
850
+ title: "On custom event",
851
+ description: 'Runs when a custom event with this name reaches the blueprint root (see "Send event"). Lets blueprints talk to each other.',
852
+ event: true,
853
+ color: "#b33",
854
+ keywords: ["message", "receive", "listen", "custom", "emit"],
855
+ props: [{ id: "name", type: "string", label: "Event name", default: "my-event", required: true }],
856
+ ports: {
857
+ inputs: [],
858
+ outputs: [
859
+ { id: "then", type: "exec" },
860
+ { id: "detail", type: "any", label: "Data" },
861
+ { id: "target", type: "element", label: "Sender" }
862
+ ]
863
+ },
864
+ compile(c) {
865
+ const lines = [c.set("detail", "event.detail"), c.set("target", "event.target"), c.next("then")];
866
+ return `${c.h("on")}(__d, ${c.root}, ${c.lit(String(c.prop("name") || "").trim())}, function (event) {
867
+ ${body(lines)}
868
+ });`;
869
+ }
870
+ });
871
+ const EVENT_NODES = [eventElement, eventStart, eventPage, eventTimer, eventKey, eventCustom];
872
+ const EXEC_IN$1 = { id: "exec", type: "exec" };
873
+ const THEN$1 = { id: "then", type: "exec" };
874
+ const block = (code) => code.split("\n").map((l) => l.trim() ? " " + l : l).join("\n");
875
+ const wrap = (head, inner, tail = "}") => inner.trim() ? `${head}
876
+ ${block(inner)}
877
+ ${tail}` : "";
878
+ const branch = validate.defineNode({
879
+ type: "flow.branch",
880
+ category: "flow",
881
+ title: "Branch",
882
+ description: 'If the condition is true, runs "True", otherwise "False".',
883
+ keywords: ["if", "else", "condition"],
884
+ ports: {
885
+ inputs: [EXEC_IN$1, { id: "condition", type: "boolean", label: "Condition", default: false }],
886
+ outputs: [
887
+ { id: "true", type: "exec", label: "True" },
888
+ { id: "false", type: "exec", label: "False" }
889
+ ]
890
+ },
891
+ compile(c) {
892
+ const t = c.next("true");
893
+ const f = c.next("false");
894
+ const cond = c.in("condition");
895
+ if (!t.trim() && !f.trim()) return "";
896
+ if (!t.trim()) return wrap(`if (!${cond}) {`, f);
897
+ return f.trim() ? `if (${cond}) {
898
+ ${block(t)}
899
+ } else {
900
+ ${block(f)}
901
+ }` : wrap(`if (${cond}) {`, t);
902
+ }
903
+ });
904
+ const sequence = validate.defineNode({
905
+ type: "flow.sequence",
906
+ category: "flow",
907
+ title: "Sequence",
908
+ description: "Runs the outputs one after another, top to bottom.",
909
+ keywords: ["then", "order", "steps"],
910
+ props: [{ id: "count", type: "number", label: "Outputs", default: 2 }],
911
+ ports: (p) => {
912
+ const n = Math.min(10, Math.max(2, Math.floor(Number(p.count) || 2)));
913
+ return { inputs: [EXEC_IN$1], outputs: Array.from({ length: n }, (_, i) => ({ id: `then${i}`, type: "exec", label: `Then ${i}` })) };
914
+ },
915
+ compile(c) {
916
+ const n = Math.min(10, Math.max(2, Math.floor(Number(c.prop("count")) || 2)));
917
+ return Array.from({ length: n }, (_, i) => c.next(`then${i}`)).filter((s) => s.trim()).join("\n");
918
+ }
919
+ });
920
+ const delay = validate.defineNode({
921
+ type: "flow.delay",
922
+ category: "flow",
923
+ title: "Delay",
924
+ description: "Waits, then continues.",
925
+ keywords: ["wait", "timeout", "sleep", "later"],
926
+ ports: { inputs: [EXEC_IN$1, { id: "ms", type: "number", label: "Milliseconds", default: 300 }], outputs: [THEN$1] },
927
+ compile(c) {
928
+ const inner = c.next("then");
929
+ return inner.trim() ? `${c.h("timeout")}(__d, function () {
930
+ ${block(inner)}
931
+ }, ${c.in("ms")});` : "";
932
+ }
933
+ });
934
+ const debounce = validate.defineNode({
935
+ type: "flow.debounce",
936
+ category: "flow",
937
+ title: "Debounce",
938
+ description: "Continues only after calls stop for the given time (typing, resizing).",
939
+ keywords: ["wait", "typing", "rate"],
940
+ ports: { inputs: [EXEC_IN$1, { id: "ms", type: "number", label: "Milliseconds", default: 300 }], outputs: [THEN$1] },
941
+ compile(c) {
942
+ const t = c.state("timer", "null");
943
+ const inner = c.next("then");
944
+ return [`clearTimeout(${t});`, `${t} = ${c.h("timeout")}(__d, function () {
945
+ ${block(inner)}
946
+ }, ${c.in("ms")});`].join("\n");
947
+ }
948
+ });
949
+ const throttle = validate.defineNode({
950
+ type: "flow.throttle",
951
+ category: "flow",
952
+ title: "Throttle",
953
+ description: "Continues at most once per the given time.",
954
+ keywords: ["rate", "limit"],
955
+ ports: { inputs: [EXEC_IN$1, { id: "ms", type: "number", label: "Milliseconds", default: 200 }], outputs: [THEN$1] },
956
+ compile(c) {
957
+ const last = c.state("last", "0");
958
+ const inner = c.next("then");
959
+ return wrap(`if (Date.now() - ${last} >= ${c.in("ms")}) {`, `${last} = Date.now();
960
+ ${inner}`);
961
+ }
962
+ });
963
+ const doOnce = validate.defineNode({
964
+ type: "flow.doOnce",
965
+ category: "flow",
966
+ title: "Do once",
967
+ description: 'Continues only the first time, until "Reset" is run.',
968
+ keywords: ["once", "first", "gate"],
969
+ ports: {
970
+ inputs: [EXEC_IN$1, { id: "reset", type: "exec", label: "Reset" }],
971
+ outputs: [THEN$1]
972
+ },
973
+ compile(c) {
974
+ const done = c.state("done", "false");
975
+ if (c.entry === "reset") return `${done} = false;`;
976
+ return `if (!${done}) {
977
+ ${block(`${done} = true;
978
+ ${c.next("then")}`)}
979
+ }`;
980
+ }
981
+ });
982
+ const forEach = validate.defineNode({
983
+ type: "flow.forEach",
984
+ category: "flow",
985
+ title: "For each",
986
+ description: 'Runs "Loop body" for every item (elements found by a selector, an array…), then "Completed".',
987
+ keywords: ["loop", "each", "iterate", "array", "list"],
988
+ ports: {
989
+ inputs: [EXEC_IN$1, { id: "items", type: "any", label: "Items", noLiteral: true }],
990
+ outputs: [
991
+ { id: "body", type: "exec", label: "Loop body" },
992
+ { id: "item", type: "any", label: "Item" },
993
+ { id: "index", type: "number", label: "Index" },
994
+ { id: "completed", type: "exec", label: "Completed" }
995
+ ]
996
+ },
997
+ compile(c) {
998
+ const list = c.local("list");
999
+ const i = c.local("i");
1000
+ const loop = c.next("body");
1001
+ return [
1002
+ loop.trim() ? `for (var ${i} = 0, ${list} = ${c.h("list")}(${c.in("items")}); ${i} < ${list}.length; ${i}++) {
1003
+ ${block(
1004
+ [c.set("item", `${list}[${i}]`), c.set("index", i), loop].filter((x) => x.trim()).join("\n")
1005
+ )}
1006
+ }` : "",
1007
+ c.next("completed")
1008
+ ].filter((s) => s.trim()).join("\n");
1009
+ }
1010
+ });
1011
+ const switchString = validate.defineNode({
1012
+ type: "flow.switch",
1013
+ category: "flow",
1014
+ title: "Switch",
1015
+ description: 'Runs the output whose case equals the value, otherwise "Default". Cases are comma-separated.',
1016
+ keywords: ["case", "match", "select"],
1017
+ props: [{ id: "cases", type: "string", label: "Cases", default: "a, b" }],
1018
+ ports: (p) => {
1019
+ const cases = splitCases(p.cases);
1020
+ return {
1021
+ inputs: [EXEC_IN$1, { id: "value", type: "any", label: "Value", default: "" }],
1022
+ outputs: [...cases.map((v, i) => ({ id: `case${i}`, type: "exec", label: v })), { id: "default", type: "exec", label: "Default" }]
1023
+ };
1024
+ },
1025
+ compile(c) {
1026
+ const cases = splitCases(c.prop("cases"));
1027
+ const v = c.local("v");
1028
+ const parts = [];
1029
+ cases.forEach((value, i) => {
1030
+ parts.push(`case ${c.lit(value)}:
1031
+ ${block(`${c.next(`case${i}`)}
1032
+ break;`)}`);
1033
+ });
1034
+ const def = c.next("default");
1035
+ if (def.trim()) parts.push(`default:
1036
+ ${block(def)}`);
1037
+ return `var ${v} = String(${c.in("value")});
1038
+ switch (${v}) {
1039
+ ${block(parts.join("\n"))}
1040
+ }`;
1041
+ }
1042
+ });
1043
+ function splitCases(v) {
1044
+ return Array.from(
1045
+ new Set(
1046
+ String(v ?? "").split(",").map((s) => s.trim()).filter(Boolean)
1047
+ )
1048
+ ).slice(0, 20);
1049
+ }
1050
+ const FLOW_NODES = [branch, sequence, delay, debounce, throttle, doOnce, forEach, switchString];
1051
+ const EXEC_IN = { id: "exec", type: "exec" };
1052
+ const THEN = { id: "then", type: "exec" };
1053
+ const argc = (p) => Math.min(6, Math.max(0, Math.floor(Number(p.args) || 0)));
1054
+ const argPins = (n) => Array.from({ length: n }, (_, i) => ({ id: `arg${i + 1}`, type: "any", label: `Argument ${i + 1}` }));
1055
+ const args = (c) => `[${Array.from({ length: argc({ args: c.prop("args") }) }, (_, i) => c.in(`arg${i + 1}`)).join(", ")}]`;
1056
+ const pathOk = (s) => /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(s);
1057
+ function path(c, id) {
1058
+ const p = String(c.prop(id) || "").trim();
1059
+ if (!pathOk(p)) c.warn(`"${p}" is not a global name like gsap.to`);
1060
+ return c.lit(p);
1061
+ }
1062
+ const libCall = validate.defineNode({
1063
+ type: "lib.call",
1064
+ category: "code",
1065
+ title: "Call function",
1066
+ description: "Calls a global function, e.g. a library one: `gsap.to`, `AOS.init`, `alert`. Arguments are passed in order.",
1067
+ keywords: ["library", "call", "function", "global", "gsap", "invoke"],
1068
+ color: "#5d4f8a",
1069
+ props: [
1070
+ { id: "fn", type: "string", label: "Function", default: "console.log", required: true },
1071
+ { id: "args", type: "number", label: "Arguments", default: 1 }
1072
+ ],
1073
+ helpers: ["lib"],
1074
+ ports: (p) => ({ inputs: [EXEC_IN, ...argPins(argc(p))], outputs: [THEN, { id: "result", type: "any", label: "Result" }] }),
1075
+ compile(c) {
1076
+ const call = `${c.h("lib")}.call(${c.win}, ${path(c, "fn")}, ${args(c)})`;
1077
+ return [c.used("result") ? c.set("result", call) : `${call};`, c.next("then")].filter((s) => s.trim()).join("\n");
1078
+ }
1079
+ });
1080
+ const libNew = validate.defineNode({
1081
+ type: "lib.new",
1082
+ category: "code",
1083
+ title: "Create object",
1084
+ description: "Creates an object of a library class: `new Swiper(element, options)`, `new Chart(canvas, config)`.",
1085
+ keywords: ["library", "new", "class", "construct", "swiper", "instance"],
1086
+ color: "#5d4f8a",
1087
+ props: [
1088
+ { id: "cls", type: "string", label: "Class", default: "Swiper", required: true },
1089
+ { id: "args", type: "number", label: "Arguments", default: 2 }
1090
+ ],
1091
+ helpers: ["lib"],
1092
+ ports: (p) => ({ inputs: [EXEC_IN, ...argPins(argc(p))], outputs: [THEN, { id: "object", type: "object", label: "Object" }] }),
1093
+ compile(c) {
1094
+ const expr = `${c.h("lib")}.create(${c.win}, ${path(c, "cls")}, ${args(c)})`;
1095
+ return [c.used("object") ? c.set("object", expr) : `${expr};`, c.next("then")].filter((s) => s.trim()).join("\n");
1096
+ }
1097
+ });
1098
+ const libMethod = validate.defineNode({
1099
+ type: "lib.method",
1100
+ category: "code",
1101
+ title: "Call method",
1102
+ description: "Calls a method of an object, e.g. `slideNext` of a Swiper, `play` of a video element.",
1103
+ keywords: ["method", "call", "object", "invoke"],
1104
+ color: "#5d4f8a",
1105
+ props: [
1106
+ { id: "method", type: "string", label: "Method", default: "", required: true },
1107
+ { id: "args", type: "number", label: "Arguments", default: 0 }
1108
+ ],
1109
+ helpers: ["lib"],
1110
+ ports: (p) => ({
1111
+ inputs: [EXEC_IN, { id: "target", type: "any", label: "Object", noLiteral: true, required: true }, ...argPins(argc(p))],
1112
+ outputs: [THEN, { id: "result", type: "any", label: "Result" }]
1113
+ }),
1114
+ compile(c) {
1115
+ const call = `${c.h("lib")}.method(${c.in("target")}, ${c.lit(String(c.prop("method") || ""))}, ${args(c)})`;
1116
+ return [c.used("result") ? c.set("result", call) : `${call};`, c.next("then")].filter((s) => s.trim()).join("\n");
1117
+ }
1118
+ });
1119
+ const libGet = validate.defineNode({
1120
+ type: "lib.get",
1121
+ category: "code",
1122
+ title: "Global value",
1123
+ description: "Reads a global value: `location.pathname`, `innerWidth`, a library object.",
1124
+ keywords: ["global", "window", "read", "property", "location"],
1125
+ color: "#5d4f8a",
1126
+ props: [{ id: "name", type: "string", label: "Name", default: "location.pathname", required: true }],
1127
+ helpers: ["lib"],
1128
+ ports: { inputs: [], outputs: [{ id: "value", type: "any", label: "Value" }] },
1129
+ compile(c) {
1130
+ return { outputs: { value: `${c.h("lib")}.get(${c.win}, ${path(c, "name")})` } };
1131
+ }
1132
+ });
1133
+ const dataObject = validate.defineNode({
1134
+ type: "data.object",
1135
+ category: "data",
1136
+ title: "Object (JSON)",
1137
+ description: 'An object or array written as JSON — for library options: `{ "loop": true, "speed": 600 }`.',
1138
+ keywords: ["json", "object", "options", "config", "array", "settings"],
1139
+ props: [{ id: "json", type: "code", label: "JSON", default: "{}" }],
1140
+ ports: { inputs: [], outputs: [{ id: "value", type: "object", label: "Object" }] },
1141
+ compile(c) {
1142
+ const raw = String(c.prop("json") ?? "").trim() || "null";
1143
+ let value = null;
1144
+ try {
1145
+ value = JSON.parse(raw);
1146
+ } catch (e) {
1147
+ c.warn(`Invalid JSON: ${e.message}`);
1148
+ }
1149
+ return { outputs: { value: `JSON.parse(${c.lit(JSON.stringify(value))})` } };
1150
+ }
1151
+ });
1152
+ const LIB_NODES = [libCall, libNew, libMethod, libGet, dataObject];
1153
+ const BUILTIN_NODES = [...EVENT_NODES, ...FLOW_NODES, ...DOM_NODES, ...DATA_NODES, ...LIB_NODES];
1154
+ function createRegistry(extra = []) {
1155
+ return new validate.NodeRegistry([...BUILTIN_NODES, ...extra]);
1156
+ }
1157
+ const VERSION = "0.2.0";
1158
+ exports.DATA_PIN_TYPES = validate.DATA_PIN_TYPES;
1159
+ exports.DEFAULT_BANNER = validate.DEFAULT_BANNER;
1160
+ exports.HELPERS = validate.HELPERS;
1161
+ exports.HELPER_PREFIX = validate.HELPER_PREFIX;
1162
+ exports.NodeRegistry = validate.NodeRegistry;
1163
+ exports.SCHEMA_VERSION = validate.SCHEMA_VERSION;
1164
+ exports.autoLayout = validate.autoLayout;
1165
+ exports.buildScript = validate.buildScript;
1166
+ exports.buildStandalone = validate.buildStandalone;
1167
+ exports.canConnect = validate.canConnect;
1168
+ exports.compileBlueprint = validate.compileBlueprint;
1169
+ exports.createBlueprint = validate.createBlueprint;
1170
+ exports.defaultProps = validate.defaultProps;
1171
+ exports.defineNode = validate.defineNode;
1172
+ exports.ident = validate.ident;
1173
+ exports.jsLiteral = validate.jsLiteral;
1174
+ exports.normalizeBlueprint = validate.normalizeBlueprint;
1175
+ exports.resolveHelpers = validate.resolveHelpers;
1176
+ exports.uid = validate.uid;
1177
+ exports.validateBlueprint = validate.validateBlueprint;
1178
+ exports.BUILTIN_NODES = BUILTIN_NODES;
1179
+ exports.DATA_NODES = DATA_NODES;
1180
+ exports.DOM_NODES = DOM_NODES;
1181
+ exports.ELEMENT_EVENTS = ELEMENT_EVENTS;
1182
+ exports.EVENT_NODES = EVENT_NODES;
1183
+ exports.FLOW_NODES = FLOW_NODES;
1184
+ exports.LIB_NODES = LIB_NODES;
1185
+ exports.PAGE_EVENTS = PAGE_EVENTS;
1186
+ exports.VERSION = VERSION;
1187
+ exports.addClass = addClass;
1188
+ exports.and = and;
1189
+ exports.booleanNode = booleanNode;
1190
+ exports.branch = branch;
1191
+ exports.compare = compare;
1192
+ exports.concat = concat;
1193
+ exports.createRegistry = createRegistry;
1194
+ exports.dataObject = dataObject;
1195
+ exports.debounce = debounce;
1196
+ exports.delay = delay;
1197
+ exports.dispatch = dispatch;
1198
+ exports.doOnce = doOnce;
1199
+ exports.eventCustom = eventCustom;
1200
+ exports.eventElement = eventElement;
1201
+ exports.eventKey = eventKey;
1202
+ exports.eventPage = eventPage;
1203
+ exports.eventStart = eventStart;
1204
+ exports.eventTarget = eventTarget;
1205
+ exports.eventTimer = eventTimer;
1206
+ exports.focus = focus;
1207
+ exports.forEach = forEach;
1208
+ exports.getAttr = getAttr;
1209
+ exports.getText = getText;
1210
+ exports.getValue = getValue;
1211
+ exports.getVar = getVar;
1212
+ exports.hasClass = hasClass;
1213
+ exports.hide = hide;
1214
+ exports.isVisible = isVisible;
1215
+ exports.jsCode = jsCode;
1216
+ exports.jsExpression = jsExpression;
1217
+ exports.libCall = libCall;
1218
+ exports.libGet = libGet;
1219
+ exports.libMethod = libMethod;
1220
+ exports.libNew = libNew;
1221
+ exports.log = log;
1222
+ exports.matches = matches;
1223
+ exports.math = math;
1224
+ exports.not = not;
1225
+ exports.numberNode = numberNode;
1226
+ exports.or = or;
1227
+ exports.param = param;
1228
+ exports.preventDefault = preventDefault;
1229
+ exports.query = query;
1230
+ exports.removeAttr = removeAttr;
1231
+ exports.removeClass = removeClass;
1232
+ exports.rootNode = rootNode;
1233
+ exports.scrollTo = scrollTo;
1234
+ exports.sequence = sequence;
1235
+ exports.setAttr = setAttr;
1236
+ exports.setHtml = setHtml;
1237
+ exports.setStyle = setStyle;
1238
+ exports.setText = setText;
1239
+ exports.setValue = setValue;
1240
+ exports.setVar = setVar;
1241
+ exports.show = show;
1242
+ exports.storageGet = storageGet;
1243
+ exports.storageSet = storageSet;
1244
+ exports.stringNode = stringNode;
1245
+ exports.switchString = switchString;
1246
+ exports.throttle = throttle;
1247
+ exports.toNumber = toNumber;
1248
+ exports.toText = toText;
1249
+ exports.toggleClass = toggleClass;
1250
+ exports.toggleVisible = toggleVisible;
1251
+ //# sourceMappingURL=index.cjs.map