mirror of
https://github.com/hanzoai/gui.git
synced 2026-10-25 02:31:41 +00:00
Both old names are owned by a different npm account (artemis-prime), so publishing them returns 403 — which is how this surfaced: the 8.0.0 run shipped @hanzogui/logo and @hanzogui/demos depending on [email protected], a version that cannot be published and therefore does not exist. Those two were uninstallable. @hanzo/gui and @hanzogui/* are ours, so the framework now carries the name it is imported by everywhere downstream, and the loader moves under the scope we control. The rewrite is limited to package references. `DEBUG?.startsWith('hanzogui')` is a log-namespace filter and join(dir, 'hanzogui') is a path — rewriting either would change behaviour, so both are untouched. Co-authored-by: Hanzo Dev <[email protected]>
78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import type { ColorsStore } from './ColorsStore'
|
|
import type { useGlobalState } from './useGlobalState'
|
|
|
|
const generateColorConfig = (input: ColorsStore) => {
|
|
const colors: Record<string, string> = {}
|
|
|
|
for (const palette of Object.values(input.palettesByScheme)) {
|
|
for (const scale of Object.values(palette.scales)) {
|
|
let idx = 0
|
|
for (const color of scale.colors) {
|
|
const colorKey = [`${scale.name}${idx + 1}`]
|
|
const key = `${colorKey}${palette.name}`
|
|
colors[key] = `hsl(${color.hue}, ${color.saturation}%, ${color.lightness}%)`
|
|
idx++
|
|
}
|
|
}
|
|
}
|
|
|
|
return colors
|
|
}
|
|
|
|
/**
|
|
* generates full output snippet
|
|
*/
|
|
export const generateOutput = (globalStore: ReturnType<typeof useGlobalState>) => {
|
|
const animations = globalStore.animations.draftAnimations
|
|
|
|
return `import { config as baseConfig } from '@hanzogui/config/v3'
|
|
import { createGui } from '@hanzo/gui'
|
|
import { createAnimations } from '@hanzogui/animations-react-native'
|
|
|
|
const animations = createAnimations({
|
|
${objToStr({ type: 'object', value: animations })}
|
|
})
|
|
|
|
export const config = createGui({
|
|
${objToStr(
|
|
{ type: 'spread', value: 'baseConfig' },
|
|
{ type: 'value', value: 'animations' },
|
|
{
|
|
type: 'value',
|
|
value: `tokens: {
|
|
${objToStr(
|
|
{ type: 'spread', value: 'baseConfig.tokens' },
|
|
{
|
|
type: 'value',
|
|
value: `color: {
|
|
${objToStr({ type: 'object', value: generateColorConfig(globalStore.colors) })}
|
|
}`,
|
|
}
|
|
)}}`,
|
|
}
|
|
)}
|
|
})
|
|
`
|
|
}
|
|
|
|
type ObjToStrInput =
|
|
| { type: 'spread'; value: string }
|
|
| { type: 'value'; value: string }
|
|
| { type: 'object'; value: any }
|
|
|
|
// TODO: this helper could be much better
|
|
const objToStr = (...input: ObjToStrInput[]) => {
|
|
let output: string[] = []
|
|
for (const item of input) {
|
|
if (item.type === 'spread') {
|
|
output.push(` ...${item.value},`)
|
|
} else if (item.type === 'value') {
|
|
output.push(` ${item.value},`)
|
|
} else if (item.type === 'object') {
|
|
const lines = JSON.stringify(item.value, null, 2).split('\n')
|
|
output.push(`${lines.slice(1, lines.length - 1).join('\n')}`)
|
|
}
|
|
}
|
|
return output.join('\n')
|
|
}
|