@webstudio-is/css-engine 0.168.0 → 0.174.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";
@@ -67,15 +220,14 @@ var toValue = (styleValue, transformValue) => {
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") {
81
233
  if (value.hidden === true) {
@@ -89,16 +241,183 @@ var toValue = (styleValue, transformValue) => {
89
241
  return captureError(new Error("Unknown value type"), value);
90
242
  };
91
243
 
92
- // src/core/to-property.ts
93
- var hyphenateProperty = (property) => property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
94
- var toProperty = (property) => {
95
- if (property === "backgroundClip") {
96
- 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
+ }
97
257
  }
98
- return hyphenateProperty(property);
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);
283
+ }
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;
99
358
  };
100
359
 
360
+ // src/core/to-property.ts
361
+ var hyphenateProperty = (property) => property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
362
+
101
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
+ });
102
421
  var getDeclarationKey = (declaraionKey) => {
103
422
  const { breakpoint, selector, property } = declaraionKey;
104
423
  return `${breakpoint}:${selector}:${property}`;
@@ -120,10 +439,12 @@ var MixinRule = class {
120
439
  this.#dirtyBreakpoints.clear();
121
440
  }
122
441
  setDeclaration(declaration) {
442
+ declaration = normalizeDeclaration(declaration);
123
443
  this.#declarations.set(getDeclarationKey(declaration), declaration);
124
444
  this.#dirtyBreakpoints.add(declaration.breakpoint);
125
445
  }
126
446
  deleteDeclaration(declaration) {
447
+ declaration = normalizeDeclaration(declaration);
127
448
  this.#declarations.delete(getDeclarationKey(declaration));
128
449
  this.#dirtyBreakpoints.add(declaration.breakpoint);
129
450
  }
@@ -164,14 +485,16 @@ var NestingRule = class {
164
485
  this.#cache.clear();
165
486
  }
166
487
  setDeclaration(declaration) {
488
+ declaration = normalizeDeclaration(declaration);
167
489
  this.#declarations.set(getDeclarationKey(declaration), declaration);
168
490
  this.#cache.delete(declaration.breakpoint);
169
491
  }
170
492
  deleteDeclaration(declaration) {
493
+ declaration = normalizeDeclaration(declaration);
171
494
  this.#declarations.delete(getDeclarationKey(declaration));
172
495
  this.#cache.delete(declaration.breakpoint);
173
496
  }
174
- getDeclarations() {
497
+ #getDeclarations() {
175
498
  const declarations = /* @__PURE__ */ new Map();
176
499
  for (const mixin of this.#mixins) {
177
500
  const rule = this.#mixinRules.get(mixin);
@@ -187,6 +510,9 @@ var NestingRule = class {
187
510
  }
188
511
  return declarations.values();
189
512
  }
513
+ getMergedDeclarations() {
514
+ return mergeDeclarations(this.#getDeclarations());
515
+ }
190
516
  toString({
191
517
  breakpoint,
192
518
  indent = 0,
@@ -202,113 +528,36 @@ var NestingRule = class {
202
528
  if (cached && cached.indent === indent && cached.transformValue === transformValue) {
203
529
  return cached.generated;
204
530
  }
205
- const spaces = " ".repeat(indent);
206
- const linesBySelector = /* @__PURE__ */ new Map();
207
- for (const declaration of this.getDeclarations()) {
531
+ const styleBySelector = /* @__PURE__ */ new Map();
532
+ for (const declaration of this.getMergedDeclarations()) {
208
533
  if (declaration.breakpoint !== breakpoint) {
209
534
  continue;
210
535
  }
211
- const { selector: nestedSelector, property, value } = declaration;
536
+ const { selector: nestedSelector } = declaration;
212
537
  const selector = this.#selector + this.#descendantSuffix + nestedSelector;
213
- const lines = linesBySelector.get(selector) ?? "";
214
- const propertyString = toProperty(property);
215
- const valueString = toValue(value, transformValue);
216
- const line = `${spaces} ${propertyString}: ${valueString}`;
217
- linesBySelector.set(selector, lines === "" ? line : `${lines};
218
- ${line}`);
219
- }
220
- const generated = Array.from(linesBySelector).sort(
221
- ([leftSelector], [rightSelector]) => leftSelector.localeCompare(rightSelector)
222
- ).map(
223
- ([selector, lines]) => `${spaces}${selector} {
224
- ${lines}
225
- ${spaces}}
226
- `
227
- ).join("").trimEnd();
228
- this.#cache.set(breakpoint, { generated, indent, transformValue });
229
- return generated;
230
- }
231
- };
232
- var StylePropertyMap = class {
233
- #cached;
234
- #styleMap = /* @__PURE__ */ new Map();
235
- #indent = 0;
236
- #transformValue;
237
- constructor(style) {
238
- let property;
239
- for (property in style) {
240
- this.#styleMap.set(property, style[property]);
241
- }
242
- }
243
- set(property, value) {
244
- this.#styleMap.set(property, value);
245
- this.#cached = void 0;
246
- }
247
- get(property) {
248
- return this.#styleMap.get(property);
249
- }
250
- has(property) {
251
- return this.#styleMap.has(property);
252
- }
253
- get size() {
254
- return this.#styleMap.size;
255
- }
256
- keys() {
257
- return this.#styleMap.keys();
258
- }
259
- delete(property) {
260
- this.#styleMap.delete(property);
261
- this.#cached = void 0;
262
- }
263
- clear() {
264
- this.#styleMap.clear();
265
- this.#cached = void 0;
266
- }
267
- toString({
268
- indent = 0,
269
- transformValue
270
- } = {}) {
271
- if (this.#cached && indent === this.#indent && transformValue === this.#transformValue) {
272
- return this.#cached;
273
- }
274
- const block = [];
275
- const spaces = " ".repeat(indent);
276
- for (const [property, value] of this.#styleMap) {
277
- if (value === void 0) {
278
- continue;
538
+ let style = styleBySelector.get(selector);
539
+ if (style === void 0) {
540
+ style = /* @__PURE__ */ new Map();
541
+ styleBySelector.set(selector, style);
279
542
  }
280
- block.push(
281
- `${spaces}${toProperty(property)}: ${toValue(value, transformValue)}`
282
- );
543
+ style.set(declaration.property, declaration.value);
283
544
  }
284
- this.#cached = block.join(";\n");
285
- this.#indent = indent;
286
- this.#transformValue = transformValue;
287
- return this.#cached;
288
- }
289
- };
290
- var StyleRule = class {
291
- styleMap;
292
- selectorText;
293
- constructor(selectorText, style) {
294
- this.selectorText = selectorText;
295
- this.styleMap = style instanceof StylePropertyMap ? style : new StylePropertyMap(style);
296
- }
297
- get cssText() {
298
- return this.toString();
299
- }
300
- toString({
301
- indent = 0,
302
- transformValue
303
- } = {}) {
304
545
  const spaces = " ".repeat(indent);
305
- const content = this.styleMap.toString({
306
- indent: indent + 2,
307
- transformValue
308
- });
309
- 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} {
310
555
  ${content}
311
- ${spaces}}`;
556
+ ${spaces}}
557
+ `;
558
+ }).join("").trimEnd();
559
+ this.#cache.set(breakpoint, { generated, indent, transformValue });
560
+ return generated;
312
561
  }
313
562
  };
314
563
  var MediaRule = class {
@@ -323,10 +572,7 @@ var MediaRule = class {
323
572
  this.#mediaType = options.mediaType ?? "all";
324
573
  }
325
574
  insertRule(rule) {
326
- this.rules.set(
327
- rule instanceof StyleRule ? rule.selectorText : rule.cssText,
328
- rule
329
- );
575
+ this.rules.set(rule.cssText, rule);
330
576
  return rule;
331
577
  }
332
578
  get cssText() {
@@ -344,7 +590,7 @@ var MediaRule = class {
344
590
  }
345
591
  const rules = [];
346
592
  for (const rule of this.rules.values()) {
347
- rules.push(rule.toString({ indent: 2, transformValue }));
593
+ rules.push(rule.toString());
348
594
  }
349
595
  for (const rule of nestingRules) {
350
596
  const generatedRule = rule.toString({
@@ -586,14 +832,7 @@ var StyleSheet = class {
586
832
  };
587
833
 
588
834
  // src/core/style-sheet-regular.ts
589
- var defaultMediaRuleId = "__default-media-rule__";
590
835
  var StyleSheetRegular = class extends StyleSheet {
591
- addStyleRule(rule, selectorText) {
592
- const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);
593
- const styleRule = new StyleRule(selectorText, rule.style);
594
- mediaRule.insertRule(styleRule);
595
- return styleRule;
596
- }
597
836
  };
598
837
 
599
838
  // src/core/create-style-sheet.ts
@@ -629,16 +868,16 @@ import hash from "@emotion/hash";
629
868
  var generateAtomic = (sheet, options) => {
630
869
  const { getKey, transformValue } = options;
631
870
  const atomicRules = /* @__PURE__ */ new Map();
632
- const classesMap = /* @__PURE__ */ new Map();
871
+ const classes = options.classes ?? /* @__PURE__ */ new Map();
633
872
  for (const rule of sheet.nestingRules.values()) {
634
873
  const descendantSuffix = rule.getDescendantSuffix();
635
874
  const groupKey = getKey(rule);
636
- let classList = classesMap.get(groupKey);
875
+ let classList = classes.get(groupKey);
637
876
  if (classList === void 0) {
638
877
  classList = [];
639
- classesMap.set(groupKey, classList);
878
+ classes.set(groupKey, classList);
640
879
  }
641
- for (const declaration of rule.getDeclarations()) {
880
+ for (const declaration of rule.getMergedDeclarations()) {
642
881
  const atomicHash = hash(
643
882
  descendantSuffix + declaration.breakpoint + declaration.selector + declaration.property + toValue(declaration.value, transformValue)
644
883
  );
@@ -660,120 +899,8 @@ var generateAtomic = (sheet, options) => {
660
899
  nestingRules: Array.from(atomicRules.values()),
661
900
  transformValue
662
901
  });
663
- return { cssText, classesMap };
902
+ return { cssText, classes };
664
903
  };
665
-
666
- // src/schema.ts
667
- import { z } from "zod";
668
- var Unit = z.string();
669
- var UnitValue = z.object({
670
- type: z.literal("unit"),
671
- unit: Unit,
672
- value: z.number()
673
- });
674
- var KeywordValue = z.object({
675
- type: z.literal("keyword"),
676
- // @todo use exact type
677
- value: z.string()
678
- });
679
- var UnparsedValue = z.object({
680
- type: z.literal("unparsed"),
681
- value: z.string(),
682
- // For the builder we want to be able to hide background-image
683
- hidden: z.boolean().optional()
684
- });
685
- var FontFamilyValue = z.object({
686
- type: z.literal("fontFamily"),
687
- value: z.array(z.string())
688
- });
689
- var RgbValue = z.object({
690
- type: z.literal("rgb"),
691
- r: z.number(),
692
- g: z.number(),
693
- b: z.number(),
694
- alpha: z.number()
695
- });
696
- var FunctionValue = z.object({
697
- type: z.literal("function"),
698
- name: z.string(),
699
- args: z.lazy(() => StyleValue),
700
- hidden: z.boolean().optional()
701
- });
702
- var ImageValue = z.object({
703
- type: z.literal("image"),
704
- value: z.union([
705
- z.object({ type: z.literal("asset"), value: z.string() }),
706
- // url is not stored in db and only used by css-engine transformValue
707
- // to prepare image value for rendering
708
- z.object({ type: z.literal("url"), url: z.string() })
709
- ]),
710
- // For the builder we want to be able to hide images
711
- hidden: z.boolean().optional()
712
- });
713
- var GuaranteedInvalidValue = z.object({
714
- type: z.literal("guaranteedInvalid")
715
- });
716
- var InvalidValue = z.object({
717
- type: z.literal("invalid"),
718
- value: z.string()
719
- });
720
- var UnsetValue = z.object({
721
- type: z.literal("unset"),
722
- value: z.literal("")
723
- });
724
- var TupleValueItem = z.union([
725
- UnitValue,
726
- KeywordValue,
727
- UnparsedValue,
728
- RgbValue,
729
- FunctionValue
730
- ]);
731
- var TupleValue = z.object({
732
- type: z.literal("tuple"),
733
- value: z.array(TupleValueItem),
734
- hidden: z.boolean().optional()
735
- });
736
- var LayerValueItem = z.union([
737
- UnitValue,
738
- KeywordValue,
739
- UnparsedValue,
740
- ImageValue,
741
- TupleValue,
742
- InvalidValue,
743
- FunctionValue
744
- ]);
745
- var LayersValue = z.object({
746
- type: z.literal("layers"),
747
- value: z.array(LayerValueItem)
748
- });
749
- var ValidStaticStyleValue = z.union([
750
- ImageValue,
751
- LayersValue,
752
- UnitValue,
753
- KeywordValue,
754
- FontFamilyValue,
755
- RgbValue,
756
- UnparsedValue,
757
- TupleValue,
758
- FunctionValue,
759
- GuaranteedInvalidValue
760
- ]);
761
- var isValidStaticStyleValue = (styleValue) => {
762
- const staticStyleValue = styleValue;
763
- 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";
764
- };
765
- var VarValue = z.object({
766
- type: z.literal("var"),
767
- value: z.string(),
768
- fallbacks: z.array(ValidStaticStyleValue)
769
- });
770
- var StyleValue = z.union([
771
- ValidStaticStyleValue,
772
- InvalidValue,
773
- UnsetValue,
774
- VarValue
775
- ]);
776
- var Style = z.record(z.string(), StyleValue);
777
904
  export {
778
905
  FunctionValue,
779
906
  GuaranteedInvalidValue,
@@ -788,11 +915,15 @@ export {
788
915
  UnparsedValue,
789
916
  compareMedia,
790
917
  createRegularStyleSheet,
918
+ cssWideKeywords,
791
919
  equalMedia,
792
920
  findApplicableMedia,
793
921
  generateAtomic,
922
+ generateStyleMap,
794
923
  hyphenateProperty,
795
924
  isValidStaticStyleValue,
796
925
  matchMedia,
926
+ mergeStyles,
927
+ prefixStyles,
797
928
  toValue
798
929
  };