@ray-core/runtime
Version:
Ray 是一个全新的基于 React 的小程序开发框架
43 lines (42 loc) • 1.59 kB
JavaScript
import plainStyle from './utils/plainStyle';
import { RuntimeOptions } from '@ray-core/framework-shared';
export function getAlias(prop, type) {
var _a, _b;
var hostComponent = RuntimeOptions.get('hostComponents')[type];
var prefix = "".concat(RuntimeOptions.get('platform'), "-");
// 判断是否是平台独有属性
if (prop.startsWith(prefix)) {
return prop.replace(new RegExp("^".concat(prefix)), '');
}
return (_b = (_a = hostComponent === null || hostComponent === void 0 ? void 0 : hostComponent.alias) === null || _a === void 0 ? void 0 : _a[prop]) !== null && _b !== void 0 ? _b : prop;
}
function getValue(prop, value) {
if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') {
return plainStyle(value);
}
return value;
}
export function propAlias(prop, value, type) {
return [getAlias(prop, type), getValue(prop, value)];
}
export default function propsAlias(props, type) {
if (!props) {
return props;
}
var prefix = "".concat(RuntimeOptions.get('platform'), "-");
var aliasProps = {};
for (var prop in props) {
// 平台前缀属性优先级提升
// @see https://github.com/remaxjs/remax/issues/1409
var hasPrefix = prop.startsWith(prefix);
var key = getAlias(prop, type);
var value = getValue(prop, props[prop]);
if (hasPrefix) {
aliasProps[key] = value;
}
else {
aliasProps[key] = aliasProps[key] || value;
}
}
return aliasProps;
}