@projectwallace/css-design-tokens 0.10.0 → 0.11.1

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.
@@ -1,486 +0,0 @@
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
- import { convert as V } from "css-time-sort";
3
- import { convert as J } from "color-sorter";
4
- import { parse as $ } from "css-tree";
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, D = 6, H = 7, X = 8, P = 9, Y = 10, v = 11, ye = /* @__PURE__ */ new Map([
7
- [A, "white"],
8
- [j, "black"],
9
- [z, "grey"],
10
- [y, "red"],
11
- [I, "orange"],
12
- [R, "yellow"],
13
- [D, "green"],
14
- [H, "cyan"],
15
- [X, "blue"],
16
- [P, "magenta"],
17
- [Y, "pink"],
18
- [v, "unknown"]
19
- ]);
20
- function we(n) {
21
- let t = /* @__PURE__ */ new Map();
22
- for (let i in n) {
23
- let e = v;
24
- if (!i.includes("var(") && !i.includes("calc(")) {
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 = D : l < 180 ? e = H : l < 250 ? e = X : l < 300 ? e = P : l < 350 ? e = Y : e = y;
27
- }
28
- t.has(e) ? t.get(e).push(i) : t.set(e, [i]);
29
- }
30
- return Array.from(t).sort(
31
- (i, e) => i[0] === v || e[0] === v ? -1 : e[1].length - i[1].length
32
- );
33
- }
34
- const c = "com.projectwallace.css-authored-as", u = "com.projectwallace.usage-count", x = "com.projectwallace.css-properties";
35
- o.register(Q);
36
- o.register(ee);
37
- o.register(te);
38
- o.register(re);
39
- o.register(ne);
40
- o.register(ie);
41
- o.register(le);
42
- o.register(se);
43
- o.register(oe);
44
- o.register(ue);
45
- o.register(ae);
46
- o.register(fe);
47
- o.register(ce);
48
- o.register(pe);
49
- o.register(me);
50
- o.register(ge);
51
- o.register(he);
52
- o.register(de);
53
- o.register(_e);
54
- o.register(ve);
55
- o.register($e);
56
- o.register(be);
57
- function g(n) {
58
- let t = n.toLowerCase();
59
- if (t === "transparent")
60
- return {
61
- colorSpace: "srgb",
62
- components: [0, 0, 0],
63
- alpha: 0
64
- };
65
- if (B.has(t) || G.has(t) || t.includes("var("))
66
- return null;
67
- try {
68
- let i = xe(n), [e, s, l] = i.coords;
69
- return {
70
- colorSpace: i.spaceId,
71
- components: [e ?? "none", s ?? "none", l ?? "none"],
72
- alpha: i.alpha ?? 1
73
- };
74
- } catch {
75
- return null;
76
- }
77
- }
78
- function N() {
79
- return {
80
- color: void 0,
81
- offsetX: void 0,
82
- offsetY: void 0,
83
- blur: void 0,
84
- spread: void 0,
85
- inset: !1
86
- };
87
- }
88
- function Se(n) {
89
- let t = $(n, {
90
- context: "value",
91
- positions: !0
92
- });
93
- function i(l) {
94
- return l.loc ? n.slice(l.loc.start.offset, l.loc.end.offset) : "";
95
- }
96
- let e = N(), s = [e];
97
- return t.children.size < 2 ? null : (t.children.forEach((l) => {
98
- if (l.type === "Identifier") {
99
- if (l.name.toLowerCase() === "inset")
100
- e.inset = !0;
101
- else if (K.has(l.name) || M.has(l.name)) {
102
- let r = g(l.name);
103
- if (r === null)
104
- return;
105
- e.color = r;
106
- }
107
- } else if (l.type === "Dimension" || l.type === "Number" && l.value === "0") {
108
- let r = l.type === "Dimension" ? {
109
- value: Number(l.value),
110
- unit: l.unit
111
- } : {
112
- value: 0,
113
- unit: "px"
114
- };
115
- e.offsetX ? e.offsetY ? e.blur ? e.spread || (e.spread = r) : e.blur = r : e.offsetY = r : e.offsetX = r;
116
- } else if (l.type === "Function") {
117
- if (U.has(l.name)) {
118
- let r = g(i(l));
119
- if (r === null)
120
- return;
121
- e.color = r;
122
- } else if (l.name.toLowerCase() === "var" && !e.color) {
123
- let r = g(i(l));
124
- if (r === null)
125
- return;
126
- e.color = r;
127
- }
128
- } else if (l.type === "Hash") {
129
- let r = g(i(l));
130
- if (r === null)
131
- return;
132
- e.color = r;
133
- } else l.type === "Operator" && l.value === "," && (O(e), e = N(), s.push(e));
134
- }), O(e), s);
135
- }
136
- const _ = {
137
- value: 0,
138
- unit: "px"
139
- };
140
- function O(n) {
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;
142
- }
143
- const E = /* @__PURE__ */ new Map([
144
- ["linear", [0, 0, 1, 1]],
145
- ["ease", [0.25, 0.1, 0.25, 1]],
146
- ["ease-in", [0.42, 0, 1, 1]],
147
- ["ease-out", [0, 0, 0.58, 1]],
148
- ["ease-in-out", [0.42, 0, 0.58, 1]]
149
- ]);
150
- function Le(n) {
151
- if (n = n.trim().toLowerCase(), E.has(n))
152
- return E.get(n);
153
- if (n.includes("var("))
154
- return null;
155
- if (n.startsWith("cubic-bezier(")) {
156
- let t = n.replace("cubic-bezier(", "").replace(")", "").split(",").map((i) => Number(i.trim()));
157
- if (t.length === 4 && t.every((i) => Number.isFinite(i)))
158
- return t;
159
- }
160
- return null;
161
- }
162
- function C(n) {
163
- return n.replaceAll(/^['"]|['"]$/g, "");
164
- }
165
- function Ne(n) {
166
- if (n.toLowerCase().includes("var("))
167
- return;
168
- let t = $(n, {
169
- context: "value",
170
- positions: !0
171
- });
172
- function i(r) {
173
- return r.loc ? n.slice(r.loc.start.offset, r.loc.end.offset) : "";
174
- }
175
- let e = [];
176
- if (!t.children || t.children.size === 0)
177
- return e;
178
- let s = "", l;
179
- for (let r of t.children) {
180
- if (r.type === "Operator" && r.value === ",") {
181
- e.push(C(s)), s = "", l = r.type;
182
- continue;
183
- }
184
- l === "Identifier" && r.type === "Identifier" && (s += " "), s += i(r), l = r.type;
185
- }
186
- return e.push(C(s)), e;
187
- }
188
- function a(n) {
189
- if (n === void 0 || typeof n == "number" && isNaN(n))
190
- return "0";
191
- typeof n != "string" && (n = n.toString());
192
- let t = 0;
193
- for (let i of n)
194
- t = (t << 5) - t + i.charCodeAt(0), t |= 0;
195
- return (t >>> 0).toString(16);
196
- }
197
- const Oe = /* @__PURE__ */ new Set(["px", "rem"]);
198
- function Ee(n) {
199
- let t = $(n, { context: "value" });
200
- if (t.children === null || t.children.size !== 1) return null;
201
- let i = t.children.first;
202
- switch (i.type) {
203
- case "Dimension": {
204
- let e = Number(i.value);
205
- if (e === 0)
206
- return 0;
207
- let s = i.unit.toLowerCase();
208
- return Oe.has(s) ? {
209
- value: e,
210
- unit: s
211
- } : null;
212
- }
213
- case "Number":
214
- return Number(i.value);
215
- case "Percentage":
216
- return Number(i.value) / 100;
217
- case "Identifier":
218
- if (i.name === "normal")
219
- return 1.2;
220
- }
221
- return null;
222
- }
223
- let q = /* @__PURE__ */ new Map([
224
- ["xx-small", 0.6],
225
- ["x-small", 0.75],
226
- ["small", 0.89],
227
- ["medium", 1],
228
- ["large", 1.2],
229
- ["x-large", 1.5],
230
- ["xx-large", 2],
231
- ["xxx-large", 3]
232
- ]);
233
- function Ce(n) {
234
- let t = $(n, { context: "value" });
235
- if (t.children === null || t.children.size !== 1) return null;
236
- let i = t.children.first;
237
- switch (i.type) {
238
- case "Dimension": {
239
- let e = i.unit.toLowerCase();
240
- if (e === "px" || e === "rem") {
241
- let s = Number(i.value);
242
- return s === 0 ? {
243
- value: 0,
244
- unit: "px"
245
- } : {
246
- value: s,
247
- unit: e
248
- };
249
- }
250
- break;
251
- }
252
- case "Identifier": {
253
- let e = i.name.toLowerCase();
254
- if (q.has(e))
255
- return {
256
- value: q.get(e),
257
- unit: "rem"
258
- };
259
- break;
260
- }
261
- case "Number": {
262
- if (Number(i.value) === 0)
263
- return {
264
- value: 0,
265
- unit: "px"
266
- };
267
- break;
268
- }
269
- }
270
- return null;
271
- }
272
- function De(n) {
273
- let t = Z(n);
274
- return qe(t);
275
- }
276
- function p(n) {
277
- return "uniqueWithLocations" in n ? n.uniqueWithLocations : n.unique;
278
- }
279
- function m(n) {
280
- return Array.isArray(n) ? n.length : n;
281
- }
282
- function qe(n) {
283
- return {
284
- color: (() => {
285
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.colors), e = we(i);
286
- for (let [s, l] of e)
287
- for (let r of l) {
288
- let f = g(r), w = m(i[r]);
289
- if (f !== null) {
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
- if (t[h]) {
292
- let d = t[h].$extensions[x];
293
- t[h].$extensions[x] = Array.from(new Set(d).union(S)), t[h].$extensions[u] += w;
294
- } else
295
- t[h] = {
296
- $type: "color",
297
- $value: f,
298
- $extensions: {
299
- [c]: r,
300
- [u]: w,
301
- [x]: Array.from(S)
302
- }
303
- };
304
- }
305
- }
306
- return t;
307
- })(),
308
- font_size: (() => {
309
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.fontSizes);
310
- for (let e in i) {
311
- let s = Ce(e), l = {
312
- [c]: e,
313
- [u]: m(i[e])
314
- };
315
- if (s === null) {
316
- let r = `fontSize-${a(e)}`;
317
- t[r] = {
318
- $value: e,
319
- $extensions: l
320
- };
321
- } else {
322
- let r = `fontSize-${a(s.value.toString() + s.unit)}`;
323
- t[r] ? t[r].$extensions[u] += l[u] : t[r] = {
324
- $type: "dimension",
325
- $value: s,
326
- $extensions: l
327
- };
328
- }
329
- }
330
- return t;
331
- })(),
332
- font_family: (() => {
333
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.fontFamilies);
334
- for (let e in i) {
335
- let s = Ne(e), l = `fontFamily-${a(e)}`, r = {
336
- [c]: e,
337
- [u]: m(i[e])
338
- };
339
- s === void 0 ? t[l] = {
340
- $value: e,
341
- $extensions: r
342
- } : t[l] = {
343
- $type: "fontFamily",
344
- $value: s,
345
- $extensions: r
346
- };
347
- }
348
- return t;
349
- })(),
350
- line_height: (() => {
351
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.lineHeights);
352
- for (let e in i) {
353
- let s = Ee(e), l = {
354
- [c]: e,
355
- [u]: m(i[e])
356
- };
357
- if (s === null) {
358
- let r = `lineHeight-${a(e)}`;
359
- t[r] = {
360
- $value: e,
361
- $extensions: l
362
- };
363
- } else if (typeof s == "number") {
364
- let r = `lineHeight-${a(s)}`;
365
- t[r] ? t[r].$extensions[u] += l[u] : t[r] = {
366
- $type: "number",
367
- $value: s,
368
- $extensions: l
369
- };
370
- } else if (typeof s == "object")
371
- if (s.unit === "px" || s.unit === "rem") {
372
- let r = `lineHeight-${a(s.value.toString() + s.unit)}`;
373
- t[r] ? t[r].$extensions[u] += l[u] : t[r] = {
374
- $type: "dimension",
375
- $value: s,
376
- $extensions: l
377
- };
378
- } else {
379
- let r = `lineHeight-${a(e)}`;
380
- t[r] = {
381
- $value: e,
382
- $extensions: l
383
- };
384
- }
385
- }
386
- return t;
387
- })(),
388
- gradient: (() => {
389
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.gradients);
390
- for (let e in i)
391
- t[`gradient-${a(e)}`] = {
392
- $value: e,
393
- $extensions: {
394
- [c]: e,
395
- [u]: m(i[e])
396
- }
397
- };
398
- return t;
399
- })(),
400
- box_shadow: (() => {
401
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.boxShadows);
402
- for (let e in i) {
403
- let s = `boxShadow-${a(e)}`, l = Se(e), r = {
404
- [c]: e,
405
- [u]: m(i[e])
406
- };
407
- l === null ? t[s] = {
408
- $value: e,
409
- $extensions: r
410
- } : t[s] = {
411
- $type: "shadow",
412
- $value: l.length === 1 ? l[0] : l,
413
- $extensions: r
414
- };
415
- }
416
- return t;
417
- })(),
418
- radius: (() => {
419
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.borderRadiuses);
420
- for (let e in i) {
421
- let s = `radius-${a(e)}`;
422
- t[s] = {
423
- $value: e,
424
- $extensions: {
425
- [c]: e,
426
- [u]: m(i[e])
427
- }
428
- };
429
- }
430
- return t;
431
- })(),
432
- duration: (() => {
433
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.animations.durations);
434
- for (let e in i) {
435
- let s = V(e), l = s < Number.MAX_SAFE_INTEGER - 1, r = {
436
- [c]: e,
437
- [u]: m(i[e])
438
- };
439
- if (l) {
440
- let f = `duration-${a(s.toString())}`;
441
- t[f] ? t[f].$extensions[u] += r[u] : t[f] = {
442
- $type: "duration",
443
- $value: {
444
- value: s,
445
- unit: "ms"
446
- },
447
- $extensions: r
448
- };
449
- } else {
450
- let f = `duration-${a("invalid" + s.toString())}`;
451
- t[f] = {
452
- $value: e,
453
- $extensions: r
454
- };
455
- }
456
- }
457
- return t;
458
- })(),
459
- easing: (() => {
460
- let t = /* @__PURE__ */ Object.create(null), i = p(n.values.animations.timingFunctions);
461
- for (let e in i) {
462
- let s = `easing-${a(e)}`, l = Le(e), r = {
463
- [c]: e,
464
- [u]: m(i[e])
465
- };
466
- l !== null ? t[s] = {
467
- $value: l,
468
- $type: "cubicBezier",
469
- $extensions: r
470
- } : t[s] = {
471
- $value: e,
472
- $extensions: r
473
- };
474
- }
475
- return t;
476
- })()
477
- };
478
- }
479
- export {
480
- c as EXTENSION_AUTHORED_AS,
481
- x as EXTENSION_CSS_PROPERTIES,
482
- u as EXTENSION_USAGE_COUNT,
483
- qe as analysis_to_tokens,
484
- g as color_to_token,
485
- De as css_to_tokens
486
- };
@@ -1,14 +0,0 @@
1
- import { ColorValue } from './types.js';
2
- export type CssLength = {
3
- value: number;
4
- unit: string;
5
- };
6
- export type ShadowValue = {
7
- color: ColorValue | undefined;
8
- offsetX: CssLength | undefined;
9
- offsetY: CssLength | undefined;
10
- blur: CssLength | undefined;
11
- spread: CssLength | undefined;
12
- inset: boolean | undefined;
13
- };
14
- export declare function destructure_box_shadow(value: string): null | ShadowValue[];
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { Easing } from './types.js';
2
- export declare function destructure_easing(easing: string): Easing | null;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { FontFamilyValue } from './types.js';
2
- export declare function destructure_font_family(value: string): FontFamilyValue | undefined;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import { Length } from './types';
2
- /**
3
- * @description Destructure a line-height from a string
4
- * The line-height property is specified as any one of the following:
5
- * - a `<number>`
6
- * - a `<length>`
7
- * - a `<percentage>`
8
- * - the keyword `normal`.
9
- */
10
- export declare function destructure_line_height(value: string): Length | number | null;
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export declare const color_dict: Map<number, string>;
2
- type AuthoredColor = string;
3
- export declare function group_colors(colors: Record<AuthoredColor, unknown>): [number, string[]][];
4
- export {};
package/dist/hash.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function hash(input: string | undefined | number): string;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- type DesignTokenLength = {
2
- value: number;
3
- unit: 'px' | 'rem';
4
- };
5
- /**
6
- * @description Parse a length from a css value
7
- * - a `<number>`
8
- * - a `<length>`
9
- * - a `<percentage>`
10
- * - the keyword `normal`.
11
- */
12
- export declare function parse_length(value: string): DesignTokenLength | null;
13
- export {};
@@ -1 +0,0 @@
1
- export {};
package/dist/types.d.ts DELETED
@@ -1,70 +0,0 @@
1
- import { analyze } from '@projectwallace/css-analyzer';
2
- import { ShadowValue } from './destructure-box-shadow';
3
- export type CssAnalysis = ReturnType<typeof analyze>;
4
- export declare const EXTENSION_AUTHORED_AS = "com.projectwallace.css-authored-as";
5
- export declare const EXTENSION_USAGE_COUNT = "com.projectwallace.usage-count";
6
- export declare const EXTENSION_CSS_PROPERTIES = "com.projectwallace.css-properties";
7
- export type Easing = [number, number, number, number];
8
- export type BaseToken = {
9
- $extensions: {
10
- [EXTENSION_AUTHORED_AS]: string;
11
- [EXTENSION_USAGE_COUNT]: number;
12
- };
13
- };
14
- export type Unit = 'rem' | 'px';
15
- export type Length = {
16
- value: number;
17
- unit: Unit;
18
- };
19
- export type DurationValue = {
20
- value: number;
21
- unit: 'ms';
22
- };
23
- export type DurationToken = BaseToken & {
24
- $type: 'duration';
25
- $value: DurationValue;
26
- };
27
- export type UnparsedToken = BaseToken & {
28
- $value: string;
29
- $type?: never;
30
- };
31
- export type ColorSpace = 'srgb' | 'display-p3' | 'hsl' | 'hwb' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'display-p3' | 'a98-rgb' | 'prophoto-rgb' | 'rec2020' | 'xyz-d65' | 'xyz-d50';
32
- export type ColorComponent = number | 'none';
33
- export type ColorValue = {
34
- colorSpace: ColorSpace;
35
- components: [ColorComponent, ColorComponent, ColorComponent];
36
- alpha: number;
37
- hex?: string;
38
- };
39
- export type ColorToken = BaseToken & {
40
- $type: 'color';
41
- $value: ColorValue;
42
- $extensions: {
43
- [EXTENSION_CSS_PROPERTIES]: Array<string>;
44
- };
45
- };
46
- export type DimensionValue = {
47
- value: number;
48
- unit: Unit;
49
- };
50
- export type DimensionToken = BaseToken & {
51
- $type: 'dimension';
52
- $value: DimensionValue;
53
- };
54
- export type NumberToken = BaseToken & {
55
- $type: 'number';
56
- $value: number;
57
- };
58
- export type CubicBezierToken = BaseToken & {
59
- $type: 'cubicBezier';
60
- $value: Easing;
61
- };
62
- export type FontFamilyValue = string[];
63
- export type FontFamilyToken = BaseToken & {
64
- $type: 'fontFamily';
65
- $value: FontFamilyValue;
66
- };
67
- export type ShadowToken = BaseToken & {
68
- $type: 'shadow';
69
- $value: ShadowValue | ShadowValue[];
70
- };
package/dist/unquote.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function unquote(input: string): string;
@@ -1 +0,0 @@
1
- export {};