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