UNPKG

@ray-core/runtime

Version:

Ray 是一个全新的基于 React 的小程序开发框架

52 lines (51 loc) 2.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.propAlias = exports.getAlias = void 0; var plainStyle_1 = __importDefault(require("./utils/plainStyle")); var framework_shared_1 = require("@ray-core/framework-shared"); function getAlias(prop, type) { var _a, _b; var hostComponent = framework_shared_1.RuntimeOptions.get('hostComponents')[type]; var prefix = "".concat(framework_shared_1.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; } exports.getAlias = getAlias; function getValue(prop, value) { if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') { return (0, plainStyle_1.default)(value); } return value; } function propAlias(prop, value, type) { return [getAlias(prop, type), getValue(prop, value)]; } exports.propAlias = propAlias; function propsAlias(props, type) { if (!props) { return props; } var prefix = "".concat(framework_shared_1.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; } exports.default = propsAlias;