@linaria/react 4.1.3 → 4.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/processors/styled.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildSlug, hasMeta, TaggedTemplateProcessor, validateParams, ValueType, toValidCSSIdentifier } from '@linaria/tags';
|
|
2
|
+
import { slugify } from '@linaria/utils';
|
|
2
3
|
|
|
3
4
|
const isNotNull = x => x !== null;
|
|
4
5
|
|
|
@@ -53,8 +54,8 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
|
|
|
53
54
|
this.component = component;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
addInterpolation(node, source, unit = '') {
|
|
57
|
-
const id = this.getVariableId(source
|
|
57
|
+
addInterpolation(node, precedingCss, source, unit = '') {
|
|
58
|
+
const id = this.getVariableId(source, unit, precedingCss);
|
|
58
59
|
this.interpolations.push({
|
|
59
60
|
id,
|
|
60
61
|
node,
|
|
@@ -139,6 +140,17 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
|
|
|
139
140
|
return res(this.component.source);
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
getCustomVariableId(source, unit, precedingCss) {
|
|
144
|
+
const context = this.getVariableContext(source, unit, precedingCss);
|
|
145
|
+
const customSlugFn = this.options.variableNameSlug;
|
|
146
|
+
|
|
147
|
+
if (!customSlugFn) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return typeof customSlugFn === 'function' ? customSlugFn(context) : buildSlug(customSlugFn, context);
|
|
152
|
+
}
|
|
153
|
+
|
|
142
154
|
getProps() {
|
|
143
155
|
const propsObj = {
|
|
144
156
|
name: this.displayName,
|
|
@@ -188,14 +200,43 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
|
|
|
188
200
|
return t.objectProperty(keyNode, t.objectExpression(vars));
|
|
189
201
|
}).filter(isNotNull);
|
|
190
202
|
return t.objectExpression(propExpressions);
|
|
191
|
-
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
getVariableContext(source, unit, precedingCss) {
|
|
206
|
+
const getIndex = () => {
|
|
207
|
+
// eslint-disable-next-line no-plusplus
|
|
208
|
+
return this.#variableIdx++;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
componentName: this.displayName,
|
|
213
|
+
componentSlug: this.slug,
|
|
192
214
|
|
|
215
|
+
get index() {
|
|
216
|
+
return getIndex();
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
precedingCss,
|
|
220
|
+
processor: this.constructor.name,
|
|
221
|
+
source,
|
|
222
|
+
unit,
|
|
223
|
+
valueSlug: slugify(source + unit)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getVariableId(source, unit, precedingCss) {
|
|
228
|
+
const value = source + unit;
|
|
193
229
|
|
|
194
|
-
getVariableId(value) {
|
|
195
230
|
if (!this.#variablesCache.has(value)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
231
|
+
const id = this.getCustomVariableId(source, unit, precedingCss);
|
|
232
|
+
|
|
233
|
+
if (id) {
|
|
234
|
+
return toValidCSSIdentifier(id);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const context = this.getVariableContext(source, unit, precedingCss); // make the variable unique to this styled component
|
|
238
|
+
|
|
239
|
+
this.#variablesCache.set(value, `${this.slug}-${context.index}`);
|
|
199
240
|
}
|
|
200
241
|
|
|
201
242
|
return this.#variablesCache.get(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","names":["TaggedTemplateProcessor","ValueType","hasMeta","validateParams","isNotNull","x","singleQuotedStringLiteral","value","type","extra","rawValue","raw","StyledProcessor","variableIdx","variablesCache","Map","constructor","params","args","tag","tagOp","template","SKIP","component","length","kind","FUNCTION","node","ex","source","dependencies","push","Error","addInterpolation","unit","id","getVariableId","interpolations","doEvaltimeReplacement","replacer","doRuntimeReplacement","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","extractRules","valueCache","cssText","loc","rules","selector","className","get","name","__linaria","extends","displayName","start","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","extendsNode","objectExpression","objectProperty","stringLiteral","nullLiteral","toString","res","arg","tagSourceCode","propsObj","class","vars","forEach","items","propExpressions","Object","entries","map","key","keyNode","booleanLiteral","propName","propValue","arrayExpression","filter","has","set","slug"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type {\n CallExpression,\n Expression,\n ObjectExpression,\n SourceLocation,\n StringLiteral,\n} from '@babel/types';\n\nimport type {\n Rules,\n WrappedNode,\n ValueCache,\n Params,\n TailProcessorParams,\n} from '@linaria/tags';\nimport {\n TaggedTemplateProcessor,\n ValueType,\n hasMeta,\n validateParams,\n} from '@linaria/tags';\n\nconst isNotNull = <T>(x: T | null): x is T => x !== null;\n\nexport interface IProps {\n atomic?: boolean;\n class?: string;\n name: string;\n vars?: Record<string, Expression[]>;\n}\n\nconst singleQuotedStringLiteral = (value: string): StringLiteral => ({\n type: 'StringLiteral',\n value,\n extra: {\n rawValue: value,\n raw: `'${value}'`,\n },\n});\n\nexport default class StyledProcessor extends TaggedTemplateProcessor {\n public component: WrappedNode;\n\n #variableIdx = 0;\n\n #variablesCache = new Map<string, string>();\n\n constructor(params: Params, ...args: TailProcessorParams) {\n validateParams(\n params,\n ['tag', ['call', 'member'], ['template', 'call']],\n 'Invalid usage of `styled` tag'\n );\n\n const [tag, tagOp, template] = params;\n\n if (template[0] === 'call') {\n // It is already transformed styled-literal. Skip it.\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw TaggedTemplateProcessor.SKIP;\n }\n\n super([tag, template], ...args);\n\n let component: WrappedNode | undefined;\n if (tagOp[0] === 'call' && tagOp.length === 2) {\n const value = tagOp[1];\n if (value.kind === ValueType.FUNCTION) {\n component = 'FunctionalComponent';\n } else {\n component = {\n node: value.ex,\n source: value.source,\n };\n\n this.dependencies.push(value);\n }\n }\n\n if (tagOp[0] === 'member') {\n [, component] = tagOp;\n }\n\n if (!component) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(\n node: Expression,\n source: string,\n unit = ''\n ): string {\n const id = this.getVariableId(source + unit);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit,\n });\n\n return id;\n }\n\n public override doEvaltimeReplacement(): void {\n this.replacer(this.value, false);\n }\n\n public override doRuntimeReplacement(): void {\n const t = this.astService;\n\n const props = this.getProps();\n\n this.replacer(\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true\n );\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n let selector = `.${this.className}`;\n\n // If `styled` wraps another component and not a primitive,\n // get its class name to create a more specific selector\n // it'll ensure that styles are overridden properly\n let value =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node.name);\n while (hasMeta(value)) {\n selector += `.${value.__linaria.className}`;\n value = value.__linaria.extends;\n }\n\n rules[selector] = {\n cssText,\n className: this.className,\n displayName: this.displayName,\n start: loc?.start ?? null,\n };\n\n return rules;\n }\n\n public override get asSelector(): string {\n return `.${this.className}`;\n }\n\n protected get tagExpressionArgument(): Expression {\n const t = this.astService;\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return t.arrowFunctionExpression([], t.blockStatement([]));\n }\n\n return singleQuotedStringLiteral(this.component);\n }\n\n return t.callExpression(t.identifier(this.component.node.name), []);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tag, [this.tagExpressionArgument]);\n }\n\n public override get value(): ObjectExpression {\n const t = this.astService;\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.node.name;\n\n return t.objectExpression([\n t.objectProperty(\n t.stringLiteral('displayName'),\n t.stringLiteral(this.displayName)\n ),\n t.objectProperty(\n t.stringLiteral('__linaria'),\n t.objectExpression([\n t.objectProperty(\n t.stringLiteral('className'),\n t.stringLiteral(this.className)\n ),\n t.objectProperty(\n t.stringLiteral('extends'),\n extendsNode\n ? t.callExpression(t.identifier(extendsNode), [])\n : t.nullLiteral()\n ),\n ])\n ),\n ]);\n }\n\n public override toString(): string {\n const res = (arg: string) => `${this.tagSourceCode()}(${arg})\\`…\\``;\n\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return res('() => {…}');\n }\n\n return res(`'${this.component}'`);\n }\n\n return res(this.component.source);\n }\n\n protected getProps(): IProps {\n const propsObj: IProps = {\n name: this.displayName,\n class: this.className,\n };\n\n // If we found any interpolations, also pass them, so they can be applied\n if (this.interpolations.length) {\n propsObj.vars = {};\n this.interpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [this.astService.callExpression(node, [])];\n\n if (unit) {\n items.push(this.astService.stringLiteral(unit));\n }\n\n propsObj.vars![id] = items;\n });\n }\n\n return propsObj;\n }\n\n protected getTagComponentProps(props: IProps): ObjectExpression {\n const t = this.astService;\n\n const propExpressions = Object.entries(props)\n .map(([key, value]: [key: string, value: IProps[keyof IProps]]) => {\n if (!value) {\n return null;\n }\n\n const keyNode = t.identifier(key);\n\n if (typeof value === 'string') {\n return t.objectProperty(keyNode, t.stringLiteral(value));\n }\n\n if (typeof value === 'boolean') {\n return t.objectProperty(keyNode, t.booleanLiteral(value));\n }\n\n const vars = Object.entries(value).map(([propName, propValue]) => {\n return t.objectProperty(\n t.stringLiteral(propName),\n t.arrayExpression(propValue)\n );\n });\n\n return t.objectProperty(keyNode, t.objectExpression(vars));\n })\n .filter(isNotNull);\n\n return t.objectExpression(propExpressions);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected getVariableId(value: string): string {\n if (!this.#variablesCache.has(value)) {\n // make the variable unique to this styled component\n // eslint-disable-next-line no-plusplus\n this.#variablesCache.set(value, `${this.slug}-${this.#variableIdx++}`);\n }\n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iBiB,OAAjB,EAA0B5C,CAAC,CAAC6C,cAAF,CAAiB/E,KAAjB,CAA1B,CAAP;MACD;;MAED,MAAMsE,IAAI,GAAGI,MAAM,CAACC,OAAP,CAAe3E,KAAf,EAAsB4E,GAAtB,CAA0B,CAAC,CAACI,QAAD,EAAWC,SAAX,CAAD,KAA2B;QAChE,OAAO/C,CAAC,CAAC2B,cAAF,CACL3B,CAAC,CAAC4B,aAAF,CAAgBkB,QAAhB,CADK,EAEL9C,CAAC,CAACgD,eAAF,CAAkBD,SAAlB,CAFK,CAAP;MAID,CALY,CAAb;MAOA,OAAO/C,CAAC,CAAC2B,cAAF,CAAiBiB,OAAjB,EAA0B5C,CAAC,CAAC0B,gBAAF,CAAmBU,IAAnB,CAA1B,CAAP;IACD,CAxBqB,EAyBrBa,MAzBqB,CAyBdtF,SAzBc,CAAxB;IA2BA,OAAOqC,CAAC,CAAC0B,gBAAF,CAAmBa,eAAnB,CAAP;EACD,CAvOkE,CAyOnE;;;EACU5C,aAAa,CAAC7B,KAAD,EAAwB;IAC7C,IAAI,CAAC,KAAK,CAACO,cAAN,CAAqB6E,GAArB,CAAyBpF,KAAzB,CAAL,EAAsC;MACpC;MACA;MACA,KAAK,CAACO,cAAN,CAAqB8E,GAArB,CAAyBrF,KAAzB,EAAiC,GAAE,KAAKsF,IAAK,IAAG,KAAK,CAAChF,WAAN,EAAoB,EAApE;IACD;;IAED,OAAO,KAAK,CAACC,cAAN,CAAqByC,GAArB,CAAyBhD,KAAzB,CAAP;EACD;;AAlPkE"}
|
|
1
|
+
{"version":3,"file":"styled.js","names":["buildSlug","hasMeta","TaggedTemplateProcessor","validateParams","ValueType","toValidCSSIdentifier","slugify","isNotNull","x","singleQuotedStringLiteral","value","type","extra","rawValue","raw","StyledProcessor","variableIdx","variablesCache","Map","constructor","params","args","tag","tagOp","template","SKIP","component","length","kind","FUNCTION","node","ex","source","dependencies","push","Error","addInterpolation","precedingCss","unit","id","getVariableId","interpolations","doEvaltimeReplacement","replacer","doRuntimeReplacement","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","extractRules","valueCache","cssText","loc","rules","selector","className","get","name","__linaria","extends","displayName","start","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","extendsNode","objectExpression","objectProperty","stringLiteral","nullLiteral","toString","res","arg","tagSourceCode","getCustomVariableId","context","getVariableContext","customSlugFn","options","variableNameSlug","undefined","propsObj","class","vars","forEach","items","propExpressions","Object","entries","map","key","keyNode","booleanLiteral","propName","propValue","arrayExpression","filter","getIndex","componentName","componentSlug","slug","index","processor","valueSlug","has","set"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type {\n CallExpression,\n Expression,\n ObjectExpression,\n SourceLocation,\n StringLiteral,\n} from '@babel/types';\n\nimport type {\n Params,\n Rules,\n TailProcessorParams,\n ValueCache,\n WrappedNode,\n} from '@linaria/tags';\nimport {\n buildSlug,\n hasMeta,\n TaggedTemplateProcessor,\n validateParams,\n ValueType,\n toValidCSSIdentifier,\n} from '@linaria/tags';\nimport type { IVariableContext } from '@linaria/utils';\nimport { slugify } from '@linaria/utils';\n\nconst isNotNull = <T>(x: T | null): x is T => x !== null;\n\nexport interface IProps {\n atomic?: boolean;\n class?: string;\n name: string;\n vars?: Record<string, Expression[]>;\n}\n\nconst singleQuotedStringLiteral = (value: string): StringLiteral => ({\n type: 'StringLiteral',\n value,\n extra: {\n rawValue: value,\n raw: `'${value}'`,\n },\n});\n\nexport default class StyledProcessor extends TaggedTemplateProcessor {\n public component: WrappedNode;\n\n #variableIdx = 0;\n\n #variablesCache = new Map<string, string>();\n\n constructor(params: Params, ...args: TailProcessorParams) {\n validateParams(\n params,\n ['tag', ['call', 'member'], ['template', 'call']],\n 'Invalid usage of `styled` tag'\n );\n\n const [tag, tagOp, template] = params;\n\n if (template[0] === 'call') {\n // It is already transformed styled-literal. Skip it.\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw TaggedTemplateProcessor.SKIP;\n }\n\n super([tag, template], ...args);\n\n let component: WrappedNode | undefined;\n if (tagOp[0] === 'call' && tagOp.length === 2) {\n const value = tagOp[1];\n if (value.kind === ValueType.FUNCTION) {\n component = 'FunctionalComponent';\n } else {\n component = {\n node: value.ex,\n source: value.source,\n };\n\n this.dependencies.push(value);\n }\n }\n\n if (tagOp[0] === 'member') {\n [, component] = tagOp;\n }\n\n if (!component) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit = ''\n ): string {\n const id = this.getVariableId(source, unit, precedingCss);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit,\n });\n\n return id;\n }\n\n public override doEvaltimeReplacement(): void {\n this.replacer(this.value, false);\n }\n\n public override doRuntimeReplacement(): void {\n const t = this.astService;\n\n const props = this.getProps();\n\n this.replacer(\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true\n );\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n let selector = `.${this.className}`;\n\n // If `styled` wraps another component and not a primitive,\n // get its class name to create a more specific selector\n // it'll ensure that styles are overridden properly\n let value =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node.name);\n while (hasMeta(value)) {\n selector += `.${value.__linaria.className}`;\n value = value.__linaria.extends;\n }\n\n rules[selector] = {\n cssText,\n className: this.className,\n displayName: this.displayName,\n start: loc?.start ?? null,\n };\n\n return rules;\n }\n\n public override get asSelector(): string {\n return `.${this.className}`;\n }\n\n protected get tagExpressionArgument(): Expression {\n const t = this.astService;\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return t.arrowFunctionExpression([], t.blockStatement([]));\n }\n\n return singleQuotedStringLiteral(this.component);\n }\n\n return t.callExpression(t.identifier(this.component.node.name), []);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tag, [this.tagExpressionArgument]);\n }\n\n public override get value(): ObjectExpression {\n const t = this.astService;\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.node.name;\n\n return t.objectExpression([\n t.objectProperty(\n t.stringLiteral('displayName'),\n t.stringLiteral(this.displayName)\n ),\n t.objectProperty(\n t.stringLiteral('__linaria'),\n t.objectExpression([\n t.objectProperty(\n t.stringLiteral('className'),\n t.stringLiteral(this.className)\n ),\n t.objectProperty(\n t.stringLiteral('extends'),\n extendsNode\n ? t.callExpression(t.identifier(extendsNode), [])\n : t.nullLiteral()\n ),\n ])\n ),\n ]);\n }\n\n public override toString(): string {\n const res = (arg: string) => `${this.tagSourceCode()}(${arg})\\`…\\``;\n\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return res('() => {…}');\n }\n\n return res(`'${this.component}'`);\n }\n\n return res(this.component.source);\n }\n\n protected getCustomVariableId(\n source: string,\n unit: string,\n precedingCss: string\n ) {\n const context = this.getVariableContext(source, unit, precedingCss);\n const customSlugFn = this.options.variableNameSlug;\n if (!customSlugFn) {\n return undefined;\n }\n\n return typeof customSlugFn === 'function'\n ? customSlugFn(context)\n : buildSlug(customSlugFn, context);\n }\n\n protected getProps(): IProps {\n const propsObj: IProps = {\n name: this.displayName,\n class: this.className,\n };\n\n // If we found any interpolations, also pass them, so they can be applied\n if (this.interpolations.length) {\n propsObj.vars = {};\n this.interpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [this.astService.callExpression(node, [])];\n\n if (unit) {\n items.push(this.astService.stringLiteral(unit));\n }\n\n propsObj.vars![id] = items;\n });\n }\n\n return propsObj;\n }\n\n protected getTagComponentProps(props: IProps): ObjectExpression {\n const t = this.astService;\n\n const propExpressions = Object.entries(props)\n .map(([key, value]: [key: string, value: IProps[keyof IProps]]) => {\n if (!value) {\n return null;\n }\n\n const keyNode = t.identifier(key);\n\n if (typeof value === 'string') {\n return t.objectProperty(keyNode, t.stringLiteral(value));\n }\n\n if (typeof value === 'boolean') {\n return t.objectProperty(keyNode, t.booleanLiteral(value));\n }\n\n const vars = Object.entries(value).map(([propName, propValue]) => {\n return t.objectProperty(\n t.stringLiteral(propName),\n t.arrayExpression(propValue)\n );\n });\n\n return t.objectProperty(keyNode, t.objectExpression(vars));\n })\n .filter(isNotNull);\n\n return t.objectExpression(propExpressions);\n }\n\n protected getVariableContext(\n source: string,\n unit: string,\n precedingCss: string\n ): IVariableContext {\n const getIndex = () => {\n // eslint-disable-next-line no-plusplus\n return this.#variableIdx++;\n };\n\n return {\n componentName: this.displayName,\n componentSlug: this.slug,\n get index() {\n return getIndex();\n },\n precedingCss,\n processor: this.constructor.name,\n source,\n unit,\n valueSlug: slugify(source + unit),\n };\n }\n\n protected getVariableId(\n source: string,\n unit: string,\n precedingCss: string\n ): string {\n const value = source + unit;\n if (!this.#variablesCache.has(value)) {\n const id = this.getCustomVariableId(source, unit, precedingCss);\n if (id) {\n return toValidCSSIdentifier(id);\n }\n\n const context = this.getVariableContext(source, unit, precedingCss);\n\n // make the variable unique to this styled component\n this.#variablesCache.set(value, `${this.slug}-${context.index}`);\n }\n\n return this.#variablesCache.get(value)!;\n }\n}\n"],"mappings":"AAeA,SACEA,SADF,EAEEC,OAFF,EAGEC,uBAHF,EAIEC,cAJF,EAKEC,SALF,EAMEC,oBANF,QAOO,eAPP;AASA,SAASC,OAAT,QAAwB,gBAAxB;;AAEA,MAAMC,SAAS,GAAOC,CAAJ,IAA4BA,CAAC,KAAK,IAApD;;AASA,MAAMC,yBAAyB,GAAIC,KAAD,KAAmC;EACnEC,IAAI,EAAE,eAD6D;EAEnED,KAFmE;EAGnEE,KAAK,EAAE;IACLC,QAAQ,EAAEH,KADL;IAELI,GAAG,EAAG,IAAGJ,KAAM;EAFV;AAH4D,CAAnC,CAAlC;;AASA,eAAe,MAAMK,eAAN,SAA8Bb,uBAA9B,CAAsD;EAGnE,CAACc,WAAD,GAAe,CAAf;EAEA,CAACC,cAAD,GAAkB,IAAIC,GAAJ,EAAlB;;EAEAC,WAAW,CAACC,MAAD,E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M,IAAjC,EAAuCD,YAAvC,CAAX;;MACA,IAAIE,EAAJ,EAAQ;QACN,OAAOlC,oBAAoB,CAACkC,EAAD,CAA3B;MACD;;MAED,MAAMyC,OAAO,GAAG,KAAKC,kBAAL,CAAwBjD,MAAxB,EAAgCM,IAAhC,EAAsCD,YAAtC,CAAhB,CANoC,CAQpC;;MACA,KAAK,CAACpB,cAAN,CAAqB6F,GAArB,CAAyBpG,KAAzB,EAAiC,GAAE,KAAK+F,IAAK,IAAGzB,OAAO,CAAC0B,KAAM,EAA9D;IACD;;IAED,OAAO,KAAK,CAACzF,cAAN,CAAqB0C,GAArB,CAAyBjD,KAAzB,CAAP;EACD;;AArSkE"}
|
package/lib/processors/styled.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _tags = require("@linaria/tags");
|
|
9
9
|
|
|
10
|
+
var _utils = require("@linaria/utils");
|
|
11
|
+
|
|
10
12
|
const isNotNull = x => x !== null;
|
|
11
13
|
|
|
12
14
|
const singleQuotedStringLiteral = value => ({
|
|
@@ -60,8 +62,8 @@ class StyledProcessor extends _tags.TaggedTemplateProcessor {
|
|
|
60
62
|
this.component = component;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
addInterpolation(node, source, unit = '') {
|
|
64
|
-
const id = this.getVariableId(source
|
|
65
|
+
addInterpolation(node, precedingCss, source, unit = '') {
|
|
66
|
+
const id = this.getVariableId(source, unit, precedingCss);
|
|
65
67
|
this.interpolations.push({
|
|
66
68
|
id,
|
|
67
69
|
node,
|
|
@@ -148,6 +150,17 @@ class StyledProcessor extends _tags.TaggedTemplateProcessor {
|
|
|
148
150
|
return res(this.component.source);
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
getCustomVariableId(source, unit, precedingCss) {
|
|
154
|
+
const context = this.getVariableContext(source, unit, precedingCss);
|
|
155
|
+
const customSlugFn = this.options.variableNameSlug;
|
|
156
|
+
|
|
157
|
+
if (!customSlugFn) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return typeof customSlugFn === 'function' ? customSlugFn(context) : (0, _tags.buildSlug)(customSlugFn, context);
|
|
162
|
+
}
|
|
163
|
+
|
|
151
164
|
getProps() {
|
|
152
165
|
const propsObj = {
|
|
153
166
|
name: this.displayName,
|
|
@@ -197,14 +210,43 @@ class StyledProcessor extends _tags.TaggedTemplateProcessor {
|
|
|
197
210
|
return t.objectProperty(keyNode, t.objectExpression(vars));
|
|
198
211
|
}).filter(isNotNull);
|
|
199
212
|
return t.objectExpression(propExpressions);
|
|
200
|
-
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
getVariableContext(source, unit, precedingCss) {
|
|
216
|
+
const getIndex = () => {
|
|
217
|
+
// eslint-disable-next-line no-plusplus
|
|
218
|
+
return this.#variableIdx++;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
componentName: this.displayName,
|
|
223
|
+
componentSlug: this.slug,
|
|
201
224
|
|
|
225
|
+
get index() {
|
|
226
|
+
return getIndex();
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
precedingCss,
|
|
230
|
+
processor: this.constructor.name,
|
|
231
|
+
source,
|
|
232
|
+
unit,
|
|
233
|
+
valueSlug: (0, _utils.slugify)(source + unit)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getVariableId(source, unit, precedingCss) {
|
|
238
|
+
const value = source + unit;
|
|
202
239
|
|
|
203
|
-
getVariableId(value) {
|
|
204
240
|
if (!this.#variablesCache.has(value)) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
241
|
+
const id = this.getCustomVariableId(source, unit, precedingCss);
|
|
242
|
+
|
|
243
|
+
if (id) {
|
|
244
|
+
return (0, _tags.toValidCSSIdentifier)(id);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const context = this.getVariableContext(source, unit, precedingCss); // make the variable unique to this styled component
|
|
248
|
+
|
|
249
|
+
this.#variablesCache.set(value, `${this.slug}-${context.index}`);
|
|
208
250
|
}
|
|
209
251
|
|
|
210
252
|
return this.#variablesCache.get(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","names":["isNotNull","x","singleQuotedStringLiteral","value","type","extra","rawValue","raw","StyledProcessor","TaggedTemplateProcessor","variableIdx","variablesCache","Map","constructor","params","args","validateParams","tag","tagOp","template","SKIP","component","length","kind","ValueType","FUNCTION","node","ex","source","dependencies","push","Error","addInterpolation","unit","id","getVariableId","interpolations","doEvaltimeReplacement","replacer","doRuntimeReplacement","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","extractRules","valueCache","cssText","loc","rules","selector","className","get","name","hasMeta","__linaria","extends","displayName","start","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","extendsNode","objectExpression","objectProperty","stringLiteral","nullLiteral","toString","res","arg","tagSourceCode","propsObj","class","vars","forEach","items","propExpressions","Object","entries","map","key","keyNode","booleanLiteral","propName","propValue","arrayExpression","filter","has","set","slug"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type {\n CallExpression,\n Expression,\n ObjectExpression,\n SourceLocation,\n StringLiteral,\n} from '@babel/types';\n\nimport type {\n Rules,\n WrappedNode,\n ValueCache,\n Params,\n TailProcessorParams,\n} from '@linaria/tags';\nimport {\n TaggedTemplateProcessor,\n ValueType,\n hasMeta,\n validateParams,\n} from '@linaria/tags';\n\nconst isNotNull = <T>(x: T | null): x is T => x !== null;\n\nexport interface IProps {\n atomic?: boolean;\n class?: string;\n name: string;\n vars?: Record<string, Expression[]>;\n}\n\nconst singleQuotedStringLiteral = (value: string): StringLiteral => ({\n type: 'StringLiteral',\n value,\n extra: {\n rawValue: value,\n raw: `'${value}'`,\n },\n});\n\nexport default class StyledProcessor extends TaggedTemplateProcessor {\n public component: WrappedNode;\n\n #variableIdx = 0;\n\n #variablesCache = new Map<string, string>();\n\n constructor(params: Params, ...args: TailProcessorParams) {\n validateParams(\n params,\n ['tag', ['call', 'member'], ['template', 'call']],\n 'Invalid usage of `styled` tag'\n );\n\n const [tag, tagOp, template] = params;\n\n if (template[0] === 'call') {\n // It is already transformed styled-literal. Skip it.\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw TaggedTemplateProcessor.SKIP;\n }\n\n super([tag, template], ...args);\n\n let component: WrappedNode | undefined;\n if (tagOp[0] === 'call' && tagOp.length === 2) {\n const value = tagOp[1];\n if (value.kind === ValueType.FUNCTION) {\n component = 'FunctionalComponent';\n } else {\n component = {\n node: value.ex,\n source: value.source,\n };\n\n this.dependencies.push(value);\n }\n }\n\n if (tagOp[0] === 'member') {\n [, component] = tagOp;\n }\n\n if (!component) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(\n node: Expression,\n source: string,\n unit = ''\n ): string {\n const id = this.getVariableId(source + unit);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit,\n });\n\n return id;\n }\n\n public override doEvaltimeReplacement(): void {\n this.replacer(this.value, false);\n }\n\n public override doRuntimeReplacement(): void {\n const t = this.astService;\n\n const props = this.getProps();\n\n this.replacer(\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true\n );\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n let selector = `.${this.className}`;\n\n // If `styled` wraps another component and not a primitive,\n // get its class name to create a more specific selector\n // it'll ensure that styles are overridden properly\n let value =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node.name);\n while (hasMeta(value)) {\n selector += `.${value.__linaria.className}`;\n value = value.__linaria.extends;\n }\n\n rules[selector] = {\n cssText,\n className: this.className,\n displayName: this.displayName,\n start: loc?.start ?? null,\n };\n\n return rules;\n }\n\n public override get asSelector(): string {\n return `.${this.className}`;\n }\n\n protected get tagExpressionArgument(): Expression {\n const t = this.astService;\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return t.arrowFunctionExpression([], t.blockStatement([]));\n }\n\n return singleQuotedStringLiteral(this.component);\n }\n\n return t.callExpression(t.identifier(this.component.node.name), []);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tag, [this.tagExpressionArgument]);\n }\n\n public override get value(): ObjectExpression {\n const t = this.astService;\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.node.name;\n\n return t.objectExpression([\n t.objectProperty(\n t.stringLiteral('displayName'),\n t.stringLiteral(this.displayName)\n ),\n t.objectProperty(\n t.stringLiteral('__linaria'),\n t.objectExpression([\n t.objectProperty(\n t.stringLiteral('className'),\n t.stringLiteral(this.className)\n ),\n t.objectProperty(\n t.stringLiteral('extends'),\n extendsNode\n ? t.callExpression(t.identifier(extendsNode), [])\n : t.nullLiteral()\n ),\n ])\n ),\n ]);\n }\n\n public override toString(): string {\n const res = (arg: string) => `${this.tagSourceCode()}(${arg})\\`…\\``;\n\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return res('() => {…}');\n }\n\n return res(`'${this.component}'`);\n }\n\n return res(this.component.source);\n }\n\n protected getProps(): IProps {\n const propsObj: IProps = {\n name: this.displayName,\n class: this.className,\n };\n\n // If we found any interpolations, also pass them, so they can be applied\n if (this.interpolations.length) {\n propsObj.vars = {};\n this.interpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [this.astService.callExpression(node, [])];\n\n if (unit) {\n items.push(this.astService.stringLiteral(unit));\n }\n\n propsObj.vars![id] = items;\n });\n }\n\n return propsObj;\n }\n\n protected getTagComponentProps(props: IProps): ObjectExpression {\n const t = this.astService;\n\n const propExpressions = Object.entries(props)\n .map(([key, value]: [key: string, value: IProps[keyof IProps]]) => {\n if (!value) {\n return null;\n }\n\n const keyNode = t.identifier(key);\n\n if (typeof value === 'string') {\n return t.objectProperty(keyNode, t.stringLiteral(value));\n }\n\n if (typeof value === 'boolean') {\n return t.objectProperty(keyNode, t.booleanLiteral(value));\n }\n\n const vars = Object.entries(value).map(([propName, propValue]) => {\n return t.objectProperty(\n t.stringLiteral(propName),\n t.arrayExpression(propValue)\n );\n });\n\n return t.objectProperty(keyNode, t.objectExpression(vars));\n })\n .filter(isNotNull);\n\n return t.objectExpression(propExpressions);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected getVariableId(value: string): string {\n if (!this.#variablesCache.has(value)) {\n // make the variable unique to this styled component\n // eslint-disable-next-line no-plusplus\n this.#variablesCache.set(value, `${this.slug}-${this.#variableIdx++}`);\n }\n\n return this.#variablesCache.get(value)!;\n }\n}\n"],"mappings":";;;;;;;AAeA;;AAOA,MAAMA,SAAS,GAAOC,CAAJ,IAA4BA,CAAC,KAAK,IAApD;;AASA,MAAMC,yBAAyB,GAAIC,KAAD,KAAmC;EACnEC,IAAI,EAAE,eAD6D;EAEnED,KAFmE;EAGnEE,KAAK,EAAE;IACLC,QAAQ,EAAEH,KADL;IAELI,GAAG,EAAG,IAAGJ,KAAM;EAFV;AAH4D,CAAnC,CAAlC;;AASe,MAAMK,eAAN,SAA8BC,6BAA9B,CAAsD;EAGnE,CAACC,WAAD,GAAe,CAAf;EAEA,CAACC,cAAD,GAAkB,IAAIC,GAAJ,EAAlB;;EAEAC,WAAW,CAACC,MAAD,EAAiB,GAAGC,IAApB,EAA+C;IACxD,IAAAC,oBAAA,EACEF,MADF,EAEE,CAAC,KAAD,EAAQ,CAAC,MAAD,EAAS,QAAT,CAAR,EAA4B,CAAC,UAAD,EAAa,MAAb,CAA5B,CAFF,EAGE,+BAHF;IAMA,MAAM,CAACG,GAAD,EAAMC,KAAN,EAAaC,QAAb,IAAyBL,MAA/B;;IAEA,IAAIK,QAAQ,CAAC,CAAD,CAAR,KAAgB,MAApB,EAA4B;MAC1B;MACA;MACA,MAAMV,6BAAA,CAAwBW,IAA9B;IACD;;IAED,MAAM,CAACH,GAAD,EAAME,QAAN,CAAN,EAAuB,GAAGJ,IAA1B;IAEA,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CAACC,cAAN,CAAqB2C,GAArB,CAAyBnD,KAAzB,CAAP;EACD;;AAlPkE"}
|
|
1
|
+
{"version":3,"file":"styled.js","names":["isNotNull","x","singleQuotedStringLiteral","value","type","extra","rawValue","raw","StyledProcessor","TaggedTemplateProcessor","variableIdx","variablesCache","Map","constructor","params","args","validateParams","tag","tagOp","template","SKIP","component","length","kind","ValueType","FUNCTION","node","ex","source","dependencies","push","Error","addInterpolation","precedingCss","unit","id","getVariableId","interpolations","doEvaltimeReplacement","replacer","doRuntimeReplacement","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","extractRules","valueCache","cssText","loc","rules","selector","className","get","name","hasMeta","__linaria","extends","displayName","start","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","extendsNode","objectExpression","objectProperty","stringLiteral","nullLiteral","toString","res","arg","tagSourceCode","getCustomVariableId","context","getVariableContext","customSlugFn","options","variableNameSlug","undefined","buildSlug","propsObj","class","vars","forEach","items","propExpressions","Object","entries","map","key","keyNode","booleanLiteral","propName","propValue","arrayExpression","filter","getIndex","componentName","componentSlug","slug","index","processor","valueSlug","slugify","has","toValidCSSIdentifier","set"],"sources":["../../src/processors/styled.ts"],"sourcesContent":["import type {\n CallExpression,\n Expression,\n ObjectExpression,\n SourceLocation,\n StringLiteral,\n} from '@babel/types';\n\nimport type {\n Params,\n Rules,\n TailProcessorParams,\n ValueCache,\n WrappedNode,\n} from '@linaria/tags';\nimport {\n buildSlug,\n hasMeta,\n TaggedTemplateProcessor,\n validateParams,\n ValueType,\n toValidCSSIdentifier,\n} from '@linaria/tags';\nimport type { IVariableContext } from '@linaria/utils';\nimport { slugify } from '@linaria/utils';\n\nconst isNotNull = <T>(x: T | null): x is T => x !== null;\n\nexport interface IProps {\n atomic?: boolean;\n class?: string;\n name: string;\n vars?: Record<string, Expression[]>;\n}\n\nconst singleQuotedStringLiteral = (value: string): StringLiteral => ({\n type: 'StringLiteral',\n value,\n extra: {\n rawValue: value,\n raw: `'${value}'`,\n },\n});\n\nexport default class StyledProcessor extends TaggedTemplateProcessor {\n public component: WrappedNode;\n\n #variableIdx = 0;\n\n #variablesCache = new Map<string, string>();\n\n constructor(params: Params, ...args: TailProcessorParams) {\n validateParams(\n params,\n ['tag', ['call', 'member'], ['template', 'call']],\n 'Invalid usage of `styled` tag'\n );\n\n const [tag, tagOp, template] = params;\n\n if (template[0] === 'call') {\n // It is already transformed styled-literal. Skip it.\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw TaggedTemplateProcessor.SKIP;\n }\n\n super([tag, template], ...args);\n\n let component: WrappedNode | undefined;\n if (tagOp[0] === 'call' && tagOp.length === 2) {\n const value = tagOp[1];\n if (value.kind === ValueType.FUNCTION) {\n component = 'FunctionalComponent';\n } else {\n component = {\n node: value.ex,\n source: value.source,\n };\n\n this.dependencies.push(value);\n }\n }\n\n if (tagOp[0] === 'member') {\n [, component] = tagOp;\n }\n\n if (!component) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit = ''\n ): string {\n const id = this.getVariableId(source, unit, precedingCss);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit,\n });\n\n return id;\n }\n\n public override doEvaltimeReplacement(): void {\n this.replacer(this.value, false);\n }\n\n public override doRuntimeReplacement(): void {\n const t = this.astService;\n\n const props = this.getProps();\n\n this.replacer(\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true\n );\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules {\n const rules: Rules = {};\n\n let selector = `.${this.className}`;\n\n // If `styled` wraps another component and not a primitive,\n // get its class name to create a more specific selector\n // it'll ensure that styles are overridden properly\n let value =\n typeof this.component === 'string'\n ? null\n : valueCache.get(this.component.node.name);\n while (hasMeta(value)) {\n selector += `.${value.__linaria.className}`;\n value = value.__linaria.extends;\n }\n\n rules[selector] = {\n cssText,\n className: this.className,\n displayName: this.displayName,\n start: loc?.start ?? null,\n };\n\n return rules;\n }\n\n public override get asSelector(): string {\n return `.${this.className}`;\n }\n\n protected get tagExpressionArgument(): Expression {\n const t = this.astService;\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return t.arrowFunctionExpression([], t.blockStatement([]));\n }\n\n return singleQuotedStringLiteral(this.component);\n }\n\n return t.callExpression(t.identifier(this.component.node.name), []);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tag, [this.tagExpressionArgument]);\n }\n\n public override get value(): ObjectExpression {\n const t = this.astService;\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.node.name;\n\n return t.objectExpression([\n t.objectProperty(\n t.stringLiteral('displayName'),\n t.stringLiteral(this.displayName)\n ),\n t.objectProperty(\n t.stringLiteral('__linaria'),\n t.objectExpression([\n t.objectProperty(\n t.stringLiteral('className'),\n t.stringLiteral(this.className)\n ),\n t.objectProperty(\n t.stringLiteral('extends'),\n extendsNode\n ? t.callExpression(t.identifier(extendsNode), [])\n : t.nullLiteral()\n ),\n ])\n ),\n ]);\n }\n\n public override toString(): string {\n const res = (arg: string) => `${this.tagSourceCode()}(${arg})\\`…\\``;\n\n if (typeof this.component === 'string') {\n if (this.component === 'FunctionalComponent') {\n return res('() => {…}');\n }\n\n return res(`'${this.component}'`);\n }\n\n return res(this.component.source);\n }\n\n protected getCustomVariableId(\n source: string,\n unit: string,\n precedingCss: string\n ) {\n const context = this.getVariableContext(source, unit, precedingCss);\n const customSlugFn = this.options.variableNameSlug;\n if (!customSlugFn) {\n return undefined;\n }\n\n return typeof customSlugFn === 'function'\n ? customSlugFn(context)\n : buildSlug(customSlugFn, context);\n }\n\n protected getProps(): IProps {\n const propsObj: IProps = {\n name: this.displayName,\n class: this.className,\n };\n\n // If we found any interpolations, also pass them, so they can be applied\n if (this.interpolations.length) {\n propsObj.vars = {};\n this.interpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [this.astService.callExpression(node, [])];\n\n if (unit) {\n items.push(this.astService.stringLiteral(unit));\n }\n\n propsObj.vars![id] = items;\n });\n }\n\n return propsObj;\n }\n\n protected getTagComponentProps(props: IProps): ObjectExpression {\n const t = this.astService;\n\n const propExpressions = Object.entries(props)\n .map(([key, value]: [key: string, value: IProps[keyof IProps]]) => {\n if (!value) {\n return null;\n }\n\n const keyNode = t.identifier(key);\n\n if (typeof value === 'string') {\n return t.objectProperty(keyNode, t.stringLiteral(value));\n }\n\n if (typeof value === 'boolean') {\n return t.objectProperty(keyNode, t.booleanLiteral(value));\n }\n\n const vars = Object.entries(value).map(([propName, propValue]) => {\n return t.objectProperty(\n t.stringLiteral(propName),\n t.arrayExpression(propValue)\n );\n });\n\n return t.objectProperty(keyNode, t.objectExpression(vars));\n })\n .filter(isNotNull);\n\n return t.objectExpression(propExpressions);\n }\n\n protected getVariableContext(\n source: string,\n unit: string,\n precedingCss: string\n ): IVariableContext {\n const getIndex = () => {\n // eslint-disable-next-line no-plusplus\n return this.#variableIdx++;\n };\n\n return {\n componentName: this.displayName,\n componentSlug: this.slug,\n get index() {\n return getIndex();\n },\n precedingCss,\n processor: this.constructor.name,\n source,\n unit,\n valueSlug: slugify(source + unit),\n };\n }\n\n protected getVariableId(\n source: string,\n unit: string,\n precedingCss: string\n ): string {\n const value = source + unit;\n if (!this.#variablesCache.has(value)) {\n const id = this.getCustomVariableId(source, unit, precedingCss);\n if (id) {\n return toValidCSSIdentifier(id);\n }\n\n const context = this.getVariableContext(source, unit, precedingCss);\n\n // make the variable unique to this styled component\n this.#variablesCache.set(value, `${this.slug}-${context.index}`);\n }\n\n return this.#variablesCache.get(value)!;\n }\n}\n"],"mappings":";;;;;;;AAeA;;AASA;;AAEA,MAAMA,SAAS,GAAOC,CAAJ,IAA4BA,CAAC,KAAK,IAApD;;AASA,MAAMC,yBAAyB,GAAIC,KAAD,KAAmC;EACnEC,IAAI,EAAE,eAD6D;EAEnED,KAFmE;EAGnEE,KAAK,EAAE;IAC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MAAM,GAAGM,IAAjB;IAVN,CAAP;EAYD;;EAESE,aAAa,CACrBR,MADqB,EAErBM,IAFqB,EAGrBD,YAHqB,EAIb;IACR,MAAM9B,KAAK,GAAGyB,MAAM,GAAGM,IAAvB;;IACA,IAAI,CAAC,KAAK,CAACvB,cAAN,CAAqBiG,GAArB,CAAyBzG,KAAzB,CAAL,EAAsC;MACpC,MAAMgC,EAAE,GAAG,KAAKyC,mBAAL,CAAyBhD,MAAzB,EAAiCM,IAAjC,EAAuCD,YAAvC,CAAX;;MACA,IAAIE,EAAJ,EAAQ;QACN,OAAO,IAAA0E,0BAAA,EAAqB1E,EAArB,CAAP;MACD;;MAED,MAAM0C,OAAO,GAAG,KAAKC,kBAAL,CAAwBlD,MAAxB,EAAgCM,IAAhC,EAAsCD,YAAtC,CAAhB,CANoC,CAQpC;;MACA,KAAK,CAACtB,cAAN,CAAqBmG,GAArB,CAAyB3G,KAAzB,EAAiC,GAAE,KAAKoG,IAAK,IAAG1B,OAAO,CAAC2B,KAAM,EAA9D;IACD;;IAED,OAAO,KAAK,CAAC7F,cAAN,CAAqB4C,GAArB,CAAyBpD,KAAzB,CAAP;EACD;;AArSkE"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linaria/react",
|
|
3
3
|
"description": "Blazing fast zero-runtime CSS in JS library",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.5",
|
|
5
5
|
"bugs": "https://github.com/callstack/linaria/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@emotion/is-prop-valid": "^0.8.8",
|
|
8
|
-
"@linaria/core": "^4.1.
|
|
9
|
-
"@linaria/tags": "^4.1.
|
|
8
|
+
"@linaria/core": "^4.1.4",
|
|
9
|
+
"@linaria/tags": "^4.1.4",
|
|
10
|
+
"@linaria/utils": "^4.2.2",
|
|
10
11
|
"ts-invariant": "^0.10.3"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CallExpression, Expression, ObjectExpression, SourceLocation } from '@babel/types';
|
|
2
|
-
import type { Rules,
|
|
2
|
+
import type { Params, Rules, TailProcessorParams, ValueCache, WrappedNode } from '@linaria/tags';
|
|
3
3
|
import { TaggedTemplateProcessor } from '@linaria/tags';
|
|
4
|
+
import type { IVariableContext } from '@linaria/utils';
|
|
4
5
|
export interface IProps {
|
|
5
6
|
atomic?: boolean;
|
|
6
7
|
class?: string;
|
|
@@ -11,7 +12,7 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
|
|
|
11
12
|
#private;
|
|
12
13
|
component: WrappedNode;
|
|
13
14
|
constructor(params: Params, ...args: TailProcessorParams);
|
|
14
|
-
addInterpolation(node: Expression, source: string, unit?: string): string;
|
|
15
|
+
addInterpolation(node: Expression, precedingCss: string, source: string, unit?: string): string;
|
|
15
16
|
doEvaltimeReplacement(): void;
|
|
16
17
|
doRuntimeReplacement(): void;
|
|
17
18
|
extractRules(valueCache: ValueCache, cssText: string, loc?: SourceLocation | null): Rules;
|
|
@@ -20,7 +21,9 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
|
|
|
20
21
|
protected get tagExpression(): CallExpression;
|
|
21
22
|
get value(): ObjectExpression;
|
|
22
23
|
toString(): string;
|
|
24
|
+
protected getCustomVariableId(source: string, unit: string, precedingCss: string): string | undefined;
|
|
23
25
|
protected getProps(): IProps;
|
|
24
26
|
protected getTagComponentProps(props: IProps): ObjectExpression;
|
|
25
|
-
protected
|
|
27
|
+
protected getVariableContext(source: string, unit: string, precedingCss: string): IVariableContext;
|
|
28
|
+
protected getVariableId(source: string, unit: string, precedingCss: string): string;
|
|
26
29
|
}
|