@webstudio-is/css-data 0.91.0 → 0.266.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.
Files changed (95) hide show
  1. package/lib/index.js +17534 -15
  2. package/lib/types/__generated__/animatable-properties.d.ts +1 -0
  3. package/lib/types/__generated__/html.d.ts +2 -0
  4. package/lib/types/__generated__/keyword-values.d.ts +4 -358
  5. package/lib/types/__generated__/properties.d.ts +10 -3674
  6. package/lib/types/__generated__/property-value-descriptions.d.ts +7 -5446
  7. package/lib/types/__generated__/pseudo-classes.d.ts +1 -0
  8. package/lib/types/__generated__/pseudo-elements.d.ts +1 -0
  9. package/lib/types/__generated__/pseudo-selector-descriptions.d.ts +2 -0
  10. package/lib/types/__generated__/shorthand-properties.d.ts +1 -0
  11. package/lib/types/css-tree.d.ts +772 -0
  12. package/lib/types/index.d.ts +18 -3680
  13. package/lib/types/media-condition-simulator.d.ts +7 -0
  14. package/lib/types/parse-css-value.d.ts +8 -3
  15. package/lib/types/parse-css.d.ts +75 -6
  16. package/lib/types/property-parsers/conic-gradient.d.ts +3 -0
  17. package/lib/types/property-parsers/gradient-utils.d.ts +20 -0
  18. package/lib/types/property-parsers/grid-template-areas.d.ts +21 -0
  19. package/lib/types/property-parsers/grid-template-tracks.d.ts +128 -0
  20. package/lib/types/property-parsers/index.d.ts +6 -2
  21. package/lib/types/property-parsers/linear-gradient.d.ts +4 -0
  22. package/lib/types/property-parsers/radial-gradient.d.ts +3 -0
  23. package/lib/types/property-parsers/types.d.ts +28 -0
  24. package/lib/types/selector-validation.d.ts +13 -0
  25. package/lib/types/shorthands.d.ts +2 -0
  26. package/package.json +29 -33
  27. package/lib/__generated__/keyword-values.js +0 -5255
  28. package/lib/__generated__/properties.js +0 -3697
  29. package/lib/__generated__/property-value-descriptions.js +0 -2740
  30. package/lib/__generated__/units.js +0 -65
  31. package/lib/cjs/__generated__/keyword-values.js +0 -5275
  32. package/lib/cjs/__generated__/properties.js +0 -3717
  33. package/lib/cjs/__generated__/property-value-descriptions.js +0 -2760
  34. package/lib/cjs/__generated__/units.js +0 -85
  35. package/lib/cjs/custom-data.js +0 -64
  36. package/lib/cjs/html-check.js +0 -25
  37. package/lib/cjs/html.js +0 -581
  38. package/lib/cjs/index.js +0 -48
  39. package/lib/cjs/package.json +0 -1
  40. package/lib/cjs/parse-css-value.js +0 -152
  41. package/lib/cjs/parse-css.js +0 -136
  42. package/lib/cjs/popularity-index.js +0 -4633
  43. package/lib/cjs/property-parsers/background.js +0 -119
  44. package/lib/cjs/property-parsers/box-shadow.js +0 -129
  45. package/lib/cjs/property-parsers/index.js +0 -19
  46. package/lib/cjs/property-parsers/parsers.js +0 -26
  47. package/lib/cjs/property-parsers/to-longhand.js +0 -24
  48. package/lib/cjs/schema.js +0 -135
  49. package/lib/custom-data.js +0 -44
  50. package/lib/html-check.js +0 -2
  51. package/lib/html.js +0 -561
  52. package/lib/parse-css-value.js +0 -122
  53. package/lib/parse-css.js +0 -106
  54. package/lib/popularity-index.js +0 -4613
  55. package/lib/property-parsers/background.js +0 -89
  56. package/lib/property-parsers/box-shadow.js +0 -99
  57. package/lib/property-parsers/index.js +0 -2
  58. package/lib/property-parsers/parsers.js +0 -6
  59. package/lib/property-parsers/to-longhand.js +0 -4
  60. package/lib/schema.js +0 -115
  61. package/lib/types/custom-data.d.ts +0 -15
  62. package/lib/types/html-check.d.ts +0 -1
  63. package/lib/types/html.d.ts +0 -62
  64. package/lib/types/parse-css-value.test.d.ts +0 -1
  65. package/lib/types/parse-css.test.d.ts +0 -1
  66. package/lib/types/popularity-index.d.ts +0 -6
  67. package/lib/types/property-parsers/background.d.ts +0 -11
  68. package/lib/types/property-parsers/background.test.d.ts +0 -1
  69. package/lib/types/property-parsers/box-shadow.d.ts +0 -3
  70. package/lib/types/property-parsers/box-shadow.test.d.ts +0 -1
  71. package/lib/types/property-parsers/parsers.d.ts +0 -2
  72. package/lib/types/property-parsers/to-longhand.d.ts +0 -1
  73. package/lib/types/schema.d.ts +0 -3243
  74. package/src/__generated__/keyword-values.ts +0 -5253
  75. package/src/__generated__/properties.ts +0 -3696
  76. package/src/__generated__/property-value-descriptions.ts +0 -4008
  77. package/src/__generated__/units.ts +0 -63
  78. package/src/custom-data.ts +0 -57
  79. package/src/html-check.ts +0 -8
  80. package/src/html.ts +0 -617
  81. package/src/index.ts +0 -25
  82. package/src/parse-css-value.test.ts +0 -136
  83. package/src/parse-css-value.ts +0 -157
  84. package/src/parse-css.test.ts +0 -101
  85. package/src/parse-css.ts +0 -137
  86. package/src/popularity-index.ts +0 -4611
  87. package/src/property-parsers/README.md +0 -11
  88. package/src/property-parsers/background.test.ts +0 -184
  89. package/src/property-parsers/background.ts +0 -147
  90. package/src/property-parsers/box-shadow.test.ts +0 -294
  91. package/src/property-parsers/box-shadow.ts +0 -130
  92. package/src/property-parsers/index.ts +0 -2
  93. package/src/property-parsers/parsers.ts +0 -5
  94. package/src/property-parsers/to-longhand.ts +0 -4
  95. package/src/schema.ts +0 -193
package/lib/html.js DELETED
@@ -1,561 +0,0 @@
1
- const display = (value) => ({
2
- property: "display",
3
- value: { type: "keyword", value }
4
- });
5
- const marginTop = (value, unit) => ({
6
- property: "marginTop",
7
- value: { type: "unit", value, unit: unit ?? "number" }
8
- });
9
- const marginRight = (value, unit) => ({
10
- property: "marginRight",
11
- value: { type: "unit", value, unit: unit ?? "number" }
12
- });
13
- const marginBottom = (value, unit) => ({
14
- property: "marginBottom",
15
- value: { type: "unit", value, unit: unit ?? "number" }
16
- });
17
- const marginLeft = (value, unit) => ({
18
- property: "marginLeft",
19
- value: { type: "unit", value, unit: unit ?? "number" }
20
- });
21
- const paddingTop = (value, unit) => ({
22
- property: "paddingTop",
23
- value: { type: "unit", value, unit }
24
- });
25
- const paddingRight = (value, unit) => ({
26
- property: "paddingRight",
27
- value: { type: "unit", value, unit }
28
- });
29
- const paddingBottom = (value, unit) => ({
30
- property: "paddingBottom",
31
- value: { type: "unit", value, unit }
32
- });
33
- const paddingLeft = (value, unit) => ({
34
- property: "paddingLeft",
35
- value: { type: "unit", value, unit }
36
- });
37
- const color = (value) => ({
38
- property: "color",
39
- value: { type: "keyword", value }
40
- });
41
- const fontSize = (value, unit) => ({
42
- property: "fontSize",
43
- value: { type: "unit", value, unit }
44
- });
45
- const fontWeight = (value) => ({
46
- property: "fontWeight",
47
- value: { type: "keyword", value }
48
- });
49
- const fontStyle = (value) => ({
50
- property: "fontStyle",
51
- value: { type: "keyword", value }
52
- });
53
- const textAlign = (value) => ({
54
- property: "textAlign",
55
- value: { type: "keyword", value }
56
- });
57
- const verticalAlign = (value) => ({
58
- property: "verticalAlign",
59
- value: { type: "keyword", value }
60
- });
61
- const whiteSpace = (value) => ({
62
- property: "whiteSpace",
63
- value: { type: "keyword", value }
64
- });
65
- const cursor = (value) => ({
66
- property: "cursor",
67
- value: { type: "keyword", value }
68
- });
69
- const borderWidth = (value, unit) => [
70
- {
71
- property: "borderTopWidth",
72
- value: { type: "unit", value, unit }
73
- },
74
- {
75
- property: "borderRightWidth",
76
- value: { type: "unit", value, unit }
77
- },
78
- {
79
- property: "borderBottomWidth",
80
- value: { type: "unit", value, unit }
81
- },
82
- {
83
- property: "borderLeftWidth",
84
- value: { type: "unit", value, unit }
85
- }
86
- ];
87
- const borderStyle = (value) => [
88
- {
89
- property: "borderTopStyle",
90
- value: { type: "keyword", value }
91
- },
92
- {
93
- property: "borderRightStyle",
94
- value: { type: "keyword", value }
95
- },
96
- {
97
- property: "borderBottomStyle",
98
- value: { type: "keyword", value }
99
- },
100
- {
101
- property: "borderLeftStyle",
102
- value: { type: "keyword", value }
103
- }
104
- ];
105
- const borderColor = (value) => [
106
- {
107
- property: "borderTopColor",
108
- value: { type: "keyword", value }
109
- },
110
- {
111
- property: "borderRightColor",
112
- value: { type: "keyword", value }
113
- },
114
- {
115
- property: "borderBottomColor",
116
- value: { type: "keyword", value }
117
- },
118
- {
119
- property: "borderLeftColor",
120
- value: { type: "keyword", value }
121
- }
122
- ];
123
- const appearance = (value) => ({
124
- property: "appearance",
125
- value: { type: "keyword", value }
126
- });
127
- const userSelect = (value) => ({
128
- property: "userSelect",
129
- value: { type: "keyword", value }
130
- });
131
- const boxSizing = (value) => ({
132
- property: "boxSizing",
133
- value: { type: "keyword", value }
134
- });
135
- const article = [display("block")];
136
- const body = [
137
- display("block"),
138
- marginTop(8, "px"),
139
- marginRight(8, "px"),
140
- marginBottom(8, "px"),
141
- marginLeft(8, "px")
142
- ];
143
- const p = [
144
- display("block"),
145
- marginTop(1, "em"),
146
- marginBottom(1, "em")
147
- ];
148
- const dd = [display("block"), marginLeft(40, "px")];
149
- const blockquote = [
150
- display("block"),
151
- marginTop(1, "em"),
152
- marginBottom(1, "em"),
153
- marginLeft(40, "px"),
154
- marginRight(40, "px")
155
- ];
156
- const address = [display("block"), fontStyle("italic")];
157
- const h1 = [
158
- display("block"),
159
- fontWeight("bold"),
160
- fontSize(2, "em"),
161
- marginTop(0.67, "em"),
162
- marginBottom(0.67, "em")
163
- ];
164
- const h2 = [
165
- display("block"),
166
- fontWeight("bold"),
167
- fontSize(1.5, "em"),
168
- marginTop(0.83, "em"),
169
- marginBottom(0.83, "em")
170
- ];
171
- const h3 = [
172
- display("block"),
173
- fontWeight("bold"),
174
- fontSize(1.17, "em"),
175
- marginTop(1, "em"),
176
- marginBottom(1, "em")
177
- ];
178
- const h4 = [
179
- display("block"),
180
- fontWeight("bold"),
181
- marginTop(1.33, "em"),
182
- marginBottom(1.33, "em")
183
- ];
184
- const h5 = [
185
- display("block"),
186
- fontWeight("bold"),
187
- fontSize(0.83, "em"),
188
- marginTop(1.67, "em"),
189
- marginBottom(1.67, "em")
190
- ];
191
- const h6 = [
192
- display("block"),
193
- fontWeight("bold"),
194
- fontSize(0.67, "em"),
195
- marginTop(2.33, "em"),
196
- marginBottom(2.33, "em")
197
- ];
198
- const pre = [
199
- display("block"),
200
- whiteSpace("pre"),
201
- marginTop(1, "em"),
202
- marginBottom(1, "em")
203
- ];
204
- const table = [
205
- display("table"),
206
- {
207
- property: "borderSpacing",
208
- value: { type: "unit", value: 2, unit: "px" }
209
- },
210
- {
211
- property: "borderCollapse",
212
- value: { type: "keyword", value: "separate" }
213
- },
214
- boxSizing("border-box"),
215
- {
216
- property: "textIndent",
217
- value: { type: "unit", value: 0, unit: "number" }
218
- }
219
- ];
220
- const caption = [display("table-caption"), textAlign("center")];
221
- const tr = [display("table-row"), verticalAlign("inherit")];
222
- const col = [display("table-column")];
223
- const colgroup = [display("table-column-group")];
224
- const tbody = [
225
- display("table-row-group"),
226
- verticalAlign("middle")
227
- ];
228
- const thead = [
229
- display("table-header-group"),
230
- verticalAlign("middle")
231
- ];
232
- const tfoot = [
233
- display("table-footer-group"),
234
- verticalAlign("middle")
235
- ];
236
- const td = [
237
- display("table-cell"),
238
- verticalAlign("inherit"),
239
- paddingTop(1, "px"),
240
- paddingRight(1, "px"),
241
- paddingBottom(1, "px"),
242
- paddingLeft(1, "px")
243
- ];
244
- const th = [
245
- display("table-cell"),
246
- verticalAlign("inherit"),
247
- fontWeight("bold"),
248
- paddingTop(1, "px"),
249
- paddingRight(1, "px"),
250
- paddingBottom(1, "px"),
251
- paddingLeft(1, "px")
252
- ];
253
- const b = [
254
- // in firefox defined as bolder
255
- fontWeight("bold")
256
- ];
257
- const i = [fontStyle("italic")];
258
- const code = [
259
- {
260
- property: "fontFamily",
261
- // in firefox defined as -moz-fixed
262
- value: { type: "fontFamily", value: ["monospace"] }
263
- }
264
- ];
265
- const mark = [
266
- {
267
- property: "backgroundColor",
268
- // in firefox defined as Mark
269
- value: { type: "keyword", value: "yellow" }
270
- },
271
- // in firefox defined as MarkText
272
- color("black")
273
- ];
274
- const u = [
275
- {
276
- property: "textDecorationStyle",
277
- value: { type: "keyword", value: "underline" }
278
- }
279
- ];
280
- const s = [
281
- {
282
- property: "textDecorationStyle",
283
- value: { type: "keyword", value: "line-through" }
284
- }
285
- ];
286
- const sub = [
287
- verticalAlign("sub"),
288
- {
289
- property: "fontSize",
290
- value: { type: "keyword", value: "smaller" }
291
- }
292
- ];
293
- const sup = [
294
- verticalAlign("super"),
295
- {
296
- property: "fontSize",
297
- value: { type: "keyword", value: "smaller" }
298
- }
299
- ];
300
- const a = [
301
- {
302
- property: "textDecorationLine",
303
- value: { type: "keyword", value: "underline" }
304
- },
305
- cursor("pointer"),
306
- {
307
- property: "color",
308
- value: { type: "rgb", r: 0, g: 0, b: 238, alpha: 1 }
309
- }
310
- // active and visited states are not defined as usually overriden with stateless color
311
- // and modeling var-like defaults is too complex
312
- ];
313
- const ul = [
314
- display("block"),
315
- {
316
- property: "listStyleType",
317
- value: { type: "keyword", value: "disc" }
318
- },
319
- marginTop(1, "em"),
320
- marginBottom(1, "em"),
321
- paddingLeft(40, "px")
322
- ];
323
- const ol = [
324
- display("block"),
325
- {
326
- property: "listStyleType",
327
- value: { type: "keyword", value: "decimal" }
328
- },
329
- marginTop(1, "em"),
330
- marginBottom(1, "em"),
331
- paddingLeft(40, "px")
332
- ];
333
- const li = [display("list-item"), textAlign("match-parent")];
334
- const hr = [
335
- color("gray"),
336
- ...borderWidth(1, "px"),
337
- ...borderStyle("inset"),
338
- marginTop(0.5, "em"),
339
- marginBottom(0.5, "em"),
340
- {
341
- property: "marginLeft",
342
- value: { type: "keyword", value: "auto" }
343
- },
344
- {
345
- property: "marginRight",
346
- value: { type: "keyword", value: "auto" }
347
- },
348
- // firefox only
349
- {
350
- property: "overflow",
351
- value: { type: "keyword", value: "hidden" }
352
- },
353
- /* This is not really per spec but all browsers define it */
354
- display("block")
355
- ];
356
- const formControlReset = [
357
- // in firefox defined as FieldText
358
- color("initial"),
359
- { property: "letterSpacing", value: { type: "keyword", value: "normal" } },
360
- { property: "wordSpacing", value: { type: "keyword", value: "normal" } },
361
- { property: "lineHeight", value: { type: "keyword", value: "normal" } },
362
- { property: "textTransform", value: { type: "keyword", value: "none" } },
363
- { property: "textIndent", value: { type: "unit", value: 0, unit: "number" } },
364
- { property: "textShadow", value: { type: "keyword", value: "none" } },
365
- display("inline-block"),
366
- textAlign("start")
367
- ];
368
- const legend = [
369
- display("block"),
370
- paddingLeft(2, "px"),
371
- paddingRight(2, "px")
372
- ];
373
- const fieldset = [
374
- display("block"),
375
- marginLeft(2, "px"),
376
- marginRight(2, "px"),
377
- paddingTop(0.35, "em"),
378
- paddingBottom(0.625, "em"),
379
- paddingLeft(0.75, "em"),
380
- paddingRight(0.75, "em"),
381
- ...borderWidth(2, "px"),
382
- // in browsers defined as groove
383
- ...borderStyle("solid"),
384
- ...borderColor("ThreeDFace"),
385
- { property: "minWidth", value: { type: "keyword", value: "min-content" } }
386
- ];
387
- const label = [cursor("default")];
388
- const input = [
389
- appearance("auto"),
390
- paddingTop(1, "px"),
391
- paddingRight(1, "px"),
392
- paddingBottom(1, "px"),
393
- paddingLeft(1, "px"),
394
- ...borderWidth(2, "px"),
395
- // in browsers defined as inset
396
- ...borderStyle("solid"),
397
- // in firefox defined as Field
398
- { property: "backgroundColor", value: { type: "keyword", value: "white" } },
399
- cursor("text")
400
- ];
401
- const textarea = [
402
- ...formControlReset,
403
- appearance("auto"),
404
- marginTop(1, "px"),
405
- marginBottom(1, "px"),
406
- // in firefox 2px
407
- ...borderWidth(1, "px"),
408
- // in browsers defined as inset
409
- ...borderStyle("solid"),
410
- paddingTop(2, "px"),
411
- paddingRight(2, "px"),
412
- paddingBottom(2, "px"),
413
- paddingLeft(2, "px"),
414
- // in firefox defined as Field
415
- { property: "backgroundColor", value: { type: "keyword", value: "white" } },
416
- verticalAlign("text-bottom"),
417
- cursor("text"),
418
- { property: "resize", value: { type: "keyword", value: "both" } },
419
- whiteSpace("pre-wrap"),
420
- {
421
- property: "wordWrap",
422
- value: { type: "keyword", value: "break-word" }
423
- }
424
- ];
425
- const select = [
426
- ...formControlReset,
427
- display("inline-block"),
428
- marginTop(0),
429
- marginRight(0),
430
- marginBottom(0),
431
- marginLeft(0),
432
- paddingTop(1, "px"),
433
- paddingBottom(1, "px"),
434
- paddingRight(4, "px"),
435
- paddingLeft(4, "px"),
436
- ...borderWidth(2, "px"),
437
- // in browsers defined as inset
438
- ...borderStyle("solid"),
439
- whiteSpace("nowrap"),
440
- {
441
- property: "wordWrap",
442
- value: { type: "keyword", value: "normal" }
443
- },
444
- cursor("default"),
445
- boxSizing("border-box"),
446
- userSelect("none"),
447
- {
448
- property: "overflow",
449
- value: { type: "keyword", value: "clip" }
450
- },
451
- verticalAlign("baseline"),
452
- appearance("auto")
453
- ];
454
- const option = [
455
- display("block"),
456
- { property: "float", value: { type: "keyword", value: "none" } },
457
- { property: "position", value: { type: "keyword", value: "static" } },
458
- { property: "minHeight", value: { type: "unit", value: 1, unit: "em" } },
459
- paddingTop(2, "px"),
460
- paddingBottom(2, "px"),
461
- paddingRight(2, "px"),
462
- paddingLeft(4, "px"),
463
- userSelect("none"),
464
- whiteSpace("nowrap"),
465
- {
466
- property: "wordWrap",
467
- value: { type: "keyword", value: "normal" }
468
- }
469
- ];
470
- const button = [
471
- ...formControlReset,
472
- appearance("auto"),
473
- // in firefox defined as 1px 8px
474
- paddingTop(2, "px"),
475
- paddingBottom(3, "px"),
476
- paddingLeft(6, "px"),
477
- paddingRight(6, "px"),
478
- ...borderWidth(2, "px"),
479
- // in browsers defined as outset
480
- ...borderStyle("solid"),
481
- cursor("default"),
482
- boxSizing("border-box"),
483
- userSelect("none"),
484
- textAlign("center"),
485
- {
486
- property: "backgroundColor",
487
- // in browsers defined as ButtonFace
488
- value: { type: "keyword", value: "lightgray" }
489
- }
490
- ];
491
- export {
492
- a,
493
- address,
494
- article,
495
- article as aside,
496
- b,
497
- blockquote,
498
- body,
499
- button,
500
- caption,
501
- i as cite,
502
- code,
503
- col,
504
- colgroup,
505
- dd,
506
- s as del,
507
- article as details,
508
- i as dfn,
509
- article as div,
510
- p as dl,
511
- article as dt,
512
- i as em,
513
- fieldset,
514
- article as figcaption,
515
- blockquote as figure,
516
- article as footer,
517
- article as form,
518
- h1,
519
- h2,
520
- h3,
521
- h4,
522
- h5,
523
- h6,
524
- article as header,
525
- article as hgroup,
526
- hr,
527
- article as html,
528
- i,
529
- input,
530
- u as ins,
531
- code as kbd,
532
- label,
533
- legend,
534
- li,
535
- article as main,
536
- mark,
537
- article as nav,
538
- ol,
539
- option,
540
- p,
541
- pre,
542
- s,
543
- code as samp,
544
- article as section,
545
- select,
546
- b as strong,
547
- sub,
548
- article as summary,
549
- sup,
550
- table,
551
- tbody,
552
- td,
553
- textarea,
554
- tfoot,
555
- th,
556
- thead,
557
- tr,
558
- u,
559
- ul,
560
- i as var
561
- };
@@ -1,122 +0,0 @@
1
- import { colord } from "colord";
2
- import * as csstree from "css-tree";
3
- import hyphenate from "hyphenate-style-name";
4
- import warnOnce from "warn-once";
5
- import { keywordValues } from "./__generated__/keyword-values";
6
- import { units } from "./__generated__/units";
7
- const cssTryParseValue = (input) => {
8
- try {
9
- const ast = csstree.parse(input, { context: "value" });
10
- return ast;
11
- } catch {
12
- return void 0;
13
- }
14
- };
15
- const isValidDeclaration = (property, value) => {
16
- const ast = cssTryParseValue(value);
17
- if (ast == null) {
18
- return false;
19
- }
20
- const cssPropertyName = hyphenate(property);
21
- const matchResult = csstree.lexer.matchProperty(cssPropertyName, ast);
22
- const isValidDeclaration2 = matchResult.matched != null;
23
- if (isValidDeclaration2 && typeof CSSStyleValue !== "undefined") {
24
- try {
25
- CSSStyleValue.parse(cssPropertyName, value);
26
- } catch {
27
- warnOnce(
28
- true,
29
- `Css property "${property}" with value "${value}" is invalid according to CSSStyleValue.parse
30
- but valid according to csstree.lexer.matchProperty.`
31
- );
32
- return false;
33
- }
34
- }
35
- return isValidDeclaration2;
36
- };
37
- const parseCssValue = (property, input) => {
38
- const invalidValue = {
39
- type: "invalid",
40
- value: input
41
- };
42
- if (input.length === 0) {
43
- return invalidValue;
44
- }
45
- if (!isValidDeclaration(property, input)) {
46
- return invalidValue;
47
- }
48
- const ast = cssTryParseValue(input);
49
- if (ast == null) {
50
- warnOnce(
51
- true,
52
- `Can't parse css property "${property}" with value "${input}"`
53
- );
54
- return invalidValue;
55
- }
56
- if (ast != null && ast.type === "Value" && ast.children.first === ast.children.last) {
57
- const first = ast.children.first;
58
- if (first?.type === "Number") {
59
- return {
60
- type: "unit",
61
- unit: "number",
62
- value: Number(first.value)
63
- };
64
- }
65
- if (first?.type === "Dimension") {
66
- const unit = first.unit;
67
- for (const unitGroup of Object.values(units)) {
68
- if (unitGroup.includes(unit)) {
69
- return {
70
- type: "unit",
71
- unit,
72
- value: Number(first.value)
73
- };
74
- }
75
- }
76
- return invalidValue;
77
- }
78
- if (first?.type === "Percentage") {
79
- return {
80
- type: "unit",
81
- unit: "%",
82
- value: Number(first.value)
83
- };
84
- }
85
- if (first?.type === "Identifier") {
86
- const values = keywordValues[property];
87
- const lettersRegex = /[^a-zA-Z]+/g;
88
- const searchValues = values.map(
89
- (value) => value.replace(lettersRegex, "").toLowerCase()
90
- );
91
- const keywordInput = input.replace(lettersRegex, "").toLowerCase();
92
- const index = searchValues.indexOf(keywordInput);
93
- if (index > -1) {
94
- return {
95
- type: "keyword",
96
- value: values[index]
97
- };
98
- }
99
- }
100
- }
101
- if (property.toLocaleLowerCase().includes("color")) {
102
- const mayBeColor = colord(input);
103
- if (mayBeColor.isValid()) {
104
- const rgb = mayBeColor.toRgb();
105
- return {
106
- type: "rgb",
107
- alpha: rgb.a,
108
- r: rgb.r,
109
- g: rgb.g,
110
- b: rgb.b
111
- };
112
- }
113
- }
114
- return {
115
- type: "unparsed",
116
- value: input
117
- };
118
- };
119
- export {
120
- isValidDeclaration,
121
- parseCssValue
122
- };