@mui/docs 9.0.0-alpha.1 → 9.0.0-alpha.2
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/CHANGELOG.md +28 -0
- package/IconImage/IconImage.d.mts +11 -0
- package/IconImage/IconImage.d.ts +11 -0
- package/IconImage/IconImage.js +91 -0
- package/IconImage/IconImage.mjs +83 -0
- package/IconImage/index.d.mts +1 -0
- package/IconImage/index.d.ts +1 -0
- package/IconImage/index.js +13 -0
- package/IconImage/index.mjs +1 -0
- package/SectionHeadline/SectionHeadline.d.mts +13 -0
- package/SectionHeadline/SectionHeadline.d.ts +13 -0
- package/SectionHeadline/SectionHeadline.js +89 -0
- package/SectionHeadline/SectionHeadline.mjs +81 -0
- package/SectionHeadline/index.d.mts +2 -0
- package/SectionHeadline/index.d.ts +2 -0
- package/SectionHeadline/index.js +25 -0
- package/SectionHeadline/index.mjs +2 -0
- package/ThemeContext/ThemeContext.d.mts +92 -0
- package/ThemeContext/ThemeContext.d.ts +92 -0
- package/ThemeContext/ThemeContext.js +212 -0
- package/ThemeContext/ThemeContext.mjs +200 -0
- package/ThemeContext/index.d.mts +1 -0
- package/ThemeContext/index.d.ts +1 -0
- package/ThemeContext/index.js +42 -0
- package/ThemeContext/index.mjs +1 -0
- package/package.json +59 -1
- package/useLazyCSS/index.d.mts +1 -0
- package/useLazyCSS/index.d.ts +1 -0
- package/useLazyCSS/index.js +13 -0
- package/useLazyCSS/index.mjs +1 -0
- package/useLazyCSS/useLazyCSS.d.mts +11 -0
- package/useLazyCSS/useLazyCSS.d.ts +11 -0
- package/useLazyCSS/useLazyCSS.js +76 -0
- package/useLazyCSS/useLazyCSS.mjs +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { loadCSS } from 'fg-loadcss';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Enhanced lazy CSS loader that wraps CSS in a layer using fetch to avoid CORS issues
|
|
6
|
+
* @param {string} href - URL of the CSS file to load
|
|
7
|
+
* @param {string} before - CSS selector to insert before
|
|
8
|
+
* @param {object} options - Additional options
|
|
9
|
+
* @param {string} options.layer - Optional CSS layer name to wrap the CSS in
|
|
10
|
+
* @returns {() => void} cleanup function
|
|
11
|
+
*/
|
|
12
|
+
export default function useLazyCSS(href, before, options = {}) {
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
// If no layer is specified, add style and clean it on unmount
|
|
15
|
+
if (!options.layer) {
|
|
16
|
+
const link = loadCSS(href, document.querySelector(before));
|
|
17
|
+
return () => {
|
|
18
|
+
link.parentElement?.removeChild(link);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// With layer option, we need to fetch the CSS content and wrap it
|
|
23
|
+
let styleElement = null;
|
|
24
|
+
const abortController = new AbortController();
|
|
25
|
+
|
|
26
|
+
// Fetch the CSS content directly to avoid CORS issues with cssRules
|
|
27
|
+
fetch(href, {
|
|
28
|
+
signal: abortController.signal
|
|
29
|
+
}).then(response => {
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new Error(`Failed to fetch CSS: ${response.statusText}`);
|
|
32
|
+
}
|
|
33
|
+
return response.text();
|
|
34
|
+
}).then(cssText => {
|
|
35
|
+
// Create a style element with the CSS wrapped in the specified layer
|
|
36
|
+
styleElement = document.createElement('style');
|
|
37
|
+
styleElement.setAttribute('data-href', href);
|
|
38
|
+
styleElement.textContent = `@layer ${options.layer} {\n${cssText}\n}`;
|
|
39
|
+
|
|
40
|
+
// Insert at the specified position
|
|
41
|
+
const beforeElement = document.querySelector(before);
|
|
42
|
+
if (beforeElement?.parentNode) {
|
|
43
|
+
beforeElement.parentNode.insertBefore(styleElement, beforeElement);
|
|
44
|
+
} else {
|
|
45
|
+
document.head.appendChild(styleElement);
|
|
46
|
+
}
|
|
47
|
+
}).catch(error => {
|
|
48
|
+
// Ignore abort errors, log others
|
|
49
|
+
if (error !== 'useEffect' && error.name !== 'AbortError') {
|
|
50
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
51
|
+
console.error('Error loading CSS with layer:', error);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Fall back to regular link element if fetch fails
|
|
55
|
+
styleElement = loadCSS(href, document.querySelector(before));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Cleanup function
|
|
60
|
+
return () => {
|
|
61
|
+
// Cancel any pending fetch
|
|
62
|
+
abortController.abort('useEffect');
|
|
63
|
+
|
|
64
|
+
// Remove the style element if it was created
|
|
65
|
+
if (styleElement && styleElement.parentElement) {
|
|
66
|
+
styleElement.parentElement.removeChild(styleElement);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}, [href, before, options.layer]);
|
|
70
|
+
}
|