shinkom 1.0.3 → 1.1.1

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 (90) hide show
  1. package/README.md +3 -2
  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 -20
  5. package/dist/bundles/core/elements/compat-view-element.d.ts +100 -0
  6. package/dist/bundles/core/elements/compat-view-element.js +440 -0
  7. package/dist/bundles/core/elements/control-panel-element.d.ts +45 -0
  8. package/dist/bundles/core/elements/control-panel-element.js +99 -0
  9. package/dist/bundles/core/elements/index.d.ts +13 -0
  10. package/dist/bundles/core/elements/index.js +13 -0
  11. package/dist/bundles/core/elements/inspector-element.d.ts +27 -0
  12. package/dist/bundles/core/elements/inspector-element.js +58 -0
  13. package/dist/bundles/core/elements/recent-result-item.js +46 -0
  14. package/dist/bundles/core/elements/results-history-item.js +46 -0
  15. package/dist/bundles/core/elements/templates/compat-view.templates.js +462 -0
  16. package/dist/bundles/core/elements/templates/control-panel.templates.js +335 -0
  17. package/dist/bundles/core/elements/templates/root-styles.template.js +40 -0
  18. package/dist/bundles/core/event-bus.d.ts +46 -32
  19. package/dist/bundles/core/event-bus.js +49 -36
  20. package/dist/bundles/core/helpers.js +47 -25
  21. package/dist/bundles/core/index.d.ts +15 -12
  22. package/dist/bundles/core/index.js +16 -12
  23. package/dist/bundles/core/state-service.d.ts +56 -36
  24. package/dist/bundles/core/state-service.js +80 -60
  25. package/dist/bundles/core/ui-component.d.ts +63 -44
  26. package/dist/bundles/core/ui-component.js +71 -52
  27. package/dist/bundles/engine/engine.d.ts +108 -60
  28. package/dist/bundles/engine/engine.js +238 -154
  29. package/dist/bundles/engine/index.js +8 -8
  30. package/dist/bundles/gen/browser-data.js +96 -96
  31. package/dist/bundles/gen/browser-usage-data.js +671 -671
  32. package/dist/bundles/gen/index.js +14 -14
  33. package/dist/bundles/index.d.ts +20 -16
  34. package/dist/bundles/index.js +23 -17
  35. package/dist/bundles/pkg/shinkore.d.ts +50 -50
  36. package/dist/bundles/pkg/shinkore.js +465 -465
  37. package/dist/bundles/pkg/shinkore_bg.wasm +0 -0
  38. package/dist/bundles/shinkom.d.ts +41 -33
  39. package/dist/bundles/shinkom.js +80 -55
  40. package/dist/bundles/types/public.d.ts +13 -29
  41. package/dist/bundles/types/types.d.ts +99 -0
  42. package/dist/bundles/ui/compat-ui/compat-ui.d.ts +43 -33
  43. package/dist/bundles/ui/compat-ui/compat-ui.js +59 -49
  44. package/dist/bundles/ui/compat-ui/index.js +8 -0
  45. package/dist/bundles/ui/compatibility-view/compatibility-view.d.ts +42 -0
  46. package/dist/bundles/ui/compatibility-view/compatibility-view.js +229 -0
  47. package/dist/bundles/ui/compatibility-view/index.js +8 -0
  48. package/dist/bundles/ui/control-panel/control-panel.d.ts +52 -38
  49. package/dist/bundles/ui/control-panel/control-panel.js +320 -409
  50. package/dist/bundles/ui/control-panel/index.js +8 -0
  51. package/dist/bundles/ui/index.d.ts +12 -11
  52. package/dist/bundles/ui/index.js +16 -11
  53. package/dist/bundles/ui/inspector/index.js +8 -0
  54. package/dist/bundles/ui/inspector/inspector.d.ts +97 -43
  55. package/dist/bundles/ui/inspector/inspector.js +394 -314
  56. package/dist/modules/core/constants.cjs +17 -1
  57. package/dist/modules/core/elements/compat-view-element.cjs +434 -0
  58. package/dist/modules/core/elements/control-panel-element.cjs +93 -0
  59. package/dist/modules/core/elements/index.cjs +11 -0
  60. package/dist/modules/core/elements/inspector-element.cjs +52 -0
  61. package/dist/modules/core/elements/recent-result-item.cjs +39 -0
  62. package/dist/modules/core/elements/results-history-item.cjs +39 -0
  63. package/dist/modules/core/elements/templates/compat-view.templates.cjs +458 -0
  64. package/dist/modules/core/elements/templates/control-panel.templates.cjs +332 -0
  65. package/dist/modules/core/elements/templates/root-styles.template.cjs +33 -0
  66. package/dist/modules/core/event-bus.cjs +43 -1
  67. package/dist/modules/core/helpers.cjs +41 -1
  68. package/dist/modules/core/index.cjs +16 -1
  69. package/dist/modules/core/state-service.cjs +74 -1
  70. package/dist/modules/core/ui-component.cjs +65 -1
  71. package/dist/modules/engine/engine.cjs +232 -1
  72. package/dist/modules/gen/browser-data.cjs +100 -1
  73. package/dist/modules/gen/browser-usage-data.cjs +675 -1
  74. package/dist/modules/gen/compat-data.cjs +31015 -1
  75. package/dist/modules/gen/index.cjs +7 -1
  76. package/dist/modules/index.cjs +27 -1
  77. package/dist/modules/pkg/shinkore.cjs +459 -1
  78. package/dist/modules/pkg/shinkore_bg.wasm +0 -0
  79. package/dist/modules/shinkom.cjs +73 -1
  80. package/dist/modules/ui/compat-ui/compat-ui.cjs +53 -1
  81. package/dist/modules/ui/compat-ui/index.cjs +1 -0
  82. package/dist/modules/ui/compatibility-view/compatibility-view.cjs +223 -0
  83. package/dist/modules/ui/compatibility-view/index.cjs +1 -0
  84. package/dist/modules/ui/control-panel/control-panel.cjs +314 -182
  85. package/dist/modules/ui/control-panel/index.cjs +1 -0
  86. package/dist/modules/ui/index.cjs +13 -1
  87. package/dist/modules/ui/inspector/index.cjs +1 -0
  88. package/dist/modules/ui/inspector/inspector.cjs +388 -1
  89. package/package.json +13 -6
  90. package/dist/bundles/node_modules/@mdn/browser-compat-data/types.d.ts +0 -78
@@ -1,409 +1,320 @@
1
- /**
2
- * Shinkom - control-panel
3
- * @version 1.0.3
4
- * @license MIT
5
- * @copyright 2026 - OneilNvM
6
- */
7
-
8
- import { UIComponent } from "../../core/ui-component.js";
9
- //#region src/ui/control-panel/control-panel.js
10
- /**@typedef {import('../../types/public').UISharedState} UISharedState */
11
- /**@typedef {import('../../types/public').UISharedStateProps} UISharedStateProps */
12
- /**@extends {UIComponent} */
13
- var CompatControlPanel = class extends UIComponent {
14
- /**@type {UISharedState | null} */
15
- #stateBind = null;
16
- /**@type {AbortController | null} */
17
- #panelController = null;
18
- /**
19
- * @param {ShinkomBus} bus
20
- * @param {ShinkomState} stateService
21
- */
22
- constructor(bus, stateService) {
23
- super(bus, stateService);
24
- /**@type {HTMLDivElement | null} */
25
- this.shadowHost = null;
26
- /**@type {ShadowRoot | null} */
27
- this.shadowRoot = null;
28
- /**@type {HTMLInputElement | null} */
29
- this.depthLevelInput = null;
30
- /**@type {HTMLParagraphElement | null} */
31
- this.ciStatusEl = null;
32
- /**@type {HTMLButtonElement | null} */
33
- this.toggleSwitchingEl = null;
34
- /**@type {HTMLButtonElement | null} */
35
- this.toggleInspectorEl = null;
36
- /**@type {number} */
37
- this.depthLevel = 0;
38
- /**@type {boolean} */
39
- this.multiElements = false;
40
- stateService.subscribe((prop, val) => {
41
- this.onStateChange(prop, val);
42
- });
43
- }
44
- /**
45
- * Applies inline styles to `shadowHost` element.
46
- */
47
- #applyHostStyles() {
48
- if (this.shadowHost) Object.assign(this.shadowHost.style, {
49
- position: "fixed",
50
- top: "2rem",
51
- left: "2rem",
52
- zIndex: "9999"
53
- });
54
- else throw new Error("Shadow host is undefined or null.");
55
- }
56
- /**
57
- * Creates the control panel in a shadow root.
58
- */
59
- createPanel() {
60
- if (this.shadowHost) {
61
- console.warn("Shadow host already exists.");
62
- return;
63
- }
64
- this.shadowHost = document.createElement("div");
65
- this.shadowHost.id = "sk-shadow-host";
66
- try {
67
- this.#applyHostStyles();
68
- } catch (error) {
69
- this.shadowHost = null;
70
- throw error;
71
- }
72
- document.body.appendChild(this.shadowHost);
73
- this.shadowRoot = this.shadowHost.attachShadow({ mode: "open" });
74
- this.shadowRoot.innerHTML = `
75
- <style>
76
- .sk-control-panel {
77
- display: flex;
78
- flex-direction: column;
79
- justify-content: space-evenly;
80
- width: 30rem;
81
- height: 85lvh;
82
- padding: 1rem;
83
- background-color: #0f0c13;
84
- color: white;
85
- font-family: Arial, Helvetica, sans-serif;
86
- border-radius: 2rem;
87
- z-index: 2;
88
- }
89
-
90
- .sk-control-panel * {
91
- transition-property: color, background-color, border-color;
92
- transition-duration: 300ms;
93
- transition-timing-function: ease-in-out;
94
- }
95
-
96
- .sk-page-buttons {
97
- display: flex;
98
- flex-direction: column;
99
- justify-content: center;
100
- align-items: center;
101
- gap: .75rem;
102
- flex: 1 1 0%;
103
- }
104
-
105
- .sk-button-style {
106
- font-size: 1.225rem;
107
- color: white;
108
- background-color: #201a27;
109
- border: 1px solid #3c00c7;
110
- border-radius: .5rem;
111
- padding-inline: .5rem;
112
- padding-block: .3rem;
113
- cursor: pointer;
114
- }
115
-
116
- .sk-hr-line {
117
- width: 100%;
118
- border: 0px solid transparent;
119
- border-top: 1px solid #8132ff;
120
- }
121
-
122
- .sk-full-page-inspect {
123
- display: flex;
124
- align-items: center;
125
- justify-content: space-evenly;
126
- font-size: 1.8rem;
127
- flex: 0.5 1 0%;
128
- }
129
-
130
- .sk-options-container {
131
- display: flex;
132
- flex-direction: column;
133
- gap: .5rem;
134
- padding-top: 1rem;
135
- padding-inline: 1rem;
136
- flex: 5 1 0%;
137
- font-size: 1.25rem;
138
- }
139
-
140
- .sk-options-header {
141
- display: flex;
142
- align-items: center;
143
- justify-content: space-between;
144
- font-size: 1.5rem;
145
- }
146
-
147
- .sk-options-header p:last-child {
148
- font-size: 1rem;
149
- }
150
-
151
- .sk-options {
152
- display: flex;
153
- flex-direction: column;
154
- justify-content: space-evenly;
155
- height: 100%;
156
- padding-left: .05rem;
157
- }
158
-
159
- .sk-options-grid {
160
- display: grid;
161
- grid-template-columns: auto auto auto;
162
- grid-template-rows: auto;
163
- justify-items: flex-start;
164
- align-items: center;
165
- }
166
-
167
- .sk-options-grid:first-child {
168
- column-gap: .5rem;
169
- }
170
-
171
- .sk-options-grid .sk-button-style {
172
- justify-self: flex-end;
173
- }
174
-
175
- .sk-options-grid .sk-options-input {
176
- justify-self: flex-end;
177
- }
178
-
179
- .sk-options-grid .sk-options-input:disabled {
180
- opacity: .5;
181
- }
182
-
183
- .sk-options-grid:nth-last-of-type(2), .sk-options-grid:nth-last-of-type(1) {
184
- grid-template-columns: auto auto;
185
- }
186
-
187
- .sk-options-input {
188
- width: 70%;
189
- padding-block: .2rem;
190
- padding-inline: .3rem;
191
- border-radius: .25rem;
192
- border: none;
193
- background-color: #232333;
194
- font-size: 1rem;
195
- color: white;
196
- }
197
- .sk-close {
198
- display: flex;
199
- flex-direction: column;
200
- justify-content: center;
201
- flex: 1 1 0%;
202
- }
203
- .sk-show-panel {
204
- width: 8rem;
205
- position: absolute;
206
- top: 1rem;
207
- left: 1rem;
208
- z-index: -1;
209
- }
210
- </style>
211
- <div style="position: relative">
212
- <button id="sk-show-panel" class="sk-button-style sk-show-panel">Show Panel</button>
213
- <div id="sk-control-panel" class="sk-control-panel" style="display: none;">
214
- <div class="sk-page-buttons">
215
- <button class="sk-button-style">Inspector</button>
216
- <button class="sk-button-style">Compatibility View</button>
217
- </div>
218
- <hr class="sk-hr-line">
219
- <div class="sk-full-page-inspect">
220
- <p>Inspect Full Page</p>
221
- <button id="sk-full-inspect" class="sk-button-style">Inspect</button>
222
- </div>
223
- <hr class="sk-hr-line">
224
- <div class="sk-options-container">
225
- <div class="sk-options-header">
226
- <p>Inspector Options</p>
227
- <p id="sk-inspector-status">Inspector Status: Active</p>
228
- </div>
229
- <div class="sk-options">
230
- <div class="sk-options-grid">
231
- <p>Inspect multiple elements</p>
232
- <input id="sk-toggle-elements" class="sk-options-checkbox" type="checkbox">
233
- <input id="sk-depth-level" class="sk-options-input" type="text" placeholder="depth_level" disabled>
234
- </div>
235
- <div class="sk-options-grid">
236
- <p>Toggle Switching</p>
237
- <button id="sk-toggle-switching" class="sk-button-style">Disabled</button>
238
- </div>
239
- <div class="sk-options-grid">
240
- <p>Toggle Inspector</p>
241
- <button id="sk-toggle-inspector" class="sk-button-style">Active</button>
242
- </div>
243
- <button id="sk-create-inspector" class="sk-button-style">Create Inspector</button>
244
- <button id="sk-reset-inspector" class="sk-button-style">Reset Inspector</button>
245
- <button id="sk-destroy-inspector" class="sk-button-style">Destroy Inspector</button>
246
- </div>
247
- </div>
248
- <hr class="sk-hr-line">
249
- <div class="sk-close">
250
- <button id="sk-close-panel" class="sk-button-style">Close</button>
251
- </div>
252
- <hr class="sk-hr-line">
253
- </div>
254
- </div>
255
- `;
256
- }
257
- /**
258
- * @param {UISharedState} state
259
- */
260
- bindState(state) {
261
- if (!this.#stateBind) this.#stateBind = state;
262
- this.#stateBind.ignorePanelEl = this.shadowHost;
263
- }
264
- /**
265
- * @param {UISharedStateProps} prop
266
- * @param {any} val
267
- */
268
- onStateChange(prop, val) {
269
- switch (prop) {
270
- case "inspectorSwitching":
271
- if (this.toggleSwitchingEl) this.toggleSwitchingEl.innerHTML = val ? "Enabled" : "Disabled";
272
- break;
273
- case "inspectorActive":
274
- if (this.toggleInspectorEl) this.toggleInspectorEl.innerHTML = val ? "Active" : "Deactive";
275
- if (this.ciStatusEl) this.ciStatusEl.innerHTML = val ? "Inspector Status: Active" : "Inspector Status: Deactive";
276
- break;
277
- default: break;
278
- }
279
- }
280
- mount() {
281
- try {
282
- this.createPanel();
283
- } catch (error) {
284
- throw error;
285
- }
286
- this.#setupShadowListeners();
287
- }
288
- /**
289
- * Setup event listeners on `shadowRoot` element.
290
- */
291
- #setupShadowListeners() {
292
- this.#panelController = new AbortController();
293
- const { signal } = this.#panelController;
294
- const toggleInspector = this.shadowRoot?.getElementById("sk-toggle-inspector");
295
- const toggleSwitching = this.shadowRoot?.getElementById("sk-toggle-switching");
296
- const createInspector = this.shadowRoot?.getElementById("sk-create-inspector");
297
- const resetInspector = this.shadowRoot?.getElementById("sk-reset-inspector");
298
- const destroyInspector = this.shadowRoot?.getElementById("sk-destroy-inspector");
299
- const showButton = this.shadowRoot?.getElementById("sk-show-panel");
300
- const closeButton = this.shadowRoot?.getElementById("sk-close-panel");
301
- const toggleElements = this.shadowRoot?.getElementById("sk-toggle-elements");
302
- const depthLevelInput = this.shadowRoot?.getElementById("sk-depth-level");
303
- const fullInspectButton = this.shadowRoot?.getElementById("sk-full-inspect");
304
- const ciStatusEl = this.shadowRoot?.getElementById("sk-inspector-status");
305
- toggleInspector?.addEventListener("click", this.#handleToggleClick, { signal });
306
- toggleSwitching?.addEventListener("click", this.#handleToggleClick, { signal });
307
- createInspector?.addEventListener("click", this.#handleToggleClick, { signal });
308
- resetInspector?.addEventListener("click", this.#handleToggleClick, { signal });
309
- destroyInspector?.addEventListener("click", this.#handleToggleClick, { signal });
310
- showButton?.addEventListener("click", this.#handleToggleClick, { signal });
311
- closeButton?.addEventListener("click", this.#handleToggleClick, { signal });
312
- toggleElements?.addEventListener("click", this.#handleToggleClick, { signal });
313
- depthLevelInput?.addEventListener("change", this.#handleDepthLevelValue, { signal });
314
- fullInspectButton?.addEventListener("click", this.#handleToggleClick, { signal });
315
- if (depthLevelInput) this.depthLevelInput = depthLevelInput;
316
- if (toggleInspector) this.toggleInspectorEl = toggleInspector;
317
- if (toggleSwitching) this.toggleSwitchingEl = toggleSwitching;
318
- if (ciStatusEl) this.ciStatusEl = ciStatusEl;
319
- }
320
- unmount() {
321
- try {
322
- if (!this.shadowHost) return;
323
- this.shadowHost.remove();
324
- this.shadowHost = null;
325
- this.#resetInternalState();
326
- } catch (error) {
327
- console.error(`Control panel destroy error: ${error}`);
328
- }
329
- }
330
- /**
331
- * Reset internal state of the instance and any related state
332
- * in the `stateBind`.
333
- */
334
- #resetInternalState() {
335
- if (this.#panelController) this.#panelController.abort();
336
- this.#panelController = null;
337
- this.shadowRoot = null;
338
- this.depthLevelInput = null;
339
- this.depthLevel = 0;
340
- this.multiElements = false;
341
- if (this.#stateBind) {
342
- this.#stateBind.depthLevel = 0;
343
- this.#stateBind.multiElements = false;
344
- this.#stateBind.ignorePanelEl = null;
345
- }
346
- }
347
- /**
348
- * Handles click events within the control panel.
349
- * @param {PointerEvent} e
350
- */
351
- #handleToggleClick = (e) => {
352
- switch (e.target.id) {
353
- case "sk-show-panel": {
354
- if (!this.shadowRoot) return;
355
- const panel = this.shadowRoot.getElementById("sk-control-panel");
356
- if (panel) panel.style.display = "flex";
357
- break;
358
- }
359
- case "sk-close-panel": {
360
- if (!this.shadowRoot) return;
361
- const panel = this.shadowRoot.getElementById("sk-control-panel");
362
- if (panel) panel.style.display = "none";
363
- break;
364
- }
365
- case "sk-toggle-inspector":
366
- this.bus.emit("ci:toggle");
367
- break;
368
- case "sk-toggle-elements":
369
- this.multiElements = !this.multiElements;
370
- if (this.depthLevelInput) if (this.multiElements) this.depthLevelInput.disabled = false;
371
- else this.depthLevelInput.disabled = true;
372
- if (this.#stateBind) this.#stateBind.multiElements = this.multiElements;
373
- break;
374
- case "sk-toggle-switching":
375
- if (this.#stateBind) this.#stateBind.inspectorSwitching = !this.#stateBind.inspectorSwitching;
376
- break;
377
- case "sk-create-inspector":
378
- this.bus.emit("ci:create");
379
- break;
380
- case "sk-reset-inspector":
381
- this.bus.emit("ci:reset");
382
- break;
383
- case "sk-destroy-inspector":
384
- this.bus.emit("ci:destroy");
385
- break;
386
- case "sk-full-inspect":
387
- this.bus.emit("engine:full");
388
- break;
389
- default:
390
- console.error(`Could not dispatch an event for element of unknown id: ${e.target.id}`);
391
- break;
392
- }
393
- };
394
- /**
395
- * Handles the change event for the `depth_level` input.
396
- * @param {Event} e
397
- */
398
- #handleDepthLevelValue = (e) => {
399
- const level = parseInt(
400
- /**@type {HTMLInputElement}*/
401
- e.target.value,
402
- 10
403
- );
404
- this.depthLevel = level;
405
- if (this.#stateBind) this.#stateBind.depthLevel = level;
406
- };
407
- };
408
- //#endregion
409
- export { CompatControlPanel };
1
+ /**
2
+ * Shinkom - control-panel
3
+ * @version 1.1.1
4
+ * @license MIT
5
+ * @copyright 2026 - OneilNvM
6
+ */
7
+
8
+ import { UIComponent } from "../../core/ui-component.js";
9
+ import { CompatControlPanelElement } from "../../core/elements/control-panel-element.js";
10
+ import "../../core/elements/index.js";
11
+ import "../../core/index.js";
12
+ //#region src/ui/control-panel/control-panel.js
13
+ /**@typedef {import('../../types/public').UISharedState} UISharedState */
14
+ /**@typedef {import('../../types/public').UISharedStateProps} UISharedStateProps */
15
+ /**
16
+ * CompatControlPanel manages the visibility, tabs, and input controls of
17
+ * the compatibility control panel overlay.
18
+ *
19
+ * It mounts the `<sk-control-panel>` custom element, binds control values
20
+ * to shared UI state, and dispatches user-driven commands over the Shinkom
21
+ * event bus.
22
+ *
23
+ * The panel supports inspector controls, compatibility view settings,
24
+ * tab switching, and display transitions with or without view transition
25
+ * support.
26
+ *
27
+ * @extends {UIComponent}
28
+ */
29
+ var CompatControlPanel = class CompatControlPanel extends UIComponent {
30
+ /**@type {UISharedState | null} */
31
+ #stateBind = null;
32
+ /**@type {AbortController | null} */
33
+ #panelController = null;
34
+ /**
35
+ * Initializes the compatibility control panel.
36
+ *
37
+ * It requires an instance of the `ShinkomBus` and `ShinkomState` to listen
38
+ * for event bus emits and state service notifications.
39
+ *
40
+ * It also registers the `<sk-control-panel>` custom element.
41
+ *
42
+ * @param {ShinkomBus} bus
43
+ * @param {ShinkomState} stateService
44
+ */
45
+ constructor(bus, stateService) {
46
+ super(bus, stateService);
47
+ CompatControlPanel.register();
48
+ /**@type {CompatControlPanelElement | null} */
49
+ this.controlPanelEl = null;
50
+ /**@type {HTMLInputElement | null} */
51
+ this.depthLevelInput = null;
52
+ /**@type {HTMLInputElement | null} */
53
+ this.maxResultsHistoryInput = null;
54
+ /**@type {number} */
55
+ this.maxResultsHistory = 10;
56
+ /**@type {number} */
57
+ this.depthLevel = 0;
58
+ /**@type {boolean} */
59
+ this.multiElements = false;
60
+ /**@type {"inspector" | "compatView"} */
61
+ this.currentTab = "inspector";
62
+ /**@type {() => void} */
63
+ this.unsubState = () => {};
64
+ }
65
+ /**
66
+ * Register custom elements to the CustomElementRegistry.
67
+ */
68
+ static register() {
69
+ if (typeof window !== "undefined" && "customElements" in globalThis && !globalThis.customElements.get("sk-control-panel")) globalThis.customElements.define("sk-control-panel", CompatControlPanelElement);
70
+ }
71
+ /**
72
+ * Subscribes to shared UI state changes from the Shinkom state service.
73
+ *
74
+ * When the state service emits updates, the control panel updates the
75
+ * relevant button labels and input state accordingly.
76
+ */
77
+ #setupStateServiceListener() {
78
+ this.unsubState = this.stateService.subscribe((prop, val) => {
79
+ this.onStateChange(prop, val);
80
+ });
81
+ }
82
+ /**
83
+ * Unsubscribes from the shared UI state service.
84
+ */
85
+ #cleanupStateServiceListener() {
86
+ this.unsubState();
87
+ }
88
+ /**
89
+ * @param {UISharedState} state
90
+ */
91
+ bindState(state) {
92
+ if (!this.#stateBind) this.#stateBind = state;
93
+ this.#stateBind.ignorePanelEl = this.controlPanelEl;
94
+ }
95
+ /**
96
+ * @param {UISharedStateProps} prop
97
+ * @param {any} val
98
+ */
99
+ onStateChange(prop, val) {
100
+ switch (prop) {
101
+ case "inspectorSwitching":
102
+ if (this.controlPanelEl) {
103
+ const toggleSwitchingButton = this.controlPanelEl.shadowRootRef.getElementById("sk-toggle-switching");
104
+ if (toggleSwitchingButton) toggleSwitchingButton.textContent = val ? "Enabled" : "Disabled";
105
+ }
106
+ break;
107
+ case "inspectorActive":
108
+ if (this.controlPanelEl) {
109
+ const toggleInspectorButton = this.controlPanelEl.shadowRootRef.getElementById("sk-toggle-inspector");
110
+ if (toggleInspectorButton) toggleInspectorButton.textContent = val ? "Enabled" : "Disabled";
111
+ }
112
+ break;
113
+ default: break;
114
+ }
115
+ }
116
+ mount() {
117
+ if (this.controlPanelEl || document.querySelector("sk-control-panel")) return;
118
+ this.controlPanelEl = document.createElement("sk-control-panel");
119
+ document.body.appendChild(this.controlPanelEl);
120
+ this.#setupShadowListeners();
121
+ this.#setupStateServiceListener();
122
+ }
123
+ /**
124
+ * Sets up event listeners within the `ShadowDOM`.
125
+ */
126
+ #setupShadowListeners() {
127
+ if (!this.controlPanelEl) return;
128
+ this.#panelController = new AbortController();
129
+ const { signal } = this.#panelController;
130
+ const depthLevelInput = this.controlPanelEl.shadowRootRef.getElementById("sk-depth-level");
131
+ this.controlPanelEl.shadowHost.addEventListener("click", this.#handleToggleClick, { signal });
132
+ depthLevelInput?.addEventListener("change", this.#handleDepthLevelValue, { signal });
133
+ if (depthLevelInput) {
134
+ this.depthLevelInput = depthLevelInput;
135
+ this.depthLevelInput.disabled = !this.#stateBind?.multiElements;
136
+ }
137
+ }
138
+ unmount() {
139
+ try {
140
+ if (!this.controlPanelEl) return;
141
+ this.controlPanelEl.remove();
142
+ this.controlPanelEl = null;
143
+ this.#resetInternalState();
144
+ this.#cleanupStateServiceListener();
145
+ } catch (error) {
146
+ console.error(`Control panel destroy error: ${error}`);
147
+ }
148
+ }
149
+ /**
150
+ * Resets any internal state and event listeners.
151
+ */
152
+ #resetInternalState() {
153
+ if (this.#panelController) this.#panelController.abort();
154
+ this.#panelController = null;
155
+ this.depthLevelInput = null;
156
+ this.depthLevel = 0;
157
+ this.multiElements = false;
158
+ if (this.#stateBind) {
159
+ this.#stateBind.depthLevel = 0;
160
+ this.#stateBind.multiElements = false;
161
+ this.#stateBind.ignorePanelEl = null;
162
+ }
163
+ }
164
+ /**
165
+ * Handles click events within the control panel.
166
+ * @param {PointerEvent} e
167
+ */
168
+ #handleToggleClick = (e) => {
169
+ switch (e.target.id) {
170
+ case "sk-show-panel":
171
+ if (!this.controlPanelEl) return;
172
+ if (!document.startViewTransition) this.controlPanelEl.renderDisplayTransition("show");
173
+ else this.#handleDisplayTransition("show");
174
+ break;
175
+ case "sk-close-panel":
176
+ if (!this.controlPanelEl) return;
177
+ if (!document.startViewTransition) this.controlPanelEl.renderDisplayTransition("hide");
178
+ else this.#handleDisplayTransition("hide");
179
+ break;
180
+ case "sk-inspector-tab":
181
+ if (!this.controlPanelEl || this.currentTab === "inspector") return;
182
+ if (!document.startViewTransition) {
183
+ this.controlPanelEl.renderTabContent("inspector");
184
+ this.#handleInspectorTabState();
185
+ this.currentTab = "inspector";
186
+ } else this.#handleTabChange("inspector");
187
+ break;
188
+ case "sk-compat-view-tab":
189
+ if (!this.controlPanelEl || this.currentTab === "compatView") return;
190
+ if (!document.startViewTransition) {
191
+ this.controlPanelEl.renderTabContent("compatView");
192
+ this.#handleCompatViewTabState();
193
+ this.currentTab = "compatView";
194
+ } else this.#handleTabChange("compatView");
195
+ break;
196
+ case "sk-toggle-inspector":
197
+ this.bus.emit("ci:toggle");
198
+ break;
199
+ case "sk-toggle-elements":
200
+ this.multiElements = !this.multiElements;
201
+ if (this.depthLevelInput) if (this.multiElements) this.depthLevelInput.disabled = false;
202
+ else this.depthLevelInput.disabled = true;
203
+ if (this.#stateBind) this.#stateBind.multiElements = this.multiElements;
204
+ break;
205
+ case "sk-toggle-switching":
206
+ if (this.#stateBind) this.#stateBind.inspectorSwitching = !this.#stateBind.inspectorSwitching;
207
+ break;
208
+ case "sk-create-inspector":
209
+ this.bus.emit("ci:create");
210
+ break;
211
+ case "sk-reset-inspector":
212
+ this.bus.emit("ci:reset");
213
+ break;
214
+ case "sk-destroy-inspector":
215
+ this.bus.emit("ci:destroy");
216
+ break;
217
+ case "sk-clear-history":
218
+ this.bus.emit("clear:history");
219
+ break;
220
+ default: break;
221
+ }
222
+ };
223
+ /**
224
+ * Handles the transition between tab changes.
225
+ * @param {"inspector" | "compatView"} tab
226
+ */
227
+ async #handleTabChange(tab) {
228
+ if (!this.controlPanelEl) return;
229
+ if (this.controlPanelEl.shadowRootRef.getElementById("sk-control-panel-main")) {
230
+ const transition = document.startViewTransition(() => {
231
+ this.controlPanelEl?.renderTabContent(tab);
232
+ });
233
+ this.currentTab = tab;
234
+ await transition.finished;
235
+ if (this.currentTab === "inspector") this.#handleInspectorTabState();
236
+ else if (this.currentTab === "compatView") this.#handleCompatViewTabState();
237
+ }
238
+ }
239
+ #handleInspectorTabState() {
240
+ if (!this.controlPanelEl) return;
241
+ const depthLevel = this.controlPanelEl.shadowRootRef.getElementById("sk-depth-level");
242
+ if (depthLevel) {
243
+ this.depthLevelInput = depthLevel;
244
+ this.depthLevelInput.addEventListener("change", this.#handleDepthLevelValue, { signal: this.#panelController?.signal });
245
+ if (this.#stateBind) {
246
+ if (this.#stateBind.multiElements) {
247
+ const checkbox = this.controlPanelEl.shadowRootRef.getElementById("sk-toggle-elements");
248
+ checkbox.checked = true;
249
+ } else this.depthLevelInput.disabled = true;
250
+ if (this.#stateBind.depthLevel > 0) this.depthLevelInput.value = `${this.#stateBind.depthLevel}`;
251
+ }
252
+ }
253
+ if (this.#stateBind) {
254
+ const switchingToggle = this.controlPanelEl.shadowRootRef.getElementById("sk-toggle-switching");
255
+ const inspectorToggle = this.controlPanelEl.shadowRootRef.getElementById("sk-toggle-inspector");
256
+ if (inspectorToggle) if (this.#stateBind.inspectorActive) inspectorToggle.textContent = "Enabled";
257
+ else inspectorToggle.textContent = "Disabled";
258
+ if (switchingToggle) if (this.#stateBind.inspectorSwitching) switchingToggle.textContent = "Enabled";
259
+ else switchingToggle.textContent = "Disabled";
260
+ }
261
+ }
262
+ #handleCompatViewTabState() {
263
+ if (!this.controlPanelEl) return;
264
+ const maxHistory = this.controlPanelEl.shadowRootRef.getElementById("sk-max-history");
265
+ if (maxHistory && maxHistory instanceof HTMLInputElement) {
266
+ this.maxResultsHistoryInput = maxHistory;
267
+ this.maxResultsHistoryInput.addEventListener("change", this.#handleMaxHistoryValue, { signal: this.#panelController?.signal });
268
+ if (this.#stateBind) {
269
+ if (this.#stateBind.maxResultsHistory >= 0 && this.#stateBind.maxResultsHistory != 10) this.maxResultsHistoryInput.value = `${this.#stateBind.maxResultsHistory}`;
270
+ }
271
+ }
272
+ }
273
+ /**
274
+ * Handles the transition when toggling the display.
275
+ * @param {"show" | "hide"} display
276
+ */
277
+ async #handleDisplayTransition(display) {
278
+ if (!this.controlPanelEl) return;
279
+ const controlPanel = this.controlPanelEl.shadowRootRef.getElementById("sk-control-panel");
280
+ if (controlPanel) {
281
+ controlPanel.part.value = "control-panel";
282
+ const transition = document.startViewTransition(() => {
283
+ this.controlPanelEl?.renderDisplayTransition(display);
284
+ });
285
+ try {
286
+ await transition.finished;
287
+ } finally {
288
+ controlPanel.removeAttribute("part");
289
+ }
290
+ }
291
+ }
292
+ /**
293
+ * Handles the change event for the `maxResultsHistory` input.
294
+ * @param {Event} e
295
+ */
296
+ #handleMaxHistoryValue = (e) => {
297
+ const value = parseInt(
298
+ /**@type {HTMLInputElement} */
299
+ e.target.value,
300
+ 10
301
+ );
302
+ this.maxResultsHistory = value;
303
+ if (this.#stateBind) this.#stateBind.maxResultsHistory = value;
304
+ };
305
+ /**
306
+ * Handles the change event for the `depth_level` input.
307
+ * @param {Event} e
308
+ */
309
+ #handleDepthLevelValue = (e) => {
310
+ const level = parseInt(
311
+ /**@type {HTMLInputElement}*/
312
+ e.target.value,
313
+ 10
314
+ );
315
+ this.depthLevel = level;
316
+ if (this.#stateBind) this.#stateBind.depthLevel = level;
317
+ };
318
+ };
319
+ //#endregion
320
+ export { CompatControlPanel };