shinkom 1.1.0 → 1.1.2
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/README.md +0 -18
- package/dist/bundles/_virtual/_rolldown/runtime.js +14 -14
- package/dist/bundles/core/constants.d.ts +15 -15
- package/dist/bundles/core/constants.js +23 -23
- package/dist/bundles/core/elements/compat-view-element.d.ts +99 -99
- package/dist/bundles/core/elements/compat-view-element.js +440 -440
- package/dist/bundles/core/elements/control-panel-element.d.ts +44 -44
- package/dist/bundles/core/elements/control-panel-element.js +99 -99
- package/dist/bundles/core/elements/index.d.ts +12 -12
- package/dist/bundles/core/elements/index.js +13 -13
- package/dist/bundles/core/elements/inspector-element.d.ts +26 -26
- package/dist/bundles/core/elements/inspector-element.js +58 -58
- package/dist/bundles/core/elements/recent-result-item.js +46 -46
- package/dist/bundles/core/elements/results-history-item.js +46 -46
- package/dist/bundles/core/elements/templates/compat-view.templates.js +462 -462
- package/dist/bundles/core/elements/templates/control-panel.templates.js +335 -335
- package/dist/bundles/core/elements/templates/root-styles.template.js +40 -40
- package/dist/bundles/core/event-bus.d.ts +46 -46
- package/dist/bundles/core/event-bus.js +49 -49
- package/dist/bundles/core/helpers.js +47 -47
- package/dist/bundles/core/index.d.ts +14 -14
- package/dist/bundles/core/index.js +16 -16
- package/dist/bundles/core/state-service.d.ts +56 -56
- package/dist/bundles/core/state-service.js +91 -80
- package/dist/bundles/core/ui-component.d.ts +63 -63
- package/dist/bundles/core/ui-component.js +71 -71
- package/dist/bundles/engine/engine.d.ts +108 -108
- package/dist/bundles/engine/engine.js +238 -238
- package/dist/bundles/engine/index.js +8 -8
- package/dist/bundles/gen/index.js +14 -14
- package/dist/bundles/index.d.ts +19 -19
- package/dist/bundles/index.js +23 -23
- package/dist/bundles/pkg/shinkore.d.ts +40 -50
- package/dist/bundles/pkg/shinkore.js +465 -465
- package/dist/bundles/pkg/shinkore_bg.wasm +0 -0
- package/dist/bundles/shinkom.d.ts +41 -41
- package/dist/bundles/shinkom.js +80 -80
- package/dist/bundles/ui/compat-ui/compat-ui.d.ts +42 -42
- package/dist/bundles/ui/compat-ui/compat-ui.js +59 -59
- package/dist/bundles/ui/compat-ui/index.js +8 -8
- package/dist/bundles/ui/compatibility-view/compatibility-view.d.ts +41 -41
- package/dist/bundles/ui/compatibility-view/compatibility-view.js +229 -229
- package/dist/bundles/ui/compatibility-view/index.js +8 -8
- package/dist/bundles/ui/control-panel/control-panel.d.ts +52 -52
- package/dist/bundles/ui/control-panel/control-panel.js +320 -320
- package/dist/bundles/ui/control-panel/index.js +8 -8
- package/dist/bundles/ui/index.d.ts +11 -11
- package/dist/bundles/ui/index.js +16 -16
- package/dist/bundles/ui/inspector/index.js +8 -8
- package/dist/bundles/ui/inspector/inspector.d.ts +97 -97
- package/dist/bundles/ui/inspector/inspector.js +394 -394
- package/dist/modules/core/constants.cjs +17 -17
- package/dist/modules/core/elements/compat-view-element.cjs +434 -434
- package/dist/modules/core/elements/control-panel-element.cjs +93 -93
- package/dist/modules/core/elements/index.cjs +11 -11
- package/dist/modules/core/elements/inspector-element.cjs +52 -52
- package/dist/modules/core/elements/recent-result-item.cjs +39 -39
- package/dist/modules/core/elements/results-history-item.cjs +39 -39
- package/dist/modules/core/elements/templates/compat-view.templates.cjs +458 -458
- package/dist/modules/core/elements/templates/control-panel.templates.cjs +332 -332
- package/dist/modules/core/elements/templates/root-styles.template.cjs +33 -33
- package/dist/modules/core/event-bus.cjs +43 -43
- package/dist/modules/core/helpers.cjs +41 -41
- package/dist/modules/core/index.cjs +16 -16
- package/dist/modules/core/state-service.cjs +85 -74
- package/dist/modules/core/ui-component.cjs +65 -65
- package/dist/modules/engine/engine.cjs +232 -232
- package/dist/modules/gen/browser-data.cjs +100 -100
- package/dist/modules/gen/browser-usage-data.cjs +675 -675
- package/dist/modules/gen/compat-data.cjs +31015 -31015
- package/dist/modules/gen/index.cjs +7 -7
- package/dist/modules/index.cjs +27 -27
- package/dist/modules/pkg/shinkore.cjs +459 -459
- package/dist/modules/pkg/shinkore_bg.wasm +0 -0
- package/dist/modules/shinkom.cjs +73 -73
- package/dist/modules/ui/compat-ui/compat-ui.cjs +53 -53
- package/dist/modules/ui/compat-ui/index.cjs +1 -1
- package/dist/modules/ui/compatibility-view/compatibility-view.cjs +223 -223
- package/dist/modules/ui/compatibility-view/index.cjs +1 -1
- package/dist/modules/ui/control-panel/control-panel.cjs +314 -314
- package/dist/modules/ui/control-panel/index.cjs +1 -1
- package/dist/modules/ui/index.cjs +13 -13
- package/dist/modules/ui/inspector/index.cjs +1 -1
- package/dist/modules/ui/inspector/inspector.cjs +388 -388
- package/package.json +100 -100
|
@@ -1,394 +1,394 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shinkom - inspector
|
|
3
|
-
* @version 1.1.
|
|
4
|
-
* @license MIT
|
|
5
|
-
* @copyright 2026 - OneilNvM
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { UIComponent } from "../../core/ui-component.js";
|
|
9
|
-
import { CompatInspectorElement } from "../../core/elements/inspector-element.js";
|
|
10
|
-
import "../../core/elements/index.js";
|
|
11
|
-
import "../../core/index.js";
|
|
12
|
-
//#region src/ui/inspector/inspector.js
|
|
13
|
-
/**@typedef {import('../../types/public').UISharedState} UISharedState */
|
|
14
|
-
/**@typedef {import('../../types/public').InspectorConfig} InspectorConfig */
|
|
15
|
-
/**@typedef {import('../../types/public').UISharedStateProps} UISharedStateProps */
|
|
16
|
-
/**
|
|
17
|
-
* CompatInspector manages the interactive compatibility inspector overlay.
|
|
18
|
-
*
|
|
19
|
-
* It mounts the custom element `<sk-compat-inspector>`, synchronizes
|
|
20
|
-
* the overlay state with the shared UI state, and emits inspection
|
|
21
|
-
* requests through the Shinkom event bus.
|
|
22
|
-
*
|
|
23
|
-
* The inspector supports pointer tracking, element freezing, optional
|
|
24
|
-
* keyboard shortcuts, and soft mount/unmount flows that preserve or
|
|
25
|
-
* skip event bus bindings.
|
|
26
|
-
*
|
|
27
|
-
* @extends {UIComponent}
|
|
28
|
-
*/
|
|
29
|
-
var CompatInspector = class CompatInspector extends UIComponent {
|
|
30
|
-
/**@type {UISharedState | null} */
|
|
31
|
-
#stateBind = null;
|
|
32
|
-
#freezeInspector = false;
|
|
33
|
-
/**@type {AbortController | null} */
|
|
34
|
-
#inspectorController = null;
|
|
35
|
-
/**
|
|
36
|
-
* Initializes the compatibility inspector.
|
|
37
|
-
*
|
|
38
|
-
* It requires an instance of the `ShinkomBus` and `ShinkomState` to listen
|
|
39
|
-
* for event bus emits and state service notifications.
|
|
40
|
-
*
|
|
41
|
-
* It also registers the `<sk-compat-inspector>` custom element.
|
|
42
|
-
*
|
|
43
|
-
* It has an optional configuration object for disabling the inspector
|
|
44
|
-
* and toggling keyboard shortcuts.
|
|
45
|
-
*
|
|
46
|
-
* ### Keyboard Shortcuts
|
|
47
|
-
*
|
|
48
|
-
* - Create inspector: Ctrl + Alt + c
|
|
49
|
-
* - Reset inspector: Ctrl + Shift + |
|
|
50
|
-
* - Destroy inspector: Ctrl + Alt + \
|
|
51
|
-
* - Toggle element switching: Ctrl + \
|
|
52
|
-
*
|
|
53
|
-
* @param {ShinkomBus} bus
|
|
54
|
-
* @param {ShinkomState} stateService
|
|
55
|
-
* @param {InspectorConfig | undefined} config
|
|
56
|
-
*/
|
|
57
|
-
constructor(bus, stateService, config = void 0) {
|
|
58
|
-
super(bus, stateService);
|
|
59
|
-
CompatInspector.register();
|
|
60
|
-
/**@type {InspectorConfig | undefined} */
|
|
61
|
-
this.config = config;
|
|
62
|
-
/**@type {boolean} */
|
|
63
|
-
this.enableSwitching = false;
|
|
64
|
-
/**@type {CompatInspectorElement | null} */
|
|
65
|
-
this.inspectorEl = null;
|
|
66
|
-
/**@type {HTMLElement | null} */
|
|
67
|
-
this.frozenTarget = null;
|
|
68
|
-
/**@type {(() => void)[]} */
|
|
69
|
-
this.unsubEvents = [];
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Register custom elements to the CustomElementRegistry.
|
|
73
|
-
*/
|
|
74
|
-
static register() {
|
|
75
|
-
if ("customElements" in globalThis && !globalThis.customElements.get("sk-compat-inspector")) globalThis.customElements.define("sk-compat-inspector", CompatInspectorElement);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Registers event bus listeners for the inspector.
|
|
79
|
-
*/
|
|
80
|
-
#setupEventBusListeners() {
|
|
81
|
-
this.unsubEvents = [
|
|
82
|
-
this.bus.on("ci:toggle", () => {
|
|
83
|
-
if (this.#stateBind?.inspectorActive) this.#removeGlobalListeners();
|
|
84
|
-
else this.#setupGlobalListeners();
|
|
85
|
-
}),
|
|
86
|
-
this.bus.on("ci:create", () => {
|
|
87
|
-
this.mountSoft();
|
|
88
|
-
}),
|
|
89
|
-
this.bus.on("ci:reset", () => {
|
|
90
|
-
this.resetSoft();
|
|
91
|
-
}),
|
|
92
|
-
this.bus.on("ci:destroy", () => {
|
|
93
|
-
this.unmountSoft();
|
|
94
|
-
})
|
|
95
|
-
];
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Removes event bus listeners for the inspector.
|
|
99
|
-
*/
|
|
100
|
-
#cleanupEventBusListeners() {
|
|
101
|
-
this.unsubEvents.forEach((cleanup) => cleanup());
|
|
102
|
-
this.unsubEvents = [];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Handler responds to keyboard shortcuts.
|
|
106
|
-
* @param {KeyboardEvent} e
|
|
107
|
-
*/
|
|
108
|
-
#handleKeyboard = (e) => {
|
|
109
|
-
const ctrlDown = e.ctrlKey;
|
|
110
|
-
const shiftDown = e.shiftKey;
|
|
111
|
-
const altDown = e.altKey;
|
|
112
|
-
if (!this.inspectorEl && ctrlDown && altDown && e.key === "c") {
|
|
113
|
-
this.mountSoft();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (this.inspectorEl && ctrlDown && shiftDown && e.key === "|") {
|
|
117
|
-
this.resetSoft();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (this.inspectorEl && ctrlDown && altDown && e.key === "\\") {
|
|
121
|
-
this.unmountSoft();
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (ctrlDown && e.key === "\\") {
|
|
125
|
-
this.enableSwitching = !this.enableSwitching;
|
|
126
|
-
if (this.#stateBind) this.#stateBind.inspectorSwitching = this.enableSwitching;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Handler toggles inspector freezing on elements.
|
|
131
|
-
* @param {PointerEvent} e
|
|
132
|
-
*/
|
|
133
|
-
#handleToggleFreeze = (e) => {
|
|
134
|
-
if (e.composedPath().includes(this.#stateBind?.ignorePanelEl) || e.composedPath().includes(this.#stateBind?.ignoreCompatViewEl)) return;
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
e.stopPropagation();
|
|
137
|
-
if (!this.#freezeInspector) {
|
|
138
|
-
this.#freeze(e.target);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (this.#freezeInspector && e.target === this.frozenTarget) {
|
|
142
|
-
this.#unfreeze();
|
|
143
|
-
return;
|
|
144
|
-
} else this.#switch(e.target);
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Freezes inspector on selected target.
|
|
148
|
-
* @param {HTMLElement} target
|
|
149
|
-
*/
|
|
150
|
-
#freeze(target) {
|
|
151
|
-
if (!this.inspectorEl) return;
|
|
152
|
-
const { width, height, top, left } = target.getBoundingClientRect();
|
|
153
|
-
const scrollTop = window.scrollY;
|
|
154
|
-
const scrollLeft = window.scrollX;
|
|
155
|
-
this.#freezeInspector = true;
|
|
156
|
-
this.frozenTarget = target;
|
|
157
|
-
this.#inspect(this.frozenTarget.outerHTML);
|
|
158
|
-
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
159
|
-
width: `${width}px`,
|
|
160
|
-
height: `${height}px`,
|
|
161
|
-
transform: `translateX(${left + scrollLeft}px) translateY(${top + scrollTop}px)`,
|
|
162
|
-
backgroundColor: "rgba(255,0,0,.3)",
|
|
163
|
-
outlineColor: "rgb(255,0,0)"
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**@param {string} frozenTarget */
|
|
167
|
-
#inspect(frozenTarget) {
|
|
168
|
-
if (this.#stateBind) this.bus.emit("engine:inspect", { detail: {
|
|
169
|
-
elem: frozenTarget,
|
|
170
|
-
multiElements: this.#stateBind.multiElements,
|
|
171
|
-
depthLevel: this.#stateBind.depthLevel
|
|
172
|
-
} });
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Unfreezes inspector from selected element.
|
|
176
|
-
*/
|
|
177
|
-
#unfreeze() {
|
|
178
|
-
if (!this.inspectorEl) return;
|
|
179
|
-
this.#freezeInspector = false;
|
|
180
|
-
this.frozenTarget = null;
|
|
181
|
-
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
182
|
-
backgroundColor: "rgba(0,255,0,.3)",
|
|
183
|
-
outlineColor: "rgb(0,255,0)"
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Handler updates inspector to wrap target element.
|
|
188
|
-
* @param {PointerEvent} e
|
|
189
|
-
*/
|
|
190
|
-
#handlePointerOver = (e) => {
|
|
191
|
-
if (this.#freezeInspector) return;
|
|
192
|
-
try {
|
|
193
|
-
this.#update(e.target);
|
|
194
|
-
} catch (error) {
|
|
195
|
-
console.error(`Inspector pointerOver error: ${error}`);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Switches inspector to target a different element.
|
|
200
|
-
* @param {HTMLElement} target
|
|
201
|
-
*/
|
|
202
|
-
#switch(target) {
|
|
203
|
-
if (this.enableSwitching) {
|
|
204
|
-
this.#freezeInspector = true;
|
|
205
|
-
this.frozenTarget = target;
|
|
206
|
-
this.#inspect(this.frozenTarget.outerHTML);
|
|
207
|
-
try {
|
|
208
|
-
this.#update(target);
|
|
209
|
-
} catch (error) {
|
|
210
|
-
console.error(`Inspector switch error: ${error}`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Updates the position of the inspector when moving to a different element.
|
|
216
|
-
* @param {HTMLElement} target
|
|
217
|
-
*/
|
|
218
|
-
#update(target) {
|
|
219
|
-
if (!this.inspectorEl) throw new Error("Failed to update inspector position and size as it does not exist.");
|
|
220
|
-
const { width, height, top, left } = target.getBoundingClientRect();
|
|
221
|
-
const scrollTop = window.scrollY;
|
|
222
|
-
const scrollLeft = window.scrollX;
|
|
223
|
-
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
224
|
-
width: `${width}px`,
|
|
225
|
-
height: `${height}px`,
|
|
226
|
-
transform: `translateX(${left + scrollLeft}px) translateY(${top + scrollTop}px)`
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* @param {UISharedState} state
|
|
231
|
-
*/
|
|
232
|
-
bindState(state) {
|
|
233
|
-
if (!this.#stateBind) this.#stateBind = state;
|
|
234
|
-
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
235
|
-
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* @param {UISharedStateProps} prop
|
|
239
|
-
* @param {any} val
|
|
240
|
-
*/
|
|
241
|
-
onStateChange(prop, val) {
|
|
242
|
-
switch (prop) {
|
|
243
|
-
case "inspectorSwitching":
|
|
244
|
-
this.enableSwitching = val;
|
|
245
|
-
break;
|
|
246
|
-
default: break;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
mount() {
|
|
250
|
-
if (this.inspectorEl || this.config?.disabled || document.querySelector("sk-compat-inspector")) {
|
|
251
|
-
console.warn("Inspector is either disabled or already exists");
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
console.log("Creating inspector");
|
|
255
|
-
this.inspectorEl = document.createElement("sk-compat-inspector");
|
|
256
|
-
document.body.appendChild(this.inspectorEl);
|
|
257
|
-
this.#setupGlobalListeners();
|
|
258
|
-
this.#setupEventBusListeners();
|
|
259
|
-
if (this.#stateBind) {
|
|
260
|
-
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
261
|
-
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Mounts the inspector without setting up event bus listeners or state listeners.
|
|
266
|
-
*
|
|
267
|
-
* This is useful when the inspector should be rendered and tracked visually,
|
|
268
|
-
* but the surrounding application already manages bus events separately.
|
|
269
|
-
*
|
|
270
|
-
* **Only use this if you do not need to setup listeners.**
|
|
271
|
-
*/
|
|
272
|
-
mountSoft() {
|
|
273
|
-
if (this.inspectorEl || this.config?.disabled || document.querySelector("sk-compat-inspector")) {
|
|
274
|
-
console.warn("Inspector is either disabled or already exists");
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
console.log("Soft creating inspector");
|
|
278
|
-
this.inspectorEl = document.createElement("sk-compat-inspector");
|
|
279
|
-
document.body.appendChild(this.inspectorEl);
|
|
280
|
-
this.#setupGlobalListeners();
|
|
281
|
-
if (this.#stateBind) {
|
|
282
|
-
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
283
|
-
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Setup event listeners on `window` object.
|
|
288
|
-
*/
|
|
289
|
-
#setupGlobalListeners() {
|
|
290
|
-
if (!this.inspectorEl) {
|
|
291
|
-
console.warn("Cannot activate inspector as it does not exist.");
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
this.#inspectorController = new AbortController();
|
|
295
|
-
const { signal } = this.#inspectorController;
|
|
296
|
-
window.addEventListener("pointerover", this.#handlePointerOver, { signal });
|
|
297
|
-
window.addEventListener("click", this.#handleToggleFreeze, {
|
|
298
|
-
signal,
|
|
299
|
-
capture: true
|
|
300
|
-
});
|
|
301
|
-
if (this.config?.keyboardShortcuts) window.addEventListener("keydown", this.#handleKeyboard);
|
|
302
|
-
if (this.#stateBind) this.#stateBind.inspectorActive = true;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Remove event listeners on `window` object.
|
|
306
|
-
*/
|
|
307
|
-
#removeGlobalListeners() {
|
|
308
|
-
if (!this.inspectorEl) {
|
|
309
|
-
console.warn("Cannot deactivate inspector as it does not exist.");
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (this.#inspectorController) this.#inspectorController.abort();
|
|
313
|
-
this.#inspectorController = null;
|
|
314
|
-
if (this.#stateBind) this.#stateBind.inspectorActive = false;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Resets the inspector.
|
|
318
|
-
*/
|
|
319
|
-
reset() {
|
|
320
|
-
if (!this.inspectorEl || document.querySelector("sk-compat-inspector")) {
|
|
321
|
-
console.warn("Cannot reset inspector as it does not exist.");
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
console.log("Resetting inspector");
|
|
325
|
-
this.unmount();
|
|
326
|
-
this.mount();
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Resets the inspector using soft operations.
|
|
330
|
-
*/
|
|
331
|
-
resetSoft() {
|
|
332
|
-
if (!this.inspectorEl) {
|
|
333
|
-
console.warn("Cannot reset inspector as it does not exist.");
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
console.log("Soft resetting inspector");
|
|
337
|
-
this.unmountSoft();
|
|
338
|
-
this.mountSoft();
|
|
339
|
-
}
|
|
340
|
-
unmount() {
|
|
341
|
-
try {
|
|
342
|
-
if (!this.inspectorEl && this.unsubEvents.length === 0) {
|
|
343
|
-
console.warn("Cannot destroy inspector as it does not exist.");
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
console.log("Destroying inspector");
|
|
347
|
-
this.#resetInternalState();
|
|
348
|
-
this.inspectorEl?.remove();
|
|
349
|
-
this.inspectorEl = null;
|
|
350
|
-
this.#cleanupEventBusListeners();
|
|
351
|
-
} catch (error) {
|
|
352
|
-
console.error(`Inspector destroy error: ${error}`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Unmounts the inspector without cleaning up event bus listeners or state listeners.
|
|
357
|
-
*
|
|
358
|
-
* This preserves any active bus subscriptions when the visual overlay is
|
|
359
|
-
* temporarily removed.
|
|
360
|
-
*
|
|
361
|
-
* **Only use this if you still need the listeners after unmounting.**
|
|
362
|
-
*/
|
|
363
|
-
unmountSoft() {
|
|
364
|
-
try {
|
|
365
|
-
if (!this.inspectorEl) {
|
|
366
|
-
console.warn("Cannot destroy inspector as it does not exist.");
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
console.log("Soft destroying inspector");
|
|
370
|
-
this.#resetInternalState();
|
|
371
|
-
this.inspectorEl.remove();
|
|
372
|
-
this.inspectorEl = null;
|
|
373
|
-
} catch (error) {
|
|
374
|
-
console.error(`Inspector destroy error: ${error}`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Reset internal state of the instance and any related state
|
|
379
|
-
* in the `stateBind`.
|
|
380
|
-
*/
|
|
381
|
-
#resetInternalState() {
|
|
382
|
-
this.#removeGlobalListeners();
|
|
383
|
-
this.#freezeInspector = false;
|
|
384
|
-
this.enableSwitching = false;
|
|
385
|
-
this.frozenTarget = null;
|
|
386
|
-
if (this.#stateBind) {
|
|
387
|
-
this.#stateBind.inspectorActive = false;
|
|
388
|
-
this.#stateBind.inspectorExists = false;
|
|
389
|
-
this.#stateBind.inspectorSwitching = false;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
//#endregion
|
|
394
|
-
export { CompatInspector };
|
|
1
|
+
/**
|
|
2
|
+
* Shinkom - inspector
|
|
3
|
+
* @version 1.1.2
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - OneilNvM
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { UIComponent } from "../../core/ui-component.js";
|
|
9
|
+
import { CompatInspectorElement } from "../../core/elements/inspector-element.js";
|
|
10
|
+
import "../../core/elements/index.js";
|
|
11
|
+
import "../../core/index.js";
|
|
12
|
+
//#region src/ui/inspector/inspector.js
|
|
13
|
+
/**@typedef {import('../../types/public').UISharedState} UISharedState */
|
|
14
|
+
/**@typedef {import('../../types/public').InspectorConfig} InspectorConfig */
|
|
15
|
+
/**@typedef {import('../../types/public').UISharedStateProps} UISharedStateProps */
|
|
16
|
+
/**
|
|
17
|
+
* CompatInspector manages the interactive compatibility inspector overlay.
|
|
18
|
+
*
|
|
19
|
+
* It mounts the custom element `<sk-compat-inspector>`, synchronizes
|
|
20
|
+
* the overlay state with the shared UI state, and emits inspection
|
|
21
|
+
* requests through the Shinkom event bus.
|
|
22
|
+
*
|
|
23
|
+
* The inspector supports pointer tracking, element freezing, optional
|
|
24
|
+
* keyboard shortcuts, and soft mount/unmount flows that preserve or
|
|
25
|
+
* skip event bus bindings.
|
|
26
|
+
*
|
|
27
|
+
* @extends {UIComponent}
|
|
28
|
+
*/
|
|
29
|
+
var CompatInspector = class CompatInspector extends UIComponent {
|
|
30
|
+
/**@type {UISharedState | null} */
|
|
31
|
+
#stateBind = null;
|
|
32
|
+
#freezeInspector = false;
|
|
33
|
+
/**@type {AbortController | null} */
|
|
34
|
+
#inspectorController = null;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the compatibility inspector.
|
|
37
|
+
*
|
|
38
|
+
* It requires an instance of the `ShinkomBus` and `ShinkomState` to listen
|
|
39
|
+
* for event bus emits and state service notifications.
|
|
40
|
+
*
|
|
41
|
+
* It also registers the `<sk-compat-inspector>` custom element.
|
|
42
|
+
*
|
|
43
|
+
* It has an optional configuration object for disabling the inspector
|
|
44
|
+
* and toggling keyboard shortcuts.
|
|
45
|
+
*
|
|
46
|
+
* ### Keyboard Shortcuts
|
|
47
|
+
*
|
|
48
|
+
* - Create inspector: Ctrl + Alt + c
|
|
49
|
+
* - Reset inspector: Ctrl + Shift + |
|
|
50
|
+
* - Destroy inspector: Ctrl + Alt + \
|
|
51
|
+
* - Toggle element switching: Ctrl + \
|
|
52
|
+
*
|
|
53
|
+
* @param {ShinkomBus} bus
|
|
54
|
+
* @param {ShinkomState} stateService
|
|
55
|
+
* @param {InspectorConfig | undefined} config
|
|
56
|
+
*/
|
|
57
|
+
constructor(bus, stateService, config = void 0) {
|
|
58
|
+
super(bus, stateService);
|
|
59
|
+
CompatInspector.register();
|
|
60
|
+
/**@type {InspectorConfig | undefined} */
|
|
61
|
+
this.config = config;
|
|
62
|
+
/**@type {boolean} */
|
|
63
|
+
this.enableSwitching = false;
|
|
64
|
+
/**@type {CompatInspectorElement | null} */
|
|
65
|
+
this.inspectorEl = null;
|
|
66
|
+
/**@type {HTMLElement | null} */
|
|
67
|
+
this.frozenTarget = null;
|
|
68
|
+
/**@type {(() => void)[]} */
|
|
69
|
+
this.unsubEvents = [];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Register custom elements to the CustomElementRegistry.
|
|
73
|
+
*/
|
|
74
|
+
static register() {
|
|
75
|
+
if ("customElements" in globalThis && !globalThis.customElements.get("sk-compat-inspector")) globalThis.customElements.define("sk-compat-inspector", CompatInspectorElement);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers event bus listeners for the inspector.
|
|
79
|
+
*/
|
|
80
|
+
#setupEventBusListeners() {
|
|
81
|
+
this.unsubEvents = [
|
|
82
|
+
this.bus.on("ci:toggle", () => {
|
|
83
|
+
if (this.#stateBind?.inspectorActive) this.#removeGlobalListeners();
|
|
84
|
+
else this.#setupGlobalListeners();
|
|
85
|
+
}),
|
|
86
|
+
this.bus.on("ci:create", () => {
|
|
87
|
+
this.mountSoft();
|
|
88
|
+
}),
|
|
89
|
+
this.bus.on("ci:reset", () => {
|
|
90
|
+
this.resetSoft();
|
|
91
|
+
}),
|
|
92
|
+
this.bus.on("ci:destroy", () => {
|
|
93
|
+
this.unmountSoft();
|
|
94
|
+
})
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Removes event bus listeners for the inspector.
|
|
99
|
+
*/
|
|
100
|
+
#cleanupEventBusListeners() {
|
|
101
|
+
this.unsubEvents.forEach((cleanup) => cleanup());
|
|
102
|
+
this.unsubEvents = [];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Handler responds to keyboard shortcuts.
|
|
106
|
+
* @param {KeyboardEvent} e
|
|
107
|
+
*/
|
|
108
|
+
#handleKeyboard = (e) => {
|
|
109
|
+
const ctrlDown = e.ctrlKey;
|
|
110
|
+
const shiftDown = e.shiftKey;
|
|
111
|
+
const altDown = e.altKey;
|
|
112
|
+
if (!this.inspectorEl && ctrlDown && altDown && e.key === "c") {
|
|
113
|
+
this.mountSoft();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (this.inspectorEl && ctrlDown && shiftDown && e.key === "|") {
|
|
117
|
+
this.resetSoft();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (this.inspectorEl && ctrlDown && altDown && e.key === "\\") {
|
|
121
|
+
this.unmountSoft();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (ctrlDown && e.key === "\\") {
|
|
125
|
+
this.enableSwitching = !this.enableSwitching;
|
|
126
|
+
if (this.#stateBind) this.#stateBind.inspectorSwitching = this.enableSwitching;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Handler toggles inspector freezing on elements.
|
|
131
|
+
* @param {PointerEvent} e
|
|
132
|
+
*/
|
|
133
|
+
#handleToggleFreeze = (e) => {
|
|
134
|
+
if (e.composedPath().includes(this.#stateBind?.ignorePanelEl) || e.composedPath().includes(this.#stateBind?.ignoreCompatViewEl)) return;
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
e.stopPropagation();
|
|
137
|
+
if (!this.#freezeInspector) {
|
|
138
|
+
this.#freeze(e.target);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (this.#freezeInspector && e.target === this.frozenTarget) {
|
|
142
|
+
this.#unfreeze();
|
|
143
|
+
return;
|
|
144
|
+
} else this.#switch(e.target);
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Freezes inspector on selected target.
|
|
148
|
+
* @param {HTMLElement} target
|
|
149
|
+
*/
|
|
150
|
+
#freeze(target) {
|
|
151
|
+
if (!this.inspectorEl) return;
|
|
152
|
+
const { width, height, top, left } = target.getBoundingClientRect();
|
|
153
|
+
const scrollTop = window.scrollY;
|
|
154
|
+
const scrollLeft = window.scrollX;
|
|
155
|
+
this.#freezeInspector = true;
|
|
156
|
+
this.frozenTarget = target;
|
|
157
|
+
this.#inspect(this.frozenTarget.outerHTML);
|
|
158
|
+
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
159
|
+
width: `${width}px`,
|
|
160
|
+
height: `${height}px`,
|
|
161
|
+
transform: `translateX(${left + scrollLeft}px) translateY(${top + scrollTop}px)`,
|
|
162
|
+
backgroundColor: "rgba(255,0,0,.3)",
|
|
163
|
+
outlineColor: "rgb(255,0,0)"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**@param {string} frozenTarget */
|
|
167
|
+
#inspect(frozenTarget) {
|
|
168
|
+
if (this.#stateBind) this.bus.emit("engine:inspect", { detail: {
|
|
169
|
+
elem: frozenTarget,
|
|
170
|
+
multiElements: this.#stateBind.multiElements,
|
|
171
|
+
depthLevel: this.#stateBind.depthLevel
|
|
172
|
+
} });
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Unfreezes inspector from selected element.
|
|
176
|
+
*/
|
|
177
|
+
#unfreeze() {
|
|
178
|
+
if (!this.inspectorEl) return;
|
|
179
|
+
this.#freezeInspector = false;
|
|
180
|
+
this.frozenTarget = null;
|
|
181
|
+
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
182
|
+
backgroundColor: "rgba(0,255,0,.3)",
|
|
183
|
+
outlineColor: "rgb(0,255,0)"
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Handler updates inspector to wrap target element.
|
|
188
|
+
* @param {PointerEvent} e
|
|
189
|
+
*/
|
|
190
|
+
#handlePointerOver = (e) => {
|
|
191
|
+
if (this.#freezeInspector) return;
|
|
192
|
+
try {
|
|
193
|
+
this.#update(e.target);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error(`Inspector pointerOver error: ${error}`);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Switches inspector to target a different element.
|
|
200
|
+
* @param {HTMLElement} target
|
|
201
|
+
*/
|
|
202
|
+
#switch(target) {
|
|
203
|
+
if (this.enableSwitching) {
|
|
204
|
+
this.#freezeInspector = true;
|
|
205
|
+
this.frozenTarget = target;
|
|
206
|
+
this.#inspect(this.frozenTarget.outerHTML);
|
|
207
|
+
try {
|
|
208
|
+
this.#update(target);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error(`Inspector switch error: ${error}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Updates the position of the inspector when moving to a different element.
|
|
216
|
+
* @param {HTMLElement} target
|
|
217
|
+
*/
|
|
218
|
+
#update(target) {
|
|
219
|
+
if (!this.inspectorEl) throw new Error("Failed to update inspector position and size as it does not exist.");
|
|
220
|
+
const { width, height, top, left } = target.getBoundingClientRect();
|
|
221
|
+
const scrollTop = window.scrollY;
|
|
222
|
+
const scrollLeft = window.scrollX;
|
|
223
|
+
Object.assign(this.inspectorEl.shadowHost.style, {
|
|
224
|
+
width: `${width}px`,
|
|
225
|
+
height: `${height}px`,
|
|
226
|
+
transform: `translateX(${left + scrollLeft}px) translateY(${top + scrollTop}px)`
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @param {UISharedState} state
|
|
231
|
+
*/
|
|
232
|
+
bindState(state) {
|
|
233
|
+
if (!this.#stateBind) this.#stateBind = state;
|
|
234
|
+
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
235
|
+
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @param {UISharedStateProps} prop
|
|
239
|
+
* @param {any} val
|
|
240
|
+
*/
|
|
241
|
+
onStateChange(prop, val) {
|
|
242
|
+
switch (prop) {
|
|
243
|
+
case "inspectorSwitching":
|
|
244
|
+
this.enableSwitching = val;
|
|
245
|
+
break;
|
|
246
|
+
default: break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
mount() {
|
|
250
|
+
if (this.inspectorEl || this.config?.disabled || document.querySelector("sk-compat-inspector")) {
|
|
251
|
+
console.warn("Inspector is either disabled or already exists");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.log("Creating inspector");
|
|
255
|
+
this.inspectorEl = document.createElement("sk-compat-inspector");
|
|
256
|
+
document.body.appendChild(this.inspectorEl);
|
|
257
|
+
this.#setupGlobalListeners();
|
|
258
|
+
this.#setupEventBusListeners();
|
|
259
|
+
if (this.#stateBind) {
|
|
260
|
+
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
261
|
+
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Mounts the inspector without setting up event bus listeners or state listeners.
|
|
266
|
+
*
|
|
267
|
+
* This is useful when the inspector should be rendered and tracked visually,
|
|
268
|
+
* but the surrounding application already manages bus events separately.
|
|
269
|
+
*
|
|
270
|
+
* **Only use this if you do not need to setup listeners.**
|
|
271
|
+
*/
|
|
272
|
+
mountSoft() {
|
|
273
|
+
if (this.inspectorEl || this.config?.disabled || document.querySelector("sk-compat-inspector")) {
|
|
274
|
+
console.warn("Inspector is either disabled or already exists");
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
console.log("Soft creating inspector");
|
|
278
|
+
this.inspectorEl = document.createElement("sk-compat-inspector");
|
|
279
|
+
document.body.appendChild(this.inspectorEl);
|
|
280
|
+
this.#setupGlobalListeners();
|
|
281
|
+
if (this.#stateBind) {
|
|
282
|
+
this.#stateBind.inspectorActive = this.inspectorEl !== null;
|
|
283
|
+
this.#stateBind.inspectorExists = this.inspectorEl !== null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Setup event listeners on `window` object.
|
|
288
|
+
*/
|
|
289
|
+
#setupGlobalListeners() {
|
|
290
|
+
if (!this.inspectorEl) {
|
|
291
|
+
console.warn("Cannot activate inspector as it does not exist.");
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.#inspectorController = new AbortController();
|
|
295
|
+
const { signal } = this.#inspectorController;
|
|
296
|
+
window.addEventListener("pointerover", this.#handlePointerOver, { signal });
|
|
297
|
+
window.addEventListener("click", this.#handleToggleFreeze, {
|
|
298
|
+
signal,
|
|
299
|
+
capture: true
|
|
300
|
+
});
|
|
301
|
+
if (this.config?.keyboardShortcuts) window.addEventListener("keydown", this.#handleKeyboard);
|
|
302
|
+
if (this.#stateBind) this.#stateBind.inspectorActive = true;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Remove event listeners on `window` object.
|
|
306
|
+
*/
|
|
307
|
+
#removeGlobalListeners() {
|
|
308
|
+
if (!this.inspectorEl) {
|
|
309
|
+
console.warn("Cannot deactivate inspector as it does not exist.");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (this.#inspectorController) this.#inspectorController.abort();
|
|
313
|
+
this.#inspectorController = null;
|
|
314
|
+
if (this.#stateBind) this.#stateBind.inspectorActive = false;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Resets the inspector.
|
|
318
|
+
*/
|
|
319
|
+
reset() {
|
|
320
|
+
if (!this.inspectorEl || document.querySelector("sk-compat-inspector")) {
|
|
321
|
+
console.warn("Cannot reset inspector as it does not exist.");
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
console.log("Resetting inspector");
|
|
325
|
+
this.unmount();
|
|
326
|
+
this.mount();
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Resets the inspector using soft operations.
|
|
330
|
+
*/
|
|
331
|
+
resetSoft() {
|
|
332
|
+
if (!this.inspectorEl) {
|
|
333
|
+
console.warn("Cannot reset inspector as it does not exist.");
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
console.log("Soft resetting inspector");
|
|
337
|
+
this.unmountSoft();
|
|
338
|
+
this.mountSoft();
|
|
339
|
+
}
|
|
340
|
+
unmount() {
|
|
341
|
+
try {
|
|
342
|
+
if (!this.inspectorEl && this.unsubEvents.length === 0) {
|
|
343
|
+
console.warn("Cannot destroy inspector as it does not exist.");
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
console.log("Destroying inspector");
|
|
347
|
+
this.#resetInternalState();
|
|
348
|
+
this.inspectorEl?.remove();
|
|
349
|
+
this.inspectorEl = null;
|
|
350
|
+
this.#cleanupEventBusListeners();
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.error(`Inspector destroy error: ${error}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Unmounts the inspector without cleaning up event bus listeners or state listeners.
|
|
357
|
+
*
|
|
358
|
+
* This preserves any active bus subscriptions when the visual overlay is
|
|
359
|
+
* temporarily removed.
|
|
360
|
+
*
|
|
361
|
+
* **Only use this if you still need the listeners after unmounting.**
|
|
362
|
+
*/
|
|
363
|
+
unmountSoft() {
|
|
364
|
+
try {
|
|
365
|
+
if (!this.inspectorEl) {
|
|
366
|
+
console.warn("Cannot destroy inspector as it does not exist.");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
console.log("Soft destroying inspector");
|
|
370
|
+
this.#resetInternalState();
|
|
371
|
+
this.inspectorEl.remove();
|
|
372
|
+
this.inspectorEl = null;
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error(`Inspector destroy error: ${error}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Reset internal state of the instance and any related state
|
|
379
|
+
* in the `stateBind`.
|
|
380
|
+
*/
|
|
381
|
+
#resetInternalState() {
|
|
382
|
+
this.#removeGlobalListeners();
|
|
383
|
+
this.#freezeInspector = false;
|
|
384
|
+
this.enableSwitching = false;
|
|
385
|
+
this.frozenTarget = null;
|
|
386
|
+
if (this.#stateBind) {
|
|
387
|
+
this.#stateBind.inspectorActive = false;
|
|
388
|
+
this.#stateBind.inspectorExists = false;
|
|
389
|
+
this.#stateBind.inspectorSwitching = false;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
//#endregion
|
|
394
|
+
export { CompatInspector };
|