Manviel commented on code in PR #19717:
URL: https://github.com/apache/echarts/pull/19717#discussion_r1559004985


##########
src/component/tooltip/TooltipHTMLContent.ts:
##########
@@ -73,34 +73,49 @@ function assembleArrow(
     borderColor = convertToColorString(borderColor);
     const arrowPos = mirrorPos(arrowPosition);
     const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
-    let positionStyle = '';
-    let transformStyle = CSS_TRANSFORM_VENDOR + ':';
+
+    const arrowClasses = ['tooltip-arrow'];
+    const transformClasses = [];
     let rotateDeg;
-    if (indexOf(['left', 'right'], arrowPos) > -1) {
-        positionStyle += 'top:50%';
-        transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos === 
'left' ? -225 : -45}deg)`;
+
+    if (['left', 'right'].includes(arrowPos)) {
+        arrowClasses.push('tooltip-arrow-horizontal');
+        transformClasses.push(`tooltip-arrow-rotate-${rotateDeg = arrowPos === 
'left' ? -225 : -45}`);
     }
     else {
-        positionStyle += 'left:50%';
-        transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos === 
'top' ? 225 : 45}deg)`;
+        arrowClasses.push('tooltip-arrow-vertical');
+        transformClasses.push(`tooltip-arrow-rotate-${rotateDeg = arrowPos === 
'top' ? 225 : 45}`);
+    }
+
+    function calculateArrowOffset(rotatedWH: number, borderWidth: number, 
arrowWH: number) {
+        return Math.round(
+            (
+                ((rotatedWH - Math.SQRT2 * borderWidth) / 2
+                    + Math.SQRT2 * borderWidth
+                    - (rotatedWH - arrowWH) / 2)
+                * 100
+            ) / 100
+        );
     }
+
+    function getColorClassName(color: ZRColor) {
+        const colorValue = convertToColorString(color);
+        return colorValue.replace(/[^a-zA-Z0-9]/g, '');
+    }
+
     const rotateRadian = rotateDeg * Math.PI / 180;
     const arrowWH = arrowSize + borderWidth;
     const rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * 
Math.abs(Math.sin(rotateRadian));
-    const arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2
-        + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
-    positionStyle += `;${arrowPos}:-${arrowOffset}px`;
-
-    const borderStyle = `${borderColor} solid ${borderWidth}px;`;
-    const styleCss = [
-        
`position:absolute;width:${arrowSize}px;height:${arrowSize}px;z-index:-1;`,
-        `${positionStyle};${transformStyle};`,
-        `border-bottom:${borderStyle}`,
-        `border-right:${borderStyle}`,
-        `background-color:${backgroundColor};`
-    ];
-
-    return `<div style="${styleCss.join('')}"></div>`;

Review Comment:
   Enabling a strict policy for the style-src directive in CSP offers several 
security benefits for your web application:
   - XSS attacks aim to inject malicious scripts into your website. By 
restricting stylesheet sources, you prevent attackers from embedding malicious 
code within stylesheets and potentially compromising user data or website 
functionality.
   - A strict policy grants you more control over the styles applied to your 
website. You determine the legitimate sources for stylesheets, preventing 
unauthorized styles from altering your website's appearance or behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to