Giter Club home page Giter Club logo

aframe-htmlembed-component's Introduction

HTML Embed Component

HTML Embed is a component created for A-Frame. The HTML Embed component allows for arbitrary html to be inserted into your aframe scene. It allows you to update the display within A-Frame simply by manipulating the DOM as you normally would.

In addition to rendering the html to the A-Frame scene it allows for interaction. Most css pseudo selectors such as hover, active, focus and target should work with interactivity enabled without any modifications to your css. Mouse events can be attached to the html elements as usual.

Limitations

  • All styles and images must be in the same origin or allow access via CORS; this allows the component to embed all of the assets required to render the html properly to the canvas via the foreignObject element.
  • transform-style css is limited to flat. This is mainly due to it not being rendered properly to canvas so element bounding for preserve-3d has not yet been implemented. If the rendering is fixed as some point I may go back and get it working as well.
  • "a-" tags do not render correctly as XHTML embeded into SVG, so any parent "a-" elements of the embed html will be converted to div tags for rendering. This may mean your css will require modification.
  • Elements that require rendering outside of the DOM such as the iframe and canvas element will not work.
  • :before and :after pseudo elements can't be accessed via the DOM so they can't be used in the element to determine the object bounds. As such, use them with caution.
  • Form elements are not consistently rendered to the canvas element so some basic default styles are included for consistency.
  • Currently there is no support for css transitions.

Properties

Property Default Description
ppu 256 number of pixels to display per unit of the aframescene.

Methods

Method Description
forceRender Forces the htmlembed component to be re-render

Events

Name Event Type Description
focusableenter FocusableEvent Dispatched when the cursor is moved over a focusable element. Useful for providing visual/haptic feedback to the user letting them know that the element is clickable.
focusableleave FocusableEvent Dispatched when the cursor is moved out of a focusable element.
inputrequired InputrequiredEvent Dispatched when an element that requires keyboard input or a user selection is clicked. Can be used to bring up a custom keyboard.
resized N/A Dispatched when the embed html content size is changed.
rendered N/A Dispatched when the embedded HTML content is rendered to the A-Frame Scene.

FocusableEvent

Property Description
target The target element that the cursor is over.

InputrequiredEvent

Property Description
target The input element that the user selected.

How to Use

To use the component you just add the component to the A-Frame entity containing the html. For example:

<a-scene>
  <a-entity htmlembed position="0 0 -5">
    <h1>An Example</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    <img src="myImages.png" alt="image">
  </a-entity>
</a-scene>

Interactivity

Using CSS

HTML Embed allows you to add interactivity by adding standard css interactions such as hover:

.button{
	display: inline-block;
	border-radius: 5px;
	background-color: #dddddd;
	color: #000000;
}
.button:hover{
	background-color: #000000;
	color: #ffffff;
}
<a-scene>
	<a-entity htmlembed>
		<a href="#home" class="button">Home</a>
	</a-entity>
</a-scene>

Using Javascript

You can add javascript interactivity in the standard way either by events on the elements themselves or alternatively by adding event listeners to the DOM.

<a-scene>
	<a-entity htmlembed>
		<div id="clickme" onclick="console.log('do something')">Click Me</div>
	</a-entity>
</a-scene>
document.querySelector('#clickme').addEventListener('click',function(e){
	console.log('do something else');
});

Interactions

Interactions are achived though the normal cursor and laser-controls components and allow you to interacte with the html as if you where using a mouse. If an element is clicked that requires keyboard input the inputrequired event is dispatched so a keyboard overlay can be invoked.

Installation

Browser

Install and use by directly including the browser files:

<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
  <script src="https://supereggbert.github.io/aframe-htmlembed-component/dist/build.js"></script>
</head>

<body>
  <a-scene>
    <a-entity position="0 1.6 -1" htmlembed>
		<p>My HTML</p>
	</a-entity>
  </a-scene>
</body>
	

npm

Install via npm:

npm install aframe-htmlembed-component

Then register and use.

require('aframe');
require('aframe-htmlembed-component');

Building

  • Install Node.js.

  • Clone the project to your file system:

git clone https://github.com/supereggbert/aframe-htmlembed-component.git
  • enter the aframe-htmlembed-component directory.

cd ./aframe-htmlembed-component

  • Install build dependencies

npm install

  • Run the build script.

npm run build

The compiled file is at aframe-htmlembed-component/dist/build.js

aframe-htmlembed-component's People

Contributors

dependabot[bot] avatar paulmasson avatar supereggbert avatar utopiah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aframe-htmlembed-component's Issues

suggestion : allow the use of css selector

Hi, i would love to have the ability to use html code outside of the aframe code.
Use case : allowing the user to visite my website in classic html And in VR without duplicate HTML and CSS.

Does setting a div visibility to hidden work?

Hi! I tried setting the visibility to hidden just like this:

 function hide(id){
    const elm = document.getElementById(id)
    current.style.visibility = 'hidden'
    document.querySelector('[htmlembed]').components.htmlembed.forceRender()
}

Despite showing changes when I look at the HTML inspector, I don't see it changed in my scene. I tried forcing the rendering with forceRenderer() but didn't have luck.

Hope this can be solved.

inputrequired event example needed

I would appreciate an HTML example that shows how to add the inputrequired event to the <input> field of a form, please, like in the following:

First name: <input type="text" name="fname"> 

Thank's.

component not working in Android

component not working in Android web view.

It display a black box instead.

Tested on: Remi Note7 Andriod Pie MIUI10.3.6.0. Native Browser and webview

not consistent

When I start my aframe application for the first time, html component built using htmlembed is visible but when refresh the app it goes invisible and this happens always. Like it is toggling its visibility on when the page is refreshed. It is built using nodejs.

Null is not a valid URL - Check element hasAttribute href

Hello,

I'm getting a Null is not a valid URL exception in generatePageCSS on line 285.
I think a hasAttribute check will solve the issue.

My situation is that I have my scene within an iframe, so I'm wondering if all the document.querySelectorAll statements are selecting from the parent document? Because there shouldn't be any styles in the iframe.

Not working with arjs inside a-marker

I want to use html inside a-scene for web ar. This library works as usual but not showing the contenet between
<a-scene> <a-marker> <a-entity htmlembed> <h1>An Example</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </a-entity> </a-marker> </a-scene>
According to the arjs documentation https://ar-js-org.github.io/AR.js-Docs/marker-based/
I would really appreciate if anyone has alternative solution for this is problem

Incompatible with A-Frame 1.3.0?

Using the included example, only change made was to pull in A-Frame 1.3.0 instead of 0.9.2. None of the elements in the demo render, no error thrown. Appears to work fine with A-Frame up to 1.2.0

This component appears to be abandonware - does anyone know of a supported component to display HTML elements in A-Frame that works with the current version? Alternately, what change

Image doesn't show

I have try the example. The image doesn't show up. But, if I try to inspect the document, it is downloaded and accessible. If there's any special requirement for using image in html? Beside what stated in the github repo.

Transparency

Is it possible to have a transparent background?

 background-color: transparent;
}

isn't doing it.

Dynamically add component

I'm trying to use this component and dynamically add it to the scene

        this._poster = make('a-entity', {
            'htmlembed': true
        }, this.el)
        this._poster.innerHMTL = '<h1>An Example</h1><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>'
        this._poster.components.htmlembed.forceRender()

I'm getting

build.js:1 Uncaught (in promise) TypeError: Cannot read property 'forceRender' of undefined
(from within the component)

And the innerHTML does not appear to be getting set, which is why I assume it's throwing that error.

Is there another way to create the element and set the inner html?

Problem with non-inline css. (Live example)

Hello.

When using not inline CSS, but .css file loaded in the header page menu is not displayed, while in the browser console have this warning:

  • Firefox: "WebGL warning: texSubImage: Offset+size must be <= the size of the existing specified image."
  • Chrome: "[.WebGL-00005B4402385500] GL_INVALID_VALUE: Offset overflows texture dimensions."

As soon as I move the css from the file to the html page in the style tag, the menu starts displaying. But, I need to use non-inline styles, how can I avoid this error and get the menu to display?

Live example: https://aframe-htmlembed-component-css-file.glitch.me
Code editor: https://glitch.com/edit/#!/aframe-htmlembed-component-css-file

Thank you.

Support for SVG

Hello there,

I am working on an app where I am using SVG data extensively and the <use> tag.
At the moment though it doesn't seem like SVG is supported in your library.
The following for eg does not render:
CodePen

<a-scene >
  <a-entity htmlembed="" position="0 1.75 -.5">
<svg id="svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="50" cy="50" r="50"/>
</svg>
 </a-entity>
</a-scene>

Is there any chance you might add support for this?

Border radius

I can see you handle border radius in the component.

How do I set it on the parent element?

i.e.

<div class="poster">
 ....
</div>


.poster = {
        border-radius: 4px;
}

isn't having any effect.

Scrolling

First: thanks a lot for creating this component!

I wondered if there could be a way to have longer content scrolling, e.g. "overflow: scroll" support?

Thanks!

Doesn't work with react

I love this component as it's making a lot of my project possible. But it appears that it's incompatible with React, the reloading of css breaks the css for everything else. I'm trying to come up with a work around, but I figured I'd let you know.

Seems to be something to do with HMR.

Freezes the browser for a long time in local environment with Vue.js

Hello, thanks for your work.

We are using this package in Vue.js and, when running the project locally with webpack-dev-server (ONLY when running it locally) we run into a very long browser freeze which we have pinpointed to
generatePageCSS and more specifically to a very long series of calls to csshack.

Attached you can find a Chrome profiler session where the problem occurs:
aframe-html-embed-problem.zip

Do you have any clue about what's happening?

As I mentioned, thi sonly happens in http://localhost:8080 , when the app is built and deployed to an https server the problem goes away.... still I find it worth reporting.

Thanks

can't invert matrix, determinant is 0

Hi,

first of all - thanks for this great component!

Then: I get tons of 'can't invert matrix, determinant is 0' warnings.
I saw that issue 1a04a62 addressed something like that?
So I rebuild the component, but the warnings are still there.

Everything is running great though, just the warnings are a bit annoying.

Thanks again,
Dirk

position() and offset() of entities are always 0

My HTML contains an image with an attached click-listener. I'd like to retrieve the mouse clicks position relative to the image like

var X = (e.pageX - this.offsetLeft);
var Y = (e.pageY - this.offsetTop);

but the offset always returns 0. Is there a way to get the precise relative position of an entity in the document without substracting its precalculated position?

mousedown behaves strange on mobile

Hi,

when you try the provided example, and you switch to mobile mode in chrome, then the execution of the mousedown/click event happens only every second time. Effectively you need two clicks - one on the button and a second one anywhere.

Best regards,
Dirk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.