@webstudio-is/css-data 0.91.0 → 0.267.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
@@ -1,89 +0,0 @@
1
- import * as csstree from "css-tree";
2
- import { parseCssValue } from "../parse-css-value";
3
- const gradientNames = [
4
- "conic-gradient",
5
- "linear-gradient",
6
- "radial-gradient",
7
- "repeating-conic-gradient",
8
- "repeating-linear-gradient",
9
- "repeating-radial-gradient"
10
- ];
11
- const parseBackground = (background) => {
12
- const { backgroundImage, backgroundColor: backgroundColorRaw } = backgroundToLonghand(background);
13
- const backgroundColor = backgroundColorRaw ? parseCssValue("backgroundColor", backgroundColorRaw) : void 0;
14
- return {
15
- backgroundImage: parseBackgroundImage(backgroundImage),
16
- backgroundColor: backgroundColor && backgroundColor.type === "rgb" ? backgroundColor : void 0
17
- };
18
- };
19
- const cssTreeTryParseValue = (input) => {
20
- try {
21
- const ast = csstree.parse(input, { context: "value" });
22
- return ast;
23
- } catch {
24
- return void 0;
25
- }
26
- };
27
- const backgroundToLonghand = (background) => {
28
- const layers = [];
29
- let tokenStream = background.trim();
30
- tokenStream = tokenStream.endsWith(";") ? tokenStream.slice(0, -1) : tokenStream;
31
- const cleanupKeywords = ["background:", "background-image:"];
32
- for (const cleanupKeyword of cleanupKeywords) {
33
- tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
34
- }
35
- const cssAst = cssTreeTryParseValue(tokenStream);
36
- if (cssAst === void 0) {
37
- return {
38
- backgroundImage: [],
39
- backgroundColor: void 0
40
- };
41
- }
42
- let backgroundColorRaw;
43
- let nestingLevel = 0;
44
- csstree.walk(cssAst, {
45
- enter: (node, item, list) => {
46
- if (node.type === "Function") {
47
- if (gradientNames.includes(node.name)) {
48
- layers.push(csstree.generate(node));
49
- }
50
- if (item.next === null && nestingLevel === 0) {
51
- backgroundColorRaw = csstree.generate(node);
52
- }
53
- nestingLevel++;
54
- }
55
- if (node.type === "Hash" && item.next === null && nestingLevel === 0) {
56
- backgroundColorRaw = csstree.generate(node);
57
- }
58
- },
59
- leave: (node, item, list) => {
60
- if (node.type === "Function") {
61
- nestingLevel--;
62
- }
63
- }
64
- });
65
- return {
66
- backgroundImage: layers,
67
- backgroundColor: backgroundColorRaw
68
- };
69
- };
70
- const parseBackgroundImage = (layers) => {
71
- const backgroundImages = [];
72
- for (const layer of layers) {
73
- if (gradientNames.some((gradientName) => layer.startsWith(gradientName)) === false) {
74
- break;
75
- }
76
- const layerStyle = parseCssValue("backgroundImage", layer);
77
- if (layerStyle.type !== "unparsed") {
78
- break;
79
- }
80
- backgroundImages.push(layerStyle);
81
- }
82
- return backgroundImages.length > 0 ? { type: "layers", value: backgroundImages } : { type: "invalid", value: layers.join(",") };
83
- };
84
- export {
85
- backgroundToLonghand,
86
- gradientNames,
87
- parseBackground,
88
- parseBackgroundImage
89
- };
@@ -1,99 +0,0 @@
1
- import * as csstree from "css-tree";
2
- import { LayersValue, TupleValue } from "../schema";
3
- import { colord } from "colord";
4
- const cssTreeTryParseValue = (input) => {
5
- try {
6
- const ast = csstree.parse(input, { context: "value" });
7
- return ast;
8
- } catch {
9
- return void 0;
10
- }
11
- };
12
- const parseBoxShadow = (boxShadow) => {
13
- let tokenStream = boxShadow.trim();
14
- tokenStream = tokenStream.endsWith(";") ? tokenStream.slice(0, -1) : tokenStream;
15
- const cleanupKeywords = ["box-shadow:"];
16
- for (const cleanupKeyword of cleanupKeywords) {
17
- tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
18
- }
19
- const cssAst = cssTreeTryParseValue(tokenStream);
20
- if (cssAst === void 0) {
21
- return {
22
- type: "invalid",
23
- value: boxShadow
24
- };
25
- }
26
- const parsed = csstree.lexer.matchProperty("box-shadow", cssAst);
27
- if (parsed.error) {
28
- return {
29
- type: "invalid",
30
- value: boxShadow
31
- };
32
- }
33
- const layers = [];
34
- csstree.walk(cssAst, (node) => {
35
- if (node.type === "Value") {
36
- const children = node.children;
37
- let layer = [];
38
- for (const child of children) {
39
- if (children.last === child) {
40
- layer.push(child);
41
- }
42
- if (child.type === "Operator" || children.last === child) {
43
- const shadow = [];
44
- for (let index = 0; index < layer.length; index++) {
45
- const item = layer[index];
46
- if (item.type === "Identifier") {
47
- shadow.push({
48
- type: "keyword",
49
- value: item.name
50
- });
51
- }
52
- if (item.type === "Function" || item.type === "Hash") {
53
- const colorValue = colord(csstree.generate(item));
54
- if (!colorValue.isValid()) {
55
- return;
56
- }
57
- const rgb = colorValue.toRgb();
58
- shadow.push({
59
- type: "rgb",
60
- alpha: rgb.a,
61
- r: rgb.r,
62
- g: rgb.g,
63
- b: rgb.b
64
- });
65
- }
66
- if (item.type === "Dimension") {
67
- shadow.push({
68
- type: "unit",
69
- value: Number(item.value),
70
- unit: item.unit
71
- });
72
- }
73
- if (item.type === "Number") {
74
- shadow.push({
75
- type: "unit",
76
- value: Number(item.value),
77
- unit: "number"
78
- });
79
- }
80
- }
81
- layers.push({
82
- type: "tuple",
83
- value: shadow
84
- });
85
- layer = [];
86
- continue;
87
- }
88
- layer.push(child);
89
- }
90
- }
91
- });
92
- return layers.length > 0 ? {
93
- type: "layers",
94
- value: layers
95
- } : { type: "invalid", value: boxShadow };
96
- };
97
- export {
98
- parseBoxShadow
99
- };
@@ -1,2 +0,0 @@
1
- export * from "./background";
2
- export * from "./box-shadow";
@@ -1,6 +0,0 @@
1
- import { parseBackgroundImage } from "./background";
2
- import { parseBoxShadow } from "./box-shadow";
3
- export {
4
- parseBackgroundImage as backgroundImage,
5
- parseBoxShadow as boxShadow
6
- };
@@ -1,4 +0,0 @@
1
- import { backgroundToLonghand } from "./background";
2
- export {
3
- backgroundToLonghand as background
4
- };
package/lib/schema.js DELETED
@@ -1,115 +0,0 @@
1
- import { units } from "./__generated__/units";
2
- import { z } from "zod";
3
- const Unit = z.union([
4
- // expected tuple with at least single element
5
- // so cast to tuple with single union element to get correct inference
6
- z.enum(Object.values(units).flat()),
7
- z.literal("number")
8
- ]);
9
- const UnitValue = z.object({
10
- type: z.literal("unit"),
11
- unit: Unit,
12
- value: z.number()
13
- });
14
- const KeywordValue = z.object({
15
- type: z.literal("keyword"),
16
- // @todo use exact type
17
- value: z.string()
18
- });
19
- const UnparsedValue = z.object({
20
- type: z.literal("unparsed"),
21
- value: z.string(),
22
- // For the builder we want to be able to hide background-image
23
- hidden: z.boolean().optional()
24
- });
25
- const FontFamilyValue = z.object({
26
- type: z.literal("fontFamily"),
27
- value: z.array(z.string())
28
- });
29
- const RgbValue = z.object({
30
- type: z.literal("rgb"),
31
- r: z.number(),
32
- g: z.number(),
33
- b: z.number(),
34
- alpha: z.number()
35
- });
36
- const ImageValue = z.object({
37
- type: z.literal("image"),
38
- value: z.union([
39
- z.object({ type: z.literal("asset"), value: z.string() }),
40
- // url is not stored in db and only used by css-engine transformValue
41
- // to prepare image value for rendering
42
- z.object({ type: z.literal("url"), url: z.string() })
43
- ]),
44
- // For the builder we want to be able to hide images
45
- hidden: z.boolean().optional()
46
- });
47
- const InvalidValue = z.object({
48
- type: z.literal("invalid"),
49
- value: z.string()
50
- });
51
- const UnsetValue = z.object({
52
- type: z.literal("unset"),
53
- value: z.literal("")
54
- });
55
- const TupleValueItem = z.union([
56
- UnitValue,
57
- KeywordValue,
58
- UnparsedValue,
59
- RgbValue
60
- ]);
61
- const TupleValue = z.object({
62
- type: z.literal("tuple"),
63
- value: z.array(TupleValueItem),
64
- hidden: z.boolean().optional()
65
- });
66
- const LayerValueItem = z.union([
67
- UnitValue,
68
- KeywordValue,
69
- UnparsedValue,
70
- ImageValue,
71
- TupleValue,
72
- InvalidValue
73
- ]);
74
- const LayersValue = z.object({
75
- type: z.literal("layers"),
76
- value: z.array(LayerValueItem)
77
- });
78
- const ValidStaticStyleValue = z.union([
79
- ImageValue,
80
- LayersValue,
81
- UnitValue,
82
- KeywordValue,
83
- FontFamilyValue,
84
- RgbValue,
85
- UnparsedValue,
86
- TupleValue
87
- ]);
88
- const isValidStaticStyleValue = (styleValue) => {
89
- const staticStyleValue = styleValue;
90
- return staticStyleValue.type === "image" || staticStyleValue.type === "layers" || staticStyleValue.type === "unit" || staticStyleValue.type === "keyword" || staticStyleValue.type === "fontFamily" || staticStyleValue.type === "rgb" || staticStyleValue.type === "unparsed" || staticStyleValue.type === "tuple";
91
- };
92
- const VarValue = z.object({
93
- type: z.literal("var"),
94
- value: z.string(),
95
- fallbacks: z.array(ValidStaticStyleValue)
96
- });
97
- const StyleValue = z.union([
98
- ValidStaticStyleValue,
99
- InvalidValue,
100
- UnsetValue,
101
- VarValue
102
- ]);
103
- const Style = z.record(z.string(), StyleValue);
104
- export {
105
- ImageValue,
106
- InvalidValue,
107
- KeywordValue,
108
- LayersValue,
109
- StyleValue,
110
- TupleValue,
111
- TupleValueItem,
112
- UnitValue,
113
- UnparsedValue,
114
- isValidStaticStyleValue
115
- };
@@ -1,15 +0,0 @@
1
- import type { StyleValue } from "./schema";
2
- type RawPropertyData = {
3
- unitGroups: string[];
4
- inherited: boolean;
5
- initial: StyleValue;
6
- popularity: number;
7
- appliesTo: string;
8
- };
9
- export declare const propertiesData: {
10
- [property: string]: RawPropertyData;
11
- };
12
- export declare const keywordValues: {
13
- [property: string]: Array<string>;
14
- };
15
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- import type { htmlTags as HtmlTags } from "html-tags";
2
- import type { StyleProperty, StyleValue } from "./schema";
3
- type StyleDecl = {
4
- property: StyleProperty;
5
- value: StyleValue;
6
- };
7
- type Styles = StyleDecl[];
8
- export type Html = {
9
- [tag in HtmlTags]?: Styles;
10
- };
11
- export declare const article: Styles;
12
- export { article as aside, article as details, article as div, article as dt, article as figcaption, article as footer, article as form, article as header, article as hgroup, article as html, article as main, article as nav, article as section, article as summary, };
13
- export declare const body: Styles;
14
- export declare const p: Styles;
15
- export { p as dl };
16
- export declare const dd: Styles;
17
- export declare const blockquote: Styles;
18
- export { blockquote as figure };
19
- export declare const address: Styles;
20
- export declare const h1: Styles;
21
- export declare const h2: Styles;
22
- export declare const h3: Styles;
23
- export declare const h4: Styles;
24
- export declare const h5: Styles;
25
- export declare const h6: Styles;
26
- export declare const pre: Styles;
27
- export declare const table: Styles;
28
- export declare const caption: Styles;
29
- export declare const tr: Styles;
30
- export declare const col: Styles;
31
- export declare const colgroup: Styles;
32
- export declare const tbody: Styles;
33
- export declare const thead: Styles;
34
- export declare const tfoot: Styles;
35
- export declare const td: Styles;
36
- export declare const th: Styles;
37
- export declare const b: Styles;
38
- export { b as strong };
39
- export declare const i: Styles;
40
- export { i as cite, i as em, i as var, i as dfn };
41
- export declare const code: Styles;
42
- export { code as kbd, code as samp };
43
- export declare const mark: Styles;
44
- export declare const u: Styles;
45
- export { u as ins };
46
- export declare const s: Styles;
47
- export { s as del };
48
- export declare const sub: Styles;
49
- export declare const sup: Styles;
50
- export declare const a: Styles;
51
- export declare const ul: Styles;
52
- export declare const ol: Styles;
53
- export declare const li: Styles;
54
- export declare const hr: Styles;
55
- export declare const legend: Styles;
56
- export declare const fieldset: Styles;
57
- export declare const label: Styles;
58
- export declare const input: Styles;
59
- export declare const textarea: Styles;
60
- export declare const select: Styles;
61
- export declare const option: Styles;
62
- export declare const button: Styles;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export declare const popularityIndex: {
2
- bucketId: number;
3
- date: string;
4
- dayPercentage: number;
5
- property: string;
6
- }[];
@@ -1,11 +0,0 @@
1
- import type { InvalidValue, LayersValue, RgbValue } from "../schema";
2
- export declare const gradientNames: string[];
3
- export declare const parseBackground: (background: string) => {
4
- backgroundImage: LayersValue | InvalidValue;
5
- backgroundColor: RgbValue | undefined;
6
- };
7
- export declare const backgroundToLonghand: (background: string) => {
8
- backgroundImage: string[];
9
- backgroundColor: string | undefined;
10
- };
11
- export declare const parseBackgroundImage: (layers: string[]) => LayersValue | InvalidValue;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { LayersValue } from "../schema";
2
- import type { InvalidValue } from "../schema";
3
- export declare const parseBoxShadow: (boxShadow: string) => LayersValue | InvalidValue;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export { parseBackgroundImage as backgroundImage } from "./background";
2
- export { parseBoxShadow as boxShadow } from "./box-shadow";
@@ -1 +0,0 @@
1
- export { backgroundToLonghand as background } from "./background";