@canonical/token-types 0.1.0 → 0.3.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.
@@ -5,5 +5,30 @@
5
5
  * This is the single source of truth. Both `@canonical/terrazzo-plugin-css` and
6
6
  * `@canonical/terrazzo-lsp` import from this package.
7
7
  */
8
- export {};
8
+ /** Shared list of known DTCG token type literals recognised by Canonical tooling. */
9
+ export const KNOWN_DTCG_TOKEN_TYPES = [
10
+ "color",
11
+ "dimension",
12
+ "number",
13
+ "typography",
14
+ "fontFamily",
15
+ "fontWeight",
16
+ "fontStyle",
17
+ "figureStyle",
18
+ "textDecoration",
19
+ "letterCase",
20
+ "fontPosition",
21
+ "duration",
22
+ "cubicBezier",
23
+ "gradient",
24
+ "border",
25
+ "shadow",
26
+ "transition",
27
+ "strokeStyle",
28
+ ];
29
+ /** Runtime guard for narrowing unknown strings to the shared known DTCG set. */
30
+ export function isKnownDtcgTokenType(value) {
31
+ return (typeof value === "string" &&
32
+ KNOWN_DTCG_TOKEN_TYPES.includes(value));
33
+ }
9
34
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/artifact/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/artifact/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,qFAAqF;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,OAAO;IACP,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,aAAa;IACb,gBAAgB;IAChB,YAAY;IACZ,cAAc;IACd,UAAU;IACV,aAAa;IACb,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,aAAa;CACL,CAAC;AAiBX,gFAAgF;AAChF,MAAM,UAAU,oBAAoB,CAClC,KAAgC;IAEhC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACxB,sBAA4C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC9D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Type-level tests for @canonical/token-types (Q34).
3
+ *
4
+ * Uses vitest `expectTypeOf` to verify the type contracts at compile time.
5
+ * No runtime assertions — these tests validate the type system only.
6
+ */
7
+ import { describe, expectTypeOf, it } from "vitest";
8
+ describe("DtcgTokenType", () => {
9
+ it("exposes the shared known DTCG literals as a narrower contract", () => {
10
+ expectTypeOf().toMatchTypeOf();
11
+ expectTypeOf().toMatchTypeOf();
12
+ expectTypeOf().toMatchTypeOf();
13
+ });
14
+ it("accepts known DTCG type literals", () => {
15
+ expectTypeOf().toMatchTypeOf();
16
+ expectTypeOf().toMatchTypeOf();
17
+ expectTypeOf().toMatchTypeOf();
18
+ expectTypeOf().toMatchTypeOf();
19
+ expectTypeOf().toMatchTypeOf();
20
+ expectTypeOf().toMatchTypeOf();
21
+ expectTypeOf().toMatchTypeOf();
22
+ });
23
+ it("accepts arbitrary strings (backward compat)", () => {
24
+ expectTypeOf().toMatchTypeOf();
25
+ expectTypeOf().toMatchTypeOf();
26
+ });
27
+ it("is assignable to ArtifactToken.type", () => {
28
+ expectTypeOf().toEqualTypeOf();
29
+ });
30
+ });
31
+ describe("TokenTier", () => {
32
+ it("is a union of three known literals", () => {
33
+ expectTypeOf().toMatchTypeOf();
34
+ expectTypeOf().toMatchTypeOf();
35
+ expectTypeOf().toMatchTypeOf();
36
+ });
37
+ it("rejects unknown tiers", () => {
38
+ expectTypeOf().not.toMatchTypeOf();
39
+ });
40
+ it("exposes an open artifact tier contract for consumers", () => {
41
+ expectTypeOf().toMatchTypeOf();
42
+ expectTypeOf().toMatchTypeOf();
43
+ });
44
+ });
45
+ describe("DerivationKind", () => {
46
+ it("includes hover, active, disabled, delta, channel-modifier, channel-surface", () => {
47
+ expectTypeOf().toMatchTypeOf();
48
+ expectTypeOf().toMatchTypeOf();
49
+ expectTypeOf().toMatchTypeOf();
50
+ expectTypeOf().toMatchTypeOf();
51
+ expectTypeOf().toMatchTypeOf();
52
+ expectTypeOf().toMatchTypeOf();
53
+ });
54
+ it("exposes an open artifact derivation contract for consumers", () => {
55
+ expectTypeOf().toMatchTypeOf();
56
+ expectTypeOf().toMatchTypeOf();
57
+ });
58
+ });
59
+ describe("ArtifactToken", () => {
60
+ it("has required fields", () => {
61
+ expectTypeOf().toHaveProperty("cssVar");
62
+ expectTypeOf().toHaveProperty("id");
63
+ expectTypeOf().toHaveProperty("type");
64
+ expectTypeOf().toHaveProperty("tier");
65
+ expectTypeOf().toHaveProperty("isPaired");
66
+ expectTypeOf().toHaveProperty("cssOutputFile");
67
+ });
68
+ it("has optional derived-tier fields", () => {
69
+ expectTypeOf().toEqualTypeOf();
70
+ expectTypeOf().toEqualTypeOf();
71
+ });
72
+ it("id is string | null (derived tokens have null id)", () => {
73
+ expectTypeOf().toEqualTypeOf();
74
+ });
75
+ it("uses the open artifact tier contract", () => {
76
+ expectTypeOf().toEqualTypeOf();
77
+ });
78
+ });
79
+ describe("artifact token init contracts", () => {
80
+ it("uses the shared DTCG vocabulary for DTCG-sourced token builders", () => {
81
+ expectTypeOf().toEqualTypeOf();
82
+ });
83
+ it("uses the shared derivation contract for derived token builders", () => {
84
+ expectTypeOf().toEqualTypeOf();
85
+ });
86
+ });
87
+ describe("shared artifact field groups", () => {
88
+ it("keep shared metadata and runtime fields aligned", () => {
89
+ expectTypeOf().toEqualTypeOf();
90
+ expectTypeOf().toEqualTypeOf();
91
+ expectTypeOf().toEqualTypeOf();
92
+ expectTypeOf().toEqualTypeOf();
93
+ expectTypeOf().toEqualTypeOf();
94
+ });
95
+ });
96
+ describe("ArtifactDeclaration", () => {
97
+ it("has selector, file, and line", () => {
98
+ expectTypeOf().toHaveProperty("selector");
99
+ expectTypeOf().toHaveProperty("file");
100
+ expectTypeOf().toHaveProperty("line");
101
+ });
102
+ it("has optional atRules array", () => {
103
+ expectTypeOf().toEqualTypeOf();
104
+ });
105
+ });
106
+ describe("Artifact", () => {
107
+ it("is Record<string, ArtifactToken>", () => {
108
+ expectTypeOf().toEqualTypeOf();
109
+ });
110
+ });
111
+ describe("ArtifactEnvelope", () => {
112
+ it("accepts flat artifact", () => {
113
+ expectTypeOf().toMatchTypeOf();
114
+ });
115
+ it("accepts wrapped artifact", () => {
116
+ expectTypeOf().toMatchTypeOf();
117
+ });
118
+ });
119
+ //# sourceMappingURL=types.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.test-d.js","sourceRoot":"","sources":["../../../src/artifact/types.test-d.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAyBpD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,YAAY,EAAW,CAAC,aAAa,EAAsB,CAAC;QAC5D,YAAY,EAAc,CAAC,aAAa,EAAsB,CAAC;QAC/D,YAAY,EAAc,CAAC,aAAa,EAAsB,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,YAAY,EAAW,CAAC,aAAa,EAAiB,CAAC;QACvD,YAAY,EAAe,CAAC,aAAa,EAAiB,CAAC;QAC3D,YAAY,EAAY,CAAC,aAAa,EAAiB,CAAC;QACxD,YAAY,EAAgB,CAAC,aAAa,EAAiB,CAAC;QAC5D,YAAY,EAAgB,CAAC,aAAa,EAAiB,CAAC;QAC5D,YAAY,EAAgB,CAAC,aAAa,EAAiB,CAAC;QAC5D,YAAY,EAAe,CAAC,aAAa,EAAiB,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,YAAY,EAAiB,CAAC,aAAa,EAAiB,CAAC;QAC7D,Y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AAC,CAAC,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ export { isKnownDtcgTokenType, KNOWN_DTCG_TOKEN_TYPES, } from "./artifact/types.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC"}
@@ -5,10 +5,42 @@
5
5
  * This is the single source of truth. Both `@canonical/terrazzo-plugin-css` and
6
6
  * `@canonical/terrazzo-lsp` import from this package.
7
7
  */
8
- /** Tier classification for a token. */
9
- export type TokenTier = "primitive" | "semantic" | "derived";
10
- /** Derivation formula kind for derived-tier tokens. */
11
- export type DerivationKind = "hover" | "active" | "disabled" | "delta" | "channel-modifier" | "channel-surface";
8
+ /** Canonical tier literals emitted by Canonical token producers. */
9
+ export type KnownTokenTier = "primitive" | "semantic" | "derived";
10
+ /** Tier classification for Canonical-produced tokens. */
11
+ export type TokenTier = KnownTokenTier;
12
+ /**
13
+ * Tier strings carried by artifacts.
14
+ *
15
+ * Consumers should distinguish known tiers, but must tolerate non-Canonical
16
+ * tier strings from other producers.
17
+ */
18
+ export type ArtifactTier = KnownTokenTier | (string & {});
19
+ /** Shared list of known DTCG token type literals recognised by Canonical tooling. */
20
+ export declare const KNOWN_DTCG_TOKEN_TYPES: readonly ["color", "dimension", "number", "typography", "fontFamily", "fontWeight", "fontStyle", "figureStyle", "textDecoration", "letterCase", "fontPosition", "duration", "cubicBezier", "gradient", "border", "shadow", "transition", "strokeStyle"];
21
+ /** Known DTCG token type literals recognised by Canonical tooling. */
22
+ export type KnownDtcgTokenType = (typeof KNOWN_DTCG_TOKEN_TYPES)[number];
23
+ /**
24
+ * DTCG $type values used by the Canonical token system.
25
+ *
26
+ * The `(string & {})` arm preserves backward compatibility — callers may
27
+ * pass arbitrary strings without a type error, but autocomplete still
28
+ * suggests the known literals.
29
+ */
30
+ export type DtcgTokenType = KnownDtcgTokenType | (string & {});
31
+ /** Runtime guard for narrowing unknown strings to the shared known DTCG set. */
32
+ export declare function isKnownDtcgTokenType(value: string | null | undefined): value is KnownDtcgTokenType;
33
+ /** Canonical derivation literals emitted by Canonical token producers. */
34
+ export type KnownDerivationKind = "hover" | "active" | "disabled" | "delta" | "channel-modifier" | "channel-surface";
35
+ /** Derivation formula kind for Canonical-produced derived tokens. */
36
+ export type DerivationKind = KnownDerivationKind;
37
+ /**
38
+ * Derivation strings carried by artifacts.
39
+ *
40
+ * Consumers should recognise known derivations, but must tolerate
41
+ * non-Canonical derivation strings from other producers.
42
+ */
43
+ export type ArtifactDerivationKind = KnownDerivationKind | (string & {});
12
44
  /** An at-rule context surrounding a declaration (e.g. `@layer ds.modifiers`). */
13
45
  export interface ArtifactAtRule {
14
46
  /** At-rule name (e.g. "layer", "media"). */
@@ -27,20 +59,23 @@ export interface ArtifactDeclaration {
27
59
  /** Enclosing at-rules, innermost-first (e.g. `@layer`, `@media`). */
28
60
  atRules?: ArtifactAtRule[];
29
61
  }
30
- /** A single token entry in the artifact JSON. */
31
- export interface ArtifactToken {
32
- /** CSS custom property name as emitted. */
33
- cssVar: string;
62
+ /** Shared artifact metadata fields carried across producer and consumer layers. */
63
+ export interface ArtifactMetadataFields {
34
64
  /** DTCG token ID from source, or `null` for derived tokens. */
35
65
  id: string | null;
36
66
  /** DTCG $type. */
37
- type: string;
67
+ type: DtcgTokenType;
38
68
  /** Token tier classification. */
39
- tier: TokenTier;
69
+ tier: ArtifactTier;
40
70
  /** DTCG $description. */
41
71
  description?: string;
42
72
  /** Full alias resolution chain (token IDs). */
43
73
  aliasChain?: string[];
74
+ /** DTCG $extensions passthrough. */
75
+ extensions?: Record<string, unknown>;
76
+ }
77
+ /** Shared resolved value fields carried in artifacts. */
78
+ export interface ArtifactResolvedValueFields {
44
79
  /** Resolved CSS value (mode-invariant tokens). */
45
80
  value?: string;
46
81
  /** Light-mode resolved CSS value. */
@@ -49,6 +84,9 @@ export interface ArtifactToken {
49
84
  valueDark?: string;
50
85
  /** `true` when valueLight !== valueDark. */
51
86
  isPaired: boolean;
87
+ }
88
+ /** Shared source-location fields carried in artifacts. */
89
+ export interface ArtifactSourceFields {
52
90
  /** DTCG source file path (relative). */
53
91
  sourceFile?: string;
54
92
  /** Line number in the DTCG source file. */
@@ -59,10 +97,16 @@ export interface ArtifactToken {
59
97
  cssOutputLine?: number;
60
98
  /** Declaration sites: where this token is provided in the CSS output. */
61
99
  declarations?: ArtifactDeclaration[];
100
+ }
101
+ /** Shared derived-token fields carried in artifacts. */
102
+ export interface ArtifactDerivationFields {
62
103
  /** CSS var name of the source token (derived tier). */
63
104
  derivedFrom?: string;
64
105
  /** Formula kind (derived tier). */
65
- derivation?: DerivationKind;
106
+ derivation?: ArtifactDerivationKind;
107
+ }
108
+ /** Shared CSS `@property` registration fields carried in artifacts. */
109
+ export interface ArtifactRegistrationFields {
66
110
  /** `true` when the token has a CSS `@property` registration. */
67
111
  registered?: boolean;
68
112
  /** `@property` syntax (e.g. `"<color>"`). */
@@ -71,18 +115,73 @@ export interface ArtifactToken {
71
115
  inherits?: boolean | null;
72
116
  /** `@property` initial-value. */
73
117
  initialValue?: string | null;
74
- /** DTCG $extensions passthrough. */
75
- extensions?: Record<string, unknown>;
118
+ }
119
+ /** A single token entry in the artifact JSON. */
120
+ export interface ArtifactToken extends ArtifactMetadataFields, ArtifactResolvedValueFields, ArtifactSourceFields, ArtifactDerivationFields, ArtifactRegistrationFields {
121
+ /** CSS custom property name as emitted. */
122
+ cssVar: string;
123
+ }
124
+ /** Input contract for constructing a DTCG-sourced artifact token. */
125
+ export interface ArtifactTokenInit {
126
+ /** CSS custom property name as emitted. */
127
+ cssVar: string;
128
+ /** DTCG token ID from source. */
129
+ id: string;
130
+ /** DTCG $type. */
131
+ type: DtcgTokenType;
132
+ /** Token tier classification. */
133
+ tier: TokenTier;
134
+ /** CSS output file containing this token's declaration. */
135
+ cssOutputFile: string;
136
+ /** DTCG $description. */
137
+ description?: string;
138
+ /** Declaration sites emitted in CSS output. */
139
+ declarations?: ArtifactDeclaration[];
140
+ /** Full alias resolution chain (token IDs). */
141
+ aliasChain?: string[];
142
+ /** Light-mode resolved CSS value. */
143
+ valueLight?: string;
144
+ /** Dark-mode resolved CSS value. */
145
+ valueDark?: string;
146
+ /** DTCG source file path (relative). */
147
+ sourceFile?: string;
148
+ /** Line number in the DTCG source file. */
149
+ sourceLine?: number;
150
+ }
151
+ /** Input contract for constructing a derived or plugin-generated artifact token. */
152
+ export interface DerivedArtifactTokenInit {
153
+ /** CSS custom property name as emitted. */
154
+ cssVar: string;
155
+ /** DTCG $type. */
156
+ type: DtcgTokenType;
157
+ /** Token tier classification. */
158
+ tier: TokenTier;
159
+ /** CSS output file containing this token's declaration. */
160
+ cssOutputFile: string;
161
+ /** CSS var name of the source token. */
162
+ derivedFrom: string;
163
+ /** Formula kind for the derived token. */
164
+ derivation: DerivationKind;
165
+ /** DTCG $description. */
166
+ description?: string;
167
+ /** Declaration sites emitted in CSS output. */
168
+ declarations?: ArtifactDeclaration[];
169
+ /** Light-mode resolved CSS value. */
170
+ valueLight?: string;
171
+ /** Dark-mode resolved CSS value. */
172
+ valueDark?: string;
76
173
  }
77
174
  /** The complete artifact: CSS variable name → token metadata. */
78
175
  export type Artifact = Record<string, ArtifactToken>;
176
+ /** Wrapped artifact payload with metadata envelope. */
177
+ export interface WrappedArtifactEnvelope {
178
+ version: string;
179
+ generator: string;
180
+ tokens: Artifact;
181
+ }
79
182
  /**
80
183
  * Wrapped artifact format (supports legacy/spec envelope).
81
184
  * The plugin may emit either flat or wrapped.
82
185
  */
83
- export type ArtifactEnvelope = Artifact | {
84
- version: string;
85
- generator: string;
86
- tokens: Artifact;
87
- };
186
+ export type ArtifactEnvelope = Artifact | WrappedArtifactEnvelope;
88
187
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/artifact/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,uCAAuC;AACvC,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;AAE7D,uDAAuD;AACvD,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,QAAQ,GACR,UAAU,GACV,OAAO,GACP,kBAAkB,GAClB,iBAAiB,CAAC;AAMtB,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,gDAAgD;AAChD,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;CAC5B;AAMD,iDAAiD;AACjD,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IAEf,+DAA+D;IAC/D,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAElB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IAEb,iCAAiC;IACjC,IAAI,EAAE,SAAS,CAAC;IAEhB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,4CAA4C;IAC5C,QAAQ,EAAE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,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD,iEAAiE;AACjE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAErD,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.test-d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.test-d.d.ts","sourceRoot":"","sources":["../../../src/artifact/types.test-d.ts"],"names":[],"mappings":""}
@@ -1,2 +1,3 @@
1
- export type { Artifact, ArtifactAtRule, ArtifactDeclaration, ArtifactEnvelope, ArtifactToken, DerivationKind, TokenTier, } from "./artifact/types.js";
1
+ export { isKnownDtcgTokenType, KNOWN_DTCG_TOKEN_TYPES, } from "./artifact/types.js";
2
+ export type { Artifact, ArtifactAtRule, ArtifactDeclaration, ArtifactDerivationKind, ArtifactDerivationFields, ArtifactEnvelope, ArtifactMetadataFields, ArtifactRegistrationFields, ArtifactResolvedValueFields, ArtifactSourceFields, ArtifactToken, ArtifactTokenInit, ArtifactTier, DerivationKind, DerivedArtifactTokenInit, DtcgTokenType, KnownDerivationKind, KnownTokenTier, KnownDtcgTokenType, TokenTier, WrappedArtifactEnvelope, } from "./artifact/types.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,SAAS,GACV,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,EAC3B,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/token-types",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared types for Canonical design token tooling.",
5
5
  "type": "module",
6
6
  "license": "LGPL-3.0",
@@ -35,10 +35,12 @@
35
35
  "scripts": {
36
36
  "build": "tsc -p tsconfig.build.json",
37
37
  "check": "bun run check:ts",
38
- "check:ts": "tsc --noEmit"
38
+ "check:ts": "tsc --noEmit",
39
+ "test": "vitest run --typecheck.only"
39
40
  },
40
41
  "devDependencies": {
41
- "@canonical/typescript-config-base": "^0.10.0-experimental.4",
42
- "typescript": "^5.9.3"
42
+ "@canonical/typescript-config-base": "^0.12.0",
43
+ "typescript": "^5.9.3",
44
+ "vitest": "^4.0.18"
43
45
  }
44
46
  }