2023-03-09 22:32:28 +01:00
|
|
|
package xrfragment;
|
|
|
|
|
|
2023-03-31 12:58:53 +02:00
|
|
|
import xrfragment.Parser;
|
2023-04-14 14:45:50 +02:00
|
|
|
import xrfragment.XRF;
|
2023-03-31 12:58:53 +02:00
|
|
|
|
2023-04-02 21:19:03 +02:00
|
|
|
/**
|
|
|
|
|
* <link rel="stylesheet" href="style.css"/>
|
|
|
|
|
* <link href="https://fonts.cdnfonts.com/css/montserrat" rel="stylesheet"/>
|
2023-04-02 21:22:22 +02:00
|
|
|
*
|
2023-04-02 21:19:03 +02:00
|
|
|
* > version 1.0.0
|
2023-04-02 21:22:22 +02:00
|
|
|
*
|
|
|
|
|
* date: $(date +"%Y-%m-%dT%H:%M:%S%z") (generated by \`./make doc\`)<br>
|
2023-04-02 21:19:03 +02:00
|
|
|
* [](https://github.com/coderofsalvation/xrfragment/actions)
|
|
|
|
|
*
|
2023-04-06 18:27:49 +02:00
|
|
|
* # XRFragment Grammar
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* reserved = gen-delims / sub-delims
|
|
|
|
|
* gen-delims = "#" / "&"
|
|
|
|
|
* sub-delims = "," / "|" / "="
|
|
|
|
|
* ```
|
2023-04-06 18:29:31 +02:00
|
|
|
* <br>
|
2023-04-06 18:29:53 +02:00
|
|
|
*
|
2023-04-06 18:27:49 +02:00
|
|
|
* > Example: `://foo.com/my3d.asset#pos=1,0,0&prio=-5&t=0,100|100,200`
|
|
|
|
|
*
|
2023-04-06 18:31:07 +02:00
|
|
|
* <br>
|
2023-04-06 18:31:26 +02:00
|
|
|
*
|
2023-04-06 18:31:07 +02:00
|
|
|
* | Explanation | |
|
|
|
|
|
* |-|-|
|
2023-04-06 18:29:31 +02:00
|
|
|
* | `x=1,2,3` | vector/coordinate argument e.g. |
|
2023-04-06 18:37:18 +02:00
|
|
|
* | `x=foo\|bar|1,2,3|1.0` | the `\|` character is used for:<br>1.specifying `n` arguments for xrfragment `x`<br>2. roundrobin of values (in case provided arguments exceeds `n` of `x` for #1) when triggered by browser URI (clicking `href` e.g.)|
|
|
|
|
|
* | `https://x.co/1.gltf||xyz://x.co/1.gltf` | multi-protocol/fallback urls |
|
2023-04-06 18:29:31 +02:00
|
|
|
* | `.mygroup` | query-alias for `class:mygroup` |
|
2023-04-02 21:19:03 +02:00
|
|
|
*
|
2023-04-06 18:30:36 +02:00
|
|
|
* > Focus: hasslefree 3D vector-data (`,`), multi-protocol/fallback-linking & dynamic values (`|`), and CSS-piggybacking (`.mygroup`)
|
|
|
|
|
*
|
2023-04-02 21:19:03 +02:00
|
|
|
* # URI parser
|
|
|
|
|
* > icanhazcode? yes, see [URI.hx](https://github.com/coderofsalvation/xrfragment/blob/main/src/xrfragment/URI.hx)
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-30 19:51:32 +02:00
|
|
|
@:expose // <- makes the class reachable from plain JavaScript
|
|
|
|
|
@:keep // <- avoids accidental removal by dead code elimination
|
2023-03-31 14:47:54 +02:00
|
|
|
class URI {
|
2023-04-02 21:19:03 +02:00
|
|
|
@:keep
|
2023-04-14 14:45:50 +02:00
|
|
|
public static function parse(qs:String,browser_override:Bool):haxe.DynamicAccess<Dynamic> {
|
2023-04-02 21:19:03 +02:00
|
|
|
var fragment:Array<String> = qs.split("#"); // 1. fragment URI starts with `#`
|
|
|
|
|
var splitArray:Array<String> = fragment[1].split('&'); // 1. fragments are split by `&`
|
|
|
|
|
var resultMap:haxe.DynamicAccess<Dynamic> = {}; // 1. store key/values into a associative array or dynamic object
|
|
|
|
|
for (i in 0...splitArray.length) { // 1. loop thru each fragment
|
2023-03-31 14:40:24 +02:00
|
|
|
|
2023-04-02 21:19:03 +02:00
|
|
|
var splitByEqual = splitArray[i].split('='); // 1. for each fragment split on `=` to separate key/values
|
2023-03-31 12:58:53 +02:00
|
|
|
var regexPlus = ~/\+/g; // 1. fragment-values are urlencoded (space becomes `+` using `encodeUriComponent` e.g.)
|
2023-03-30 19:51:32 +02:00
|
|
|
var key:String = splitByEqual[0];
|
2023-04-14 17:37:33 +02:00
|
|
|
var value:String = "";
|
2023-03-30 19:51:32 +02:00
|
|
|
if (splitByEqual.length > 1) {
|
2023-04-14 17:37:33 +02:00
|
|
|
value = StringTools.urlDecode(regexPlus.split(splitByEqual[1]).join(" "));
|
2023-03-09 22:32:28 +01:00
|
|
|
}
|
2023-04-14 17:37:33 +02:00
|
|
|
var ok:Bool = Parser.parse(key,value,resultMap); // 1. every recognized fragment key/value-pair is added to a central map/associative array/object
|
2023-03-30 19:51:32 +02:00
|
|
|
}
|
2023-04-14 14:45:50 +02:00
|
|
|
if( browser_override ){
|
|
|
|
|
for (key in resultMap.keys()) {
|
|
|
|
|
var xrf:XRF = resultMap.get(key);
|
2023-04-14 17:37:33 +02:00
|
|
|
if( !xrf.is( XRF.BROWSER_OVERRIDE ) ){
|
|
|
|
|
resultMap.remove(key);
|
|
|
|
|
}
|
2023-04-14 14:45:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-30 19:51:32 +02:00
|
|
|
return resultMap;
|
2023-03-09 22:32:28 +01:00
|
|
|
}
|
|
|
|
|
}
|