You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.7 KiB

3 years ago
/* eslint-disable */
3 years ago
///////////////////////////////////dist\wxs\array.wxs/////////////////////////////////
3 years ago
3 years ago
/* eslint-disable */
///////////////////////////////////dist\wxs\bem.wxs/////////////////////////////////
function isArray(array) {
return array && array.constructor === 'Array';
}
/* eslint-disable */
///////////////////////////////////dist\wxs\object.wxs/////////////////////////////////
var REGEXP = getRegExp('{|}|"', 'g');
function keys(obj) {
return JSON.stringify(obj).replace(REGEXP, '').split(',').map(function (item) {
return item.split(':')[0];
});
}
var PREFIX = 'van-';
function join(name, mods) {
name = PREFIX + name;
mods = mods.map(function (mod) {
return name + '--' + mod;
});
mods.unshift(name);
return mods.join(' ');
}
function traversing(mods, conf) {
if (!conf) {
return;
}
if (typeof conf === 'string' || typeof conf === 'number') {
mods.push(conf);
} else if (isArray(conf)) {
conf.forEach(function (item) {
traversing(mods, item);
});
} else if (typeof conf === 'object') {
keys(conf).forEach(function (key) {
conf[key] && mods.push(key);
});
}
}
function bem(name, conf) {
var mods = [];
traversing(mods, conf);
return join(name, mods);
}
module.exports = bem;
/**
* Simple memoize
* wxs doesn't support fn.apply, so this memoize only support up to 2 args
*/
/* eslint-disable */
///////////////////////////////////dist\wxs\memoize.wxs/////////////////////////////////
function isPrimitive(value) {
var type = typeof value;
return type === 'boolean' || type === 'number' || type === 'string' || type === 'undefined' || value === null;
} // mock simple fn.call in wxs
function call(fn, args) {
if (args.length === 2) {
return fn(args[0], args[1]);
}
if (args.length === 1) {
return fn(args[0]);
}
return fn();
}
function serializer(args) {
if (args.length === 1 && isPrimitive(args[0])) {
return args[0];
}
var obj = {};
for (var i = 0; i < args.length; i++) {
obj['key' + i] = args[i];
}
return JSON.stringify(obj);
}
function memoize(fn) {
var cache = {};
return function () {
var key = serializer(arguments);
if (cache[key] === undefined) {
cache[key] = call(fn, arguments);
}
return cache[key];
};
}
module.exports = memoize;
/* eslint-disable */
///////////////////////////////////dist\wxs\add-unit.wxs/////////////////////////////////
var REGEXP = getRegExp('^-?\d+(\.\d+)?$');
function addUnit(value) {
if (value == null) {
return undefined;
}
return REGEXP.test('' + value) ? value + 'px' : value;
}
module.exports = addUnit;
3 years ago
module.exports = {
bem: memoize(bem),
memoize: memoize,
addUnit: addUnit
3 years ago
};