1
1
import { test , expect , describe } from 'vitest'
2
2
import { destructure_box_shadow } from './destructure-box-shadow.js'
3
+ import { ColorToken , EXTENSION_AUTHORED_AS } from './types.js'
4
+ import { color_to_token } from './colors.js'
3
5
4
6
function create_px_length ( value : number ) : { value : number , unit : string , $type : 'dimension' } {
5
7
return {
@@ -9,6 +11,20 @@ function create_px_length(value: number): { value: number, unit: string, $type:
9
11
}
10
12
}
11
13
14
+ function create_color_token ( ) : ColorToken {
15
+ return {
16
+ $type : 'color' ,
17
+ $value : {
18
+ colorSpace : 'srgb' ,
19
+ components : [ 0 , 0 , 0 ] ,
20
+ alpha : 1 ,
21
+ } ,
22
+ $extensions : {
23
+ [ EXTENSION_AUTHORED_AS ] : '#000'
24
+ }
25
+ }
26
+ }
27
+
12
28
test ( 'handles invalid input' , ( ) => {
13
29
expect . soft ( destructure_box_shadow ( '' ) ) . toBeNull ( )
14
30
expect . soft ( destructure_box_shadow ( 'foo' ) ) . toBeNull ( )
@@ -19,7 +35,7 @@ test('handles invalid input', () => {
19
35
test ( '0px 0px 0px 0px #000' , ( ) => {
20
36
expect ( destructure_box_shadow ( '0px 0px 0px 0px #000' ) ) . toEqual ( [
21
37
{
22
- color : '#000' ,
38
+ color : create_color_token ( ) ,
23
39
offsetX : create_px_length ( 0 ) ,
24
40
offsetY : create_px_length ( 0 ) ,
25
41
blur : create_px_length ( 0 ) ,
@@ -32,7 +48,7 @@ test('0px 0px 0px 0px #000', () => {
32
48
test ( 'adds units when omitted: 0 0 0 0 #000' , ( ) => {
33
49
expect ( destructure_box_shadow ( '0 0 0 0 #000' ) ) . toEqual ( [
34
50
{
35
- color : '#000' ,
51
+ color : create_color_token ( ) ,
36
52
offsetX : create_px_length ( 0 ) ,
37
53
offsetY : create_px_length ( 0 ) ,
38
54
blur : create_px_length ( 0 ) ,
@@ -45,7 +61,7 @@ test('adds units when omitted: 0 0 0 0 #000', () => {
45
61
test ( 'offsetX and offsetY: 2px 4px #000' , ( ) => {
46
62
expect ( destructure_box_shadow ( '2px 4px #000' ) ) . toEqual ( [
47
63
{
48
- color : '#000' ,
64
+ color : create_color_token ( ) ,
49
65
offsetX : create_px_length ( 2 ) ,
50
66
offsetY : create_px_length ( 4 ) ,
51
67
blur : create_px_length ( 0 ) ,
@@ -58,7 +74,7 @@ test('offsetX and offsetY: 2px 4px #000', () => {
58
74
test ( 'offsetX, offsetY and blur: 2px 4px 6px #000' , ( ) => {
59
75
expect ( destructure_box_shadow ( '2px 4px 6px #000' ) ) . toEqual ( [
60
76
{
61
- color : '#000' ,
77
+ color : create_color_token ( ) ,
62
78
offsetX : create_px_length ( 2 ) ,
63
79
offsetY : create_px_length ( 4 ) ,
64
80
blur : create_px_length ( 6 ) ,
@@ -71,7 +87,7 @@ test('offsetX, offsetY and blur: 2px 4px 6px #000', () => {
71
87
test ( 'offsetX, offsetY, blur and spread: 2px 4px 6px 8px #000' , ( ) => {
72
88
expect ( destructure_box_shadow ( '2px 4px 6px 8px #000' ) ) . toEqual ( [
73
89
{
74
- color : '#000' ,
90
+ color : create_color_token ( ) ,
75
91
offsetX : create_px_length ( 2 ) ,
76
92
offsetY : create_px_length ( 4 ) ,
77
93
blur : create_px_length ( 6 ) ,
@@ -84,7 +100,7 @@ test('offsetX, offsetY, blur and spread: 2px 4px 6px 8px #000', () => {
84
100
test ( 'inset: 2px 4px 6px 8px #000 inset' , ( ) => {
85
101
expect ( destructure_box_shadow ( '2px 4px 6px 8px #000 inset' ) ) . toEqual ( [
86
102
{
87
- color : '#000' ,
103
+ color : create_color_token ( ) ,
88
104
offsetX : create_px_length ( 2 ) ,
89
105
offsetY : create_px_length ( 4 ) ,
90
106
blur : create_px_length ( 6 ) ,
@@ -97,7 +113,7 @@ test('inset: 2px 4px 6px 8px #000 inset', () => {
97
113
test ( 'INSET: 2px 4px 6px 8px #000 inset' , ( ) => {
98
114
expect ( destructure_box_shadow ( '2px 4px 6px 8px #000 INSET' ) ) . toEqual ( [
99
115
{
100
- color : '#000' ,
116
+ color : create_color_token ( ) ,
101
117
offsetX : create_px_length ( 2 ) ,
102
118
offsetY : create_px_length ( 4 ) ,
103
119
blur : create_px_length ( 6 ) ,
@@ -110,7 +126,7 @@ test('INSET: 2px 4px 6px 8px #000 inset', () => {
110
126
test ( 'color in a different order: #000 2px 4px 6px 8px' , ( ) => {
111
127
expect ( destructure_box_shadow ( '#000 2px 4px 6px 8px' ) ) . toEqual ( [
112
128
{
113
- color : '#000' ,
129
+ color : create_color_token ( ) ,
114
130
offsetX : create_px_length ( 2 ) ,
115
131
offsetY : create_px_length ( 4 ) ,
116
132
blur : create_px_length ( 6 ) ,
@@ -123,15 +139,15 @@ test('color in a different order: #000 2px 4px 6px 8px', () => {
123
139
test ( 'multiple shadows' , ( ) => {
124
140
expect ( destructure_box_shadow ( '2px 4px 6px 8px #000, 0 0 0 0 #fff inset' ) ) . toEqual ( [
125
141
{
126
- color : '#000' ,
142
+ color : create_color_token ( ) ,
127
143
offsetX : create_px_length ( 2 ) ,
128
144
offsetY : create_px_length ( 4 ) ,
129
145
blur : create_px_length ( 6 ) ,
130
146
spread : create_px_length ( 8 ) ,
131
147
inset : false
132
148
} ,
133
149
{
134
- color : '#fff' ,
150
+ color : color_to_token ( '#fff' ) ,
135
151
offsetX : create_px_length ( 0 ) ,
136
152
offsetY : create_px_length ( 0 ) ,
137
153
blur : create_px_length ( 0 ) ,
@@ -154,7 +170,7 @@ describe('color formats', () => {
154
170
test ( `1px ${ color } ` , ( ) => {
155
171
expect ( destructure_box_shadow ( `1px ${ color } ` ) ) . toEqual ( [
156
172
{
157
- color : color ,
173
+ color : color_to_token ( color ) ,
158
174
offsetX : create_px_length ( 1 ) ,
159
175
offsetY : create_px_length ( 0 ) ,
160
176
blur : create_px_length ( 0 ) ,
0 commit comments