@webstudio-is/css-data 0.90.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.
- package/lib/index.js +17534 -15
- package/lib/types/__generated__/animatable-properties.d.ts +1 -0
- package/lib/types/__generated__/html.d.ts +2 -0
- package/lib/types/__generated__/keyword-values.d.ts +4 -358
- package/lib/types/__generated__/properties.d.ts +10 -3674
- package/lib/types/__generated__/property-value-descriptions.d.ts +7 -5446
- package/lib/types/__generated__/pseudo-classes.d.ts +1 -0
- package/lib/types/__generated__/pseudo-elements.d.ts +1 -0
- package/lib/types/__generated__/pseudo-selector-descriptions.d.ts +2 -0
- package/lib/types/__generated__/shorthand-properties.d.ts +1 -0
- package/lib/types/css-tree.d.ts +772 -0
- package/lib/types/index.d.ts +18 -3680
- package/lib/types/media-condition-simulator.d.ts +7 -0
- package/lib/types/parse-css-value.d.ts +8 -3
- package/lib/types/parse-css.d.ts +75 -6
- package/lib/types/property-parsers/conic-gradient.d.ts +3 -0
- package/lib/types/property-parsers/gradient-utils.d.ts +20 -0
- package/lib/types/property-parsers/grid-template-areas.d.ts +21 -0
- package/lib/types/property-parsers/grid-template-tracks.d.ts +128 -0
- package/lib/types/property-parsers/index.d.ts +6 -2
- package/lib/types/property-parsers/linear-gradient.d.ts +4 -0
- package/lib/types/property-parsers/radial-gradient.d.ts +3 -0
- package/lib/types/property-parsers/types.d.ts +28 -0
- package/lib/types/selector-validation.d.ts +13 -0
- package/lib/types/shorthands.d.ts +2 -0
- package/package.json +29 -33
- package/lib/__generated__/keyword-values.js +0 -5255
- package/lib/__generated__/properties.js +0 -3697
- package/lib/__generated__/property-value-descriptions.js +0 -2740
- package/lib/__generated__/units.js +0 -65
- package/lib/cjs/__generated__/keyword-values.js +0 -5275
- package/lib/cjs/__generated__/properties.js +0 -3717
- package/lib/cjs/__generated__/property-value-descriptions.js +0 -2760
- package/lib/cjs/__generated__/units.js +0 -85
- package/lib/cjs/custom-data.js +0 -64
- package/lib/cjs/html-check.js +0 -25
- package/lib/cjs/html.js +0 -581
- package/lib/cjs/index.js +0 -48
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/parse-css-value.js +0 -152
- package/lib/cjs/parse-css.js +0 -136
- package/lib/cjs/popularity-index.js +0 -4633
- package/lib/cjs/property-parsers/background.js +0 -119
- package/lib/cjs/property-parsers/box-shadow.js +0 -129
- package/lib/cjs/property-parsers/index.js +0 -19
- package/lib/cjs/property-parsers/parsers.js +0 -26
- package/lib/cjs/property-parsers/to-longhand.js +0 -24
- package/lib/cjs/schema.js +0 -135
- package/lib/custom-data.js +0 -44
- package/lib/html-check.js +0 -2
- package/lib/html.js +0 -561
- package/lib/parse-css-value.js +0 -122
- package/lib/parse-css.js +0 -106
- package/lib/popularity-index.js +0 -4613
- package/lib/property-parsers/background.js +0 -89
- package/lib/property-parsers/box-shadow.js +0 -99
- package/lib/property-parsers/index.js +0 -2
- package/lib/property-parsers/parsers.js +0 -6
- package/lib/property-parsers/to-longhand.js +0 -4
- package/lib/schema.js +0 -115
- package/lib/types/custom-data.d.ts +0 -15
- package/lib/types/html-check.d.ts +0 -1
- package/lib/types/html.d.ts +0 -62
- package/lib/types/parse-css-value.test.d.ts +0 -1
- package/lib/types/parse-css.test.d.ts +0 -1
- package/lib/types/popularity-index.d.ts +0 -6
- package/lib/types/property-parsers/background.d.ts +0 -11
- package/lib/types/property-parsers/background.test.d.ts +0 -1
- package/lib/types/property-parsers/box-shadow.d.ts +0 -3
- package/lib/types/property-parsers/box-shadow.test.d.ts +0 -1
- package/lib/types/property-parsers/parsers.d.ts +0 -2
- package/lib/types/property-parsers/to-longhand.d.ts +0 -1
- package/lib/types/schema.d.ts +0 -3243
- package/src/__generated__/keyword-values.ts +0 -5253
- package/src/__generated__/properties.ts +0 -3696
- package/src/__generated__/property-value-descriptions.ts +0 -4008
- package/src/__generated__/units.ts +0 -63
- package/src/custom-data.ts +0 -57
- package/src/html-check.ts +0 -8
- package/src/html.ts +0 -617
- package/src/index.ts +0 -25
- package/src/parse-css-value.test.ts +0 -136
- package/src/parse-css-value.ts +0 -157
- package/src/parse-css.test.ts +0 -101
- package/src/parse-css.ts +0 -137
- package/src/popularity-index.ts +0 -4611
- package/src/property-parsers/README.md +0 -11
- package/src/property-parsers/background.test.ts +0 -184
- package/src/property-parsers/background.ts +0 -147
- package/src/property-parsers/box-shadow.test.ts +0 -294
- package/src/property-parsers/box-shadow.ts +0 -130
- package/src/property-parsers/index.ts +0 -2
- package/src/property-parsers/parsers.ts +0 -5
- package/src/property-parsers/to-longhand.ts +0 -4
- package/src/schema.ts +0 -193
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var parse_css_value_exports = {};
|
|
30
|
-
__export(parse_css_value_exports, {
|
|
31
|
-
isValidDeclaration: () => isValidDeclaration,
|
|
32
|
-
parseCssValue: () => parseCssValue
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(parse_css_value_exports);
|
|
35
|
-
var import_colord = require("colord");
|
|
36
|
-
var csstree = __toESM(require("css-tree"), 1);
|
|
37
|
-
var import_hyphenate_style_name = __toESM(require("hyphenate-style-name"), 1);
|
|
38
|
-
var import_warn_once = __toESM(require("warn-once"), 1);
|
|
39
|
-
var import_keyword_values = require("./__generated__/keyword-values");
|
|
40
|
-
var import_units = require("./__generated__/units");
|
|
41
|
-
const cssTryParseValue = (input) => {
|
|
42
|
-
try {
|
|
43
|
-
const ast = csstree.parse(input, { context: "value" });
|
|
44
|
-
return ast;
|
|
45
|
-
} catch {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const isValidDeclaration = (property, value) => {
|
|
50
|
-
const ast = cssTryParseValue(value);
|
|
51
|
-
if (ast == null) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
const cssPropertyName = (0, import_hyphenate_style_name.default)(property);
|
|
55
|
-
const matchResult = csstree.lexer.matchProperty(cssPropertyName, ast);
|
|
56
|
-
const isValidDeclaration2 = matchResult.matched != null;
|
|
57
|
-
if (isValidDeclaration2 && typeof CSSStyleValue !== "undefined") {
|
|
58
|
-
try {
|
|
59
|
-
CSSStyleValue.parse(cssPropertyName, value);
|
|
60
|
-
} catch {
|
|
61
|
-
(0, import_warn_once.default)(
|
|
62
|
-
true,
|
|
63
|
-
`Css property "${property}" with value "${value}" is invalid according to CSSStyleValue.parse
|
|
64
|
-
but valid according to csstree.lexer.matchProperty.`
|
|
65
|
-
);
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return isValidDeclaration2;
|
|
70
|
-
};
|
|
71
|
-
const parseCssValue = (property, input) => {
|
|
72
|
-
const invalidValue = {
|
|
73
|
-
type: "invalid",
|
|
74
|
-
value: input
|
|
75
|
-
};
|
|
76
|
-
if (input.length === 0) {
|
|
77
|
-
return invalidValue;
|
|
78
|
-
}
|
|
79
|
-
if (!isValidDeclaration(property, input)) {
|
|
80
|
-
return invalidValue;
|
|
81
|
-
}
|
|
82
|
-
const ast = cssTryParseValue(input);
|
|
83
|
-
if (ast == null) {
|
|
84
|
-
(0, import_warn_once.default)(
|
|
85
|
-
true,
|
|
86
|
-
`Can't parse css property "${property}" with value "${input}"`
|
|
87
|
-
);
|
|
88
|
-
return invalidValue;
|
|
89
|
-
}
|
|
90
|
-
if (ast != null && ast.type === "Value" && ast.children.first === ast.children.last) {
|
|
91
|
-
const first = ast.children.first;
|
|
92
|
-
if (first?.type === "Number") {
|
|
93
|
-
return {
|
|
94
|
-
type: "unit",
|
|
95
|
-
unit: "number",
|
|
96
|
-
value: Number(first.value)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (first?.type === "Dimension") {
|
|
100
|
-
const unit = first.unit;
|
|
101
|
-
for (const unitGroup of Object.values(import_units.units)) {
|
|
102
|
-
if (unitGroup.includes(unit)) {
|
|
103
|
-
return {
|
|
104
|
-
type: "unit",
|
|
105
|
-
unit,
|
|
106
|
-
value: Number(first.value)
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return invalidValue;
|
|
111
|
-
}
|
|
112
|
-
if (first?.type === "Percentage") {
|
|
113
|
-
return {
|
|
114
|
-
type: "unit",
|
|
115
|
-
unit: "%",
|
|
116
|
-
value: Number(first.value)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (first?.type === "Identifier") {
|
|
120
|
-
const values = import_keyword_values.keywordValues[property];
|
|
121
|
-
const lettersRegex = /[^a-zA-Z]+/g;
|
|
122
|
-
const searchValues = values.map(
|
|
123
|
-
(value) => value.replace(lettersRegex, "").toLowerCase()
|
|
124
|
-
);
|
|
125
|
-
const keywordInput = input.replace(lettersRegex, "").toLowerCase();
|
|
126
|
-
const index = searchValues.indexOf(keywordInput);
|
|
127
|
-
if (index > -1) {
|
|
128
|
-
return {
|
|
129
|
-
type: "keyword",
|
|
130
|
-
value: values[index]
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (property.toLocaleLowerCase().includes("color")) {
|
|
136
|
-
const mayBeColor = (0, import_colord.colord)(input);
|
|
137
|
-
if (mayBeColor.isValid()) {
|
|
138
|
-
const rgb = mayBeColor.toRgb();
|
|
139
|
-
return {
|
|
140
|
-
type: "rgb",
|
|
141
|
-
alpha: rgb.a,
|
|
142
|
-
r: rgb.r,
|
|
143
|
-
g: rgb.g,
|
|
144
|
-
b: rgb.b
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
type: "unparsed",
|
|
150
|
-
value: input
|
|
151
|
-
};
|
|
152
|
-
};
|
package/lib/cjs/parse-css.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var parse_css_exports = {};
|
|
30
|
-
__export(parse_css_exports, {
|
|
31
|
-
parseCss: () => parseCss
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(parse_css_exports);
|
|
34
|
-
var csstree = __toESM(require("css-tree"), 1);
|
|
35
|
-
var import_parse_css_value = require("./parse-css-value");
|
|
36
|
-
var parsers = __toESM(require("./property-parsers/parsers"), 1);
|
|
37
|
-
var toLonghand = __toESM(require("./property-parsers/to-longhand"), 1);
|
|
38
|
-
var import_schema = require("./schema");
|
|
39
|
-
const parseCssValue = function parseCssValue2(property, value) {
|
|
40
|
-
const unwrap = toLonghand[property];
|
|
41
|
-
if (typeof unwrap === "function") {
|
|
42
|
-
const longhands = unwrap(value);
|
|
43
|
-
return Object.fromEntries(
|
|
44
|
-
Object.entries(longhands).map(([property2, value2]) => {
|
|
45
|
-
const valueParser = parsers[property2];
|
|
46
|
-
if (typeof valueParser === "function") {
|
|
47
|
-
return [property2, valueParser(value2)];
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(value2)) {
|
|
50
|
-
return [
|
|
51
|
-
property2,
|
|
52
|
-
{
|
|
53
|
-
type: "invalid",
|
|
54
|
-
value: value2.join("")
|
|
55
|
-
}
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
if (!value2) {
|
|
59
|
-
return [property2, { type: "invalid", value: "" }];
|
|
60
|
-
}
|
|
61
|
-
return [
|
|
62
|
-
property2,
|
|
63
|
-
(0, import_parse_css_value.parseCssValue)(property2, value2)
|
|
64
|
-
];
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
[property]: (0, import_parse_css_value.parseCssValue)(property, value)
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
const cssTreeTryParse = (input) => {
|
|
73
|
-
try {
|
|
74
|
-
const ast = csstree.parse(input);
|
|
75
|
-
return ast;
|
|
76
|
-
} catch {
|
|
77
|
-
return void 0;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const parseCss = function cssToWS(css) {
|
|
81
|
-
const ast = cssTreeTryParse(css);
|
|
82
|
-
let selectors = [];
|
|
83
|
-
const styles = {};
|
|
84
|
-
if (ast === void 0) {
|
|
85
|
-
return styles;
|
|
86
|
-
}
|
|
87
|
-
csstree.walk(ast, (node, item) => {
|
|
88
|
-
if (node.type === "SelectorList") {
|
|
89
|
-
selectors = [];
|
|
90
|
-
}
|
|
91
|
-
if (node.type === "ClassSelector") {
|
|
92
|
-
if (!item.prev && !item.next) {
|
|
93
|
-
selectors.push(node.name);
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (node.type === "Declaration") {
|
|
98
|
-
const stringValue = csstree.generate(node.value);
|
|
99
|
-
const parsedCss = parseCssValue(
|
|
100
|
-
node.property,
|
|
101
|
-
stringValue
|
|
102
|
-
);
|
|
103
|
-
Object.entries(parsedCss).forEach(
|
|
104
|
-
([property, value]) => {
|
|
105
|
-
try {
|
|
106
|
-
import_schema.StyleValue.parse(value);
|
|
107
|
-
selectors.forEach((selector) => {
|
|
108
|
-
if (Array.isArray(styles[selector])) {
|
|
109
|
-
styles[selector].push({
|
|
110
|
-
property,
|
|
111
|
-
value
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
styles[selector] = [{ property, value }];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if (true) {
|
|
119
|
-
console.warn(
|
|
120
|
-
true,
|
|
121
|
-
`Declaration parsing for \`${selectors.join(", ")}.${node.property}: ${stringValue}\` failed:
|
|
122
|
-
|
|
123
|
-
${JSON.stringify(
|
|
124
|
-
parsedCss,
|
|
125
|
-
null,
|
|
126
|
-
2
|
|
127
|
-
)}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
return styles;
|
|
136
|
-
};
|