Repository URL to install this package:
Version:
1.2.13 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @flow
/* eslint-disable import/no-unresolved */
const css_to_react_native_1 = __importDefault(require("css-to-react-native"));
const hash_1 = __importDefault(require("../vendor/glamor/hash"));
const flatten_1 = __importDefault(require("../utils/flatten"));
const parse_1 = __importDefault(require("../vendor/postcss-safe-parser/parse"));
let generated = {};
exports.resetStyleCache = () => {
generated = {};
};
/*
InlineStyle takes arbitrary CSS and generates a flat object
*/
const exporting = (styleSheet) => {
class InlineStyle {
constructor(rules) {
this.rules = rules;
}
generateStyleObject(executionContext) {
const flatCSS = flatten_1.default(this.rules, executionContext).join('');
const hash = hash_1.default(flatCSS);
if (!generated[hash]) {
const root = parse_1.default(flatCSS);
const declPairs = [];
root.each(node => {
if (node.type === 'decl') {
declPairs.push([node.prop, node.value]);
}
else if (node.type !== 'comment' &&
process.env.NODE_ENV !== 'production') {
/* eslint-disable no-console */
console.warn(`Node of type ${node.type} not supported as an inline style`);
}
});
// RN currently does not support differing values for the corner radii of Image
// components (but does for View). It is almost impossible to tell whether we'll have
// support, so we'll just disable multiple values here.
// https://github.com/styled-components/css-to-react-native/issues/11
const styleObject = css_to_react_native_1.default(declPairs, [
'borderRadius',
'borderWidth',
'borderColor',
'borderStyle',
]);
const styles = styleSheet.create({
generated: styleObject,
});
generated[hash] = styles.generated;
}
return generated[hash];
}
}
return InlineStyle;
};
exports.default = exporting;
//# sourceMappingURL=InlineStyle.js.map