@cobalt-ui/core
Advanced tools
Comparing version 1.0.0 to 1.1.0
# @cobalt-ui/core | ||
## 1.1.0 | ||
### Minor Changes | ||
- [#30](https://github.com/drwpow/cobalt-ui/pull/30) [`482f5cd`](https://github.com/drwpow/cobalt-ui/commit/482f5cd4dfd7dd5bf71b64ae1f103322e6709717) Thanks [@drwpow](https://github.com/drwpow)! - Deprecate Figma sync CLI and core functionality (in favor of Tokens Studio support) | ||
- [#30](https://github.com/drwpow/cobalt-ui/pull/30) [`482f5cd`](https://github.com/drwpow/cobalt-ui/commit/482f5cd4dfd7dd5bf71b64ae1f103322e6709717) Thanks [@drwpow](https://github.com/drwpow)! - Add Tokens Studio support | ||
### Patch Changes | ||
- [#33](https://github.com/drwpow/cobalt-ui/pull/33) [`eb942a7`](https://github.com/drwpow/cobalt-ui/commit/eb942a7c50a7afd48e73c0f652f34f71f01db68f) Thanks [@drwpow](https://github.com/drwpow)! - Remove unused deps | ||
- [#30](https://github.com/drwpow/cobalt-ui/pull/30) [`482f5cd`](https://github.com/drwpow/cobalt-ui/commit/482f5cd4dfd7dd5bf71b64ae1f103322e6709717) Thanks [@drwpow](https://github.com/drwpow)! - Fix bug where $value: `0` wasn’t a valid value | ||
- Updated dependencies [[`152f666`](https://github.com/drwpow/cobalt-ui/commit/152f66661de125e1c4b9d872794bbcff8b51de8f)]: | ||
- @cobalt-ui/utils@1.1.0 | ||
## 1.0.0 | ||
@@ -4,0 +21,0 @@ |
{ | ||
"name": "@cobalt-ui/core", | ||
"description": "CLI for using the W3C design token format", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -20,12 +20,10 @@ "name": "Drew Powers", | ||
"dependencies": { | ||
"@cobalt-ui/utils": "1.0.0", | ||
"@types/csso": "^5.0.0", | ||
"better-color-tools": "^0.10.2", | ||
"svgo": "^3.0.2" | ||
"@cobalt-ui/utils": "^1.1.0", | ||
"better-color-tools": "^0.12.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.16.0", | ||
"esbuild": "^0.17.18", | ||
"@types/node": "^20.2.5", | ||
"esbuild": "^0.17.19", | ||
"npm-run-all": "^4.1.5", | ||
"vitest": "^0.30.1" | ||
"vitest": "^0.31.4" | ||
}, | ||
@@ -32,0 +30,0 @@ "scripts": { |
@@ -1,2 +0,1 @@ | ||
import type SVGO from 'svgo'; | ||
import type {Group, ParsedToken} from './token.js'; | ||
@@ -55,29 +54,2 @@ export type { | ||
export interface FigmaDoc { | ||
url: string; | ||
tokens: FigmaToken[]; | ||
} | ||
export interface FigmaToken { | ||
style?: string; | ||
component?: string; | ||
token: string; | ||
type: string; | ||
filename?: string; | ||
/** optional: override default optimization settings for this instance */ | ||
optimize?: FigmaOptimizationSettings | boolean; | ||
} | ||
export interface FigmaOptimizationSettings { | ||
/** Default SVGO settings */ | ||
svgo?: SVGO.Config | boolean; | ||
} | ||
export interface FigmaSettings { | ||
/** Figma docs to sync (required if "figma" is specified) */ | ||
docs: FigmaDoc[]; | ||
/** set default optimizations */ | ||
optimize?: FigmaOptimizationSettings | boolean; | ||
} | ||
export interface ResolvedConfig { | ||
@@ -87,3 +59,2 @@ tokens: URL; | ||
plugins: Plugin[]; | ||
figma?: FigmaSettings; | ||
} | ||
@@ -106,4 +77,2 @@ | ||
plugins: Plugin[]; | ||
/** map Figma styles & components to tokens.json */ | ||
figma?: FigmaSettings; | ||
} | ||
@@ -110,0 +79,0 @@ |
@@ -1,2 +0,2 @@ | ||
import {cloneDeep, FG_YELLOW, RESET} from '@cobalt-ui/utils'; | ||
import {cloneDeep, FG_YELLOW, getAliasID, isAlias, RESET} from '@cobalt-ui/utils'; | ||
import type {Group, ParsedToken, TokenType, TokenOrGroup} from '../token.js'; | ||
@@ -18,2 +18,3 @@ import {isEmpty, isObj, splitType} from '../util.js'; | ||
import {normalizeNumberValue} from './tokens/number.js'; | ||
import {convertTokensStudioFormat, isTokensStudioFormat} from './tokens-studio.js'; | ||
@@ -29,12 +30,17 @@ export interface ParseResult { | ||
const ALIAS_RE = /^\{([^}]+)\}$/; | ||
interface InheritedGroup { | ||
$type?: TokenType; | ||
$extensions: { | ||
requiredModes: string[]; | ||
}; | ||
} | ||
const RESERVED_KEYS = new Set(['$description', '$name', '$type', '$value', '$extensions']); | ||
export function parse(schema: Group): ParseResult { | ||
export function parse(rawTokens: unknown): ParseResult { | ||
const errors: string[] = []; | ||
const warnings: string[] = []; | ||
const result: ParseResult = {result: {metadata: {}, tokens: []}}; | ||
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) { | ||
errors.push(`Invalid schema type. Expected object, received "${Array.isArray(schema) ? 'Array' : typeof schema}"`); | ||
if (!rawTokens || typeof rawTokens !== 'object' || Array.isArray(rawTokens)) { | ||
errors.push(`Invalid schema type. Expected object, received "${Array.isArray(rawTokens) ? 'Array' : typeof rawTokens}"`); | ||
result.errors = errors; | ||
@@ -44,7 +50,10 @@ return result; | ||
interface InheritedGroup { | ||
$type?: TokenType; | ||
$extensions: { | ||
requiredModes: string[]; | ||
}; | ||
// 0. handle Tokens Studio for Figma format | ||
let schema = rawTokens as Group; | ||
if (isTokensStudioFormat(rawTokens)) { | ||
const tokensStudioResult = convertTokensStudioFormat(rawTokens as Group); | ||
errors.push(...(tokensStudioResult.errors ?? [])); | ||
warnings.push(...(tokensStudioResult.warnings ?? [])); | ||
schema = tokensStudioResult.result; | ||
} | ||
@@ -138,3 +147,3 @@ | ||
if (k.startsWith('$')) { | ||
if (k === '$extensions') group.$extensions = {...group.$extensions, ...schema.$extensions}; | ||
if (k === '$extensions') group.$extensions = {...schema.$extensions, ...group.$extensions}; | ||
else (group as any)[k] = schema[k]; | ||
@@ -176,5 +185,5 @@ if (!RESERVED_KEYS.has(k)) { | ||
string(strVal) { | ||
if (!ALIAS_RE.test(strVal)) return strVal; | ||
if (!isAlias(strVal)) return strVal; | ||
const nextID = getAliasID(strVal); | ||
if (!values[nextID]) { | ||
if (!(nextID in values)) { | ||
throw new Error(`${id}: can’t find ${strVal}`); | ||
@@ -185,3 +194,3 @@ } | ||
const ref = values[nextID] as string; | ||
if (typeof ref === 'string' && ALIAS_RE.test(ref) && id === getAliasID(ref)) { | ||
if (typeof ref === 'string' && isAlias(ref) && id === getAliasID(ref)) { | ||
throw new Error(`${id}: can’t reference circular alias ${strVal}`); | ||
@@ -366,6 +375,6 @@ } | ||
default: () => false, | ||
string: (value) => ALIAS_RE.test(value), | ||
string: (value) => isAlias(value), | ||
array: (value) => | ||
value.some((part) => { | ||
if (typeof part === 'string') return ALIAS_RE.test(part); | ||
if (typeof part === 'string') return isAlias(part); | ||
if (isObj(part)) return unaliasedValues(part as Record<string, unknown>); | ||
@@ -378,7 +387,1 @@ return false; | ||
} | ||
function getAliasID(input: string): string { | ||
const match = input.match(ALIAS_RE); | ||
if (!match) return input; | ||
return match[1]; | ||
} |
@@ -23,3 +23,3 @@ import type {ShadowValue} from '../../token.js'; | ||
const v = value as any; | ||
['offsetX', 'offsetX', 'blur', 'spread', 'color'].forEach((k) => { | ||
for (const k of ['offsetX', 'offsetX', 'blur', 'spread', 'color']) { | ||
if (typeof v[k] === 'number' && v[k] > 0) throw new Error(`${k} missing units`); | ||
@@ -29,3 +29,3 @@ if (k === 'offsetX' || k === 'offsetY') { | ||
} | ||
}); | ||
} | ||
return { | ||
@@ -32,0 +32,0 @@ offsetX: normalizeDimensionValue(v.offsetX || '0'), |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2
54134
23
1313
1
+ Added@cobalt-ui/utils@1.2.6(transitive)
+ Addedbetter-color-tools@0.12.3(transitive)
- Removed@types/csso@^5.0.0
- Removedsvgo@^3.0.2
- Removed@cobalt-ui/utils@1.0.0(transitive)
- Removed@trysound/sax@0.2.0(transitive)
- Removed@types/css-tree@2.3.10(transitive)
- Removed@types/csso@5.0.4(transitive)
- Removedbetter-color-tools@0.10.2(transitive)
- Removedboolbase@1.0.0(transitive)
- Removedcommander@7.2.0(transitive)
- Removedcss-select@5.1.0(transitive)
- Removedcss-tree@2.2.12.3.1(transitive)
- Removedcss-what@6.1.0(transitive)
- Removedcsso@5.0.5(transitive)
- Removeddom-serializer@2.0.0(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@5.0.3(transitive)
- Removeddomutils@3.2.2(transitive)
- Removedentities@4.5.0(transitive)
- Removedmdn-data@2.0.282.0.30(transitive)
- Removednth-check@2.1.1(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedsource-map-js@1.2.1(transitive)
- Removedsvgo@3.3.2(transitive)
Updated@cobalt-ui/utils@^1.1.0
Updatedbetter-color-tools@^0.12.3