@emotion/serialize
Advanced tools
Comparing version 1.1.4 to 1.2.0
@@ -1,2 +0,35 @@ | ||
export * from '../types' | ||
export { default } from '../types' | ||
import type { RegisteredCache, SerializedStyles } from '@emotion/utils'; | ||
import * as CSS from 'csstype'; | ||
export type { RegisteredCache, SerializedStyles }; | ||
export type CSSProperties = CSS.PropertiesFallback<number | string>; | ||
export type CSSPropertiesWithMultiValues = { | ||
[K in keyof CSSProperties]: CSSProperties[K] | ReadonlyArray<Extract<CSSProperties[K], string>>; | ||
}; | ||
export type CSSPseudos = { | ||
[K in CSS.Pseudos]?: CSSObject; | ||
}; | ||
export interface ArrayCSSInterpolation extends ReadonlyArray<CSSInterpolation> { | ||
} | ||
export type InterpolationPrimitive = null | undefined | boolean | number | string | ComponentSelector | Keyframes | SerializedStyles | CSSObject; | ||
export type CSSInterpolation = InterpolationPrimitive | ArrayCSSInterpolation; | ||
export interface CSSOthersObject { | ||
[propertiesName: string]: CSSInterpolation; | ||
} | ||
export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject { | ||
} | ||
export interface ComponentSelector { | ||
__emotion_styles: any; | ||
} | ||
export type Keyframes = { | ||
name: string; | ||
styles: string; | ||
anim: number; | ||
toString: () => string; | ||
} & string; | ||
export interface ArrayInterpolation<Props = unknown> extends ReadonlyArray<Interpolation<Props>> { | ||
} | ||
export interface FunctionInterpolation<Props = unknown> { | ||
(props: Props): Interpolation<Props>; | ||
} | ||
export type Interpolation<Props = unknown> = InterpolationPrimitive | ArrayInterpolation<Props> | FunctionInterpolation<Props>; | ||
export declare function serializeStyles<Props>(args: Array<TemplateStringsArray | Interpolation<Props>>, registered?: RegisteredCache, mergedProps?: Props): SerializedStyles; |
@@ -82,8 +82,10 @@ import hashString from '@emotion/hash'; | ||
if (interpolation.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && interpolation.toString() === 'NO_COMPONENT_SELECTOR') { | ||
var componentSelector = interpolation; | ||
if (componentSelector.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && String(componentSelector) === 'NO_COMPONENT_SELECTOR') { | ||
throw new Error(noComponentSelectorMessage); | ||
} | ||
return interpolation; | ||
return componentSelector; | ||
} | ||
@@ -99,14 +101,18 @@ | ||
{ | ||
if (interpolation.anim === 1) { | ||
var keyframes = interpolation; | ||
if (keyframes.anim === 1) { | ||
cursor = { | ||
name: interpolation.name, | ||
styles: interpolation.styles, | ||
name: keyframes.name, | ||
styles: keyframes.styles, | ||
next: cursor | ||
}; | ||
return interpolation.name; | ||
return keyframes.name; | ||
} | ||
if (interpolation.styles !== undefined) { | ||
var next = interpolation.next; | ||
var serializedStyles = interpolation; | ||
if (serializedStyles.styles !== undefined) { | ||
var next = serializedStyles.next; | ||
if (next !== undefined) { | ||
@@ -125,6 +131,6 @@ // not the most efficient thing ever but this is a pretty rare case | ||
var styles = interpolation.styles + ";"; | ||
var styles = serializedStyles.styles + ";"; | ||
if (process.env.NODE_ENV !== 'production' && interpolation.map !== undefined) { | ||
styles += interpolation.map; | ||
if (process.env.NODE_ENV !== 'production' && serializedStyles.map !== undefined) { | ||
styles += serializedStyles.map; | ||
} | ||
@@ -155,3 +161,3 @@ | ||
var matched = []; | ||
var replaced = interpolation.replace(animationRegex, function (match, p1, p2) { | ||
var replaced = interpolation.replace(animationRegex, function (_match, _p1, p2) { | ||
var fakeVarName = "animation" + matched.length; | ||
@@ -163,3 +169,3 @@ matched.push("const " + fakeVarName + " = keyframes`" + p2.replace(/^@keyframes animation-\w+/, '') + "`"); | ||
if (matched.length) { | ||
console.error('`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\n' + 'Instead of doing this:\n\n' + [].concat(matched, ["`" + replaced + "`"]).join('\n') + '\n\nYou should wrap it with `css` like this:\n\n' + ("css`" + replaced + "`")); | ||
console.error("`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\nInstead of doing this:\n\n" + [].concat(matched, ["`" + replaced + "`"]).join('\n') + "\n\nYou should wrap it with `css` like this:\n\ncss`" + replaced + "`"); | ||
} | ||
@@ -172,8 +178,10 @@ } | ||
var asString = interpolation; | ||
if (registered == null) { | ||
return interpolation; | ||
return asString; | ||
} | ||
var cached = registered[interpolation]; | ||
return cached !== undefined ? cached : interpolation; | ||
var cached = registered[asString]; | ||
return cached !== undefined ? cached : asString; | ||
} | ||
@@ -189,13 +197,15 @@ | ||
} else { | ||
for (var _key in obj) { | ||
var value = obj[_key]; | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (typeof value !== 'object') { | ||
if (registered != null && registered[value] !== undefined) { | ||
string += _key + "{" + registered[value] + "}"; | ||
} else if (isProcessableValue(value)) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";"; | ||
var asString = value; | ||
if (registered != null && registered[asString] !== undefined) { | ||
string += key + "{" + registered[asString] + "}"; | ||
} else if (isProcessableValue(asString)) { | ||
string += processStyleName(key) + ":" + processStyleValue(key, asString) + ";"; | ||
} | ||
} else { | ||
if (_key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
if (key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
throw new Error(noComponentSelectorMessage); | ||
@@ -207,3 +217,3 @@ } | ||
if (isProcessableValue(value[_i])) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";"; | ||
string += processStyleName(key) + ":" + processStyleValue(key, value[_i]) + ";"; | ||
} | ||
@@ -214,7 +224,7 @@ } | ||
switch (_key) { | ||
switch (key) { | ||
case 'animation': | ||
case 'animationName': | ||
{ | ||
string += processStyleName(_key) + ":" + interpolated + ";"; | ||
string += processStyleName(key) + ":" + interpolated + ";"; | ||
break; | ||
@@ -225,7 +235,7 @@ } | ||
{ | ||
if (process.env.NODE_ENV !== 'production' && _key === 'undefined') { | ||
if (process.env.NODE_ENV !== 'production' && key === 'undefined') { | ||
console.error(UNDEFINED_AS_OBJECT_KEY_ERROR); | ||
} | ||
string += _key + "{" + interpolated + "}"; | ||
string += key + "{" + interpolated + "}"; | ||
} | ||
@@ -251,3 +261,3 @@ } | ||
var cursor; | ||
var serializeStyles = function serializeStyles(args, registered, mergedProps) { | ||
function serializeStyles(args, registered, mergedProps) { | ||
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) { | ||
@@ -266,7 +276,9 @@ return args[0]; | ||
} else { | ||
if (process.env.NODE_ENV !== 'production' && strings[0] === undefined) { | ||
var asTemplateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && asTemplateStringsArr[0] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[0]; | ||
styles += asTemplateStringsArr[0]; | ||
} // we start at 1 since we've already handled the first arg | ||
@@ -279,7 +291,9 @@ | ||
if (stringMode) { | ||
if (process.env.NODE_ENV !== 'production' && strings[i] === undefined) { | ||
var templateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && templateStringsArr[i] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[i]; | ||
styles += templateStringsArr[i]; | ||
} | ||
@@ -303,4 +317,3 @@ } | ||
while ((match = labelPattern.exec(styles)) !== null) { | ||
identifierName += '-' + // $FlowFixMe we know it's not null | ||
match[1]; | ||
identifierName += '-' + match[1]; | ||
} | ||
@@ -311,4 +324,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
// $FlowFixMe SerializedStyles type doesn't have toString property (and we don't want to add it) | ||
return { | ||
var devStyles = { | ||
name: name, | ||
@@ -322,2 +334,3 @@ styles: styles, | ||
}; | ||
return devStyles; | ||
} | ||
@@ -330,4 +343,4 @@ | ||
}; | ||
}; | ||
} | ||
export { serializeStyles }; |
@@ -92,8 +92,10 @@ 'use strict'; | ||
if (interpolation.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && interpolation.toString() === 'NO_COMPONENT_SELECTOR') { | ||
var componentSelector = interpolation; | ||
if (componentSelector.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && String(componentSelector) === 'NO_COMPONENT_SELECTOR') { | ||
throw new Error(noComponentSelectorMessage); | ||
} | ||
return interpolation; | ||
return componentSelector; | ||
} | ||
@@ -109,14 +111,18 @@ | ||
{ | ||
if (interpolation.anim === 1) { | ||
var keyframes = interpolation; | ||
if (keyframes.anim === 1) { | ||
cursor = { | ||
name: interpolation.name, | ||
styles: interpolation.styles, | ||
name: keyframes.name, | ||
styles: keyframes.styles, | ||
next: cursor | ||
}; | ||
return interpolation.name; | ||
return keyframes.name; | ||
} | ||
if (interpolation.styles !== undefined) { | ||
var next = interpolation.next; | ||
var serializedStyles = interpolation; | ||
if (serializedStyles.styles !== undefined) { | ||
var next = serializedStyles.next; | ||
if (next !== undefined) { | ||
@@ -135,6 +141,6 @@ // not the most efficient thing ever but this is a pretty rare case | ||
var styles = interpolation.styles + ";"; | ||
var styles = serializedStyles.styles + ";"; | ||
if (process.env.NODE_ENV !== 'production' && interpolation.map !== undefined) { | ||
styles += interpolation.map; | ||
if (process.env.NODE_ENV !== 'production' && serializedStyles.map !== undefined) { | ||
styles += serializedStyles.map; | ||
} | ||
@@ -165,3 +171,3 @@ | ||
var matched = []; | ||
var replaced = interpolation.replace(animationRegex, function (match, p1, p2) { | ||
var replaced = interpolation.replace(animationRegex, function (_match, _p1, p2) { | ||
var fakeVarName = "animation" + matched.length; | ||
@@ -173,3 +179,3 @@ matched.push("const " + fakeVarName + " = keyframes`" + p2.replace(/^@keyframes animation-\w+/, '') + "`"); | ||
if (matched.length) { | ||
console.error('`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\n' + 'Instead of doing this:\n\n' + [].concat(matched, ["`" + replaced + "`"]).join('\n') + '\n\nYou should wrap it with `css` like this:\n\n' + ("css`" + replaced + "`")); | ||
console.error("`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\nInstead of doing this:\n\n" + [].concat(matched, ["`" + replaced + "`"]).join('\n') + "\n\nYou should wrap it with `css` like this:\n\ncss`" + replaced + "`"); | ||
} | ||
@@ -182,8 +188,10 @@ } | ||
var asString = interpolation; | ||
if (registered == null) { | ||
return interpolation; | ||
return asString; | ||
} | ||
var cached = registered[interpolation]; | ||
return cached !== undefined ? cached : interpolation; | ||
var cached = registered[asString]; | ||
return cached !== undefined ? cached : asString; | ||
} | ||
@@ -199,13 +207,15 @@ | ||
} else { | ||
for (var _key in obj) { | ||
var value = obj[_key]; | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (typeof value !== 'object') { | ||
if (registered != null && registered[value] !== undefined) { | ||
string += _key + "{" + registered[value] + "}"; | ||
} else if (isProcessableValue(value)) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";"; | ||
var asString = value; | ||
if (registered != null && registered[asString] !== undefined) { | ||
string += key + "{" + registered[asString] + "}"; | ||
} else if (isProcessableValue(asString)) { | ||
string += processStyleName(key) + ":" + processStyleValue(key, asString) + ";"; | ||
} | ||
} else { | ||
if (_key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
if (key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
throw new Error(noComponentSelectorMessage); | ||
@@ -217,3 +227,3 @@ } | ||
if (isProcessableValue(value[_i])) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";"; | ||
string += processStyleName(key) + ":" + processStyleValue(key, value[_i]) + ";"; | ||
} | ||
@@ -224,7 +234,7 @@ } | ||
switch (_key) { | ||
switch (key) { | ||
case 'animation': | ||
case 'animationName': | ||
{ | ||
string += processStyleName(_key) + ":" + interpolated + ";"; | ||
string += processStyleName(key) + ":" + interpolated + ";"; | ||
break; | ||
@@ -235,7 +245,7 @@ } | ||
{ | ||
if (process.env.NODE_ENV !== 'production' && _key === 'undefined') { | ||
if (process.env.NODE_ENV !== 'production' && key === 'undefined') { | ||
console.error(UNDEFINED_AS_OBJECT_KEY_ERROR); | ||
} | ||
string += _key + "{" + interpolated + "}"; | ||
string += key + "{" + interpolated + "}"; | ||
} | ||
@@ -261,3 +271,3 @@ } | ||
var cursor; | ||
var serializeStyles = function serializeStyles(args, registered, mergedProps) { | ||
function serializeStyles(args, registered, mergedProps) { | ||
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) { | ||
@@ -276,7 +286,9 @@ return args[0]; | ||
} else { | ||
if (process.env.NODE_ENV !== 'production' && strings[0] === undefined) { | ||
var asTemplateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && asTemplateStringsArr[0] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[0]; | ||
styles += asTemplateStringsArr[0]; | ||
} // we start at 1 since we've already handled the first arg | ||
@@ -289,7 +301,9 @@ | ||
if (stringMode) { | ||
if (process.env.NODE_ENV !== 'production' && strings[i] === undefined) { | ||
var templateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && templateStringsArr[i] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[i]; | ||
styles += templateStringsArr[i]; | ||
} | ||
@@ -313,4 +327,3 @@ } | ||
while ((match = labelPattern.exec(styles)) !== null) { | ||
identifierName += '-' + // $FlowFixMe we know it's not null | ||
match[1]; | ||
identifierName += '-' + match[1]; | ||
} | ||
@@ -321,4 +334,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
// $FlowFixMe SerializedStyles type doesn't have toString property (and we don't want to add it) | ||
return { | ||
var devStyles = { | ||
name: name, | ||
@@ -332,2 +344,3 @@ styles: styles, | ||
}; | ||
return devStyles; | ||
} | ||
@@ -340,4 +353,4 @@ | ||
}; | ||
}; | ||
} | ||
exports.serializeStyles = serializeStyles; |
@@ -62,5 +62,7 @@ 'use strict'; | ||
if (interpolation.__emotion_styles !== undefined) { | ||
var componentSelector = interpolation; | ||
return interpolation; | ||
if (componentSelector.__emotion_styles !== undefined) { | ||
return componentSelector; | ||
} | ||
@@ -76,14 +78,18 @@ | ||
{ | ||
if (interpolation.anim === 1) { | ||
var keyframes = interpolation; | ||
if (keyframes.anim === 1) { | ||
cursor = { | ||
name: interpolation.name, | ||
styles: interpolation.styles, | ||
name: keyframes.name, | ||
styles: keyframes.styles, | ||
next: cursor | ||
}; | ||
return interpolation.name; | ||
return keyframes.name; | ||
} | ||
if (interpolation.styles !== undefined) { | ||
var next = interpolation.next; | ||
var serializedStyles = interpolation; | ||
if (serializedStyles.styles !== undefined) { | ||
var next = serializedStyles.next; | ||
if (next !== undefined) { | ||
@@ -102,3 +108,3 @@ // not the most efficient thing ever but this is a pretty rare case | ||
var styles = interpolation.styles + ";"; | ||
var styles = serializedStyles.styles + ";"; | ||
@@ -125,8 +131,10 @@ return styles; | ||
var asString = interpolation; | ||
if (registered == null) { | ||
return interpolation; | ||
return asString; | ||
} | ||
var cached = registered[interpolation]; | ||
return cached !== undefined ? cached : interpolation; | ||
var cached = registered[asString]; | ||
return cached !== undefined ? cached : asString; | ||
} | ||
@@ -142,13 +150,15 @@ | ||
} else { | ||
for (var _key in obj) { | ||
var value = obj[_key]; | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (typeof value !== 'object') { | ||
if (registered != null && registered[value] !== undefined) { | ||
string += _key + "{" + registered[value] + "}"; | ||
} else if (isProcessableValue(value)) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";"; | ||
var asString = value; | ||
if (registered != null && registered[asString] !== undefined) { | ||
string += key + "{" + registered[asString] + "}"; | ||
} else if (isProcessableValue(asString)) { | ||
string += processStyleName(key) + ":" + processStyleValue(key, asString) + ";"; | ||
} | ||
} else { | ||
if (_key === 'NO_COMPONENT_SELECTOR' && "production" !== 'production') { | ||
if (key === 'NO_COMPONENT_SELECTOR' && "production" !== 'production') { | ||
throw new Error(noComponentSelectorMessage); | ||
@@ -160,3 +170,3 @@ } | ||
if (isProcessableValue(value[_i])) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";"; | ||
string += processStyleName(key) + ":" + processStyleValue(key, value[_i]) + ";"; | ||
} | ||
@@ -167,7 +177,7 @@ } | ||
switch (_key) { | ||
switch (key) { | ||
case 'animation': | ||
case 'animationName': | ||
{ | ||
string += processStyleName(_key) + ":" + interpolated + ";"; | ||
string += processStyleName(key) + ":" + interpolated + ";"; | ||
break; | ||
@@ -179,3 +189,3 @@ } | ||
string += _key + "{" + interpolated + "}"; | ||
string += key + "{" + interpolated + "}"; | ||
} | ||
@@ -196,3 +206,3 @@ } | ||
var cursor; | ||
var serializeStyles = function serializeStyles(args, registered, mergedProps) { | ||
function serializeStyles(args, registered, mergedProps) { | ||
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) { | ||
@@ -211,4 +221,5 @@ return args[0]; | ||
} else { | ||
var asTemplateStringsArr = strings; | ||
styles += strings[0]; | ||
styles += asTemplateStringsArr[0]; | ||
} // we start at 1 since we've already handled the first arg | ||
@@ -221,4 +232,5 @@ | ||
if (stringMode) { | ||
var templateStringsArr = strings; | ||
styles += strings[i]; | ||
styles += templateStringsArr[i]; | ||
} | ||
@@ -233,4 +245,3 @@ } | ||
while ((match = labelPattern.exec(styles)) !== null) { | ||
identifierName += '-' + // $FlowFixMe we know it's not null | ||
match[1]; | ||
identifierName += '-' + match[1]; | ||
} | ||
@@ -245,4 +256,4 @@ | ||
}; | ||
}; | ||
} | ||
exports.serializeStyles = serializeStyles; |
@@ -82,8 +82,10 @@ import hashString from '@emotion/hash'; | ||
if (interpolation.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && interpolation.toString() === 'NO_COMPONENT_SELECTOR') { | ||
var componentSelector = interpolation; | ||
if (componentSelector.__emotion_styles !== undefined) { | ||
if (process.env.NODE_ENV !== 'production' && String(componentSelector) === 'NO_COMPONENT_SELECTOR') { | ||
throw new Error(noComponentSelectorMessage); | ||
} | ||
return interpolation; | ||
return componentSelector; | ||
} | ||
@@ -99,14 +101,18 @@ | ||
{ | ||
if (interpolation.anim === 1) { | ||
var keyframes = interpolation; | ||
if (keyframes.anim === 1) { | ||
cursor = { | ||
name: interpolation.name, | ||
styles: interpolation.styles, | ||
name: keyframes.name, | ||
styles: keyframes.styles, | ||
next: cursor | ||
}; | ||
return interpolation.name; | ||
return keyframes.name; | ||
} | ||
if (interpolation.styles !== undefined) { | ||
var next = interpolation.next; | ||
var serializedStyles = interpolation; | ||
if (serializedStyles.styles !== undefined) { | ||
var next = serializedStyles.next; | ||
if (next !== undefined) { | ||
@@ -125,6 +131,6 @@ // not the most efficient thing ever but this is a pretty rare case | ||
var styles = interpolation.styles + ";"; | ||
var styles = serializedStyles.styles + ";"; | ||
if (process.env.NODE_ENV !== 'production' && interpolation.map !== undefined) { | ||
styles += interpolation.map; | ||
if (process.env.NODE_ENV !== 'production' && serializedStyles.map !== undefined) { | ||
styles += serializedStyles.map; | ||
} | ||
@@ -155,3 +161,3 @@ | ||
var matched = []; | ||
var replaced = interpolation.replace(animationRegex, function (match, p1, p2) { | ||
var replaced = interpolation.replace(animationRegex, function (_match, _p1, p2) { | ||
var fakeVarName = "animation" + matched.length; | ||
@@ -163,3 +169,3 @@ matched.push("const " + fakeVarName + " = keyframes`" + p2.replace(/^@keyframes animation-\w+/, '') + "`"); | ||
if (matched.length) { | ||
console.error('`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\n' + 'Instead of doing this:\n\n' + [].concat(matched, ["`" + replaced + "`"]).join('\n') + '\n\nYou should wrap it with `css` like this:\n\n' + ("css`" + replaced + "`")); | ||
console.error("`keyframes` output got interpolated into plain string, please wrap it with `css`.\n\nInstead of doing this:\n\n" + [].concat(matched, ["`" + replaced + "`"]).join('\n') + "\n\nYou should wrap it with `css` like this:\n\ncss`" + replaced + "`"); | ||
} | ||
@@ -172,8 +178,10 @@ } | ||
var asString = interpolation; | ||
if (registered == null) { | ||
return interpolation; | ||
return asString; | ||
} | ||
var cached = registered[interpolation]; | ||
return cached !== undefined ? cached : interpolation; | ||
var cached = registered[asString]; | ||
return cached !== undefined ? cached : asString; | ||
} | ||
@@ -189,13 +197,15 @@ | ||
} else { | ||
for (var _key in obj) { | ||
var value = obj[_key]; | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (typeof value !== 'object') { | ||
if (registered != null && registered[value] !== undefined) { | ||
string += _key + "{" + registered[value] + "}"; | ||
} else if (isProcessableValue(value)) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";"; | ||
var asString = value; | ||
if (registered != null && registered[asString] !== undefined) { | ||
string += key + "{" + registered[asString] + "}"; | ||
} else if (isProcessableValue(asString)) { | ||
string += processStyleName(key) + ":" + processStyleValue(key, asString) + ";"; | ||
} | ||
} else { | ||
if (_key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
if (key === 'NO_COMPONENT_SELECTOR' && process.env.NODE_ENV !== 'production') { | ||
throw new Error(noComponentSelectorMessage); | ||
@@ -207,3 +217,3 @@ } | ||
if (isProcessableValue(value[_i])) { | ||
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";"; | ||
string += processStyleName(key) + ":" + processStyleValue(key, value[_i]) + ";"; | ||
} | ||
@@ -214,7 +224,7 @@ } | ||
switch (_key) { | ||
switch (key) { | ||
case 'animation': | ||
case 'animationName': | ||
{ | ||
string += processStyleName(_key) + ":" + interpolated + ";"; | ||
string += processStyleName(key) + ":" + interpolated + ";"; | ||
break; | ||
@@ -225,7 +235,7 @@ } | ||
{ | ||
if (process.env.NODE_ENV !== 'production' && _key === 'undefined') { | ||
if (process.env.NODE_ENV !== 'production' && key === 'undefined') { | ||
console.error(UNDEFINED_AS_OBJECT_KEY_ERROR); | ||
} | ||
string += _key + "{" + interpolated + "}"; | ||
string += key + "{" + interpolated + "}"; | ||
} | ||
@@ -251,3 +261,3 @@ } | ||
var cursor; | ||
var serializeStyles = function serializeStyles(args, registered, mergedProps) { | ||
function serializeStyles(args, registered, mergedProps) { | ||
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) { | ||
@@ -266,7 +276,9 @@ return args[0]; | ||
} else { | ||
if (process.env.NODE_ENV !== 'production' && strings[0] === undefined) { | ||
var asTemplateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && asTemplateStringsArr[0] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[0]; | ||
styles += asTemplateStringsArr[0]; | ||
} // we start at 1 since we've already handled the first arg | ||
@@ -279,7 +291,9 @@ | ||
if (stringMode) { | ||
if (process.env.NODE_ENV !== 'production' && strings[i] === undefined) { | ||
var templateStringsArr = strings; | ||
if (process.env.NODE_ENV !== 'production' && templateStringsArr[i] === undefined) { | ||
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR); | ||
} | ||
styles += strings[i]; | ||
styles += templateStringsArr[i]; | ||
} | ||
@@ -303,4 +317,3 @@ } | ||
while ((match = labelPattern.exec(styles)) !== null) { | ||
identifierName += '-' + // $FlowFixMe we know it's not null | ||
match[1]; | ||
identifierName += '-' + match[1]; | ||
} | ||
@@ -311,4 +324,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
// $FlowFixMe SerializedStyles type doesn't have toString property (and we don't want to add it) | ||
return { | ||
var devStyles = { | ||
name: name, | ||
@@ -322,2 +334,3 @@ styles: styles, | ||
}; | ||
return devStyles; | ||
} | ||
@@ -330,4 +343,4 @@ | ||
}; | ||
}; | ||
} | ||
export { serializeStyles }; |
{ | ||
"name": "@emotion/serialize", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "serialization utils for emotion", | ||
"main": "dist/emotion-serialize.cjs.js", | ||
"module": "dist/emotion-serialize.esm.js", | ||
"types": "types/index.d.ts", | ||
"types": "dist/emotion-serialize.cjs.d.ts", | ||
"license": "MIT", | ||
@@ -17,6 +17,6 @@ "repository": "https://github.com/emotion-js/emotion/tree/main/packages/serialize", | ||
"dependencies": { | ||
"@emotion/hash": "^0.9.1", | ||
"@emotion/memoize": "^0.8.1", | ||
"@emotion/unitless": "^0.8.1", | ||
"@emotion/utils": "^1.2.1", | ||
"@emotion/hash": "^0.9.2", | ||
"@emotion/memoize": "^0.9.0", | ||
"@emotion/unitless": "^0.9.0", | ||
"@emotion/utils": "^1.3.0", | ||
"csstype": "^3.0.2" | ||
@@ -26,8 +26,7 @@ }, | ||
"@definitelytyped/dtslint": "0.0.112", | ||
"typescript": "^4.5.5" | ||
"typescript": "^5.4.5" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"types/*.d.ts" | ||
"dist" | ||
], | ||
@@ -34,0 +33,0 @@ "browser": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59808
1464
38
14
+ Added@emotion/memoize@0.9.0(transitive)
+ Added@emotion/unitless@0.9.0(transitive)
- Removed@emotion/memoize@0.8.1(transitive)
- Removed@emotion/unitless@0.8.1(transitive)
Updated@emotion/hash@^0.9.2
Updated@emotion/memoize@^0.9.0
Updated@emotion/unitless@^0.9.0
Updated@emotion/utils@^1.3.0