npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

three-dom-texture

v0.1.0

Published

Transform DOM to threejs texture

Downloads

3

Readme

THREE.DOMTexture

Transform DOM to threejs texture

中文

Overview

DOMTexture transform DOM to threejs texture with Blob and Foreign object SVG.

Usage

install with npm install three-dom-texture

import { DOMTexture } from 'three-dom-texture'
// or
const { DOMTexture } = require('three-dom-texture')

include script

<script src="three.min.js"></script>
<script src="DOMTexture.min.js"></script>

create texture

    var domTexture = new THREE.DOMTexure(options, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding)
    // don't forget update texture when you update the dom
    domTexture.needsUpdate = true

the first parameter is options to set DOM, which can be a DOM, DOMString or object, other parameters is the same as THREE.Texture.

  // DOM
  new THREE.DOMTexture(document.createElement('div'))
  // DOMString
  new THREE.DOMTexture('<div>...</div>')
  // object
  new THREE.DOMTexture({
      width: <number>, // internal DOM width, default 512
      height: <number>, // internal DOM height, default 512
      content: <DOM | DOMString>, // internal DOM
      dpr: <number>, // canvas devicePixelRatio, default window.devicePixelRatio
  })

The methods that domTexture added on THREE.Texture:

  • updateSize - set innernal DOM width, height, dpr. this method will return a new DOMTexure instance and dispose current instance.
  • setContent - set internal DOM [ DOM or DOMString ]
  • domInlineStyle - write the context style to the element. affect your DOM, useless for DOMString.

after use these methods, don't forget to set needsUpdate.

Caveats

Due to the use of Foreign object SVG, there are some things to be aware of.

  • Internet Explorer is not supported, as it doesn't support the foreignObject tag in SVG.
  • SVG's foreignObject is subject to strong security, any external content will likely fail (i.e. link, iframes, web fonts)
    • if you want to <link> some stylesheet, you can use <style> and write CSS in it.
    • if you want to use <img>, you can use <div> and set the image as background. --WARN: The background can not be a URL, but it can be base64
  • DOMTexture can get style inside the <style> of the internal DOM, but can not get in the document context. you can run domTexture.domInlineStyle() to write the context style to the element. --WARN: domInlineStyle will affect your DOM, useless for DOMString

License

MIT licensed

Copyright (c) 2017 jinrui