bruce-models 7.1.54 → 7.1.56
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/bruce-models.es5.js +388 -231
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +388 -231
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/bruce-models.js +1 -1
- package/dist/lib/calculator/calculator.js +387 -236
- package/dist/lib/calculator/calculator.js.map +1 -1
- package/dist/lib/project/project-view-bookmark.js.map +1 -1
- package/dist/types/bruce-models.d.ts +1 -1
- package/dist/types/calculator/calculator.d.ts +67 -0
- package/dist/types/project/project-view-bookmark.d.ts +4 -0
- package/package.json +1 -1
package/dist/bruce-models.umd.js
CHANGED
|
@@ -7193,12 +7193,234 @@
|
|
|
7193
7193
|
EValueType[EValueType["RandomColor"] = 5] = "RandomColor";
|
|
7194
7194
|
})(EValueType = Calculator.EValueType || (Calculator.EValueType = {}));
|
|
7195
7195
|
/**
|
|
7196
|
-
*
|
|
7197
|
-
*
|
|
7198
|
-
* When a value fails to be calculated, the 'defaultValue' is returned.
|
|
7199
|
-
* If no 'defaultValue' is provided, then 'null' is returned.
|
|
7196
|
+
* Decodes an effective string produced by TraceCalculate back into a structured object.
|
|
7197
|
+
* Returns null if the string is null, empty, or does not match the expected format.
|
|
7200
7198
|
*/
|
|
7201
|
-
function
|
|
7199
|
+
function DecodeEffective(effective) {
|
|
7200
|
+
if (!effective) {
|
|
7201
|
+
return null;
|
|
7202
|
+
}
|
|
7203
|
+
// Format: f{index}:{type}[:{part1}[:{part2}]]
|
|
7204
|
+
const match = effective.match(/^f(\d+):([^:]+)(?::([^:]+)(?::([^:]+))?)?$/);
|
|
7205
|
+
if (!match) {
|
|
7206
|
+
return null;
|
|
7207
|
+
}
|
|
7208
|
+
const fieldIndex = parseInt(match[1], 10);
|
|
7209
|
+
const type = match[2];
|
|
7210
|
+
const part1 = match[3] != null ? decodeEffective(match[3]) : null;
|
|
7211
|
+
const part2 = match[4] != null ? decodeEffective(match[4]) : null;
|
|
7212
|
+
const base = { type, fieldIndex };
|
|
7213
|
+
switch (type) {
|
|
7214
|
+
case "color":
|
|
7215
|
+
if (part1 == null) {
|
|
7216
|
+
return null;
|
|
7217
|
+
}
|
|
7218
|
+
return Object.assign(Object.assign({}, base), { colorStr: part1 });
|
|
7219
|
+
case "gradient":
|
|
7220
|
+
case "mapping":
|
|
7221
|
+
return Object.assign(Object.assign(Object.assign({}, base), (part1 != null && { path: part1 })), (part2 != null && { entityValue: part2 }));
|
|
7222
|
+
case "input":
|
|
7223
|
+
if (part1 == null || part2 == null) {
|
|
7224
|
+
return null;
|
|
7225
|
+
}
|
|
7226
|
+
return Object.assign(Object.assign({}, base), { template: part1, resolvedValue: part2 });
|
|
7227
|
+
case "tag":
|
|
7228
|
+
if (part1 == null) {
|
|
7229
|
+
return null;
|
|
7230
|
+
}
|
|
7231
|
+
return Object.assign(Object.assign({}, base), { tagColor: part1 });
|
|
7232
|
+
case "random":
|
|
7233
|
+
case "fn":
|
|
7234
|
+
return base;
|
|
7235
|
+
default:
|
|
7236
|
+
return null;
|
|
7237
|
+
}
|
|
7238
|
+
}
|
|
7239
|
+
Calculator.DecodeEffective = DecodeEffective;
|
|
7240
|
+
function encodeEffective(str) {
|
|
7241
|
+
const s = String(str == null ? "" : str);
|
|
7242
|
+
try {
|
|
7243
|
+
if (typeof Buffer !== "undefined") {
|
|
7244
|
+
return Buffer.from(s).toString("base64").replace(/=+$/, "");
|
|
7245
|
+
}
|
|
7246
|
+
// Browser fallback
|
|
7247
|
+
return btoa(s).replace(/=+$/, "");
|
|
7248
|
+
}
|
|
7249
|
+
catch (e) {
|
|
7250
|
+
return encodeURIComponent(s);
|
|
7251
|
+
}
|
|
7252
|
+
}
|
|
7253
|
+
function decodeEffective(encoded) {
|
|
7254
|
+
try {
|
|
7255
|
+
if (typeof Buffer !== "undefined") {
|
|
7256
|
+
return Buffer.from(encoded, "base64").toString("utf8");
|
|
7257
|
+
}
|
|
7258
|
+
return atob(encoded);
|
|
7259
|
+
}
|
|
7260
|
+
catch (e) {
|
|
7261
|
+
return decodeURIComponent(encoded);
|
|
7262
|
+
}
|
|
7263
|
+
}
|
|
7264
|
+
function _getMappingTrace(value, entity) {
|
|
7265
|
+
const attrPaths = parseLegacyPath(value.field);
|
|
7266
|
+
for (let i = 0; i < attrPaths.length; i++) {
|
|
7267
|
+
const attrPath = attrPaths[i];
|
|
7268
|
+
let eValue = exports.Entity.GetValue({
|
|
7269
|
+
entity: entity,
|
|
7270
|
+
path: attrPath
|
|
7271
|
+
});
|
|
7272
|
+
let isValueNum = !isNaN(+eValue);
|
|
7273
|
+
if (eValue == null) {
|
|
7274
|
+
isValueNum = false;
|
|
7275
|
+
}
|
|
7276
|
+
for (let j = 0; j < value.values.length; j++) {
|
|
7277
|
+
const option = value.values[j];
|
|
7278
|
+
const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
|
|
7279
|
+
for (let k = 0; k < fieldValues.length; k++) {
|
|
7280
|
+
let mapValue = fieldValues[k];
|
|
7281
|
+
// If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
|
|
7282
|
+
// This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
|
|
7283
|
+
if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
|
|
7284
|
+
try {
|
|
7285
|
+
let jsEval = mapValue.replace("JS:", "").trim();
|
|
7286
|
+
const attrPathStr = exports.PathUtils.Wrap(attrPath);
|
|
7287
|
+
jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
|
|
7288
|
+
jsEval = exports.BruceVariable.SwapValues({
|
|
7289
|
+
str: jsEval,
|
|
7290
|
+
entity: entity
|
|
7291
|
+
});
|
|
7292
|
+
// https://rollupjs.org/guide/en/#avoiding-eval
|
|
7293
|
+
// This stops eval warning.
|
|
7294
|
+
const eval2 = eval;
|
|
7295
|
+
mapValue = eval2(jsEval);
|
|
7296
|
+
if (mapValue) {
|
|
7297
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7298
|
+
}
|
|
7299
|
+
else {
|
|
7300
|
+
continue;
|
|
7301
|
+
}
|
|
7302
|
+
}
|
|
7303
|
+
catch (exception) {
|
|
7304
|
+
const e = exception;
|
|
7305
|
+
let suppress = false;
|
|
7306
|
+
if (e && typeof e == "object") {
|
|
7307
|
+
const msg = e.message;
|
|
7308
|
+
suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
|
|
7309
|
+
}
|
|
7310
|
+
if (!suppress) {
|
|
7311
|
+
console.error(e);
|
|
7312
|
+
}
|
|
7313
|
+
// Eval failed, therefor not a valid mapping-row.
|
|
7314
|
+
continue;
|
|
7315
|
+
}
|
|
7316
|
+
}
|
|
7317
|
+
let isMapValueNum = !isNaN(+mapValue);
|
|
7318
|
+
if (isMapValueNum == null) {
|
|
7319
|
+
isMapValueNum = false;
|
|
7320
|
+
}
|
|
7321
|
+
if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
|
|
7322
|
+
if (+mapValue == +eValue) {
|
|
7323
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7324
|
+
}
|
|
7325
|
+
const mapSplit = mapValue.split("-");
|
|
7326
|
+
if (mapSplit.length == 2) {
|
|
7327
|
+
const min = mapSplit[0];
|
|
7328
|
+
const max = mapSplit[1];
|
|
7329
|
+
if (min != "") {
|
|
7330
|
+
if (+eValue < +min) {
|
|
7331
|
+
continue;
|
|
7332
|
+
}
|
|
7333
|
+
}
|
|
7334
|
+
if (max != "") {
|
|
7335
|
+
if (+eValue > +max) {
|
|
7336
|
+
continue;
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
7339
|
+
if (min == "" && max == "") {
|
|
7340
|
+
continue;
|
|
7341
|
+
}
|
|
7342
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7343
|
+
}
|
|
7344
|
+
}
|
|
7345
|
+
else {
|
|
7346
|
+
if (mapValue == eValue) {
|
|
7347
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7348
|
+
}
|
|
7349
|
+
// Case where Entity value is a boolean but the mapping value is a string.
|
|
7350
|
+
// Common as mapping value is typically a user-entered string.
|
|
7351
|
+
else if (typeof eValue === "boolean" && typeof mapValue === "string") {
|
|
7352
|
+
const eValueStr = eValue ? "true" : "false";
|
|
7353
|
+
if (mapValue.toLowerCase() == eValueStr) {
|
|
7354
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
// Handling possible case where the opposite is true.
|
|
7358
|
+
// Have not seen this happen yet, but preparing for any future cases.
|
|
7359
|
+
else if (typeof mapValue === "boolean" && typeof eValue === "string") {
|
|
7360
|
+
const mapValueStr = mapValue ? "true" : "false";
|
|
7361
|
+
if (mapValueStr == eValue.toLowerCase()) {
|
|
7362
|
+
return { result: option.appliedValue, attrPath, eValue };
|
|
7363
|
+
}
|
|
7364
|
+
}
|
|
7365
|
+
}
|
|
7366
|
+
}
|
|
7367
|
+
}
|
|
7368
|
+
}
|
|
7369
|
+
return { result: null, attrPath: null, eValue: null };
|
|
7370
|
+
}
|
|
7371
|
+
function _getGradientTrace(value, entity, defaultToMin) {
|
|
7372
|
+
const min = +value.points[0].position;
|
|
7373
|
+
const max = +value.points[value.points.length - 1].position;
|
|
7374
|
+
const attrPaths = parseLegacyPath(value.field);
|
|
7375
|
+
for (let i = 0; i < attrPaths.length; i++) {
|
|
7376
|
+
const attrPath = attrPaths[i];
|
|
7377
|
+
let eValue = exports.Entity.GetValue({
|
|
7378
|
+
entity: entity,
|
|
7379
|
+
path: attrPath
|
|
7380
|
+
});
|
|
7381
|
+
if (typeof eValue == "string") {
|
|
7382
|
+
eValue = Number(eValue);
|
|
7383
|
+
}
|
|
7384
|
+
if ((!eValue && eValue != 0) || isNaN(eValue)) {
|
|
7385
|
+
continue;
|
|
7386
|
+
}
|
|
7387
|
+
if (eValue >= max) {
|
|
7388
|
+
return { result: exports.Color.ColorFromStr(value.points[value.points.length - 1].color), attrPath, eValue };
|
|
7389
|
+
}
|
|
7390
|
+
else if (eValue <= min) {
|
|
7391
|
+
return { result: exports.Color.ColorFromStr(value.points[0].color), attrPath, eValue };
|
|
7392
|
+
}
|
|
7393
|
+
for (let j = 0; j < value.points.length - 1; j++) {
|
|
7394
|
+
const pointA = value.points[j];
|
|
7395
|
+
const pointB = value.points[j + 1];
|
|
7396
|
+
if (eValue >= pointA.position && eValue <= pointB.position) {
|
|
7397
|
+
if (pointA.position == pointB.position) {
|
|
7398
|
+
return { result: exports.Color.ColorFromStr(pointA.color), attrPath, eValue };
|
|
7399
|
+
}
|
|
7400
|
+
const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
|
|
7401
|
+
const colorA = exports.Color.ColorFromStr(pointA.color);
|
|
7402
|
+
const colorB = exports.Color.ColorFromStr(pointB.color);
|
|
7403
|
+
return {
|
|
7404
|
+
result: {
|
|
7405
|
+
red: colorA.red + (colorB.red - colorA.red) * distance,
|
|
7406
|
+
green: colorA.green + (colorB.green - colorA.green) * distance,
|
|
7407
|
+
blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
|
|
7408
|
+
alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
|
|
7409
|
+
},
|
|
7410
|
+
attrPath,
|
|
7411
|
+
eValue
|
|
7412
|
+
};
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
// Fallback to min (static, no data path resolved).
|
|
7417
|
+
return { result: exports.Color.ColorFromStr(value.points[0].color), attrPath: null, eValue: null };
|
|
7418
|
+
}
|
|
7419
|
+
/**
|
|
7420
|
+
* Like Calculate, but also returns an 'effective' key describing how the value
|
|
7421
|
+
* was derived. See ITraceResult for the key format.
|
|
7422
|
+
*/
|
|
7423
|
+
function TraceCalculate(params) {
|
|
7202
7424
|
let { fields, tags, data, defaultValue, type } = params;
|
|
7203
7425
|
// If params doesn't include a defaultValue, use null.
|
|
7204
7426
|
// Though passing in undefined is valid!
|
|
@@ -7206,7 +7428,7 @@
|
|
|
7206
7428
|
defaultValue = null;
|
|
7207
7429
|
}
|
|
7208
7430
|
if (fields == null) {
|
|
7209
|
-
return defaultValue;
|
|
7431
|
+
return { value: defaultValue, effective: null };
|
|
7210
7432
|
}
|
|
7211
7433
|
if (data == null || typeof data != "object") {
|
|
7212
7434
|
data = {};
|
|
@@ -7251,16 +7473,21 @@
|
|
|
7251
7473
|
}
|
|
7252
7474
|
return false;
|
|
7253
7475
|
};
|
|
7254
|
-
// Calculate the value.
|
|
7255
7476
|
let value = null;
|
|
7477
|
+
let computedEffective = null;
|
|
7256
7478
|
for (let i = 0; i < fieldsArr.length; i++) {
|
|
7257
7479
|
let field = fieldsArr[i];
|
|
7480
|
+
// Intermediate trace parts — assembled into effective only if value resolves.
|
|
7481
|
+
let traceType = null;
|
|
7482
|
+
let tracePart1 = null;
|
|
7483
|
+
let tracePart2 = null;
|
|
7258
7484
|
// Bad data has it set to 'color' but expects the input to be a number.
|
|
7259
7485
|
if (type == "number" && field.type == EValueType.Color) {
|
|
7260
7486
|
field.type = EValueType.Input;
|
|
7261
7487
|
}
|
|
7262
7488
|
// Custom resolution.
|
|
7263
7489
|
if (field.value instanceof Function) {
|
|
7490
|
+
traceType = "fn";
|
|
7264
7491
|
value = field.value(data, tags);
|
|
7265
7492
|
if (type == "number") {
|
|
7266
7493
|
if (typeof value == "string" && value != "" && value != null && value != undefined) {
|
|
@@ -7294,6 +7521,8 @@
|
|
|
7294
7521
|
break;
|
|
7295
7522
|
}
|
|
7296
7523
|
value = field.value;
|
|
7524
|
+
traceType = "color";
|
|
7525
|
+
tracePart1 = encodeEffective(value);
|
|
7297
7526
|
value = assertColor(value);
|
|
7298
7527
|
if (value && type == "string") {
|
|
7299
7528
|
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
@@ -7303,10 +7532,17 @@
|
|
|
7303
7532
|
if (type === "number") {
|
|
7304
7533
|
break;
|
|
7305
7534
|
}
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7535
|
+
{
|
|
7536
|
+
const gradTrace = _getGradientTrace(field.value, data, shouldRangesDefaultToMin);
|
|
7537
|
+
value = assertColor(gradTrace.result);
|
|
7538
|
+
traceType = "gradient";
|
|
7539
|
+
if (gradTrace.attrPath != null) {
|
|
7540
|
+
tracePart1 = encodeEffective(exports.PathUtils.Wrap(gradTrace.attrPath));
|
|
7541
|
+
tracePart2 = encodeEffective(String(gradTrace.eValue));
|
|
7542
|
+
}
|
|
7543
|
+
if (value && type == "string") {
|
|
7544
|
+
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
7545
|
+
}
|
|
7310
7546
|
}
|
|
7311
7547
|
break;
|
|
7312
7548
|
case EValueType.RandomColor:
|
|
@@ -7315,6 +7551,7 @@
|
|
|
7315
7551
|
}
|
|
7316
7552
|
value = exports.Color.RandomColor();
|
|
7317
7553
|
value = assertColor(value);
|
|
7554
|
+
traceType = "random";
|
|
7318
7555
|
if (value && type == "string") {
|
|
7319
7556
|
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
7320
7557
|
}
|
|
@@ -7323,12 +7560,14 @@
|
|
|
7323
7560
|
if (type === "number") {
|
|
7324
7561
|
break;
|
|
7325
7562
|
}
|
|
7326
|
-
for (let
|
|
7327
|
-
const tag = tags[
|
|
7563
|
+
for (let ti = 0; ti < tags.length; ti++) {
|
|
7564
|
+
const tag = tags[ti];
|
|
7328
7565
|
if (tag.Color) {
|
|
7329
7566
|
value = exports.Color.ColorFromStr(tag.Color);
|
|
7330
7567
|
value = assertColor(value);
|
|
7331
7568
|
if (value) {
|
|
7569
|
+
traceType = "tag";
|
|
7570
|
+
tracePart1 = encodeEffective(tag.Color);
|
|
7332
7571
|
break;
|
|
7333
7572
|
}
|
|
7334
7573
|
}
|
|
@@ -7342,31 +7581,37 @@
|
|
|
7342
7581
|
// Eg: Result is a colour, a number, a string.
|
|
7343
7582
|
// This means we first calculate the value, then validate it in the context of the desired type.
|
|
7344
7583
|
case EValueType.Input:
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
else if (type == "string") {
|
|
7356
|
-
if (typeof value == "number") {
|
|
7357
|
-
value = String(value);
|
|
7358
|
-
}
|
|
7359
|
-
else if (typeof value == "object") {
|
|
7360
|
-
if (isColor(value)) {
|
|
7361
|
-
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
7584
|
+
{
|
|
7585
|
+
const inputTemplate = String(field.value);
|
|
7586
|
+
value = GetInputValue(field.value, data);
|
|
7587
|
+
if (value != null) {
|
|
7588
|
+
traceType = "input";
|
|
7589
|
+
tracePart1 = encodeEffective(inputTemplate);
|
|
7590
|
+
tracePart2 = encodeEffective(String(value));
|
|
7591
|
+
if (type == "number") {
|
|
7592
|
+
if (typeof value == "string" && value != "" && value != null && value != undefined) {
|
|
7593
|
+
value = Number(value);
|
|
7362
7594
|
}
|
|
7363
|
-
else {
|
|
7595
|
+
else if (typeof value != "number") {
|
|
7364
7596
|
value = null;
|
|
7365
7597
|
}
|
|
7366
7598
|
}
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7599
|
+
else if (type == "string") {
|
|
7600
|
+
if (typeof value == "number") {
|
|
7601
|
+
value = String(value);
|
|
7602
|
+
}
|
|
7603
|
+
else if (typeof value == "object") {
|
|
7604
|
+
if (isColor(value)) {
|
|
7605
|
+
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
7606
|
+
}
|
|
7607
|
+
else {
|
|
7608
|
+
value = null;
|
|
7609
|
+
}
|
|
7610
|
+
}
|
|
7611
|
+
}
|
|
7612
|
+
else if (type == "color") {
|
|
7613
|
+
value = assertColor(value);
|
|
7614
|
+
}
|
|
7370
7615
|
}
|
|
7371
7616
|
}
|
|
7372
7617
|
break;
|
|
@@ -7374,31 +7619,39 @@
|
|
|
7374
7619
|
// Eg: mapping a value to a Client File ID, or a colour, or a number.
|
|
7375
7620
|
// This means we first calculate the value, then validate it in the context of the desired type.
|
|
7376
7621
|
case EValueType.Mapping:
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
}
|
|
7386
|
-
}
|
|
7387
|
-
else if (type == "string") {
|
|
7388
|
-
if (typeof value == "number") {
|
|
7389
|
-
value = String(value);
|
|
7622
|
+
{
|
|
7623
|
+
const mapTrace = _getMappingTrace(field.value, data);
|
|
7624
|
+
value = mapTrace.result;
|
|
7625
|
+
if (value != null) {
|
|
7626
|
+
traceType = "mapping";
|
|
7627
|
+
if (mapTrace.attrPath != null) {
|
|
7628
|
+
tracePart1 = encodeEffective(exports.PathUtils.Wrap(mapTrace.attrPath));
|
|
7629
|
+
tracePart2 = encodeEffective(String(mapTrace.eValue));
|
|
7390
7630
|
}
|
|
7391
|
-
|
|
7392
|
-
if (
|
|
7393
|
-
value =
|
|
7631
|
+
if (type == "number") {
|
|
7632
|
+
if (typeof value == "string" && value != "" && value != null && value != undefined) {
|
|
7633
|
+
value = Number(value);
|
|
7394
7634
|
}
|
|
7395
|
-
else {
|
|
7635
|
+
else if (typeof value != "number") {
|
|
7396
7636
|
value = null;
|
|
7397
7637
|
}
|
|
7398
7638
|
}
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7639
|
+
else if (type == "string") {
|
|
7640
|
+
if (typeof value == "number") {
|
|
7641
|
+
value = String(value);
|
|
7642
|
+
}
|
|
7643
|
+
else if (typeof value == "object") {
|
|
7644
|
+
if (isColor(value)) {
|
|
7645
|
+
value = `rgba(${value.red},${value.green},${value.blue},${value.alpha})`;
|
|
7646
|
+
}
|
|
7647
|
+
else {
|
|
7648
|
+
value = null;
|
|
7649
|
+
}
|
|
7650
|
+
}
|
|
7651
|
+
}
|
|
7652
|
+
else if (type == "color") {
|
|
7653
|
+
value = assertColor(typeof value === "number" ? String(value) : value);
|
|
7654
|
+
}
|
|
7402
7655
|
}
|
|
7403
7656
|
}
|
|
7404
7657
|
break;
|
|
@@ -7422,11 +7675,34 @@
|
|
|
7422
7675
|
}
|
|
7423
7676
|
}
|
|
7424
7677
|
if (value != null) {
|
|
7678
|
+
if (traceType != null) {
|
|
7679
|
+
if (tracePart1 != null && tracePart2 != null) {
|
|
7680
|
+
computedEffective = `f${i}:${traceType}:${tracePart1}:${tracePart2}`;
|
|
7681
|
+
}
|
|
7682
|
+
else if (tracePart1 != null) {
|
|
7683
|
+
computedEffective = `f${i}:${traceType}:${tracePart1}`;
|
|
7684
|
+
}
|
|
7685
|
+
else {
|
|
7686
|
+
computedEffective = `f${i}:${traceType}`;
|
|
7687
|
+
}
|
|
7688
|
+
}
|
|
7425
7689
|
break;
|
|
7426
7690
|
}
|
|
7427
7691
|
}
|
|
7428
|
-
|
|
7429
|
-
|
|
7692
|
+
return {
|
|
7693
|
+
value: value != null ? value : defaultValue,
|
|
7694
|
+
effective: value != null ? computedEffective : null
|
|
7695
|
+
};
|
|
7696
|
+
}
|
|
7697
|
+
Calculator.TraceCalculate = TraceCalculate;
|
|
7698
|
+
/**
|
|
7699
|
+
* Calculates a value-type 'T' based on given set of fields.
|
|
7700
|
+
* The supplied data + tags are fed into the calculation.
|
|
7701
|
+
* When a value fails to be calculated, the 'defaultValue' is returned.
|
|
7702
|
+
* If no 'defaultValue' is provided, then 'null' is returned.
|
|
7703
|
+
*/
|
|
7704
|
+
function Calculate(params) {
|
|
7705
|
+
return TraceCalculate(params).value;
|
|
7430
7706
|
}
|
|
7431
7707
|
Calculator.Calculate = Calculate;
|
|
7432
7708
|
/**
|
|
@@ -7438,13 +7714,7 @@
|
|
|
7438
7714
|
* @returns
|
|
7439
7715
|
*/
|
|
7440
7716
|
function GetValue(fields, entity = {}, tags = []) {
|
|
7441
|
-
return
|
|
7442
|
-
fields: fields,
|
|
7443
|
-
data: entity,
|
|
7444
|
-
defaultValue: null,
|
|
7445
|
-
tags: tags,
|
|
7446
|
-
type: "any"
|
|
7447
|
-
});
|
|
7717
|
+
return TraceGetValue(fields, entity, tags).value;
|
|
7448
7718
|
}
|
|
7449
7719
|
Calculator.GetValue = GetValue;
|
|
7450
7720
|
/**
|
|
@@ -7455,13 +7725,7 @@
|
|
|
7455
7725
|
* @param tags
|
|
7456
7726
|
*/
|
|
7457
7727
|
function GetColor(fields, entity = {}, tags = []) {
|
|
7458
|
-
return
|
|
7459
|
-
fields: fields,
|
|
7460
|
-
data: entity,
|
|
7461
|
-
defaultValue: null,
|
|
7462
|
-
tags: tags,
|
|
7463
|
-
type: "color"
|
|
7464
|
-
});
|
|
7728
|
+
return TraceGetColor(fields, entity, tags).value;
|
|
7465
7729
|
}
|
|
7466
7730
|
Calculator.GetColor = GetColor;
|
|
7467
7731
|
/**
|
|
@@ -7473,13 +7737,7 @@
|
|
|
7473
7737
|
* @returns
|
|
7474
7738
|
*/
|
|
7475
7739
|
function GetNumber(fields, entity = {}, tags = []) {
|
|
7476
|
-
return
|
|
7477
|
-
fields: fields,
|
|
7478
|
-
data: entity,
|
|
7479
|
-
defaultValue: null,
|
|
7480
|
-
tags: tags,
|
|
7481
|
-
type: "number"
|
|
7482
|
-
});
|
|
7740
|
+
return TraceGetNumber(fields, entity, tags).value;
|
|
7483
7741
|
}
|
|
7484
7742
|
Calculator.GetNumber = GetNumber;
|
|
7485
7743
|
/**
|
|
@@ -7491,15 +7749,61 @@
|
|
|
7491
7749
|
* @returns
|
|
7492
7750
|
*/
|
|
7493
7751
|
function GetString(fields, entity = {}, tags = []) {
|
|
7494
|
-
return
|
|
7495
|
-
|
|
7752
|
+
return TraceGetString(fields, entity, tags).value;
|
|
7753
|
+
}
|
|
7754
|
+
Calculator.GetString = GetString;
|
|
7755
|
+
/**
|
|
7756
|
+
* Like GetValue, but also returns 'effective' describing how the value was derived.
|
|
7757
|
+
*/
|
|
7758
|
+
function TraceGetValue(fields, entity = {}, tags = []) {
|
|
7759
|
+
return TraceCalculate({
|
|
7760
|
+
fields,
|
|
7496
7761
|
data: entity,
|
|
7497
7762
|
defaultValue: null,
|
|
7498
|
-
tags
|
|
7763
|
+
tags,
|
|
7764
|
+
type: "any"
|
|
7765
|
+
});
|
|
7766
|
+
}
|
|
7767
|
+
Calculator.TraceGetValue = TraceGetValue;
|
|
7768
|
+
/**
|
|
7769
|
+
* Like GetColor, but also returns 'effective' describing how the color was derived.
|
|
7770
|
+
*/
|
|
7771
|
+
function TraceGetColor(fields, entity = {}, tags = []) {
|
|
7772
|
+
return TraceCalculate({
|
|
7773
|
+
fields,
|
|
7774
|
+
data: entity,
|
|
7775
|
+
defaultValue: null,
|
|
7776
|
+
tags,
|
|
7777
|
+
type: "color"
|
|
7778
|
+
});
|
|
7779
|
+
}
|
|
7780
|
+
Calculator.TraceGetColor = TraceGetColor;
|
|
7781
|
+
/**
|
|
7782
|
+
* Like GetNumber, but also returns 'effective' describing how the number was derived.
|
|
7783
|
+
*/
|
|
7784
|
+
function TraceGetNumber(fields, entity = {}, tags = []) {
|
|
7785
|
+
return TraceCalculate({
|
|
7786
|
+
fields,
|
|
7787
|
+
data: entity,
|
|
7788
|
+
defaultValue: null,
|
|
7789
|
+
tags,
|
|
7790
|
+
type: "number"
|
|
7791
|
+
});
|
|
7792
|
+
}
|
|
7793
|
+
Calculator.TraceGetNumber = TraceGetNumber;
|
|
7794
|
+
/**
|
|
7795
|
+
* Like GetString, but also returns 'effective' describing how the string was derived.
|
|
7796
|
+
*/
|
|
7797
|
+
function TraceGetString(fields, entity = {}, tags = []) {
|
|
7798
|
+
return TraceCalculate({
|
|
7799
|
+
fields,
|
|
7800
|
+
data: entity,
|
|
7801
|
+
defaultValue: null,
|
|
7802
|
+
tags,
|
|
7499
7803
|
type: "string"
|
|
7500
7804
|
});
|
|
7501
7805
|
}
|
|
7502
|
-
Calculator.
|
|
7806
|
+
Calculator.TraceGetString = TraceGetString;
|
|
7503
7807
|
/**
|
|
7504
7808
|
* Calculates a mapping value. This can return any value type.
|
|
7505
7809
|
* It is intended to be parsed and validated within a value-type context. Eg: GetColor, GetNumber, GetString.
|
|
@@ -7508,114 +7812,7 @@
|
|
|
7508
7812
|
* @returns
|
|
7509
7813
|
*/
|
|
7510
7814
|
function GetMappingValue(value, entity) {
|
|
7511
|
-
|
|
7512
|
-
for (let i = 0; i < attrPaths.length; i++) {
|
|
7513
|
-
const attrPath = attrPaths[i];
|
|
7514
|
-
let eValue = exports.Entity.GetValue({
|
|
7515
|
-
entity: entity,
|
|
7516
|
-
path: attrPath
|
|
7517
|
-
});
|
|
7518
|
-
let isValueNum = !isNaN(+eValue);
|
|
7519
|
-
if (eValue == null) {
|
|
7520
|
-
isValueNum = false;
|
|
7521
|
-
}
|
|
7522
|
-
for (let i = 0; i < value.values.length; i++) {
|
|
7523
|
-
const option = value.values[i];
|
|
7524
|
-
const fieldValues = Array.isArray(option.fieldValue) ? option.fieldValue : [option.fieldValue];
|
|
7525
|
-
// Check each field value in the array.
|
|
7526
|
-
for (let j = 0; j < fieldValues.length; j++) {
|
|
7527
|
-
let mapValue = fieldValues[j];
|
|
7528
|
-
// If mapValue is prefixed with "JS:", we evaluate it as JavaScript.
|
|
7529
|
-
// This lets us do things like JS:Boolean("${}") as a quick way to map 'existence' to a target value.
|
|
7530
|
-
if (typeof mapValue === "string" && mapValue.startsWith("JS:")) {
|
|
7531
|
-
try {
|
|
7532
|
-
let jsEval = mapValue.replace("JS:", "").trim();
|
|
7533
|
-
const attrPathStr = exports.PathUtils.Wrap(attrPath);
|
|
7534
|
-
jsEval = jsEval.replace("${}", "${" + attrPathStr + "}");
|
|
7535
|
-
jsEval = exports.BruceVariable.SwapValues({
|
|
7536
|
-
str: jsEval,
|
|
7537
|
-
entity: entity
|
|
7538
|
-
});
|
|
7539
|
-
// https://rollupjs.org/guide/en/#avoiding-eval
|
|
7540
|
-
// This stops eval warning.
|
|
7541
|
-
const eval2 = eval;
|
|
7542
|
-
mapValue = eval2(jsEval);
|
|
7543
|
-
// We currently expect eval to return a validity bool.
|
|
7544
|
-
// So it either matches and we return it, or it doesn't and we continue.
|
|
7545
|
-
if (mapValue) {
|
|
7546
|
-
return option.appliedValue;
|
|
7547
|
-
}
|
|
7548
|
-
else {
|
|
7549
|
-
continue;
|
|
7550
|
-
}
|
|
7551
|
-
}
|
|
7552
|
-
catch (exception) {
|
|
7553
|
-
const e = exception;
|
|
7554
|
-
let suppress = false;
|
|
7555
|
-
if (e && typeof e == "object") {
|
|
7556
|
-
const msg = e.message;
|
|
7557
|
-
suppress = !!msg && (msg.includes("Unexpected end") || msg.includes("got end of script"));
|
|
7558
|
-
}
|
|
7559
|
-
if (!suppress) {
|
|
7560
|
-
console.error(e);
|
|
7561
|
-
}
|
|
7562
|
-
// Eval failed, therefor not a valid mapping-row.
|
|
7563
|
-
continue;
|
|
7564
|
-
}
|
|
7565
|
-
}
|
|
7566
|
-
let isMapValueNum = !isNaN(+mapValue);
|
|
7567
|
-
if (isMapValueNum == null) {
|
|
7568
|
-
isMapValueNum = false;
|
|
7569
|
-
}
|
|
7570
|
-
if (isValueNum && (isMapValueNum || (typeof mapValue === "string" && mapValue.includes("-")))) {
|
|
7571
|
-
if (+mapValue == +eValue) {
|
|
7572
|
-
return option.appliedValue;
|
|
7573
|
-
}
|
|
7574
|
-
const mapSplit = mapValue.split("-");
|
|
7575
|
-
if (mapSplit.length == 2) {
|
|
7576
|
-
const min = mapSplit[0];
|
|
7577
|
-
const max = mapSplit[1];
|
|
7578
|
-
if (min != "") {
|
|
7579
|
-
if (+eValue < +min) {
|
|
7580
|
-
continue;
|
|
7581
|
-
}
|
|
7582
|
-
}
|
|
7583
|
-
if (max != "") {
|
|
7584
|
-
if (+eValue > +max) {
|
|
7585
|
-
continue;
|
|
7586
|
-
}
|
|
7587
|
-
}
|
|
7588
|
-
if (min == "" && max == "") {
|
|
7589
|
-
continue;
|
|
7590
|
-
}
|
|
7591
|
-
return option.appliedValue;
|
|
7592
|
-
}
|
|
7593
|
-
}
|
|
7594
|
-
else {
|
|
7595
|
-
if (mapValue == eValue) {
|
|
7596
|
-
return option.appliedValue;
|
|
7597
|
-
}
|
|
7598
|
-
// Case where Entity value is a boolean but the mapping value is a string.
|
|
7599
|
-
// Common as mapping value is typically a user-entered string.
|
|
7600
|
-
else if (typeof eValue === "boolean" && typeof mapValue === "string") {
|
|
7601
|
-
const eValueStr = eValue ? "true" : "false";
|
|
7602
|
-
if (mapValue.toLowerCase() == eValueStr) {
|
|
7603
|
-
return option.appliedValue;
|
|
7604
|
-
}
|
|
7605
|
-
}
|
|
7606
|
-
// Handling possible case where the opposite is true.
|
|
7607
|
-
// Have not seen this happen yet, but preparing for any future cases.
|
|
7608
|
-
else if (typeof mapValue === "boolean" && typeof eValue === "string") {
|
|
7609
|
-
const mapValueStr = mapValue ? "true" : "false";
|
|
7610
|
-
if (mapValueStr == eValue.toLowerCase()) {
|
|
7611
|
-
return option.appliedValue;
|
|
7612
|
-
}
|
|
7613
|
-
}
|
|
7614
|
-
}
|
|
7615
|
-
}
|
|
7616
|
-
}
|
|
7617
|
-
}
|
|
7618
|
-
return null;
|
|
7815
|
+
return _getMappingTrace(value, entity).result;
|
|
7619
7816
|
}
|
|
7620
7817
|
Calculator.GetMappingValue = GetMappingValue;
|
|
7621
7818
|
/**
|
|
@@ -7628,47 +7825,7 @@
|
|
|
7628
7825
|
* @returns
|
|
7629
7826
|
*/
|
|
7630
7827
|
function GetGradientValue(value, entity, defaultToMin) {
|
|
7631
|
-
|
|
7632
|
-
const max = +value.points[value.points.length - 1].position;
|
|
7633
|
-
const attrPaths = parseLegacyPath(value.field);
|
|
7634
|
-
for (let i = 0; i < attrPaths.length; i++) {
|
|
7635
|
-
const attrPath = attrPaths[i];
|
|
7636
|
-
let eValue = exports.Entity.GetValue({
|
|
7637
|
-
entity: entity,
|
|
7638
|
-
path: attrPath
|
|
7639
|
-
});
|
|
7640
|
-
if (typeof eValue == "string") {
|
|
7641
|
-
eValue = Number(eValue);
|
|
7642
|
-
}
|
|
7643
|
-
if ((!eValue && eValue != 0) || isNaN(eValue)) {
|
|
7644
|
-
continue;
|
|
7645
|
-
}
|
|
7646
|
-
if (eValue >= max) {
|
|
7647
|
-
return exports.Color.ColorFromStr(value.points[value.points.length - 1].color);
|
|
7648
|
-
}
|
|
7649
|
-
else if (eValue <= min) {
|
|
7650
|
-
return exports.Color.ColorFromStr(value.points[0].color);
|
|
7651
|
-
}
|
|
7652
|
-
for (let i = 0; i < value.points.length - 1; i++) {
|
|
7653
|
-
const pointA = value.points[i];
|
|
7654
|
-
const pointB = value.points[i + 1];
|
|
7655
|
-
if (eValue >= pointA.position && eValue <= pointB.position) {
|
|
7656
|
-
if (pointA.position == pointB.position) {
|
|
7657
|
-
return exports.Color.ColorFromStr(pointA.color);
|
|
7658
|
-
}
|
|
7659
|
-
const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
|
|
7660
|
-
const colorA = exports.Color.ColorFromStr(pointA.color);
|
|
7661
|
-
const colorB = exports.Color.ColorFromStr(pointB.color);
|
|
7662
|
-
return {
|
|
7663
|
-
red: colorA.red + (colorB.red - colorA.red) * distance,
|
|
7664
|
-
green: colorA.green + (colorB.green - colorA.green) * distance,
|
|
7665
|
-
blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
|
|
7666
|
-
alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
|
|
7667
|
-
};
|
|
7668
|
-
}
|
|
7669
|
-
}
|
|
7670
|
-
}
|
|
7671
|
-
return exports.Color.ColorFromStr(value.points[0].color);
|
|
7828
|
+
return _getGradientTrace(value, entity, defaultToMin).result;
|
|
7672
7829
|
}
|
|
7673
7830
|
Calculator.GetGradientValue = GetGradientValue;
|
|
7674
7831
|
/**
|
|
@@ -18760,7 +18917,7 @@
|
|
|
18760
18917
|
})(exports.UrlUtils || (exports.UrlUtils = {}));
|
|
18761
18918
|
|
|
18762
18919
|
// This is updated with the package.json version on build.
|
|
18763
|
-
const VERSION = "7.1.
|
|
18920
|
+
const VERSION = "7.1.56";
|
|
18764
18921
|
|
|
18765
18922
|
exports.VERSION = VERSION;
|
|
18766
18923
|
exports.AbstractApi = AbstractApi;
|