-
Notifications
You must be signed in to change notification settings - Fork 447
Color links as common type #7211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import type { IColorable } from '@/lib/litegraph/src/interfaces' | ||
| import { without } from 'es-toolkit' | ||
|
|
||
| import type { IColorable, ISlotType } from '@/lib/litegraph/src/interfaces' | ||
|
|
||
| /** | ||
| * Converts a plain object to a class instance if it is not already an instance of the class. | ||
|
|
@@ -26,3 +28,31 @@ export function isColorable(obj: unknown): obj is IColorable { | |
| 'getColorOption' in obj | ||
| ) | ||
| } | ||
|
|
||
| export function commonType(...types: ISlotType[]): ISlotType | undefined { | ||
| if (!isStrings(types)) return undefined | ||
|
|
||
| const withoutWildcards = without(types, '*') | ||
| if (withoutWildcards.length === 0) return '*' | ||
|
|
||
| const typeLists: string[][] = withoutWildcards.map((type) => type.split(',')) | ||
|
|
||
| const combinedTypes = intersection(...typeLists) | ||
| if (combinedTypes.length === 0) return undefined | ||
|
|
||
| return combinedTypes.join(',') | ||
| } | ||
|
|
||
| function intersection(...sets: string[][]): string[] { | ||
| const itemCounts: Record<string, number> = {} | ||
| for (const set of sets) | ||
| for (const item of new Set(set)) | ||
| itemCounts[item] = (itemCounts[item] ?? 0) + 1 | ||
| return Object.entries(itemCounts) | ||
| .filter(([, count]) => count == sets.length) | ||
| .map(([key]) => key) | ||
| } | ||
|
|
||
| function isStrings(types: unknown[]): types is string[] { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little conflicted about moving this here, but I think it's good enough.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intent is less important than how it's currently being used, so I support this. |
||
| return types.every((t) => typeof t === 'string') | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.