$71 GRAYBYTE WORDPRESS FILE MANAGER $93

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 104.21.43.35 | ADMIN IP 216.73.216.180
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : mail

/home/bravrvjk/dantho.rw/wp-content/plugins/extendify/src/Agent/hooks/

HOME
Current File : /home/bravrvjk/dantho.rw/wp-content/plugins/extendify/src/Agent/hooks//useFontVariationOverride.js
import { useEffect, useRef, useState } from '@wordpress/element';

const id = 'global-styles-inline-css';
const path = window.location.pathname;
const s = new URLSearchParams(window.location.search);
const onEditor =
	path.includes('/wp-admin/post.php') && s.get('action') === 'edit';

export const useFontVariationOverride = ({ css }) => {
	const frontStyles = useRef(null);
	const [theDocument, setDocument] = useState(null);

	useEffect(() => {
		if (!css || onEditor) return;
		const style = document.getElementById(id);
		if (!style) return;
		if (!frontStyles.current) {
			frontStyles.current = style.innerHTML;
		}
		style.innerHTML = css;
	}, [css]);

	// Handle the editor
	useEffect(() => {
		if (!css || !theDocument || !onEditor) return;
		const style = theDocument.getElementById(id);
		const hasIframe = document.querySelector('iframe[name="editor-canvas"]');
		style.innerHTML = css.replaceAll(
			':root',
			// If the iframe was removed, target the editor the old way
			hasIframe ? ':root' : '.editor-styles-wrapper',
		);

		// Since these effects should not affect the whole editor, only the text
		if (!hasIframe) {
			// we need to replace the individual elements with the style wrapper
			style.innerHTML = style.innerHTML
				.replace('body{', '.editor-styles-wrapper{')
				// or prefix them with the editor class
				.replace(
					/(h[1-6](?:\s*,\s*h[1-6])*)\s*\{/g,
					'.editor-styles-wrapper $1{',
				);
		}
	}, [css, theDocument]);

	useEffect(() => {
		if (theDocument) return;
		const timer = setTimeout(() => {
			if (theDocument) return;
			const frame = document.querySelector('iframe[name="editor-canvas"]');
			const doc = frame?.contentDocument || document;
			if (!doc || !doc.body) return;
			// Add a tag to the body
			const newStyle = doc.createElement('style');
			newStyle.id = id;
			doc.body.appendChild(newStyle);
			setDocument(doc);
		}, 300); // wait for iframe
		return () => clearTimeout(timer);
	}, [theDocument]);

	return {
		undoChange: () => {
			// Revert CSS changes
			const style = document.getElementById(id);
			if (style && frontStyles.current) {
				style.innerHTML = frontStyles.current;
			}

			// Remove editor CSS
			if (!onEditor) return;
			const iframe = document.querySelector('iframe[name="editor-canvas"]');
			const doc = iframe?.contentDocument || document;
			doc?.getElementById(id)?.remove();
		},
	};
};


Current_dir [ WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
6 Nov 2025 10.43 AM
bravrvjk / bravrvjk
0755
useDraggable.js
3.773 KB
27 Aug 2025 5.47 PM
bravrvjk / bravrvjk
0644
useFontVariationOverride.js
2.335 KB
30 Sep 2025 9.20 PM
bravrvjk / bravrvjk
0644
useLockPost.js
0.554 KB
3 Nov 2025 11.10 PM
bravrvjk / bravrvjk
0644
usePortal.js
0.474 KB
5 Sep 2025 2.23 PM
bravrvjk / bravrvjk
0644
useResizable.js
3.171 KB
27 Aug 2025 5.47 PM
bravrvjk / bravrvjk
0644
useThemeFontsVariations.js
0.39 KB
30 Sep 2025 9.20 PM
bravrvjk / bravrvjk
0644
useThemeVariations.js
1.138 KB
9 Sep 2025 7.55 PM
bravrvjk / bravrvjk
0644
useVariationOverride.js
3.106 KB
27 Aug 2025 5.47 PM
bravrvjk / bravrvjk
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF