@pixerate/editor 0.23.0 → 0.25.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.
Files changed (187) hide show
  1. package/README.md +167 -2
  2. package/THIRD_PARTY_NOTICES.md +80 -0
  3. package/dist/agent/index.cjs +10 -8
  4. package/dist/agent/index.cjs.map +1 -1
  5. package/dist/agent/index.d.cts +4 -3
  6. package/dist/agent/index.d.ts +4 -3
  7. package/dist/agent/index.js +4 -2
  8. package/dist/agent/index.js.map +1 -1
  9. package/dist/canvas/index.cjs +4437 -411
  10. package/dist/canvas/index.cjs.map +1 -1
  11. package/dist/canvas/index.d.cts +934 -4
  12. package/dist/canvas/index.d.ts +934 -4
  13. package/dist/canvas/index.js +4309 -283
  14. package/dist/canvas/index.js.map +1 -1
  15. package/dist/chunk-4BVP64JJ.cjs +1406 -0
  16. package/dist/chunk-4BVP64JJ.cjs.map +1 -0
  17. package/dist/chunk-664LQYFJ.js +115 -0
  18. package/dist/chunk-664LQYFJ.js.map +1 -0
  19. package/dist/chunk-7WISYZFO.cjs +740 -0
  20. package/dist/chunk-7WISYZFO.cjs.map +1 -0
  21. package/dist/chunk-AL6JMGWW.cjs +783 -0
  22. package/dist/chunk-AL6JMGWW.cjs.map +1 -0
  23. package/dist/chunk-BVP3TSLH.cjs +69 -0
  24. package/dist/chunk-BVP3TSLH.cjs.map +1 -0
  25. package/dist/{chunk-RIKBJLS2.cjs → chunk-C7P22VIP.cjs} +2001 -279
  26. package/dist/chunk-C7P22VIP.cjs.map +1 -0
  27. package/dist/chunk-D6FH2YAX.cjs +131 -0
  28. package/dist/chunk-D6FH2YAX.cjs.map +1 -0
  29. package/dist/chunk-ECCCYKGL.js +740 -0
  30. package/dist/chunk-ECCCYKGL.js.map +1 -0
  31. package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
  32. package/dist/chunk-FD4LPFAE.cjs.map +1 -0
  33. package/dist/{chunk-QBJ22YZR.js → chunk-FH6F67DN.js} +1999 -277
  34. package/dist/chunk-FH6F67DN.js.map +1 -0
  35. package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
  36. package/dist/chunk-FPENXAEJ.js.map +1 -0
  37. package/dist/chunk-HLIMTC6N.js +1 -0
  38. package/dist/chunk-HLIMTC6N.js.map +1 -0
  39. package/dist/chunk-HRMEDT2L.js +1406 -0
  40. package/dist/chunk-HRMEDT2L.js.map +1 -0
  41. package/dist/{chunk-QGHGJ56O.js → chunk-IXHSYOVY.js} +2518 -122
  42. package/dist/chunk-IXHSYOVY.js.map +1 -0
  43. package/dist/chunk-MKA3AHLV.cjs +256 -0
  44. package/dist/chunk-MKA3AHLV.cjs.map +1 -0
  45. package/dist/chunk-NAXVVS5I.js +783 -0
  46. package/dist/chunk-NAXVVS5I.js.map +1 -0
  47. package/dist/chunk-O5RYH2PG.js +69 -0
  48. package/dist/chunk-O5RYH2PG.js.map +1 -0
  49. package/dist/chunk-OXSV64JX.js +689 -0
  50. package/dist/chunk-OXSV64JX.js.map +1 -0
  51. package/dist/chunk-P3RQ5UJE.cjs +689 -0
  52. package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
  53. package/dist/chunk-P6ODPZ4W.js +256 -0
  54. package/dist/chunk-P6ODPZ4W.js.map +1 -0
  55. package/dist/chunk-PL4JB3BF.cjs +1 -0
  56. package/dist/chunk-PL4JB3BF.cjs.map +1 -0
  57. package/dist/{chunk-GVSMRPHB.cjs → chunk-PO6A6QQH.cjs} +2607 -211
  58. package/dist/chunk-PO6A6QQH.cjs.map +1 -0
  59. package/dist/{chunk-JJDLPEWL.js → chunk-QGYDWPRM.js} +2 -2
  60. package/dist/chunk-RR7F5GUM.js +5726 -0
  61. package/dist/chunk-RR7F5GUM.js.map +1 -0
  62. package/dist/chunk-TNNJXF46.cjs +115 -0
  63. package/dist/chunk-TNNJXF46.cjs.map +1 -0
  64. package/dist/chunk-U5HZSFCS.js +131 -0
  65. package/dist/chunk-U5HZSFCS.js.map +1 -0
  66. package/dist/{chunk-MJZBNWG7.js → chunk-UAKDG62Z.js} +309 -581
  67. package/dist/chunk-UAKDG62Z.js.map +1 -0
  68. package/dist/{chunk-CL37JGFW.cjs → chunk-V3CHHWOE.cjs} +4 -4
  69. package/dist/{chunk-CL37JGFW.cjs.map → chunk-V3CHHWOE.cjs.map} +1 -1
  70. package/dist/chunk-WSQKHXW7.cjs +5726 -0
  71. package/dist/chunk-WSQKHXW7.cjs.map +1 -0
  72. package/dist/{chunk-AA4ZEVCC.cjs → chunk-X4N4WUKB.cjs} +336 -608
  73. package/dist/chunk-X4N4WUKB.cjs.map +1 -0
  74. package/dist/commands/index.cjs +74 -1
  75. package/dist/commands/index.cjs.map +1 -1
  76. package/dist/commands/index.d.cts +38 -353
  77. package/dist/commands/index.d.ts +38 -353
  78. package/dist/commands/index.js +73 -0
  79. package/dist/commands/index.js.map +1 -1
  80. package/dist/comment-store-BEMgVlAA.d.cts +135 -0
  81. package/dist/comment-store-BEMgVlAA.d.ts +135 -0
  82. package/dist/compare/index.cjs +15 -0
  83. package/dist/compare/index.cjs.map +1 -0
  84. package/dist/compare/index.d.cts +58 -0
  85. package/dist/compare/index.d.ts +58 -0
  86. package/dist/compare/index.js +15 -0
  87. package/dist/compare/index.js.map +1 -0
  88. package/dist/controller-BIJiNoVs.d.cts +1842 -0
  89. package/dist/controller-BIJiNoVs.d.ts +1842 -0
  90. package/dist/documents-CHT1U5Vs.d.ts +86 -0
  91. package/dist/documents-Gp7wb0Me.d.cts +86 -0
  92. package/dist/extensions/index.cjs +100 -5
  93. package/dist/extensions/index.cjs.map +1 -1
  94. package/dist/extensions/index.d.cts +16 -4
  95. package/dist/extensions/index.d.ts +16 -4
  96. package/dist/extensions/index.js +100 -5
  97. package/dist/generation/index.cjs +2317 -0
  98. package/dist/generation/index.cjs.map +1 -0
  99. package/dist/generation/index.d.cts +1015 -0
  100. package/dist/generation/index.d.ts +1015 -0
  101. package/dist/generation/index.js +2317 -0
  102. package/dist/generation/index.js.map +1 -0
  103. package/dist/grammar/index.cjs +48 -3
  104. package/dist/grammar/index.cjs.map +1 -1
  105. package/dist/grammar/index.d.cts +322 -100
  106. package/dist/grammar/index.d.ts +322 -100
  107. package/dist/grammar/index.js +54 -9
  108. package/dist/image-editor/index.cjs +4392 -481
  109. package/dist/image-editor/index.cjs.map +1 -1
  110. package/dist/image-editor/index.d.cts +1249 -97
  111. package/dist/image-editor/index.d.ts +1249 -97
  112. package/dist/image-editor/index.js +4281 -370
  113. package/dist/image-editor/index.js.map +1 -1
  114. package/dist/index-7a6bHTLy.d.ts +1754 -0
  115. package/dist/index-Csd5qI8u.d.cts +1754 -0
  116. package/dist/index.cjs +1682 -99
  117. package/dist/index.cjs.map +1 -1
  118. package/dist/index.d.cts +118 -21
  119. package/dist/index.d.ts +118 -21
  120. package/dist/index.js +1630 -47
  121. package/dist/index.js.map +1 -1
  122. package/dist/mention-text-CDnCFd3c.d.cts +53 -0
  123. package/dist/mention-text-CDnCFd3c.d.ts +53 -0
  124. package/dist/migrate-iTlm3a8h.d.cts +112 -0
  125. package/dist/migrate-iTlm3a8h.d.ts +112 -0
  126. package/dist/model-C1zApQM8.d.cts +219 -0
  127. package/dist/model-C1zApQM8.d.ts +219 -0
  128. package/dist/persistence/index.cjs +676 -0
  129. package/dist/persistence/index.cjs.map +1 -0
  130. package/dist/persistence/index.d.cts +230 -0
  131. package/dist/persistence/index.d.ts +230 -0
  132. package/dist/persistence/index.js +676 -0
  133. package/dist/persistence/index.js.map +1 -0
  134. package/dist/{registry-D5-R90p0.d.cts → registry-BDe-vlv3.d.ts} +2 -40
  135. package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.cts} +12 -1
  136. package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.ts} +12 -1
  137. package/dist/registry-D32LpIc4.d.cts +354 -0
  138. package/dist/{registry-D5-R90p0.d.ts → registry-DnzpgY27.d.cts} +2 -40
  139. package/dist/registry-evKTP4ls.d.ts +354 -0
  140. package/dist/schema-DYDGdYL9.d.cts +41 -0
  141. package/dist/schema-DYDGdYL9.d.ts +41 -0
  142. package/dist/serializers/index.cjs +12 -3
  143. package/dist/serializers/index.cjs.map +1 -1
  144. package/dist/serializers/index.d.cts +40 -12
  145. package/dist/serializers/index.d.ts +40 -12
  146. package/dist/serializers/index.js +12 -3
  147. package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
  148. package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
  149. package/dist/spreadsheet/index.cjs +161 -3
  150. package/dist/spreadsheet/index.cjs.map +1 -1
  151. package/dist/spreadsheet/index.d.cts +611 -20
  152. package/dist/spreadsheet/index.d.ts +611 -20
  153. package/dist/spreadsheet/index.js +168 -10
  154. package/dist/storage-BpFfspHm.d.cts +120 -0
  155. package/dist/storage-BpFfspHm.d.ts +120 -0
  156. package/dist/tokens/index.cjs +115 -0
  157. package/dist/tokens/index.cjs.map +1 -0
  158. package/dist/tokens/index.d.cts +212 -0
  159. package/dist/tokens/index.d.ts +212 -0
  160. package/dist/tokens/index.js +115 -0
  161. package/dist/tokens/index.js.map +1 -0
  162. package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
  163. package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
  164. package/dist/{track-changes-BSF58RK0.d.cts → track-changes-D_VAPELi.d.cts} +110 -144
  165. package/dist/{track-changes-BSF58RK0.d.ts → track-changes-Db_fGEvx.d.ts} +110 -144
  166. package/package.json +21 -1
  167. package/dist/chunk-4SUNJZWB.cjs.map +0 -1
  168. package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
  169. package/dist/chunk-AXV2ZW34.cjs +0 -118
  170. package/dist/chunk-AXV2ZW34.cjs.map +0 -1
  171. package/dist/chunk-B2ZRLN4S.js +0 -118
  172. package/dist/chunk-B2ZRLN4S.js.map +0 -1
  173. package/dist/chunk-GVSMRPHB.cjs.map +0 -1
  174. package/dist/chunk-K3R5NG2D.js +0 -3100
  175. package/dist/chunk-K3R5NG2D.js.map +0 -1
  176. package/dist/chunk-MJZBNWG7.js.map +0 -1
  177. package/dist/chunk-OYXSKQFR.js.map +0 -1
  178. package/dist/chunk-QBJ22YZR.js.map +0 -1
  179. package/dist/chunk-QGHGJ56O.js.map +0 -1
  180. package/dist/chunk-RIKBJLS2.cjs.map +0 -1
  181. package/dist/chunk-XDMXXC4Z.cjs +0 -3100
  182. package/dist/chunk-XDMXXC4Z.cjs.map +0 -1
  183. package/dist/controller-pePCJLT1.d.cts +0 -959
  184. package/dist/controller-pePCJLT1.d.ts +0 -959
  185. package/dist/index-CCr_z9kF.d.cts +0 -899
  186. package/dist/index-Ck6ajwXh.d.ts +0 -899
  187. /package/dist/{chunk-JJDLPEWL.js.map → chunk-QGYDWPRM.js.map} +0 -0
@@ -0,0 +1,112 @@
1
+ /** A section whose stored value did not fit; its defaults were used instead. */
2
+ interface SectionProblem {
3
+ /** Top-level key of the section. */
4
+ section: string;
5
+ message: string;
6
+ }
7
+ /** Why a loaded document must not be written back. */
8
+ type ReadOnlyReason = {
9
+ kind: "newerVersion";
10
+ version: number;
11
+ supported: number;
12
+ message: string;
13
+ } | {
14
+ kind: "migrationFailed";
15
+ from: number;
16
+ message: string;
17
+ } | {
18
+ kind: "invalid";
19
+ message: string;
20
+ };
21
+ /** What happened while loading a document. Nothing in here is fatal. */
22
+ interface LoadReport {
23
+ /** Set when the document was upgraded step by step from this older version. */
24
+ migratedFrom: number | null;
25
+ /** The version found in the input (`null` when it had none). */
26
+ version: number | null;
27
+ /** Sections replaced by their defaults (see `loadSections`). */
28
+ problems: SectionProblem[];
29
+ /**
30
+ * Set when the document must not be saved over: written by a newer build,
31
+ * a migration step failed, or the input was not an object. Show the values,
32
+ * but never overwrite the stored document.
33
+ */
34
+ readOnly: ReadOnlyReason | null;
35
+ /** Top-level keys this build does not know; kept in `unknown` so a save can write them back. */
36
+ unknownKeys: string[];
37
+ }
38
+ /** True when something should be shown to the user. */
39
+ declare function hasLoadProblems(report: LoadReport): boolean;
40
+ declare function createLoadReport(partial?: Partial<LoadReport>): LoadReport;
41
+ type JsonObject = Record<string, unknown>;
42
+ /** One migration step: turns a document at version `from` into version `from + 1`. */
43
+ type MigrationStep = (doc: JsonObject) => JsonObject | void;
44
+ interface MigrateOptions {
45
+ /** The version this build writes. */
46
+ currentVersion: number;
47
+ /** Steps keyed by the version they start from. */
48
+ steps?: Record<number, MigrationStep>;
49
+ /** Key holding the version (default `"version"`). */
50
+ versionKey?: string;
51
+ /**
52
+ * Version assumed when the key is missing (default: `currentVersion`, i.e. a
53
+ * hand-written document is taken as current and the key is added).
54
+ */
55
+ missingVersion?: number;
56
+ }
57
+ interface MigrateResult {
58
+ /** The migrated document (a deep copy; the input is never modified). */
59
+ doc: JsonObject;
60
+ report: LoadReport;
61
+ }
62
+ /**
63
+ * Brings a stored document up to `currentVersion` by running one step per
64
+ * version (`steps[v]` turns version `v` into `v + 1`).
65
+ *
66
+ * - Missing version: taken as `missingVersion` (default current); the key is added.
67
+ * - Newer than `currentVersion`: left alone and reported `readOnly` (never overwrite
68
+ * a file written by a newer build).
69
+ * - A missing or throwing step: the document is returned as it was before
70
+ * migrating and reported `readOnly`.
71
+ * - Keys the steps do not touch are preserved.
72
+ */
73
+ declare function migrateDocument(json: unknown, options: MigrateOptions): MigrateResult;
74
+ /** How one top-level section is read. */
75
+ interface SectionSpec<V> {
76
+ /** Validates / converts the stored value; throw (or return `undefined`) to reject it. */
77
+ parse: (value: unknown) => V | undefined;
78
+ /** Used when the section is missing or rejected. */
79
+ defaults: V | (() => V);
80
+ }
81
+ type SectionSpecs<T> = {
82
+ [K in keyof T]: SectionSpec<T[K]>;
83
+ };
84
+ interface LoadSectionsOptions {
85
+ /** Keys that are neither sections nor unknown (default `["version"]`). */
86
+ ignore?: string[];
87
+ }
88
+ interface LoadSectionsResult<T> {
89
+ value: T;
90
+ /** Sections that were present but rejected (missing ones are not problems). */
91
+ problems: SectionProblem[];
92
+ /** Top-level keys not described by `sections`; write them back to keep them. */
93
+ unknown: JsonObject;
94
+ }
95
+ /**
96
+ * Reads `doc` one top-level section at a time: a section that does not parse
97
+ * is reported and replaced by its defaults, every other section is kept. This
98
+ * keeps one bad value (e.g. a renamed enum) from resetting the whole document.
99
+ */
100
+ declare function loadSections<T>(doc: unknown, sections: SectionSpecs<T>, options?: LoadSectionsOptions): LoadSectionsResult<T>;
101
+ interface LoadDocumentOptions extends MigrateOptions, LoadSectionsOptions {
102
+ }
103
+ interface LoadDocumentResult<T> extends LoadSectionsResult<T> {
104
+ report: LoadReport;
105
+ }
106
+ /**
107
+ * `migrateDocument` followed by `loadSections`, with one `LoadReport`
108
+ * (`problems` and `unknownKeys` filled in).
109
+ */
110
+ declare function loadDocument<T>(json: unknown, sections: SectionSpecs<T>, options: LoadDocumentOptions): LoadDocumentResult<T>;
111
+
112
+ export { type JsonObject as J, type LoadDocumentOptions as L, type MigrateOptions as M, type ReadOnlyReason as R, type SectionProblem as S, type LoadDocumentResult as a, type LoadReport as b, type LoadSectionsOptions as c, type LoadSectionsResult as d, type MigrateResult as e, type MigrationStep as f, type SectionSpec as g, type SectionSpecs as h, createLoadReport as i, hasLoadProblems as j, loadSections as k, loadDocument as l, migrateDocument as m };
@@ -0,0 +1,112 @@
1
+ /** A section whose stored value did not fit; its defaults were used instead. */
2
+ interface SectionProblem {
3
+ /** Top-level key of the section. */
4
+ section: string;
5
+ message: string;
6
+ }
7
+ /** Why a loaded document must not be written back. */
8
+ type ReadOnlyReason = {
9
+ kind: "newerVersion";
10
+ version: number;
11
+ supported: number;
12
+ message: string;
13
+ } | {
14
+ kind: "migrationFailed";
15
+ from: number;
16
+ message: string;
17
+ } | {
18
+ kind: "invalid";
19
+ message: string;
20
+ };
21
+ /** What happened while loading a document. Nothing in here is fatal. */
22
+ interface LoadReport {
23
+ /** Set when the document was upgraded step by step from this older version. */
24
+ migratedFrom: number | null;
25
+ /** The version found in the input (`null` when it had none). */
26
+ version: number | null;
27
+ /** Sections replaced by their defaults (see `loadSections`). */
28
+ problems: SectionProblem[];
29
+ /**
30
+ * Set when the document must not be saved over: written by a newer build,
31
+ * a migration step failed, or the input was not an object. Show the values,
32
+ * but never overwrite the stored document.
33
+ */
34
+ readOnly: ReadOnlyReason | null;
35
+ /** Top-level keys this build does not know; kept in `unknown` so a save can write them back. */
36
+ unknownKeys: string[];
37
+ }
38
+ /** True when something should be shown to the user. */
39
+ declare function hasLoadProblems(report: LoadReport): boolean;
40
+ declare function createLoadReport(partial?: Partial<LoadReport>): LoadReport;
41
+ type JsonObject = Record<string, unknown>;
42
+ /** One migration step: turns a document at version `from` into version `from + 1`. */
43
+ type MigrationStep = (doc: JsonObject) => JsonObject | void;
44
+ interface MigrateOptions {
45
+ /** The version this build writes. */
46
+ currentVersion: number;
47
+ /** Steps keyed by the version they start from. */
48
+ steps?: Record<number, MigrationStep>;
49
+ /** Key holding the version (default `"version"`). */
50
+ versionKey?: string;
51
+ /**
52
+ * Version assumed when the key is missing (default: `currentVersion`, i.e. a
53
+ * hand-written document is taken as current and the key is added).
54
+ */
55
+ missingVersion?: number;
56
+ }
57
+ interface MigrateResult {
58
+ /** The migrated document (a deep copy; the input is never modified). */
59
+ doc: JsonObject;
60
+ report: LoadReport;
61
+ }
62
+ /**
63
+ * Brings a stored document up to `currentVersion` by running one step per
64
+ * version (`steps[v]` turns version `v` into `v + 1`).
65
+ *
66
+ * - Missing version: taken as `missingVersion` (default current); the key is added.
67
+ * - Newer than `currentVersion`: left alone and reported `readOnly` (never overwrite
68
+ * a file written by a newer build).
69
+ * - A missing or throwing step: the document is returned as it was before
70
+ * migrating and reported `readOnly`.
71
+ * - Keys the steps do not touch are preserved.
72
+ */
73
+ declare function migrateDocument(json: unknown, options: MigrateOptions): MigrateResult;
74
+ /** How one top-level section is read. */
75
+ interface SectionSpec<V> {
76
+ /** Validates / converts the stored value; throw (or return `undefined`) to reject it. */
77
+ parse: (value: unknown) => V | undefined;
78
+ /** Used when the section is missing or rejected. */
79
+ defaults: V | (() => V);
80
+ }
81
+ type SectionSpecs<T> = {
82
+ [K in keyof T]: SectionSpec<T[K]>;
83
+ };
84
+ interface LoadSectionsOptions {
85
+ /** Keys that are neither sections nor unknown (default `["version"]`). */
86
+ ignore?: string[];
87
+ }
88
+ interface LoadSectionsResult<T> {
89
+ value: T;
90
+ /** Sections that were present but rejected (missing ones are not problems). */
91
+ problems: SectionProblem[];
92
+ /** Top-level keys not described by `sections`; write them back to keep them. */
93
+ unknown: JsonObject;
94
+ }
95
+ /**
96
+ * Reads `doc` one top-level section at a time: a section that does not parse
97
+ * is reported and replaced by its defaults, every other section is kept. This
98
+ * keeps one bad value (e.g. a renamed enum) from resetting the whole document.
99
+ */
100
+ declare function loadSections<T>(doc: unknown, sections: SectionSpecs<T>, options?: LoadSectionsOptions): LoadSectionsResult<T>;
101
+ interface LoadDocumentOptions extends MigrateOptions, LoadSectionsOptions {
102
+ }
103
+ interface LoadDocumentResult<T> extends LoadSectionsResult<T> {
104
+ report: LoadReport;
105
+ }
106
+ /**
107
+ * `migrateDocument` followed by `loadSections`, with one `LoadReport`
108
+ * (`problems` and `unknownKeys` filled in).
109
+ */
110
+ declare function loadDocument<T>(json: unknown, sections: SectionSpecs<T>, options: LoadDocumentOptions): LoadDocumentResult<T>;
111
+
112
+ export { type JsonObject as J, type LoadDocumentOptions as L, type MigrateOptions as M, type ReadOnlyReason as R, type SectionProblem as S, type LoadDocumentResult as a, type LoadReport as b, type LoadSectionsOptions as c, type LoadSectionsResult as d, type MigrateResult as e, type MigrationStep as f, type SectionSpec as g, type SectionSpecs as h, createLoadReport as i, hasLoadProblems as j, loadSections as k, loadDocument as l, migrateDocument as m };
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Design tokens (Figma-style "variables"): collections hold modes (e.g. Light / Dark) and
3
+ * typed variables with one value per mode. A value is a literal or an alias to another
4
+ * variable of the same type, possibly in another collection.
5
+ *
6
+ * The state is plain, immutable, JSON-serialisable data. Every operation returns a new state.
7
+ */
8
+ /** A variable's type. */
9
+ type TokenType = 'color' | 'number' | 'string' | 'boolean';
10
+ declare const TOKEN_TYPES: readonly TokenType[];
11
+ /** A resolved value: colours are normalised hex strings (`#rrggbb` or `#rrggbbaa`). */
12
+ type TokenLiteral = string | number | boolean;
13
+ /** A reference to another variable (by id). */
14
+ interface TokenAlias {
15
+ alias: string;
16
+ }
17
+ /** What a variable holds in one mode. */
18
+ type TokenValue = TokenLiteral | TokenAlias;
19
+ interface TokenMode {
20
+ id: string;
21
+ name: string;
22
+ }
23
+ interface TokenCollection {
24
+ id: string;
25
+ name: string;
26
+ /** At least one mode. The first one is the default mode. */
27
+ modes: readonly TokenMode[];
28
+ }
29
+ /**
30
+ * Which properties pickers offer a variable for (figcraft / Figma scope ids). Scopes only
31
+ * filter pickers: binding out of scope still works.
32
+ */
33
+ type TokenScope = 'ALL_SCOPES' | 'ALL_FILLS' | 'FRAME_FILL' | 'SHAPE_FILL' | 'TEXT_FILL' | 'STROKE_COLOR' | 'EFFECT_COLOR' | 'CORNER_RADIUS' | 'WIDTH_HEIGHT' | 'GAP' | 'OPACITY' | 'STROKE_FLOAT' | 'EFFECT_FLOAT' | 'FONT_WEIGHT' | 'FONT_SIZE' | 'LINE_HEIGHT' | 'LETTER_SPACING' | 'PARAGRAPH_SPACING' | 'PARAGRAPH_INDENT' | 'TEXT_CONTENT' | 'FONT_FAMILY' | 'FONT_STYLE';
34
+ interface TokenVariable {
35
+ id: string;
36
+ /** Unique within its collection. `/` separates groups (`color/bg`). */
37
+ name: string;
38
+ collectionId: string;
39
+ type: TokenType;
40
+ /** Value per mode id of the collection. */
41
+ valuesByMode: Readonly<Record<string, TokenValue>>;
42
+ description?: string;
43
+ /** Pickers offer the variable for these scopes; `undefined` = every supported property. */
44
+ scopes?: readonly TokenScope[];
45
+ /** Unit for number variables in CSS / W3C export (`px`, `rem`, `ms`, …). */
46
+ unit?: string;
47
+ }
48
+ interface TokenState {
49
+ collections: readonly TokenCollection[];
50
+ variables: readonly TokenVariable[];
51
+ }
52
+ /**
53
+ * Chosen mode per collection: `{ [collectionId]: modeId }`. Collections not listed (or with an
54
+ * unknown mode) use their default (first) mode.
55
+ */
56
+ type TokenModeContext = Readonly<Record<string, string>>;
57
+ type TokenErrorCode = 'not-found' | 'invalid-name' | 'duplicate-name' | 'name-conflict' | 'invalid-type' | 'invalid-value' | 'type-mismatch' | 'alias-missing' | 'alias-cycle' | 'last-mode' | 'unknown-scope' | 'invalid-input';
58
+ /** Thrown by token operations that are refused; `code` says why. */
59
+ declare class TokenError extends Error {
60
+ readonly code: TokenErrorCode;
61
+ constructor(code: TokenErrorCode, message: string);
62
+ }
63
+ declare function isTokenAlias(value: unknown): value is TokenAlias;
64
+ declare const EMPTY_TOKEN_STATE: TokenState;
65
+
66
+ declare function getTokenCollection(state: TokenState, id: string): TokenCollection | undefined;
67
+ declare function getTokenVariable(state: TokenState, id: string): TokenVariable | undefined;
68
+ /** The collection with this name. */
69
+ declare function findTokenCollection(state: TokenState, name: string): TokenCollection | undefined;
70
+ /** The variable named `name` (in `collectionId` when given, else the first match). */
71
+ declare function findTokenVariable(state: TokenState, name: string, collectionId?: string): TokenVariable | undefined;
72
+ /** The variables of a collection, in order. */
73
+ declare function getCollectionVariables(state: TokenState, collectionId: string): TokenVariable[];
74
+ /** The collection's default (first) mode. */
75
+ declare function getDefaultMode(collection: TokenCollection): TokenMode;
76
+ /** The mode with id `key`, else the one named `key`. */
77
+ declare function findTokenMode(collection: TokenCollection, key: string): TokenMode | undefined;
78
+ /** The mode `collection` is in under `modes` (its chosen mode if valid, else the default). */
79
+ declare function getCurrentMode(collection: TokenCollection, modes: TokenModeContext | undefined): TokenMode;
80
+ /** A new variable's value per type: black, 0, empty, true (figcraft's pinned defaults). */
81
+ declare function defaultTokenValue(type: TokenType): TokenLiteral;
82
+ /** The literal as `type`, or `null` when it does not fit (colours are normalised). */
83
+ declare function coerceTokenLiteral(type: TokenType, value: unknown): TokenLiteral | null;
84
+ /** The type of a literal value (strings that are colours count as strings). */
85
+ declare function literalTokenType(value: TokenLiteral): TokenType;
86
+ /** A short text for a value: hex, number, string, boolean, or `→ name` for an alias. */
87
+ declare function formatTokenValue(state: TokenState, value: TokenValue | undefined): string;
88
+ type TokenResolutionErrorCode = 'missing' | 'cycle' | 'no-value' | 'type-mismatch';
89
+ type TokenResolution = {
90
+ ok: true;
91
+ value: TokenLiteral;
92
+ type: TokenType;
93
+ /** The variable whose literal was used (the end of the alias chain). */
94
+ variable: TokenVariable;
95
+ /** Mode of `variable`'s collection that supplied the value. */
96
+ modeId: string;
97
+ /** Variable ids visited, starting with the requested one. */
98
+ chain: string[];
99
+ } | {
100
+ ok: false;
101
+ code: TokenResolutionErrorCode;
102
+ message: string;
103
+ chain: string[];
104
+ };
105
+ /**
106
+ * Resolves variable `id` under `modes` (collection id → mode id; the default mode otherwise),
107
+ * following aliases. Each variable along the chain is read in its own collection's mode.
108
+ * Cycles, missing variables and type changes along the chain are reported, never thrown.
109
+ */
110
+ declare function resolveToken(state: TokenState, id: string, modes?: TokenModeContext): TokenResolution;
111
+ /** The resolved literal, or `undefined` when it does not resolve. */
112
+ declare function resolveTokenValue(state: TokenState, id: string, modes?: TokenModeContext): TokenLiteral | undefined;
113
+ /** The value of `variableId` in mode `modeId` of its own collection (other collections in their default mode). */
114
+ declare function resolveTokenInMode(state: TokenState, variableId: string, modeId: string): TokenLiteral | undefined;
115
+ /**
116
+ * Why `variable` cannot alias `targetId`, or `null` when it can: the target must exist, have
117
+ * the same type, and not lead back to `variable` through any alias in any mode.
118
+ */
119
+ declare function checkTokenAlias(state: TokenState, variable: Pick<TokenVariable, 'id' | 'type' | 'name'>, targetId: string): TokenError | null;
120
+ declare const TOKEN_SCOPES_BY_TYPE: Readonly<Record<TokenType, readonly TokenScope[]>>;
121
+ /** Whether `scope` is a scope a variable of `type` can be limited to. */
122
+ declare function isTokenScopeKnown(type: TokenType, scope: string): scope is TokenScope;
123
+ /**
124
+ * Canonical scope list: known ids only, no repeats, `undefined` (no limit) when every
125
+ * supported property is named. Unknown ids throw `unknown-scope`.
126
+ */
127
+ declare function normalizeTokenScopes(type: TokenType, scopes: readonly string[] | null | undefined): TokenScope[] | undefined;
128
+ /** Whether pickers offer `variable` for a property of `scope` (no scope: any). */
129
+ declare function isTokenInScope(variable: Pick<TokenVariable, 'scopes'>, scope: TokenScope | undefined): boolean;
130
+ /** Trims each `/`-separated group; throws `invalid-name` when empty or not exportable. */
131
+ declare function normalizeTokenName(name: unknown, what?: string): string;
132
+ type TokenIdFactory = (kind: 'collection' | 'mode' | 'variable') => string;
133
+ /** Default id factory: `crypto.randomUUID`, with a counter fallback. */
134
+ declare const defaultTokenId: TokenIdFactory;
135
+ interface CreateTokenCollectionInput {
136
+ name: string;
137
+ /** Mode names (default `['Default']`). */
138
+ modes?: readonly string[];
139
+ }
140
+ declare function createTokenCollection(state: TokenState, input: CreateTokenCollectionInput, createId?: TokenIdFactory): {
141
+ state: TokenState;
142
+ collection: TokenCollection;
143
+ };
144
+ declare function renameTokenCollection(state: TokenState, id: string, name: string): TokenState;
145
+ /**
146
+ * Deletes variables `ids`. Variables aliasing one of them take its values (per mode: the deleted
147
+ * variable resolved in that mode when it is in the same collection, else in its default mode).
148
+ */
149
+ declare function deleteTokenVariables(state: TokenState, ids: Iterable<string>): {
150
+ state: TokenState;
151
+ deleted: string[];
152
+ };
153
+ /** Deletes a collection and its variables (aliases into it are detached to their values). */
154
+ declare function deleteTokenCollection(state: TokenState, id: string): {
155
+ state: TokenState;
156
+ deleted: string[];
157
+ };
158
+ /**
159
+ * Adds a mode. Variables start with the values of mode `from` (default: the default mode).
160
+ */
161
+ declare function addTokenMode(state: TokenState, collectionId: string, name: string, options?: {
162
+ from?: string;
163
+ }, createId?: TokenIdFactory): {
164
+ state: TokenState;
165
+ mode: TokenMode;
166
+ };
167
+ declare function renameTokenMode(state: TokenState, collectionId: string, modeId: string, name: string): TokenState;
168
+ /** Removes a mode and its values; a collection keeps at least one mode. */
169
+ declare function removeTokenMode(state: TokenState, collectionId: string, modeId: string): TokenState;
170
+ /** Moves a mode to index `to` (clamped). Index 0 makes it the default mode. */
171
+ declare function moveTokenMode(state: TokenState, collectionId: string, modeId: string, to: number): TokenState;
172
+ interface CreateTokenVariableInput {
173
+ collectionId: string;
174
+ name: string;
175
+ type: TokenType;
176
+ /** Value for every mode (literal or `{ alias }`). Default: the type's default. */
177
+ value?: unknown;
178
+ /** Values by mode id or name (win over `value`). */
179
+ values?: Readonly<Record<string, unknown>>;
180
+ description?: string;
181
+ scopes?: readonly string[];
182
+ unit?: string;
183
+ }
184
+ /** A value for `variable`: a normalised literal or a checked alias. Throws when refused. */
185
+ declare function prepareTokenValue(state: TokenState, variable: Pick<TokenVariable, 'id' | 'type' | 'name'>, value: unknown): TokenValue;
186
+ declare function createTokenVariable(state: TokenState, input: CreateTokenVariableInput, createId?: TokenIdFactory): {
187
+ state: TokenState;
188
+ variable: TokenVariable;
189
+ };
190
+ /**
191
+ * Sets a variable's value in one mode (id or name; default: the default mode) to a literal or
192
+ * `{ alias: variableId }`. Aliases must keep the type and not create a cycle.
193
+ */
194
+ declare function setTokenValue(state: TokenState, variableId: string, value: unknown, modeId?: string): TokenState;
195
+ declare function renameTokenVariable(state: TokenState, variableId: string, name: string): TokenState;
196
+ interface UpdateTokenVariableInput {
197
+ description?: string;
198
+ /** `null` clears the limit (every property). */
199
+ scopes?: readonly string[] | null;
200
+ /** `null` clears the unit. */
201
+ unit?: string | null;
202
+ }
203
+ declare function updateTokenVariable(state: TokenState, variableId: string, input: UpdateTokenVariableInput): TokenState;
204
+ interface TokenStateIssue {
205
+ message: string;
206
+ collectionId?: string;
207
+ variableId?: string;
208
+ }
209
+ /**
210
+ * Reads untrusted data (e.g. a saved `TokenState`) and keeps what is valid: junk collections,
211
+ * modes and variables are dropped, bad values replaced by the type's default and alias cycles
212
+ * broken, each with an issue.
213
+ */
214
+ declare function parseTokenState(input: unknown): {
215
+ state: TokenState;
216
+ issues: TokenStateIssue[];
217
+ };
218
+
219
+ export { resolveToken as $, deleteTokenCollection as A, deleteTokenVariables as B, type CreateTokenVariableInput as C, findTokenCollection as D, EMPTY_TOKEN_STATE as E, findTokenMode as F, findTokenVariable as G, formatTokenValue as H, getCollectionVariables as I, getCurrentMode as J, getDefaultMode as K, getTokenCollection as L, getTokenVariable as M, isTokenAlias as N, isTokenInScope as O, isTokenScopeKnown as P, literalTokenType as Q, moveTokenMode as R, normalizeTokenName as S, type TokenState as T, type UpdateTokenVariableInput as U, normalizeTokenScopes as V, prepareTokenValue as W, removeTokenMode as X, renameTokenCollection as Y, renameTokenMode as Z, renameTokenVariable as _, type TokenIdFactory as a, resolveTokenInMode as a0, resolveTokenValue as a1, setTokenValue as a2, updateTokenVariable as a3, type TokenCollection as b, type TokenVariable as c, type TokenModeContext as d, type TokenResolution as e, type TokenLiteral as f, type TokenMode as g, type CreateTokenCollectionInput as h, TOKEN_SCOPES_BY_TYPE as i, TOKEN_TYPES as j, type TokenAlias as k, TokenError as l, type TokenErrorCode as m, type TokenResolutionErrorCode as n, type TokenScope as o, parseTokenState as p, type TokenStateIssue as q, type TokenType as r, type TokenValue as s, addTokenMode as t, checkTokenAlias as u, coerceTokenLiteral as v, createTokenCollection as w, createTokenVariable as x, defaultTokenId as y, defaultTokenValue as z };
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Design tokens (Figma-style "variables"): collections hold modes (e.g. Light / Dark) and
3
+ * typed variables with one value per mode. A value is a literal or an alias to another
4
+ * variable of the same type, possibly in another collection.
5
+ *
6
+ * The state is plain, immutable, JSON-serialisable data. Every operation returns a new state.
7
+ */
8
+ /** A variable's type. */
9
+ type TokenType = 'color' | 'number' | 'string' | 'boolean';
10
+ declare const TOKEN_TYPES: readonly TokenType[];
11
+ /** A resolved value: colours are normalised hex strings (`#rrggbb` or `#rrggbbaa`). */
12
+ type TokenLiteral = string | number | boolean;
13
+ /** A reference to another variable (by id). */
14
+ interface TokenAlias {
15
+ alias: string;
16
+ }
17
+ /** What a variable holds in one mode. */
18
+ type TokenValue = TokenLiteral | TokenAlias;
19
+ interface TokenMode {
20
+ id: string;
21
+ name: string;
22
+ }
23
+ interface TokenCollection {
24
+ id: string;
25
+ name: string;
26
+ /** At least one mode. The first one is the default mode. */
27
+ modes: readonly TokenMode[];
28
+ }
29
+ /**
30
+ * Which properties pickers offer a variable for (figcraft / Figma scope ids). Scopes only
31
+ * filter pickers: binding out of scope still works.
32
+ */
33
+ type TokenScope = 'ALL_SCOPES' | 'ALL_FILLS' | 'FRAME_FILL' | 'SHAPE_FILL' | 'TEXT_FILL' | 'STROKE_COLOR' | 'EFFECT_COLOR' | 'CORNER_RADIUS' | 'WIDTH_HEIGHT' | 'GAP' | 'OPACITY' | 'STROKE_FLOAT' | 'EFFECT_FLOAT' | 'FONT_WEIGHT' | 'FONT_SIZE' | 'LINE_HEIGHT' | 'LETTER_SPACING' | 'PARAGRAPH_SPACING' | 'PARAGRAPH_INDENT' | 'TEXT_CONTENT' | 'FONT_FAMILY' | 'FONT_STYLE';
34
+ interface TokenVariable {
35
+ id: string;
36
+ /** Unique within its collection. `/` separates groups (`color/bg`). */
37
+ name: string;
38
+ collectionId: string;
39
+ type: TokenType;
40
+ /** Value per mode id of the collection. */
41
+ valuesByMode: Readonly<Record<string, TokenValue>>;
42
+ description?: string;
43
+ /** Pickers offer the variable for these scopes; `undefined` = every supported property. */
44
+ scopes?: readonly TokenScope[];
45
+ /** Unit for number variables in CSS / W3C export (`px`, `rem`, `ms`, …). */
46
+ unit?: string;
47
+ }
48
+ interface TokenState {
49
+ collections: readonly TokenCollection[];
50
+ variables: readonly TokenVariable[];
51
+ }
52
+ /**
53
+ * Chosen mode per collection: `{ [collectionId]: modeId }`. Collections not listed (or with an
54
+ * unknown mode) use their default (first) mode.
55
+ */
56
+ type TokenModeContext = Readonly<Record<string, string>>;
57
+ type TokenErrorCode = 'not-found' | 'invalid-name' | 'duplicate-name' | 'name-conflict' | 'invalid-type' | 'invalid-value' | 'type-mismatch' | 'alias-missing' | 'alias-cycle' | 'last-mode' | 'unknown-scope' | 'invalid-input';
58
+ /** Thrown by token operations that are refused; `code` says why. */
59
+ declare class TokenError extends Error {
60
+ readonly code: TokenErrorCode;
61
+ constructor(code: TokenErrorCode, message: string);
62
+ }
63
+ declare function isTokenAlias(value: unknown): value is TokenAlias;
64
+ declare const EMPTY_TOKEN_STATE: TokenState;
65
+
66
+ declare function getTokenCollection(state: TokenState, id: string): TokenCollection | undefined;
67
+ declare function getTokenVariable(state: TokenState, id: string): TokenVariable | undefined;
68
+ /** The collection with this name. */
69
+ declare function findTokenCollection(state: TokenState, name: string): TokenCollection | undefined;
70
+ /** The variable named `name` (in `collectionId` when given, else the first match). */
71
+ declare function findTokenVariable(state: TokenState, name: string, collectionId?: string): TokenVariable | undefined;
72
+ /** The variables of a collection, in order. */
73
+ declare function getCollectionVariables(state: TokenState, collectionId: string): TokenVariable[];
74
+ /** The collection's default (first) mode. */
75
+ declare function getDefaultMode(collection: TokenCollection): TokenMode;
76
+ /** The mode with id `key`, else the one named `key`. */
77
+ declare function findTokenMode(collection: TokenCollection, key: string): TokenMode | undefined;
78
+ /** The mode `collection` is in under `modes` (its chosen mode if valid, else the default). */
79
+ declare function getCurrentMode(collection: TokenCollection, modes: TokenModeContext | undefined): TokenMode;
80
+ /** A new variable's value per type: black, 0, empty, true (figcraft's pinned defaults). */
81
+ declare function defaultTokenValue(type: TokenType): TokenLiteral;
82
+ /** The literal as `type`, or `null` when it does not fit (colours are normalised). */
83
+ declare function coerceTokenLiteral(type: TokenType, value: unknown): TokenLiteral | null;
84
+ /** The type of a literal value (strings that are colours count as strings). */
85
+ declare function literalTokenType(value: TokenLiteral): TokenType;
86
+ /** A short text for a value: hex, number, string, boolean, or `→ name` for an alias. */
87
+ declare function formatTokenValue(state: TokenState, value: TokenValue | undefined): string;
88
+ type TokenResolutionErrorCode = 'missing' | 'cycle' | 'no-value' | 'type-mismatch';
89
+ type TokenResolution = {
90
+ ok: true;
91
+ value: TokenLiteral;
92
+ type: TokenType;
93
+ /** The variable whose literal was used (the end of the alias chain). */
94
+ variable: TokenVariable;
95
+ /** Mode of `variable`'s collection that supplied the value. */
96
+ modeId: string;
97
+ /** Variable ids visited, starting with the requested one. */
98
+ chain: string[];
99
+ } | {
100
+ ok: false;
101
+ code: TokenResolutionErrorCode;
102
+ message: string;
103
+ chain: string[];
104
+ };
105
+ /**
106
+ * Resolves variable `id` under `modes` (collection id → mode id; the default mode otherwise),
107
+ * following aliases. Each variable along the chain is read in its own collection's mode.
108
+ * Cycles, missing variables and type changes along the chain are reported, never thrown.
109
+ */
110
+ declare function resolveToken(state: TokenState, id: string, modes?: TokenModeContext): TokenResolution;
111
+ /** The resolved literal, or `undefined` when it does not resolve. */
112
+ declare function resolveTokenValue(state: TokenState, id: string, modes?: TokenModeContext): TokenLiteral | undefined;
113
+ /** The value of `variableId` in mode `modeId` of its own collection (other collections in their default mode). */
114
+ declare function resolveTokenInMode(state: TokenState, variableId: string, modeId: string): TokenLiteral | undefined;
115
+ /**
116
+ * Why `variable` cannot alias `targetId`, or `null` when it can: the target must exist, have
117
+ * the same type, and not lead back to `variable` through any alias in any mode.
118
+ */
119
+ declare function checkTokenAlias(state: TokenState, variable: Pick<TokenVariable, 'id' | 'type' | 'name'>, targetId: string): TokenError | null;
120
+ declare const TOKEN_SCOPES_BY_TYPE: Readonly<Record<TokenType, readonly TokenScope[]>>;
121
+ /** Whether `scope` is a scope a variable of `type` can be limited to. */
122
+ declare function isTokenScopeKnown(type: TokenType, scope: string): scope is TokenScope;
123
+ /**
124
+ * Canonical scope list: known ids only, no repeats, `undefined` (no limit) when every
125
+ * supported property is named. Unknown ids throw `unknown-scope`.
126
+ */
127
+ declare function normalizeTokenScopes(type: TokenType, scopes: readonly string[] | null | undefined): TokenScope[] | undefined;
128
+ /** Whether pickers offer `variable` for a property of `scope` (no scope: any). */
129
+ declare function isTokenInScope(variable: Pick<TokenVariable, 'scopes'>, scope: TokenScope | undefined): boolean;
130
+ /** Trims each `/`-separated group; throws `invalid-name` when empty or not exportable. */
131
+ declare function normalizeTokenName(name: unknown, what?: string): string;
132
+ type TokenIdFactory = (kind: 'collection' | 'mode' | 'variable') => string;
133
+ /** Default id factory: `crypto.randomUUID`, with a counter fallback. */
134
+ declare const defaultTokenId: TokenIdFactory;
135
+ interface CreateTokenCollectionInput {
136
+ name: string;
137
+ /** Mode names (default `['Default']`). */
138
+ modes?: readonly string[];
139
+ }
140
+ declare function createTokenCollection(state: TokenState, input: CreateTokenCollectionInput, createId?: TokenIdFactory): {
141
+ state: TokenState;
142
+ collection: TokenCollection;
143
+ };
144
+ declare function renameTokenCollection(state: TokenState, id: string, name: string): TokenState;
145
+ /**
146
+ * Deletes variables `ids`. Variables aliasing one of them take its values (per mode: the deleted
147
+ * variable resolved in that mode when it is in the same collection, else in its default mode).
148
+ */
149
+ declare function deleteTokenVariables(state: TokenState, ids: Iterable<string>): {
150
+ state: TokenState;
151
+ deleted: string[];
152
+ };
153
+ /** Deletes a collection and its variables (aliases into it are detached to their values). */
154
+ declare function deleteTokenCollection(state: TokenState, id: string): {
155
+ state: TokenState;
156
+ deleted: string[];
157
+ };
158
+ /**
159
+ * Adds a mode. Variables start with the values of mode `from` (default: the default mode).
160
+ */
161
+ declare function addTokenMode(state: TokenState, collectionId: string, name: string, options?: {
162
+ from?: string;
163
+ }, createId?: TokenIdFactory): {
164
+ state: TokenState;
165
+ mode: TokenMode;
166
+ };
167
+ declare function renameTokenMode(state: TokenState, collectionId: string, modeId: string, name: string): TokenState;
168
+ /** Removes a mode and its values; a collection keeps at least one mode. */
169
+ declare function removeTokenMode(state: TokenState, collectionId: string, modeId: string): TokenState;
170
+ /** Moves a mode to index `to` (clamped). Index 0 makes it the default mode. */
171
+ declare function moveTokenMode(state: TokenState, collectionId: string, modeId: string, to: number): TokenState;
172
+ interface CreateTokenVariableInput {
173
+ collectionId: string;
174
+ name: string;
175
+ type: TokenType;
176
+ /** Value for every mode (literal or `{ alias }`). Default: the type's default. */
177
+ value?: unknown;
178
+ /** Values by mode id or name (win over `value`). */
179
+ values?: Readonly<Record<string, unknown>>;
180
+ description?: string;
181
+ scopes?: readonly string[];
182
+ unit?: string;
183
+ }
184
+ /** A value for `variable`: a normalised literal or a checked alias. Throws when refused. */
185
+ declare function prepareTokenValue(state: TokenState, variable: Pick<TokenVariable, 'id' | 'type' | 'name'>, value: unknown): TokenValue;
186
+ declare function createTokenVariable(state: TokenState, input: CreateTokenVariableInput, createId?: TokenIdFactory): {
187
+ state: TokenState;
188
+ variable: TokenVariable;
189
+ };
190
+ /**
191
+ * Sets a variable's value in one mode (id or name; default: the default mode) to a literal or
192
+ * `{ alias: variableId }`. Aliases must keep the type and not create a cycle.
193
+ */
194
+ declare function setTokenValue(state: TokenState, variableId: string, value: unknown, modeId?: string): TokenState;
195
+ declare function renameTokenVariable(state: TokenState, variableId: string, name: string): TokenState;
196
+ interface UpdateTokenVariableInput {
197
+ description?: string;
198
+ /** `null` clears the limit (every property). */
199
+ scopes?: readonly string[] | null;
200
+ /** `null` clears the unit. */
201
+ unit?: string | null;
202
+ }
203
+ declare function updateTokenVariable(state: TokenState, variableId: string, input: UpdateTokenVariableInput): TokenState;
204
+ interface TokenStateIssue {
205
+ message: string;
206
+ collectionId?: string;
207
+ variableId?: string;
208
+ }
209
+ /**
210
+ * Reads untrusted data (e.g. a saved `TokenState`) and keeps what is valid: junk collections,
211
+ * modes and variables are dropped, bad values replaced by the type's default and alias cycles
212
+ * broken, each with an issue.
213
+ */
214
+ declare function parseTokenState(input: unknown): {
215
+ state: TokenState;
216
+ issues: TokenStateIssue[];
217
+ };
218
+
219
+ export { resolveToken as $, deleteTokenCollection as A, deleteTokenVariables as B, type CreateTokenVariableInput as C, findTokenCollection as D, EMPTY_TOKEN_STATE as E, findTokenMode as F, findTokenVariable as G, formatTokenValue as H, getCollectionVariables as I, getCurrentMode as J, getDefaultMode as K, getTokenCollection as L, getTokenVariable as M, isTokenAlias as N, isTokenInScope as O, isTokenScopeKnown as P, literalTokenType as Q, moveTokenMode as R, normalizeTokenName as S, type TokenState as T, type UpdateTokenVariableInput as U, normalizeTokenScopes as V, prepareTokenValue as W, removeTokenMode as X, renameTokenCollection as Y, renameTokenMode as Z, renameTokenVariable as _, type TokenIdFactory as a, resolveTokenInMode as a0, resolveTokenValue as a1, setTokenValue as a2, updateTokenVariable as a3, type TokenCollection as b, type TokenVariable as c, type TokenModeContext as d, type TokenResolution as e, type TokenLiteral as f, type TokenMode as g, type CreateTokenCollectionInput as h, TOKEN_SCOPES_BY_TYPE as i, TOKEN_TYPES as j, type TokenAlias as k, TokenError as l, type TokenErrorCode as m, type TokenResolutionErrorCode as n, type TokenScope as o, parseTokenState as p, type TokenStateIssue as q, type TokenType as r, type TokenValue as s, addTokenMode as t, checkTokenAlias as u, coerceTokenLiteral as v, createTokenCollection as w, createTokenVariable as x, defaultTokenId as y, defaultTokenValue as z };