design-token-library 0.1.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2023-05-16
11
+
12
+ ### Added
13
+
14
+ Initial release of the package.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Nicholas Rice
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ![CI](https://github.com/nicholasrice/design-token-library/actions/workflows/ci.yml/badge.svg)
2
+ ![Docs](https://github.com/nicholasrice/design-token-library/actions/workflows/deploy.yml/badge.svg)
3
+
4
+ [API Documentation](https://nicholasrice.github.io/design-token-library/)
Binary file
@@ -0,0 +1,24 @@
1
+ import { DesignToken } from "./design-token.js";
2
+ import { Library } from "./library.js";
3
+ /**
4
+ * @public
5
+ */
6
+ export declare function toCSS(library: Library.Library<any, any>): string;
7
+ interface CSSPropertyValues {
8
+ readonly var: `var(--${string})`;
9
+ readonly property: `--${string}`;
10
+ }
11
+ /**
12
+ * A collection of {@link @CSSPropertyValues} that mirrors the
13
+ * structure of the source {@link Library.Library<any> | Library}.
14
+ * @public
15
+ */
16
+ export type CSSPropertiesLibrary<T extends {}> = {
17
+ [K in keyof Readonly<T>]: T[K] extends DesignToken.Any ? CSSPropertyValues : K extends "type" ? DesignToken.Type : T[K] extends {} ? CSSPropertiesLibrary<T[K]> : never;
18
+ };
19
+ /**
20
+ * Construct an {@link CSSPropertiesLibrary} from a {@link Library.Library<any>}.
21
+ * @public
22
+ */
23
+ export declare function toProperties<T extends Library.Library<any>>(library: T): CSSPropertiesLibrary<T["tokens"]>;
24
+ export {};
@@ -0,0 +1,110 @@
1
+ import { DesignToken } from "./design-token.js";
2
+ /**
3
+ * @public
4
+ */
5
+ export function toCSS(library) {
6
+ return recurseToCss(library.tokens);
7
+ }
8
+ /**
9
+ * Construct an {@link CSSPropertiesLibrary} from a {@link Library.Library<any>}.
10
+ * @public
11
+ */
12
+ export function toProperties(library) {
13
+ const recurse = (section, properties) => {
14
+ for (const key in section) {
15
+ const sectionValue = section[key];
16
+ if (isToken(sectionValue)) {
17
+ // TODO add a strategy for name conversion
18
+ const property = `--${sectionValue.name.replaceAll(".", "-")}`;
19
+ const propertyValue = Object.freeze({
20
+ var: `var(${property})`,
21
+ property,
22
+ });
23
+ Reflect.defineProperty(properties, key, {
24
+ value: propertyValue,
25
+ enumerable: true,
26
+ });
27
+ }
28
+ else {
29
+ const value = {};
30
+ recurse(sectionValue, value);
31
+ Reflect.defineProperty(properties, key, {
32
+ value: Object.freeze(value),
33
+ enumerable: true,
34
+ });
35
+ }
36
+ }
37
+ };
38
+ const properties = {};
39
+ recurse(library.tokens, properties);
40
+ return properties;
41
+ }
42
+ const isToken = (value) => {
43
+ return "value" in value;
44
+ };
45
+ const recurseToCss = (librarySection) => {
46
+ let result = "";
47
+ for (const key in librarySection) {
48
+ const tokenOrGroup = librarySection[key];
49
+ if (isToken(tokenOrGroup)) {
50
+ let value = tokenOrGroup.value;
51
+ if (tokenOrGroup.type !== undefined &&
52
+ Reflect.has(TokenConverters, tokenOrGroup.type)) {
53
+ value = Reflect.get(TokenConverters, tokenOrGroup.type)(value);
54
+ }
55
+ result += `--${tokenOrGroup.name}:${value};`;
56
+ }
57
+ else {
58
+ result = recurseToCss(tokenOrGroup);
59
+ }
60
+ }
61
+ return result;
62
+ };
63
+ const joiner = (value) => {
64
+ return value.join(" ");
65
+ };
66
+ /**
67
+ * Convert a border value to CSS
68
+ */
69
+ const borderConverter = (value) => {
70
+ return `${value.width} ${value.style} ${value.color}`;
71
+ };
72
+ const fontFamilyConverter = (value) => {
73
+ return typeof value === "string"
74
+ ? fontFamilyQuoter(value)
75
+ : value.map(fontFamilyQuoter).join();
76
+ };
77
+ const fontFamilyQuoter = (value) => {
78
+ const test = /^(\'|\")?(.*?)(\'|\")?$/;
79
+ const result = test.exec(value);
80
+ if (result !== null && (result[1] || result[3])) {
81
+ value = result[2];
82
+ }
83
+ return value.includes(" ") ? `"${value}"` : value;
84
+ };
85
+ const gradientReducer = (accumulated, value) => {
86
+ return accumulated + `${value.color} ${value.position * 100}%,`;
87
+ };
88
+ const gradientConverter = (value) => {
89
+ return value.reduce(gradientReducer, "").replace(/,$/, "");
90
+ };
91
+ const shadowConverter = (value) => {
92
+ return `${value.offsetX} ${value.offsetY} ${value.blur} ${value.spread} ${value.color}`;
93
+ };
94
+ const strokeStyleConverter = (value) => {
95
+ // CSS doesn't support customizing dashed borders at the time of authoring.
96
+ return typeof value === "string" ? value : "dashed";
97
+ };
98
+ const transitionConverter = (value) => {
99
+ return `${value.duration} ${value.delay} ${value.timingFunction}`;
100
+ };
101
+ const TokenConverters = {
102
+ [DesignToken.Type.Border]: borderConverter,
103
+ [DesignToken.Type.CubicBezier]: joiner,
104
+ [DesignToken.Type.FontFamily]: fontFamilyConverter,
105
+ [DesignToken.Type.Gradient]: gradientConverter,
106
+ [DesignToken.Type.Shadow]: shadowConverter,
107
+ [DesignToken.Type.StrokeStyle]: strokeStyleConverter,
108
+ [DesignToken.Type.Transition]: transitionConverter,
109
+ };
110
+ //# sourceMappingURL=css-reflector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-reflector.js","sourceRoot":"","sources":["../../src/lib/css-reflector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,OAAkC;IACtD,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAsBD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAU;IAEV,MAAM,OAAO,GAAG,CACd,OAAkC,EAClC,UAAqC,EACrC,EAAE;QACF,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAElC,IAAI,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC1B,0CAA0C;gBAC1C,MAAM,QAAQ,GAAG,KAAK,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;gBAC/D,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;oBAClC,GAAG,EAAE,OAAO,QAAQ,GAAG;oBACvB,QAAQ;iBACT,CAAC,CAAC;gBACH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE;oBACtC,KAAK,EAAE,aAAa;oBACpB,UAAU,EAAE,IAAI;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2
+ * @public
3
+ */
4
+ export declare namespace DesignToken {
5
+ /**
6
+ * An enumeration of all supported types defined
7
+ * by {@link https://tr.designtokens.org/format/#types}
8
+ */
9
+ enum Type {
10
+ Border = "border",
11
+ Color = "color",
12
+ CubicBezier = "cubicBezier",
13
+ Dimension = "dimension",
14
+ Duration = "duration",
15
+ FontFamily = "fontFamily",
16
+ FontWeight = "fontWeight",
17
+ Gradient = "gradient",
18
+ Number = "number",
19
+ Shadow = "shadow",
20
+ StrokeStyle = "strokeStyle",
21
+ Transition = "transition",
22
+ Typography = "typography"
23
+ }
24
+ /**
25
+ * The values supported for each {@link DesignToken.Type | DesignToken type}.
26
+ */
27
+ namespace Values {
28
+ /**
29
+ * A six or 8 digit hexadecimal string.
30
+ *
31
+ * @see {@link https://tr.designtokens.org/format/#color}
32
+ *
33
+ * @remarks
34
+ * Ideally we would be able to enumerate a-zA-Z1-9 * 6 | 8 chars
35
+ * and narrow this type, however TypeScript cannot handle that
36
+ * many type union combinations and will fail to compile. This
37
+ * is the best representation of a 6 or 8 digit hex char that
38
+ * can be accomplished
39
+ *
40
+ */
41
+ type Color = `#${string}`;
42
+ /**
43
+ * A dimension value (floating or integer) with a 'px' or 'rm' unit.
44
+ *
45
+ * @see {@link https://tr.designtokens.org/format/#dimension}
46
+ */
47
+ type Dimension = `${Values.Number}px` | `${Values.Number}rm`;
48
+ /**
49
+ * The name of the font family;
50
+ *
51
+ * @see {@link https://tr.designtokens.org/format/#font-family}
52
+ */
53
+ type FontFamily = string | string[];
54
+ /**
55
+ * @see {@link https://tr.designtokens.org/format/#number}
56
+ */
57
+ type Number = number;
58
+ /**
59
+ * A number between 0 and 1000, or a font-weight keyword.
60
+ *
61
+ * @see {@link https://tr.designtokens.org/format/#font-weight}
62
+ */
63
+ type FontWeight = Values.Number | "thin" | "hairline" | "extra-light" | "ultra-light" | "light" | "normal" | "regular" | "book" | "medium" | "smi-bold" | "demi-bold" | "bold" | "extra-bold" | "ultra-bold" | "black" | "heavy" | "extra-black" | "ultra-black";
64
+ /**
65
+ * A duration value in milliseconds
66
+ *
67
+ * @see {@link https://tr.designtokens.org/format/#duration}
68
+ */
69
+ type Duration = `${Values.Number}ms`;
70
+ /**
71
+ * Cubic Bézier coordinates.
72
+ *
73
+ * @see {@link https://tr.designtokens.org/format/#cubic-bezier}
74
+ */
75
+ type CubicBezier = [
76
+ P1x: Values.Number,
77
+ P1y: Values.Number,
78
+ P2x: Values.Number,
79
+ P2y: Values.Number
80
+ ];
81
+ /**
82
+ * @see {@link https://tr.designtokens.org/format/#shadow}
83
+ */
84
+ interface Shadow {
85
+ color: Values.Color;
86
+ offsetX: Values.Dimension;
87
+ offsetY: Values.Dimension;
88
+ blur: Values.Dimension;
89
+ spread: Values.Dimension;
90
+ }
91
+ /**
92
+ *
93
+ * @see {@link https://tr.designtokens.org/format/#stroke-style}
94
+ */
95
+ type StrokeStyle = "solid" | "dashed" | "dotted" | "double" | "groove" | "ridge" | "outset" | "inset" | {
96
+ dashArray: Values.Dimension[];
97
+ lineCap: "round" | "butt" | "square";
98
+ };
99
+ /**
100
+ * @see {@link https://tr.designtokens.org/format/#border}
101
+ */
102
+ interface Border {
103
+ color: Values.Color;
104
+ width: Values.Dimension;
105
+ style: Values.StrokeStyle;
106
+ }
107
+ /**
108
+ * @see {@link https://tr.designtokens.org/format/#transition}
109
+ */
110
+ interface Transition {
111
+ duration: Values.Duration;
112
+ delay: Values.Duration;
113
+ timingFunction: Values.CubicBezier;
114
+ }
115
+ /**
116
+ * @see {@link https://tr.designtokens.org/format/#gradient}
117
+ * @remarks
118
+ * Position values must be a number withing [0, 1].
119
+ */
120
+ type Gradient = Array<{
121
+ color: Values.Color;
122
+ position: Values.Number;
123
+ }>;
124
+ /**
125
+ * @see {@link https://tr.designtokens.org/format/#typography}
126
+ */
127
+ interface Typography {
128
+ fontFamily: Values.FontFamily;
129
+ fontSize: Values.Dimension;
130
+ fontWeight: Values.FontWeight;
131
+ letterSpacing: Values.Dimension;
132
+ lineHeight: Values.Number;
133
+ }
134
+ /**
135
+ * @internal
136
+ */
137
+ type Any = Color | Dimension | FontFamily | Number | FontWeight | Duration | CubicBezier | Shadow | StrokeStyle | Border | Transition | Gradient | Typography;
138
+ }
139
+ /**
140
+ * @internal
141
+ */
142
+ type TokenByType<T extends DesignToken.Type> = T extends DesignToken.Type.Border ? DesignToken.Border : T extends DesignToken.Type.Color ? DesignToken.Color : T extends DesignToken.Type.CubicBezier ? DesignToken.CubicBezier : T extends DesignToken.Type.Dimension ? DesignToken.Dimension : T extends DesignToken.Type.Duration ? DesignToken.Duration : T extends DesignToken.Type.FontFamily ? DesignToken.FontFamily : T extends DesignToken.Type.FontWeight ? DesignToken.FontWeight : T extends DesignToken.Type.Gradient ? DesignToken.Gradient : T extends DesignToken.Type.Number ? DesignToken.Number : T extends DesignToken.Type.Shadow ? DesignToken.Shadow : T extends DesignToken.Type.StrokeStyle ? DesignToken.StrokeStyle : T extends DesignToken.Type.Transition ? DesignToken.Transition : T extends DesignToken.Type.Typography ? DesignToken.Typography : never;
143
+ /**
144
+ * @internal
145
+ */
146
+ type TypeByToken<T extends DesignToken.Any> = T extends DesignToken.Border ? DesignToken.Type.Border : T extends DesignToken.Color ? DesignToken.Type.Color : T extends DesignToken.CubicBezier ? DesignToken.Type.CubicBezier : T extends DesignToken.Dimension ? DesignToken.Type.Dimension : T extends DesignToken.Duration ? DesignToken.Type.Duration : T extends DesignToken.FontFamily ? DesignToken.Type.FontFamily : T extends DesignToken.FontWeight ? DesignToken.Type.FontWeight : T extends DesignToken.Gradient ? DesignToken.Type.Gradient : T extends DesignToken.Number ? DesignToken.Type.Number : T extends DesignToken.Shadow ? DesignToken.Type.Shadow : T extends DesignToken.StrokeStyle ? DesignToken.Type.StrokeStyle : T extends DesignToken.Transition ? DesignToken.Type.Transition : T extends DesignToken.Typography ? DesignToken.Type.Typography : never;
147
+ /**
148
+ * @internal
149
+ */
150
+ type TokenByValue<T> = T extends DesignToken.Values.Border ? DesignToken.Border : T extends DesignToken.Values.Color ? DesignToken.Color : T extends DesignToken.Values.CubicBezier ? DesignToken.CubicBezier : T extends DesignToken.Values.Dimension ? DesignToken.Dimension : T extends DesignToken.Values.Duration ? DesignToken.Duration : T extends DesignToken.Values.FontFamily ? DesignToken.FontFamily : T extends DesignToken.Values.FontWeight ? DesignToken.FontWeight : T extends DesignToken.Values.Gradient ? DesignToken.Gradient : T extends DesignToken.Values.Number ? DesignToken.Number : T extends DesignToken.Values.Shadow ? DesignToken.Shadow : T extends DesignToken.Values.StrokeStyle ? DesignToken.StrokeStyle : T extends DesignToken.Values.Transition ? DesignToken.Transition : T extends DesignToken.Values.Typography ? DesignToken.Typography : never;
151
+ /**
152
+ * @internal
153
+ */
154
+ type ValueByType<T> = T extends DesignToken.Values.Border ? DesignToken.Type.Border : T extends DesignToken.Values.Color ? DesignToken.Type.Color : T extends DesignToken.Values.CubicBezier ? DesignToken.Type.CubicBezier : T extends DesignToken.Values.Dimension ? DesignToken.Type.Dimension : T extends DesignToken.Values.Duration ? DesignToken.Type.Duration : T extends DesignToken.Values.FontFamily ? DesignToken.Type.FontFamily : T extends DesignToken.Values.FontWeight ? DesignToken.Type.FontWeight : T extends DesignToken.Values.Gradient ? DesignToken.Type.Gradient : T extends DesignToken.Values.Number ? DesignToken.Type.Number : T extends DesignToken.Values.Shadow ? DesignToken.Type.Shadow : T extends DesignToken.Values.StrokeStyle ? DesignToken.Type.StrokeStyle : T extends DesignToken.Values.Transition ? DesignToken.Type.Transition : T extends DesignToken.Values.Typography ? DesignToken.Type.Typography : never;
155
+ /**
156
+ * @internal
157
+ */
158
+ type ValueByToken<T extends DesignToken.Any> = T extends DesignToken.Border ? DesignToken.Values.Border : T extends Color ? DesignToken.Values.Color : T extends DesignToken.CubicBezier ? DesignToken.Values.CubicBezier : T extends DesignToken.Dimension ? DesignToken.Values.Dimension : T extends DesignToken.Duration ? DesignToken.Values.Duration : T extends DesignToken.FontFamily ? DesignToken.Values.FontFamily : T extends DesignToken.FontWeight ? DesignToken.Values.FontWeight : T extends DesignToken.Gradient ? DesignToken.Values.Gradient : T extends DesignToken.Number ? DesignToken.Values.Number : T extends DesignToken.Shadow ? DesignToken.Values.Shadow : T extends DesignToken.StrokeStyle ? DesignToken.Values.StrokeStyle : T extends DesignToken.Transition ? DesignToken.Values.Transition : T extends Typography ? DesignToken.Values.Typography : never;
159
+ /**
160
+ * All properties supported by a DesignToken
161
+ */
162
+ interface Properties<Type extends DesignToken.Type, Value extends DesignToken.Values.Any> {
163
+ description?: string;
164
+ type?: Type;
165
+ extensions?: Record<string, any>;
166
+ value: Value;
167
+ }
168
+ type Border = Properties<DesignToken.Type.Border, DesignToken.Values.Border>;
169
+ type Color = Properties<DesignToken.Type.Color, DesignToken.Values.Color>;
170
+ type CubicBezier = Properties<DesignToken.Type.CubicBezier, DesignToken.Values.CubicBezier>;
171
+ type Dimension = Properties<DesignToken.Type.Dimension, DesignToken.Values.Dimension>;
172
+ type Duration = Properties<DesignToken.Type.Duration, DesignToken.Values.Duration>;
173
+ type FontFamily = Properties<DesignToken.Type.FontFamily, DesignToken.Values.FontFamily>;
174
+ type FontWeight = Properties<DesignToken.Type.FontWeight, DesignToken.Values.FontWeight>;
175
+ type Gradient = Properties<DesignToken.Type.Gradient, DesignToken.Values.Gradient>;
176
+ type Number = Properties<DesignToken.Type.Number, DesignToken.Values.Number>;
177
+ type Shadow = Properties<DesignToken.Type.Shadow, DesignToken.Values.Shadow>;
178
+ type StrokeStyle = Properties<DesignToken.Type.StrokeStyle, DesignToken.Values.StrokeStyle>;
179
+ type Transition = Properties<DesignToken.Type.Transition, DesignToken.Values.Transition>;
180
+ type Typography = Properties<DesignToken.Type.Typography, DesignToken.Values.Typography>;
181
+ /**
182
+ * A group of DesignTokens.
183
+ */
184
+ type Group = {
185
+ /**
186
+ * If the group has a type, the type is inferred for all descendent design tokens,
187
+ * unless specified by the token.
188
+ */
189
+ type?: DesignToken.Type;
190
+ };
191
+ /**
192
+ * @internal
193
+ */
194
+ type Any = Border | Color | CubicBezier | Dimension | Duration | FontFamily | FontWeight | Gradient | Number | Shadow | StrokeStyle | Transition | Typography;
195
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export var DesignToken;
5
+ (function (DesignToken) {
6
+ /**
7
+ * An enumeration of all supported types defined
8
+ * by {@link https://tr.designtokens.org/format/#types}
9
+ */
10
+ let Type;
11
+ (function (Type) {
12
+ Type["Border"] = "border";
13
+ Type["Color"] = "color";
14
+ Type["CubicBezier"] = "cubicBezier";
15
+ Type["Dimension"] = "dimension";
16
+ Type["Duration"] = "duration";
17
+ Type["FontFamily"] = "fontFamily";
18
+ Type["FontWeight"] = "fontWeight";
19
+ Type["Gradient"] = "gradient";
20
+ Type["Number"] = "number";
21
+ Type["Shadow"] = "shadow";
22
+ Type["StrokeStyle"] = "strokeStyle";
23
+ Type["Transition"] = "transition";
24
+ Type["Typography"] = "typography";
25
+ })(Type = DesignToken.Type || (DesignToken.Type = {}));
26
+ })(DesignToken || (DesignToken = {}));
27
+ //# sourceMappingURL=design-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"design-token.js","sourceRoot":"","sources":["../../src/lib/design-token.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,KAAW,WAAW,CA2b3B;AA3bD,WAAiB,WAAW;IAC1B;;;OAGG;IACH,IAAY,IAcX;IAdD,WAAY,IAAI;QACd,yBAAiB,CAAA;QACjB,uBAAe,CAAA;QACf,mCAA2B,CAAA;QAC3B,+BAAuB,CAAA;QACvB,6BAAqB,CAAA;QACrB,iCAAyB,CAAA;QACzB,iCAAyB,CAAA;QACzB,6BAAqB,CAAA;QACrB,yBAAiB,CAAA;QACjB,yBAAiB,CAAA;QACjB,mCAA2B,CAAA;QAC3B,iCAAyB,CAAA;QACzB,iCAAyB,CAAA;IAC3B,CAAC,EAdW,IAAI,GAAJ,gBAAI,KAAJ,gBAAI,QAcf;AAwaH,CAAC,EA3bgB,WAAW,KAAX,WAAW,QA2b3B"}
@@ -0,0 +1,3 @@
1
+ export { DesignToken } from "./design-token.js";
2
+ export * from "./library.js";
3
+ export * from "./css-reflector.js";
@@ -0,0 +1,4 @@
1
+ export { DesignToken } from "./design-token.js";
2
+ export * from "./library.js";
3
+ export * from "./css-reflector.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { DesignToken } from "./design-token.js";
2
+ import { DeepPartial } from "./utilities.js";
3
+ /**
4
+ * @public
5
+ */
6
+ export declare namespace Library {
7
+ interface Library<T extends {}, R extends {} = T> {
8
+ tokens: TokenLibrary<T, R>;
9
+ subscribe(subscriber: Library.Subscriber<R>): void;
10
+ unsubscribe(subscriber: Library.Subscriber<R>): void;
11
+ extend<K extends {} = any>(config: DeepPartial<T> & Config<K, R & K>): Library<T & K, R & K>;
12
+ }
13
+ interface Subscriber<R extends {}> {
14
+ onChange(records: ReadonlyArray<Library.Token<DesignToken.Any, R>>): void;
15
+ }
16
+ /**
17
+ * Defines a token library that can be interacted with
18
+ * to mutate token values.
19
+ *
20
+ * @public
21
+ */
22
+ type TokenLibrary<T extends {}, R extends {} = T> = {
23
+ [K in keyof Readonly<T>]: T[K] extends DesignToken.Any ? Token<T[K], R> : K extends "type" ? DesignToken.Type : T[K] extends {} ? TokenLibrary<T[K], R> : never;
24
+ };
25
+ /**
26
+ * A token value that serves as an alias to another token value
27
+ *
28
+ * @public
29
+ */
30
+ type Alias<T extends DesignToken.Any, R extends Context<any>> = (context: R) => T | DesignToken.ValueByToken<T>;
31
+ /**
32
+ * An {@link (Library:namespace).Alias} that supports complex token value types
33
+ * such as {@link DesignToken.Border}
34
+ *
35
+ * @public
36
+ */
37
+ type DeepAlias<V extends DesignToken.Values.Any, T extends Context<any>> = {
38
+ [K in keyof V]: V[K] extends DesignToken.Values.Any ? V[K] | Alias<DesignToken.TokenByValue<V[K]>, T> | DeepAlias<V[K], T> : never;
39
+ };
40
+ /**
41
+ * Context object provided to {@link (Library:namespace).Alias} values at runtime
42
+ *
43
+ * @public
44
+ */
45
+ type Context<T extends {}, R extends {} = T> = {
46
+ [K in keyof Readonly<T>]: T[K] extends DesignToken.Any ? Readonly<T[K]> : K extends "type" ? DesignToken.Type : T[K] extends {} ? Context<T[K], R> : never;
47
+ };
48
+ /**
49
+ * A token in a {@link (Library:namespace).TokenLibrary}
50
+ *
51
+ * @public
52
+ */
53
+ type Token<T extends DesignToken.Any, C extends {}> = {
54
+ set(value: DesignToken.ValueByToken<T> | Alias<T, C>): void;
55
+ toString(): string;
56
+ readonly type: DesignToken.TypeByToken<T>;
57
+ readonly extensions: Record<string, any>;
58
+ readonly value: DesignToken.ValueByToken<T>;
59
+ readonly description: string;
60
+ readonly name: string;
61
+ };
62
+ /**
63
+ * A configuration object provided to {@link Library.create}
64
+ *
65
+ * @public
66
+ */
67
+ type Config<T extends {}, R extends {} = T> = {
68
+ [K in keyof T]: T[K] extends DesignToken.Any ? ConfigValue<T[K], R> : T[K] extends {} ? Config<T[K], R> : never;
69
+ };
70
+ /**
71
+ * @public
72
+ */
73
+ type ConfigValue<T extends DesignToken.Any, R extends {}> = T | (Omit<T, "value"> & {
74
+ value: Library.Alias<T, Context<R>> | Library.DeepAlias<DesignToken.ValueByToken<T>, Context<R>>;
75
+ });
76
+ /**
77
+ * @public
78
+ */
79
+ const create: <T extends {} = any>(config: Library.Config<T, T>) => Library.Library<T>;
80
+ }
@@ -0,0 +1,252 @@
1
+ import { getNotifier } from "./notifier.js";
2
+ import { Queue } from "./queue.js";
3
+ import { empty } from "./utilities.js";
4
+ import { Watcher } from "./watcher.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export var Library;
9
+ (function (Library) {
10
+ /**
11
+ * @public
12
+ */
13
+ Library.create = (config) => {
14
+ return LibraryImpl.create(config);
15
+ };
16
+ })(Library || (Library = {}));
17
+ const isObject = (value) => {
18
+ return typeof value === "object" && value !== null;
19
+ };
20
+ /**
21
+ * @internal
22
+ */
23
+ const isToken = (value) => {
24
+ return isObject(value) && "value" in value;
25
+ };
26
+ const isGroup = (value) => {
27
+ return isObject(value) && !isToken(value);
28
+ };
29
+ const isAlias = (value) => {
30
+ return typeof value === "function";
31
+ };
32
+ const recurseCreate = (name, library, config, context, typeContext, queue) => {
33
+ for (const key in config) {
34
+ if (key === "type") {
35
+ typeContext = config[key];
36
+ continue;
37
+ }
38
+ const _name = name.length === 0 ? key : `${name}.${key}`;
39
+ if (isGroup(config[key])) {
40
+ Reflect.defineProperty(library, key, {
41
+ value: {},
42
+ enumerable: true,
43
+ });
44
+ recurseCreate(_name, library[key], config[key], context, config[key].type || typeContext, queue);
45
+ Object.freeze(library[key]);
46
+ }
47
+ else if (isToken(config[key])) {
48
+ const { value, type, description, extensions } = config[key];
49
+ if (!type && !typeContext) {
50
+ throw new Error(`No 'type' found for token '${key}'. Types cannot be inferred, please add a type to the token or to a group ancestor.`);
51
+ }
52
+ const token = new LibraryToken(_name, value, type || typeContext, context, description || "", extensions || {}, queue);
53
+ Reflect.defineProperty(library, key, {
54
+ get() {
55
+ // Token access needs to be tracked because an alias token
56
+ // is a function that returns a token
57
+ Watcher.track(token);
58
+ return token;
59
+ },
60
+ enumerable: true,
61
+ });
62
+ }
63
+ }
64
+ };
65
+ const recurseExtend = (name, sourceTokens, extendedTokens, config, // TODO allow new config options
66
+ context, typeContext, queue) => {
67
+ const keys = new Set(Object.keys(sourceTokens).concat(Object.keys(config))); // Remove duplicate keys
68
+ for (const key of keys) {
69
+ const sourceHasKey = key in sourceTokens;
70
+ const configHasKey = key in config;
71
+ const _name = name.length === 0 ? key : `${name}.${key}`;
72
+ const keyIsGroup = isGroup(sourceTokens[key]) || isGroup(config[key]);
73
+ const keyIsToken = isToken(sourceTokens[key]) || isToken(config[key]);
74
+ if (key === "type") {
75
+ typeContext = sourceTokens[key];
76
+ continue;
77
+ }
78
+ if (keyIsGroup) {
79
+ Reflect.defineProperty(extendedTokens, key, Object.create(sourceTokens[key]));
80
+ if (sourceHasKey) {
81
+ recurseExtend(_name, sourceTokens[key], extendedTokens[key], config[key] || {}, context, (sourceTokens.type || typeContext), queue);
82
+ }
83
+ else if (configHasKey) {
84
+ // This will always be the case
85
+ recurseCreate(_name, sourceTokens[key], extendedTokens[key], context, (sourceTokens.type || typeContext), queue);
86
+ }
87
+ }
88
+ else if (keyIsToken) {
89
+ const token = sourceTokens[key] !== undefined
90
+ ? extendToken(sourceTokens[key], context, queue, config[key])
91
+ : new LibraryToken(_name, config[key].value, config[key].type || typeContext, context, config[key].description || "", config[key].extensions || {}, queue);
92
+ Reflect.defineProperty(extendedTokens, key, {
93
+ get() {
94
+ // Token access needs to be tracked because an alias token
95
+ // is a function that returns a token
96
+ Watcher.track(token);
97
+ return token;
98
+ },
99
+ enumerable: true,
100
+ });
101
+ }
102
+ }
103
+ };
104
+ function extendToken(token, context, queue, value) {
105
+ const extendingToken = Object.create(token);
106
+ extendingToken.context = context;
107
+ extendingToken.cached = empty;
108
+ extendingToken.watchContext = extendingToken;
109
+ extendingToken.queue = queue;
110
+ if (value !== undefined) {
111
+ extendingToken.raw = value;
112
+ }
113
+ else {
114
+ // Subscribe to changes
115
+ // spy on set, unsubscribe when set
116
+ const subscriber = {
117
+ onChange() {
118
+ extendingToken.onChange();
119
+ },
120
+ };
121
+ // token.value;
122
+ getNotifier(token).subscribe(subscriber);
123
+ const set = extendingToken.set;
124
+ extendingToken.set = (value) => {
125
+ getNotifier(token).unsubscribe(subscriber);
126
+ set.call(extendingToken, value);
127
+ extendingToken.set = set;
128
+ };
129
+ }
130
+ return extendingToken;
131
+ }
132
+ const recurseResolve = (value, context) => {
133
+ const r = Array.isArray(value) ? [] : {};
134
+ for (const key in value) {
135
+ let v = value[key];
136
+ if (isAlias(v)) {
137
+ v = v(context);
138
+ }
139
+ if (isToken(v)) {
140
+ v = v.value;
141
+ }
142
+ if (isObject(v)) {
143
+ r[key] = recurseResolve(v, context);
144
+ }
145
+ else {
146
+ r[key] = v;
147
+ }
148
+ }
149
+ return r;
150
+ };
151
+ class LibraryImpl {
152
+ tokens;
153
+ queue;
154
+ constructor(tokens, queue) {
155
+ this.tokens = tokens;
156
+ this.queue = queue;
157
+ }
158
+ subscribe(subscriber) {
159
+ this.queue.subscribe(subscriber);
160
+ }
161
+ unsubscribe(subscriber) {
162
+ this.queue.unsubscribe(subscriber);
163
+ }
164
+ extend(config) {
165
+ // TODO should not type Library.Config<any>
166
+ const queue = new Queue();
167
+ const tokens = {};
168
+ recurseExtend("", this.tokens, tokens, config, tokens, null, queue);
169
+ return new LibraryImpl(tokens, queue);
170
+ }
171
+ static create(config) {
172
+ const queue = new Queue();
173
+ const tokens = {};
174
+ recurseCreate("", tokens, config, tokens, null, queue);
175
+ return new LibraryImpl(tokens, queue);
176
+ }
177
+ }
178
+ /**
179
+ * An individual token value in a library
180
+ */
181
+ class LibraryToken {
182
+ name;
183
+ _type;
184
+ context;
185
+ _description;
186
+ _extensions;
187
+ queue;
188
+ raw;
189
+ cached = empty;
190
+ subscriptions = new Set();
191
+ constructor(name, value, _type, context, _description, _extensions, queue) {
192
+ this.name = name;
193
+ this._type = _type;
194
+ this.context = context;
195
+ this._description = _description;
196
+ this._extensions = _extensions;
197
+ this.queue = queue;
198
+ this.raw = value;
199
+ this.context = context;
200
+ }
201
+ get type() {
202
+ return this._type;
203
+ }
204
+ get description() {
205
+ return this._description;
206
+ }
207
+ get extensions() {
208
+ return this._extensions;
209
+ }
210
+ /**
211
+ * Gets the token value
212
+ */
213
+ get value() {
214
+ if (this.cached !== empty) {
215
+ return this.cached;
216
+ }
217
+ this.disconnect();
218
+ const stopWatching = Watcher.use(this);
219
+ const raw = isAlias(this.raw) ? this.raw(this.context) : this.raw;
220
+ const normalized = isToken(raw) ? raw.value : raw;
221
+ const value = isObject(normalized)
222
+ ? recurseResolve(normalized, this.context)
223
+ : normalized;
224
+ this.cached = value;
225
+ stopWatching();
226
+ return value;
227
+ }
228
+ set(value) {
229
+ this.raw = value;
230
+ this.onChange();
231
+ }
232
+ onChange() {
233
+ this.queue.add(this);
234
+ this.cached = empty;
235
+ getNotifier(this).notify();
236
+ }
237
+ watch(source) {
238
+ const notifier = getNotifier(source);
239
+ notifier.subscribe(this);
240
+ this.subscriptions.add(notifier);
241
+ }
242
+ /**
243
+ * Disconnect the token from it's subscriptions
244
+ */
245
+ disconnect() {
246
+ for (const record of this.subscriptions.values()) {
247
+ record.unsubscribe(this);
248
+ this.subscriptions.delete(record);
249
+ }
250
+ }
251
+ }
252
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/lib/library.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAU,KAAK,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAe,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAY,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjD;;GAEG;AACH,MAAM,KAAW,OAAO,CAuHvB;AAvHD,WAAiB,OAAO;IA+GtB;;OAEG;IACU,cAAM,GAAG,CACpB,MAA4B,EACR,EAAE;QACtB,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC,EAvHgB,OAAO,KAAP,OAAO,QAuHvB;AAED,MAAM,QAAQ,GAAG,CAAI,KAAQ,EAAmB,EAAE;IAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,GAAG,CACd,KAAc,EACY,EAAE;IAC5B,OAAO,QAAQ,CAAC,KA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ACpB,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,MAAc;QACzB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QACrC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACI,UAAU;QACf,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;YACjD,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACzB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ export declare abstract class Subscribable<T> implements ISubscribable<T> {
2
+ protected subscribers: Set<ISubscriber<T>>;
3
+ subscribe(target: ISubscriber<T>): void;
4
+ unsubscribe(target: ISubscriber<T>): void;
5
+ }
6
+ declare class Notifier<T = any> extends Subscribable<T> implements INotifier<T> {
7
+ #private;
8
+ static getNotifier<T>(target: T): INotifier<T>;
9
+ private static lookup;
10
+ constructor(subject: T);
11
+ notify(): void;
12
+ }
13
+ /**
14
+ * @internal
15
+ */
16
+ export interface ISubscriber<T> {
17
+ onChange(target: T): void;
18
+ }
19
+ export interface ISubscribable<T> {
20
+ subscribe(target: ISubscriber<T>): void;
21
+ unsubscribe(target: ISubscriber<T>): void;
22
+ }
23
+ /**
24
+ * @internal
25
+ */
26
+ export interface INotifier<T> extends ISubscribable<T> {
27
+ notify(): void;
28
+ }
29
+ export declare const getNotifier: typeof Notifier.getNotifier;
30
+ export {};
@@ -0,0 +1,33 @@
1
+ export class Subscribable {
2
+ subscribers = new Set();
3
+ subscribe(target) {
4
+ this.subscribers.add(target);
5
+ }
6
+ unsubscribe(target) {
7
+ this.subscribers.delete(target);
8
+ }
9
+ }
10
+ class Notifier extends Subscribable {
11
+ static getNotifier(target) {
12
+ let notifier = Notifier.lookup.get(target);
13
+ if (!notifier) {
14
+ notifier = new Notifier(target);
15
+ Notifier.lookup.set(target, notifier);
16
+ }
17
+ return notifier;
18
+ }
19
+ static lookup = new WeakMap();
20
+ #subject;
21
+ constructor(subject) {
22
+ super();
23
+ this.#subject = subject;
24
+ }
25
+ notify() {
26
+ const subject = this.#subject;
27
+ for (const value of this.subscribers) {
28
+ value.onChange(subject);
29
+ }
30
+ }
31
+ }
32
+ export const getNotifier = Notifier.getNotifier;
33
+ //# sourceMappingURL=notifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifier.js","sourceRoot":"","sources":["../../src/lib/notifier.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,YAAY;IACtB,WAAW,GAAwB,IAAI,GAAG,EAAE,CAAC;IACvD,SAAS,CAAC,MAAsB;QAC9B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,MAAsB;QAChC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAED,MAAM,QAAkB,SAAQ,YAAe;IACtC,MAAM,CAAC,WAAW,CAAI,MAAS;QACpC,IAAI,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAE3C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;YAChC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,MAAM,CAAC,MAAM,GAAqC,IAAI,OAAO,EAAE,CAAC;IAC/D,QAAQ,CAAI;IAErB,YAAY,OAAU;QACpB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;;AAqBH,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ISubscribable, Subscribable } from "./notifier.js";
2
+ export interface IQueue<T extends {}> extends ISubscribable<ReadonlyArray<T>> {
3
+ add(target: T): void;
4
+ }
5
+ export declare class Queue<T extends {}> extends Subscribable<ReadonlyArray<T>> implements IQueue<T> {
6
+ private targets;
7
+ private needsQueue;
8
+ add(target: T): void;
9
+ private queue;
10
+ }
@@ -0,0 +1,23 @@
1
+ import { Subscribable } from "./notifier.js";
2
+ export class Queue extends Subscribable {
3
+ targets = new Set();
4
+ needsQueue = true;
5
+ add(target) {
6
+ this.targets.add(target);
7
+ if (this.needsQueue) {
8
+ this.queue();
9
+ }
10
+ }
11
+ queue() {
12
+ this.needsQueue = false;
13
+ queueMicrotask(() => {
14
+ const targets = Object.freeze(Array.from(this.targets));
15
+ this.targets.clear();
16
+ this.needsQueue = true;
17
+ for (const subscriber of this.subscribers) {
18
+ subscriber.onChange(targets);
19
+ }
20
+ });
21
+ }
22
+ }
23
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/lib/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAC;AAM5D,MAAM,OAAO,KACX,SAAQ,YAA8B;IAG9B,OAAO,GAAW,IAAI,GAAG,EAAE,CAAC;IAC5B,UAAU,GAAY,IAAI,CAAC;IAE5B,GAAG,CAAC,MAAS;QAClB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,cAAc,CAAC,GAAG,EAAE;YAClB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YACxD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YAEvB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1C,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { DesignToken } from "./design-token.js";
2
+ export declare const empty: unique symbol;
3
+ export type DeepPartial<T> = T extends object ? {
4
+ [P in keyof T]?: T[P] extends DesignToken.Any ? T[P] : DeepPartial<T[P]>;
5
+ } : T;
@@ -0,0 +1,2 @@
1
+ export const empty = Symbol();
2
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../src/lib/utilities.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ export interface IWatcher {
2
+ watch(source: Object): void;
3
+ }
4
+ export declare namespace Watcher {
5
+ function track(source: any): void;
6
+ /**
7
+ * Use the provided watcher
8
+ * @param watcher - the watcher to use
9
+ * @returns - a function that instructs the watcher to stop using the provided watcher
10
+ */
11
+ function use(watcher: IWatcher): () => void;
12
+ }
@@ -0,0 +1,25 @@
1
+ import { empty } from "./utilities.js";
2
+ let _watcher = empty;
3
+ export var Watcher;
4
+ (function (Watcher) {
5
+ function track(source) {
6
+ if (_watcher !== empty) {
7
+ _watcher.watch(source);
8
+ }
9
+ }
10
+ Watcher.track = track;
11
+ /**
12
+ * Use the provided watcher
13
+ * @param watcher - the watcher to use
14
+ * @returns - a function that instructs the watcher to stop using the provided watcher
15
+ */
16
+ function use(watcher) {
17
+ const previousWatcher = _watcher;
18
+ _watcher = watcher;
19
+ return () => {
20
+ _watcher = previousWatcher;
21
+ };
22
+ }
23
+ Watcher.use = use;
24
+ })(Watcher || (Watcher = {}));
25
+ //# sourceMappingURL=watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../src/lib/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAMvC,IAAI,QAAQ,GAA4B,KAAK,CAAC;AAE9C,MAAM,KAAW,OAAO,CAoBvB;AApBD,WAAiB,OAAO;IACtB,SAAgB,KAAK,CAAC,MAAW;QAC/B,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YACvB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAJe,aAAK,QAIpB,CAAA;IAED;;;;OAIG;IACH,SAAgB,GAAG,CAAC,OAAiB;QACnC,MAAM,eAAe,GAAG,QAAQ,CAAC;QACjC,QAAQ,GAAG,OAAO,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,QAAQ,GAAG,eAAe,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC;IAPe,WAAG,MAOlB,CAAA;AACH,CAAC,EApBgB,OAAO,KAAP,OAAO,QAoBvB"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "design-token-library",
3
+ "version": "0.1.0",
4
+ "description": "A library for managing design tokens",
5
+ "type": "module",
6
+ "main": "./dist/lib/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/lib/index.d.ts",
10
+ "default": "./dist/lib/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/lib/index.d.ts",
14
+ "scripts": {
15
+ "build": "tsc -b",
16
+ "watch": "tsc -b -w",
17
+ "watch:test": "watchlist dist/test -- npm test",
18
+ "test": "npx uvu dist/test .spec.js$",
19
+ "report-size": "npx esbuild dist/lib/index.js --bundle --outfile=temp/bundle.js --minify; rm -rf temp",
20
+ "api-report": "npx api-extractor run --local --verbose",
21
+ "docs:api-reference": "npx api-documenter markdown --input-folder temp --output-folder doc-site/docs/api-reference"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/nicholasrice/design-token-library.git"
26
+ },
27
+ "author": "https://github.com/nicholasrice",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/nicholasrice/design-token-library/issues"
31
+ },
32
+ "homepage": "https://github.com/nicholasrice/design-token-library#readme",
33
+ "devDependencies": {
34
+ "@microsoft/api-documenter": "^7.23.12",
35
+ "@microsoft/api-extractor": "^7.38.3",
36
+ "@types/sinon": "^17.0.1",
37
+ "esbuild": "0.19.8",
38
+ "sinon": "^17.0.1",
39
+ "typescript": "^5.4.5",
40
+ "uvu": "^0.5.6",
41
+ "watchlist": "^0.3.1"
42
+ }
43
+ }