xrfragment/doc/RFC.md

99 lines
4.1 KiB
Markdown
Raw Normal View History

2023-04-02 21:19:03 +02:00
2023-03-31 19:53:23 +02:00
<link rel="stylesheet" href="style.css"/>
2023-03-31 19:37:16 +02:00
<link href="https://fonts.cdnfonts.com/css/montserrat" rel="stylesheet"/>
2023-04-02 21:22:22 +02:00
2023-03-31 19:37:16 +02:00
> version 1.0.0
2023-04-02 21:22:22 +02:00
2023-04-06 18:37:18 +02:00
date: 2023-04-06T18:37:15+0200<br>
2023-03-31 19:37:16 +02:00
[![Actions Status](https://github.com/coderofsalvation/xrfragment/workflows/test/badge.svg)](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-06 18:30:36 +02:00
> Focus: hasslefree 3D vector-data (`,`), multi-protocol/fallback-linking & dynamic values (`|`), and CSS-piggybacking (`.mygroup`)
2023-03-31 14:40:24 +02:00
# URI parser
2023-03-31 17:27:40 +02:00
> icanhazcode? yes, see [URI.hx](https://github.com/coderofsalvation/xrfragment/blob/main/src/xrfragment/URI.hx)
2023-03-31 12:58:53 +02:00
1. fragment URI starts with `#`
1. fragments are split by `&`
2023-04-02 21:19:03 +02:00
1. store key/values into a associative array or dynamic object
1. loop thru each fragment
1. for each fragment split on `=` to separate key/values
2023-03-31 12:58:53 +02:00
1. fragment-values are urlencoded (space becomes `+` using `encodeUriComponent` e.g.)
1. every recognized fragment key/value-pair is added to a central map/associative array/object
# XR Fragments (key/value params)
2023-04-02 21:19:03 +02:00
2023-03-31 19:21:31 +02:00
> ⛁ = define in 3D asset-file (as custom property or default projection)<br>
> ☇ = mutable, using navigator URI (`document.location.href` e.g.)<br>
2023-03-31 17:16:39 +02:00
2023-03-31 17:15:57 +02:00
| param | type | scope(s) | category | notes |
|---------|---------------|-------|--------------------|---------------------------------|
2023-04-02 21:19:03 +02:00
| prio | int (-10..1) | ⛁ | Asset loading / linking | \#static allow client to ignore lower-prio objects in the renderloop, to compensate frame-drop/cpu/gpu-overload scenarios |
2023-03-31 19:21:31 +02:00
| pos | 3D vector | ⛁ ☇ |HREF navigation/portals | |
| q | string | ⛁ |Query Selector | |
2023-03-31 14:40:24 +02:00
# XR Fragments parser
2023-04-02 21:19:03 +02:00
2023-03-31 16:35:54 +02:00
note: community parsers will prolly outperform this initial parser :)
2023-03-31 17:27:40 +02:00
> icanhazcode? yes, see [Parser.hx](https://github.com/coderofsalvation/xrfragment/blob/main/src/xrfragment/Parser.hx)
2023-03-31 14:40:24 +02:00
the gist of it:
2023-04-02 21:19:03 +02:00
1. check if param exist
2023-03-31 14:40:24 +02:00
1. each key has a regex to validate its value-type (see regexes)
2023-04-02 21:19:03 +02:00
1. extract the type
1. use `|` on stringvalues, to split multiple/fallback values
1. for each multiple/fallback value, guess the type
1. `,` assumes 1D/2D/3D vector-values like x[,y[,z]]
1. parseFloat(..) and parseInt(..) is applied to vector/float and int values
1. anything else will be treated as string-value
1. incompatible value-types will be dropped / not used
2023-04-02 21:19:03 +02:00
> the xrfragment specification should stay simple enough
2023-04-02 21:19:03 +02:00
> for anyone to write a parser using either regexes or grammar/lexers
2023-04-02 21:19:03 +02:00
> therefore expressions/comprehensions are not supported (max wildcard/comparison operators for queries e.g.)
2023-03-31 15:57:35 +02:00
# Parser Value types
2023-03-30 15:44:13 +02:00
| type | info | format | example |
2023-03-30 15:57:58 +02:00
|------|------|--------|----------------------------------|
2023-03-30 15:44:13 +02:00
|vector| x,y,z| comma-separated | #pos=1,2,3 |
|string| color| FFFFFF (hex) | #fog=5m,FFAACC |
|string| | | #q=-sun |
|int | | [-]x[xxxxx] | #price:>=100 |
2023-03-31 19:27:56 +02:00
|float | | [-]x[.xxxx] (ieee)| #prio=-20 |
|array | mixed| \|-separated | #pos=0,0,0\|90,0,0 |
2023-03-30 15:44:13 +02:00
2023-04-02 21:19:03 +02:00
2023-03-30 16:23:47 +02:00
> rule for thumb: type-limitations will piggyback JSON limitations (IEEE floatsize e.g.)
2023-04-02 21:19:03 +02:00
Regexes:
2023-03-30 16:23:47 +02:00
1. hex colors are detected using regex `/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/`
1. integers are detected using regex `/^[0-9]+$/`
1. floats are detected using regex `/^[0-9]+\.[0-9]+$/`
1. vectors are detected using regex `/[,]/` (but can also be an string referring to an entity-ID in the asset)
2023-03-31 19:21:31 +02:00
1. anything else is string `/.*/`
2023-03-31 12:58:53 +02:00