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