nuke-dimensions
Advanced tools
Comparing version 2.0.1 to 2.1.1-1
105
lib/index.js
@@ -1,104 +0,1 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _nukeEnv = require('nuke-env'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var FULL_WIDTH = 750; | ||
var NAVBAR_HEIGHT = 64; | ||
var DEFAULT_SCALE = 2; | ||
function getDimensions() { | ||
var landscape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
var dimensions = {}; | ||
if (_nukeEnv.isWeex) { | ||
var weexEnv = typeof WXEnvironment !== 'undefined' ? WXEnvironment : {}; | ||
weexEnv.deviceHeight = parseInt(weexEnv.deviceHeight, 10); | ||
weexEnv.deviceWidth = parseInt(weexEnv.deviceWidth, 10); | ||
var scale = parseFloat(weexEnv.scale, 10) || DEFAULT_SCALE; | ||
if (landscape) { | ||
dimensions = { | ||
window: { | ||
width: (weexEnv.deviceHeight * 750 / weexEnv.deviceWidth).toFixed(), | ||
scale: scale, | ||
fontScale: 1 | ||
}, | ||
screen: { | ||
width: weexEnv.deviceHeight, | ||
height: weexEnv.deviceWidth | ||
} | ||
}; | ||
var navbarHeight = 52; | ||
if (scale > 2) { | ||
navbarHeight = 64; | ||
} | ||
dimensions.window.height = (FULL_WIDTH - navbarHeight * scale * FULL_WIDTH / weexEnv.deviceWidth).toFixed(); | ||
} else { | ||
dimensions = { | ||
window: { | ||
width: FULL_WIDTH, | ||
height: ((weexEnv.deviceHeight - NAVBAR_HEIGHT * scale) * FULL_WIDTH / weexEnv.deviceWidth).toFixed(), | ||
scale: scale, | ||
fontScale: 1 | ||
}, | ||
screen: { | ||
width: weexEnv.deviceWidth, | ||
height: weexEnv.deviceHeight | ||
} | ||
}; | ||
} | ||
} else if (_nukeEnv.isWeb) { | ||
var documentElement = document.documentElement; | ||
dimensions = { | ||
window: { | ||
width: FULL_WIDTH, | ||
height: (documentElement.clientHeight * FULL_WIDTH / documentElement.clientWidth).toFixed(), | ||
scale: window.devicePixelRatio || DEFAULT_SCALE, | ||
fontScale: 1 | ||
} | ||
}; | ||
dimensions.screen = _extends({}, window.screen); | ||
dimensions.screen.width = window.screen.width * window.devicePixelRatio; | ||
dimensions.screen.height = window.screen.height * window.devicePixelRatio; | ||
} | ||
return dimensions; | ||
} | ||
var Dimensions = function () { | ||
function Dimensions() { | ||
_classCallCheck(this, Dimensions); | ||
} | ||
_createClass(Dimensions, null, [{ | ||
key: 'get', | ||
value: function get(dim) { | ||
return getDimensions()[dim]; | ||
} | ||
}, { | ||
key: 'getWindowInfo', | ||
value: function getWindowInfo(landscape) { | ||
return getDimensions(landscape)['window']; | ||
} | ||
}, { | ||
key: 'getScreenInfo', | ||
value: function getScreenInfo(landscape) { | ||
return getDimensions(landscape)['screen']; | ||
} | ||
}]); | ||
return Dimensions; | ||
}(); | ||
exports.default = Dimensions; | ||
module.exports = exports['default']; | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.default=void 0;var _createClass=function(){function defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),_extends=Object.assign||function(target){for(var source,i=1;i<arguments.length;i++)for(var key in source=arguments[i],source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key]);return target},_nukeEnv=require('nuke-env');function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError('Cannot call a class as a function')}var FULL_WIDTH=750,NAVBAR_HEIGHT=64,DEFAULT_SCALE=2;function getDimensions(){var landscape=!!(0<arguments.length&&arguments[0]!==void 0)&&arguments[0],dimensions={};if(_nukeEnv.isWeex){var weexEnv='undefined'==typeof WXEnvironment?{}:WXEnvironment;weexEnv.deviceHeight=parseInt(weexEnv.deviceHeight,10),weexEnv.deviceWidth=parseInt(weexEnv.deviceWidth,10);var scale=parseFloat(weexEnv.scale,10)||DEFAULT_SCALE;if(landscape){dimensions={window:{width:(750*weexEnv.deviceHeight/weexEnv.deviceWidth).toFixed(),scale:scale,fontScale:1},screen:{width:weexEnv.deviceHeight,height:weexEnv.deviceWidth}};var navbarHeight=52;2<scale&&(navbarHeight=64),dimensions.window.height=(FULL_WIDTH-navbarHeight*scale*FULL_WIDTH/weexEnv.deviceWidth).toFixed()}else dimensions={window:{width:FULL_WIDTH,height:((weexEnv.deviceHeight-NAVBAR_HEIGHT*scale)*FULL_WIDTH/weexEnv.deviceWidth).toFixed(),scale:scale,fontScale:1},screen:{width:weexEnv.deviceWidth,height:weexEnv.deviceHeight}}}else if(_nukeEnv.isWeb){var documentElement=document.documentElement;dimensions={window:{width:FULL_WIDTH,height:(documentElement.clientHeight*FULL_WIDTH/documentElement.clientWidth).toFixed(),scale:window.devicePixelRatio||DEFAULT_SCALE,fontScale:1}},dimensions.screen=_extends({},window.screen),dimensions.screen.width=window.screen.width*window.devicePixelRatio,dimensions.screen.height=window.screen.height*window.devicePixelRatio}return dimensions}var Dimensions=function(){function Dimensions(){_classCallCheck(this,Dimensions)}return _createClass(Dimensions,null,[{key:'get',value:function get(dim){return getDimensions()[dim]}},{key:'getWindowInfo',value:function getWindowInfo(landscape){return getDimensions(landscape).window}},{key:'getScreenInfo',value:function getScreenInfo(landscape){return getDimensions(landscape).screen}}]),Dimensions}();exports.default=Dimensions,module.exports=exports['default']; |
{ | ||
"name": "nuke-dimensions", | ||
"version": "2.0.1", | ||
"version": "2.1.1-1", | ||
"description": "屏幕参数", | ||
@@ -23,9 +23,2 @@ "main": "lib/index", | ||
}, | ||
"scripts": { | ||
"dev": "nuke-bin server", | ||
"build": "nuke-bin build", | ||
"prepublish": "nuke-bin build", | ||
"test": "nuke-bin test", | ||
"lint": "eslint '@(src|docs)/**/*.@(js|jsx|md)' || true" | ||
}, | ||
"repository": { | ||
@@ -36,9 +29,9 @@ "type": "git", | ||
"dependencies": { | ||
"nuke-env": "^2.x.x" | ||
"nuke-env": "^2.1.1-1" | ||
}, | ||
"devDependencies": { | ||
"nuke-page": "^2.x.x", | ||
"nuke-button": "^2.x.x", | ||
"nuke-view": "^2.x.x", | ||
"nuke-text": "^2.x.x" | ||
"nuke-button": "^2.1.1-1", | ||
"nuke-page": "^2.1.1-1", | ||
"nuke-text": "^2.1.1-1", | ||
"nuke-view": "^2.1.1-1" | ||
}, | ||
@@ -48,3 +41,4 @@ "publishConfig": { | ||
}, | ||
"license": "Apache" | ||
"license": "Apache", | ||
"gitHead": "cec01e455f5e020ef33ebf3a1d4006d33c87914e" | ||
} |
/** @jsx createElement */ | ||
import {createElement, Component,render} from 'rax'; | ||
import { createElement, Component, render } from 'rax'; | ||
import View from 'nuke-view'; | ||
@@ -8,52 +8,59 @@ import Text from 'nuke-text'; | ||
import Button from 'nuke-button'; | ||
let App = class NukeDemoIndex extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
width:0, | ||
height:0 | ||
} | ||
} | ||
press = ()=>{ | ||
let { height, width } = Dimensions.getWindowInfo(); | ||
this.setState({ | ||
width:width, | ||
height:height | ||
}) | ||
} | ||
render() { | ||
return ( | ||
<Page title="Dimensions"> | ||
<View style={styles.result}> | ||
{this.state.width ? <Text style={styles.resultText}>屏幕宽度:{this.state.width} rem,高度{this.state.height} rem</Text> :null} | ||
</View> | ||
<View style={styles.btns}> | ||
<Button style={styles.btn} block onPress={this.press} type="primary">获取</Button> | ||
</View> | ||
</Page> | ||
); | ||
} | ||
} | ||
const styles={ | ||
result : { | ||
height:'480rem', | ||
margin:'30rem', | ||
padding:'10rem', | ||
backgroundColor:'#ffffff', | ||
justifyContent:'center', | ||
alignItems:'center' | ||
}, | ||
resultText : { | ||
fontSize:'28rem' | ||
}, | ||
btns:{ | ||
margin:'30rem', | ||
}, | ||
btn:{ | ||
marginBottom:'30rem' | ||
} | ||
} | ||
render(<App/>); | ||
const styles = { | ||
result: { | ||
height: '480rem', | ||
margin: '30rem', | ||
padding: '10rem', | ||
backgroundColor: '#ffffff', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
resultText: { | ||
fontSize: '28rem', | ||
}, | ||
btns: { | ||
margin: '30rem', | ||
}, | ||
btn: { | ||
marginBottom: '30rem', | ||
}, | ||
}; | ||
const App = class NukeDemoIndex extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
width: 0, | ||
height: 0, | ||
}; | ||
} | ||
press = () => { | ||
const { height, width } = Dimensions.getWindowInfo(); | ||
this.setState({ | ||
width, | ||
height, | ||
}); | ||
}; | ||
render() { | ||
return ( | ||
<Page title="Dimensions"> | ||
<View style={styles.result}> | ||
{this.state.width ? ( | ||
<Text style={styles.resultText}> | ||
屏幕宽度: | ||
{this.state.width} rem,高度 | ||
{this.state.height} rem | ||
</Text> | ||
) : null} | ||
</View> | ||
<View style={styles.btns}> | ||
<Button style={styles.btn} block onPress={this.press} type="primary"> | ||
获取 | ||
</Button> | ||
</View> | ||
</Page> | ||
); | ||
} | ||
}; | ||
render(<App />); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15102
144
3
1
Updatednuke-env@^2.1.1-1