var $hx_exports = typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this; (function ($global) { "use strict"; $hx_exports["xrfragment"] = $hx_exports["xrfragment"] || {}; $hx_exports["xrfragment"]["Query"] = $hx_exports["xrfragment"]["Query"] || {}; var EReg = function(r,opt) { this.r = new RegExp(r,opt.split("u").join("")); }; EReg.__name__ = true; EReg.prototype = { match: function(s) { if(this.r.global) { this.r.lastIndex = 0; } this.r.m = this.r.exec(s); this.r.s = s; return this.r.m != null; } ,split: function(s) { var d = "#__delim__#"; return s.replace(this.r,d).split(d); } }; var HxOverrides = function() { }; HxOverrides.__name__ = true; HxOverrides.cca = function(s,index) { var x = s.charCodeAt(index); if(x != x) { return undefined; } return x; }; HxOverrides.substr = function(s,pos,len) { if(len == null) { len = s.length; } else if(len < 0) { if(pos == 0) { len = s.length + len; } else { return ""; } } return s.substr(pos,len); }; HxOverrides.now = function() { return Date.now(); }; Math.__name__ = true; var Reflect = function() { }; Reflect.__name__ = true; Reflect.field = function(o,field) { try { return o[field]; } catch( _g ) { return null; } }; Reflect.fields = function(o) { var a = []; if(o != null) { var hasOwnProperty = Object.prototype.hasOwnProperty; for( var f in o ) { if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) { a.push(f); } } } return a; }; var Std = function() { }; Std.__name__ = true; Std.string = function(s) { return js_Boot.__string_rec(s,""); }; Std.parseInt = function(x) { if(x != null) { var _g = 0; var _g1 = x.length; while(_g < _g1) { var i = _g++; var c = x.charCodeAt(i); if(c <= 8 || c >= 14 && c != 32 && c != 45) { var nc = x.charCodeAt(i + 1); var v = parseInt(x,nc == 120 || nc == 88 ? 16 : 10); if(isNaN(v)) { return null; } else { return v; } } } } return null; }; var StringTools = function() { }; StringTools.__name__ = true; StringTools.isSpace = function(s,pos) { var c = HxOverrides.cca(s,pos); if(!(c > 8 && c < 14)) { return c == 32; } else { return true; } }; StringTools.ltrim = function(s) { var l = s.length; var r = 0; while(r < l && StringTools.isSpace(s,r)) ++r; if(r > 0) { return HxOverrides.substr(s,r,l - r); } else { return s; } }; StringTools.rtrim = function(s) { var l = s.length; var r = 0; while(r < l && StringTools.isSpace(s,l - r - 1)) ++r; if(r > 0) { return HxOverrides.substr(s,0,l - r); } else { return s; } }; StringTools.trim = function(s) { return StringTools.ltrim(StringTools.rtrim(s)); }; StringTools.replace = function(s,sub,by) { return s.split(sub).join(by); }; var Test = function() { }; Test.__name__ = true; Test.main = function() { Test.test([{ fn : "url", expect : { fn : "equal.string", input : "pos", out : "flop"}, data : "http://foo.com?foo=1#pos=flop"},{ fn : "url", expect : { fn : "equal.xy", input : "pos", out : "1.22.2"}, label : "a equal.xy", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "drop incompatible type", data : "http://foo.com?foo=1#prio=foo"},{ fn : "url", expect : { fn : "equal.multi", input : "pos", out : "c|d|1,2,3"}, label : "b equal.multi", data : "http://foo.com?foo=1#pos=c|d|1,2,3"}]); Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : "class:bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, label : ".bar shorthand", data : ".bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : false}, data : ".bar -.foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, data : ".bar -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","bar"], out : true}, data : ".bar -.bar .bar"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo bar:>5 .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["class","foo"], out : true}, label : "class:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : false}, label : "!id:foo", data : ".foo -.foo .foo"},{ fn : "query", expect : { fn : "testProperty", input : ["id","foo"], out : true}, label : "id:foo?", data : "foo -foo foo"}]); Test.test([{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : true}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","10"], out : false}, data : "price:>=15"},{ fn : "query", expect : { fn : "testProperty", input : ["price","4"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : false}, data : "price:>=5"},{ fn : "query", expect : { fn : "testProperty", input : ["price","1"], out : false}, label : "price=1", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","0"], out : true}, label : "price=0", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["price","6"], out : true}, label : "price=6", data : "price:>=5 price:0"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : true}, data : "tag:foo"},{ fn : "query", expect : { fn : "testProperty", input : ["tag","foo"], out : false}, data : "-tag:foo"},{ fn : "query", expect : { fn : "testPropertyExclude", input : ["tag","foo"], out : true}, label : "testExclude", data : "-tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ price : 5}], out : true}, data : ".foo price:5 -tag:foo"},{ fn : "query", expect : { fn : "test", input : [{ tag : "foo", price : 5}], out : false}, data : ".foo price:5 -tag:foo"}]); if(Test.errors > 1) { console.log("src/Test.hx:21:","\n-----\n[ ❌] " + Test.errors + " errors :/"); } }; Test.test = function(spec) { var Query = xrfragment_Query; var _g = 0; var _g1 = spec.length; while(_g < _g1) { var i = _g++; var q = null; var res = null; var valid = false; var item = spec[i]; if(item.fn == "query") { q = new xrfragment_Query(item.data); } if(item.fn == "url") { res = xrfragment_Url.parse(item.data); } if(item.expect.fn == "test") { valid = item.expect.out == q.test(item.expect.input[0]); } if(item.expect.fn == "testProperty") { valid = item.expect.out == q.testProperty(item.expect.input[0],item.expect.input[1]); } if(item.expect.fn == "testPropertyExclude") { valid = item.expect.out == q.testProperty(item.expect.input[0],item.expect.input[1],true); } if(item.expect.fn == "testParsed") { valid = item.expect.out == Object.prototype.hasOwnProperty.call(res,item.expect.input); } if(item.expect.fn == "equal.string") { valid = item.expect.out == res[item.expect.input].string; } if(item.expect.fn == "equal.xy") { valid = item.expect.out == Std.string(res[item.expect.input].x) + Std.string(res[item.expect.input].y); } if(item.expect.fn == "equal.multi") { valid = Test.equalMulti(res,item); } var ok = valid ? "[ ✔ ] " : "[ ❌] "; console.log("src/Test.hx:41:",ok + Std.string(item.fn) + ": '" + Std.string(item.data) + "'" + (item.label ? " (" + (item.label ? item.label : item.expect.fn) + ")" : "")); if(!valid) { Test.errors += 1; } } }; Test.equalMulti = function(res,item) { var target = res[item.expect.input]; var str = ""; if(!target) { return false; } var _g = 0; var _g1 = target.args.length; while(_g < _g1) { var i = _g++; str = str + "|" + target.args[i].string; } str = HxOverrides.substr(str,1,null); if(item.expect.out) { return str == item.expect.out; } else { return false; } }; var haxe_iterators_ArrayIterator = function(array) { this.current = 0; this.array = array; }; haxe_iterators_ArrayIterator.__name__ = true; haxe_iterators_ArrayIterator.prototype = { hasNext: function() { return this.current < this.array.length; } ,next: function() { return this.array[this.current++]; } }; var js_Boot = function() { }; js_Boot.__name__ = true; js_Boot.__string_rec = function(o,s) { if(o == null) { return "null"; } if(s.length >= 5) { return "<...>"; } var t = typeof(o); if(t == "function" && (o.__name__ || o.__ename__)) { t = "object"; } switch(t) { case "function": return ""; case "object": if(((o) instanceof Array)) { var str = "["; s += "\t"; var _g = 0; var _g1 = o.length; while(_g < _g1) { var i = _g++; str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s); } str += "]"; return str; } var tostr; try { tostr = o.toString; } catch( _g ) { return "???"; } if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { var s2 = o.toString(); if(s2 != "[object Object]") { return s2; } } var str = "{\n"; s += "\t"; var hasp = o.hasOwnProperty != null; var k = null; for( k in o ) { if(hasp && !o.hasOwnProperty(k)) { continue; } if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { continue; } if(str.length != 2) { str += ", \n"; } str += s + k + " : " + js_Boot.__string_rec(o[k],s); } s = s.substring(1); str += "\n" + s + "}"; return str; case "string": return o; default: return String(o); } }; var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { }; xrfragment_Parser.__name__ = true; xrfragment_Parser.parse = function(key,value,resultMap) { var Frag_h = Object.create(null); Frag_h["pos"] = xrfragment_Type.isVector; Frag_h["prio"] = xrfragment_Type.isInt; if(Object.prototype.hasOwnProperty.call(Frag_h,key)) { if(Frag_h[key].match(value)) { var v = new xrfragment_Value(); xrfragment_Parser.guessType(v,value); if(value.split("|").length > 1) { v.args = []; var args = value.split("|"); var _g = 0; var _g1 = args.length; while(_g < _g1) { var i = _g++; var x = new xrfragment_Value(); xrfragment_Parser.guessType(x,args[i]); v.args.push(x); } } resultMap[key] = v; } else { console.log("src/xrfragment/Parser.hx:36:","[ i ] fragment '" + key + "' has incompatible value (" + value + ")"); return false; } } else { console.log("src/xrfragment/Parser.hx:37:","[ i ] fragment '" + key + "' does not exist or has no type defined (yet)"); return false; } return true; }; xrfragment_Parser.guessType = function(v,str) { v.string = str; if(str.split(",").length > 1) { var xyz = str.split(","); if(xyz.length > 0) { v.x = parseFloat(xyz[0]); } if(xyz.length > 1) { v.y = parseFloat(xyz[1]); } if(xyz.length > 2) { v.y = parseFloat(xyz[2]); } } if(xrfragment_Type.isColor.match(str)) { v.color = str; } if(xrfragment_Type.isFloat.match(str)) { v.float = parseFloat(str); } if(xrfragment_Type.isInt.match(str)) { v.int = Std.parseInt(str); } }; var xrfragment_Value = function() { }; xrfragment_Value.__name__ = true; var xrfragment_Type = function() { }; xrfragment_Type.__name__ = true; var xrfragment_Query = function(str) { this.isNumber = new EReg("^[0-9\\.]+$",""); this.isClass = new EReg("^[-]?class$",""); this.isExclude = new EReg("^-",""); this.isProp = new EReg("^.*:[><=!]?",""); this.q = { }; if(str != null) { this.parse(str); } }; xrfragment_Query.__name__ = true; xrfragment_Query.prototype = { expandAliases: function(token) { var classAlias = new EReg("^(-)?\\.",""); if(classAlias.match(token)) { return StringTools.replace(token,".","class:"); } else { return token; } } ,parse: function(str,recurse) { if(recurse == null) { recurse = false; } var _gthis = this; var token = str.split(" "); var q = { }; var process = function(str,prefix) { if(prefix == null) { prefix = ""; } str = StringTools.trim(str); var k = str.split(":")[0]; var v = str.split(":")[1]; var filter = { }; if(q[prefix + k]) { filter = q[prefix + k]; } filter["rules"] = filter["rules"] != null ? filter["rules"] : []; if(_gthis.isProp.match(str)) { var oper = ""; if(str.indexOf("*") != -1) { oper = "*"; } if(str.indexOf(">") != -1) { oper = ">"; } if(str.indexOf("<") != -1) { oper = "<"; } if(str.indexOf(">=") != -1) { oper = ">="; } if(str.indexOf("<=") != -1) { oper = "<="; } if(_gthis.isExclude.match(k)) { oper = "!="; k = HxOverrides.substr(k,1,null); } else { v = HxOverrides.substr(v,oper.length,null); } if(oper.length == 0) { oper = "="; } if(_gthis.isClass.match(k)) { filter[prefix + k] = oper != "!="; q[v] = filter; } else { var rule = { }; if(_gthis.isNumber.match(v)) { rule[oper] = parseFloat(v); } else { rule[oper] = v; } filter["rules"].push(rule); q[k] = filter; } return; } else { filter["id"] = _gthis.isExclude.match(str) ? false : true; var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str; q[key] = filter; } }; var _g = 0; var _g1 = token.length; while(_g < _g1) { var i = _g++; process(this.expandAliases(token[i])); } this.q = q; return this.q; } ,test: function(obj) { var qualify = false; var _g = 0; var _g1 = Reflect.fields(obj); while(_g < _g1.length) { var k = _g1[_g]; ++_g; var v = Std.string(Reflect.field(obj,k)); if(this.testProperty(k,v)) { qualify = true; } } var _g = 0; var _g1 = Reflect.fields(obj); while(_g < _g1.length) { var k = _g1[_g]; ++_g; var v = Std.string(Reflect.field(obj,k)); if(this.testProperty(k,v,true)) { qualify = false; } } return qualify; } ,testProperty: function(property,value,exclude) { var conds = 0; var fails = 0; var qualify = 0; var testprop = function(expr) { conds += 1; fails += expr ? 0 : 1; return expr; }; if(this.q[value] != null) { var v = this.q[value]; if(v[property] != null) { return v[property]; } } var _g = 0; var _g1 = Reflect.fields(this.q); while(_g < _g1.length) { var k = _g1[_g]; ++_g; var filter = Reflect.field(this.q,k); if(filter.rules == null) { continue; } var rules = filter.rules; var _g2 = 0; while(_g2 < rules.length) { var rule = rules[_g2]; ++_g2; if(exclude) { if(Reflect.field(rule,"!=") != null && testprop((value == null ? "null" : "" + value) == Std.string(Reflect.field(rule,"!="))) && exclude) { ++qualify; } } else { if(Reflect.field(rule,"*") != null && testprop(parseFloat(value) != null)) { ++qualify; } if(Reflect.field(rule,">") != null && testprop(parseFloat(value) > parseFloat(Reflect.field(rule,">")))) { ++qualify; } if(Reflect.field(rule,"<") != null && testprop(parseFloat(value) < parseFloat(Reflect.field(rule,"<")))) { ++qualify; } if(Reflect.field(rule,">=") != null && testprop(parseFloat(value) >= parseFloat(Reflect.field(rule,">=")))) { ++qualify; } if(Reflect.field(rule,"<=") != null && testprop(parseFloat(value) <= parseFloat(Reflect.field(rule,"<=")))) { ++qualify; } if(Reflect.field(rule,"=") != null && (testprop(value == Reflect.field(rule,"=")) || testprop(parseFloat(value) == parseFloat(Reflect.field(rule,"="))))) { ++qualify; } } } } return qualify > 0; } }; var xrfragment_Url = $hx_exports["xrfragment"]["Url"] = function() { }; xrfragment_Url.__name__ = true; xrfragment_Url.parse = function(qs) { var fragment = qs.split("#"); var splitArray = fragment[1].split("&"); var resultMap = { }; var _g = 0; var _g1 = splitArray.length; while(_g < _g1) { var i = _g++; var splitByEqual = splitArray[i].split("="); var regexPlus = new EReg("\\+","g"); var key = splitByEqual[0]; if(splitByEqual.length > 1) { var s = regexPlus.split(splitByEqual[1]).join(" "); var value = decodeURIComponent(s.split("+").join(" ")); var ok = xrfragment_Parser.parse(key,value,resultMap); } } return resultMap; }; if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) { HxOverrides.now = performance.now.bind(performance); } String.__name__ = true; Array.__name__ = true; js_Boot.__toStr = ({ }).toString; Test.errors = 0; xrfragment_Parser.error = ""; xrfragment_Type.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",""); xrfragment_Type.isInt = new EReg("^[0-9]+$",""); xrfragment_Type.isFloat = new EReg("^[0-9]+\\.[0-9]+$",""); xrfragment_Type.isVector = new EReg("([,]+|\\w)",""); var xrfragment_Query_ok = $hx_exports["xrfragment"]["Query"]["ok"] = // haxe workarounds Array.prototype.contains = Array.prototype.includes if (typeof Array.prototype.remove !== "function") { Array.prototype.remove = function (item) { const oldLength = this.length let newLength = 0 for (let i = 0; i < oldLength; i++) { const entry = this[i] if (entry === item) { let newLength = i++ while (i !== this.length) { const entry = this[i] if (entry !== item) this[newLength++] = entry i++ } this.length = newLength for (let i = newLength; i < oldLength; i++) delete this[i] return true } } return false } } ; xrfragment_Url.error = ""; Test.main(); })({}); var xrfragment = $hx_exports["xrfragment"];