|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <base data-ice="baseUrl" href="../../"> |
| 6 | + <title data-ice="title">src/elementMgr.js | live2d-widget.js</title> |
| 7 | + <link type="text/css" rel="stylesheet" href="css/style.css"> |
| 8 | + <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> |
| 9 | + <script src="script/prettify/prettify.js"></script> |
| 10 | + <script src="script/manual.js"></script> |
| 11 | +<meta name="description" content="Add the Sseexxyyy live2d to webpages."><meta property="twitter:card" content="summary"><meta property="twitter:title" content="live2d-widget.js"><meta property="twitter:description" content="Add the Sseexxyyy live2d to webpages."></head> |
| 12 | +<body class="layout-container" data-ice="rootContainer"> |
| 13 | + |
| 14 | +<header> |
| 15 | + <a href="./">Home</a> |
| 16 | + |
| 17 | + <a href="identifiers.html">Reference</a> |
| 18 | + <a href="source.html">Source</a> |
| 19 | + |
| 20 | + <div class="search-box"> |
| 21 | + <span> |
| 22 | + <img src="./image/search.png"> |
| 23 | + <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> |
| 24 | + </span> |
| 25 | + <ul class="search-result"></ul> |
| 26 | + </div> |
| 27 | +<a style="position:relative; top:3px;" href="https://github.com/xiazeyu/live2d-widget.js"><img width="20px" src="./image/github.png"></a></header> |
| 28 | + |
| 29 | +<nav class="navigation" data-ice="nav"><div> |
| 30 | + <ul> |
| 31 | + |
| 32 | + <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-PlatformManager">PlatformManager</a></span></span></li> |
| 33 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-cManager">cManager</a></span></span></li> |
| 34 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-cModel">cModel</a></span></span></li> |
| 35 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-cLive2DApp">cLive2DApp</a></span></span></li> |
| 36 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-createElement">createElement</a></span></span></li> |
| 37 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-init">init</a></span></span></li> |
| 38 | +<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getCurrentPath">getCurrentPath</a></span></span></li> |
| 39 | +<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-currWebGL">currWebGL</a></span></span></li> |
| 40 | +<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#-utils">_utils</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-ModelSettingJson">ModelSettingJson</a></span></span></li> |
| 41 | +<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#config">config</a><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-configApplyer">configApplyer</a></span></span></li> |
| 42 | +</ul> |
| 43 | +</div> |
| 44 | +</nav> |
| 45 | + |
| 46 | +<div class="content" data-ice="content"><h1 data-ice="title">src/elementMgr.js</h1> |
| 47 | +<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">/** |
| 48 | + * @description The container and manager for all the DOM and WebGL emelents. |
| 49 | + */ |
| 50 | + |
| 51 | + |
| 52 | +import { config } from './config/configMgr'; |
| 53 | +import htmlTemplate from './tmplate/innerHTML'; |
| 54 | + |
| 55 | +/** |
| 56 | + * The current WebGL element |
| 57 | + * @type {RenderingContext} |
| 58 | + */ |
| 59 | + |
| 60 | +let currWebGL = undefined; |
| 61 | + |
| 62 | +/** |
| 63 | + * The current canvas element |
| 64 | + * @type {HTMLElement} |
| 65 | + */ |
| 66 | + |
| 67 | +let currCanvas; |
| 68 | + |
| 69 | +/** |
| 70 | + * Create the canvas and styles using DOM |
| 71 | + * @return {null} |
| 72 | + */ |
| 73 | + |
| 74 | +function createElement(){ |
| 75 | + |
| 76 | + let newElem = document.createElement('div'); |
| 77 | + newElem.id = config.name.div; |
| 78 | + newElem.innerHTML = htmlTemplate; |
| 79 | + let newCanvasElem = document.createElement('canvas'); |
| 80 | + newCanvasElem.setAttribute('id', config.name.canvas); |
| 81 | + newCanvasElem.setAttribute('width', config.display.width * config.display.antialias); |
| 82 | + newCanvasElem.setAttribute('height', config.display.height * config.display.antialias); |
| 83 | + newCanvasElem.style.setProperty('position', 'fixed'); |
| 84 | + newCanvasElem.style.setProperty('width', config.display.width); |
| 85 | + newCanvasElem.style.setProperty('height', config.display.height); |
| 86 | + newCanvasElem.style.setProperty('opacity', config.react.opacityDefault); |
| 87 | + newCanvasElem.style.setProperty(config.display.position, config.display.hOffset + 'px'); |
| 88 | + newCanvasElem.style.setProperty('bottom', config.display.vOffset + 'px'); |
| 89 | + newCanvasElem.style.setProperty('z-index', 99999); |
| 90 | + newCanvasElem.style.setProperty('pointer-events', 'none'); |
| 91 | + if(config.dev.border) newCanvasElem.style.setProperty('border', 'dashed 1px #CCC'); |
| 92 | + newElem.appendChild(newCanvasElem); |
| 93 | + |
| 94 | + document.body.appendChild(newElem); |
| 95 | + currCanvas = document.getElementById(config.name.canvas); |
| 96 | + |
| 97 | + initWebGL(); |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +/** |
| 102 | + * Find and set the current WebGL element to the container |
| 103 | + * @return {null} |
| 104 | + */ |
| 105 | + |
| 106 | +function initWebGL(){ |
| 107 | + |
| 108 | + var NAMES = ['webgl2', 'webgl', 'experimental-webgl2', 'experimental-webgl', 'webkit-3d', 'moz-webgl']; |
| 109 | + for(let i = 0; i < NAMES.length; i++){ |
| 110 | + try{ |
| 111 | + let ctx = currCanvas.getContext(NAMES[i], { |
| 112 | + alpha: true, |
| 113 | + antialias: true, |
| 114 | + premultipliedAlpha: true, |
| 115 | + failIfMajorPerformanceCaveat: false, |
| 116 | + }); |
| 117 | + if(ctx) currWebGL = ctx; |
| 118 | + }catch(e){} |
| 119 | + } |
| 120 | + if(!currWebGL){ |
| 121 | + console.error('Live2D widgets: Failed to create WebGL context.'); |
| 122 | + if(!window.WebGLRenderingContext){ |
| 123 | + console.error('Your browser may not support WebGL, check https://get.webgl.org/ for futher information.'); |
| 124 | + } |
| 125 | + return; |
| 126 | + } |
| 127 | +}; |
| 128 | + |
| 129 | + |
| 130 | +export{ |
| 131 | + createElement, |
| 132 | + currWebGL, |
| 133 | +} |
| 134 | +</code></pre> |
| 135 | + |
| 136 | +</div> |
| 137 | + |
| 138 | +<footer class="footer"> |
| 139 | + Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a> |
| 140 | +</footer> |
| 141 | + |
| 142 | +<script src="script/search_index.js"></script> |
| 143 | +<script src="script/search.js"></script> |
| 144 | +<script src="script/pretty-print.js"></script> |
| 145 | +<script src="script/inherited-summary.js"></script> |
| 146 | +<script src="script/test-summary.js"></script> |
| 147 | +<script src="script/inner-link.js"></script> |
| 148 | +<script src="script/patch-for-local.js"></script> |
| 149 | +</body> |
| 150 | +</html> |
0 commit comments