Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Dec 7, 2023
1 parent 4df3165 commit 2511e2a
Show file tree
Hide file tree
Showing 43 changed files with 4,390 additions and 853 deletions.
18 changes: 9 additions & 9 deletions packages/class-variant/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import clsx from 'clsx'

type Param<T> = string
type Param<T> = string
| string[]
| Record<string, boolean>
| [string, { [key in keyof T]?: T[key] }]
| { [key in keyof T]?: T[key] extends boolean | undefined ? string : Record<string, string> }
| ((valueByProp: T) => any)
type ReturnType<T> = { default?: Partial<T> } & ((valueByProp?: T) => string)
type ReturnType<T> = { default?: Partial<T> } & ((valueByProp?: T) => string)

/**
* 1. 'inline-flex rounded'
Expand All @@ -20,7 +20,7 @@ function cv<T extends Record<string, string | number | boolean>>(...params: Arra
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray, ...params: Array<Param<T>>): ReturnType<T>
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray | Param<T>, ...params: Array<Param<T>>): ReturnType<T> {
return function getClassNames(valueByProp: T = {} as any) {
const mergedValueByProp = Object.assign({}, getClassNames['default'], valueByProp)
const mergedValueByProp = Object.assign({}, (getClassNames as ReturnType<T>).default, valueByProp)
const isTemplateLiteral = Array.isArray(firstParam) && 'raw' in firstParam
const classesConditions: [string, Record<string, string | number | boolean>][] = []
const valuesByProp: Record<string, Record<string, string>> = {}
Expand All @@ -34,7 +34,7 @@ function cv<T extends Record<string, string | number | boolean>>(firstParam: Tem
const newClassesByCondition = param[1]
if (newClassesByCondition && typeof newClassesByCondition === 'object') {
const keys = Object.keys(newClassesByCondition)

let duplicated = false
for (const eachClassesByCondition of classesConditions) {
const entries = Object.entries(eachClassesByCondition[1])
Expand All @@ -47,7 +47,7 @@ function cv<T extends Record<string, string | number | boolean>>(firstParam: Tem
break
}
}

if (!duplicated) {
classesConditions.push(param as any)
}
Expand Down Expand Up @@ -83,7 +83,7 @@ function cv<T extends Record<string, string | number | boolean>>(firstParam: Tem
}
}
break
}
}
}
}
break
Expand Down Expand Up @@ -126,10 +126,10 @@ function cv<T extends Record<string, string | number | boolean>>(firstParam: Tem
classNames.push(eachClassesByCondition[0])
}
}

for (const eachProp in valuesByProp) {
const value = mergedValueByProp[eachProp] ?? mergedValueByProp['$' + eachProp] ?? ''
const classes = valuesByProp[eachProp][value]
const classes = valuesByProp[eachProp][value as string | number]
if (classes) {
classNames.push(classes)
}
Expand All @@ -148,7 +148,7 @@ function cv<T extends Record<string, string | number | boolean>>(firstParam: Tem
classNames.push(eachClasses)
}
}

let result = classNames.join(' ')
if (isTemplateLiteral) {
result = result.trim().replace(/\n/g, ' ').replace(/ +/g, ' ')
Expand Down
4 changes: 2 additions & 2 deletions packages/css/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ program.command('render')
try {
const action = require('@master/css-renderer/actions/main')
await action(args, options)
} catch (error) {
} catch (error: any) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
log.i`Please run **npm** **install** **@master/css-renderer** first`
} else {
Expand All @@ -88,7 +88,7 @@ program.command('extract')
try {
const action = require('@master/css-extractor/actions/main')
await action(args, options)
} catch (error) {
} catch (error: any) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
log.i`Please run **npm** **install** **@master/css-extractor** first`
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/css/src/config/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FunctionDefinition } from './'
import type { FunctionDefinition, FunctionDefinitions } from './'
import type { Rule } from '../rule'

const functions = {
Expand All @@ -20,7 +20,7 @@ const functions = {
calc: {
transform(value, bypassVariableNames) {
const valueComponents: Rule['valueComponents'] = []
const functions = this.css.config.functions
const functions = this.css.config.functions as FunctionDefinitions
let i = 0
const anaylze = (currentValueComponents: Rule['valueComponents'], bypassHandlingSeparator: boolean, bypassHandlingUnitForcely: boolean) => {
let bypassHandlingUnit = false
Expand Down
8 changes: 5 additions & 3 deletions packages/css/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import type { Rule, RuleDefinition, ValueComponent } from '../rule'
const config: Config = {
mediaQueries,
selectors,
// @ts-expect-error
semantics,
rules,
functions: functions as any,
functions,
// @ts-expect-error
animations,
variables: variables as any,
variables,
scope: '',
rootSize: 16,
override: false,
Expand Down Expand Up @@ -48,7 +50,7 @@ export type SemanticDefinitions = { [key in keyof typeof semantics]?: CSSDeclara
export interface FunctionDefinition {
unit?: string
colored?: boolean
transform?(this: Rule, value: string, bypassVariableNames?: string[]): string | ValueComponent[]
transform?(this: Rule, value: string, bypassVariableNames: string[]): string | ValueComponent[]
}
export type FunctionDefinitions = { [key: string]: FunctionDefinition }

Expand Down
Loading

0 comments on commit 2511e2a

Please sign in to comment.