@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fluixi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@fluixi-css/language",
3
+ "version": "1.0.0-next.5",
4
+ "description": "Completion, hover, diagnostics and colours for Fluixi CSS, for any editor integration",
5
+ "license": "MIT",
6
+ "author": "fluixi",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE",
11
+ "!dist/**/*.map"
12
+ ],
13
+ "main": "./src/index.js",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./src/index.d.ts",
17
+ "import": "./src/index.mjs",
18
+ "require": "./src/index.cjs"
19
+ }
20
+ },
21
+ "private": false,
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/fluixi/css.git"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
30
+ "scripts": {
31
+ "build:typings": "cross-env tsc --project ./tsconfig.json --declarationDir dist",
32
+ "build:rollup": "pnpm run build:typings && cross-env NODE_ENV=production INPUT_FILE=./src/index.ts rollup -c ../configs/rollup.config.mjs",
33
+ "build": "pnpm run build:rollup && tsc",
34
+ "test": "vitest run"
35
+ },
36
+ "keywords": [
37
+ "fluixi",
38
+ "css",
39
+ "language-server",
40
+ "intellisense"
41
+ ],
42
+ "dependencies": {
43
+ "@fluixi-css/core": "workspace:*"
44
+ },
45
+ "devDependencies": {
46
+ "vitest": "^4.1.10"
47
+ }
48
+ }
@@ -0,0 +1,9 @@
1
+ import { type Registry } from '@fluixi-css/core';
2
+ export interface ClassCandidate {
3
+ /** The class as written: `p-4`, `bg-red-500`, `flex`. */
4
+ name: string;
5
+ /** The theme variable it reads, when its value came from one. */
6
+ token?: string;
7
+ }
8
+ export declare function classCandidates(reg: Registry): ClassCandidate[];
9
+ //# sourceMappingURL=candidates.d.ts.map
@@ -0,0 +1,69 @@
1
+ // Every class a context can produce, for completion. Static utilities are listed by the
2
+ // registry. A functional one (`bg-*`, `p-*`) takes values the registry cannot list, so they are
3
+ // found by trying: one key from each theme namespace, and a small set of scale values and
4
+ // keywords. A namespace whose key works, and whose variable the output reads, is used whole.
5
+ // Correct for any utility, a project's own `@utility` included, with nothing to keep in sync.
6
+ import { compileClasses } from '@fluixi-css/core';
7
+ const SCALE = [
8
+ '0', 'px', '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4', '5', '6', '7', '8', '9', '10', '11', '12',
9
+ '14', '16', '20', '24', '28', '32', '36', '40', '44', '48', '52', '56', '60', '64', '72', '80', '96',
10
+ ];
11
+ const 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'];
12
+ const KEYWORDS = [
13
+ 'auto', 'full', 'screen', 'svw', 'lvw', 'dvw', 'svh', 'lvh', 'dvh', 'min', 'max', 'fit', 'none', 'inherit',
14
+ 'current', 'transparent', 'black', 'white', 'start', 'end', 'center', 'left', 'right', 'top', 'bottom',
15
+ 'x', 'y', 'solid', 'dashed', 'dotted', 'double', 'hidden', 'normal', 'wrap', 'nowrap', 'reverse',
16
+ 'col', 'row', 'both', 'visible', 'scroll', 'clip', 'contain', 'cover', 'fill', 'initial', 'between',
17
+ 'around', 'evenly', 'stretch', 'baseline', 'dense', 'span-full', 'prose', 'xs', 'sm', 'md', 'lg', 'xl',
18
+ '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', '8xl', '9xl', 'inner',
19
+ ];
20
+ /** Namespaces in a theme: `--color-red-500` is `color` (key `red-500`) and `color-red` (key `500`). */
21
+ function namespaces(names) {
22
+ const out = new Map();
23
+ for (const name of names) {
24
+ const parts = name.slice(2).split('-');
25
+ for (let i = 1; i < parts.length; i++) {
26
+ const ns = parts.slice(0, i).join('-');
27
+ const key = parts.slice(i).join('-');
28
+ const keys = out.get(ns) ?? [];
29
+ keys.push(key);
30
+ out.set(ns, keys);
31
+ }
32
+ }
33
+ return out;
34
+ }
35
+ const produces = (cls, reg) => compileClasses([cls], reg, { minify: true });
36
+ export function classCandidates(reg) {
37
+ const out = [];
38
+ const seen = new Set();
39
+ const add = (name, token) => {
40
+ if (seen.has(name))
41
+ return;
42
+ seen.add(name);
43
+ out.push(token ? { name, token } : { name });
44
+ };
45
+ const { rules, dynamicRules } = reg.names();
46
+ for (const name of rules)
47
+ add(name);
48
+ const themeNames = reg.theme.entries().map(([name]) => name);
49
+ const spaces = namespaces(themeNames);
50
+ for (const root of dynamicRules) {
51
+ if (produces(root, reg))
52
+ add(root);
53
+ for (const [ns, keys] of spaces) {
54
+ const probe = keys[0];
55
+ const css = produces(`${root}-${probe}`, reg);
56
+ if (!css.includes(`--${ns}-${probe}`))
57
+ continue;
58
+ for (const key of keys)
59
+ add(`${root}-${key}`, `--${ns}-${key}`);
60
+ }
61
+ for (const value of [...SCALE, ...FRACTIONS, ...KEYWORDS]) {
62
+ const cls = `${root}-${value}`;
63
+ if (!seen.has(cls) && produces(cls, reg))
64
+ add(cls);
65
+ }
66
+ }
67
+ return out;
68
+ }
69
+ //# sourceMappingURL=candidates.js.map
@@ -0,0 +1,8 @@
1
+ export interface Rgba {
2
+ red: number;
3
+ green: number;
4
+ blue: number;
5
+ alpha: number;
6
+ }
7
+ export declare function parseColor(value: string): Rgba | null;
8
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1,79 @@
1
+ // CSS colour values to sRGB, for an editor's colour swatches. Covers what a theme writes:
2
+ // hex, rgb(), hsl(), oklch(), oklab(). Anything else is not a colour this can show.
3
+ const clamp = (n) => Math.min(1, Math.max(0, n));
4
+ function channel(part, scale) {
5
+ return part.endsWith('%') ? parseFloat(part) / 100 : parseFloat(part) / scale;
6
+ }
7
+ function alphaOf(part) {
8
+ if (part === undefined)
9
+ return 1;
10
+ return clamp(part.endsWith('%') ? parseFloat(part) / 100 : parseFloat(part));
11
+ }
12
+ // `a b c / d` and `a, b, c, d` alike.
13
+ function args(inner) {
14
+ return inner.replace(/\//g, ' / ').split(/[\s,]+/).filter((p) => p && p !== '/');
15
+ }
16
+ function hex(value) {
17
+ const h = value.slice(1);
18
+ const full = h.length === 3 || h.length === 4 ? [...h].map((c) => c + c).join('') : h;
19
+ if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(full))
20
+ return null;
21
+ const n = (i) => parseInt(full.slice(i, i + 2), 16) / 255;
22
+ return { red: n(0), green: n(2), blue: n(4), alpha: full.length === 8 ? n(6) : 1 };
23
+ }
24
+ function hslToRgb(h, s, l) {
25
+ const k = (n) => (n + h / 30) % 12;
26
+ const a = s * Math.min(l, 1 - l);
27
+ const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
28
+ return [f(0), f(8), f(4)];
29
+ }
30
+ function oklabToRgb(L, a, b) {
31
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
32
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
33
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
34
+ const linear = [
35
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
36
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
37
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
38
+ ];
39
+ const gamma = (x) => (x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055);
40
+ return linear.map((x) => clamp(gamma(x)));
41
+ }
42
+ export function parseColor(value) {
43
+ const v = value.trim().toLowerCase();
44
+ if (v.startsWith('#'))
45
+ return hex(v);
46
+ const m = /^(rgba?|hsla?|oklch|oklab)\((.*)\)$/.exec(v);
47
+ if (!m)
48
+ return null;
49
+ const p = args(m[2]);
50
+ if (p.length < 3)
51
+ return null;
52
+ const alpha = alphaOf(p[3]);
53
+ let rgb;
54
+ switch (m[1]) {
55
+ case 'rgb':
56
+ case 'rgba':
57
+ rgb = [channel(p[0], 255), channel(p[1], 255), channel(p[2], 255)];
58
+ break;
59
+ case 'hsl':
60
+ case 'hsla':
61
+ rgb = hslToRgb(parseFloat(p[0]), channel(p[1], 100), channel(p[2], 100));
62
+ break;
63
+ case 'oklch': {
64
+ const L = channel(p[0], 1);
65
+ const C = p[1].endsWith('%') ? (parseFloat(p[1]) / 100) * 0.4 : parseFloat(p[1]);
66
+ const h = (parseFloat(p[2]) * Math.PI) / 180;
67
+ rgb = oklabToRgb(L, C * Math.cos(h), C * Math.sin(h));
68
+ break;
69
+ }
70
+ default: {
71
+ const ab = (part) => (part.endsWith('%') ? (parseFloat(part) / 100) * 0.4 : parseFloat(part));
72
+ rgb = oklabToRgb(channel(p[0], 1), ab(p[1]), ab(p[2]));
73
+ }
74
+ }
75
+ if (rgb.some((n) => Number.isNaN(n)) || Number.isNaN(alpha))
76
+ return null;
77
+ return { red: clamp(rgb[0]), green: clamp(rgb[1]), blue: clamp(rgb[2]), alpha };
78
+ }
79
+ //# sourceMappingURL=color.js.map