@webstudio-is/css-engine 0.91.0 → 0.92.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 (59) hide show
  1. package/lib/__generated__/types.js +1 -0
  2. package/lib/core/compare-media.js +2 -4
  3. package/{src/core/compare-media.test.ts → lib/core/compare-media.test.js} +7 -9
  4. package/lib/core/create-css-engine.js +2 -4
  5. package/lib/core/css-engine.js +2 -4
  6. package/lib/core/css-engine.stories.js +48 -0
  7. package/{src/core/css-engine.test.ts → lib/core/css-engine.test.js} +51 -88
  8. package/lib/core/equal-media.js +2 -4
  9. package/{src/core/equal-media.test.ts → lib/core/equal-media.test.js} +1 -3
  10. package/lib/core/find-applicable-media.js +2 -4
  11. package/{src/core/find-applicable-media.test.ts → lib/core/find-applicable-media.test.js} +7 -8
  12. package/lib/core/index.js +2 -4
  13. package/lib/core/match-media.js +2 -4
  14. package/{src/core/match-media.test.ts → lib/core/match-media.test.js} +1 -3
  15. package/lib/core/rules.js +5 -10
  16. package/lib/core/style-element.js +2 -4
  17. package/lib/core/style-sheet.js +2 -4
  18. package/lib/core/to-property.js +2 -4
  19. package/{src/core/to-property.test.ts → lib/core/to-property.test.js} +1 -1
  20. package/lib/core/to-value.js +2 -4
  21. package/{src/core/to-value.test.ts → lib/core/to-value.test.js} +21 -32
  22. package/lib/index.js +2 -0
  23. package/lib/schema.js +98 -0
  24. package/lib/types/__generated__/types.d.ts +2 -0
  25. package/lib/types/core/css-engine.d.ts +1 -1
  26. package/lib/types/core/rules.d.ts +2 -2
  27. package/lib/types/core/to-property.d.ts +1 -1
  28. package/lib/types/core/to-value.d.ts +1 -1
  29. package/lib/types/index.d.ts +2 -0
  30. package/lib/types/schema.d.ts +3233 -0
  31. package/package.json +12 -15
  32. package/lib/cjs/core/compare-media.js +0 -38
  33. package/lib/cjs/core/create-css-engine.js +0 -27
  34. package/lib/cjs/core/css-engine.js +0 -122
  35. package/lib/cjs/core/equal-media.js +0 -26
  36. package/lib/cjs/core/find-applicable-media.js +0 -33
  37. package/lib/cjs/core/index.js +0 -32
  38. package/lib/cjs/core/match-media.js +0 -28
  39. package/lib/cjs/core/rules.js +0 -187
  40. package/lib/cjs/core/style-element.js +0 -61
  41. package/lib/cjs/core/style-sheet.js +0 -36
  42. package/lib/cjs/core/to-property.js +0 -40
  43. package/lib/cjs/core/to-value.js +0 -98
  44. package/lib/cjs/index.js +0 -18
  45. package/lib/cjs/package.json +0 -1
  46. package/src/core/compare-media.ts +0 -30
  47. package/src/core/create-css-engine.ts +0 -5
  48. package/src/core/css-engine.stories.tsx +0 -48
  49. package/src/core/css-engine.ts +0 -128
  50. package/src/core/equal-media.ts +0 -5
  51. package/src/core/find-applicable-media.ts +0 -20
  52. package/src/core/index.ts +0 -15
  53. package/src/core/match-media.ts +0 -8
  54. package/src/core/rules.ts +0 -182
  55. package/src/core/style-element.ts +0 -38
  56. package/src/core/style-sheet.ts +0 -15
  57. package/src/core/to-property.ts +0 -12
  58. package/src/core/to-value.ts +0 -108
  59. package/src/index.ts +0 -1
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,4 +1,5 @@
1
- const compareMedia = (optionA, optionB) => {
1
+ "use strict";
2
+ export const compareMedia = (optionA, optionB) => {
2
3
  if (optionA.minWidth === void 0 && optionA.maxWidth === void 0) {
3
4
  return -1;
4
5
  }
@@ -13,6 +14,3 @@ const compareMedia = (optionA, optionB) => {
13
14
  }
14
15
  return "minWidth" in optionA ? 1 : -1;
15
16
  };
16
- export {
17
- compareMedia
18
- };
@@ -1,6 +1,6 @@
1
+ "use strict";
1
2
  import { describe, test, expect } from "@jest/globals";
2
3
  import { compareMedia } from "./compare-media";
3
-
4
4
  describe("Compare media", () => {
5
5
  test("min-width", () => {
6
6
  const initial = [
@@ -8,38 +8,36 @@ describe("Compare media", () => {
8
8
  { minWidth: 1280 },
9
9
  { minWidth: 0 },
10
10
  { minWidth: 1024 },
11
- { minWidth: 768 },
11
+ { minWidth: 768 }
12
12
  ];
13
13
  const expected = [
14
14
  {},
15
15
  { minWidth: 0 },
16
16
  { minWidth: 768 },
17
17
  { minWidth: 1024 },
18
- { minWidth: 1280 },
18
+ { minWidth: 1280 }
19
19
  ];
20
20
  const sorted = initial.sort(compareMedia);
21
21
  expect(sorted).toStrictEqual(expected);
22
22
  });
23
-
24
23
  test("max-width", () => {
25
24
  const initial = [
26
25
  {},
27
26
  { maxWidth: 1280 },
28
27
  { maxWidth: 0 },
29
28
  { maxWidth: 1024 },
30
- { maxWidth: 768 },
29
+ { maxWidth: 768 }
31
30
  ];
32
31
  const expected = [
33
32
  {},
34
33
  { maxWidth: 1280 },
35
34
  { maxWidth: 1024 },
36
35
  { maxWidth: 768 },
37
- { maxWidth: 0 },
36
+ { maxWidth: 0 }
38
37
  ];
39
38
  const sorted = initial.sort(compareMedia);
40
39
  expect(sorted).toStrictEqual(expected);
41
40
  });
42
-
43
41
  test("mixed max and min", () => {
44
42
  const initial = [
45
43
  {},
@@ -48,7 +46,7 @@ describe("Compare media", () => {
48
46
  { maxWidth: 767 },
49
47
  { minWidth: 1440 },
50
48
  { minWidth: 1280 },
51
- { minWidth: 1920 },
49
+ { minWidth: 1920 }
52
50
  ];
53
51
  const expected = [
54
52
  {},
@@ -57,7 +55,7 @@ describe("Compare media", () => {
57
55
  { maxWidth: 479 },
58
56
  { minWidth: 1280 },
59
57
  { minWidth: 1440 },
60
- { minWidth: 1920 },
58
+ { minWidth: 1920 }
61
59
  ];
62
60
  const sorted = initial.sort(compareMedia);
63
61
  expect(sorted).toStrictEqual(expected);
@@ -1,7 +1,5 @@
1
+ "use strict";
1
2
  import { CssEngine } from "./css-engine";
2
- const createCssEngine = (options = {}) => {
3
+ export const createCssEngine = (options = {}) => {
3
4
  return new CssEngine(options);
4
5
  };
5
- export {
6
- createCssEngine
7
- };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  import {
2
3
  FontFaceRule,
3
4
  MediaRule,
@@ -8,7 +9,7 @@ import { compareMedia } from "./compare-media";
8
9
  import { StyleElement } from "./style-element";
9
10
  import { StyleSheet } from "./style-sheet";
10
11
  const defaultMediaRuleId = "__default-media-rule__";
11
- class CssEngine {
12
+ export class CssEngine {
12
13
  #element;
13
14
  #mediaRules = /* @__PURE__ */ new Map();
14
15
  #plainRules = /* @__PURE__ */ new Map();
@@ -102,6 +103,3 @@ class CssEngine {
102
103
  this.#isDirty = true;
103
104
  };
104
105
  }
105
- export {
106
- CssEngine
107
- };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { CssEngine } from "./css-engine";
4
+ export default {
5
+ component: "CssEngine"
6
+ };
7
+ const style0 = {
8
+ color: { type: "keyword", value: "red" }
9
+ };
10
+ const mediaRuleOptions0 = { minWidth: 0 };
11
+ const mediaId = "0";
12
+ export const Basic = () => {
13
+ const engine = new CssEngine({ name: "test" });
14
+ engine.addMediaRule(mediaId, mediaRuleOptions0);
15
+ const rule = engine.addStyleRule(".test", {
16
+ style: style0,
17
+ breakpoint: "0"
18
+ });
19
+ engine.render();
20
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
21
+ /* @__PURE__ */ jsx("div", { className: "test", children: "Should be red" }),
22
+ /* @__PURE__ */ jsx(
23
+ "button",
24
+ {
25
+ onClick: () => {
26
+ rule.styleMap.set("color", { type: "keyword", value: "green" });
27
+ engine.render();
28
+ },
29
+ children: "Make it green"
30
+ }
31
+ ),
32
+ /* @__PURE__ */ jsx(
33
+ "button",
34
+ {
35
+ onClick: () => {
36
+ engine.addStyleRule(".test", {
37
+ style: {
38
+ backgroundColor: { type: "keyword", value: "yellow" }
39
+ },
40
+ breakpoint: "0"
41
+ });
42
+ engine.render();
43
+ },
44
+ children: "Add rule with yellow background"
45
+ }
46
+ )
47
+ ] });
48
+ };
@@ -1,39 +1,31 @@
1
+ "use strict";
1
2
  import { describe, beforeEach, test, expect } from "@jest/globals";
2
3
  import { CssEngine } from "./css-engine";
3
-
4
4
  const style0 = {
5
- display: { type: "keyword", value: "block" },
6
- } as const;
7
-
8
- const mediaRuleOptions0 = { minWidth: 0 } as const;
5
+ display: { type: "keyword", value: "block" }
6
+ };
7
+ const mediaRuleOptions0 = { minWidth: 0 };
9
8
  const mediaId0 = "0";
10
-
11
9
  const style1 = {
12
- display: { type: "keyword", value: "flex" },
13
- } as const;
14
-
10
+ display: { type: "keyword", value: "flex" }
11
+ };
15
12
  const style2 = {
16
13
  display: { type: "keyword", value: "block" },
17
- color: { type: "keyword", value: "black" },
18
- } as const;
19
-
20
- const mediaRuleOptions1 = { minWidth: 300 } as const;
14
+ color: { type: "keyword", value: "black" }
15
+ };
16
+ const mediaRuleOptions1 = { minWidth: 300 };
21
17
  const mediaId1 = "1";
22
-
23
18
  describe("CssEngine", () => {
24
- let engine: CssEngine;
25
-
19
+ let engine;
26
20
  const reset = () => {
27
21
  engine = new CssEngine({ name: "test" });
28
22
  };
29
-
30
23
  beforeEach(reset);
31
-
32
24
  test("minWidth media rule", () => {
33
25
  engine.addMediaRule("0", { minWidth: 0 });
34
26
  engine.addStyleRule(".c1", {
35
27
  style: { color: { type: "keyword", value: "red" } },
36
- breakpoint: "0",
28
+ breakpoint: "0"
37
29
  });
38
30
  expect(engine.cssText).toMatchInlineSnapshot(`
39
31
  "@media all and (min-width: 0px) {
@@ -43,12 +35,11 @@ describe("CssEngine", () => {
43
35
  }"
44
36
  `);
45
37
  });
46
-
47
38
  test("maxWidth media rule", () => {
48
- engine.addMediaRule("0", { maxWidth: 1000 });
39
+ engine.addMediaRule("0", { maxWidth: 1e3 });
49
40
  engine.addStyleRule(".c1", {
50
41
  style: { color: { type: "keyword", value: "red" } },
51
- breakpoint: "0",
42
+ breakpoint: "0"
52
43
  });
53
44
  expect(engine.cssText).toMatchInlineSnapshot(`
54
45
  "@media all and (max-width: 1000px) {
@@ -58,12 +49,11 @@ describe("CssEngine", () => {
58
49
  }"
59
50
  `);
60
51
  });
61
-
62
52
  test("maxWidth and maxWith media rule", () => {
63
- engine.addMediaRule("0", { maxWidth: 1000, minWidth: 360 });
53
+ engine.addMediaRule("0", { maxWidth: 1e3, minWidth: 360 });
64
54
  engine.addStyleRule(".c1", {
65
55
  style: { color: { type: "keyword", value: "red" } },
66
- breakpoint: "0",
56
+ breakpoint: "0"
67
57
  });
68
58
  expect(engine.cssText).toMatchInlineSnapshot(`
69
59
  "@media all and (min-width: 360px) and (max-width: 1000px) {
@@ -73,11 +63,10 @@ describe("CssEngine", () => {
73
63
  }"
74
64
  `);
75
65
  });
76
-
77
66
  test("use default media rule when there is no matching one registered", () => {
78
67
  engine.addStyleRule(".c", {
79
68
  style: style0,
80
- breakpoint: "x",
69
+ breakpoint: "x"
81
70
  });
82
71
  expect(engine.cssText).toMatchInlineSnapshot(`
83
72
  "@media all {
@@ -88,7 +77,7 @@ describe("CssEngine", () => {
88
77
  `);
89
78
  engine.addStyleRule(".c1", {
90
79
  style: { color: { type: "keyword", value: "red" } },
91
- breakpoint: "x",
80
+ breakpoint: "x"
92
81
  });
93
82
  expect(engine.cssText).toMatchInlineSnapshot(`
94
83
  "@media all {
@@ -100,13 +89,11 @@ describe("CssEngine", () => {
100
89
  }
101
90
  }"
102
91
  `);
103
-
104
92
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
105
93
  engine.addStyleRule(".c1", {
106
94
  style: { color: { type: "keyword", value: "blue" } },
107
- breakpoint: mediaId0,
95
+ breakpoint: mediaId0
108
96
  });
109
- // Default media query should allways be the first to have the lowest source order specificity
110
97
  expect(engine.cssText).toMatchInlineSnapshot(`
111
98
  "@media all {
112
99
  .c {
@@ -123,26 +110,21 @@ describe("CssEngine", () => {
123
110
  }"
124
111
  `);
125
112
  });
126
-
127
113
  test("sort media queries based on lower min-width", () => {
128
114
  engine.addMediaRule(mediaId1, mediaRuleOptions1);
129
115
  engine.addStyleRule(".c2", {
130
116
  style: style1,
131
- breakpoint: mediaId1,
117
+ breakpoint: mediaId1
132
118
  });
133
-
134
119
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
135
120
  engine.addStyleRule(".c1", {
136
121
  style: style0,
137
- breakpoint: mediaId0,
122
+ breakpoint: mediaId0
138
123
  });
139
-
140
124
  engine.addStyleRule(".c3", {
141
125
  style: style0,
142
- breakpoint: "x",
126
+ breakpoint: "x"
143
127
  });
144
-
145
- // Default media query should allways be the first to have the lowest source order specificity
146
128
  expect(engine.cssText).toMatchInlineSnapshot(`
147
129
  "@media all {
148
130
  .c3 {
@@ -161,15 +143,14 @@ describe("CssEngine", () => {
161
143
  }"
162
144
  `);
163
145
  });
164
-
165
146
  test("keep the sort order when minWidth is not defined", () => {
166
147
  engine.addStyleRule(".c0", {
167
148
  style: style0,
168
- breakpoint: "x",
149
+ breakpoint: "x"
169
150
  });
170
151
  engine.addStyleRule(".c1", {
171
152
  style: style1,
172
- breakpoint: "x",
153
+ breakpoint: "x"
173
154
  });
174
155
  expect(engine.cssText).toMatchInlineSnapshot(`
175
156
  "@media all {
@@ -181,16 +162,14 @@ describe("CssEngine", () => {
181
162
  }
182
163
  }"
183
164
  `);
184
-
185
165
  reset();
186
-
187
166
  engine.addStyleRule(".c1", {
188
167
  style: style1,
189
- breakpoint: "x",
168
+ breakpoint: "x"
190
169
  });
191
170
  engine.addStyleRule(".c0", {
192
171
  style: style0,
193
- breakpoint: "x",
172
+ breakpoint: "x"
194
173
  });
195
174
  expect(engine.cssText).toMatchInlineSnapshot(`
196
175
  "@media all {
@@ -203,15 +182,14 @@ describe("CssEngine", () => {
203
182
  }"
204
183
  `);
205
184
  });
206
-
207
185
  test("rule with multiple properties", () => {
208
186
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
209
187
  engine.addStyleRule(".c", {
210
188
  style: {
211
189
  ...style0,
212
- color: { type: "keyword", value: "red" },
190
+ color: { type: "keyword", value: "red" }
213
191
  },
214
- breakpoint: "0",
192
+ breakpoint: "0"
215
193
  });
216
194
  expect(engine.cssText).toMatchInlineSnapshot(`
217
195
  "@media all and (min-width: 0px) {
@@ -222,14 +200,13 @@ describe("CssEngine", () => {
222
200
  }"
223
201
  `);
224
202
  });
225
-
226
203
  test("hyphenate property", () => {
227
204
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
228
205
  engine.addStyleRule(".c", {
229
206
  style: {
230
- backgroundColor: { type: "keyword", value: "red" },
207
+ backgroundColor: { type: "keyword", value: "red" }
231
208
  },
232
- breakpoint: "0",
209
+ breakpoint: "0"
233
210
  });
234
211
  expect(engine.cssText).toMatchInlineSnapshot(`
235
212
  "@media all and (min-width: 0px) {
@@ -239,15 +216,14 @@ describe("CssEngine", () => {
239
216
  }"
240
217
  `);
241
218
  });
242
-
243
219
  test("add rule", () => {
244
220
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
245
221
  const rule1 = engine.addStyleRule(".c", {
246
222
  style: {
247
223
  ...style0,
248
- color: { type: "keyword", value: "red" },
224
+ color: { type: "keyword", value: "red" }
249
225
  },
250
- breakpoint: "0",
226
+ breakpoint: "0"
251
227
  });
252
228
  expect(engine.cssText).toMatchInlineSnapshot(`
253
229
  "@media all and (min-width: 0px) {
@@ -266,9 +242,9 @@ describe("CssEngine", () => {
266
242
  engine.addStyleRule(".c2", {
267
243
  style: {
268
244
  ...style0,
269
- color: { type: "keyword", value: "green" },
245
+ color: { type: "keyword", value: "green" }
270
246
  },
271
- breakpoint: "0",
247
+ breakpoint: "0"
272
248
  });
273
249
  expect(engine.cssText).toMatchInlineSnapshot(`
274
250
  "@media all and (min-width: 0px) {
@@ -283,15 +259,14 @@ describe("CssEngine", () => {
283
259
  }"
284
260
  `);
285
261
  });
286
-
287
262
  test("update rule", () => {
288
263
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
289
264
  const rule = engine.addStyleRule(".c", {
290
265
  style: {
291
266
  ...style0,
292
- color: { type: "keyword", value: "red" },
267
+ color: { type: "keyword", value: "red" }
293
268
  },
294
- breakpoint: "0",
269
+ breakpoint: "0"
295
270
  });
296
271
  expect(engine.cssText).toMatchInlineSnapshot(`
297
272
  "@media all and (min-width: 0px) {
@@ -307,16 +282,13 @@ describe("CssEngine", () => {
307
282
  color: red
308
283
  }"
309
284
  `);
310
-
311
285
  rule.styleMap.set("color", { type: "keyword", value: "green" });
312
-
313
286
  expect(rule.cssText).toMatchInlineSnapshot(`
314
287
  ".c {
315
288
  display: block;
316
289
  color: green
317
290
  }"
318
291
  `);
319
-
320
292
  expect(engine.cssText).toMatchInlineSnapshot(`
321
293
  "@media all and (min-width: 0px) {
322
294
  .c {
@@ -326,14 +298,13 @@ describe("CssEngine", () => {
326
298
  }"
327
299
  `);
328
300
  });
329
-
330
301
  test("update media rule options", () => {
331
302
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
332
303
  engine.addStyleRule(".c", {
333
304
  style: {
334
- color: { type: "keyword", value: "red" },
305
+ color: { type: "keyword", value: "red" }
335
306
  },
336
- breakpoint: "0",
307
+ breakpoint: "0"
337
308
  });
338
309
  expect(engine.cssText).toMatchInlineSnapshot(`
339
310
  "@media all and (min-width: 0px) {
@@ -351,12 +322,11 @@ describe("CssEngine", () => {
351
322
  }"
352
323
  `);
353
324
  });
354
-
355
325
  test("don't override media queries", () => {
356
326
  engine.addMediaRule(mediaId0, mediaRuleOptions0);
357
327
  engine.addStyleRule(".c", {
358
328
  style: style0,
359
- breakpoint: "0",
329
+ breakpoint: "0"
360
330
  });
361
331
  expect(engine.cssText).toMatchInlineSnapshot(`
362
332
  "@media all and (min-width: 0px) {
@@ -374,12 +344,10 @@ describe("CssEngine", () => {
374
344
  }"
375
345
  `);
376
346
  });
377
-
378
347
  test("plaintext rule", () => {
379
348
  engine.addPlaintextRule(".c { color: red }");
380
349
  expect(engine.cssText).toMatchInlineSnapshot(`".c { color: red }"`);
381
350
  });
382
-
383
351
  test("plaintext - no duplicates", () => {
384
352
  engine.addPlaintextRule(".c { color: red }");
385
353
  engine.addPlaintextRule(".c { color: red }");
@@ -389,14 +357,13 @@ describe("CssEngine", () => {
389
357
  .c { color: green }"
390
358
  `);
391
359
  });
392
-
393
360
  test("font family rule", () => {
394
361
  engine.addFontFaceRule({
395
362
  fontFamily: "Roboto",
396
363
  fontStyle: "normal",
397
364
  fontWeight: 400,
398
365
  fontDisplay: "swap",
399
- src: "url(/src)",
366
+ src: "url(/src)"
400
367
  });
401
368
  expect(engine.cssText).toMatchInlineSnapshot(`
402
369
  "@font-face {
@@ -404,20 +371,18 @@ describe("CssEngine", () => {
404
371
  }"
405
372
  `);
406
373
  });
407
-
408
374
  test("clear", () => {
409
375
  engine.addStyleRule(".c", {
410
376
  style: style0,
411
- breakpoint: "0",
377
+ breakpoint: "0"
412
378
  });
413
379
  engine.clear();
414
380
  expect(engine.cssText).toMatchInlineSnapshot(`""`);
415
381
  });
416
-
417
382
  test("get all rule style keys", () => {
418
383
  const rule = engine.addStyleRule(".c", {
419
384
  style: style2,
420
- breakpoint: "0",
385
+ breakpoint: "0"
421
386
  });
422
387
  expect(Array.from(rule.styleMap.keys())).toMatchInlineSnapshot(`
423
388
  [
@@ -426,11 +391,10 @@ describe("CssEngine", () => {
426
391
  ]
427
392
  `);
428
393
  });
429
-
430
394
  test("delete style from rule", () => {
431
395
  const rule = engine.addStyleRule(".c", {
432
396
  style: style2,
433
- breakpoint: "0",
397
+ breakpoint: "0"
434
398
  });
435
399
  rule.styleMap.delete("display");
436
400
  expect(engine.cssText).toMatchInlineSnapshot(`
@@ -441,10 +405,9 @@ describe("CssEngine", () => {
441
405
  }"
442
406
  `);
443
407
  });
444
-
445
408
  test("render images with injected asset url", () => {
446
- const assets = new Map<string, { path: string }>([
447
- ["1234", { path: "foo.png" }],
409
+ const assets = /* @__PURE__ */ new Map([
410
+ ["1234", { path: "foo.png" }]
448
411
  ]);
449
412
  const rule = engine.addStyleRule(
450
413
  ".c",
@@ -454,24 +417,24 @@ describe("CssEngine", () => {
454
417
  type: "image",
455
418
  value: {
456
419
  type: "asset",
457
- value: "1234",
458
- },
459
- },
420
+ value: "1234"
421
+ }
422
+ }
460
423
  },
461
- breakpoint: "0",
424
+ breakpoint: "0"
462
425
  },
463
426
  (styleValue) => {
464
427
  if (styleValue.type === "image" && styleValue.value.type === "asset") {
465
428
  const asset = assets.get(styleValue.value.value);
466
- if (asset === undefined) {
429
+ if (asset === void 0) {
467
430
  return { type: "keyword", value: "none" };
468
431
  }
469
432
  return {
470
433
  type: "image",
471
434
  value: {
472
435
  type: "url",
473
- url: asset.path,
474
- },
436
+ url: asset.path
437
+ }
475
438
  };
476
439
  }
477
440
  }
@@ -1,6 +1,4 @@
1
- const equalMedia = (left, right) => {
1
+ "use strict";
2
+ export const equalMedia = (left, right) => {
2
3
  return left.minWidth === right.minWidth && left.maxWidth === right.maxWidth;
3
4
  };
4
- export {
5
- equalMedia
6
- };
@@ -1,19 +1,17 @@
1
+ "use strict";
1
2
  import { describe, expect, test } from "@jest/globals";
2
3
  import { equalMedia } from "./equal-media";
3
-
4
4
  describe("equalMedia", () => {
5
5
  test("minWidth", () => {
6
6
  expect(equalMedia({ minWidth: 100 }, { minWidth: 10 })).toBe(false);
7
7
  expect(equalMedia({ minWidth: 100 }, { minWidth: 100 })).toBe(true);
8
8
  expect(equalMedia({ minWidth: 100 }, { minWidth: 101 })).toBe(false);
9
9
  });
10
-
11
10
  test("maxWidth", () => {
12
11
  expect(equalMedia({ maxWidth: 100 }, { maxWidth: 101 })).toBe(false);
13
12
  expect(equalMedia({ maxWidth: 100 }, { maxWidth: 100 })).toBe(true);
14
13
  expect(equalMedia({ maxWidth: 100 }, { maxWidth: 10 })).toBe(false);
15
14
  });
16
-
17
15
  test("minWidth and maxWidth", () => {
18
16
  expect(equalMedia({ maxWidth: 100, minWidth: 10 }, { maxWidth: 100 })).toBe(
19
17
  false
@@ -1,6 +1,7 @@
1
+ "use strict";
1
2
  import { compareMedia } from "./compare-media";
2
3
  import { matchMedia } from "./match-media";
3
- const findApplicableMedia = (media, width) => {
4
+ export const findApplicableMedia = (media, width) => {
4
5
  const sortedMedia = [...media].sort(compareMedia).reverse();
5
6
  for (const options of sortedMedia) {
6
7
  if (matchMedia(options, width)) {
@@ -8,6 +9,3 @@ const findApplicableMedia = (media, width) => {
8
9
  }
9
10
  }
10
11
  };
11
- export {
12
- findApplicableMedia
13
- };
@@ -1,6 +1,6 @@
1
+ "use strict";
1
2
  import { describe, test, expect } from "@jest/globals";
2
3
  import { findApplicableMedia } from "./find-applicable-media";
3
-
4
4
  const media = [
5
5
  {},
6
6
  { maxWidth: 991 },
@@ -8,23 +8,22 @@ const media = [
8
8
  { maxWidth: 479 },
9
9
  { minWidth: 1280 },
10
10
  { minWidth: 1440 },
11
- { minWidth: 1920 },
11
+ { minWidth: 1920 }
12
12
  ];
13
-
14
13
  describe("Find applicable media", () => {
15
14
  test("200", () => {
16
15
  expect(findApplicableMedia([...media], 200)).toStrictEqual({
17
- maxWidth: 479,
16
+ maxWidth: 479
18
17
  });
19
18
  });
20
19
  test("479", () => {
21
20
  expect(findApplicableMedia([...media], 479)).toStrictEqual({
22
- maxWidth: 479,
21
+ maxWidth: 479
23
22
  });
24
23
  });
25
24
  test("480", () => {
26
25
  expect(findApplicableMedia([...media], 480)).toStrictEqual({
27
- maxWidth: 767,
26
+ maxWidth: 767
28
27
  });
29
28
  });
30
29
  test("1279", () => {
@@ -32,12 +31,12 @@ describe("Find applicable media", () => {
32
31
  });
33
32
  test("1280", () => {
34
33
  expect(findApplicableMedia([...media], 1280)).toStrictEqual({
35
- minWidth: 1280,
34
+ minWidth: 1280
36
35
  });
37
36
  });
38
37
  test("1440", () => {
39
38
  expect(findApplicableMedia([...media], 1440)).toStrictEqual({
40
- minWidth: 1440,
39
+ minWidth: 1440
41
40
  });
42
41
  });
43
42
  });