@salt-ds/styles 0.0.0-snapshot-20230516135848 → 0.1.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.
@@ -5,20 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
7
 
8
- const insertionPointContext = React.createContext(null);
8
+ const InsertionPointContext = React.createContext(null);
9
9
  if (process.env.NODE_ENV !== "production") {
10
- insertionPointContext.displayName = "insertionPointContext";
10
+ InsertionPointContext.displayName = "InsertionPointContext";
11
11
  }
12
12
  function InsertionPointProvider(props) {
13
13
  const { insertionPoint: insertionPointProp, children } = props;
14
14
  const value = React.useMemo(() => insertionPointProp, [insertionPointProp]);
15
- return /* @__PURE__ */ jsxRuntime.jsx(insertionPointContext.Provider, {
15
+ return /* @__PURE__ */ jsxRuntime.jsx(InsertionPointContext.Provider, {
16
16
  value,
17
17
  children
18
18
  });
19
19
  }
20
20
  function useInsertionPoint() {
21
- const value = React.useContext(insertionPointContext);
21
+ const value = React.useContext(InsertionPointContext);
22
22
  return value;
23
23
  }
24
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"InsertionPointProvider.js","sources":["../src/use-style-injection/InsertionPointProvider.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useMemo } from \"react\";\n\nexport interface InsertionPointContextType {\n insertionPoint: ChildNode | null;\n}\n\nconst insertionPointContext = createContext<ChildNode | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n insertionPointContext.displayName = \"insertionPointContext\";\n}\n\nexport interface InsertionPointProviderProps extends InsertionPointContextType {\n children: ReactNode;\n}\n\nexport function InsertionPointProvider(props: InsertionPointProviderProps) {\n const { insertionPoint: insertionPointProp, children } = props;\n const value = useMemo(() => insertionPointProp, [insertionPointProp]);\n\n return (\n <insertionPointContext.Provider value={value}>\n {children}\n </insertionPointContext.Provider>\n );\n}\n\nexport function useInsertionPoint() {\n const value = useContext(insertionPointContext);\n return value;\n}\n"],"names":["createContext","useMemo","jsx","useContext"],"mappings":";;;;;;;AAMA,MAAM,qBAAA,GAAwBA,oBAAgC,IAAI,CAAA,CAAA;AAElE,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,EAAA,qBAAA,CAAsB,WAAc,GAAA,uBAAA,CAAA;AACtC,CAAA;AAMO,SAAS,uBAAuB,KAAoC,EAAA;AACzE,EAAA,MAAM,EAAE,cAAA,EAAgB,kBAAoB,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AACzD,EAAA,MAAM,QAAQC,aAAQ,CAAA,MAAM,kBAAoB,EAAA,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEpE,EACE,uBAAAC,cAAA,CAAC,sBAAsB,QAAtB,EAAA;AAAA,IAA+B,KAAA;AAAA,IAC7B,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,iBAAoB,GAAA;AAClC,EAAM,MAAA,KAAA,GAAQC,iBAAW,qBAAqB,CAAA,CAAA;AAC9C,EAAO,OAAA,KAAA,CAAA;AACT;;;;;"}
1
+ {"version":3,"file":"InsertionPointProvider.js","sources":["../src/use-style-injection/InsertionPointProvider.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useMemo } from \"react\";\n\nexport interface InsertionPointContextType {\n insertionPoint: ChildNode | null;\n}\n\nconst InsertionPointContext = createContext<ChildNode | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n InsertionPointContext.displayName = \"InsertionPointContext\";\n}\n\nexport interface InsertionPointProviderProps extends InsertionPointContextType {\n children: ReactNode;\n}\n\nexport function InsertionPointProvider(props: InsertionPointProviderProps) {\n const { insertionPoint: insertionPointProp, children } = props;\n const value = useMemo(() => insertionPointProp, [insertionPointProp]);\n\n return (\n <InsertionPointContext.Provider value={value}>\n {children}\n </InsertionPointContext.Provider>\n );\n}\n\nexport function useInsertionPoint() {\n const value = useContext(InsertionPointContext);\n return value;\n}\n"],"names":["createContext","useMemo","jsx","useContext"],"mappings":";;;;;;;AAMA,MAAM,qBAAA,GAAwBA,oBAAgC,IAAI,CAAA,CAAA;AAElE,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,EAAA,qBAAA,CAAsB,WAAc,GAAA,uBAAA,CAAA;AACtC,CAAA;AAMO,SAAS,uBAAuB,KAAoC,EAAA;AACzE,EAAA,MAAM,EAAE,cAAA,EAAgB,kBAAoB,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AACzD,EAAA,MAAM,QAAQC,aAAQ,CAAA,MAAM,kBAAoB,EAAA,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEpE,EACE,uBAAAC,cAAA,CAAC,sBAAsB,QAAtB,EAAA;AAAA,IAA+B,KAAA;AAAA,IAC7B,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,iBAAoB,GAAA;AAClC,EAAM,MAAA,KAAA,GAAQC,iBAAW,qBAAqB,CAAA,CAAA;AAC9C,EAAO,OAAA,KAAA,CAAA;AACT;;;;;"}
@@ -29,7 +29,7 @@ var _a;
29
29
  const maybeUseInsertionEffect = (_a = React__namespace[`${"useInsertionEffect"}${""}`]) != null ? _a : React__namespace.useLayoutEffect;
30
30
  const windowSheetsMap = /* @__PURE__ */ new WeakMap();
31
31
  function useComponentCssInjection({
32
- id,
32
+ testId,
33
33
  css,
34
34
  window: targetWindow
35
35
  }) {
@@ -44,7 +44,7 @@ function useComponentCssInjection({
44
44
  if (styleMap.styleElement == null) {
45
45
  styleMap.styleElement = targetWindow.document.createElement("style");
46
46
  styleMap.styleElement.setAttribute("type", "text/css");
47
- styleMap.styleElement.setAttribute("data-salt-style", id || "");
47
+ styleMap.styleElement.setAttribute("data-salt-style", testId || "");
48
48
  styleMap.styleElement.textContent = css;
49
49
  styleMap.count = 1;
50
50
  targetWindow.document.head.insertBefore(
@@ -69,7 +69,7 @@ function useComponentCssInjection({
69
69
  }
70
70
  }
71
71
  };
72
- }, [id, css, targetWindow]);
72
+ }, [testId, css, targetWindow]);
73
73
  }
74
74
 
75
75
  exports.useComponentCssInjection = useComponentCssInjection;
@@ -1 +1 @@
1
- {"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[`${\"useInsertionEffect\"}${\"\"}`] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\ntype WindowLike = Window & typeof globalThis;\n\nexport interface UseComponentCssInjection {\n id?: string;\n css: string;\n window?: WindowLike;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\nconst windowSheetsMap = new WeakMap<WindowLike, StyleElementMap>();\nexport function useComponentCssInjection({\n id,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", id || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [id, css, targetWindow]);\n}\n"],"names":["React","useInsertionPoint","_a","sheetsMap","styleMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAAA,gBAAA,CAAA,CAAA,EAAG,oBAAuB,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,KAAxC,YAAiDA,gBAAM,CAAA,eAAA,CAAA;AAgB1D,MAAM,eAAA,uBAAsB,OAAqC,EAAA,CAAA;AAC1D,SAAS,wBAAyB,CAAA;AAAA,EACvC,EAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAQ,EAAA,YAAA;AACV,CAAmC,EAAA;AACjC,EAAA,MAAM,iBAAiBC,wCAAkB,EAAA,CAAA;AAEzC,EAAA,uBAAA,CAAwB,MAAM;AA7BhC,IAAA,IAAAC,GAAA,EAAA,EAAA,CAAA;AA8BI,IAAA,IAAI,CAAC,YAAc,EAAA;AACjB,MAAA,OAAA;AAAA,KACF;AAEA,IAAM,MAAA,SAAA,GAAA,CACJA,MAAA,eAAgB,CAAA,GAAA,CAAI,YAAY,CAAhC,KAAA,IAAA,GAAAA,GACA,mBAAA,IAAI,GAGF,EAAA,CAAA;AACJ,IAAM,MAAA,QAAA,GAAA,CAAW,EAAU,GAAA,SAAA,CAAA,GAAA,CAAI,GAAG,CAAA,KAAjB,YAAsB,EAAE,YAAA,EAAc,IAAM,EAAA,KAAA,EAAO,CAAE,EAAA,CAAA;AAEtE,IAAI,IAAA,QAAA,CAAS,gBAAgB,IAAM,EAAA;AACjC,MAA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AK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,EAAI,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAC5B;;;;"}
1
+ {"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[`${\"useInsertionEffect\"}${\"\"}`] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\nexport interface UseComponentCssInjection {\n testId?: string;\n css: string;\n window?: Window | null;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\n// windowSheetsMap maps window objects to StyleElementMaps\n// A StyleElementMap maps css strings to style element tags\nconst windowSheetsMap = new WeakMap<Window, StyleElementMap>();\n\nexport function useComponentCssInjection({\n testId,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", testId || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [testId, css, targetWindow]);\n}\n"],"names":["React","useInsertionPoint","_a","sheetsMap","styleMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAAA,gBAAA,CAAA,CAAA,EAAG,oBAAuB,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,KAAxC,YAAiDA,gBAAM,CAAA,eAAA,CAAA;AAgB1D,MAAM,eAAA,uBAAsB,OAAiC,EAAA,CAAA;AAEtD,SAAS,wBAAyB,CAAA;AAAA,EACvC,MAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAQ,EAAA,YAAA;AACV,CAAmC,EAAA;AACjC,EAAA,MAAM,iBAAiBC,wCAAkB,EAAA,CAAA;AAEzC,EAAA,uBAAA,CAAwB,MAAM;AA9BhC,IAAA,IAAAC,GAAA,EAAA,EAAA,CAAA;AA+BI,IAAA,IAAI,CAAC,YAAc,EAAA;AACjB,MAAA,OAAA;AAAA,KACF;AAEA,IAAM,MAAA,SAAA,GAAA,CACJA,MAAA,eAAgB,CAAA,GAAA,CAAI,YAAY,CAAhC,KAAA,IAAA,GAAAA,GACA,mBAAA,IAAI,GAGF,EAAA,CAAA;AACJ,IA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A,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,SAAAA,CAAU,YAAc,EAAA;AAC1B,QAAAA,SAAS,CAAA,KAAA,EAAA,CAAA;AACT,QAAIA,IAAAA,SAAAA,CAAS,QAAQ,CAAG,EAAA;AACtB,UAAA,YAAA,CAAa,QAAS,CAAA,IAAA,CAAK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,MAAQ,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAChC;;;;"}
@@ -1,20 +1,20 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { createContext, useMemo, useContext } from 'react';
3
3
 
4
- const insertionPointContext = createContext(null);
4
+ const InsertionPointContext = createContext(null);
5
5
  if (process.env.NODE_ENV !== "production") {
6
- insertionPointContext.displayName = "insertionPointContext";
6
+ InsertionPointContext.displayName = "InsertionPointContext";
7
7
  }
8
8
  function InsertionPointProvider(props) {
9
9
  const { insertionPoint: insertionPointProp, children } = props;
10
10
  const value = useMemo(() => insertionPointProp, [insertionPointProp]);
11
- return /* @__PURE__ */ jsx(insertionPointContext.Provider, {
11
+ return /* @__PURE__ */ jsx(InsertionPointContext.Provider, {
12
12
  value,
13
13
  children
14
14
  });
15
15
  }
16
16
  function useInsertionPoint() {
17
- const value = useContext(insertionPointContext);
17
+ const value = useContext(InsertionPointContext);
18
18
  return value;
19
19
  }
20
20
 
@@ -1 +1 @@
1
- {"version":3,"file":"InsertionPointProvider.js","sources":["../src/use-style-injection/InsertionPointProvider.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useMemo } from \"react\";\n\nexport interface InsertionPointContextType {\n insertionPoint: ChildNode | null;\n}\n\nconst insertionPointContext = createContext<ChildNode | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n insertionPointContext.displayName = \"insertionPointContext\";\n}\n\nexport interface InsertionPointProviderProps extends InsertionPointContextType {\n children: ReactNode;\n}\n\nexport function InsertionPointProvider(props: InsertionPointProviderProps) {\n const { insertionPoint: insertionPointProp, children } = props;\n const value = useMemo(() => insertionPointProp, [insertionPointProp]);\n\n return (\n <insertionPointContext.Provider value={value}>\n {children}\n </insertionPointContext.Provider>\n );\n}\n\nexport function useInsertionPoint() {\n const value = useContext(insertionPointContext);\n return value;\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,qBAAA,GAAwB,cAAgC,IAAI,CAAA,CAAA;AAElE,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,EAAA,qBAAA,CAAsB,WAAc,GAAA,uBAAA,CAAA;AACtC,CAAA;AAMO,SAAS,uBAAuB,KAAoC,EAAA;AACzE,EAAA,MAAM,EAAE,cAAA,EAAgB,kBAAoB,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AACzD,EAAA,MAAM,QAAQ,OAAQ,CAAA,MAAM,kBAAoB,EAAA,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEpE,EACE,uBAAA,GAAA,CAAC,sBAAsB,QAAtB,EAAA;AAAA,IAA+B,KAAA;AAAA,IAC7B,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,iBAAoB,GAAA;AAClC,EAAM,MAAA,KAAA,GAAQ,WAAW,qBAAqB,CAAA,CAAA;AAC9C,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"InsertionPointProvider.js","sources":["../src/use-style-injection/InsertionPointProvider.tsx"],"sourcesContent":["import { createContext, ReactNode, useContext, useMemo } from \"react\";\n\nexport interface InsertionPointContextType {\n insertionPoint: ChildNode | null;\n}\n\nconst InsertionPointContext = createContext<ChildNode | null>(null);\n\nif (process.env.NODE_ENV !== \"production\") {\n InsertionPointContext.displayName = \"InsertionPointContext\";\n}\n\nexport interface InsertionPointProviderProps extends InsertionPointContextType {\n children: ReactNode;\n}\n\nexport function InsertionPointProvider(props: InsertionPointProviderProps) {\n const { insertionPoint: insertionPointProp, children } = props;\n const value = useMemo(() => insertionPointProp, [insertionPointProp]);\n\n return (\n <InsertionPointContext.Provider value={value}>\n {children}\n </InsertionPointContext.Provider>\n );\n}\n\nexport function useInsertionPoint() {\n const value = useContext(InsertionPointContext);\n return value;\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,qBAAA,GAAwB,cAAgC,IAAI,CAAA,CAAA;AAElE,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;AACzC,EAAA,qBAAA,CAAsB,WAAc,GAAA,uBAAA,CAAA;AACtC,CAAA;AAMO,SAAS,uBAAuB,KAAoC,EAAA;AACzE,EAAA,MAAM,EAAE,cAAA,EAAgB,kBAAoB,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AACzD,EAAA,MAAM,QAAQ,OAAQ,CAAA,MAAM,kBAAoB,EAAA,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEpE,EACE,uBAAA,GAAA,CAAC,sBAAsB,QAAtB,EAAA;AAAA,IAA+B,KAAA;AAAA,IAC7B,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,iBAAoB,GAAA;AAClC,EAAM,MAAA,KAAA,GAAQ,WAAW,qBAAqB,CAAA,CAAA;AAC9C,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
@@ -5,7 +5,7 @@ var _a;
5
5
  const maybeUseInsertionEffect = (_a = React[`${"useInsertionEffect"}${""}`]) != null ? _a : React.useLayoutEffect;
6
6
  const windowSheetsMap = /* @__PURE__ */ new WeakMap();
7
7
  function useComponentCssInjection({
8
- id,
8
+ testId,
9
9
  css,
10
10
  window: targetWindow
11
11
  }) {
@@ -20,7 +20,7 @@ function useComponentCssInjection({
20
20
  if (styleMap.styleElement == null) {
21
21
  styleMap.styleElement = targetWindow.document.createElement("style");
22
22
  styleMap.styleElement.setAttribute("type", "text/css");
23
- styleMap.styleElement.setAttribute("data-salt-style", id || "");
23
+ styleMap.styleElement.setAttribute("data-salt-style", testId || "");
24
24
  styleMap.styleElement.textContent = css;
25
25
  styleMap.count = 1;
26
26
  targetWindow.document.head.insertBefore(
@@ -45,7 +45,7 @@ function useComponentCssInjection({
45
45
  }
46
46
  }
47
47
  };
48
- }, [id, css, targetWindow]);
48
+ }, [testId, css, targetWindow]);
49
49
  }
50
50
 
51
51
  export { useComponentCssInjection };
@@ -1 +1 @@
1
- {"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[`${\"useInsertionEffect\"}${\"\"}`] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\ntype WindowLike = Window & typeof globalThis;\n\nexport interface UseComponentCssInjection {\n id?: string;\n css: string;\n window?: WindowLike;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\nconst windowSheetsMap = new WeakMap<WindowLike, StyleElementMap>();\nexport function useComponentCssInjection({\n id,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", id || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [id, css, targetWindow]);\n}\n"],"names":["_a","sheetsMap","styleMap"],"mappings":";;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAA,KAAA,CAAA,CAAA,EAAG,oBAAuB,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,KAAxC,YAAiD,KAAM,CAAA,eAAA,CAAA;AAgB1D,MAAM,eAAA,uBAAsB,OAAqC,EAAA,CAAA;AAC1D,SAAS,wBAAyB,CAAA;AAAA,EACvC,EAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAQ,EAAA,YAAA;AACV,CAAmC,EAAA;AACjC,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AAEzC,EAAA,uBAAA,CAAwB,MAAM;AA7BhC,IAAA,IAAAA,GAAA,EAAA,EAAA,CAAA;AA8BI,IAAA,IAAI,CAAC,YAAc,EAAA;AACjB,MAAA,OAAA;AAAA,KACF;AAEA,IAAM,MAAA,SAAA,GAAA,CACJA,MAAA,eAAgB,CAAA,GAAA,CAAI,YAAY,CAAhC,KAAA,IAAA,GAAAA,GACA,mBAAA,IAAI,GAGF,EA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MAAIC,IAAAA,SAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,SAAAA,CAAU,YAAc,EAAA;AAC1B,QAAAA,SAAS,CAAA,KAAA,EAAA,CAAA;AACT,QAAIA,IAAAA,SAAAA,CAAS,QAAQ,CAAG,EAAA;AACtB,UAAA,YAAA,CAAa,QAAS,CAAA,IAAA,CAAK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,EAAI,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAC5B;;;;"}
1
+ {"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[`${\"useInsertionEffect\"}${\"\"}`] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\nexport interface UseComponentCssInjection {\n testId?: string;\n css: string;\n window?: Window | null;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\n// windowSheetsMap maps window objects to StyleElementMaps\n// A StyleElementMap maps css strings to style element tags\nconst windowSheetsMap = new WeakMap<Window, StyleElementMap>();\n\nexport function useComponentCssInjection({\n testId,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", testId || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [testId, css, targetWindow]);\n}\n"],"names":["_a","sheetsMap","styleMap"],"mappings":";;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAA,KAAA,CAAA,CAAA,EAAG,oBAAuB,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,KAAxC,YAAiD,KAAM,CAAA,eAAA,CAAA;AAgB1D,MAAM,eAAA,uBAAsB,OAAiC,EAAA,CAAA;AAEtD,SAAS,wBAAyB,CAAA;AAAA,EACvC,MAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAQ,EAAA,YAAA;AACV,CAAmC,EAAA;AACjC,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AAEzC,EAAA,uBAAA,CAAwB,MAAM;AA9BhC,IAAA,IAAAA,GAAA,EAAA,EAAA,CAAA;AA+BI,IAAA,IAAI,CAAC,YAA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GAAA,CAAI,YAAY,CAAA,CAAA;AAClD,MAAA,MAAMC,SAAWD,GAAAA,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,GAAI,CAAA,GAAA,CAAA,CAAA;AAChC,MAAIC,IAAAA,SAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,SAAAA,CAAU,YAAc,EAAA;AAC1B,QAAAA,SAAS,CAAA,KAAA,EAAA,CAAA;AACT,QAAIA,IAAAA,SAAAA,CAAS,QAAQ,CAAG,EAAA;AACtB,UAAA,YAAA,CAAa,QAAS,CAAA,IAAA,CAAK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,MAAQ,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAChC;;;;"}
@@ -1,8 +1,6 @@
1
- declare type WindowLike = Window & typeof globalThis;
2
1
  export interface UseComponentCssInjection {
3
- id?: string;
2
+ testId?: string;
4
3
  css: string;
5
- window?: WindowLike;
4
+ window?: Window | null;
6
5
  }
7
- export declare function useComponentCssInjection({ id, css, window: targetWindow, }: UseComponentCssInjection): void;
8
- export {};
6
+ export declare function useComponentCssInjection({ testId, css, window: targetWindow, }: UseComponentCssInjection): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salt-ds/styles",
3
- "version": "0.0.0-snapshot-20230516135848",
3
+ "version": "0.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist-cjs/index.js",
6
6
  "sideEffects": false,