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