(function (__global__){ var __o__ = (function () { var __o__ = Object.create(null); var Data = (function () { var __o__ = Object.create(null); var Bit = (function () { var __o__ = Object.create(null); var and = function (i1) { return function (i2) { return (i1 & i2); } }; var or = function (i1) { return function (i2) { return (i1 | i2); } }; var xor = function (i1) { return function (i2) { return (i1 ^ i2); } }; var left = function (i1) { return function (i2) { return (i1 << i2); } }; var right = function (i1) { return function (i2) { return (i1 >> i2); } }; var right0 = function (i1) { return function (i2) { return (i1 >>> i2); } }; __o__.and = and; __o__.or = or; __o__.xor = xor; __o__.left = left; __o__.right = right; __o__.right0 = right0; return __o__; })(); var Locale = (function () { var __o__ = Object.create(null); var comparison = function () { return "..................Data.Locale.comparison...................................."; }; var toUpperCase = function (s) { return s.toLocaleUpperCase(); }; var toLowerCase = function (s) { return s.toLocaleLowerCase(); }; __o__.comparison = comparison; __o__.toUpperCase = toUpperCase; __o__.toLowerCase = toLowerCase; return __o__; })(); var DATETIME = Type.fromRecord ({ complain: function (x) { if (x instanceof Date) { return ''; } else { return "Not a date object." } }, chi: function (x) { return (x instanceof Date); }, name: 'Data.DATETIME', cardinality: function () { return null; } }); var DateTime = (function () { var __o__ = Object.create(null); var getWeek = function (d) { var date = new Date (d.getTime ()); date.setHours (0, 0, 0, 0); // Thursday in current week decides the year. date.setDate (date.getDate () + 3 - (date.getDay () + 6) % 7); // January 4 is always in week 1. var week1 = new Date (date.getFullYear (), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return 1 + Math.round (((date.getTime () - week1.getTime ()) / 86400000 - 3 + (week1.getDay () + 6) % 7) / 7); }; var now = function () { return new Date(); }; var localeOffset = function () { var d = new Date (); return d.getTimezoneOffset(); }; var fromInt = function (i) { return new Date (i); }; var toInt = function (d) { return d.getTime(); }; var fromString = function (s) { var n = Date.parse (s); // integer for the internal millisecond representation of `s` var d = new Date (n); if (isNaN (n)) { throw Error ("`Data.DateTime.fromString(s)` error, the argument is not a string representation of a date/time: `" + Any.literal(s) + "`."); } else { if (d === undefined) { throw Error ("`Data.DateTime.fromString(s)` error, the string argument cannot be converted `" + Any.literal(s) + "`."); } else { return d; } } }; var toIsoString = function (d) { return d.toISOString(); }; var toLocaleDateString = function (d) { return d.toLocaleDateString(); }; var toLocaleTimeString = function (d) { return d.toLocaleTimeString(); }; var DATETIME_RECORD = undefined // DUMMY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!; var toLocaleRecord = function (d) { return Rec.create ({ year : d.getFullYear (), month : d.getMonth (), date : d.getDate (), hours : d.getHours (), minutes : d.getMinutes (), seconds : d.getSeconds (), milliseconds : d.getMilliseconds (), week : getWeek (d), offset : d.getTimezoneOffset (), }); }; var toUtcRecord = function (d) { return Rec.create ({ year : d.getUTCFullYear (), month : d.getUTCMonth (), date : d.getUTCDate (), hours : d.getUTCHours (), minutes : d.getUTCMinutes (), seconds : d.getUTCSeconds (), milliseconds : d.getUTCMilliseconds (), week : getWeek (d), offset : 0, }); }; var fromRecord = function (r) { // the mandatory part of the date-time record `r` var year = r.year; var month = r.month; var date = r.date; // the optional part of `r` var hours = r.hours || 0; var minutes = r.minutes || 0; var seconds = r.seconds || 0; var milliseconds = r.milliseconds || 0; var offset = r.offset || 0; // correct the minutes by the offset minutes = minutes + offset; // define and return the result var dateTime = new Date ( year, month, date, hours, minutes + offset, seconds, milliseconds ); return dateTime; }; var normalRecord = function (r) { return toUtcRecord (fromRecord (r)); }; __o__.now = now; __o__.localeOffset = localeOffset; __o__.fromInt = fromInt; __o__.toInt = toInt; __o__.fromString = fromString; __o__.toIsoString = toIsoString; __o__.toLocaleDateString = toLocaleDateString; __o__.toLocaleTimeString = toLocaleTimeString; __o__.DATETIME_RECORD = DATETIME_RECORD; __o__.toLocaleRecord = toLocaleRecord; __o__.toUtcRecord = toUtcRecord; __o__.fromRecord = fromRecord; __o__.normalRecord = normalRecord; return __o__; })(); var REGULAR_EXPRESSION = Type.object (RegExp); var Rex = (function () { var __o__ = Object.create(null); var create = function (pattern) { return function (flags) { return new RegExp (pattern, flags); } }; var pattern = function (regex) { return regex.source; }; var flags = function (regex) { var flags = ''; if (regex.global) { flags += 'g'; } if (regex.ignoreCase) { flags += 'i'; } if (regex.multiline) { flags += 'm'; } if (regex.sticky) { flags += 'y'; } return flags; }; var search = function (str) { return function (regex) { return str.search (regex); } }; var replace = function (str) { return function (regex) { return function (newStr) { return str.replace (regex, newStr); } } }; var match = function (str) { return function (regex) { return str.match (regex); } }; var exec = function (regex) { return function (str) { return regex.exec (str); } }; var test = function (regex) { return function (str) { return regex.test (str); } }; __o__.create = create; __o__.pattern = pattern; __o__.flags = flags; __o__.search = search; __o__.replace = replace; __o__.match = match; __o__.exec = exec; __o__.test = test; return __o__; })(); var Maths = (function () { var __o__ = Object.create(null); var pi = Math.PI; var e = Math.E; var ln2 = Math.LN2; var ln10 = Math.LN10; var log2e = Math.LOG2E; var log10e = Math.LOG10E; var sqrt2 = Math.SQRT2; var sqrt1_2 = Math.SQRT1_2; var abs = Math.abs; var acos = Math.acos; var acosh = Math.acosh; var asin = Math.asin; var asinh = Math.asinh; var atan = Math.atan; var atanh = Math.atanh; var atan2 = function (y) { return function (x) { return Math.atan2 (y, x); } }; var cbrt = Math.cbrt; var ceil = Math.ceil; var clz32 = Math.clz32; var cos = Math.cos; var cosh = Math.cosh; var exp = Math.exp; var expm1 = Math.expm1; var floor = Math.floor; var fround = Math.fround; var hypot = Math.hypot; var imul = Math.imul; var log = Math.log; var log1p = Math.log1p; var log10 = Math.log10; var log2 = Math.log2; var max = function (xL) { return Math.max.apply (null, xL); }; var min = function (xL) { return Math.min.apply (null, xL); }; var pow = function (x) { return function (y) { return Math.pow (x) (y); } }; var round = Math.round; var sign = Math.sign; var sin = Math.sin; var sinh = Math.sinh; var sqrt = Math.sqrt; var tan = Math.tan; var tanh = Math.tanh; var trunc = Math.trunc; var random = function (x) { return Math.random(); }; __o__.pi = pi; __o__.e = e; __o__.ln2 = ln2; __o__.ln10 = ln10; __o__.log2e = log2e; __o__.log10e = log10e; __o__.sqrt2 = sqrt2; __o__.sqrt1_2 = sqrt1_2; __o__.abs = abs; __o__.acos = acos; __o__.acosh = acosh; __o__.asin = asin; __o__.asinh = asinh; __o__.atan = atan; __o__.atanh = atanh; __o__.atan2 = atan2; __o__.cbrt = cbrt; __o__.ceil = ceil; __o__.clz32 = clz32; __o__.cos = cos; __o__.cosh = cosh; __o__.exp = exp; __o__.expm1 = expm1; __o__.floor = floor; __o__.fround = fround; __o__.hypot = hypot; __o__.imul = imul; __o__.log = log; __o__.log1p = log1p; __o__.log10 = log10; __o__.log2 = log2; __o__.max = max; __o__.min = min; __o__.pow = pow; __o__.round = round; __o__.sign = sign; __o__.sin = sin; __o__.sinh = sinh; __o__.sqrt = sqrt; __o__.tan = tan; __o__.tanh = tanh; __o__.trunc = trunc; __o__.random = random; return __o__; })(); var Json = (function () { var __o__ = Object.create(null); var VALUE = Type.fromRecord ({ complain: function (x) { var y = JSON.stringify (JSON.parse (x)); if (Any.equal (x) (y)) { return ''; } else { return "The value is not a JSON value."; } }, name: 'Data.Json.VALUE', cardinality: function () { return null; } }); var CODE = STRING // dummy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!; var code2value = JSON.parse; var value2code = JSON.stringify; var urtype = function (x) { switch (typeof x) { case 'boolean': return BOOLEAN; case 'number': return NUMBER; case 'string': return STRING; case 'object': if (x === null) { return NULL; } else if (Array.isArray (x)) { return LIST; } else { return RECORD; } default: throw Error ("The given `" + (typeof x) + "` value is not a JSON value."); } }; var compare = function (x) { return function (y) { return ".......................................Data.Json.compare(x)(y)........................................."; } }; var equal = function (x) { return function (y) { return ".............................Data.Json.equal(x)(y)..................................................."; } }; var comparisonValue = function comparisonValue (x) { return function (y) { if (x === y) { return 0; } else { if (Type.chi (LIST) (x) && Type.chi (LIST) (y)) { var zL = []; var isEqual = true; for (var i = 0; i < Math.min (x.length, y.length); i++) { var t = comparisonValue (x[i]) (y[i]); if (typeof t === 'number' && t < 0) { isEqual = false; } zL.push (t); } if (x.length > y.length) { for (var i = 0; i < x.length - y.length; i++) { zL.push (1); } return zL; } else if (x.length < y.length) { for (var i = 0; i < y.length - x.length; i++) { zL.push (2); } return zL; } else { if (isEqual) { return 0; } else { return zL; } } } else if (Type.chi (RECORD) (x) && Type.chi (RECORD) (y)) { var o = {}; var isEqual = true; for (var k in x) { if (k in y) { var t = comparisonValue (x[k]) (y[k]); if (typeof t === 'number' && t < 0) { isEqual = false; } o [k] = t; } else { isEqual = false; o [k] = 1; } } for (var k in y) { if (! (k in x)) { isEqual = false; o [k] = 2; } } if (isEqual) { return 0; } else { return Rec.create (o); } } else { return -1; } } } }; __o__.VALUE = VALUE; __o__.CODE = CODE; __o__.code2value = code2value; __o__.value2code = value2code; __o__.urtype = urtype; __o__.compare = compare; __o__.equal = equal; __o__.comparisonValue = comparisonValue; return __o__; })(); var URL = Type.subType (STRING) (function (s) { if (Data.Url.regex.test (s)) { return ""; } else { return "Not a valid URL: `" + Any.ellipsis(s) + "`."; }; }); var Url = (function () { var __o__ = Object.create(null); var regex = new RegExp( "^" + // protocol identifier "(?:(?:https?|ftp)://)" + // user:pass authentication "(?:\\S+(?::\\S*)?@)?" + "(?:" + // IP address exclusion // private & local networks "(?!(?:10|127)(?:\\.\\d{1,3}){3})" + "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" + // IP address dotted notation octets // excludes loopback network 0.0.0.0 // excludes reserved space >= 224.0.0.0 // excludes network & broacast addresses // (first & last IP address of each class) "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + "|" + // host name "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" + // domain name "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" + // TLD identifier "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" + ")" + // port number "(?::\\d{2,5})?" + // resource path "(?:/\\S*)?" + "$", "i" );; __o__.regex = regex; return __o__; })(); var Uri = (function () { var __o__ = Object.create(null); var encode = encodeURI; var decode = decodeURI; var encodeComponent = encodeURIComponent; var decodeComponent = decodeURIComponent; var record2queryString = function (r) { var strL = []; for (var k in r) { if (Type.chi (STRING) (r [k])) { strL.push (k + "=" + encodeComponent (r [k])); } else if (Type.chi (NULL) (r [k])) { strL.push (k); } else { throw Error ( "`Data.Uri.record2queryString(r)` error, `r` is not a nullified string record, its `" + k + "` value `" + r[k] + "` is neither a string nor `null`." ); } } return strL.join ("&"); }; var queryString2record = function (s) { var r = {}; if (s.length > 0) { var strL = s.split ("&"); for (var i = 0; i < strL.length; i++) { var pair = strL[i].split ('='); var key = pair[0]; var value = pair[1]; value = ( value ? decodeComponent (value) : null ); r[key] = value; } } return Rec.create (r); }; __o__.encode = encode; __o__.decode = decode; __o__.encodeComponent = encodeComponent; __o__.decodeComponent = decodeComponent; __o__.record2queryString = record2queryString; __o__.queryString2record = queryString2record; return __o__; })(); var Email = (function () { var __o__ = Object.create(null); var ADDRESS = Type.regularString ( '^\\w+@[a-zA-Z_]+?\\.[a-zA-Z]{2,3}$' ); __o__.ADDRESS = ADDRESS; return __o__; })(); var Map = Object.create(null); var Set = Object.create(null); var HTML = Type.synonym (STRING); var Html = (function () { var __o__ = Object.create(null); var anchor = function (h) { return function (href) { return h.anchor(href); } }; var entityify = function (str) { return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); };; var HTML_NAME = Type.subType (STRING) (function (s) { var rex = /^[A-Za-z][A-Za-z0-9-]*$/; if (rex.test (s)) { return ""; } else { return ( "`" + s + "` is not a non-empty string, beginning with a letter and only comprising letters, digits and hyphens.") } } ); var toHtmlName = function (name) { if (name === '') { return 'ROOT'; } var htmlName = name . replace (/\$/g, "DOLLAR") . replace (/\./g, "-"); if (htmlName === '') { throw Error ("`Data.Html.toHtmlName(name)` error, the conversion leaves an empty string for the given argument `" + name + "`."); } else { return htmlName; } }; var fromHtmlName = function (htmlName) { if (htmlName === 'ROOT') { return ''; } var name = htmlName . replace ("DOLLAR", "\u0024") . replace (new RegExp ('-', 'g'), "."); return name; }; var htmlNameCompare = function (n1) { return function (n2) { return Str.compare (Str.toLowerCase (n1)) (Str.toLowerCase (n2)); } }; var HTML_DOC = Type.synonym (STRING); var htmlDoc = function (parameter) { return function (bodyContent) { // Normalize the `parameter` record var title = parameter.title || ''; var script = parameter.script || ''; var scriptLinks = parameter.scriptLinks || []; // type `Type.list(URL)`; later type `HTML` var css = parameter.css || ''; var cssLinks = parameter.cssLinks || []; // of type `Type.list(URL)`; later type `HTML` // turn the parameter values into HTML if (title) { title = '