prefix custom fragments with _ to parser
This commit is contained in:
parent
436ed610d1
commit
af76c65a39
|
@ -214,7 +214,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -242,23 +242,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -290,10 +292,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
@ -1172,6 +1171,7 @@ xrf.frag.pos = function(v, opts){
|
|||
const updatePredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
|
||||
// spec: https://xrfragment.org/#Selection%20of%20interest
|
||||
const selectionOfInterest = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
let oldSelection
|
||||
|
@ -1194,6 +1194,7 @@ const updatePredefinedView = (opts) => {
|
|||
return oldSelection
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#predefined_view
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( !id ) return // prevent empty matches
|
||||
|
@ -1250,11 +1251,14 @@ xrf.addEventListener('href', (opts) => {
|
|||
//
|
||||
//xrf.addEventListener('predefinedView', updateUrl )
|
||||
//xrf.addEventListener('selection', updateUrl )
|
||||
// spec: https://xrfragment.org/#queries
|
||||
|
||||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
// spec: https://xrfragment.org/#src
|
||||
const instanceScene = () => {
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
|
@ -1285,6 +1289,7 @@ xrf.frag.q = function(v, opts){
|
|||
negative.map( (mesh) => mesh.visible = false )
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#queries
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
|
@ -1300,8 +1305,8 @@ xrf.frag.q = function(v, opts){
|
|||
})
|
||||
}
|
||||
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene()
|
||||
else showHide() // href
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene() // spec : https://xrfragment.org/#src
|
||||
else showHide() // predefined view // spec : https://xrfragment.org/#queries
|
||||
}
|
||||
xrf.frag.rot = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
@ -1359,7 +1364,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
},
|
||||
init: function () {
|
||||
if( !AFRAME.XRF ) this.initXRFragments()
|
||||
if( this.data ){
|
||||
if( typeof this.data == "string" ){
|
||||
if( document.location.search || document.location.hash.length > 1 ){ // override url
|
||||
this.data = `${document.location.search.substr(1)}${document.location.hash}`
|
||||
}
|
||||
|
@ -1378,22 +1383,22 @@ window.AFRAME.registerComponent('xrf', {
|
|||
|
||||
// enable XR fragments
|
||||
let aScene = document.querySelector('a-scene')
|
||||
let XRF = AFRAME.XRF = xrf.init({
|
||||
let XRF = AFRAME.XRF = xrf.init({
|
||||
THREE,
|
||||
camera: aScene.camera,
|
||||
camera: aScene.camera,
|
||||
scene: aScene.object3D,
|
||||
renderer: aScene.renderer,
|
||||
debug: true,
|
||||
loaders: { gltf: THREE.GLTFLoader } // which 3D assets (exts) to check for XR fragments?
|
||||
})
|
||||
if( !XRF.camera ) throw 'xrfragment: no camera detected, please declare <a-entity camera..> ABOVE entities with xrf-attributes'
|
||||
|
||||
// override the camera-related XR Fragments so the camera-rig is affected
|
||||
|
||||
// override the camera-related XR Fragments so the camera-rig is affected
|
||||
let camOverride = (xrf,v,opts) => {
|
||||
opts.camera = document.querySelector('[camera]').object3D.parent
|
||||
opts.camera = document.querySelector('[camera]').object3D.parent
|
||||
xrf(v,opts)
|
||||
}
|
||||
|
||||
|
||||
xrf.pos = camOverride
|
||||
|
||||
// in order to set the rotation programmatically
|
||||
|
@ -1403,15 +1408,15 @@ window.AFRAME.registerComponent('xrf', {
|
|||
let look = document.querySelector('[look-controls]')
|
||||
if( look ) look.removeAttribute("look-controls")
|
||||
camOverride(xrf,v,opts)
|
||||
// *TODO* make look-controls compatible, because simply
|
||||
// *TODO* make look-controls compatible, because simply
|
||||
// adding the look-controls will revert to the old rotation (cached somehow?)
|
||||
//setTimeout( () => look.setAttribute("look-controls",""), 100 )
|
||||
}
|
||||
|
||||
// convert portal to a-entity so AFRAME
|
||||
// raycaster can find & execute it
|
||||
xrf.href = (xrf,v,opts) => {
|
||||
camOverride(xrf,v,opts)
|
||||
xrf.href = (xrf,v,opts) => {
|
||||
camOverride(xrf,v,opts)
|
||||
let {mesh,camera} = opts;
|
||||
let el = document.createElement("a-entity")
|
||||
el.setAttribute("xrf-get",mesh.name )
|
||||
|
@ -1427,7 +1432,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
let els = [...document.querySelectorAll('[xrf-get]')]
|
||||
els.map( (el) => document.querySelector('a-scene').removeChild(el) )
|
||||
})(XRF.reset)
|
||||
|
||||
|
||||
// undo lookup-control shenanigans (which blocks updating camerarig position in VR)
|
||||
aScene.addEventListener('enter-vr', () => document.querySelector('[camera]').object3D.parent.matrixAutoUpdate = true )
|
||||
},
|
||||
|
|
|
@ -214,7 +214,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -242,23 +242,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -290,10 +292,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
|
|
@ -1406,7 +1406,7 @@ __lua_Thread.__name__ = true
|
|||
__xrfragment_Parser.new = {}
|
||||
_hx_exports["xrfragment"]["Parser"] = __xrfragment_Parser
|
||||
__xrfragment_Parser.__name__ = true
|
||||
__xrfragment_Parser.parse = function(key,value,resultMap)
|
||||
__xrfragment_Parser.parse = function(key,value,store)
|
||||
local Frag_h = ({});
|
||||
local value1 = _hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.T_INT);
|
||||
if (value1 == nil) then
|
||||
|
@ -1549,7 +1549,7 @@ __xrfragment_Parser.parse = function(key,value,resultMap)
|
|||
if (((__lua_lib_luautf8_Utf8.len(value) == 0) and (__lua_lib_luautf8_Utf8.len(key) > 0)) and (Frag_h[key] == nil)) then
|
||||
local v = __xrfragment_XRF.new(key, _hx_bit.bor(__xrfragment_XRF.PV_EXECUTE,__xrfragment_XRF.NAVIGATOR));
|
||||
v:validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
do return true end;
|
||||
end;
|
||||
local tmp;
|
||||
|
@ -1604,23 +1604,25 @@ __xrfragment_Parser.parse = function(key,value,resultMap)
|
|||
end;
|
||||
if (tmp) then
|
||||
local value = __xrfragment_XRF.new(key, _hx_bit.bor(_hx_bit.bor(_hx_bit.bor(__xrfragment_XRF.ASSET,__xrfragment_XRF.PV_OVERRIDE),__xrfragment_XRF.T_STRING),__xrfragment_XRF.PROP_BIND));
|
||||
resultMap[key] = value;
|
||||
store[key] = value;
|
||||
do return true end;
|
||||
end;
|
||||
local ret = Frag_h[key];
|
||||
if (ret == __haxe_ds_StringMap.tnull) then
|
||||
ret = nil;
|
||||
end;
|
||||
local v = __xrfragment_XRF.new(key, ret);
|
||||
if (Frag_h[key] ~= nil) then
|
||||
local ret = Frag_h[key];
|
||||
if (ret == __haxe_ds_StringMap.tnull) then
|
||||
ret = nil;
|
||||
end;
|
||||
local v = __xrfragment_XRF.new(key, ret);
|
||||
if (not v:validate(value)) then
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string(Std.string("⚠ fragment '") .. Std.string(key)) .. Std.string("' has incompatible value (")) .. Std.string(value)) .. Std.string(")"), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=79,className="xrfragment.Parser",methodName="parse"}));
|
||||
do return false end;
|
||||
end;
|
||||
store[key] = v;
|
||||
if (__xrfragment_Parser.debug) then
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string("✔ ") .. Std.string(key)) .. Std.string(": ")) .. Std.string(v.string), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=82,className="xrfragment.Parser",methodName="parse"}));
|
||||
__haxe_Log.trace(Std.string(Std.string(Std.string("✔ ") .. Std.string(key)) .. Std.string(": ")) .. Std.string(v.string), _hx_o({__fields__={fileName=true,lineNumber=true,className=true,methodName=true},fileName="src/xrfragment/Parser.hx",lineNumber=83,className="xrfragment.Parser",methodName="parse"}));
|
||||
end;
|
||||
resultMap[key] = v;
|
||||
else
|
||||
store[Std.string("_") .. Std.string(key)] = v;
|
||||
end;
|
||||
do return true end;
|
||||
end
|
||||
|
@ -1659,10 +1661,7 @@ end
|
|||
__xrfragment_Query.prototype.get = function(self)
|
||||
do return self.q end
|
||||
end
|
||||
__xrfragment_Query.prototype.parse = function(self,str,recurse)
|
||||
if (recurse == nil) then
|
||||
recurse = false;
|
||||
end;
|
||||
__xrfragment_Query.prototype.parse = function(self,str)
|
||||
local _gthis = self;
|
||||
local idx = 1;
|
||||
local ret = _hx_tab_array({}, 0);
|
||||
|
|
|
@ -214,7 +214,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -242,23 +242,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -290,10 +292,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
|
|
@ -1291,7 +1291,7 @@ class xrfragment_Parser:
|
|||
_hx_statics = ["error", "debug", "parse"]
|
||||
|
||||
@staticmethod
|
||||
def parse(key,value,resultMap):
|
||||
def parse(key,value,store):
|
||||
Frag = haxe_ds_StringMap()
|
||||
Frag.h["prio"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_INT)
|
||||
Frag.h["#"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW)
|
||||
|
@ -1319,20 +1319,23 @@ class xrfragment_Parser:
|
|||
if (((len(value) == 0) and ((len(key) > 0))) and (not (key in Frag.h))):
|
||||
v = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
v.validate(key)
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
return True
|
||||
if ((len(key.split(".")) > 1) and ((len(value.split(".")) > 1))):
|
||||
value1 = xrfragment_XRF(key,(((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.PROP_BIND))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
return True
|
||||
v = xrfragment_XRF(key,Frag.h.get(key,None))
|
||||
if (key in Frag.h):
|
||||
v = xrfragment_XRF(key,Frag.h.get(key,None))
|
||||
if (not v.validate(value)):
|
||||
print(str((((("⚠ fragment '" + ("null" if key is None else key)) + "' has incompatible value (") + ("null" if value is None else value)) + ")")))
|
||||
return False
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
if xrfragment_Parser.debug:
|
||||
print(str(((("✔ " + ("null" if key is None else key)) + ": ") + HxOverrides.stringOrNull(v.string))))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
else:
|
||||
key1 = ("_" + ("null" if key is None else key))
|
||||
setattr(store,(("_hx_" + key1) if ((key1 in python_Boot.keywords)) else (("_hx_" + key1) if (((((len(key1) > 2) and ((ord(key1[0]) == 95))) and ((ord(key1[1]) == 95))) and ((ord(key1[(len(key1) - 1)]) != 95)))) else key1)),v)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -1367,9 +1370,7 @@ class xrfragment_Query:
|
|||
def get(self):
|
||||
return self.q
|
||||
|
||||
def parse(self,_hx_str,recurse = None):
|
||||
if (recurse is None):
|
||||
recurse = False
|
||||
def parse(self,_hx_str):
|
||||
_gthis = self
|
||||
token = _hx_str.split(" ")
|
||||
q = _hx_AnonObject({})
|
||||
|
|
|
@ -214,7 +214,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -242,23 +242,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -290,10 +292,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
@ -1172,6 +1171,7 @@ xrf.frag.pos = function(v, opts){
|
|||
const updatePredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
|
||||
// spec: https://xrfragment.org/#Selection%20of%20interest
|
||||
const selectionOfInterest = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
let oldSelection
|
||||
|
@ -1194,6 +1194,7 @@ const updatePredefinedView = (opts) => {
|
|||
return oldSelection
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#predefined_view
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( !id ) return // prevent empty matches
|
||||
|
@ -1250,11 +1251,14 @@ xrf.addEventListener('href', (opts) => {
|
|||
//
|
||||
//xrf.addEventListener('predefinedView', updateUrl )
|
||||
//xrf.addEventListener('selection', updateUrl )
|
||||
// spec: https://xrfragment.org/#queries
|
||||
|
||||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
// spec: https://xrfragment.org/#src
|
||||
const instanceScene = () => {
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
|
@ -1285,6 +1289,7 @@ xrf.frag.q = function(v, opts){
|
|||
negative.map( (mesh) => mesh.visible = false )
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#queries
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
|
@ -1300,8 +1305,8 @@ xrf.frag.q = function(v, opts){
|
|||
})
|
||||
}
|
||||
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene()
|
||||
else showHide() // href
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene() // spec : https://xrfragment.org/#src
|
||||
else showHide() // predefined view // spec : https://xrfragment.org/#queries
|
||||
}
|
||||
xrf.frag.rot = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
|
|
@ -214,7 +214,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -242,23 +242,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -290,10 +292,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
@ -1172,6 +1171,7 @@ xrf.frag.pos = function(v, opts){
|
|||
const updatePredefinedView = (opts) => {
|
||||
let {frag,scene} = opts
|
||||
|
||||
// spec: https://xrfragment.org/#Selection%20of%20interest
|
||||
const selectionOfInterest = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
let oldSelection
|
||||
|
@ -1194,6 +1194,7 @@ const updatePredefinedView = (opts) => {
|
|||
return oldSelection
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#predefined_view
|
||||
const predefinedView = (frag,scene,mesh) => {
|
||||
let id = frag.string
|
||||
if( !id ) return // prevent empty matches
|
||||
|
@ -1250,11 +1251,14 @@ xrf.addEventListener('href', (opts) => {
|
|||
//
|
||||
//xrf.addEventListener('predefinedView', updateUrl )
|
||||
//xrf.addEventListener('selection', updateUrl )
|
||||
// spec: https://xrfragment.org/#queries
|
||||
|
||||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
// spec: https://xrfragment.org/#src
|
||||
const instanceScene = () => {
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
|
@ -1285,6 +1289,7 @@ xrf.frag.q = function(v, opts){
|
|||
negative.map( (mesh) => mesh.visible = false )
|
||||
}
|
||||
|
||||
// spec: https://xrfragment.org/#queries
|
||||
const showHide = () => {
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
|
@ -1300,8 +1305,8 @@ xrf.frag.q = function(v, opts){
|
|||
})
|
||||
}
|
||||
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene()
|
||||
else showHide() // href
|
||||
if( opts.embedded && opts.embedded.fragment == "src" ) instanceScene() // spec : https://xrfragment.org/#src
|
||||
else showHide() // predefined view // spec : https://xrfragment.org/#queries
|
||||
}
|
||||
xrf.frag.rot = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
{"fn":"url","data":"http://foo.com?foo=1#mypredefinedview&another", "expect":{ "fn":"testPredefinedView", "input":"another","out":true},"label":"test predefined view executed (multiple)"},
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mypredefinedview&another", "expect":{ "fn":"testPredefinedView", "input":"mypredefinedview","out":true},"label":"test predefined view executed (multiple)"},
|
||||
{"fn":"url","data":"#cube.position.x=music.position.x", "expect":{ "fn":"testPropertyAssign", "input":"cube.position.x","out":true},"label":"test data assign"},
|
||||
{"fn":"url","data":"#cube.position.x=@music.position.x", "expect":{ "fn":"testPropertyAssign", "input":"cube.position.x","out":true},"label":"test one-way data bind"}
|
||||
{"fn":"url","data":"#cube.position.x=@music.position.x", "expect":{ "fn":"testPropertyAssign", "input":"cube.position.x","out":true},"label":"test one-way data bind"},
|
||||
{"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testParsed", "input":"_mycustom","out":true},"label":"test custom property"}
|
||||
]
|
||||
|
|
|
@ -11,8 +11,8 @@ class Parser {
|
|||
public static var debug:Bool = false;
|
||||
|
||||
@:keep
|
||||
public static function parse(key:String,value:String,resultMap:haxe.DynamicAccess<Dynamic>):Bool {
|
||||
|
||||
public static function parse(key:String,value:String,store:haxe.DynamicAccess<Dynamic>):Bool {
|
||||
|
||||
// here we define allowed characteristics & datatypes for each fragment (stored as bitmasked int for performance purposes)
|
||||
var Frag:Map<String, Int> = new Map<String, Int>();
|
||||
|
||||
|
@ -64,23 +64,25 @@ class Parser {
|
|||
if( value.length == 0 && key.length > 0 && !Frag.exists(key) ){
|
||||
var v:XRF = new XRF(key, XRF.PV_EXECUTE | XRF.NAVIGATOR );
|
||||
v.validate(key); // will fail but will parse multiple args for us (separated by |)
|
||||
resultMap.set(key, v );
|
||||
store.set(key, v );
|
||||
return true;
|
||||
}
|
||||
if( key.split(".").length > 1 && value.split(".").length > 1 ){
|
||||
resultMap.set(key, new XRF(key, XRF.ASSET | XRF.PV_OVERRIDE | XRF.T_STRING | XRF.PROP_BIND ) );
|
||||
store.set(key, new XRF(key, XRF.ASSET | XRF.PV_OVERRIDE | XRF.T_STRING | XRF.PROP_BIND ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
// regular fragments:
|
||||
if( Frag.exists(key) ){ // 1. check if param exist
|
||||
var v:XRF = new XRF(key, Frag.get(key));
|
||||
var v:XRF = new XRF(key, Frag.get(key));
|
||||
if( Frag.exists(key) ){ // 1. check if fragment is official XR Fragment
|
||||
if( !v.validate(value) ){
|
||||
trace("⚠ fragment '"+key+"' has incompatible value ("+value+")");
|
||||
trace("⚠ fragment '"+key+"' has incompatible value ("+value+")");// 1. don't add to store if value-type is incorrect
|
||||
return false;
|
||||
}
|
||||
store.set(key, v ); // 1. if valid, add to store
|
||||
if( debug ) trace("✔ "+key+": "+v.string);
|
||||
resultMap.set(key, v );
|
||||
}else{ // 1. prefix non-offical fragment key's with underscore (and add to store)
|
||||
store.set("_"+key,v);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -136,7 +136,7 @@ StringTools.replace = function(s,sub,by) {
|
|||
var Test = function() { };
|
||||
Test.__name__ = true;
|
||||
Test.main = function() {
|
||||
Test.test([{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : false}, label : "equal.xyz: should trigger incompatible type)", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : "1.2,2.2,3"}, label : "equal.xyz", data : "http://foo.com?foo=1#pos=1.2,2.2,3"},{ fn : "url", expect : { fn : "equal.xy", input : "t", out : "1,100"}, label : "a equal.xy", data : "http://foo.com?foo=1#t=1,100"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "should trigger 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"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "t", out : true}, label : "browser URI can override t (defined in asset)", data : "http://foo.com?foo=1#t=2,500"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "q", out : false}, label : "browser URI cannot override q (defined in asset)", data : "http://foo.com?foo=1#q=-bar"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "scale", out : false}, label : "scale does not have NAVIGATOR set", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testEmbedOverride", input : "scale", out : true}, label : "embedded (src) URI can override scale", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed", data : "http://foo.com?foo=1#mypredefinedview"},{ fn : "url", expect : { fn : "testPredefinedView", input : "another", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test data assign", data : "#cube.position.x=music.position.x"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test one-way data bind", data : "#cube.position.x=@music.position.x"}]);
|
||||
Test.test([{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : false}, label : "equal.xyz: should trigger incompatible type)", data : "http://foo.com?foo=1#pos=1.2,2.2"},{ fn : "url", expect : { fn : "equal.xyz", input : "pos", out : "1.2,2.2,3"}, label : "equal.xyz", data : "http://foo.com?foo=1#pos=1.2,2.2,3"},{ fn : "url", expect : { fn : "equal.xy", input : "t", out : "1,100"}, label : "a equal.xy", data : "http://foo.com?foo=1#t=1,100"},{ fn : "url", expect : { fn : "testParsed", input : "prio", out : false}, label : "should trigger 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"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "t", out : true}, label : "browser URI can override t (defined in asset)", data : "http://foo.com?foo=1#t=2,500"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "q", out : false}, label : "browser URI cannot override q (defined in asset)", data : "http://foo.com?foo=1#q=-bar"},{ fn : "url", expect : { fn : "testBrowserOverride", input : "scale", out : false}, label : "scale does not have NAVIGATOR set", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testEmbedOverride", input : "scale", out : true}, label : "embedded (src) URI can override scale", data : "http://foo.com?foo=1#scale=2,2,2"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed", data : "http://foo.com?foo=1#mypredefinedview"},{ fn : "url", expect : { fn : "testPredefinedView", input : "another", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPredefinedView", input : "mypredefinedview", out : true}, label : "test predefined view executed (multiple)", data : "http://foo.com?foo=1#mypredefinedview&another"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test data assign", data : "#cube.position.x=music.position.x"},{ fn : "url", expect : { fn : "testPropertyAssign", input : "cube.position.x", out : true}, label : "test one-way data bind", data : "#cube.position.x=@music.position.x"},{ fn : "url", expect : { fn : "testParsed", input : "_mycustom", out : true}, label : "test custom property", data : "http://foo.com?foo=1#mycustom=foo"}]);
|
||||
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"},{ fn : "query", expect : { fn : "testQueryRoot", input : ["foo"], out : true}, label : "foo should be root-only", data : "/foo"},{ fn : "query", expect : { fn : "testQueryRoot", input : ["foo"], out : false}, label : "foo should recursively selected", data : "/foo foo"}]);
|
||||
Test.test([]);
|
||||
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","2"], out : true}, data : "price:>=2"},{ 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"}]);
|
||||
|
@ -328,7 +328,7 @@ js_Boot.__string_rec = function(o,s) {
|
|||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
xrfragment_Parser.parse = function(key,value,store) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
|
@ -356,23 +356,25 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(value.length == 0 && key.length > 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
v.validate(key);
|
||||
resultMap[key] = v;
|
||||
store[key] = v;
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
store[key] = v;
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:82:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
} else {
|
||||
store["_" + key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -404,10 +406,7 @@ xrfragment_Query.prototype = {
|
|||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
,parse: function(str) {
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
|
|
|
@ -390,7 +390,7 @@ class Test:
|
|||
|
||||
@staticmethod
|
||||
def main():
|
||||
Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': False}), 'label': "equal.xyz: should trigger incompatible type)", 'data': "http://foo.com?foo=1#pos=1.2,2.2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': "1.2,2.2,3"}), 'label': "equal.xyz", 'data': "http://foo.com?foo=1#pos=1.2,2.2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "t", 'out': "1,100"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#t=1,100"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "prio", 'out': False}), 'label': "should trigger incompatible type", 'data': "http://foo.com?foo=1#prio=foo"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'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"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "t", 'out': True}), 'label': "browser URI can override t (defined in asset)", 'data': "http://foo.com?foo=1#t=2,500"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "q", 'out': False}), 'label': "browser URI cannot override q (defined in asset)", 'data': "http://foo.com?foo=1#q=-bar"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "scale", 'out': False}), 'label': "scale does not have NAVIGATOR set", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testEmbedOverride", 'input': "scale", 'out': True}), 'label': "embedded (src) URI can override scale", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed", 'data': "http://foo.com?foo=1#mypredefinedview"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "another", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test data assign", 'data': "#cube.position.x=music.position.x"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test one-way data bind", 'data': "#cube.position.x=@music.position.x"})])
|
||||
Test.test([_hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': False}), 'label': "equal.xyz: should trigger incompatible type)", 'data': "http://foo.com?foo=1#pos=1.2,2.2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xyz", 'input': "pos", 'out': "1.2,2.2,3"}), 'label': "equal.xyz", 'data': "http://foo.com?foo=1#pos=1.2,2.2,3"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "equal.xy", 'input': "t", 'out': "1,100"}), 'label': "a equal.xy", 'data': "http://foo.com?foo=1#t=1,100"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "prio", 'out': False}), 'label': "should trigger incompatible type", 'data': "http://foo.com?foo=1#prio=foo"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'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"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "t", 'out': True}), 'label': "browser URI can override t (defined in asset)", 'data': "http://foo.com?foo=1#t=2,500"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "q", 'out': False}), 'label': "browser URI cannot override q (defined in asset)", 'data': "http://foo.com?foo=1#q=-bar"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testBrowserOverride", 'input': "scale", 'out': False}), 'label': "scale does not have NAVIGATOR set", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testEmbedOverride", 'input': "scale", 'out': True}), 'label': "embedded (src) URI can override scale", 'data': "http://foo.com?foo=1#scale=2,2,2"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed", 'data': "http://foo.com?foo=1#mypredefinedview"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "another", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPredefinedView", 'input': "mypredefinedview", 'out': True}), 'label': "test predefined view executed (multiple)", 'data': "http://foo.com?foo=1#mypredefinedview&another"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test data assign", 'data': "#cube.position.x=music.position.x"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testPropertyAssign", 'input': "cube.position.x", 'out': True}), 'label': "test one-way data bind", 'data': "#cube.position.x=@music.position.x"}), _hx_AnonObject({'fn': "url", 'expect': _hx_AnonObject({'fn': "testParsed", 'input': "_mycustom", 'out': True}), 'label': "test custom property", 'data': "http://foo.com?foo=1#mycustom=foo"})])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': "class:bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'label': ".bar shorthand", 'data': ".bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': False}), 'data': ".bar -.foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'data': ".bar -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "bar"], 'out': True}), 'data': ".bar -.bar .bar"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo bar:>5 .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["class", "foo"], 'out': True}), 'label': "class:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': False}), 'label': "!id:foo", 'data': ".foo -.foo .foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["id", "foo"], 'out': True}), 'label': "id:foo?", 'data': "foo -foo foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testQueryRoot", 'input': ["foo"], 'out': True}), 'label': "foo should be root-only", 'data': "/foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testQueryRoot", 'input': ["foo"], 'out': False}), 'label': "foo should recursively selected", 'data': "/foo foo"})])
|
||||
Test.test([])
|
||||
Test.test([_hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': True}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "10"], 'out': False}), 'data': "price:>=15"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "4"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': False}), 'data': "price:>=5"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "2"], 'out': True}), 'data': "price:>=2"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "1"], 'out': False}), 'label': "price=1", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "0"], 'out': True}), 'label': "price=0", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["price", "6"], 'out': True}), 'label': "price=6", 'data': "price:>=5 price:0"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': True}), 'data': "tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testProperty", 'input': ["tag", "foo"], 'out': False}), 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "testPropertyExclude", 'input': ["tag", "foo"], 'out': True}), 'label': "testExclude", 'data': "-tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'price': 5})], 'out': True}), 'data': ".foo price:5 -tag:foo"}), _hx_AnonObject({'fn': "query", 'expect': _hx_AnonObject({'fn': "test", 'input': [_hx_AnonObject({'tag': "foo", 'price': 5})], 'out': False}), 'data': ".foo price:5 -tag:foo"})])
|
||||
|
@ -1408,7 +1408,7 @@ class xrfragment_Parser:
|
|||
_hx_statics = ["error", "debug", "parse"]
|
||||
|
||||
@staticmethod
|
||||
def parse(key,value,resultMap):
|
||||
def parse(key,value,store):
|
||||
Frag = haxe_ds_StringMap()
|
||||
Frag.h["prio"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_INT)
|
||||
Frag.h["#"] = (xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW)
|
||||
|
@ -1436,20 +1436,23 @@ class xrfragment_Parser:
|
|||
if (((len(value) == 0) and ((len(key) > 0))) and (not (key in Frag.h))):
|
||||
v = xrfragment_XRF(key,(xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR))
|
||||
v.validate(key)
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
return True
|
||||
if ((len(key.split(".")) > 1) and ((len(value.split(".")) > 1))):
|
||||
value1 = xrfragment_XRF(key,(((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.PROP_BIND))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1)
|
||||
return True
|
||||
v = xrfragment_XRF(key,Frag.h.get(key,None))
|
||||
if (key in Frag.h):
|
||||
v = xrfragment_XRF(key,Frag.h.get(key,None))
|
||||
if (not v.validate(value)):
|
||||
print(str((((("⚠ fragment '" + ("null" if key is None else key)) + "' has incompatible value (") + ("null" if value is None else value)) + ")")))
|
||||
return False
|
||||
setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
if xrfragment_Parser.debug:
|
||||
print(str(((("✔ " + ("null" if key is None else key)) + ": ") + HxOverrides.stringOrNull(v.string))))
|
||||
setattr(resultMap,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v)
|
||||
else:
|
||||
key1 = ("_" + ("null" if key is None else key))
|
||||
setattr(store,(("_hx_" + key1) if ((key1 in python_Boot.keywords)) else (("_hx_" + key1) if (((((len(key1) > 2) and ((ord(key1[0]) == 95))) and ((ord(key1[1]) == 95))) and ((ord(key1[(len(key1) - 1)]) != 95)))) else key1)),v)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -1484,9 +1487,7 @@ class xrfragment_Query:
|
|||
def get(self):
|
||||
return self.q
|
||||
|
||||
def parse(self,_hx_str,recurse = None):
|
||||
if (recurse is None):
|
||||
recurse = False
|
||||
def parse(self,_hx_str):
|
||||
_gthis = self
|
||||
token = _hx_str.split(" ")
|
||||
q = _hx_AnonObject({})
|
||||
|
@ -1605,8 +1606,8 @@ class xrfragment_Query:
|
|||
fails = 0
|
||||
qualify = 0
|
||||
def _hx_local_2(expr):
|
||||
nonlocal fails
|
||||
nonlocal conds
|
||||
nonlocal fails
|
||||
conds = (conds + 1)
|
||||
fails = (fails + (0 if expr else 1))
|
||||
return expr
|
||||
|
|
Loading…
Reference in New Issue