@griffel/react 1.1.0 → 1.2.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/README.md CHANGED
@@ -148,6 +148,20 @@ const useClasses = makeStyles({
148
148
  });
149
149
  ```
150
150
 
151
+ ### `shorthands.flex`
152
+
153
+ ```js
154
+ import { makeStyles, shorthands } from '@griffel/react';
155
+
156
+ const useClasses = makeStyles({
157
+ root: {
158
+ ...shorthands.flex('auto'),
159
+ ...shorthands.flex(1, '2.5rem'),
160
+ ...shorthands.flex(0, 0, 'auto'),
161
+ },
162
+ });
163
+ ```
164
+
151
165
  ### `shorthands.gap`
152
166
 
153
167
  ```js
package/__css.cjs.js ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var TextDirectionContext = require('./TextDirectionContext.cjs.js');
7
+
8
+ /**
9
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms & DOM insertion.
10
+ *
11
+ * @internal
12
+ */
13
+ // eslint-disable-next-line @typescript-eslint/naming-convention
14
+
15
+ function __css(classesMapBySlot) {
16
+ const getStyles = core.__css(classesMapBySlot);
17
+ return function useClasses() {
18
+ const dir = TextDirectionContext.useTextDirection();
19
+ return getStyles({
20
+ dir
21
+ });
22
+ };
23
+ }
24
+
25
+ exports.__css = __css;
26
+ //# sourceMappingURL=__css.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__css.cjs.js","sources":["../../../packages/react/src/__css.ts"],"sourcesContent":["import { __css as vanillaCSS } from '@griffel/core';\nimport type { CSSClassesMapBySlot } from '@griffel/core';\n\nimport { useTextDirection } from './TextDirectionContext';\n\n/**\n * A version of makeStyles() that accepts build output as an input and skips all runtime transforms & DOM insertion.\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function __css<Slots extends string>(classesMapBySlot: CSSClassesMapBySlot<Slots>) {\n const getStyles = vanillaCSS(classesMapBySlot);\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n\n return getStyles({ dir });\n };\n}\n"],"names":["__css","classesMapBySlot","getStyles","vanillaCSS","useClasses","dir","useTextDirection"],"mappings":";;;;;;;AAKA;;;;;AAKA;;SACgBA,MAA4BC;AAC1C,QAAMC,SAAS,GAAGC,UAAU,CAACF,gBAAD,CAA5B;AAEA,SAAO,SAASG,UAAT;AACL,UAAMC,GAAG,GAAGC,qCAAgB,EAA5B;AAEA,WAAOJ,SAAS,CAAC;AAAEG,MAAAA;AAAF,KAAD,CAAhB;AACD,GAJD;AAKD;;;;"}
package/__css.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { CSSClassesMapBySlot } from '@griffel/core';
2
+ /**
3
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms & DOM insertion.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare function __css<Slots extends string>(classesMapBySlot: CSSClassesMapBySlot<Slots>): () => Record<Slots, string>;
package/__css.esm.js ADDED
@@ -0,0 +1,22 @@
1
+ import { __css as __css$1 } from '@griffel/core';
2
+ import { useTextDirection } from './TextDirectionContext.esm.js';
3
+
4
+ /**
5
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms & DOM insertion.
6
+ *
7
+ * @internal
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+
11
+ function __css(classesMapBySlot) {
12
+ const getStyles = __css$1(classesMapBySlot);
13
+ return function useClasses() {
14
+ const dir = useTextDirection();
15
+ return getStyles({
16
+ dir
17
+ });
18
+ };
19
+ }
20
+
21
+ export { __css };
22
+ //# sourceMappingURL=__css.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__css.esm.js","sources":["../../../packages/react/src/__css.ts"],"sourcesContent":["import { __css as vanillaCSS } from '@griffel/core';\nimport type { CSSClassesMapBySlot } from '@griffel/core';\n\nimport { useTextDirection } from './TextDirectionContext';\n\n/**\n * A version of makeStyles() that accepts build output as an input and skips all runtime transforms & DOM insertion.\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function __css<Slots extends string>(classesMapBySlot: CSSClassesMapBySlot<Slots>) {\n const getStyles = vanillaCSS(classesMapBySlot);\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n\n return getStyles({ dir });\n };\n}\n"],"names":["__css","classesMapBySlot","getStyles","vanillaCSS","useClasses","dir","useTextDirection"],"mappings":";;;AAKA;;;;;AAKA;;SACgBA,MAA4BC;AAC1C,QAAMC,SAAS,GAAGC,OAAU,CAACF,gBAAD,CAA5B;AAEA,SAAO,SAASG,UAAT;AACL,UAAMC,GAAG,GAAGC,gBAAgB,EAA5B;AAEA,WAAOJ,SAAS,CAAC;AAAEG,MAAAA;AAAF,KAAD,CAAhB;AACD,GAJD;AAKD;;;;"}
package/index.cjs.js CHANGED
@@ -8,6 +8,7 @@ var makeStaticStyles = require('./makeStaticStyles.cjs.js');
8
8
  var renderToStyleElements = require('./renderToStyleElements.cjs.js');
9
9
  var RendererContext = require('./RendererContext.cjs.js');
10
10
  var TextDirectionContext = require('./TextDirectionContext.cjs.js');
11
+ var __css = require('./__css.cjs.js');
11
12
  var __styles = require('./__styles.cjs.js');
12
13
 
13
14
 
@@ -30,5 +31,6 @@ exports.renderToStyleElements = renderToStyleElements.renderToStyleElements;
30
31
  exports.RendererProvider = RendererContext.RendererProvider;
31
32
  exports.useRenderer_unstable = RendererContext.useRenderer;
32
33
  exports.TextDirectionProvider = TextDirectionContext.TextDirectionProvider;
34
+ exports.__css = __css.__css;
33
35
  exports.__styles = __styles.__styles;
34
36
  //# sourceMappingURL=index.cjs.js.map
package/index.cjs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { makeStaticStyles } from './makeStaticStyles';
5
5
  export { renderToStyleElements } from './renderToStyleElements';
6
6
  export { RendererProvider, useRenderer as useRenderer_unstable } from './RendererContext';
7
7
  export { TextDirectionProvider } from './TextDirectionContext';
8
+ export { __css } from './__css';
8
9
  export { __styles } from './__styles';
package/index.esm.js CHANGED
@@ -4,5 +4,6 @@ export { makeStaticStyles } from './makeStaticStyles.esm.js';
4
4
  export { renderToStyleElements } from './renderToStyleElements.esm.js';
5
5
  export { RendererProvider, useRenderer as useRenderer_unstable } from './RendererContext.esm.js';
6
6
  export { TextDirectionProvider } from './TextDirectionContext.esm.js';
7
+ export { __css } from './__css.esm.js';
7
8
  export { __styles } from './__styles.esm.js';
8
9
  //# sourceMappingURL=index.esm.js.map
package/index.esm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@griffel/react",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "React implementation of Atomic CSS-in-JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "sideEffects": false,
11
11
  "dependencies": {
12
- "@griffel/core": "^1.3.1",
12
+ "@griffel/core": "^1.4.0",
13
13
  "tslib": "^2.1.0"
14
14
  },
15
15
  "peerDependencies": {
@@ -32,34 +32,39 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
32
  */
33
33
 
34
34
  function renderToStyleElements(renderer) {
35
- const styles = core.styleBucketOrdering.reduce((acc, bucketName) => {
36
- return Object.assign(Object.assign({}, acc), {
37
- [bucketName]: []
38
- });
39
- }, {}); // eslint-disable-next-line guard-for-in
35
+ const stylesheets = Object.values(renderer.stylesheets) // first sort: bucket names
36
+ .sort((a, b) => {
37
+ return core.styleBucketOrdering.indexOf(a.bucketName) - core.styleBucketOrdering.indexOf(b.bucketName);
38
+ }) // second sort: media queries
39
+ .sort((a, b) => {
40
+ const mediaA = a.elementAttributes['media'];
41
+ const mediaB = b.elementAttributes['media'];
40
42
 
41
- for (const cssRule in renderer.insertionCache) {
42
- const bucketName = renderer.insertionCache[cssRule];
43
- styles[bucketName].push(cssRule);
44
- }
43
+ if (mediaA && mediaB) {
44
+ return renderer.compareMediaQueries(mediaA, mediaB);
45
+ }
45
46
 
46
- return Object.keys(styles).map(bucketName => {
47
- const cssRules = styles[bucketName].join(''); // We don't want to create empty style elements
47
+ if (mediaA || mediaB) {
48
+ return mediaA ? 1 : -1;
49
+ }
50
+
51
+ return 0;
52
+ });
53
+ return stylesheets.map(stylesheet => {
54
+ const cssRules = stylesheet.cssRules(); // don't want to create any empty style elements
48
55
 
49
- if (cssRules.length === 0) {
56
+ if (!cssRules.length) {
50
57
  return null;
51
58
  }
52
59
 
53
- return /*#__PURE__*/React__namespace.createElement('style', {
54
- key: bucketName,
55
- // TODO: support "nonce"
56
- // ...renderer.styleNodeAttributes,
57
- 'data-make-styles-bucket': bucketName || 'default',
58
- 'data-make-styles-rehydration': true,
60
+ return /*#__PURE__*/React__namespace.createElement('style', Object.assign(Object.assign({
61
+ key: stylesheet.bucketName
62
+ }, stylesheet.elementAttributes), {
63
+ 'data-make-styles-rehydration': 'true',
59
64
  dangerouslySetInnerHTML: {
60
- __html: cssRules
65
+ __html: cssRules.join('')
61
66
  }
62
- });
67
+ }));
63
68
  }).filter(Boolean);
64
69
  }
65
70
 
@@ -1 +1 @@
1
- {"version":3,"file":"renderToStyleElements.cjs.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer, StyleBucketName } from '@griffel/core';\n\ntype CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const styles = styleBucketOrdering.reduce<CSSRulesGroupedByStyleBucket>((acc, bucketName) => {\n return { ...acc, [bucketName]: [] };\n }, {} as CSSRulesGroupedByStyleBucket);\n\n // eslint-disable-next-line guard-for-in\n for (const cssRule in renderer.insertionCache) {\n const bucketName: StyleBucketName = renderer.insertionCache[cssRule];\n\n styles[bucketName].push(cssRule);\n }\n\n return (Object.keys(styles) as StyleBucketName[])\n .map(bucketName => {\n const cssRules = styles[bucketName].join('');\n\n // We don't want to create empty style elements\n if (cssRules.length === 0) {\n return null;\n }\n\n return React.createElement('style', {\n key: bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n\n 'data-make-styles-bucket': bucketName || 'default',\n 'data-make-styles-rehydration': true,\n\n dangerouslySetInnerHTML: {\n __html: cssRules,\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","styles","styleBucketOrdering","reduce","acc","bucketName","cssRule","insertionCache","push","Object","keys","map","cssRules","join","length","React","createElement","key","dangerouslySetInnerHTML","__html","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,MAAM,GAAGC,wBAAmB,CAACC,MAApB,CAAyD,CAACC,GAAD,EAAMC,UAAN;AACtE,2CAAYD;AAAK,OAACC,UAAD,GAAc;MAA/B;AACD,GAFc,EAEZ,EAFY,CAAf;;AAKA,OAAK,MAAMC,OAAX,IAAsBN,QAAQ,CAACO,cAA/B,EAA+C;AAC7C,UAAMF,UAAU,GAAoBL,QAAQ,CAACO,cAAT,CAAwBD,OAAxB,CAApC;AAEAL,IAAAA,MAAM,CAACI,UAAD,CAAN,CAAmBG,IAAnB,CAAwBF,OAAxB;AACD;;AAED,SAAQG,MAAM,CAACC,IAAP,CAAYT,MAAZ,EACLU,GADK,CACDN,UAAU;AACb,UAAMO,QAAQ,GAAGX,MAAM,CAACI,UAAD,CAAN,CAAmBQ,IAAnB,CAAwB,EAAxB,CAAjB;;AAGA,QAAID,QAAQ,CAACE,MAAT,KAAoB,CAAxB,EAA2B;AACzB,aAAO,IAAP;AACD;;AAED,wBAAOC,gBAAK,CAACC,aAAN,CAAoB,OAApB,EAA6B;AAClCC,MAAAA,GAAG,EAAEZ,UAD6B;AAGlC;AACA;AAEA,iCAA2BA,UAAU,IAAI,SANP;AAOlC,sCAAgC,IAPE;AASlCa,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEP;AADe;AATS,KAA7B,CAAP;AAaD,GAtBK,EAuBLQ,MAvBK,CAuBEC,OAvBF,CAAR;AAwBD;;;;"}
1
+ {"version":3,"file":"renderToStyleElements.cjs.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer } from '@griffel/core';\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const stylesheets = Object.values(renderer.stylesheets)\n // first sort: bucket names\n .sort((a, b) => {\n return styleBucketOrdering.indexOf(a.bucketName) - styleBucketOrdering.indexOf(b.bucketName);\n })\n // second sort: media queries\n .sort((a, b) => {\n const mediaA = a.elementAttributes['media'];\n const mediaB = b.elementAttributes['media'];\n\n if (mediaA && mediaB) {\n return renderer.compareMediaQueries(mediaA, mediaB);\n }\n\n if (mediaA || mediaB) {\n return mediaA ? 1 : -1;\n }\n\n return 0;\n });\n\n return stylesheets\n .map(stylesheet => {\n const cssRules = stylesheet.cssRules();\n // don't want to create any empty style elements\n if (!cssRules.length) {\n return null;\n }\n\n return React.createElement('style', {\n key: stylesheet.bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n ...stylesheet.elementAttributes,\n 'data-make-styles-rehydration': 'true',\n\n dangerouslySetInnerHTML: {\n __html: cssRules.join(''),\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","stylesheets","Object","values","sort","a","b","styleBucketOrdering","indexOf","bucketName","mediaA","elementAttributes","mediaB","compareMediaQueries","map","stylesheet","cssRules","length","React","createElement","key","dangerouslySetInnerHTML","__html","join","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAcH,QAAQ,CAACC,WAAvB;AAAA,GAEjBG,IAFiB,CAEZ,CAACC,CAAD,EAAIC,CAAJ;AACJ,WAAOC,wBAAmB,CAACC,OAApB,CAA4BH,CAAC,CAACI,UAA9B,IAA4CF,wBAAmB,CAACC,OAApB,CAA4BF,CAAC,CAACG,UAA9B,CAAnD;AACD,GAJiB;AAAA,GAMjBL,IANiB,CAMZ,CAACC,CAAD,EAAIC,CAAJ;AACJ,UAAMI,MAAM,GAAGL,CAAC,CAACM,iBAAF,CAAoB,OAApB,CAAf;AACA,UAAMC,MAAM,GAAGN,CAAC,CAACK,iBAAF,CAAoB,OAApB,CAAf;;AAEA,QAAID,MAAM,IAAIE,MAAd,EAAsB;AACpB,aAAOZ,QAAQ,CAACa,mBAAT,CAA6BH,MAA7B,EAAqCE,MAArC,CAAP;AACD;;AAED,QAAIF,MAAM,IAAIE,MAAd,EAAsB;AACpB,aAAOF,MAAM,GAAG,CAAH,GAAO,CAAC,CAArB;AACD;;AAED,WAAO,CAAP;AACD,GAnBiB,CAApB;AAqBA,SAAOT,WAAW,CACfa,GADI,CACAC,UAAU;AACb,UAAMC,QAAQ,GAAGD,UAAU,CAACC,QAAX,EAAjB;;AAEA,QAAI,CAACA,QAAQ,CAACC,MAAd,EAAsB;AACpB,aAAO,IAAP;AACD;;AAED,wBAAOC,gBAAK,CAACC,aAAN,CAAoB,OAApB;AACLC,MAAAA,GAAG,EAAEL,UAAU,CAACN;OAIbM,UAAU,CAACJ;AACd,sCAAgC;AAEhCU,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEN,QAAQ,CAACO,IAAT,CAAc,EAAd;AADe;MARpB,CAAP;AAYD,GApBI,EAqBJC,MArBI,CAqBGC,OArBH,CAAP;AAsBD;;;;"}
@@ -8,34 +8,39 @@ import * as React from 'react';
8
8
  */
9
9
 
10
10
  function renderToStyleElements(renderer) {
11
- const styles = styleBucketOrdering.reduce((acc, bucketName) => {
12
- return Object.assign(Object.assign({}, acc), {
13
- [bucketName]: []
14
- });
15
- }, {}); // eslint-disable-next-line guard-for-in
11
+ const stylesheets = Object.values(renderer.stylesheets) // first sort: bucket names
12
+ .sort((a, b) => {
13
+ return styleBucketOrdering.indexOf(a.bucketName) - styleBucketOrdering.indexOf(b.bucketName);
14
+ }) // second sort: media queries
15
+ .sort((a, b) => {
16
+ const mediaA = a.elementAttributes['media'];
17
+ const mediaB = b.elementAttributes['media'];
16
18
 
17
- for (const cssRule in renderer.insertionCache) {
18
- const bucketName = renderer.insertionCache[cssRule];
19
- styles[bucketName].push(cssRule);
20
- }
19
+ if (mediaA && mediaB) {
20
+ return renderer.compareMediaQueries(mediaA, mediaB);
21
+ }
22
+
23
+ if (mediaA || mediaB) {
24
+ return mediaA ? 1 : -1;
25
+ }
21
26
 
22
- return Object.keys(styles).map(bucketName => {
23
- const cssRules = styles[bucketName].join(''); // We don't want to create empty style elements
27
+ return 0;
28
+ });
29
+ return stylesheets.map(stylesheet => {
30
+ const cssRules = stylesheet.cssRules(); // don't want to create any empty style elements
24
31
 
25
- if (cssRules.length === 0) {
32
+ if (!cssRules.length) {
26
33
  return null;
27
34
  }
28
35
 
29
- return /*#__PURE__*/React.createElement('style', {
30
- key: bucketName,
31
- // TODO: support "nonce"
32
- // ...renderer.styleNodeAttributes,
33
- 'data-make-styles-bucket': bucketName || 'default',
34
- 'data-make-styles-rehydration': true,
36
+ return /*#__PURE__*/React.createElement('style', Object.assign(Object.assign({
37
+ key: stylesheet.bucketName
38
+ }, stylesheet.elementAttributes), {
39
+ 'data-make-styles-rehydration': 'true',
35
40
  dangerouslySetInnerHTML: {
36
- __html: cssRules
41
+ __html: cssRules.join('')
37
42
  }
38
- });
43
+ }));
39
44
  }).filter(Boolean);
40
45
  }
41
46
 
@@ -1 +1 @@
1
- {"version":3,"file":"renderToStyleElements.esm.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer, StyleBucketName } from '@griffel/core';\n\ntype CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const styles = styleBucketOrdering.reduce<CSSRulesGroupedByStyleBucket>((acc, bucketName) => {\n return { ...acc, [bucketName]: [] };\n }, {} as CSSRulesGroupedByStyleBucket);\n\n // eslint-disable-next-line guard-for-in\n for (const cssRule in renderer.insertionCache) {\n const bucketName: StyleBucketName = renderer.insertionCache[cssRule];\n\n styles[bucketName].push(cssRule);\n }\n\n return (Object.keys(styles) as StyleBucketName[])\n .map(bucketName => {\n const cssRules = styles[bucketName].join('');\n\n // We don't want to create empty style elements\n if (cssRules.length === 0) {\n return null;\n }\n\n return React.createElement('style', {\n key: bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n\n 'data-make-styles-bucket': bucketName || 'default',\n 'data-make-styles-rehydration': true,\n\n dangerouslySetInnerHTML: {\n __html: cssRules,\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","styles","styleBucketOrdering","reduce","acc","bucketName","cssRule","insertionCache","push","Object","keys","map","cssRules","join","length","React","createElement","key","dangerouslySetInnerHTML","__html","filter","Boolean"],"mappings":";;;AAMA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,MAAM,GAAGC,mBAAmB,CAACC,MAApB,CAAyD,CAACC,GAAD,EAAMC,UAAN;AACtE,2CAAYD;AAAK,OAACC,UAAD,GAAc;MAA/B;AACD,GAFc,EAEZ,EAFY,CAAf;;AAKA,OAAK,MAAMC,OAAX,IAAsBN,QAAQ,CAACO,cAA/B,EAA+C;AAC7C,UAAMF,UAAU,GAAoBL,QAAQ,CAACO,cAAT,CAAwBD,OAAxB,CAApC;AAEAL,IAAAA,MAAM,CAACI,UAAD,CAAN,CAAmBG,IAAnB,CAAwBF,OAAxB;AACD;;AAED,SAAQG,MAAM,CAACC,IAAP,CAAYT,MAAZ,EACLU,GADK,CACDN,UAAU;AACb,UAAMO,QAAQ,GAAGX,MAAM,CAACI,UAAD,CAAN,CAAmBQ,IAAnB,CAAwB,EAAxB,CAAjB;;AAGA,QAAID,QAAQ,CAACE,MAAT,KAAoB,CAAxB,EAA2B;AACzB,aAAO,IAAP;AACD;;AAED,wBAAOC,KAAK,CAACC,aAAN,CAAoB,OAApB,EAA6B;AAClCC,MAAAA,GAAG,EAAEZ,UAD6B;AAGlC;AACA;AAEA,iCAA2BA,UAAU,IAAI,SANP;AAOlC,sCAAgC,IAPE;AASlCa,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEP;AADe;AATS,KAA7B,CAAP;AAaD,GAtBK,EAuBLQ,MAvBK,CAuBEC,OAvBF,CAAR;AAwBD;;;;"}
1
+ {"version":3,"file":"renderToStyleElements.esm.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer } from '@griffel/core';\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const stylesheets = Object.values(renderer.stylesheets)\n // first sort: bucket names\n .sort((a, b) => {\n return styleBucketOrdering.indexOf(a.bucketName) - styleBucketOrdering.indexOf(b.bucketName);\n })\n // second sort: media queries\n .sort((a, b) => {\n const mediaA = a.elementAttributes['media'];\n const mediaB = b.elementAttributes['media'];\n\n if (mediaA && mediaB) {\n return renderer.compareMediaQueries(mediaA, mediaB);\n }\n\n if (mediaA || mediaB) {\n return mediaA ? 1 : -1;\n }\n\n return 0;\n });\n\n return stylesheets\n .map(stylesheet => {\n const cssRules = stylesheet.cssRules();\n // don't want to create any empty style elements\n if (!cssRules.length) {\n return null;\n }\n\n return React.createElement('style', {\n key: stylesheet.bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n ...stylesheet.elementAttributes,\n 'data-make-styles-rehydration': 'true',\n\n dangerouslySetInnerHTML: {\n __html: cssRules.join(''),\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","stylesheets","Object","values","sort","a","b","styleBucketOrdering","indexOf","bucketName","mediaA","elementAttributes","mediaB","compareMediaQueries","map","stylesheet","cssRules","length","React","createElement","key","dangerouslySetInnerHTML","__html","join","filter","Boolean"],"mappings":";;;AAIA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAcH,QAAQ,CAACC,WAAvB;AAAA,GAEjBG,IAFiB,CAEZ,CAACC,CAAD,EAAIC,CAAJ;AACJ,WAAOC,mBAAmB,CAACC,OAApB,CAA4BH,CAAC,CAACI,UAA9B,IAA4CF,mBAAmB,CAACC,OAApB,CAA4BF,CAAC,CAACG,UAA9B,CAAnD;AACD,GAJiB;AAAA,GAMjBL,IANiB,CAMZ,CAACC,CAAD,EAAIC,CAAJ;AACJ,UAAMI,MAAM,GAAGL,CAAC,CAACM,iBAAF,CAAoB,OAApB,CAAf;AACA,UAAMC,MAAM,GAAGN,CAAC,CAACK,iBAAF,CAAoB,OAApB,CAAf;;AAEA,QAAID,MAAM,IAAIE,MAAd,EAAsB;AACpB,aAAOZ,QAAQ,CAACa,mBAAT,CAA6BH,MAA7B,EAAqCE,MAArC,CAAP;AACD;;AAED,QAAIF,MAAM,IAAIE,MAAd,EAAsB;AACpB,aAAOF,MAAM,GAAG,CAAH,GAAO,CAAC,CAArB;AACD;;AAED,WAAO,CAAP;AACD,GAnBiB,CAApB;AAqBA,SAAOT,WAAW,CACfa,GADI,CACAC,UAAU;AACb,UAAMC,QAAQ,GAAGD,UAAU,CAACC,QAAX,EAAjB;;AAEA,QAAI,CAACA,QAAQ,CAACC,MAAd,EAAsB;AACpB,aAAO,IAAP;AACD;;AAED,wBAAOC,KAAK,CAACC,aAAN,CAAoB,OAApB;AACLC,MAAAA,GAAG,EAAEL,UAAU,CAACN;OAIbM,UAAU,CAACJ;AACd,sCAAgC;AAEhCU,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEN,QAAQ,CAACO,IAAT,CAAc,EAAd;AADe;MARpB,CAAP;AAYD,GApBI,EAqBJC,MArBI,CAqBGC,OArBH,CAAP;AAsBD;;;;"}