styled-components 6.4.4 → 6.5.0
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/dist/constructors/constructWithOptions.d.ts +4 -4
- package/dist/constructors/styled.d.ts +3 -4
- package/dist/index.d.ts +1 -1
- package/dist/native/index.d.ts +4 -4
- package/dist/styled-components.browser.cjs.js +1 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +4 -3
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/types.d.ts +148 -27
- package/dist/utils/domElements.d.ts +1 -1
- package/dist/utils/noInfer.d.ts +10 -0
- package/native/dist/constructors/constructWithOptions.d.ts +4 -4
- package/native/dist/constructors/styled.d.ts +3 -4
- package/native/dist/dist/constructors/constructWithOptions.d.ts +4 -4
- package/native/dist/dist/constructors/styled.d.ts +3 -4
- package/native/dist/dist/index.d.ts +1 -1
- package/native/dist/dist/native/index.d.ts +4 -4
- package/native/dist/dist/types.d.ts +148 -27
- package/native/dist/dist/utils/domElements.d.ts +1 -1
- package/native/dist/dist/utils/noInfer.d.ts +10 -0
- package/native/dist/index.d.ts +1 -1
- package/native/dist/native/index.d.ts +4 -4
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/native/dist/types.d.ts +148 -27
- package/native/dist/utils/noInfer.d.ts +10 -0
- package/package.json +2 -1
package/dist/types.d.ts
CHANGED
|
@@ -82,8 +82,8 @@ export interface ExecutionContext extends ExecutionProps {
|
|
|
82
82
|
export interface StyleFunction<Props extends BaseObject> {
|
|
83
83
|
(executionContext: ExecutionContext & Props): Interpolation<Props>;
|
|
84
84
|
}
|
|
85
|
-
export type Interpolation<Props extends BaseObject> = StyleFunction<Props> | StyledObject<Props> | TemplateStringsArray | string | number | false | undefined | null | Keyframes | StyledComponentBrand | RuleSet<Props
|
|
86
|
-
export type Attrs<Props extends BaseObject = BaseObject> = (ExecutionProps & Partial<
|
|
85
|
+
export type Interpolation<Props extends BaseObject> = StyleFunction<Props> | StyledObject<Props> | TemplateStringsArray | string | number | false | undefined | null | Keyframes | StyledComponentBrand | RuleSet<Props>;
|
|
86
|
+
export type Attrs<Props extends BaseObject = BaseObject> = (ExecutionProps & Partial<Props>) | ((props: ExecutionContext & Props) => ExecutionProps & Partial<Props>);
|
|
87
87
|
export type RuleSet<Props extends BaseObject = BaseObject> = Interpolation<Props>[];
|
|
88
88
|
export type Styles<Props extends BaseObject> = TemplateStringsArray | StyledObject<Props> | StyleFunction<Props>;
|
|
89
89
|
export type NameGenerator = (hash: number) => string;
|
|
@@ -122,23 +122,65 @@ export interface IStyledStatics<out R extends Runtime, in out OuterProps extends
|
|
|
122
122
|
interface ThemedExecutionProps {
|
|
123
123
|
theme?: DefaultTheme | undefined;
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Props of a render target, for `as` / `forwardedAs`.
|
|
127
|
+
*
|
|
128
|
+
* One distributive conditional, never two nested, and tags resolve by indexed
|
|
129
|
+
* access rather than `React.ComponentPropsWithRef`. Both are load-bearing: this
|
|
130
|
+
* shape is the #5767 fix, and nesting a `T extends KnownTarget` check around it
|
|
131
|
+
* costs ~4x the check time. The `AnyComponent` arm doubles as that test, and
|
|
132
|
+
* every non-target falls through to `{}`.
|
|
133
|
+
*
|
|
134
|
+
* The `style` widening happens here, once per target, rather than at every JSX
|
|
135
|
+
* call site -- directly via {@link WithCSSVars} on the intrinsic arm, which
|
|
136
|
+
* needs no guard, and via {@link OverrideStyle} on the component arm, which
|
|
137
|
+
* does. See AGENTS.md before changing any of it.
|
|
138
|
+
*
|
|
139
|
+
* `R` carries the runtime so the widening stays web-only; it is deliberately
|
|
140
|
+
* undefaulted, since a default is what would let a native call site pick up web
|
|
141
|
+
* CSS by omission.
|
|
142
|
+
*/
|
|
143
|
+
export type TargetProps<R extends Runtime, T> = T extends keyof React.JSX.IntrinsicElements ? IntrinsicProps<T> : T extends AnyComponent ? ComponentTargetProps<R, T> : {};
|
|
144
|
+
/**
|
|
145
|
+
* Props of an HTML or SVG tag.
|
|
146
|
+
*
|
|
147
|
+
* Both branches of {@link TargetProps} are named rather than inlined, so a
|
|
148
|
+
* component's type reads as `Substituted<IntrinsicProps<"button">, { … }>`
|
|
149
|
+
* instead of the full expansion of every tag attribute. See {@link WithCSSVars}
|
|
150
|
+
* for why a conditional's inline branch cannot keep a name.
|
|
151
|
+
*
|
|
152
|
+
* Applies the widening directly rather than through {@link OverrideStyle}: every
|
|
153
|
+
* intrinsic element declares `style`, so the guard has nothing to decide here.
|
|
154
|
+
*/
|
|
155
|
+
type IntrinsicProps<T extends keyof React.JSX.IntrinsicElements> = WithCSSVars<React.JSX.IntrinsicElements[T]>;
|
|
156
|
+
/**
|
|
157
|
+
* Props of a component render target. Named for the same reason as {@link IntrinsicProps}.
|
|
158
|
+
*
|
|
159
|
+
* The `style` widening is web-only: a React Native `style` takes a `ViewStyle`,
|
|
160
|
+
* which carries neither web CSS nor custom properties. This is the only seam that
|
|
161
|
+
* knows the runtime, which is why the gate sits here rather than inside
|
|
162
|
+
* {@link OverrideStyle}. The conditional is over `Runtime` -- two members, concrete
|
|
163
|
+
* at every entry point -- never over the target union.
|
|
164
|
+
*/
|
|
165
|
+
type ComponentTargetProps<R extends Runtime, T extends AnyComponent> = R extends 'web' ? OverrideStyle<React.ComponentPropsWithRef<T>> : React.ComponentPropsWithRef<T>;
|
|
125
166
|
/**
|
|
126
167
|
* Used by PolymorphicComponent to define prop override cascading order.
|
|
127
168
|
*/
|
|
128
169
|
export type PolymorphicComponentProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
129
170
|
as?: infer A;
|
|
130
|
-
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void, AsTargetProps extends BaseObject =
|
|
171
|
+
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void, AsTargetProps extends BaseObject = TargetProps<R, AsTarget>, ForwardedAsTargetProps extends BaseObject = TargetProps<R, ForwardedAsTarget>> = NoInfer<FastOmit<MergeProps<BaseProps, Substitute<ForwardedAsTargetProps, AsTargetProps>>, keyof ExecutionProps>> & ThemedExecutionProps & {
|
|
131
172
|
as?: AsTarget;
|
|
132
173
|
forwardedAs?: ForwardedAsTarget;
|
|
133
|
-
}
|
|
174
|
+
};
|
|
134
175
|
/**
|
|
135
176
|
* Resolves the call-site props for one usage of a polymorphic component from its
|
|
136
|
-
* `as` / `forwardedAs` targets. An `as` render target
|
|
137
|
-
* props and requires `as`; plain usage (or `as` being the wrapped
|
|
138
|
-
* non-target type, e.g. Next.js Link's `as?: Url`)
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
177
|
+
* `as` / `forwardedAs` targets. An `as` render target has its props merged over
|
|
178
|
+
* the base props and requires `as`; plain usage (or `as` being the wrapped
|
|
179
|
+
* component's own non-target type, e.g. Next.js Link's `as?: Url`) reaches
|
|
180
|
+
* {@link PolymorphicComponentProps} not at all, so the base props stay untouched
|
|
181
|
+
* and ref callbacks infer with spread props (#5687), the wrapped `as` stays
|
|
182
|
+
* assignable (#5734), and BaseProps keys keep completing (#5741). `forwardedAs`
|
|
183
|
+
* merges the same way, and loses to `as` where both name a target.
|
|
142
184
|
*
|
|
143
185
|
* The target test is `string | AnyComponent`, not `KnownTarget`: narrowing it
|
|
144
186
|
* drops custom element strings (`as="my-element"`) out of the target branch.
|
|
@@ -161,7 +203,7 @@ type PolymorphicCallProps<R extends Runtime, BaseProps extends BaseObject, AsTar
|
|
|
161
203
|
as: AsTarget;
|
|
162
204
|
} : unknown) & ([AsTarget] extends [string | AnyComponent] ? unknown : [ForwardedAsTarget] extends [string | AnyComponent] ? PolymorphicComponentProps<R, BaseProps, void, ForwardedAsTarget> & {
|
|
163
205
|
forwardedAs: ForwardedAsTarget;
|
|
164
|
-
} :
|
|
206
|
+
} : NoInfer<FastOmit<BaseProps, keyof ExecutionProps>> & ThemedExecutionProps);
|
|
165
207
|
/**
|
|
166
208
|
* This type forms the signature for a forwardRef-enabled component
|
|
167
209
|
* that accepts the "as" prop to dynamically change the underlying
|
|
@@ -189,13 +231,25 @@ export interface PolymorphicComponent<out R extends Runtime, in out BaseProps ex
|
|
|
189
231
|
* statics (`IStyledStatics`, `defaultProps`), so internal code keeps the real
|
|
190
232
|
* `Props` and the widening can't leak past the call site.
|
|
191
233
|
*
|
|
192
|
-
* The
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
|
|
196
|
-
|
|
234
|
+
* The test distributes over `Props` first: `keyof` on a union intersects each
|
|
235
|
+
* member's keys, so a union of disjoint shapes has `keyof` of `never` while
|
|
236
|
+
* being perfectly introspectable. Checking each member alone avoids widening it.
|
|
237
|
+
*/
|
|
238
|
+
export type WidenUntypedProps<Props extends BaseObject> = WidenForUntypedTarget<Props, Props>;
|
|
239
|
+
/**
|
|
240
|
+
* Widens because the *target* is un-introspectable, even when the component
|
|
241
|
+
* declares props of its own.
|
|
242
|
+
*
|
|
243
|
+
* `Target` must be the target's props, never a bag the component's own props
|
|
244
|
+
* were merged into. Pass the latter and the test degrades: adding one transient
|
|
245
|
+
* prop makes `keyof` non-`never`, the widening switches off, and the target's
|
|
246
|
+
* own props including `children` start being rejected. That is #5756, and every
|
|
247
|
+
* call site here passes `TargetProps<R, Target>` for that reason.
|
|
248
|
+
*
|
|
249
|
+
* Applying it to an already-widened `Target` is a no-op, since the index
|
|
250
|
+
* signature makes `keyof` be `string`.
|
|
197
251
|
*/
|
|
198
|
-
export type
|
|
252
|
+
export type WidenForUntypedTarget<Target extends BaseObject, Props extends BaseObject> = (Target extends unknown ? (keyof Target extends never ? true : false) : never) extends true ? Props & {
|
|
199
253
|
[key: string]: unknown;
|
|
200
254
|
} : Props;
|
|
201
255
|
export interface IStyledComponentBase<out R extends Runtime, in out Props extends BaseObject = BaseObject> extends PolymorphicComponent<R, WidenUntypedProps<Props>>, IStyledStatics<R, Props>, StyledComponentBrand {
|
|
@@ -224,11 +278,55 @@ export type CSSProperties = CSS.Properties<number | (string & {})>;
|
|
|
224
278
|
export type CSSPropertiesWithVars = CSSProperties & {
|
|
225
279
|
[key: `--${string}`]: string | number | undefined;
|
|
226
280
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
281
|
+
/**
|
|
282
|
+
* A `style` type that accepts exactly the fields given and nothing else.
|
|
283
|
+
*
|
|
284
|
+
* A declared `style` normally narrows the fields it names and leaves the rest of
|
|
285
|
+
* CSS available, which is what you want when constraining one or two properties:
|
|
286
|
+
*
|
|
287
|
+
* ```tsx
|
|
288
|
+
* // `width` must be a number; `color` and custom properties still work
|
|
289
|
+
* const Box = styled.div<{ style?: { width: number } }>``;
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* Wrap the declaration in `CustomStyle` when the point is to forbid everything
|
|
293
|
+
* else, rather than writing `color?: never` for every property by hand:
|
|
294
|
+
*
|
|
295
|
+
* ```tsx
|
|
296
|
+
* // `width` is the only accepted style field
|
|
297
|
+
* const Box = styled.div<{ style?: CustomStyle<{ width: number }> }>``;
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export type CustomStyle<T extends object> = T & {
|
|
301
|
+
[K in Exclude<keyof CSSPropertiesWithVars, keyof T>]?: never;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Widens a target's `style` prop so CSS custom properties are accepted, and the
|
|
305
|
+
* taken branch of {@link OverrideStyle}. Keep it named: a conditional alias
|
|
306
|
+
* loses its name once it resolves, so an inline branch prints its whole
|
|
307
|
+
* expansion in every hover and error.
|
|
308
|
+
*
|
|
309
|
+
* `(P['style'] & {})` is load-bearing under `exactOptionalPropertyTypes` -- it
|
|
310
|
+
* filters `undefined` out so the `?:` stays the sole optional source -- and the
|
|
311
|
+
* explicit `| undefined` then restores `style={undefined}`.
|
|
312
|
+
*/
|
|
313
|
+
type WithCSSVars<P extends BaseObject> = Omit<P, 'style'> & {
|
|
314
|
+
style?: CSSPropertiesWithVars | (P[keyof P & 'style'] & {}) | undefined;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Applies the `style` widening to a target that may or may not declare `style`.
|
|
318
|
+
*
|
|
319
|
+
* Applied once per target in {@link TargetProps}, never to a merged prop bag at
|
|
320
|
+
* a JSX call site. It runs before a component's own props, which then merge over
|
|
321
|
+
* it via {@link MergeProps} rather than replacing it.
|
|
322
|
+
*
|
|
323
|
+
* The test is `'style' extends keyof P`, not `P extends { style?: infer S }`:
|
|
324
|
+
* the latter is vacuously satisfied by `{}`, which would hand a `style` key to
|
|
325
|
+
* targets that expose no props at all and defeat `WidenUntypedProps` (#5756).
|
|
326
|
+
* Only {@link ComponentTargetProps} needs the guard; every intrinsic element
|
|
327
|
+
* declares `style`, so {@link IntrinsicProps} applies `WithCSSVars` directly.
|
|
328
|
+
*/
|
|
329
|
+
type OverrideStyle<P extends BaseObject> = 'style' extends keyof P ? WithCSSVars<P> : P;
|
|
232
330
|
export type CSSPseudos = {
|
|
233
331
|
[K in CSS.Pseudos]?: CSSObject;
|
|
234
332
|
};
|
|
@@ -261,15 +359,38 @@ export interface StyledObject<Props extends BaseObject = BaseObject> extends CSS
|
|
|
261
359
|
* {@link DefaultTheme}.
|
|
262
360
|
*/
|
|
263
361
|
export type CSSProp = Interpolation<any>;
|
|
362
|
+
export type { NoInfer } from './utils/noInfer';
|
|
363
|
+
/** The taken branch of {@link Substitute}. Named so it survives into hovers and
|
|
364
|
+
* error messages; see {@link WithCSSVars} for why an inline branch does not. */
|
|
365
|
+
export type Substituted<A extends BaseObject, B> = FastOmit<A, keyof B> & B;
|
|
366
|
+
export type Substitute<A extends BaseObject, B> = keyof B extends never ? A : Substituted<A, B>;
|
|
264
367
|
/**
|
|
265
|
-
*
|
|
266
|
-
*
|
|
368
|
+
* A component's own props over its target's props, with `style` merged rather
|
|
369
|
+
* than replaced, so `styled.div<{ style?: { width: number } }>` constrains
|
|
370
|
+
* `width` and leaves the rest of CSS accepted. A field declared `never` is
|
|
371
|
+
* removed; {@link CustomStyle} removes everything a declaration omits.
|
|
372
|
+
*
|
|
373
|
+
* Under `exactOptionalPropertyTypes` the intersection leaves no `undefined` arm,
|
|
374
|
+
* so such a component rejects an explicit `style={undefined}`; declare
|
|
375
|
+
* `style?: X | undefined` to allow it. Omitting the prop is unaffected.
|
|
376
|
+
*
|
|
377
|
+
* Both conditional spellings of this were measured and rejected, one of them
|
|
378
|
+
* fatal. Keep it an intersection; see AGENTS.md before changing the shape.
|
|
267
379
|
*/
|
|
268
|
-
export type
|
|
269
|
-
|
|
380
|
+
export type MergeProps<A extends BaseObject, B> = keyof B extends never ? A : Merged<A, B>;
|
|
381
|
+
/** The taken branch of {@link MergeProps}, named so hovers print a name rather
|
|
382
|
+
* than the expansion. Keep it named; see {@link Substituted}. */
|
|
383
|
+
export type Merged<A extends BaseObject, B> = FastOmit<A, Exclude<keyof B, 'style'>> & B;
|
|
270
384
|
/**
|
|
271
385
|
* Makes keys in K optional while keeping all others required.
|
|
272
386
|
* Used to make attrs-provided props optional on the final component.
|
|
387
|
+
*
|
|
388
|
+
* The guard is `[K] extends [never]`, not `keyof K extends never`. `K` is the set
|
|
389
|
+
* of attrs-provided keys and is `never` for any component without `.attrs()`,
|
|
390
|
+
* which is most of them, but `keyof never` is `string | number | symbol`, so the
|
|
391
|
+
* old spelling never short-circuited. Every such component paid an omit plus a
|
|
392
|
+
* `Partial<Pick<...>>` that removed and re-added nothing, and carried both in its
|
|
393
|
+
* displayed type.
|
|
273
394
|
*/
|
|
274
|
-
export type MakeAttrsOptional<P extends BaseObject, K extends keyof any> =
|
|
395
|
+
export type MakeAttrsOptional<P extends BaseObject, K extends keyof any> = [K] extends [never] ? P : FastOmit<P, K & keyof P> & Partial<Pick<P, K & keyof P>>;
|
|
275
396
|
export type InsertionTarget = HTMLElement | ShadowRoot;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const elements: readonly ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote", "body", "button", "br", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "menu", "meter", "nav", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "slot", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "u", "ul", "var", "video", "wbr", "circle", "clipPath", "defs", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "foreignObject", "g", "image", "line", "linearGradient", "marker", "mask", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", "stop", "svg", "switch", "symbol", "text", "textPath", "tspan", "use"];
|
|
2
|
-
declare const _default: Set<"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "bdi" | "bdo" | "blockquote" | "body" | "
|
|
2
|
+
declare const _default: Set<"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "bdi" | "bdo" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "label" | "legend" | "li" | "main" | "map" | "mark" | "menu" | "meter" | "nav" | "ol" | "optgroup" | "option" | "output" | "p" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "search" | "slot" | "section" | "select" | "small" | "span" | "strong" | "sub" | "summary" | "sup" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "tr" | "u" | "ul" | "var" | "video" | "wbr" | "svg" | "circle" | "clipPath" | "defs" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use">;
|
|
3
3
|
export default _default;
|
|
4
4
|
export type SupportedHTMLElements = (typeof elements)[number];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use the built-in `NoInfer` from TypeScript 5.4+ directly.
|
|
3
|
+
*
|
|
4
|
+
* Kept for consumers importing it from `styled-components/dist/types`. It lives
|
|
5
|
+
* in its own module rather than in `types.ts` because a module-local `NoInfer`
|
|
6
|
+
* shadows the TypeScript intrinsic within that module, silently downgrading
|
|
7
|
+
* every reference there to this slower deferred form. `types.ts` re-exports the
|
|
8
|
+
* name, and a re-export introduces no local binding.
|
|
9
|
+
*/
|
|
10
|
+
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles,
|
|
1
|
+
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, MergeProps, Runtime, StyledOptions, StyledTarget, Styles, TargetProps, WidenForUntypedTarget } from '../types';
|
|
2
2
|
type AttrsResult<T extends Attrs<any>> = T extends (...args: any) => infer P ? P extends object ? P : never : T extends object ? T : never;
|
|
3
3
|
/**
|
|
4
4
|
* Based on Attrs being a simple object or function that returns
|
|
@@ -9,9 +9,9 @@ type AttrsTarget<R extends Runtime, T extends Attrs<any>, FallbackTarget extends
|
|
|
9
9
|
as: infer RuntimeTarget;
|
|
10
10
|
} ? RuntimeTarget extends KnownTarget ? RuntimeTarget : FallbackTarget : FallbackTarget;
|
|
11
11
|
export interface Styled<out R extends Runtime, out Target extends StyledTarget<R>, in out OuterProps extends object, out OuterStatics extends object = BaseObject, out AttrsKeys extends keyof any = never> {
|
|
12
|
-
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<
|
|
13
|
-
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object =
|
|
12
|
+
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<MergeProps<OuterProps, NoInfer<Props>>>, ...interpolations: Interpolation<MergeProps<OuterProps, NoInfer<Props>>>[]): IStyledComponent<R, WidenForUntypedTarget<TargetProps<R, Target>, MakeAttrsOptional<MergeProps<OuterProps, Props>, AttrsKeys>>> & OuterStatics & Statics & (R extends 'web' ? Target extends string ? {} : Omit<Target, keyof React.Component<any>> : {});
|
|
13
|
+
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = MergeProps<OuterProps, Props>, PrivateAttrsArg extends Attrs<WidenForUntypedTarget<TargetProps<R, Target>, PrivateMergedProps>> = Attrs<WidenForUntypedTarget<TargetProps<R, Target>, PrivateMergedProps>>, PrivateResolvedTarget extends StyledTarget<R> = AttrsTarget<R, PrivateAttrsArg, Target>>(attrs: PrivateAttrsArg) => Styled<R, PrivateResolvedTarget, PrivateResolvedTarget extends KnownTarget ? MergeProps<MergeProps<OuterProps, React.ComponentPropsWithRef<PrivateResolvedTarget>>, Props> : PrivateMergedProps, OuterStatics, AttrsKeys | keyof AttrsResult<PrivateAttrsArg>>;
|
|
14
14
|
withConfig: (config: StyledOptions<R, OuterProps>) => Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
15
15
|
}
|
|
16
|
-
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object =
|
|
16
|
+
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = TargetProps<R, Target>, OuterStatics extends object = BaseObject, AttrsKeys extends keyof any = never>(componentConstructor: IStyledComponentFactory<R, StyledTarget<R>, object, any>, tag: StyledTarget<R>, options?: StyledOptions<R, OuterProps>): Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
17
17
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BaseObject, KnownTarget, WebTarget } from '../types';
|
|
1
|
+
import { BaseObject, TargetProps, WebTarget } from '../types';
|
|
3
2
|
import { SupportedHTMLElements } from '../utils/domElements';
|
|
4
3
|
import { Styled as StyledInstance } from './constructWithOptions';
|
|
5
4
|
/**
|
|
@@ -10,8 +9,8 @@ import { Styled as StyledInstance } from './constructWithOptions';
|
|
|
10
9
|
* const Link = styled(RouterLink)`text-decoration: none;`;
|
|
11
10
|
* ```
|
|
12
11
|
*/
|
|
13
|
-
declare const baseStyled: <Target extends WebTarget, InjectedProps extends object = BaseObject>(tag: Target) => StyledInstance<"web", Target,
|
|
14
|
-
declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E,
|
|
12
|
+
declare const baseStyled: <Target extends WebTarget, InjectedProps extends object = BaseObject>(tag: Target) => StyledInstance<"web", Target, TargetProps<"web", Target> & InjectedProps, BaseObject, never>;
|
|
13
|
+
declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E, TargetProps<"web", E>>; };
|
|
15
14
|
export default styled;
|
|
16
15
|
export { StyledInstance };
|
|
17
16
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles,
|
|
1
|
+
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, MergeProps, Runtime, StyledOptions, StyledTarget, Styles, TargetProps, WidenForUntypedTarget } from '../types';
|
|
2
2
|
type AttrsResult<T extends Attrs<any>> = T extends (...args: any) => infer P ? P extends object ? P : never : T extends object ? T : never;
|
|
3
3
|
/**
|
|
4
4
|
* Based on Attrs being a simple object or function that returns
|
|
@@ -9,9 +9,9 @@ type AttrsTarget<R extends Runtime, T extends Attrs<any>, FallbackTarget extends
|
|
|
9
9
|
as: infer RuntimeTarget;
|
|
10
10
|
} ? RuntimeTarget extends KnownTarget ? RuntimeTarget : FallbackTarget : FallbackTarget;
|
|
11
11
|
export interface Styled<out R extends Runtime, out Target extends StyledTarget<R>, in out OuterProps extends object, out OuterStatics extends object = BaseObject, out AttrsKeys extends keyof any = never> {
|
|
12
|
-
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<
|
|
13
|
-
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object =
|
|
12
|
+
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<MergeProps<OuterProps, NoInfer<Props>>>, ...interpolations: Interpolation<MergeProps<OuterProps, NoInfer<Props>>>[]): IStyledComponent<R, WidenForUntypedTarget<TargetProps<R, Target>, MakeAttrsOptional<MergeProps<OuterProps, Props>, AttrsKeys>>> & OuterStatics & Statics & (R extends 'web' ? Target extends string ? {} : Omit<Target, keyof React.Component<any>> : {});
|
|
13
|
+
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = MergeProps<OuterProps, Props>, PrivateAttrsArg extends Attrs<WidenForUntypedTarget<TargetProps<R, Target>, PrivateMergedProps>> = Attrs<WidenForUntypedTarget<TargetProps<R, Target>, PrivateMergedProps>>, PrivateResolvedTarget extends StyledTarget<R> = AttrsTarget<R, PrivateAttrsArg, Target>>(attrs: PrivateAttrsArg) => Styled<R, PrivateResolvedTarget, PrivateResolvedTarget extends KnownTarget ? MergeProps<MergeProps<OuterProps, React.ComponentPropsWithRef<PrivateResolvedTarget>>, Props> : PrivateMergedProps, OuterStatics, AttrsKeys | keyof AttrsResult<PrivateAttrsArg>>;
|
|
14
14
|
withConfig: (config: StyledOptions<R, OuterProps>) => Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
15
15
|
}
|
|
16
|
-
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object =
|
|
16
|
+
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = TargetProps<R, Target>, OuterStatics extends object = BaseObject, AttrsKeys extends keyof any = never>(componentConstructor: IStyledComponentFactory<R, StyledTarget<R>, object, any>, tag: StyledTarget<R>, options?: StyledOptions<R, OuterProps>): Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
17
17
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BaseObject, KnownTarget, WebTarget } from '../types';
|
|
1
|
+
import { BaseObject, TargetProps, WebTarget } from '../types';
|
|
3
2
|
import { SupportedHTMLElements } from '../utils/domElements';
|
|
4
3
|
import { Styled as StyledInstance } from './constructWithOptions';
|
|
5
4
|
/**
|
|
@@ -10,8 +9,8 @@ import { Styled as StyledInstance } from './constructWithOptions';
|
|
|
10
9
|
* const Link = styled(RouterLink)`text-decoration: none;`;
|
|
11
10
|
* ```
|
|
12
11
|
*/
|
|
13
|
-
declare const baseStyled: <Target extends WebTarget, InjectedProps extends object = BaseObject>(tag: Target) => StyledInstance<"web", Target,
|
|
14
|
-
declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E,
|
|
12
|
+
declare const baseStyled: <Target extends WebTarget, InjectedProps extends object = BaseObject>(tag: Target) => StyledInstance<"web", Target, TargetProps<"web", Target> & InjectedProps, BaseObject, never>;
|
|
13
|
+
declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E, TargetProps<"web", E>>; };
|
|
15
14
|
export default styled;
|
|
16
15
|
export { StyledInstance };
|
|
17
16
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styled, { LibraryStyled, Styled, StyledInstance } from './constructors/styled';
|
|
2
2
|
export * from './base';
|
|
3
3
|
export { default as stylisPluginRSC } from './utils/stylisPluginRSC';
|
|
4
|
-
export { CSSKeyframes, CSSObject, CSSProp, CSSProperties, CSSPseudos, DataAttributes, DefaultTheme, ExecutionContext, ExecutionProps, FastOmit, Interpolation, IStyledComponent, IStyledComponentFactory, IStyledStatics, PolymorphicComponent, PolymorphicComponentProps, RuleSet, Runtime, StyledObject, StyledOptions, StyleFunction, SupportedHTMLElements, WebTarget, } from './types';
|
|
4
|
+
export { CSSKeyframes, CSSObject, CSSProp, CSSProperties, CSSPseudos, CustomStyle, DataAttributes, DefaultTheme, ExecutionContext, ExecutionProps, FastOmit, Interpolation, IStyledComponent, IStyledComponentFactory, IStyledStatics, PolymorphicComponent, PolymorphicComponentProps, RuleSet, Runtime, StyledObject, StyledOptions, StyleFunction, SupportedHTMLElements, WebTarget, } from './types';
|
|
5
5
|
export { styled as default, LibraryStyled, Styled, styled, StyledInstance };
|
|
@@ -3,7 +3,7 @@ import { Styled } from '../constructors/constructWithOptions';
|
|
|
3
3
|
import css from '../constructors/css';
|
|
4
4
|
import withTheme from '../hoc/withTheme';
|
|
5
5
|
import ThemeProvider, { ThemeConsumer, ThemeContext, useTheme } from '../models/ThemeProvider';
|
|
6
|
-
import { NativeTarget, RuleSet } from '../types';
|
|
6
|
+
import { NativeTarget, RuleSet, TargetProps } from '../types';
|
|
7
7
|
import isStyledComponent from '../utils/isStyledComponent';
|
|
8
8
|
declare const reactNative: Awaited<typeof import("react-native")>;
|
|
9
9
|
/**
|
|
@@ -14,14 +14,14 @@ declare const reactNative: Awaited<typeof import("react-native")>;
|
|
|
14
14
|
* const Label = styled(Text)`font-size: 14px;`;
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
declare const baseStyled: <Target extends NativeTarget>(tag: Target) => Styled<"native", Target,
|
|
17
|
+
declare const baseStyled: <Target extends NativeTarget>(tag: Target) => Styled<"native", Target, TargetProps<"native", Target>, import("../types").BaseObject, never>;
|
|
18
18
|
declare const aliases: readonly ["ActivityIndicator", "Button", "FlatList", "Image", "ImageBackground", "InputAccessoryView", "KeyboardAvoidingView", "Modal", "Pressable", "RefreshControl", "SafeAreaView", "ScrollView", "SectionList", "StatusBar", "Switch", "Text", "TextInput", "TouchableHighlight", "TouchableNativeFeedback", "TouchableOpacity", "TouchableWithoutFeedback", "View", "VirtualizedList"];
|
|
19
19
|
type KnownComponents = (typeof aliases)[number];
|
|
20
20
|
/** Isolates RN-provided components since they don't expose a helper type for this. */
|
|
21
21
|
type RNComponents = {
|
|
22
22
|
[K in keyof typeof reactNative]: (typeof reactNative)[K] extends React.ComponentType<any> ? (typeof reactNative)[K] : never;
|
|
23
23
|
};
|
|
24
|
-
declare const styled: typeof baseStyled & { [E in KnownComponents]: Styled<"native", RNComponents[E],
|
|
24
|
+
declare const styled: typeof baseStyled & { [E in KnownComponents]: Styled<"native", RNComponents[E], TargetProps<"native", RNComponents[E]>>; };
|
|
25
25
|
/**
|
|
26
26
|
* Convert a `css` tagged template to a React Native StyleSheet object.
|
|
27
27
|
*
|
|
@@ -31,5 +31,5 @@ declare const styled: typeof baseStyled & { [E in KnownComponents]: Styled<"nati
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare const toStyleSheet: (rules: RuleSet<object>) => any;
|
|
34
|
-
export { CSSKeyframes, CSSObject, CSSProperties, CSSPseudos, DefaultTheme, ExecutionContext, ExecutionProps, IStyledComponent, IStyledComponentFactory, IStyledStatics, NativeTarget, PolymorphicComponent, PolymorphicComponentProps, Runtime, StyledObject, StyledOptions, } from '../types';
|
|
34
|
+
export { CSSKeyframes, CSSObject, CSSProperties, CSSPseudos, CustomStyle, DefaultTheme, ExecutionContext, ExecutionProps, IStyledComponent, IStyledComponentFactory, IStyledStatics, NativeTarget, PolymorphicComponent, PolymorphicComponentProps, Runtime, StyledObject, StyledOptions, } from '../types';
|
|
35
35
|
export { css, styled as default, isStyledComponent, styled, ThemeConsumer, ThemeContext, ThemeProvider, toStyleSheet, useTheme, withTheme, };
|