Skip to content

Commit

Permalink
Merge pull request #20 from maxholman/refactor-variants
Browse files Browse the repository at this point in the history
fix: token and var export and generation
  • Loading branch information
maxholman authored Jun 24, 2024
2 parents de5dc62 + ca609ba commit ecd08d4
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 247 deletions.
43 changes: 7 additions & 36 deletions bin/token.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-restricted-syntax */
import { createWriteStream } from 'node:fs';
import { PassThrough } from 'node:stream';
import { parseArgs } from 'node:util';
import { camelCase } from 'change-case';
import { leafNodeMapper, type PathStr, type VarFn, vargEx } from './utils.js';
import {
formControlTokens,
globalTokens,
panelTokens,
propsTokens,
} from '#defaults';
import {
badgeVars,
badgeVarsMapFnPrefix,
buttonVars,
buttonVarsMapFnPrefix,
formControlVarsMapFnPrefix,
globalVars,
globalVarsMapFnPrefix,
panelVars,
panelVarsMapFnPrefix,
propsVars,
propsVarsMapFnPrefix,
} from '#vars';
import { vars, tokens } from '#vars';

const {
values: { type, outputPath },
Expand All @@ -40,39 +21,29 @@ const {
},
},
});

/**
* vars
*/
const knownVars = new Map<VarFn, { path: PathStr }>();
for (const [vars, prefix] of [
[globalVars, globalVarsMapFnPrefix] as const,
[propsVars, propsVarsMapFnPrefix] as const,
[panelVars, panelVarsMapFnPrefix] as const,
[badgeVars, badgeVarsMapFnPrefix] as const,
[buttonVars, buttonVarsMapFnPrefix] as const,
]) {
for (const [prefix, v] of Object.entries(vars)) {
leafNodeMapper(
vars,
v,
(path, value) => {
knownVars.set(value, { path });
},
[prefix],
);
}

/**
/*
* tokens
*/
const knownTokens = new Map<VarFn, { value: string }>();

for (const [vars, prefix] of [
[globalTokens, globalVarsMapFnPrefix] as const,
[propsTokens, propsVarsMapFnPrefix] as const,
[panelTokens, panelVarsMapFnPrefix] as const,
[formControlTokens, formControlVarsMapFnPrefix] as const,
]) {
for (const [prefix, t] of Object.entries(tokens)) {
leafNodeMapper(
vars,
t,
(path, value) => {
knownTokens.set(path, { value });
},
Expand Down
6 changes: 3 additions & 3 deletions lib/css-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { calc } from '@vanilla-extract/css-utils';

export function createGlobalThemeMapFn(prefix = '') {
const delim = '-';
const fullPrefix = prefix ? `${prefix}${delim}` : '';
export function createGlobalThemeMapFn<T extends string>(prefix: T) {
const delim = '-' as const;
const fullPrefix = prefix ? (`${prefix}${delim}` as const) : ('' as const);
return Object.assign(
(value: string | null, path: Array<string>) =>
`${fullPrefix}${value}${path.join(delim)}`,
Expand Down
133 changes: 0 additions & 133 deletions lib/defaults.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export * from './icons.js';
export * from './virtual.js';
export * from './panel.js';

export type { ReactHTMLElementsHacked } from './types.js';
export type { ReactHTMLElementsHacked, Falsy } from './types.js';
Loading

0 comments on commit ecd08d4

Please sign in to comment.