@terrazzo/token-tools 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/color.d.ts +1 -9
  2. package/dist/color.js.map +1 -1
  3. package/dist/css/boolean.d.ts +6 -0
  4. package/dist/css/boolean.js +12 -0
  5. package/dist/css/boolean.js.map +1 -0
  6. package/dist/css/border.d.ts +13 -0
  7. package/dist/css/border.js +30 -0
  8. package/dist/css/border.js.map +1 -0
  9. package/dist/css/color.d.ts +13 -0
  10. package/dist/css/color.js +72 -0
  11. package/dist/css/color.js.map +1 -0
  12. package/dist/css/cubic-bezier.d.ts +8 -0
  13. package/dist/css/cubic-bezier.js +11 -0
  14. package/dist/css/cubic-bezier.js.map +1 -0
  15. package/dist/css/dimension.d.ts +6 -0
  16. package/dist/css/dimension.js +12 -0
  17. package/dist/css/dimension.js.map +1 -0
  18. package/dist/css/duration.d.ts +6 -0
  19. package/dist/css/duration.js +12 -0
  20. package/dist/css/duration.js.map +1 -0
  21. package/dist/css/font-family.d.ts +7 -0
  22. package/dist/css/font-family.js +22 -0
  23. package/dist/css/font-family.js.map +1 -0
  24. package/dist/css/font-weight.d.ts +6 -0
  25. package/dist/css/font-weight.js +9 -0
  26. package/dist/css/font-weight.js.map +1 -0
  27. package/dist/css/gradient.d.ts +9 -0
  28. package/dist/css/gradient.js +24 -0
  29. package/dist/css/gradient.js.map +1 -0
  30. package/dist/css/index.d.ts +25 -162
  31. package/dist/css/index.js +93 -315
  32. package/dist/css/index.js.map +1 -1
  33. package/dist/css/lib.d.ts +24 -0
  34. package/dist/css/lib.js +36 -0
  35. package/dist/css/lib.js.map +1 -0
  36. package/dist/css/link.d.ts +6 -0
  37. package/dist/css/link.js +9 -0
  38. package/dist/css/link.js.map +1 -0
  39. package/dist/css/number.d.ts +6 -0
  40. package/dist/css/number.js +6 -0
  41. package/dist/css/number.js.map +1 -0
  42. package/dist/css/shadow.d.ts +14 -0
  43. package/dist/css/shadow.js +42 -0
  44. package/dist/css/shadow.js.map +1 -0
  45. package/dist/css/string.d.ts +6 -0
  46. package/dist/css/string.js +8 -0
  47. package/dist/css/string.js.map +1 -0
  48. package/dist/css/stroke-style.d.ts +7 -0
  49. package/dist/css/stroke-style.js +9 -0
  50. package/dist/css/stroke-style.js.map +1 -0
  51. package/dist/css/transition.d.ts +14 -0
  52. package/dist/css/transition.js +21 -0
  53. package/dist/css/transition.js.map +1 -0
  54. package/dist/css/typography.d.ts +7 -0
  55. package/dist/css/typography.js +38 -0
  56. package/dist/css/typography.js.map +1 -0
  57. package/dist/index.d.ts +2 -0
  58. package/dist/index.js +2 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/js/index.d.ts +12 -0
  61. package/dist/js/index.js +16 -0
  62. package/dist/js/index.js.map +1 -0
  63. package/dist/transform.d.ts +6 -0
  64. package/dist/transform.js +17 -0
  65. package/dist/transform.js.map +1 -0
  66. package/dist/types.d.ts +384 -0
  67. package/dist/types.js +2 -0
  68. package/dist/types.js.map +1 -0
  69. package/package.json +7 -5
  70. package/src/color.ts +1 -27
  71. package/src/css/boolean.ts +15 -0
  72. package/src/css/border.ts +46 -0
  73. package/src/css/color.ts +80 -0
  74. package/src/css/cubic-bezier.ts +23 -0
  75. package/src/css/dimension.ts +15 -0
  76. package/src/css/duration.ts +15 -0
  77. package/src/css/font-family.ts +32 -0
  78. package/src/css/font-weight.ts +12 -0
  79. package/src/css/gradient.ts +42 -0
  80. package/src/css/index.ts +105 -539
  81. package/src/css/lib.ts +54 -0
  82. package/src/css/link.ts +12 -0
  83. package/src/css/number.ts +9 -0
  84. package/src/css/shadow.ts +75 -0
  85. package/src/css/string.ts +11 -0
  86. package/src/css/stroke-style.ts +13 -0
  87. package/src/css/transition.ts +41 -0
  88. package/src/css/typography.ts +44 -0
  89. package/src/index.ts +2 -0
  90. package/src/js/index.ts +31 -0
  91. package/src/transform.ts +23 -0
  92. package/src/types.ts +524 -0
@@ -0,0 +1,8 @@
1
+ import { defaultAliasTransform } from './lib.js';
2
+ /** Convert string value to CSS */
3
+ export function transformStringValue(value, { aliasOf, transformAlias = defaultAliasTransform } = {}) {
4
+ // this seems like a useless function—because it is—but this is a placeholder
5
+ // that can handle unexpected values in the future should any arise
6
+ return aliasOf ? transformAlias(aliasOf) : String(value);
7
+ }
8
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/css/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEnE,kCAAkC;AAClC,MAAM,UAAU,oBAAoB,CAClC,KAAgC,EAChC,EAAE,OAAO,EAAE,cAAc,GAAG,qBAAqB,KAAyD,EAAE;IAE5G,6EAA6E;IAC7E,mEAAmE;IACnE,OAAO,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { StrokeStyleValue } from '../types.js';
2
+ import { type IDGenerator } from './lib.js';
3
+ /** Convert strokeStyle value to CSS */
4
+ export declare function transformStrokeStyleValue(value: string | StrokeStyleValue, { aliasOf, transformAlias }?: {
5
+ aliasOf?: string;
6
+ transformAlias?: IDGenerator;
7
+ }): string;
@@ -0,0 +1,9 @@
1
+ import { defaultAliasTransform } from './lib.js';
2
+ /** Convert strokeStyle value to CSS */
3
+ export function transformStrokeStyleValue(value, { aliasOf, transformAlias = defaultAliasTransform } = {}) {
4
+ if (aliasOf) {
5
+ return transformAlias(aliasOf);
6
+ }
7
+ return typeof value === 'string' ? value : 'dashed'; // CSS doesn’t have `dash-array`; it’s just "dashed"
8
+ }
9
+ //# sourceMappingURL=stroke-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stroke-style.js","sourceRoot":"","sources":["../../src/css/stroke-style.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEnE,uCAAuC;AACvC,MAAM,UAAU,yBAAyB,CACvC,KAAgC,EAChC,EAAE,OAAO,EAAE,cAAc,GAAG,qBAAqB,KAAyD,EAAE;IAE5G,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,oDAAoD;AAC3G,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { TransitionValueNormalized } from '../types.js';
2
+ import { transformCubicBezierValue } from './cubic-bezier.js';
3
+ import { transformDurationValue } from './duration.js';
4
+ import { type IDGenerator } from './lib.js';
5
+ /** Convert transition value to multiple CSS values */
6
+ export declare function transformTransitionValue(value: TransitionValueNormalized, { aliasOf, partialAliasOf, transformAlias, }?: {
7
+ aliasOf?: string;
8
+ partialAliasOf?: Partial<Record<keyof typeof value, string>>;
9
+ transformAlias?: IDGenerator;
10
+ }): {
11
+ duration: ReturnType<typeof transformDurationValue>;
12
+ delay: ReturnType<typeof transformDurationValue>;
13
+ 'timing-function': ReturnType<typeof transformCubicBezierValue>;
14
+ };
@@ -0,0 +1,21 @@
1
+ import { transformCubicBezierValue } from './cubic-bezier.js';
2
+ import { transformDurationValue } from './duration.js';
3
+ import { defaultAliasTransform, transformCompositeAlias } from './lib.js';
4
+ /** Convert transition value to multiple CSS values */
5
+ export function transformTransitionValue(value, { aliasOf, partialAliasOf, transformAlias = defaultAliasTransform, } = {}) {
6
+ if (aliasOf) {
7
+ return transformCompositeAlias(value, { aliasOf, transformAlias });
8
+ }
9
+ return {
10
+ duration: partialAliasOf?.duration
11
+ ? transformAlias(partialAliasOf.duration)
12
+ : transformDurationValue(value.duration, { transformAlias }),
13
+ delay: partialAliasOf?.delay
14
+ ? transformAlias(partialAliasOf.delay)
15
+ : transformDurationValue(value.delay, { transformAlias }),
16
+ 'timing-function': partialAliasOf?.timingFunction
17
+ ? transformAlias(partialAliasOf.timingFunction)
18
+ : transformCubicBezierValue(value.timingFunction, { transformAlias }),
19
+ };
20
+ }
21
+ //# sourceMappingURL=transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition.js","sourceRoot":"","sources":["../../src/css/transition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAoB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAE5F,sDAAsD;AACtD,MAAM,UAAU,wBAAwB,CACtC,KAAgC,EAChC,EACE,OAAO,EACP,cAAc,EACd,cAAc,GAAG,qBAAqB,MAKpC,EAAE;IAMN,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,uBAAuB,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAIhE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,cAAc,EAAE,QAAQ;YAChC,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,QAAQ,CAAC;YACzC,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,CAAC;QAC9D,KAAK,EAAE,cAAc,EAAE,KAAK;YAC1B,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC;YACtC,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,CAAC;QAC3D,iBAAiB,EAAE,cAAc,EAAE,cAAc;YAC/C,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,cAAc,CAAC;YAC/C,CAAC,CAAC,yBAAyB,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,cAAc,EAAE,CAAC;KACxE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type IDGenerator } from './lib.js';
2
+ /** Convert typography value to multiple CSS values */
3
+ export declare function transformTypographyValue(value: Record<string, string | string[]>, { aliasOf, partialAliasOf, transformAlias, }?: {
4
+ aliasOf?: string;
5
+ partialAliasOf?: Record<keyof typeof value, string>;
6
+ transformAlias?: IDGenerator;
7
+ }): Record<string, string>;
@@ -0,0 +1,38 @@
1
+ import { kebabCase } from 'scule';
2
+ import { transformFontFamilyValue } from './font-family.js';
3
+ import { transformFontWeightValue } from './font-weight.js';
4
+ import { defaultAliasTransform, transformCompositeAlias } from './lib.js';
5
+ import { transformStringValue } from './string.js';
6
+ /** Convert typography value to multiple CSS values */
7
+ export function transformTypographyValue(value, { aliasOf, partialAliasOf, transformAlias = defaultAliasTransform, } = {}) {
8
+ const output = {};
9
+ if (aliasOf) {
10
+ return transformCompositeAlias(value, { aliasOf, transformAlias });
11
+ }
12
+ for (const [property, subvalue] of Object.entries(value)) {
13
+ let transformedValue;
14
+ if (partialAliasOf?.[property]) {
15
+ transformedValue = transformAlias(partialAliasOf[property]);
16
+ }
17
+ else {
18
+ switch (property) {
19
+ case 'fontFamily': {
20
+ transformedValue = transformFontFamilyValue(subvalue, { transformAlias });
21
+ break;
22
+ }
23
+ case 'fontSize':
24
+ case 'fontWeight': {
25
+ transformedValue = transformFontWeightValue(subvalue, { transformAlias });
26
+ break;
27
+ }
28
+ default: {
29
+ transformedValue = transformStringValue(subvalue, { transformAlias });
30
+ break;
31
+ }
32
+ }
33
+ }
34
+ output[kebabCase(property)] = transformedValue;
35
+ }
36
+ return output;
37
+ }
38
+ //# sourceMappingURL=typography.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typography.js","sourceRoot":"","sources":["../../src/css/typography.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAoB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,sDAAsD;AACtD,MAAM,UAAU,wBAAwB,CACtC,KAAwC,EACxC,EACE,OAAO,EACP,cAAc,EACd,cAAc,GAAG,qBAAqB,MACqE,EAAE;IAE/G,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,uBAAuB,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,IAAI,gBAAwB,CAAC;QAC7B,IAAI,cAAc,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,gBAAgB,GAAG,cAAc,CAAC,cAAc,CAAC,QAAQ,CAAE,CAAC,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,QAAQ,QAAQ,EAAE,CAAC;gBACjB,KAAK,YAAY,CAAC,CAAC,CAAC;oBAClB,gBAAgB,GAAG,wBAAwB,CAAC,QAAoB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;oBACtF,MAAM;gBACR,CAAC;gBACD,KAAK,UAAU,CAAC;gBAChB,KAAK,YAAY,CAAC,CAAC,CAAC;oBAClB,gBAAgB,GAAG,wBAAwB,CAAC,QAAkB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;oBACpF,MAAM;gBACR,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACR,gBAAgB,GAAG,oBAAoB,CAAC,QAAkB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;oBAChF,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,gBAAgB,CAAC;IACjD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './color.js';
2
2
  export * from './id.js';
3
3
  export * from './string.js';
4
+ export * from './transform.js';
5
+ export * from './types.js';
package/dist/index.js CHANGED
@@ -25,4 +25,6 @@
25
25
  export * from './color.js';
26
26
  export * from './id.js';
27
27
  export * from './string.js';
28
+ export * from './transform.js';
29
+ export * from './types.js';
28
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { TokenNormalized } from '../types.js';
2
+ export interface TransformJSValueOptions {
3
+ mode: string;
4
+ /** indent space count */
5
+ indent?: number;
6
+ /** initial indent level */
7
+ startingIndent?: number;
8
+ }
9
+ /**
10
+ * Convert token value to a JS string via acorn/astring.
11
+ */
12
+ export declare function transformJSValue<T extends TokenNormalized>(token: T, { mode, indent, startingIndent }: TransformJSValueOptions): string | undefined;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Convert token value to a JS string via acorn/astring.
3
+ */
4
+ export function transformJSValue(token, { mode, indent = 2, startingIndent = 0 }) {
5
+ if (!(mode in token.mode)) {
6
+ return;
7
+ }
8
+ const indentStart = startingIndent > 0 ? ' '.repeat(startingIndent ?? 2) : '';
9
+ // note: since tokens are JSON-serializable to begin with, using
10
+ // JSON.stringify generates the same output as an AST parser/generator would
11
+ // but faster and without the added overhead (even acorn/astring leave object
12
+ // keys quoted).
13
+ // TODO: use @biomejs/js-api when it’s stable for pretty formatting
14
+ return JSON.stringify(token.mode[mode].$value, undefined, indent).replace(/\n/g, `\n${indentStart}`);
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/js/index.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAQ,EACR,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,cAAc,GAAG,CAAC,EAA2B;IAEjE,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO;IACT,CAAC;IACD,MAAM,WAAW,GAAG,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9E,gEAAgE;IAChE,4EAA4E;IAC5E,6EAA6E;IAC7E,gBAAgB;IAEhB,mEAAmE;IAEnE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,WAAW,EAAE,CAAC,CAAC;AACxG,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface CustomTransformOptions {
2
+ /** Token $type */
3
+ $type: string;
4
+ }
5
+ /** Give a user pertinent feedback if they override a transform incorrectly */
6
+ export declare function validateCustomTransform(value: unknown, { $type }: CustomTransformOptions): void;
@@ -0,0 +1,17 @@
1
+ /** Give a user pertinent feedback if they override a transform incorrectly */
2
+ export function validateCustomTransform(value, { $type }) {
3
+ if (value) {
4
+ if ((typeof value !== 'string' && typeof value !== 'object') || Array.isArray(value)) {
5
+ throw new Error(`transform(): expected string or Object of strings, received ${Array.isArray(value) ? 'Array' : typeof value}`);
6
+ }
7
+ switch ($type) {
8
+ case 'typography': {
9
+ if (typeof value !== 'object') {
10
+ throw new Error('transform(): typography tokens must be an object of keys');
11
+ }
12
+ break;
13
+ }
14
+ }
15
+ }
16
+ }
17
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAKA,8EAA8E;AAC9E,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,EAAE,KAAK,EAA0B;IACvF,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACrF,MAAM,IAAI,KAAK,CACb,+DAA+D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,EAAE,CAC/G,CAAC;QACJ,CAAC;QACD,QAAQ,KAAK,EAAE,CAAC;YACd,KAAK,YAAY,CAAC,CAAC,CAAC;gBAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;gBAC9E,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,384 @@
1
+ import type { ObjectNode } from '@humanwhocodes/momoa';
2
+ export interface TokenCore<E extends {} = Record<string, unknown>> {
3
+ $description?: string;
4
+ $extensions?: E;
5
+ }
6
+ export type Token = BooleanToken | BorderToken | ColorToken | CubicBézierToken | DimensionToken | DurationToken | FontFamilyToken | FontWeightToken | GradientToken | LinkToken | NumberToken | ShadowToken | StringToken | StringToken | TransitionToken | TypographyToken | StrokeStyleToken;
7
+ export type AliasValue = string;
8
+ /**
9
+ * 8.? Boolean (beta)
10
+ */
11
+ export interface BooleanToken extends TokenCore {
12
+ $type: 'boolean';
13
+ $value: BooleanValue | AliasValue;
14
+ }
15
+ export type BooleanValue = boolean;
16
+ /**
17
+ * 9.3 Border
18
+ */
19
+ export interface BorderToken extends TokenCore {
20
+ $type: 'border';
21
+ $value: BorderValue | AliasValue;
22
+ }
23
+ export interface BorderValue {
24
+ color: ColorValue | AliasValue;
25
+ width: DimensionValue | AliasValue;
26
+ style: StrokeStyleValue | AliasValue;
27
+ }
28
+ /**
29
+ * 8.1 Color
30
+ */
31
+ export interface ColorToken extends TokenCore {
32
+ $type: 'color';
33
+ $value: ColorValue | AliasValue;
34
+ }
35
+ export type ColorValue = string | {
36
+ colorSpace: ColorSpace;
37
+ channels: [number, number, number];
38
+ alpha?: number;
39
+ hex?: string;
40
+ };
41
+ export interface CubicBézierToken extends TokenCore {
42
+ $type: 'cubicBezier';
43
+ $value: CubicBézierValue | AliasValue;
44
+ }
45
+ export type CubicBézierValue = [number, number, number, number];
46
+ /**
47
+ * 8.2 Dimension
48
+ */
49
+ export interface DimensionToken extends TokenCore {
50
+ $type: 'dimension';
51
+ $value: string | AliasValue;
52
+ }
53
+ export type DimensionValue = `${number}px` | `${number}em` | `${number}rem`;
54
+ /**
55
+ * 8.5 Duration
56
+ */
57
+ export interface DurationToken extends TokenCore {
58
+ $type: 'duration';
59
+ $value: string | AliasValue;
60
+ }
61
+ export type DurationValue = `${number}ms` | `${number}s`;
62
+ /**
63
+ * 9.6 Gradient
64
+ */
65
+ export interface GradientToken extends TokenCore {
66
+ $type: 'gradient';
67
+ $value: GradientValue | AliasValue;
68
+ }
69
+ export type GradientValue = GradientStop[];
70
+ export interface GradientStop {
71
+ color: ColorValue | AliasValue;
72
+ position: NumberValue | AliasValue;
73
+ }
74
+ /**
75
+ * 8.3 Font Family
76
+ */
77
+ export interface FontFamilyToken extends TokenCore {
78
+ $type: 'fontFamily';
79
+ $value: FontFamilyValue | AliasValue;
80
+ }
81
+ export type FontFamilyValue = string | string[];
82
+ /**
83
+ * 8.4 Font Weight
84
+ */
85
+ export interface FontWeightToken extends TokenCore {
86
+ $type: 'fontWeight';
87
+ $value: FontWeightValue | AliasValue;
88
+ }
89
+ export type FontWeightValue = 'thin' | 'hairline' | 'extra-light' | 'ultra-light' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'semi-bold' | 'demi-bold' | 'bold' | 'extra-bold' | 'ultra-bold' | 'black' | 'heavy' | 'extra-black' | 'ultra-black' | number;
90
+ /**
91
+ * 8.? Link (beta)
92
+ */
93
+ export interface LinkToken extends TokenCore {
94
+ $type: 'link';
95
+ $value: LinkValue | AliasValue;
96
+ }
97
+ export type LinkValue = string;
98
+ /**
99
+ * 8.7 Number
100
+ */
101
+ export interface NumberToken extends TokenCore {
102
+ $type: 'number';
103
+ $value: NumberValue | AliasValue;
104
+ }
105
+ export type NumberValue = number;
106
+ /**
107
+ * 8.? String (beta)
108
+ */
109
+ export interface StringToken extends TokenCore {
110
+ $type: 'string';
111
+ $value: StringValue | AliasValue;
112
+ }
113
+ export type StringValue = string;
114
+ /**
115
+ * 9.2 Stroke Style
116
+ */
117
+ export interface StrokeStyleToken extends TokenCore {
118
+ $type: 'strokeStyle';
119
+ $value: StrokeStyleValue | AliasValue;
120
+ }
121
+ export type StrokeStyleValue = 'solid' | 'dashed' | 'dotted' | 'double' | 'groove' | 'ridge' | 'outset' | 'inset' | StrokeStyleValueExpanded;
122
+ export interface StrokeStyleValueExpanded {
123
+ dashArray: DimensionValue[];
124
+ lineCap: 'round' | 'butt' | 'square';
125
+ }
126
+ /**
127
+ * 9.5 Shadow
128
+ */
129
+ export interface ShadowToken extends TokenCore {
130
+ $type: 'shadow';
131
+ $value: ShadowValue | ShadowValue[] | AliasValue;
132
+ }
133
+ export interface ShadowValue {
134
+ color: ColorValue | AliasValue;
135
+ offsetX: DimensionValue | AliasValue;
136
+ offsetY: DimensionValue | AliasValue;
137
+ blur?: DimensionValue | AliasValue;
138
+ spread?: DimensionValue | AliasValue;
139
+ }
140
+ /**
141
+ * 9.4 Transition
142
+ */
143
+ export interface TransitionToken extends TokenCore {
144
+ $type: 'transition';
145
+ $value: TransitionValue | AliasValue;
146
+ }
147
+ export interface TransitionValue {
148
+ duration: DurationValue | AliasValue;
149
+ delay: DurationValue | AliasValue;
150
+ timingFunction: CubicBézierValue | AliasValue;
151
+ }
152
+ /**
153
+ * 9.7 Typography
154
+ */
155
+ export interface TypographyToken extends TokenCore {
156
+ $type: 'typography';
157
+ $value: TypographyValue | AliasValue;
158
+ }
159
+ export interface TypographyValue {
160
+ fontFamily?: FontFamilyValue | AliasValue;
161
+ fontSize?: DimensionValue | AliasValue;
162
+ fontStyle?: string;
163
+ fontVariant?: string;
164
+ fontVariantAlternatives?: string;
165
+ fontVariantCaps?: string;
166
+ fontVariantEastAsian?: string;
167
+ fontVariantEmoji?: string;
168
+ fontVariantLigatures?: string;
169
+ fontVariantNumeric?: string;
170
+ fontVariantPosition?: string;
171
+ fontVariationSettings?: string;
172
+ fontWeight?: FontWeightValue | AliasValue;
173
+ letterSpacing?: DimensionValue | AliasValue;
174
+ lineHeight?: DimensionValue | NumberValue | AliasValue;
175
+ textDecoration?: string;
176
+ textTransform?: string;
177
+ [key: string]: any;
178
+ }
179
+ export interface GroupCore {
180
+ $description?: string;
181
+ $type?: Token['$type'];
182
+ $extensions?: Record<string, unknown>;
183
+ }
184
+ export type Group = GroupCore & {
185
+ [key: string]: GroupOrToken;
186
+ };
187
+ export type GroupOrToken = Group | Token;
188
+ export interface TokenNormalizedCore {
189
+ $description?: string;
190
+ $extensions?: Record<string, unknown>;
191
+ id: string;
192
+ sourceNode: ObjectNode;
193
+ group: {
194
+ $description?: string;
195
+ $extensions?: Record<string, unknown>;
196
+ id: string;
197
+ /** IDs of all tokens contained in this group */
198
+ tokens: string[];
199
+ };
200
+ }
201
+ export type TokenNormalized = BooleanTokenNormalized | BorderTokenNormalized | ColorTokenNormalized | CubicBézierTokenNormalized | DimensionTokenNormalized | DurationTokenNormalized | FontFamilyTokenNormalized | FontWeightTokenNormalized | GradientTokenNormalized | LinkTokenNormalized | NumberTokenNormalized | ShadowTokenNormalized | StringTokenNormalized | StrokeStyleTokenNormalized | TransitionTokenNormalized | TypographyTokenNormalized;
202
+ export interface BooleanTokenNormalized extends TokenNormalizedCore {
203
+ $type: 'boolean';
204
+ $value: BooleanValue;
205
+ aliasOf?: string;
206
+ partialAliasOf?: never;
207
+ mode: Record<string, BooleanTokenNormalized | undefined>;
208
+ originalValue: BooleanToken;
209
+ }
210
+ export interface BorderTokenNormalized extends TokenNormalizedCore {
211
+ $type: 'border';
212
+ $value: BorderValueNormalized;
213
+ aliasOf?: string;
214
+ partialAliasOf?: Partial<Record<keyof BorderValueNormalized, string>>;
215
+ mode: Record<string, BorderTokenNormalized | undefined>;
216
+ originalValue: BorderToken;
217
+ }
218
+ export interface BorderValueNormalized {
219
+ color: ColorValueNormalized;
220
+ width: DimensionValue;
221
+ style: StrokeStyleValueExpanded;
222
+ }
223
+ export interface ColorTokenNormalized extends TokenNormalizedCore {
224
+ $type: 'color';
225
+ $value: ColorValueNormalized;
226
+ aliasOf?: string;
227
+ partialAliasOf?: never;
228
+ mode: Record<string, ColorTokenNormalized | undefined>;
229
+ originalValue: ColorToken;
230
+ }
231
+ export interface ColorValueNormalized {
232
+ /** Colorspace (default: `srgb`) @see https://www.w3.org/TR/css-color-4/#predefined */
233
+ colorSpace: ColorSpace;
234
+ /** Color channels. Will be normalized to 1 unless the colorspace prevents it (e.g. XYZ, LAB) */
235
+ channels: [number, number, number];
236
+ /** Alpha channel, normalized from 0 – 1 */
237
+ alpha: number;
238
+ /** Hex fallback (for sRGB) */
239
+ hex?: string;
240
+ }
241
+ export type ColorSpace = 'a98' | 'display-p3' | 'hsb' | 'hsl' | 'hsv' | 'hwb' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'prophoto-rgb' | 'rec2020' | 'srgb-linear' | 'srgb' | 'xyz-d50' | 'xyz-d65';
242
+ export interface CubicBézierTokenNormalized extends TokenNormalizedCore {
243
+ $type: 'cubicBezier';
244
+ $value: CubicBézierValue;
245
+ aliasOf?: string;
246
+ partialAliasOf?: [string | undefined, string | undefined, string | undefined, string | undefined];
247
+ mode: Record<string, CubicBézierTokenNormalized | undefined>;
248
+ originalValue: CubicBézierToken;
249
+ }
250
+ export interface DimensionTokenNormalized extends TokenNormalizedCore {
251
+ $type: 'dimension';
252
+ $value: DimensionValue;
253
+ aliasOf?: string;
254
+ partialAliasOf?: never;
255
+ mode: Record<string, DimensionTokenNormalized | undefined>;
256
+ originalValue: DimensionToken;
257
+ }
258
+ export interface DurationTokenNormalized extends TokenNormalizedCore {
259
+ $type: 'duration';
260
+ $value: DurationValue;
261
+ aliasOf?: string;
262
+ partialAliasOf?: never;
263
+ mode: Record<string, DurationTokenNormalized | undefined>;
264
+ originalValue: DurationToken;
265
+ }
266
+ export interface FontFamilyTokenNormalized extends TokenNormalizedCore {
267
+ $type: 'fontFamily';
268
+ $value: FontFamilyValueNormalized;
269
+ aliasOf?: string;
270
+ partialAliasOf?: never;
271
+ mode: Record<string, FontFamilyTokenNormalized | undefined>;
272
+ originalValue: FontFamilyToken;
273
+ }
274
+ export type FontFamilyValueNormalized = string[];
275
+ export interface FontWeightTokenNormalized extends TokenNormalizedCore {
276
+ $type: 'fontWeight';
277
+ $value: FontWeightValueNormalized;
278
+ aliasOf?: string;
279
+ partialAliasOf?: never;
280
+ mode: Record<string, FontWeightTokenNormalized | undefined>;
281
+ originalValue: FontWeightToken;
282
+ }
283
+ export type FontWeightValueNormalized = number;
284
+ export interface GradientTokenNormalized extends TokenNormalizedCore {
285
+ $type: 'gradient';
286
+ $value: GradientValueNormalized;
287
+ aliasOf?: string;
288
+ partialAliasOf?: Partial<Record<keyof GradientStopNormalized, string>>[];
289
+ mode: Record<string, GradientTokenNormalized | undefined>;
290
+ originalValue: GradientTokenNormalized;
291
+ }
292
+ export type GradientValueNormalized = GradientStopNormalized[];
293
+ export interface GradientStopNormalized {
294
+ color: ColorValueNormalized;
295
+ position: number;
296
+ }
297
+ export interface LinkTokenNormalized extends TokenNormalizedCore {
298
+ $type: 'link';
299
+ $value: LinkValue;
300
+ aliasOf?: string;
301
+ partialAliasOf?: never;
302
+ mode: Record<string, LinkTokenNormalized | undefined>;
303
+ originalValue: LinkToken;
304
+ }
305
+ export interface NumberTokenNormalized extends TokenNormalizedCore {
306
+ $type: 'number';
307
+ $value: NumberValue;
308
+ aliasOf?: string;
309
+ partialAliasOf?: never;
310
+ mode: Record<string, NumberTokenNormalized | undefined>;
311
+ originalValue: NumberToken;
312
+ }
313
+ export interface ShadowTokenNormalized extends TokenNormalizedCore {
314
+ $type: 'shadow';
315
+ $value: ShadowValueNormalized[];
316
+ aliasOf?: string;
317
+ partialAliasOf?: Partial<Record<keyof ShadowValueNormalized, string>>[];
318
+ mode: Record<string, ShadowTokenNormalized | undefined>;
319
+ originalValue: ShadowToken;
320
+ }
321
+ export interface ShadowValueNormalized {
322
+ color: ColorValueNormalized;
323
+ offsetX: DimensionValue;
324
+ offsetY: DimensionValue;
325
+ blur: DimensionValue;
326
+ spread: DimensionValue;
327
+ }
328
+ export interface StringTokenNormalized extends TokenNormalizedCore {
329
+ $type: 'string';
330
+ $value: StringValue;
331
+ aliasOf?: string;
332
+ partialAliasOf?: never;
333
+ mode: Record<string, StringTokenNormalized | undefined>;
334
+ originalValue: StringTokenNormalized;
335
+ }
336
+ export interface StrokeStyleTokenNormalized extends TokenNormalizedCore {
337
+ $type: 'strokeStyle';
338
+ $value: StrokeStyleValueExpanded;
339
+ aliasOf?: string;
340
+ partialAliasOf?: never;
341
+ mode: Record<string, StrokeStyleTokenNormalized | undefined>;
342
+ originalValue: StrokeStyleToken;
343
+ }
344
+ export interface TransitionTokenNormalized extends TokenNormalizedCore {
345
+ $type: 'transition';
346
+ $value: TransitionValueNormalized;
347
+ aliasOf?: string;
348
+ partialAliasOf?: Partial<Record<keyof TransitionValueNormalized, string>>;
349
+ mode: Record<string, TransitionTokenNormalized | undefined>;
350
+ originalValue: TransitionToken;
351
+ }
352
+ export interface TransitionValueNormalized {
353
+ duration: DurationValue;
354
+ delay: DurationValue;
355
+ timingFunction: CubicBézierValue;
356
+ }
357
+ export interface TypographyTokenNormalized extends TokenNormalizedCore {
358
+ $type: 'typography';
359
+ $value: TypographyValueNormalized;
360
+ aliasOf?: string;
361
+ partialAliasOf?: Record<string, string>;
362
+ mode: Record<string, TypographyTokenNormalized | undefined>;
363
+ originalValue: TypographyToken;
364
+ }
365
+ export interface TypographyValueNormalized {
366
+ fontFamily?: FontFamilyValue;
367
+ fontSize?: DimensionValue;
368
+ fontStyle?: string;
369
+ fontVariant?: string;
370
+ fontVariantAlternatives?: string;
371
+ fontVariantCaps?: string;
372
+ fontVariantEastAsian?: string;
373
+ fontVariantEmoji?: string;
374
+ fontVariantLigatures?: string;
375
+ fontVariantNumeric?: string;
376
+ fontVariantPosition?: string;
377
+ fontVariationSettings?: string;
378
+ fontWeight?: FontWeightValue;
379
+ letterSpacing?: DimensionValue;
380
+ lineHeight?: DimensionValue | NumberValue;
381
+ textDecoration?: string;
382
+ textTransform?: string;
383
+ [key: string]: any;
384
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@terrazzo/token-tools",
3
3
  "description": "Various utilities for token types",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "author": {
6
6
  "name": "Drew Powers",
7
7
  "email": "drew@pow.rs"
@@ -28,15 +28,17 @@
28
28
  "exports": {
29
29
  ".": "./dist/index.js",
30
30
  "./css": "./dist/css/index.js",
31
+ "./js": "./dist/js/index.js",
31
32
  "./*": "./*"
32
33
  },
33
34
  "dependencies": {
34
- "culori": "^4.0.1",
35
- "scule": "^1.3.0",
36
- "wildcard-match": "^5.1.3"
35
+ "@humanwhocodes/momoa": "^3.0",
36
+ "culori": "^4.0",
37
+ "scule": "^1.3",
38
+ "wildcard-match": "^5.1"
37
39
  },
38
40
  "devDependencies": {
39
- "@types/culori": "^2.1.0"
41
+ "@types/culori": "^2.1"
40
42
  },
41
43
  "scripts": {
42
44
  "build": "pnpm run build:clean && pnpm run build:ts && pnpm run build:license",