@bitflow/core 0.5.2 → 0.5.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.
@@ -0,0 +1,732 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __reExport = (target, module2, copyDefault, desc) => {
30
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
31
+ for (let key of __getOwnPropNames(module2))
32
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
33
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
34
+ }
35
+ return target;
36
+ };
37
+ var __toESM = (module2, isNodeMode) => {
38
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
39
+ };
40
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
41
+ return (module2, temp) => {
42
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
43
+ };
44
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
45
+
46
+ // src/index.ts
47
+ var src_exports = {};
48
+ __export(src_exports, {
49
+ AndConditionSchema: () => AndConditionSchema,
50
+ ConditionSchema: () => ConditionSchema,
51
+ ControlFlowNodeSchema: () => ControlFlowNodeSchema,
52
+ EndSchema: () => EndSchema,
53
+ EqualConditionSchema: () => EqualConditionSchema,
54
+ FeedbackMessageSchema: () => FeedbackMessageSchema,
55
+ FlowCheckpointNodeSchema: () => FlowCheckpointNodeSchema,
56
+ FlowEdgeSchema: () => FlowEdgeSchema,
57
+ FlowPortalInputNodeSchema: () => FlowPortalInputNodeSchema,
58
+ FlowPortalOutputNodeSchema: () => FlowPortalOutputNodeSchema,
59
+ FlowSplitAnswerNodeSchema: () => FlowSplitAnswerNodeSchema,
60
+ FlowSplitPointsNodeSchema: () => FlowSplitPointsNodeSchema,
61
+ FlowSplitRandomNodeSchema: () => FlowSplitRandomNodeSchema,
62
+ FlowSplitResultNodeSchema: () => FlowSplitResultNodeSchema,
63
+ FlowSynchronizeNodeSchema: () => FlowSynchronizeNodeSchema,
64
+ GreaterConditionSchema: () => GreaterConditionSchema,
65
+ InConditionSchema: () => InConditionSchema,
66
+ InputSchema: () => InputSchema,
67
+ LessConditionSchema: () => LessConditionSchema,
68
+ OrConditionSchema: () => OrConditionSchema,
69
+ PortalInputSchema: () => PortalInputSchema,
70
+ PortalOutputSchema: () => PortalOutputSchema,
71
+ PrimitiveConditionSchema: () => PrimitiveConditionSchema,
72
+ SplitAnswerSchema: () => SplitAnswerSchema,
73
+ SplitPointsSchema: () => SplitPointsSchema,
74
+ SplitResultSchema: () => SplitResultSchema,
75
+ StartSchema: () => StartSchema,
76
+ TaskAnswerSchema: () => TaskAnswerSchema,
77
+ TaskResultSchema: () => TaskResultSchema,
78
+ TaskSchema: () => TaskSchema,
79
+ TaskStatisticSchema: () => TaskStatisticSchema,
80
+ TitleSchema: () => TitleSchema,
81
+ TrueConditionSchema: () => TrueConditionSchema,
82
+ extractInteractiveFlowPublicNode: () => extractInteractiveFlowPublicNode,
83
+ findLast: () => findLast,
84
+ finishDoTry: () => finishDoTry,
85
+ groupBy: () => groupBy,
86
+ isControlFlowNode: () => isControlFlowNode,
87
+ isDoFinishedTry: () => isDoFinishedTry,
88
+ isDoSkippedTry: () => isDoSkippedTry,
89
+ isDoStartedTry: () => isDoStartedTry,
90
+ isFlowEndNode: () => isFlowEndNode,
91
+ isFlowInputNode: () => isFlowInputNode,
92
+ isFlowPortalInputNode: () => isFlowPortalInputNode,
93
+ isFlowPortalOutputNode: () => isFlowPortalOutputNode,
94
+ isFlowSplitAnswerNode: () => isFlowSplitAnswerNode,
95
+ isFlowSplitPointsNode: () => isFlowSplitPointsNode,
96
+ isFlowSplitRandomNode: () => isFlowSplitRandomNode,
97
+ isFlowSplitResultNode: () => isFlowSplitResultNode,
98
+ isFlowStartNode: () => isFlowStartNode,
99
+ isFlowTaskNode: () => isFlowTaskNode,
100
+ isFlowTitleNode: () => isFlowTitleNode,
101
+ isInteractiveFlowNode: () => isInteractiveFlowNode,
102
+ lerpColor: () => lerpColor,
103
+ levenshtein: () => levenshtein,
104
+ makeDoBaseTrySchema: () => makeDoBaseTrySchema,
105
+ makeDoFinishedTry: () => makeDoFinishedTry,
106
+ makeDoSkippedTry: () => makeDoSkippedTry,
107
+ makeDoStartedTry: () => makeDoStartedTry,
108
+ makeEvaluate: () => makeEvaluate,
109
+ makeFlowEndNodeSchema: () => makeFlowEndNodeSchema,
110
+ makeFlowInputNodeSchema: () => makeFlowInputNodeSchema,
111
+ makeFlowNodeSchema: () => makeFlowNodeSchema,
112
+ makeFlowSchema: () => makeFlowSchema,
113
+ makeFlowStartNodeSchema: () => makeFlowStartNodeSchema,
114
+ makeFlowTaskNodeSchema: () => makeFlowTaskNodeSchema,
115
+ makeFlowTitleNodeSchema: () => makeFlowTitleNodeSchema,
116
+ makeInteractiveFlowNodeSchema: () => makeInteractiveFlowNodeSchema,
117
+ retryDoTry: () => retryDoTry,
118
+ skipDoTry: () => skipDoTry,
119
+ uuidv4: () => uuidv4
120
+ });
121
+
122
+ // ../../scripts/emotion-shim.js
123
+ var import_react = require("@emotion/react");
124
+
125
+ // src/bits.ts
126
+ var makeEvaluate = (evaluateMap) => ({ task, answer }) => {
127
+ const subtype = task.subtype;
128
+ const evaluate = evaluateMap[subtype];
129
+ if (!evaluate) {
130
+ throw new Error("subtype not supported");
131
+ }
132
+ return evaluate({ answer, task });
133
+ };
134
+
135
+ // src/bitsSchema.ts
136
+ var z = __toESM(require("zod"));
137
+ var FeedbackMessageSchema = z.object({
138
+ message: z.string(),
139
+ severity: z.enum(["error", "warning", "info", "success"])
140
+ });
141
+ var TaskSchema = z.object({
142
+ name: z.string(),
143
+ description: z.string().optional(),
144
+ subtype: z.string(),
145
+ view: z.record(z.any()),
146
+ evaluation: z.object({
147
+ mode: z.enum(["auto", "skip", "manual"]),
148
+ enableRetry: z.boolean(),
149
+ showFeedback: z.boolean()
150
+ }),
151
+ feedback: z.record(z.any()).optional()
152
+ });
153
+ var TaskStatisticSchema = z.object({
154
+ subtype: z.string(),
155
+ count: z.number()
156
+ });
157
+ var TaskAnswerSchema = z.object({
158
+ subtype: z.string()
159
+ });
160
+ var TaskResultSchema = z.object({
161
+ subtype: z.string(),
162
+ state: z.enum(["unknown", "manual", "correct", "wrong"]),
163
+ allowRetry: z.boolean().optional(),
164
+ feedback: z.any()
165
+ });
166
+ var InputSchema = z.object({
167
+ name: z.string(),
168
+ description: z.string(),
169
+ subtype: z.string(),
170
+ view: z.object({})
171
+ });
172
+ var TitleSchema = z.object({
173
+ name: z.string(),
174
+ description: z.string(),
175
+ subtype: z.string(),
176
+ view: z.object({})
177
+ });
178
+ var StartSchema = z.object({
179
+ name: z.string(),
180
+ description: z.string(),
181
+ subtype: z.string(),
182
+ view: z.object({})
183
+ });
184
+ var EndSchema = z.object({
185
+ name: z.string(),
186
+ description: z.string(),
187
+ subtype: z.string(),
188
+ view: z.object({})
189
+ });
190
+
191
+ // src/do.ts
192
+ var isDoStartedTry = (d) => {
193
+ return d.status === "started";
194
+ };
195
+ var isDoFinishedTry = (d) => {
196
+ return d.status === "finished";
197
+ };
198
+ var isDoSkippedTry = (d) => {
199
+ return d.status === "skipped";
200
+ };
201
+ var skipDoTry = (doResult, evaluation = { mode: "skip" }) => {
202
+ const { tries } = doResult;
203
+ let { maxPoints } = doResult;
204
+ const currentTry = tries[tries.length - 1];
205
+ const hasTry = tries.find((doTry) => doTry.node.id === currentTry.node.id && doTry.status !== "started");
206
+ if (!hasTry && (evaluation == null ? void 0 : evaluation.mode) !== "skip") {
207
+ maxPoints += 1;
208
+ }
209
+ tries[tries.length - 1] = __spreadProps(__spreadValues({}, currentTry), {
210
+ evaluation,
211
+ status: "skipped",
212
+ endDate: new Date()
213
+ });
214
+ return __spreadProps(__spreadValues({}, doResult), {
215
+ maxPoints,
216
+ tries
217
+ });
218
+ };
219
+ var finishDoTry = (doResult, answer, result) => {
220
+ var _a, _b;
221
+ const { tries } = doResult;
222
+ let { points, maxPoints } = doResult;
223
+ const currentTry = tries[tries.length - 1];
224
+ const hasTry = tries.find((doTry) => doTry.node.id === currentTry.node.id && doTry.status !== "started");
225
+ if (!hasTry && (result == null ? void 0 : result.state) !== "unknown") {
226
+ maxPoints += 1;
227
+ }
228
+ tries[tries.length - 1] = __spreadProps(__spreadValues({}, currentTry), {
229
+ status: "finished",
230
+ endDate: new Date(),
231
+ answer,
232
+ result
233
+ });
234
+ const lastTry = tries.filter(isDoFinishedTry).find((doTry) => doTry.node.id === currentTry.node.id && currentTry.try - 1 === doTry.try);
235
+ if (!lastTry && (result == null ? void 0 : result.state) === "correct") {
236
+ points += 1;
237
+ } else if (((_a = lastTry == null ? void 0 : lastTry.result) == null ? void 0 : _a.state) === "correct" && (result == null ? void 0 : result.state) !== "correct") {
238
+ points -= 1;
239
+ } else if (((_b = lastTry == null ? void 0 : lastTry.result) == null ? void 0 : _b.state) !== "correct" && (result == null ? void 0 : result.state) === "correct") {
240
+ points += 1;
241
+ }
242
+ return __spreadProps(__spreadValues({}, doResult), {
243
+ maxPoints,
244
+ points,
245
+ tries
246
+ });
247
+ };
248
+ var retryDoTry = (doResult) => {
249
+ const { tries } = doResult;
250
+ const lastTry = tries[tries.length - 1];
251
+ tries.push({
252
+ status: "started",
253
+ try: lastTry.try + 1,
254
+ startDate: new Date(),
255
+ node: __spreadValues({}, lastTry.node)
256
+ });
257
+ return __spreadProps(__spreadValues({}, doResult), { tries });
258
+ };
259
+
260
+ // src/doSchema.ts
261
+ var import_zod2 = require("zod");
262
+
263
+ // src/flowSchema.ts
264
+ var import_zod = require("zod");
265
+ var NodeBaseSchema = import_zod.z.object({
266
+ id: import_zod.z.string(),
267
+ position: import_zod.z.object({
268
+ x: import_zod.z.number(),
269
+ y: import_zod.z.number()
270
+ })
271
+ });
272
+ var FlowCheckpointNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
273
+ type: import_zod.z.literal("checkpoint")
274
+ }));
275
+ var FlowSynchronizeNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
276
+ type: import_zod.z.literal("synchronize"),
277
+ data: import_zod.z.object({
278
+ unlocked: import_zod.z.boolean()
279
+ })
280
+ }));
281
+ var makeFlowTaskNodeSchema = (task) => NodeBaseSchema.merge(import_zod.z.object({
282
+ type: import_zod.z.literal("task"),
283
+ data: task
284
+ }));
285
+ var makeFlowStartNodeSchema = (start) => NodeBaseSchema.merge(import_zod.z.object({
286
+ type: import_zod.z.literal("start"),
287
+ data: start
288
+ }));
289
+ var makeFlowEndNodeSchema = (end) => NodeBaseSchema.merge(import_zod.z.object({
290
+ type: import_zod.z.literal("end"),
291
+ data: end
292
+ }));
293
+ var makeFlowInputNodeSchema = (input) => NodeBaseSchema.merge(import_zod.z.object({
294
+ type: import_zod.z.literal("input"),
295
+ data: input
296
+ }));
297
+ var makeFlowTitleNodeSchema = (title) => NodeBaseSchema.merge(import_zod.z.object({
298
+ type: import_zod.z.literal("title"),
299
+ data: title
300
+ }));
301
+ var EqualConditionSchema = import_zod.z.object({
302
+ type: import_zod.z.literal("equal"),
303
+ not: import_zod.z.boolean(),
304
+ nodeId: import_zod.z.string(),
305
+ key: import_zod.z.string(),
306
+ value: import_zod.z.union([import_zod.z.string(), import_zod.z.number()])
307
+ });
308
+ var TrueConditionSchema = import_zod.z.object({
309
+ type: import_zod.z.literal("true"),
310
+ not: import_zod.z.boolean(),
311
+ nodeId: import_zod.z.string(),
312
+ key: import_zod.z.string()
313
+ });
314
+ var GreaterConditionSchema = import_zod.z.object({
315
+ type: import_zod.z.literal("greater"),
316
+ include: import_zod.z.boolean(),
317
+ not: import_zod.z.boolean(),
318
+ nodeId: import_zod.z.string(),
319
+ key: import_zod.z.string(),
320
+ value: import_zod.z.number()
321
+ });
322
+ var LessConditionSchema = import_zod.z.object({
323
+ type: import_zod.z.literal("less"),
324
+ include: import_zod.z.boolean(),
325
+ not: import_zod.z.boolean(),
326
+ nodeId: import_zod.z.string(),
327
+ key: import_zod.z.string(),
328
+ value: import_zod.z.number()
329
+ });
330
+ var InConditionSchema = import_zod.z.object({
331
+ type: import_zod.z.literal("in"),
332
+ not: import_zod.z.boolean(),
333
+ nodeId: import_zod.z.string(),
334
+ key: import_zod.z.string(),
335
+ value: import_zod.z.array(import_zod.z.union([import_zod.z.string(), import_zod.z.number()]))
336
+ });
337
+ var PrimitiveConditionSchema = import_zod.z.union([
338
+ EqualConditionSchema,
339
+ TrueConditionSchema,
340
+ GreaterConditionSchema,
341
+ LessConditionSchema,
342
+ InConditionSchema
343
+ ]);
344
+ var AndConditionSchema = import_zod.z.object({
345
+ type: import_zod.z.literal("and"),
346
+ conditions: import_zod.z.array(PrimitiveConditionSchema)
347
+ });
348
+ var OrConditionSchema = import_zod.z.object({
349
+ type: import_zod.z.literal("or"),
350
+ conditions: import_zod.z.array(PrimitiveConditionSchema)
351
+ });
352
+ var ConditionSchema = import_zod.z.union([
353
+ PrimitiveConditionSchema,
354
+ AndConditionSchema,
355
+ OrConditionSchema
356
+ ]);
357
+ var SplitAnswerSchema = import_zod.z.object({
358
+ condition: ConditionSchema
359
+ });
360
+ var FlowSplitAnswerNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
361
+ type: import_zod.z.literal("split-answer"),
362
+ data: SplitAnswerSchema
363
+ }));
364
+ var SplitResultSchema = import_zod.z.object({
365
+ condition: ConditionSchema
366
+ });
367
+ var FlowSplitResultNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
368
+ type: import_zod.z.literal("split-result"),
369
+ data: SplitResultSchema
370
+ }));
371
+ var SplitPointsSchema = import_zod.z.object({
372
+ points: import_zod.z.number()
373
+ });
374
+ var FlowSplitPointsNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
375
+ type: import_zod.z.literal("split-points"),
376
+ data: SplitPointsSchema
377
+ }));
378
+ var PortalInputSchema = import_zod.z.object({
379
+ portal: import_zod.z.string(),
380
+ description: import_zod.z.string()
381
+ });
382
+ var PortalOutputSchema = import_zod.z.object({
383
+ portal: import_zod.z.string(),
384
+ description: import_zod.z.string()
385
+ });
386
+ var FlowPortalInputNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
387
+ type: import_zod.z.literal("portal-input"),
388
+ data: PortalInputSchema
389
+ }));
390
+ var FlowPortalOutputNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
391
+ type: import_zod.z.literal("portal-output"),
392
+ data: PortalOutputSchema
393
+ }));
394
+ var FlowSplitRandomNodeSchema = NodeBaseSchema.merge(import_zod.z.object({
395
+ type: import_zod.z.literal("split-random")
396
+ }));
397
+ var ControlFlowNodeSchema = import_zod.z.union([
398
+ FlowSplitAnswerNodeSchema,
399
+ FlowSplitResultNodeSchema,
400
+ FlowSplitPointsNodeSchema,
401
+ FlowSplitRandomNodeSchema,
402
+ FlowPortalInputNodeSchema,
403
+ FlowPortalOutputNodeSchema
404
+ ]);
405
+ var makeInteractiveFlowNodeSchema = ({
406
+ start,
407
+ end,
408
+ input,
409
+ title,
410
+ task
411
+ }) => import_zod.z.union([
412
+ makeFlowStartNodeSchema(start),
413
+ makeFlowEndNodeSchema(end),
414
+ makeFlowInputNodeSchema(input),
415
+ makeFlowTaskNodeSchema(task),
416
+ makeFlowTitleNodeSchema(title),
417
+ FlowSynchronizeNodeSchema,
418
+ FlowCheckpointNodeSchema
419
+ ]);
420
+ var FlowEdgeSchema = import_zod.z.object({
421
+ id: import_zod.z.string(),
422
+ source: import_zod.z.string(),
423
+ sourceHandle: import_zod.z.union([
424
+ import_zod.z.literal("a"),
425
+ import_zod.z.literal("b"),
426
+ import_zod.z.literal("c"),
427
+ import_zod.z.literal("d"),
428
+ import_zod.z.literal("e"),
429
+ import_zod.z.literal("f")
430
+ ]).optional(),
431
+ target: import_zod.z.string()
432
+ });
433
+ var makeFlowNodeSchema = ({
434
+ end,
435
+ input,
436
+ start,
437
+ task,
438
+ title
439
+ }) => import_zod.z.union([
440
+ FlowSplitAnswerNodeSchema,
441
+ FlowSplitResultNodeSchema,
442
+ FlowSplitPointsNodeSchema,
443
+ FlowSplitRandomNodeSchema,
444
+ FlowPortalInputNodeSchema,
445
+ FlowPortalOutputNodeSchema,
446
+ FlowSynchronizeNodeSchema,
447
+ FlowCheckpointNodeSchema,
448
+ makeFlowEndNodeSchema(end),
449
+ makeFlowInputNodeSchema(input),
450
+ makeFlowStartNodeSchema(start),
451
+ makeFlowTaskNodeSchema(task),
452
+ makeFlowTitleNodeSchema(title)
453
+ ]);
454
+ var makeFlowSchema = ({
455
+ end,
456
+ input,
457
+ start,
458
+ task,
459
+ title
460
+ }) => import_zod.z.object({
461
+ name: import_zod.z.string(),
462
+ description: import_zod.z.string(),
463
+ language: import_zod.z.enum(["en", "de", "fr", "es", "nl", "pt", "tr", "it"]),
464
+ visibility: import_zod.z.enum(["public", "private", "unlisted"]),
465
+ draft: import_zod.z.boolean(),
466
+ nodes: import_zod.z.array(makeFlowNodeSchema({ start, end, input, title, task })),
467
+ edges: import_zod.z.array(FlowEdgeSchema),
468
+ zoom: import_zod.z.number().positive().default(1),
469
+ position: import_zod.z.tuple([import_zod.z.number(), import_zod.z.number()]).default([0, 0])
470
+ }).refine((data) => {
471
+ const ids = data.nodes.map((n) => n.id);
472
+ for (let edge of data.edges) {
473
+ if (!ids.includes(edge.source) || !ids.includes(edge.target)) {
474
+ return false;
475
+ }
476
+ }
477
+ return true;
478
+ }, { message: "Target and source of an edge need to be valid node ids." });
479
+
480
+ // src/doSchema.ts
481
+ var makeDoBaseTrySchema = (flowNodeSchemas) => import_zod2.z.object({
482
+ node: makeInteractiveFlowNodeSchema(flowNodeSchemas),
483
+ startDate: import_zod2.z.date(),
484
+ try: import_zod2.z.number(),
485
+ status: import_zod2.z.string()
486
+ });
487
+ var makeDoStartedTry = (flowNodeSchemas) => makeDoBaseTrySchema(flowNodeSchemas).merge(import_zod2.z.object({
488
+ status: import_zod2.z.literal("started")
489
+ }));
490
+ var makeDoFinishedTry = (flowNodeSchemas) => makeDoBaseTrySchema(flowNodeSchemas).merge(import_zod2.z.object({
491
+ status: import_zod2.z.literal("finished"),
492
+ endDate: import_zod2.z.date(),
493
+ answer: TaskAnswerSchema.optional(),
494
+ result: TaskResultSchema.optional()
495
+ }));
496
+ var makeDoSkippedTry = (flowNodeSchemas) => makeDoBaseTrySchema(flowNodeSchemas).merge(import_zod2.z.object({
497
+ status: import_zod2.z.literal("skipped"),
498
+ endDate: import_zod2.z.date()
499
+ }));
500
+
501
+ // src/findLast.ts
502
+ function findLast(array, predicate) {
503
+ let l = array.length;
504
+ while (l--) {
505
+ if (predicate(array[l], l, array))
506
+ return array[l];
507
+ }
508
+ return null;
509
+ }
510
+
511
+ // src/flow.ts
512
+ var isFlowTaskNode = (n) => {
513
+ if (n.type === "task") {
514
+ return true;
515
+ }
516
+ return false;
517
+ };
518
+ var isFlowStartNode = (n) => {
519
+ if (n.type === "start") {
520
+ return true;
521
+ }
522
+ return false;
523
+ };
524
+ var isFlowEndNode = (n) => {
525
+ if (n.type === "end") {
526
+ return true;
527
+ }
528
+ return false;
529
+ };
530
+ var isFlowInputNode = (n) => {
531
+ if (n.type === "input") {
532
+ return true;
533
+ }
534
+ return false;
535
+ };
536
+ var isFlowTitleNode = (n) => {
537
+ if (n.type === "title") {
538
+ return true;
539
+ }
540
+ return false;
541
+ };
542
+ var isFlowSplitAnswerNode = (n) => {
543
+ return n.type === "split-answer";
544
+ };
545
+ var isFlowSplitResultNode = (n) => {
546
+ return n.type === "split-result";
547
+ };
548
+ var isFlowSplitPointsNode = (n) => {
549
+ return n.type === "split-points";
550
+ };
551
+ var isFlowPortalInputNode = (n) => {
552
+ return n.type === "portal-input";
553
+ };
554
+ var isFlowPortalOutputNode = (n) => {
555
+ return n.type === "portal-output";
556
+ };
557
+ var isFlowSplitRandomNode = (n) => {
558
+ return n.type === "split-random";
559
+ };
560
+ var isControlFlowNode = (n) => {
561
+ return n.type === "portal-input" || n.type === "portal-output" || n.type === "split-answer" || n.type === "split-points" || n.type === "split-random" || n.type === "split-result";
562
+ };
563
+ var isInteractiveFlowNode = (n) => {
564
+ if (n.type === "checkpoint" || n.type === "end" || n.type === "input" || n.type === "start" || n.type === "synchronize" || n.type === "task" || n.type === "title") {
565
+ return true;
566
+ }
567
+ return false;
568
+ };
569
+ var extractInteractiveFlowPublicNode = (n) => {
570
+ if (n.type === "task") {
571
+ return {
572
+ id: n.id,
573
+ type: n.type,
574
+ data: {
575
+ name: n.data.name,
576
+ subtype: n.data.subtype,
577
+ view: n.data.view
578
+ }
579
+ };
580
+ } else if (n.type === "synchronize" || n.type === "checkpoint") {
581
+ return {
582
+ id: n.id,
583
+ type: n.type
584
+ };
585
+ } else if (n.type === "input") {
586
+ return {
587
+ id: n.id,
588
+ type: n.type,
589
+ data: n.data
590
+ };
591
+ } else if (n.type === "end") {
592
+ return {
593
+ id: n.id,
594
+ type: n.type,
595
+ data: n.data
596
+ };
597
+ } else if (n.type === "start") {
598
+ return {
599
+ id: n.id,
600
+ type: n.type,
601
+ data: n.data
602
+ };
603
+ }
604
+ return {
605
+ id: n.id,
606
+ type: n.type,
607
+ data: n.data
608
+ };
609
+ };
610
+
611
+ // src/groupBy.ts
612
+ function groupBy(array, by) {
613
+ const grouped = [];
614
+ let index = 0;
615
+ const indexes = {};
616
+ let l = 0;
617
+ while (l < array.length) {
618
+ const value = array[l];
619
+ const key = by(value);
620
+ if (indexes[key] === void 0) {
621
+ indexes[key] = index;
622
+ index++;
623
+ }
624
+ if (!grouped[indexes[key]]) {
625
+ grouped[indexes[key]] = [value];
626
+ } else {
627
+ grouped[indexes[key]].push(value);
628
+ }
629
+ l++;
630
+ }
631
+ return grouped;
632
+ }
633
+
634
+ // src/lerpColor.ts
635
+ function lerpColor(a, b, amount) {
636
+ let ah = +a.replace("#", "0x"), ar = ah >> 16, ag = ah >> 8 & 255, ab = ah & 255, bh = +b.replace("#", "0x"), br = bh >> 16, bg = bh >> 8 & 255, bb = bh & 255, rr = ar + amount * (br - ar), rg = ag + amount * (bg - ag), rb = ab + amount * (bb - ab);
637
+ return "#" + ((1 << 24) + (rr << 16) + (rg << 8) + rb | 0).toString(16).slice(1);
638
+ }
639
+
640
+ // src/levenshtein.ts
641
+ function _min(d0, d1, d2, bx, ay) {
642
+ return d0 < d1 || d2 < d1 ? d0 > d2 ? d2 + 1 : d0 + 1 : bx === ay ? d1 : d1 + 1;
643
+ }
644
+ var levenshtein = (a, b) => {
645
+ if (a === b) {
646
+ return 0;
647
+ }
648
+ if (a.length > b.length) {
649
+ var tmp = a;
650
+ a = b;
651
+ b = tmp;
652
+ }
653
+ var la = a.length;
654
+ var lb = b.length;
655
+ while (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) {
656
+ la--;
657
+ lb--;
658
+ }
659
+ var offset = 0;
660
+ while (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) {
661
+ offset++;
662
+ }
663
+ la -= offset;
664
+ lb -= offset;
665
+ if (la === 0 || lb < 3) {
666
+ return lb;
667
+ }
668
+ let x = 0;
669
+ let y;
670
+ let d0;
671
+ let d1;
672
+ let d2;
673
+ let d3;
674
+ let dd = 0;
675
+ let dy;
676
+ let ay;
677
+ let bx0;
678
+ let bx1;
679
+ let bx2;
680
+ let bx3;
681
+ let vector = [];
682
+ for (y = 0; y < la; y++) {
683
+ vector.push(y + 1);
684
+ vector.push(a.charCodeAt(offset + y));
685
+ }
686
+ let len = vector.length - 1;
687
+ for (; x < lb - 3; ) {
688
+ bx0 = b.charCodeAt(offset + (d0 = x));
689
+ bx1 = b.charCodeAt(offset + (d1 = x + 1));
690
+ bx2 = b.charCodeAt(offset + (d2 = x + 2));
691
+ bx3 = b.charCodeAt(offset + (d3 = x + 3));
692
+ dd = x += 4;
693
+ for (y = 0; y < len; y += 2) {
694
+ dy = vector[y];
695
+ ay = vector[y + 1];
696
+ d0 = _min(dy, d0, d1, bx0, ay);
697
+ d1 = _min(d0, d1, d2, bx1, ay);
698
+ d2 = _min(d1, d2, d3, bx2, ay);
699
+ dd = _min(d2, d3, dd, bx3, ay);
700
+ vector[y] = dd;
701
+ d3 = d2;
702
+ d2 = d1;
703
+ d1 = d0;
704
+ d0 = dy;
705
+ }
706
+ }
707
+ for (; x < lb; ) {
708
+ bx0 = b.charCodeAt(offset + (d0 = x));
709
+ dd = ++x;
710
+ for (y = 0; y < len; y += 2) {
711
+ dy = vector[y];
712
+ vector[y] = dd = _min(dy, d0, dd, bx0, vector[y + 1]);
713
+ d0 = dy;
714
+ }
715
+ }
716
+ return dd;
717
+ };
718
+
719
+ // src/uuid.ts
720
+ function uuidv4() {
721
+ var uuid = "", i, random;
722
+ for (i = 0; i < 32; i++) {
723
+ random = Math.random() * 16 | 0;
724
+ if (i == 8 || i == 12 || i == 16 || i == 20) {
725
+ uuid += "-";
726
+ }
727
+ uuid += (i == 12 ? 4 : i == 16 ? random & 3 | 8 : random).toString(16);
728
+ }
729
+ return uuid;
730
+ }
731
+ module.exports = __toCommonJS(src_exports);
732
+ //# sourceMappingURL=index.cjs.js.map