@acusti/styling 0.5.0 → 0.6.0-alpha

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/dist/Style.js CHANGED
@@ -4,19 +4,19 @@ const { useCallback, useEffect, useRef, useState } = React;
4
4
  const Style = ({ children: styles }) => {
5
5
  const [ownerDocument, setOwnerDocument] = useState(null);
6
6
  const handleRef = useCallback((element) => {
7
- if (!element) return;
7
+ if (!element)
8
+ return;
8
9
  setOwnerDocument(element.ownerDocument);
9
10
  }, []);
10
- useEffect(
11
- () => () => {
12
- if (!ownerDocument) return;
13
- unregisterStyles({ ownerDocument, styles });
14
- },
15
- [ownerDocument],
16
- );
11
+ useEffect(() => () => {
12
+ if (!ownerDocument)
13
+ return;
14
+ unregisterStyles({ ownerDocument, styles });
15
+ }, [ownerDocument]);
17
16
  const previousStylesRef = useRef('');
18
17
  useEffect(() => {
19
- if (!ownerDocument) return;
18
+ if (!ownerDocument)
19
+ return;
20
20
  updateStyles({
21
21
  ownerDocument,
22
22
  previousStyles: previousStylesRef.current,
@@ -24,8 +24,11 @@ const Style = ({ children: styles }) => {
24
24
  });
25
25
  previousStylesRef.current = styles;
26
26
  }, [ownerDocument, styles]);
27
- if (ownerDocument) return null;
28
- return React.createElement('style', { ref: handleRef }, styles);
27
+ if (ownerDocument)
28
+ return null;
29
+ return (React.createElement("style", { dangerouslySetInnerHTML: {
30
+ __html: styles,
31
+ }, ref: handleRef }));
29
32
  };
30
33
  export default Style;
31
- //# sourceMappingURL=Style.js.map
34
+ //# sourceMappingURL=Style.js.map
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Flowtype definitions for Style
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.20.0
5
5
  * @flow
6
6
  */
7
7
 
8
8
  declare type Props = {|
9
- children: string,
9
+ children: string,
10
10
  |};
11
11
  declare var Style: (x: Props) => React$Node | null;
12
12
  declare export default typeof Style;
package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AAC;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"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default as Style } from './Style.js';
2
- export declare const SYSTEM_UI_FONT =
3
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
2
+ export declare const SYSTEM_UI_FONT = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen-Sans, Ubuntu, Cantarell, \"Helvetica Neue\", sans-serif";
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export { default as Style } from './Style.js';
2
- export const SYSTEM_UI_FONT =
3
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
4
- //# sourceMappingURL=index.js.map
2
+ export const SYSTEM_UI_FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
3
+ //# sourceMappingURL=index.js.map
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.20.0
5
5
  * @flow
6
6
  */
7
7
 
8
- declare export { default as Style } from './Style.js';
8
+ declare export { default as Style } from "./Style.js";
9
9
  declare export var SYSTEM_UI_FONT: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
@@ -9,9 +9,5 @@ declare type UpdatePayload = {
9
9
  previousStyles: string;
10
10
  styles: string;
11
11
  };
12
- export declare const updateStyles: ({
13
- ownerDocument,
14
- previousStyles,
15
- styles,
16
- }: UpdatePayload) => void;
12
+ export declare const updateStyles: ({ ownerDocument, previousStyles, styles, }: UpdatePayload) => void;
17
13
  export {};
@@ -1,11 +1,9 @@
1
1
  const styleRegistry = new Map();
2
2
  export const registerStyles = ({ ownerDocument, styles }) => {
3
- if (!styles) return;
3
+ if (!styles)
4
+ return;
4
5
  const stylesMap = styleRegistry.get(styles);
5
- const existingStylesItem =
6
- stylesMap === null || stylesMap === void 0
7
- ? void 0
8
- : stylesMap.get(ownerDocument);
6
+ const existingStylesItem = stylesMap === null || stylesMap === void 0 ? void 0 : stylesMap.get(ownerDocument);
9
7
  if (existingStylesItem) {
10
8
  existingStylesItem.referenceCount++;
11
9
  return;
@@ -22,15 +20,15 @@ export const registerStyles = ({ ownerDocument, styles }) => {
22
20
  styleRegistry.set(styles, new Map([[ownerDocument, stylesItem]]));
23
21
  };
24
22
  export const unregisterStyles = ({ ownerDocument, styles }) => {
25
- if (!styles) return;
23
+ if (!styles)
24
+ return;
26
25
  const stylesMap = styleRegistry.get(styles);
27
- const stylesItem =
28
- stylesMap === null || stylesMap === void 0
29
- ? void 0
30
- : stylesMap.get(ownerDocument);
31
- if (!stylesMap || !stylesItem) return;
26
+ const stylesItem = stylesMap === null || stylesMap === void 0 ? void 0 : stylesMap.get(ownerDocument);
27
+ if (!stylesMap || !stylesItem)
28
+ return;
32
29
  stylesItem.referenceCount--;
33
- if (stylesItem.referenceCount) return;
30
+ if (stylesItem.referenceCount)
31
+ return;
34
32
  // If no more references to these styles in this document, remove <style> element from the DOM
35
33
  const { parentElement } = stylesItem.element;
36
34
  if (parentElement) {
@@ -38,15 +36,17 @@ export const unregisterStyles = ({ ownerDocument, styles }) => {
38
36
  }
39
37
  // Then remove the document Map
40
38
  stylesMap.delete(ownerDocument);
41
- if (stylesMap.size) return;
39
+ if (stylesMap.size)
40
+ return;
42
41
  // If no more references to these styles in any document, remove it entirely
43
42
  styleRegistry.delete(styles);
44
43
  };
45
- export const updateStyles = ({ ownerDocument, previousStyles, styles }) => {
46
- if (previousStyles === styles) return;
44
+ export const updateStyles = ({ ownerDocument, previousStyles, styles, }) => {
45
+ if (previousStyles === styles)
46
+ return;
47
47
  if (previousStyles) {
48
48
  unregisterStyles({ ownerDocument, styles: previousStyles });
49
49
  }
50
50
  registerStyles({ ownerDocument, styles });
51
51
  };
52
- //# sourceMappingURL=style-registry.js.map
52
+ //# sourceMappingURL=style-registry.js.map
@@ -1,20 +1,19 @@
1
1
  /**
2
2
  * Flowtype definitions for style-registry
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.20.0
5
5
  * @flow
6
6
  */
7
7
 
8
8
  declare type Payload = {|
9
- ownerDocument: Document,
10
- styles: string,
9
+ ownerDocument: Document,
10
+ styles: string,
11
11
  |};
12
12
  declare export var registerStyles: (x: Payload) => void;
13
13
  declare export var unregisterStyles: (x: Payload) => void;
14
14
  declare type UpdatePayload = {|
15
- ownerDocument: Document,
16
- previousStyles: string,
17
- styles: string,
15
+ ownerDocument: Document,
16
+ previousStyles: string,
17
+ styles: string,
18
18
  |};
19
19
  declare export var updateStyles: (x: UpdatePayload) => void;
20
- declare export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acusti/styling",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-alpha",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": "./dist/index.js",
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "homepage": "https://github.com/acusti/uikit/tree/main/packages/styling#readme",
23
23
  "devDependencies": {
24
- "@types/react": "^17.0.3",
25
- "typescript": "^4.4.3"
24
+ "@types/react": "^18.0.15",
25
+ "typescript": "~4.6.4"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^16.8 || ^17 || ^18",
package/src/Style.tsx CHANGED
@@ -40,7 +40,14 @@ const Style = ({ children: styles }: Props) => {
40
40
 
41
41
  if (ownerDocument) return null;
42
42
 
43
- return <style ref={handleRef}>{styles}</style>;
43
+ return (
44
+ <style
45
+ dangerouslySetInnerHTML={{
46
+ __html: styles,
47
+ }}
48
+ ref={handleRef}
49
+ />
50
+ );
44
51
  };
45
52
 
46
53
  export default Style;