class Utility { static clamp(val, min, max) { return Math.min(Math.max(val, min), max) } static getScale(element) { return getComputedStyle(element).getPropertyValue('--ueb-scale') } /** * Sets a value in an object * @param {String[]} keys The chained keys to access from object in order to set the value * @param {any} value Value to be set * @param {Object} target Object holding the data * @param {Boolean} create Whether to create or not the key in case it doesn't exist * @returns {Boolean} Returns true on succes, false otherwise */ static objectSet(target, keys, value, create = false) { if (keys.constructor != Array) { console.error("Expected keys to be an array."); } if (keys.length == 1) { if (create || keys[0] in target) { target[keys[0]] = value; return true } } else if (keys.length > 0) { return Utility.objectSet(target[keys[0]], keys.slice(1), value, create) } return false } /** * Gets a value from an object, gives defaultValue in case of failure * @param {Object} source Object holding the data * @param {String[]} keys The chained keys to access from object in order to get the value * @param {any} defaultValue Value to return in case from doesn't have it * @returns {any} The value in from corresponding to the keys or defaultValue otherwise */ static objectGet(source, keys, defaultValue = null) { if (keys.constructor != Array) { console.error("Expected keys to be an array."); } if (keys.length == 0 || !(keys[0] in source)) { return defaultValue } if (keys.length == 1) { return source[keys[0]] } return Utility.objectGet(source[keys[0]], keys.slice(1), defaultValue) } static sanitize(value) { if (!(value instanceof Object)) { return value } switch (value?.constructor) { case Boolean: return value.valueOf() case Number: return value.valueOf() case String: return value.toString() default: return value } } static equals(a, b) { a = Utility.sanitize(a); b = Utility.sanitize(b); return a === b } /** * * @param {String} value */ static FirstCapital(value) { return value.charAt(0).toUpperCase() + value.substring(1) } static getType(value) { let constructor = value?.constructor; switch (constructor) { case TypeInitialization: return value.type case Function: return value default: return constructor } } } class TypeInitialization { constructor(value, showDefault = true, type = Utility.getType(value)) { this.value = value; this.showDefault = showDefault; this.type = type; } } class Entity { constructor(options = {}) { /** * * @param {String[]} prefix * @param {Object} target * @param {Object} properties */ const defineAllAttributes = (prefix, target, properties, propertySetter = (t, p, v) => t[p] = v) => { let fullKey = prefix.concat(""); const last = fullKey.length - 1; for (let property in properties) { fullKey[last] = property; // Not instanceof because all objects are instenceof Object if (properties[property]?.constructor === Object) { propertySetter(target, property, {}); defineAllAttributes(fullKey, target[property], properties[property]); continue } /* * The value can either be: * - Array: can contain multiple values, its property is assigned multiple times like (X=1, X=4, X="Hello World") * - TypeInitialization: contains the maximum amount of information about the attribute. * - A type: the default value will be default constructed object without arguments. * - A proper value. */ const value = Utility.objectGet(options, fullKey); if (value !== null) { propertySetter(target, property, value); continue } let defaultValue = properties[property]; if (defaultValue instanceof TypeInitialization) { if (!defaultValue.showDefault) { continue } defaultValue = defaultValue.value; } if (defaultValue instanceof Array) { propertySetter(target, property, []); defineAllAttributes( fullKey, target[property], defaultValue, (t, _, v) => t.push(v)); continue } if (defaultValue instanceof Function) { defaultValue = Utility.sanitize(new defaultValue()); } propertySetter(target, property, defaultValue); } }; defineAllAttributes([], this, this.getAttributes()); } } class GuidEntity extends Entity { static attributes = { value: String } static generateGuid(random) { let values = new Uint32Array(4); if (random === true) { crypto.getRandomValues(values); } let result = ""; values.forEach(n => { result += ('00000000' + n.toString(16).toUpperCase()).slice(-8); }); return result } constructor(guid) { if (guid?.constructor === String) { guid = { value: guid }; } else if (guid?.constructor === Boolean) { guid = { value: GuidEntity.generateGuid(guid == true) }; } super(guid); } getAttributes() { return GuidEntity.attributes } } class LocalizedTextEntity extends Entity { static attributes = { namespace: "", key: "", value: "" } getAttributes() { return LocalizedTextEntity.attributes } } class ObjectReferenceEntity extends Entity { static attributes = { type: "", path: "" } getAttributes() { return ObjectReferenceEntity.attributes } toString() { return (this.type ?? "") + ( this.path ? this.type ? `'"${this.path}"'` : this.path : "" ) } } class PinReferenceEntity extends Entity { static attributes = { objectName: String, pinGuid: GuidEntity } getAttributes() { return PinReferenceEntity.attributes } } class PinEntity$1 extends Entity { static attributes = { PinId: GuidEntity, PinName: "", PinFriendlyName: new TypeInitialization(new LocalizedTextEntity(), false), PinToolTip: "", Direction: new TypeInitialization("", false), PinType: { PinCategory: "", PinSubCategory: "", PinSubCategoryObject: ObjectReferenceEntity, PinSubCategoryMemberReference: null, PinValueType: null, ContainerType: ObjectReferenceEntity, bIsReference: false, bIsConst: false, bIsWeakPointer: false, bIsUObjectWrapper: false }, LinkedTo: [new TypeInitialization(null, false, PinReferenceEntity)], DefaultValue: "", AutogeneratedDefaultValue: "", PersistentGuid: GuidEntity, bHidden: false, bNotConnectable: false, bDefaultValueIsReadOnly: false, bDefaultValueIsIgnored: false, bAdvancedView: false, bOrphanedPin: false, } getAttributes() { return PinEntity$1.attributes } isOutput() { if (this.Direction === "EGPD_Output") { return true } } } class FunctionReferenceEntity extends Entity { static attributes = { MemberParent: ObjectReferenceEntity, MemberName: "" } getAttributes() { return FunctionReferenceEntity.attributes } } class Integer extends Entity { static attributes = { value: 0 } constructor(value) { if (value?.constructor === String) { value = Number(value); } if (value?.constructor === Number) { value = { value: Math.round(value.valueOf()) }; } super(value); } getAttributes() { return Integer.attributes } } var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var parsimmon_umd_min = {exports: {}}; (function (module, exports) { !function(n,t){module.exports=t();}("undefined"!=typeof self?self:commonjsGlobal,function(){return function(n){var t={};function r(e){if(t[e])return t[e].exports;var u=t[e]={i:e,l:!1,exports:{}};return n[e].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:e});},r.r=function(n){Object.defineProperty(n,"__esModule",{value:!0});},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=0)}([function(n,t,r){function e(n){if(!(this instanceof e))return new e(n);this._=n;}var u=e.prototype;function o(n,t){for(var r=0;r>7),buf:function(n){var t=i(function(n,t,r,e){return n.concat(r===e.length-1?Buffer.from([t,0]).readUInt16BE(0):e.readUInt16BE(r))},[],n);return Buffer.from(f(function(n){return (n<<1&65535)>>8},t))}(r.buf)};}),r}function c(){return "undefined"!=typeof Buffer}function s(){if(!c())throw new Error("Buffer global does not exist; please use webpack if you need to parse Buffers in the browser.")}function l(n){s();var t=i(function(n,t){return n+t},0,n);if(t%8!=0)throw new Error("The bits ["+n.join(", ")+"] add up to "+t+" which is not an even number of bytes; the total should be divisible by 8");var r,u=t/8,o=(r=function(n){return n>48},i(function(n,t){return n||(r(t)?t:n)},null,n));if(o)throw new Error(o+" bit range requested exceeds 48 bit (6 byte) Number max.");return new e(function(t,r){var e=u+r;return e>t.length?x(r,u.toString()+" bytes"):b(e,i(function(n,t){var r=a(t,n.buf);return {coll:n.coll.concat(r.v),buf:r.buf}},{coll:[],buf:t.slice(r,e)},n).coll)})}function p(n,t){return new e(function(r,e){return s(),e+t>r.length?x(e,t+" bytes for "+n):b(e+t,r.slice(e,e+t))})}function h(n,t){if("number"!=typeof(r=t)||Math.floor(r)!==r||t<0||t>6)throw new Error(n+" requires integer length in range [0, 6].");var r;}function d(n){return h("uintBE",n),p("uintBE("+n+")",n).map(function(t){return t.readUIntBE(0,n)})}function v(n){return h("uintLE",n),p("uintLE("+n+")",n).map(function(t){return t.readUIntLE(0,n)})}function g(n){return h("intBE",n),p("intBE("+n+")",n).map(function(t){return t.readIntBE(0,n)})}function m(n){return h("intLE",n),p("intLE("+n+")",n).map(function(t){return t.readIntLE(0,n)})}function y(n){return n instanceof e}function E(n){return "[object Array]"==={}.toString.call(n)}function w(n){return c()&&Buffer.isBuffer(n)}function b(n,t){return {status:!0,index:n,value:t,furthest:-1,expected:[]}}function x(n,t){return E(t)||(t=[t]),{status:!1,index:-1,value:null,furthest:n,expected:t}}function B(n,t){if(!t)return n;if(n.furthest>t.furthest)return n;var r=n.furthest===t.furthest?function(n,t){if(function(){if(void 0!==e._supportsSet)return e._supportsSet;var n="undefined"!=typeof Set;return e._supportsSet=n,n}()&&Array.from){for(var r=new Set(n),u=0;u=0;){if(i in r){e=r[i].line,0===o&&(o=r[i].lineStart);break}"\n"===n.charAt(i)&&(u++,0===o&&(o=i+1)),i--;}var f=e+u,a=t-o;return r[t]={line:f,lineStart:o},{offset:t,line:f+1,column:a+1}}function _(n){if(!y(n))throw new Error("not a parser: "+n)}function L(n,t){return "string"==typeof n?n.charAt(t):n[t]}function O(n){if("number"!=typeof n)throw new Error("not a number: "+n)}function k(n){if("function"!=typeof n)throw new Error("not a function: "+n)}function P(n){if("string"!=typeof n)throw new Error("not a string: "+n)}var q=2,A=3,I=8,F=5*I,M=4*I,z=" ";function R(n,t){return new Array(t+1).join(n)}function U(n,t,r){var e=t-n.length;return e<=0?n:R(r,e)+n}function W(n,t,r,e){return {from:n-t>0?n-t:0,to:n+r>e?e:n+r}}function D(n,t){var r,e,u,o,a,c=t.index,s=c.offset,l=1;if(s===n.length)return "Got the end of the input";if(w(n)){var p=s-s%I,h=s-p,d=W(p,F,M+I,n.length),v=f(function(n){return f(function(n){return U(n.toString(16),2,"0")},n)},function(n,t){var r=n.length,e=[],u=0;if(r<=t)return [n.slice()];for(var o=0;o=4&&(r+=1),l=2,u=f(function(n){return n.length<=4?n.join(" "):n.slice(0,4).join(" ")+" "+n.slice(4).join(" ")},v),(a=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(a=2);}else {var g=n.split(/\r\n|[\n\r\u2028\u2029]/);r=c.column-1,e=c.line-1,o=W(e,q,A,g.length),u=g.slice(o.from,o.to),a=o.to.toString().length;}var m=e-o.from;return w(n)&&(a=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(a=2),i(function(t,e,u){var i,f=u===m,c=f?"> ":z;return i=w(n)?U((8*(o.from+u)).toString(16),a,"0"):U((o.from+u+1).toString(),a," "),[].concat(t,[c+i+" | "+e],f?[z+R(" ",a)+" | "+U("",r," ")+R("^",l)]:[])},[],u).join("\n")}function N(n,t){return ["\n","-- PARSING FAILED "+R("-",50),"\n\n",D(n,t),"\n\n",(r=t.expected,1===r.length?"Expected:\n\n"+r[0]:"Expected one of the following: \n\n"+r.join(", ")),"\n"].join("");var r;}function G(n){return void 0!==n.flags?n.flags:[n.global?"g":"",n.ignoreCase?"i":"",n.multiline?"m":"",n.unicode?"u":"",n.sticky?"y":""].join("")}function C(){for(var n=[].slice.call(arguments),t=n.length,r=0;r=2?O(t):t=0;var r=function(n){return RegExp("^(?:"+n.source+")",G(n))}(n),u=""+n;return e(function(n,e){var o=r.exec(n.slice(e));if(o){if(0<=t&&t<=o.length){var i=o[0],f=o[t];return b(e+i.length,f)}return x(e,"valid match group (0 to "+o.length+") in "+u)}return x(e,u)})}function X(n){return e(function(t,r){return b(r,n)})}function Y(n){return e(function(t,r){return x(r,n)})}function Z(n){if(y(n))return e(function(t,r){var e=n._(t,r);return e.index=r,e.value="",e});if("string"==typeof n)return Z(K(n));if(n instanceof RegExp)return Z(Q(n));throw new Error("not a string, regexp, or parser: "+n)}function $(n){return _(n),e(function(t,r){var e=n._(t,r),u=t.slice(r,e.index);return e.status?x(r,'not "'+u+'"'):b(r,null)})}function nn(n){return k(n),e(function(t,r){var e=L(t,r);return r=n.length?x(t,"any character/byte"):b(t+1,L(n,t))}),on=e(function(n,t){return b(n.length,n.slice(t))}),fn=e(function(n,t){return t=0}).desc(t)},e.optWhitespace=pn,e.Parser=e,e.range=function(n,t){return nn(function(r){return n<=r&&r<=t}).desc(n+"-"+t)},e.regex=Q,e.regexp=Q,e.sepBy=V,e.sepBy1=H,e.seq=C,e.seqMap=J,e.seqObj=function(){for(var n,t={},r=0,u=(n=arguments,Array.prototype.slice.call(n)),o=u.length,i=0;i255)throw new Error("Value specified to byte constructor ("+n+"=0x"+n.toString(16)+") is larger in value than a single byte.");var t=(n>15?"0x":"0x0")+n.toString(16);return e(function(r,e){var u=L(r,e);return u===n?b(e+1,u):x(e,t)})},buffer:function(n){return p("buffer",n).map(function(n){return Buffer.from(n)})},encodedString:function(n,t){return p("string",t).map(function(t){return t.toString(n)})},uintBE:d,uint8BE:d(1),uint16BE:d(2),uint32BE:d(4),uintLE:v,uint8LE:v(1),uint16LE:v(2),uint32LE:v(4),intBE:g,int8BE:g(1),int16BE:g(2),int32BE:g(4),intLE:m,int8LE:m(1),int16LE:m(2),int32LE:m(4),floatBE:p("floatBE",4).map(function(n){return n.readFloatBE(0)}),floatLE:p("floatLE",4).map(function(n){return n.readFloatLE(0)}),doubleBE:p("doubleBE",8).map(function(n){return n.readDoubleBE(0)}),doubleLE:p("doubleLE",8).map(function(n){return n.readDoubleLE(0)})},n.exports=e;}])}); }(parsimmon_umd_min)); var Parsimmon = /*@__PURE__*/getDefaultExportFromCjs(parsimmon_umd_min.exports); class VariableReferenceEntity extends Entity { static attributes = { MemberName: String, MemberGuid: GuidEntity, bSelfContext: true } getAttributes() { return VariableReferenceEntity.attributes } } class ObjectEntity extends Entity { static attributes = { Class: ObjectReferenceEntity, Name: "", bIsPureFunc: new TypeInitialization(false, false), VariableReference: new TypeInitialization(new VariableReferenceEntity(), false), FunctionReference: new TypeInitialization(new FunctionReferenceEntity(), false), TargetType: new TypeInitialization(new ObjectReferenceEntity(), false), NodePosX: Integer, NodePosY: Integer, NodeGuid: GuidEntity, CustomProperties: [PinEntity$1] } getAttributes() { return ObjectEntity.attributes } } let P = Parsimmon; class Grammar { // General InlineWhitespace = _ => P.regex(/[^\S\n]+/).desc("inline whitespace") InlineOptWhitespace = _ => P.regex(/[^\S\n]*/).desc("inline optional whitespace") WhitespaceNewline = _ => P.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline") Null = r => P.seq(P.string("("), r.InlineOptWhitespace, P.string(")")).map(_ => null).desc("null: ()") None = _ => P.string("None").map(_ => new ObjectReferenceEntity({ type: "None" })).desc("none") Boolean = _ => P.alt(P.string("True"), P.string("False")).map(v => v === "True" ? true : false).desc("either True or False") Number = _ => P.regex(/[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number") Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer") String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")') Word = _ => P.regex(/[a-zA-Z]+/).desc("a word") Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value") PathSymbol = _ => P.regex(/[0-9a-zA-Z_]+/) ReferencePath = _ => P.seq(P.string("/"), r.PathSymbol.sepBy1(P.string(".")).tieWith(".")) .tie() .atLeast(2) .tie() .desc('a path (words with possibly underscore, separated by ".", separated by "/")') Reference = r => P.alt( r.None, r.ReferencePath.map(path => new ObjectReferenceEntity({ path: path })), P.seqMap( r.Word, P.optWhitespace, P.alt(P.string(`"`), P.string(`'"`)).chain( result => r.ReferencePath.skip( P.string(result.split("").reverse().join("")) ) ), (referenceType, _, referencePath) => new ObjectReferenceEntity({ type: referenceType, path: referencePath }) ) ) AttributeName = r => r.Word.sepBy1(P.string(".")).tieWith(".").desc('words separated by ""') AttributeAnyValue = r => P.alt(r.Null, r.None, r.Boolean, r.Number, r.Integer, r.String, r.Guid, r.Reference, r.LocalizedText) LocalizedText = r => P.seqMap( P.string("NSLOCTEXT").skip(P.optWhitespace).skip(P.string("(")), r.String.trim(P.optWhitespace), // namespace P.string(","), r.String.trim(P.optWhitespace), // key P.string(","), r.String.trim(P.optWhitespace), // value P.string(")"), (_, namespace, __, key, ___, value, ____) => new LocalizedTextEntity({ namespace: namespace, key: key, value: value }) ) PinReference = r => P.seqMap( r.PathSymbol, P.whitespace, r.Guid, (objectName, _, pinGuid) => new PinReferenceEntity({ objectName: objectName, pinGuid: pinGuid }) ) static getGrammarForType(r, attributeType, defaultGrammar) { switch (Utility.getType(attributeType)) { case Boolean: return r.Boolean case Number: return r.Number case Integer: return r.Integer case String: return r.String case GuidEntity: return r.Guid case ObjectReferenceEntity: return r.Reference case LocalizedTextEntity: return r.LocalizedText case PinReferenceEntity: return r.PinReference case FunctionReferenceEntity: return r.FunctionReference case PinEntity$1: return r.Pin case Array: return P.seqMap( P.string("("), attributeType .map(v => Grammar.getGrammarForType(r, Utility.getType(v))) .reduce((accum, cur) => !cur || accum === r.AttributeAnyValue ? r.AttributeAnyValue : accum.or(cur) ) .trim(P.optWhitespace) .sepBy(P.string(",")) .skip(P.regex(/,?\s*/)), P.string(")"), (_, grammar, __) => grammar ) default: return defaultGrammar } } // Meta grammar static CreateAttributeGrammar = (r, attributeGrammar, attributeSupplier, valueSeparator = P.string("=").trim(P.optWhitespace)) => attributeGrammar.skip(valueSeparator) .chain(attributeName => { const attributeKey = attributeName.split("."); const attribute = attributeSupplier(attributeKey); let attributeValueGrammar = Grammar.getGrammarForType(r, attribute, r.AttributeAnyValue); return attributeValueGrammar.map(attributeValue => entity => Utility.objectSet(entity, attributeKey, attributeValue, true) ) // returns attributeSetter: a function called with an object as argument that will set the correct attribute value }) // Meta grammar static CreateMultiAttributeGrammar = (r, keyGrammar, entityType, attributeSupplier) => /** * Basically this creates a parser that looks for a string like 'Key (A=False,B="Something",)' * Then it populates an object of type EntityType with the attribute values found inside the parentheses. */ P.seqMap( P.seq(keyGrammar, P.optWhitespace, P.string("(")), Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeSupplier) .trim(P.optWhitespace) .sepBy(P.string(",")) .skip(P.regex(/,?/).then(P.optWhitespace)), // Optional trailing comma P.string(')'), (_, attributes, __) => { let result = new entityType(); attributes.forEach(attributeSetter => attributeSetter(result)); return result }) FunctionReference = r => Grammar.CreateMultiAttributeGrammar( r, P.succeed(), FunctionReferenceEntity, attributeKey => Utility.objectGet(FunctionReferenceEntity.attributes, attributeKey) ) Pin = r => Grammar.CreateMultiAttributeGrammar( r, P.string("Pin"), PinEntity$1, attributeKey => Utility.objectGet(PinEntity$1.attributes, attributeKey) ) Object = r => P.seqMap( P.seq(P.string("Begin"), P.whitespace, P.string("Object"), P.whitespace), P.alt( Grammar.CreateAttributeGrammar(r, P.string("CustomProperties"), _ => ObjectEntity.attributes.CustomProperties, P.whitespace), Grammar.CreateAttributeGrammar(r, r.AttributeName, attributeKey => Utility.objectGet(ObjectEntity.attributes, attributeKey)) ) .sepBy1(P.whitespace), P.seq(r.WhitespaceNewline, P.string("End"), P.whitespace, P.string("Object")), (_, attributes, __) => { let result = new ObjectEntity(); attributes.forEach(attributeSetter => attributeSetter(result)); return result } ) MultipleObject = r => r.Object.sepBy1(P.whitespace).trim(P.optWhitespace) } class Serializer { static grammar = Parsimmon.createLanguage(new Grammar()) writeValue(value) { if (value === null) { return "()" } switch (value?.constructor) { case Function: return this.writeValue(value()) case Boolean: return Utility.FirstCapital(value.toString()) case ObjectReferenceEntity: case GuidEntity: return value.toString() case String: return `"${value}"` } } /** * * @param {String[]} prefix * @param {Object} object * @param {String} separator * @returns */ subWrite(key, object, separator = "\n", prefix = "") { let result = ""; let fullKey = key.concat(""); const last = fullKey.length - 1; for (const property in object) { fullKey[last] = property; const value = object[property]; if (object[property]?.constructor === Object) { // Recursive call when finding an object result += this.subWrite(fullKey, value, separator, prefix); } else if (this.showProperty(fullKey, value)) { result += prefix + fullKey.join(".") + "=" + this.writeValue(value) + separator; } } return result } getAttributes() { return PinEntity.attributes } showProperty(attributeKey, attributeValue) { const attributes = this.getAttributes(); const attribute = Utility.objectGet(attributes, attributeKey); if (attribute instanceof TypeInitialization) { return !Utility.equals(attribute.value, attributeValue) || attribute.showDefault } return true } /** * * @param {String} value */ read(value) { } /** * Returns a string representing the object (serialization) * @param {*} object * @returns The serialized string */ write(object) { return '' } } class PinSerializer extends Serializer { getAttributes() { return PinEntity$1.attributes } read(value) { const parseResult = Serializer.grammar.Pin.parse(value); if (!parseResult.status) { console.error("Error when trying to parse the pin."); return parseResult } return parseResult.value } write(object) { let result = `Pin (${this.subWrite([], object, ",")})`; return result } } export { PinSerializer };