@linaria/react
Advanced tools
| import BaseProcessor from '@linaria/core/processors/BaseProcessor'; | ||
| export function hasMeta(value) { | ||
| return typeof value === 'object' && value !== null && '__linaria' in value; | ||
| } | ||
| const isNotNull = x => x !== null; | ||
| const singleQuotedStringLiteral = value => ({ | ||
| type: 'StringLiteral', | ||
| value, | ||
| extra: { | ||
| rawValue: value, | ||
| raw: `'${value}'` | ||
| } | ||
| }); | ||
| export default class StyledProcessor extends BaseProcessor { | ||
| constructor(...args) { | ||
| super(...args); | ||
| let component; | ||
| const [type, value, ...rest] = this.params[0] ?? []; | ||
| if (type === 'call' && rest.length === 0) { | ||
| const [source, path] = value; | ||
| if (path.node.type === 'StringLiteral') { | ||
| component = path.node.value; | ||
| } else if (path.node.type === 'ArrowFunctionExpression' || path.node.type === 'FunctionExpression') { | ||
| // Special case when styled wraps a function | ||
| // It's actually the same as wrapping a built-in tag | ||
| component = 'FunctionalComponent'; | ||
| } else { | ||
| component = { | ||
| node: path.node, | ||
| source | ||
| }; | ||
| this.dependencies.push({ | ||
| ex: path, | ||
| source | ||
| }); | ||
| } | ||
| } | ||
| if (type === 'member') { | ||
| if (value.node.type === 'Identifier') { | ||
| component = value.node.name; | ||
| } else if (value.node.type === 'StringLiteral') { | ||
| component = value.node.value; | ||
| } | ||
| } | ||
| if (!component || this.params.length > 1) { | ||
| throw new Error('Invalid usage of `styled` tag'); | ||
| } | ||
| this.component = component; | ||
| } | ||
| addInterpolation(node, source) { | ||
| const id = this.getVariableId(source); | ||
| this.interpolations.push({ | ||
| id, | ||
| node, | ||
| source, | ||
| unit: '' | ||
| }); | ||
| return `var(--${id})`; | ||
| } | ||
| extractRules(valueCache, cssText, loc) { | ||
| const rules = {}; | ||
| let selector = `.${this.className}`; // If `styled` wraps another component and not a primitive, | ||
| // get its class name to create a more specific selector | ||
| // it'll ensure that styles are overridden properly | ||
| let value = typeof this.component === 'string' ? null : valueCache.get(this.component.node); | ||
| while (hasMeta(value)) { | ||
| selector += `.${value.__linaria.className}`; | ||
| value = value.__linaria.extends; | ||
| } | ||
| rules[selector] = { | ||
| cssText, | ||
| className: this.className, | ||
| displayName: this.displayName, | ||
| start: loc?.start ?? null | ||
| }; | ||
| return [rules, this.className]; | ||
| } | ||
| getRuntimeReplacement(classes, uniqInterpolations) { | ||
| const t = this.astService; | ||
| const props = this.getProps(classes, uniqInterpolations); | ||
| return [t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]), true]; | ||
| } | ||
| get asSelector() { | ||
| return `.${this.className}`; | ||
| } | ||
| get tagExpressionArgument() { | ||
| const t = this.astService; | ||
| if (typeof this.component === 'string') { | ||
| if (this.component === 'FunctionalComponent') { | ||
| return t.arrowFunctionExpression([], t.blockStatement([])); | ||
| } | ||
| return singleQuotedStringLiteral(this.component); | ||
| } | ||
| return t.identifier(this.component.source); | ||
| } | ||
| get tagExpression() { | ||
| const t = this.astService; | ||
| return t.callExpression(this.tagExp, [this.tagExpressionArgument]); | ||
| } | ||
| get valueSource() { | ||
| const extendsNode = typeof this.component === 'string' ? null : this.component.source; | ||
| return `{ | ||
| displayName: "${this.displayName}", | ||
| __linaria: { | ||
| className: "${this.className}", | ||
| extends: ${extendsNode} | ||
| } | ||
| }`; | ||
| } | ||
| getProps(classes, uniqInterpolations) { | ||
| const propsObj = { | ||
| name: this.displayName, | ||
| class: this.className | ||
| }; // If we found any interpolations, also pass them, so they can be applied | ||
| if (this.interpolations.length) { | ||
| propsObj.vars = {}; | ||
| uniqInterpolations.forEach(({ | ||
| id, | ||
| unit, | ||
| node | ||
| }) => { | ||
| const items = [node]; | ||
| if (unit) { | ||
| items.push(this.astService.stringLiteral(unit)); | ||
| } | ||
| propsObj.vars[id] = items; | ||
| }); | ||
| } | ||
| return propsObj; | ||
| } | ||
| getTagComponentProps(props) { | ||
| const t = this.astService; | ||
| const propExpressions = Object.entries(props).map(([key, value]) => { | ||
| if (!value) { | ||
| return null; | ||
| } | ||
| const keyNode = t.identifier(key); | ||
| if (typeof value === 'string') { | ||
| return t.objectProperty(keyNode, t.stringLiteral(value)); | ||
| } | ||
| if (typeof value === 'boolean') { | ||
| return t.objectProperty(keyNode, t.booleanLiteral(value)); | ||
| } | ||
| const vars = Object.entries(value).map(([propName, propValue]) => { | ||
| return t.objectProperty(t.stringLiteral(propName), t.arrayExpression(propValue)); | ||
| }); | ||
| return t.objectProperty(keyNode, t.objectExpression(vars)); | ||
| }).filter(isNotNull); | ||
| return t.objectExpression(propExpressions); | ||
| } // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| getVariableId(value) { | ||
| // make the variable unique to this styled component | ||
| return `${this.slug}-${this.interpolations.length}`; | ||
| } | ||
| } | ||
| //# sourceMappingURL=styled.js.map |
| {"version":3,"file":"styled.js","names":["BaseProcessor","hasMeta","value","isNotNull","x","singleQuotedStringLiteral","type","extra","rawValue","raw","StyledProcessor","constructor","args","component","rest","params","length","source","path","node","dependencies","push","ex","name","Error","addInterpolation","id","getVariableId","interpolations","unit","extractRules","valueCache","cssText","loc","rules","selector","className","get","__linaria","extends","displayName","start","getRuntimeReplacement","classes","uniqInterpolations","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","tagExp","valueSource","extendsNode","propsObj","class","vars","forEach","items","stringLiteral","propExpressions","Object","entries","map","key","keyNode","objectProperty","booleanLiteral","propName","propValue","arrayExpression","objectExpression","filter","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 { StyledMeta } from '@linaria/core';\nimport type { ProcessorParams } from '@linaria/core/processors/BaseProcessor';\nimport BaseProcessor from '@linaria/core/processors/BaseProcessor';\nimport type {\n Rules,\n WrappedNode,\n IInterpolation,\n ValueCache,\n} from '@linaria/core/processors/types';\n\nexport function hasMeta(value: unknown): value is StyledMeta {\n return typeof value === 'object' && value !== null && '__linaria' in value;\n}\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 BaseProcessor {\n public component: WrappedNode;\n\n constructor(...args: ProcessorParams) {\n super(...args);\n\n let component: WrappedNode | undefined;\n const [type, value, ...rest] = this.params[0] ?? [];\n if (type === 'call' && rest.length === 0) {\n const [source, path] = value;\n if (path.node.type === 'StringLiteral') {\n component = path.node.value;\n } else if (\n path.node.type === 'ArrowFunctionExpression' ||\n path.node.type === 'FunctionExpression'\n ) {\n // Special case when styled wraps a function\n // It's actually the same as wrapping a built-in tag\n component = 'FunctionalComponent';\n } else {\n component = {\n node: path.node,\n source,\n };\n this.dependencies.push({\n ex: path,\n source,\n });\n }\n }\n\n if (type === 'member') {\n if (value.node.type === 'Identifier') {\n component = value.node.name;\n } else if (value.node.type === 'StringLiteral') {\n component = value.node.value;\n }\n }\n\n if (!component || this.params.length > 1) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(node: Expression, source: string) {\n const id = this.getVariableId(source);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit: '',\n });\n\n return `var(--${id})`;\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\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);\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, this.className];\n }\n\n public override getRuntimeReplacement(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): [Expression, boolean] {\n const t = this.astService;\n\n const props = this.getProps(classes, uniqInterpolations);\n\n return [\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true,\n ];\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.identifier(this.component.source);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tagExp, [this.tagExpressionArgument]);\n }\n\n public override get valueSource(): string {\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.source;\n return `{\n displayName: \"${this.displayName}\",\n __linaria: {\n className: \"${this.className}\",\n extends: ${extendsNode}\n }\n }`;\n }\n\n protected getProps(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): 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 uniqInterpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [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 // make the variable unique to this styled component\n return `${this.slug}-${this.interpolations.length}`;\n }\n}\n"],"mappings":"AAUA,OAAOA,aAAP,MAA0B,wCAA1B;AAQA,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAsD;EAC3D,OAAO,OAAOA,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,KAAK,IAAvC,IAA+C,eAAeA,KAArE;AACD;;AAED,MAAMC,SAAS,GAAOC,CAAJ,IAA4BA,CAAC,KAAK,IAApD;;AASA,MAAMC,yBAAyB,GAAIH,KAAD,KAAmC;EACnEI,IAAI,EAAE,eAD6D;EAEnEJ,KAFmE;EAGnEK,KAAK,EAAE;IACLC,QAAQ,EAAEN,KADL;IAELO,GAAG,EAAG,IAAGP,KAAM;EAFV;AAH4D,CAAnC,CAAlC;;AASA,eAAe,MAAMQ,eAAN,SAA8BV,aAA9B,CAA4C;EAGzDW,WAAW,CAAC,GAAGC,IAAJ,EAA2B;IACpC,MAAM,GAAGA,IAAT;IAEA,IAAIC,SAAJ;IACA,MAAM,CAACP,IAAD,EAAOJ,KAAP,EAAc,GAAGY,IAAjB,IAAyB,KAAKC,MAAL,CAAY,CAAZ,KAAkB,EAAjD;;IACA,IAAIT,IAAI,KAAK,MAAT,IAAmBQ,IAAI,CAACE,MAAL,KAAgB,CAAvC,EAA0C;MACxC,MAAM,CAACC,MAAD,EAASC,IAAT,IAAiBhB,KAAvB;;MACA,IAAIgB,IAAI,CAACC,IAAL,CAAUb,IAAV,KAAmB,eAAvB,EAAwC;QACtCO,SAAS,GAAGK,IAAI,CAACC,IAAL,CAAUjB,KAAtB;MACD,CAFD,MAEO,IACLgB,IAAI,CAACC,IAAL,CAAUb,IAAV,KAAmB,yBAAnB,IACAY,IAAI,CAACC,IAAL,CAAUb,IAAV,KAAmB,oB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
| exports.default = void 0; | ||
| exports.hasMeta = hasMeta; | ||
| var _BaseProcessor = _interopRequireDefault(require("@linaria/core/processors/BaseProcessor")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function hasMeta(value) { | ||
| return typeof value === 'object' && value !== null && '__linaria' in value; | ||
| } | ||
| const isNotNull = x => x !== null; | ||
| const singleQuotedStringLiteral = value => ({ | ||
| type: 'StringLiteral', | ||
| value, | ||
| extra: { | ||
| rawValue: value, | ||
| raw: `'${value}'` | ||
| } | ||
| }); | ||
| class StyledProcessor extends _BaseProcessor.default { | ||
| constructor(...args) { | ||
| var _this$params$; | ||
| super(...args); | ||
| let component; | ||
| const [type, value, ...rest] = (_this$params$ = this.params[0]) !== null && _this$params$ !== void 0 ? _this$params$ : []; | ||
| if (type === 'call' && rest.length === 0) { | ||
| const [source, path] = value; | ||
| if (path.node.type === 'StringLiteral') { | ||
| component = path.node.value; | ||
| } else if (path.node.type === 'ArrowFunctionExpression' || path.node.type === 'FunctionExpression') { | ||
| // Special case when styled wraps a function | ||
| // It's actually the same as wrapping a built-in tag | ||
| component = 'FunctionalComponent'; | ||
| } else { | ||
| component = { | ||
| node: path.node, | ||
| source | ||
| }; | ||
| this.dependencies.push({ | ||
| ex: path, | ||
| source | ||
| }); | ||
| } | ||
| } | ||
| if (type === 'member') { | ||
| if (value.node.type === 'Identifier') { | ||
| component = value.node.name; | ||
| } else if (value.node.type === 'StringLiteral') { | ||
| component = value.node.value; | ||
| } | ||
| } | ||
| if (!component || this.params.length > 1) { | ||
| throw new Error('Invalid usage of `styled` tag'); | ||
| } | ||
| this.component = component; | ||
| } | ||
| addInterpolation(node, source) { | ||
| const id = this.getVariableId(source); | ||
| this.interpolations.push({ | ||
| id, | ||
| node, | ||
| source, | ||
| unit: '' | ||
| }); | ||
| return `var(--${id})`; | ||
| } | ||
| extractRules(valueCache, cssText, loc) { | ||
| var _loc$start; | ||
| const rules = {}; | ||
| let selector = `.${this.className}`; // If `styled` wraps another component and not a primitive, | ||
| // get its class name to create a more specific selector | ||
| // it'll ensure that styles are overridden properly | ||
| let value = typeof this.component === 'string' ? null : valueCache.get(this.component.node); | ||
| while (hasMeta(value)) { | ||
| selector += `.${value.__linaria.className}`; | ||
| value = value.__linaria.extends; | ||
| } | ||
| rules[selector] = { | ||
| cssText, | ||
| className: this.className, | ||
| displayName: this.displayName, | ||
| start: (_loc$start = loc === null || loc === void 0 ? void 0 : loc.start) !== null && _loc$start !== void 0 ? _loc$start : null | ||
| }; | ||
| return [rules, this.className]; | ||
| } | ||
| getRuntimeReplacement(classes, uniqInterpolations) { | ||
| const t = this.astService; | ||
| const props = this.getProps(classes, uniqInterpolations); | ||
| return [t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]), true]; | ||
| } | ||
| get asSelector() { | ||
| return `.${this.className}`; | ||
| } | ||
| get tagExpressionArgument() { | ||
| const t = this.astService; | ||
| if (typeof this.component === 'string') { | ||
| if (this.component === 'FunctionalComponent') { | ||
| return t.arrowFunctionExpression([], t.blockStatement([])); | ||
| } | ||
| return singleQuotedStringLiteral(this.component); | ||
| } | ||
| return t.identifier(this.component.source); | ||
| } | ||
| get tagExpression() { | ||
| const t = this.astService; | ||
| return t.callExpression(this.tagExp, [this.tagExpressionArgument]); | ||
| } | ||
| get valueSource() { | ||
| const extendsNode = typeof this.component === 'string' ? null : this.component.source; | ||
| return `{ | ||
| displayName: "${this.displayName}", | ||
| __linaria: { | ||
| className: "${this.className}", | ||
| extends: ${extendsNode} | ||
| } | ||
| }`; | ||
| } | ||
| getProps(classes, uniqInterpolations) { | ||
| const propsObj = { | ||
| name: this.displayName, | ||
| class: this.className | ||
| }; // If we found any interpolations, also pass them, so they can be applied | ||
| if (this.interpolations.length) { | ||
| propsObj.vars = {}; | ||
| uniqInterpolations.forEach(({ | ||
| id, | ||
| unit, | ||
| node | ||
| }) => { | ||
| const items = [node]; | ||
| if (unit) { | ||
| items.push(this.astService.stringLiteral(unit)); | ||
| } | ||
| propsObj.vars[id] = items; | ||
| }); | ||
| } | ||
| return propsObj; | ||
| } | ||
| getTagComponentProps(props) { | ||
| const t = this.astService; | ||
| const propExpressions = Object.entries(props).map(([key, value]) => { | ||
| if (!value) { | ||
| return null; | ||
| } | ||
| const keyNode = t.identifier(key); | ||
| if (typeof value === 'string') { | ||
| return t.objectProperty(keyNode, t.stringLiteral(value)); | ||
| } | ||
| if (typeof value === 'boolean') { | ||
| return t.objectProperty(keyNode, t.booleanLiteral(value)); | ||
| } | ||
| const vars = Object.entries(value).map(([propName, propValue]) => { | ||
| return t.objectProperty(t.stringLiteral(propName), t.arrayExpression(propValue)); | ||
| }); | ||
| return t.objectProperty(keyNode, t.objectExpression(vars)); | ||
| }).filter(isNotNull); | ||
| return t.objectExpression(propExpressions); | ||
| } // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| getVariableId(value) { | ||
| // make the variable unique to this styled component | ||
| return `${this.slug}-${this.interpolations.length}`; | ||
| } | ||
| } | ||
| exports.default = StyledProcessor; | ||
| //# sourceMappingURL=styled.js.map |
| {"version":3,"file":"styled.js","names":["hasMeta","value","isNotNull","x","singleQuotedStringLiteral","type","extra","rawValue","raw","StyledProcessor","BaseProcessor","constructor","args","component","rest","params","length","source","path","node","dependencies","push","ex","name","Error","addInterpolation","id","getVariableId","interpolations","unit","extractRules","valueCache","cssText","loc","rules","selector","className","get","__linaria","extends","displayName","start","getRuntimeReplacement","classes","uniqInterpolations","t","astService","props","getProps","callExpression","tagExpression","getTagComponentProps","asSelector","tagExpressionArgument","arrowFunctionExpression","blockStatement","identifier","tagExp","valueSource","extendsNode","propsObj","class","vars","forEach","items","stringLiteral","propExpressions","Object","entries","map","key","keyNode","objectProperty","booleanLiteral","propName","propValue","arrayExpression","objectExpression","filter","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 { StyledMeta } from '@linaria/core';\nimport type { ProcessorParams } from '@linaria/core/processors/BaseProcessor';\nimport BaseProcessor from '@linaria/core/processors/BaseProcessor';\nimport type {\n Rules,\n WrappedNode,\n IInterpolation,\n ValueCache,\n} from '@linaria/core/processors/types';\n\nexport function hasMeta(value: unknown): value is StyledMeta {\n return typeof value === 'object' && value !== null && '__linaria' in value;\n}\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 BaseProcessor {\n public component: WrappedNode;\n\n constructor(...args: ProcessorParams) {\n super(...args);\n\n let component: WrappedNode | undefined;\n const [type, value, ...rest] = this.params[0] ?? [];\n if (type === 'call' && rest.length === 0) {\n const [source, path] = value;\n if (path.node.type === 'StringLiteral') {\n component = path.node.value;\n } else if (\n path.node.type === 'ArrowFunctionExpression' ||\n path.node.type === 'FunctionExpression'\n ) {\n // Special case when styled wraps a function\n // It's actually the same as wrapping a built-in tag\n component = 'FunctionalComponent';\n } else {\n component = {\n node: path.node,\n source,\n };\n this.dependencies.push({\n ex: path,\n source,\n });\n }\n }\n\n if (type === 'member') {\n if (value.node.type === 'Identifier') {\n component = value.node.name;\n } else if (value.node.type === 'StringLiteral') {\n component = value.node.value;\n }\n }\n\n if (!component || this.params.length > 1) {\n throw new Error('Invalid usage of `styled` tag');\n }\n\n this.component = component;\n }\n\n public override addInterpolation(node: Expression, source: string) {\n const id = this.getVariableId(source);\n\n this.interpolations.push({\n id,\n node,\n source,\n unit: '',\n });\n\n return `var(--${id})`;\n }\n\n public override extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): [Rules, string] {\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);\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, this.className];\n }\n\n public override getRuntimeReplacement(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): [Expression, boolean] {\n const t = this.astService;\n\n const props = this.getProps(classes, uniqInterpolations);\n\n return [\n t.callExpression(this.tagExpression, [this.getTagComponentProps(props)]),\n true,\n ];\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.identifier(this.component.source);\n }\n\n protected get tagExpression(): CallExpression {\n const t = this.astService;\n return t.callExpression(this.tagExp, [this.tagExpressionArgument]);\n }\n\n public override get valueSource(): string {\n const extendsNode =\n typeof this.component === 'string' ? null : this.component.source;\n return `{\n displayName: \"${this.displayName}\",\n __linaria: {\n className: \"${this.className}\",\n extends: ${extendsNode}\n }\n }`;\n }\n\n protected getProps(\n classes: string,\n uniqInterpolations: IInterpolation[]\n ): 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 uniqInterpolations.forEach(({ id, unit, node }) => {\n const items: Expression[] = [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 // make the variable unique to this styled component\n return `${this.slug}-${this.interpolations.length}`;\n }\n}\n"],"mappings":";;;;;;;;AAUA;;;;AAQO,SAASA,OAAT,CAAiBC,KAAjB,EAAsD;EAC3D,OAAO,OAAOA,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,KAAK,IAAvC,IAA+C,eAAeA,KAArE;AACD;;AAED,MAAMC,SAAS,GAAOC,CAAJ,IAA4BA,CAAC,KAAK,IAApD;;AASA,MAAMC,yBAAyB,GAAIH,KAAD,KAAmC;EACnEI,IAAI,EAAE,eAD6D;EAEnEJ,KAFmE;EAGnEK,KAAK,EAAE;IACLC,QAAQ,EAAEN,KADL;IAELO,GAAG,EAAG,IAAGP,KAAM;EAFV;AAH4D,CAAnC,CAAlC;;AASe,MAAMQ,eAAN,SAA8BC,sBAA9B,CAA4C;EAGzDC,WAAW,CAAC,GAAGC,IAAJ,EAA2B;IAAA;;IACpC,MAAM,GAAGA,IAAT;IAEA,IAAIC,SAAJ;IACA,MAAM,CAACR,IAAD,EAAOJ,KAAP,EAAc,GAAGa,IAAjB,qBAAyB,KAAKC,MAAL,CAAY,CAAZ,CAAzB,yDAA2C,EAAjD;;IACA,IAAIV,IAAI,KAAK,MAAT,IAAmBS,IAAI,CAACE,MAAL,KAAgB,CAAvC,EAA0C;MACxC,MAAM,CAACC,MAAD,EAASC,IAAT,IAAiBjB,KAAvB;;MACA,IAAIiB,I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AAO2C,CAAC,CAACgC,gBAAF,CAAmBX,eAAnB,CAAP;EACD,CAnMwD,CAqMzD;;;EACUvC,aAAa,CAAC1B,KAAD,EAAwB;IAC7C;IACA,OAAQ,GAAE,KAAK8E,IAAK,IAAG,KAAKnD,cAAL,CAAoBZ,MAAO,EAAlD;EACD;;AAzMwD"} |
| import type { CallExpression, Expression, ObjectExpression, SourceLocation } from '@babel/types'; | ||
| import type { StyledMeta } from '@linaria/core'; | ||
| import type { ProcessorParams } from '@linaria/core/processors/BaseProcessor'; | ||
| import BaseProcessor from '@linaria/core/processors/BaseProcessor'; | ||
| import type { Rules, WrappedNode, IInterpolation, ValueCache } from '@linaria/core/processors/types'; | ||
| export declare function hasMeta(value: unknown): value is StyledMeta; | ||
| export interface IProps { | ||
| atomic?: boolean; | ||
| class?: string; | ||
| name: string; | ||
| vars?: Record<string, Expression[]>; | ||
| } | ||
| export default class StyledProcessor extends BaseProcessor { | ||
| component: WrappedNode; | ||
| constructor(...args: ProcessorParams); | ||
| addInterpolation(node: Expression, source: string): string; | ||
| extractRules(valueCache: ValueCache, cssText: string, loc?: SourceLocation | null): [Rules, string]; | ||
| getRuntimeReplacement(classes: string, uniqInterpolations: IInterpolation[]): [Expression, boolean]; | ||
| get asSelector(): string; | ||
| protected get tagExpressionArgument(): Expression; | ||
| protected get tagExpression(): CallExpression; | ||
| get valueSource(): string; | ||
| protected getProps(classes: string, uniqInterpolations: IInterpolation[]): IProps; | ||
| protected getTagComponentProps(props: IProps): ObjectExpression; | ||
| protected getVariableId(value: string): string; | ||
| } |
+18
-0
@@ -6,2 +6,20 @@ # Change Log | ||
| # [3.0.0-beta.19](https://github.com/callstack/linaria/compare/v3.0.0-beta.18...v3.0.0-beta.19) (2022-06-03) | ||
| ### Bug Fixes | ||
| * **react:** support UpperCamelCase custom elements [#968](https://github.com/callstack/linaria/issues/968) ([#970](https://github.com/callstack/linaria/issues/970)) ([59800db](https://github.com/callstack/linaria/commit/59800dba540e09c0c43b1f0ec1d4b2c46d8a4672)) | ||
| ### Features | ||
| * **atomic:** add support for atomic using styled API ([#966](https://github.com/callstack/linaria/issues/966)) ([f59860b](https://github.com/callstack/linaria/commit/f59860b09c5f91b0423dbf188e5f8aaaef38a6b5)) | ||
| * **babel:** api for custom tags ([#976](https://github.com/callstack/linaria/issues/976)) ([3285ccc](https://github.com/callstack/linaria/commit/3285ccc1d00449b78b3fc74087528cd38cbdd116)) | ||
| * **babel:** new way for detecting tag imports ([#974](https://github.com/callstack/linaria/issues/974)) ([3305cfb](https://github.com/callstack/linaria/commit/3305cfb0c0f65abdacceeb7e6bad118c59f7d551)) | ||
| # [3.0.0-beta.18](https://github.com/callstack/linaria/compare/v3.0.0-beta.17...v3.0.0-beta.18) (2022-04-01) | ||
@@ -8,0 +26,0 @@ |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":["default","styled"],"mappings":"AAAA,SAASA,OAAO,IAAIC,MAApB,QAAkC,UAAlC","sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"file":"index.js"} | ||
| {"version":3,"file":"index.js","names":["default","styled"],"sources":["../src/index.ts"],"sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,MAApB,QAAkC,UAAlC"} |
+31
-30
@@ -0,1 +1,3 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /** | ||
@@ -7,22 +9,36 @@ * This file contains an runtime version of `styled` component. Responsibilities of the component are: | ||
| */ | ||
| import validAttr from '@emotion/is-prop-valid'; | ||
| import React from 'react'; | ||
| import validAttr from '@emotion/is-prop-valid'; | ||
| import { cx } from '@linaria/core'; | ||
| // Workaround for rest operator | ||
| export const restOp = (obj, keys) => { | ||
| const res = {}; | ||
| let key; | ||
| for (key in obj) { | ||
| if (keys.indexOf(key) === -1) { | ||
| res[key] = obj[key]; | ||
| } | ||
| } | ||
| const isCapital = ch => ch.toUpperCase() === ch; | ||
| const filterKey = keys => key => keys.indexOf(key) === -1; | ||
| export const omit = (obj, keys) => { | ||
| const res = {}; | ||
| Object.keys(obj).filter(filterKey(keys)).forEach(key => { | ||
| res[key] = obj[key]; | ||
| }); | ||
| return res; | ||
| }; | ||
| function filterProps(component, props, omitKeys) { | ||
| const filteredProps = omit(props, omitKeys); // Check if it's an HTML tag and not a custom element | ||
| if (typeof component === 'string' && component.indexOf('-') === -1 && !isCapital(component[0])) { | ||
| Object.keys(filteredProps).forEach(key => { | ||
| if (!validAttr(key)) { | ||
| // Don't pass through invalid attributes to HTML elements | ||
| delete filteredProps[key]; | ||
| } | ||
| }); | ||
| } | ||
| return filteredProps; | ||
| } | ||
| const warnIfInvalid = (value, componentName) => { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| if (typeof value === 'string' || // eslint-disable-next-line no-self-compare | ||
| if (typeof value === 'string' || // eslint-disable-next-line no-self-compare,no-restricted-globals | ||
| typeof value === 'number' && isFinite(value)) { | ||
@@ -52,20 +68,5 @@ return; | ||
| } = props; | ||
| const rest = restOp(props, ['as', 'class']); | ||
| let filteredProps; // Check if it's an HTML tag and not a custom element | ||
| if (typeof component === 'string' && component.indexOf('-') === -1) { | ||
| filteredProps = {}; // eslint-disable-next-line guard-for-in | ||
| for (const key in rest) { | ||
| if (key === 'as' || validAttr(key)) { | ||
| // Don't pass through invalid attributes to HTML elements | ||
| filteredProps[key] = rest[key]; | ||
| } | ||
| } | ||
| } else { | ||
| filteredProps = rest; | ||
| } | ||
| const filteredProps = filterProps(component, props, ['as', 'class']); | ||
| filteredProps.ref = ref; | ||
| filteredProps.className = cx(filteredProps.className || className, options.class); | ||
| filteredProps.className = options.atomic ? cx(options.class, filteredProps.className || className) : cx(filteredProps.className || className, options.class); | ||
| const { | ||
@@ -76,3 +77,3 @@ vars | ||
| if (vars) { | ||
| const style = {}; // eslint-disable-next-line guard-for-in | ||
| const style = {}; // eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
@@ -113,3 +114,3 @@ for (const name in vars) { | ||
| props => { | ||
| const rest = restOp(props, ['innerRef']); | ||
| const rest = omit(props, ['innerRef']); | ||
| return render(rest, props.innerRef); | ||
@@ -116,0 +117,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","restOp","obj","keys","res","key","indexOf","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","class","className","rest","filteredProps","vars","style","name","variable","result","unit","ownStyle","Object","length","forEach","__linaria","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o","prop"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AACA,SAASC,EAAT,QAAmB,eAAnB;AAsBA;AACA,OAAO,MAAMC,MAAM,GAAG,CACpBC,GADoB,EAEpBC,IAFoB,KAGjB;AACH,QAAMC,GAAG,GAAG,EAAZ;AACA,MAAIC,GAAJ;;AACA,OAAKA,GAAL,IAAYH,GAAZ,EAAiB;AACf,QAAIC,IAAI,CAACG,OAAL,CAAaD,GAAb,MAAsB,CAAC,CAA3B,EAA8B;AAC5BD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAWH,GAAG,CAACG,GAAD,CAAd;AACD;AACF;;AACD,SAAOD,GAAP;AACD,CAZM;;AAcP,MAAMG,aAAa,GAAG,CAACC,KAAD,EAAaC,aAAb,KAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,OAAOJ,KAAP,KAAiB,QAAjB,IACA;AACC,WAAOA,KAAP,KAAiB,QAAjB,IAA6BK,QAAQ,CAACL,KAAD,CAHxC,EAIE;AACA;AACD;;AAED,UAAMM,WAAW,GACf,OAAON,KAAP,KAAiB,QA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AAnB;AAEA,4BAAOhC,KAAK,CAACgD,aAAN,CAAoBzB,GAApB,EAAyBa,aAAzB,CAAP;AACD;;AACD,0BAAOpC,KAAK,CAACgD,aAAN,CAAoBhB,SAApB,EAA+BI,aAA/B,CAAP;AACD,KA9DD;;AAgEA,UAAMa,MAAM,GAAGjD,KAAK,CAACkD,UAAN,gBACXlD,KAAK,CAACkD,UAAN,CAAiBtB,MAAjB,CADW,GAEX;AACA;AACCC,IAAAA,KAAD,IAAgB;AACd,YAAMM,IAAI,GAAGhC,MAAM,CAAC0B,KAAD,EAAQ,CAAC,UAAD,CAAR,CAAnB;AACA,aAAOD,MAAM,CAACO,IAAD,EAAON,KAAK,CAACsB,QAAb,CAAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B5B,OAAO,CAACe,IAAtC,CAnF2B,CAqF3B;;AACCU,IAAAA,MAAD,CAAgBF,SAAhB,GAA4B;AAC1Bb,MAAAA,SAAS,EAAEV,OAAO,CAACS,KADO;AAE1BoB,MAAAA,OAAO,EAAE9B;AAFiB,KAA5B;AAKA,WAAO0B,MAAP;AACD,GA5FD;AA6FD;;AA+CD,eAAgBrC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIwC,KAAJ,CAAUhC,MAAV,EAAkB;AAChBiC,EAAAA,GAAG,CAACC,CAAD,EAAIC,IAAJ,EAAuC;AACxC,WAAOD,CAAC,CAACC,IAAD,CAAR;AACD;;AAHe,CAAlB,CADY,GAMZnC,MANJ","sourcesContent":["/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\n// Workaround for rest operator\nexport const restOp = <T extends object, TKeys extends [...(keyof T)[]]>(\n obj: T,\n keys: TKeys\n) => {\n const res = {} as { [K in keyof T]: T[K] };\n let key: keyof typeof obj;\n for (key in obj) {\n if (keys.indexOf(key) === -1) {\n res[key] = obj[key];\n }\n }\n return res;\n};\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps: IProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"} | ||
| {"version":3,"file":"styled.js","names":["validAttr","React","cx","isCapital","ch","toUpperCase","filterKey","keys","key","indexOf","omit","obj","res","Object","filter","forEach","filterProps","component","props","omitKeys","filteredProps","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","ref","as","class","className","atomic","vars","style","name","variable","result","unit","ownStyle","length","__linaria","createElement","Result","forwardRef","rest","innerRef","displayName","extends","Proxy","get","o","prop"],"sources":["../src/styled.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport validAttr from '@emotion/is-prop-valid';\nimport React from 'react';\n\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A> = [A][A extends any ? 0 : never];\n\ntype Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n atomic?: boolean;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\nconst isCapital = (ch: string): boolean => ch.toUpperCase() === ch;\nconst filterKey =\n <TExclude extends keyof any>(keys: TExclude[]) =>\n <TAll extends keyof any>(key: TAll): key is Exclude<TAll, TExclude> =>\n keys.indexOf(key as any) === -1;\n\nexport const omit = <T extends Record<string, unknown>, TKeys extends keyof T>(\n obj: T,\n keys: TKeys[]\n): Omit<T, TKeys> => {\n const res = {} as Omit<T, TKeys>;\n Object.keys(obj)\n .filter(filterKey(keys))\n .forEach((key) => {\n res[key] = obj[key];\n });\n\n return res;\n};\n\nfunction filterProps<T extends Record<string, unknown>, TKeys extends keyof T>(\n component: string | unknown,\n props: T,\n omitKeys: TKeys[]\n): Partial<Omit<T, TKeys>> {\n const filteredProps = omit(props, omitKeys) as Partial<T>;\n\n // Check if it's an HTML tag and not a custom element\n if (\n typeof component === 'string' &&\n component.indexOf('-') === -1 &&\n !isCapital(component[0])\n ) {\n Object.keys(filteredProps).forEach((key) => {\n if (!validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n delete filteredProps[key];\n }\n });\n }\n\n return filteredProps;\n}\n\nconst warnIfInvalid = (value: unknown, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare,no-restricted-globals\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const filteredProps: IProps = filterProps(component, props, [\n 'as',\n 'class',\n ]);\n\n filteredProps.ref = ref;\n filteredProps.className = options.atomic\n ? cx(options.class, filteredProps.className || className)\n : cx(filteredProps.className || className, options.class);\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = omit(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = Record<string, unknown>\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <\n OwnProps = Record<string, unknown>\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,wBAAtB;AACA,OAAOC,KAAP,MAAkB,OAAlB;AAEA,SAASC,EAAT,QAAmB,eAAnB;;AAuBA,MAAMC,SAAS,GAAIC,EAAD,IAAyBA,EAAE,CAACC,WAAH,OAAqBD,EAAhE;;AACA,MAAME,SAAS,GACgBC,IAA7B,IACyBC,GAAzB,IACED,IAAI,CAACE,OAAL,CAAaD,GAAb,MAA6B,CAAC,CAHlC;;AAKA,OAAO,MAAME,IAAI,GAAG,CAClBC,GADkB,EAElBJ,IAFkB,KAGC;EACnB,MAAMK,GAAG,GAAG,EAAZ;EACAC,MAAM,CAACN,IAAP,CAAYI,GAAZ,EACGG,MADH,CACUR,SAAS,CAACC,IAAD,CADnB,EAEGQ,OAFH,CAEYP,GAAD,IAAS;IAChBI,GAAG,CAACJ,GAAD,CAAH,GAAWG,GAAG,CAACH,GAAD,CAAd;EACD,CAJH;EAMA,OAAOI,GAAP;AACD,CAZM;;AAcP,SAASI,WAAT,CACEC,SADF,EAEEC,KAFF,EAGEC,QAHF,EAI2B;EACzB,MAAMC,aAAa,GAAGV,IA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"} |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA","sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"file":"index.js"} | ||
| {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"mappings":";;;;;AAAA"} |
+56
-52
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.default = exports.restOp = void 0; | ||
| exports.omit = exports.default = void 0; | ||
| var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid")); | ||
| var _react = _interopRequireDefault(require("react")); | ||
| var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid")); | ||
| var _core = require("@linaria/core"); | ||
@@ -14,2 +14,4 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /** | ||
@@ -21,21 +23,34 @@ * This file contains an runtime version of `styled` component. Responsibilities of the component are: | ||
| */ | ||
| // Workaround for rest operator | ||
| var restOp = function restOp(obj, keys) { | ||
| var res = {}; | ||
| var key; | ||
| const isCapital = ch => ch.toUpperCase() === ch; | ||
| for (key in obj) { | ||
| if (keys.indexOf(key) === -1) { | ||
| res[key] = obj[key]; | ||
| } | ||
| } | ||
| const filterKey = keys => key => keys.indexOf(key) === -1; | ||
| const omit = (obj, keys) => { | ||
| const res = {}; | ||
| Object.keys(obj).filter(filterKey(keys)).forEach(key => { | ||
| res[key] = obj[key]; | ||
| }); | ||
| return res; | ||
| }; | ||
| exports.restOp = restOp; | ||
| exports.omit = omit; | ||
| var warnIfInvalid = function warnIfInvalid(value, componentName) { | ||
| function filterProps(component, props, omitKeys) { | ||
| const filteredProps = omit(props, omitKeys); // Check if it's an HTML tag and not a custom element | ||
| if (typeof component === 'string' && component.indexOf('-') === -1 && !isCapital(component[0])) { | ||
| Object.keys(filteredProps).forEach(key => { | ||
| if (!(0, _isPropValid.default)(key)) { | ||
| // Don't pass through invalid attributes to HTML elements | ||
| delete filteredProps[key]; | ||
| } | ||
| }); | ||
| } | ||
| return filteredProps; | ||
| } | ||
| const warnIfInvalid = (value, componentName) => { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| if (typeof value === 'string' || // eslint-disable-next-line no-self-compare | ||
| if (typeof value === 'string' || // eslint-disable-next-line no-self-compare,no-restricted-globals | ||
| typeof value === 'number' && isFinite(value)) { | ||
@@ -45,3 +60,3 @@ return; | ||
| var stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console | ||
| const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console | ||
@@ -53,3 +68,3 @@ console.warn("An interpolation evaluated to '" + stringified + "' in the component '" + componentName + "', which is probably a mistake. You should explicitly cast or transform the value to a string."); | ||
| function styled(tag) { | ||
| return function (options) { | ||
| return options => { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
@@ -62,34 +77,22 @@ if (Array.isArray(options)) { | ||
| var render = function render(props, ref) { | ||
| var _props$as = props.as, | ||
| component = _props$as === void 0 ? tag : _props$as, | ||
| className = props.class; | ||
| var rest = restOp(props, ['as', 'class']); | ||
| var filteredProps; // Check if it's an HTML tag and not a custom element | ||
| if (typeof component === 'string' && component.indexOf('-') === -1) { | ||
| filteredProps = {}; // eslint-disable-next-line guard-for-in | ||
| for (var _key in rest) { | ||
| if (_key === 'as' || (0, _isPropValid.default)(_key)) { | ||
| // Don't pass through invalid attributes to HTML elements | ||
| filteredProps[_key] = rest[_key]; | ||
| } | ||
| } | ||
| } else { | ||
| filteredProps = rest; | ||
| } | ||
| const render = (props, ref) => { | ||
| const { | ||
| as: component = tag, | ||
| class: className | ||
| } = props; | ||
| const filteredProps = filterProps(component, props, ['as', 'class']); | ||
| filteredProps.ref = ref; | ||
| filteredProps.className = (0, _core.cx)(filteredProps.className || className, options.class); | ||
| var vars = options.vars; | ||
| filteredProps.className = options.atomic ? (0, _core.cx)(options.class, filteredProps.className || className) : (0, _core.cx)(filteredProps.className || className, options.class); | ||
| const { | ||
| vars | ||
| } = options; | ||
| if (vars) { | ||
| var style = {}; // eslint-disable-next-line guard-for-in | ||
| const style = {}; // eslint-disable-next-line guard-for-in,no-restricted-syntax | ||
| for (var name in vars) { | ||
| var variable = vars[name]; | ||
| var result = variable[0]; | ||
| var unit = variable[1] || ''; | ||
| var value = typeof result === 'function' ? result(props) : result; | ||
| for (const name in vars) { | ||
| const variable = vars[name]; | ||
| const result = variable[0]; | ||
| const unit = variable[1] || ''; | ||
| const value = typeof result === 'function' ? result(props) : result; | ||
| warnIfInvalid(value, options.name); | ||
@@ -99,7 +102,7 @@ style["--" + name] = "" + value + unit; | ||
| var ownStyle = filteredProps.style || {}; | ||
| var keys = Object.keys(ownStyle); | ||
| const ownStyle = filteredProps.style || {}; | ||
| const keys = Object.keys(ownStyle); | ||
| if (keys.length > 0) { | ||
| keys.forEach(function (key) { | ||
| keys.forEach(key => { | ||
| style[key] = ownStyle[key]; | ||
@@ -122,6 +125,6 @@ }); | ||
| var Result = _react.default.forwardRef ? /*#__PURE__*/_react.default.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact | ||
| const Result = _react.default.forwardRef ? /*#__PURE__*/_react.default.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact | ||
| // Fallback to a innerRef prop in that case | ||
| function (props) { | ||
| var rest = restOp(props, ['innerRef']); | ||
| props => { | ||
| const rest = omit(props, ['innerRef']); | ||
| return render(rest, props.innerRef); | ||
@@ -140,5 +143,6 @@ }; | ||
| var _default = process.env.NODE_ENV !== 'production' ? new Proxy(styled, { | ||
| get: function get(o, prop) { | ||
| get(o, prop) { | ||
| return o(prop); | ||
| } | ||
| }) : styled; | ||
@@ -145,0 +149,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["restOp","obj","keys","res","key","indexOf","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","className","class","rest","filteredProps","vars","style","name","variable","result","unit","ownStyle","Object","length","forEach","__linaria","React","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o","prop"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;AARA;AACA;AACA;AACA;AACA;AACA;AAyBA;AACO,IAAMA,MAAM,GAAG,SAATA,MAAS,CACpBC,GADoB,EAEpBC,IAFoB,EAGjB;AACH,MAAMC,GAAG,GAAG,EAAZ;AACA,MAAIC,GAAJ;;AACA,OAAKA,GAAL,IAAYH,GAAZ,EAAiB;AACf,QAAIC,IAAI,CAACG,OAAL,CAAaD,GAAb,MAAsB,CAAC,CAA3B,EAA8B;AAC5BD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAWH,GAAG,CAACG,GAAD,CAAd;AACD;AACF;;AACD,SAAOD,GAAP;AACD,CAZM;;;;AAcP,IAAMG,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAaC,aAAb,EAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,OAAOJ,KAAP,KAAiB,QAAjB,IACA;AACC,WAAOA,KAAP,KAAiB,QAAjB,IAA6BK,QAAQ,CAACL,KAAD,CAHxC,EAIE;AACA;AACD;;AAED,QAAMM,WAAW,GACf,OAAON,KAAP,KAAiB,QAAjB,GAA4BO,IAAI,CAACC,SAAL,CAAeR,KAAf,CAA5B,GAAoDS,MAAM,CAACT,KAAD,CAD5D,CATyC,CAYzC;;AACAU,IAAAA,OAAO,CAACC,IAAR,qCACoCL,WADpC,4BACsEL,aADtE;AAGD;AACF,CAlBD;;AAgDA,SAASW,MAAT,CAAgBC,GAAhB,EAA+B;AAC7B,SAAO,UAACC,OAAD,EAAsB;AAC3B,QAAIZ,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,UAAIW,KAAK,C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MAAM,CAACO,IAAD,EAAON,KAAK,CAACuB,QAAb,CAAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B7B,OAAO,CAACe,IAAtC,CAnF2B,CAqF3B;;AACCW,IAAAA,MAAD,CAAgBH,SAAhB,GAA4B;AAC1Bd,MAAAA,SAAS,EAAET,OAAO,CAACU,KADO;AAE1BoB,MAAAA,OAAO,EAAE/B;AAFiB,KAA5B;AAKA,WAAO2B,MAAP;AACD,GA5FD;AA6FD;;eA+CetC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIyC,KAAJ,CAAUjC,MAAV,EAAkB;AAChBkC,EAAAA,GADgB,eACZC,CADY,EACTC,IADS,EAC0B;AACxC,WAAOD,CAAC,CAACC,IAAD,CAAR;AACD;AAHe,CAAlB,CADY,GAMZpC,M","sourcesContent":["/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\n// Workaround for rest operator\nexport const restOp = <T extends object, TKeys extends [...(keyof T)[]]>(\n obj: T,\n keys: TKeys\n) => {\n const res = {} as { [K in keyof T]: T[K] };\n let key: keyof typeof obj;\n for (key in obj) {\n if (keys.indexOf(key) === -1) {\n res[key] = obj[key];\n }\n }\n return res;\n};\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps: IProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"} | ||
| {"version":3,"file":"styled.js","names":["isCapital","ch","toUpperCase","filterKey","keys","key","indexOf","omit","obj","res","Object","filter","forEach","filterProps","component","props","omitKeys","filteredProps","validAttr","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","ref","as","class","className","atomic","cx","vars","style","name","variable","result","unit","ownStyle","length","__linaria","React","createElement","Result","forwardRef","rest","innerRef","displayName","extends","Proxy","get","o","prop"],"sources":["../src/styled.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport validAttr from '@emotion/is-prop-valid';\nimport React from 'react';\n\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A> = [A][A extends any ? 0 : never];\n\ntype Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n atomic?: boolean;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\nconst isCapital = (ch: string): boolean => ch.toUpperCase() === ch;\nconst filterKey =\n <TExclude extends keyof any>(keys: TExclude[]) =>\n <TAll extends keyof any>(key: TAll): key is Exclude<TAll, TExclude> =>\n keys.indexOf(key as any) === -1;\n\nexport const omit = <T extends Record<string, unknown>, TKeys extends keyof T>(\n obj: T,\n keys: TKeys[]\n): Omit<T, TKeys> => {\n const res = {} as Omit<T, TKeys>;\n Object.keys(obj)\n .filter(filterKey(keys))\n .forEach((key) => {\n res[key] = obj[key];\n });\n\n return res;\n};\n\nfunction filterProps<T extends Record<string, unknown>, TKeys extends keyof T>(\n component: string | unknown,\n props: T,\n omitKeys: TKeys[]\n): Partial<Omit<T, TKeys>> {\n const filteredProps = omit(props, omitKeys) as Partial<T>;\n\n // Check if it's an HTML tag and not a custom element\n if (\n typeof component === 'string' &&\n component.indexOf('-') === -1 &&\n !isCapital(component[0])\n ) {\n Object.keys(filteredProps).forEach((key) => {\n if (!validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n delete filteredProps[key];\n }\n });\n }\n\n return filteredProps;\n}\n\nconst warnIfInvalid = (value: unknown, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare,no-restricted-globals\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const filteredProps: IProps = filterProps(component, props, [\n 'as',\n 'class',\n ]);\n\n filteredProps.ref = ref;\n filteredProps.className = options.atomic\n ? cx(options.class, filteredProps.className || className)\n : cx(filteredProps.className || className, options.class);\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = omit(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = Record<string, unknown>\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <\n OwnProps = Record<string, unknown>\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"mappings":";;;;;AAOA;;AACA;;AAEA;;;;AAVA;;AACA;AACA;AACA;AACA;AACA;AACA;AA2BA,MAAMA,SAAS,GAAIC,EAAD,IAAyBA,EAAE,CAACC,WAAH,OAAqBD,EAAhE;;AACA,MAAME,SAAS,GACgBC,IAA7B,IACyBC,GAAzB,IACED,IAAI,CAACE,OAAL,CAAaD,GAAb,MAA6B,CAAC,CAHlC;;AAKO,MAAME,IAAI,GAAG,CAClBC,GADkB,EAElBJ,IAFkB,KAGC;EACnB,MAAMK,GAAG,GAAG,EAAZ;EACAC,MAAM,CAACN,IAAP,CAAYI,GAAZ,EACGG,MADH,CACUR,SAAS,CAACC,IAAD,CADnB,EAEGQ,OAFH,CAEYP,GAAD,IAAS;IAChBI,GAAG,CAACJ,GAAD,CAAH,GAAWG,GAAG,CAACH,GAAD,CAAd;EACD,CAJH;EAMA,OAAOI,GAAP;AACD,CAZM;;;;AAcP,SAASI,WAAT,CACEC,SADF,EAEEC,KAFF,EAGEC,QAHF,EAI2B;EACzB,MAAMC,aAAa,GAAGV,IAAI,CAACQ,KAAD,EAAQC,QAAR,CAA1B,CADyB,CAGzB;;EACA,IACE,OAAOF,SAAP,KAAqB,QAArB,IACAA,SAAS,CAACR,OAAV,CAAkB,GAAlB,MAA2B,CAAC,CAD5B,IAEA,CAACN,SAAS,CAACc,SAAS,CAAC,CAAD,CAAV,CAHZ,EAIE;IACAJ,MAAM,CAACN,IAAP,CAAYa,aAAZ,EAA2BL,OAA3B,CAAoCP,GAAD,IAAS;MAC1C,IAAI,CAAC,IAAAa,oBAAA,EAAUb,GAAV,CAAL,EAAqB;QACnB;QACA,OAAOY,aAAa,CAACZ,GAAD,CAApB;MACD;IACF,CALD;EAMD;;EAED,OAAOY,aAAP;AACD;;AAED,MAAME,aAAa,GAAG,CAACC,KAAD,EAAiBC,aAAjB,KAA2C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MAAM,GAAGF,cAAA,CAAMG,UAAN,gBACXH,cAAA,CAAMG,UAAN,CAAiBnB,MAAjB,CADW,GAEX;IACA;IACCvB,KAAD,IAAgB;MACd,MAAM2C,IAAI,GAAGnD,IAAI,CAACQ,KAAD,EAAQ,CAAC,UAAD,CAAR,CAAjB;MACA,OAAOuB,MAAM,CAACoB,IAAD,EAAO3C,KAAK,CAAC4C,QAAb,CAAb;IACD,CAPL;IASCH,MAAD,CAAgBI,WAAhB,GAA8B1B,OAAO,CAACa,IAAtC,CArE2B,CAuE3B;;IACCS,MAAD,CAAgBH,SAAhB,GAA4B;MAC1BX,SAAS,EAAER,OAAO,CAACO,KADO;MAE1BoB,OAAO,EAAE5B;IAFiB,CAA5B;IAKA,OAAOuB,MAAP;EACD,CA9ED;AA+ED;;eAiDelC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIsC,KAAJ,CAAU9B,MAAV,EAAkB;EAChB+B,GAAG,CAACC,CAAD,EAAIC,IAAJ,EAAuC;IACxC,OAAOD,CAAC,CAACC,IAAD,CAAR;EACD;;AAHe,CAAlB,CADY,GAMZjC,M"} |
+33
-3
| { | ||
| "name": "@linaria/react", | ||
| "version": "3.0.0-beta.18", | ||
| "version": "3.0.0-beta.19", | ||
| "publishConfig": { | ||
@@ -17,4 +17,12 @@ "access": "public" | ||
| ], | ||
| "linaria": { | ||
| "tags": { | ||
| "styled": "./lib/processors/styled.js" | ||
| } | ||
| }, | ||
| "license": "MIT", | ||
| "repository": "git@github.com:callstack/linaria.git", | ||
| "engines": { | ||
| "node": "^12.16.0 || >=13.7.0" | ||
| }, | ||
| "bugs": { | ||
@@ -33,2 +41,3 @@ "url": "https://github.com/callstack/linaria/issues" | ||
| "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start", | ||
| "build:corejs-test": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --ignore \"src/processors/**/*\"", | ||
| "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start", | ||
@@ -50,3 +59,4 @@ "build": "yarn build:lib && yarn build:esm", | ||
| "@emotion/is-prop-valid": "^0.8.8", | ||
| "@linaria/core": "^3.0.0-beta.18" | ||
| "@linaria/core": "^3.0.0-beta.19", | ||
| "ts-invariant": "^0.10.3" | ||
| }, | ||
@@ -56,3 +66,23 @@ "peerDependencies": { | ||
| }, | ||
| "gitHead": "c3f093a3a7fb4e7c82d23e44adb19a94438da68c" | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./esm/index.js", | ||
| "default": "./lib/index.js" | ||
| }, | ||
| "./*": { | ||
| "types": "./types/*.d.ts", | ||
| "import": "./esm/*.js", | ||
| "default": "./lib/*.js" | ||
| } | ||
| }, | ||
| "typesVersions": { | ||
| "*": { | ||
| "processors/*": [ | ||
| "./types/processors/*.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
| "gitHead": "73aab0a3908325333e452b9cbd5e438a0f1de463" | ||
| } |
+4
-10
@@ -1,10 +0,4 @@ | ||
| /** | ||
| * This file contains an runtime version of `styled` component. Responsibilities of the component are: | ||
| * - returns ReactElement based on HTML tag used with `styled` or custom React Component | ||
| * - injects classNames for the returned component | ||
| * - injects CSS variables used to define dynamic styles based on props | ||
| */ | ||
| import React from 'react'; | ||
| import type { CSSProperties, StyledMeta } from '@linaria/core'; | ||
| export declare type NoInfer<A extends any> = [A][A extends any ? 0 : never]; | ||
| export declare type NoInfer<A> = [A][A extends any ? 0 : never]; | ||
| declare type Component<TProps> = ((props: TProps) => unknown) | { | ||
@@ -14,3 +8,3 @@ new (props: TProps): unknown; | ||
| declare type Has<T, TObj> = [T] extends [TObj] ? T : T & TObj; | ||
| export declare const restOp: <T extends object, TKeys extends (keyof T)[]>(obj: T, keys: TKeys) => { [K in keyof T]: T[K]; }; | ||
| export declare const omit: <T extends Record<string, unknown>, TKeys extends keyof T>(obj: T, keys: TKeys[]) => Omit<T, TKeys>; | ||
| declare function styled<TProps extends Has<TMustHave, { | ||
@@ -32,5 +26,5 @@ style?: React.CSSProperties; | ||
| declare type StaticPlaceholder = string | number | CSSProperties | StyledMeta; | ||
| declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <TAdditionalProps = {}>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>; | ||
| declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <TAdditionalProps = Record<string, unknown>>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>; | ||
| declare type ComponentStyledTagWithoutInterpolation<TOrigCmp> = (strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: 'The target component should have a style prop') => never)>) => StyledMeta & TOrigCmp; | ||
| declare type ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)>) => keyof OwnProps extends never ? StyledMeta & TOrigCmp : StyledComponent<OwnProps & TTrgProps>; | ||
| declare type ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = Record<string, unknown>>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)>) => keyof OwnProps extends never ? StyledMeta & TOrigCmp : StyledComponent<OwnProps & TTrgProps>; | ||
| declare type StyledJSXIntrinsics = { | ||
@@ -37,0 +31,0 @@ readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
84982
93.56%19
35.71%608
127.72%4
33.33%1
Infinity%+ Added
+ Added
+ Added
Updated