tokenami 0.0.77--canary.400.e4d091f.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 +3 -0
- package/bin.js +2 -0
- package/dist/cli.cjs +1256 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1227 -0
- package/dist/index.cjs +1172 -0
- package/dist/index.d.cts +526 -0
- package/dist/index.d.ts +526 -0
- package/dist/index.js +1149 -0
- package/package.json +69 -0
- package/stubs/tokenami.config.cjs +175 -0
- package/stubs/tokenami.config.js +175 -0
- package/stubs/tokenami.config.mjs +175 -0
- package/stubs/tokenami.config.ts +175 -0
- package/stubs/tokenami.env-custom.d.ts +9 -0
- package/stubs/tokenami.env.ci.d.ts +8 -0
- package/stubs/tokenami.env.d.ts +7 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1149 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import TrieSearch from 'trie-search';
|
|
4
|
+
import * as culori from 'culori';
|
|
5
|
+
import * as TokenamiConfig from '@tokenami/config';
|
|
6
|
+
import createJiti from 'jiti';
|
|
7
|
+
import { transform } from 'sucrase';
|
|
8
|
+
import * as pathe from 'pathe';
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
|
|
11
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
12
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
13
|
+
}) : x)(function(x) {
|
|
14
|
+
if (typeof require !== "undefined")
|
|
15
|
+
return require.apply(this, arguments);
|
|
16
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
+
});
|
|
18
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
19
|
+
var getDirname = () => path.dirname(getFilename());
|
|
20
|
+
var __dirname = /* @__PURE__ */ getDirname();
|
|
21
|
+
var __filename = /* @__PURE__ */ getFilename();
|
|
22
|
+
|
|
23
|
+
// src/supports.ts
|
|
24
|
+
var supportedLogical = {
|
|
25
|
+
"block-overflow": 1,
|
|
26
|
+
"block-size": 1,
|
|
27
|
+
"border-block": 1,
|
|
28
|
+
"border-block-end": 1,
|
|
29
|
+
"border-block-start": 1,
|
|
30
|
+
"border-block-color": 1,
|
|
31
|
+
"border-block-end-color": 1,
|
|
32
|
+
"border-block-end-style": 1,
|
|
33
|
+
"border-block-end-width": 1,
|
|
34
|
+
"border-block-start-color": 1,
|
|
35
|
+
"border-block-start-style": 1,
|
|
36
|
+
"border-block-start-width": 1,
|
|
37
|
+
"border-block-style": 1,
|
|
38
|
+
"border-block-width": 1,
|
|
39
|
+
"border-inline": 1,
|
|
40
|
+
"border-inline-end": 1,
|
|
41
|
+
"border-inline-start": 1,
|
|
42
|
+
"border-inline-color": 1,
|
|
43
|
+
"border-inline-end-color": 1,
|
|
44
|
+
"border-inline-end-style": 1,
|
|
45
|
+
"border-inline-end-width": 1,
|
|
46
|
+
"border-inline-start-color": 1,
|
|
47
|
+
"border-inline-start-style": 1,
|
|
48
|
+
"border-inline-start-width": 1,
|
|
49
|
+
"border-inline-style": 1,
|
|
50
|
+
"border-inline-width": 1,
|
|
51
|
+
"contain-intrinsic-block-size": 1,
|
|
52
|
+
"contain-intrinsic-inline-size": 1,
|
|
53
|
+
"inline-size": 1,
|
|
54
|
+
"inset-block": 1,
|
|
55
|
+
"inset-block-end": 1,
|
|
56
|
+
"inset-block-start": 1,
|
|
57
|
+
"inset-inline": 1,
|
|
58
|
+
"inset-inline-end": 1,
|
|
59
|
+
"inset-inline-start": 1,
|
|
60
|
+
"margin-block": 1,
|
|
61
|
+
"margin-block-end": 1,
|
|
62
|
+
"margin-block-start": 1,
|
|
63
|
+
"margin-inline": 1,
|
|
64
|
+
"margin-inline-end": 1,
|
|
65
|
+
"margin-inline-start": 1,
|
|
66
|
+
"max-block-size": 1,
|
|
67
|
+
"max-inline-size": 1,
|
|
68
|
+
"min-block-size": 1,
|
|
69
|
+
"min-inline-size": 1,
|
|
70
|
+
"overflow-block": 1,
|
|
71
|
+
"overflow-inline": 1,
|
|
72
|
+
"overscroll-behavior-block": 1,
|
|
73
|
+
"overscroll-behavior-inline": 1,
|
|
74
|
+
"padding-block": 1,
|
|
75
|
+
"padding-block-end": 1,
|
|
76
|
+
"padding-block-start": 1,
|
|
77
|
+
"padding-inline": 1,
|
|
78
|
+
"padding-inline-end": 1,
|
|
79
|
+
"padding-inline-start": 1,
|
|
80
|
+
"scroll-margin-block": 1,
|
|
81
|
+
"scroll-margin-block-end": 1,
|
|
82
|
+
"scroll-margin-block-start": 1,
|
|
83
|
+
"scroll-margin-inline": 1,
|
|
84
|
+
"scroll-margin-inline-end": 1,
|
|
85
|
+
"scroll-margin-inline-start": 1,
|
|
86
|
+
"scroll-padding-block": 1,
|
|
87
|
+
"scroll-padding-block-end": 1,
|
|
88
|
+
"scroll-padding-block-start": 1,
|
|
89
|
+
"scroll-padding-inline": 1,
|
|
90
|
+
"scroll-padding-inline-end": 1,
|
|
91
|
+
"scroll-padding-inline-start": 1
|
|
92
|
+
};
|
|
93
|
+
var supported = {
|
|
94
|
+
all: 1,
|
|
95
|
+
animation: 1,
|
|
96
|
+
"animation-range": 1,
|
|
97
|
+
background: 1,
|
|
98
|
+
"background-position": 1,
|
|
99
|
+
border: 1,
|
|
100
|
+
"border-bottom": 1,
|
|
101
|
+
"border-color": 1,
|
|
102
|
+
"border-image": 1,
|
|
103
|
+
"border-left": 1,
|
|
104
|
+
"border-radius": 1,
|
|
105
|
+
"border-right": 1,
|
|
106
|
+
"border-style": 1,
|
|
107
|
+
"border-top": 1,
|
|
108
|
+
"border-width": 1,
|
|
109
|
+
caret: 1,
|
|
110
|
+
"column-rule": 1,
|
|
111
|
+
columns: 1,
|
|
112
|
+
"contain-intrinsic-size": 1,
|
|
113
|
+
container: 1,
|
|
114
|
+
flex: 1,
|
|
115
|
+
"flex-flow": 1,
|
|
116
|
+
font: 1,
|
|
117
|
+
gap: 1,
|
|
118
|
+
grid: 1,
|
|
119
|
+
"grid-area": 1,
|
|
120
|
+
"grid-column": 1,
|
|
121
|
+
"grid-row": 1,
|
|
122
|
+
"grid-template": 1,
|
|
123
|
+
inset: 1,
|
|
124
|
+
"line-clamp": 1,
|
|
125
|
+
"list-style": 1,
|
|
126
|
+
margin: 1,
|
|
127
|
+
mask: 1,
|
|
128
|
+
"mask-border": 1,
|
|
129
|
+
motion: 1,
|
|
130
|
+
offset: 1,
|
|
131
|
+
outline: 1,
|
|
132
|
+
overflow: 1,
|
|
133
|
+
"overscroll-behavior": 1,
|
|
134
|
+
padding: 1,
|
|
135
|
+
"place-content": 1,
|
|
136
|
+
"place-items": 1,
|
|
137
|
+
"place-self": 1,
|
|
138
|
+
"scroll-margin": 1,
|
|
139
|
+
"scroll-padding": 1,
|
|
140
|
+
"scroll-snap-margin": 1,
|
|
141
|
+
"scroll-timeline": 1,
|
|
142
|
+
"text-decoration": 1,
|
|
143
|
+
"text-emphasis": 1,
|
|
144
|
+
transition: 1,
|
|
145
|
+
"view-timeline": 1,
|
|
146
|
+
"accent-color": 1,
|
|
147
|
+
"align-content": 1,
|
|
148
|
+
"align-items": 1,
|
|
149
|
+
"align-self": 1,
|
|
150
|
+
"align-tracks": 1,
|
|
151
|
+
"animation-composition": 1,
|
|
152
|
+
"animation-delay": 1,
|
|
153
|
+
"animation-direction": 1,
|
|
154
|
+
"animation-duration": 1,
|
|
155
|
+
"animation-fill-mode": 1,
|
|
156
|
+
"animation-iteration-count": 1,
|
|
157
|
+
"animation-name": 1,
|
|
158
|
+
"animation-play-state": 1,
|
|
159
|
+
"animation-range-end": 1,
|
|
160
|
+
"animation-range-start": 1,
|
|
161
|
+
"animation-timeline": 1,
|
|
162
|
+
"animation-timing-function": 1,
|
|
163
|
+
appearance: 1,
|
|
164
|
+
"aspect-ratio": 1,
|
|
165
|
+
"backdrop-filter": 1,
|
|
166
|
+
"backface-visibility": 1,
|
|
167
|
+
"background-attachment": 1,
|
|
168
|
+
"background-blend-mode": 1,
|
|
169
|
+
"background-clip": 1,
|
|
170
|
+
"background-color": 1,
|
|
171
|
+
"background-image": 1,
|
|
172
|
+
"background-origin": 1,
|
|
173
|
+
"background-position-x": 1,
|
|
174
|
+
"background-position-y": 1,
|
|
175
|
+
"background-repeat": 1,
|
|
176
|
+
"background-size": 1,
|
|
177
|
+
"border-bottom-color": 1,
|
|
178
|
+
"border-bottom-left-radius": 1,
|
|
179
|
+
"border-bottom-right-radius": 1,
|
|
180
|
+
"border-bottom-style": 1,
|
|
181
|
+
"border-bottom-width": 1,
|
|
182
|
+
"border-collapse": 1,
|
|
183
|
+
"border-end-end-radius": 1,
|
|
184
|
+
"border-end-start-radius": 1,
|
|
185
|
+
"border-image-outset": 1,
|
|
186
|
+
"border-image-repeat": 1,
|
|
187
|
+
"border-image-slice": 1,
|
|
188
|
+
"border-image-source": 1,
|
|
189
|
+
"border-image-width": 1,
|
|
190
|
+
"border-left-color": 1,
|
|
191
|
+
"border-left-style": 1,
|
|
192
|
+
"border-left-width": 1,
|
|
193
|
+
"border-right-color": 1,
|
|
194
|
+
"border-right-style": 1,
|
|
195
|
+
"border-right-width": 1,
|
|
196
|
+
"border-spacing": 1,
|
|
197
|
+
"border-start-end-radius": 1,
|
|
198
|
+
"border-start-start-radius": 1,
|
|
199
|
+
"border-top-color": 1,
|
|
200
|
+
"border-top-left-radius": 1,
|
|
201
|
+
"border-top-right-radius": 1,
|
|
202
|
+
"border-top-style": 1,
|
|
203
|
+
"border-top-width": 1,
|
|
204
|
+
bottom: 1,
|
|
205
|
+
"box-decoration-break": 1,
|
|
206
|
+
"box-shadow": 1,
|
|
207
|
+
"box-sizing": 1,
|
|
208
|
+
"break-after": 1,
|
|
209
|
+
"break-before": 1,
|
|
210
|
+
"break-inside": 1,
|
|
211
|
+
"caption-side": 1,
|
|
212
|
+
"caret-color": 1,
|
|
213
|
+
"caret-shape": 1,
|
|
214
|
+
clear: 1,
|
|
215
|
+
"clip-path": 1,
|
|
216
|
+
color: 1,
|
|
217
|
+
"color-adjust": 1,
|
|
218
|
+
"color-scheme": 1,
|
|
219
|
+
"column-count": 1,
|
|
220
|
+
"column-fill": 1,
|
|
221
|
+
"column-gap": 1,
|
|
222
|
+
"column-rule-color": 1,
|
|
223
|
+
"column-rule-style": 1,
|
|
224
|
+
"column-rule-width": 1,
|
|
225
|
+
"column-span": 1,
|
|
226
|
+
"column-width": 1,
|
|
227
|
+
contain: 1,
|
|
228
|
+
"contain-intrinsic-height": 1,
|
|
229
|
+
"contain-intrinsic-width": 1,
|
|
230
|
+
"container-name": 1,
|
|
231
|
+
"container-type": 1,
|
|
232
|
+
content: 1,
|
|
233
|
+
"content-visibility": 1,
|
|
234
|
+
"counter-increment": 1,
|
|
235
|
+
"counter-reset": 1,
|
|
236
|
+
"counter-set": 1,
|
|
237
|
+
cursor: 1,
|
|
238
|
+
direction: 1,
|
|
239
|
+
display: 1,
|
|
240
|
+
"empty-cells": 1,
|
|
241
|
+
filter: 1,
|
|
242
|
+
"flex-basis": 1,
|
|
243
|
+
"flex-direction": 1,
|
|
244
|
+
"flex-grow": 1,
|
|
245
|
+
"flex-shrink": 1,
|
|
246
|
+
"flex-wrap": 1,
|
|
247
|
+
float: 1,
|
|
248
|
+
"font-family": 1,
|
|
249
|
+
"font-feature-settings": 1,
|
|
250
|
+
"font-kerning": 1,
|
|
251
|
+
"font-language-override": 1,
|
|
252
|
+
"font-optical-sizing": 1,
|
|
253
|
+
"font-palette": 1,
|
|
254
|
+
"font-size": 1,
|
|
255
|
+
"font-size-adjust": 1,
|
|
256
|
+
"font-smooth": 1,
|
|
257
|
+
"font-stretch": 1,
|
|
258
|
+
"font-style": 1,
|
|
259
|
+
"font-synthesis": 1,
|
|
260
|
+
"font-synthesis-position": 1,
|
|
261
|
+
"font-synthesis-small-caps": 1,
|
|
262
|
+
"font-synthesis-style": 1,
|
|
263
|
+
"font-synthesis-weight": 1,
|
|
264
|
+
"font-variant": 1,
|
|
265
|
+
"font-variant-alternates": 1,
|
|
266
|
+
"font-variant-caps": 1,
|
|
267
|
+
"font-variant-east-asian": 1,
|
|
268
|
+
"font-variant-emoji": 1,
|
|
269
|
+
"font-variant-ligatures": 1,
|
|
270
|
+
"font-variant-numeric": 1,
|
|
271
|
+
"font-variant-position": 1,
|
|
272
|
+
"font-variation-settings": 1,
|
|
273
|
+
"font-weight": 1,
|
|
274
|
+
"forced-color-adjust": 1,
|
|
275
|
+
"grid-auto-columns": 1,
|
|
276
|
+
"grid-auto-flow": 1,
|
|
277
|
+
"grid-auto-rows": 1,
|
|
278
|
+
"grid-column-end": 1,
|
|
279
|
+
"grid-column-start": 1,
|
|
280
|
+
"grid-row-end": 1,
|
|
281
|
+
"grid-row-start": 1,
|
|
282
|
+
"grid-template-areas": 1,
|
|
283
|
+
"grid-template-columns": 1,
|
|
284
|
+
"grid-template-rows": 1,
|
|
285
|
+
"hanging-punctuation": 1,
|
|
286
|
+
height: 1,
|
|
287
|
+
"hyphenate-character": 1,
|
|
288
|
+
"hyphenate-limit-chars": 1,
|
|
289
|
+
hyphens: 1,
|
|
290
|
+
"image-orientation": 1,
|
|
291
|
+
"image-rendering": 1,
|
|
292
|
+
"image-resolution": 1,
|
|
293
|
+
"initial-letter": 1,
|
|
294
|
+
"input-security": 1,
|
|
295
|
+
isolation: 1,
|
|
296
|
+
"justify-content": 1,
|
|
297
|
+
"justify-items": 1,
|
|
298
|
+
"justify-self": 1,
|
|
299
|
+
"justify-tracks": 1,
|
|
300
|
+
left: 1,
|
|
301
|
+
"letter-spacing": 1,
|
|
302
|
+
"line-break": 1,
|
|
303
|
+
"line-height": 1,
|
|
304
|
+
"line-height-step": 1,
|
|
305
|
+
"list-style-image": 1,
|
|
306
|
+
"list-style-position": 1,
|
|
307
|
+
"list-style-type": 1,
|
|
308
|
+
"margin-bottom": 1,
|
|
309
|
+
"margin-left": 1,
|
|
310
|
+
"margin-right": 1,
|
|
311
|
+
"margin-top": 1,
|
|
312
|
+
"margin-trim": 1,
|
|
313
|
+
"mask-border-mode": 1,
|
|
314
|
+
"mask-border-outset": 1,
|
|
315
|
+
"mask-border-repeat": 1,
|
|
316
|
+
"mask-border-slice": 1,
|
|
317
|
+
"mask-border-source": 1,
|
|
318
|
+
"mask-border-width": 1,
|
|
319
|
+
"mask-clip": 1,
|
|
320
|
+
"mask-composite": 1,
|
|
321
|
+
"mask-image": 1,
|
|
322
|
+
"mask-mode": 1,
|
|
323
|
+
"mask-origin": 1,
|
|
324
|
+
"mask-position": 1,
|
|
325
|
+
"mask-repeat": 1,
|
|
326
|
+
"mask-size": 1,
|
|
327
|
+
"mask-type": 1,
|
|
328
|
+
"masonry-auto-flow": 1,
|
|
329
|
+
"math-depth": 1,
|
|
330
|
+
"math-shift": 1,
|
|
331
|
+
"math-style": 1,
|
|
332
|
+
"max-height": 1,
|
|
333
|
+
"max-lines": 1,
|
|
334
|
+
"max-width": 1,
|
|
335
|
+
"min-height": 1,
|
|
336
|
+
"min-width": 1,
|
|
337
|
+
"mix-blend-mode": 1,
|
|
338
|
+
"motion-distance": 1,
|
|
339
|
+
"motion-path": 1,
|
|
340
|
+
"motion-rotation": 1,
|
|
341
|
+
"object-fit": 1,
|
|
342
|
+
"object-position": 1,
|
|
343
|
+
"offset-anchor": 1,
|
|
344
|
+
"offset-distance": 1,
|
|
345
|
+
"offset-path": 1,
|
|
346
|
+
"offset-position": 1,
|
|
347
|
+
"offset-rotate": 1,
|
|
348
|
+
"offset-rotation": 1,
|
|
349
|
+
opacity: 1,
|
|
350
|
+
order: 1,
|
|
351
|
+
orphans: 1,
|
|
352
|
+
"outline-color": 1,
|
|
353
|
+
"outline-offset": 1,
|
|
354
|
+
"outline-style": 1,
|
|
355
|
+
"outline-width": 1,
|
|
356
|
+
"overflow-anchor": 1,
|
|
357
|
+
"overflow-clip-box": 1,
|
|
358
|
+
"overflow-clip-margin": 1,
|
|
359
|
+
"overflow-wrap": 1,
|
|
360
|
+
"overflow-x": 1,
|
|
361
|
+
"overflow-y": 1,
|
|
362
|
+
overlay: 1,
|
|
363
|
+
"overscroll-behavior-x": 1,
|
|
364
|
+
"overscroll-behavior-y": 1,
|
|
365
|
+
"padding-bottom": 1,
|
|
366
|
+
"padding-left": 1,
|
|
367
|
+
"padding-right": 1,
|
|
368
|
+
"padding-top": 1,
|
|
369
|
+
page: 1,
|
|
370
|
+
"page-break-after": 1,
|
|
371
|
+
"page-break-before": 1,
|
|
372
|
+
"page-break-inside": 1,
|
|
373
|
+
"paint-order": 1,
|
|
374
|
+
perspective: 1,
|
|
375
|
+
"perspective-origin": 1,
|
|
376
|
+
"pointer-events": 1,
|
|
377
|
+
position: 1,
|
|
378
|
+
"print-color-adjust": 1,
|
|
379
|
+
quotes: 1,
|
|
380
|
+
resize: 1,
|
|
381
|
+
right: 1,
|
|
382
|
+
rotate: 1,
|
|
383
|
+
"row-gap": 1,
|
|
384
|
+
"ruby-align": 1,
|
|
385
|
+
"ruby-merge": 1,
|
|
386
|
+
"ruby-position": 1,
|
|
387
|
+
scale: 1,
|
|
388
|
+
"scroll-behavior": 1,
|
|
389
|
+
"scroll-margin-bottom": 1,
|
|
390
|
+
"scroll-margin-left": 1,
|
|
391
|
+
"scroll-margin-right": 1,
|
|
392
|
+
"scroll-margin-top": 1,
|
|
393
|
+
"scroll-padding-bottom": 1,
|
|
394
|
+
"scroll-padding-left": 1,
|
|
395
|
+
"scroll-padding-right": 1,
|
|
396
|
+
"scroll-padding-top": 1,
|
|
397
|
+
"scroll-snap-align": 1,
|
|
398
|
+
"scroll-snap-margin-bottom": 1,
|
|
399
|
+
"scroll-snap-margin-left": 1,
|
|
400
|
+
"scroll-snap-margin-right": 1,
|
|
401
|
+
"scroll-snap-margin-top": 1,
|
|
402
|
+
"scroll-snap-stop": 1,
|
|
403
|
+
"scroll-snap-type": 1,
|
|
404
|
+
"scroll-timeline-axis": 1,
|
|
405
|
+
"scroll-timeline-name": 1,
|
|
406
|
+
"scrollbar-color": 1,
|
|
407
|
+
"scrollbar-gutter": 1,
|
|
408
|
+
"scrollbar-width": 1,
|
|
409
|
+
"shape-image-threshold": 1,
|
|
410
|
+
"shape-margin": 1,
|
|
411
|
+
"shape-outside": 1,
|
|
412
|
+
"tab-size": 1,
|
|
413
|
+
"table-layout": 1,
|
|
414
|
+
"text-align": 1,
|
|
415
|
+
"text-align-last": 1,
|
|
416
|
+
"text-combine-upright": 1,
|
|
417
|
+
"text-decoration-color": 1,
|
|
418
|
+
"text-decoration-line": 1,
|
|
419
|
+
"text-decoration-skip": 1,
|
|
420
|
+
"text-decoration-skip-ink": 1,
|
|
421
|
+
"text-decoration-style": 1,
|
|
422
|
+
"text-decoration-thickness": 1,
|
|
423
|
+
"text-emphasis-color": 1,
|
|
424
|
+
"text-emphasis-position": 1,
|
|
425
|
+
"text-emphasis-style": 1,
|
|
426
|
+
"text-indent": 1,
|
|
427
|
+
"text-justify": 1,
|
|
428
|
+
"text-orientation": 1,
|
|
429
|
+
"text-overflow": 1,
|
|
430
|
+
"text-rendering": 1,
|
|
431
|
+
"text-shadow": 1,
|
|
432
|
+
"text-size-adjust": 1,
|
|
433
|
+
"text-transform": 1,
|
|
434
|
+
"text-underline-offset": 1,
|
|
435
|
+
"text-underline-position": 1,
|
|
436
|
+
"text-wrap": 1,
|
|
437
|
+
"timeline-scope": 1,
|
|
438
|
+
top: 1,
|
|
439
|
+
"touch-action": 1,
|
|
440
|
+
transform: 1,
|
|
441
|
+
"transform-box": 1,
|
|
442
|
+
"transform-origin": 1,
|
|
443
|
+
"transform-style": 1,
|
|
444
|
+
"transition-behavior": 1,
|
|
445
|
+
"transition-delay": 1,
|
|
446
|
+
"transition-duration": 1,
|
|
447
|
+
"transition-property": 1,
|
|
448
|
+
"transition-timing-function": 1,
|
|
449
|
+
translate: 1,
|
|
450
|
+
"unicode-bidi": 1,
|
|
451
|
+
"user-select": 1,
|
|
452
|
+
"vertical-align": 1,
|
|
453
|
+
"view-timeline-axis": 1,
|
|
454
|
+
"view-timeline-inset": 1,
|
|
455
|
+
"view-timeline-name": 1,
|
|
456
|
+
"view-transition-name": 1,
|
|
457
|
+
visibility: 1,
|
|
458
|
+
"white-space": 1,
|
|
459
|
+
"white-space-collapse": 1,
|
|
460
|
+
"white-space-trim": 1,
|
|
461
|
+
widows: 1,
|
|
462
|
+
width: 1,
|
|
463
|
+
"will-change": 1,
|
|
464
|
+
"word-break": 1,
|
|
465
|
+
"word-spacing": 1,
|
|
466
|
+
"word-wrap": 1,
|
|
467
|
+
"writing-mode": 1,
|
|
468
|
+
"z-index": 1,
|
|
469
|
+
zoom: 1,
|
|
470
|
+
"alignment-baseline": 1,
|
|
471
|
+
"baseline-shift": 1,
|
|
472
|
+
clip: 1,
|
|
473
|
+
"clip-rule": 1,
|
|
474
|
+
"color-interpolation": 1,
|
|
475
|
+
"color-rendering": 1,
|
|
476
|
+
"dominant-baseline": 1,
|
|
477
|
+
fill: 1,
|
|
478
|
+
"fill-opacity": 1,
|
|
479
|
+
"fill-rule": 1,
|
|
480
|
+
"flood-color": 1,
|
|
481
|
+
"flood-opacity": 1,
|
|
482
|
+
"glyph-orientation-vertical": 1,
|
|
483
|
+
"lighting-color": 1,
|
|
484
|
+
marker: 1,
|
|
485
|
+
"marker-end": 1,
|
|
486
|
+
"marker-mid": 1,
|
|
487
|
+
"marker-start": 1,
|
|
488
|
+
"shape-rendering": 1,
|
|
489
|
+
"stop-color": 1,
|
|
490
|
+
"stop-opacity": 1,
|
|
491
|
+
stroke: 1,
|
|
492
|
+
"stroke-dasharray": 1,
|
|
493
|
+
"stroke-dashoffset": 1,
|
|
494
|
+
"stroke-linecap": 1,
|
|
495
|
+
"stroke-linejoin": 1,
|
|
496
|
+
"stroke-miterlimit": 1,
|
|
497
|
+
"stroke-opacity": 1,
|
|
498
|
+
"stroke-width": 1,
|
|
499
|
+
"text-anchor": 1,
|
|
500
|
+
"vector-effect": 1,
|
|
501
|
+
...supportedLogical
|
|
502
|
+
};
|
|
503
|
+
var supportedProperties = new Set(Object.keys(supported));
|
|
504
|
+
new Set(Object.keys(supportedLogical));
|
|
505
|
+
|
|
506
|
+
// src/utils.ts
|
|
507
|
+
var DEFAULT_PATHS = {
|
|
508
|
+
js: "./.tokenami/tokenami.config.js",
|
|
509
|
+
ts: "./.tokenami/tokenami.config.ts",
|
|
510
|
+
cjs: "./.tokenami/tokenami.config.cjs",
|
|
511
|
+
mjs: "./.tokenami/tokenami.config.mjs"
|
|
512
|
+
};
|
|
513
|
+
function getConfigPath(cwd, path2, type) {
|
|
514
|
+
path2 = path2 || getConfigDefaultPath(cwd, type);
|
|
515
|
+
return pathe.join(cwd, path2);
|
|
516
|
+
}
|
|
517
|
+
function getConfigAtPath(path2) {
|
|
518
|
+
const config = function() {
|
|
519
|
+
try {
|
|
520
|
+
return __require(path2);
|
|
521
|
+
} catch {
|
|
522
|
+
return lazyJiti()(path2);
|
|
523
|
+
}
|
|
524
|
+
}();
|
|
525
|
+
return mergedConfigs(config.default ?? config);
|
|
526
|
+
}
|
|
527
|
+
function getReloadedConfigAtPath(path2) {
|
|
528
|
+
const config = function() {
|
|
529
|
+
try {
|
|
530
|
+
delete __require.cache[__require.resolve(path2)];
|
|
531
|
+
return __require(path2);
|
|
532
|
+
} catch {
|
|
533
|
+
return lazyJiti({ cache: false })(path2);
|
|
534
|
+
}
|
|
535
|
+
}();
|
|
536
|
+
return mergedConfigs(config.default ?? config);
|
|
537
|
+
}
|
|
538
|
+
function getConfigDefaultPath(cwd, type) {
|
|
539
|
+
const existingConfig = Object.values(DEFAULT_PATHS).find((path2) => {
|
|
540
|
+
return fs.existsSync(pathe.join(cwd, path2));
|
|
541
|
+
});
|
|
542
|
+
return existingConfig || DEFAULT_PATHS[type || "js"];
|
|
543
|
+
}
|
|
544
|
+
function getTypeDefsPath(configPath) {
|
|
545
|
+
const dirname2 = pathe.dirname(configPath);
|
|
546
|
+
return `${dirname2}/tokenami.env.d.ts`;
|
|
547
|
+
}
|
|
548
|
+
function getCiTypeDefsPath(configPath) {
|
|
549
|
+
const dirname2 = pathe.dirname(configPath);
|
|
550
|
+
return `${dirname2}/tokenami.env.ci.d.ts`;
|
|
551
|
+
}
|
|
552
|
+
function getThemeFromConfig(themeConfig) {
|
|
553
|
+
const { modes = {}, root, ...base } = themeConfig;
|
|
554
|
+
if ("modes" in themeConfig) {
|
|
555
|
+
const config = themeConfig;
|
|
556
|
+
return { modes: config.modes, root: config.root };
|
|
557
|
+
}
|
|
558
|
+
return { modes: {}, root: base };
|
|
559
|
+
}
|
|
560
|
+
function getThemeValuesByThemeMode(tokenValue, themeConfig) {
|
|
561
|
+
const theme = getThemeFromConfig(themeConfig);
|
|
562
|
+
const parts = TokenamiConfig.getTokenValueParts(tokenValue);
|
|
563
|
+
const modeThemeEntries = Object.entries(theme.modes);
|
|
564
|
+
const modeValues = modeThemeEntries.concat([["root", theme.root]]).flatMap(([mode, theme2]) => {
|
|
565
|
+
const value = theme2[parts.themeKey]?.[parts.token];
|
|
566
|
+
return value == null ? [] : [[mode, String(value)]];
|
|
567
|
+
});
|
|
568
|
+
return Object.fromEntries(modeValues);
|
|
569
|
+
}
|
|
570
|
+
function mergedConfigs(theirs) {
|
|
571
|
+
return theirs;
|
|
572
|
+
}
|
|
573
|
+
function generateTypeDefs(configPath, stubPath = "../stubs/tokenami.env.d.ts") {
|
|
574
|
+
const parsed = pathe.parse(configPath);
|
|
575
|
+
const typeDefStubPath = pathe.resolve(__dirname, stubPath);
|
|
576
|
+
const typeDefStub = fs.readFileSync(typeDefStubPath, "utf8");
|
|
577
|
+
return typeDefStub.replace("tokenami.config", parsed.name);
|
|
578
|
+
}
|
|
579
|
+
function generateCiTypeDefs(configPath) {
|
|
580
|
+
return generateTypeDefs(configPath, "../stubs/tokenami.env.ci.d.ts");
|
|
581
|
+
}
|
|
582
|
+
function getValidProperties(config) {
|
|
583
|
+
return /* @__PURE__ */ new Set([
|
|
584
|
+
...supportedProperties,
|
|
585
|
+
...Object.keys(config.properties || {}),
|
|
586
|
+
...Object.keys(config.customProperties || {}),
|
|
587
|
+
...Object.keys(config.aliases || {})
|
|
588
|
+
]);
|
|
589
|
+
}
|
|
590
|
+
var jitiCache = {};
|
|
591
|
+
function lazyJiti(options = {}) {
|
|
592
|
+
const cacheId = JSON.stringify(options);
|
|
593
|
+
return jitiCache[cacheId] ??= createJiti(__filename, {
|
|
594
|
+
transform: (opts) => transform(opts.source, { transforms: ["typescript", "imports"] }),
|
|
595
|
+
interopDefault: true,
|
|
596
|
+
requireCache: options.cache
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/ts-plugin.ts
|
|
601
|
+
var INVALID_PROPERTY_ERROR_CODE = 2353;
|
|
602
|
+
var INVALID_VALUE_ERROR_CODE = 2322;
|
|
603
|
+
function createTSPlugin(modules) {
|
|
604
|
+
const ts = modules.typescript;
|
|
605
|
+
let entryConfigMap = /* @__PURE__ */ new Map();
|
|
606
|
+
function getAllProperties(config) {
|
|
607
|
+
return Array.from(getValidProperties(config));
|
|
608
|
+
}
|
|
609
|
+
function getSelectorEntries(config) {
|
|
610
|
+
const configSelectorEntries = Object.entries(config.selectors || {});
|
|
611
|
+
return configSelectorEntries.concat([["{}", ""]]);
|
|
612
|
+
}
|
|
613
|
+
function getResponsiveEntries(config) {
|
|
614
|
+
return Object.entries(config.responsive || {});
|
|
615
|
+
}
|
|
616
|
+
function getResponsiveSelectorEntries(config) {
|
|
617
|
+
const selectorEntries = getSelectorEntries(config);
|
|
618
|
+
const responsiveEntries = getResponsiveEntries(config);
|
|
619
|
+
const responsiveSelectorEntries = responsiveEntries.flatMap(
|
|
620
|
+
([responsiveSelector, responsiveValue]) => {
|
|
621
|
+
return selectorEntries.map(([selector, value]) => {
|
|
622
|
+
const combinedSelector = `${responsiveSelector}_${selector}`;
|
|
623
|
+
const combinedValue = [responsiveValue].concat(value);
|
|
624
|
+
return [combinedSelector, combinedValue];
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
);
|
|
628
|
+
return responsiveSelectorEntries;
|
|
629
|
+
}
|
|
630
|
+
function getSelectorCompletions(config, quote) {
|
|
631
|
+
const entries = getSelectorEntries(config).concat(getResponsiveEntries(config));
|
|
632
|
+
const properties = getAllProperties(config);
|
|
633
|
+
return properties.flatMap((property) => {
|
|
634
|
+
const create2 = createVariantPropertyEntry(property, quote);
|
|
635
|
+
return entries.map(create2);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
function getResponsiveSelectorCompletions(config, quote) {
|
|
639
|
+
const entries = getResponsiveSelectorEntries(config);
|
|
640
|
+
const properties = getAllProperties(config);
|
|
641
|
+
return properties.flatMap((property) => {
|
|
642
|
+
const create2 = createVariantPropertyEntry(property, quote);
|
|
643
|
+
return entries.map(create2);
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function getSelectorSnippetCompletions(config, quote) {
|
|
647
|
+
const entries = getSelectorEntries(config).concat(getResponsiveEntries(config));
|
|
648
|
+
const create2 = createVariantPropertyEntry("", quote);
|
|
649
|
+
return entries.map(create2);
|
|
650
|
+
}
|
|
651
|
+
function getResponsiveSelectorSnippetCompletions(config, quote) {
|
|
652
|
+
const entries = getResponsiveSelectorEntries(config);
|
|
653
|
+
const create2 = createVariantPropertyEntry("", quote);
|
|
654
|
+
return entries.map(create2);
|
|
655
|
+
}
|
|
656
|
+
const createSelectorSnippetTrie = (config) => {
|
|
657
|
+
const completions = getSelectorSnippetCompletions(config);
|
|
658
|
+
const quotedCompletions = getSelectorSnippetCompletions(config, '"');
|
|
659
|
+
return {
|
|
660
|
+
unquoted: createCompletionEntriesTrie(completions),
|
|
661
|
+
quoted: createCompletionEntriesTrie(quotedCompletions)
|
|
662
|
+
};
|
|
663
|
+
};
|
|
664
|
+
const createResponsiveSelectorSnippetTrie = (config) => {
|
|
665
|
+
const completions = getResponsiveSelectorSnippetCompletions(config);
|
|
666
|
+
const quotedCompletions = getResponsiveSelectorSnippetCompletions(config, '"');
|
|
667
|
+
return {
|
|
668
|
+
unquoted: createCompletionEntriesTrie(completions),
|
|
669
|
+
quoted: createCompletionEntriesTrie(quotedCompletions)
|
|
670
|
+
};
|
|
671
|
+
};
|
|
672
|
+
const createSelectorTrie = (config) => {
|
|
673
|
+
const completions = getSelectorCompletions(config);
|
|
674
|
+
const quotedCompletions = getSelectorCompletions(config, '"');
|
|
675
|
+
return {
|
|
676
|
+
unquoted: createCompletionEntriesTrie(completions),
|
|
677
|
+
quoted: createCompletionEntriesTrie(quotedCompletions)
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
const createResponsiveSelectorTrie = (config) => {
|
|
681
|
+
const completions = getResponsiveSelectorCompletions(config);
|
|
682
|
+
const quotedCompletions = getResponsiveSelectorCompletions(config, '"');
|
|
683
|
+
return {
|
|
684
|
+
unquoted: createCompletionEntriesTrie(completions),
|
|
685
|
+
quoted: createCompletionEntriesTrie(quotedCompletions)
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
const createCompletionEntriesTrie = (items) => {
|
|
689
|
+
const trie = new TrieSearch("sortText", {
|
|
690
|
+
splitOnRegEx: /\$/g,
|
|
691
|
+
expandRegexes: []
|
|
692
|
+
});
|
|
693
|
+
trie.addAll(items);
|
|
694
|
+
return trie;
|
|
695
|
+
};
|
|
696
|
+
const createVariantPropertyEntry = (property, quote = "") => {
|
|
697
|
+
return ([selector, value]) => {
|
|
698
|
+
const tokenProperty2 = TokenamiConfig.variantProperty(selector, property);
|
|
699
|
+
const name = `${quote}${tokenProperty2}${quote}`;
|
|
700
|
+
const isSnippet = name.includes("{}");
|
|
701
|
+
const entry = isSnippet ? createPropertySnippetEntry(name) : createPropertyEntry(name);
|
|
702
|
+
updateEntryDetailsConfig({ ...entry, value });
|
|
703
|
+
return entry;
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
const createPropertyEntry = (name, sortText = getSortText(name)) => {
|
|
707
|
+
const kind = ts.ScriptElementKind.memberVariableElement;
|
|
708
|
+
const kindModifiers = ts.ScriptElementKindModifier.optionalModifier;
|
|
709
|
+
return { name, kind, kindModifiers, sortText, insertText: name };
|
|
710
|
+
};
|
|
711
|
+
const createPropertySnippetEntry = (name, sortText = getSortText(name)) => {
|
|
712
|
+
const entry = createPropertyEntry(name, sortText);
|
|
713
|
+
const insertText = entry.name.replace("{}", "{${1}}");
|
|
714
|
+
return { ...entry, insertText, isSnippet: true };
|
|
715
|
+
};
|
|
716
|
+
const getSortText = (name) => {
|
|
717
|
+
const regex = new RegExp(`['"-]|${TokenamiConfig.tokenProperty("")}`, "g");
|
|
718
|
+
name = name.replace(regex, "").replace(/[0-9]+/g, (m) => m.padStart(6, "0"));
|
|
719
|
+
return `$${name}`;
|
|
720
|
+
};
|
|
721
|
+
function updateEntryDetailsConfig(params) {
|
|
722
|
+
const { name, ...config } = params;
|
|
723
|
+
entryConfigMap.set(params.name, config);
|
|
724
|
+
}
|
|
725
|
+
function getEntryDetailsConfig(name) {
|
|
726
|
+
return entryConfigMap.get(name);
|
|
727
|
+
}
|
|
728
|
+
function getBaseResults(entries, search) {
|
|
729
|
+
const baseTrie = createCompletionEntriesTrie(entries);
|
|
730
|
+
return baseTrie.search(search);
|
|
731
|
+
}
|
|
732
|
+
function isQuoted(node) {
|
|
733
|
+
return ts.isStringLiteral(node);
|
|
734
|
+
}
|
|
735
|
+
function findNodeAtPosition(sourceFile, position) {
|
|
736
|
+
function find(node) {
|
|
737
|
+
if (position >= node.getStart(sourceFile) && position < node.getEnd()) {
|
|
738
|
+
return ts.forEachChild(node, find) || node;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return find(sourceFile);
|
|
742
|
+
}
|
|
743
|
+
const getInputAtPosition = (node, position) => {
|
|
744
|
+
let input = node.getText();
|
|
745
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
746
|
+
for (const property of node.properties) {
|
|
747
|
+
const start = property.getStart();
|
|
748
|
+
const end = property.getEnd();
|
|
749
|
+
if (start <= position && position <= end) {
|
|
750
|
+
input = property.getText();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return input.replace(/'|"/g, "");
|
|
755
|
+
};
|
|
756
|
+
function createTextSpanFromNode(node) {
|
|
757
|
+
return { start: node.getStart(), length: node.getEnd() - node.getStart() };
|
|
758
|
+
}
|
|
759
|
+
function shouldSuppressDiagnosticForNode(node, sourceFile) {
|
|
760
|
+
const lineStarts = sourceFile.getLineStarts();
|
|
761
|
+
const nodeStartPos = node.getStart(sourceFile);
|
|
762
|
+
const nodeStartLine = sourceFile.getLineAndCharacterOfPosition(nodeStartPos).line;
|
|
763
|
+
if (nodeStartLine > 0) {
|
|
764
|
+
const previousLineStartPos = lineStarts[nodeStartLine - 1] || 0;
|
|
765
|
+
const previousLineEndPos = lineStarts[nodeStartLine] || 0;
|
|
766
|
+
const previousLineText = sourceFile.text.substring(previousLineStartPos, previousLineEndPos);
|
|
767
|
+
return /\/\/ @ts-ignore/.test(previousLineText);
|
|
768
|
+
}
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
function transformBasePropertyEntry(entry) {
|
|
772
|
+
const property = TokenamiConfig.TokenProperty.safeParse(entry.name);
|
|
773
|
+
if (!property.success)
|
|
774
|
+
return null;
|
|
775
|
+
const sortText = `$${getSortText(entry.name)}`;
|
|
776
|
+
return { ...entry, sortText, insertText: entry.name };
|
|
777
|
+
}
|
|
778
|
+
function transformTokenValueEntry(entry, config) {
|
|
779
|
+
const entryName = entry.name;
|
|
780
|
+
const property = TokenamiConfig.TokenValue.safeParse(entryName);
|
|
781
|
+
if (!property.success)
|
|
782
|
+
return entry;
|
|
783
|
+
const parts = TokenamiConfig.getTokenValueParts(property.output);
|
|
784
|
+
const modeValues = getThemeValuesByThemeMode(property.output, config.theme);
|
|
785
|
+
if (!Object.entries(modeValues).length)
|
|
786
|
+
return entry;
|
|
787
|
+
const name = `$${parts.token}`;
|
|
788
|
+
const kindModifiers = isColorThemeEntry(modeValues) ? "color" : parts.themeKey;
|
|
789
|
+
const tokenIndex = getTokenValueIndexFromTheme(property.output, config.theme);
|
|
790
|
+
const sortText = getSortText(`${tokenIndex}${entryName}`);
|
|
791
|
+
const labelDetails = { detail: "", description: entryName };
|
|
792
|
+
const insertText = entryName;
|
|
793
|
+
const nextEntry = { ...entry, name, sortText, kindModifiers, insertText, labelDetails };
|
|
794
|
+
updateEntryDetailsConfig({ ...nextEntry, themeKey: parts.themeKey, modeValues });
|
|
795
|
+
return nextEntry;
|
|
796
|
+
}
|
|
797
|
+
function getTokenValueIndexFromTheme(tokenValue, themeConfig) {
|
|
798
|
+
const theme = getThemeFromConfig(themeConfig);
|
|
799
|
+
const parts = TokenamiConfig.getTokenValueParts(tokenValue);
|
|
800
|
+
const modeKey = Object.keys(theme.modes)[0];
|
|
801
|
+
const modeTheme = modeKey && theme.modes[modeKey];
|
|
802
|
+
const flattenedTheme = { ...theme.root, ...modeTheme };
|
|
803
|
+
const tokenNames = Object.keys(flattenedTheme[parts.themeKey]);
|
|
804
|
+
return tokenNames.indexOf(parts.token);
|
|
805
|
+
}
|
|
806
|
+
function updateEnvFile(configPath, config) {
|
|
807
|
+
const envFilePath = getTypeDefsPath(configPath);
|
|
808
|
+
const ciEnvFilePath = getCiTypeDefsPath(configPath);
|
|
809
|
+
const envFileContent = ts.sys.readFile(envFilePath, "utf-8");
|
|
810
|
+
if (!envFileContent)
|
|
811
|
+
throw new Error("Cannot read tokenami.env.d.ts file");
|
|
812
|
+
const properties = Object.keys(config.properties || {});
|
|
813
|
+
const customProperties = Object.keys(config.customProperties || {});
|
|
814
|
+
const experimentalProperties = properties.flatMap((property) => {
|
|
815
|
+
if (supportedProperties.has(property))
|
|
816
|
+
return [];
|
|
817
|
+
return [property];
|
|
818
|
+
});
|
|
819
|
+
const customPropertyTypes = [...experimentalProperties, ...customProperties].map((property) => {
|
|
820
|
+
return [`TokenProperties<'${property}'>`];
|
|
821
|
+
});
|
|
822
|
+
const updatedEnvFileContent = !customProperties.length ? generateTypeDefs(configPath, "../stubs/tokenami.env.d.ts") : generateTypeDefs(configPath, "../stubs/tokenami.env-custom.d.ts").replace(
|
|
823
|
+
"interface TokenamiProperties {",
|
|
824
|
+
`interface TokenamiProperties extends ${customPropertyTypes.join(", ")} {`
|
|
825
|
+
);
|
|
826
|
+
ts.sys.writeFile(envFilePath, updatedEnvFileContent);
|
|
827
|
+
if (ts.sys.readFile(ciEnvFilePath, "utf-8")) {
|
|
828
|
+
ts.sys.writeFile(ciEnvFilePath, generateCiTypeDefs(configPath));
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function create(info) {
|
|
832
|
+
const proxy = /* @__PURE__ */ Object.create(null);
|
|
833
|
+
for (let k of Object.keys(info.languageService)) {
|
|
834
|
+
const x = info.languageService[k];
|
|
835
|
+
proxy[k] = (...args) => x.apply(info.languageService, args);
|
|
836
|
+
}
|
|
837
|
+
const logger = info.project.projectService.logger;
|
|
838
|
+
const cwd = info.project.getCurrentDirectory();
|
|
839
|
+
const configPath = getConfigPath(cwd, info.config.configPath);
|
|
840
|
+
const configExists = ts.sys.fileExists(configPath);
|
|
841
|
+
if (!configExists) {
|
|
842
|
+
logger.info(`Tokenami:: Cannot find config at ${configPath}`);
|
|
843
|
+
return proxy;
|
|
844
|
+
}
|
|
845
|
+
let config = getConfigAtPath(configPath);
|
|
846
|
+
let selectorCompletions = createSelectorTrie(config);
|
|
847
|
+
let selectorSnippetCompletions = createSelectorSnippetTrie(config);
|
|
848
|
+
let responsiveSelectorCompletions = createResponsiveSelectorTrie(config);
|
|
849
|
+
let responsiveSelectorSnippetCompletions = createResponsiveSelectorSnippetTrie(config);
|
|
850
|
+
try {
|
|
851
|
+
updateEnvFile(configPath, config);
|
|
852
|
+
} catch (e) {
|
|
853
|
+
logger.info(`Tokenami:: Skipped typedefs update with ${e}`);
|
|
854
|
+
}
|
|
855
|
+
logger.info(`Tokenami:: Watching config at ${configPath}`);
|
|
856
|
+
ts.sys.watchFile?.(configPath, (_, eventKind) => {
|
|
857
|
+
if (eventKind === modules.typescript.FileWatcherEventKind.Changed) {
|
|
858
|
+
logger.info(`Tokenami:: Config changed at ${configPath}`);
|
|
859
|
+
try {
|
|
860
|
+
config = getReloadedConfigAtPath(configPath);
|
|
861
|
+
info.project.refreshDiagnostics();
|
|
862
|
+
selectorCompletions = createSelectorTrie(config);
|
|
863
|
+
selectorSnippetCompletions = createSelectorSnippetTrie(config);
|
|
864
|
+
responsiveSelectorCompletions = createResponsiveSelectorTrie(config);
|
|
865
|
+
responsiveSelectorSnippetCompletions = createResponsiveSelectorSnippetTrie(config);
|
|
866
|
+
updateEnvFile(configPath, config);
|
|
867
|
+
} catch (e) {
|
|
868
|
+
logger.info(`Tokenami:: Skipped change to ${configPath} with ${e}`);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
const getVariantResults = (input, search, node) => {
|
|
873
|
+
const parts = TokenamiConfig.getTokenPropertySplit(input);
|
|
874
|
+
const type = isQuoted(node) ? "unquoted" : "quoted";
|
|
875
|
+
if (parts.variants.length) {
|
|
876
|
+
if (parts.variants.length > 1) {
|
|
877
|
+
return responsiveSelectorCompletions[type].search(search);
|
|
878
|
+
}
|
|
879
|
+
const selectors = selectorCompletions[type].search(search);
|
|
880
|
+
const snippets = responsiveSelectorSnippetCompletions[type].search(search);
|
|
881
|
+
return [...selectors, ...snippets];
|
|
882
|
+
}
|
|
883
|
+
return selectorSnippetCompletions[type].search(search);
|
|
884
|
+
};
|
|
885
|
+
proxy.getSemanticDiagnostics = (fileName) => {
|
|
886
|
+
const diagnostics = info.languageService.getSemanticDiagnostics(fileName);
|
|
887
|
+
const program = info.languageService.getProgram();
|
|
888
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
889
|
+
const findDiagnosticIndex = (code, node) => {
|
|
890
|
+
return diagnostics.findIndex((diagnostic) => {
|
|
891
|
+
const isCodeMatch = diagnostic.code === code;
|
|
892
|
+
const isCurrentNode = diagnostic.start === node.getStart();
|
|
893
|
+
return isCodeMatch && isCurrentNode;
|
|
894
|
+
});
|
|
895
|
+
};
|
|
896
|
+
const updateDiagnosticMessage = (index, messageText) => {
|
|
897
|
+
if (index === -1)
|
|
898
|
+
return;
|
|
899
|
+
diagnostics[index] = { ...diagnostics[index], messageText };
|
|
900
|
+
};
|
|
901
|
+
const processNode = (node) => {
|
|
902
|
+
const isDiagnosticPrevented = shouldSuppressDiagnosticForNode(node, sourceFile);
|
|
903
|
+
if (isDiagnosticPrevented || !ts.isPropertyAssignment(node))
|
|
904
|
+
return;
|
|
905
|
+
const nodeProperty = ts.isStringLiteral(node.name) ? node.name.text : null;
|
|
906
|
+
const property = TokenamiConfig.TokenProperty.safeParse(nodeProperty);
|
|
907
|
+
if (!property.success)
|
|
908
|
+
return;
|
|
909
|
+
const { variants } = TokenamiConfig.getTokenPropertySplit(property.output);
|
|
910
|
+
const parts = TokenamiConfig.getTokenPropertyParts(property.output, config);
|
|
911
|
+
const invalidValueIndex = findDiagnosticIndex(INVALID_VALUE_ERROR_CODE, node);
|
|
912
|
+
const isArbitrarySelector = variants.some(TokenamiConfig.getArbitrarySelector);
|
|
913
|
+
if (variants.length && !parts && !isArbitrarySelector) {
|
|
914
|
+
const selector = variants.join("_");
|
|
915
|
+
const isEmptyArbitrarySelector = variants.includes("{}");
|
|
916
|
+
const message = `Tokenami properties may only specify known selectors, and '${selector}' does not exist.${isEmptyArbitrarySelector ? ` Add an arbitrary selector or remove '${selector}'.` : ""}`;
|
|
917
|
+
diagnostics.push({
|
|
918
|
+
file: sourceFile,
|
|
919
|
+
start: node.getStart(),
|
|
920
|
+
length: node.name.getWidth(),
|
|
921
|
+
messageText: message,
|
|
922
|
+
category: ts.DiagnosticCategory.Error,
|
|
923
|
+
code: INVALID_PROPERTY_ERROR_CODE
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
if (invalidValueIndex > -1 && ts.isStringLiteral(node.initializer)) {
|
|
927
|
+
const value = node.initializer.text;
|
|
928
|
+
const arbitraryValue2 = TokenamiConfig.arbitraryValue(value);
|
|
929
|
+
const message = `Value '${value}' is not assignable to Tokenami property '${property.output}'. Use value from theme or mark arbitrary with '${arbitraryValue2}'.`;
|
|
930
|
+
updateDiagnosticMessage(invalidValueIndex, message);
|
|
931
|
+
}
|
|
932
|
+
if (invalidValueIndex > -1 && ts.isNumericLiteral(node.initializer)) {
|
|
933
|
+
const message = `Tokenami grid values are not assignable to '${property.output}'.`;
|
|
934
|
+
updateDiagnosticMessage(invalidValueIndex, message);
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
if (sourceFile) {
|
|
938
|
+
ts.forEachChild(sourceFile, function nextNode(node) {
|
|
939
|
+
processNode(node);
|
|
940
|
+
ts.forEachChild(node, nextNode);
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
return diagnostics;
|
|
944
|
+
};
|
|
945
|
+
proxy.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
|
|
946
|
+
const original = info.languageService.getCodeFixesAtPosition(
|
|
947
|
+
fileName,
|
|
948
|
+
start,
|
|
949
|
+
end,
|
|
950
|
+
errorCodes,
|
|
951
|
+
formatOptions,
|
|
952
|
+
preferences
|
|
953
|
+
);
|
|
954
|
+
if (!errorCodes.includes(INVALID_VALUE_ERROR_CODE))
|
|
955
|
+
return original;
|
|
956
|
+
const program = info.languageService.getProgram();
|
|
957
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
958
|
+
if (!sourceFile)
|
|
959
|
+
return original;
|
|
960
|
+
const node = findNodeAtPosition(sourceFile, start);
|
|
961
|
+
if (!node?.parent || !ts.isPropertyAssignment(node.parent))
|
|
962
|
+
return original;
|
|
963
|
+
const assignment = node.parent;
|
|
964
|
+
const valueSpan = createTextSpanFromNode(assignment.initializer);
|
|
965
|
+
const value = ts.isStringLiteral(assignment.initializer) && assignment.initializer.text;
|
|
966
|
+
if (!value)
|
|
967
|
+
return original;
|
|
968
|
+
const quoteMark = assignment.initializer.getText().slice(-1);
|
|
969
|
+
const arbitraryValue2 = TokenamiConfig.arbitraryValue(value);
|
|
970
|
+
const arbitraryText = `${quoteMark}${arbitraryValue2}${quoteMark}`;
|
|
971
|
+
return [
|
|
972
|
+
{
|
|
973
|
+
description: `Use ${arbitraryText} to mark as arbitrary`,
|
|
974
|
+
fixName: "replaceWithArbitrary",
|
|
975
|
+
changes: [
|
|
976
|
+
{
|
|
977
|
+
fileName,
|
|
978
|
+
textChanges: [{ span: valueSpan, newText: arbitraryText }]
|
|
979
|
+
}
|
|
980
|
+
]
|
|
981
|
+
}
|
|
982
|
+
];
|
|
983
|
+
};
|
|
984
|
+
proxy.getCompletionsAtPosition = (fileName, position, options) => {
|
|
985
|
+
const original = info.languageService.getCompletionsAtPosition(fileName, position, options);
|
|
986
|
+
const program = info.languageService.getProgram();
|
|
987
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
988
|
+
if (!original || !sourceFile)
|
|
989
|
+
return;
|
|
990
|
+
const isTokenPropertyEntries = original.entries.some(
|
|
991
|
+
(entry) => TokenamiConfig.TokenProperty.safeParse(entry.name).success
|
|
992
|
+
);
|
|
993
|
+
const isTokenValueEntries = original.entries.some(
|
|
994
|
+
(entry) => TokenamiConfig.TokenValue.safeParse(entry.name).success
|
|
995
|
+
);
|
|
996
|
+
if (isTokenValueEntries) {
|
|
997
|
+
original.entries = original.entries.map((entry) => transformTokenValueEntry(entry, config));
|
|
998
|
+
} else if (isTokenPropertyEntries) {
|
|
999
|
+
const node = findNodeAtPosition(sourceFile, position);
|
|
1000
|
+
if (!node)
|
|
1001
|
+
return;
|
|
1002
|
+
const input = getInputAtPosition(node, position);
|
|
1003
|
+
const search = getSortText(input).replace("$", "");
|
|
1004
|
+
const entries = original.entries.flatMap((entry) => {
|
|
1005
|
+
const transformedEntry = transformBasePropertyEntry(entry);
|
|
1006
|
+
return transformedEntry ? [transformedEntry] : [];
|
|
1007
|
+
});
|
|
1008
|
+
if (search) {
|
|
1009
|
+
const baseResults = getBaseResults(entries, search);
|
|
1010
|
+
const variantResults = getVariantResults(input, search, node);
|
|
1011
|
+
original.entries = [...baseResults, ...variantResults];
|
|
1012
|
+
} else {
|
|
1013
|
+
const snippetEntries = isQuoted(node) ? getSelectorSnippetCompletions(config) : getSelectorSnippetCompletions(config, '"');
|
|
1014
|
+
original.entries = [...entries, ...snippetEntries];
|
|
1015
|
+
}
|
|
1016
|
+
return { ...original, isIncomplete: true };
|
|
1017
|
+
}
|
|
1018
|
+
return original;
|
|
1019
|
+
};
|
|
1020
|
+
proxy.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
1021
|
+
const entryConfig = getEntryDetailsConfig(entryName);
|
|
1022
|
+
const original = info.languageService.getCompletionEntryDetails(
|
|
1023
|
+
fileName,
|
|
1024
|
+
position,
|
|
1025
|
+
entryName,
|
|
1026
|
+
formatOptions,
|
|
1027
|
+
source,
|
|
1028
|
+
preferences,
|
|
1029
|
+
data
|
|
1030
|
+
);
|
|
1031
|
+
if (!entryConfig)
|
|
1032
|
+
return original;
|
|
1033
|
+
const common = {
|
|
1034
|
+
...original,
|
|
1035
|
+
name: entryName,
|
|
1036
|
+
kind: entryConfig.kind,
|
|
1037
|
+
kindModifiers: entryConfig.kindModifiers,
|
|
1038
|
+
displayParts: original?.displayParts || []
|
|
1039
|
+
};
|
|
1040
|
+
const originalDocumentation = original?.documentation || [];
|
|
1041
|
+
if (entryConfig.modeValues) {
|
|
1042
|
+
const entries = Object.entries(entryConfig.modeValues);
|
|
1043
|
+
const [mode, firstValue] = entries[0] || [];
|
|
1044
|
+
if (isColorThemeEntry(entryConfig.modeValues)) {
|
|
1045
|
+
const description = createColorTokenDescription(entryConfig.modeValues);
|
|
1046
|
+
const rgb2 = firstValue ? convertToRgb(replaceCssVarsWithFallback(firstValue), mode) : firstValue;
|
|
1047
|
+
const docs = { text: `${rgb2}
|
|
1048
|
+
|
|
1049
|
+
${description}`, kind: "markdown" };
|
|
1050
|
+
return { ...common, documentation: [docs, ...originalDocumentation] };
|
|
1051
|
+
} else {
|
|
1052
|
+
const description = createTokenDescription(entryConfig.modeValues);
|
|
1053
|
+
const docs = { text: `${firstValue}
|
|
1054
|
+
|
|
1055
|
+
${description}`, kind: "markdown" };
|
|
1056
|
+
return { ...common, documentation: [docs, ...originalDocumentation] };
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
if (entryConfig.value) {
|
|
1060
|
+
const docs = { kind: "markdown", text: String(entryConfig.value) };
|
|
1061
|
+
const documentation = [docs, ...originalDocumentation];
|
|
1062
|
+
return { ...common, documentation };
|
|
1063
|
+
}
|
|
1064
|
+
return common;
|
|
1065
|
+
};
|
|
1066
|
+
proxy.getQuickInfoAtPosition = (fileName, position) => {
|
|
1067
|
+
const original = info.languageService.getQuickInfoAtPosition(fileName, position);
|
|
1068
|
+
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
1069
|
+
if (!original || !sourceFile)
|
|
1070
|
+
return original;
|
|
1071
|
+
const node = findNodeAtPosition(sourceFile, position);
|
|
1072
|
+
if (!node || !node.parent || !ts.isPropertyAssignment(node.parent))
|
|
1073
|
+
return original;
|
|
1074
|
+
const property = node.parent;
|
|
1075
|
+
const propertyName = property.name.getText(sourceFile);
|
|
1076
|
+
const propertyValue = property.initializer.getText();
|
|
1077
|
+
const tokenProperty2 = TokenamiConfig.TokenProperty.safeParse(propertyName);
|
|
1078
|
+
const tokenValue = TokenamiConfig.TokenValue.safeParse(propertyValue);
|
|
1079
|
+
if (!tokenProperty2.success || !tokenValue.success)
|
|
1080
|
+
return original;
|
|
1081
|
+
const { variants } = TokenamiConfig.getTokenPropertySplit(tokenProperty2.output);
|
|
1082
|
+
const propertyParts = TokenamiConfig.getTokenPropertyParts(tokenProperty2.output, config);
|
|
1083
|
+
if (!propertyParts && variants.length)
|
|
1084
|
+
return;
|
|
1085
|
+
const modeValues = getThemeValuesByThemeMode(tokenValue.output, config.theme);
|
|
1086
|
+
const text = isColorThemeEntry(modeValues) ? createColorTokenDescription(modeValues) : createTokenDescription(modeValues);
|
|
1087
|
+
return { ...original, documentation: [{ text, kind: "markdown" }] };
|
|
1088
|
+
};
|
|
1089
|
+
return proxy;
|
|
1090
|
+
}
|
|
1091
|
+
return { create };
|
|
1092
|
+
}
|
|
1093
|
+
function convertToRgb(fill, mode) {
|
|
1094
|
+
try {
|
|
1095
|
+
const parsed = culori.parse(fill);
|
|
1096
|
+
const color = culori.rgb(parsed);
|
|
1097
|
+
const modeColor = culori.rgb(mode == "dark" ? "#000" : "#fff");
|
|
1098
|
+
const bgColor = fill === "transparent" ? void 0 : modeColor;
|
|
1099
|
+
if (!color)
|
|
1100
|
+
return fill;
|
|
1101
|
+
if (!bgColor || parsed?.alpha === void 0 || parsed.alpha === 1) {
|
|
1102
|
+
return culori.formatRgb(color);
|
|
1103
|
+
}
|
|
1104
|
+
const alpha = parsed.alpha;
|
|
1105
|
+
color.r = color.r * alpha + bgColor.r * (1 - alpha);
|
|
1106
|
+
color.g = color.g * alpha + bgColor.g * (1 - alpha);
|
|
1107
|
+
color.b = color.b * alpha + bgColor.b * (1 - alpha);
|
|
1108
|
+
color.alpha = 1;
|
|
1109
|
+
return culori.formatRgb(color);
|
|
1110
|
+
} catch {
|
|
1111
|
+
return fill;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
function createColorTokenDescription(modeValues) {
|
|
1115
|
+
return createDescription(modeValues, (mode, value) => [createSquare(value, mode), mode, value]);
|
|
1116
|
+
}
|
|
1117
|
+
function createTokenDescription(modeValues) {
|
|
1118
|
+
return createDescription(modeValues, (mode, value) => [mode, value]);
|
|
1119
|
+
}
|
|
1120
|
+
function createDescription(modeValues, builder) {
|
|
1121
|
+
const entries = Object.entries(modeValues);
|
|
1122
|
+
const rows = entries.map(([mode, value]) => createRow(builder(mode, value)));
|
|
1123
|
+
return rows.join(`
|
|
1124
|
+
|
|
1125
|
+
`);
|
|
1126
|
+
}
|
|
1127
|
+
function createRow(row) {
|
|
1128
|
+
return row.join(createSquare("transparent") + createSquare("transparent"));
|
|
1129
|
+
}
|
|
1130
|
+
var createSquare = (color, mode) => {
|
|
1131
|
+
const fill = convertToRgb(replaceCssVarsWithFallback(color), mode);
|
|
1132
|
+
const svg = `<svg width="10" height="10" xmlns="http://www.w3.org/2000/svg"><rect width="10" height="10" x="0" y="0" fill="${fill}" /></svg>`;
|
|
1133
|
+
return `})`;
|
|
1134
|
+
};
|
|
1135
|
+
function replaceCssVarsWithFallback(value) {
|
|
1136
|
+
const regex = /var\([\w-_]+,\s*([\w-_]+)\)/g;
|
|
1137
|
+
return value.replace(regex, (_, fallback) => fallback);
|
|
1138
|
+
}
|
|
1139
|
+
function isColorThemeEntry(modeValues) {
|
|
1140
|
+
try {
|
|
1141
|
+
const firstValue = Object.values(modeValues || {})?.[0];
|
|
1142
|
+
const isString = isNaN(Number(firstValue));
|
|
1143
|
+
return isString ? Boolean(culori.parse(replaceCssVarsWithFallback(firstValue || ""))) : false;
|
|
1144
|
+
} catch {
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
export { createTSPlugin as default };
|