import { SpecifyDesignTokenTypeName, TokenState } from '@specifyapp/specify-design-token-format'; const TYPE_ALIAS: { [k in SpecifyDesignTokenTypeName]?: string } = { dimension: 'size', breakpoint: 'size', fontWeight: 'size', spacing: 'size', spacings: 'size', duration: 'time', radius: 'borderRadius', cubicBezier: 'easing', shadows: 'shadow', gradients: 'gradient', bitmap: 'asset', vector: 'asset', font: 'asset', }; /* v8 ignore start */ export function sdtfTypeToSdType(sdtfType: SpecifyDesignTokenTypeName) { return TYPE_ALIAS[sdtfType] ?? sdtfType; } /* v8 ignore stop */ export function makeFileName( type: SpecifyDesignTokenTypeName, token: TokenState, mode: string, ): [string, string] { const collection = token.getCollection()?.name; const tokenType = TYPE_ALIAS[type] ?? type; const [fileNameGroup, nestingGroup] = (() => { if (token.path.length < 2) return [undefined, []]; if (token.path.at(0) === collection && token.path.at(1) === token.name) return [undefined, []]; else if (token.path.at(0) === collection) { return [token.path.at(1), token.path.toArray().slice(2, token.path.length - 1)]; } else return [token.path.at(0), token.path.toArray().slice(1, token.path.length - 1)]; })(); const path = mode === 'default' ? `${tokenType}/${fileNameGroup ?? 'base'}` : !!fileNameGroup ? `${tokenType}/${mode}/${fileNameGroup}` : `${tokenType}/${mode}`; return [!!collection ? `${collection}/${path}` : path, nestingGroup.join('.')]; }