function DeviceTest() { //MSIE, Firefox, Chrome, Safari, Opera, Gecko, Presto, Mozilla var agent=navigator.userAgent.toLowerCase(); if(agent.indexOf("msie") > 0 && document.all) return "MSIE"; else if(agent.indexOf("firefox") > 0) return "Firefox"; else if(agent.indexOf("chrome") > 0) return "Chrome"; else if(agent.indexOf("safari") > 0) return "Safari"; else if(agent.indexOf("opera") > 0) return "Opera"; else if(agent.indexOf("camino") > 0) return "Camino"; else if(agent.indexOf("gecko") > 0) return "Gecko"; else if(agent.indexOf("trident") > 0) return "Trident"; else if(agent.indexOf("mozilla") > 0) return "Mozilla"; return null; } (function () { var lastAnimate = 0; if (!("requestAnimationFrame" in self)) { self.requestAnimationFrame = self.mozRequestAnimationFrame || self.webkitRequestAnimationFrame || self.msRequestAnimationFrame || function (handler) { return setTimeout(function () { handler(lastAnimate = GetTickCount()); }, Math.max(0, 1000.0 / 60.0 - (GetTickCount() - lastAnimate))); }; } if (!("cancelAnimationFrame" in self)) { self.cancelAnimationFrame = self.mozCancelAnimationFrame || self.webkitCancelAnimationFrame || self.msCancelAnimationFrame || self.mozCancelRequestAnimationFrame || self.webkitCancelRequestAnimationFrame || self.msCancelRequestAnimationFrame || function (id) { clearTimeout(id); }; } })(); if (!("console" in self)) { //function args() { // if (arguments.length <= 0) // return undefined; // if (String.isString(arguments[0])) // return String.format.apply(null, Array.from(arguments)); // return Array.from(arguments).map(x => x.toString()).join(" "); //} self.console = { assert: function (assertion) { }, clear: function () { }, count: function (label) { }, countReset: function (label) { }, debug: function (args) { }, dir: function (object) { }, dirxml: function (object) { }, error: function (args) { return this.exception.apply(this, arguments); }, exception: function (args) { }, group: function (label) { }, groupCollapsed: function (label) { }, groupEnd: function () { }, info: function (args) { }, log: function (args) { }, profile: function (profileName) { }, profileEnd: function (profileName) { }, table: function (data) { }, time: function (label) { }, timeEnd: function (label) { }, timeLog: function (label, val) { }, timeStamp: function (label) { }, trace: function (args) { }, warn: function (args) { } }; } Object.forEachKeys = function(obj, f) { if (obj) Object.keys(obj).forEach(function(k, i) { f.call(obj, obj[k], k, i); }); } Object.asArray = function (obj, f) { if (!obj) return obj; return Object.keys(obj).map(function (k, i) { return f ? f.call(obj, obj[k], k, i) : obj[k]; }); } Object.map = function (obj, f) { if (!obj) return obj; return Object.keys(obj).reduce(function (r, k, i) { var o = {}; o[k] = f ? f.call(obj, obj[k], k, i) : obj[k]; return Object.assign(r, o); }, {}); } Object.merge = function () { function mo(ds, a) { if (a === undefined) return ds; if (!ds || a == null || a.constructor !== ({}).constructor) return a; Object.forEachKeys(a, function (ap, k) { ds[k] = mo(ds[k], ap); }); return ds; } if (arguments.length <= 0) return null; return Array.from(arguments).slice(1).reduce(mo, arguments[0]); } Object.defineOnceProperty = function (obj, propName, once) { if (once && Function.isFunction(once)) { // PS. configurable ¬° true ¤~¯à delete ¦¹ property Object.defineProperty(obj, propName, { "configurable": true, "get": function () { delete this[propName]; return this[propName] = once.call(this, propName); } }); } else obj.propName = once; } if (!Object.assign) Object.assign = function (t, s) { function mo(ds, a) { if (a === undefined) return ds; if (!ds || a == null || a.constructor !== ({}).constructor) return a; Object.forEachKeys(a, function (ap, k) { ds[k] = ap; }); return ds; } if (arguments.length <= 0) return null; return Array.from(arguments).slice(1).reduce(mo, arguments[0]); } var Location; if (Location) { Location.prototype.getParameter = function (parameterName) { var result = this.search.substr(1).split("&") .map(function (item) { return item.split("="); }) .find(function (item) { return item[0] === parameterName; }); if (result) return decodeURIComponent(result[1]); return null; } Location.prototype.pathInfo = function (exeApp) { var aPath = location.pathname.split("/"); var nPageIndex = 0; for (nPageIndex = 0; nPageIndex < aPath.length; nPageIndex++) if (aPath[nPageIndex].toLowerCase() == exeApp) return aPath.slice(nPageIndex + 1); return null; } Location.prototype.toTags = function() { if (this.hash) return decodeURIComponent(this.hash.substr(1)).split("/"); return null; } Location.prototype.fromTags = function(ptags, tag) { if (ptags == null) ptags = []; ptags = ptags.concat([tag]); this.replace("#" + ptags.join("/")); return ptags; } } if (!Array.isArray) Object.defineProperty(Array, "isArray", { value: function (v) { return v instanceof Array || v.constructor === Array; } }); if (!Array.from) Object.defineProperty(Array, "from", { value: function (arrLike) { return new Array(arrLike.length).fill().map(function (n, i) { return arrLike[i]; }); } }); if (!Array.init) Object.defineProperty(Array, "init", { value: function (size, initVal) { var tgt = new Array(size); if (Function.isFunction(initVal)) return tgt.fill().map(function (n, i) { return initVal(i); }); return tgt.fill(initVal); } }); if (!Array.prototype.equals) Object.defineProperty(Array.prototype, "equals", { value : function(another) { if (another == null) return false; if (this.length != another.length) return false; for (var i in another) { if (this[i] != another[i]) return false; } return true; } }); if (!Array.prototype.forEach) Object.defineProperty(Array.prototype, "forEach", { value: function (f) { if (f) for (var i = 0; i < this.length; i++) { f(this[i], i, this); } } }); if (!Array.prototype.mapObject) Object.defineProperty(Array.prototype, "mapObject", { value: function (f, t) { return this.reduce(function (c, x, i, a) { c[x] = f.call(t, x, i, a); return c; }, {}); } }); if (!Array.prototype.flat) Object.defineProperty(Array.prototype, "flat", { value: function (depth) { if (depth === undefined) depth = 1; return this.reduce(function (c, x) { if (!Array.isArray(x)) x = [x]; else if (depth > 1) x = x.flat(depth - 1); Array.prototype.push.apply(c, x); return c; }, []); } }); if (!Array.prototype.flatMap) Object.defineProperty(Array.prototype, "flatMap", { value: function (f, t) { return this.reduce(function (c, x, i, a) { x = f.call(t, x, i, a); if (!Array.isArray(x)) x = [x]; Array.prototype.push.apply(c, x); return c; }, []); } }); if (!Array.prototype.find) Object.defineProperty(Array.prototype, "find", { value: function (f, t) { for (var i = 0; i < this.length; i++) if (f.call(t, this[i], i, this)) return this[i]; return null; } }); if (!Array.prototype.findIndex) Object.defineProperty(Array.prototype, "findIndex", { value: function (f, t) { for (var i = 0; i < this.length; i++) if (f.call(t, this[i], i, this)) return i; return -1; } }); if (!Array.prototype.indexOf) Object.defineProperty(Array.prototype, "indexOf", { value: function (elt, from) { var len = this.length >>> 0; var from = parseInt(Number(from)) || 0; if (from < 0) from += len; for (; from < len; from++) if (from in this && this[from] === elt) return from; return -1; } }); if (!Array.prototype.findRight) Object.defineProperty(Array.prototype, "findRight", { value: function (f, t) { for (var i = this.length - 1; i >= 0; i--) if (f.call(t, this[i], i, this)) return this[i]; return null; } }); if (!Array.prototype.includes) Object.defineProperty(Array.prototype, "includes", { value: function (v) { return this.indexOf(v) >= 0; } }); if (!Array.prototype.remove) Object.defineProperty(Array.prototype, "remove", { value: function (f, t) { var result = []; var i = 0; while (i < this.length) { if (f.call(t, this[i], i, this)) result.push.apply(result, this.splice(i, 1)); else i++; } return result; } }); if (!Array.prototype.removeElement) Object.defineProperty(Array.prototype, "removeElement", { value: function (e) { var idx = this.indexOf(e); if (idx >= 0) this.splice(idx, 1); return idx; } }); if (!Array.prototype.loop) Object.defineProperty(Array.prototype, "loop", { value: function (func) { var t = this.slice(0); (function k(i) { func(i, i ? k.bind(null, t.shift()) : null); })(t.shift()) } }); if (!Array.prototype.fill) Object.defineProperty(Array.prototype, "fill", { value: function (v) { for (var i = 0; i < this.length; i++) { this[i] = v; } return this; } }); if (!Array.prototype.chunk) Object.defineProperty(Array.prototype, "chunk", { value: function (size) { return new Array.init(Math.floor(this.length / size), (function (n) { return this.slice(n * size, n * size + size); }).bind(this)); } }); if (!Array.prototype.group) Object.defineProperty(Array.prototype, "group", { value: function (id, f) { return this.reduce(function (o, x) { return !x || !x[id] ? o : Object.assign(o, { [x[id]] : (o[x[id]] || []).concat([f ? f(x) : x]) }); }, {}); } }); if (!Array.prototype.asJSON) Object.defineProperty(Array.prototype, "asJSON", { value: function (id, f) { return this.reduce(function (o, x) { var t = {}; t[x[id]] = f ? f(x) : x; return Object.assign(o || {}, t); }, null); } }); if (!("isFunction" in Function)) Function.isFunction = function (f) { return f instanceof Function || typeof f === "function"; } Object.assign(Function.prototype, { inherit: function (baseClass) { //Object.assign(this, Object.fromEntries(Object.entries(baseClass).filter(e => Object.prototype.hasOwnProperty.call(baseClass, e[0])))); //Object.getOwnPropertyNames(base).forEach(m => this[m] = base[m]); //Object.defineProperties(this, ); return Object.assign(this, { prototype: Object.defineProperties(new (Object.assign(function X() {}, { prototype: Object.create(baseClass.prototype) })), { constructor: { value: this }, base: { value: baseClass } }) }); }, derive: function (destClass) { return (destClass ?? function() {}).inherit(this); }, resources: function (props, isStatic, isWritable) { let tgt = isStatic ? this : this.prototype; props = Function.isFunction(props) ? props.call(tgt) : props; if (isWritable) Object.assign(tgt, props); else Object.defineProperties(tgt, Object.fromEntries(Object.entries(props).map(e => [e[0], { "value": e[1] }]))); return this; }, properties: function (props, isStatic) { let tgt = isStatic ? this : this.prototype; props = Function.isFunction(props) ? props.call(tgt) : props; Object.defineProperties(tgt, props); return this; }, statics: function (props) { return this.resources(props, true, true); }, constStatics: function (props) { return this.resources(props, true, false); }, members: function (props) { return this.resources(props, false, true); }, constMembers: function (props) { return this.resources(props, false, false); } }); Date.prototype.customBaseYear = 1911; Date.prototype.format = function(format) //author: meizz { if (isNaN(this.getTime())) return "NaN"; var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; var weekshort = ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']; var month = ['January', 'February', 'March', 'April', 'May', ' June', 'July', 'August', 'September', 'October', 'November', 'December']; var monthshort = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.']; var o = { "[yY]+": function(f) { return f == 1 || f == 2 ? this.getFullYear() % 100 : this.getFullYear(); }, "C+": function(f) { return this.getFullYear() - this.customBaseYear; }, "q+": function(f) { return Math.floor((this.getMonth() + 3) / 3); }, //quarter "M+": function(f) { return f == 4 ? month[this.getMonth()] : f == 3 ? monthshort[this.getMonth()] : this.getMonth() + 1; }, //month "[dD]+": function(f) { return f == 4 ? week[this.getDay()] : f == 3 ? weekshort[this.getDay()] : this.getDate(); }, //day "h+": function(f) { return (this.getHours() - 1) % 12 + 1; }, //hour "H+": function(f) { return this.getHours(); }, //hour "m+": function(f) { return this.getMinutes(); }, //minute "s+": function(f) { return this.getSeconds(); }, //second "S": function(f) { return this.getMilliseconds(); }, //millisecond } var mtchs = []; for (var k in o) { var v = o[k]; var re = new RegExp("(" + k + ")", "g"); var arr = null; while ((arr = re.exec(format)) != null) { var m = { s: arr.index, l: arr[0].length }; var d = v.call(this, m.l); if (m.l > 1 && !(d instanceof String)) d = ("0000" + d).substr(4 - Math.max(0, m.l - ("" + d).length)) m.v = d; if (d) mtchs.push(m); } } mtchs.sort(function (a, b) { return a.s > b.s ? -1 : 1; }); mtchs.forEach(function (m) { format = format.substr(0, m.s) + m.v + format.substr(m.s + m.l); }); return format; } Date.prototype.toString = function() { return this.format("yyyy/MM/dd"); } Date.prototype.addDiff = function (type, diff) { if (isNaN(this.getTime())) return this; switch (type) { case "y": return new Date(this.getFullYear() + diff, this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds()); case "M": var nmth = (this.getMonth() + diff) % 12 var ndt = new Date(this.getFullYear(), this.getMonth() + diff, this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds()); while (ndt.getMonth() != nmth) ndt = ndt.addDiff("d", -1); return ndt; case "d": return new Date(this.getTime() + diff * 24 * 3600000); case "H": return new Date(this.getTime() + diff * 3600000); case "m": return new Date(this.getTime() + diff * 60000); case "s": return new Date(this.getTime() + diff * 1000); } return this; } Date.prototype.diff = function (type, other) { if (isNaN(this.getTime()) || isNaN(other.getTime())) return this; var diff = 0 switch (type) { case "y": diff = other.getFullYear() - this.getFullYear(); break; case "M": diff = other.getMonth() - this.getMonth(); break; case "d": return Math.floor((other.getTime() - this.getTime()) / 86400000); case "H": return Math.floor((other.getTime() - this.getTime()) / 3600000); case "m": return Math.floor((other.getTime() - this.getTime()) / 60000); case "s": return Math.floor((other.getTime() - this.getTime()) / 1000); } if (diff == 0) return 0; var n = other.getTime() - this.addDiff(type, diff).getTime(); return diff + (n * diff >= 0 ? 0 : diff > 0 ? -1 : 1); } if (!('sinh' in Math)) Math.sinh = function(x) {var y = Math.exp(x); return (y - 1 / y) / 2;} if (!('cosh' in Math)) Math.cosh = function(x) {var y = Math.exp(x); return (y + 1 / y) / 2;} if (!('limits' in Math)) Math.limits = function (v, minv, maxv) { return Math.max(minv, Math.min(maxv, v)); } if (!('hypot' in Math)) Math.hypot = function () { var dSum = 0; for (var i in arguments) dSum += arguments[i] * arguments[i]; return Math.sqrt(dSum); }; if (!('_hypot' in Math)) Math._hypot = Math.hypot; if (!('log10' in Math)) Math.log10 = function (v) { return Math.log(v) / Math.LN10; } if (!("isString" in String)) String.isString = function (v) { return (typeof v === "string" || v instanceof String); } if (!("isURL" in String)) String.isURL = function (v) { return String.isString(v) && (/^(blob:)?\w+:\/\//.test(v) || /^data:(\w+)?(;base64)?,/.test(v)); } if (!("format" in String)) String.format = function (format) { var o = { "o": function (v) { return JSON.stringify(v); }, "O": function (v) { return JSON.stringify(v); }, "d": function (v) { return parseInt(v).toString(); }, "i": function (v) { return parseInt(v).toString(); }, "s": function (v) { return v.toString(); }, "f": function (v, d) { return parseFloat(v).toFixed(d); }, } var exp = "(%([.](\\d+))?(" + Object.keys(o).join("|") + "))"; console.log(exp); var mtchs = []; var re = new RegExp(exp, "g"); var i = 1; var arr = null; while ((arr = re.exec(format)) != null) { var v = o[arr[4]]; var m = { s: arr.index, l: arr[0].length, v: v.call(this, arguments[i], parseInt(arr[3])) }; console.log(arr, arguments[i], m); i++; if (m.v) mtchs.push(m); } mtchs.sort(function (a, b) { return a.s > b.s ? -1 : 1; }); mtchs.forEach(function (m) { format = format.substr(0, m.s) + m.v + format.substr(m.s + m.l); }); return format; } if (!("startsWith" in String.prototype)) String.prototype.startsWith = function (v) { return this.substr(0, v.length) === v; } if (!("format" in String.prototype)) String.prototype.format = function () { return String.format.apply(null, [this].concat(Array.from(arguments))); } if (!("isNumber" in Number)) Number.isNumber = function (v) { return (typeof v === "number" || v instanceof Number) && !isNaN(v); } if (!("text" in Blob.prototype)) Blob.prototype.text = function () { var reader = new FileReader(); reader.onload = function (x) { Promise.resolve(x.target.result); }; reader.onerror = function (e) { Promise.reject(e); }; reader.readAsText(this); } if (!("arrayBuffer" in Blob.prototype)) Blob.prototype.arrayBuffer = function () { var reader = new FileReader(); reader.onload = function (x) { Promise.resolve(x.target.result); }; reader.onerror = function (e) { Promise.reject(e); }; reader.readAsArrayBuffer(this); } if (!("dataURL" in Blob.prototype)) Blob.prototype.dataURL = function () { var reader = new FileReader(); reader.onload = function (x) { Promise.resolve(x.target.result); }; reader.onerror = function (e) { Promise.reject(e); }; reader.readAsDataURL(this); } var HTMLElement; var DOMTokenList; if (HTMLElement && !("classList" in HTMLElement.prototype)) Object.defineProperty(HTMLElement.prototype, "classList", { get: function () { var clsTokens = (this.getAttribute("class") || "").split(" "); var elem = this; return Object.defineProperty( Object.defineProperty({ add: function () { clsTokens = clsTokens.concat(Array.from(arguments).filter(c => !this.contains(c))); elem.setAttribute("class", clsTokens.join(" ")); }, remove: function () { var cs = Array.from(arguments).filter(c => this.contains(c)); clsTokens = clsTokens.filter(c => !cs.contains(c)); elem.setAttribute("class", clsTokens.join(" ")); }, toggle: function (token, force) { var cur = this.contains(token); if (force === cur) return cur; if (cur) this.remove(token) else this.add(token); return !cur; }, contains: function (token) { return clsTokens.indexOf(token) >= 0; }, forEach: function () { clsTokens.forEach.apply(clsTokens, arguments); }, replace: function (oldToken, newToken) { this.remove(oldToken); this.add(newToken); }, switch: function (v, vs) { this.remove.apply(this, vs); this.add(v); } }, "length", { get: function () { return clsTokens.length; } }), "value", { get: function () { return clsTokens.join(" "); }, set: function (newValue) { clsTokens = (newValue || "").split(" "); elem.setAttribute("class", clsTokens.join(" ")); } }); } }); else if (DOMTokenList && !("switch" in DOMTokenList.prototype)) Object.defineProperty(DOMTokenList.prototype, "switch", { value: function (v, vs) { this.remove.apply(this, vs); this.add(v); } }); if (HTMLElement && !("getBoundingClientRect" in HTMLElement.prototype)) Object.defineProperty(HTMLElement.prototype, "getBoundingClientRect", { value: function () { return { x: this.clientLeft, y: this.clientTop, width: this.clientWidth, height: this.clientHeight, left: this.clientLeft, top: this.clientTop, right: this.clientLeft + this.clientWidth, bottom: this.clientTop + this.clientHeight, } } }); function Color() { var m_R = 0; var m_G = 0; var m_B = 0; var m_A = 255; function parseNumber(v) { if (typeof v === "string" || v instanceof String) { if (v.substr(0, 1) == '#') return parseInt(v.substr(1), 16); else if (v.substr(0, 2) == '0x') return parseInt(v.substr(2), 16); return parseFloat(v); } return v; } function ArrayValue(valarr, hex) { m_R = valarr[0]; m_G = valarr[1]; m_B = valarr[2]; if (valarr.length > 3) m_A = valarr[3] * (hex ? 1 : 255); else m_A = 255; } this.fromString = function(arg) { if (!arg || arg.length == 0) return this; var hex = (arg.substr(0, 1) == '#'); var fac = 1; var valarr = null; if (hex) { valarr = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i.exec(arg); if (valarr == null) valarr = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(arg); else fac = 0x11; } else { valarr = /^rgb\(?\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)?$/.exec(arg); if (valarr == null) valarr = /^rgba\(?\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)?$/.exec(arg); } var radix = (hex ? 16 : 10); if (valarr != null) ArrayValue(valarr.filter(function (x, i) { return i != 0 && x; }).map(function (v) { return parseInt(v, radix) * fac; }), hex); return this; } this.fromRGB = function(arg) { if (arguments.length > 1) ArrayValue(Array.from(arguments).map(parseNumber), false); else if (typeof arg === "array" || arg instanceof Array) ArrayValue(arg.map(parseNumber), false); else { if ("a" in arg) m_A = parseNumber(arg.a) * 255; if ("r" in arg) m_R = parseNumber(arg.r); if ("g" in arg) m_G = parseNumber(arg.g); if ("b" in arg) m_B = parseNumber(arg.b); } return this; } this.fromHSV = function(arg) { if (arguments.length === 3) arg = { h: parseNumber(arguments[0]), s: parseNumber(arguments[1]), v: parseNumber(arguments[2]) }; else if (typeof arg === "array" || arg instanceof Array) arg = { h: parseNumber(arg[0]), s: parseNumber(arg[1]), v: parseNumber(arg[2]) }; arg.h /= 360; arg.s /= 100; arg.v /= 100; var i = Math.floor(arg.h * 6); var f = arg.h * 6 - i; var vals = [1 - (1 - f) * arg.s, 1 - arg.s, 1 - f * arg.s].slice(i % 2, i % 2 + 2); vals = [].concat(1, vals, 1, vals).slice(3 - Math.round((i % 6) / 2)); m_R = Math.min(255, Math.round(vals[0] * arg.v * 256)); m_G = Math.min(255, Math.round(vals[1] * arg.v * 256)); m_B = Math.min(255, Math.round(vals[2] * arg.v * 256)); return this; } this.asArray = function () { return [m_R, m_G, m_B, m_A]; } this.toHEX = function() { var hex = '#' + (0x1000000 + (((m_R % 0x100) << 16) | ((m_G % 0x100) << 8) | (m_B % 0x100))).toString(16).slice(1).toUpperCase(); if (m_A != 255) return hex + (0x100 + (Math.round(m_A) % 0x100)).toString(16).slice(1).toUpperCase(); else return hex; } this.toCSS = function () { if (m_A != 255) return "rgba(" + m_R + "," + m_G + "," + m_B + "," + (m_A / 255) + ")"; return "rgb(" + m_R + "," + m_G + "," + m_B + ")"; } this.toARGB = function() { return { r: m_R, g: m_G, b: m_B, a: m_A / 255 }; } this.toHSV = function() { var max = Math.max(Math.max(m_R, m_G), m_B); var min = Math.min(Math.min(m_R, m_G), m_B); var d = max - min; var h = (d == 0 ? 0 : max == m_R ? (m_G - m_B) / d : max == m_G ? (m_B - m_R) / d + 2 : max == m_B ? (m_R - m_G) / d + 4 : 0) / 6; if (h < 0) h += 1; return { h: h * 360, s: (max === 0 ? 0 : d / max) * 100, v: max / 255 * 100 }; } } Object.defineProperty(Color.prototype, "toConstract", { value: function () { if (this.luminance < 0.179128784747792) return new Color().fromRGB(255, 255, 255); return new Color().fromRGB(0, 0, 0); } }); Object.defineProperty(Color.prototype, "luminance", { get: function () { var rgba = this.toARGB(); var r = { r: .2126, g: .7152, b: .0722}; return Object.keys(r).reduce(function(o, k) { var v = rgba[k] / 255; return o + r[k] * (v < .03928 ? v / 12.92 : Math.pow((v + .055) / 1.055, 2.4)); }, 0); } }); Object.defineProperty(Color.prototype, "interpolation", { value: function (target, t) { var o = this.toARGB(); var s = target.toARGB(); return new Color().fromRGB(o.r + (s.r - o.r) * t, o.g + (s.g - o.g) * t, o.b + (s.b - o.b) * t, o.a + (s.a - o.a) * t); } }); function GetOffset(pObj) { var dX = 0; var dY = 0; while (pObj != null) { if ("offsetLeft" in pObj) dX += pObj.offsetLeft - pObj.scrollLeft; if ("offsetTop" in pObj) dY += pObj.offsetTop - pObj.scrollTop; pObj = pObj.offsetParent; } return {X:dX, Y:dY}; } function FuncAdapter(pCaller, pFunc) { return pFunc.bind(pCaller); } //return function(pEvent) { return pFunc.call(pCaller, pEvent); }; function SystemEvent(targetObj, actEvent) { return Object.keys(targetObj).contains("on" + actEvent); } function AttachEvent(targetObj, actEvent, actFunc, useCapture) { if (targetObj.addEventListener) { if (actEvent == "mousewheel" && DeviceTest() == 'Firefox') actEvent = "DOMMouseScroll"; if (useCapture) targetObj.ownerDocument.addEventListener(actEvent, actFunc, useCapture); else targetObj.addEventListener(actEvent, actFunc, useCapture); } else if (targetObj.attachEvent) { if (SystemEvent(targetObj, actEvent)) targetObj.attachEvent(se, actFunc); else { if (!targetObj[actEvent]) targetObj[actEvent] = 1; actFunc._wrapfunc = function (pEvent) { if (pEvent.propertyName == actEvent) actFunc(pEvent); } targetObj.attachEvent("onpropertychange", actFunc._wrapfunc); } if (useCapture) targetObj.setCapture(); } return { raise: function(customDetail) { FireEvent(targetObj, actEvent, customDetail); }, detach: function() { DetachEvent(targetObj, actEvent, actFunc, useCapture); }, } } function DetachEvent(targetObj, actEvent, actFunc, useCapture) { if (targetObj.removeEventListener) { if (actEvent == "mousewheel" && DeviceTest() == 'Firefox') actEvent = "DOMMouseScroll"; if (useCapture) targetObj.ownerDocument.removeEventListener(actEvent, actFunc, useCapture); else targetObj.removeEventListener(actEvent, actFunc, useCapture); } else if (targetObj.detachEvent) { targetObj.detachEvent("on" + actEvent, actFunc); if (actFunc._wrapfunc) targetObj.detachEvent("onpropertychange", actFunc._wrapfunc); if (useCapture) targetObj.releaseCapture(); } } function FireEvent(targetObj, actEvent, customDetail) { let pDoc = targetObj.ownerDocument || targetObj.document || null; let pEvent = null; if (targetObj.dispatchEvent) { if (actEvent == "mousewheel" && DeviceTest() == 'Firefox') actEvent = "DOMMouseScroll"; if (!!Event) { if (customDetail instanceof Event) pEvent = !customDetail.target ? customDetail : new customDetail.constructor(customDetail.type, customDetail); else if (customDetail && CustomEvent) pEvent = Object.assign(new CustomEvent(actEvent, { "detail": customDetail, "bubbles": false, "cancelable": false }), customDetail); else pEvent = new Event(actEvent, { "bubbles": false, "cancelable": false }); } else if (customDetail != null) { pEvent = pDoc?.createEvent("CustomEvent"); pEvent?.initCustomEvent(actEvent, false, false, customDetail); } else { pEvent = pDoc?.createEvent("UIEvents"); pEvent?.initEvent(actEvent, false, false); } if (pEvent) { targetObj.dispatchEvent(pEvent); if (pEvent.cancelBubble && customDetail instanceof Event) customDetail.stopPropagation(); } } else if (targetObj.fireEvent && pDoc) { //targetObj[actEvent]++; pEvent = pDoc?.createEventObject(); if (pEvent) targetObj.fireEvent("on" + actEvent, pEvent); } } function Inherit(pParent, pChild) { if (!pParent.Inherits) { pParent.Inherits = new Array(); pParent.ParseTest = function (testElem) { var pInhs = pParent.Inherits; if (pInhs) { for (var i in pInhs) { if (pInhs[i].ParseTest) { var pObj = pInhs[i].ParseTest(testElem); if (pObj != null) return pObj; } } } if (pParent.TestTags) return pParent.TestTags(testElem); return null; } } pParent.Inherits.push(pChild); } function Implement(pBase, parseTags) { pBase.ParseTest = function (testElem) { return pBase.TestTags(testElem); } pBase.TestTags = function (testElem) { if (testElem == null) return null; var testTag = testElem.localName; var testNSURI = testElem.namespaceURI; if (parseTags.constructor != Array) parseTags = [parseTags]; for (var i in parseTags) { var pTag = parseTags[i]; if (pTag.constructor == String) { if (testTag == pTag) return new pBase(testElem); } else { if (testTag == pTag.tag && testNSURI == pTag.nsuri) return new pBase(testElem); } } return null; } } function SetObj(pObj1, pObj2) { if (pObj2 == null) return pObj1; return pObj2; } function AddObjArray(pObjs, pObj) { if (pObj != null) { if (pObjs == null) pObjs = new Array(); pObjs.push(pObj) } return pObjs; } function FormatDegrees(dDegrees, positive, negative, e) { var v = Math.abs(dDegrees); var Deg = Math.floor(v); v = (v - Deg) * 60; var Minute = Math.floor(v); var Second = (v - Minute) * 60; var strTmp = Deg + "\u02DA"; if (Minute != 0 || Second != 0) { strTmp += Minute + "\u2019"; if (Second != 0) { if (Math.abs(Second - Math.floor(Second)) < 0.01) strTmp += Math.floor(Second) + "\u201D"; else strTmp += Second.toFixed(e || 2) + "\u201D"; } } return strTmp + (dDegrees < 0 ? negative : positive); } function GetTickCount() { var pDate = new Date(); var ntick = pDate.valueOf(); delete pDate; return ntick; } var SuperGIS = new function () { var _NS_ = this; this.Debug = function (bDebug) { var pErrorFunc = function (sMsg, sUrl, sLine) { console.log("Error: " + sMsg + "\r\nLine: " + sLine + "\r\nURL: " + sUrl); } var pUnload = function () { DetachEvent(window, "error", pErrorFunc); DetachEvent(window, "unload", pUnload); } if (bDebug) { AttachEvent(window, "unload", pUnload); AttachEvent(window, "error", pErrorFunc); } else { pUnload(); } } var m_strServicePath = null; var m_Modules = {}; Object.defineProperty(this, 'ServicePath', { get: function() { return m_strServicePath; } }); this.Initialize = function (strServicePath, funcCallback) { m_strServicePath = strServicePath; this.LoadModules(["scripts/AjaxAgent.js", "scripts/CoordSys.js", "scripts/Projection.js", "scripts/Base64.js", "scripts/Geometry.js", "scripts/Graphic.js", "scripts/Render.js", "scripts/EPSG.js", "scripts/Tracker.js", "scripts/Window.js", "scripts/Interpolation.js", "scripts/earcut.js", "scripts/suncalc.js", "scripts/pbf.js", "scripts/MVTData.js", "scripts/MVTDocument.js", "scripts/OGC.js", "scripts/DDDCore.js"], (function () { this.LoadModules(["scripts/KML.js", "scripts/Collada.js"], funcCallback); }).bind(this)); } function LoadScript(sSrc, pFunc) { var pScp = document.createElement("script"); if (pFunc) { function readystatechanged() { if (pScp.readyState == "loaded") Loaded(); } function Loaded() { pFunc.call(pScp); DetachEvent(pScp, "readystatechange", readystatechanged, false); DetachEvent(pScp, "load", Loaded, false); } AttachEvent(pScp, "readystatechange", readystatechanged, false); AttachEvent(pScp, "load", Loaded, false); } document.head.appendChild(pScp); pScp.type = "text/javascript"; pScp.src = sSrc; return pScp; } this.LoadModule = function (strScriptName, funcCallback) { if (self.importScripts) { self.importScripts(m_strServicePath + strScriptName); funcCallback?.call(null); return; } if (m_Modules[strScriptName]) return funcCallback?.call(m_Modules[strScriptName]); m_Modules[strScriptName] = LoadScript(m_strServicePath + strScriptName, funcCallback); } this.LoadModules = function (strScriptNames, funcCallback) { if (!Array.isArray(strScriptNames)) strScriptNames = [strScriptNames]; strScriptNames = strScriptNames.filter(function(s) { return typeof s === "string" || s instanceof String; }); var n = strScriptNames.length; function Loaded() { n--; if (n <= 0 && funcCallback) funcCallback(); } strScriptNames.forEach((function (s) { this.LoadModule(s, Loaded); }).bind(this)) } this._EventTarget = function (pNode) { if (this.addEventListener && this.removeEventListener) return; let _InnerEvent = null; let pEventObj = pNode; if (pEventObj == null) pEventObj = _InnerEvent = new EventTarget(); this.destroy = function () { pEventObj = null; if (_InnerEvent == null) return; delete _InnerEvent; _InnerEvent = null; } this.addEventListener = EventTarget.prototype.addEventListener.bind(pEventObj); this.removeEventListener = EventTarget.prototype.removeEventListener.bind(pEventObj); this.dispatchEvent = EventTarget.prototype.dispatchEvent.bind(pEventObj); this.raiseEvent = function (actEvent, customDetail) { FireEvent(pEventObj, actEvent, customDetail); }; } this._EnumType = function _EnumType(sText) { var m_value = 0; //var m_text = enumArray[0]; //this.getText = function() {return m_text;}; //this.setText = function(val) {m_text = val;}; this.toString = function () { return this.constructor._enum[m_value]; }; this.valueOf = function () { return m_value; } if (sText == null) return; for (var i in this.constructor._enum) { if (sText == this.constructor._enum[i]) { m_value = i; //m_text = sText; break; } } }; this._EnumType.Enum = function (eValues, pEnum) { if (pEnum == null) pEnum = function (sValue) { SuperGIS._EnumType.call(this, sValue); }; else if (pEnum.constructor == String) pEnum = function () { SuperGIS._EnumType.call(this, pEnum); }; //pEnum = SuperGIS._EnumType.derive(pEnum); pEnum._enum = eValues; for (var i in eValues) { if (eValues[i].constructor == String) pEnum[eValues[i]] = i; else pEnum[eValues[i].name] = eValues[i].value; } return pEnum; } this._ListType = function (sText, separator, funcItem) { if (sText == null) return; var m_list = sText.split(separator); for (var i in m_list) { var str = m_list[i]; if (str.length > 0) { if (funcItem) str = funcItem(str); if (str != null) this.push(str); } } } this.AnimationFrame = function (aniFunc) { var pThis = this; var bContinue = false; var post = self.requestAnimationFrame; this.action = function () { if (bContinue) return; bContinue = true; tick(); } this.cut = function () { bContinue = false; } this.isRunning = function () { return bContinue; } function tick() { if (!bContinue) return; post(tick); if (aniFunc) aniFunc(pThis); } } this.AlphaAnimation = function (pDiv, minAlpha, maxAlpha, duration) { var divalphaT = minAlpha; var divalpha = minAlpha; var speed = 1; if (duration) speed = (maxAlpha - minAlpha) / duration; function setDivAlpha(opac) { divalpha = opac; if ("opacity" in pDiv.style) pDiv.style.opacity = opac; else if ("MozOpacity" in pDiv.style) pDiv.style.MozOpacity = opac; else if ("filter" in pDiv.style) pDiv.style.filter = 'Alpha(Opacity=' + (opac * 100) + ')'; } setDivAlpha(minAlpha); var lastTime = 0; function resetTime() { lastTime = (new Date()).getTime(); } resetTime(); var alphaact = new _NS_.AnimationFrame(function (ani) { var dt = new Date().getTime(); var dx = (dt - lastTime) / 1000; lastTime = dt; var i = dx * speed; if (Math.abs(divalphaT - divalpha) < i) { ani.cut(); setDivAlpha(divalphaT) return; } if (divalphaT < divalpha) setDivAlpha(divalpha - i); else setDivAlpha(divalpha + i); }); function funcMouseOver() { divalphaT = maxAlpha; resetTime(); alphaact.action(); } function funcMouseOut() { divalphaT = minAlpha; resetTime(); alphaact.action(); } AttachEvent(pDiv, "mouseover", funcMouseOver, false); AttachEvent(pDiv, "mouseout", funcMouseOut, false); var bEnable = true; this.getEnable = function () { return bEnable; }; this.setEnable = function (v) { if (bEnable == v) return; bEnable = v; if (bEnable) { AttachEvent(pDiv, "mouseover", funcMouseOver, false); AttachEvent(pDiv, "mouseout", funcMouseOut, false); setDivAlpha(minAlpha); } else { DetachEvent(pDiv, "mouseover", funcMouseOver, false); DetachEvent(pDiv, "mouseout", funcMouseOut, false); setDivAlpha(1); } }; } this.RecyclingArray = function () { var m_LastID = 0; var m_IDs = []; var m_Datas = []; this.push = function (pData) { if (pData == null) return -1; var nID = m_IDs.shift(); if (nID == undefined) nID = m_LastID++; m_Datas[nID] = pData; return nID; } this.pop = function (nID, bReserve) { if (nID < 0) return null; var pData = m_Datas[nID]; if (!bReserve) { m_Datas[nID] = null; m_IDs.push(nID); } return pData; } } this.WorkThread = function (pWorkFunc, pInitFunc, pFinalFunc) { var ThreadCallback = new _NS_.RecyclingArray(); var m_pWorker = null; var _ObjectURL = null; var m_Imports = []; this.Import = function (sScript) { var url = document.createElement("a"); url.href = sScript; m_Imports.push("importScripts('" + url.href + "');\r\n"); this.Close(); } var _Initialize = function () { self.window = self; self.addEventListener('message', function (e) { var pArgs = e.data.data; if (pArgs.constructor != Array) pArgs = [pArgs]; var pCall = { "handled": false, "pass": function (pData, transfer) { postMessage({ '_ID': e.data._ID, '_Reserve': true, 'data': pData }, transfer); }, "return": function (pData, transfer) { this.handled = true; postMessage({ '_ID': e.data._ID, 'data': pData }, transfer); } } var pData = self[e.data._Name || '_'].apply(pCall, pArgs); if (!pCall.handled) pCall.return(pData); }, false); //self._Works = {}; } var m_Works = ["(" + _Initialize.toString() + ")();\r\n"]; if (pInitFunc != null) m_Works.push("(" + pInitFunc.toString() + ")();\r\n"); m_Works.push("self._close = function() {self.close();};\r\n"); this.AddWork = function (sName, pFunc) { m_Works.push("self." + (sName == null ? "_" : sName) + " = " + pFunc.toString() + ";\r\n"); this.Close(); }; this.Create = function () { var pScripts = m_Works; if (pFinalFunc != null) pScripts = m_Works.concat("postMessage({ '_ID': -2, 'data': null });\r\n"); if (_ObjectURL) URL.revokeObjectURL(_ObjectURL); _ObjectURL = URL.createObjectURL(new Blob(m_Imports.concat(pScripts), { type: "text/javascript" })) m_pWorker = new Worker(_ObjectURL); AttachEvent(m_pWorker, "message", function (e) { var pMsg = e.data; switch (pMsg._ID) { case -2: if (pFinalFunc != null) pFinalFunc.call(null, pMsg.data); break; case -1: break; default: { var pCallback = ThreadCallback.pop(pMsg._ID, pMsg._Reserve); if (pCallback != null && pCallback.Function != null) pCallback.Function.call(pCallback.Caller, pMsg.data); } } }, false) } this.Close = function () { if (m_pWorker != null) this.Post("_close", null, m_pWorker, function () { this.terminate(); }); m_pWorker = null; if (_ObjectURL) URL.revokeObjectURL(_ObjectURL); _ObjectURL = null; } this.Post = function (sName, pData, pCaller, pFunction, transfer) { if (m_pWorker == null) this.Create(); var pMsg = { "_Name": sName, "_ID": ThreadCallback.push({ "Caller": pCaller, "Function": pFunction }), "data": pData }; m_pWorker.postMessage(pMsg, transfer); } if (pWorkFunc != null) this.AddWork(null, pWorkFunc); } this.UnblockQueue = function () { var buffered = []; var bufferTimeout = null; var bufferProcess = function () { var buf = buffered.shift(); if (!buf) { bufferTimeout = null; return; } if (!!buf.func) buf.func(buf.data); bufferTimeout = setTimeout(bufferProcess, 0); } this.push = function (func, data) { buffered.push({ data: data, func: func }); if (bufferTimeout == null) bufferTimeout = setTimeout(bufferProcess, 0); } } this.DelayRun = function() { let handle = null; this.run = function(functionRef, delay, override) { if (handle) { if (!override) return; clearTimeout(handle); } handle = setTimeout(function () { if (override) handle = null; functionRef?.call(); handle = null; }, delay ?? 0); } } }