2023-11-11 12:53:43 +01:00
|
|
|
AFRAME.registerComponent('helloworld', {
|
|
|
|
schema: {
|
2023-12-31 21:25:51 +01:00
|
|
|
foo: { type:"string"}
|
2023-11-11 12:53:43 +01:00
|
|
|
},
|
2023-12-31 21:25:51 +01:00
|
|
|
|
2024-01-02 19:00:25 +01:00
|
|
|
requires:{
|
2023-12-31 21:25:51 +01:00
|
|
|
"html": "https://unpkg.com/aframe-htmlmesh@2.1.0/build/aframe-html.js", // html to AFRAME
|
|
|
|
"stylis": "https://unpkg.com/stylis@4.3.1/dist/umd/stylis.js" // modern CSS (https://stylis.js.org)
|
2023-11-11 12:53:43 +01:00
|
|
|
},
|
|
|
|
|
2023-12-31 21:25:51 +01:00
|
|
|
dom: {
|
2024-01-03 13:40:05 +01:00
|
|
|
scale: 3,
|
2024-01-01 14:01:35 +01:00
|
|
|
events: ['click','input'],
|
2024-01-01 19:53:10 +01:00
|
|
|
html: (me) => `
|
|
|
|
<div id="${me.el.uid}" class="modal hello">
|
|
|
|
<div class="top">
|
|
|
|
<div class="title">Hello world</div>
|
|
|
|
</div>
|
2024-01-01 14:01:35 +01:00
|
|
|
<br><br>
|
|
|
|
<fieldset>
|
|
|
|
<legend>Colour</legend>
|
|
|
|
<input type="radio" id="color-red" name="color" value="red" checked><label for="color-red"> Red</label><br>
|
|
|
|
<input type="radio" id="color-blue" name="color" value="blue"><label for="color-blue"> Blue</label><br>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
|
|
<legend>Material:</legend>
|
|
|
|
<input id="material-wireframe" type="checkbox" name="wireframe"><label for="material-wireframe"> Wireframe</label><br>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
2024-01-01 19:53:10 +01:00
|
|
|
<legend>Size: <span id="value"></span></legend>
|
2024-01-01 14:01:35 +01:00
|
|
|
<input type="range" min="0.1" max="2" value="1" step="0.01" id="myRange" style="background-color: transparent;">
|
|
|
|
</fieldset>
|
2024-01-01 19:53:10 +01:00
|
|
|
<button>hello</button>
|
2024-01-01 14:01:35 +01:00
|
|
|
</div>`,
|
2024-01-01 19:53:10 +01:00
|
|
|
css: `.modal.hello {
|
2024-01-03 13:40:05 +01:00
|
|
|
position:relative;
|
|
|
|
top:0;
|
|
|
|
width:200px;
|
|
|
|
.title { font-weight:bold; } /* modern nested buildless css thanks to stylis */
|
2024-01-01 19:53:10 +01:00
|
|
|
}`
|
2023-12-31 21:25:51 +01:00
|
|
|
},
|
2023-11-11 12:53:43 +01:00
|
|
|
|
2023-12-31 21:25:51 +01:00
|
|
|
events:{
|
2024-01-03 13:40:05 +01:00
|
|
|
|
|
|
|
html: function( ){ console.log("html-mesh requirement mounted") },
|
|
|
|
stylis: function( ){ console.log("stylis requirement mounted") },
|
|
|
|
|
|
|
|
DOMready: function(e){
|
|
|
|
// our reactive dom element has been added to the dom (DOMElement = this.el.dom)
|
|
|
|
},
|
|
|
|
|
2024-01-01 19:53:10 +01:00
|
|
|
click: function(e){ // a click was detected on this.el.dom or AFRAME entity
|
|
|
|
let el = e.detail.target || e.detail.srcElement
|
|
|
|
if( !el ) return
|
|
|
|
if( el.className.match("fold") ) this.el.toggleFold()
|
|
|
|
if( el.className.match("close") ) this.el.close()
|
2023-12-31 21:25:51 +01:00
|
|
|
},
|
2024-01-03 13:40:05 +01:00
|
|
|
|
2024-01-01 14:01:35 +01:00
|
|
|
input: function(e){
|
|
|
|
if( !e.detail.target ) return
|
2024-01-01 19:53:10 +01:00
|
|
|
if( e.detail.target.id == 'myRange' ) this.data.value = e.detail.target.value // reactive demonstration
|
|
|
|
},
|
2024-01-03 13:40:05 +01:00
|
|
|
|
|
|
|
value: function(e){ this.el.dom.querySelector("#value").innerHTML = e.detail.v }, // auto-emitted when this.data.value gets updated
|
|
|
|
|
2023-11-11 12:53:43 +01:00
|
|
|
},
|
|
|
|
|
2023-12-31 21:25:51 +01:00
|
|
|
init: function () {
|
2024-01-02 19:00:25 +01:00
|
|
|
this.require( this.requires )
|
2024-01-03 13:40:05 +01:00
|
|
|
|
|
|
|
this.scene.addEventListener('apps:2D', () => this.el.setAttribute('visible', false) )
|
|
|
|
this.scene.addEventListener('apps:XR', () => {
|
|
|
|
this.el.setAttribute('visible', true)
|
|
|
|
this.el.setAttribute("html",`html:#${this.el.uid}; cursor:#cursor`)
|
|
|
|
})
|
2023-12-31 21:25:51 +01:00
|
|
|
},
|
2023-11-11 12:53:43 +01:00
|
|
|
|
|
|
|
manifest: { // HTML5 manifest to identify app to xrsh
|
|
|
|
"short_name": "Hello world",
|
|
|
|
"name": "Hello world",
|
|
|
|
"icons": [
|
|
|
|
{
|
|
|
|
"src": "/images/icons-vector.svg",
|
|
|
|
"type": "image/svg+xml",
|
|
|
|
"sizes": "512x512"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"id": "/?source=pwa",
|
|
|
|
"start_url": "/?source=pwa",
|
|
|
|
"background_color": "#3367D6",
|
|
|
|
"display": "standalone",
|
|
|
|
"scope": "/",
|
|
|
|
"theme_color": "#3367D6",
|
|
|
|
"shortcuts": [
|
|
|
|
{
|
2023-12-31 21:25:51 +01:00
|
|
|
"name": "What is the latest news?",
|
|
|
|
"cli":{
|
|
|
|
"usage": "helloworld <type> [options]",
|
|
|
|
"example": "helloworld news",
|
|
|
|
"args":{
|
|
|
|
"--latest": {type:"string"}
|
|
|
|
}
|
|
|
|
},
|
2023-11-11 12:53:43 +01:00
|
|
|
"short_name": "Today",
|
|
|
|
"description": "View weather information for today",
|
|
|
|
"url": "/today?source=pwa",
|
|
|
|
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "Hello world information",
|
|
|
|
"screenshots": [
|
|
|
|
{
|
|
|
|
"src": "/images/screenshot1.png",
|
|
|
|
"type": "image/png",
|
|
|
|
"sizes": "540x720",
|
|
|
|
"form_factor": "narrow"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"help":`
|
|
|
|
Helloworld application
|
|
|
|
|
|
|
|
This is a help file which describes the application.
|
|
|
|
It will be rendered thru troika text, and will contain
|
|
|
|
headers based on non-punctualized lines separated by linebreaks,
|
|
|
|
in above's case "\nHelloworld application\n" will qualify as header.
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|