@acusti/styling 0.6.0-alpha3 → 0.6.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
@@ -1,7 +1,7 @@
1
1
  # @acusti/styling
2
2
 
3
3
  [![latest version](https://img.shields.io/npm/v/@acusti/styling?style=for-the-badge)](https://www.npmjs.com/package/@acusti/styling)
4
- [![dependencies status](https://img.shields.io/librariesio/release/npm/@acusti/styling?style=for-the-badge)](https://libraries.io/npm/@acusti%2Fstyling/sourcerank)
4
+ [![maintenance status](https://img.shields.io/npms-io/maintenance-score/@acusti/styling?style=for-the-badge)](https://npms.io/search?q=%40acusti%2Fstyling)
5
5
  [![bundle size](https://img.shields.io/bundlephobia/minzip/@acusti/styling?style=for-the-badge)](https://bundlephobia.com/package/@acusti/styling)
6
6
  [![downloads per month](https://img.shields.io/npm/dm/@acusti/styling?style=for-the-badge)](https://www.npmjs.com/package/@acusti/styling)
7
7
 
package/dist/Style.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- declare type Props = {
2
+ type Props = {
3
3
  children: string;
4
4
  };
5
- declare const Style: ({ children: styles }: Props) => JSX.Element | null;
5
+ declare const Style: ({ children }: Props) => JSX.Element | null;
6
6
  export default Style;
package/dist/Style.js CHANGED
@@ -1,13 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { unregisterStyles, updateStyles } from './style-registry.js';
3
- const { useCallback, useEffect, useRef, useState } = React;
4
- const Style = ({ children: styles }) => {
3
+ const { useCallback, useEffect, useMemo, useRef, useState } = React;
4
+ const Style = ({ children }) => {
5
+ // Minify CSS styles by replacing consecutive whitespace (including \n) with ' '
6
+ const styles = useMemo(() => children.replace(/\s+/gm, ' '), [children]);
5
7
  const [ownerDocument, setOwnerDocument] = useState(null);
6
- const handleRef = useCallback((element) => {
7
- if (!element)
8
- return;
9
- setOwnerDocument(element.ownerDocument);
10
- }, []);
11
8
  useEffect(() => () => {
12
9
  if (!ownerDocument)
13
10
  return;
@@ -24,20 +21,15 @@ const Style = ({ children: styles }) => {
24
21
  });
25
22
  previousStylesRef.current = styles;
26
23
  }, [ownerDocument, styles]);
24
+ const handleRef = useCallback((element) => {
25
+ if (!element)
26
+ return;
27
+ setOwnerDocument(element.ownerDocument);
28
+ }, []);
27
29
  if (ownerDocument)
28
30
  return null;
29
- console.log('styles', styles);
30
- console.log('replaced styles', styles.replace(/&quot;/g, '"'));
31
- // TODO why does styles get HTML entities for double quote marks?
32
31
  return (React.createElement("style", { dangerouslySetInnerHTML: {
33
- __html: styles.replace(/&quot;/g, '"') +
34
- '/*\n' +
35
- 'styles:' +
36
- styles +
37
- '\n\n' +
38
- 'replaced styles: ' +
39
- styles.replace(/&quot;/g, '"') +
40
- '\n*/',
32
+ __html: styles,
41
33
  }, ref: handleRef }));
42
34
  };
43
35
  export default Style;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for Style
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.0
4
+ * Flowgen v1.20.1
5
5
  * @flow
6
6
  */
7
7
 
package/dist/Style.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Style.js","sourceRoot":"","sources":["../src/Style.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;AAM3D,MAAM,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAS,EAAE,EAAE;IAC1C,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAkB,IAAI,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,OAA2B,EAAE,EAAE;QAC1D,IAAI,CAAC,OAAO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QAAE,OAAO,IAAI,CAAC;IAE/B,OAAO,CACH,+BACI,uBAAuB,EAAE;YACrB,MAAM,EAAE,MAAM;SACjB,EACD,GAAG,EAAE,SAAS,GAChB,CACL,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.0
4
+ * Flowgen v1.20.1
5
5
  * @flow
6
6
  */
7
7
 
@@ -1,10 +1,10 @@
1
- declare type Payload = {
1
+ type Payload = {
2
2
  ownerDocument: Document;
3
3
  styles: string;
4
4
  };
5
5
  export declare const registerStyles: ({ ownerDocument, styles }: Payload) => void;
6
6
  export declare const unregisterStyles: ({ ownerDocument, styles }: Payload) => void;
7
- declare type UpdatePayload = {
7
+ type UpdatePayload = {
8
8
  ownerDocument: Document;
9
9
  previousStyles: string;
10
10
  styles: string;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for style-registry
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.0
4
+ * Flowgen v1.20.1
5
5
  * @flow
6
6
  */
7
7
 
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "@acusti/styling",
3
- "version": "0.6.0-alpha3",
3
+ "version": "0.6.0",
4
+ "description": "React component that renders a CSS style string as a <style> element in the <head> of the document (with global style de-duplication)",
5
+ "keywords": [
6
+ "react",
7
+ "react-component",
8
+ "styles",
9
+ "css",
10
+ "css-in-js",
11
+ "ssr",
12
+ "typescript",
13
+ "ts",
14
+ "flow"
15
+ ],
4
16
  "type": "module",
5
17
  "sideEffects": false,
6
18
  "exports": "./dist/index.js",
@@ -12,7 +24,8 @@
12
24
  ],
13
25
  "repository": {
14
26
  "type": "git",
15
- "url": "git+https://github.com/acusti/uikit.git"
27
+ "url": "https://github.com/acusti/uikit.git",
28
+ "directory": "packages/styling"
16
29
  },
17
30
  "author": "andrew patton <andrew@acusti.ca> (https://www.acusti.ca)",
18
31
  "license": "Unlicense",
@@ -21,8 +34,8 @@
21
34
  },
22
35
  "homepage": "https://github.com/acusti/uikit/tree/main/packages/styling#readme",
23
36
  "devDependencies": {
24
- "@types/react": "^18.0.15",
25
- "typescript": "~4.6.4"
37
+ "@types/react": "^18.0.25",
38
+ "typescript": "^4.9.3"
26
39
  },
27
40
  "peerDependencies": {
28
41
  "react": "^16.8 || ^17 || ^18",
package/src/Style.tsx CHANGED
@@ -2,20 +2,17 @@ import * as React from 'react';
2
2
 
3
3
  import { unregisterStyles, updateStyles } from './style-registry.js';
4
4
 
5
- const { useCallback, useEffect, useRef, useState } = React;
5
+ const { useCallback, useEffect, useMemo, useRef, useState } = React;
6
6
 
7
7
  type Props = {
8
8
  children: string;
9
9
  };
10
10
 
11
- const Style = ({ children: styles }: Props) => {
11
+ const Style = ({ children }: Props) => {
12
+ // Minify CSS styles by replacing consecutive whitespace (including \n) with ' '
13
+ const styles = useMemo(() => children.replace(/\s+/gm, ' '), [children]);
12
14
  const [ownerDocument, setOwnerDocument] = useState<Document | null>(null);
13
15
 
14
- const handleRef = useCallback((element: HTMLElement | null) => {
15
- if (!element) return;
16
- setOwnerDocument(element.ownerDocument);
17
- }, []);
18
-
19
16
  useEffect(
20
17
  () => () => {
21
18
  if (!ownerDocument) return;
@@ -38,22 +35,17 @@ const Style = ({ children: styles }: Props) => {
38
35
  previousStylesRef.current = styles;
39
36
  }, [ownerDocument, styles]);
40
37
 
38
+ const handleRef = useCallback((element: HTMLElement | null) => {
39
+ if (!element) return;
40
+ setOwnerDocument(element.ownerDocument);
41
+ }, []);
42
+
41
43
  if (ownerDocument) return null;
42
- console.log('styles', styles);
43
- console.log('replaced styles', styles.replace(/&quot;/g, '"'));
44
- // TODO why does styles get HTML entities for double quote marks?
44
+
45
45
  return (
46
46
  <style
47
47
  dangerouslySetInnerHTML={{
48
- __html:
49
- styles.replace(/&quot;/g, '"') +
50
- '/*\n' +
51
- 'styles:' +
52
- styles +
53
- '\n\n' +
54
- 'replaced styles: ' +
55
- styles.replace(/&quot;/g, '"') +
56
- '\n*/',
48
+ __html: styles,
57
49
  }}
58
50
  ref={handleRef}
59
51
  />