@lushly-dev/violet-runtime 0.0.0-stage → 0.3.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/cache.d.ts +73 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +205 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +157 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +454 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/theme.d.ts +136 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +287 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -3
package/dist/client.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Violet Runtime Client
|
|
3
|
+
*
|
|
4
|
+
* Main client for loading and managing design tokens.
|
|
5
|
+
*/
|
|
6
|
+
import { TokenCache } from './cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* Default configuration values. The empty apiUrl means the page's own origin;
|
|
9
|
+
* there is no default remote host, so an API key is only ever sent to a URL
|
|
10
|
+
* the caller chose.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_CONFIG = {
|
|
13
|
+
apiUrl: '',
|
|
14
|
+
cacheEnabled: true,
|
|
15
|
+
cacheTtl: 3600,
|
|
16
|
+
autoApply: true,
|
|
17
|
+
cssPrefix: '',
|
|
18
|
+
timeout: 10_000,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convert a glob pattern (where `*` matches any characters) into an anchored,
|
|
22
|
+
* fully escaped RegExp. All other characters are matched literally.
|
|
23
|
+
*/
|
|
24
|
+
function globToRegExp(pattern) {
|
|
25
|
+
const source = pattern
|
|
26
|
+
.split('*')
|
|
27
|
+
.map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&'))
|
|
28
|
+
.join('.*');
|
|
29
|
+
return new RegExp(`^${source}$`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validate a preloaded source and copy its tokens, so later changes to the
|
|
33
|
+
* caller's array do not reach the runtime. A token without `resolvedAt` is
|
|
34
|
+
* recorded as resolved at `nodeId`.
|
|
35
|
+
*/
|
|
36
|
+
function sourceTokens(source, nodeId) {
|
|
37
|
+
if (!source || !Array.isArray(source.tokens)) {
|
|
38
|
+
throw new Error(`VioletRuntime: the source for "${nodeId}" must be { tokens: Token[] }, an array of resolved tokens such as { id: "color.brand", value: "#352064" }.`);
|
|
39
|
+
}
|
|
40
|
+
return source.tokens.map((token, index) => {
|
|
41
|
+
const value = token?.value;
|
|
42
|
+
const valid = token !== null &&
|
|
43
|
+
typeof token === 'object' &&
|
|
44
|
+
typeof token.id === 'string' &&
|
|
45
|
+
token.id !== '' &&
|
|
46
|
+
(typeof value === 'string' ||
|
|
47
|
+
(typeof value === 'number' && Number.isFinite(value)) ||
|
|
48
|
+
(value !== null && typeof value === 'object' && !Array.isArray(value))) &&
|
|
49
|
+
(token.resolvedAt === undefined || typeof token.resolvedAt === 'string');
|
|
50
|
+
if (!valid) {
|
|
51
|
+
throw new Error(`VioletRuntime: token ${index} in the source for "${nodeId}" needs a non-empty string id, a string, finite number or object value, and a string resolvedAt if any.`);
|
|
52
|
+
}
|
|
53
|
+
return { ...token, resolvedAt: token.resolvedAt ?? nodeId };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* VioletRuntime - Web SDK for dynamic token loading and application.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const violet = new VioletRuntime({
|
|
62
|
+
* nodeId: "xbox-web-dark",
|
|
63
|
+
* apiUrl: "https://violet.example.com",
|
|
64
|
+
* apiKey: "your-api-key",
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Load tokens from API
|
|
68
|
+
* await violet.load();
|
|
69
|
+
*
|
|
70
|
+
* // Get a specific token
|
|
71
|
+
* const primary = violet.get("color.brand.primary");
|
|
72
|
+
*
|
|
73
|
+
* // Apply to document as CSS variables
|
|
74
|
+
* violet.applyToDocument();
|
|
75
|
+
*
|
|
76
|
+
* // Switch to different theme
|
|
77
|
+
* await violet.switchNode("xbox-web-light");
|
|
78
|
+
*
|
|
79
|
+
* // Or apply preloaded tokens with no token server
|
|
80
|
+
* const local = new VioletRuntime({ nodeId: "brand-dark", source: { tokens } });
|
|
81
|
+
* await local.load();
|
|
82
|
+
* await local.switchNode("brand-light", { tokens: lightTokens });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export class VioletRuntime {
|
|
86
|
+
config;
|
|
87
|
+
/** Tokens for currentNodeId when created with a preloaded source; null over HTTP. */
|
|
88
|
+
source = null;
|
|
89
|
+
cache;
|
|
90
|
+
tokens = new Map();
|
|
91
|
+
currentNodeId;
|
|
92
|
+
listeners = new Map();
|
|
93
|
+
initialized = false;
|
|
94
|
+
/**
|
|
95
|
+
* Incremented by every load()/switchNode(). A request only applies its
|
|
96
|
+
* result if no newer request has started since (latest request wins).
|
|
97
|
+
*/
|
|
98
|
+
generation = 0;
|
|
99
|
+
constructor(config) {
|
|
100
|
+
if (config.source !== undefined) {
|
|
101
|
+
if (config.apiUrl !== undefined || config.apiKey !== undefined) {
|
|
102
|
+
throw new Error('VioletRuntime: pass either source or apiUrl/apiKey, not both. A preloaded source makes no request; drop apiUrl and apiKey, or drop source to load over HTTP.');
|
|
103
|
+
}
|
|
104
|
+
this.source = sourceTokens(config.source, config.nodeId);
|
|
105
|
+
}
|
|
106
|
+
else if (config.apiKey && !config.apiUrl?.trim()) {
|
|
107
|
+
throw new Error('VioletRuntime: apiUrl is required when apiKey is set. Pass the URL of your Violet deployment, for example { apiUrl: "https://violet.example.com", apiKey }.');
|
|
108
|
+
}
|
|
109
|
+
const { source: _source, ...options } = config;
|
|
110
|
+
this.config = {
|
|
111
|
+
...DEFAULT_CONFIG,
|
|
112
|
+
...options,
|
|
113
|
+
apiKey: config.apiKey ?? '',
|
|
114
|
+
};
|
|
115
|
+
// A preloaded source is already in memory; a cached copy could only shadow it.
|
|
116
|
+
if (this.source)
|
|
117
|
+
this.config.cacheEnabled = false;
|
|
118
|
+
this.currentNodeId = config.nodeId;
|
|
119
|
+
this.cache = new TokenCache();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Initialize the runtime (call once before using).
|
|
123
|
+
*/
|
|
124
|
+
async init() {
|
|
125
|
+
if (this.initialized)
|
|
126
|
+
return;
|
|
127
|
+
if (this.config.cacheEnabled) {
|
|
128
|
+
await this.cache.init();
|
|
129
|
+
}
|
|
130
|
+
this.initialized = true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Load tokens from the preloaded source, or from API or cache.
|
|
134
|
+
* Automatically applies tokens if autoApply is enabled.
|
|
135
|
+
*/
|
|
136
|
+
async load() {
|
|
137
|
+
await this.init();
|
|
138
|
+
const generation = ++this.generation;
|
|
139
|
+
const nodeId = this.currentNodeId;
|
|
140
|
+
const { tokens, fromCache } = this.source
|
|
141
|
+
? { tokens: [...this.source], fromCache: false }
|
|
142
|
+
: await this.resolveTokens(nodeId);
|
|
143
|
+
// A newer load()/switchNode() has started: don't clobber its state.
|
|
144
|
+
if (generation !== this.generation)
|
|
145
|
+
return tokens;
|
|
146
|
+
this.setTokens(tokens);
|
|
147
|
+
if (!fromCache) {
|
|
148
|
+
this.emit('load', { tokens });
|
|
149
|
+
}
|
|
150
|
+
if (this.config.autoApply) {
|
|
151
|
+
this.applyToDocument();
|
|
152
|
+
}
|
|
153
|
+
return tokens;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get a token by ID.
|
|
157
|
+
*/
|
|
158
|
+
get(tokenId) {
|
|
159
|
+
return this.tokens.get(tokenId);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get token value directly.
|
|
163
|
+
*/
|
|
164
|
+
getValue(tokenId) {
|
|
165
|
+
return this.tokens.get(tokenId)?.value;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get all loaded tokens.
|
|
169
|
+
*/
|
|
170
|
+
getAll() {
|
|
171
|
+
return Array.from(this.tokens.values());
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get tokens whose ID matches a glob pattern. `*` matches any characters;
|
|
175
|
+
* everything else is literal and the whole ID must match
|
|
176
|
+
* (`color.*` matches `color.primary` but not `bgcolor.primary`).
|
|
177
|
+
*/
|
|
178
|
+
getByPattern(pattern) {
|
|
179
|
+
const regex = globToRegExp(pattern);
|
|
180
|
+
return this.getAll().filter((token) => regex.test(token.id));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Apply tokens to document as CSS custom properties.
|
|
184
|
+
*/
|
|
185
|
+
applyToDocument() {
|
|
186
|
+
if (typeof document === 'undefined')
|
|
187
|
+
return;
|
|
188
|
+
const root = document.documentElement;
|
|
189
|
+
const prefix = this.config.cssPrefix;
|
|
190
|
+
for (const token of this.tokens.values()) {
|
|
191
|
+
if (typeof token.value === 'string' || typeof token.value === 'number') {
|
|
192
|
+
const varName = this.tokenToCssVar(token.id, prefix);
|
|
193
|
+
root.style.setProperty(varName, String(token.value));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Remove tokens from document.
|
|
199
|
+
*/
|
|
200
|
+
removeFromDocument() {
|
|
201
|
+
if (typeof document === 'undefined')
|
|
202
|
+
return;
|
|
203
|
+
const root = document.documentElement;
|
|
204
|
+
const prefix = this.config.cssPrefix;
|
|
205
|
+
for (const token of this.tokens.values()) {
|
|
206
|
+
if (typeof token.value === 'string' || typeof token.value === 'number') {
|
|
207
|
+
const varName = this.tokenToCssVar(token.id, prefix);
|
|
208
|
+
root.style.removeProperty(varName);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Switch to a different node (e.g., theme switch).
|
|
214
|
+
*
|
|
215
|
+
* A runtime created with a `source` takes the new node's tokens as
|
|
216
|
+
* `source`; it may be omitted only to reapply the node it already holds.
|
|
217
|
+
* An HTTP runtime refuses a source.
|
|
218
|
+
*/
|
|
219
|
+
async switchNode(nodeId, source) {
|
|
220
|
+
// Checked before anything starts, so a refused switch supersedes nothing.
|
|
221
|
+
const preloaded = this.nextSource(nodeId, source);
|
|
222
|
+
await this.init();
|
|
223
|
+
const generation = ++this.generation;
|
|
224
|
+
const previousNodeId = this.currentNodeId;
|
|
225
|
+
// Resolve first: if this fails (network, API error) nothing has changed -
|
|
226
|
+
// the previous theme stays applied and currentNodeId is untouched.
|
|
227
|
+
const { tokens, fromCache } = preloaded
|
|
228
|
+
? { tokens: [...preloaded], fromCache: false }
|
|
229
|
+
: await this.resolveTokens(nodeId);
|
|
230
|
+
// A newer load()/switchNode() has started: this result is stale.
|
|
231
|
+
if (generation !== this.generation)
|
|
232
|
+
return tokens;
|
|
233
|
+
// Commit: remove old tokens, then apply the new ones.
|
|
234
|
+
this.removeFromDocument();
|
|
235
|
+
this.currentNodeId = nodeId;
|
|
236
|
+
if (preloaded)
|
|
237
|
+
this.source = preloaded;
|
|
238
|
+
this.setTokens(tokens);
|
|
239
|
+
if (!fromCache) {
|
|
240
|
+
this.emit('load', { tokens });
|
|
241
|
+
}
|
|
242
|
+
if (this.config.autoApply) {
|
|
243
|
+
this.applyToDocument();
|
|
244
|
+
}
|
|
245
|
+
this.emit('theme:change', {
|
|
246
|
+
from: previousNodeId,
|
|
247
|
+
to: nodeId,
|
|
248
|
+
tokens,
|
|
249
|
+
});
|
|
250
|
+
return tokens;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get current node ID.
|
|
254
|
+
*/
|
|
255
|
+
getCurrentNodeId() {
|
|
256
|
+
return this.currentNodeId;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Preload tokens for a node without applying. Nothing to do with a
|
|
260
|
+
* preloaded source: its tokens are already in memory.
|
|
261
|
+
*/
|
|
262
|
+
async preload(nodeId) {
|
|
263
|
+
if (this.source)
|
|
264
|
+
return;
|
|
265
|
+
await this.init();
|
|
266
|
+
if (this.config.cacheEnabled) {
|
|
267
|
+
const cached = await this.readCache(nodeId);
|
|
268
|
+
if (cached && !this.cache.isExpired(cached)) {
|
|
269
|
+
return; // Already cached
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const tokens = await this.fetchTokens(nodeId);
|
|
273
|
+
if (this.config.cacheEnabled) {
|
|
274
|
+
await this.writeCache(nodeId, tokens);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Invalidate cache for current or specified node.
|
|
279
|
+
*/
|
|
280
|
+
async invalidateCache(nodeId) {
|
|
281
|
+
await this.cache.delete(this.cacheKey(nodeId ?? this.currentNodeId));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Clear all cached tokens.
|
|
285
|
+
*/
|
|
286
|
+
async clearCache() {
|
|
287
|
+
await this.cache.clear();
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Subscribe to runtime events.
|
|
291
|
+
*/
|
|
292
|
+
on(event, listener) {
|
|
293
|
+
if (!this.listeners.has(event)) {
|
|
294
|
+
this.listeners.set(event, new Set());
|
|
295
|
+
}
|
|
296
|
+
this.listeners.get(event)?.add(listener);
|
|
297
|
+
// Return unsubscribe function
|
|
298
|
+
return () => {
|
|
299
|
+
this.listeners.get(event)?.delete(listener);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Emit an event to listeners.
|
|
304
|
+
*/
|
|
305
|
+
emit(type, data, nodeId = this.currentNodeId) {
|
|
306
|
+
const eventData = {
|
|
307
|
+
type,
|
|
308
|
+
nodeId,
|
|
309
|
+
timestamp: Date.now(),
|
|
310
|
+
data,
|
|
311
|
+
};
|
|
312
|
+
const listeners = this.listeners.get(type);
|
|
313
|
+
if (listeners) {
|
|
314
|
+
for (const listener of listeners) {
|
|
315
|
+
try {
|
|
316
|
+
listener(eventData);
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
// Don't let listener errors break the runtime
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The validated tokens a switch to `nodeId` applies from memory, or null
|
|
326
|
+
* when this runtime loads over HTTP. Throws when the call does not fit the
|
|
327
|
+
* runtime's token origin.
|
|
328
|
+
*/
|
|
329
|
+
nextSource(nodeId, source) {
|
|
330
|
+
if (this.source === null) {
|
|
331
|
+
if (source !== undefined) {
|
|
332
|
+
throw new Error('VioletRuntime: switchNode was given a source, but this runtime loads over HTTP. Create the runtime with { nodeId, source } to apply preloaded tokens, or call switchNode(nodeId) without one.');
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
if (source !== undefined)
|
|
337
|
+
return sourceTokens(source, nodeId);
|
|
338
|
+
if (nodeId === this.currentNodeId)
|
|
339
|
+
return this.source;
|
|
340
|
+
throw new Error(`VioletRuntime: switchNode("${nodeId}") needs a source, because this runtime applies preloaded tokens and holds none for "${nodeId}". Call switchNode("${nodeId}", { tokens }).`);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Set tokens in internal map.
|
|
344
|
+
*/
|
|
345
|
+
setTokens(tokens) {
|
|
346
|
+
this.tokens.clear();
|
|
347
|
+
for (const token of tokens) {
|
|
348
|
+
this.tokens.set(token.id, token);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Convert token ID to CSS variable name.
|
|
353
|
+
*/
|
|
354
|
+
tokenToCssVar(tokenId, prefix) {
|
|
355
|
+
const name = tokenId.replace(/\./g, '-');
|
|
356
|
+
return prefix ? `--${prefix}-${name}` : `--${name}`;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Cache key for a node. Includes the API URL so tokens from different
|
|
360
|
+
* backends (staging/production) never collide.
|
|
361
|
+
*/
|
|
362
|
+
cacheKey(nodeId) {
|
|
363
|
+
return `${this.config.apiUrl.replace(/\/+$/, '')}::${nodeId}`;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Read from the cache. Cache I/O is best-effort: failures count as a miss.
|
|
367
|
+
*/
|
|
368
|
+
async readCache(nodeId) {
|
|
369
|
+
try {
|
|
370
|
+
return await this.cache.get(this.cacheKey(nodeId));
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Write to the cache. Cache I/O is best-effort (e.g. storage quota errors
|
|
378
|
+
* must not break loading). Returns whether the write succeeded.
|
|
379
|
+
*/
|
|
380
|
+
async writeCache(nodeId, tokens) {
|
|
381
|
+
try {
|
|
382
|
+
await this.cache.set(this.cacheKey(nodeId), tokens, this.config.cacheTtl);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Resolve tokens for a node from cache or API without touching runtime
|
|
391
|
+
* state (tokens, currentNodeId, document).
|
|
392
|
+
*/
|
|
393
|
+
async resolveTokens(nodeId) {
|
|
394
|
+
if (this.config.cacheEnabled) {
|
|
395
|
+
const cached = await this.readCache(nodeId);
|
|
396
|
+
if (cached && !this.cache.isExpired(cached)) {
|
|
397
|
+
this.emit('cache:hit', { tokens: cached.tokens }, nodeId);
|
|
398
|
+
return { tokens: cached.tokens, fromCache: true };
|
|
399
|
+
}
|
|
400
|
+
this.emit('cache:miss', {}, nodeId);
|
|
401
|
+
}
|
|
402
|
+
const tokens = await this.fetchTokens(nodeId);
|
|
403
|
+
if (this.config.cacheEnabled && (await this.writeCache(nodeId, tokens))) {
|
|
404
|
+
this.emit('cache:update', { tokens }, nodeId);
|
|
405
|
+
}
|
|
406
|
+
return { tokens, fromCache: false };
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Fetch tokens from API (with timeout). Emits `load:error` exactly once on failure.
|
|
410
|
+
*/
|
|
411
|
+
async fetchTokens(nodeId) {
|
|
412
|
+
const url = `${this.config.apiUrl}/api/v1/nodes/${encodeURIComponent(nodeId)}/tokens`;
|
|
413
|
+
const headers = {
|
|
414
|
+
'Content-Type': 'application/json',
|
|
415
|
+
};
|
|
416
|
+
if (this.config.apiKey) {
|
|
417
|
+
headers['X-API-Key'] = this.config.apiKey;
|
|
418
|
+
}
|
|
419
|
+
const timeout = this.config.timeout ?? DEFAULT_CONFIG.timeout;
|
|
420
|
+
const controller = new AbortController();
|
|
421
|
+
let timedOut = false;
|
|
422
|
+
const timer = timeout > 0
|
|
423
|
+
? setTimeout(() => {
|
|
424
|
+
timedOut = true;
|
|
425
|
+
controller.abort();
|
|
426
|
+
}, timeout)
|
|
427
|
+
: undefined;
|
|
428
|
+
try {
|
|
429
|
+
const response = await fetch(url, { headers, signal: controller.signal });
|
|
430
|
+
if (!response.ok) {
|
|
431
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
432
|
+
}
|
|
433
|
+
const result = await response.json();
|
|
434
|
+
if (!result.success || !result.data) {
|
|
435
|
+
const error = result.error ?? {
|
|
436
|
+
code: 'UNKNOWN',
|
|
437
|
+
message: 'Unknown error',
|
|
438
|
+
};
|
|
439
|
+
throw new Error(`${error.code}: ${error.message}`);
|
|
440
|
+
}
|
|
441
|
+
return result.data.tokens;
|
|
442
|
+
}
|
|
443
|
+
catch (caught) {
|
|
444
|
+
const error = timedOut ? new Error(`Request timed out after ${timeout}ms: ${url}`) : caught;
|
|
445
|
+
this.emit('load:error', error, nodeId);
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
finally {
|
|
449
|
+
if (timer !== undefined)
|
|
450
|
+
clearTimeout(timer);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAcxC;;;;GAIG;AACH,MAAM,cAAc,GAAqE;IACxF,MAAM,EAAE,EAAE;IACV,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,MAAM;CACf,CAAC;AAEF;;;GAGG;AACH,SAAS,YAAY,CAAC,OAAe;IACpC,MAAM,MAAM,GAAG,OAAO;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;SACzD,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAyB,EAAE,MAAc;IAC9D,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACd,kCAAkC,MAAM,6GAA6G,CACrJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACzC,MAAM,KAAK,GAAG,KAAK,EAAE,KAAK,CAAC;QAC3B,MAAM,KAAK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vC,MAAM,KAAK,CAAC;QACb,CAAC;gBAAS,CAAC;YACV,IAAI,KAAK,KAAK,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lushly-dev/violet-runtime - Web SDK for Violet Design Tokens
|
|
3
|
+
*
|
|
4
|
+
* Dynamic token loading, caching, and theme management for web applications.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { VioletRuntime, ThemeManager } from "@lushly-dev/violet-runtime";
|
|
9
|
+
*
|
|
10
|
+
* // Basic usage
|
|
11
|
+
* const violet = new VioletRuntime({
|
|
12
|
+
* nodeId: "xbox-web-dark",
|
|
13
|
+
* apiUrl: "https://violet.example.com",
|
|
14
|
+
* apiKey: "your-api-key",
|
|
15
|
+
* });
|
|
16
|
+
* await violet.load();
|
|
17
|
+
*
|
|
18
|
+
* // With theme management
|
|
19
|
+
* const themes = new ThemeManager(violet, {
|
|
20
|
+
* themes: [
|
|
21
|
+
* { nodeId: "brand-light", name: "Light" },
|
|
22
|
+
* { nodeId: "brand-dark", name: "Dark" },
|
|
23
|
+
* ],
|
|
24
|
+
* defaultTheme: "brand-light",
|
|
25
|
+
* });
|
|
26
|
+
* await themes.switch("brand-dark");
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @packageDocumentation
|
|
30
|
+
*/
|
|
31
|
+
export { VioletRuntime } from './client.js';
|
|
32
|
+
export { ThemeManager, type ThemeManagerOptions } from './theme.js';
|
|
33
|
+
export { TokenCache } from './cache.js';
|
|
34
|
+
export type { VioletConfig, VioletBaseConfig, VioletHttpConfig, VioletSourceConfig, VioletTokenSource, SourceToken, Token, TokenMetadata, Theme, CacheEntry, ApiResponse, TokensResponse, RuntimeEvent, RuntimeEventListener, RuntimeEventData, } from './types.js';
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,YAAY,EACX,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,KAAK,EACL,aAAa,EACb,KAAK,EACL,UAAU,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lushly-dev/violet-runtime - Web SDK for Violet Design Tokens
|
|
3
|
+
*
|
|
4
|
+
* Dynamic token loading, caching, and theme management for web applications.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { VioletRuntime, ThemeManager } from "@lushly-dev/violet-runtime";
|
|
9
|
+
*
|
|
10
|
+
* // Basic usage
|
|
11
|
+
* const violet = new VioletRuntime({
|
|
12
|
+
* nodeId: "xbox-web-dark",
|
|
13
|
+
* apiUrl: "https://violet.example.com",
|
|
14
|
+
* apiKey: "your-api-key",
|
|
15
|
+
* });
|
|
16
|
+
* await violet.load();
|
|
17
|
+
*
|
|
18
|
+
* // With theme management
|
|
19
|
+
* const themes = new ThemeManager(violet, {
|
|
20
|
+
* themes: [
|
|
21
|
+
* { nodeId: "brand-light", name: "Light" },
|
|
22
|
+
* { nodeId: "brand-dark", name: "Dark" },
|
|
23
|
+
* ],
|
|
24
|
+
* defaultTheme: "brand-light",
|
|
25
|
+
* });
|
|
26
|
+
* await themes.switch("brand-dark");
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @packageDocumentation
|
|
30
|
+
*/
|
|
31
|
+
// Main client
|
|
32
|
+
export { VioletRuntime } from './client.js';
|
|
33
|
+
// Theme management
|
|
34
|
+
export { ThemeManager } from './theme.js';
|
|
35
|
+
// Cache (for advanced usage)
|
|
36
|
+
export { TokenCache } from './cache.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,mBAAmB;AACnB,OAAO,EAAE,YAAY,EAA4B,MAAM,YAAY,CAAC;AAEpE,6BAA6B;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages theme switching with preloading and transitions.
|
|
5
|
+
*/
|
|
6
|
+
import type { VioletRuntime } from './client.js';
|
|
7
|
+
import type { Theme } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Theme Manager options
|
|
10
|
+
*/
|
|
11
|
+
export interface ThemeManagerOptions {
|
|
12
|
+
/** Available themes */
|
|
13
|
+
themes: Theme[];
|
|
14
|
+
/** Default theme node ID */
|
|
15
|
+
defaultTheme: string;
|
|
16
|
+
/** Storage key for persisting theme preference */
|
|
17
|
+
storageKey?: string;
|
|
18
|
+
/** Transition duration in ms (default: 200) */
|
|
19
|
+
transitionDuration?: number;
|
|
20
|
+
/** CSS class added during theme transitions */
|
|
21
|
+
transitionClass?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* ThemeManager - Manages theme switching with smooth transitions.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const violet = new VioletRuntime({ nodeId: "brand-light" });
|
|
29
|
+
* await violet.load();
|
|
30
|
+
*
|
|
31
|
+
* const themes = new ThemeManager(violet, {
|
|
32
|
+
* themes: [
|
|
33
|
+
* { nodeId: "brand-light", name: "Light" },
|
|
34
|
+
* { nodeId: "brand-dark", name: "Dark" },
|
|
35
|
+
* ],
|
|
36
|
+
* defaultTheme: "brand-light",
|
|
37
|
+
* storageKey: "preferred-theme",
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Get saved preference or default
|
|
41
|
+
* const initial = themes.getSavedTheme();
|
|
42
|
+
* await themes.apply(initial);
|
|
43
|
+
*
|
|
44
|
+
* // Switch theme
|
|
45
|
+
* await themes.switch("brand-dark");
|
|
46
|
+
*
|
|
47
|
+
* // Preload for instant switching
|
|
48
|
+
* await themes.preloadAll();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class ThemeManager {
|
|
52
|
+
private runtime;
|
|
53
|
+
private themes;
|
|
54
|
+
private currentTheme;
|
|
55
|
+
private storageKey;
|
|
56
|
+
private transitionDuration;
|
|
57
|
+
private transitionClass;
|
|
58
|
+
private listeners;
|
|
59
|
+
/** Incremented by every apply()/switch(); only the latest request updates state. */
|
|
60
|
+
private requestSeq;
|
|
61
|
+
/** Theme of the latest apply()/switch() while it is in flight, else null. */
|
|
62
|
+
private requestedTheme;
|
|
63
|
+
/** Number of in-flight transitions holding the transition class on <html>. */
|
|
64
|
+
private activeTransitions;
|
|
65
|
+
constructor(runtime: VioletRuntime, options: ThemeManagerOptions);
|
|
66
|
+
/**
|
|
67
|
+
* Get all available themes.
|
|
68
|
+
*/
|
|
69
|
+
getThemes(): Theme[];
|
|
70
|
+
/**
|
|
71
|
+
* Get current theme.
|
|
72
|
+
*/
|
|
73
|
+
getCurrentTheme(): Theme | null;
|
|
74
|
+
/**
|
|
75
|
+
* Get saved theme preference from storage.
|
|
76
|
+
*/
|
|
77
|
+
getSavedTheme(): string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Save theme preference to storage (best-effort).
|
|
80
|
+
*/
|
|
81
|
+
private saveTheme;
|
|
82
|
+
/**
|
|
83
|
+
* Apply a theme (initial load).
|
|
84
|
+
*/
|
|
85
|
+
apply(nodeId: string): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Switch to a different theme with transition.
|
|
88
|
+
*/
|
|
89
|
+
switch(nodeId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Toggle between two themes.
|
|
92
|
+
*/
|
|
93
|
+
toggle(themeA: string, themeB: string): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Preload a specific theme.
|
|
96
|
+
*/
|
|
97
|
+
preload(nodeId: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Preload all themes.
|
|
100
|
+
*/
|
|
101
|
+
preloadAll(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to theme changes.
|
|
104
|
+
*/
|
|
105
|
+
onChange(listener: (theme: Theme) => void): () => void;
|
|
106
|
+
/**
|
|
107
|
+
* Set up system preference detection (prefers-color-scheme), and, when a
|
|
108
|
+
* high-contrast theme is given, prefers-contrast and forced-colors: the
|
|
109
|
+
* high-contrast theme wins whenever `(prefers-contrast: more)` or
|
|
110
|
+
* `(forced-colors: active)` matches, whatever the color scheme.
|
|
111
|
+
*
|
|
112
|
+
* Follows changes to every query until the returned function is called.
|
|
113
|
+
*/
|
|
114
|
+
useSystemPreference(lightTheme: string, darkTheme: string, highContrastTheme?: string): () => void;
|
|
115
|
+
/**
|
|
116
|
+
* Start a request: it becomes the latest, and its theme the requested one.
|
|
117
|
+
*/
|
|
118
|
+
private begin;
|
|
119
|
+
/**
|
|
120
|
+
* End a request, successful or not. Only the latest clears the requested theme.
|
|
121
|
+
*/
|
|
122
|
+
private settle;
|
|
123
|
+
/**
|
|
124
|
+
* Switch the runtime to a theme, with the theme's preloaded tokens if it has any.
|
|
125
|
+
*/
|
|
126
|
+
private switchRuntime;
|
|
127
|
+
/**
|
|
128
|
+
* Notify listeners of theme change.
|
|
129
|
+
*/
|
|
130
|
+
private notifyListeners;
|
|
131
|
+
/**
|
|
132
|
+
* Delay helper.
|
|
133
|
+
*/
|
|
134
|
+
private delay;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=theme.d.ts.map
|