@webstudio-is/css-data 0.75.0 → 0.77.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.
@@ -0,0 +1,128 @@
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 box_shadow_exports = {};
30
+ __export(box_shadow_exports, {
31
+ parseBoxShadow: () => parseBoxShadow
32
+ });
33
+ module.exports = __toCommonJS(box_shadow_exports);
34
+ var csstree = __toESM(require("css-tree"), 1);
35
+ var import_colord = require("colord");
36
+ const cssTreeTryParseValue = (input) => {
37
+ try {
38
+ const ast = csstree.parse(input, { context: "value" });
39
+ return ast;
40
+ } catch {
41
+ return void 0;
42
+ }
43
+ };
44
+ const parseBoxShadow = (boxShadow) => {
45
+ let tokenStream = boxShadow.trim();
46
+ tokenStream = tokenStream.endsWith(";") ? tokenStream.slice(0, -1) : tokenStream;
47
+ const cleanupKeywords = ["box-shadow:"];
48
+ for (const cleanupKeyword of cleanupKeywords) {
49
+ tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
50
+ }
51
+ const cssAst = cssTreeTryParseValue(tokenStream);
52
+ if (cssAst === void 0) {
53
+ return {
54
+ type: "invalid",
55
+ value: boxShadow
56
+ };
57
+ }
58
+ const parsed = csstree.lexer.matchProperty("box-shadow", cssAst);
59
+ if (parsed.error) {
60
+ return {
61
+ type: "invalid",
62
+ value: boxShadow
63
+ };
64
+ }
65
+ const layers = [];
66
+ csstree.walk(cssAst, (node) => {
67
+ if (node.type === "Value") {
68
+ const children = node.children;
69
+ let layer = [];
70
+ for (const child of children) {
71
+ if (children.last === child) {
72
+ layer.push(child);
73
+ }
74
+ if (child.type === "Operator" || children.last === child) {
75
+ const shadow = [];
76
+ for (let index = 0; index < layer.length; index++) {
77
+ const item = layer[index];
78
+ if (item.type === "Identifier") {
79
+ shadow.push({
80
+ type: "keyword",
81
+ value: item.name
82
+ });
83
+ }
84
+ if (item.type === "Function" || item.type === "Hash") {
85
+ const colorValue = (0, import_colord.colord)(csstree.generate(item));
86
+ if (!colorValue.isValid()) {
87
+ return;
88
+ }
89
+ const rgb = colorValue.toRgb();
90
+ shadow.push({
91
+ type: "rgb",
92
+ alpha: rgb.a,
93
+ r: rgb.r,
94
+ g: rgb.g,
95
+ b: rgb.b
96
+ });
97
+ }
98
+ if (item.type === "Dimension") {
99
+ shadow.push({
100
+ type: "unit",
101
+ value: Number(item.value),
102
+ unit: item.unit
103
+ });
104
+ }
105
+ if (item.type === "Number") {
106
+ shadow.push({
107
+ type: "unit",
108
+ value: Number(item.value),
109
+ unit: "number"
110
+ });
111
+ }
112
+ }
113
+ layers.push({
114
+ type: "tuple",
115
+ value: shadow
116
+ });
117
+ layer = [];
118
+ continue;
119
+ }
120
+ layer.push(child);
121
+ }
122
+ }
123
+ });
124
+ return layers.length > 0 ? {
125
+ type: "layers",
126
+ value: layers
127
+ } : { type: "invalid", value: boxShadow };
128
+ };
@@ -16,3 +16,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var property_parsers_exports = {};
17
17
  module.exports = __toCommonJS(property_parsers_exports);
18
18
  __reExport(property_parsers_exports, require("./background"), module.exports);
19
+ __reExport(property_parsers_exports, require("./box-shadow"), module.exports);
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var parsers_exports = {};
20
20
  __export(parsers_exports, {
21
- backgroundImage: () => import_background.parseBackgroundImage
21
+ backgroundImage: () => import_background.parseBackgroundImage,
22
+ boxShadow: () => import_box_shadow.parseBoxShadow
22
23
  });
23
24
  module.exports = __toCommonJS(parsers_exports);
24
25
  var import_background = require("./background");
26
+ var import_box_shadow = require("./box-shadow");
package/lib/cjs/schema.js CHANGED
@@ -84,23 +84,28 @@ const UnsetValue = import_zod.z.object({
84
84
  type: import_zod.z.literal("unset"),
85
85
  value: import_zod.z.literal("")
86
86
  });
87
- const TupleValueItem = import_zod.z.union([UnitValue, KeywordValue, UnparsedValue]);
87
+ const TupleValueItem = import_zod.z.union([
88
+ UnitValue,
89
+ KeywordValue,
90
+ UnparsedValue,
91
+ RgbValue
92
+ ]);
88
93
  const TupleValue = import_zod.z.object({
89
94
  type: import_zod.z.literal("tuple"),
90
- value: import_zod.z.array(TupleValueItem)
95
+ value: import_zod.z.array(TupleValueItem),
96
+ hidden: import_zod.z.boolean().optional()
91
97
  });
98
+ const LayerValueItem = import_zod.z.union([
99
+ UnitValue,
100
+ KeywordValue,
101
+ UnparsedValue,
102
+ ImageValue,
103
+ TupleValue,
104
+ InvalidValue
105
+ ]);
92
106
  const LayersValue = import_zod.z.object({
93
107
  type: import_zod.z.literal("layers"),
94
- value: import_zod.z.array(
95
- import_zod.z.union([
96
- UnitValue,
97
- KeywordValue,
98
- UnparsedValue,
99
- ImageValue,
100
- TupleValue,
101
- InvalidValue
102
- ])
103
- )
108
+ value: import_zod.z.array(LayerValueItem)
104
109
  });
105
110
  const ValidStaticStyleValue = import_zod.z.union([
106
111
  ImageValue,
@@ -0,0 +1,98 @@
1
+ import * as csstree from "css-tree";
2
+ import { colord } from "colord";
3
+ const cssTreeTryParseValue = (input) => {
4
+ try {
5
+ const ast = csstree.parse(input, { context: "value" });
6
+ return ast;
7
+ } catch {
8
+ return void 0;
9
+ }
10
+ };
11
+ const parseBoxShadow = (boxShadow) => {
12
+ let tokenStream = boxShadow.trim();
13
+ tokenStream = tokenStream.endsWith(";") ? tokenStream.slice(0, -1) : tokenStream;
14
+ const cleanupKeywords = ["box-shadow:"];
15
+ for (const cleanupKeyword of cleanupKeywords) {
16
+ tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
17
+ }
18
+ const cssAst = cssTreeTryParseValue(tokenStream);
19
+ if (cssAst === void 0) {
20
+ return {
21
+ type: "invalid",
22
+ value: boxShadow
23
+ };
24
+ }
25
+ const parsed = csstree.lexer.matchProperty("box-shadow", cssAst);
26
+ if (parsed.error) {
27
+ return {
28
+ type: "invalid",
29
+ value: boxShadow
30
+ };
31
+ }
32
+ const layers = [];
33
+ csstree.walk(cssAst, (node) => {
34
+ if (node.type === "Value") {
35
+ const children = node.children;
36
+ let layer = [];
37
+ for (const child of children) {
38
+ if (children.last === child) {
39
+ layer.push(child);
40
+ }
41
+ if (child.type === "Operator" || children.last === child) {
42
+ const shadow = [];
43
+ for (let index = 0; index < layer.length; index++) {
44
+ const item = layer[index];
45
+ if (item.type === "Identifier") {
46
+ shadow.push({
47
+ type: "keyword",
48
+ value: item.name
49
+ });
50
+ }
51
+ if (item.type === "Function" || item.type === "Hash") {
52
+ const colorValue = colord(csstree.generate(item));
53
+ if (!colorValue.isValid()) {
54
+ return;
55
+ }
56
+ const rgb = colorValue.toRgb();
57
+ shadow.push({
58
+ type: "rgb",
59
+ alpha: rgb.a,
60
+ r: rgb.r,
61
+ g: rgb.g,
62
+ b: rgb.b
63
+ });
64
+ }
65
+ if (item.type === "Dimension") {
66
+ shadow.push({
67
+ type: "unit",
68
+ value: Number(item.value),
69
+ unit: item.unit
70
+ });
71
+ }
72
+ if (item.type === "Number") {
73
+ shadow.push({
74
+ type: "unit",
75
+ value: Number(item.value),
76
+ unit: "number"
77
+ });
78
+ }
79
+ }
80
+ layers.push({
81
+ type: "tuple",
82
+ value: shadow
83
+ });
84
+ layer = [];
85
+ continue;
86
+ }
87
+ layer.push(child);
88
+ }
89
+ }
90
+ });
91
+ return layers.length > 0 ? {
92
+ type: "layers",
93
+ value: layers
94
+ } : { type: "invalid", value: boxShadow };
95
+ };
96
+ export {
97
+ parseBoxShadow
98
+ };
@@ -1 +1,2 @@
1
1
  export * from "./background";
2
+ export * from "./box-shadow";
@@ -1,4 +1,6 @@
1
1
  import { parseBackgroundImage } from "./background";
2
+ import { parseBoxShadow } from "./box-shadow";
2
3
  export {
3
- parseBackgroundImage as backgroundImage
4
+ parseBackgroundImage as backgroundImage,
5
+ parseBoxShadow as boxShadow
4
6
  };
package/lib/schema.js CHANGED
@@ -52,23 +52,28 @@ const UnsetValue = z.object({
52
52
  type: z.literal("unset"),
53
53
  value: z.literal("")
54
54
  });
55
- const TupleValueItem = z.union([UnitValue, KeywordValue, UnparsedValue]);
55
+ const TupleValueItem = z.union([
56
+ UnitValue,
57
+ KeywordValue,
58
+ UnparsedValue,
59
+ RgbValue
60
+ ]);
56
61
  const TupleValue = z.object({
57
62
  type: z.literal("tuple"),
58
- value: z.array(TupleValueItem)
63
+ value: z.array(TupleValueItem),
64
+ hidden: z.boolean().optional()
59
65
  });
66
+ const LayerValueItem = z.union([
67
+ UnitValue,
68
+ KeywordValue,
69
+ UnparsedValue,
70
+ ImageValue,
71
+ TupleValue,
72
+ InvalidValue
73
+ ]);
60
74
  const LayersValue = z.object({
61
75
  type: z.literal("layers"),
62
- value: z.array(
63
- z.union([
64
- UnitValue,
65
- KeywordValue,
66
- UnparsedValue,
67
- ImageValue,
68
- TupleValue,
69
- InvalidValue
70
- ])
71
- )
76
+ value: z.array(LayerValueItem)
72
77
  });
73
78
  const ValidStaticStyleValue = z.union([
74
79
  ImageValue,
@@ -929,7 +929,7 @@ export declare const properties: {
929
929
  readonly inherited: true;
930
930
  readonly initial: {
931
931
  readonly type: "keyword";
932
- readonly value: "inherit";
932
+ readonly value: "black";
933
933
  };
934
934
  readonly popularity: 0.90791486;
935
935
  readonly appliesTo: "allElementsAndText";
@@ -3105,7 +3105,7 @@ export declare const properties: {
3105
3105
  readonly inherited: true;
3106
3106
  readonly initial: {
3107
3107
  readonly type: "keyword";
3108
- readonly value: "startOrNamelessValueIfLTRRightIfRTL";
3108
+ readonly value: "start";
3109
3109
  };
3110
3110
  readonly popularity: 0.89287477;
3111
3111
  readonly appliesTo: "blockContainers";