@stylexjs/shared
Advanced tools
Comparing version
@@ -37,7 +37,6 @@ /** | ||
}>; | ||
export type StyleXOptions = { | ||
export type StyleXOptions = Readonly<{ | ||
dev: boolean; | ||
test: boolean; | ||
useRemForFontSize: boolean; | ||
runtimeInjection: boolean; | ||
classNamePrefix: string; | ||
@@ -49,4 +48,4 @@ definedStylexCSSVariables?: { [key: string]: unknown }; | ||
| 'legacy-expand-shorthands'; | ||
}; | ||
}>; | ||
export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles }; | ||
export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>; |
@@ -18,4 +18,4 @@ "use strict"; | ||
exports.types = _types; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -22,0 +22,0 @@ const create = exports.create = _stylexCreate.default; |
@@ -10,4 +10,6 @@ /** | ||
export declare const ILLEGAL_ARGUMENT_LENGTH: 'stylex() should have 1 argument.'; | ||
export declare const ILLEGAL_ARGUMENT_LENGTH: 'stylex.create() should have 1 argument.'; | ||
export declare const ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES: 'stylex.keyframes() should have 1 argument.'; | ||
export declare const NON_STATIC_VALUE: 'Only static values are allowed inside of a stylex.create() call.'; | ||
export declare const NON_STATIC_KEYFRAME_VALUE: 'Only static values are allowed inside of a stylex.keyframes() call.'; | ||
export declare const ESCAPED_STYLEX_VALUE: 'Escaping a stylex.create() value is not allowed.'; | ||
@@ -17,2 +19,3 @@ export declare const UNBOUND_STYLEX_CALL_VALUE: 'stylex.create calls must be bound to a bare variable.'; | ||
export declare const NON_OBJECT_FOR_STYLEX_CALL: 'stylex.create() can only accept a style object.'; | ||
export declare const NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL: 'stylex.keyframes() can only accept an object.'; | ||
export declare const UNKNOWN_PROP_KEY: 'Unknown property key'; | ||
@@ -28,2 +31,3 @@ export declare const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.'; | ||
export declare const ILLEGAL_NAMESPACE_VALUE: 'A stylex namespace must be an object.'; | ||
export declare const NON_OBJECT_KEYFRAME: 'Every frame within a stylex.keyframes() call must be an object.'; | ||
export declare const INVALID_SPREAD: 'Imported styles spread with a stylex.create call must be type cast as `XStyle` to verify their type.'; | ||
@@ -35,3 +39,3 @@ export declare const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function'; | ||
export declare const NO_PARENT_PATH: 'Unexpected AST node without a parent path.'; | ||
export declare const ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.'; | ||
export declare const ONLY_TOP_LEVEL_INCLUDES: 'stylex.include() is only at the top level of a style definition object.'; | ||
export declare const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.'; | ||
@@ -41,1 +45,2 @@ export declare const NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.'; | ||
export declare const ANONYMOUS_THEME: 'stylex.createTheme() must be bound to a named constant.'; | ||
export declare const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.'; |
@@ -6,5 +6,7 @@ 'use strict'; | ||
}); | ||
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL_INLCUDES = exports.ONLY_TOP_LEVEL = exports.NO_PROJECT_ROOT_DIRECTORY = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.NON_EXPORT_NAMED_DECLARATION = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = exports.ANONYMOUS_THEME = void 0; | ||
const ILLEGAL_ARGUMENT_LENGTH = exports.ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.'; | ||
exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL_INCLUDES = exports.ONLY_TOP_LEVEL = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.NO_PROJECT_ROOT_DIRECTORY = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_STATIC_KEYFRAME_VALUE = exports.NON_OBJECT_KEYFRAME = exports.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.NON_EXPORT_NAMED_DECLARATION = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = exports.ANONYMOUS_THEME = void 0; | ||
const ILLEGAL_ARGUMENT_LENGTH = exports.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.'; | ||
const ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = exports.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.'; | ||
const NON_STATIC_VALUE = exports.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.'; | ||
const NON_STATIC_KEYFRAME_VALUE = exports.NON_STATIC_KEYFRAME_VALUE = 'Only static values are allowed inside of a stylex.keyframes() call.'; | ||
const ESCAPED_STYLEX_VALUE = exports.ESCAPED_STYLEX_VALUE = 'Escaping a stylex.create() value is not allowed.'; | ||
@@ -14,2 +16,3 @@ const UNBOUND_STYLEX_CALL_VALUE = exports.UNBOUND_STYLEX_CALL_VALUE = 'stylex.create calls must be bound to a bare variable.'; | ||
const NON_OBJECT_FOR_STYLEX_CALL = exports.NON_OBJECT_FOR_STYLEX_CALL = 'stylex.create() can only accept a style object.'; | ||
const NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = exports.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = 'stylex.keyframes() can only accept an object.'; | ||
const UNKNOWN_PROP_KEY = exports.UNKNOWN_PROP_KEY = 'Unknown property key'; | ||
@@ -25,2 +28,3 @@ const INVALID_PSEUDO = exports.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.'; | ||
const ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_VALUE = 'A stylex namespace must be an object.'; | ||
const NON_OBJECT_KEYFRAME = exports.NON_OBJECT_KEYFRAME = 'Every frame within a stylex.keyframes() call must be an object.'; | ||
const INVALID_SPREAD = exports.INVALID_SPREAD = 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.'; | ||
@@ -32,6 +36,7 @@ const LINT_UNCLOSED_FUNCTION = exports.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function'; | ||
const NO_PARENT_PATH = exports.NO_PARENT_PATH = 'Unexpected AST node without a parent path.'; | ||
const ONLY_TOP_LEVEL_INLCUDES = exports.ONLY_TOP_LEVEL_INLCUDES = 'stylex.include() is only at the top level of a style definition object.'; | ||
const ONLY_TOP_LEVEL_INCLUDES = exports.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.'; | ||
const DUPLICATE_CONDITIONAL = exports.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.'; | ||
const NO_PROJECT_ROOT_DIRECTORY = exports.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.'; | ||
const NON_EXPORT_NAMED_DECLARATION = exports.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.'; | ||
const ANONYMOUS_THEME = exports.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.'; | ||
const ANONYMOUS_THEME = exports.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.'; | ||
const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.'; |
@@ -127,4 +127,4 @@ /** | ||
borderBottom: (rawValue: TStyleValue) => TReturn; | ||
borderInlineStart: (_rawValue: TStyleValue) => TReturn; | ||
borderLeft: (_rawValue: TStyleValue) => TReturn; | ||
borderInlineStart: (rawValue: TStyleValue) => TReturn; | ||
borderLeft: (rawValue: TStyleValue) => TReturn; | ||
borderInlineWidth: (rawValue: TStyleValue) => TReturn; | ||
@@ -131,0 +131,0 @@ borderInlineStyle: (rawValue: TStyleValue) => TReturn; |
@@ -7,4 +7,2 @@ "use strict"; | ||
exports.default = void 0; | ||
var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const shorthands = { | ||
@@ -25,4 +23,4 @@ all: _ => { | ||
borderBottom: rawValue => [['borderBottom', rawValue], ['borderBottomWidth', null], ['borderBottomStyle', null], ['borderBottomColor', null]], | ||
borderInlineStart: _rawValue => [['borderInlineStart', null], ...shorthands.borderInlineStartWidth(null), ...shorthands.borderInlineStartStyle(null), ...shorthands.borderInlineStartColor(null)], | ||
borderLeft: _rawValue => [['borderLeft', null], ...shorthands.borderLeftWidth(null), ...shorthands.borderLeftStyle(null), ...shorthands.borderLeftColor(null)], | ||
borderInlineStart: rawValue => [['borderInlineStart', rawValue], ...shorthands.borderInlineStartWidth(null), ...shorthands.borderInlineStartStyle(null), ...shorthands.borderInlineStartColor(null)], | ||
borderLeft: rawValue => [['borderLeft', rawValue], ...shorthands.borderLeftWidth(null), ...shorthands.borderLeftStyle(null), ...shorthands.borderLeftColor(null)], | ||
borderInlineWidth: rawValue => [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderLeftWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null]], | ||
@@ -94,8 +92,3 @@ borderInlineStyle: rawValue => [['borderInlineStyle', rawValue], ['borderInlineStartStyle', null], ['borderLeftStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null]], | ||
padding: rawValue => { | ||
const values = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue); | ||
if (values.length === 1) { | ||
return [['padding', values[0]], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null], ['paddingTop', null], ['paddingBottom', null]]; | ||
} | ||
const [top, right = top, bottom = top, left = right] = values; | ||
return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]]; | ||
return [['padding', rawValue], ...shorthands.paddingInline(null), ...shorthands.paddingBlock(null)]; | ||
}, | ||
@@ -102,0 +95,0 @@ paddingInline: rawValue => [['paddingInline', rawValue], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null]], |
@@ -10,4 +10,4 @@ "use strict"; | ||
var _objectUtils = require("../utils/object-utils"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function validateNamespace(namespace) { | ||
@@ -37,3 +37,3 @@ let conditions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
} | ||
throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES); | ||
throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES); | ||
} | ||
@@ -77,3 +77,3 @@ if ((0, _objectUtils.isPlainObject)(val)) { | ||
if (v instanceof _stylexInclude.IncludedStyles) { | ||
throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES); | ||
throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES); | ||
} | ||
@@ -80,0 +80,0 @@ if ((0, _objectUtils.isPlainObject)(v)) { |
@@ -49,15 +49,20 @@ "use strict"; | ||
const overrideClassName = classNamePrefix + (0, _hash.default)(cssVariablesOverrideString + atRulesStringForHash); | ||
const atRulesCss = sortedAtRules.map(atRule => { | ||
return `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`; | ||
}).join(''); | ||
const stylesToInject = { | ||
[overrideClassName]: { | ||
ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`, | ||
priority: 0.8, | ||
rtl: undefined | ||
} | ||
}; | ||
for (const atRule of sortedAtRules) { | ||
stylesToInject[overrideClassName + '-' + (0, _hash.default)(atRule)] = { | ||
ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`, | ||
priority: 0.9, | ||
rtl: null | ||
}; | ||
} | ||
return [{ | ||
$$css: true, | ||
[themeVars.__themeName__]: overrideClassName | ||
}, { | ||
[overrideClassName]: { | ||
ltr: `.${overrideClassName}{${cssVariablesOverrideString}}${atRulesCss}`, | ||
priority: 0.99, | ||
rtl: undefined | ||
} | ||
}]; | ||
}, stylesToInject]; | ||
} |
@@ -10,21 +10,14 @@ /** | ||
import type { StyleXOptions } from './common-types'; | ||
type VarsObject< | ||
Vars extends { | ||
readonly [$$Key$$: string]: | ||
| string | ||
| { readonly default: string; readonly [$$Key$$: string]: string }; | ||
}, | ||
> = Readonly</** | ||
* > 15 | ...$ObjMapConst<Vars, string>, | ||
import type { InjectableStyle, StyleXOptions } from './common-types'; | ||
type VarsConfig = Readonly<{ | ||
[$$Key$$: string]: | ||
| string | ||
| Readonly<{ default: string; [$$Key$$: string]: string }>; | ||
}>; | ||
type VarsObject<Vars extends VarsConfig> = Readonly</** | ||
* > 17 | ...$ObjMapConst<Vars, string>, | ||
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with complex spreads" is currently not supported. | ||
**/ | ||
any>; | ||
declare function styleXDefineVars< | ||
Vars extends { | ||
readonly [$$Key$$: string]: | ||
| string | ||
| { readonly default: string; readonly [$$Key$$: string]: string }; | ||
}, | ||
>( | ||
declare function styleXDefineVars<Vars extends VarsConfig>( | ||
variables: Vars, | ||
@@ -36,3 +29,3 @@ options: Readonly< | ||
>, | ||
): [VarsObject<Vars>, { css: string }]; | ||
): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }]; | ||
export default styleXDefineVars; |
@@ -33,17 +33,14 @@ "use strict"; | ||
}); | ||
const cssVariablesString = constructCssVariablesString(variablesMap); | ||
const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash); | ||
return [{ | ||
...themeVariablesObject, | ||
__themeName__: themeNameHash | ||
}, { | ||
css: cssVariablesString | ||
}]; | ||
}, injectableStyles]; | ||
} | ||
function constructCssVariablesString(variables) { | ||
const atRules = {}; | ||
const varsString = (0, _objectUtils.objEntries)(variables).map(_ref2 => { | ||
let [key, { | ||
nameHash, | ||
value | ||
}] = _ref2; | ||
function constructCssVariablesString(variables, themeNameHash) { | ||
const ruleByAtRule = {}; | ||
for (const [key, { | ||
nameHash, | ||
value | ||
}] of (0, _objectUtils.objEntries)(variables)) { | ||
if (value !== null && typeof value === 'object') { | ||
@@ -53,22 +50,26 @@ if (value.default === undefined) { | ||
} | ||
const definedVarString = `--${nameHash}:${value.default};`; | ||
Object.keys(value).forEach(key => { | ||
if (key.startsWith('@')) { | ||
const definedVarStringForAtRule = `--${nameHash}:${value[key]};`; | ||
if (atRules[key] == null) { | ||
atRules[key] = [definedVarStringForAtRule]; | ||
} else { | ||
atRules[key].push(definedVarStringForAtRule); | ||
} | ||
} | ||
}); | ||
return definedVarString; | ||
const v = value; | ||
for (const [key, value] of (0, _objectUtils.objEntries)(v)) { | ||
ruleByAtRule[key] ??= []; | ||
ruleByAtRule[key].push(`--${nameHash}:${value};`); | ||
} | ||
} else { | ||
ruleByAtRule.default ??= []; | ||
ruleByAtRule.default.push(`--${nameHash}:${value};`); | ||
} | ||
return `--${nameHash}:${value};`; | ||
}).join(''); | ||
const atRulesString = (0, _objectUtils.objEntries)(atRules).map(_ref3 => { | ||
let [atRule, varsArr] = _ref3; | ||
return `${atRule}{:root{${varsArr.join('')}}}`; | ||
}).join(''); | ||
return `:root{${varsString}}${atRulesString || ''}`; | ||
} | ||
const result = {}; | ||
for (const [key, value] of (0, _objectUtils.objEntries)(ruleByAtRule)) { | ||
const suffix = key === 'default' ? '' : `-${(0, _hash.default)(key)}`; | ||
let ltr = `:root{${value.join('')}}`; | ||
if (key !== 'default') { | ||
ltr = `${key}{${ltr}}`; | ||
} | ||
result[themeNameHash + suffix] = { | ||
ltr, | ||
rtl: null, | ||
priority: key === 'default' ? 0 : 0.1 | ||
}; | ||
} | ||
return result; | ||
} |
@@ -9,4 +9,4 @@ "use strict"; | ||
var messages = _interopRequireWildcard(require("./messages")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
let number = 0; | ||
@@ -13,0 +13,0 @@ function uuid() { |
@@ -9,3 +9,2 @@ "use strict"; | ||
dev: false, | ||
runtimeInjection: false, | ||
useRemForFontSize: true, | ||
@@ -12,0 +11,0 @@ test: false, |
@@ -8,4 +8,4 @@ 'use strict'; | ||
var messages = _interopRequireWildcard(require("../../messages")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function detectUnclosedFns(ast, _) { | ||
@@ -12,0 +12,0 @@ ast.walk(node => { |
@@ -12,3 +12,3 @@ /** | ||
* Use single spaces and remove spaces when not needed: around functions, | ||
* commas. But preserve spece around + and - as they are required in calc() | ||
* commas. But preserve space around + and - as they are required in calc() | ||
*/ | ||
@@ -15,0 +15,0 @@ |
{ | ||
"name": "@stylexjs/shared", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "lib/index.js", | ||
@@ -16,3 +16,3 @@ "repository": "https://www.github.com/facebook/stylex", | ||
"devDependencies": { | ||
"@stylexjs/scripts": "0.3.0" | ||
"@stylexjs/scripts": "0.4.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "jest": { |
@@ -7,4 +7,4 @@ # @stylexjs/shared | ||
1. `create` - takes a map of style rules. The return value include: a) the map with each style value replaced by a unique, reproducible, hashed className string, and b) a list of the CSS styles to be inserted into the document. | ||
2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style ot be injected. | ||
1. `create` - takes a map of style rules. The return value includes: a) the map with each style value replaced by a unique, reproducible, hashed `className` string, and b) a list of the CSS styles to be inserted into the document. | ||
2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style to be injected. | ||
@@ -33,3 +33,3 @@ #### ⭐️ `create` | ||
We hash each style `[key, value]` pair and generate a className and an associated CSS rule. Thie is done in the `convertToClassName(...)` function defined within [`convert-to-className.js`](#convert-to-classname-shared-package). (Explained below) | ||
We hash each style `[key, value]` pair and generate a className and an associated CSS rule. This is done in the `convertToClassName(...)` function defined within [`convert-to-className.js`](#convert-to-classname-shared-package). (Explained below) | ||
@@ -36,0 +36,0 @@ **Step 3** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
852373
0.05%25894
-0.03%