@storybook/web-components 11.0.0-alpha.1 → 11.0.0-alpha.2

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/index.d.ts CHANGED
@@ -1,8 +1,22 @@
1
- import { AnnotatedStoryFn, ArgTypes, Args, Args as Args$1, ArgsStoryFn, ComponentAnnotations, DecoratorFunction, LoaderFunction, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Parameters as Parameters$1, ProjectAnnotations, Renderer, StoryAnnotations, StoryContext as StoryContext$1, StrictArgs, StrictArgs as StrictArgs$1, WebRenderer } from "storybook/internal/types";
1
+ import { AnnotatedStoryFn, ArgTypes, Args, Args as Args$1, ArgsStoryFn, ComponentAnnotations, DecoratorFunction, LoaderFunction, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Parameters, ProjectAnnotations, StoryAnnotations, StoryContext as StoryContext$1, StrictArgs, StrictArgs as StrictArgs$1, WebRenderer } from "storybook/internal/types";
2
2
  import { SVGTemplateResult, TemplateResult } from "lit";
3
- import { AddonTypes, InferTypes, Meta as Meta$1, Preview as Preview$1, PreviewAddon, Story } from "storybook/internal/csf";
3
+ import { AddonTypes, InferTypes, Meta as Meta$1, MetaInput, MetaTypes, Preview as Preview$1, PreviewAddon, Story, StoryArgs, TypedMetaArgKeys, WithRenderArgs } from "storybook/internal/csf";
4
4
 
5
5
  //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/types.d.ts
6
+ type WebComponentsFrameworkOptions = {
7
+ /**
8
+ * Paths to Custom Elements Manifest files, relative to the Storybook config directory.
9
+ *
10
+ * When omitted, Storybook reads `customElements` from the nearest `package.json`.
11
+ * When neither is available, server-side docgen is skipped and the runtime `setCustomElementsManifest` path keeps working as before.
12
+ *
13
+ * Please note that the runtime `setCustomElementsManifest` path is deprecated and will be removed in next major.
14
+ */
15
+ customElementsManifest?: string | string[];
16
+ docgen?: {
17
+ /** Manifest key that holds analyzer-resolved type text; defaults to `parsedType`. */typeProperty?: string;
18
+ };
19
+ };
6
20
  type StoryFnHtmlReturnType = string | Node | DocumentFragment | TemplateResult | SVGTemplateResult;
7
21
  interface WebComponentsRenderer extends WebRenderer {
8
22
  component: string;
@@ -64,373 +78,6 @@ declare function getCustomElements(): any;
64
78
  */
65
79
  declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]): NormalizedProjectAnnotations<WebComponentsRenderer>;
66
80
  //#endregion
67
- //#region node_modules/type-fest/source/union-to-intersection.d.ts
68
- /**
69
- Convert a union type to an intersection type.
70
-
71
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
72
-
73
- @example
74
- ```
75
- import type {UnionToIntersection} from 'type-fest';
76
-
77
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
78
-
79
- type Intersection = UnionToIntersection<Union>;
80
- //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
81
- ```
82
-
83
- @category Type
84
- */
85
- type UnionToIntersection<Union> = (// `extends unknown` is always going to be the case and is used to convert the
86
- // `Union` into a [distributive conditional
87
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
88
- Union extends unknown // The union type is used as the only argument to a function since the union
89
- // of function arguments is an intersection.
90
- ? (distributedUnion: Union) => void // This won't happen.
91
- : never // Infer the `Intersection` type since TypeScript represents the positional
92
- // arguments of unions of functions as an intersection of the union.
93
- ) extends ((mergedIntersection: infer Intersection) => void) // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
94
- ? Intersection & Union : never;
95
- //#endregion
96
- //#region node_modules/type-fest/source/keys-of-union.d.ts
97
- /**
98
- Create a union of all keys from a given type, even those exclusive to specific union members.
99
-
100
- Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
101
-
102
- @link https://stackoverflow.com/a/49402091
103
-
104
- @example
105
- ```
106
- import type {KeysOfUnion} from 'type-fest';
107
-
108
- type A = {
109
- common: string;
110
- a: number;
111
- };
112
-
113
- type B = {
114
- common: string;
115
- b: string;
116
- };
117
-
118
- type C = {
119
- common: string;
120
- c: boolean;
121
- };
122
-
123
- type Union = A | B | C;
124
-
125
- type CommonKeys = keyof Union;
126
- //=> 'common'
127
-
128
- type AllKeys = KeysOfUnion<Union>;
129
- //=> 'common' | 'a' | 'b' | 'c'
130
- ```
131
-
132
- @category Object
133
- */
134
- type KeysOfUnion<ObjectType> = // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
135
- keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
136
- //#endregion
137
- //#region node_modules/type-fest/source/is-any.d.ts
138
- /**
139
- Returns a boolean for whether the given type is `any`.
140
-
141
- @link https://stackoverflow.com/a/49928360/1490091
142
-
143
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
144
-
145
- @example
146
- ```
147
- import type {IsAny} from 'type-fest';
148
-
149
- const typedObject = {a: 1, b: 2} as const;
150
- const anyObject: any = {a: 1, b: 2};
151
-
152
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
153
- return object[key];
154
- }
155
-
156
- const typedA = get(typedObject, 'a');
157
- //=> 1
158
-
159
- const anyA = get(anyObject, 'a');
160
- //=> any
161
- ```
162
-
163
- @category Type Guard
164
- @category Utilities
165
- */
166
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
167
- //#endregion
168
- //#region node_modules/type-fest/source/is-optional-key-of.d.ts
169
- /**
170
- Returns a boolean for whether the given key is an optional key of type.
171
-
172
- This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
173
-
174
- @example
175
- ```
176
- import type {IsOptionalKeyOf} from 'type-fest';
177
-
178
- type User = {
179
- name: string;
180
- surname: string;
181
-
182
- luckyNumber?: number;
183
- };
184
-
185
- type Admin = {
186
- name: string;
187
- surname?: string;
188
- };
189
-
190
- type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
191
- //=> true
192
-
193
- type T2 = IsOptionalKeyOf<User, 'name'>;
194
- //=> false
195
-
196
- type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
197
- //=> boolean
198
-
199
- type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
200
- //=> false
201
-
202
- type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
203
- //=> boolean
204
- ```
205
-
206
- @category Type Guard
207
- @category Utilities
208
- */
209
- type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
210
- //#endregion
211
- //#region node_modules/type-fest/source/optional-keys-of.d.ts
212
- /**
213
- Extract all optional keys from the given type.
214
-
215
- This is useful when you want to create a new type that contains different type values for the optional keys only.
216
-
217
- @example
218
- ```
219
- import type {OptionalKeysOf, Except} from 'type-fest';
220
-
221
- type User = {
222
- name: string;
223
- surname: string;
224
-
225
- luckyNumber?: number;
226
- };
227
-
228
- const REMOVE_FIELD = Symbol('remove field symbol');
229
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
230
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
231
- };
232
-
233
- const update1: UpdateOperation<User> = {
234
- name: 'Alice',
235
- };
236
-
237
- const update2: UpdateOperation<User> = {
238
- name: 'Bob',
239
- luckyNumber: REMOVE_FIELD,
240
- };
241
- ```
242
-
243
- @category Utilities
244
- */
245
- type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
246
- ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
247
- : never;
248
- //#endregion
249
- //#region node_modules/type-fest/source/required-keys-of.d.ts
250
- /**
251
- Extract all required keys from the given type.
252
-
253
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
254
-
255
- @example
256
- ```
257
- import type {RequiredKeysOf} from 'type-fest';
258
-
259
- declare function createValidation<
260
- Entity extends object,
261
- Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
262
- >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
263
-
264
- type User = {
265
- name: string;
266
- surname: string;
267
- luckyNumber?: number;
268
- };
269
-
270
- const validator1 = createValidation<User>('name', value => value.length < 25);
271
- const validator2 = createValidation<User>('surname', value => value.length < 25);
272
-
273
- // @ts-expect-error
274
- const validator3 = createValidation<User>('luckyNumber', value => value > 0);
275
- // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
276
- ```
277
-
278
- @category Utilities
279
- */
280
- type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
281
- ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
282
- //#endregion
283
- //#region node_modules/type-fest/source/is-never.d.ts
284
- /**
285
- Returns a boolean for whether the given type is `never`.
286
-
287
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
288
- @link https://stackoverflow.com/a/53984913/10292952
289
- @link https://www.zhenghao.io/posts/ts-never
290
-
291
- Useful in type utilities, such as checking if something does not occur.
292
-
293
- @example
294
- ```
295
- import type {IsNever, And} from 'type-fest';
296
-
297
- type A = IsNever<never>;
298
- //=> true
299
-
300
- type B = IsNever<any>;
301
- //=> false
302
-
303
- type C = IsNever<unknown>;
304
- //=> false
305
-
306
- type D = IsNever<never[]>;
307
- //=> false
308
-
309
- type E = IsNever<object>;
310
- //=> false
311
-
312
- type F = IsNever<string>;
313
- //=> false
314
- ```
315
-
316
- @example
317
- ```
318
- import type {IsNever} from 'type-fest';
319
-
320
- type IsTrue<T> = T extends true ? true : false;
321
-
322
- // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
323
- type A = IsTrue<never>;
324
- //=> never
325
-
326
- // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
327
- type IsTrueFixed<T> =
328
- IsNever<T> extends true ? false : T extends true ? true : false;
329
-
330
- type B = IsTrueFixed<never>;
331
- //=> false
332
- ```
333
-
334
- @category Type Guard
335
- @category Utilities
336
- */
337
- type IsNever<T> = [T] extends [never] ? true : false;
338
- //#endregion
339
- //#region node_modules/type-fest/source/if.d.ts
340
- /**
341
- An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
342
-
343
- Use-cases:
344
- - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
345
-
346
- Note:
347
- - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
348
- - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
349
-
350
- @example
351
- ```
352
- import type {If} from 'type-fest';
353
-
354
- type A = If<true, 'yes', 'no'>;
355
- //=> 'yes'
356
-
357
- type B = If<false, 'yes', 'no'>;
358
- //=> 'no'
359
-
360
- type C = If<boolean, 'yes', 'no'>;
361
- //=> 'yes' | 'no'
362
-
363
- type D = If<any, 'yes', 'no'>;
364
- //=> 'yes' | 'no'
365
-
366
- type E = If<never, 'yes', 'no'>;
367
- //=> 'no'
368
- ```
369
-
370
- @example
371
- ```
372
- import type {If, IsAny, IsNever} from 'type-fest';
373
-
374
- type A = If<IsAny<unknown>, 'is any', 'not any'>;
375
- //=> 'not any'
376
-
377
- type B = If<IsNever<never>, 'is never', 'not never'>;
378
- //=> 'is never'
379
- ```
380
-
381
- @example
382
- ```
383
- import type {If, IsEqual} from 'type-fest';
384
-
385
- type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
386
-
387
- type A = IfEqual<string, string, 'equal', 'not equal'>;
388
- //=> 'equal'
389
-
390
- type B = IfEqual<string, number, 'equal', 'not equal'>;
391
- //=> 'not equal'
392
- ```
393
-
394
- Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
395
-
396
- @example
397
- ```
398
- import type {If, IsEqual, StringRepeat} from 'type-fest';
399
-
400
- type HundredZeroes = StringRepeat<'0', 100>;
401
-
402
- // The following implementation is not tail recursive
403
- type Includes<S extends string, Char extends string> =
404
- S extends `${infer First}${infer Rest}`
405
- ? If<IsEqual<First, Char>,
406
- 'found',
407
- Includes<Rest, Char>>
408
- : 'not found';
409
-
410
- // Hence, instantiations with long strings will fail
411
- // @ts-expect-error
412
- type Fails = Includes<HundredZeroes, '1'>;
413
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
414
- // Error: Type instantiation is excessively deep and possibly infinite.
415
-
416
- // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
417
- type IncludesWithoutIf<S extends string, Char extends string> =
418
- S extends `${infer First}${infer Rest}`
419
- ? IsEqual<First, Char> extends true
420
- ? 'found'
421
- : IncludesWithoutIf<Rest, Char>
422
- : 'not found';
423
-
424
- // Now, instantiations with long strings will work
425
- type Works = IncludesWithoutIf<HundredZeroes, '1'>;
426
- //=> 'not found'
427
- ```
428
-
429
- @category Type Guard
430
- @category Utilities
431
- */
432
- type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
433
- //#endregion
434
81
  //#region node_modules/type-fest/source/simplify.d.ts
435
82
  /**
436
83
  Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
@@ -492,470 +139,6 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
492
139
  */
493
140
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
494
141
  //#endregion
495
- //#region node_modules/type-fest/source/is-equal.d.ts
496
- /**
497
- Returns a boolean for whether the two given types are equal.
498
-
499
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
500
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
501
-
502
- Use-cases:
503
- - If you want to make a conditional branch based on the result of a comparison of two types.
504
-
505
- @example
506
- ```
507
- import type {IsEqual} from 'type-fest';
508
-
509
- // This type returns a boolean for whether the given array includes the given item.
510
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
511
- type Includes<Value extends readonly any[], Item> =
512
- Value extends readonly [Value[0], ...infer rest]
513
- ? IsEqual<Value[0], Item> extends true
514
- ? true
515
- : Includes<rest, Item>
516
- : false;
517
- ```
518
-
519
- @category Type Guard
520
- @category Utilities
521
- */
522
- type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
523
- // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
524
- type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
525
- //#endregion
526
- //#region node_modules/type-fest/source/omit-index-signature.d.ts
527
- /**
528
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
529
-
530
- This is the counterpart of `PickIndexSignature`.
531
-
532
- Use-cases:
533
- - Remove overly permissive signatures from third-party types.
534
-
535
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
536
-
537
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
538
-
539
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
540
-
541
- ```
542
- const indexed: Record<string, unknown> = {}; // Allowed
543
-
544
- // @ts-expect-error
545
- const keyed: Record<'foo', unknown> = {}; // Error
546
- // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
547
- ```
548
-
549
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
550
-
551
- ```
552
- type Indexed = {} extends Record<string, unknown>
553
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
554
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
555
-
556
- type IndexedResult = Indexed;
557
- //=> '✅ `{}` is assignable to `Record<string, unknown>`'
558
-
559
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
560
- ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
561
- : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
562
-
563
- type KeyedResult = Keyed;
564
- //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
565
- ```
566
-
567
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
568
-
569
- ```
570
- type OmitIndexSignature<ObjectType> = {
571
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
572
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
573
- };
574
- ```
575
-
576
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
577
-
578
- ```
579
- type OmitIndexSignature<ObjectType> = {
580
- [KeyType in keyof ObjectType
581
- // Is `{}` assignable to `Record<KeyType, unknown>`?
582
- as {} extends Record<KeyType, unknown>
583
- ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
584
- : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
585
- ]: ObjectType[KeyType];
586
- };
587
- ```
588
-
589
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
590
-
591
- @example
592
- ```
593
- import type {OmitIndexSignature} from 'type-fest';
594
-
595
- type Example = {
596
- // These index signatures will be removed.
597
- [x: string]: any;
598
- [x: number]: any;
599
- [x: symbol]: any;
600
- [x: `head-${string}`]: string;
601
- [x: `${string}-tail`]: string;
602
- [x: `head-${string}-tail`]: string;
603
- [x: `${bigint}`]: string;
604
- [x: `embedded-${number}`]: string;
605
-
606
- // These explicitly defined keys will remain.
607
- foo: 'bar';
608
- qux?: 'baz';
609
- };
610
-
611
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
612
- //=> {foo: 'bar'; qux?: 'baz'}
613
- ```
614
-
615
- @see {@link PickIndexSignature}
616
- @category Object
617
- */
618
- type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
619
- //#endregion
620
- //#region node_modules/type-fest/source/pick-index-signature.d.ts
621
- /**
622
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
623
-
624
- This is the counterpart of `OmitIndexSignature`.
625
-
626
- @example
627
- ```
628
- import type {PickIndexSignature} from 'type-fest';
629
-
630
- declare const symbolKey: unique symbol;
631
-
632
- type Example = {
633
- // These index signatures will remain.
634
- [x: string]: unknown;
635
- [x: number]: unknown;
636
- [x: symbol]: unknown;
637
- [x: `head-${string}`]: string;
638
- [x: `${string}-tail`]: string;
639
- [x: `head-${string}-tail`]: string;
640
- [x: `${bigint}`]: string;
641
- [x: `embedded-${number}`]: string;
642
-
643
- // These explicitly defined keys will be removed.
644
- ['kebab-case-key']: string;
645
- [symbolKey]: string;
646
- foo: 'bar';
647
- qux?: 'baz';
648
- };
649
-
650
- type ExampleIndexSignature = PickIndexSignature<Example>;
651
- // {
652
- // [x: string]: unknown;
653
- // [x: number]: unknown;
654
- // [x: symbol]: unknown;
655
- // [x: `head-${string}`]: string;
656
- // [x: `${string}-tail`]: string;
657
- // [x: `head-${string}-tail`]: string;
658
- // [x: `${bigint}`]: string;
659
- // [x: `embedded-${number}`]: string;
660
- // }
661
- ```
662
-
663
- @see {@link OmitIndexSignature}
664
- @category Object
665
- */
666
- type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
667
- //#endregion
668
- //#region node_modules/type-fest/source/merge.d.ts
669
- // Merges two objects without worrying about index signatures.
670
- type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
671
- /**
672
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
673
-
674
- This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
675
-
676
- @example
677
- ```
678
- import type {Merge} from 'type-fest';
679
-
680
- type Foo = {
681
- a: string;
682
- b: number;
683
- };
684
-
685
- type Bar = {
686
- a: number; // Conflicts with Foo['a']
687
- c: boolean;
688
- };
689
-
690
- // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
691
- type WithIntersection = (Foo & Bar)['a'];
692
- //=> never
693
-
694
- // With `Merge`, `a` is cleanly overridden to `number`.
695
- type WithMerge = Merge<Foo, Bar>['a'];
696
- //=> number
697
- ```
698
-
699
- @example
700
- ```
701
- import type {Merge} from 'type-fest';
702
-
703
- type Foo = {
704
- [x: string]: unknown;
705
- [x: number]: unknown;
706
- foo: string;
707
- bar: symbol;
708
- };
709
-
710
- type Bar = {
711
- [x: number]: number;
712
- [x: symbol]: unknown;
713
- bar: Date;
714
- baz: boolean;
715
- };
716
-
717
- export type FooBar = Merge<Foo, Bar>;
718
- //=> {
719
- // [x: string]: unknown;
720
- // [x: number]: number;
721
- // [x: symbol]: unknown;
722
- // foo: string;
723
- // bar: Date;
724
- // baz: boolean;
725
- // }
726
- ```
727
-
728
- Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
729
-
730
- @see {@link ObjectMerge}
731
- @category Object
732
- */
733
- type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
734
- ? Source extends unknown // For distributing `Source`
735
- ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
736
- : never;
737
- // Should never happen
738
- type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
739
- //#endregion
740
- //#region node_modules/type-fest/source/internal/object.d.ts
741
- /**
742
- Works similar to the built-in `Pick` utility type, except for the following differences:
743
- - Distributes over union types and allows picking keys from any member of the union type.
744
- - Primitives types are returned as-is.
745
- - Picks all keys if `Keys` is `any`.
746
- - Doesn't pick `number` from a `string` index signature.
747
-
748
- @example
749
- ```
750
- type ImageUpload = {
751
- url: string;
752
- size: number;
753
- thumbnailUrl: string;
754
- };
755
-
756
- type VideoUpload = {
757
- url: string;
758
- duration: number;
759
- encodingFormat: string;
760
- };
761
-
762
- // Distributes over union types and allows picking keys from any member of the union type
763
- type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
764
- //=> {url: string; size: number} | {url: string; duration: number}
765
-
766
- // Primitive types are returned as-is
767
- type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
768
- //=> string | number
769
-
770
- // Picks all keys if `Keys` is `any`
771
- type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
772
- //=> {a: 1; b: 2} | {c: 3}
773
-
774
- // Doesn't pick `number` from a `string` index signature
775
- type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
776
- //=> {}
777
- */
778
- type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
779
- /**
780
- Merges user specified options with default options.
781
-
782
- @example
783
- ```
784
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
785
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
786
- type SpecifiedOptions = {leavesOnly: true};
787
-
788
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
789
- //=> {maxRecursionDepth: 10; leavesOnly: true}
790
- ```
791
-
792
- @example
793
- ```
794
- // Complains if default values are not provided for optional options
795
-
796
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
797
- type DefaultPathsOptions = {maxRecursionDepth: 10};
798
- type SpecifiedOptions = {};
799
-
800
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
801
- // ~~~~~~~~~~~~~~~~~~~
802
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
803
- ```
804
-
805
- @example
806
- ```
807
- // Complains if an option's default type does not conform to the expected type
808
-
809
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
810
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
811
- type SpecifiedOptions = {};
812
-
813
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
814
- // ~~~~~~~~~~~~~~~~~~~
815
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
816
- ```
817
-
818
- @example
819
- ```
820
- // Complains if an option's specified type does not conform to the expected type
821
-
822
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
823
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
824
- type SpecifiedOptions = {leavesOnly: 'yes'};
825
-
826
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
827
- // ~~~~~~~~~~~~~~~~
828
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
829
- ```
830
- */
831
- type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
832
- //#endregion
833
- //#region node_modules/type-fest/source/except.d.ts
834
- /**
835
- Filter out keys from an object.
836
-
837
- Returns `never` if `Exclude` is strictly equal to `Key`.
838
- Returns `never` if `Key` extends `Exclude`.
839
- Returns `Key` otherwise.
840
-
841
- @example
842
- ```
843
- type Filtered = Filter<'foo', 'foo'>;
844
- //=> never
845
- ```
846
-
847
- @example
848
- ```
849
- type Filtered = Filter<'bar', string>;
850
- //=> never
851
- ```
852
-
853
- @example
854
- ```
855
- type Filtered = Filter<'bar', 'foo'>;
856
- //=> 'bar'
857
- ```
858
-
859
- @see {Except}
860
- */
861
- type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
862
- type ExceptOptions = {
863
- /**
864
- Disallow assigning non-specified properties.
865
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
866
- @default false
867
- */
868
- requireExactProps?: boolean;
869
- };
870
- type DefaultExceptOptions = {
871
- requireExactProps: false;
872
- };
873
- /**
874
- Create a type from an object type without certain keys.
875
-
876
- We recommend setting the `requireExactProps` option to `true`.
877
-
878
- This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
879
-
880
- This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
881
-
882
- @example
883
- ```
884
- import type {Except} from 'type-fest';
885
-
886
- type Foo = {
887
- a: number;
888
- b: string;
889
- };
890
-
891
- type FooWithoutA = Except<Foo, 'a'>;
892
- //=> {b: string}
893
-
894
- // @ts-expect-error
895
- const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
896
- // errors: 'a' does not exist in type '{ b: string; }'
897
-
898
- type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
899
- //=> {a: number} & Partial<Record<'b', never>>
900
-
901
- // @ts-expect-error
902
- const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
903
- // errors at 'b': Type 'string' is not assignable to type 'undefined'.
904
-
905
- // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
906
-
907
- // Consider the following example:
908
-
909
- type UserData = {
910
- [metadata: string]: string;
911
- email: string;
912
- name: string;
913
- role: 'admin' | 'user';
914
- };
915
-
916
- // `Omit` clearly doesn't behave as expected in this case:
917
- type PostPayload = Omit<UserData, 'email'>;
918
- //=> {[x: string]: string; [x: number]: string}
919
-
920
- // In situations like this, `Except` works better.
921
- // It simply removes the `email` key while preserving all the other keys.
922
- type PostPayloadFixed = Except<UserData, 'email'>;
923
- //=> {[x: string]: string; name: string; role: 'admin' | 'user'}
924
- ```
925
-
926
- @category Object
927
- */
928
- type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
929
- type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
930
- //#endregion
931
- //#region node_modules/type-fest/source/set-optional.d.ts
932
- /**
933
- Create a type that makes the given keys optional, while keeping the remaining keys as is.
934
-
935
- Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
936
-
937
- @example
938
- ```
939
- import type {SetOptional} from 'type-fest';
940
-
941
- type Foo = {
942
- a: number;
943
- b?: string;
944
- c: boolean;
945
- };
946
-
947
- type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
948
- //=> {a: number; b?: string; c?: boolean}
949
- ```
950
-
951
- @category Object
952
- */
953
- type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
954
- type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
955
- ? Simplify< // Pick just the keys that are readonly from the base type.
956
- Except<BaseType, Keys> // Pick the keys that should be mutable from the base type and make them mutable.
957
- & Partial<HomomorphicPick<BaseType, Keys>>> : never;
958
- //#endregion
959
142
  //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/preview.d.ts
960
143
  /**
961
144
  * Creates a Web Components-specific preview configuration with CSF factories support.
@@ -979,10 +162,6 @@ Except<BaseType, Keys> // Pick the keys that should be mutable from the base typ
979
162
  declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
980
163
  addons: Addons;
981
164
  } & ProjectAnnotations<WebComponentsTypes & InferTypes<Addons>>): WebComponentsPreview<WebComponentsTypes & InferTypes<Addons>>;
982
- type InferArgs<TArgs, T, Decorators> = Simplify<TArgs & Simplify<OmitIndexSignature<DecoratorsArgs<WebComponentsTypes & T, Decorators>>>>;
983
- type InferWebComponentsTypes<T, TArgs, Decorators> = WebComponentsTypes & T & {
984
- args: Simplify<InferArgs<TArgs, T, Decorators>>;
985
- };
986
165
  /**
987
166
  * Infers args from a web component's HTMLElement type, allowing both camelCase properties and
988
167
  * kebab-case HTML attribute names (e.g., 'aria-label', 'data-testid', 'static-color').
@@ -1016,23 +195,14 @@ interface WebComponentsPreview<T extends AddonTypes> extends Preview$1<WebCompon
1016
195
  * ```
1017
196
  */
1018
197
  type<S>(): WebComponentsPreview<T & S>;
1019
- meta<C extends keyof HTMLElementTagNameMap, Decorators extends DecoratorFunction<WebComponentsTypes & T, any>, TMetaArgs extends InferArgsFromComponent<C> & Partial<T['args']>>(meta: {
1020
- component?: C;
1021
- args?: TMetaArgs;
1022
- decorators?: Decorators | Decorators[];
1023
- } & Omit<ComponentAnnotations<WebComponentsTypes & T, InferArgsFromComponent<C> & T['args']>, 'decorators' | 'component' | 'args'>): WebComponentsMeta<InferWebComponentsTypes<T, InferArgsFromComponent<C>, Decorators>, Omit<ComponentAnnotations<InferWebComponentsTypes<T, InferArgsFromComponent<C>, Decorators>>, 'args'> & {
1024
- args: {} extends TMetaArgs ? {} : TMetaArgs;
1025
- }>;
1026
- meta<TArgs, Decorators extends DecoratorFunction<WebComponentsTypes & T, any>, TMetaArgs extends Partial<TArgs>>(meta: {
1027
- render?: ArgsStoryFn<WebComponentsTypes & T, TArgs>;
1028
- args?: TMetaArgs;
1029
- decorators?: Decorators | Decorators[];
1030
- } & Omit<ComponentAnnotations<WebComponentsTypes & T, TArgs & T['args']>, 'decorators' | 'component' | 'args' | 'render'>): WebComponentsMeta<InferWebComponentsTypes<T, TArgs, Decorators>, Omit<ComponentAnnotations<InferWebComponentsTypes<T, TArgs, Decorators>>, 'args'> & {
1031
- args: {} extends TMetaArgs ? {} : TMetaArgs;
1032
- }>;
198
+ meta<C extends keyof HTMLElementTagNameMap = never, Decorators extends DecoratorFunction<WebComponentsTypes & T, any> = DecoratorFunction<WebComponentsTypes & T, any>, TRenderArgs = unknown, TMetaArgKeys extends PropertyKey = never>(meta: {
199
+ component: C;
200
+ render?: ArgsStoryFn<WebComponentsTypes & T, InferArgsFromComponent<C> & TRenderArgs & T['args']>;
201
+ } & MetaInput<WebComponentsTypes & T, WithRenderArgs<InferArgsFromComponent<C>, TRenderArgs>, Decorators, TMetaArgKeys>): WebComponentsMeta<MetaTypes<WebComponentsTypes & T, WithRenderArgs<InferArgsFromComponent<C>, TRenderArgs>, Decorators, TMetaArgKeys>, TMetaArgKeys>;
202
+ meta<TArgs = Args$1, Decorators extends DecoratorFunction<WebComponentsTypes & T, any> = DecoratorFunction<WebComponentsTypes & T, any>, TMetaArgKeys extends PropertyKey = never>(meta: {
203
+ render?: ArgsStoryFn<WebComponentsTypes & T, TArgs & T['args']>;
204
+ } & MetaInput<WebComponentsTypes & T, TArgs, Decorators, TMetaArgKeys>): WebComponentsMeta<MetaTypes<WebComponentsTypes & T, TArgs, Decorators, TMetaArgKeys>, TMetaArgKeys>;
1033
205
  }
1034
- /** Extracts and unions all args types from an array of decorators. */
1035
- type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
1036
206
  /**
1037
207
  * Web Components-specific Meta interface returned by `preview.meta()`.
1038
208
  *
@@ -1040,7 +210,7 @@ type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersectio
1040
210
  * provided in meta become optional in stories, while missing required args must be provided at the
1041
211
  * story level.
1042
212
  */
1043
- interface WebComponentsMeta<T extends WebComponentsTypes, MetaInput extends ComponentAnnotations<T>> /** @ts-expect-error WebComponentsMeta requires two type parameters, but Meta's constraints differ */ extends Meta$1<T, MetaInput> {
213
+ interface WebComponentsMeta<T extends WebComponentsTypes, TMetaArgKeys extends PropertyKey = never> extends Meta$1<T, TMetaArgKeys> {
1044
214
  /**
1045
215
  * Creates a story with a custom render function that takes no args.
1046
216
  *
@@ -1086,12 +256,12 @@ interface WebComponentsMeta<T extends WebComponentsTypes, MetaInput extends Comp
1086
256
  * });
1087
257
  * ```
1088
258
  */
1089
- story<TInput extends Simplify<StoryAnnotations<T, T['args'], SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story: TInput): WebComponentsStory<T, TInput>;
259
+ story<TInput extends Simplify<StoryAnnotations<T, T['args'], StoryArgs<T['args'], TMetaArgKeys>>>>(story: TInput): WebComponentsStory<T, TInput>;
1090
260
  /**
1091
261
  * Creates a story with no additional configuration.
1092
262
  *
1093
263
  * This overload is only available when all required args have been provided in meta. The
1094
- * conditional type `Partial<T['args']> extends SetOptional<...>` checks if the remaining required
264
+ * conditional type `Partial<T['args']> extends StoryArgs<...>` checks if the remaining required
1095
265
  * args (after accounting for args provided in meta) are all optional. If so, the function accepts
1096
266
  * zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
1097
267
  * forcing the user to provide args.
@@ -1104,7 +274,12 @@ interface WebComponentsMeta<T extends WebComponentsTypes, MetaInput extends Comp
1104
274
  * export const Default = meta.story(); // Valid - all args provided in meta
1105
275
  * ```
1106
276
  */
1107
- story(..._args: Partial<T['args']> extends SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']> ? [] : [never]): WebComponentsStory<T, {}>;
277
+ story(..._args: Partial<T['args']> extends StoryArgs<T['args'], TMetaArgKeys> ? [] : [never]): WebComponentsStory<T, {}>;
278
+ /**
279
+ * Add types to the stories created from the returned meta, such as an arg that only one story
280
+ * has: `meta.type<{ args: { icon: string } }>().story({ args: { icon: 'star' } })`.
281
+ */
282
+ type<S>(): WebComponentsMeta<T & S, TypedMetaArgKeys<TMetaArgKeys, S>>;
1108
283
  }
1109
284
  /**
1110
285
  * Web Components-specific Story interface returned by `meta.story()`.
@@ -1114,4 +289,4 @@ interface WebComponentsMeta<T extends WebComponentsTypes, MetaInput extends Comp
1114
289
  */
1115
290
  interface WebComponentsStory<T extends WebComponentsTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {}
1116
291
  //#endregion
1117
- export { type ArgTypes, type Args, Decorator, Loader, Meta, type Parameters$1 as Parameters, Preview, StoryContext, StoryFn, StoryObj, type StrictArgs, WebComponentsMeta, WebComponentsPreview, type WebComponentsRenderer, WebComponentsStory, type WebComponentsTypes, __definePreview, getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };
292
+ export { type ArgTypes, type Args, Decorator, Loader, Meta, type Parameters, Preview, StoryContext, StoryFn, StoryObj, type StrictArgs, type WebComponentsFrameworkOptions, WebComponentsMeta, WebComponentsPreview, type WebComponentsRenderer, WebComponentsStory, type WebComponentsTypes, __definePreview, getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };