@fluixi-css/language 1.0.0-next.5

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.
@@ -0,0 +1,885 @@
1
+ import { compileClasses, createCssContext, splitAtTopLevel, parseAtom, parseVariant } from '@fluixi-css/core';
2
+
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithHoles(r) {
9
+ if (Array.isArray(r)) return r;
10
+ }
11
+ function _arrayWithoutHoles(r) {
12
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
13
+ }
14
+ function _createForOfIteratorHelper(r, e) {
15
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
16
+ if (!t) {
17
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
18
+ t && (r = t);
19
+ var n = 0,
20
+ F = function () {};
21
+ return {
22
+ s: F,
23
+ n: function () {
24
+ return n >= r.length ? {
25
+ done: true
26
+ } : {
27
+ done: false,
28
+ value: r[n++]
29
+ };
30
+ },
31
+ e: function (r) {
32
+ throw r;
33
+ },
34
+ f: F
35
+ };
36
+ }
37
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
38
+ }
39
+ var o,
40
+ a = true,
41
+ u = false;
42
+ return {
43
+ s: function () {
44
+ t = t.call(r);
45
+ },
46
+ n: function () {
47
+ var r = t.next();
48
+ return a = r.done, r;
49
+ },
50
+ e: function (r) {
51
+ u = true, o = r;
52
+ },
53
+ f: function () {
54
+ try {
55
+ a || null == t.return || t.return();
56
+ } finally {
57
+ if (u) throw o;
58
+ }
59
+ }
60
+ };
61
+ }
62
+ function _defineProperty(e, r, t) {
63
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
64
+ value: t,
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true
68
+ }) : e[r] = t, e;
69
+ }
70
+ function _iterableToArray(r) {
71
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
72
+ }
73
+ function _iterableToArrayLimit(r, l) {
74
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
75
+ if (null != t) {
76
+ var e,
77
+ n,
78
+ i,
79
+ u,
80
+ a = [],
81
+ f = true,
82
+ o = false;
83
+ try {
84
+ if (i = (t = t.call(r)).next, 0 === l) {
85
+ if (Object(t) !== t) return;
86
+ f = !1;
87
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
88
+ } catch (r) {
89
+ o = true, n = r;
90
+ } finally {
91
+ try {
92
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
93
+ } finally {
94
+ if (o) throw n;
95
+ }
96
+ }
97
+ return a;
98
+ }
99
+ }
100
+ function _nonIterableRest() {
101
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
+ }
103
+ function _nonIterableSpread() {
104
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
105
+ }
106
+ function ownKeys(e, r) {
107
+ var t = Object.keys(e);
108
+ if (Object.getOwnPropertySymbols) {
109
+ var o = Object.getOwnPropertySymbols(e);
110
+ r && (o = o.filter(function (r) {
111
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
112
+ })), t.push.apply(t, o);
113
+ }
114
+ return t;
115
+ }
116
+ function _objectSpread2(e) {
117
+ for (var r = 1; r < arguments.length; r++) {
118
+ var t = null != arguments[r] ? arguments[r] : {};
119
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
120
+ _defineProperty(e, r, t[r]);
121
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
122
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
123
+ });
124
+ }
125
+ return e;
126
+ }
127
+ function _slicedToArray(r, e) {
128
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
129
+ }
130
+ function _toConsumableArray(r) {
131
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
132
+ }
133
+ function _toPrimitive(t, r) {
134
+ if ("object" != typeof t || !t) return t;
135
+ var e = t[Symbol.toPrimitive];
136
+ if (void 0 !== e) {
137
+ var i = e.call(t, r);
138
+ if ("object" != typeof i) return i;
139
+ throw new TypeError("@@toPrimitive must return a primitive value.");
140
+ }
141
+ return ("string" === r ? String : Number)(t);
142
+ }
143
+ function _toPropertyKey(t) {
144
+ var i = _toPrimitive(t, "string");
145
+ return "symbol" == typeof i ? i : i + "";
146
+ }
147
+ function _unsupportedIterableToArray(r, a) {
148
+ if (r) {
149
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
150
+ var t = {}.toString.call(r).slice(8, -1);
151
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
152
+ }
153
+ }
154
+
155
+ var SCALE = ['0', 'px', '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4', '5', '6', '7', '8', '9', '10', '11', '12', '14', '16', '20', '24', '28', '32', '36', '40', '44', '48', '52', '56', '60', '64', '72', '80', '96'];
156
+ var FRACTIONS = ['1/2', '1/3', '2/3', '1/4', '2/4', '3/4', '1/5', '2/5', '3/5', '4/5', '1/6', '5/6', '1/12', '5/12', '7/12', '11/12'];
157
+ var KEYWORDS = ['auto', 'full', 'screen', 'svw', 'lvw', 'dvw', 'svh', 'lvh', 'dvh', 'min', 'max', 'fit', 'none', 'inherit', 'current', 'transparent', 'black', 'white', 'start', 'end', 'center', 'left', 'right', 'top', 'bottom', 'x', 'y', 'solid', 'dashed', 'dotted', 'double', 'hidden', 'normal', 'wrap', 'nowrap', 'reverse', 'col', 'row', 'both', 'visible', 'scroll', 'clip', 'contain', 'cover', 'fill', 'initial', 'between', 'around', 'evenly', 'stretch', 'baseline', 'dense', 'span-full', 'prose', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', '8xl', '9xl', 'inner'];
158
+
159
+ /** Namespaces in a theme: `--color-red-500` is `color` (key `red-500`) and `color-red` (key `500`). */
160
+ function namespaces(names) {
161
+ var out = new Map();
162
+ var _iterator = _createForOfIteratorHelper(names),
163
+ _step;
164
+ try {
165
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
166
+ var name = _step.value;
167
+ var parts = name.slice(2).split('-');
168
+ for (var i = 1; i < parts.length; i++) {
169
+ var _out$get;
170
+ var ns = parts.slice(0, i).join('-');
171
+ var key = parts.slice(i).join('-');
172
+ var keys = (_out$get = out.get(ns)) !== null && _out$get !== void 0 ? _out$get : [];
173
+ keys.push(key);
174
+ out.set(ns, keys);
175
+ }
176
+ }
177
+ } catch (err) {
178
+ _iterator.e(err);
179
+ } finally {
180
+ _iterator.f();
181
+ }
182
+ return out;
183
+ }
184
+ var produces = function produces(cls, reg) {
185
+ return compileClasses([cls], reg, {
186
+ minify: true
187
+ });
188
+ };
189
+ function classCandidates(reg) {
190
+ var out = [];
191
+ var seen = new Set();
192
+ var add = function add(name, token) {
193
+ if (seen.has(name)) return;
194
+ seen.add(name);
195
+ out.push(token ? {
196
+ name: name,
197
+ token: token
198
+ } : {
199
+ name: name
200
+ });
201
+ };
202
+ var _reg$names = reg.names(),
203
+ rules = _reg$names.rules,
204
+ dynamicRules = _reg$names.dynamicRules;
205
+ var _iterator2 = _createForOfIteratorHelper(rules),
206
+ _step2;
207
+ try {
208
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
209
+ var name = _step2.value;
210
+ add(name);
211
+ }
212
+ } catch (err) {
213
+ _iterator2.e(err);
214
+ } finally {
215
+ _iterator2.f();
216
+ }
217
+ var themeNames = reg.theme.entries().map(function (_ref) {
218
+ var _ref2 = _slicedToArray(_ref, 1),
219
+ name = _ref2[0];
220
+ return name;
221
+ });
222
+ var spaces = namespaces(themeNames);
223
+ var _iterator3 = _createForOfIteratorHelper(dynamicRules),
224
+ _step3;
225
+ try {
226
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
227
+ var root = _step3.value;
228
+ if (produces(root, reg)) add(root);
229
+ var _iterator4 = _createForOfIteratorHelper(spaces),
230
+ _step4;
231
+ try {
232
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
233
+ var _step4$value = _slicedToArray(_step4.value, 2),
234
+ ns = _step4$value[0],
235
+ keys = _step4$value[1];
236
+ var probe = keys[0];
237
+ var css = produces("".concat(root, "-").concat(probe), reg);
238
+ if (!css.includes("--".concat(ns, "-").concat(probe))) continue;
239
+ var _iterator5 = _createForOfIteratorHelper(keys),
240
+ _step5;
241
+ try {
242
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
243
+ var key = _step5.value;
244
+ add("".concat(root, "-").concat(key), "--".concat(ns, "-").concat(key));
245
+ }
246
+ } catch (err) {
247
+ _iterator5.e(err);
248
+ } finally {
249
+ _iterator5.f();
250
+ }
251
+ }
252
+ } catch (err) {
253
+ _iterator4.e(err);
254
+ } finally {
255
+ _iterator4.f();
256
+ }
257
+ for (var _i = 0, _arr = [].concat(SCALE, FRACTIONS, KEYWORDS); _i < _arr.length; _i++) {
258
+ var value = _arr[_i];
259
+ var cls = "".concat(root, "-").concat(value);
260
+ if (!seen.has(cls) && produces(cls, reg)) add(cls);
261
+ }
262
+ }
263
+ } catch (err) {
264
+ _iterator3.e(err);
265
+ } finally {
266
+ _iterator3.f();
267
+ }
268
+ return out;
269
+ }
270
+
271
+ // CSS colour values to sRGB, for an editor's colour swatches. Covers what a theme writes:
272
+ // hex, rgb(), hsl(), oklch(), oklab(). Anything else is not a colour this can show.
273
+
274
+ var clamp = function clamp(n) {
275
+ return Math.min(1, Math.max(0, n));
276
+ };
277
+ function channel(part, scale) {
278
+ return part.endsWith('%') ? parseFloat(part) / 100 : parseFloat(part) / scale;
279
+ }
280
+ function alphaOf(part) {
281
+ if (part === undefined) return 1;
282
+ return clamp(part.endsWith('%') ? parseFloat(part) / 100 : parseFloat(part));
283
+ }
284
+
285
+ // `a b c / d` and `a, b, c, d` alike.
286
+ function args(inner) {
287
+ return inner.replace(/\//g, ' / ').split(/[\s,]+/).filter(function (p) {
288
+ return p && p !== '/';
289
+ });
290
+ }
291
+ function hex(value) {
292
+ var h = value.slice(1);
293
+ var full = h.length === 3 || h.length === 4 ? _toConsumableArray(h).map(function (c) {
294
+ return c + c;
295
+ }).join('') : h;
296
+ if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(full)) return null;
297
+ var n = function n(i) {
298
+ return parseInt(full.slice(i, i + 2), 16) / 255;
299
+ };
300
+ return {
301
+ red: n(0),
302
+ green: n(2),
303
+ blue: n(4),
304
+ alpha: full.length === 8 ? n(6) : 1
305
+ };
306
+ }
307
+ function hslToRgb(h, s, l) {
308
+ var k = function k(n) {
309
+ return (n + h / 30) % 12;
310
+ };
311
+ var a = s * Math.min(l, 1 - l);
312
+ var f = function f(n) {
313
+ return l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
314
+ };
315
+ return [f(0), f(8), f(4)];
316
+ }
317
+ function oklabToRgb(L, a, b) {
318
+ var l = Math.pow(L + 0.3963377774 * a + 0.2158037573 * b, 3);
319
+ var m = Math.pow(L - 0.1055613458 * a - 0.0638541728 * b, 3);
320
+ var s = Math.pow(L - 0.0894841775 * a - 1.291485548 * b, 3);
321
+ var linear = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
322
+ var gamma = function gamma(x) {
323
+ return x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055;
324
+ };
325
+ return linear.map(function (x) {
326
+ return clamp(gamma(x));
327
+ });
328
+ }
329
+ function parseColor(value) {
330
+ var v = value.trim().toLowerCase();
331
+ if (v.startsWith('#')) return hex(v);
332
+ var m = /^(rgba?|hsla?|oklch|oklab)\((.*)\)$/.exec(v);
333
+ if (!m) return null;
334
+ var p = args(m[2]);
335
+ if (p.length < 3) return null;
336
+ var alpha = alphaOf(p[3]);
337
+ var rgb;
338
+ switch (m[1]) {
339
+ case 'rgb':
340
+ case 'rgba':
341
+ rgb = [channel(p[0], 255), channel(p[1], 255), channel(p[2], 255)];
342
+ break;
343
+ case 'hsl':
344
+ case 'hsla':
345
+ rgb = hslToRgb(parseFloat(p[0]), channel(p[1], 100), channel(p[2], 100));
346
+ break;
347
+ case 'oklch':
348
+ {
349
+ var L = channel(p[0], 1);
350
+ var C = p[1].endsWith('%') ? parseFloat(p[1]) / 100 * 0.4 : parseFloat(p[1]);
351
+ var h = parseFloat(p[2]) * Math.PI / 180;
352
+ rgb = oklabToRgb(L, C * Math.cos(h), C * Math.sin(h));
353
+ break;
354
+ }
355
+ default:
356
+ {
357
+ var ab = function ab(part) {
358
+ return part.endsWith('%') ? parseFloat(part) / 100 * 0.4 : parseFloat(part);
359
+ };
360
+ rgb = oklabToRgb(channel(p[0], 1), ab(p[1]), ab(p[2]));
361
+ }
362
+ }
363
+ if (rgb.some(function (n) {
364
+ return Number.isNaN(n);
365
+ }) || Number.isNaN(alpha)) return null;
366
+ return {
367
+ red: clamp(rgb[0]),
368
+ green: clamp(rgb[1]),
369
+ blue: clamp(rgb[2]),
370
+ alpha: alpha
371
+ };
372
+ }
373
+
374
+ var DIRECTIVES = [{
375
+ name: 'apply',
376
+ documentation: 'Inline utilities into this rule: `@apply p-4 rounded-xl hover:shadow-md;`'
377
+ }, {
378
+ name: 'theme',
379
+ documentation: 'Declare theme variables (`--color-*`, `--spacing`, …) that utilities read.'
380
+ }, {
381
+ name: 'utility',
382
+ documentation: 'Define a utility: `@utility tab-4 { tab-size: 4; }`, or `@utility tab-* { … }` for one that takes a value.'
383
+ }, {
384
+ name: 'custom-variant',
385
+ documentation: 'Define a variant: `@custom-variant theme-dark (&:where([data-theme=dark] *));`'
386
+ }, {
387
+ name: 'source',
388
+ documentation: 'Scan more files for class names: `@source "../components";`'
389
+ }, {
390
+ name: 'fluixi',
391
+ documentation: 'Where the generated theme variables and utilities go in this stylesheet.'
392
+ }];
393
+ var DIRECTIVE_DOCS = new Map(DIRECTIVES.map(function (d) {
394
+ return [d.name, d.documentation];
395
+ }));
396
+
397
+ /**
398
+ * Fluixi's at-rules and pseudo-classes in the CSS custom data format editors read
399
+ * (`css.customData` in VS Code, `newCSSDataProvider` in vscode-css-languageservice), so a
400
+ * stock CSS service stops flagging `@apply` or `:deep()` as unknown.
401
+ */
402
+ var CSS_CUSTOM_DATA = {
403
+ version: 1.1,
404
+ atDirectives: [].concat(_toConsumableArray(DIRECTIVES.map(function (d) {
405
+ return {
406
+ name: "@".concat(d.name),
407
+ description: d.documentation
408
+ };
409
+ })), [{
410
+ name: '@slot',
411
+ description: 'Inside `@custom-variant`: where the rule it wraps goes.'
412
+ }]),
413
+ pseudoClasses: [{
414
+ name: ':global',
415
+ description: 'In a scoped `<style>`: this selector is left unscoped.'
416
+ }, {
417
+ name: ':deep',
418
+ description: 'In a scoped `<style>`: reaches elements a child component renders.'
419
+ }]
420
+ };
421
+
422
+ // Comments and string contents blanked to spaces, so offsets stay put and nothing inside
423
+ // them reads as a directive or a reference.
424
+ function mask(css) {
425
+ var out = '';
426
+ var i = 0;
427
+ while (i < css.length) {
428
+ if (css.startsWith('/*', i)) {
429
+ var end = css.indexOf('*/', i + 2);
430
+ var stop = end === -1 ? css.length : end + 2;
431
+ out += css.slice(i, stop).replace(/[^\n]/g, ' ');
432
+ i = stop;
433
+ } else if (css[i] === '"' || css[i] === "'") {
434
+ var quote = css[i];
435
+ var j = i + 1;
436
+ while (j < css.length && css[j] !== quote && css[j] !== '\n') j += css[j] === '\\' ? 2 : 1;
437
+ out += quote + ' '.repeat(Math.max(0, Math.min(j, css.length) - i - 1)) + (j < css.length ? css[j] : '');
438
+ i = j + 1;
439
+ } else {
440
+ out += css[i];
441
+ i++;
442
+ }
443
+ }
444
+ return out.slice(0, css.length);
445
+ }
446
+ /** The class words of every `@apply`, with their offsets. */
447
+ function applyWords(masked) {
448
+ var words = [];
449
+ var re = /@apply\b/g;
450
+ for (var m = re.exec(masked); m; m = re.exec(masked)) {
451
+ var i = m.index + m[0].length;
452
+ while (i < masked.length && !';{}'.includes(masked[i])) {
453
+ if (/\s/.test(masked[i])) {
454
+ i++;
455
+ continue;
456
+ }
457
+ var _start = i;
458
+ while (i < masked.length && !/\s/.test(masked[i]) && !';{}'.includes(masked[i])) i++;
459
+ words.push({
460
+ text: masked.slice(_start, i),
461
+ start: _start,
462
+ end: i
463
+ });
464
+ }
465
+ }
466
+ return words;
467
+ }
468
+
469
+ /** Every `var(--name` reference, the name's range. */
470
+ function varRefs(masked) {
471
+ var refs = [];
472
+ var re = /var\(\s*(--[\w-]+)/g;
473
+ for (var m = re.exec(masked); m; m = re.exec(masked)) {
474
+ var _start2 = m.index + m[0].length - m[1].length;
475
+ refs.push({
476
+ text: m[1],
477
+ start: _start2,
478
+ end: _start2 + m[1].length
479
+ });
480
+ }
481
+ return refs;
482
+ }
483
+ function createLanguageService() {
484
+ var _options$context;
485
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
486
+ var context = (_options$context = options.context) !== null && _options$context !== void 0 ? _options$context : createCssContext(options.theme ? {
487
+ theme: options.theme
488
+ } : {});
489
+ var reg = context.registry;
490
+ var candidates;
491
+ var all = function all() {
492
+ return candidates !== null && candidates !== void 0 ? candidates : candidates = classCandidates(reg);
493
+ };
494
+
495
+ // A theme value with its `var()` references followed, for a colour or a hover.
496
+ var _resolveValue = function resolveValue(value) {
497
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
498
+ return depth > 8 ? value : value.replace(/var\(\s*(--[\w-]+)\s*(?:,[^)]*)?\)/g, function (whole, name) {
499
+ var v = reg.theme.get(name);
500
+ return v === undefined ? whole : _resolveValue(v, depth + 1);
501
+ });
502
+ };
503
+
504
+ // `var(--radius-xl)` says nothing on its own: the theme's value goes beside it.
505
+ var annotate = function annotate(css) {
506
+ return css.replace(/var\(\s*(--[\w-]+)\s*\)/g, function (whole, name) {
507
+ var value = reg.theme.get(name);
508
+ return value === undefined ? whole : "".concat(whole, " /* ").concat(_resolveValue(value), " */");
509
+ });
510
+ };
511
+ var classCss = function classCss(cls) {
512
+ var css = compileClasses([cls], reg);
513
+ return css.trim() ? annotate(css) : null;
514
+ };
515
+ var classColor = function classColor(cls) {
516
+ var css = compileClasses([cls], reg, {
517
+ minify: true
518
+ });
519
+ var _iterator = _createForOfIteratorHelper(css.matchAll(/:([^;{}]+)[;}]/g)),
520
+ _step;
521
+ try {
522
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
523
+ var m = _step.value;
524
+ var color = parseColor(_resolveValue(m[1].replace(/!important$/, '').trim()));
525
+ if (color) return color;
526
+ }
527
+ } catch (err) {
528
+ _iterator.e(err);
529
+ } finally {
530
+ _iterator.f();
531
+ }
532
+ return null;
533
+ };
534
+
535
+ // Any utility-shaped name parses; a known one is a rule, or a registered root with a value.
536
+ var isKnownUtility = function isKnownUtility(utility) {
537
+ var bare = utility.replace(/^[!-]+|!$/g, '');
538
+ if (reg.isRule(bare) || bare.startsWith('[')) return true;
539
+ return reg.names().dynamicRules.some(function (root) {
540
+ return bare === root || bare.startsWith("".concat(root, "-"));
541
+ });
542
+ };
543
+ var checkClass = function checkClass(cls, start) {
544
+ var range = {
545
+ start: start,
546
+ end: start + cls.length
547
+ };
548
+ if (/^\[.*\]$/.test(cls)) return null;
549
+ if (classCss(cls)) return null;
550
+ var parts = splitAtTopLevel(cls, ':');
551
+ var utility = parts[parts.length - 1];
552
+ var variants = parts.slice(0, -1);
553
+ var utilityStart = start + cls.length - utility.length;
554
+ if (!parseAtom(utility, reg) || !isKnownUtility(utility)) {
555
+ return {
556
+ range: {
557
+ start: utilityStart,
558
+ end: utilityStart + utility.length
559
+ },
560
+ message: "Unknown utility '".concat(utility, "'."),
561
+ severity: 'error'
562
+ };
563
+ }
564
+ if (!classCss(utility)) {
565
+ return {
566
+ range: range,
567
+ message: "'".concat(utility, "' produces no CSS: no theme value or rule matches it."),
568
+ severity: 'error'
569
+ };
570
+ }
571
+ // The utility works alone, so a variant is what fails. A variant-shaped name parses
572
+ // whether or not it exists; compiling it with the utility is what tells.
573
+ var offset = start;
574
+ var _iterator2 = _createForOfIteratorHelper(variants),
575
+ _step2;
576
+ try {
577
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
578
+ var variant = _step2.value;
579
+ if (!parseVariant(variant, reg) || !classCss("".concat(variant, ":").concat(utility))) {
580
+ return {
581
+ range: {
582
+ start: offset,
583
+ end: offset + variant.length
584
+ },
585
+ message: "Unknown variant '".concat(variant, "'."),
586
+ severity: 'error'
587
+ };
588
+ }
589
+ offset += variant.length + 1;
590
+ }
591
+ } catch (err) {
592
+ _iterator2.e(err);
593
+ } finally {
594
+ _iterator2.f();
595
+ }
596
+ return {
597
+ range: range,
598
+ message: "'".concat(cls, "' produces no CSS."),
599
+ severity: 'error'
600
+ };
601
+ };
602
+ var completeClass = function completeClass(partial, start) {
603
+ var _parts, _typed$split$;
604
+ var parts = splitAtTopLevel(partial, ':');
605
+ var current = (_parts = parts[parts.length - 1]) !== null && _parts !== void 0 ? _parts : '';
606
+ // `!` and `-` lead a class (`!p-4`, `-mt-2`) and stay as written.
607
+ var lead = /^[!-]*/.exec(current)[0];
608
+ var typed = current.slice(lead.length);
609
+ var range = {
610
+ start: start + partial.length - typed.length,
611
+ end: start + partial.length
612
+ };
613
+ var root = (_typed$split$ = typed.split('-')[0]) !== null && _typed$split$ !== void 0 ? _typed$split$ : '';
614
+ var out = [];
615
+ var _iterator3 = _createForOfIteratorHelper(all()),
616
+ _step3;
617
+ try {
618
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
619
+ var c = _step3.value;
620
+ if (root && !c.name.startsWith(root)) continue;
621
+ var value = c.token ? reg.theme.get(c.token) : undefined;
622
+ var color = value ? parseColor(_resolveValue(value)) : null;
623
+ out.push(_objectSpread2(_objectSpread2({
624
+ label: c.name,
625
+ kind: 'utility',
626
+ range: range
627
+ }, value ? {
628
+ detail: value
629
+ } : {}), color ? {
630
+ color: color
631
+ } : {}));
632
+ }
633
+ } catch (err) {
634
+ _iterator3.e(err);
635
+ } finally {
636
+ _iterator3.f();
637
+ }
638
+ var _reg$names = reg.names(),
639
+ variants = _reg$names.variants,
640
+ dynamicVariants = _reg$names.dynamicVariants;
641
+ var _iterator4 = _createForOfIteratorHelper(variants),
642
+ _step4;
643
+ try {
644
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
645
+ var v = _step4.value;
646
+ if (root && !v.startsWith(root)) continue;
647
+ out.push({
648
+ label: "".concat(v, ":"),
649
+ kind: 'variant',
650
+ range: range
651
+ });
652
+ }
653
+ } catch (err) {
654
+ _iterator4.e(err);
655
+ } finally {
656
+ _iterator4.f();
657
+ }
658
+ var _iterator5 = _createForOfIteratorHelper(dynamicVariants),
659
+ _step5;
660
+ try {
661
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
662
+ var _v = _step5.value;
663
+ if (root && !_v.startsWith(root)) continue;
664
+ out.push({
665
+ label: "".concat(_v, "-"),
666
+ kind: 'variant',
667
+ range: range,
668
+ detail: 'takes a value'
669
+ });
670
+ }
671
+ } catch (err) {
672
+ _iterator5.e(err);
673
+ } finally {
674
+ _iterator5.f();
675
+ }
676
+ return out;
677
+ };
678
+ var themeCompletions = function themeCompletions(range) {
679
+ return reg.theme.entries().map(function (_ref) {
680
+ var _ref2 = _slicedToArray(_ref, 2),
681
+ name = _ref2[0],
682
+ value = _ref2[1];
683
+ var color = parseColor(_resolveValue(value));
684
+ return _objectSpread2({
685
+ label: name,
686
+ kind: 'variable',
687
+ range: range,
688
+ detail: value
689
+ }, color ? {
690
+ color: color
691
+ } : {});
692
+ });
693
+ };
694
+ return {
695
+ registry: reg,
696
+ completeClass: completeClass,
697
+ classCss: classCss,
698
+ classColor: classColor,
699
+ checkClass: checkClass,
700
+ complete: function complete(css, offset) {
701
+ var masked = mask(css);
702
+ var before = masked.slice(0, offset);
703
+ var directive = /@([\w-]*)$/.exec(before);
704
+ if (directive) {
705
+ var range = {
706
+ start: offset - directive[1].length,
707
+ end: offset
708
+ };
709
+ return DIRECTIVES.map(function (d) {
710
+ return {
711
+ label: d.name,
712
+ kind: 'directive',
713
+ range: range,
714
+ documentation: d.documentation
715
+ };
716
+ });
717
+ }
718
+ var variable = /var\(\s*(--[\w-]*|-?)$/.exec(before);
719
+ if (variable) return themeCompletions({
720
+ start: offset - variable[1].length,
721
+ end: offset
722
+ });
723
+ var apply = before.lastIndexOf('@apply');
724
+ if (apply !== -1 && !/[;{}]/.test(before.slice(apply))) {
725
+ var word = /[^\s]*$/.exec(before)[0];
726
+ if (offset - word.length > apply + 5) return completeClass(word, offset - word.length);
727
+ }
728
+ return [];
729
+ },
730
+ hover: function hover(css, offset) {
731
+ var masked = mask(css);
732
+ var _iterator6 = _createForOfIteratorHelper(applyWords(masked)),
733
+ _step6;
734
+ try {
735
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
736
+ var w = _step6.value;
737
+ if (offset < w.start || offset > w.end) continue;
738
+ var out = classCss(w.text);
739
+ return out ? {
740
+ range: {
741
+ start: w.start,
742
+ end: w.end
743
+ },
744
+ css: out
745
+ } : null;
746
+ }
747
+ } catch (err) {
748
+ _iterator6.e(err);
749
+ } finally {
750
+ _iterator6.f();
751
+ }
752
+ var _iterator7 = _createForOfIteratorHelper(varRefs(masked)),
753
+ _step7;
754
+ try {
755
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
756
+ var r = _step7.value;
757
+ if (offset < r.start || offset > r.end) continue;
758
+ var value = reg.theme.get(r.text);
759
+ return value === undefined ? null : {
760
+ range: {
761
+ start: r.start,
762
+ end: r.end
763
+ },
764
+ css: "".concat(r.text, ": ").concat(value, ";")
765
+ };
766
+ }
767
+ } catch (err) {
768
+ _iterator7.e(err);
769
+ } finally {
770
+ _iterator7.f();
771
+ }
772
+ var at = /@([\w-]+)/g;
773
+ for (var m = at.exec(masked); m; m = at.exec(masked)) {
774
+ var doc = DIRECTIVE_DOCS.get(m[1]);
775
+ if (doc && offset >= m.index && offset <= m.index + m[0].length) {
776
+ return {
777
+ range: {
778
+ start: m.index,
779
+ end: m.index + m[0].length
780
+ },
781
+ css: "/* ".concat(doc, " */")
782
+ };
783
+ }
784
+ }
785
+ return null;
786
+ },
787
+ diagnostics: function diagnostics(css) {
788
+ var masked = mask(css);
789
+ var out = [];
790
+ var _iterator8 = _createForOfIteratorHelper(applyWords(masked)),
791
+ _step8;
792
+ try {
793
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
794
+ var w = _step8.value;
795
+ var d = checkClass(w.text, w.start);
796
+ if (d) out.push(d);
797
+ }
798
+ // A theme-shaped reference (`--color-…`) to a key the theme does not have, and that this
799
+ // stylesheet does not declare either: most likely a typo in a token name.
800
+ } catch (err) {
801
+ _iterator8.e(err);
802
+ } finally {
803
+ _iterator8.f();
804
+ }
805
+ var declared = new Set(_toConsumableArray(masked.matchAll(/(--[\w-]+)\s*:/g)).map(function (m) {
806
+ return m[1];
807
+ }));
808
+ var spaces = new Set(reg.theme.entries().map(function (_ref3) {
809
+ var _ref4 = _slicedToArray(_ref3, 1),
810
+ name = _ref4[0];
811
+ return name.slice(2).split('-')[0];
812
+ }));
813
+ var _iterator9 = _createForOfIteratorHelper(varRefs(masked)),
814
+ _step9;
815
+ try {
816
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
817
+ var r = _step9.value;
818
+ if (reg.theme.has(r.text) || declared.has(r.text)) continue;
819
+ var ns = r.text.slice(2).split('-')[0];
820
+ if (!spaces.has(ns) || r.text === "--".concat(ns)) continue;
821
+ out.push({
822
+ range: {
823
+ start: r.start,
824
+ end: r.end
825
+ },
826
+ message: "".concat(r.text, " is not in the theme."),
827
+ severity: 'warning'
828
+ });
829
+ }
830
+ } catch (err) {
831
+ _iterator9.e(err);
832
+ } finally {
833
+ _iterator9.f();
834
+ }
835
+ return out;
836
+ },
837
+ colors: function colors(css) {
838
+ var masked = mask(css);
839
+ var out = [];
840
+ var _iterator0 = _createForOfIteratorHelper(applyWords(masked)),
841
+ _step0;
842
+ try {
843
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
844
+ var w = _step0.value;
845
+ var color = classColor(w.text);
846
+ if (color) out.push({
847
+ range: {
848
+ start: w.start,
849
+ end: w.end
850
+ },
851
+ color: color
852
+ });
853
+ }
854
+ } catch (err) {
855
+ _iterator0.e(err);
856
+ } finally {
857
+ _iterator0.f();
858
+ }
859
+ var _iterator1 = _createForOfIteratorHelper(varRefs(masked)),
860
+ _step1;
861
+ try {
862
+ for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
863
+ var r = _step1.value;
864
+ var value = reg.theme.get(r.text);
865
+ var _color = value ? parseColor(_resolveValue(value)) : null;
866
+ if (_color) out.push({
867
+ range: {
868
+ start: r.start,
869
+ end: r.end
870
+ },
871
+ color: _color
872
+ });
873
+ }
874
+ } catch (err) {
875
+ _iterator1.e(err);
876
+ } finally {
877
+ _iterator1.f();
878
+ }
879
+ return out;
880
+ }
881
+ };
882
+ }
883
+
884
+ export { CSS_CUSTOM_DATA, DIRECTIVES, classCandidates, createLanguageService, parseColor };
885
+ //# sourceMappingURL=index.mjs.map