Skip to content

Commit

Permalink
Refactor gradient creator following in-depth testing
Browse files Browse the repository at this point in the history
  • Loading branch information
enourbakhsh committed Nov 1, 2024
1 parent 5f82e6e commit 491b271
Show file tree
Hide file tree
Showing 2 changed files with 587 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const draw = async function (text: string, id: string, _version: string,
);

if (!shapeElement.empty() && shapeElement.node() !== null) {
log.debug(`Working of node ${vertex.id}->${vertex.domId}`);
log.debug(`Working on node ${vertex.id}->${vertex.domId}`);

// Log all cssCompiledStyles for the node if available
if (vertex.cssCompiledStyles) {
Expand All @@ -104,11 +104,15 @@ export const draw = async function (text: string, id: string, _version: string,
?.match(/fill\s*:\s*linear-gradient\([^()]*?(?:\([^()]*?\)[^()]*)*\)/g);

if (linearGradientStyles) {
shapeElement.style('fill', null); // Clear any existing fill
// Clear any existing fill otherwise the theme's color bleeds through (semi-)transparent areas
shapeElement.style('fill', 'none');
shapeElement.style('mix-blend-mode', 'normal');

// Apply gradient style to the node's shape through a cloned element
linearGradientStyles.forEach((style, index) => {
log.debug(`Found gradient style ${index + 1} for node ${vertex.id}: "${style}"`);

// Remove the 'fill: linear-gradient()' wrapper to get the gradient definition
// Remove the 'fill: linear-gradient()' wrapper to get the gradient definition only
const linearGradientStyle = style.replace(/fill\s*:\s*linear-gradient\((.+)\)/, '$1');
const gradientId = `gradient-${vertex.id}-${index}`;

Expand Down
Loading

0 comments on commit 491b271

Please sign in to comment.