@compiled/react 0.17.3 → 0.18.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.
@@ -1,7 +1,12 @@
1
1
  import type { Bucket, StyleSheetOpts } from './types';
2
2
  /**
3
- * Ordered style buckets using their short psuedo name.
4
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
3
+ * Ordered style buckets using their short pseudo name.
4
+ *
5
+ * This is very bare-bones, with no support for nesting, like styles in
6
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
7
+ *
8
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
9
+ * definition in `packages/css/src/utils/style-ordering.ts`.
5
10
  */
6
11
  export declare const styleBucketOrdering: Bucket[];
7
12
  /**
@@ -1,9 +1,22 @@
1
1
  import { isCacheDisabled } from './cache';
2
+ import { getShorthandDepth } from './shorthand';
2
3
  /**
3
- * Ordered style buckets using their short psuedo name.
4
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
4
+ * Ordered style buckets using their short pseudo name.
5
+ *
6
+ * This is very bare-bones, with no support for nesting, like styles in
7
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
8
+ *
9
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
10
+ * definition in `packages/css/src/utils/style-ordering.ts`.
5
11
  */
6
12
  export const styleBucketOrdering = [
13
+ // shorthand properties
14
+ 's-0',
15
+ 's-1',
16
+ 's-2',
17
+ 's-3',
18
+ 's-4',
19
+ 's-5',
7
20
  // catch-all
8
21
  '',
9
22
  // link
@@ -30,8 +43,8 @@ const styleBucketsInHead = {};
30
43
  /**
31
44
  * Maps the long pseudo name to the short pseudo name.
32
45
  * Pseudos that match here will be ordered,
33
- * everythin else will make their way to the catch all style bucket.
34
- * We reduce the pseduo name to save bundlesize.
46
+ * everything else will make their way to the catch all style bucket.
47
+ * We reduce the pseudo name to save bundlesize.
35
48
  * Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes.
36
49
  */
37
50
  const pseudosMap = {
@@ -102,15 +115,23 @@ export const getStyleBucketName = (sheet) => {
102
115
  if (sheet.charCodeAt(0) === 64 /* "@" */) {
103
116
  return 'm';
104
117
  }
118
+ const firstBracket = sheet.indexOf('{');
105
119
  /**
106
120
  * We assume that classname will always be 9 character long,
107
- * using this the 10th character could be a pseudo declaration.
121
+ * using this the 10th characters could be a pseudo declaration.
108
122
  */
109
123
  if (sheet.charCodeAt(10) === 58 /* ":" */) {
110
124
  // We send through a subset of the string instead of the full pseudo name.
111
125
  // For example `"focus-visible"` name would instead of `"us-visible"`.
112
126
  // Return a mapped pseudo else the default catch all bucket.
113
- return pseudosMap[sheet.slice(14, sheet.indexOf('{'))] || '';
127
+ const mapped = pseudosMap[sheet.slice(14, firstBracket)];
128
+ if (mapped)
129
+ return mapped;
130
+ }
131
+ const property = sheet.slice(firstBracket + 1, sheet.indexOf(':', firstBracket)).trim();
132
+ const shorthandDepth = getShorthandDepth(property);
133
+ if (typeof shorthandDepth === 'number') {
134
+ return `s-${shorthandDepth}`;
114
135
  }
115
136
  // Return default catch all bucket
116
137
  return '';
@@ -1 +1 @@
1
- {"version":3,"file":"sheet.js","sourceRoot":"","sources":["../../../src/runtime/sheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG1C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAa;IAC3C,YAAY;IACZ,EAAE;IACF,OAAO;IACP,GAAG;IACH,UAAU;IACV,GAAG;IACH,eAAe;IACf,GAAG;IACH,QAAQ;IACR,GAAG;IACH,gBAAgB;IAChB,GAAG;IACH,QAAQ;IACR,GAAG;IACH,SAAS;IACT,GAAG;IACH,WAAW;IACX,GAAG;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAA8C,EAAE,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,UAA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Ac,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACtC,OAAO,KAAK,cAAc,EAAW,CAAC;KACvC;IAED,kCAAkC;IAClC,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,GAAW,EAAE,IAAoB;IAClE,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,wBAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEzD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAsB,CAAC;QAE3C,uGAAuG;QACvG,IAAI;YACF,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC9C;QAAC,WAAM,GAAE;KACX;SAAM;QACL,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;KACjD;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Depths } from '@compiled/utils';
2
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
3
+ * 0 – `all`
4
+ * 1 – `border`, `margin`, `flex`, etc
5
+ * 2 – `border-block`, `border-top` `margin-inline`
6
+ * 3 – `border-block-end`, etc
7
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
8
+ */
9
+ export declare const getShorthandDepth: (shorthand: string) => Depths | null;
@@ -0,0 +1,87 @@
1
+ // Copied from packages/utils/src/shorthand.ts so that we avoid
2
+ // inflating the bundle size of @compiled/react/runtime with the contents
3
+ // of @compiled/utils
4
+ //
5
+ // Keep this `shorthandBuckets` in sync with the `shorthandBuckets` defined in
6
+ // packages/utils/src/shorthand.ts
7
+ const shorthandBuckets = {
8
+ all: 0,
9
+ animation: 1,
10
+ 'animation-range': 1,
11
+ background: 1,
12
+ border: 1,
13
+ 'border-color': 2,
14
+ 'border-style': 2,
15
+ 'border-width': 2,
16
+ 'border-block': 3,
17
+ 'border-inline': 3,
18
+ 'border-top': 4,
19
+ 'border-right': 4,
20
+ 'border-bottom': 4,
21
+ 'border-left': 4,
22
+ 'border-block-start': 5,
23
+ 'border-block-end': 5,
24
+ 'border-inline-start': 5,
25
+ 'border-inline-end': 5,
26
+ 'border-image': 1,
27
+ 'border-radius': 1,
28
+ 'column-rule': 1,
29
+ columns: 1,
30
+ 'contain-intrinsic-size': 1,
31
+ container: 1,
32
+ flex: 1,
33
+ 'flex-flow': 1,
34
+ font: 1,
35
+ 'font-synthesis': 1,
36
+ 'font-variant': 2,
37
+ gap: 1,
38
+ grid: 1,
39
+ 'grid-area': 1,
40
+ 'grid-column': 2,
41
+ 'grid-row': 2,
42
+ 'grid-template': 2,
43
+ inset: 1,
44
+ 'inset-block': 2,
45
+ 'inset-inline': 2,
46
+ 'list-style': 1,
47
+ margin: 1,
48
+ 'margin-block': 2,
49
+ 'margin-inline': 2,
50
+ mask: 1,
51
+ 'mask-border': 1,
52
+ offset: 1,
53
+ outline: 1,
54
+ overflow: 1,
55
+ 'overscroll-behavior': 1,
56
+ padding: 1,
57
+ 'padding-block': 2,
58
+ 'padding-inline': 2,
59
+ 'place-content': 1,
60
+ 'place-items': 1,
61
+ 'place-self': 1,
62
+ 'position-try': 1,
63
+ 'scroll-margin': 1,
64
+ 'scroll-margin-block': 2,
65
+ 'scroll-margin-inline': 2,
66
+ 'scroll-padding': 1,
67
+ 'scroll-padding-block': 2,
68
+ 'scroll-padding-inline': 2,
69
+ 'scroll-timeline': 1,
70
+ 'text-decoration': 1,
71
+ 'text-emphasis': 1,
72
+ 'text-wrap': 1,
73
+ transition: 1,
74
+ 'view-timeline': 1,
75
+ };
76
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
77
+ * 0 – `all`
78
+ * 1 – `border`, `margin`, `flex`, etc
79
+ * 2 – `border-block`, `border-top` `margin-inline`
80
+ * 3 – `border-block-end`, etc
81
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
82
+ */
83
+ export const getShorthandDepth = (shorthand) => {
84
+ var _a;
85
+ return (_a = shorthandBuckets[shorthand]) !== null && _a !== void 0 ? _a : null;
86
+ };
87
+ //# sourceMappingURL=shorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shorthand.js","sourceRoot":"","sources":["../../../src/runtime/shorthand.ts"],"names":[],"mappings":"AAMA,+DAA+D;AAC/D,yEAAyE;AACzE,qBAAqB;AACrB,EAAE;AACF,8EAA8E;AAC9E,kCAAkC;AAClC,MAAM,gBAAgB,GAAgC;IACpD,GAAG,EAAE,CAAC;IACN,SAAS,EAAE,CAAC;IACZ,iBAAiB,EAAE,CAAC;IACpB,UAAU,EAAE,CAAC;IAEb,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IAEjB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAElB,YAAY,EAAE,CAAC;IACf,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAEhB,oBAAoB,EAAE,CAAC;IACvB,kBAAkB,EAAE,CAAC;IACrB,qBAAqB,EAAE,CAAC;IACxB,mBAAmB,EAAE,CAAC;IAEtB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAElB,aAAa,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC;IACV,wBAAwB,EAAE,CAAC;IAC3B,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,CAAC;IACP,WAAW,EAAE,CAAC;IACd,IAAI,EAAE,CAAC;IACP,gBAAgB,EAAE,CAAC;IACnB,cAAc,EAAE,CAAC;IACjB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,CAAC;IAClB,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,CAAC;IAChB,cAAc,EAAE,CAAC;IACjB,YAAY,EAAE,CAAC;IAEf,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAElB,IAAI,EAAE,CAAC;IACP,aAAa,EAAE,CAAC;IAChB,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,qBAAqB,EAAE,CAAC;IAExB,OAAO,EAAE,CAAC;IACV,eAAe,EAAE,CAAC;IAClB,gBAAgB,EAAE,CAAC;IAEnB,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,cAAc,EAAE,CAAC;IAEjB,eAAe,EAAE,CAAC;IAClB,qBAAqB,EAAE,CAAC;IACxB,sBAAsB,EAAE,CAAC;IAEzB,gBAAgB,EAAE,CAAC;IACnB,sBAAsB,EAAE,CAAC;IACzB,uBAAuB,EAAE,CAAC;IAE1B,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,CAAC;IAClB,WAAW,EAAE,CAAC;IACd,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAiB,EAAE;;IACpE,OAAO,MAAA,gBAAgB,CAAC,SAAgC,CAAC,mCAAI,IAAI,CAAC;AACpE,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { Depths } from '@compiled/utils';
2
3
  export interface StyleSheetOpts {
3
4
  /**
4
5
  * Used to set a nonce on the style element.
@@ -10,7 +11,7 @@ export interface StyleSheetOpts {
10
11
  /**
11
12
  * Buckets under which we will group our stylesheets
12
13
  */
13
- export type Bucket = '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
+ export type Bucket = `s-${Depths}` | '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
15
  export type UseCacheHook = () => Record<string, true>;
15
16
  export type ProviderComponent = (props: {
16
17
  children: JSX.Element[] | JSX.Element;
@@ -1,7 +1,12 @@
1
1
  import type { Bucket, StyleSheetOpts } from './types';
2
2
  /**
3
- * Ordered style buckets using their short psuedo name.
4
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
3
+ * Ordered style buckets using their short pseudo name.
4
+ *
5
+ * This is very bare-bones, with no support for nesting, like styles in
6
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
7
+ *
8
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
9
+ * definition in `packages/css/src/utils/style-ordering.ts`.
5
10
  */
6
11
  export declare const styleBucketOrdering: Bucket[];
7
12
  /**
@@ -2,11 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getStyleBucketName = exports.styleBucketOrdering = void 0;
4
4
  const cache_1 = require("./cache");
5
+ const shorthand_1 = require("./shorthand");
5
6
  /**
6
- * Ordered style buckets using their short psuedo name.
7
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
7
+ * Ordered style buckets using their short pseudo name.
8
+ *
9
+ * This is very bare-bones, with no support for nesting, like styles in
10
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
11
+ *
12
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
13
+ * definition in `packages/css/src/utils/style-ordering.ts`.
8
14
  */
9
15
  exports.styleBucketOrdering = [
16
+ // shorthand properties
17
+ 's-0',
18
+ 's-1',
19
+ 's-2',
20
+ 's-3',
21
+ 's-4',
22
+ 's-5',
10
23
  // catch-all
11
24
  '',
12
25
  // link
@@ -33,8 +46,8 @@ const styleBucketsInHead = {};
33
46
  /**
34
47
  * Maps the long pseudo name to the short pseudo name.
35
48
  * Pseudos that match here will be ordered,
36
- * everythin else will make their way to the catch all style bucket.
37
- * We reduce the pseduo name to save bundlesize.
49
+ * everything else will make their way to the catch all style bucket.
50
+ * We reduce the pseudo name to save bundlesize.
38
51
  * Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes.
39
52
  */
40
53
  const pseudosMap = {
@@ -105,15 +118,23 @@ const getStyleBucketName = (sheet) => {
105
118
  if (sheet.charCodeAt(0) === 64 /* "@" */) {
106
119
  return 'm';
107
120
  }
121
+ const firstBracket = sheet.indexOf('{');
108
122
  /**
109
123
  * We assume that classname will always be 9 character long,
110
- * using this the 10th character could be a pseudo declaration.
124
+ * using this the 10th characters could be a pseudo declaration.
111
125
  */
112
126
  if (sheet.charCodeAt(10) === 58 /* ":" */) {
113
127
  // We send through a subset of the string instead of the full pseudo name.
114
128
  // For example `"focus-visible"` name would instead of `"us-visible"`.
115
129
  // Return a mapped pseudo else the default catch all bucket.
116
- return pseudosMap[sheet.slice(14, sheet.indexOf('{'))] || '';
130
+ const mapped = pseudosMap[sheet.slice(14, firstBracket)];
131
+ if (mapped)
132
+ return mapped;
133
+ }
134
+ const property = sheet.slice(firstBracket + 1, sheet.indexOf(':', firstBracket)).trim();
135
+ const shorthandDepth = (0, shorthand_1.getShorthandDepth)(property);
136
+ if (typeof shorthandDepth === 'number') {
137
+ return `s-${shorthandDepth}`;
117
138
  }
118
139
  // Return default catch all bucket
119
140
  return '';
@@ -1 +1 @@
1
- {"version":3,"file":"sheet.js","sourceRoot":"","sources":["../../../src/runtime/sheet.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAG1C;;;GAGG;AACU,QAAA,mBAAmB,GAAa;IAC3C,YAAY;IACZ,EAAE;IACF,OAAO;IACP,GAAG;IACH,UAAU;IACV,GAAG;IACH,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K,CAAC,YAAY,GAAG,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAExF,MAAM,cAAc,GAAG,IAAA,6BAAiB,EAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACtC,OAAO,KAAK,cAAc,EAAW,CAAC;KACvC;IAED,kCAAkC;IAClC,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AA7BW,QAAA,kBAAkB,sBA6B7B;AAEF;;;;;GAKG;AACH,SAAwB,UAAU,CAAC,GAAW,EAAE,IAAoB;IAClE,MAAM,UAAU,GAAG,IAAA,0BAAkB,EAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,wBAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEzD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAsB,CAAC;QAE3C,uGAAuG;QACvG,IAAI;YACF,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC9C;QAAC,WAAM,GAAE;KACX;SAAM;QACL,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;KACjD;AACH,CAAC;AAdD,6BAcC"}
@@ -0,0 +1,9 @@
1
+ import type { Depths } from '@compiled/utils';
2
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
3
+ * 0 – `all`
4
+ * 1 – `border`, `margin`, `flex`, etc
5
+ * 2 – `border-block`, `border-top` `margin-inline`
6
+ * 3 – `border-block-end`, etc
7
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
8
+ */
9
+ export declare const getShorthandDepth: (shorthand: string) => Depths | null;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getShorthandDepth = void 0;
4
+ // Copied from packages/utils/src/shorthand.ts so that we avoid
5
+ // inflating the bundle size of @compiled/react/runtime with the contents
6
+ // of @compiled/utils
7
+ //
8
+ // Keep this `shorthandBuckets` in sync with the `shorthandBuckets` defined in
9
+ // packages/utils/src/shorthand.ts
10
+ const shorthandBuckets = {
11
+ all: 0,
12
+ animation: 1,
13
+ 'animation-range': 1,
14
+ background: 1,
15
+ border: 1,
16
+ 'border-color': 2,
17
+ 'border-style': 2,
18
+ 'border-width': 2,
19
+ 'border-block': 3,
20
+ 'border-inline': 3,
21
+ 'border-top': 4,
22
+ 'border-right': 4,
23
+ 'border-bottom': 4,
24
+ 'border-left': 4,
25
+ 'border-block-start': 5,
26
+ 'border-block-end': 5,
27
+ 'border-inline-start': 5,
28
+ 'border-inline-end': 5,
29
+ 'border-image': 1,
30
+ 'border-radius': 1,
31
+ 'column-rule': 1,
32
+ columns: 1,
33
+ 'contain-intrinsic-size': 1,
34
+ container: 1,
35
+ flex: 1,
36
+ 'flex-flow': 1,
37
+ font: 1,
38
+ 'font-synthesis': 1,
39
+ 'font-variant': 2,
40
+ gap: 1,
41
+ grid: 1,
42
+ 'grid-area': 1,
43
+ 'grid-column': 2,
44
+ 'grid-row': 2,
45
+ 'grid-template': 2,
46
+ inset: 1,
47
+ 'inset-block': 2,
48
+ 'inset-inline': 2,
49
+ 'list-style': 1,
50
+ margin: 1,
51
+ 'margin-block': 2,
52
+ 'margin-inline': 2,
53
+ mask: 1,
54
+ 'mask-border': 1,
55
+ offset: 1,
56
+ outline: 1,
57
+ overflow: 1,
58
+ 'overscroll-behavior': 1,
59
+ padding: 1,
60
+ 'padding-block': 2,
61
+ 'padding-inline': 2,
62
+ 'place-content': 1,
63
+ 'place-items': 1,
64
+ 'place-self': 1,
65
+ 'position-try': 1,
66
+ 'scroll-margin': 1,
67
+ 'scroll-margin-block': 2,
68
+ 'scroll-margin-inline': 2,
69
+ 'scroll-padding': 1,
70
+ 'scroll-padding-block': 2,
71
+ 'scroll-padding-inline': 2,
72
+ 'scroll-timeline': 1,
73
+ 'text-decoration': 1,
74
+ 'text-emphasis': 1,
75
+ 'text-wrap': 1,
76
+ transition: 1,
77
+ 'view-timeline': 1,
78
+ };
79
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
80
+ * 0 – `all`
81
+ * 1 – `border`, `margin`, `flex`, etc
82
+ * 2 – `border-block`, `border-top` `margin-inline`
83
+ * 3 – `border-block-end`, etc
84
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
85
+ */
86
+ const getShorthandDepth = (shorthand) => {
87
+ var _a;
88
+ return (_a = shorthandBuckets[shorthand]) !== null && _a !== void 0 ? _a : null;
89
+ };
90
+ exports.getShorthandDepth = getShorthandDepth;
91
+ //# sourceMappingURL=shorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shorthand.js","sourceRoot":"","sources":["../../../src/runtime/shorthand.ts"],"names":[],"mappings":";;;AAMA,+DAA+D;AAC/D,yEAAyE;AACzE,qBAAqB;AACrB,EAAE;AACF,8EAA8E;AAC9E,kCAAkC;AAClC,MAAM,gBAAgB,GAAgC;IACpD,GAAG,EAAE,CAAC;IACN,SAAS,EAAE,CAAC;IACZ,iBAAiB,EAAE,CAAC;IACpB,UAAU,EAAE,CAAC;IAEb,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IAEjB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAElB,YAAY,EAAE,CAAC;IACf,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAEhB,oBAAoB,EAAE,CAAC;IACvB,kBAAkB,EAAE,CAAC;IACrB,qBAAqB,EAAE,CAAC;IACxB,mBAAmB,EAAE,CAAC;IAEt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AiB,GAAG,CAAC,SAAiB,EAAiB,EAAE;;IACpE,OAAO,MAAA,gBAAgB,CAAC,SAAgC,CAAC,mCAAI,IAAI,CAAC;AACpE,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { Depths } from '@compiled/utils';
2
3
  export interface StyleSheetOpts {
3
4
  /**
4
5
  * Used to set a nonce on the style element.
@@ -10,7 +11,7 @@ export interface StyleSheetOpts {
10
11
  /**
11
12
  * Buckets under which we will group our stylesheets
12
13
  */
13
- export type Bucket = '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
+ export type Bucket = `s-${Depths}` | '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
15
  export type UseCacheHook = () => Record<string, true>;
15
16
  export type ProviderComponent = (props: {
16
17
  children: JSX.Element[] | JSX.Element;
@@ -1,7 +1,12 @@
1
1
  import type { Bucket, StyleSheetOpts } from './types';
2
2
  /**
3
- * Ordered style buckets using their short psuedo name.
4
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
3
+ * Ordered style buckets using their short pseudo name.
4
+ *
5
+ * This is very bare-bones, with no support for nesting, like styles in
6
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
7
+ *
8
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
9
+ * definition in `packages/css/src/utils/style-ordering.ts`.
5
10
  */
6
11
  export declare const styleBucketOrdering: Bucket[];
7
12
  /**
@@ -1,9 +1,22 @@
1
1
  import { isCacheDisabled } from './cache';
2
+ import { getShorthandDepth } from './shorthand';
2
3
  /**
3
- * Ordered style buckets using their short psuedo name.
4
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
4
+ * Ordered style buckets using their short pseudo name.
5
+ *
6
+ * This is very bare-bones, with no support for nesting, like styles in
7
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
8
+ *
9
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
10
+ * definition in `packages/css/src/utils/style-ordering.ts`.
5
11
  */
6
12
  export const styleBucketOrdering = [
13
+ // shorthand properties
14
+ 's-0',
15
+ 's-1',
16
+ 's-2',
17
+ 's-3',
18
+ 's-4',
19
+ 's-5',
7
20
  // catch-all
8
21
  '',
9
22
  // link
@@ -30,8 +43,8 @@ const styleBucketsInHead = {};
30
43
  /**
31
44
  * Maps the long pseudo name to the short pseudo name.
32
45
  * Pseudos that match here will be ordered,
33
- * everythin else will make their way to the catch all style bucket.
34
- * We reduce the pseduo name to save bundlesize.
46
+ * everything else will make their way to the catch all style bucket.
47
+ * We reduce the pseudo name to save bundlesize.
35
48
  * Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes.
36
49
  */
37
50
  const pseudosMap = {
@@ -102,15 +115,23 @@ export const getStyleBucketName = (sheet) => {
102
115
  if (sheet.charCodeAt(0) === 64 /* "@" */) {
103
116
  return 'm';
104
117
  }
118
+ const firstBracket = sheet.indexOf('{');
105
119
  /**
106
120
  * We assume that classname will always be 9 character long,
107
- * using this the 10th character could be a pseudo declaration.
121
+ * using this the 10th characters could be a pseudo declaration.
108
122
  */
109
123
  if (sheet.charCodeAt(10) === 58 /* ":" */) {
110
124
  // We send through a subset of the string instead of the full pseudo name.
111
125
  // For example `"focus-visible"` name would instead of `"us-visible"`.
112
126
  // Return a mapped pseudo else the default catch all bucket.
113
- return pseudosMap[sheet.slice(14, sheet.indexOf('{'))] || '';
127
+ const mapped = pseudosMap[sheet.slice(14, firstBracket)];
128
+ if (mapped)
129
+ return mapped;
130
+ }
131
+ const property = sheet.slice(firstBracket + 1, sheet.indexOf(':', firstBracket)).trim();
132
+ const shorthandDepth = getShorthandDepth(property);
133
+ if (typeof shorthandDepth === 'number') {
134
+ return `s-${shorthandDepth}`;
114
135
  }
115
136
  // Return default catch all bucket
116
137
  return '';
@@ -1 +1 @@
1
-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 /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
3
+ * 0 – `all`
4
+ * 1 – `border`, `margin`, `flex`, etc
5
+ * 2 – `border-block`, `border-top` `margin-inline`
6
+ * 3 – `border-block-end`, etc
7
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
8
+ */
9
+ export declare const getShorthandDepth: (shorthand: string) => Depths | null;
@@ -0,0 +1,87 @@
1
+ // Copied from packages/utils/src/shorthand.ts so that we avoid
2
+ // inflating the bundle size of @compiled/react/runtime with the contents
3
+ // of @compiled/utils
4
+ //
5
+ // Keep this `shorthandBuckets` in sync with the `shorthandBuckets` defined in
6
+ // packages/utils/src/shorthand.ts
7
+ const shorthandBuckets = {
8
+ all: 0,
9
+ animation: 1,
10
+ 'animation-range': 1,
11
+ background: 1,
12
+ border: 1,
13
+ 'border-color': 2,
14
+ 'border-style': 2,
15
+ 'border-width': 2,
16
+ 'border-block': 3,
17
+ 'border-inline': 3,
18
+ 'border-top': 4,
19
+ 'border-right': 4,
20
+ 'border-bottom': 4,
21
+ 'border-left': 4,
22
+ 'border-block-start': 5,
23
+ 'border-block-end': 5,
24
+ 'border-inline-start': 5,
25
+ 'border-inline-end': 5,
26
+ 'border-image': 1,
27
+ 'border-radius': 1,
28
+ 'column-rule': 1,
29
+ columns: 1,
30
+ 'contain-intrinsic-size': 1,
31
+ container: 1,
32
+ flex: 1,
33
+ 'flex-flow': 1,
34
+ font: 1,
35
+ 'font-synthesis': 1,
36
+ 'font-variant': 2,
37
+ gap: 1,
38
+ grid: 1,
39
+ 'grid-area': 1,
40
+ 'grid-column': 2,
41
+ 'grid-row': 2,
42
+ 'grid-template': 2,
43
+ inset: 1,
44
+ 'inset-block': 2,
45
+ 'inset-inline': 2,
46
+ 'list-style': 1,
47
+ margin: 1,
48
+ 'margin-block': 2,
49
+ 'margin-inline': 2,
50
+ mask: 1,
51
+ 'mask-border': 1,
52
+ offset: 1,
53
+ outline: 1,
54
+ overflow: 1,
55
+ 'overscroll-behavior': 1,
56
+ padding: 1,
57
+ 'padding-block': 2,
58
+ 'padding-inline': 2,
59
+ 'place-content': 1,
60
+ 'place-items': 1,
61
+ 'place-self': 1,
62
+ 'position-try': 1,
63
+ 'scroll-margin': 1,
64
+ 'scroll-margin-block': 2,
65
+ 'scroll-margin-inline': 2,
66
+ 'scroll-padding': 1,
67
+ 'scroll-padding-block': 2,
68
+ 'scroll-padding-inline': 2,
69
+ 'scroll-timeline': 1,
70
+ 'text-decoration': 1,
71
+ 'text-emphasis': 1,
72
+ 'text-wrap': 1,
73
+ transition: 1,
74
+ 'view-timeline': 1,
75
+ };
76
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
77
+ * 0 – `all`
78
+ * 1 – `border`, `margin`, `flex`, etc
79
+ * 2 – `border-block`, `border-top` `margin-inline`
80
+ * 3 – `border-block-end`, etc
81
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
82
+ */
83
+ export const getShorthandDepth = (shorthand) => {
84
+ var _a;
85
+ return (_a = shorthandBuckets[shorthand]) !== null && _a !== void 0 ? _a : null;
86
+ };
87
+ //# sourceMappingURL=shorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shorthand.js","sourceRoot":"","sources":["../../../src/runtime/shorthand.ts"],"names":[],"mappings":"AAMA,+DAA+D;AAC/D,yEAAyE;AACzE,qBAAqB;AACrB,EAAE;AACF,8EAA8E;AAC9E,kCAAkC;AAClC,MAAM,gBAAgB,GAAgC;IACpD,GAAG,EAAE,CAAC;IACN,SAAS,EAAE,CAAC;IACZ,iBAAiB,EAAE,CAAC;IACpB,UAAU,EAAE,CAAC;IAEb,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IAEjB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAElB,YAAY,EAAE,CAAC;IACf,cAAc,EA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AAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,CAAC;IAClB,WAAW,EAAE,CAAC;IACd,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAiB,EAAE;;IACpE,OAAO,MAAA,gBAAgB,CAAC,SAAgC,CAAC,mCAAI,IAAI,CAAC;AACpE,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { Depths } from '@compiled/utils';
2
3
  export interface StyleSheetOpts {
3
4
  /**
4
5
  * Used to set a nonce on the style element.
@@ -10,7 +11,7 @@ export interface StyleSheetOpts {
10
11
  /**
11
12
  * Buckets under which we will group our stylesheets
12
13
  */
13
- export type Bucket = '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
+ export type Bucket = `s-${Depths}` | '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
14
15
  export type UseCacheHook = () => Record<string, true>;
15
16
  export type ProviderComponent = (props: {
16
17
  children: JSX.Element[] | JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.17.3",
3
+ "version": "0.18.0",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -76,6 +76,7 @@
76
76
  },
77
77
  "devDependencies": {
78
78
  "@compiled/benchmark": "^1.1.0",
79
+ "@compiled/utils": "^0.12.0",
79
80
  "@fixture/strict-api-test": "*",
80
81
  "@testing-library/react": "^12.1.5",
81
82
  "@types/jsdom": "^16.2.15",
@@ -43,12 +43,19 @@ describe('<Style />', () => {
43
43
  `._g1234567:visited{ color: grey; }`,
44
44
  `._h1234567:focus-visible{ color: white; }`,
45
45
  `._i1234567:focus-within{ color: black; }`,
46
+ `._j1234567{ border: none; }`,
47
+ `._j1234567{ border-top: 1px solid transparent; }`,
48
+ `._j1234567{ border-top-color: red; }`,
49
+ `._j1234567:focus{ border-top-color: transparent; }`,
50
+ `._j1234567:focus{ border-color: blue; }`,
51
+ `._j1234567:focus{ border: 1px solid; }`,
46
52
  ]}
47
53
  </Style>
48
54
  );
49
55
 
56
+ // WARNING: This is wrong, the `focus` border properties are different than without focus, borders would be indeterministic.
50
57
  expect(result.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
51
- "<style data-cmpld="true">._c1234567{ display: block; }._d1234567:link{ color: green; }._g1234567:visited{ color: grey; }._i1234567:focus-within{ color: black; }._f1234567:focus{ color: pink; }._h1234567:focus-visible{ color: white; }._a1234567:hover{ color: red; }._b1234567:active{ color: blue; }@media (max-width: 800px){ ._e1234567{ color: yellow; } }</style>
58
+ "<style data-cmpld="true">._j1234567{ border: none; }._j1234567{ border-top: 1px solid transparent; }._c1234567{ display: block; }._j1234567{ border-top-color: red; }._d1234567:link{ color: green; }._g1234567:visited{ color: grey; }._i1234567:focus-within{ color: black; }._f1234567:focus{ color: pink; }._j1234567:focus{ border-top-color: transparent; }._j1234567:focus{ border-color: blue; }._j1234567:focus{ border: 1px solid; }._h1234567:focus-visible{ color: white; }._a1234567:hover{ color: red; }._b1234567:active{ color: blue; }@media (max-width: 800px){ ._e1234567{ color: yellow; } }</style>
52
59
  "
53
60
  `);
54
61
  });
@@ -66,7 +66,7 @@ describe('<Style />', () => {
66
66
  });
67
67
  });
68
68
 
69
- it('should warn in dev when using a dangerous pseduo selector', () => {
69
+ it('should warn in dev when using a dangerous pseudo selector', () => {
70
70
  createIsolatedTest((Style) => {
71
71
  process.env.NODE_ENV = 'development';
72
72
 
@@ -124,6 +124,50 @@ describe('<Style />', () => {
124
124
  });
125
125
  });
126
126
 
127
+ it('should render shorthands in buckets', () => {
128
+ // Our buckets don't actually support mixing pseudo-selectors with shorthand
129
+ // properties, so the pseudo-selector buckets don't have correct shorthand
130
+ // property order...
131
+ createIsolatedTest((Style) => {
132
+ render(
133
+ <Style>
134
+ {[
135
+ `._a1234567:hover{ all: revert; }`,
136
+ `._a1234567{ all: unset; }`,
137
+ `._b1234567{ border: solid 1px blue; }`,
138
+ `._c1234567{ border-block: solid 2px blue; }`,
139
+ `._d1234567{ border-block-end: solid 3px blue; }`,
140
+ `._e1234567{ border-bottom: solid 4px blue; }`,
141
+ `._g1234567{ border-inline: solid 5px blue; }`,
142
+ `._h1234567{ border-top: solid 6px blue; }`,
143
+ `._i1234567{ border-top-color: pink; }`,
144
+ `._j1234567{ padding: 5px; }`,
145
+ `._k1234567{ padding-block: 6px; }`,
146
+ `._l1234567{ padding-inline: 7px; }`,
147
+ `._m1234567{ padding-top: 8px; }`,
148
+
149
+ `._g1234567:hover{ border-inline: solid 5px blue; }`,
150
+ `._k1234567:hover{ padding-block: 6px; }`,
151
+ `._l1234567:hover{ padding-inline: 7px; }`,
152
+ `._j1234567:hover{ padding: 5px; }`,
153
+ ]}
154
+ </Style>
155
+ );
156
+ expect(document.head.innerHTML.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
157
+ "<style>._a1234567{ all: unset; }</style>
158
+ <style>._b1234567{ border: solid 1px blue; }._j1234567{ padding: 5px; }</style>
159
+ <style>._k1234567{ padding-block: 6px; }._l1234567{ padding-inline: 7px; }</style>
160
+ <style>._c1234567{ border-block: solid 2px blue; }._g1234567{ border-inline: solid 5px blue; }</style>
161
+ <style>._e1234567{ border-bottom: solid 4px blue; }._h1234567{ border-top: solid 6px blue; }</style>
162
+ <style>._d1234567{ border-block-end: solid 3px blue; }</style>
163
+ <style>._i1234567{ border-top-color: pink; }._m1234567{ padding-top: 8px; }</style>
164
+ <style>._a1234567:hover{ all: revert; }._g1234567:hover{ border-inline: solid 5px blue; }._k1234567:hover{ padding-block: 6px; }._l1234567:hover{ padding-inline: 7px; }._j1234567:hover{ padding: 5px; }</style>
165
+ "
166
+ `);
167
+ expect(console.error).not.toHaveBeenCalled();
168
+ });
169
+ });
170
+
127
171
  it('should update styles', () => {
128
172
  createIsolatedTest((Style) => {
129
173
  const { rerender } = render(<Style>{[`.first-render { display: block; }`]}</Style>);
@@ -1,11 +1,24 @@
1
1
  import { isCacheDisabled } from './cache';
2
+ import { getShorthandDepth } from './shorthand';
2
3
  import type { Bucket, StyleSheetOpts } from './types';
3
4
 
4
5
  /**
5
- * Ordered style buckets using their short psuedo name.
6
- * If changes are needed make sure that it aligns with the definition in `sort-at-rule-pseudos.tsx`.
6
+ * Ordered style buckets using their short pseudo name.
7
+ *
8
+ * This is very bare-bones, with no support for nesting, like styles in
9
+ * `@media` queries, pseudo-selectors mixed with shorthand properties, etc.
10
+ *
11
+ * If changes are needed to the pseudo-selectors, make sure that it aligns with the
12
+ * definition in `packages/css/src/utils/style-ordering.ts`.
7
13
  */
8
14
  export const styleBucketOrdering: Bucket[] = [
15
+ // shorthand properties
16
+ 's-0',
17
+ 's-1',
18
+ 's-2',
19
+ 's-3',
20
+ 's-4',
21
+ 's-5',
9
22
  // catch-all
10
23
  '',
11
24
  // link
@@ -34,8 +47,8 @@ const styleBucketsInHead: Partial<Record<Bucket, HTMLStyleElement>> = {};
34
47
  /**
35
48
  * Maps the long pseudo name to the short pseudo name.
36
49
  * Pseudos that match here will be ordered,
37
- * everythin else will make their way to the catch all style bucket.
38
- * We reduce the pseduo name to save bundlesize.
50
+ * everything else will make their way to the catch all style bucket.
51
+ * We reduce the pseudo name to save bundlesize.
39
52
  * Thankfully there aren't any overlaps, see: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes.
40
53
  */
41
54
  const pseudosMap: Record<string, Bucket | undefined> = {
@@ -114,15 +127,25 @@ export const getStyleBucketName = (sheet: string): Bucket => {
114
127
  return 'm';
115
128
  }
116
129
 
130
+ const firstBracket = sheet.indexOf('{');
131
+
117
132
  /**
118
133
  * We assume that classname will always be 9 character long,
119
- * using this the 10th character could be a pseudo declaration.
134
+ * using this the 10th characters could be a pseudo declaration.
120
135
  */
121
136
  if (sheet.charCodeAt(10) === 58 /* ":" */) {
122
137
  // We send through a subset of the string instead of the full pseudo name.
123
138
  // For example `"focus-visible"` name would instead of `"us-visible"`.
124
139
  // Return a mapped pseudo else the default catch all bucket.
125
- return pseudosMap[sheet.slice(14, sheet.indexOf('{'))] || '';
140
+ const mapped = pseudosMap[sheet.slice(14, firstBracket)];
141
+ if (mapped) return mapped;
142
+ }
143
+
144
+ const property = sheet.slice(firstBracket + 1, sheet.indexOf(':', firstBracket)).trim();
145
+
146
+ const shorthandDepth = getShorthandDepth(property);
147
+ if (typeof shorthandDepth === 'number') {
148
+ return `s-${shorthandDepth}` as const;
126
149
  }
127
150
 
128
151
  // Return default catch all bucket
@@ -0,0 +1,105 @@
1
+ import type {
2
+ Depths,
3
+ ShorthandProperties,
4
+ shorthandBuckets as ShorthandBucketsType,
5
+ } from '@compiled/utils';
6
+
7
+ // Copied from packages/utils/src/shorthand.ts so that we avoid
8
+ // inflating the bundle size of @compiled/react/runtime with the contents
9
+ // of @compiled/utils
10
+ //
11
+ // Keep this `shorthandBuckets` in sync with the `shorthandBuckets` defined in
12
+ // packages/utils/src/shorthand.ts
13
+ const shorthandBuckets: typeof ShorthandBucketsType = {
14
+ all: 0,
15
+ animation: 1,
16
+ 'animation-range': 1,
17
+ background: 1,
18
+
19
+ border: 1,
20
+ 'border-color': 2,
21
+ 'border-style': 2,
22
+ 'border-width': 2,
23
+
24
+ 'border-block': 3,
25
+ 'border-inline': 3,
26
+
27
+ 'border-top': 4,
28
+ 'border-right': 4,
29
+ 'border-bottom': 4,
30
+ 'border-left': 4,
31
+
32
+ 'border-block-start': 5,
33
+ 'border-block-end': 5,
34
+ 'border-inline-start': 5,
35
+ 'border-inline-end': 5,
36
+
37
+ 'border-image': 1,
38
+ 'border-radius': 1,
39
+
40
+ 'column-rule': 1,
41
+ columns: 1,
42
+ 'contain-intrinsic-size': 1,
43
+ container: 1,
44
+ flex: 1,
45
+ 'flex-flow': 1,
46
+ font: 1,
47
+ 'font-synthesis': 1,
48
+ 'font-variant': 2,
49
+ gap: 1,
50
+ grid: 1,
51
+ 'grid-area': 1,
52
+ 'grid-column': 2,
53
+ 'grid-row': 2,
54
+ 'grid-template': 2,
55
+ inset: 1,
56
+ 'inset-block': 2,
57
+ 'inset-inline': 2,
58
+ 'list-style': 1,
59
+
60
+ margin: 1,
61
+ 'margin-block': 2,
62
+ 'margin-inline': 2,
63
+
64
+ mask: 1,
65
+ 'mask-border': 1,
66
+ offset: 1,
67
+ outline: 1,
68
+ overflow: 1,
69
+ 'overscroll-behavior': 1,
70
+
71
+ padding: 1,
72
+ 'padding-block': 2,
73
+ 'padding-inline': 2,
74
+
75
+ 'place-content': 1,
76
+ 'place-items': 1,
77
+ 'place-self': 1,
78
+ 'position-try': 1,
79
+
80
+ 'scroll-margin': 1,
81
+ 'scroll-margin-block': 2,
82
+ 'scroll-margin-inline': 2,
83
+
84
+ 'scroll-padding': 1,
85
+ 'scroll-padding-block': 2,
86
+ 'scroll-padding-inline': 2,
87
+
88
+ 'scroll-timeline': 1,
89
+ 'text-decoration': 1,
90
+ 'text-emphasis': 1,
91
+ 'text-wrap': 1,
92
+ transition: 1,
93
+ 'view-timeline': 1,
94
+ };
95
+
96
+ /** We look at shorthands to determine what level they are because we need some shorthands to override other shorthands…
97
+ * 0 – `all`
98
+ * 1 – `border`, `margin`, `flex`, etc
99
+ * 2 – `border-block`, `border-top` `margin-inline`
100
+ * 3 – `border-block-end`, etc
101
+ * null – `border-top-color`, `border-block-start-color`, `margin-block-start`, `margin-top`, etc (not shorthands)
102
+ */
103
+ export const getShorthandDepth = (shorthand: string): Depths | null => {
104
+ return shorthandBuckets[shorthand as ShorthandProperties] ?? null;
105
+ };
@@ -1,3 +1,5 @@
1
+ import type { Depths } from '@compiled/utils';
2
+
1
3
  export interface StyleSheetOpts {
2
4
  /**
3
5
  * Used to set a nonce on the style element.
@@ -11,6 +13,8 @@ export interface StyleSheetOpts {
11
13
  * Buckets under which we will group our stylesheets
12
14
  */
13
15
  export type Bucket =
16
+ // shorthand properties
17
+ | `s-${Depths}`
14
18
  // catch-all
15
19
  | ''
16
20
  // link