breakdancer 4.2.1 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +1 -1
- package/lib/breakdancer.js +0 -152
- package/lib/index.js +0 -113
- package/lib/index.native.js +0 -95
- package/lib/test.js +0 -177
- package/lib/test.native.js +0 -105
package/index.js
CHANGED
package/package.json
CHANGED
package/lib/breakdancer.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
10
|
-
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); } }
|
|
11
|
-
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Breakdancer is a simple breakpoint utility.
|
|
16
|
-
*
|
|
17
|
-
* @constructor
|
|
18
|
-
* @param {Object} specification Different breakpoints we need to know.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
var Breakdancer =
|
|
22
|
-
/*#__PURE__*/
|
|
23
|
-
function () {
|
|
24
|
-
function Breakdancer(specification) {
|
|
25
|
-
_classCallCheck(this, Breakdancer);
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
// Setup our default values after the window has been set so we don't have
|
|
29
|
-
// any undefined references.
|
|
30
|
-
//
|
|
31
|
-
this.specification = this.normalize(specification);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Normalize the specification.
|
|
35
|
-
*
|
|
36
|
-
* @param {Array|Object} specification Different breakpoints we need to know.
|
|
37
|
-
* @returns {Array} List of media query specifications
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_createClass(Breakdancer, [{
|
|
43
|
-
key: "normalize",
|
|
44
|
-
value: function normalize(specification) {
|
|
45
|
-
if (Array.isArray(specification)) return specification;
|
|
46
|
-
return Object.keys(specification).reduce(function reduce(memo, key) {
|
|
47
|
-
var breakpoint = specification[key]; //
|
|
48
|
-
// If there is no name specified, use the key as name.
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
breakpoint.name = breakpoint.name || key;
|
|
52
|
-
memo.push(breakpoint);
|
|
53
|
-
return memo;
|
|
54
|
-
}, []);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Check if the setup has changed since we've last checked the real estate.
|
|
58
|
-
*
|
|
59
|
-
* @param {Object} viewport The view port specification.
|
|
60
|
-
* @returns {Boolean} True if the breakpoint for the viewport has changed.
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
}, {
|
|
65
|
-
key: "changed",
|
|
66
|
-
value: function changed(viewport) {
|
|
67
|
-
var breakpoint = this.breakpoint;
|
|
68
|
-
this.breakpoint = this.currently(viewport);
|
|
69
|
-
return this.breakpoint !== breakpoint;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Check if a given specification matches our current set resolution.
|
|
73
|
-
*
|
|
74
|
-
* @param {Object} viewport The view port specification.
|
|
75
|
-
* @param {Object} specification The supplied specification.
|
|
76
|
-
* @returns {Boolean} True if viewport fits into the specification.
|
|
77
|
-
* @private
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
}, {
|
|
81
|
-
key: "matches",
|
|
82
|
-
value: function matches(viewport, specification) {
|
|
83
|
-
viewport = viewport || this.viewport();
|
|
84
|
-
var matched = false;
|
|
85
|
-
|
|
86
|
-
if ('height' in specification) {
|
|
87
|
-
matched = viewport.height < specification.height;
|
|
88
|
-
if (!matched) return matched;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if ('width' in specification) {
|
|
92
|
-
matched = viewport.width < specification.width;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return matched;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Find out which breakpoint we're currently triggering.
|
|
99
|
-
*
|
|
100
|
-
* @param {Object} viewport The view port specification.
|
|
101
|
-
* @returns {String} The current breakpoint that we got triggered.
|
|
102
|
-
* @public
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
}, {
|
|
106
|
-
key: "currently",
|
|
107
|
-
value: function currently(viewport) {
|
|
108
|
-
viewport = viewport || this.viewport();
|
|
109
|
-
|
|
110
|
-
for (var i = 0, l = this.specification.length; i < l; i++) {
|
|
111
|
-
var spec = this.specification[i];
|
|
112
|
-
if (this.matches(viewport, spec)) return spec.name;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return 'unknown';
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Returns the difference between the current width and the given breakpoint. This
|
|
119
|
-
* can be used to check if the window is "greater" than a breakpoint. If either the
|
|
120
|
-
* given breakpoint or the given attribute do not exist, a `TypeError` will be thrown.
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @param {String} breakpoint to be compared
|
|
124
|
-
* @param {String} property height or width
|
|
125
|
-
* @throws {TypeError} If not given breakpoint and property do not exist within the given spec
|
|
126
|
-
* @returns {Number} different between current and specified properties
|
|
127
|
-
* @public
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
}, {
|
|
131
|
-
key: "compare",
|
|
132
|
-
value: function compare(breakpoint, property) {
|
|
133
|
-
var desiredSpec = this.specification.filter(function (spec) {
|
|
134
|
-
return spec.name === breakpoint;
|
|
135
|
-
})[0];
|
|
136
|
-
|
|
137
|
-
if (!desiredSpec) {
|
|
138
|
-
return new TypeError("".concat(breakpoint, " is not part of the given specifications"));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (!desiredSpec[property]) {
|
|
142
|
-
return new TypeError("".concat(breakpoint, ".").concat(property, " is not part of the given specifications"));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return this[property]() - desiredSpec[property];
|
|
146
|
-
}
|
|
147
|
-
}]);
|
|
148
|
-
|
|
149
|
-
return Breakdancer;
|
|
150
|
-
}();
|
|
151
|
-
|
|
152
|
-
exports.default = Breakdancer;
|
package/lib/index.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _breakdancer = _interopRequireDefault(require("./breakdancer"));
|
|
9
|
-
|
|
10
|
-
var _propget = _interopRequireDefault(require("propget"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
15
|
-
|
|
16
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
-
|
|
18
|
-
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); } }
|
|
19
|
-
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
21
|
-
|
|
22
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
23
|
-
|
|
24
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
|
|
26
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
-
|
|
28
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
|
-
|
|
30
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Small fallback for when the `window` global is not accessible in a given
|
|
34
|
-
* environment. This allows the module to still be used in a regular `node`
|
|
35
|
-
* environment.
|
|
36
|
-
*
|
|
37
|
-
* @type {Object} Window reference or inner{height|width} polyfill.
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
var win = typeof window !== 'undefined' ? window : {
|
|
41
|
-
innerWidth: 1280,
|
|
42
|
-
innerHeight: 768
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Breakdancer is a simple breakpoint utility.
|
|
46
|
-
*
|
|
47
|
-
* @constructor
|
|
48
|
-
* @param {Object} specification Different breakpoints we need to know.
|
|
49
|
-
* @param {Object} windows Option window object reference.
|
|
50
|
-
* @public
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
var WebDancer =
|
|
54
|
-
/*#__PURE__*/
|
|
55
|
-
function (_Breakdancer) {
|
|
56
|
-
_inherits(WebDancer, _Breakdancer);
|
|
57
|
-
|
|
58
|
-
function WebDancer(specification, windows) {
|
|
59
|
-
var _this;
|
|
60
|
-
|
|
61
|
-
_classCallCheck(this, WebDancer);
|
|
62
|
-
|
|
63
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(WebDancer).call(this, specification));
|
|
64
|
-
_this.window = windows || win;
|
|
65
|
-
_this.breakpoint = _this.currently();
|
|
66
|
-
return _this;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Return the current view port.
|
|
70
|
-
*
|
|
71
|
-
* @returns {Object} viewport
|
|
72
|
-
* @public
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
_createClass(WebDancer, [{
|
|
77
|
-
key: "viewport",
|
|
78
|
-
value: function viewport() {
|
|
79
|
-
return {
|
|
80
|
-
height: this.height(),
|
|
81
|
-
width: this.width()
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Lookup the view port width.
|
|
86
|
-
*
|
|
87
|
-
* @returns {Number} Current width.
|
|
88
|
-
* @public
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
}, {
|
|
92
|
-
key: "width",
|
|
93
|
-
value: function width() {
|
|
94
|
-
return (0, _propget.default)(this.window, 'innerWidth') || (0, _propget.default)(this.window, 'document.documentElement.clientWidth') || (0, _propget.default)(this.window, 'document.body.clientWidth') || 0;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Lookup the view port height.
|
|
98
|
-
*
|
|
99
|
-
* @returns {Number} Current height.
|
|
100
|
-
* @public
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
}, {
|
|
104
|
-
key: "height",
|
|
105
|
-
value: function height() {
|
|
106
|
-
return (0, _propget.default)(this.window, 'innerHeight') || (0, _propget.default)(this.window, 'document.documentElement.clientHeight') || (0, _propget.default)(this.window, 'document.body.clientHeight') || 0;
|
|
107
|
-
}
|
|
108
|
-
}]);
|
|
109
|
-
|
|
110
|
-
return WebDancer;
|
|
111
|
-
}(_breakdancer.default);
|
|
112
|
-
|
|
113
|
-
exports.default = WebDancer;
|
package/lib/index.native.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _breakdancer = _interopRequireDefault(require("./breakdancer"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
15
|
-
|
|
16
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
-
|
|
18
|
-
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); } }
|
|
19
|
-
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
21
|
-
|
|
22
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
23
|
-
|
|
24
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
|
|
26
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
-
|
|
28
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
|
-
|
|
30
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Breakdancer is a simple breakpoint utility.
|
|
34
|
-
*
|
|
35
|
-
* @constructor
|
|
36
|
-
* @param {Object} specification Different breakpoints we need to know.
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
var NativeDancer =
|
|
40
|
-
/*#__PURE__*/
|
|
41
|
-
function (_Breakdancer) {
|
|
42
|
-
_inherits(NativeDancer, _Breakdancer);
|
|
43
|
-
|
|
44
|
-
function NativeDancer(specification) {
|
|
45
|
-
var _this;
|
|
46
|
-
|
|
47
|
-
_classCallCheck(this, NativeDancer);
|
|
48
|
-
|
|
49
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(NativeDancer).call(this, specification));
|
|
50
|
-
_this.breakpoint = _this.currently();
|
|
51
|
-
return _this;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Return the current view port.
|
|
55
|
-
*
|
|
56
|
-
* @returns {Object} viewport
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
_createClass(NativeDancer, [{
|
|
62
|
-
key: "viewport",
|
|
63
|
-
value: function viewport() {
|
|
64
|
-
return _reactNative.Dimensions.get('window');
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Lookup the view port width.
|
|
68
|
-
*
|
|
69
|
-
* @returns {Number} Current width.
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
}, {
|
|
74
|
-
key: "width",
|
|
75
|
-
value: function width() {
|
|
76
|
-
return _reactNative.Dimensions.get('window').width;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Lookup the view port height.
|
|
80
|
-
*
|
|
81
|
-
* @returns {Number} Current height.
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
}, {
|
|
86
|
-
key: "height",
|
|
87
|
-
value: function height() {
|
|
88
|
-
return _reactNative.Dimensions.get('window').height;
|
|
89
|
-
}
|
|
90
|
-
}]);
|
|
91
|
-
|
|
92
|
-
return NativeDancer;
|
|
93
|
-
}(_breakdancer.default);
|
|
94
|
-
|
|
95
|
-
exports.default = NativeDancer;
|
package/lib/test.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = _interopRequireDefault(require("./index"));
|
|
4
|
-
|
|
5
|
-
var _assume = _interopRequireDefault(require("assume"));
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
it('is exposed as a function', function () {
|
|
10
|
-
(0, _assume.default)(_index.default).is.a('function');
|
|
11
|
-
});
|
|
12
|
-
describe('breakdancer', function () {
|
|
13
|
-
var breakdancer;
|
|
14
|
-
var specification = [{
|
|
15
|
-
name: 'mobile',
|
|
16
|
-
width: 400,
|
|
17
|
-
height: 600
|
|
18
|
-
}, {
|
|
19
|
-
name: 'desktop',
|
|
20
|
-
width: 1024
|
|
21
|
-
}, {
|
|
22
|
-
name: 'whatever',
|
|
23
|
-
width: 1409
|
|
24
|
-
}];
|
|
25
|
-
beforeEach(function () {
|
|
26
|
-
breakdancer = new _index.default(specification);
|
|
27
|
-
});
|
|
28
|
-
it('safely works without existing windows object', function () {
|
|
29
|
-
breakdancer = new _index.default(specification, {});
|
|
30
|
-
(0, _assume.default)(breakdancer.height()).equals(0);
|
|
31
|
-
(0, _assume.default)(breakdancer.width()).equals(0);
|
|
32
|
-
});
|
|
33
|
-
describe('constructor', function () {
|
|
34
|
-
it('stores the specification as arrays', function () {
|
|
35
|
-
(0, _assume.default)(breakdancer.specification).is.a('array');
|
|
36
|
-
(0, _assume.default)(breakdancer.specification[0].name).equals('mobile');
|
|
37
|
-
});
|
|
38
|
-
it('sets the current breakpoint', function () {
|
|
39
|
-
(0, _assume.default)(breakdancer.breakpoint).is.a('string');
|
|
40
|
-
(0, _assume.default)(breakdancer.breakpoint).is.either(['mobile', 'desktop', 'whatever']);
|
|
41
|
-
});
|
|
42
|
-
it('can be supplied with a custom window object', function () {
|
|
43
|
-
var bd = new _index.default(specification, {
|
|
44
|
-
innerHeight: 10,
|
|
45
|
-
innerWidth: 10
|
|
46
|
-
});
|
|
47
|
-
(0, _assume.default)(bd.breakpoint).equals('mobile');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('#height', function () {
|
|
51
|
-
it('defaults to documentElement clientHeight on missing innerHeight', function () {
|
|
52
|
-
var bd = new _index.default(specification, {
|
|
53
|
-
document: {
|
|
54
|
-
documentElement: {
|
|
55
|
-
clientHeight: 1337,
|
|
56
|
-
clientWidth: 1337
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
(0, _assume.default)(bd.height()).equals(1337);
|
|
61
|
-
});
|
|
62
|
-
it('defaults to innerHeight', function () {
|
|
63
|
-
var bd = new _index.default(specification, {
|
|
64
|
-
innerHeight: 10,
|
|
65
|
-
innerWidth: 11,
|
|
66
|
-
document: {
|
|
67
|
-
documentElement: {
|
|
68
|
-
clientHeight: 1337,
|
|
69
|
-
clientWidth: 1338
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
(0, _assume.default)(bd.height()).equals(10);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe('#width', function () {
|
|
77
|
-
it('defaults to documentElement clientHeight on missing innerWidth', function () {
|
|
78
|
-
var bd = new _index.default(specification, {
|
|
79
|
-
document: {
|
|
80
|
-
documentElement: {
|
|
81
|
-
clientHeight: 1337,
|
|
82
|
-
clientWidth: 1338
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
(0, _assume.default)(bd.width()).equals(1338);
|
|
87
|
-
});
|
|
88
|
-
it('defaults to innerWidth', function () {
|
|
89
|
-
var bd = new _index.default(specification, {
|
|
90
|
-
innerHeight: 10,
|
|
91
|
-
innerWidth: 11,
|
|
92
|
-
document: {
|
|
93
|
-
documentElement: {
|
|
94
|
-
clientHeight: 1337,
|
|
95
|
-
clientWidth: 1338
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
(0, _assume.default)(bd.width()).equals(11);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe('#changed', function () {
|
|
103
|
-
it('returns a boolean if the breakpoint has changed', function () {
|
|
104
|
-
(0, _assume.default)(breakdancer.changed()).is.false();
|
|
105
|
-
(0, _assume.default)(breakdancer.changed()).is.false();
|
|
106
|
-
(0, _assume.default)(breakdancer.changed()).is.false();
|
|
107
|
-
var viewport = {
|
|
108
|
-
width: 200,
|
|
109
|
-
height: 500
|
|
110
|
-
};
|
|
111
|
-
(0, _assume.default)(breakdancer.changed(viewport)).is.true();
|
|
112
|
-
});
|
|
113
|
-
it('updates the .breakpoint', function () {
|
|
114
|
-
var viewport = {
|
|
115
|
-
width: 200,
|
|
116
|
-
height: 500
|
|
117
|
-
};
|
|
118
|
-
(0, _assume.default)(breakdancer.breakpoint).does.not.equal('mobile');
|
|
119
|
-
(0, _assume.default)(breakdancer.changed(viewport)).is.true();
|
|
120
|
-
(0, _assume.default)(breakdancer.breakpoint).equals('mobile');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('#currently', function () {
|
|
124
|
-
it('matches as desktop', function () {
|
|
125
|
-
var viewport = {
|
|
126
|
-
width: 800,
|
|
127
|
-
height: 600
|
|
128
|
-
};
|
|
129
|
-
(0, _assume.default)(breakdancer.currently(viewport)).equals('desktop');
|
|
130
|
-
});
|
|
131
|
-
it('matches as mobile', function () {
|
|
132
|
-
var viewport = {
|
|
133
|
-
width: 200,
|
|
134
|
-
height: 500
|
|
135
|
-
};
|
|
136
|
-
(0, _assume.default)(breakdancer.currently(viewport)).equals('mobile');
|
|
137
|
-
});
|
|
138
|
-
it('matches unknown', function () {
|
|
139
|
-
var viewport = {
|
|
140
|
-
width: 1800,
|
|
141
|
-
height: 1600
|
|
142
|
-
};
|
|
143
|
-
(0, _assume.default)(breakdancer.currently(viewport)).equals('unknown');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe('#viewport', function () {
|
|
147
|
-
it('returns the width and height', function () {
|
|
148
|
-
var viewport = breakdancer.viewport();
|
|
149
|
-
(0, _assume.default)(viewport.width).is.above(0);
|
|
150
|
-
(0, _assume.default)(viewport.width).equals(breakdancer.width());
|
|
151
|
-
(0, _assume.default)(viewport.height).is.above(0);
|
|
152
|
-
(0, _assume.default)(viewport.height).equals(breakdancer.height());
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('#compare', function () {
|
|
156
|
-
var bd = new _index.default(specification, {
|
|
157
|
-
innerWidth: 1234,
|
|
158
|
-
innerHeight: 1000,
|
|
159
|
-
document: {
|
|
160
|
-
documentElement: {
|
|
161
|
-
clientHeight: 1337,
|
|
162
|
-
clientWidth: 1338
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
it('should throw an error when looking at an unspecified breakpoint', function () {
|
|
167
|
-
(0, _assume.default)(bd.compare('hologram', 'width')).throws(TypeError);
|
|
168
|
-
});
|
|
169
|
-
it('should throw an error when the given dimension does not exist for the given breakpoint', function () {
|
|
170
|
-
(0, _assume.default)(bd.compare('whatever', 'height')).throws(TypeError);
|
|
171
|
-
});
|
|
172
|
-
it('should return the difference in width between the current and specified breakpoint', function () {
|
|
173
|
-
(0, _assume.default)(bd.compare('mobile', 'width')).equals(1234 - 400);
|
|
174
|
-
(0, _assume.default)(bd.compare('mobile', 'height')).equals(1000 - 600);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
package/lib/test.native.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = _interopRequireDefault(require("./index.native"));
|
|
4
|
-
|
|
5
|
-
var _assume = _interopRequireDefault(require("assume"));
|
|
6
|
-
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
it('is exposed as a function', function () {
|
|
12
|
-
(0, _assume.default)(_index.default).is.a('function');
|
|
13
|
-
});
|
|
14
|
-
describe('nativeDancer', function () {
|
|
15
|
-
var nativeDancer;
|
|
16
|
-
var specification = [{
|
|
17
|
-
name: 'mobile',
|
|
18
|
-
width: 400,
|
|
19
|
-
height: 600
|
|
20
|
-
}, {
|
|
21
|
-
name: 'tablet',
|
|
22
|
-
width: 1024
|
|
23
|
-
}, {
|
|
24
|
-
name: 'whatever',
|
|
25
|
-
width: 1409
|
|
26
|
-
}];
|
|
27
|
-
beforeEach(function () {
|
|
28
|
-
nativeDancer = new _index.default(specification);
|
|
29
|
-
});
|
|
30
|
-
describe('constructor', function () {
|
|
31
|
-
it('stores the specification as arrays', function () {
|
|
32
|
-
(0, _assume.default)(nativeDancer.specification).is.a('array');
|
|
33
|
-
(0, _assume.default)(nativeDancer.specification[0].name).equals('mobile');
|
|
34
|
-
});
|
|
35
|
-
it('sets the current breakpoint', function () {
|
|
36
|
-
(0, _assume.default)(nativeDancer.breakpoint).is.a('string');
|
|
37
|
-
(0, _assume.default)(nativeDancer.breakpoint).is.either(['mobile', 'tablet', 'whatever']);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('#height', function () {
|
|
41
|
-
it('equals to device\'s height', function () {
|
|
42
|
-
var bd = new _index.default(specification);
|
|
43
|
-
(0, _assume.default)(bd.height()).equals(_reactNative.Dimensions.get('window').height);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe('#width', function () {
|
|
47
|
-
it('equals to device\'s width', function () {
|
|
48
|
-
var bd = new _index.default(specification);
|
|
49
|
-
(0, _assume.default)(bd.width()).equals(_reactNative.Dimensions.get('window').width);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('#changed', function () {
|
|
53
|
-
it('returns a boolean if the breakpoint has changed', function () {
|
|
54
|
-
(0, _assume.default)(nativeDancer.changed()).is.false();
|
|
55
|
-
(0, _assume.default)(nativeDancer.changed()).is.false();
|
|
56
|
-
(0, _assume.default)(nativeDancer.changed()).is.false();
|
|
57
|
-
var viewport = {
|
|
58
|
-
width: 200,
|
|
59
|
-
height: 500
|
|
60
|
-
};
|
|
61
|
-
(0, _assume.default)(nativeDancer.changed(viewport)).is.true();
|
|
62
|
-
});
|
|
63
|
-
it('updates the .breakpoint', function () {
|
|
64
|
-
var viewport = {
|
|
65
|
-
width: 200,
|
|
66
|
-
height: 500
|
|
67
|
-
};
|
|
68
|
-
(0, _assume.default)(nativeDancer.breakpoint).does.not.equal('mobile');
|
|
69
|
-
(0, _assume.default)(nativeDancer.changed(viewport)).is.true();
|
|
70
|
-
(0, _assume.default)(nativeDancer.breakpoint).equals('mobile');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('#currently', function () {
|
|
74
|
-
it('matches as tablet', function () {
|
|
75
|
-
var viewport = {
|
|
76
|
-
width: 800,
|
|
77
|
-
height: 600
|
|
78
|
-
};
|
|
79
|
-
(0, _assume.default)(nativeDancer.currently(viewport)).equals('tablet');
|
|
80
|
-
});
|
|
81
|
-
it('matches as mobile', function () {
|
|
82
|
-
var viewport = {
|
|
83
|
-
width: 200,
|
|
84
|
-
height: 500
|
|
85
|
-
};
|
|
86
|
-
(0, _assume.default)(nativeDancer.currently(viewport)).equals('mobile');
|
|
87
|
-
});
|
|
88
|
-
it('matches unknown', function () {
|
|
89
|
-
var viewport = {
|
|
90
|
-
width: 1800,
|
|
91
|
-
height: 1600
|
|
92
|
-
};
|
|
93
|
-
(0, _assume.default)(nativeDancer.currently(viewport)).equals('unknown');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
describe('#viewport', function () {
|
|
97
|
-
it('returns the width and height', function () {
|
|
98
|
-
var viewport = nativeDancer.viewport();
|
|
99
|
-
(0, _assume.default)(viewport.width).is.above(0);
|
|
100
|
-
(0, _assume.default)(viewport.width).equals(nativeDancer.width());
|
|
101
|
-
(0, _assume.default)(viewport.height).is.above(0);
|
|
102
|
-
(0, _assume.default)(viewport.height).equals(nativeDancer.height());
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|