@projectwallace/css-design-tokens 0.9.0 → 0.10.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/dist/css-design-tokens.js +38 -37
- package/dist/destructure-line-height.d.ts +1 -5
- package/dist/index.d.ts +1 -0
- package/dist/types.d.ts +7 -2
- package/package.json +1 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { cssKeywords as
|
|
1
|
+
import { cssKeywords as B, colorKeywords as G, namedColors as K, systemColors as M, colorFunctions as U, analyze as Z } from "@projectwallace/css-analyzer";
|
|
2
2
|
import { convert as V } from "css-time-sort";
|
|
3
3
|
import { convert as J } from "color-sorter";
|
|
4
4
|
import { parse as $ } from "css-tree";
|
|
5
5
|
import { ColorSpace as o, sRGB as Q, XYZ_D65 as ee, XYZ_D50 as te, XYZ_ABS_D65 as re, Lab_D65 as ne, Lab as ie, LCH as le, sRGB_Linear as se, HSL as oe, HWB as ue, HSV as ae, P3_Linear as fe, P3 as ce, A98RGB_Linear as pe, A98RGB as me, ProPhoto_Linear as ge, ProPhoto as he, REC_2020_Linear as de, REC_2020 as _e, OKLab as ve, OKLCH as $e, OKLrab as be, parse as xe } from "colorjs.io/fn";
|
|
6
|
-
const A = 0, j = 1, z = 2, y = 3, I = 4, R = 5,
|
|
6
|
+
const A = 0, j = 1, z = 2, y = 3, I = 4, R = 5, D = 6, H = 7, X = 8, P = 9, Y = 10, v = 11, ye = /* @__PURE__ */ new Map([
|
|
7
7
|
[A, "white"],
|
|
8
8
|
[j, "black"],
|
|
9
9
|
[z, "grey"],
|
|
10
10
|
[y, "red"],
|
|
11
11
|
[I, "orange"],
|
|
12
12
|
[R, "yellow"],
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
13
|
+
[D, "green"],
|
|
14
|
+
[H, "cyan"],
|
|
15
|
+
[X, "blue"],
|
|
16
16
|
[P, "magenta"],
|
|
17
17
|
[Y, "pink"],
|
|
18
18
|
[v, "unknown"]
|
|
@@ -23,7 +23,7 @@ function we(n) {
|
|
|
23
23
|
let e = v;
|
|
24
24
|
if (!i.includes("var(") && !i.includes("calc(")) {
|
|
25
25
|
let s = J(i), { hue: l, saturation: r, lightness: f } = s;
|
|
26
|
-
r < 10 && f === 100 ? e = A : r < 10 && f === 0 ? e = j : r < 5 ? e = z : l < 22 ? e = y : l < 50 ? e = I : l < 72 ? e = R : l < 144 ? e =
|
|
26
|
+
r < 10 && f === 100 ? e = A : r < 10 && f === 0 ? e = j : r < 5 ? e = z : l < 22 ? e = y : l < 50 ? e = I : l < 72 ? e = R : l < 144 ? e = D : l < 180 ? e = H : l < 250 ? e = X : l < 300 ? e = P : l < 350 ? e = Y : e = y;
|
|
27
27
|
}
|
|
28
28
|
t.has(e) ? t.get(e).push(i) : t.set(e, [i]);
|
|
29
29
|
}
|
|
@@ -62,24 +62,20 @@ function g(n) {
|
|
|
62
62
|
components: [0, 0, 0],
|
|
63
63
|
alpha: 0
|
|
64
64
|
};
|
|
65
|
-
if (
|
|
65
|
+
if (B.has(t) || G.has(t) || t.includes("var("))
|
|
66
66
|
return null;
|
|
67
67
|
try {
|
|
68
68
|
let i = xe(n), [e, s, l] = i.coords;
|
|
69
69
|
return {
|
|
70
70
|
colorSpace: i.spaceId,
|
|
71
|
-
components: [
|
|
72
|
-
|
|
73
|
-
s ?? "none",
|
|
74
|
-
l ?? "none"
|
|
75
|
-
],
|
|
76
|
-
alpha: i.alpha ?? 0
|
|
71
|
+
components: [e ?? "none", s ?? "none", l ?? "none"],
|
|
72
|
+
alpha: i.alpha ?? 1
|
|
77
73
|
};
|
|
78
74
|
} catch {
|
|
79
75
|
return null;
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
|
-
function
|
|
78
|
+
function N() {
|
|
83
79
|
return {
|
|
84
80
|
color: void 0,
|
|
85
81
|
offsetX: void 0,
|
|
@@ -97,7 +93,7 @@ function Se(n) {
|
|
|
97
93
|
function i(l) {
|
|
98
94
|
return l.loc ? n.slice(l.loc.start.offset, l.loc.end.offset) : "";
|
|
99
95
|
}
|
|
100
|
-
let e =
|
|
96
|
+
let e = N(), s = [e];
|
|
101
97
|
return t.children.size < 2 ? null : (t.children.forEach((l) => {
|
|
102
98
|
if (l.type === "Identifier") {
|
|
103
99
|
if (l.name.toLowerCase() === "inset")
|
|
@@ -118,7 +114,7 @@ function Se(n) {
|
|
|
118
114
|
};
|
|
119
115
|
e.offsetX ? e.offsetY ? e.blur ? e.spread || (e.spread = r) : e.blur = r : e.offsetY = r : e.offsetX = r;
|
|
120
116
|
} else if (l.type === "Function") {
|
|
121
|
-
if (
|
|
117
|
+
if (U.has(l.name)) {
|
|
122
118
|
let r = g(i(l));
|
|
123
119
|
if (r === null)
|
|
124
120
|
return;
|
|
@@ -134,14 +130,14 @@ function Se(n) {
|
|
|
134
130
|
if (r === null)
|
|
135
131
|
return;
|
|
136
132
|
e.color = r;
|
|
137
|
-
} else l.type === "Operator" && l.value === "," && (
|
|
138
|
-
}),
|
|
133
|
+
} else l.type === "Operator" && l.value === "," && (O(e), e = N(), s.push(e));
|
|
134
|
+
}), O(e), s);
|
|
139
135
|
}
|
|
140
136
|
const _ = {
|
|
141
137
|
value: 0,
|
|
142
138
|
unit: "px"
|
|
143
139
|
};
|
|
144
|
-
function
|
|
140
|
+
function O(n) {
|
|
145
141
|
return n.offsetX || (n.offsetX = _), n.offsetY || (n.offsetY = _), n.blur || (n.blur = _), n.spread || (n.spread = _), n.color || (n.color = g("#000")), n;
|
|
146
142
|
}
|
|
147
143
|
const E = /* @__PURE__ */ new Map([
|
|
@@ -151,7 +147,7 @@ const E = /* @__PURE__ */ new Map([
|
|
|
151
147
|
["ease-out", [0, 0, 0.58, 1]],
|
|
152
148
|
["ease-in-out", [0.42, 0, 0.58, 1]]
|
|
153
149
|
]);
|
|
154
|
-
function
|
|
150
|
+
function Le(n) {
|
|
155
151
|
if (n = n.trim().toLowerCase(), E.has(n))
|
|
156
152
|
return E.get(n);
|
|
157
153
|
if (n.includes("var("))
|
|
@@ -166,7 +162,7 @@ function Ne(n) {
|
|
|
166
162
|
function C(n) {
|
|
167
163
|
return n.replaceAll(/^['"]|['"]$/g, "");
|
|
168
164
|
}
|
|
169
|
-
function
|
|
165
|
+
function Ne(n) {
|
|
170
166
|
if (n.toLowerCase().includes("var("))
|
|
171
167
|
return;
|
|
172
168
|
let t = $(n, {
|
|
@@ -198,17 +194,21 @@ function a(n) {
|
|
|
198
194
|
t = (t << 5) - t + i.charCodeAt(0), t |= 0;
|
|
199
195
|
return (t >>> 0).toString(16);
|
|
200
196
|
}
|
|
201
|
-
|
|
197
|
+
const Oe = /* @__PURE__ */ new Set(["px", "rem"]);
|
|
198
|
+
function Ee(n) {
|
|
202
199
|
let t = $(n, { context: "value" });
|
|
203
200
|
if (t.children === null || t.children.size !== 1) return null;
|
|
204
201
|
let i = t.children.first;
|
|
205
202
|
switch (i.type) {
|
|
206
203
|
case "Dimension": {
|
|
207
204
|
let e = Number(i.value);
|
|
208
|
-
|
|
205
|
+
if (e === 0)
|
|
206
|
+
return 0;
|
|
207
|
+
let s = i.unit.toLowerCase();
|
|
208
|
+
return Oe.has(s) ? {
|
|
209
209
|
value: e,
|
|
210
|
-
unit:
|
|
211
|
-
};
|
|
210
|
+
unit: s
|
|
211
|
+
} : null;
|
|
212
212
|
}
|
|
213
213
|
case "Number":
|
|
214
214
|
return Number(i.value);
|
|
@@ -230,7 +230,7 @@ let q = /* @__PURE__ */ new Map([
|
|
|
230
230
|
["xx-large", 2],
|
|
231
231
|
["xxx-large", 3]
|
|
232
232
|
]);
|
|
233
|
-
function
|
|
233
|
+
function Ce(n) {
|
|
234
234
|
let t = $(n, { context: "value" });
|
|
235
235
|
if (t.children === null || t.children.size !== 1) return null;
|
|
236
236
|
let i = t.children.first;
|
|
@@ -269,9 +269,9 @@ function Ee(n) {
|
|
|
269
269
|
}
|
|
270
270
|
return null;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
let t =
|
|
274
|
-
return
|
|
272
|
+
function De(n) {
|
|
273
|
+
let t = Z(n);
|
|
274
|
+
return qe(t);
|
|
275
275
|
}
|
|
276
276
|
function p(n) {
|
|
277
277
|
return "uniqueWithLocations" in n ? n.uniqueWithLocations : n.unique;
|
|
@@ -279,7 +279,7 @@ function p(n) {
|
|
|
279
279
|
function m(n) {
|
|
280
280
|
return Array.isArray(n) ? n.length : n;
|
|
281
281
|
}
|
|
282
|
-
function
|
|
282
|
+
function qe(n) {
|
|
283
283
|
return {
|
|
284
284
|
color: (() => {
|
|
285
285
|
let t = /* @__PURE__ */ Object.create(null), i = p(n.values.colors), e = we(i);
|
|
@@ -287,7 +287,7 @@ function Ce(n) {
|
|
|
287
287
|
for (let r of l) {
|
|
288
288
|
let f = g(r), w = m(i[r]);
|
|
289
289
|
if (f !== null) {
|
|
290
|
-
let { colorSpace: k, components: F, alpha:
|
|
290
|
+
let { colorSpace: k, components: F, alpha: T } = f, h = `${ye.get(s)}-${a([k, ...F, T].join(""))}`, W = n.values.colors.itemsPerContext, S = Object.entries(W).reduce((d, [L, b]) => r in b.unique || b.uniqueWithLocations && r in b.uniqueWithLocations ? d.add(L) : d, /* @__PURE__ */ new Set());
|
|
291
291
|
if (t[h]) {
|
|
292
292
|
let d = t[h].$extensions[x];
|
|
293
293
|
t[h].$extensions[x] = Array.from(new Set(d).union(S)), t[h].$extensions[u] += w;
|
|
@@ -308,7 +308,7 @@ function Ce(n) {
|
|
|
308
308
|
font_size: (() => {
|
|
309
309
|
let t = /* @__PURE__ */ Object.create(null), i = p(n.values.fontSizes);
|
|
310
310
|
for (let e in i) {
|
|
311
|
-
let s =
|
|
311
|
+
let s = Ce(e), l = {
|
|
312
312
|
[c]: e,
|
|
313
313
|
[u]: m(i[e])
|
|
314
314
|
};
|
|
@@ -332,7 +332,7 @@ function Ce(n) {
|
|
|
332
332
|
font_family: (() => {
|
|
333
333
|
let t = /* @__PURE__ */ Object.create(null), i = p(n.values.fontFamilies);
|
|
334
334
|
for (let e in i) {
|
|
335
|
-
let s =
|
|
335
|
+
let s = Ne(e), l = `fontFamily-${a(e)}`, r = {
|
|
336
336
|
[c]: e,
|
|
337
337
|
[u]: m(i[e])
|
|
338
338
|
};
|
|
@@ -350,7 +350,7 @@ function Ce(n) {
|
|
|
350
350
|
line_height: (() => {
|
|
351
351
|
let t = /* @__PURE__ */ Object.create(null), i = p(n.values.lineHeights);
|
|
352
352
|
for (let e in i) {
|
|
353
|
-
let s =
|
|
353
|
+
let s = Ee(e), l = {
|
|
354
354
|
[c]: e,
|
|
355
355
|
[u]: m(i[e])
|
|
356
356
|
};
|
|
@@ -459,7 +459,7 @@ function Ce(n) {
|
|
|
459
459
|
easing: (() => {
|
|
460
460
|
let t = /* @__PURE__ */ Object.create(null), i = p(n.values.animations.timingFunctions);
|
|
461
461
|
for (let e in i) {
|
|
462
|
-
let s = `easing-${a(e)}`, l =
|
|
462
|
+
let s = `easing-${a(e)}`, l = Le(e), r = {
|
|
463
463
|
[c]: e,
|
|
464
464
|
[u]: m(i[e])
|
|
465
465
|
};
|
|
@@ -480,6 +480,7 @@ export {
|
|
|
480
480
|
c as EXTENSION_AUTHORED_AS,
|
|
481
481
|
x as EXTENSION_CSS_PROPERTIES,
|
|
482
482
|
u as EXTENSION_USAGE_COUNT,
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
qe as analysis_to_tokens,
|
|
484
|
+
g as color_to_token,
|
|
485
|
+
De as css_to_tokens
|
|
485
486
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
value: number;
|
|
3
|
-
unit: string;
|
|
4
|
-
};
|
|
1
|
+
import { Length } from './types';
|
|
5
2
|
/**
|
|
6
3
|
* @description Destructure a line-height from a string
|
|
7
4
|
* The line-height property is specified as any one of the following:
|
|
@@ -11,4 +8,3 @@ type Length = {
|
|
|
11
8
|
* - the keyword `normal`.
|
|
12
9
|
*/
|
|
13
10
|
export declare function destructure_line_height(value: string): Length | number | null;
|
|
14
|
-
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CubicBezierToken, DimensionToken, DurationToken, FontFamilyToken, NumberToken, UnparsedToken, ColorToken, CssAnalysis, ShadowToken } from './types.js';
|
|
2
|
+
export { color_to_token } from './colors.js';
|
|
2
3
|
export { EXTENSION_AUTHORED_AS, EXTENSION_USAGE_COUNT, EXTENSION_CSS_PROPERTIES, type Easing, type CubicBezierToken, type DimensionValue, type DimensionToken, type DurationToken, type DurationValue, type FontFamilyToken, type NumberToken, type UnparsedToken, type CssAnalysis, type ShadowToken, type ColorSpace, type ColorToken, type ColorValue, type ColorComponent, } from './types.js';
|
|
3
4
|
export type { CssLength, ShadowValue } from './destructure-box-shadow.js';
|
|
4
5
|
export declare function css_to_tokens(css: string): Tokens;
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export type BaseToken = {
|
|
|
11
11
|
[EXTENSION_USAGE_COUNT]: number;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
+
export type Unit = 'rem' | 'px';
|
|
15
|
+
export type Length = {
|
|
16
|
+
value: number;
|
|
17
|
+
unit: Unit;
|
|
18
|
+
};
|
|
14
19
|
export type DurationValue = {
|
|
15
20
|
value: number;
|
|
16
21
|
unit: 'ms';
|
|
@@ -23,7 +28,7 @@ export type UnparsedToken = BaseToken & {
|
|
|
23
28
|
$value: string;
|
|
24
29
|
$type?: never;
|
|
25
30
|
};
|
|
26
|
-
export type ColorSpace =
|
|
31
|
+
export type ColorSpace = 'srgb' | 'display-p3' | 'hsl' | 'hwb' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'display-p3' | 'a98-rgb' | 'prophoto-rgb' | 'rec2020' | 'xyz-d65' | 'xyz-d50';
|
|
27
32
|
export type ColorComponent = number | 'none';
|
|
28
33
|
export type ColorValue = {
|
|
29
34
|
colorSpace: ColorSpace;
|
|
@@ -40,7 +45,7 @@ export type ColorToken = BaseToken & {
|
|
|
40
45
|
};
|
|
41
46
|
export type DimensionValue = {
|
|
42
47
|
value: number;
|
|
43
|
-
unit:
|
|
48
|
+
unit: Unit;
|
|
44
49
|
};
|
|
45
50
|
export type DimensionToken = BaseToken & {
|
|
46
51
|
$type: 'dimension';
|
package/package.json
CHANGED