feat: migrated packages to ts

This commit is contained in:
Haoyu Xu
2025-05-02 02:27:42 +08:00
parent 0af0c785d4
commit 8f6f537c81
111 changed files with 3166 additions and 1155 deletions

View File

@@ -1,11 +1,20 @@
import type { OperatorConfig, Codename } from '@aklive2d/operator/types'
import type { Assets } from '../types.ts'
export default class Matcher {
#start
#end
#reExp
#config
#assets
content: string = ''
constructor(start, end, config, assets) {
constructor(
start: string,
end: string,
config: OperatorConfig,
assets: Assets
) {
this.#start = start
this.#end = end
this.#reExp = new RegExp(`${start}.+?${end}`, 'g')
@@ -40,27 +49,50 @@ class Evalable {
#config
#assets
constructor(config, assets) {
constructor(config: OperatorConfig, assets: Assets) {
this.#config = config
this.#assets = assets
}
split(location, varName, separator) {
return this.#step(location, varName).split(separator)
split(location: 'config' | 'assets', varName: string, separator: string) {
return (this.#step(location, varName) as string).split(separator)
}
var(location, varName) {
var(location: 'config' | 'assets', varName: string) {
return this.#step(location, varName)
}
#step(location, varName) {
let content = this.#config
#step(
location: 'config' | 'assets',
varName: string
):
| OperatorConfig
| Assets
| string
| number
| boolean
| Codename
| string[] {
let content:
| OperatorConfig
| Assets
| string
| number
| boolean
| Codename
| string[] = this.#config
if (location === 'assets') content = this.#assets
varName.split('->').forEach((item) => {
try {
content = content[item]
} catch (e) {
throw new Error(`Cannot step ${varName}.`, e)
if (location === 'config') {
content = (content as OperatorConfig)[
item as keyof OperatorConfig
]
} else {
content = (content as Assets)[item as keyof Assets]
}
} catch (e: unknown) {
throw new Error(`Cannot step ${varName}. ${e}`)
}
})
return content