-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Charanor/feature/mask-highlight
Mask highlight
- Loading branch information
Showing
11 changed files
with
323 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,5 +121,8 @@ | |
} | ||
] | ||
] | ||
}, | ||
"dependencies": { | ||
"react-native-svg": "^12.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import type { Bounds, ElementsRecord } from "./context/context"; | ||
|
||
type ElementBounds = { | ||
startX: number; | ||
startY: number; | ||
endX: number; | ||
endY: number; | ||
}; | ||
|
||
const M = (x: number, y: number) => `M ${x} ${y}`; | ||
const L = (x: number, y: number) => `L ${x} ${y}`; | ||
const arc = (toX: number, toY: number, radius: number) => | ||
`A ${radius},${radius} 0 0 0 ${toX},${toY}`; | ||
const z = "z"; | ||
|
||
const constructClipPath = (data: ElementsRecord[string], containerSize: Bounds): string => { | ||
const parentBounds = { | ||
startX: 0, | ||
startY: 0, | ||
endX: containerSize.width, | ||
endY: containerSize.height, | ||
}; | ||
|
||
switch (data.options?.mode) { | ||
case "circle": { | ||
const { | ||
bounds: { x, y, width, height }, | ||
options: { padding = 0 }, | ||
} = data; | ||
const radius = Math.max(width, height) / 2; | ||
return constructCircularPath( | ||
parentBounds, | ||
{ cx: x + width / 2, cy: y + height / 2 }, | ||
radius + padding | ||
); | ||
} | ||
case "rectangle": // Fallthrough | ||
default: { | ||
const padding = data.options?.padding ?? 0; | ||
const borderRadius = data.options?.borderRadius ?? 0; | ||
|
||
const startX = data.bounds.x - padding; | ||
const endX = startX + data.bounds.width + padding * 2; | ||
const startY = data.bounds.y - padding; | ||
const endY = startY + data.bounds.height + padding * 2; | ||
return constructRectangularPath( | ||
parentBounds, | ||
{ startX, startY, endX, endY }, | ||
borderRadius | ||
); | ||
} | ||
} | ||
}; | ||
|
||
const constructRectangularPath = ( | ||
parentBounds: ElementBounds, | ||
{ startX, startY, endX, endY }: ElementBounds, | ||
borderRadius: number | ||
): string => { | ||
return [ | ||
M(parentBounds.startX, parentBounds.startY), | ||
L(parentBounds.startX, parentBounds.endY), | ||
L(parentBounds.endX, parentBounds.endY), | ||
L(parentBounds.endX, parentBounds.startY), | ||
z, | ||
M(startX, startY + borderRadius), | ||
L(startX, endY - borderRadius), | ||
arc(startX + borderRadius, endY, borderRadius), | ||
L(endX - borderRadius, endY), | ||
arc(endX, endY - borderRadius, borderRadius), | ||
L(endX, startY + borderRadius), | ||
arc(endX - borderRadius, startY, borderRadius), | ||
L(startX + borderRadius, startY), | ||
arc(startX, startY + borderRadius, borderRadius), | ||
].join(" "); | ||
}; | ||
|
||
const constructCircularPath = ( | ||
parentBounds: ElementBounds, | ||
{ cx, cy }: { cx: number; cy: number }, | ||
radius: number | ||
): string => { | ||
return [ | ||
M(parentBounds.startX, parentBounds.startY), | ||
L(parentBounds.startX, parentBounds.endY), | ||
L(parentBounds.endX, parentBounds.endY), | ||
L(parentBounds.endX, parentBounds.startY), | ||
z, | ||
M(cx, cy), | ||
`m ${-radius} 0`, | ||
`a ${radius},${radius} 0 1,0 ${radius * 2},0`, | ||
`a ${radius},${radius} 0 1,0 ${-radius * 2},0`, | ||
].join(" "); | ||
}; | ||
|
||
export default constructClipPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.