Skip to content
Snippets Groups Projects
Commit 9f936d9c authored by David Sehnal's avatar David Sehnal
Browse files

Merge gl-geo

parents d4ed6cc7 152b5219
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
/*
* This code has been modified from https://github.com/mikolalysenko/to-px,
* copyright (c) 2015 Mikola Lysenko. MIT License
*/
import parseUnit from './parse-unit'
const PIXELS_PER_INCH = 96
function getPropertyInPX(element: Element, prop: string) {
const parts = parseUnit(getComputedStyle(element).getPropertyValue(prop))
return parts[0] * toPixels(parts[1], element)
}
// This brutal hack is needed
function getSizeBrutal(unit: string, element: Element) {
const testDIV = document.createElement('div')
testDIV.style.setProperty('font-size', '128' + unit)
element.appendChild(testDIV)
const size = getPropertyInPX(testDIV, 'font-size') / 128
element.removeChild(testDIV)
return size
}
export default function toPixels(str: string, element: Element = document.body): number {
str = (str || 'px').trim().toLowerCase()
switch (str) {
case '%': // Ambiguous, not sure if we should use width or height
return element.clientHeight / 100.0
case 'ch':
case 'ex':
return getSizeBrutal(str, element)
case 'em':
return getPropertyInPX(element, 'font-size')
case 'rem':
return getPropertyInPX(document.body, 'font-size')
case 'vw':
return window.innerWidth/100
case 'vh':
return window.innerHeight/100
case 'vmin':
return Math.min(window.innerWidth, window.innerHeight) / 100
case 'vmax':
return Math.max(window.innerWidth, window.innerHeight) / 100
case 'in':
return PIXELS_PER_INCH
case 'cm':
return PIXELS_PER_INCH / 2.54
case 'mm':
return PIXELS_PER_INCH / 25.4
case 'pt':
return PIXELS_PER_INCH / 72
case 'pc':
return PIXELS_PER_INCH / 6
}
return 1
}
\ No newline at end of file
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
"outDir": "build/node_modules", "outDir": "build/node_modules",
"baseUrl": "src", "baseUrl": "src",
"paths": { "paths": {
"mol-task": ["./mol-task", "./mol-task/index.ts"],
"mol-comp": ["./mol-comp", "./mol-comp/index.ts"],
"mol-util": ["./mol-util", "./mol-util/index.ts"],
"mol-data": ["./mol-data", "./mol-data/index.ts"], "mol-data": ["./mol-data", "./mol-data/index.ts"],
"mol-math": ["./mol-math"], "mol-gl": ["./mol-gl"],
"mol-io": ["./mol-io"], "mol-io": ["./mol-io"],
"mol-model": ["./mol-model"] "mol-math": ["./mol-math"],
"mol-model": ["./mol-model"],
"mol-ql": ["./mol-ql"],
"mol-task": ["./mol-task", "./mol-task/index.ts"],
"mol-util": ["./mol-util", "./mol-util/index.ts"],
} }
}, },
"include": [ "**/*" ] "include": [ "**/*" ]
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=1" />
<title>Mol* Render Test</title>
</head>
<body>
<div id="app"></div>
<script src="./index.js"></script>
</body>
</html>
\ No newline at end of file
const path = require('path');
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
module.exports = {
module: {
rules: [
{
loader: 'raw-loader',
test: /\.(glsl|frag|vert)$/,
include: [ path.resolve(__dirname, "build/node_modules/") ],
},
{
loader: 'glslify-loader',
test: /\.(glsl|frag|vert)$/,
include: [ path.resolve(__dirname, "build/node_modules/") ]
}
]
},
plugins: [
new ExtraWatchWebpackPlugin({
files: [ './**/*.vert', './**/*.frag', './**/*.glsl' ],
}),
],
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment