@almadar/evaluator 2.13.0 → 2.14.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.
- package/dist/index.js +583 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function createEffectContext(base, handlers) {
|
|
|
21
21
|
}
|
|
22
22
|
function createChildContext(parent, locals) {
|
|
23
23
|
const mergedLocals = new Map(parent.locals);
|
|
24
|
-
locals.forEach((value,
|
|
24
|
+
locals.forEach((value, key2) => mergedLocals.set(key2, value));
|
|
25
25
|
return {
|
|
26
26
|
...parent,
|
|
27
27
|
locals: mergedLocals
|
|
@@ -222,7 +222,7 @@ function deepEqual(a, b) {
|
|
|
222
222
|
const keysB = Object.keys(b);
|
|
223
223
|
if (keysA.length !== keysB.length) return false;
|
|
224
224
|
return keysA.every(
|
|
225
|
-
(
|
|
225
|
+
(key2) => deepEqual(a[key2], b[key2])
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
return false;
|
|
@@ -518,13 +518,13 @@ function evalCallService(args, evaluate2, ctx) {
|
|
|
518
518
|
}
|
|
519
519
|
function evaluateNestedProps(obj, evaluate2, ctx) {
|
|
520
520
|
const result = {};
|
|
521
|
-
for (const [
|
|
521
|
+
for (const [key2, value] of Object.entries(obj)) {
|
|
522
522
|
if (Array.isArray(value) && value.length > 0 && typeof value[0] === "string") {
|
|
523
|
-
result[
|
|
523
|
+
result[key2] = evaluate2(value, ctx);
|
|
524
524
|
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
525
|
-
result[
|
|
525
|
+
result[key2] = evaluateNestedProps(value, evaluate2, ctx);
|
|
526
526
|
} else {
|
|
527
|
-
result[
|
|
527
|
+
result[key2] = value;
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
return result;
|
|
@@ -915,8 +915,8 @@ function evalStrTemplate(args, evaluate2, ctx) {
|
|
|
915
915
|
const template = evaluate2(args[0], ctx);
|
|
916
916
|
const vars = evaluate2(args[1], ctx);
|
|
917
917
|
if (!template) return "";
|
|
918
|
-
return template.replace(/\{(\w+)\}/g, (_,
|
|
919
|
-
const value = vars?.[
|
|
918
|
+
return template.replace(/\{(\w+)\}/g, (_, key2) => {
|
|
919
|
+
const value = vars?.[key2];
|
|
920
920
|
return value !== void 0 ? String(value) : "";
|
|
921
921
|
});
|
|
922
922
|
}
|
|
@@ -940,15 +940,15 @@ function evalWithItem(expr, evaluate2, ctx, item, index) {
|
|
|
940
940
|
const params = fnArgs[0];
|
|
941
941
|
const body = fnArgs[1];
|
|
942
942
|
if (typeof params === "string") {
|
|
943
|
-
const
|
|
944
|
-
locals.set(
|
|
943
|
+
const key2 = params.startsWith("@") ? params.slice(1) : params;
|
|
944
|
+
locals.set(key2, item);
|
|
945
945
|
} else if (Array.isArray(params)) {
|
|
946
946
|
const paramNames = params;
|
|
947
947
|
const values = [item, index];
|
|
948
948
|
for (let i = 0; i < paramNames.length; i++) {
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
locals.set(
|
|
949
|
+
const p2 = paramNames[i];
|
|
950
|
+
const key2 = p2.startsWith("@") ? p2.slice(1) : p2;
|
|
951
|
+
locals.set(key2, values[i]);
|
|
952
952
|
}
|
|
953
953
|
}
|
|
954
954
|
const childCtx2 = createChildContext(ctx, locals);
|
|
@@ -971,13 +971,13 @@ function evalReduceLambda(lambdaExpr, evaluate2, ctx, acc, item) {
|
|
|
971
971
|
if (Array.isArray(params)) {
|
|
972
972
|
const paramNames = params;
|
|
973
973
|
const values = [acc, item];
|
|
974
|
-
paramNames.forEach((
|
|
975
|
-
const
|
|
976
|
-
locals.set(
|
|
974
|
+
paramNames.forEach((p2, i) => {
|
|
975
|
+
const key2 = p2.startsWith("@") ? p2.slice(1) : p2;
|
|
976
|
+
locals.set(key2, values[i]);
|
|
977
977
|
});
|
|
978
978
|
} else if (typeof params === "string") {
|
|
979
|
-
const
|
|
980
|
-
locals.set(
|
|
979
|
+
const key2 = params.startsWith("@") ? params.slice(1) : params;
|
|
980
|
+
locals.set(key2, acc);
|
|
981
981
|
}
|
|
982
982
|
const childCtx2 = createChildContext(ctx, locals);
|
|
983
983
|
return evaluate2(body, childCtx2);
|
|
@@ -1059,13 +1059,13 @@ function evalArrayReverse(args, evaluate2, ctx) {
|
|
|
1059
1059
|
}
|
|
1060
1060
|
function evalArraySort(args, evaluate2, ctx) {
|
|
1061
1061
|
const arr = evaluate2(args[0], ctx);
|
|
1062
|
-
const
|
|
1062
|
+
const key2 = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
1063
1063
|
const dir = args.length > 2 ? evaluate2(args[2], ctx) : "asc";
|
|
1064
1064
|
const result = [...arr ?? []];
|
|
1065
|
-
if (
|
|
1065
|
+
if (key2) {
|
|
1066
1066
|
result.sort((a, b) => {
|
|
1067
|
-
const aVal = a[
|
|
1068
|
-
const bVal = b[
|
|
1067
|
+
const aVal = a[key2];
|
|
1068
|
+
const bVal = b[key2];
|
|
1069
1069
|
if (aVal < bVal) return dir === "asc" ? -1 : 1;
|
|
1070
1070
|
if (aVal > bVal) return dir === "asc" ? 1 : -1;
|
|
1071
1071
|
return 0;
|
|
@@ -1172,18 +1172,18 @@ function evalArrayCount(args, evaluate2, ctx) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
function evalArraySum(args, evaluate2, ctx) {
|
|
1174
1174
|
const arr = evaluate2(args[0], ctx);
|
|
1175
|
-
const
|
|
1175
|
+
const key2 = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
1176
1176
|
return (arr ?? []).reduce((sum, item) => {
|
|
1177
|
-
const value =
|
|
1177
|
+
const value = key2 ? item[key2] : item;
|
|
1178
1178
|
return sum + (typeof value === "number" ? value : 0);
|
|
1179
1179
|
}, 0);
|
|
1180
1180
|
}
|
|
1181
1181
|
function evalArrayAvg(args, evaluate2, ctx) {
|
|
1182
1182
|
const arr = evaluate2(args[0], ctx);
|
|
1183
1183
|
if (!arr || arr.length === 0) return 0;
|
|
1184
|
-
const
|
|
1184
|
+
const key2 = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
1185
1185
|
const sum = arr.reduce((s, item) => {
|
|
1186
|
-
const value =
|
|
1186
|
+
const value = key2 ? item[key2] : item;
|
|
1187
1187
|
return s + (typeof value === "number" ? value : 0);
|
|
1188
1188
|
}, 0);
|
|
1189
1189
|
return sum / arr.length;
|
|
@@ -1191,9 +1191,9 @@ function evalArrayAvg(args, evaluate2, ctx) {
|
|
|
1191
1191
|
function evalArrayMin(args, evaluate2, ctx) {
|
|
1192
1192
|
const arr = evaluate2(args[0], ctx);
|
|
1193
1193
|
if (!arr || arr.length === 0) return 0;
|
|
1194
|
-
const
|
|
1194
|
+
const key2 = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
1195
1195
|
const values = arr.map((item) => {
|
|
1196
|
-
const value =
|
|
1196
|
+
const value = key2 ? item[key2] : item;
|
|
1197
1197
|
return typeof value === "number" ? value : Infinity;
|
|
1198
1198
|
});
|
|
1199
1199
|
return Math.min(...values);
|
|
@@ -1201,19 +1201,19 @@ function evalArrayMin(args, evaluate2, ctx) {
|
|
|
1201
1201
|
function evalArrayMax(args, evaluate2, ctx) {
|
|
1202
1202
|
const arr = evaluate2(args[0], ctx);
|
|
1203
1203
|
if (!arr || arr.length === 0) return 0;
|
|
1204
|
-
const
|
|
1204
|
+
const key2 = args.length > 1 ? evaluate2(args[1], ctx) : void 0;
|
|
1205
1205
|
const values = arr.map((item) => {
|
|
1206
|
-
const value =
|
|
1206
|
+
const value = key2 ? item[key2] : item;
|
|
1207
1207
|
return typeof value === "number" ? value : -Infinity;
|
|
1208
1208
|
});
|
|
1209
1209
|
return Math.max(...values);
|
|
1210
1210
|
}
|
|
1211
1211
|
function evalArrayGroupBy(args, evaluate2, ctx) {
|
|
1212
1212
|
const arr = evaluate2(args[0], ctx);
|
|
1213
|
-
const
|
|
1213
|
+
const key2 = evaluate2(args[1], ctx);
|
|
1214
1214
|
const result = {};
|
|
1215
1215
|
for (const item of arr ?? []) {
|
|
1216
|
-
const groupKey = String(item[
|
|
1216
|
+
const groupKey = String(item[key2] ?? "undefined");
|
|
1217
1217
|
if (!result[groupKey]) {
|
|
1218
1218
|
result[groupKey] = [];
|
|
1219
1219
|
}
|
|
@@ -1271,8 +1271,8 @@ function evalLambda(lambdaExpr, evaluate2, ctx, ...values) {
|
|
|
1271
1271
|
values.forEach((v, i) => {
|
|
1272
1272
|
if (paramNames[i]) {
|
|
1273
1273
|
const paramName = paramNames[i];
|
|
1274
|
-
const
|
|
1275
|
-
newLocals.set(
|
|
1274
|
+
const key2 = paramName.startsWith("@") ? paramName.slice(1) : paramName;
|
|
1275
|
+
newLocals.set(key2, v);
|
|
1276
1276
|
}
|
|
1277
1277
|
});
|
|
1278
1278
|
} else if (typeof params === "string") {
|
|
@@ -1320,7 +1320,7 @@ function evalObjectSet(args, evaluate2, ctx) {
|
|
|
1320
1320
|
if (!path) return obj ?? {};
|
|
1321
1321
|
const result = structuredClone(obj ?? {});
|
|
1322
1322
|
const parts = path.split(".");
|
|
1323
|
-
if (parts.some((
|
|
1323
|
+
if (parts.some((p2) => FORBIDDEN_KEYS.has(p2))) {
|
|
1324
1324
|
return result;
|
|
1325
1325
|
}
|
|
1326
1326
|
let current = result;
|
|
@@ -1359,15 +1359,15 @@ function evalObjectDeepMerge(args, evaluate2, ctx) {
|
|
|
1359
1359
|
const objects = args.map((a) => evaluate2(a, ctx));
|
|
1360
1360
|
function deepMerge(target, source) {
|
|
1361
1361
|
const result = { ...target };
|
|
1362
|
-
for (const
|
|
1363
|
-
if (FORBIDDEN_KEYS.has(
|
|
1364
|
-
if (source[
|
|
1365
|
-
result[
|
|
1366
|
-
target[
|
|
1367
|
-
source[
|
|
1362
|
+
for (const key2 of Object.keys(source)) {
|
|
1363
|
+
if (FORBIDDEN_KEYS.has(key2)) continue;
|
|
1364
|
+
if (source[key2] !== null && typeof source[key2] === "object" && !Array.isArray(source[key2]) && target[key2] !== null && typeof target[key2] === "object" && !Array.isArray(target[key2])) {
|
|
1365
|
+
result[key2] = deepMerge(
|
|
1366
|
+
target[key2],
|
|
1367
|
+
source[key2]
|
|
1368
1368
|
);
|
|
1369
1369
|
} else {
|
|
1370
|
-
result[
|
|
1370
|
+
result[key2] = source[key2];
|
|
1371
1371
|
}
|
|
1372
1372
|
}
|
|
1373
1373
|
return result;
|
|
@@ -1378,9 +1378,9 @@ function evalObjectPick(args, evaluate2, ctx) {
|
|
|
1378
1378
|
const obj = evaluate2(args[0], ctx);
|
|
1379
1379
|
const keys = evaluate2(args[1], ctx);
|
|
1380
1380
|
const result = {};
|
|
1381
|
-
for (const
|
|
1382
|
-
if (obj && Object.prototype.hasOwnProperty.call(obj,
|
|
1383
|
-
result[
|
|
1381
|
+
for (const key2 of keys ?? []) {
|
|
1382
|
+
if (obj && Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
1383
|
+
result[key2] = obj[key2];
|
|
1384
1384
|
}
|
|
1385
1385
|
}
|
|
1386
1386
|
return result;
|
|
@@ -1390,9 +1390,9 @@ function evalObjectOmit(args, evaluate2, ctx) {
|
|
|
1390
1390
|
const keys = evaluate2(args[1], ctx);
|
|
1391
1391
|
const keysSet = new Set(keys ?? []);
|
|
1392
1392
|
const result = {};
|
|
1393
|
-
for (const
|
|
1394
|
-
if (!keysSet.has(
|
|
1395
|
-
result[
|
|
1393
|
+
for (const key2 of Object.keys(obj ?? {})) {
|
|
1394
|
+
if (!keysSet.has(key2)) {
|
|
1395
|
+
result[key2] = obj[key2];
|
|
1396
1396
|
}
|
|
1397
1397
|
}
|
|
1398
1398
|
return result;
|
|
@@ -1401,8 +1401,8 @@ function evalObjectMapValues(args, evaluate2, ctx) {
|
|
|
1401
1401
|
const obj = evaluate2(args[0], ctx);
|
|
1402
1402
|
const lambda = args[1];
|
|
1403
1403
|
const result = {};
|
|
1404
|
-
for (const [
|
|
1405
|
-
result[
|
|
1404
|
+
for (const [key2, value] of Object.entries(obj ?? {})) {
|
|
1405
|
+
result[key2] = evalLambda(lambda, evaluate2, ctx, value);
|
|
1406
1406
|
}
|
|
1407
1407
|
return result;
|
|
1408
1408
|
}
|
|
@@ -1410,8 +1410,8 @@ function evalObjectMapKeys(args, evaluate2, ctx) {
|
|
|
1410
1410
|
const obj = evaluate2(args[0], ctx);
|
|
1411
1411
|
const lambda = args[1];
|
|
1412
1412
|
const result = {};
|
|
1413
|
-
for (const [
|
|
1414
|
-
const newKey = String(evalLambda(lambda, evaluate2, ctx,
|
|
1413
|
+
for (const [key2, value] of Object.entries(obj ?? {})) {
|
|
1414
|
+
const newKey = String(evalLambda(lambda, evaluate2, ctx, key2));
|
|
1415
1415
|
result[newKey] = value;
|
|
1416
1416
|
}
|
|
1417
1417
|
return result;
|
|
@@ -1420,9 +1420,9 @@ function evalObjectFilter(args, evaluate2, ctx) {
|
|
|
1420
1420
|
const obj = evaluate2(args[0], ctx);
|
|
1421
1421
|
const lambda = args[1];
|
|
1422
1422
|
const result = {};
|
|
1423
|
-
for (const [
|
|
1424
|
-
if (evalLambda(lambda, evaluate2, ctx,
|
|
1425
|
-
result[
|
|
1423
|
+
for (const [key2, value] of Object.entries(obj ?? {})) {
|
|
1424
|
+
if (evalLambda(lambda, evaluate2, ctx, key2, value)) {
|
|
1425
|
+
result[key2] = value;
|
|
1426
1426
|
}
|
|
1427
1427
|
}
|
|
1428
1428
|
return result;
|
|
@@ -1442,8 +1442,8 @@ function evalObjectEquals(args, evaluate2, ctx) {
|
|
|
1442
1442
|
const xKeys = Object.keys(x);
|
|
1443
1443
|
const yKeys = Object.keys(y);
|
|
1444
1444
|
if (xKeys.length !== yKeys.length) return false;
|
|
1445
|
-
for (const
|
|
1446
|
-
if (!deepEqual2(x[
|
|
1445
|
+
for (const key2 of xKeys) {
|
|
1446
|
+
if (!deepEqual2(x[key2], y[key2])) {
|
|
1447
1447
|
return false;
|
|
1448
1448
|
}
|
|
1449
1449
|
}
|
|
@@ -1621,8 +1621,8 @@ function evalValidateEquals(args, evaluate2, ctx) {
|
|
|
1621
1621
|
const xKeys = Object.keys(x);
|
|
1622
1622
|
const yKeys = Object.keys(y);
|
|
1623
1623
|
if (xKeys.length !== yKeys.length) return false;
|
|
1624
|
-
for (const
|
|
1625
|
-
if (!deepEqual2(x[
|
|
1624
|
+
for (const key2 of xKeys) {
|
|
1625
|
+
if (!deepEqual2(x[key2], y[key2])) {
|
|
1626
1626
|
return false;
|
|
1627
1627
|
}
|
|
1628
1628
|
}
|
|
@@ -2292,8 +2292,8 @@ function evalProbSeed(args, evaluate2, ctx) {
|
|
|
2292
2292
|
ctx._probSeed = { state: n | 0 };
|
|
2293
2293
|
}
|
|
2294
2294
|
function evalProbFlip(args, evaluate2, ctx) {
|
|
2295
|
-
const
|
|
2296
|
-
return getRandom(ctx) <
|
|
2295
|
+
const p2 = evaluate2(args[0], ctx);
|
|
2296
|
+
return getRandom(ctx) < p2;
|
|
2297
2297
|
}
|
|
2298
2298
|
function evalProbGaussian(args, evaluate2, ctx) {
|
|
2299
2299
|
const mu = evaluate2(args[0], ctx);
|
|
@@ -2327,11 +2327,11 @@ function evalProbPoisson(args, evaluate2, ctx) {
|
|
|
2327
2327
|
const lambda = evaluate2(args[0], ctx);
|
|
2328
2328
|
const limit = Math.exp(-lambda);
|
|
2329
2329
|
let k = 0;
|
|
2330
|
-
let
|
|
2330
|
+
let p2 = 1;
|
|
2331
2331
|
do {
|
|
2332
2332
|
k++;
|
|
2333
|
-
|
|
2334
|
-
} while (
|
|
2333
|
+
p2 *= getRandom(ctx);
|
|
2334
|
+
} while (p2 > limit);
|
|
2335
2335
|
return k - 1;
|
|
2336
2336
|
}
|
|
2337
2337
|
function evalProbCondition(args, evaluate2, ctx) {
|
|
@@ -2443,10 +2443,10 @@ function evalProbHistogram(args, evaluate2, ctx) {
|
|
|
2443
2443
|
}
|
|
2444
2444
|
function evalProbPercentile(args, evaluate2, ctx) {
|
|
2445
2445
|
const samples = evaluate2(args[0], ctx);
|
|
2446
|
-
const
|
|
2446
|
+
const p2 = evaluate2(args[1], ctx);
|
|
2447
2447
|
if (samples.length === 0) return 0;
|
|
2448
2448
|
const sorted = [...samples].sort((a, b) => a - b);
|
|
2449
|
-
const idx =
|
|
2449
|
+
const idx = p2 / 100 * (sorted.length - 1);
|
|
2450
2450
|
const lo = Math.floor(idx);
|
|
2451
2451
|
const hi = Math.ceil(idx);
|
|
2452
2452
|
if (lo === hi) return sorted[lo];
|
|
@@ -2784,14 +2784,14 @@ function evalGeoRectCircleOverlap(args, evaluate2, ctx) {
|
|
|
2784
2784
|
return dx * dx + dy * dy <= c.r * c.r;
|
|
2785
2785
|
}
|
|
2786
2786
|
function evalGeoPointInRect(args, evaluate2, ctx) {
|
|
2787
|
-
const
|
|
2787
|
+
const p2 = asVec2(evaluate2(args[0], ctx));
|
|
2788
2788
|
const r = asRect(evaluate2(args[1], ctx));
|
|
2789
|
-
return
|
|
2789
|
+
return p2.x >= r.x && p2.x <= r.x + r.w && p2.y >= r.y && p2.y <= r.y + r.h;
|
|
2790
2790
|
}
|
|
2791
2791
|
function evalGeoPointInCircle(args, evaluate2, ctx) {
|
|
2792
|
-
const
|
|
2792
|
+
const p2 = asVec2(evaluate2(args[0], ctx));
|
|
2793
2793
|
const c = asCircle(evaluate2(args[1], ctx));
|
|
2794
|
-
const dx =
|
|
2794
|
+
const dx = p2.x - c.x, dy = p2.y - c.y;
|
|
2795
2795
|
return dx * dx + dy * dy <= c.r * c.r;
|
|
2796
2796
|
}
|
|
2797
2797
|
function evalGeoReflect(args, evaluate2, ctx) {
|
|
@@ -3067,6 +3067,500 @@ function evalEaseSmoothstep(args, evaluate2, ctx) {
|
|
|
3067
3067
|
return t * t * (3 - 2 * t);
|
|
3068
3068
|
}
|
|
3069
3069
|
|
|
3070
|
+
// std/noise.ts
|
|
3071
|
+
var PERM = [
|
|
3072
|
+
151,
|
|
3073
|
+
160,
|
|
3074
|
+
137,
|
|
3075
|
+
91,
|
|
3076
|
+
90,
|
|
3077
|
+
15,
|
|
3078
|
+
131,
|
|
3079
|
+
13,
|
|
3080
|
+
201,
|
|
3081
|
+
95,
|
|
3082
|
+
96,
|
|
3083
|
+
53,
|
|
3084
|
+
194,
|
|
3085
|
+
233,
|
|
3086
|
+
7,
|
|
3087
|
+
225,
|
|
3088
|
+
140,
|
|
3089
|
+
36,
|
|
3090
|
+
103,
|
|
3091
|
+
30,
|
|
3092
|
+
69,
|
|
3093
|
+
142,
|
|
3094
|
+
8,
|
|
3095
|
+
99,
|
|
3096
|
+
37,
|
|
3097
|
+
240,
|
|
3098
|
+
21,
|
|
3099
|
+
10,
|
|
3100
|
+
23,
|
|
3101
|
+
190,
|
|
3102
|
+
6,
|
|
3103
|
+
148,
|
|
3104
|
+
247,
|
|
3105
|
+
120,
|
|
3106
|
+
234,
|
|
3107
|
+
75,
|
|
3108
|
+
0,
|
|
3109
|
+
26,
|
|
3110
|
+
197,
|
|
3111
|
+
62,
|
|
3112
|
+
94,
|
|
3113
|
+
252,
|
|
3114
|
+
219,
|
|
3115
|
+
203,
|
|
3116
|
+
117,
|
|
3117
|
+
35,
|
|
3118
|
+
11,
|
|
3119
|
+
32,
|
|
3120
|
+
57,
|
|
3121
|
+
177,
|
|
3122
|
+
33,
|
|
3123
|
+
88,
|
|
3124
|
+
237,
|
|
3125
|
+
149,
|
|
3126
|
+
56,
|
|
3127
|
+
87,
|
|
3128
|
+
174,
|
|
3129
|
+
20,
|
|
3130
|
+
125,
|
|
3131
|
+
136,
|
|
3132
|
+
171,
|
|
3133
|
+
168,
|
|
3134
|
+
68,
|
|
3135
|
+
175,
|
|
3136
|
+
74,
|
|
3137
|
+
165,
|
|
3138
|
+
71,
|
|
3139
|
+
134,
|
|
3140
|
+
139,
|
|
3141
|
+
48,
|
|
3142
|
+
27,
|
|
3143
|
+
166,
|
|
3144
|
+
77,
|
|
3145
|
+
146,
|
|
3146
|
+
158,
|
|
3147
|
+
231,
|
|
3148
|
+
83,
|
|
3149
|
+
111,
|
|
3150
|
+
229,
|
|
3151
|
+
122,
|
|
3152
|
+
60,
|
|
3153
|
+
211,
|
|
3154
|
+
133,
|
|
3155
|
+
230,
|
|
3156
|
+
220,
|
|
3157
|
+
105,
|
|
3158
|
+
92,
|
|
3159
|
+
41,
|
|
3160
|
+
55,
|
|
3161
|
+
46,
|
|
3162
|
+
245,
|
|
3163
|
+
40,
|
|
3164
|
+
244,
|
|
3165
|
+
102,
|
|
3166
|
+
143,
|
|
3167
|
+
54,
|
|
3168
|
+
65,
|
|
3169
|
+
25,
|
|
3170
|
+
63,
|
|
3171
|
+
161,
|
|
3172
|
+
1,
|
|
3173
|
+
216,
|
|
3174
|
+
80,
|
|
3175
|
+
73,
|
|
3176
|
+
209,
|
|
3177
|
+
76,
|
|
3178
|
+
132,
|
|
3179
|
+
187,
|
|
3180
|
+
208,
|
|
3181
|
+
89,
|
|
3182
|
+
18,
|
|
3183
|
+
169,
|
|
3184
|
+
200,
|
|
3185
|
+
196,
|
|
3186
|
+
135,
|
|
3187
|
+
130,
|
|
3188
|
+
116,
|
|
3189
|
+
188,
|
|
3190
|
+
159,
|
|
3191
|
+
86,
|
|
3192
|
+
164,
|
|
3193
|
+
100,
|
|
3194
|
+
109,
|
|
3195
|
+
198,
|
|
3196
|
+
173,
|
|
3197
|
+
186,
|
|
3198
|
+
3,
|
|
3199
|
+
64,
|
|
3200
|
+
52,
|
|
3201
|
+
217,
|
|
3202
|
+
226,
|
|
3203
|
+
250,
|
|
3204
|
+
124,
|
|
3205
|
+
123,
|
|
3206
|
+
5,
|
|
3207
|
+
202,
|
|
3208
|
+
38,
|
|
3209
|
+
147,
|
|
3210
|
+
118,
|
|
3211
|
+
126,
|
|
3212
|
+
255,
|
|
3213
|
+
82,
|
|
3214
|
+
85,
|
|
3215
|
+
212,
|
|
3216
|
+
207,
|
|
3217
|
+
206,
|
|
3218
|
+
59,
|
|
3219
|
+
227,
|
|
3220
|
+
47,
|
|
3221
|
+
16,
|
|
3222
|
+
58,
|
|
3223
|
+
17,
|
|
3224
|
+
182,
|
|
3225
|
+
189,
|
|
3226
|
+
28,
|
|
3227
|
+
42,
|
|
3228
|
+
223,
|
|
3229
|
+
183,
|
|
3230
|
+
170,
|
|
3231
|
+
213,
|
|
3232
|
+
119,
|
|
3233
|
+
248,
|
|
3234
|
+
152,
|
|
3235
|
+
2,
|
|
3236
|
+
44,
|
|
3237
|
+
154,
|
|
3238
|
+
163,
|
|
3239
|
+
70,
|
|
3240
|
+
221,
|
|
3241
|
+
153,
|
|
3242
|
+
101,
|
|
3243
|
+
155,
|
|
3244
|
+
167,
|
|
3245
|
+
43,
|
|
3246
|
+
172,
|
|
3247
|
+
9,
|
|
3248
|
+
129,
|
|
3249
|
+
22,
|
|
3250
|
+
39,
|
|
3251
|
+
253,
|
|
3252
|
+
19,
|
|
3253
|
+
98,
|
|
3254
|
+
108,
|
|
3255
|
+
110,
|
|
3256
|
+
79,
|
|
3257
|
+
113,
|
|
3258
|
+
224,
|
|
3259
|
+
232,
|
|
3260
|
+
178,
|
|
3261
|
+
185,
|
|
3262
|
+
112,
|
|
3263
|
+
104,
|
|
3264
|
+
218,
|
|
3265
|
+
246,
|
|
3266
|
+
97,
|
|
3267
|
+
228,
|
|
3268
|
+
251,
|
|
3269
|
+
34,
|
|
3270
|
+
242,
|
|
3271
|
+
193,
|
|
3272
|
+
238,
|
|
3273
|
+
210,
|
|
3274
|
+
144,
|
|
3275
|
+
12,
|
|
3276
|
+
191,
|
|
3277
|
+
179,
|
|
3278
|
+
162,
|
|
3279
|
+
241,
|
|
3280
|
+
81,
|
|
3281
|
+
51,
|
|
3282
|
+
145,
|
|
3283
|
+
235,
|
|
3284
|
+
249,
|
|
3285
|
+
14,
|
|
3286
|
+
239,
|
|
3287
|
+
107,
|
|
3288
|
+
49,
|
|
3289
|
+
192,
|
|
3290
|
+
214,
|
|
3291
|
+
31,
|
|
3292
|
+
181,
|
|
3293
|
+
199,
|
|
3294
|
+
106,
|
|
3295
|
+
157,
|
|
3296
|
+
184,
|
|
3297
|
+
84,
|
|
3298
|
+
204,
|
|
3299
|
+
176,
|
|
3300
|
+
115,
|
|
3301
|
+
121,
|
|
3302
|
+
50,
|
|
3303
|
+
45,
|
|
3304
|
+
127,
|
|
3305
|
+
4,
|
|
3306
|
+
150,
|
|
3307
|
+
254,
|
|
3308
|
+
138,
|
|
3309
|
+
236,
|
|
3310
|
+
205,
|
|
3311
|
+
93,
|
|
3312
|
+
222,
|
|
3313
|
+
114,
|
|
3314
|
+
67,
|
|
3315
|
+
29,
|
|
3316
|
+
24,
|
|
3317
|
+
72,
|
|
3318
|
+
243,
|
|
3319
|
+
141,
|
|
3320
|
+
128,
|
|
3321
|
+
195,
|
|
3322
|
+
78,
|
|
3323
|
+
66,
|
|
3324
|
+
215,
|
|
3325
|
+
61,
|
|
3326
|
+
156,
|
|
3327
|
+
180
|
|
3328
|
+
];
|
|
3329
|
+
function p(i) {
|
|
3330
|
+
return PERM[i & 255];
|
|
3331
|
+
}
|
|
3332
|
+
function fade(t) {
|
|
3333
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
3334
|
+
}
|
|
3335
|
+
function lerp(a, b, t) {
|
|
3336
|
+
return a + t * (b - a);
|
|
3337
|
+
}
|
|
3338
|
+
function grad2(hash, x, y) {
|
|
3339
|
+
const h = hash & 7;
|
|
3340
|
+
const u = h < 4 ? x : y;
|
|
3341
|
+
const v = h < 4 ? y : x;
|
|
3342
|
+
return ((h & 1) === 0 ? u : -u) + ((h & 2) === 0 ? v : -v);
|
|
3343
|
+
}
|
|
3344
|
+
function perlin(x, y, seed) {
|
|
3345
|
+
const s = Math.floor(seed) & 255;
|
|
3346
|
+
const X = Math.floor(x) + s & 255;
|
|
3347
|
+
const Y = Math.floor(y) + s & 255;
|
|
3348
|
+
const xf = x - Math.floor(x);
|
|
3349
|
+
const yf = y - Math.floor(y);
|
|
3350
|
+
const u = fade(xf);
|
|
3351
|
+
const v = fade(yf);
|
|
3352
|
+
const aa = p(p(X) + Y);
|
|
3353
|
+
const ab = p(p(X) + Y + 1);
|
|
3354
|
+
const ba = p(p(X + 1) + Y);
|
|
3355
|
+
const bb = p(p(X + 1) + Y + 1);
|
|
3356
|
+
const x1 = lerp(grad2(aa, xf, yf), grad2(ba, xf - 1, yf), u);
|
|
3357
|
+
const x2 = lerp(grad2(ab, xf, yf - 1), grad2(bb, xf - 1, yf - 1), u);
|
|
3358
|
+
return lerp(x1, x2, v);
|
|
3359
|
+
}
|
|
3360
|
+
function simplex(x, y, seed) {
|
|
3361
|
+
return (perlin(x, y, seed) + perlin(x * 2 + 5.2, y * 2 + 1.3, seed) * 0.5 + perlin(x * 4 + 9.1, y * 4 + 7.7, seed) * 0.25) / 1.75;
|
|
3362
|
+
}
|
|
3363
|
+
function fbm(x, y, octaves, seed) {
|
|
3364
|
+
let n = Math.floor(octaves);
|
|
3365
|
+
if (n < 1) n = 1;
|
|
3366
|
+
if (n > 8) n = 8;
|
|
3367
|
+
let total = 0;
|
|
3368
|
+
let freq = 1;
|
|
3369
|
+
let amp = 1;
|
|
3370
|
+
let max = 0;
|
|
3371
|
+
for (let i = 0; i < n; i++) {
|
|
3372
|
+
total += perlin(x * freq, y * freq, seed) * amp;
|
|
3373
|
+
max += amp;
|
|
3374
|
+
freq *= 2;
|
|
3375
|
+
amp *= 0.5;
|
|
3376
|
+
}
|
|
3377
|
+
return total / max;
|
|
3378
|
+
}
|
|
3379
|
+
function evalNoisePerlin(args, evaluate2, ctx) {
|
|
3380
|
+
const x = evaluate2(args[0], ctx);
|
|
3381
|
+
const y = args.length > 1 ? evaluate2(args[1], ctx) : 0;
|
|
3382
|
+
const seed = args.length > 2 ? evaluate2(args[2], ctx) : 0;
|
|
3383
|
+
return perlin(x, y, seed);
|
|
3384
|
+
}
|
|
3385
|
+
function evalNoiseSimplex(args, evaluate2, ctx) {
|
|
3386
|
+
const x = evaluate2(args[0], ctx);
|
|
3387
|
+
const y = evaluate2(args[1], ctx);
|
|
3388
|
+
const seed = args.length > 2 ? evaluate2(args[2], ctx) : 0;
|
|
3389
|
+
return simplex(x, y, seed);
|
|
3390
|
+
}
|
|
3391
|
+
function evalNoiseFbm(args, evaluate2, ctx) {
|
|
3392
|
+
const x = evaluate2(args[0], ctx);
|
|
3393
|
+
const y = evaluate2(args[1], ctx);
|
|
3394
|
+
const octaves = evaluate2(args[2], ctx);
|
|
3395
|
+
const seed = args.length > 3 ? evaluate2(args[3], ctx) : 0;
|
|
3396
|
+
return fbm(x, y, octaves, seed);
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
// std/path.ts
|
|
3400
|
+
function asCell2(v) {
|
|
3401
|
+
const o = v ?? {};
|
|
3402
|
+
const x = typeof o.x === "number" ? o.x : 0;
|
|
3403
|
+
const y = typeof o.y === "number" ? o.y : 0;
|
|
3404
|
+
return { x, y };
|
|
3405
|
+
}
|
|
3406
|
+
function key(x, y) {
|
|
3407
|
+
return `${x},${y}`;
|
|
3408
|
+
}
|
|
3409
|
+
var DIRS4 = [
|
|
3410
|
+
[0, -1],
|
|
3411
|
+
[1, 0],
|
|
3412
|
+
[0, 1],
|
|
3413
|
+
[-1, 0]
|
|
3414
|
+
];
|
|
3415
|
+
var DIRS_DIAG = [
|
|
3416
|
+
[1, -1],
|
|
3417
|
+
[1, 1],
|
|
3418
|
+
[-1, 1],
|
|
3419
|
+
[-1, -1]
|
|
3420
|
+
];
|
|
3421
|
+
function neighbors(diagonal) {
|
|
3422
|
+
return diagonal ? [...DIRS4, ...DIRS_DIAG] : DIRS4;
|
|
3423
|
+
}
|
|
3424
|
+
function blockedSet(blocked) {
|
|
3425
|
+
const set = /* @__PURE__ */ new Set();
|
|
3426
|
+
for (const b of blocked) {
|
|
3427
|
+
const c = asCell2(b);
|
|
3428
|
+
set.add(key(c.x, c.y));
|
|
3429
|
+
}
|
|
3430
|
+
return set;
|
|
3431
|
+
}
|
|
3432
|
+
function evalPathAstar(args, evaluate2, ctx) {
|
|
3433
|
+
const start = asCell2(evaluate2(args[0], ctx));
|
|
3434
|
+
const goal = asCell2(evaluate2(args[1], ctx));
|
|
3435
|
+
const blockedArr = evaluate2(args[2], ctx) ?? [];
|
|
3436
|
+
const w = evaluate2(args[3], ctx);
|
|
3437
|
+
const h = evaluate2(args[4], ctx);
|
|
3438
|
+
const diagonal = args.length > 5 ? Boolean(evaluate2(args[5], ctx)) : false;
|
|
3439
|
+
const blocked = blockedSet(blockedArr);
|
|
3440
|
+
const dirs = neighbors(diagonal);
|
|
3441
|
+
const heuristic = (x, y) => {
|
|
3442
|
+
const dx = Math.abs(x - goal.x);
|
|
3443
|
+
const dy = Math.abs(y - goal.y);
|
|
3444
|
+
return diagonal ? Math.max(dx, dy) : dx + dy;
|
|
3445
|
+
};
|
|
3446
|
+
const startKey = key(start.x, start.y);
|
|
3447
|
+
const goalKey = key(goal.x, goal.y);
|
|
3448
|
+
if (start.x < 0 || start.x >= w || start.y < 0 || start.y >= h || goal.x < 0 || goal.x >= w || goal.y < 0 || goal.y >= h || blocked.has(startKey) || blocked.has(goalKey)) {
|
|
3449
|
+
return [];
|
|
3450
|
+
}
|
|
3451
|
+
const open = [];
|
|
3452
|
+
const gScore = /* @__PURE__ */ new Map();
|
|
3453
|
+
const cameFrom = /* @__PURE__ */ new Map();
|
|
3454
|
+
let counter = 0;
|
|
3455
|
+
gScore.set(startKey, 0);
|
|
3456
|
+
open.push({
|
|
3457
|
+
x: start.x,
|
|
3458
|
+
y: start.y,
|
|
3459
|
+
g: 0,
|
|
3460
|
+
h: heuristic(start.x, start.y),
|
|
3461
|
+
f: heuristic(start.x, start.y),
|
|
3462
|
+
order: counter++
|
|
3463
|
+
});
|
|
3464
|
+
while (open.length > 0) {
|
|
3465
|
+
let bestIdx = 0;
|
|
3466
|
+
for (let i = 1; i < open.length; i++) {
|
|
3467
|
+
const a = open[i];
|
|
3468
|
+
const b = open[bestIdx];
|
|
3469
|
+
if (a.f < b.f || a.f === b.f && a.h < b.h || a.f === b.f && a.h === b.h && a.order < b.order) {
|
|
3470
|
+
bestIdx = i;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
const current = open[bestIdx];
|
|
3474
|
+
open.splice(bestIdx, 1);
|
|
3475
|
+
const curKey = key(current.x, current.y);
|
|
3476
|
+
if (curKey === goalKey) {
|
|
3477
|
+
const path = [];
|
|
3478
|
+
let k = curKey;
|
|
3479
|
+
while (k !== void 0) {
|
|
3480
|
+
const parts = k.split(",");
|
|
3481
|
+
path.push({ x: Number(parts[0]), y: Number(parts[1]) });
|
|
3482
|
+
k = cameFrom.get(k);
|
|
3483
|
+
}
|
|
3484
|
+
path.reverse();
|
|
3485
|
+
return path;
|
|
3486
|
+
}
|
|
3487
|
+
const recordedG = gScore.get(curKey);
|
|
3488
|
+
if (recordedG !== void 0 && current.g > recordedG) {
|
|
3489
|
+
continue;
|
|
3490
|
+
}
|
|
3491
|
+
for (const [dx, dy] of dirs) {
|
|
3492
|
+
const nx = current.x + dx;
|
|
3493
|
+
const ny = current.y + dy;
|
|
3494
|
+
if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
|
|
3495
|
+
continue;
|
|
3496
|
+
}
|
|
3497
|
+
const nKey = key(nx, ny);
|
|
3498
|
+
if (blocked.has(nKey)) {
|
|
3499
|
+
continue;
|
|
3500
|
+
}
|
|
3501
|
+
const tentativeG = current.g + 1;
|
|
3502
|
+
const existingG = gScore.get(nKey);
|
|
3503
|
+
if (existingG === void 0 || tentativeG < existingG) {
|
|
3504
|
+
gScore.set(nKey, tentativeG);
|
|
3505
|
+
cameFrom.set(nKey, curKey);
|
|
3506
|
+
const nh = heuristic(nx, ny);
|
|
3507
|
+
open.push({
|
|
3508
|
+
x: nx,
|
|
3509
|
+
y: ny,
|
|
3510
|
+
g: tentativeG,
|
|
3511
|
+
h: nh,
|
|
3512
|
+
f: tentativeG + nh,
|
|
3513
|
+
order: counter++
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
return [];
|
|
3519
|
+
}
|
|
3520
|
+
function evalPathReachable(args, evaluate2, ctx) {
|
|
3521
|
+
const start = asCell2(evaluate2(args[0], ctx));
|
|
3522
|
+
const steps = Math.floor(evaluate2(args[1], ctx));
|
|
3523
|
+
const blockedArr = evaluate2(args[2], ctx) ?? [];
|
|
3524
|
+
const w = evaluate2(args[3], ctx);
|
|
3525
|
+
const h = evaluate2(args[4], ctx);
|
|
3526
|
+
const diagonal = args.length > 5 ? Boolean(evaluate2(args[5], ctx)) : false;
|
|
3527
|
+
const blocked = blockedSet(blockedArr);
|
|
3528
|
+
const dirs = neighbors(diagonal);
|
|
3529
|
+
const startKey = key(start.x, start.y);
|
|
3530
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3531
|
+
if (start.x < 0 || start.x >= w || start.y < 0 || start.y >= h || blocked.has(startKey)) {
|
|
3532
|
+
return [];
|
|
3533
|
+
}
|
|
3534
|
+
visited.add(startKey);
|
|
3535
|
+
let frontier = [{ x: start.x, y: start.y }];
|
|
3536
|
+
for (let depth = 0; depth < steps; depth++) {
|
|
3537
|
+
const next = [];
|
|
3538
|
+
for (const cell of frontier) {
|
|
3539
|
+
for (const [dx, dy] of dirs) {
|
|
3540
|
+
const nx = cell.x + dx;
|
|
3541
|
+
const ny = cell.y + dy;
|
|
3542
|
+
if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
|
|
3543
|
+
continue;
|
|
3544
|
+
}
|
|
3545
|
+
const nKey = key(nx, ny);
|
|
3546
|
+
if (blocked.has(nKey) || visited.has(nKey)) {
|
|
3547
|
+
continue;
|
|
3548
|
+
}
|
|
3549
|
+
visited.add(nKey);
|
|
3550
|
+
next.push({ x: nx, y: ny });
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
frontier = next;
|
|
3554
|
+
}
|
|
3555
|
+
const result = [];
|
|
3556
|
+
for (const k of visited) {
|
|
3557
|
+
const parts = k.split(",");
|
|
3558
|
+
result.push({ x: Number(parts[0]), y: Number(parts[1]) });
|
|
3559
|
+
}
|
|
3560
|
+
result.sort((a, b) => a.y !== b.y ? a.y - b.y : a.x - b.x);
|
|
3561
|
+
return result;
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3070
3564
|
// SExpressionEvaluator.ts
|
|
3071
3565
|
var jitCache = /* @__PURE__ */ new Map();
|
|
3072
3566
|
var MAX_JIT_CACHE_SIZE = 1e3;
|
|
@@ -3138,8 +3632,8 @@ var SExpressionEvaluator = class {
|
|
|
3138
3632
|
* @returns Function that evaluates the expression given a context
|
|
3139
3633
|
*/
|
|
3140
3634
|
compile(expr) {
|
|
3141
|
-
const
|
|
3142
|
-
const cached = jitCache.get(
|
|
3635
|
+
const key2 = JSON.stringify(expr);
|
|
3636
|
+
const cached = jitCache.get(key2);
|
|
3143
3637
|
if (cached) {
|
|
3144
3638
|
return cached;
|
|
3145
3639
|
}
|
|
@@ -3150,7 +3644,7 @@ var SExpressionEvaluator = class {
|
|
|
3150
3644
|
jitCache.delete(firstKey);
|
|
3151
3645
|
}
|
|
3152
3646
|
}
|
|
3153
|
-
jitCache.set(
|
|
3647
|
+
jitCache.set(key2, fn);
|
|
3154
3648
|
return fn;
|
|
3155
3649
|
}
|
|
3156
3650
|
/**
|
|
@@ -3439,6 +3933,22 @@ var SExpressionEvaluator = class {
|
|
|
3439
3933
|
case "ease/smoothstep":
|
|
3440
3934
|
return evalEaseSmoothstep(args, evaluate2, ctx);
|
|
3441
3935
|
// ===============================
|
|
3936
|
+
// Standard Library: noise/*
|
|
3937
|
+
// ===============================
|
|
3938
|
+
case "noise/perlin":
|
|
3939
|
+
return evalNoisePerlin(args, evaluate2, ctx);
|
|
3940
|
+
case "noise/simplex":
|
|
3941
|
+
return evalNoiseSimplex(args, evaluate2, ctx);
|
|
3942
|
+
case "noise/fbm":
|
|
3943
|
+
return evalNoiseFbm(args, evaluate2, ctx);
|
|
3944
|
+
// ===============================
|
|
3945
|
+
// Standard Library: path/*
|
|
3946
|
+
// ===============================
|
|
3947
|
+
case "path/astar":
|
|
3948
|
+
return evalPathAstar(args, evaluate2, ctx);
|
|
3949
|
+
case "path/reachable":
|
|
3950
|
+
return evalPathReachable(args, evaluate2, ctx);
|
|
3951
|
+
// ===============================
|
|
3442
3952
|
// Standard Library: str/*
|
|
3443
3953
|
// ===============================
|
|
3444
3954
|
case "str/len":
|