@webstudio-is/css-engine 0.167.0 → 0.173.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 CHANGED
@@ -1,3 +1,156 @@
1
+ // src/core/prefixer.ts
2
+ var prefixStyles = (styleMap) => {
3
+ const newStyleMap = /* @__PURE__ */ new Map();
4
+ for (const [property, value] of styleMap) {
5
+ if (property === "background-clip") {
6
+ newStyleMap.set("-webkit-background-clip", value);
7
+ }
8
+ if (property === "user-select") {
9
+ newStyleMap.set("-webkit-user-select", value);
10
+ }
11
+ if (property === "text-size-adjust") {
12
+ newStyleMap.set("-webkit-text-size-adjust", value);
13
+ }
14
+ if (property === "backdrop-filter") {
15
+ newStyleMap.set("-webkit-backdrop-filter", value);
16
+ }
17
+ newStyleMap.set(property, value);
18
+ }
19
+ return newStyleMap;
20
+ };
21
+
22
+ // src/schema.ts
23
+ import { z } from "zod";
24
+ var Unit = z.string();
25
+ var UnitValue = z.object({
26
+ type: z.literal("unit"),
27
+ unit: Unit,
28
+ value: z.number(),
29
+ hidden: z.boolean().optional()
30
+ });
31
+ var KeywordValue = z.object({
32
+ type: z.literal("keyword"),
33
+ // @todo use exact type
34
+ value: z.string(),
35
+ hidden: z.boolean().optional()
36
+ });
37
+ var UnparsedValue = z.object({
38
+ type: z.literal("unparsed"),
39
+ value: z.string(),
40
+ // For the builder we want to be able to hide background-image
41
+ hidden: z.boolean().optional()
42
+ });
43
+ var FontFamilyValue = z.object({
44
+ type: z.literal("fontFamily"),
45
+ value: z.array(z.string()),
46
+ hidden: z.boolean().optional()
47
+ });
48
+ var RgbValue = z.object({
49
+ type: z.literal("rgb"),
50
+ r: z.number(),
51
+ g: z.number(),
52
+ b: z.number(),
53
+ alpha: z.number(),
54
+ hidden: z.boolean().optional()
55
+ });
56
+ var FunctionValue = z.object({
57
+ type: z.literal("function"),
58
+ name: z.string(),
59
+ args: z.lazy(() => StyleValue),
60
+ hidden: z.boolean().optional()
61
+ });
62
+ var ImageValue = z.object({
63
+ type: z.literal("image"),
64
+ value: z.union([
65
+ z.object({ type: z.literal("asset"), value: z.string() }),
66
+ // url is not stored in db and only used by css-engine transformValue
67
+ // to prepare image value for rendering
68
+ z.object({ type: z.literal("url"), url: z.string() })
69
+ ]),
70
+ // For the builder we want to be able to hide images
71
+ hidden: z.boolean().optional()
72
+ });
73
+ var GuaranteedInvalidValue = z.object({
74
+ type: z.literal("guaranteedInvalid"),
75
+ hidden: z.boolean().optional()
76
+ });
77
+ var InvalidValue = z.object({
78
+ type: z.literal("invalid"),
79
+ value: z.string(),
80
+ hidden: z.boolean().optional()
81
+ });
82
+ var UnsetValue = z.object({
83
+ type: z.literal("unset"),
84
+ value: z.literal(""),
85
+ hidden: z.boolean().optional()
86
+ });
87
+ var TupleValueItem = z.union([
88
+ UnitValue,
89
+ KeywordValue,
90
+ UnparsedValue,
91
+ ImageValue,
92
+ RgbValue,
93
+ FunctionValue
94
+ ]);
95
+ var TupleValue = z.object({
96
+ type: z.literal("tuple"),
97
+ value: z.array(TupleValueItem),
98
+ hidden: z.boolean().optional()
99
+ });
100
+ var LayerValueItem = z.union([
101
+ UnitValue,
102
+ KeywordValue,
103
+ UnparsedValue,
104
+ ImageValue,
105
+ TupleValue,
106
+ RgbValue,
107
+ InvalidValue,
108
+ FunctionValue
109
+ ]);
110
+ var LayersValue = z.object({
111
+ type: z.literal("layers"),
112
+ value: z.array(LayerValueItem),
113
+ hidden: z.boolean().optional()
114
+ });
115
+ var ValidStaticStyleValue = z.union([
116
+ ImageValue,
117
+ LayersValue,
118
+ UnitValue,
119
+ KeywordValue,
120
+ FontFamilyValue,
121
+ RgbValue,
122
+ UnparsedValue,
123
+ TupleValue,
124
+ FunctionValue,
125
+ GuaranteedInvalidValue
126
+ ]);
127
+ var isValidStaticStyleValue = (styleValue) => {
128
+ const staticStyleValue = styleValue;
129
+ 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" || staticStyleValue.type === "function" || staticStyleValue.type === "guaranteedInvalid";
130
+ };
131
+ var VarValue = z.object({
132
+ type: z.literal("var"),
133
+ value: z.string(),
134
+ fallbacks: z.array(ValidStaticStyleValue),
135
+ hidden: z.boolean().optional()
136
+ });
137
+ var StyleValue = z.union([
138
+ ValidStaticStyleValue,
139
+ InvalidValue,
140
+ UnsetValue,
141
+ VarValue
142
+ ]);
143
+ var Style = z.record(z.string(), StyleValue);
144
+
145
+ // src/css.ts
146
+ var cssWideKeywords = /* @__PURE__ */ new Set([
147
+ "initial",
148
+ "inherit",
149
+ "unset",
150
+ "revert",
151
+ "revert-layer"
152
+ ]);
153
+
1
154
  // src/core/to-value.ts
2
155
  import { captureError } from "@webstudio-is/error-utils";
3
156
  import { DEFAULT_FONT_FALLBACK, SYSTEM_FONTS } from "@webstudio-is/fonts";
@@ -61,23 +214,25 @@ var toValue = (styleValue, transformValue) => {
61
214
  return `url(${sanitizeCssUrl(value.value.url)})`;
62
215
  }
63
216
  if (value.type === "unparsed") {
64
- if (value.hidden) {
217
+ if (value.hidden === true) {
65
218
  return "none";
66
219
  }
67
220
  return value.value;
68
221
  }
69
222
  if (value.type === "layers") {
70
- const valueString = value.value.filter(
71
- (layer) => "hidden" in layer === false || "hidden" in layer && layer.hidden === false
72
- ).map((layer) => {
73
- return toValue(layer, transformValue);
74
- }).join(", ");
223
+ const valueString = value.value.filter((layer) => layer.hidden !== true).map((layer) => toValue(layer, transformValue)).join(", ");
75
224
  return valueString === "" ? "none" : valueString;
76
225
  }
77
226
  if (value.type === "tuple") {
78
- return value.value.map((value2) => toValue(value2, transformValue)).join(" ");
227
+ if (value.hidden === true) {
228
+ return "none";
229
+ }
230
+ return value.value.filter((value2) => value2.hidden !== true).map((value2) => toValue(value2, transformValue)).join(" ");
79
231
  }
80
232
  if (value.type === "function") {
233
+ if (value.hidden === true) {
234
+ return "";
235
+ }
81
236
  return `${value.name}(${toValue(value.args, transformValue)})`;
82
237
  }
83
238
  if (value.type === "guaranteedInvalid") {
@@ -86,16 +241,183 @@ var toValue = (styleValue, transformValue) => {
86
241
  return captureError(new Error("Unknown value type"), value);
87
242
  };
88
243
 
89
- // src/core/to-property.ts
90
- var hyphenateProperty = (property) => property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
91
- var toProperty = (property) => {
92
- if (property === "backgroundClip") {
93
- return "-webkit-background-clip";
244
+ // src/core/merger.ts
245
+ var isLonghandValue = (value) => {
246
+ if (value === void 0) {
247
+ return false;
248
+ }
249
+ if (value.type === "keyword" && cssWideKeywords.has(value.value)) {
250
+ return false;
251
+ }
252
+ if (value.type === "var") {
253
+ const fallback = value.fallbacks.at(0);
254
+ if (fallback?.type === "keyword" && cssWideKeywords.has(fallback.value)) {
255
+ return false;
256
+ }
257
+ }
258
+ return true;
259
+ };
260
+ var mergeBorder = (styleMap, base) => {
261
+ const width = styleMap.get(`${base}-width`);
262
+ const style = styleMap.get(`${base}-style`);
263
+ const color = styleMap.get(`${base}-color`);
264
+ if (isLonghandValue(width) && isLonghandValue(style) && isLonghandValue(color)) {
265
+ styleMap.delete(`${base}-width`);
266
+ styleMap.delete(`${base}-style`);
267
+ styleMap.delete(`${base}-color`);
268
+ styleMap.set(base, { type: "tuple", value: [width, style, color] });
269
+ }
270
+ };
271
+ var mergeBox = (styleMap, base) => {
272
+ const topValue = styleMap.get(`${base}-top`);
273
+ const top = toValue(topValue);
274
+ const right = toValue(styleMap.get(`${base}-right`));
275
+ const bottom = toValue(styleMap.get(`${base}-bottom`));
276
+ const left = toValue(styleMap.get(`${base}-left`));
277
+ if (isLonghandValue(topValue) && top === right && top === bottom && top === left) {
278
+ styleMap.delete(`${base}-top`);
279
+ styleMap.delete(`${base}-right`);
280
+ styleMap.delete(`${base}-bottom`);
281
+ styleMap.delete(`${base}-left`);
282
+ styleMap.set(base, topValue);
94
283
  }
95
- return hyphenateProperty(property);
284
+ };
285
+ var mergeWhiteSpaceAndTextWrap = (styleMap) => {
286
+ const collapseValue = styleMap.get("white-space-collapse");
287
+ const collapse = toValue(collapseValue);
288
+ const modeValue = styleMap.get("text-wrap-mode");
289
+ const mode = toValue(modeValue);
290
+ const styleValue = styleMap.get("text-wrap-style");
291
+ const style = toValue(styleValue);
292
+ styleMap.delete("text-wrap-mode");
293
+ styleMap.delete("text-wrap-style");
294
+ if (collapse === "collapse" || collapse === "initial" || mode === "wrap" || mode === "initial") {
295
+ styleMap.set("white-space", { type: "keyword", value: "normal" });
296
+ }
297
+ if (mode === "nowrap") {
298
+ styleMap.set("white-space", { type: "keyword", value: "nowrap" });
299
+ }
300
+ if (collapse === "preserve") {
301
+ if (mode === "nowrap") {
302
+ styleMap.set("white-space", { type: "keyword", value: "pre" });
303
+ } else {
304
+ styleMap.set("white-space", { type: "keyword", value: "pre-wrap" });
305
+ }
306
+ }
307
+ if (collapse === "preserve-breaks") {
308
+ styleMap.set("white-space", { type: "keyword", value: "pre-line" });
309
+ }
310
+ if (collapse === "break-spaces") {
311
+ styleMap.set("white-space", { type: "keyword", value: "break-spaces" });
312
+ }
313
+ if (style === "balance" || style === "stable" || style === "pretty") {
314
+ styleMap.set("text-wrap", { type: "keyword", value: style });
315
+ }
316
+ const textWrap = (styleValue?.type !== "keyword" ? styleValue : void 0) ?? (modeValue?.type !== "keyword" ? modeValue : void 0);
317
+ if (textWrap) {
318
+ styleMap.set("text-wrap", textWrap);
319
+ }
320
+ if (collapseValue) {
321
+ styleMap.delete("white-space-collapse");
322
+ styleMap.set("white-space-collapse", collapseValue);
323
+ }
324
+ };
325
+ var mergeBackgroundPosition = (styleMap) => {
326
+ const x = styleMap.get("background-position-x");
327
+ const y = styleMap.get("background-position-y");
328
+ if (x?.type === "layers" && y?.type === "layers" && x.value.length === y.value.length) {
329
+ const position = x.value.map((xValue, index) => {
330
+ const yValue = y.value[index];
331
+ return {
332
+ type: "tuple",
333
+ value: [xValue, yValue]
334
+ };
335
+ });
336
+ styleMap.delete("background-position-x");
337
+ styleMap.delete("background-position-y");
338
+ styleMap.set("background-position", {
339
+ type: "layers",
340
+ value: position
341
+ });
342
+ }
343
+ };
344
+ var mergeStyles = (styleMap) => {
345
+ const newStyle = new Map(styleMap);
346
+ mergeBorder(newStyle, "border-top");
347
+ mergeBorder(newStyle, "border-right");
348
+ mergeBorder(newStyle, "border-bottom");
349
+ mergeBorder(newStyle, "border-left");
350
+ mergeBorder(newStyle, "border");
351
+ mergeBorder(newStyle, "outline");
352
+ mergeBox(newStyle, "border");
353
+ mergeBox(newStyle, "margin");
354
+ mergeBox(newStyle, "padding");
355
+ mergeWhiteSpaceAndTextWrap(newStyle);
356
+ mergeBackgroundPosition(newStyle);
357
+ return newStyle;
96
358
  };
97
359
 
360
+ // src/core/to-property.ts
361
+ var hyphenateProperty = (property) => property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
362
+
98
363
  // src/core/rules.ts
364
+ var mapGroupBy = (array, getKey) => {
365
+ const groups = /* @__PURE__ */ new Map();
366
+ for (const item of array) {
367
+ const key = getKey(item);
368
+ let group = groups.get(key);
369
+ if (group === void 0) {
370
+ group = [];
371
+ groups.set(key, group);
372
+ }
373
+ group.push(item);
374
+ }
375
+ return groups;
376
+ };
377
+ var mergeDeclarations = (declarations) => {
378
+ const newDeclarations = [];
379
+ const groups = mapGroupBy(
380
+ declarations,
381
+ (declaration) => declaration.breakpoint + declaration.selector
382
+ );
383
+ for (const groupDeclarations of groups.values()) {
384
+ const { breakpoint, selector } = groupDeclarations[0];
385
+ const merged = mergeStyles(
386
+ new Map(
387
+ groupDeclarations.map((item) => [item.property, item.value])
388
+ )
389
+ );
390
+ for (const [property, value] of merged) {
391
+ newDeclarations.push({
392
+ breakpoint,
393
+ selector,
394
+ property,
395
+ value
396
+ });
397
+ }
398
+ }
399
+ return newDeclarations;
400
+ };
401
+ var generateStyleMap = ({
402
+ style,
403
+ indent = 0,
404
+ transformValue
405
+ }) => {
406
+ const spaces = " ".repeat(indent);
407
+ let lines = "";
408
+ for (const [property, value] of style) {
409
+ const propertyString = hyphenateProperty(property);
410
+ const valueString = toValue(value, transformValue);
411
+ const line = `${spaces}${propertyString}: ${valueString}`;
412
+ lines += lines === "" ? line : `;
413
+ ${line}`;
414
+ }
415
+ return lines;
416
+ };
417
+ var normalizeDeclaration = (declaration) => ({
418
+ ...declaration,
419
+ property: hyphenateProperty(declaration.property)
420
+ });
99
421
  var getDeclarationKey = (declaraionKey) => {
100
422
  const { breakpoint, selector, property } = declaraionKey;
101
423
  return `${breakpoint}:${selector}:${property}`;
@@ -117,10 +439,12 @@ var MixinRule = class {
117
439
  this.#dirtyBreakpoints.clear();
118
440
  }
119
441
  setDeclaration(declaration) {
442
+ declaration = normalizeDeclaration(declaration);
120
443
  this.#declarations.set(getDeclarationKey(declaration), declaration);
121
444
  this.#dirtyBreakpoints.add(declaration.breakpoint);
122
445
  }
123
446
  deleteDeclaration(declaration) {
447
+ declaration = normalizeDeclaration(declaration);
124
448
  this.#declarations.delete(getDeclarationKey(declaration));
125
449
  this.#dirtyBreakpoints.add(declaration.breakpoint);
126
450
  }
@@ -161,14 +485,16 @@ var NestingRule = class {
161
485
  this.#cache.clear();
162
486
  }
163
487
  setDeclaration(declaration) {
488
+ declaration = normalizeDeclaration(declaration);
164
489
  this.#declarations.set(getDeclarationKey(declaration), declaration);
165
490
  this.#cache.delete(declaration.breakpoint);
166
491
  }
167
492
  deleteDeclaration(declaration) {
493
+ declaration = normalizeDeclaration(declaration);
168
494
  this.#declarations.delete(getDeclarationKey(declaration));
169
495
  this.#cache.delete(declaration.breakpoint);
170
496
  }
171
- getDeclarations() {
497
+ #getDeclarations() {
172
498
  const declarations = /* @__PURE__ */ new Map();
173
499
  for (const mixin of this.#mixins) {
174
500
  const rule = this.#mixinRules.get(mixin);
@@ -184,6 +510,9 @@ var NestingRule = class {
184
510
  }
185
511
  return declarations.values();
186
512
  }
513
+ getMergedDeclarations() {
514
+ return mergeDeclarations(this.#getDeclarations());
515
+ }
187
516
  toString({
188
517
  breakpoint,
189
518
  indent = 0,
@@ -199,113 +528,36 @@ var NestingRule = class {
199
528
  if (cached && cached.indent === indent && cached.transformValue === transformValue) {
200
529
  return cached.generated;
201
530
  }
202
- const spaces = " ".repeat(indent);
203
- const linesBySelector = /* @__PURE__ */ new Map();
204
- for (const declaration of this.getDeclarations()) {
531
+ const styleBySelector = /* @__PURE__ */ new Map();
532
+ for (const declaration of this.getMergedDeclarations()) {
205
533
  if (declaration.breakpoint !== breakpoint) {
206
534
  continue;
207
535
  }
208
- const { selector: nestedSelector, property, value } = declaration;
536
+ const { selector: nestedSelector } = declaration;
209
537
  const selector = this.#selector + this.#descendantSuffix + nestedSelector;
210
- const lines = linesBySelector.get(selector) ?? "";
211
- const propertyString = toProperty(property);
212
- const valueString = toValue(value, transformValue);
213
- const line = `${spaces} ${propertyString}: ${valueString}`;
214
- linesBySelector.set(selector, lines === "" ? line : `${lines};
215
- ${line}`);
216
- }
217
- const generated = Array.from(linesBySelector).sort(
218
- ([leftSelector], [rightSelector]) => leftSelector.localeCompare(rightSelector)
219
- ).map(
220
- ([selector, lines]) => `${spaces}${selector} {
221
- ${lines}
222
- ${spaces}}
223
- `
224
- ).join("").trimEnd();
225
- this.#cache.set(breakpoint, { generated, indent, transformValue });
226
- return generated;
227
- }
228
- };
229
- var StylePropertyMap = class {
230
- #cached;
231
- #styleMap = /* @__PURE__ */ new Map();
232
- #indent = 0;
233
- #transformValue;
234
- constructor(style) {
235
- let property;
236
- for (property in style) {
237
- this.#styleMap.set(property, style[property]);
238
- }
239
- }
240
- set(property, value) {
241
- this.#styleMap.set(property, value);
242
- this.#cached = void 0;
243
- }
244
- get(property) {
245
- return this.#styleMap.get(property);
246
- }
247
- has(property) {
248
- return this.#styleMap.has(property);
249
- }
250
- get size() {
251
- return this.#styleMap.size;
252
- }
253
- keys() {
254
- return this.#styleMap.keys();
255
- }
256
- delete(property) {
257
- this.#styleMap.delete(property);
258
- this.#cached = void 0;
259
- }
260
- clear() {
261
- this.#styleMap.clear();
262
- this.#cached = void 0;
263
- }
264
- toString({
265
- indent = 0,
266
- transformValue
267
- } = {}) {
268
- if (this.#cached && indent === this.#indent && transformValue === this.#transformValue) {
269
- return this.#cached;
270
- }
271
- const block = [];
272
- const spaces = " ".repeat(indent);
273
- for (const [property, value] of this.#styleMap) {
274
- if (value === void 0) {
275
- continue;
538
+ let style = styleBySelector.get(selector);
539
+ if (style === void 0) {
540
+ style = /* @__PURE__ */ new Map();
541
+ styleBySelector.set(selector, style);
276
542
  }
277
- block.push(
278
- `${spaces}${toProperty(property)}: ${toValue(value, transformValue)}`
279
- );
543
+ style.set(declaration.property, declaration.value);
280
544
  }
281
- this.#cached = block.join(";\n");
282
- this.#indent = indent;
283
- this.#transformValue = transformValue;
284
- return this.#cached;
285
- }
286
- };
287
- var StyleRule = class {
288
- styleMap;
289
- selectorText;
290
- constructor(selectorText, style) {
291
- this.selectorText = selectorText;
292
- this.styleMap = style instanceof StylePropertyMap ? style : new StylePropertyMap(style);
293
- }
294
- get cssText() {
295
- return this.toString();
296
- }
297
- toString({
298
- indent = 0,
299
- transformValue
300
- } = {}) {
301
545
  const spaces = " ".repeat(indent);
302
- const content = this.styleMap.toString({
303
- indent: indent + 2,
304
- transformValue
305
- });
306
- return `${spaces}${this.selectorText} {
546
+ const generated = Array.from(styleBySelector).sort(
547
+ ([leftSelector], [rightSelector]) => leftSelector.localeCompare(rightSelector)
548
+ ).map(([selector, style]) => {
549
+ const content = generateStyleMap({
550
+ style: prefixStyles(style),
551
+ indent: indent + 2,
552
+ transformValue
553
+ });
554
+ return `${spaces}${selector} {
307
555
  ${content}
308
- ${spaces}}`;
556
+ ${spaces}}
557
+ `;
558
+ }).join("").trimEnd();
559
+ this.#cache.set(breakpoint, { generated, indent, transformValue });
560
+ return generated;
309
561
  }
310
562
  };
311
563
  var MediaRule = class {
@@ -320,10 +572,7 @@ var MediaRule = class {
320
572
  this.#mediaType = options.mediaType ?? "all";
321
573
  }
322
574
  insertRule(rule) {
323
- this.rules.set(
324
- rule instanceof StyleRule ? rule.selectorText : rule.cssText,
325
- rule
326
- );
575
+ this.rules.set(rule.cssText, rule);
327
576
  return rule;
328
577
  }
329
578
  get cssText() {
@@ -341,7 +590,7 @@ var MediaRule = class {
341
590
  }
342
591
  const rules = [];
343
592
  for (const rule of this.rules.values()) {
344
- rules.push(rule.toString({ indent: 2, transformValue }));
593
+ rules.push(rule.toString());
345
594
  }
346
595
  for (const rule of nestingRules) {
347
596
  const generatedRule = rule.toString({
@@ -583,14 +832,7 @@ var StyleSheet = class {
583
832
  };
584
833
 
585
834
  // src/core/style-sheet-regular.ts
586
- var defaultMediaRuleId = "__default-media-rule__";
587
835
  var StyleSheetRegular = class extends StyleSheet {
588
- addStyleRule(rule, selectorText) {
589
- const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
590
- const styleRule = new StyleRule(selectorText, rule.style);
591
- mediaRule.insertRule(styleRule);
592
- return styleRule;
593
- }
594
836
  };
595
837
 
596
838
  // src/core/create-style-sheet.ts
@@ -626,16 +868,16 @@ import hash from "@emotion/hash";
626
868
  var generateAtomic = (sheet, options) => {
627
869
  const { getKey, transformValue } = options;
628
870
  const atomicRules = /* @__PURE__ */ new Map();
629
- const classesMap = /* @__PURE__ */ new Map();
871
+ const classes = options.classes ?? /* @__PURE__ */ new Map();
630
872
  for (const rule of sheet.nestingRules.values()) {
631
873
  const descendantSuffix = rule.getDescendantSuffix();
632
874
  const groupKey = getKey(rule);
633
- let classList = classesMap.get(groupKey);
875
+ let classList = classes.get(groupKey);
634
876
  if (classList === void 0) {
635
877
  classList = [];
636
- classesMap.set(groupKey, classList);
878
+ classes.set(groupKey, classList);
637
879
  }
638
- for (const declaration of rule.getDeclarations()) {
880
+ for (const declaration of rule.getMergedDeclarations()) {
639
881
  const atomicHash = hash(
640
882
  descendantSuffix + declaration.breakpoint + declaration.selector + declaration.property + toValue(declaration.value, transformValue)
641
883
  );
@@ -657,119 +899,8 @@ var generateAtomic = (sheet, options) => {
657
899
  nestingRules: Array.from(atomicRules.values()),
658
900
  transformValue
659
901
  });
660
- return { cssText, classesMap };
661
- };
662
-
663
- // src/schema.ts
664
- import { z } from "zod";
665
- var Unit = z.string();
666
- var UnitValue = z.object({
667
- type: z.literal("unit"),
668
- unit: Unit,
669
- value: z.number()
670
- });
671
- var KeywordValue = z.object({
672
- type: z.literal("keyword"),
673
- // @todo use exact type
674
- value: z.string()
675
- });
676
- var UnparsedValue = z.object({
677
- type: z.literal("unparsed"),
678
- value: z.string(),
679
- // For the builder we want to be able to hide background-image
680
- hidden: z.boolean().optional()
681
- });
682
- var FontFamilyValue = z.object({
683
- type: z.literal("fontFamily"),
684
- value: z.array(z.string())
685
- });
686
- var RgbValue = z.object({
687
- type: z.literal("rgb"),
688
- r: z.number(),
689
- g: z.number(),
690
- b: z.number(),
691
- alpha: z.number()
692
- });
693
- var FunctionValue = z.object({
694
- type: z.literal("function"),
695
- name: z.string(),
696
- args: z.lazy(() => StyleValue)
697
- });
698
- var ImageValue = z.object({
699
- type: z.literal("image"),
700
- value: z.union([
701
- z.object({ type: z.literal("asset"), value: z.string() }),
702
- // url is not stored in db and only used by css-engine transformValue
703
- // to prepare image value for rendering
704
- z.object({ type: z.literal("url"), url: z.string() })
705
- ]),
706
- // For the builder we want to be able to hide images
707
- hidden: z.boolean().optional()
708
- });
709
- var GuaranteedInvalidValue = z.object({
710
- type: z.literal("guaranteedInvalid")
711
- });
712
- var InvalidValue = z.object({
713
- type: z.literal("invalid"),
714
- value: z.string()
715
- });
716
- var UnsetValue = z.object({
717
- type: z.literal("unset"),
718
- value: z.literal("")
719
- });
720
- var TupleValueItem = z.union([
721
- UnitValue,
722
- KeywordValue,
723
- UnparsedValue,
724
- RgbValue,
725
- FunctionValue
726
- ]);
727
- var TupleValue = z.object({
728
- type: z.literal("tuple"),
729
- value: z.array(TupleValueItem),
730
- hidden: z.boolean().optional()
731
- });
732
- var LayerValueItem = z.union([
733
- UnitValue,
734
- KeywordValue,
735
- UnparsedValue,
736
- ImageValue,
737
- TupleValue,
738
- InvalidValue,
739
- FunctionValue
740
- ]);
741
- var LayersValue = z.object({
742
- type: z.literal("layers"),
743
- value: z.array(LayerValueItem)
744
- });
745
- var ValidStaticStyleValue = z.union([
746
- ImageValue,
747
- LayersValue,
748
- UnitValue,
749
- KeywordValue,
750
- FontFamilyValue,
751
- RgbValue,
752
- UnparsedValue,
753
- TupleValue,
754
- FunctionValue,
755
- GuaranteedInvalidValue
756
- ]);
757
- var isValidStaticStyleValue = (styleValue) => {
758
- const staticStyleValue = styleValue;
759
- 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" || staticStyleValue.type === "function" || staticStyleValue.type === "guaranteedInvalid";
902
+ return { cssText, classes };
760
903
  };
761
- var VarValue = z.object({
762
- type: z.literal("var"),
763
- value: z.string(),
764
- fallbacks: z.array(ValidStaticStyleValue)
765
- });
766
- var StyleValue = z.union([
767
- ValidStaticStyleValue,
768
- InvalidValue,
769
- UnsetValue,
770
- VarValue
771
- ]);
772
- var Style = z.record(z.string(), StyleValue);
773
904
  export {
774
905
  FunctionValue,
775
906
  GuaranteedInvalidValue,
@@ -784,11 +915,15 @@ export {
784
915
  UnparsedValue,
785
916
  compareMedia,
786
917
  createRegularStyleSheet,
918
+ cssWideKeywords,
787
919
  equalMedia,
788
920
  findApplicableMedia,
789
921
  generateAtomic,
922
+ generateStyleMap,
790
923
  hyphenateProperty,
791
924
  isValidStaticStyleValue,
792
925
  matchMedia,
926
+ mergeStyles,
927
+ prefixStyles,
793
928
  toValue
794
929
  };