@bleedingdev/modern-js-boundary-debugger 0.0.0 → 3.9.0-ultramodern.5
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/LICENSE +21 -0
- package/dist/cjs/boundary-debugger/index.js +317 -0
- package/dist/esm/boundary-debugger/index.mjs +277 -0
- package/dist/esm-node/boundary-debugger/index.mjs +278 -0
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/package.json +58 -7
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +36 -0
- package/src/boundary-debugger/index.tsx +427 -0
- package/tests/boundary-debugger/browser.test.ts +252 -0
- package/tests/boundary-debugger/client.test.tsx +297 -0
- package/tests/boundary-debugger/index.test.tsx +63 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
default: ()=>boundary_debugger,
|
|
32
|
+
ultramodernBoundaryDebuggerPlugin: ()=>ultramodernBoundaryDebuggerPlugin
|
|
33
|
+
});
|
|
34
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
35
|
+
const external_react_namespaceObject = require("react");
|
|
36
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
37
|
+
const queryParamName = 'modern-boundaries';
|
|
38
|
+
const boundarySelector = '[data-modern-boundary-id]';
|
|
39
|
+
const defaultLabels = {
|
|
40
|
+
cs: {
|
|
41
|
+
toggle: 'zobrazit hranice týmů'
|
|
42
|
+
},
|
|
43
|
+
en: {
|
|
44
|
+
toggle: 'show team boundaries'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const palette = [
|
|
48
|
+
'#ff5a5f',
|
|
49
|
+
'#30e27a',
|
|
50
|
+
'#f6cf45',
|
|
51
|
+
'#7c8cff',
|
|
52
|
+
'#29b6f6'
|
|
53
|
+
];
|
|
54
|
+
const readStoredEnabled = (storageKey, fallback)=>{
|
|
55
|
+
if ("u" < typeof window) return fallback;
|
|
56
|
+
try {
|
|
57
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
58
|
+
return null === stored ? fallback : 'true' === stored;
|
|
59
|
+
} catch {
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
64
|
+
if ("u" < typeof window) return;
|
|
65
|
+
try {
|
|
66
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
67
|
+
} catch {}
|
|
68
|
+
};
|
|
69
|
+
const parseEnabledOverride = (value)=>{
|
|
70
|
+
if (null === value) return;
|
|
71
|
+
const normalized = value.toLowerCase();
|
|
72
|
+
if ('1' === normalized || 'true' === normalized) return true;
|
|
73
|
+
if ('0' === normalized || 'false' === normalized) return false;
|
|
74
|
+
};
|
|
75
|
+
const readQueryEnabledOverride = ()=>{
|
|
76
|
+
if ("u" < typeof window) return;
|
|
77
|
+
try {
|
|
78
|
+
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const detectLanguage = ()=>{
|
|
84
|
+
if ("u" < typeof document) return 'en';
|
|
85
|
+
const htmlLanguage = document.documentElement.lang;
|
|
86
|
+
if ('' !== htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
87
|
+
if ("u" < typeof window) return 'en';
|
|
88
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
89
|
+
};
|
|
90
|
+
const hashBoundaryId = (id)=>{
|
|
91
|
+
let hash = 0;
|
|
92
|
+
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
93
|
+
return hash;
|
|
94
|
+
};
|
|
95
|
+
const formatRectKey = (rect)=>[
|
|
96
|
+
Math.round(100 * rect.left) / 100,
|
|
97
|
+
Math.round(100 * rect.top) / 100,
|
|
98
|
+
Math.round(100 * rect.width) / 100,
|
|
99
|
+
Math.round(100 * rect.height) / 100
|
|
100
|
+
].join(':');
|
|
101
|
+
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
102
|
+
const collectBoundaryElements = (legacySelector)=>{
|
|
103
|
+
const elements = new Set();
|
|
104
|
+
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
105
|
+
if (void 0 === legacySelector || '' === legacySelector) return Array.from(elements);
|
|
106
|
+
try {
|
|
107
|
+
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
108
|
+
} catch {}
|
|
109
|
+
return Array.from(elements);
|
|
110
|
+
};
|
|
111
|
+
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
112
|
+
const [mounted, setMounted] = (0, external_react_namespaceObject.useState)(false);
|
|
113
|
+
const [enabled, setEnabled] = (0, external_react_namespaceObject.useState)(false);
|
|
114
|
+
const [boxes, setBoxes] = (0, external_react_namespaceObject.useState)([]);
|
|
115
|
+
const boundaries = (0, external_react_namespaceObject.useMemo)(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
116
|
+
entry.mfName,
|
|
117
|
+
{
|
|
118
|
+
...entry,
|
|
119
|
+
color: entry.color ?? palette[index % palette.length],
|
|
120
|
+
label: entry.label ?? entry.appId
|
|
121
|
+
}
|
|
122
|
+
])), [
|
|
123
|
+
metadata
|
|
124
|
+
]);
|
|
125
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
126
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
127
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
128
|
+
setMounted(true);
|
|
129
|
+
const queryOverride = readQueryEnabledOverride();
|
|
130
|
+
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
131
|
+
}, [
|
|
132
|
+
enabledByDefault,
|
|
133
|
+
storageKey
|
|
134
|
+
]);
|
|
135
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
136
|
+
if (!mounted) return;
|
|
137
|
+
writeStoredEnabled(storageKey, enabled);
|
|
138
|
+
}, [
|
|
139
|
+
enabled,
|
|
140
|
+
mounted,
|
|
141
|
+
storageKey
|
|
142
|
+
]);
|
|
143
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
144
|
+
if (!enabled) return void setBoxes([]);
|
|
145
|
+
let resizeObserver;
|
|
146
|
+
const observedElements = new Set();
|
|
147
|
+
const observeBoundaryElements = (elements)=>{
|
|
148
|
+
if (void 0 === resizeObserver) return;
|
|
149
|
+
for (const element of elements)if (!observedElements.has(element)) {
|
|
150
|
+
observedElements.add(element);
|
|
151
|
+
resizeObserver.observe(element);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const readBoxes = ()=>{
|
|
155
|
+
const elements = collectBoundaryElements(legacySelector);
|
|
156
|
+
observeBoundaryElements(elements);
|
|
157
|
+
const seenBoxes = new Set();
|
|
158
|
+
const nextBoxes = elements.map((element)=>{
|
|
159
|
+
const boundaryId = getBoundaryId(element);
|
|
160
|
+
if (void 0 === boundaryId || '' === boundaryId) return;
|
|
161
|
+
const rect = element.getBoundingClientRect();
|
|
162
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
163
|
+
const rectKey = formatRectKey(rect);
|
|
164
|
+
const boxKey = `${boundaryId}:${rectKey}`;
|
|
165
|
+
if (seenBoxes.has(boxKey)) return;
|
|
166
|
+
seenBoxes.add(boxKey);
|
|
167
|
+
const boundary = boundaries.get(boundaryId);
|
|
168
|
+
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
169
|
+
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
170
|
+
const expose = element.dataset.modernMfExpose;
|
|
171
|
+
const detail = void 0 !== expose && '' !== expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
172
|
+
const box = {
|
|
173
|
+
color,
|
|
174
|
+
height: rect.height,
|
|
175
|
+
id: boxKey,
|
|
176
|
+
label,
|
|
177
|
+
left: rect.left,
|
|
178
|
+
top: rect.top,
|
|
179
|
+
width: rect.width
|
|
180
|
+
};
|
|
181
|
+
if (void 0 !== detail) box.detail = detail;
|
|
182
|
+
return box;
|
|
183
|
+
}).filter((box)=>void 0 !== box);
|
|
184
|
+
setBoxes(nextBoxes);
|
|
185
|
+
};
|
|
186
|
+
resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
187
|
+
readBoxes();
|
|
188
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
189
|
+
mutationObserver.observe(document.body, {
|
|
190
|
+
childList: true,
|
|
191
|
+
subtree: true
|
|
192
|
+
});
|
|
193
|
+
window.addEventListener('resize', readBoxes);
|
|
194
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
195
|
+
return ()=>{
|
|
196
|
+
mutationObserver.disconnect();
|
|
197
|
+
resizeObserver?.disconnect();
|
|
198
|
+
window.removeEventListener('resize', readBoxes);
|
|
199
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
200
|
+
};
|
|
201
|
+
}, [
|
|
202
|
+
boundaries,
|
|
203
|
+
enabled,
|
|
204
|
+
legacySelector
|
|
205
|
+
]);
|
|
206
|
+
if (!mounted) return null;
|
|
207
|
+
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
208
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
209
|
+
children: [
|
|
210
|
+
shouldRenderToggle ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("label", {
|
|
211
|
+
style: {
|
|
212
|
+
alignItems: 'center',
|
|
213
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
214
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
215
|
+
borderRadius: 10,
|
|
216
|
+
boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
|
|
217
|
+
color: '#111827',
|
|
218
|
+
display: 'flex',
|
|
219
|
+
font: '600 13px/1.2 system-ui, sans-serif',
|
|
220
|
+
gap: 8,
|
|
221
|
+
left: 'max(12px, env(safe-area-inset-left))',
|
|
222
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
223
|
+
padding: '9px 11px',
|
|
224
|
+
position: 'fixed',
|
|
225
|
+
top: 'max(12px, env(safe-area-inset-top))',
|
|
226
|
+
zIndex: 2147483000
|
|
227
|
+
},
|
|
228
|
+
children: [
|
|
229
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
230
|
+
checked: enabled,
|
|
231
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
232
|
+
type: "checkbox"
|
|
233
|
+
}),
|
|
234
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
235
|
+
children: toggleLabel
|
|
236
|
+
})
|
|
237
|
+
]
|
|
238
|
+
}) : null,
|
|
239
|
+
enabled ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
240
|
+
"aria-hidden": "true",
|
|
241
|
+
children: boxes.map((box)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
242
|
+
"data-modern-boundary-overlay": "",
|
|
243
|
+
"data-modern-boundary-overlay-id": box.id,
|
|
244
|
+
"data-modern-boundary-overlay-label": box.label,
|
|
245
|
+
style: {
|
|
246
|
+
border: `2px solid ${box.color}`,
|
|
247
|
+
borderRadius: 8,
|
|
248
|
+
boxSizing: 'border-box',
|
|
249
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
250
|
+
height: box.height,
|
|
251
|
+
left: box.left,
|
|
252
|
+
pointerEvents: 'none',
|
|
253
|
+
position: 'fixed',
|
|
254
|
+
top: box.top,
|
|
255
|
+
width: box.width,
|
|
256
|
+
zIndex: 2147482999
|
|
257
|
+
},
|
|
258
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
|
|
259
|
+
style: {
|
|
260
|
+
background: box.color,
|
|
261
|
+
borderRadius: 999,
|
|
262
|
+
color: '#111827',
|
|
263
|
+
display: 'grid',
|
|
264
|
+
font: '800 11px/1.1 system-ui, sans-serif',
|
|
265
|
+
gap: 3,
|
|
266
|
+
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
267
|
+
padding: '5px 8px',
|
|
268
|
+
position: 'absolute',
|
|
269
|
+
right: 4,
|
|
270
|
+
top: 4,
|
|
271
|
+
whiteSpace: 'nowrap'
|
|
272
|
+
},
|
|
273
|
+
children: [
|
|
274
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
275
|
+
children: box.label
|
|
276
|
+
}),
|
|
277
|
+
void 0 !== box.detail && '' !== box.detail ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
278
|
+
style: {
|
|
279
|
+
font: '700 10px/1.1 system-ui, sans-serif',
|
|
280
|
+
opacity: 0.82,
|
|
281
|
+
overflow: 'hidden',
|
|
282
|
+
textOverflow: 'ellipsis'
|
|
283
|
+
},
|
|
284
|
+
children: box.detail
|
|
285
|
+
}) : null
|
|
286
|
+
]
|
|
287
|
+
})
|
|
288
|
+
}, box.id))
|
|
289
|
+
}) : null
|
|
290
|
+
]
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
294
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
295
|
+
setup: (api)=>{
|
|
296
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
297
|
+
children: [
|
|
298
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
299
|
+
...props
|
|
300
|
+
}),
|
|
301
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BoundaryDebugger, {
|
|
302
|
+
...options
|
|
303
|
+
})
|
|
304
|
+
]
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
309
|
+
exports["default"] = __webpack_exports__["default"];
|
|
310
|
+
exports.ultramodernBoundaryDebuggerPlugin = __webpack_exports__.ultramodernBoundaryDebuggerPlugin;
|
|
311
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
312
|
+
"default",
|
|
313
|
+
"ultramodernBoundaryDebuggerPlugin"
|
|
314
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
315
|
+
Object.defineProperty(exports, '__esModule', {
|
|
316
|
+
value: true
|
|
317
|
+
});
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
4
|
+
const queryParamName = 'modern-boundaries';
|
|
5
|
+
const boundarySelector = '[data-modern-boundary-id]';
|
|
6
|
+
const defaultLabels = {
|
|
7
|
+
cs: {
|
|
8
|
+
toggle: 'zobrazit hranice týmů'
|
|
9
|
+
},
|
|
10
|
+
en: {
|
|
11
|
+
toggle: 'show team boundaries'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const palette = [
|
|
15
|
+
'#ff5a5f',
|
|
16
|
+
'#30e27a',
|
|
17
|
+
'#f6cf45',
|
|
18
|
+
'#7c8cff',
|
|
19
|
+
'#29b6f6'
|
|
20
|
+
];
|
|
21
|
+
const readStoredEnabled = (storageKey, fallback)=>{
|
|
22
|
+
if ("u" < typeof window) return fallback;
|
|
23
|
+
try {
|
|
24
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
25
|
+
return null === stored ? fallback : 'true' === stored;
|
|
26
|
+
} catch {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
31
|
+
if ("u" < typeof window) return;
|
|
32
|
+
try {
|
|
33
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
34
|
+
} catch {}
|
|
35
|
+
};
|
|
36
|
+
const parseEnabledOverride = (value)=>{
|
|
37
|
+
if (null === value) return;
|
|
38
|
+
const normalized = value.toLowerCase();
|
|
39
|
+
if ('1' === normalized || 'true' === normalized) return true;
|
|
40
|
+
if ('0' === normalized || 'false' === normalized) return false;
|
|
41
|
+
};
|
|
42
|
+
const readQueryEnabledOverride = ()=>{
|
|
43
|
+
if ("u" < typeof window) return;
|
|
44
|
+
try {
|
|
45
|
+
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const detectLanguage = ()=>{
|
|
51
|
+
if ("u" < typeof document) return 'en';
|
|
52
|
+
const htmlLanguage = document.documentElement.lang;
|
|
53
|
+
if ('' !== htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
54
|
+
if ("u" < typeof window) return 'en';
|
|
55
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
56
|
+
};
|
|
57
|
+
const hashBoundaryId = (id)=>{
|
|
58
|
+
let hash = 0;
|
|
59
|
+
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
60
|
+
return hash;
|
|
61
|
+
};
|
|
62
|
+
const formatRectKey = (rect)=>[
|
|
63
|
+
Math.round(100 * rect.left) / 100,
|
|
64
|
+
Math.round(100 * rect.top) / 100,
|
|
65
|
+
Math.round(100 * rect.width) / 100,
|
|
66
|
+
Math.round(100 * rect.height) / 100
|
|
67
|
+
].join(':');
|
|
68
|
+
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
69
|
+
const collectBoundaryElements = (legacySelector)=>{
|
|
70
|
+
const elements = new Set();
|
|
71
|
+
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
72
|
+
if (void 0 === legacySelector || '' === legacySelector) return Array.from(elements);
|
|
73
|
+
try {
|
|
74
|
+
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
75
|
+
} catch {}
|
|
76
|
+
return Array.from(elements);
|
|
77
|
+
};
|
|
78
|
+
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
79
|
+
const [mounted, setMounted] = useState(false);
|
|
80
|
+
const [enabled, setEnabled] = useState(false);
|
|
81
|
+
const [boxes, setBoxes] = useState([]);
|
|
82
|
+
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
83
|
+
entry.mfName,
|
|
84
|
+
{
|
|
85
|
+
...entry,
|
|
86
|
+
color: entry.color ?? palette[index % palette.length],
|
|
87
|
+
label: entry.label ?? entry.appId
|
|
88
|
+
}
|
|
89
|
+
])), [
|
|
90
|
+
metadata
|
|
91
|
+
]);
|
|
92
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
93
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
94
|
+
useEffect(()=>{
|
|
95
|
+
setMounted(true);
|
|
96
|
+
const queryOverride = readQueryEnabledOverride();
|
|
97
|
+
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
98
|
+
}, [
|
|
99
|
+
enabledByDefault,
|
|
100
|
+
storageKey
|
|
101
|
+
]);
|
|
102
|
+
useEffect(()=>{
|
|
103
|
+
if (!mounted) return;
|
|
104
|
+
writeStoredEnabled(storageKey, enabled);
|
|
105
|
+
}, [
|
|
106
|
+
enabled,
|
|
107
|
+
mounted,
|
|
108
|
+
storageKey
|
|
109
|
+
]);
|
|
110
|
+
useEffect(()=>{
|
|
111
|
+
if (!enabled) return void setBoxes([]);
|
|
112
|
+
let resizeObserver;
|
|
113
|
+
const observedElements = new Set();
|
|
114
|
+
const observeBoundaryElements = (elements)=>{
|
|
115
|
+
if (void 0 === resizeObserver) return;
|
|
116
|
+
for (const element of elements)if (!observedElements.has(element)) {
|
|
117
|
+
observedElements.add(element);
|
|
118
|
+
resizeObserver.observe(element);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const readBoxes = ()=>{
|
|
122
|
+
const elements = collectBoundaryElements(legacySelector);
|
|
123
|
+
observeBoundaryElements(elements);
|
|
124
|
+
const seenBoxes = new Set();
|
|
125
|
+
const nextBoxes = elements.map((element)=>{
|
|
126
|
+
const boundaryId = getBoundaryId(element);
|
|
127
|
+
if (void 0 === boundaryId || '' === boundaryId) return;
|
|
128
|
+
const rect = element.getBoundingClientRect();
|
|
129
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
130
|
+
const rectKey = formatRectKey(rect);
|
|
131
|
+
const boxKey = `${boundaryId}:${rectKey}`;
|
|
132
|
+
if (seenBoxes.has(boxKey)) return;
|
|
133
|
+
seenBoxes.add(boxKey);
|
|
134
|
+
const boundary = boundaries.get(boundaryId);
|
|
135
|
+
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
136
|
+
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
137
|
+
const expose = element.dataset.modernMfExpose;
|
|
138
|
+
const detail = void 0 !== expose && '' !== expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
139
|
+
const box = {
|
|
140
|
+
color,
|
|
141
|
+
height: rect.height,
|
|
142
|
+
id: boxKey,
|
|
143
|
+
label,
|
|
144
|
+
left: rect.left,
|
|
145
|
+
top: rect.top,
|
|
146
|
+
width: rect.width
|
|
147
|
+
};
|
|
148
|
+
if (void 0 !== detail) box.detail = detail;
|
|
149
|
+
return box;
|
|
150
|
+
}).filter((box)=>void 0 !== box);
|
|
151
|
+
setBoxes(nextBoxes);
|
|
152
|
+
};
|
|
153
|
+
resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
154
|
+
readBoxes();
|
|
155
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
156
|
+
mutationObserver.observe(document.body, {
|
|
157
|
+
childList: true,
|
|
158
|
+
subtree: true
|
|
159
|
+
});
|
|
160
|
+
window.addEventListener('resize', readBoxes);
|
|
161
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
162
|
+
return ()=>{
|
|
163
|
+
mutationObserver.disconnect();
|
|
164
|
+
resizeObserver?.disconnect();
|
|
165
|
+
window.removeEventListener('resize', readBoxes);
|
|
166
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
167
|
+
};
|
|
168
|
+
}, [
|
|
169
|
+
boundaries,
|
|
170
|
+
enabled,
|
|
171
|
+
legacySelector
|
|
172
|
+
]);
|
|
173
|
+
if (!mounted) return null;
|
|
174
|
+
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
175
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
176
|
+
children: [
|
|
177
|
+
shouldRenderToggle ? /*#__PURE__*/ jsxs("label", {
|
|
178
|
+
style: {
|
|
179
|
+
alignItems: 'center',
|
|
180
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
181
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
182
|
+
borderRadius: 10,
|
|
183
|
+
boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
|
|
184
|
+
color: '#111827',
|
|
185
|
+
display: 'flex',
|
|
186
|
+
font: '600 13px/1.2 system-ui, sans-serif',
|
|
187
|
+
gap: 8,
|
|
188
|
+
left: 'max(12px, env(safe-area-inset-left))',
|
|
189
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
190
|
+
padding: '9px 11px',
|
|
191
|
+
position: 'fixed',
|
|
192
|
+
top: 'max(12px, env(safe-area-inset-top))',
|
|
193
|
+
zIndex: 2147483000
|
|
194
|
+
},
|
|
195
|
+
children: [
|
|
196
|
+
/*#__PURE__*/ jsx("input", {
|
|
197
|
+
checked: enabled,
|
|
198
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
199
|
+
type: "checkbox"
|
|
200
|
+
}),
|
|
201
|
+
/*#__PURE__*/ jsx("span", {
|
|
202
|
+
children: toggleLabel
|
|
203
|
+
})
|
|
204
|
+
]
|
|
205
|
+
}) : null,
|
|
206
|
+
enabled ? /*#__PURE__*/ jsx("div", {
|
|
207
|
+
"aria-hidden": "true",
|
|
208
|
+
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
209
|
+
"data-modern-boundary-overlay": "",
|
|
210
|
+
"data-modern-boundary-overlay-id": box.id,
|
|
211
|
+
"data-modern-boundary-overlay-label": box.label,
|
|
212
|
+
style: {
|
|
213
|
+
border: `2px solid ${box.color}`,
|
|
214
|
+
borderRadius: 8,
|
|
215
|
+
boxSizing: 'border-box',
|
|
216
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
217
|
+
height: box.height,
|
|
218
|
+
left: box.left,
|
|
219
|
+
pointerEvents: 'none',
|
|
220
|
+
position: 'fixed',
|
|
221
|
+
top: box.top,
|
|
222
|
+
width: box.width,
|
|
223
|
+
zIndex: 2147482999
|
|
224
|
+
},
|
|
225
|
+
children: /*#__PURE__*/ jsxs("span", {
|
|
226
|
+
style: {
|
|
227
|
+
background: box.color,
|
|
228
|
+
borderRadius: 999,
|
|
229
|
+
color: '#111827',
|
|
230
|
+
display: 'grid',
|
|
231
|
+
font: '800 11px/1.1 system-ui, sans-serif',
|
|
232
|
+
gap: 3,
|
|
233
|
+
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
234
|
+
padding: '5px 8px',
|
|
235
|
+
position: 'absolute',
|
|
236
|
+
right: 4,
|
|
237
|
+
top: 4,
|
|
238
|
+
whiteSpace: 'nowrap'
|
|
239
|
+
},
|
|
240
|
+
children: [
|
|
241
|
+
/*#__PURE__*/ jsx("span", {
|
|
242
|
+
children: box.label
|
|
243
|
+
}),
|
|
244
|
+
void 0 !== box.detail && '' !== box.detail ? /*#__PURE__*/ jsx("span", {
|
|
245
|
+
style: {
|
|
246
|
+
font: '700 10px/1.1 system-ui, sans-serif',
|
|
247
|
+
opacity: 0.82,
|
|
248
|
+
overflow: 'hidden',
|
|
249
|
+
textOverflow: 'ellipsis'
|
|
250
|
+
},
|
|
251
|
+
children: box.detail
|
|
252
|
+
}) : null
|
|
253
|
+
]
|
|
254
|
+
})
|
|
255
|
+
}, box.id))
|
|
256
|
+
}) : null
|
|
257
|
+
]
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
261
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
262
|
+
setup: (api)=>{
|
|
263
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
264
|
+
children: [
|
|
265
|
+
/*#__PURE__*/ jsx(App, {
|
|
266
|
+
...props
|
|
267
|
+
}),
|
|
268
|
+
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
269
|
+
...options
|
|
270
|
+
})
|
|
271
|
+
]
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
276
|
+
export default boundary_debugger;
|
|
277
|
+
export { ultramodernBoundaryDebuggerPlugin };
|