Removed GopherJS, basic frontend completed, need backend changes for

torrent storage
This commit is contained in:
2017-11-30 18:12:11 -05:00
parent 67fdef16b1
commit e98ad2cc88
69321 changed files with 5498914 additions and 337 deletions

View File

@@ -0,0 +1,178 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = jssExpand;
var _props = require('./props');
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Map values by given prop.
*
* @param {Array} array of values
* @param {String} original property
* @param {String} original rule
* @return {String} mapped values
*/
function mapValuesByProp(value, prop, rule) {
return value.map(function (item) {
return objectToString(item, prop, rule);
});
}
/**
* Convert array to string.
*
* @param {Array} array of values
* @param {String} original property
* @param {Object} sheme, for converting arrays in strings
* @param {Object} original rule
* @return {String} converted string
*/
function arrayToString(value, prop, scheme, rule) {
if (scheme[prop] == null) return value.join(',');
if (value.length === 0) return '';
if (Array.isArray(value[0])) return arrayToString(value[0], prop, scheme);
if (_typeof(value[0]) === 'object') return mapValuesByProp(value, prop, rule);
return value.join(' ');
}
/**
* Convert object to string.
*
* @param {Object} object of values
* @param {String} original property
* @param {Object} original rule
* @param {Boolean} is fallback prop
* @return {String} converted string
*/
function objectToString(value, prop, rule, isFallback) {
if (!(_props.propObj[prop] || _props.customPropObj[prop])) return '';
var result = [];
// Check if exists any non-standart property
if (_props.customPropObj[prop]) {
value = customPropsToStyle(value, rule, _props.customPropObj[prop], isFallback);
}
// Pass throught all standart props
if (Object.keys(value).length) {
for (var baseProp in _props.propObj[prop]) {
if (value[baseProp]) {
if (Array.isArray(value[baseProp])) {
result.push(arrayToString(value[baseProp], baseProp, _props.propArrayInObj));
} else result.push(value[baseProp]);
continue;
}
// Add default value from props config.
if (_props.propObj[prop][baseProp] != null) {
result.push(_props.propObj[prop][baseProp]);
}
}
}
return result.join(' ');
}
/**
* Convert custom properties values to styles adding them to rule directly
*
* @param {Object} object of values
* @param {Object} original rule
* @param {String} property, that contain partial custom properties
* @param {Boolean} is fallback prop
* @return {Object} value without custom properties, that was already added to rule
*/
function customPropsToStyle(value, rule, customProps, isFallback) {
for (var prop in customProps) {
var propName = customProps[prop];
// If current property doesn't exist already in rule - add new one
if (typeof value[prop] !== 'undefined' && (isFallback || !rule.prop(propName))) {
var appendedValue = styleDetector(_defineProperty({}, propName, value[prop]), rule)[propName];
// Add style directly in rule
if (isFallback) rule.style.fallbacks[propName] = appendedValue;else rule.style[propName] = appendedValue;
}
// Delete converted property to avoid double converting
delete value[prop];
}
return value;
}
/**
* Detect if a style needs to be converted.
*
* @param {Object} style
* @param {Object} rule
* @param {Boolean} is fallback prop
* @return {Object} convertedStyle
*/
function styleDetector(style, rule, isFallback) {
for (var prop in style) {
var value = style[prop];
if (Array.isArray(value)) {
// Check double arrays to avoid recursion.
if (!Array.isArray(value[0])) {
if (prop === 'fallbacks') {
for (var index = 0; index < style.fallbacks.length; index++) {
style.fallbacks[index] = styleDetector(style.fallbacks[index], rule, true);
}
continue;
}
style[prop] = arrayToString(value, prop, _props.propArray);
// Avoid creating properties with empty values
if (!style[prop]) delete style[prop];
}
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
if (prop === 'fallbacks') {
style.fallbacks = styleDetector(style.fallbacks, rule, true);
continue;
}
style[prop] = objectToString(value, prop, rule, isFallback);
// Avoid creating properties with empty values
if (!style[prop]) delete style[prop];
}
// Maybe a computed value resulting in an empty string
else if (style[prop] === '') delete style[prop];
}
return style;
}
/**
* Adds possibility to write expanded styles.
*
* @param {Rule} rule
* @api public
*/
function jssExpand() {
function onProcessStyle(style, rule) {
if (!style || rule.type !== 'style') return style;
if (Array.isArray(style)) {
// Pass rules one by one and reformat them
for (var index = 0; index < style.length; index++) {
style[index] = styleDetector(style[index], rule);
}
return style;
}
return styleDetector(style, rule);
}
return { onProcessStyle: onProcessStyle };
}

View File

@@ -0,0 +1,306 @@
'use strict';
var _expect = require('expect.js');
var _expect2 = _interopRequireDefault(_expect);
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
var _jss = require('jss');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var settings = {
createGenerateClassName: function createGenerateClassName() {
return function (rule) {
return rule.key + '-id';
};
}
};
describe('jss-expand', function () {
var jss = void 0;
beforeEach(function () {
jss = (0, _jss.create)(settings).use((0, _index2.default)());
});
describe('space-separated values as arrays', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
padding: [20, 10],
'background-size': [10, 'auto'],
'border-radius': [10, 15, 20, 20]
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' padding: 20 10;\n' + ' background-size: 10 auto;\n' + ' border-radius: 10 15 20 20;\n' + '}');
});
});
describe('comma-separated values as arrays (using double arrays)', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
transition: [['opacity', 1, 'linear'], ['transform', 300, 'ease']]
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' transition: opacity 1 linear, transform 300 ease;\n' + '}');
});
});
describe('simple expanded rules', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
border: {
width: 1,
style: 'solid',
color: '#f00'
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' border: 1 solid #f00;\n' + '}');
});
});
describe('expanded rules as an object (without some styles)', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
background: {
color: '#000',
image: 'url(test.jpg)',
position: [0, 0],
repeat: 'no-repeat'
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' background: #000 0 0 no-repeat;\n' + ' background-image: url(test.jpg);\n' + '}');
});
});
describe('expand with fallbacks', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
background: {
color: 'rgba(255, 255, 255, 0.8)'
},
padding: 50,
fallbacks: {
background: {
color: 'white'
},
padding: 20
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' background: white;\n' + ' padding: 20;\n' + ' background: rgba(255, 255, 255, 0.8);\n' + ' padding: 50;\n' + '}');
});
});
describe('expand with multiple fallbacks for the same prop', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
background: 'linear-gradient(red 0%, green 100%)',
fallbacks: [{
background: 'red'
}, {
background: {
color: 'url(test.png)',
repeat: 'no-repeat',
position: [0, 0]
}
}]
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' background: red;\n' + ' background: url(test.png) 0 0 no-repeat;\n' + ' background: linear-gradient(red 0%, green 100%);\n' + '}');
});
});
describe('expand with fallbacks and custom properties', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
background: {
image: 'linear-gradient(red 0%, green 100%)',
size: [10, 20]
},
fallbacks: {
background: {
image: 'url(gradient.png)',
size: 'auto'
}
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' background-size: auto;\n' + ' background-image: url(gradient.png);\n' + ' background-size: 10 20;\n' + ' background-image: linear-gradient(red 0%, green 100%);\n' + '}');
});
});
describe('integration with jss-camel-case', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
transition: {
timingFunction: 'linear',
delay: '300ms',
property: 'opacity',
duration: '200ms'
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' transition: opacity 200ms linear 300ms;\n' + '}');
});
});
describe('non-standart properties support', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
border: {
width: '2px',
style: 'solid',
color: 'black',
radius: ['5px', '10px']
}
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' border: 2px solid black;\n' + ' border-radius: 5px 10px;\n' + '}');
});
});
describe('non-standart properties should not overwrite standart properties notation', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
border: {
radius: ['5px', '10px']
},
'border-radius': '10px'
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' border-radius: 10px;\n' + '}');
});
});
describe('gracefully handle invalid values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
padding: [], // Empty: incorrect, to ignore
color: '',
margin: 0,
'border-radius': '10px' // Still one correct value
},
p: {
margin: [] // Will lead to empty rule, eliminated
}
});
});
it('should add rules', function () {
(0, _expect2.default)(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2.default)(sheet.toString()).to.be('.a-id {\n' + ' margin: 0;\n' + ' border-radius: 10px;\n' + '}');
});
});
});

View File

@@ -0,0 +1,168 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* A scheme for converting properties from array to regular style.
* All properties listed below will be transformed to a string separated by space.
*/
var propArray = exports.propArray = {
'background-size': true,
'background-position': true,
border: true,
'border-bottom': true,
'border-left': true,
'border-top': true,
'border-right': true,
'border-radius': true,
'box-shadow': true,
flex: true,
margin: true,
padding: true,
outline: true,
'transform-origin': true,
transform: true,
transition: true
};
/**
* A scheme for converting arrays to regular styles inside of objects.
* For e.g.: "{position: [0, 0]}" => "background-position: 0 0;".
*/
var propArrayInObj = exports.propArrayInObj = {
position: true, // background-position
size: true // background-size
};
/**
* A scheme for parsing and building correct styles from passed objects.
*/
var propObj = exports.propObj = {
padding: {
top: 0,
right: 0,
bottom: 0,
left: 0
},
margin: {
top: 0,
right: 0,
bottom: 0,
left: 0
},
background: {
attachment: null,
color: null,
image: null,
position: null,
repeat: null
},
border: {
width: null,
style: null,
color: null
},
'border-top': {
width: null,
style: null,
color: null
},
'border-right': {
width: null,
style: null,
color: null
},
'border-bottom': {
width: null,
style: null,
color: null
},
'border-left': {
width: null,
style: null,
color: null
},
outline: {
width: null,
style: null,
color: null
},
'list-style': {
type: null,
position: null,
image: null
},
transition: {
property: null,
duration: null,
'timing-function': null,
timingFunction: null, // Needed for avoiding comilation issues with jss-camel-case
delay: null
},
animation: {
name: null,
duration: null,
'timing-function': null,
timingFunction: null, // Needed to avoid compilation issues with jss-camel-case
delay: null,
'iteration-count': null,
iterationCount: null, // Needed to avoid compilation issues with jss-camel-case
direction: null,
'fill-mode': null,
fillMode: null, // Needed to avoid compilation issues with jss-camel-case
'play-state': null,
playState: null // Needed to avoid compilation issues with jss-camel-case
},
'box-shadow': {
x: 0,
y: 0,
blur: 0,
spread: 0,
color: null,
inset: null
},
'text-shadow': {
x: 0,
y: 0,
blur: null,
color: null
}
};
/**
* A scheme for converting non-standart properties inside object.
* For e.g.: include 'border-radius' property inside 'border' object.
*/
var customPropObj = exports.customPropObj = {
border: {
radius: 'border-radius'
},
background: {
size: 'background-size',
image: 'background-image'
},
font: {
style: 'font-style',
variant: 'font-variant',
weight: 'font-weight',
stretch: 'font-stretch',
size: 'font-size',
family: 'font-family',
lineHeight: 'line-height', // Needed to avoid compilation issues with jss-camel-case
'line-height': 'line-height'
},
flex: {
grow: 'flex-grow',
basis: 'flex-basis',
direction: 'flex-direction',
wrap: 'flex-wrap',
flow: 'flex-flow',
shrink: 'flex-shrink'
},
align: {
self: 'align-self',
items: 'align-items',
content: 'align-content'
}
};