@fluentui/react-positioning 9.23.2 → 9.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.js +51 -110
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.js +2 -2
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.js +2 -2
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/computeOutsideClipPath.js +3 -6
- package/lib/hooks/useSafeZoneArea/computeOutsideClipPath.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/getSafeZonePoints.js +72 -0
- package/lib/hooks/useSafeZoneArea/getSafeZonePoints.js.map +1 -0
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.cjs +53 -121
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.cjs.map +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.cjs +2 -2
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.cjs.map +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.cjs +2 -2
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.cjs.map +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/computeOutsideClipPath.cjs +2 -5
- package/lib-commonjs/hooks/useSafeZoneArea/computeOutsideClipPath.cjs.map +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/getSafeZonePoints.cjs +82 -0
- package/lib-commonjs/hooks/useSafeZoneArea/getSafeZonePoints.cjs.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Wed, 23 Sep 2026 09:03:15 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.23.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.23.3)
|
|
8
|
+
|
|
9
|
+
Wed, 23 Sep 2026 09:03:15 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.23.2..@fluentui/react-positioning_v9.23.3)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: improve safe zone hit testing and avoid rerenders during pointer movement ([PR #36708](https://github.com/microsoft/fluentui/pull/36708) by jakubmiskech@microsoft.com)
|
|
15
|
+
|
|
7
16
|
## [9.23.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.23.2)
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
Tue, 22 Sep 2026 11:25:39 GMT
|
|
10
19
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.23.1..@fluentui/react-positioning_v9.23.2)
|
|
11
20
|
|
|
12
21
|
### Patches
|
|
@@ -8,34 +8,13 @@ import { getMouseAnchor } from "./getMouseAnchor.js";
|
|
|
8
8
|
import { pointsToSvgPath } from "./pointsToSvgPath.js";
|
|
9
9
|
import { useStyles } from "./SafeZoneArea.styles.js";
|
|
10
10
|
import { computeOutsideClipPath } from "./computeOutsideClipPath.js";
|
|
11
|
-
|
|
12
|
-
const EMPTY_RECT = {
|
|
13
|
-
top: 0,
|
|
14
|
-
right: 0,
|
|
15
|
-
bottom: 0,
|
|
16
|
-
left: 0,
|
|
17
|
-
width: 0,
|
|
18
|
-
height: 0,
|
|
19
|
-
x: 0,
|
|
20
|
-
y: 0,
|
|
21
|
-
toJSON () {
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
export function isSameRect(a, b) {
|
|
26
|
-
return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left && a.width === b.width && a.height === b.height;
|
|
27
|
-
}
|
|
28
|
-
export function isSameCoordinates(a, b) {
|
|
29
|
-
return a[0] === b[0] && a[1] === b[1];
|
|
30
|
-
}
|
|
11
|
+
import { getSafeZonePoints } from "./getSafeZonePoints.js";
|
|
31
12
|
// ---
|
|
32
13
|
/**
|
|
33
14
|
* A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state
|
|
34
15
|
* to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.
|
|
35
16
|
*
|
|
36
|
-
* Draws
|
|
37
|
-
* - a triangle that points to the target element which is an actual safe zone
|
|
38
|
-
* - a rectangle for a clip path that clips out the target element
|
|
17
|
+
* Draws a polygon from the mouse to the facing edges of the container and clips out the target element.
|
|
39
18
|
*
|
|
40
19
|
* @internal
|
|
41
20
|
*/ export const SafeZoneArea = /*#__PURE__*/ React.memo((props)=>{
|
|
@@ -44,114 +23,76 @@ export function isSameCoordinates(a, b) {
|
|
|
44
23
|
const styles = useStyles();
|
|
45
24
|
const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);
|
|
46
25
|
const svgRef = React.useRef(null);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
mouseCoordinates: [
|
|
51
|
-
0,
|
|
52
|
-
0
|
|
53
|
-
]
|
|
54
|
-
}));
|
|
26
|
+
const safeZoneRef = React.useRef(null);
|
|
27
|
+
const clipPathRef = React.useRef(null);
|
|
28
|
+
const rectDebugRef = React.useRef(null);
|
|
55
29
|
React.useImperativeHandle(props.imperativeRef, ()=>({
|
|
56
|
-
updateSVG (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
updateSVG ({ containerRect, targetRect, mouseCoordinates }) {
|
|
31
|
+
var _safeZoneRef_current, _clipPathRef_current, _rectDebugRef_current;
|
|
32
|
+
const topOffset = Math.min(targetRect.top, containerRect.top);
|
|
33
|
+
const leftOffset = Math.min(targetRect.left, containerRect.left);
|
|
34
|
+
const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);
|
|
35
|
+
const rightOffset = Math.max(targetRect.right, containerRect.right);
|
|
36
|
+
const containerCorners = getRectCorners(containerRect, [
|
|
37
|
+
leftOffset,
|
|
38
|
+
topOffset
|
|
39
|
+
]);
|
|
40
|
+
const targetCorners = getRectCorners(targetRect, [
|
|
41
|
+
leftOffset,
|
|
42
|
+
topOffset
|
|
43
|
+
]);
|
|
44
|
+
// SVG coordinates are relative to its top-left corner.
|
|
45
|
+
const relativeMouseCoordinates = [
|
|
46
|
+
mouseCoordinates[0] - leftOffset,
|
|
47
|
+
mouseCoordinates[1] - topOffset
|
|
48
|
+
];
|
|
49
|
+
const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);
|
|
50
|
+
const svgWidth = rightOffset - leftOffset;
|
|
51
|
+
const svgHeight = bottomOffset - topOffset;
|
|
52
|
+
const clipPath = computeOutsideClipPath(svgWidth, svgHeight, {
|
|
53
|
+
x: targetCorners.topLeft[0],
|
|
54
|
+
y: targetCorners.topLeft[1],
|
|
55
|
+
width: targetRect.width,
|
|
56
|
+
height: targetRect.height
|
|
64
57
|
});
|
|
58
|
+
if (svgRef.current) {
|
|
59
|
+
svgRef.current.style.width = `${svgWidth}px`;
|
|
60
|
+
svgRef.current.style.height = `${svgHeight}px`;
|
|
61
|
+
svgRef.current.style.transform = `translate(${leftOffset}px, ${topOffset}px)`;
|
|
62
|
+
}
|
|
63
|
+
const safeZonePoints = getSafeZonePoints(mouseAnchor, containerCorners);
|
|
64
|
+
(_safeZoneRef_current = safeZoneRef.current) === null || _safeZoneRef_current === void 0 ? void 0 : _safeZoneRef_current.setAttribute('d', safeZonePoints.length > 0 ? pointsToSvgPath(safeZonePoints) : '');
|
|
65
|
+
(_clipPathRef_current = clipPathRef.current) === null || _clipPathRef_current === void 0 ? void 0 : _clipPathRef_current.setAttribute('d', clipPath);
|
|
66
|
+
(_rectDebugRef_current = rectDebugRef.current) === null || _rectDebugRef_current === void 0 ? void 0 : _rectDebugRef_current.setAttribute('d', clipPath);
|
|
65
67
|
}
|
|
66
68
|
}), []);
|
|
67
|
-
const { containerRect, targetRect, mouseCoordinates } = state;
|
|
68
|
-
const topOffset = Math.min(targetRect.top, containerRect.top);
|
|
69
|
-
const leftOffset = Math.min(targetRect.left, containerRect.left);
|
|
70
|
-
const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);
|
|
71
|
-
const rightOffset = Math.max(targetRect.right, containerRect.right);
|
|
72
|
-
// ---
|
|
73
|
-
const containerCorners = getRectCorners(containerRect, [
|
|
74
|
-
leftOffset,
|
|
75
|
-
topOffset
|
|
76
|
-
]);
|
|
77
|
-
const targetCorners = getRectCorners(targetRect, [
|
|
78
|
-
leftOffset,
|
|
79
|
-
topOffset
|
|
80
|
-
]);
|
|
81
|
-
// Heads up!
|
|
82
|
-
// The SVG coordinate system starts at the top-left corner of the SVG element,
|
|
83
|
-
// so we need to adjust the mouse coordinates relative to the SVG's top-left corner.
|
|
84
|
-
const relativeMouseCoordinates = [
|
|
85
|
-
mouseCoordinates[0] - leftOffset,
|
|
86
|
-
mouseCoordinates[1] - topOffset
|
|
87
|
-
];
|
|
88
|
-
const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);
|
|
89
|
-
const triangleA = [
|
|
90
|
-
mouseAnchor,
|
|
91
|
-
containerCorners.topLeft,
|
|
92
|
-
containerCorners.topRight
|
|
93
|
-
];
|
|
94
|
-
const triangleB = [
|
|
95
|
-
mouseAnchor,
|
|
96
|
-
containerCorners.topRight,
|
|
97
|
-
containerCorners.bottomRight
|
|
98
|
-
];
|
|
99
|
-
const triangleC = [
|
|
100
|
-
mouseAnchor,
|
|
101
|
-
containerCorners.bottomRight,
|
|
102
|
-
containerCorners.bottomLeft
|
|
103
|
-
];
|
|
104
|
-
const triangleD = [
|
|
105
|
-
mouseAnchor,
|
|
106
|
-
containerCorners.bottomLeft,
|
|
107
|
-
containerCorners.topLeft
|
|
108
|
-
];
|
|
109
|
-
const svgWidth = rightOffset - leftOffset;
|
|
110
|
-
const svgHeight = bottomOffset - topOffset;
|
|
111
|
-
const clipPath = computeOutsideClipPath(svgWidth, svgHeight, {
|
|
112
|
-
x: targetCorners.topLeft[0],
|
|
113
|
-
y: targetCorners.topLeft[1],
|
|
114
|
-
width: targetRect.width,
|
|
115
|
-
height: targetRect.height
|
|
116
|
-
}, {
|
|
117
|
-
x: containerCorners.topLeft[0],
|
|
118
|
-
y: containerCorners.topLeft[1],
|
|
119
|
-
width: containerRect.width,
|
|
120
|
-
height: containerRect.height
|
|
121
|
-
});
|
|
122
69
|
return /*#__PURE__*/ React.createElement("div", {
|
|
123
70
|
className: mergeClasses(styles.wrapper, active && styles.wrapperActive),
|
|
124
71
|
"data-safe-zone": ""
|
|
125
|
-
},
|
|
72
|
+
}, /*#__PURE__*/ React.createElement("svg", {
|
|
126
73
|
"aria-hidden": true,
|
|
127
74
|
className: styles.svg,
|
|
128
75
|
xmlns: "http://www.w3.org/2000/svg",
|
|
129
76
|
ref: svgRef,
|
|
130
77
|
style: {
|
|
131
|
-
width:
|
|
132
|
-
height:
|
|
133
|
-
transform:
|
|
78
|
+
width: 0,
|
|
79
|
+
height: 0,
|
|
80
|
+
transform: 'translate(0px, 0px)'
|
|
134
81
|
}
|
|
135
82
|
}, /*#__PURE__*/ React.createElement("g", {
|
|
136
|
-
className: mergeClasses(styles.
|
|
83
|
+
className: mergeClasses(styles.safeZone, debug && styles.safeZoneDebug),
|
|
137
84
|
clipPath: `url(#${clipPathId})`,
|
|
138
85
|
onMouseEnter: onMouseEnter,
|
|
139
86
|
onMouseMove: onMouseMove,
|
|
140
87
|
onMouseLeave: onMouseLeave
|
|
141
88
|
}, /*#__PURE__*/ React.createElement("path", {
|
|
142
|
-
|
|
143
|
-
}), /*#__PURE__*/ React.createElement("path", {
|
|
144
|
-
d: pointsToSvgPath(triangleB)
|
|
145
|
-
}), /*#__PURE__*/ React.createElement("path", {
|
|
146
|
-
d: pointsToSvgPath(triangleC)
|
|
147
|
-
}), /*#__PURE__*/ React.createElement("path", {
|
|
148
|
-
d: pointsToSvgPath(triangleD)
|
|
89
|
+
ref: safeZoneRef
|
|
149
90
|
})), /*#__PURE__*/ React.createElement("clipPath", {
|
|
150
91
|
id: clipPathId
|
|
151
92
|
}, /*#__PURE__*/ React.createElement("path", {
|
|
152
|
-
|
|
93
|
+
ref: clipPathRef
|
|
153
94
|
})), debug && /*#__PURE__*/ React.createElement("path", {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}))
|
|
95
|
+
ref: rectDebugRef,
|
|
96
|
+
className: styles.rectDebug
|
|
97
|
+
})));
|
|
157
98
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n/**\n * @internal\n */\ntype SafeZoneAreaState = {\n containerRect: DOMRect;\n targetRect: DOMRect;\n mouseCoordinates: Point;\n};\n\n// ---\n\nconst EMPTY_RECT: DOMRect = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n width: 0,\n height: 0,\n x: 0,\n y: 0,\n toJSON() {\n return '';\n },\n};\n\nexport function isSameRect(a: DOMRect, b: DOMRect): boolean {\n return (\n a.top === b.top &&\n a.right === b.right &&\n a.bottom === b.bottom &&\n a.left === b.left &&\n a.width === b.width &&\n a.height === b.height\n );\n}\n\nexport function isSameCoordinates(a: Point, b: Point): boolean {\n return a[0] === b[0] && a[1] === b[1];\n}\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws two shapes:\n * - a triangle that points to the target element which is an actual safe zone\n * - a rectangle for a clip path that clips out the target element\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n\n const [state, setState] = React.useState<SafeZoneAreaState>(() => ({\n containerRect: EMPTY_RECT,\n targetRect: EMPTY_RECT,\n mouseCoordinates: [0, 0],\n }));\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG(newState) {\n setState(prevState => {\n // Heads up!\n // A small optimization to avoid unnecessary re-renders\n if (\n isSameRect(prevState.containerRect, newState.containerRect) &&\n isSameRect(prevState.targetRect, newState.targetRect) &&\n isSameCoordinates(prevState.mouseCoordinates, newState.mouseCoordinates)\n ) {\n return prevState;\n }\n\n return newState;\n });\n },\n }),\n [],\n );\n\n const { containerRect, targetRect, mouseCoordinates } = state;\n\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n // ---\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // Heads up!\n // The SVG coordinate system starts at the top-left corner of the SVG element,\n // so we need to adjust the mouse coordinates relative to the SVG's top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);\n\n const triangleA = [mouseAnchor, containerCorners.topLeft, containerCorners.topRight];\n const triangleB = [mouseAnchor, containerCorners.topRight, containerCorners.bottomRight];\n const triangleC = [mouseAnchor, containerCorners.bottomRight, containerCorners.bottomLeft];\n const triangleD = [mouseAnchor, containerCorners.bottomLeft, containerCorners.topLeft];\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n\n const clipPath = computeOutsideClipPath(\n svgWidth,\n svgHeight,\n {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n },\n {\n x: containerCorners.topLeft[0],\n y: containerCorners.topLeft[1],\n width: containerRect.width,\n height: containerRect.height,\n },\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n {active ? (\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{\n width: `${svgWidth}px`,\n height: `${svgHeight}px`,\n transform: `translate(${leftOffset}px, ${topOffset}px)`,\n }}\n >\n <g\n className={mergeClasses(styles.triangle, debug && styles.triangleDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path d={pointsToSvgPath(triangleA)} />\n <path d={pointsToSvgPath(triangleB)} />\n <path d={pointsToSvgPath(triangleC)} />\n <path d={pointsToSvgPath(triangleD)} />\n </g>\n\n <clipPath id={clipPathId}>\n <path d={clipPath} />\n </clipPath>\n\n {debug && <path className={styles.rectDebug} d={clipPath} />}\n </svg>\n ) : null}\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","EMPTY_RECT","top","right","bottom","left","width","height","x","y","toJSON","isSameRect","a","b","isSameCoordinates","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","state","setState","useState","containerRect","targetRect","mouseCoordinates","useImperativeHandle","imperativeRef","updateSVG","newState","prevState","topOffset","Math","min","leftOffset","bottomOffset","max","rightOffset","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","triangleA","topRight","triangleB","triangleC","bottomLeft","triangleD","svgWidth","svgHeight","clipPath","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","style","transform","g","triangle","triangleDebug","path","d","id","rectDebug"],"mappings":"AAAA;AAEA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,4BAA4B;AAElD,YAAYC,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,QAAQ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,GAAGhF,gBAAgBwD;sBACzB,oBAACuB;QAAKC,GAAGhF,gBAAgB0D;sBACzB,oBAACqB;QAAKC,GAAGhF,gBAAgB2D;sBACzB,oBAACoB;QAAKC,GAAGhF,gBAAgB6D;uBAG3B,oBAACG;QAASiB,IAAIxD;qBACZ,oBAACsD;QAAKC,GAAGhB;SAGV5C,uBAAS,oBAAC2D;QAAKb,WAAWxC,OAAOwD,SAAS;QAAEF,GAAGhB;UAEhD;AAGV,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\nimport { getSafeZonePoints } from './getSafeZonePoints';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws a polygon from the mouse to the facing edges of the container and clips out the target element.\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n const safeZoneRef = React.useRef<SVGPathElement>(null);\n const clipPathRef = React.useRef<SVGPathElement>(null);\n const rectDebugRef = React.useRef<SVGPathElement>(null);\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG({ containerRect, targetRect, mouseCoordinates }) {\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // SVG coordinates are relative to its top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(\n containerCorners.topLeft,\n containerCorners.bottomRight,\n relativeMouseCoordinates,\n );\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n const clipPath = computeOutsideClipPath(svgWidth, svgHeight, {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n });\n\n if (svgRef.current) {\n svgRef.current.style.width = `${svgWidth}px`;\n svgRef.current.style.height = `${svgHeight}px`;\n svgRef.current.style.transform = `translate(${leftOffset}px, ${topOffset}px)`;\n }\n\n const safeZonePoints = getSafeZonePoints(mouseAnchor, containerCorners);\n safeZoneRef.current?.setAttribute('d', safeZonePoints.length > 0 ? pointsToSvgPath(safeZonePoints) : '');\n clipPathRef.current?.setAttribute('d', clipPath);\n rectDebugRef.current?.setAttribute('d', clipPath);\n },\n }),\n [],\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{ width: 0, height: 0, transform: 'translate(0px, 0px)' }}\n >\n <g\n className={mergeClasses(styles.safeZone, debug && styles.safeZoneDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path ref={safeZoneRef} />\n </g>\n\n <clipPath id={clipPathId}>\n <path ref={clipPathRef} />\n </clipPath>\n\n {debug && <path ref={rectDebugRef} className={styles.rectDebug} />}\n </svg>\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","getSafeZonePoints","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","safeZoneRef","clipPathRef","rectDebugRef","useImperativeHandle","imperativeRef","updateSVG","containerRect","targetRect","mouseCoordinates","topOffset","Math","min","top","leftOffset","left","bottomOffset","max","bottom","rightOffset","right","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","svgWidth","svgHeight","clipPath","x","y","width","height","current","style","transform","safeZonePoints","setAttribute","length","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","g","safeZone","safeZoneDebug","path","id","rectDebug"],"mappings":"AAAA;AAEA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,4BAA4B;AAElD,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BAACW;QAAIC,WAAWjE,aAAamB,OAAO+C,OAAO,EAAE9C,UAAUD,OAAOgD,aAAa;QAAGC,kBAAe;qBAC3F,oBAACC;QACCC,eAAAA;QACAL,WAAW9C,OAAOkD,GAAG;QACrBE,OAAM;QACNC,KAAKjD;QACLoC,OAAO;YAAEH,OAAO;YAAGC,QAAQ;YAAGG,WAAW;QAAsB;qBAE/D,oBAACa;QACCR,WAAWjE,aAAamB,OAAOuD,QAAQ,EAAE7D,SAASM,OAAOwD,aAAa;QACtEtB,UAAU,CAAC,KAAK,EAAEnC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;qBAEd,oBAAC4D;QAAKJ,KAAK/C;uBAGb,oBAAC4B;QAASwB,IAAI3D;qBACZ,oBAAC0D;QAAKJ,KAAK9C;SAGZb,uBAAS,oBAAC+D;QAAKJ,KAAK7C;QAAcsC,WAAW9C,OAAO2D,SAAS;;AAItE,GAAG"}
|
|
@@ -19,10 +19,10 @@ export const useStyles = /*#__PURE__*/__styles({
|
|
|
19
19
|
Bhzewxz: "f15twtuk",
|
|
20
20
|
oyh7mz: ["f1vgc2s3", "f1e31b4d"]
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
safeZone: {
|
|
23
23
|
Bkecrkj: "f1cguypg"
|
|
24
24
|
},
|
|
25
|
-
|
|
25
|
+
safeZoneDebug: {
|
|
26
26
|
Bceei9c: "f7116n6",
|
|
27
27
|
Bkfmm31: "f1xab38x"
|
|
28
28
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__styles","tokens","useStyles","wrapper","mc9l5x","Bqenvij","a9b677","Bkecrkj","wrapperActive","svg","Bkfmm31","qhf8xq","Bhzewxz","oyh7mz","
|
|
1
|
+
{"version":3,"names":["__styles","tokens","useStyles","wrapper","mc9l5x","Bqenvij","a9b677","Bkecrkj","wrapperActive","svg","Bkfmm31","qhf8xq","Bhzewxz","oyh7mz","safeZone","safeZoneDebug","Bceei9c","rectDebug","d"],"sources":["SafeZoneArea.styles.js"],"sourcesContent":["'use client';\nimport { makeStyles } from \"@griffel/react\";\nimport { tokens } from \"@fluentui/react-theme\";\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none'\n },\n wrapperActive: {\n display: 'block'\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0\n },\n safeZone: {\n pointerEvents: 'auto'\n },\n safeZoneDebug: {\n cursor: 'crosshair',\n fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`\n },\n rectDebug: {\n fill: `color-mix(in srgb, ${tokens.colorPaletteRedBackground3} 20%, transparent)`\n }\n});\n"],"mappings":"AAAA,YAAY;;AACZ,SAAAA,QAAA,QAA2B,gBAAgB;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,OAAO,MAAMC,SAAS,gBAAGF,QAAA;EAAAG,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;EAAA;EAAAC,aAAA;IAAAJ,MAAA;EAAA;EAAAK,GAAA;IAAAC,OAAA;IAAAH,OAAA;IAAAI,MAAA;IAAAC,OAAA;IAAAC,MAAA;EAAA;EAAAC,QAAA;IAAAP,OAAA;EAAA;EAAAQ,aAAA;IAAAC,OAAA;IAAAN,OAAA;EAAA;EAAAO,SAAA;IAAAP,OAAA;EAAA;AAAA;EAAAQ,CAAA;AAAA,CA2BxB,CAAC","ignoreList":[]}
|
|
@@ -18,10 +18,10 @@ export const useStyles = makeStyles({
|
|
|
18
18
|
top: 0,
|
|
19
19
|
left: 0
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
safeZone: {
|
|
22
22
|
pointerEvents: 'auto'
|
|
23
23
|
},
|
|
24
|
-
|
|
24
|
+
safeZoneDebug: {
|
|
25
25
|
cursor: 'crosshair',
|
|
26
26
|
fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`
|
|
27
27
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.styles.ts"],"sourcesContent":["'use client';\n\nimport { makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\n\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none',\n },\n wrapperActive: {\n display: 'block',\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0,\n },\n
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.styles.ts"],"sourcesContent":["'use client';\n\nimport { makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\n\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none',\n },\n wrapperActive: {\n display: 'block',\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0,\n },\n safeZone: {\n pointerEvents: 'auto',\n },\n safeZoneDebug: {\n cursor: 'crosshair',\n fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`,\n },\n rectDebug: {\n fill: `color-mix(in srgb, ${tokens.colorPaletteRedBackground3} 20%, transparent)`,\n },\n});\n"],"names":["makeStyles","tokens","useStyles","wrapper","display","height","width","pointerEvents","wrapperActive","svg","fill","position","top","left","safeZone","safeZoneDebug","cursor","colorPaletteGreenBackground3","rectDebug","colorPaletteRedBackground3"],"mappings":"AAAA;AAEA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,MAAM,QAAQ,wBAAwB;AAE/C,OAAO,MAAMC,YAAYF,WAAW;IAClCG,SAAS;QACPC,SAAS;QACTC,QAAQ;QACRC,OAAO;QACPC,eAAe;IACjB;IACAC,eAAe;QACbJ,SAAS;IACX;IACAK,KAAK;QACHC,MAAM;QACNH,eAAe;QACfI,UAAU;QACVC,KAAK;QACLC,MAAM;IACR;IACAC,UAAU;QACRP,eAAe;IACjB;IACAQ,eAAe;QACbC,QAAQ;QACRN,MAAM,CAAC,mBAAmB,EAAET,OAAOgB,4BAA4B,CAAC,kBAAkB,CAAC;IACrF;IACAC,WAAW;QACTR,MAAM,CAAC,mBAAmB,EAAET,OAAOkB,0BAA0B,CAAC,kBAAkB,CAAC;IACnF;AACF,GAAG"}
|
|
@@ -13,15 +13,12 @@ function drawRectangle(rect) {
|
|
|
13
13
|
return pathData;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Computes a clip path that covers the area outside
|
|
16
|
+
* Computes a clip path that covers the area outside a rectangle.
|
|
17
17
|
*
|
|
18
18
|
* @internal
|
|
19
|
-
*/ export function computeOutsideClipPath(svgWidth, svgHeight, targetRect
|
|
19
|
+
*/ export function computeOutsideClipPath(svgWidth, svgHeight, targetRect) {
|
|
20
20
|
let pathData = `M 0,0 H ${svgWidth} V ${svgHeight} H 0 Z `;
|
|
21
|
-
//
|
|
22
|
-
// The trick is to draw each rectangle in the counterclockwise direction
|
|
23
|
-
// which creates a "hole" in the main path
|
|
21
|
+
// Draw the rectangle counterclockwise to create a hole in the main path.
|
|
24
22
|
pathData += drawRectangle(targetRect);
|
|
25
|
-
pathData += drawRectangle(containerRect);
|
|
26
23
|
return pathData;
|
|
27
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/computeOutsideClipPath.ts"],"sourcesContent":["function drawRectangle(rect: { x: number; y: number; width: number; height: number }): string {\n if (rect.width <= 0 || rect.height <= 0) {\n return '';\n }\n\n let pathData = '';\n\n // Creates a subpath moving in counterclockwise direction to create a hole\n\n pathData += `M ${rect.x},${rect.y} `;\n pathData += `V ${rect.y + rect.height} `; // Down to bottom-left\n pathData += `H ${rect.x + rect.width} `; // Right to bottom-right\n pathData += `V ${rect.y} `; // Up to top-right\n pathData += `H ${rect.x} `; // Left to top-left (closing)\n pathData += `Z `; // Close path\n\n return pathData;\n}\n\n/**\n * Computes a clip path that covers the area outside
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/computeOutsideClipPath.ts"],"sourcesContent":["function drawRectangle(rect: { x: number; y: number; width: number; height: number }): string {\n if (rect.width <= 0 || rect.height <= 0) {\n return '';\n }\n\n let pathData = '';\n\n // Creates a subpath moving in counterclockwise direction to create a hole\n\n pathData += `M ${rect.x},${rect.y} `;\n pathData += `V ${rect.y + rect.height} `; // Down to bottom-left\n pathData += `H ${rect.x + rect.width} `; // Right to bottom-right\n pathData += `V ${rect.y} `; // Up to top-right\n pathData += `H ${rect.x} `; // Left to top-left (closing)\n pathData += `Z `; // Close path\n\n return pathData;\n}\n\n/**\n * Computes a clip path that covers the area outside a rectangle.\n *\n * @internal\n */\nexport function computeOutsideClipPath(\n svgWidth: number,\n svgHeight: number,\n targetRect: { x: number; y: number; width: number; height: number },\n): string {\n let pathData = `M 0,0 H ${svgWidth} V ${svgHeight} H 0 Z `;\n\n // Draw the rectangle counterclockwise to create a hole in the main path.\n\n pathData += drawRectangle(targetRect);\n\n return pathData;\n}\n"],"names":["drawRectangle","rect","width","height","pathData","x","y","computeOutsideClipPath","svgWidth","svgHeight","targetRect"],"mappings":"AAAA,SAASA,cAAcC,IAA6D;IAClF,IAAIA,KAAKC,KAAK,IAAI,KAAKD,KAAKE,MAAM,IAAI,GAAG;QACvC,OAAO;IACT;IAEA,IAAIC,WAAW;IAEf,0EAA0E;IAE1EA,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,CAAC,CAAC,EAAEJ,KAAKK,CAAC,CAAC,CAAC,CAAC;IACpCF,YAAY,CAAC,EAAE,EAAEH,KAAKK,CAAC,GAAGL,KAAKE,MAAM,CAAC,CAAC,CAAC,EAAE,sBAAsB;IAChEC,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,GAAGJ,KAAKC,KAAK,CAAC,CAAC,CAAC,EAAE,wBAAwB;IACjEE,YAAY,CAAC,EAAE,EAAEH,KAAKK,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB;IAC9CF,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,CAAC,CAAC,CAAC,EAAE,6BAA6B;IACzDD,YAAY,CAAC,EAAE,CAAC,EAAE,aAAa;IAE/B,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,uBACdC,QAAgB,EAChBC,SAAiB,EACjBC,UAAmE;IAEnE,IAAIN,WAAW,CAAC,QAAQ,EAAEI,SAAS,GAAG,EAAEC,UAAU,OAAO,CAAC;IAE1D,yEAAyE;IAEzEL,YAAYJ,cAAcU;IAE1B,OAAON;AACT"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the mouse anchor and the container corners facing it.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/ export function getSafeZonePoints(mouseAnchor, containerCorners) {
|
|
6
|
+
const { topLeft, topRight, bottomRight, bottomLeft } = containerCorners;
|
|
7
|
+
const isAbove = mouseAnchor[1] < topLeft[1];
|
|
8
|
+
const isBelow = mouseAnchor[1] > bottomLeft[1];
|
|
9
|
+
const isLeft = mouseAnchor[0] < topLeft[0];
|
|
10
|
+
const isRight = mouseAnchor[0] > topRight[0];
|
|
11
|
+
if (isAbove) {
|
|
12
|
+
if (isLeft) {
|
|
13
|
+
return [
|
|
14
|
+
mouseAnchor,
|
|
15
|
+
bottomLeft,
|
|
16
|
+
topLeft,
|
|
17
|
+
topRight
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
if (isRight) {
|
|
21
|
+
return [
|
|
22
|
+
mouseAnchor,
|
|
23
|
+
topLeft,
|
|
24
|
+
topRight,
|
|
25
|
+
bottomRight
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
return [
|
|
29
|
+
mouseAnchor,
|
|
30
|
+
topLeft,
|
|
31
|
+
topRight
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (isBelow) {
|
|
35
|
+
if (isLeft) {
|
|
36
|
+
return [
|
|
37
|
+
mouseAnchor,
|
|
38
|
+
topLeft,
|
|
39
|
+
bottomLeft,
|
|
40
|
+
bottomRight
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
if (isRight) {
|
|
44
|
+
return [
|
|
45
|
+
mouseAnchor,
|
|
46
|
+
topRight,
|
|
47
|
+
bottomRight,
|
|
48
|
+
bottomLeft
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
return [
|
|
52
|
+
mouseAnchor,
|
|
53
|
+
bottomRight,
|
|
54
|
+
bottomLeft
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
if (isLeft) {
|
|
58
|
+
return [
|
|
59
|
+
mouseAnchor,
|
|
60
|
+
bottomLeft,
|
|
61
|
+
topLeft
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
if (isRight) {
|
|
65
|
+
return [
|
|
66
|
+
mouseAnchor,
|
|
67
|
+
topRight,
|
|
68
|
+
bottomRight
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/getSafeZonePoints.ts"],"sourcesContent":["import type { Point } from './types';\n\ntype RectCorners = Record<'topLeft' | 'topRight' | 'bottomRight' | 'bottomLeft', Point>;\n\n/**\n * Returns the mouse anchor and the container corners facing it.\n *\n * @internal\n */\nexport function getSafeZonePoints(mouseAnchor: Point, containerCorners: RectCorners): Point[] {\n const { topLeft, topRight, bottomRight, bottomLeft } = containerCorners;\n const isAbove = mouseAnchor[1] < topLeft[1];\n const isBelow = mouseAnchor[1] > bottomLeft[1];\n const isLeft = mouseAnchor[0] < topLeft[0];\n const isRight = mouseAnchor[0] > topRight[0];\n\n if (isAbove) {\n if (isLeft) {\n return [mouseAnchor, bottomLeft, topLeft, topRight];\n }\n\n if (isRight) {\n return [mouseAnchor, topLeft, topRight, bottomRight];\n }\n\n return [mouseAnchor, topLeft, topRight];\n }\n\n if (isBelow) {\n if (isLeft) {\n return [mouseAnchor, topLeft, bottomLeft, bottomRight];\n }\n\n if (isRight) {\n return [mouseAnchor, topRight, bottomRight, bottomLeft];\n }\n\n return [mouseAnchor, bottomRight, bottomLeft];\n }\n\n if (isLeft) {\n return [mouseAnchor, bottomLeft, topLeft];\n }\n\n if (isRight) {\n return [mouseAnchor, topRight, bottomRight];\n }\n\n return [];\n}\n"],"names":["getSafeZonePoints","mouseAnchor","containerCorners","topLeft","topRight","bottomRight","bottomLeft","isAbove","isBelow","isLeft","isRight"],"mappings":"AAIA;;;;CAIC,GACD,OAAO,SAASA,kBAAkBC,WAAkB,EAAEC,gBAA6B;IACjF,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,EAAE,GAAGJ;IACvD,MAAMK,UAAUN,WAAW,CAAC,EAAE,GAAGE,OAAO,CAAC,EAAE;IAC3C,MAAMK,UAAUP,WAAW,CAAC,EAAE,GAAGK,UAAU,CAAC,EAAE;IAC9C,MAAMG,SAASR,WAAW,CAAC,EAAE,GAAGE,OAAO,CAAC,EAAE;IAC1C,MAAMO,UAAUT,WAAW,CAAC,EAAE,GAAGG,QAAQ,CAAC,EAAE;IAE5C,IAAIG,SAAS;QACX,IAAIE,QAAQ;YACV,OAAO;gBAACR;gBAAaK;gBAAYH;gBAASC;aAAS;QACrD;QAEA,IAAIM,SAAS;YACX,OAAO;gBAACT;gBAAaE;gBAASC;gBAAUC;aAAY;QACtD;QAEA,OAAO;YAACJ;YAAaE;YAASC;SAAS;IACzC;IAEA,IAAII,SAAS;QACX,IAAIC,QAAQ;YACV,OAAO;gBAACR;gBAAaE;gBAASG;gBAAYD;aAAY;QACxD;QAEA,IAAIK,SAAS;YACX,OAAO;gBAACT;gBAAaG;gBAAUC;gBAAaC;aAAW;QACzD;QAEA,OAAO;YAACL;YAAaI;YAAaC;SAAW;IAC/C;IAEA,IAAIG,QAAQ;QACV,OAAO;YAACR;YAAaK;YAAYH;SAAQ;IAC3C;IAEA,IAAIO,SAAS;QACX,OAAO;YAACT;YAAaG;YAAUC;SAAY;IAC7C;IAEA,OAAO,EAAE;AACX"}
|
|
@@ -3,21 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get: all[name]
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
_export(exports, {
|
|
13
|
-
SafeZoneArea: function() {
|
|
6
|
+
Object.defineProperty(exports, "SafeZoneArea", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
14
9
|
return SafeZoneArea;
|
|
15
|
-
},
|
|
16
|
-
isSameCoordinates: function() {
|
|
17
|
-
return isSameCoordinates;
|
|
18
|
-
},
|
|
19
|
-
isSameRect: function() {
|
|
20
|
-
return isSameRect;
|
|
21
10
|
}
|
|
22
11
|
});
|
|
23
12
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
@@ -30,140 +19,83 @@ const _getMouseAnchor = require("./getMouseAnchor.cjs");
|
|
|
30
19
|
const _pointsToSvgPath = require("./pointsToSvgPath.cjs");
|
|
31
20
|
const _SafeZoneAreastyles = require("./SafeZoneArea.styles.cjs");
|
|
32
21
|
const _computeOutsideClipPath = require("./computeOutsideClipPath.cjs");
|
|
33
|
-
|
|
34
|
-
const EMPTY_RECT = {
|
|
35
|
-
top: 0,
|
|
36
|
-
right: 0,
|
|
37
|
-
bottom: 0,
|
|
38
|
-
left: 0,
|
|
39
|
-
width: 0,
|
|
40
|
-
height: 0,
|
|
41
|
-
x: 0,
|
|
42
|
-
y: 0,
|
|
43
|
-
toJSON () {
|
|
44
|
-
return '';
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function isSameRect(a, b) {
|
|
48
|
-
return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left && a.width === b.width && a.height === b.height;
|
|
49
|
-
}
|
|
50
|
-
function isSameCoordinates(a, b) {
|
|
51
|
-
return a[0] === b[0] && a[1] === b[1];
|
|
52
|
-
}
|
|
22
|
+
const _getSafeZonePoints = require("./getSafeZonePoints.cjs");
|
|
53
23
|
const SafeZoneArea = /*#__PURE__*/ _react1.memo((props)=>{
|
|
54
24
|
const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;
|
|
55
25
|
const clipPathId = (0, _reactutilities.useId)();
|
|
56
26
|
const styles = (0, _SafeZoneAreastyles.useStyles)();
|
|
57
27
|
const active = (0, _shim.useSyncExternalStore)(stateStore.subscribe, stateStore.isActive);
|
|
58
28
|
const svgRef = _react1.useRef(null);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
mouseCoordinates: [
|
|
63
|
-
0,
|
|
64
|
-
0
|
|
65
|
-
]
|
|
66
|
-
}));
|
|
29
|
+
const safeZoneRef = _react1.useRef(null);
|
|
30
|
+
const clipPathRef = _react1.useRef(null);
|
|
31
|
+
const rectDebugRef = _react1.useRef(null);
|
|
67
32
|
_react1.useImperativeHandle(props.imperativeRef, ()=>({
|
|
68
|
-
updateSVG (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
33
|
+
updateSVG ({ containerRect, targetRect, mouseCoordinates }) {
|
|
34
|
+
var _safeZoneRef_current, _clipPathRef_current, _rectDebugRef_current;
|
|
35
|
+
const topOffset = Math.min(targetRect.top, containerRect.top);
|
|
36
|
+
const leftOffset = Math.min(targetRect.left, containerRect.left);
|
|
37
|
+
const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);
|
|
38
|
+
const rightOffset = Math.max(targetRect.right, containerRect.right);
|
|
39
|
+
const containerCorners = (0, _getRectCorners.getRectCorners)(containerRect, [
|
|
40
|
+
leftOffset,
|
|
41
|
+
topOffset
|
|
42
|
+
]);
|
|
43
|
+
const targetCorners = (0, _getRectCorners.getRectCorners)(targetRect, [
|
|
44
|
+
leftOffset,
|
|
45
|
+
topOffset
|
|
46
|
+
]);
|
|
47
|
+
// SVG coordinates are relative to its top-left corner.
|
|
48
|
+
const relativeMouseCoordinates = [
|
|
49
|
+
mouseCoordinates[0] - leftOffset,
|
|
50
|
+
mouseCoordinates[1] - topOffset
|
|
51
|
+
];
|
|
52
|
+
const mouseAnchor = (0, _getMouseAnchor.getMouseAnchor)(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);
|
|
53
|
+
const svgWidth = rightOffset - leftOffset;
|
|
54
|
+
const svgHeight = bottomOffset - topOffset;
|
|
55
|
+
const clipPath = (0, _computeOutsideClipPath.computeOutsideClipPath)(svgWidth, svgHeight, {
|
|
56
|
+
x: targetCorners.topLeft[0],
|
|
57
|
+
y: targetCorners.topLeft[1],
|
|
58
|
+
width: targetRect.width,
|
|
59
|
+
height: targetRect.height
|
|
76
60
|
});
|
|
61
|
+
if (svgRef.current) {
|
|
62
|
+
svgRef.current.style.width = `${svgWidth}px`;
|
|
63
|
+
svgRef.current.style.height = `${svgHeight}px`;
|
|
64
|
+
svgRef.current.style.transform = `translate(${leftOffset}px, ${topOffset}px)`;
|
|
65
|
+
}
|
|
66
|
+
const safeZonePoints = (0, _getSafeZonePoints.getSafeZonePoints)(mouseAnchor, containerCorners);
|
|
67
|
+
(_safeZoneRef_current = safeZoneRef.current) === null || _safeZoneRef_current === void 0 ? void 0 : _safeZoneRef_current.setAttribute('d', safeZonePoints.length > 0 ? (0, _pointsToSvgPath.pointsToSvgPath)(safeZonePoints) : '');
|
|
68
|
+
(_clipPathRef_current = clipPathRef.current) === null || _clipPathRef_current === void 0 ? void 0 : _clipPathRef_current.setAttribute('d', clipPath);
|
|
69
|
+
(_rectDebugRef_current = rectDebugRef.current) === null || _rectDebugRef_current === void 0 ? void 0 : _rectDebugRef_current.setAttribute('d', clipPath);
|
|
77
70
|
}
|
|
78
71
|
}), []);
|
|
79
|
-
const { containerRect, targetRect, mouseCoordinates } = state;
|
|
80
|
-
const topOffset = Math.min(targetRect.top, containerRect.top);
|
|
81
|
-
const leftOffset = Math.min(targetRect.left, containerRect.left);
|
|
82
|
-
const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);
|
|
83
|
-
const rightOffset = Math.max(targetRect.right, containerRect.right);
|
|
84
|
-
// ---
|
|
85
|
-
const containerCorners = (0, _getRectCorners.getRectCorners)(containerRect, [
|
|
86
|
-
leftOffset,
|
|
87
|
-
topOffset
|
|
88
|
-
]);
|
|
89
|
-
const targetCorners = (0, _getRectCorners.getRectCorners)(targetRect, [
|
|
90
|
-
leftOffset,
|
|
91
|
-
topOffset
|
|
92
|
-
]);
|
|
93
|
-
// Heads up!
|
|
94
|
-
// The SVG coordinate system starts at the top-left corner of the SVG element,
|
|
95
|
-
// so we need to adjust the mouse coordinates relative to the SVG's top-left corner.
|
|
96
|
-
const relativeMouseCoordinates = [
|
|
97
|
-
mouseCoordinates[0] - leftOffset,
|
|
98
|
-
mouseCoordinates[1] - topOffset
|
|
99
|
-
];
|
|
100
|
-
const mouseAnchor = (0, _getMouseAnchor.getMouseAnchor)(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);
|
|
101
|
-
const triangleA = [
|
|
102
|
-
mouseAnchor,
|
|
103
|
-
containerCorners.topLeft,
|
|
104
|
-
containerCorners.topRight
|
|
105
|
-
];
|
|
106
|
-
const triangleB = [
|
|
107
|
-
mouseAnchor,
|
|
108
|
-
containerCorners.topRight,
|
|
109
|
-
containerCorners.bottomRight
|
|
110
|
-
];
|
|
111
|
-
const triangleC = [
|
|
112
|
-
mouseAnchor,
|
|
113
|
-
containerCorners.bottomRight,
|
|
114
|
-
containerCorners.bottomLeft
|
|
115
|
-
];
|
|
116
|
-
const triangleD = [
|
|
117
|
-
mouseAnchor,
|
|
118
|
-
containerCorners.bottomLeft,
|
|
119
|
-
containerCorners.topLeft
|
|
120
|
-
];
|
|
121
|
-
const svgWidth = rightOffset - leftOffset;
|
|
122
|
-
const svgHeight = bottomOffset - topOffset;
|
|
123
|
-
const clipPath = (0, _computeOutsideClipPath.computeOutsideClipPath)(svgWidth, svgHeight, {
|
|
124
|
-
x: targetCorners.topLeft[0],
|
|
125
|
-
y: targetCorners.topLeft[1],
|
|
126
|
-
width: targetRect.width,
|
|
127
|
-
height: targetRect.height
|
|
128
|
-
}, {
|
|
129
|
-
x: containerCorners.topLeft[0],
|
|
130
|
-
y: containerCorners.topLeft[1],
|
|
131
|
-
width: containerRect.width,
|
|
132
|
-
height: containerRect.height
|
|
133
|
-
});
|
|
134
72
|
return /*#__PURE__*/ _react1.createElement("div", {
|
|
135
73
|
className: (0, _react.mergeClasses)(styles.wrapper, active && styles.wrapperActive),
|
|
136
74
|
"data-safe-zone": ""
|
|
137
|
-
},
|
|
75
|
+
}, /*#__PURE__*/ _react1.createElement("svg", {
|
|
138
76
|
"aria-hidden": true,
|
|
139
77
|
className: styles.svg,
|
|
140
78
|
xmlns: "http://www.w3.org/2000/svg",
|
|
141
79
|
ref: svgRef,
|
|
142
80
|
style: {
|
|
143
|
-
width:
|
|
144
|
-
height:
|
|
145
|
-
transform:
|
|
81
|
+
width: 0,
|
|
82
|
+
height: 0,
|
|
83
|
+
transform: 'translate(0px, 0px)'
|
|
146
84
|
}
|
|
147
85
|
}, /*#__PURE__*/ _react1.createElement("g", {
|
|
148
|
-
className: (0, _react.mergeClasses)(styles.
|
|
86
|
+
className: (0, _react.mergeClasses)(styles.safeZone, debug && styles.safeZoneDebug),
|
|
149
87
|
clipPath: `url(#${clipPathId})`,
|
|
150
88
|
onMouseEnter: onMouseEnter,
|
|
151
89
|
onMouseMove: onMouseMove,
|
|
152
90
|
onMouseLeave: onMouseLeave
|
|
153
91
|
}, /*#__PURE__*/ _react1.createElement("path", {
|
|
154
|
-
|
|
155
|
-
}), /*#__PURE__*/ _react1.createElement("path", {
|
|
156
|
-
d: (0, _pointsToSvgPath.pointsToSvgPath)(triangleB)
|
|
157
|
-
}), /*#__PURE__*/ _react1.createElement("path", {
|
|
158
|
-
d: (0, _pointsToSvgPath.pointsToSvgPath)(triangleC)
|
|
159
|
-
}), /*#__PURE__*/ _react1.createElement("path", {
|
|
160
|
-
d: (0, _pointsToSvgPath.pointsToSvgPath)(triangleD)
|
|
92
|
+
ref: safeZoneRef
|
|
161
93
|
})), /*#__PURE__*/ _react1.createElement("clipPath", {
|
|
162
94
|
id: clipPathId
|
|
163
95
|
}, /*#__PURE__*/ _react1.createElement("path", {
|
|
164
|
-
|
|
96
|
+
ref: clipPathRef
|
|
165
97
|
})), debug && /*#__PURE__*/ _react1.createElement("path", {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}))
|
|
98
|
+
ref: rectDebugRef,
|
|
99
|
+
className: styles.rectDebug
|
|
100
|
+
})));
|
|
169
101
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n/**\n * @internal\n */\ntype SafeZoneAreaState = {\n containerRect: DOMRect;\n targetRect: DOMRect;\n mouseCoordinates: Point;\n};\n\n// ---\n\nconst EMPTY_RECT: DOMRect = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n width: 0,\n height: 0,\n x: 0,\n y: 0,\n toJSON() {\n return '';\n },\n};\n\nexport function isSameRect(a: DOMRect, b: DOMRect): boolean {\n return (\n a.top === b.top &&\n a.right === b.right &&\n a.bottom === b.bottom &&\n a.left === b.left &&\n a.width === b.width &&\n a.height === b.height\n );\n}\n\nexport function isSameCoordinates(a: Point, b: Point): boolean {\n return a[0] === b[0] && a[1] === b[1];\n}\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws two shapes:\n * - a triangle that points to the target element which is an actual safe zone\n * - a rectangle for a clip path that clips out the target element\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n\n const [state, setState] = React.useState<SafeZoneAreaState>(() => ({\n containerRect: EMPTY_RECT,\n targetRect: EMPTY_RECT,\n mouseCoordinates: [0, 0],\n }));\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG(newState) {\n setState(prevState => {\n // Heads up!\n // A small optimization to avoid unnecessary re-renders\n if (\n isSameRect(prevState.containerRect, newState.containerRect) &&\n isSameRect(prevState.targetRect, newState.targetRect) &&\n isSameCoordinates(prevState.mouseCoordinates, newState.mouseCoordinates)\n ) {\n return prevState;\n }\n\n return newState;\n });\n },\n }),\n [],\n );\n\n const { containerRect, targetRect, mouseCoordinates } = state;\n\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n // ---\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // Heads up!\n // The SVG coordinate system starts at the top-left corner of the SVG element,\n // so we need to adjust the mouse coordinates relative to the SVG's top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);\n\n const triangleA = [mouseAnchor, containerCorners.topLeft, containerCorners.topRight];\n const triangleB = [mouseAnchor, containerCorners.topRight, containerCorners.bottomRight];\n const triangleC = [mouseAnchor, containerCorners.bottomRight, containerCorners.bottomLeft];\n const triangleD = [mouseAnchor, containerCorners.bottomLeft, containerCorners.topLeft];\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n\n const clipPath = computeOutsideClipPath(\n svgWidth,\n svgHeight,\n {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n },\n {\n x: containerCorners.topLeft[0],\n y: containerCorners.topLeft[1],\n width: containerRect.width,\n height: containerRect.height,\n },\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n {active ? (\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{\n width: `${svgWidth}px`,\n height: `${svgHeight}px`,\n transform: `translate(${leftOffset}px, ${topOffset}px)`,\n }}\n >\n <g\n className={mergeClasses(styles.triangle, debug && styles.triangleDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path d={pointsToSvgPath(triangleA)} />\n <path d={pointsToSvgPath(triangleB)} />\n <path d={pointsToSvgPath(triangleC)} />\n <path d={pointsToSvgPath(triangleD)} />\n </g>\n\n <clipPath id={clipPathId}>\n <path d={clipPath} />\n </clipPath>\n\n {debug && <path className={styles.rectDebug} d={clipPath} />}\n </svg>\n ) : null}\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","EMPTY_RECT","top","right","bottom","left","width","height","x","y","toJSON","isSameRect","a","b","isSameCoordinates","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","state","setState","useState","containerRect","targetRect","mouseCoordinates","useImperativeHandle","imperativeRef","updateSVG","newState","prevState","topOffset","Math","min","leftOffset","bottomOffset","max","rightOffset","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","triangleA","topRight","triangleB","triangleC","bottomLeft","triangleD","svgWidth","svgHeight","clipPath","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","style","transform","g","triangle","triangleDebug","path","d","id","rectDebug"],"mappings":"AAAA;;;;;;;;;;;;IAyFauB,YAAAA;;;qBAhBGD;;;cAXAH;;;;;uBA5Da,iBAAiB;gCACxB,4BAA4B;kEAE3B,QAAQ;sBACM,+BAA+B;gCAGrC,sBAAmB;gCACnB,sBAAmB;i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hF,gCAAAA,EAAgBwD;sBACzB,QAAA,aAAA,CAACuB,QAAAA;QAAKC,OAAGhF,gCAAAA,EAAgB0D;sBACzB,QAAA,aAAA,CAACqB,QAAAA;QAAKC,OAAGhF,gCAAAA,EAAgB2D;sBACzB,QAAA,aAAA,CAACoB,QAAAA;QAAKC,OAAGhF,gCAAAA,EAAgB6D;uBAG3B,QAAA,aAAA,CAACG,YAAAA;QAASiB,IAAIxD;qBACZ,QAAA,aAAA,CAACsD,QAAAA;QAAKC,GAAGhB;SAGV5C,SAAAA,WAAAA,GAAS,QAAA,aAAA,CAAC2D,QAAAA;QAAKb,WAAWxC,OAAOwD,SAAS;QAAEF,GAAGhB;UAEhD;AAGV,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\nimport { getSafeZonePoints } from './getSafeZonePoints';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws a polygon from the mouse to the facing edges of the container and clips out the target element.\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n const safeZoneRef = React.useRef<SVGPathElement>(null);\n const clipPathRef = React.useRef<SVGPathElement>(null);\n const rectDebugRef = React.useRef<SVGPathElement>(null);\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG({ containerRect, targetRect, mouseCoordinates }) {\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // SVG coordinates are relative to its top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(\n containerCorners.topLeft,\n containerCorners.bottomRight,\n relativeMouseCoordinates,\n );\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n const clipPath = computeOutsideClipPath(svgWidth, svgHeight, {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n });\n\n if (svgRef.current) {\n svgRef.current.style.width = `${svgWidth}px`;\n svgRef.current.style.height = `${svgHeight}px`;\n svgRef.current.style.transform = `translate(${leftOffset}px, ${topOffset}px)`;\n }\n\n const safeZonePoints = getSafeZonePoints(mouseAnchor, containerCorners);\n safeZoneRef.current?.setAttribute('d', safeZonePoints.length > 0 ? pointsToSvgPath(safeZonePoints) : '');\n clipPathRef.current?.setAttribute('d', clipPath);\n rectDebugRef.current?.setAttribute('d', clipPath);\n },\n }),\n [],\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{ width: 0, height: 0, transform: 'translate(0px, 0px)' }}\n >\n <g\n className={mergeClasses(styles.safeZone, debug && styles.safeZoneDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path ref={safeZoneRef} />\n </g>\n\n <clipPath id={clipPathId}>\n <path ref={clipPathRef} />\n </clipPath>\n\n {debug && <path ref={rectDebugRef} className={styles.rectDebug} />}\n </svg>\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","getSafeZonePoints","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","safeZoneRef","clipPathRef","rectDebugRef","useImperativeHandle","imperativeRef","updateSVG","containerRect","targetRect","mouseCoordinates","topOffset","Math","min","top","leftOffset","left","bottomOffset","max","bottom","rightOffset","right","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","svgWidth","svgHeight","clipPath","x","y","width","height","current","style","transform","safeZonePoints","setAttribute","length","div","className","wrapper","wrapperActive","data-safe-z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,yBAAAA,aAAa+B,OAAAA,AAAO,MAAA,QAApB/B,0BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,sBAAsBmC,YAAY,CAAC,KAAKT;YAC1C;SACF,CAAA,EACA,EAAE;IAGJ,OAAA,WAAA,GACE,QAAA,aAAA,CAACW,OAAAA;QAAIC,eAAWjE,mBAAAA,EAAamB,OAAO+C,OAAO,EAAE9C,UAAUD,OAAOgD,aAAa;QAAGC,kBAAe;qBAC3F,QAAA,aAAA,CAACC,OAAAA;QACCC,eAAAA;QACAL,WAAW9C,OAAOkD,GAAG;QACrBE,OAAM;QACNC,KAAKjD;QACLoC,OAAO;YAAEH,OAAO;YAAGC,QAAQ;YAAGG,WAAW;QAAsB;qBAE/D,QAAA,aAAA,CAACa,KAAAA;QACCR,eAAWjE,mBAAAA,EAAamB,OAAOuD,QAAQ,EAAE7D,SAASM,OAAOwD,aAAa;QACtEtB,UAAU,CAAC,KAAK,EAAEnC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;qBAEd,QAAA,aAAA,CAAC4D,QAAAA;QAAKJ,KAAK/C;uBAGb,QAAA,aAAA,CAAC4B,YAAAA;QAASwB,IAAI3D;qBACZ,QAAA,aAAA,CAAC0D,QAAAA;QAAKJ,KAAK9C;SAGZb,SAAAA,WAAAA,GAAS,QAAA,aAAA,CAAC+D,QAAAA;QAAKJ,KAAK7C;QAAcsC,WAAW9C,OAAO2D,SAAS;;AAItE,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SafeZoneArea.styles.js"],"sourcesContent":["'use client';\nimport { makeStyles } from \"@griffel/react\";\nimport { tokens } from \"@fluentui/react-theme\";\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none'\n },\n wrapperActive: {\n display: 'block'\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0\n },\n
|
|
1
|
+
{"version":3,"sources":["SafeZoneArea.styles.js"],"sourcesContent":["'use client';\nimport { makeStyles } from \"@griffel/react\";\nimport { tokens } from \"@fluentui/react-theme\";\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none'\n },\n wrapperActive: {\n display: 'block'\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0\n },\n safeZone: {\n pointerEvents: 'auto'\n },\n safeZoneDebug: {\n cursor: 'crosshair',\n fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`\n },\n rectDebug: {\n fill: `color-mix(in srgb, ${tokens.colorPaletteRedBackground3} 20%, transparent)`\n }\n});\n"],"names":["__styles","tokens","useStyles","wrapper","mc9l5x","Bqenvij","a9b677","Bkecrkj","wrapperActive","svg","Bkfmm31","qhf8xq","Bhzewxz","oyh7mz","safeZone","safeZoneDebug","Bceei9c","rectDebug","d"],"mappings":"AAAA,YAAY;;;;;+BAGCE,SAAS;;;;;;uBAFK,gBAAgB;AAEpC,kBAAe,WAAA,OAAGF,eAAA,EAAA;IAAAG,OAAA,EAAA;QAAAC,MAAA,EAAA;QAAAC,OAAA,EAAA;QAAAC,MAAA,EAAA;QAAAC,OAAA,EAAA;IAAA;IAAAC,aAAA,EAAA;QAAAJ,MAAA,EAAA;IAAA;IAAAK,GAAA,EAAA;QAAAC,OAAA,EAAA;QAAAH,OAAA,EAAA;QAAAI,MAAA,EAAA;QAAAC,OAAA,EAAA;QAAAC,MAAA,EAAA;YAAA;YAAA;SAAA;IAAA;IAAAC,QAAA,EAAA;QAAAP,OAAA,EAAA;IAAA;IAAAQ,aAAA,EAAA;QAAAC,OAAA,EAAA;QAAAN,OAAA,EAAA;IAAA;IAAAO,SAAA,EAAA;QAAAP,OAAA,EAAA;IAAA;AAAA,GAAA;IAAAQ,CAAA,EAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;QAAA;KAAA;AAAA,CA2BxB,CAAC"}
|
|
@@ -28,10 +28,10 @@ const useStyles = (0, _react.makeStyles)({
|
|
|
28
28
|
top: 0,
|
|
29
29
|
left: 0
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
safeZone: {
|
|
32
32
|
pointerEvents: 'auto'
|
|
33
33
|
},
|
|
34
|
-
|
|
34
|
+
safeZoneDebug: {
|
|
35
35
|
cursor: 'crosshair',
|
|
36
36
|
fill: `color-mix(in srgb, ${_reacttheme.tokens.colorPaletteGreenBackground3} 20%, transparent)`
|
|
37
37
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.styles.ts"],"sourcesContent":["'use client';\n\nimport { makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\n\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none',\n },\n wrapperActive: {\n display: 'block',\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0,\n },\n
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.styles.ts"],"sourcesContent":["'use client';\n\nimport { makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\n\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none',\n },\n wrapperActive: {\n display: 'block',\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0,\n },\n safeZone: {\n pointerEvents: 'auto',\n },\n safeZoneDebug: {\n cursor: 'crosshair',\n fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`,\n },\n rectDebug: {\n fill: `color-mix(in srgb, ${tokens.colorPaletteRedBackground3} 20%, transparent)`,\n },\n});\n"],"names":["makeStyles","tokens","useStyles","wrapper","display","height","width","pointerEvents","wrapperActive","svg","fill","position","top","left","safeZone","safeZoneDebug","cursor","colorPaletteGreenBackground3","rectDebug","colorPaletteRedBackground3"],"mappings":"AAAA;;;;;+BAKaE;;;;;;uBAHc,iBAAiB;4BACrB,wBAAwB;AAExC,sBAAkBF,iBAAAA,EAAW;IAClCG,SAAS;QACPC,SAAS;QACTC,QAAQ;QACRC,OAAO;QACPC,eAAe;IACjB;IACAC,eAAe;QACbJ,SAAS;IACX;IACAK,KAAK;QACHC,MAAM;QACNH,eAAe;QACfI,UAAU;QACVC,KAAK;QACLC,MAAM;IACR;IACAC,UAAU;QACRP,eAAe;IACjB;IACAQ,eAAe;QACbC,QAAQ;QACRN,MAAM,CAAC,mBAAmB,EAAET,kBAAAA,CAAOgB,4BAA4B,CAAC,kBAAkB,CAAC;IACrF;IACAC,WAAW;QACTR,MAAM,CAAC,mBAAmB,EAAET,kBAAAA,CAAOkB,0BAA0B,CAAC,kBAAkB,CAAC;IACnF;AACF,GAAG"}
|
|
@@ -22,12 +22,9 @@ function drawRectangle(rect) {
|
|
|
22
22
|
pathData += `Z `; // Close path
|
|
23
23
|
return pathData;
|
|
24
24
|
}
|
|
25
|
-
function computeOutsideClipPath(svgWidth, svgHeight, targetRect
|
|
25
|
+
function computeOutsideClipPath(svgWidth, svgHeight, targetRect) {
|
|
26
26
|
let pathData = `M 0,0 H ${svgWidth} V ${svgHeight} H 0 Z `;
|
|
27
|
-
//
|
|
28
|
-
// The trick is to draw each rectangle in the counterclockwise direction
|
|
29
|
-
// which creates a "hole" in the main path
|
|
27
|
+
// Draw the rectangle counterclockwise to create a hole in the main path.
|
|
30
28
|
pathData += drawRectangle(targetRect);
|
|
31
|
-
pathData += drawRectangle(containerRect);
|
|
32
29
|
return pathData;
|
|
33
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/computeOutsideClipPath.ts"],"sourcesContent":["function drawRectangle(rect: { x: number; y: number; width: number; height: number }): string {\n if (rect.width <= 0 || rect.height <= 0) {\n return '';\n }\n\n let pathData = '';\n\n // Creates a subpath moving in counterclockwise direction to create a hole\n\n pathData += `M ${rect.x},${rect.y} `;\n pathData += `V ${rect.y + rect.height} `; // Down to bottom-left\n pathData += `H ${rect.x + rect.width} `; // Right to bottom-right\n pathData += `V ${rect.y} `; // Up to top-right\n pathData += `H ${rect.x} `; // Left to top-left (closing)\n pathData += `Z `; // Close path\n\n return pathData;\n}\n\n/**\n * Computes a clip path that covers the area outside
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/computeOutsideClipPath.ts"],"sourcesContent":["function drawRectangle(rect: { x: number; y: number; width: number; height: number }): string {\n if (rect.width <= 0 || rect.height <= 0) {\n return '';\n }\n\n let pathData = '';\n\n // Creates a subpath moving in counterclockwise direction to create a hole\n\n pathData += `M ${rect.x},${rect.y} `;\n pathData += `V ${rect.y + rect.height} `; // Down to bottom-left\n pathData += `H ${rect.x + rect.width} `; // Right to bottom-right\n pathData += `V ${rect.y} `; // Up to top-right\n pathData += `H ${rect.x} `; // Left to top-left (closing)\n pathData += `Z `; // Close path\n\n return pathData;\n}\n\n/**\n * Computes a clip path that covers the area outside a rectangle.\n *\n * @internal\n */\nexport function computeOutsideClipPath(\n svgWidth: number,\n svgHeight: number,\n targetRect: { x: number; y: number; width: number; height: number },\n): string {\n let pathData = `M 0,0 H ${svgWidth} V ${svgHeight} H 0 Z `;\n\n // Draw the rectangle counterclockwise to create a hole in the main path.\n\n pathData += drawRectangle(targetRect);\n\n return pathData;\n}\n"],"names":["drawRectangle","rect","width","height","pathData","x","y","computeOutsideClipPath","svgWidth","svgHeight","targetRect"],"mappings":";;;;;;;;;;AAAA,SAASA,cAAcC,IAA6D;IAClF,IAAIA,KAAKC,KAAK,IAAI,KAAKD,KAAKE,MAAM,IAAI,GAAG;QACvC,OAAO;IACT;IAEA,IAAIC,WAAW;IAEf,0EAA0E;IAE1EA,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,CAAC,CAAC,EAAEJ,KAAKK,CAAC,CAAC,CAAC,CAAC;IACpCF,YAAY,CAAC,EAAE,EAAEH,KAAKK,CAAC,GAAGL,KAAKE,MAAM,CAAC,CAAC,CAAC,EAAE,sBAAsB;IAChEC,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,GAAGJ,KAAKC,KAAK,CAAC,CAAC,CAAC,EAAE,wBAAwB;IACjEE,YAAY,CAAC,EAAE,EAAEH,KAAKK,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB;IAC9CF,YAAY,CAAC,EAAE,EAAEH,KAAKI,CAAC,CAAC,CAAC,CAAC,EAAE,6BAA6B;IACzDD,YAAY,CAAC,EAAE,CAAC,EAAE,aAAa;IAE/B,OAAOA;AACT;AAOO,SAASG,uBACdC,QAAgB,EAChBC,SAAiB,EACjBC,UAAmE;IAEnE,IAAIN,WAAW,CAAC,QAAQ,EAAEI,SAAS,GAAG,EAAEC,UAAU,OAAO,CAAC;IAE1D,yEAAyE;IAEzEL,YAAYJ,cAAcU;IAE1B,OAAON;AACT"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the mouse anchor and the container corners facing it.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "getSafeZonePoints", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return getSafeZonePoints;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
function getSafeZonePoints(mouseAnchor, containerCorners) {
|
|
16
|
+
const { topLeft, topRight, bottomRight, bottomLeft } = containerCorners;
|
|
17
|
+
const isAbove = mouseAnchor[1] < topLeft[1];
|
|
18
|
+
const isBelow = mouseAnchor[1] > bottomLeft[1];
|
|
19
|
+
const isLeft = mouseAnchor[0] < topLeft[0];
|
|
20
|
+
const isRight = mouseAnchor[0] > topRight[0];
|
|
21
|
+
if (isAbove) {
|
|
22
|
+
if (isLeft) {
|
|
23
|
+
return [
|
|
24
|
+
mouseAnchor,
|
|
25
|
+
bottomLeft,
|
|
26
|
+
topLeft,
|
|
27
|
+
topRight
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
if (isRight) {
|
|
31
|
+
return [
|
|
32
|
+
mouseAnchor,
|
|
33
|
+
topLeft,
|
|
34
|
+
topRight,
|
|
35
|
+
bottomRight
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
return [
|
|
39
|
+
mouseAnchor,
|
|
40
|
+
topLeft,
|
|
41
|
+
topRight
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
if (isBelow) {
|
|
45
|
+
if (isLeft) {
|
|
46
|
+
return [
|
|
47
|
+
mouseAnchor,
|
|
48
|
+
topLeft,
|
|
49
|
+
bottomLeft,
|
|
50
|
+
bottomRight
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
if (isRight) {
|
|
54
|
+
return [
|
|
55
|
+
mouseAnchor,
|
|
56
|
+
topRight,
|
|
57
|
+
bottomRight,
|
|
58
|
+
bottomLeft
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
mouseAnchor,
|
|
63
|
+
bottomRight,
|
|
64
|
+
bottomLeft
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (isLeft) {
|
|
68
|
+
return [
|
|
69
|
+
mouseAnchor,
|
|
70
|
+
bottomLeft,
|
|
71
|
+
topLeft
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
if (isRight) {
|
|
75
|
+
return [
|
|
76
|
+
mouseAnchor,
|
|
77
|
+
topRight,
|
|
78
|
+
bottomRight
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/getSafeZonePoints.ts"],"sourcesContent":["import type { Point } from './types';\n\ntype RectCorners = Record<'topLeft' | 'topRight' | 'bottomRight' | 'bottomLeft', Point>;\n\n/**\n * Returns the mouse anchor and the container corners facing it.\n *\n * @internal\n */\nexport function getSafeZonePoints(mouseAnchor: Point, containerCorners: RectCorners): Point[] {\n const { topLeft, topRight, bottomRight, bottomLeft } = containerCorners;\n const isAbove = mouseAnchor[1] < topLeft[1];\n const isBelow = mouseAnchor[1] > bottomLeft[1];\n const isLeft = mouseAnchor[0] < topLeft[0];\n const isRight = mouseAnchor[0] > topRight[0];\n\n if (isAbove) {\n if (isLeft) {\n return [mouseAnchor, bottomLeft, topLeft, topRight];\n }\n\n if (isRight) {\n return [mouseAnchor, topLeft, topRight, bottomRight];\n }\n\n return [mouseAnchor, topLeft, topRight];\n }\n\n if (isBelow) {\n if (isLeft) {\n return [mouseAnchor, topLeft, bottomLeft, bottomRight];\n }\n\n if (isRight) {\n return [mouseAnchor, topRight, bottomRight, bottomLeft];\n }\n\n return [mouseAnchor, bottomRight, bottomLeft];\n }\n\n if (isLeft) {\n return [mouseAnchor, bottomLeft, topLeft];\n }\n\n if (isRight) {\n return [mouseAnchor, topRight, bottomRight];\n }\n\n return [];\n}\n"],"names":["getSafeZonePoints","mouseAnchor","containerCorners","topLeft","topRight","bottomRight","bottomLeft","isAbove","isBelow","isLeft","isRight"],"mappings":"AAIA;;;;CAIC,GACD;;;;+BAAgBA;;;;;;AAAT,2BAA2BC,WAAkB,EAAEC,gBAA6B;IACjF,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,EAAE,GAAGJ;IACvD,MAAMK,UAAUN,WAAW,CAAC,EAAE,GAAGE,OAAO,CAAC,EAAE;IAC3C,MAAMK,UAAUP,WAAW,CAAC,EAAE,GAAGK,UAAU,CAAC,EAAE;IAC9C,MAAMG,SAASR,WAAW,CAAC,EAAE,GAAGE,OAAO,CAAC,EAAE;IAC1C,MAAMO,UAAUT,WAAW,CAAC,EAAE,GAAGG,QAAQ,CAAC,EAAE;IAE5C,IAAIG,SAAS;QACX,IAAIE,QAAQ;YACV,OAAO;gBAACR;gBAAaK;gBAAYH;gBAASC;aAAS;QACrD;QAEA,IAAIM,SAAS;YACX,OAAO;gBAACT;gBAAaE;gBAASC;gBAAUC;aAAY;QACtD;QAEA,OAAO;YAACJ;YAAaE;YAASC;SAAS;IACzC;IAEA,IAAII,SAAS;QACX,IAAIC,QAAQ;YACV,OAAO;gBAACR;gBAAaE;gBAASG;gBAAYD;aAAY;QACxD;QAEA,IAAIK,SAAS;YACX,OAAO;gBAACT;gBAAaG;gBAAUC;gBAAaC;aAAW;QACzD;QAEA,OAAO;YAACL;YAAaI;YAAaC;SAAW;IAC/C;IAEA,IAAIG,QAAQ;QACV,OAAO;YAACR;YAAaK;YAAYH;SAAQ;IAC3C;IAEA,IAAIO,SAAS;QACX,OAAO;YAACT;YAAaG;YAAUC;SAAY;IAC7C;IAEA,OAAO,EAAE;AACX"}
|