UNPKG

tableau-react

Version:

React component for rendering tableau reports using tableau javascript API.

1,514 lines (1,255 loc) 444 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var tableauSoftware = {}; /*! tableau-2.9.1 */ /*! BEGIN MscorlibSlim */ //////////////////////////////////////////////////////////////////////////////// // Globals and assembly registration //////////////////////////////////////////////////////////////////////////////// var global = {}; (function (global) { 'use strict'; var ss = { __assemblies: {} }; ss.initAssembly = function (obj, name, res) { res = res || {}; obj.name = name; obj.toString = function () { return this.name; }; obj.__types = {}; obj.getResourceNames = function () { return Object.keys(res); }; obj.getResourceDataBase64 = function (name) { return res[name] || null; }; obj.getResourceData = function (name) { var r = res[name];return r ? ss.dec64(r) : null; }; ss.__assemblies[name] = obj; }; ss.initAssembly(ss, 'mscorlib'); //////////////////////////////////////////////////////////////////////////////// // Utility methods (generated via Script.IsNull, etc.) //////////////////////////////////////////////////////////////////////////////// ss.getAssemblies = function () { return Object.keys(ss.__assemblies).map(function (n) { return ss.__assemblies[n]; }); }; ss.isNullOrUndefined = function (o) { return o === null || o === undefined; }; ss.isValue = function (o) { return o !== null && o !== undefined; }; ss.referenceEquals = function (a, b) { return ss.isValue(a) ? a === b : !ss.isValue(b); }; ss.mkdict = function () { var a = arguments.length !== 1 ? arguments : arguments[0]; var r = {}; for (var i = 0; i < a.length; i += 2) { r[a[i]] = a[i + 1]; } return r; }; ss.clone = function (t, o) { return o ? t.$clone(o) : o; }; ss.coalesce = function (a, b) { return ss.isValue(a) ? a : b; }; ss.isDate = function (obj) { return Object.prototype.toString.call(obj) === '[object Date]'; }; ss.isArray = function (obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }; ss.isTypedArrayType = function (type) { return ['Float32Array', 'Float64Array', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Uint8ClampedArray'].indexOf(ss.getTypeFullName(type)) >= 0; }; ss.isArrayOrTypedArray = function (obj) { return ss.isArray(obj) || ss.isTypedArrayType(ss.getInstanceType(obj)); }; ss.equals = function (a, b) { if (!ss.isValue(a)) throw new ss_NullReferenceException('Object is null');else if (a !== ss && typeof a.equals === 'function') return a.equals(b); if (ss.isDate(a) && ss.isDate(b)) return a.valueOf() === b.valueOf();else if (typeof a === 'function' && typeof b === 'function') return ss.delegateEquals(a, b);else if (ss.isNullOrUndefined(a) && ss.isNullOrUndefined(b)) return true;else return a === b; }; ss.compare = function (a, b) { if (!ss.isValue(a)) throw new ss_NullReferenceException('Object is null');else if (typeof a === 'number' || typeof a === 'string' || typeof a === 'boolean') return ss.isValue(b) ? a < b ? -1 : a > b ? 1 : 0 : 1;else if (ss.isDate(a)) return ss.isValue(b) ? ss.compare(a.valueOf(), b.valueOf()) : 1;else return a.compareTo(b); }; ss.equalsT = function (a, b) { if (!ss.isValue(a)) throw new ss_NullReferenceException('Object is null');else if (typeof a === 'number' || typeof a === 'string' || typeof a === 'boolean') return a === b;else if (ss.isDate(a)) return a.valueOf() === b.valueOf();else return a.equalsT(b); }; ss.staticEquals = function (a, b) { if (!ss.isValue(a)) return !ss.isValue(b);else return ss.isValue(b) ? ss.equals(a, b) : false; }; ss.shallowCopy = function () { try { var x = Object.getOwnPropertyDescriptor({ a: 0 }, 'a').value;return true; } catch (ex) { return false; } }() ? function (source, target) { var keys = Object.keys(source); for (var i = 0, l = keys.length; i < l; i++) { Object.defineProperty(target, keys[i], Object.getOwnPropertyDescriptor(source, keys[i])); } } : function (source, target) { var keys = Object.keys(source); for (var i = 0, l = keys.length; i < l; i++) { target[keys[i]] = source[keys[i]]; } }; if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) == 'object') { // Browser-specific stuff that could go into the Web assembly, but that assembly does not have an associated JS file. if (!window.Element) { // IE does not have an Element constructor. This implementation should make casting to elements work. window.Element = function () {}; window.Element.isInstanceOfType = function (instance) { return instance && typeof instance.constructor === 'undefined' && typeof instance.tagName === 'string'; }; } window.Element.__typeName = 'Element'; ss.parseXml = function (markup) { var domParser = new DOMParser(); return domParser.parseFromString(markup, 'text/xml'); }; } /////////////////////////////////////////////////////////////////////////////// // Object Extensions ss.clearKeys = function (d) { for (var n in d) { if (d.hasOwnProperty(n)) delete d[n]; } }; ss.keyExists = function (d, key) { return d[key] !== undefined; }; if (!Object.keys) { Object.keys = function () { 'use strict'; var hasOwnProperty = Object.prototype.hasOwnProperty, hasDontEnumBug = !{ toString: null }.propertyIsEnumerable('toString'), dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'], dontEnumsLength = dontEnums.length; return function (obj) { if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && (typeof obj !== 'function' || obj === null)) { throw new TypeError('Object.keys called on non-object'); } var result = [], prop, i; for (prop in obj) { if (hasOwnProperty.call(obj, prop)) { result.push(prop); } } if (hasDontEnumBug) { for (i = 0; i < dontEnumsLength; i++) { if (hasOwnProperty.call(obj, dontEnums[i])) { result.push(dontEnums[i]); } } } return result; }; }(); } ss.getKeyCount = function (d) { return Object.keys(d).length; }; //////////////////////////////////////////////////////////////////////////////// // Type System Implementation //////////////////////////////////////////////////////////////////////////////// // When FULL_TYPE_SYSTEM is not defined, then the code is not the full-blown // type system. It's Just enough to allow us to call base class methods. ss.__genericCache = {}; ss._makeGenericTypeName = function (genericType, typeArguments) { var result = ss.getTypeFullName(genericType); for (var i = 0; i < typeArguments.length; i++) { result += (i === 0 ? '[' : ',') + '[' + ss.getTypeFullName(typeArguments[i]) + ']'; }result += ']'; return result; }; ss.makeGenericType = function (genericType, typeArguments) { var name = ss._makeGenericTypeName(genericType, typeArguments); return ss.__genericCache[ss._makeQName(name, genericType.__assembly)] || genericType.apply(null, typeArguments); }; ss._registerGenericInstance = function (genericType, typeArguments, instance, members, statics, init) { if (!instance) { instance = function instance() {}; } var name = ss._makeGenericTypeName(genericType, typeArguments); ss.__genericCache[ss._makeQName(name, genericType.__assembly)] = instance; instance.__typeName = name; instance.__assembly = genericType.__assembly; instance.__genericTypeDefinition = genericType; instance.__typeArguments = typeArguments; if (statics) { ss.shallowCopy(statics, instance); } init(instance); if (members) { ss.shallowCopy(members, instance.prototype); } return instance; }; ss.registerGenericClassInstance = function (genericType, typeArguments, instance, members, statics, baseType, getInterfaceTypesFunc) { return ss._registerGenericInstance(genericType, typeArguments, instance, members, statics, function (inst) { ss.initClass(inst, baseType ? baseType() : null, getInterfaceTypesFunc ? getInterfaceTypesFunc() : null); }); }; ss.registerGenericStructInstance = function (genericType, typeArguments, instance, members, statics, getInterfaceTypesFunc) { return ss._registerGenericInstance(genericType, typeArguments, instance, members, statics, function (inst) { ss.initStruct(inst, getInterfaceTypesFunc ? getInterfaceTypesFunc() : null); }); }; ss.registerGenericInterfaceInstance = function (genericType, typeArguments, members, getBaseInterfacesFunc) { return ss._registerGenericInstance(genericType, typeArguments, null, members, null, function (instance) { ss.initInterface(instance, members, getBaseInterfacesFunc ? getBaseInterfacesFunc() : null); }); }; ss.isGenericTypeDefinition = function (type) { return type.__isGenericTypeDefinition || false; }; ss.getGenericTypeDefinition = function (type) { return type.__genericTypeDefinition || null; }; ss.getGenericParameterCount = function (type) { return type.__typeArgumentCount || 0; }; ss.getGenericArguments = function (type) { return type.__typeArguments || null; }; ss.__anonymousCache = {}; ss.anonymousType = function () { var members = Array.prototype.slice.call(arguments); var name = 'Anonymous<' + members.map(function (m) { return m[1] + ':' + ss.getTypeFullName(m[0]); }).join(',') + '>'; var type = ss.__anonymousCache[name]; if (!type) { type = new Function(members.map(function (m) { return m[1]; }).join(','), members.map(function (m) { return 'this.' + m[1] + '=' + m[1] + ';'; }).join('')); type.__typeName = name; var infos = members.map(function (m) { return { name: m[1], typeDef: type, type: 16, returnType: m[0], getter: { name: 'get_' + m[1], typeDef: type, params: [], returnType: m[0], fget: m[1] } }; }); infos.push({ name: '.ctor', typeDef: type, type: 1, params: members.map(function (m) { return m[0]; }) }); type.__metadata = { members: infos }; ss.__anonymousCache[name] = type; } return type; }; ss.setMetadata = function (type, metadata) { if (metadata.members) { for (var i = 0; i < metadata.members.length; i++) { var m = metadata.members[i]; m.typeDef = type; if (m.adder) m.adder.typeDef = type; if (m.remover) m.remover.typeDef = type; if (m.getter) m.getter.typeDef = type; if (m.setter) m.setter.typeDef = type; } } type.__metadata = metadata; if (metadata.variance) { type.isAssignableFrom = function (source) { var check = function check(target, type) { if (type.__genericTypeDefinition === target.__genericTypeDefinition && type.__typeArguments.length === target.__typeArguments.length) { for (var i = 0; i < target.__typeArguments.length; i++) { var v = target.__metadata.variance[i], t = target.__typeArguments[i], s = type.__typeArguments[i]; switch (v) { case 1: if (!ss.isAssignableFrom(t, s)) return false;break; case 2: if (!ss.isAssignableFrom(s, t)) return false;break; default: if (s !== t) return false; } } return true; } return false; }; if (source.__interface && check(this, source)) return true; var ifs = ss.getInterfaces(source); for (var i = 0; i < ifs.length; i++) { if (ifs[i] === this || check(this, ifs[i])) return true; } return false; }; } }; ss.setMetadata = function (type, metadata) {}; ss.mkType = function (asm, typeName, ctor, members, statics) { if (!ctor) ctor = function ctor() {}; ctor.__assembly = asm; ctor.__typeName = typeName; if (asm) asm.__types[typeName] = ctor; if (members) ctor.__members = members; if (statics) ss.shallowCopy(statics, ctor); return ctor; }; ss.mkEnum = function (asm, typeName, values, namedValues) { var result = ss.mkType(asm, typeName); ss.shallowCopy(values, result.prototype); result.__enum = true; result.getDefaultValue = result.createInstance = function () { return namedValues ? null : 0; }; result.isInstanceOfType = function (instance) { return (typeof instance === 'undefined' ? 'undefined' : _typeof(instance)) === (namedValues ? 'string' : 'number'); }; return result; }; ss.initClass = function (ctor, baseType, interfaces) { ctor.__class = true; if (baseType && baseType !== Object) { var f = function f() {}; f.prototype = baseType.prototype; ctor.prototype = new f(); ctor.prototype.constructor = ctor; } if (ctor.__members) { ss.shallowCopy(ctor.__members, ctor.prototype); delete ctor.__members; } if (interfaces) ctor.__interfaces = interfaces; }; ss.initStruct = function (ctor, interfaces) { ss.initClass(ctor, null, interfaces); ctor.__class = false; ctor.getDefaultValue = ctor.getDefaultValue || ctor.createInstance || function () { return new ctor(); }; }; ss.initGenericClass = function (ctor, typeArgumentCount) { ctor.__class = true; ctor.__typeArgumentCount = typeArgumentCount; ctor.__isGenericTypeDefinition = true; }; ss.initGenericStruct = function (ctor, typeArgumentCount) { ss.initGenericClass(ctor, typeArgumentCount); ctor.__class = false; }; ss.initInterface = function (ctor, members, baseInterfaces) { ctor.__interface = true; if (baseInterfaces) { ctor.__interfaces = baseInterfaces; } ss.shallowCopy(members, ctor.prototype); ctor.isAssignableFrom = function (type) { return ss.contains(ss.getInterfaces(type), this); }; }; ss.initGenericInterface = function (ctor, typeArgumentCount) { ctor.__interface = true; ctor.__typeArgumentCount = typeArgumentCount; ctor.__isGenericTypeDefinition = true; }; ss.getBaseType = function (type) { if (type === Object || type.__interface) { return null; } else if (Object.getPrototypeOf) { return Object.getPrototypeOf(type.prototype).constructor; } else { var p = type.prototype; if (Object.prototype.hasOwnProperty.call(p, 'constructor')) { var ownValue = p.constructor; try { delete p.constructor; return p.constructor; } finally { p.constructor = ownValue; } } return p.constructor; } }; ss.getTypeFullName = function (type) { return type.__typeName || type.name || (type.toString().match(/^\s*function\s*([^\s(]+)/) || [])[1] || 'Object'; }; ss._makeQName = function (name, asm) { return name + (asm ? ', ' + asm.name : ''); }; ss.getTypeQName = function (type) { return ss._makeQName(ss.getTypeFullName(type), type.__assembly); }; ss.getTypeName = function (type) { var fullName = ss.getTypeFullName(type); var bIndex = fullName.indexOf('['); var nsIndex = fullName.lastIndexOf('.', bIndex >= 0 ? bIndex : fullName.length); return nsIndex > 0 ? fullName.substr(nsIndex + 1) : fullName; }; ss.getTypeNamespace = function (type) { var fullName = ss.getTypeFullName(type); var bIndex = fullName.indexOf('['); var nsIndex = fullName.lastIndexOf('.', bIndex >= 0 ? bIndex : fullName.length); return nsIndex > 0 ? fullName.substr(0, nsIndex) : ''; }; ss.getTypeAssembly = function (type) { if (ss.contains([Date, Number, Boolean, String, Function, Array], type)) return ss;else return type.__assembly || null; }; ss._getAssemblyType = function (asm, name) { if (asm.__types) { return asm.__types[name] || null; } else { var a = name.split('.'); for (var i = 0; i < a.length; i++) { asm = asm[a[i]]; if (!ss.isValue(asm)) return null; } if (typeof asm !== 'function') return null; return asm; } }; ss.getAssemblyTypes = function (asm) { var result = []; if (asm.__types) { for (var t in asm.__types) { if (asm.__types.hasOwnProperty(t)) result.push(asm.__types[t]); } } else { var traverse = function traverse(s, n) { for (var c in s) { if (s.hasOwnProperty(c)) traverse(s[c], c); } if (typeof s === 'function' && ss.isUpper(n.charCodeAt(0))) result.push(s); }; traverse(asm, ''); } return result; }; ss.createAssemblyInstance = function (asm, typeName) { var t = ss.getType(typeName, asm); return t ? ss.createInstance(t) : null; }; ss.getInterfaces = function (type) { if (type.__interfaces) return type.__interfaces;else if (type === Date || type === Number) return [ss_IEquatable, ss_IComparable, ss_IFormattable];else if (type === Boolean || type === String) return [ss_IEquatable, ss_IComparable];else if (type === Array || ss.isTypedArrayType(type)) return [ss_IEnumerable, ss_ICollection, ss_IList, ss_IReadOnlyCollection, ss_IReadOnlyList];else return []; }; ss.isInstanceOfType = function (instance, type) { if (ss.isNullOrUndefined(instance)) return false; if (typeof type.isInstanceOfType === 'function') return type.isInstanceOfType(instance); return ss.isAssignableFrom(type, ss.getInstanceType(instance)); }; ss.isAssignableFrom = function (target, type) { return target === type || typeof target.isAssignableFrom === 'function' && target.isAssignableFrom(type) || type.prototype instanceof target; }; ss.isClass = function (type) { return type.__class === true || type === Array || type === Function || type === RegExp || type === String || type === Error || type === Object; }; ss.isEnum = function (type) { return !!type.__enum; }; ss.isFlags = function (type) { return type.__metadata && type.__metadata.enumFlags || false; }; ss.isInterface = function (type) { return !!type.__interface; }; ss.safeCast = function (instance, type) { if (type === true) return instance;else if (type === false) return null;else return ss.isInstanceOfType(instance, type) ? instance : null; }; ss.cast = function (instance, type) { if (instance === null || typeof instance === 'undefined') return instance;else if (type === true || type !== false && ss.isInstanceOfType(instance, type)) return instance; throw new ss_InvalidCastException('Cannot cast object to type ' + ss.getTypeFullName(type)); }; ss.getInstanceType = function (instance) { if (!ss.isValue(instance)) throw new ss_NullReferenceException('Cannot get type of null'); // NOTE: We have to catch exceptions because the constructor // cannot be looked up on native COM objects try { return instance.constructor; } catch (ex) { return Object; } }; ss._getType = function (typeName, asm, re) { var outer = !re; re = re || /[[,\]]/g; var last = re.lastIndex, m = re.exec(typeName), tname, targs = []; var t; if (m) { tname = typeName.substring(last, m.index); switch (m[0]) { case '[': if (typeName[m.index + 1] !== '[') return null; for (;;) { re.exec(typeName); t = ss._getType(typeName, global, re); if (!t) return null; targs.push(t); m = re.exec(typeName); if (m[0] === ']') break;else if (m[0] !== ',') return null; } m = re.exec(typeName); if (m && m[0] === ',') { re.exec(typeName); if (!(asm = ss.__assemblies[(re.lastIndex > 0 ? typeName.substring(m.index + 1, re.lastIndex - 1) : typeName.substring(m.index + 1)).trim()])) return null; } break; case ']': break; case ',': re.exec(typeName); if (!(asm = ss.__assemblies[(re.lastIndex > 0 ? typeName.substring(m.index + 1, re.lastIndex - 1) : typeName.substring(m.index + 1)).trim()])) return null; break; } } else { tname = typeName.substring(last); } if (outer && re.lastIndex) return null; t = ss._getAssemblyType(asm, tname.trim()); return targs.length ? ss.makeGenericType(t, targs) : t; }; ss.getType = function (typeName, asm) { return typeName ? ss._getType(typeName, asm || global) : null; }; ss.getDefaultValue = function (type) { if (typeof type.getDefaultValue === 'function') return type.getDefaultValue();else if (type === Boolean) return false;else if (type === Date) return new Date(0);else if (type === Number) return 0; return null; }; ss.createInstance = function (type) { if (typeof type.createInstance === 'function') return type.createInstance();else if (type === Boolean) return false;else if (type === Date) return new Date(0);else if (type === Number) return 0;else if (type === String) return '';else return new type(); }; /////////////////////////////////////////////////////////////////////////////// // IFormattable var ss_IFormattable = ss.IFormattable = ss.mkType(ss, 'ss.IFormattable'); ss.initInterface(ss_IFormattable, { format: null }); /////////////////////////////////////////////////////////////////////////////// // IComparable var ss_IComparable = ss.IComparable = ss.mkType(ss, 'ss.IComparable'); ss.initInterface(ss_IComparable, { compareTo: null }); /////////////////////////////////////////////////////////////////////////////// // IEquatable var ss_IEquatable = ss.IEquatable = ss.mkType(ss, 'ss.IEquatable'); ss.initInterface(ss_IEquatable, { equalsT: null }); /////////////////////////////////////////////////////////////////////////////// // Number Extensions /////////////////////////////////////////////////////////////////////////////// // String Extensions ss.isNullOrEmptyString = function (s) { return !s || !s.length; }; if (!String.prototype.trim) { String.prototype.trim = function () { return ss.trimStartString(ss.trimEndString(this)); }; } ss.trimEndString = function (s, chars) { return s.replace(chars ? new RegExp('[' + String.fromCharCode.apply(null, chars) + ']+$') : /\s*$/, ''); }; ss.trimStartString = function (s, chars) { return s.replace(chars ? new RegExp('^[' + String.fromCharCode.apply(null, chars) + ']+') : /^\s*/, ''); }; ss.trimString = function (s, chars) { return ss.trimStartString(ss.trimEndString(s, chars), chars); }; /////////////////////////////////////////////////////////////////////////////// // Math Extensions /////////////////////////////////////////////////////////////////////////////// // IFormatProvider /////////////////////////////////////////////////////////////////////////////// // NumberFormatInfo /////////////////////////////////////////////////////////////////////////////// // DateTimeFormatInfo /////////////////////////////////////////////////////////////////////////////// // Array Extensions ss.arrayClone = function (arr) { if (arr.length === 1) { return [arr[0]]; } else { return Array.apply(null, arr); } }; if (!Array.prototype.map) { Array.prototype.map = function (callback, instance) { var length = this.length; var mapped = new Array(length); for (var i = 0; i < length; i++) { if (i in this) { mapped[i] = callback.call(instance, this[i], i, this); } } return mapped; }; } if (!Array.prototype.some) { Array.prototype.some = function (callback, instance) { var length = this.length; for (var i = 0; i < length; i++) { if (i in this && callback.call(instance, this[i], i, this)) { return true; } } return false; }; } // Production steps of ECMA-262, Edition 5, 15.4.4.18 // Reference: http://es5.github.io/#x15.4.4.18 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach if (!Array.prototype.forEach) { Array.prototype.forEach = function (callback, thisArg) { var T, k; if (this == null) { throw new TypeError(' this is null or not defined'); } // 1. Let O be the result of calling ToObject passing the |this| value as the argument. var O = Object(this); // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". // 3. Let len be ToUint32(lenValue). var len = O.length >>> 0; // 4. If IsCallable(callback) is false, throw a TypeError exception. // See: http://es5.github.com/#x9.11 if (typeof callback !== 'function') { throw new TypeError(callback + ' is not a function'); } // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. if (arguments.length > 1) { T = thisArg; } // 6. Let k be 0 k = 0; // 7. Repeat, while k < len while (k < len) { var kValue; // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. // This step can be combined with c // c. If kPresent is true, then if (k in O) { // i. Let kValue be the result of calling the Get internal method of O with argument Pk. kValue = O[k]; // ii. Call the Call internal method of callback with T as the this value and // argument list containing kValue, k, and O. callback.call(T, kValue, k, O); } // d. Increase k by 1. k++; } // 8. return undefined }; } // Production steps of ECMA-262, Edition 5 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter if (!Array.prototype.filter) { Array.prototype.filter = function (fun /*, thisArg*/) { if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (typeof fun !== 'function') { throw new TypeError(); } var res = []; var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { if (i in t) { var val = t[i]; // NOTE: Technically this should Object.defineProperty at // the next index, as push can be affected by // properties on Object.prototype and Array.prototype. // But that method's new, and collisions should be // rare, so use the more-compatible alternative. if (fun.call(thisArg, val, i, t)) { res.push(val); } } } return res; }; } /////////////////////////////////////////////////////////////////////////////// // Date Extensions /////////////////////////////////////////////////////////////////////////////// // Function Extensions ss._delegateContains = function (targets, object, method) { for (var i = 0; i < targets.length; i += 2) { if (targets[i] === object && targets[i + 1] === method) { return true; } } return false; }; ss._mkdel = function (targets) { var delegate = function delegate() { if (targets.length === 2) { return targets[1].apply(targets[0], arguments); } else { var clone = ss.arrayClone(targets); for (var i = 0; i < clone.length; i += 2) { if (ss._delegateContains(targets, clone[i], clone[i + 1])) { clone[i + 1].apply(clone[i], arguments); } } return null; } }; delegate._targets = targets; return delegate; }; ss.mkdel = function (object, method) { if (!object) { return method; } if (typeof method === 'string') { method = object[method]; } return ss._mkdel([object, method]); }; ss.delegateCombine = function (delegate1, delegate2) { if (!delegate1) { if (!delegate2._targets) { return ss.mkdel(null, delegate2); } return delegate2; } if (!delegate2) { if (!delegate1._targets) { return ss.mkdel(null, delegate1); } return delegate1; } var targets1 = delegate1._targets ? delegate1._targets : [null, delegate1]; var targets2 = delegate2._targets ? delegate2._targets : [null, delegate2]; return ss._mkdel(targets1.concat(targets2)); }; ss.delegateRemove = function (delegate1, delegate2) { if (!delegate1 || delegate1 === delegate2) { return null; } var targets = delegate1._targets; if (!delegate2 || !targets) { return delegate1; } var object = null; var method; if (delegate2._targets) { object = delegate2._targets[0]; method = delegate2._targets[1]; } else { method = delegate2; } for (var i = 0; i < targets.length; i += 2) { if (targets[i] === object && targets[i + 1] === method) { if (targets.length === 2) { return null; } var t = ss.arrayClone(targets); t.splice(i, 2); return ss._mkdel(t); } } return delegate1; }; ss.delegateEquals = function (a, b) { if (a === b) return true; if (!a._targets && !b._targets) return false; var ta = a._targets || [null, a], tb = b._targets || [null, b]; if (ta.length !== tb.length) return false; for (var i = 0; i < ta.length; i++) { if (ta[i] !== tb[i]) return false; } return true; }; /////////////////////////////////////////////////////////////////////////////// // RegExp Extensions /////////////////////////////////////////////////////////////////////////////// // Debug Extensions /////////////////////////////////////////////////////////////////////////////// // Enum var ss_Enum = ss.Enum = ss.mkType(ss, 'ss.Enum', {}); ss.initClass(ss_Enum); ss_Enum.getValues = function Enum$getValues(enumType) { var parts = []; var values = enumType.prototype; for (var i in values) { if (values.hasOwnProperty(i)) parts.push(values[i]); } return parts; }; /////////////////////////////////////////////////////////////////////////////// // CultureInfo /////////////////////////////////////////////////////////////////////////////// // IEnumerator var ss_IEnumerator = ss.IEnumerator = ss.mkType(ss, 'ss.IEnumerator'); ss.initInterface(ss_IEnumerator, { current: null, moveNext: null, reset: null }, [ss_IDisposable]); /////////////////////////////////////////////////////////////////////////////// // IEnumerable var ss_IEnumerable = ss.IEnumerable = ss.mkType(ss, 'ss.IEnumerable'); ss.initInterface(ss_IEnumerable, { getEnumerator: null }); ss.getEnumerator = function (obj) { return obj.getEnumerator ? obj.getEnumerator() : new ss_ArrayEnumerator(obj); }; /////////////////////////////////////////////////////////////////////////////// // ICollection var ss_ICollection = ss.ICollection = ss.mkType(ss, 'ss.ICollection'); ss.initInterface(ss_ICollection, { get_count: null, add: null, clear: null, remove: null, contains: null }, [ss_IEnumerable]); ss.count = function (obj) { return obj.get_count ? obj.get_count() : obj.length; }; ss.add = function (obj, item) { if (obj.add) obj.add(item);else if (ss.isArray(obj)) obj.push(item);else throw new ss_NotSupportedException(); }; ss.clear = function (obj) { if (obj.clear) obj.clear();else if (ss.isArray(obj)) obj.length = 0;else throw new ss_NotSupportedException(); }; ss.remove = function (obj, item) { if (obj.remove) return obj.remove(item);else if (ss.isArray(obj)) { var index = ss.indexOf(obj, item); if (index >= 0) { obj.splice(index, 1); return true; } return false; } else throw new ss_NotSupportedException(); }; ss.contains = function (obj, item) { if (obj.contains) return obj.contains(item);else return ss.indexOf(obj, item) >= 0; }; /////////////////////////////////////////////////////////////////////////////// // IReadOnlyCollection var ss_IReadOnlyCollection = ss.IReadOnlyCollection = ss.mkType(ss, 'ss.IReadOnlyCollection'); ss.initInterface(ss_IReadOnlyCollection, { get_count: null, contains: null }, [ss_IEnumerable]); //#include "TimeSpan.js" /////////////////////////////////////////////////////////////////////////////// // IEqualityComparer var ss_IEqualityComparer = ss.IEqualityComparer = ss.mkType(ss, 'ss.IEqualityComparer'); ss.initInterface(ss_IEqualityComparer, { areEqual: null, getObjectHashCode: null }); /////////////////////////////////////////////////////////////////////////////// // IComparer var ss_IComparer = ss.IComparer = ss.mkType(ss, 'ss.IComparer'); ss.initInterface(ss_IComparer, { compare: null }); /////////////////////////////////////////////////////////////////////////////// // Nullable ss.unbox = function (instance) { if (!ss.isValue(instance)) throw new ss_InvalidOperationException('Nullable object must have a value.'); return instance; }; var ss_Nullable$1 = ss.Nullable$1 = ss.mkType(ss, 'ss.Nullable$1', function (T) { var $type = ss.registerGenericClassInstance(ss_Nullable$1, [T], null, {}, { isInstanceOfType: function isInstanceOfType(instance) { return ss.isInstanceOfType(instance, T); } }); return $type; }, null, { eq: function eq(a, b) { return !ss.isValue(a) ? !ss.isValue(b) : a === b; }, ne: function ne(a, b) { return !ss.isValue(a) ? ss.isValue(b) : a !== b; }, le: function le(a, b) { return ss.isValue(a) && ss.isValue(b) && a <= b; }, ge: function ge(a, b) { return ss.isValue(a) && ss.isValue(b) && a >= b; }, lt: function lt(a, b) { return ss.isValue(a) && ss.isValue(b) && a < b; }, gt: function gt(a, b) { return ss.isValue(a) && ss.isValue(b) && a > b; }, sub: function sub(a, b) { return ss.isValue(a) && ss.isValue(b) ? a - b : null; }, add: function add(a, b) { return ss.isValue(a) && ss.isValue(b) ? a + b : null; }, mod: function mod(a, b) { return ss.isValue(a) && ss.isValue(b) ? a % b : null; }, div: function div(a, b) { return ss.isValue(a) && ss.isValue(b) ? a / b : null; }, mul: function mul(a, b) { return ss.isValue(a) && ss.isValue(b) ? a * b : null; }, band: function band(a, b) { return ss.isValue(a) && ss.isValue(b) ? a & b : null; }, bor: function bor(a, b) { return ss.isValue(a) && ss.isValue(b) ? a | b : null; }, bxor: function bxor(a, b) { return ss.isValue(a) && ss.isValue(b) ? a ^ b : null; }, shl: function shl(a, b) { return ss.isValue(a) && ss.isValue(b) ? a << b : null; }, srs: function srs(a, b) { return ss.isValue(a) && ss.isValue(b) ? a >> b : null; }, sru: function sru(a, b) { return ss.isValue(a) && ss.isValue(b) ? a >>> b : null; }, and: function and(a, b) { if (a === true && b === true) return true;else if (a === false || b === false) return false;else return null; }, or: function or(a, b) { if (a === true || b === true) return true;else if (a === false && b === false) return false;else return null; }, xor: function xor(a, b) { return ss.isValue(a) && ss.isValue(b) ? !!(a ^ b) : null; }, not: function not(a) { return ss.isValue(a) ? !a : null; }, neg: function neg(a) { return ss.isValue(a) ? -a : null; }, pos: function pos(a) { return ss.isValue(a) ? +a : null; }, cpl: function cpl(a) { return ss.isValue(a) ? ~a : null; }, lift1: function lift1(f, o) { return ss.isValue(o) ? f(o) : null; }, lift2: function lift2(f, a, b) { return ss.isValue(a) && ss.isValue(b) ? f(a, b) : null; }, liftcmp: function liftcmp(f, a, b) { return ss.isValue(a) && ss.isValue(b) ? f(a, b) : false; }, lifteq: function lifteq(f, a, b) { var va = ss.isValue(a), vb = ss.isValue(b); return !va && !vb || va && vb && f(a, b); }, liftne: function liftne(f, a, b) { var va = ss.isValue(a), vb = ss.isValue(b); return va !== vb || va && f(a, b); } }); ss.initGenericClass(ss_Nullable$1, 1); /////////////////////////////////////////////////////////////////////////////// // IList var ss_IList = ss.IList = ss.mkType(ss, 'ss.IList'); ss.initInterface(ss_IList, { get_item: null, set_item: null, indexOf: null, insert: null, removeAt: null }, [ss_ICollection, ss_IEnumerable]); ss.getItem = function (obj, index) { return obj.get_item ? obj.get_item(index) : obj[index]; }; ss.setItem = function (obj, index, value) { obj.set_item ? obj.set_item(index, value) : obj[index] = value; }; ss.indexOf = function (obj, item) { if ((!item || typeof item.equals !== 'function') && typeof obj.indexOf === 'function') { // use indexOf if item is null or if item does not implement an equals function return obj.indexOf(item); } else if (ss.isArrayOrTypedArray(obj)) { for (var i = 0; i < obj.length; i++) { if (ss.staticEquals(obj[i], item)) { return i; } } return -1; } else return obj.indexOf(item); }; ss.insert = function (obj, index, item) { if (obj.insert) obj.insert(index, item);else if (ss.isArray(obj)) obj.splice(index, 0, item);else throw new ss_NotSupportedException(); }; ss.removeAt = function (obj, index) { if (obj.removeAt) obj.removeAt(index);else if (ss.isArray(obj)) obj.splice(index, 1);else throw new ss_NotSupportedException(); }; /////////////////////////////////////////////////////////////////////////////// // IReadOnlyList var ss_IReadOnlyList = ss.IReadOnlyList = ss.mkType(ss, 'ss.IReadOnlyList'); ss.initInterface(ss_IReadOnlyList, { get_item: null }, [ss_IReadOnlyCollection, ss_IEnumerable]); // #include "IDictionary.js" // #include "IReadOnlyDictionary.js" /////////////////////////////////////////////////////////////////////////////// // Int32 var defInt = function defInt(name, min, max) { var type = ss[name] = ss.mkType(ss, 'ss.' + name, function () {}, null, { isInstanceOfType: function isInstanceOfType(instance) { return typeof instance === 'number' && Math.round(instance, 0) === instance && instance >= min && instance <= max; }, createInstance: function createInstance() { return 0; } }); ss.initStruct(type, [ss_IEquatable, ss_IComparable, ss_IFormattable]); return type; }; var ss_Byte = defInt('Byte', 0, 255); var ss_SByte = defInt('SByte', -128, 127); var ss_Int16 = defInt('Int16', -32768, 32767); var ss_UInt16 = defInt('UInt16', 0, 65535); var ss_Int32 = defInt('Int32', -2147483648, 2147483647); var ss_UInt32 = defInt('UInt32', 0, 4294967295); var ss_Int64 = defInt('Int64', -9223372036854775808, 9223372036854775807); var ss_UInt64 = defInt('UInt64', 0, 18446744073709551615); var ss_Char = defInt('Char', 0, 65535); ss.sxb = function (x) { return x | (x & 0x80 ? 0xffffff00 : 0); }; ss.sxs = function (x) { return x | (x & 0x8000 ? 0xffff0000 : 0); }; ss.clip8 = function (x) { return ss.isValue(x) ? ss.sxb(x & 0xff) : null; }; ss.clipu8 = function (x) { return ss.isValue(x) ? x & 0xff : null; }; ss.clip16 = function (x) { return ss.isValue(x) ? ss.sxs(x & 0xffff) : null; }; ss.clipu16 = function (x) { return ss.isValue(x) ? x & 0xffff : null; }; ss.clip32 = function (x) { return ss.isValue(x) ? x | 0 : null; }; ss.clipu32 = function (x) { return ss.isValue(x) ? x >>> 0 : null; }; ss.clip64 = function (x) { return ss.isValue(x) ? (Math.floor(x / 0x100000000) | 0) * 0x100000000 + (x >>> 0) : null; }; ss.clipu64 = function (x) { return ss.isValue(x) ? (Math.floor(x / 0x100000000) >>> 0) * 0x100000000 + (x >>> 0) : null; }; ss.ck = function (x, tp) { if (ss.isValue(x) && !tp.isInstanceOfType(x)) throw new ss_OverflowException(); return x; }; ss.trunc = function (n) { return ss.isValue(n) ? n > 0 ? Math.floor(n) : Math.ceil(n) : null; }; ss.idiv = function (a, b) { if (!ss.isValue(a) || !ss.isValue(b)) return null; if (!b) throw new ss_DivideByZeroException(); return ss.trunc(a / b); }; ss.imod = function (a, b) { if (!ss.isValue(a) || !ss.isValue(b)) return null; if (!b) throw new ss_DivideByZeroException(); return a % b; }; /////////////////////////////////////////////////////////////////////////////// // MutableDateTime var ss_JsDate = ss.JsDate = ss.mkType(ss, 'ss.JsDate', function () {}, null, { createInstance: function createInstance() { return new Date(); }, isInstanceOfType: function isInstanceOfType(instance) { return instance instanceof Date; } }); ss.initClass(ss_JsDate, null, [ss_IEquatable, ss_IComparable]); /////////////////////////////////////////////////////////////////////////////// // ArrayEnumerator var ss_ArrayEnumerator = ss.ArrayEnumerator = ss.mkType(ss, 'ss.ArrayEnumerator', function (array) { this._array = array; this._index = -1; }, { moveNext: function moveNext() { this._index++; return this._index < this._array.length; }, reset: function reset() { this._index = -1; }, current: function current() { if (this._index < 0 || this._index >= this._array.length) throw 'Invalid operation'; return this._array[this._index]; }, dispose: function dispose() {} }); ss.initClass(ss_ArrayEnumerator, null, [ss_IEnumerator, ss_IDisposable]); /////////////////////////////////////////////////////////////////////////////// // ObjectEnumerator var ss_ObjectEnumerator = ss.ObjectEnumerator = ss.mkType(ss, 'ss.ObjectEnumerator', function (o) { this._keys = Object.keys(o); this._index = -1; this._object = o; }, { moveNext: function moveNext() { this._index++; return this._index < this._keys.length; }, reset: function reset() { this._index = -1; }, current: function current() { if (this._index < 0 || this._index >= this._keys.length) throw new ss_InvalidOperationException('Invalid operation'); var k = this._keys[this._index]; return { key: k, value: this._object[k] }; }, dispose: function dispose() {} }); ss.initClass(ss_ObjectEnumerator, null, [ss_IEnumerator, ss_IDisposable]); /////////////////////////////////////////////////////////////////////////////// // EqualityComparer var ss_EqualityComparer = ss.EqualityComparer = ss.mkType(ss, 'ss.EqualityComparer', function () {}, { areEqual: function areEqual(x, y) { return ss.staticEquals(x, y); }, getObjectHashCode: function getObjectHashCode(obj) { return ss.isValue(obj) ? ss.getHashCode(obj) : 0; } }); ss.initClass(ss_EqualityComparer, null, [ss_IEqualityComparer]); ss_EqualityComparer.def = new ss_EqualityComparer(); /////////////////////////////////////////////////////////////////////////////// // Comparer var ss_Comparer = ss.Comparer = ss.mkType(ss, 'ss.Comparer', function (f) { this.f = f; }, { compare: function compare(x, y) { return this.f(x, y); } }); ss.initClass(ss_Comparer, null, [ss_IComparer]); ss_Comparer.def = new ss_Comparer(function (a, b) { if (!ss.isValue(a)) return !ss.isValue(b) ? 0 : -1;else if (!ss.isValue(b)) return 1;else return ss.compare(a, b); }); /////////////////////////////////////////////////////////////////////////////// // KeyValuePair //#include "Dictionary.js" /////////////////////////////////////////////////////////////////////////////// // IDisposable var ss_IDisposable = ss.IDisposable = ss.mkType(ss, 'ss.IDisposable'); ss.initInterface(ss_IDisposable, { dispose: null }); /////////////////////////////////////////////////////////////////////////////// // StringBuilder var ss_StringBuilder = ss.StringBuilder = ss.mkType(ss, 'ss.StringBuilder', function (s) { this._parts = ss.isValue(s) && s !== '' ? [s] : []; this.length = ss.isValue(s) ? s.length : 0; }, { append: function append(o) { if (ss.isValue(o)) { var s = o.toString(); ss.add(this._parts, s); this.length += s.length; } return this; }, appendChar: function appendChar(c) { return this.append(String.fromCharCode(c)); }, appendLine: function appendLine(s) { this.append(s); this.append('\r\n'); return this; }, appendLineChar: function appendLineChar(c) { return this.appendLine(String.fromCharCode(c)); }, clear: function clear() { this._parts = []; this.length = 0; }, toString: function toString() { return this._parts.join(''); } }); ss.initClass(ss_StringBuilder); /////////////////////////////////////////////////////////////////////////////// // Random /////////////////////////////////////////////////////////////////////////////// // EventArgs var ss_EventArgs = ss.EventArgs = ss.mkType(ss, 'ss.EventArgs', function () {}); ss.initClass(ss_EventArgs); ss_EventArgs.Empty = new ss_EventArgs(); /////////////////////////////////////////////////////////////////////////////// // Exception var ss_Exception = ss.Exception = ss.mkType(ss, 'ss.Exception', function (message, innerException) { this._message = message || 'An error occurred.'; this._innerException = innerException || null; this._error = new Error(); }, { get_message: function get_message() { return this._message; }, get_innerException: function get_innerException() { return this._innerException; }, get_stack: function get_stack() { return this._error.stack; }, toString: function toString() { var message = this._message; var exception = this; if (ss.isNullOrEmptyString(message)) { if (ss.isValue(ss.getInstanceType(exception)) && ss.isValue(ss.getTypeFullName(ss.getInstanceType(exception)))) { message = ss.getTypeFullName(ss.getInstanceType(exception)); } else { message = '[object Exception]'; } } return message; } }, { wrap: function wrap(o) { if (ss.isInstanceOfType(o, ss_Exception)) { return o; } else if (o instanceof TypeError) { // TypeError can either be 'cannot read property blah of null/undefined' (proper NullReferenceException), or it can be eg. accessing a non-existent method of an object. // As long as all code is compiled, they should with a very high probability indicate the use of a null reference. return new ss_NullReferenceException(o.message, new ss_JsErrorException(o)); } else if (o instanceof RangeError) { return new ss_ArgumentOutOfRangeException(null, o.message, new ss_JsErrorException(o)); } else if (o instanceof Error) { return new ss_JsErrorException(o); } else { return new ss_Exception(o.toString()); } } }); ss.initClass(ss_Exception); //////////////////////////////////////////////////////////////////////////////// // NotImplementedException var ss_NotImplementedException = ss.NotImplementedException = ss.mkType(ss, 'ss.NotImplementedException', function (message, innerException) { ss_Exception.call(this, message || 'The method or operation is not implemented.', innerException); }); ss.initClass(ss_NotImplementedException, ss_Exception); //////////////////////////////////////////////////////////////////////////////// // NotSupportedException var ss_NotSupportedException = ss.NotSupportedException = ss.mkType(ss, 'ss.NotSupportedException', function (message, innerException) { ss_Exception.call(this, message || 'Specified method is not supported.', innerException); }); ss.initClass(ss_NotSupportedException, ss_Exception); //////////////////////////////////////////////////////////////////////////////// // AggregateException //////////////////////////////////////////////////////////////////////////////// // PromiseException //////////////////////////////////////////////////////////////////////////////// // JsErrorException var ss_JsErrorException = ss.JsErrorException = ss.mkType(ss, 'ss.JsErrorException', function (error, message, innerException) { ss_Exception.call(this, message || error.message, innerException); this.error = error; }, { get_stack: function get_stack() { return this.error.stack; } }); ss.initClass(ss_JsErrorException, ss_E