@pixerate/editor 0.24.0 → 0.26.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 (162) hide show
  1. package/README.md +101 -1
  2. package/THIRD_PARTY_NOTICES.md +40 -0
  3. package/dist/agent/index.cjs +175 -11
  4. package/dist/agent/index.cjs.map +1 -1
  5. package/dist/agent/index.d.cts +18 -4
  6. package/dist/agent/index.d.ts +18 -4
  7. package/dist/agent/index.js +168 -4
  8. package/dist/agent/index.js.map +1 -1
  9. package/dist/{arrangeShortcuts-B8O3f8-P.d.cts → arrange-BICutYPk.d.cts} +243 -29
  10. package/dist/{arrangeShortcuts-sLlD2rSX.d.ts → arrange-BICutYPk.d.ts} +243 -29
  11. package/dist/builtins-CdPcLwwF.d.cts +176 -0
  12. package/dist/builtins-Chj6zv_O.d.ts +176 -0
  13. package/dist/canvas/index.cjs +8588 -1857
  14. package/dist/canvas/index.cjs.map +1 -1
  15. package/dist/canvas/index.d.cts +1847 -9
  16. package/dist/canvas/index.d.ts +1847 -9
  17. package/dist/canvas/index.js +8577 -1846
  18. package/dist/canvas/index.js.map +1 -1
  19. package/dist/chunk-3CC7OPUQ.cjs +831 -0
  20. package/dist/chunk-3CC7OPUQ.cjs.map +1 -0
  21. package/dist/chunk-4BVP64JJ.cjs +1406 -0
  22. package/dist/chunk-4BVP64JJ.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-OLZJXL4R.cjs → chunk-CS6NZWWA.cjs} +59 -25
  26. package/dist/chunk-CS6NZWWA.cjs.map +1 -0
  27. package/dist/{chunk-MCSJFWAO.cjs → chunk-EWCOFSCQ.cjs} +685 -100
  28. package/dist/chunk-EWCOFSCQ.cjs.map +1 -0
  29. package/dist/chunk-HDYMLS3X.cjs +409 -0
  30. package/dist/chunk-HDYMLS3X.cjs.map +1 -0
  31. package/dist/chunk-HRMEDT2L.js +1406 -0
  32. package/dist/chunk-HRMEDT2L.js.map +1 -0
  33. package/dist/{chunk-D27YFC46.cjs → chunk-IFHKKVXH.cjs} +382 -63
  34. package/dist/chunk-IFHKKVXH.cjs.map +1 -0
  35. package/dist/{chunk-PGNZKFQS.js → chunk-JOIREKL7.js} +137 -58
  36. package/dist/chunk-JOIREKL7.js.map +1 -0
  37. package/dist/chunk-KRGXUQ2Y.js +1696 -0
  38. package/dist/chunk-KRGXUQ2Y.js.map +1 -0
  39. package/dist/{chunk-3LV6RRPH.js → chunk-MHEPLBFB.js} +2 -2
  40. package/dist/chunk-MR2764X2.js +831 -0
  41. package/dist/chunk-MR2764X2.js.map +1 -0
  42. package/dist/{chunk-XNORY7M6.cjs → chunk-NFVBT3UZ.cjs} +166 -87
  43. package/dist/chunk-NFVBT3UZ.cjs.map +1 -0
  44. package/dist/chunk-NQF32I6Z.cjs +6478 -0
  45. package/dist/chunk-NQF32I6Z.cjs.map +1 -0
  46. package/dist/chunk-O5RYH2PG.js +69 -0
  47. package/dist/chunk-O5RYH2PG.js.map +1 -0
  48. package/dist/{chunk-ITBSKI26.js → chunk-Q2OHWD2A.js} +1064 -360
  49. package/dist/chunk-Q2OHWD2A.js.map +1 -0
  50. package/dist/{chunk-FODNLX5N.js → chunk-QJSOZFCZ.js} +38 -4
  51. package/dist/chunk-QJSOZFCZ.js.map +1 -0
  52. package/dist/{chunk-SML64VJG.cjs → chunk-RRREAOVM.cjs} +4 -4
  53. package/dist/{chunk-SML64VJG.cjs.map → chunk-RRREAOVM.cjs.map} +1 -1
  54. package/dist/{chunk-5S3Z4PPF.js → chunk-SWE3NPOU.js} +347 -28
  55. package/dist/chunk-SWE3NPOU.js.map +1 -0
  56. package/dist/chunk-TXXNBDQX.cjs +1696 -0
  57. package/dist/chunk-TXXNBDQX.cjs.map +1 -0
  58. package/dist/chunk-UBCFIABU.js +409 -0
  59. package/dist/chunk-UBCFIABU.js.map +1 -0
  60. package/dist/chunk-X7HXL2SB.js +6478 -0
  61. package/dist/chunk-X7HXL2SB.js.map +1 -0
  62. package/dist/{chunk-SBCZ6RN5.cjs → chunk-YOMYSFJU.cjs} +1163 -459
  63. package/dist/chunk-YOMYSFJU.cjs.map +1 -0
  64. package/dist/{chunk-3CN2WD3X.js → chunk-ZRNHGAQT.js} +661 -76
  65. package/dist/chunk-ZRNHGAQT.js.map +1 -0
  66. package/dist/commands/index.cjs +425 -4
  67. package/dist/commands/index.cjs.map +1 -1
  68. package/dist/commands/index.d.cts +39 -77
  69. package/dist/commands/index.d.ts +39 -77
  70. package/dist/commands/index.js +424 -3
  71. package/dist/commands/index.js.map +1 -1
  72. package/dist/compare/index.cjs +3 -3
  73. package/dist/compare/index.d.cts +1 -1
  74. package/dist/compare/index.d.ts +1 -1
  75. package/dist/compare/index.js +2 -2
  76. package/dist/controller-CxXGOEmy.d.cts +2038 -0
  77. package/dist/controller-CxXGOEmy.d.ts +2038 -0
  78. package/dist/{documents-BQjzJNe2.d.ts → documents-CHT1U5Vs.d.ts} +10 -0
  79. package/dist/{documents-KRTPhvst.d.cts → documents-Gp7wb0Me.d.cts} +10 -0
  80. package/dist/export/index.cjs +36 -0
  81. package/dist/export/index.cjs.map +1 -0
  82. package/dist/export/index.d.cts +243 -0
  83. package/dist/export/index.d.ts +243 -0
  84. package/dist/export/index.js +36 -0
  85. package/dist/export/index.js.map +1 -0
  86. package/dist/extensions/index.cjs +101 -6
  87. package/dist/extensions/index.cjs.map +1 -1
  88. package/dist/extensions/index.d.cts +18 -5
  89. package/dist/extensions/index.d.ts +18 -5
  90. package/dist/extensions/index.js +101 -6
  91. package/dist/generation/index.cjs +1013 -69
  92. package/dist/generation/index.cjs.map +1 -1
  93. package/dist/generation/index.d.cts +474 -13
  94. package/dist/generation/index.d.ts +474 -13
  95. package/dist/generation/index.js +976 -32
  96. package/dist/generation/index.js.map +1 -1
  97. package/dist/image-editor/index.cjs +3385 -1275
  98. package/dist/image-editor/index.cjs.map +1 -1
  99. package/dist/image-editor/index.d.cts +693 -128
  100. package/dist/image-editor/index.d.ts +693 -128
  101. package/dist/image-editor/index.js +3325 -1215
  102. package/dist/image-editor/index.js.map +1 -1
  103. package/dist/{index-fJrlkJCd.d.ts → index-B273Zllk.d.ts} +500 -7
  104. package/dist/{index-BhJBSm2d.d.cts → index-jcJwmBYt.d.cts} +500 -7
  105. package/dist/index.cjs +1603 -45
  106. package/dist/index.cjs.map +1 -1
  107. package/dist/index.d.cts +154 -27
  108. package/dist/index.d.ts +154 -27
  109. package/dist/index.js +1584 -26
  110. package/dist/index.js.map +1 -1
  111. package/dist/mention-text-CDnCFd3c.d.cts +53 -0
  112. package/dist/mention-text-CDnCFd3c.d.ts +53 -0
  113. package/dist/model-C1zApQM8.d.cts +219 -0
  114. package/dist/model-C1zApQM8.d.ts +219 -0
  115. package/dist/persistence/index.d.cts +3 -120
  116. package/dist/persistence/index.d.ts +3 -120
  117. package/dist/registry-CED5C0lA.d.cts +204 -0
  118. package/dist/registry-CED5C0lA.d.ts +204 -0
  119. package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.cts} +12 -1
  120. package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.ts} +12 -1
  121. package/dist/{registry-D32LpIc4.d.cts → registry-D0GADKc7.d.cts} +1 -1
  122. package/dist/{registry-evKTP4ls.d.ts → registry-DhVUZioj.d.ts} +1 -1
  123. package/dist/serializers/index.cjs +12 -4
  124. package/dist/serializers/index.cjs.map +1 -1
  125. package/dist/serializers/index.d.cts +41 -13
  126. package/dist/serializers/index.d.ts +41 -13
  127. package/dist/serializers/index.js +12 -4
  128. package/dist/spreadsheet/index.cjs +157 -3
  129. package/dist/spreadsheet/index.cjs.map +1 -1
  130. package/dist/spreadsheet/index.d.cts +534 -11
  131. package/dist/spreadsheet/index.d.ts +534 -11
  132. package/dist/spreadsheet/index.js +157 -3
  133. package/dist/storage-BpFfspHm.d.cts +120 -0
  134. package/dist/storage-BpFfspHm.d.ts +120 -0
  135. package/dist/tokens/index.cjs +115 -0
  136. package/dist/tokens/index.cjs.map +1 -0
  137. package/dist/tokens/index.d.cts +212 -0
  138. package/dist/tokens/index.d.ts +212 -0
  139. package/dist/tokens/index.js +115 -0
  140. package/dist/tokens/index.js.map +1 -0
  141. package/dist/{track-changes-BK5sVf4_.d.cts → track-changes-D_VAPELi.d.cts} +95 -11
  142. package/dist/{track-changes-CDjCrwKe.d.ts → track-changes-Db_fGEvx.d.ts} +95 -11
  143. package/package.json +15 -1
  144. package/dist/chunk-3CN2WD3X.js.map +0 -1
  145. package/dist/chunk-5S3Z4PPF.js.map +0 -1
  146. package/dist/chunk-D27YFC46.cjs.map +0 -1
  147. package/dist/chunk-FODNLX5N.js.map +0 -1
  148. package/dist/chunk-ITBSKI26.js.map +0 -1
  149. package/dist/chunk-MA2F5KHF.cjs +0 -3223
  150. package/dist/chunk-MA2F5KHF.cjs.map +0 -1
  151. package/dist/chunk-MCSJFWAO.cjs.map +0 -1
  152. package/dist/chunk-OLZJXL4R.cjs.map +0 -1
  153. package/dist/chunk-PGNZKFQS.js.map +0 -1
  154. package/dist/chunk-SBCZ6RN5.cjs.map +0 -1
  155. package/dist/chunk-U5KWZU4X.js +0 -3223
  156. package/dist/chunk-U5KWZU4X.js.map +0 -1
  157. package/dist/chunk-XNORY7M6.cjs.map +0 -1
  158. package/dist/controller-BhLLAoi8.d.cts +0 -1000
  159. package/dist/controller-BhLLAoi8.d.ts +0 -1000
  160. package/dist/types-DX4Mh4SL.d.cts +0 -217
  161. package/dist/types-DX4Mh4SL.d.ts +0 -217
  162. /package/dist/{chunk-3LV6RRPH.js.map → chunk-MHEPLBFB.js.map} +0 -0
@@ -0,0 +1,212 @@
1
+ import { T as TokenState, a as TokenIdFactory, b as TokenCollection, c as TokenVariable, d as TokenModeContext, e as TokenResolution, f as TokenLiteral, p as parseTokenState, g as TokenMode, C as CreateTokenVariableInput, U as UpdateTokenVariableInput } from '../model-C1zApQM8.cjs';
2
+ export { h as CreateTokenCollectionInput, E as EMPTY_TOKEN_STATE, i as TOKEN_SCOPES_BY_TYPE, j as TOKEN_TYPES, k as TokenAlias, l as TokenError, m as TokenErrorCode, n as TokenResolutionErrorCode, o as TokenScope, q as TokenStateIssue, r as TokenType, s as TokenValue, t as addTokenMode, u as checkTokenAlias, v as coerceTokenLiteral, w as createTokenCollection, x as createTokenVariable, y as defaultTokenId, z as defaultTokenValue, A as deleteTokenCollection, B as deleteTokenVariables, D as findTokenCollection, F as findTokenMode, G as findTokenVariable, H as formatTokenValue, I as getCollectionVariables, J as getCurrentMode, K as getDefaultMode, L as getTokenCollection, M as getTokenVariable, N as isTokenAlias, O as isTokenInScope, P as isTokenScopeKnown, Q as literalTokenType, R as moveTokenMode, S as normalizeTokenName, V as normalizeTokenScopes, W as prepareTokenValue, X as removeTokenMode, Y as renameTokenCollection, Z as renameTokenMode, _ as renameTokenVariable, $ as resolveToken, a0 as resolveTokenInMode, a1 as resolveTokenValue, a2 as setTokenValue, a3 as updateTokenVariable } from '../model-C1zApQM8.cjs';
3
+
4
+ /**
5
+ * Colour parsing for colour tokens. Colours are stored as lowercase hex: `#rrggbb`, or
6
+ * `#rrggbbaa` when not opaque. Accepted input: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,
7
+ * `rgb()` / `rgba()` (numbers or percentages, comma or space separated, `/ alpha`),
8
+ * `transparent`, `black`, `white`, `{ r, g, b, a? }` with channels in 0–1 (Figma JSON) and
9
+ * W3C colour objects (`{ colorSpace: 'srgb', components: [r, g, b], alpha?, hex? }`).
10
+ */
11
+ /** `#rrggbb` / `#rrggbbaa` from 0–1 channels. */
12
+ declare function rgbaToHex(r: number, g: number, b: number, a?: number): string;
13
+ /** 0–1 channels of a normalised hex colour. */
14
+ declare function hexToRgba(hex: string): {
15
+ r: number;
16
+ g: number;
17
+ b: number;
18
+ a: number;
19
+ } | null;
20
+ /** The colour as normalised hex, or `null` when it is not a colour this module reads. */
21
+ declare function normalizeTokenColor(input: unknown): string | null;
22
+
23
+ /** Why the state changed. */
24
+ type TokenChangeSource = 'edit' | 'undo' | 'redo' | 'replace';
25
+ interface TokenChangeEvent {
26
+ source: TokenChangeSource;
27
+ /** Operation name (`setValue`, `deleteVariables`, a `transact` label, …). */
28
+ reason: string;
29
+ state: TokenState;
30
+ previous: TokenState;
31
+ /**
32
+ * Variables this edit deleted (also via `deleteCollection`). Detach canvas bindings to them
33
+ * with `detachTokenBindings(nodes, event.previous, event.deletedVariableIds)`.
34
+ */
35
+ deletedVariableIds: readonly string[];
36
+ }
37
+ type TokenChangeListener = (event: TokenChangeEvent) => void;
38
+ interface TokenStoreOptions {
39
+ initialState?: TokenState;
40
+ createId?: TokenIdFactory;
41
+ /** Undo steps kept (default 100). */
42
+ historyLimit?: number;
43
+ }
44
+ /**
45
+ * Undoable design-token store. Every edit is one undo step (group several with `transact`)
46
+ * and notifies subscribers once. `getState()` returns an immutable snapshot whose reference
47
+ * only changes on edits, so it works with `useSyncExternalStore` and Svelte stores.
48
+ * Refused edits throw a `TokenError` and change nothing.
49
+ */
50
+ declare class TokenStore {
51
+ private state;
52
+ private undoStack;
53
+ private redoStack;
54
+ private listeners;
55
+ private pending;
56
+ private depth;
57
+ private readonly createId;
58
+ private readonly historyLimit;
59
+ constructor(options?: TokenStoreOptions);
60
+ getState: () => TokenState;
61
+ subscribe: (listener: TokenChangeListener) => (() => void);
62
+ get collections(): readonly TokenCollection[];
63
+ get variables(): readonly TokenVariable[];
64
+ canUndo(): boolean;
65
+ canRedo(): boolean;
66
+ /** Resolves a variable under `modes` (see `resolveToken`). */
67
+ resolve(id: string, modes?: TokenModeContext): TokenResolution;
68
+ resolveValue(id: string, modes?: TokenModeContext): TokenLiteral | undefined;
69
+ /**
70
+ * Runs `fn` as one undo step with one change event. If `fn` throws, every change it made is
71
+ * rolled back and the error rethrown.
72
+ */
73
+ transact<T>(reason: string, fn: (store: this) => T): T;
74
+ private apply;
75
+ private flush;
76
+ private emit;
77
+ undo(): boolean;
78
+ redo(): boolean;
79
+ /**
80
+ * Replaces the whole state (e.g. after loading a file). Untrusted data should go through
81
+ * `parseTokenState` first. With `record: true` it is an undo step; otherwise history is cleared.
82
+ */
83
+ replaceState(state: TokenState, options?: {
84
+ record?: boolean;
85
+ reason?: string;
86
+ }): void;
87
+ /** Loads untrusted JSON (or an object) as the new state; returns the issues found. */
88
+ load(input: unknown): ReturnType<typeof parseTokenState>['issues'];
89
+ /** The state as JSON. */
90
+ toJSON(): TokenState;
91
+ createCollection(name: string, modes?: readonly string[]): TokenCollection;
92
+ renameCollection(id: string, name: string): void;
93
+ deleteCollection(id: string): string[];
94
+ addMode(collectionId: string, name: string, options?: {
95
+ from?: string;
96
+ }): TokenMode;
97
+ renameMode(collectionId: string, modeId: string, name: string): void;
98
+ removeMode(collectionId: string, modeId: string): void;
99
+ moveMode(collectionId: string, modeId: string, to: number): void;
100
+ /** Makes a mode the default by moving it first. */
101
+ setDefaultMode(collectionId: string, modeId: string): void;
102
+ createVariable(input: CreateTokenVariableInput): TokenVariable;
103
+ /** Sets a literal or `{ alias }` in one mode (id or name; default: the default mode). */
104
+ setValue(variableId: string, value: unknown, modeId?: string): void;
105
+ renameVariable(variableId: string, name: string): void;
106
+ updateVariable(variableId: string, input: UpdateTokenVariableInput): void;
107
+ /** Deletes variables; aliases to them take their values. Returns the ids deleted. */
108
+ deleteVariables(ids: string | Iterable<string>): string[];
109
+ /** Applies a pure state transform (e.g. `importW3CTokens`) as one undo step. */
110
+ update(reason: string, fn: (state: TokenState) => TokenState): void;
111
+ }
112
+ declare function createTokenStore(options?: TokenStoreOptions): TokenStore;
113
+
114
+ interface TokenCssOptions {
115
+ /** Collections to export (ids; default all). */
116
+ collections?: readonly string[];
117
+ /** Prefix after `--` (e.g. `ds-` → `--ds-color-bg`). */
118
+ prefix?: string;
119
+ /** Also prefix each variable with its collection name (avoids clashes between collections). */
120
+ collectionPrefix?: boolean;
121
+ /** Root selector (default `:root`). */
122
+ selector?: string;
123
+ /** Attribute that selects a mode (default `data-mode`), or one per collection. */
124
+ attribute?: string | ((collection: TokenCollection) => string);
125
+ /** Attribute value for a mode (default: the mode name as a lowercase slug, e.g. `dark`). */
126
+ modeValue?: (mode: TokenMode, collection: TokenCollection) => string;
127
+ /**
128
+ * Also emit `[data-mode="…"]` rules that match any element (not just the root), so a subtree
129
+ * can switch mode. Default `false`.
130
+ */
131
+ nested?: boolean;
132
+ /** Formats numbers (default: the number with the variable's `unit`, if any). */
133
+ formatNumber?: (value: number, variable: TokenVariable) => string;
134
+ }
135
+ /** Lowercase slug of a name: groups and spaces become `-` (`Color/Bg Muted` → `color-bg-muted`). */
136
+ declare function tokenSlug(name: string): string;
137
+ /** The CSS custom property for a variable (e.g. `--color-bg`). */
138
+ declare function getTokenCssName(state: TokenState, variable: TokenVariable, options?: Pick<TokenCssOptions, 'prefix' | 'collectionPrefix'>): string;
139
+ /** A CSS string literal with `"`, `\`, newlines and `<` escaped. */
140
+ declare function cssString(value: string): string;
141
+ /** A literal as CSS. */
142
+ declare function formatTokenCssValue(value: TokenLiteral, variable: TokenVariable, options?: Pick<TokenCssOptions, 'formatNumber'>): string;
143
+ /**
144
+ * Flat CSS custom properties per mode: each collection's default mode on `:root`, its other
145
+ * modes on `:root[data-mode="dark"]`. Aliases to exported variables become `var(--target)`, so
146
+ * switching the attribute re-themes everything; aliases to other variables are resolved.
147
+ */
148
+ declare function exportTokensCss(state: TokenState, options?: TokenCssOptions): string;
149
+ /**
150
+ * Resolved CSS custom properties for one mode context, e.g. for an element's inline style:
151
+ * `{ '--color-bg': '#ffffff', … }`. Aliases are resolved (no `var()`).
152
+ */
153
+ declare function getTokenCssVariables(state: TokenState, modes?: TokenModeContext, options?: Omit<TokenCssOptions, 'selector' | 'attribute' | 'modeValue' | 'nested'>): Record<string, string>;
154
+
155
+ /**
156
+ * W3C Design Tokens (DTCG) JSON. Each collection is a top-level group named after it; variable
157
+ * names' `/` groups become nested groups; aliases are `{Collection.group.token}` references.
158
+ * `$value` holds the default mode (or the modes passed in). Modes, ids and scopes ride along in
159
+ * `$extensions["com.pixerate.tokens"]`, so an export round-trips; tools that ignore extensions
160
+ * still read the default mode. Strings and booleans use `$type: "string"` / `"boolean"`
161
+ * (outside the spec, as Tokens Studio and Style Dictionary do).
162
+ */
163
+ declare const W3C_TOKENS_EXTENSION = "com.pixerate.tokens";
164
+ interface W3CTokensExportOptions {
165
+ /** Collections to export (ids; default all). */
166
+ collections?: readonly string[];
167
+ /** Modes that supply `$value` (default: each collection's default mode). */
168
+ modes?: TokenModeContext;
169
+ /** Include `$extensions` with ids, every mode's value and scopes (default `true`). */
170
+ extensions?: boolean;
171
+ /** Colours as `#hex` strings (default) or W3C colour objects. */
172
+ colorFormat?: 'hex' | 'object';
173
+ }
174
+ type Json = null | boolean | number | string | Json[] | {
175
+ [key: string]: Json;
176
+ };
177
+ /** The tokens as a W3C Design Tokens object (see {@link W3C_TOKENS_EXTENSION}). */
178
+ declare function exportW3CTokens(state: TokenState, options?: W3CTokensExportOptions): Record<string, Json>;
179
+ /** {@link exportW3CTokens} as indented JSON text. */
180
+ declare function exportW3CTokensJson(state: TokenState, options?: W3CTokensExportOptions): string;
181
+ interface W3CTokensImportOptions {
182
+ /**
183
+ * Collection for tokens outside a marked collection group (a plain W3C file). Default
184
+ * `"Tokens"`; an existing collection with that name is updated.
185
+ */
186
+ collection?: string;
187
+ /** Mode that plain `$value`s go to (name; created when missing). Default: the default mode. */
188
+ mode?: string;
189
+ createId?: TokenIdFactory;
190
+ }
191
+ interface W3CTokensImportReport {
192
+ collectionsAdded: number;
193
+ modesAdded: number;
194
+ variablesAdded: number;
195
+ /** Existing variables (matched by collection and name) that were updated in place. */
196
+ variablesUpdated: number;
197
+ /** Entries skipped or values not taken, with the reason. */
198
+ warnings: string[];
199
+ }
200
+ /**
201
+ * Merges a W3C Design Tokens document (object or JSON text) into `state`. Collections, modes
202
+ * and variables are matched by name and updated in place (ids, and so canvas bindings, are
203
+ * kept); new ones take the ids in the file's extensions when free. Junk entries, type clashes,
204
+ * unresolved references and alias cycles are skipped with a warning. Throws `invalid-input`
205
+ * only when the input is not a JSON object.
206
+ */
207
+ declare function importW3CTokens(state: TokenState, input: unknown, options?: W3CTokensImportOptions): {
208
+ state: TokenState;
209
+ report: W3CTokensImportReport;
210
+ };
211
+
212
+ export { CreateTokenVariableInput, type TokenChangeEvent, type TokenChangeListener, type TokenChangeSource, TokenCollection, type TokenCssOptions, TokenIdFactory, TokenLiteral, TokenMode, TokenModeContext, TokenResolution, TokenState, TokenStore, type TokenStoreOptions, TokenVariable, UpdateTokenVariableInput, type W3CTokensExportOptions, type W3CTokensImportOptions, type W3CTokensImportReport, W3C_TOKENS_EXTENSION, createTokenStore, cssString, exportTokensCss, exportW3CTokens, exportW3CTokensJson, formatTokenCssValue, getTokenCssName, getTokenCssVariables, hexToRgba, importW3CTokens, normalizeTokenColor, parseTokenState, rgbaToHex, tokenSlug };
@@ -0,0 +1,212 @@
1
+ import { T as TokenState, a as TokenIdFactory, b as TokenCollection, c as TokenVariable, d as TokenModeContext, e as TokenResolution, f as TokenLiteral, p as parseTokenState, g as TokenMode, C as CreateTokenVariableInput, U as UpdateTokenVariableInput } from '../model-C1zApQM8.js';
2
+ export { h as CreateTokenCollectionInput, E as EMPTY_TOKEN_STATE, i as TOKEN_SCOPES_BY_TYPE, j as TOKEN_TYPES, k as TokenAlias, l as TokenError, m as TokenErrorCode, n as TokenResolutionErrorCode, o as TokenScope, q as TokenStateIssue, r as TokenType, s as TokenValue, t as addTokenMode, u as checkTokenAlias, v as coerceTokenLiteral, w as createTokenCollection, x as createTokenVariable, y as defaultTokenId, z as defaultTokenValue, A as deleteTokenCollection, B as deleteTokenVariables, D as findTokenCollection, F as findTokenMode, G as findTokenVariable, H as formatTokenValue, I as getCollectionVariables, J as getCurrentMode, K as getDefaultMode, L as getTokenCollection, M as getTokenVariable, N as isTokenAlias, O as isTokenInScope, P as isTokenScopeKnown, Q as literalTokenType, R as moveTokenMode, S as normalizeTokenName, V as normalizeTokenScopes, W as prepareTokenValue, X as removeTokenMode, Y as renameTokenCollection, Z as renameTokenMode, _ as renameTokenVariable, $ as resolveToken, a0 as resolveTokenInMode, a1 as resolveTokenValue, a2 as setTokenValue, a3 as updateTokenVariable } from '../model-C1zApQM8.js';
3
+
4
+ /**
5
+ * Colour parsing for colour tokens. Colours are stored as lowercase hex: `#rrggbb`, or
6
+ * `#rrggbbaa` when not opaque. Accepted input: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,
7
+ * `rgb()` / `rgba()` (numbers or percentages, comma or space separated, `/ alpha`),
8
+ * `transparent`, `black`, `white`, `{ r, g, b, a? }` with channels in 0–1 (Figma JSON) and
9
+ * W3C colour objects (`{ colorSpace: 'srgb', components: [r, g, b], alpha?, hex? }`).
10
+ */
11
+ /** `#rrggbb` / `#rrggbbaa` from 0–1 channels. */
12
+ declare function rgbaToHex(r: number, g: number, b: number, a?: number): string;
13
+ /** 0–1 channels of a normalised hex colour. */
14
+ declare function hexToRgba(hex: string): {
15
+ r: number;
16
+ g: number;
17
+ b: number;
18
+ a: number;
19
+ } | null;
20
+ /** The colour as normalised hex, or `null` when it is not a colour this module reads. */
21
+ declare function normalizeTokenColor(input: unknown): string | null;
22
+
23
+ /** Why the state changed. */
24
+ type TokenChangeSource = 'edit' | 'undo' | 'redo' | 'replace';
25
+ interface TokenChangeEvent {
26
+ source: TokenChangeSource;
27
+ /** Operation name (`setValue`, `deleteVariables`, a `transact` label, …). */
28
+ reason: string;
29
+ state: TokenState;
30
+ previous: TokenState;
31
+ /**
32
+ * Variables this edit deleted (also via `deleteCollection`). Detach canvas bindings to them
33
+ * with `detachTokenBindings(nodes, event.previous, event.deletedVariableIds)`.
34
+ */
35
+ deletedVariableIds: readonly string[];
36
+ }
37
+ type TokenChangeListener = (event: TokenChangeEvent) => void;
38
+ interface TokenStoreOptions {
39
+ initialState?: TokenState;
40
+ createId?: TokenIdFactory;
41
+ /** Undo steps kept (default 100). */
42
+ historyLimit?: number;
43
+ }
44
+ /**
45
+ * Undoable design-token store. Every edit is one undo step (group several with `transact`)
46
+ * and notifies subscribers once. `getState()` returns an immutable snapshot whose reference
47
+ * only changes on edits, so it works with `useSyncExternalStore` and Svelte stores.
48
+ * Refused edits throw a `TokenError` and change nothing.
49
+ */
50
+ declare class TokenStore {
51
+ private state;
52
+ private undoStack;
53
+ private redoStack;
54
+ private listeners;
55
+ private pending;
56
+ private depth;
57
+ private readonly createId;
58
+ private readonly historyLimit;
59
+ constructor(options?: TokenStoreOptions);
60
+ getState: () => TokenState;
61
+ subscribe: (listener: TokenChangeListener) => (() => void);
62
+ get collections(): readonly TokenCollection[];
63
+ get variables(): readonly TokenVariable[];
64
+ canUndo(): boolean;
65
+ canRedo(): boolean;
66
+ /** Resolves a variable under `modes` (see `resolveToken`). */
67
+ resolve(id: string, modes?: TokenModeContext): TokenResolution;
68
+ resolveValue(id: string, modes?: TokenModeContext): TokenLiteral | undefined;
69
+ /**
70
+ * Runs `fn` as one undo step with one change event. If `fn` throws, every change it made is
71
+ * rolled back and the error rethrown.
72
+ */
73
+ transact<T>(reason: string, fn: (store: this) => T): T;
74
+ private apply;
75
+ private flush;
76
+ private emit;
77
+ undo(): boolean;
78
+ redo(): boolean;
79
+ /**
80
+ * Replaces the whole state (e.g. after loading a file). Untrusted data should go through
81
+ * `parseTokenState` first. With `record: true` it is an undo step; otherwise history is cleared.
82
+ */
83
+ replaceState(state: TokenState, options?: {
84
+ record?: boolean;
85
+ reason?: string;
86
+ }): void;
87
+ /** Loads untrusted JSON (or an object) as the new state; returns the issues found. */
88
+ load(input: unknown): ReturnType<typeof parseTokenState>['issues'];
89
+ /** The state as JSON. */
90
+ toJSON(): TokenState;
91
+ createCollection(name: string, modes?: readonly string[]): TokenCollection;
92
+ renameCollection(id: string, name: string): void;
93
+ deleteCollection(id: string): string[];
94
+ addMode(collectionId: string, name: string, options?: {
95
+ from?: string;
96
+ }): TokenMode;
97
+ renameMode(collectionId: string, modeId: string, name: string): void;
98
+ removeMode(collectionId: string, modeId: string): void;
99
+ moveMode(collectionId: string, modeId: string, to: number): void;
100
+ /** Makes a mode the default by moving it first. */
101
+ setDefaultMode(collectionId: string, modeId: string): void;
102
+ createVariable(input: CreateTokenVariableInput): TokenVariable;
103
+ /** Sets a literal or `{ alias }` in one mode (id or name; default: the default mode). */
104
+ setValue(variableId: string, value: unknown, modeId?: string): void;
105
+ renameVariable(variableId: string, name: string): void;
106
+ updateVariable(variableId: string, input: UpdateTokenVariableInput): void;
107
+ /** Deletes variables; aliases to them take their values. Returns the ids deleted. */
108
+ deleteVariables(ids: string | Iterable<string>): string[];
109
+ /** Applies a pure state transform (e.g. `importW3CTokens`) as one undo step. */
110
+ update(reason: string, fn: (state: TokenState) => TokenState): void;
111
+ }
112
+ declare function createTokenStore(options?: TokenStoreOptions): TokenStore;
113
+
114
+ interface TokenCssOptions {
115
+ /** Collections to export (ids; default all). */
116
+ collections?: readonly string[];
117
+ /** Prefix after `--` (e.g. `ds-` → `--ds-color-bg`). */
118
+ prefix?: string;
119
+ /** Also prefix each variable with its collection name (avoids clashes between collections). */
120
+ collectionPrefix?: boolean;
121
+ /** Root selector (default `:root`). */
122
+ selector?: string;
123
+ /** Attribute that selects a mode (default `data-mode`), or one per collection. */
124
+ attribute?: string | ((collection: TokenCollection) => string);
125
+ /** Attribute value for a mode (default: the mode name as a lowercase slug, e.g. `dark`). */
126
+ modeValue?: (mode: TokenMode, collection: TokenCollection) => string;
127
+ /**
128
+ * Also emit `[data-mode="…"]` rules that match any element (not just the root), so a subtree
129
+ * can switch mode. Default `false`.
130
+ */
131
+ nested?: boolean;
132
+ /** Formats numbers (default: the number with the variable's `unit`, if any). */
133
+ formatNumber?: (value: number, variable: TokenVariable) => string;
134
+ }
135
+ /** Lowercase slug of a name: groups and spaces become `-` (`Color/Bg Muted` → `color-bg-muted`). */
136
+ declare function tokenSlug(name: string): string;
137
+ /** The CSS custom property for a variable (e.g. `--color-bg`). */
138
+ declare function getTokenCssName(state: TokenState, variable: TokenVariable, options?: Pick<TokenCssOptions, 'prefix' | 'collectionPrefix'>): string;
139
+ /** A CSS string literal with `"`, `\`, newlines and `<` escaped. */
140
+ declare function cssString(value: string): string;
141
+ /** A literal as CSS. */
142
+ declare function formatTokenCssValue(value: TokenLiteral, variable: TokenVariable, options?: Pick<TokenCssOptions, 'formatNumber'>): string;
143
+ /**
144
+ * Flat CSS custom properties per mode: each collection's default mode on `:root`, its other
145
+ * modes on `:root[data-mode="dark"]`. Aliases to exported variables become `var(--target)`, so
146
+ * switching the attribute re-themes everything; aliases to other variables are resolved.
147
+ */
148
+ declare function exportTokensCss(state: TokenState, options?: TokenCssOptions): string;
149
+ /**
150
+ * Resolved CSS custom properties for one mode context, e.g. for an element's inline style:
151
+ * `{ '--color-bg': '#ffffff', … }`. Aliases are resolved (no `var()`).
152
+ */
153
+ declare function getTokenCssVariables(state: TokenState, modes?: TokenModeContext, options?: Omit<TokenCssOptions, 'selector' | 'attribute' | 'modeValue' | 'nested'>): Record<string, string>;
154
+
155
+ /**
156
+ * W3C Design Tokens (DTCG) JSON. Each collection is a top-level group named after it; variable
157
+ * names' `/` groups become nested groups; aliases are `{Collection.group.token}` references.
158
+ * `$value` holds the default mode (or the modes passed in). Modes, ids and scopes ride along in
159
+ * `$extensions["com.pixerate.tokens"]`, so an export round-trips; tools that ignore extensions
160
+ * still read the default mode. Strings and booleans use `$type: "string"` / `"boolean"`
161
+ * (outside the spec, as Tokens Studio and Style Dictionary do).
162
+ */
163
+ declare const W3C_TOKENS_EXTENSION = "com.pixerate.tokens";
164
+ interface W3CTokensExportOptions {
165
+ /** Collections to export (ids; default all). */
166
+ collections?: readonly string[];
167
+ /** Modes that supply `$value` (default: each collection's default mode). */
168
+ modes?: TokenModeContext;
169
+ /** Include `$extensions` with ids, every mode's value and scopes (default `true`). */
170
+ extensions?: boolean;
171
+ /** Colours as `#hex` strings (default) or W3C colour objects. */
172
+ colorFormat?: 'hex' | 'object';
173
+ }
174
+ type Json = null | boolean | number | string | Json[] | {
175
+ [key: string]: Json;
176
+ };
177
+ /** The tokens as a W3C Design Tokens object (see {@link W3C_TOKENS_EXTENSION}). */
178
+ declare function exportW3CTokens(state: TokenState, options?: W3CTokensExportOptions): Record<string, Json>;
179
+ /** {@link exportW3CTokens} as indented JSON text. */
180
+ declare function exportW3CTokensJson(state: TokenState, options?: W3CTokensExportOptions): string;
181
+ interface W3CTokensImportOptions {
182
+ /**
183
+ * Collection for tokens outside a marked collection group (a plain W3C file). Default
184
+ * `"Tokens"`; an existing collection with that name is updated.
185
+ */
186
+ collection?: string;
187
+ /** Mode that plain `$value`s go to (name; created when missing). Default: the default mode. */
188
+ mode?: string;
189
+ createId?: TokenIdFactory;
190
+ }
191
+ interface W3CTokensImportReport {
192
+ collectionsAdded: number;
193
+ modesAdded: number;
194
+ variablesAdded: number;
195
+ /** Existing variables (matched by collection and name) that were updated in place. */
196
+ variablesUpdated: number;
197
+ /** Entries skipped or values not taken, with the reason. */
198
+ warnings: string[];
199
+ }
200
+ /**
201
+ * Merges a W3C Design Tokens document (object or JSON text) into `state`. Collections, modes
202
+ * and variables are matched by name and updated in place (ids, and so canvas bindings, are
203
+ * kept); new ones take the ids in the file's extensions when free. Junk entries, type clashes,
204
+ * unresolved references and alias cycles are skipped with a warning. Throws `invalid-input`
205
+ * only when the input is not a JSON object.
206
+ */
207
+ declare function importW3CTokens(state: TokenState, input: unknown, options?: W3CTokensImportOptions): {
208
+ state: TokenState;
209
+ report: W3CTokensImportReport;
210
+ };
211
+
212
+ export { CreateTokenVariableInput, type TokenChangeEvent, type TokenChangeListener, type TokenChangeSource, TokenCollection, type TokenCssOptions, TokenIdFactory, TokenLiteral, TokenMode, TokenModeContext, TokenResolution, TokenState, TokenStore, type TokenStoreOptions, TokenVariable, UpdateTokenVariableInput, type W3CTokensExportOptions, type W3CTokensImportOptions, type W3CTokensImportReport, W3C_TOKENS_EXTENSION, createTokenStore, cssString, exportTokensCss, exportW3CTokens, exportW3CTokensJson, formatTokenCssValue, getTokenCssName, getTokenCssVariables, hexToRgba, importW3CTokens, normalizeTokenColor, parseTokenState, rgbaToHex, tokenSlug };
@@ -0,0 +1,115 @@
1
+ import {
2
+ EMPTY_TOKEN_STATE,
3
+ TOKEN_SCOPES_BY_TYPE,
4
+ TOKEN_TYPES,
5
+ TokenError,
6
+ TokenStore,
7
+ W3C_TOKENS_EXTENSION,
8
+ addTokenMode,
9
+ checkTokenAlias,
10
+ coerceTokenLiteral,
11
+ createTokenCollection,
12
+ createTokenStore,
13
+ createTokenVariable,
14
+ cssString,
15
+ defaultTokenId,
16
+ defaultTokenValue,
17
+ deleteTokenCollection,
18
+ deleteTokenVariables,
19
+ exportTokensCss,
20
+ exportW3CTokens,
21
+ exportW3CTokensJson,
22
+ findTokenCollection,
23
+ findTokenMode,
24
+ findTokenVariable,
25
+ formatTokenCssValue,
26
+ formatTokenValue,
27
+ getCollectionVariables,
28
+ getCurrentMode,
29
+ getDefaultMode,
30
+ getTokenCollection,
31
+ getTokenCssName,
32
+ getTokenCssVariables,
33
+ getTokenVariable,
34
+ hexToRgba,
35
+ importW3CTokens,
36
+ isTokenAlias,
37
+ isTokenInScope,
38
+ isTokenScopeKnown,
39
+ literalTokenType,
40
+ moveTokenMode,
41
+ normalizeTokenColor,
42
+ normalizeTokenName,
43
+ normalizeTokenScopes,
44
+ parseTokenState,
45
+ prepareTokenValue,
46
+ removeTokenMode,
47
+ renameTokenCollection,
48
+ renameTokenMode,
49
+ renameTokenVariable,
50
+ resolveToken,
51
+ resolveTokenInMode,
52
+ resolveTokenValue,
53
+ rgbaToHex,
54
+ setTokenValue,
55
+ tokenSlug,
56
+ updateTokenVariable
57
+ } from "../chunk-HRMEDT2L.js";
58
+ export {
59
+ EMPTY_TOKEN_STATE,
60
+ TOKEN_SCOPES_BY_TYPE,
61
+ TOKEN_TYPES,
62
+ TokenError,
63
+ TokenStore,
64
+ W3C_TOKENS_EXTENSION,
65
+ addTokenMode,
66
+ checkTokenAlias,
67
+ coerceTokenLiteral,
68
+ createTokenCollection,
69
+ createTokenStore,
70
+ createTokenVariable,
71
+ cssString,
72
+ defaultTokenId,
73
+ defaultTokenValue,
74
+ deleteTokenCollection,
75
+ deleteTokenVariables,
76
+ exportTokensCss,
77
+ exportW3CTokens,
78
+ exportW3CTokensJson,
79
+ findTokenCollection,
80
+ findTokenMode,
81
+ findTokenVariable,
82
+ formatTokenCssValue,
83
+ formatTokenValue,
84
+ getCollectionVariables,
85
+ getCurrentMode,
86
+ getDefaultMode,
87
+ getTokenCollection,
88
+ getTokenCssName,
89
+ getTokenCssVariables,
90
+ getTokenVariable,
91
+ hexToRgba,
92
+ importW3CTokens,
93
+ isTokenAlias,
94
+ isTokenInScope,
95
+ isTokenScopeKnown,
96
+ literalTokenType,
97
+ moveTokenMode,
98
+ normalizeTokenColor,
99
+ normalizeTokenName,
100
+ normalizeTokenScopes,
101
+ parseTokenState,
102
+ prepareTokenValue,
103
+ removeTokenMode,
104
+ renameTokenCollection,
105
+ renameTokenMode,
106
+ renameTokenVariable,
107
+ resolveToken,
108
+ resolveTokenInMode,
109
+ resolveTokenValue,
110
+ rgbaToHex,
111
+ setTokenValue,
112
+ tokenSlug,
113
+ updateTokenVariable
114
+ };
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}