shinkom 1.0.2 → 1.1.0
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 +3 -2
- package/dist/bundles/_virtual/_rolldown/runtime.js +1 -1
- package/dist/bundles/core/constants.d.ts +1 -1
- package/dist/bundles/core/constants.js +5 -2
- package/dist/bundles/core/elements/compat-view-element.d.ts +100 -0
- package/dist/bundles/core/elements/compat-view-element.js +440 -0
- package/dist/bundles/core/elements/control-panel-element.d.ts +45 -0
- package/dist/bundles/core/elements/control-panel-element.js +99 -0
- package/dist/bundles/core/elements/index.d.ts +13 -0
- package/dist/bundles/core/elements/index.js +13 -0
- package/dist/bundles/core/elements/inspector-element.d.ts +27 -0
- package/dist/bundles/core/elements/inspector-element.js +58 -0
- package/dist/bundles/core/elements/recent-result-item.js +46 -0
- package/dist/bundles/core/elements/results-history-item.js +46 -0
- package/dist/bundles/core/elements/templates/compat-view.templates.js +462 -0
- package/dist/bundles/core/elements/templates/control-panel.templates.js +335 -0
- package/dist/bundles/core/elements/templates/root-styles.template.js +40 -0
- package/dist/bundles/core/event-bus.d.ts +19 -5
- package/dist/bundles/core/event-bus.js +21 -8
- package/dist/bundles/core/helpers.js +24 -2
- package/dist/bundles/core/index.d.ts +5 -2
- package/dist/bundles/core/index.js +6 -2
- package/dist/bundles/core/state-service.d.ts +24 -4
- package/dist/bundles/core/state-service.js +25 -5
- package/dist/bundles/core/ui-component.d.ts +25 -6
- package/dist/bundles/core/ui-component.js +31 -12
- package/dist/bundles/engine/engine.d.ts +57 -9
- package/dist/bundles/engine/engine.js +115 -31
- package/dist/bundles/engine/index.js +1 -1
- package/dist/bundles/gen/browser-data.js +36 -36
- package/dist/bundles/gen/browser-usage-data.js +224 -222
- package/dist/bundles/gen/compat-data.js +1 -1
- package/dist/bundles/gen/index.js +1 -1
- package/dist/bundles/index.d.ts +6 -2
- package/dist/bundles/index.js +8 -2
- package/dist/bundles/pkg/shinkore.d.ts +1 -1
- package/dist/bundles/pkg/shinkore.js +1 -1
- package/dist/bundles/pkg/shinkore_bg.wasm +0 -0
- package/dist/bundles/shinkom.d.ts +9 -1
- package/dist/bundles/shinkom.js +31 -6
- package/dist/bundles/types/public.d.ts +13 -29
- package/dist/bundles/types/types.d.ts +99 -0
- package/dist/bundles/ui/compat-ui/compat-ui.d.ts +12 -2
- package/dist/bundles/ui/compat-ui/compat-ui.js +12 -2
- package/dist/bundles/ui/compat-ui/index.js +8 -0
- package/dist/bundles/ui/compatibility-view/compatibility-view.d.ts +42 -0
- package/dist/bundles/ui/compatibility-view/compatibility-view.js +229 -0
- package/dist/bundles/ui/compatibility-view/index.js +8 -0
- package/dist/bundles/ui/control-panel/control-panel.d.ts +30 -16
- package/dist/bundles/ui/control-panel/control-panel.js +188 -277
- package/dist/bundles/ui/control-panel/index.js +8 -0
- package/dist/bundles/ui/index.d.ts +3 -2
- package/dist/bundles/ui/index.js +7 -2
- package/dist/bundles/ui/inspector/index.js +8 -0
- package/dist/bundles/ui/inspector/inspector.d.ts +60 -6
- package/dist/bundles/ui/inspector/inspector.js +149 -69
- package/dist/modules/core/constants.cjs +17 -1
- package/dist/modules/core/elements/compat-view-element.cjs +434 -0
- package/dist/modules/core/elements/control-panel-element.cjs +93 -0
- package/dist/modules/core/elements/index.cjs +11 -0
- package/dist/modules/core/elements/inspector-element.cjs +52 -0
- package/dist/modules/core/elements/recent-result-item.cjs +39 -0
- package/dist/modules/core/elements/results-history-item.cjs +39 -0
- package/dist/modules/core/elements/templates/compat-view.templates.cjs +458 -0
- package/dist/modules/core/elements/templates/control-panel.templates.cjs +332 -0
- package/dist/modules/core/elements/templates/root-styles.template.cjs +33 -0
- package/dist/modules/core/event-bus.cjs +43 -1
- package/dist/modules/core/helpers.cjs +41 -1
- package/dist/modules/core/index.cjs +16 -1
- package/dist/modules/core/state-service.cjs +74 -1
- package/dist/modules/core/ui-component.cjs +65 -1
- package/dist/modules/engine/engine.cjs +232 -1
- package/dist/modules/gen/browser-data.cjs +100 -1
- package/dist/modules/gen/browser-usage-data.cjs +675 -1
- package/dist/modules/gen/compat-data.cjs +31015 -1
- package/dist/modules/gen/index.cjs +7 -1
- package/dist/modules/index.cjs +27 -1
- package/dist/modules/pkg/shinkore.cjs +459 -1
- package/dist/modules/pkg/shinkore_bg.wasm +0 -0
- package/dist/modules/shinkom.cjs +73 -1
- package/dist/modules/ui/compat-ui/compat-ui.cjs +53 -1
- package/dist/modules/ui/compat-ui/index.cjs +1 -0
- package/dist/modules/ui/compatibility-view/compatibility-view.cjs +223 -0
- package/dist/modules/ui/compatibility-view/index.cjs +1 -0
- package/dist/modules/ui/control-panel/control-panel.cjs +314 -182
- package/dist/modules/ui/control-panel/index.cjs +1 -0
- package/dist/modules/ui/index.cjs +13 -1
- package/dist/modules/ui/inspector/index.cjs +1 -0
- package/dist/modules/ui/inspector/inspector.cjs +388 -1
- package/package.json +15 -8
- package/dist/bundles/node_modules/@mdn/browser-compat-data/types.d.ts +0 -78
package/README.md
CHANGED
|
@@ -148,7 +148,8 @@ then consider contributing by creating a **pull request** on the **dev** branch
|
|
|
148
148
|
|
|
149
149
|
### Basic
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
https://github.com/user-attachments/assets/fc0dda8d-1f1b-44cf-bcbe-db7a5f4c76c9
|
|
152
|
+
|
|
152
153
|
The simplest and **recommended** way to utilize Shinkom is through the main entry-point.
|
|
153
154
|
|
|
154
155
|
```javascript
|
|
@@ -395,7 +396,7 @@ Make sure to check out both of these great projects!
|
|
|
395
396
|
- [x] Configurable cross-browser compatibility DOM inspection
|
|
396
397
|
- [x] Full page cross-browser compatibility scan
|
|
397
398
|
- [x] HTML parsing and compatibility checks via Rust and WASM engine module
|
|
398
|
-
- [
|
|
399
|
+
- [x] Interactive panel for viewing results of compatibility checks
|
|
399
400
|
- [ ] Hints for improving cross-browser compatibility based on checks
|
|
400
401
|
- [ ] Optional accessibility evaluation and hints based on WCAG guidelines
|
|
401
402
|
- [ ] CSS and Javascript file parsing and cross-browser compatibility checks
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shinkom - core
|
|
3
|
-
* @version 1.0
|
|
3
|
+
* @version 1.1.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - OneilNvM
|
|
6
6
|
*/
|
|
@@ -13,8 +13,11 @@ const DEFAULT_STATE = {
|
|
|
13
13
|
inspectorActive: false,
|
|
14
14
|
inspectorSwitching: false,
|
|
15
15
|
ignorePanelEl: null,
|
|
16
|
+
ignoreCompatViewEl: null,
|
|
16
17
|
multiElements: false,
|
|
17
|
-
depthLevel: 0
|
|
18
|
+
depthLevel: 0,
|
|
19
|
+
compatViewTab: "overview",
|
|
20
|
+
maxResultsHistory: 10
|
|
18
21
|
};
|
|
19
22
|
//#endregion
|
|
20
23
|
export { DEFAULT_STATE };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shinkom - elements
|
|
3
|
+
* @version 1.1.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - OneilNvM
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ShinkomBus } from "../event-bus.js";
|
|
9
|
+
import { ShinkomState } from "../state-service.js";
|
|
10
|
+
import { CompatResult as CompatResult$1, CompatSnapshot as CompatSnapshot$1, LookupResult as LookupResult$1 } from "../../types/public.js";
|
|
11
|
+
|
|
12
|
+
//#region src/core/elements/compat-view-element.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* A custom element for the `CompatView` UI component.
|
|
15
|
+
*
|
|
16
|
+
* An autonomous custom element created via the [Web Components API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
|
|
17
|
+
* This component contains methods for rendering components for the CompatView and handling how the results from the engine
|
|
18
|
+
* is stored and displayed for viewing.
|
|
19
|
+
*
|
|
20
|
+
* Since this element is defined via the Web Components API, to use this element outside of the CompatView, it must be registered
|
|
21
|
+
* as a custom element on the `window` object.
|
|
22
|
+
* @extends {BaseElement}
|
|
23
|
+
*/
|
|
24
|
+
declare class CompatViewElement extends HTMLElement {
|
|
25
|
+
/**@type {ShadowRoot} */
|
|
26
|
+
shadowRootRef: ShadowRoot;
|
|
27
|
+
shadowHost: HTMLDivElement;
|
|
28
|
+
/**@type {"overview" | "results" | "history"} */
|
|
29
|
+
currentTab: "overview" | "results" | "history";
|
|
30
|
+
/**@type {ShinkomState | null} */
|
|
31
|
+
state: ShinkomState | null;
|
|
32
|
+
/**@type {ShinkomBus | null} */
|
|
33
|
+
bus: ShinkomBus | null;
|
|
34
|
+
/**@type {CompatResult | null} */
|
|
35
|
+
_results: CompatResult | null;
|
|
36
|
+
/**@type {CompatSnapshot[]} */
|
|
37
|
+
_resultsHistory: CompatSnapshot[];
|
|
38
|
+
set results(val: CompatResult$1 | null);
|
|
39
|
+
get results(): CompatResult$1 | null;
|
|
40
|
+
set resultsHistory(val: CompatSnapshot$1[]);
|
|
41
|
+
get resultsHistory(): CompatSnapshot$1[];
|
|
42
|
+
/**
|
|
43
|
+
* Updates the results history and backs up the results to `localStorage`.
|
|
44
|
+
* @param {CompatSnapshot} val
|
|
45
|
+
*/
|
|
46
|
+
updateResultsHistory(val: CompatSnapshot): void;
|
|
47
|
+
/**
|
|
48
|
+
* Checks the current release version of `Shinkom`
|
|
49
|
+
*/
|
|
50
|
+
checkVersion(): Promise<void>;
|
|
51
|
+
connectedCallback(): void;
|
|
52
|
+
_unsubEvent: (() => void) | undefined;
|
|
53
|
+
_unsubState: (() => void) | undefined;
|
|
54
|
+
disconnectedCallback(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Renders the `CompatViewElement` on a specific tab.
|
|
57
|
+
*
|
|
58
|
+
* Renders the `overview` tab by default.
|
|
59
|
+
* @param {"overview" | "results" | "history" | undefined} tab
|
|
60
|
+
*/
|
|
61
|
+
render(tab?: "overview" | "results" | "history" | undefined): void;
|
|
62
|
+
/**
|
|
63
|
+
* Renders list items for the 5 most recent results.
|
|
64
|
+
* @throws {Error} If the list for the recent results does not exist.
|
|
65
|
+
*/
|
|
66
|
+
renderRecentResults(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Renders content for a specific tab.
|
|
69
|
+
* @param {"overview" | "results" | "history"} tab
|
|
70
|
+
*/
|
|
71
|
+
renderTabContent(tab: "overview" | "results" | "history"): void;
|
|
72
|
+
/**
|
|
73
|
+
* Renders the results from the results history.
|
|
74
|
+
* @throws {Error} If the main container does not exist.
|
|
75
|
+
*/
|
|
76
|
+
renderHistoryResults(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Renders the content of a compatibility result.
|
|
79
|
+
* @param {CompatSnapshot | undefined} snapshot
|
|
80
|
+
* @throws {Error} If the main container does not exist.
|
|
81
|
+
*/
|
|
82
|
+
renderCompatResult(snapshot?: CompatSnapshot | undefined): void;
|
|
83
|
+
/**
|
|
84
|
+
* Renders the content of a browser result for a web feature.
|
|
85
|
+
* @param {LookupResult} lookupResult
|
|
86
|
+
* @returns {string} browser results HTML
|
|
87
|
+
*/
|
|
88
|
+
renderBrowserResults(lookupResult: LookupResult): string;
|
|
89
|
+
/**
|
|
90
|
+
* Renders the display of the `CompatViewElement`.
|
|
91
|
+
* @param {"show" | "hide"} display
|
|
92
|
+
*/
|
|
93
|
+
renderDisplayTransition(display: "show" | "hide"): void;
|
|
94
|
+
#private;
|
|
95
|
+
}
|
|
96
|
+
type CompatResult = CompatResult$1;
|
|
97
|
+
type CompatSnapshot = CompatSnapshot$1;
|
|
98
|
+
type LookupResult = LookupResult$1;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { CompatResult, CompatSnapshot, CompatViewElement, LookupResult };
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shinkom - elements
|
|
3
|
+
* @version 1.1.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - OneilNvM
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getStyleSheet, versionToParts } from "../helpers.js";
|
|
9
|
+
import { compatViewHTML, compatViewOverviewHTML, compatViewStyles, compatViewTransitions } from "./templates/compat-view.templates.js";
|
|
10
|
+
import { hostStyles } from "./templates/root-styles.template.js";
|
|
11
|
+
//#region src/core/elements/compat-view-element.js
|
|
12
|
+
/**
|
|
13
|
+
* @type {typeof HTMLElement}
|
|
14
|
+
*/
|
|
15
|
+
const BaseElement = typeof window !== "undefined" ? HTMLElement : class {};
|
|
16
|
+
/**@type {CSSStyleSheet | null} */
|
|
17
|
+
let cachedHostStyleSheet = null;
|
|
18
|
+
/**@type {CSSStyleSheet | null} */
|
|
19
|
+
let cachedStyleSheet = null;
|
|
20
|
+
/**@type {CSSStyleSheet | null} */
|
|
21
|
+
let cachedTransitions = null;
|
|
22
|
+
/**
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
const _macroVersion = "1.1.0";
|
|
26
|
+
/**
|
|
27
|
+
* A custom element for the `CompatView` UI component.
|
|
28
|
+
*
|
|
29
|
+
* An autonomous custom element created via the [Web Components API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
|
|
30
|
+
* This component contains methods for rendering components for the CompatView and handling how the results from the engine
|
|
31
|
+
* is stored and displayed for viewing.
|
|
32
|
+
*
|
|
33
|
+
* Since this element is defined via the Web Components API, to use this element outside of the CompatView, it must be registered
|
|
34
|
+
* as a custom element on the `window` object.
|
|
35
|
+
* @extends {BaseElement}
|
|
36
|
+
*/
|
|
37
|
+
var CompatViewElement = class extends BaseElement {
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
/**@type {ShadowRoot} */
|
|
41
|
+
this.shadowRootRef = this.attachShadow({ mode: "open" });
|
|
42
|
+
this.shadowHost = document.createElement("div");
|
|
43
|
+
this.shadowHost.id = "sk-shadow-host";
|
|
44
|
+
this.shadowHost.classList.add("sk-shadow-host");
|
|
45
|
+
/**@type {"overview" | "results" | "history"} */
|
|
46
|
+
this.currentTab = "overview";
|
|
47
|
+
/**@type {ShinkomState | null} */
|
|
48
|
+
this.state = null;
|
|
49
|
+
/**@type {ShinkomBus | null} */
|
|
50
|
+
this.bus = null;
|
|
51
|
+
/**@type {CompatResult | null} */
|
|
52
|
+
this._results = null;
|
|
53
|
+
/**@type {CompatSnapshot[]} */
|
|
54
|
+
this._resultsHistory = [];
|
|
55
|
+
cachedHostStyleSheet = getStyleSheet(cachedHostStyleSheet, hostStyles);
|
|
56
|
+
cachedStyleSheet = getStyleSheet(cachedStyleSheet, compatViewStyles);
|
|
57
|
+
cachedTransitions = getStyleSheet(cachedTransitions, compatViewTransitions);
|
|
58
|
+
}
|
|
59
|
+
get results() {
|
|
60
|
+
return this._results;
|
|
61
|
+
}
|
|
62
|
+
set results(val) {
|
|
63
|
+
if (!val) return;
|
|
64
|
+
this._results = val;
|
|
65
|
+
this.updateResultsHistory({
|
|
66
|
+
...val,
|
|
67
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
if (this.currentTab === "overview") this.renderRecentResults();
|
|
71
|
+
else if (this.currentTab === "results") this.renderCompatResult();
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(`CompatView rendering error: ${error}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
get resultsHistory() {
|
|
77
|
+
return this._resultsHistory;
|
|
78
|
+
}
|
|
79
|
+
set resultsHistory(val) {
|
|
80
|
+
if (!val) return;
|
|
81
|
+
this._resultsHistory = val;
|
|
82
|
+
try {
|
|
83
|
+
if (this.currentTab === "history") this.renderHistoryResults();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`CompatView rendering error: ${error}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Updates the results history and backs up the results to `localStorage`.
|
|
90
|
+
* @param {CompatSnapshot} val
|
|
91
|
+
*/
|
|
92
|
+
updateResultsHistory(val) {
|
|
93
|
+
if (this.state) this.resultsHistory = [val, ...this.resultsHistory].slice(0, this.state.getState().maxResultsHistory);
|
|
94
|
+
else this.resultsHistory = [val, ...this.resultsHistory].slice(0, 10);
|
|
95
|
+
this.#backupResultsToLocalStorage();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves results history from `localStorage`.
|
|
99
|
+
*/
|
|
100
|
+
#retrieveResultsFromLocalStorage() {
|
|
101
|
+
const resultsHistory = localStorage.getItem("resultsHistory");
|
|
102
|
+
try {
|
|
103
|
+
if (resultsHistory) this.resultsHistory = JSON.parse(resultsHistory);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(`Failed to parse results history from localStorage: ${error}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Used to backup results history to `localStorage`.
|
|
110
|
+
*/
|
|
111
|
+
#backupResultsToLocalStorage() {
|
|
112
|
+
try {
|
|
113
|
+
localStorage.setItem("resultsHistory", JSON.stringify(this.resultsHistory));
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(`Failed to backup results history to localStorage: ${error}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Injects google font link into `document.head`.
|
|
120
|
+
*/
|
|
121
|
+
#injectFontLink() {
|
|
122
|
+
if (document.getElementById("sk-font-doto")) return;
|
|
123
|
+
const link = document.createElement("link");
|
|
124
|
+
link.id = "sk-font-doto";
|
|
125
|
+
link.href = "https://fonts.googleapis.com/css2?family=Doto:wght,ROND@700,100&display=swap";
|
|
126
|
+
link.rel = "stylesheet";
|
|
127
|
+
document.head.appendChild(link);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Checks the current release version of `Shinkom`
|
|
131
|
+
*/
|
|
132
|
+
async checkVersion() {
|
|
133
|
+
const shinkomVersion = sessionStorage.getItem("shinkom-latest-version");
|
|
134
|
+
try {
|
|
135
|
+
if (shinkomVersion) this.#processVersions(_macroVersion, shinkomVersion);
|
|
136
|
+
else {
|
|
137
|
+
const version = await this.#checkLatestVersion();
|
|
138
|
+
if (version) sessionStorage.setItem("shinkom-latest-version", version);
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error(`Failed to perform Shinkom version check: ${error}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Processes and compares two version strings.
|
|
146
|
+
* @param {string} localV
|
|
147
|
+
* @param {string} remoteV
|
|
148
|
+
*/
|
|
149
|
+
#processVersions(localV, remoteV) {
|
|
150
|
+
const versionIndicator = this.shadowRootRef.getElementById("sk-version-indicator");
|
|
151
|
+
const local = versionToParts(localV);
|
|
152
|
+
const remote = versionToParts(remoteV);
|
|
153
|
+
if (versionIndicator) if (remote[0] > local[0]) versionIndicator.style.backgroundImage = "radial-gradient(circle at center, var(--sk-indicator-red) 1px, transparent 0)";
|
|
154
|
+
else if (remote[1] > local[1]) versionIndicator.style.backgroundImage = "radial-gradient(circle at center, var(--sk-indicator-yellow) 1px, transparent 0)";
|
|
155
|
+
else if ((remote[2] || 0) > (local[2] || 0)) versionIndicator.style.backgroundImage = "radial-gradient(circle at center, var(--sk-indicator-blue) 1px, transparent 0)";
|
|
156
|
+
else versionIndicator.style.backgroundImage = "radial-gradient(circle at center, var(--sk-indicator-green) 1px, transparent 0)";
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Sends a fetch request for the latest release of `Shinkom`
|
|
160
|
+
* @returns {Promise<string | undefined>} tag name of latest version
|
|
161
|
+
*/
|
|
162
|
+
async #checkLatestVersion() {
|
|
163
|
+
const response = await fetch("https://api.github.com/repos/OneilNvM/shinkom/releases/latest");
|
|
164
|
+
if (!response.ok) throw new Error("Unable to fetch Shinkom latest release. Network response was not ok.");
|
|
165
|
+
const data = await response.json();
|
|
166
|
+
this.#processVersions(_macroVersion, data.tag_name);
|
|
167
|
+
return data.tag_name;
|
|
168
|
+
}
|
|
169
|
+
connectedCallback() {
|
|
170
|
+
if (this.bus) this._unsubEvent = this.bus.on("clear:history", () => {
|
|
171
|
+
localStorage.removeItem("resultsHistory");
|
|
172
|
+
this.resultsHistory = [];
|
|
173
|
+
console.log("Cleared results history!");
|
|
174
|
+
try {
|
|
175
|
+
if (this.currentTab === "overview") this.renderRecentResults();
|
|
176
|
+
else if (this.currentTab === "results") this.renderCompatResult();
|
|
177
|
+
else this.renderHistoryResults();
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error(`CompatView rendering error: ${error}`);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
else console.warn("No event bus was provided to the CompatViewElement. This may cause functional problems when emitting events the CompatViewElement listens for. If this was intentional, then ignore this warning.");
|
|
183
|
+
if (this.state) this._unsubState = this.state.subscribe((prop, val) => {
|
|
184
|
+
if (prop === "compatViewTab") this.currentTab = val;
|
|
185
|
+
});
|
|
186
|
+
else console.warn("No state was provided to the CompatViewElement. This may cause syncing mistakes between it and the CompatView. If this was intentional, then ignore this warning.");
|
|
187
|
+
this.#retrieveResultsFromLocalStorage();
|
|
188
|
+
if (cachedTransitions) document.adoptedStyleSheets.push(cachedTransitions);
|
|
189
|
+
this.#injectFontLink();
|
|
190
|
+
if (cachedHostStyleSheet) this.shadowRootRef.adoptedStyleSheets = [cachedHostStyleSheet];
|
|
191
|
+
if (cachedStyleSheet) this.shadowRootRef.adoptedStyleSheets.push(cachedStyleSheet);
|
|
192
|
+
this.shadowRootRef.appendChild(this.shadowHost);
|
|
193
|
+
this.render();
|
|
194
|
+
}
|
|
195
|
+
disconnectedCallback() {
|
|
196
|
+
const fontLink = document.getElementById("sk-font-doto");
|
|
197
|
+
if (fontLink) document.head.removeChild(fontLink);
|
|
198
|
+
if (this._unsubEvent) this._unsubEvent();
|
|
199
|
+
if (this._unsubState) this._unsubState();
|
|
200
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((sheet) => sheet !== cachedTransitions);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Renders the `CompatViewElement` on a specific tab.
|
|
204
|
+
*
|
|
205
|
+
* Renders the `overview` tab by default.
|
|
206
|
+
* @param {"overview" | "results" | "history" | undefined} tab
|
|
207
|
+
*/
|
|
208
|
+
render(tab = void 0) {
|
|
209
|
+
this.shadowHost.innerHTML = compatViewHTML;
|
|
210
|
+
tab ? this.renderTabContent(tab) : this.renderTabContent("overview");
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Renders list items for the 5 most recent results.
|
|
214
|
+
* @throws {Error} If the list for the recent results does not exist.
|
|
215
|
+
*/
|
|
216
|
+
renderRecentResults() {
|
|
217
|
+
const list = this.shadowRootRef.getElementById("sk-recent-results-list");
|
|
218
|
+
if (!list) throw new Error("Failed to render recent results. Container with id 'sk-recent-results-list' does not exist.");
|
|
219
|
+
else if (this.resultsHistory.length === 0) {
|
|
220
|
+
list.innerHTML = `<p>NO RECENT RESULTS</p>`;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const recentResultsItems = this.resultsHistory.slice(0, 5).map((snap) => {
|
|
224
|
+
const item = document.createElement("sk-recent-result-item");
|
|
225
|
+
item.classList.add("sk-recent-results-item-container");
|
|
226
|
+
item.result = snap;
|
|
227
|
+
item.viewResult = (res) => {
|
|
228
|
+
if (!document.startViewTransition) {
|
|
229
|
+
const sharedState = this.state?.getState();
|
|
230
|
+
if (sharedState) sharedState.compatViewTab = "results";
|
|
231
|
+
this.renderCompatResult(res);
|
|
232
|
+
} else this.#handleViewResultTransition(res);
|
|
233
|
+
};
|
|
234
|
+
item.innerHTML = `
|
|
235
|
+
<div class="sk-recent-results-item">
|
|
236
|
+
<p>${snap.checkedAt}</p>
|
|
237
|
+
<p>${snap.overall_score}</p>
|
|
238
|
+
<button class="sk-view-result sk-button-style">Details</button>
|
|
239
|
+
</div>
|
|
240
|
+
<hr class="sk-hr-line">
|
|
241
|
+
`;
|
|
242
|
+
return item;
|
|
243
|
+
});
|
|
244
|
+
list.replaceChildren(...recentResultsItems);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Handles the transition after clicking an item with a `viewResult` callback.
|
|
248
|
+
* @param {CompatSnapshot} res
|
|
249
|
+
*/
|
|
250
|
+
async #handleViewResultTransition(res) {
|
|
251
|
+
const sharedState = this.state?.getState();
|
|
252
|
+
const mainSection = this.shadowRootRef.getElementById("sk-compat-view-main");
|
|
253
|
+
if (mainSection) {
|
|
254
|
+
const tabs = [
|
|
255
|
+
"overview",
|
|
256
|
+
"results",
|
|
257
|
+
"history"
|
|
258
|
+
];
|
|
259
|
+
const direction = tabs.indexOf("results") > tabs.indexOf(this.currentTab) ? "forward" : "backward";
|
|
260
|
+
mainSection.part.value = "compat-view";
|
|
261
|
+
document.documentElement.dataset.transition = direction;
|
|
262
|
+
if (sharedState) sharedState.compatViewTab = "results";
|
|
263
|
+
const transition = document.startViewTransition(() => this.renderCompatResult(res));
|
|
264
|
+
try {
|
|
265
|
+
await transition.finished;
|
|
266
|
+
} finally {
|
|
267
|
+
mainSection.removeAttribute("part");
|
|
268
|
+
delete document.documentElement.dataset.transition;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Renders content for a specific tab.
|
|
274
|
+
* @param {"overview" | "results" | "history"} tab
|
|
275
|
+
*/
|
|
276
|
+
renderTabContent(tab) {
|
|
277
|
+
try {
|
|
278
|
+
switch (tab) {
|
|
279
|
+
case "overview":
|
|
280
|
+
const main = this.shadowRootRef.getElementById("sk-compat-view-main");
|
|
281
|
+
if (main) {
|
|
282
|
+
main.innerHTML = compatViewOverviewHTML;
|
|
283
|
+
this.checkVersion();
|
|
284
|
+
this.renderRecentResults();
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
case "results":
|
|
288
|
+
this.renderCompatResult();
|
|
289
|
+
break;
|
|
290
|
+
case "history":
|
|
291
|
+
this.renderHistoryResults();
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
} catch (error) {
|
|
295
|
+
console.error(`CompatView rendering error: ${error}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Renders the results from the results history.
|
|
300
|
+
* @throws {Error} If the main container does not exist.
|
|
301
|
+
*/
|
|
302
|
+
renderHistoryResults() {
|
|
303
|
+
const main = this.shadowRootRef.getElementById("sk-compat-view-main");
|
|
304
|
+
if (!main) throw new Error("Failed to render history results. Container with id 'sk-compat-view-main' does not exist");
|
|
305
|
+
else if (this.resultsHistory.length === 0) {
|
|
306
|
+
main.innerHTML = `<p>NO PREVIOUS RESULTS</p>`;
|
|
307
|
+
return;
|
|
308
|
+
} else main.innerHTML = `<div id="sk-history-container" class="sk-history-container"></div>`;
|
|
309
|
+
const historyContainer = this.shadowRootRef.getElementById("sk-history-container");
|
|
310
|
+
const resultsHistoryItems = this.resultsHistory.map((snapshot) => {
|
|
311
|
+
const item = document.createElement("sk-history-item");
|
|
312
|
+
item.result = snapshot;
|
|
313
|
+
item.viewResult = (res) => {
|
|
314
|
+
if (!document.startViewTransition) {
|
|
315
|
+
const sharedState = this.state?.getState();
|
|
316
|
+
if (sharedState) sharedState.compatViewTab = "results";
|
|
317
|
+
this.renderCompatResult(res);
|
|
318
|
+
} else this.#handleViewResultTransition(res);
|
|
319
|
+
};
|
|
320
|
+
item.innerHTML = `
|
|
321
|
+
<div class="sk-history-item">
|
|
322
|
+
<p>Score ${snapshot.overall_score}</p>
|
|
323
|
+
<p>Check performed at: ${snapshot.checkedAt}</p>
|
|
324
|
+
</div>
|
|
325
|
+
`;
|
|
326
|
+
return item;
|
|
327
|
+
});
|
|
328
|
+
if (!historyContainer) throw new Error("Could not render results history items. Container with id 'sk-history-container' does not exist");
|
|
329
|
+
else {
|
|
330
|
+
const fragment = document.createDocumentFragment();
|
|
331
|
+
resultsHistoryItems.forEach((item) => fragment.appendChild(item));
|
|
332
|
+
historyContainer.appendChild(fragment);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Renders the content of a compatibility result.
|
|
337
|
+
* @param {CompatSnapshot | undefined} snapshot
|
|
338
|
+
* @throws {Error} If the main container does not exist.
|
|
339
|
+
*/
|
|
340
|
+
renderCompatResult(snapshot = void 0) {
|
|
341
|
+
const main = this.shadowRootRef.getElementById("sk-compat-view-main");
|
|
342
|
+
const data = snapshot || this.resultsHistory[0];
|
|
343
|
+
if (!main) throw new Error("Failed to render compat result. Container with id 'sk-compat-view-main' does not exist.");
|
|
344
|
+
else if (!data) {
|
|
345
|
+
main.innerHTML = `<p>NO RESULTS ARRIVING</p>`;
|
|
346
|
+
return;
|
|
347
|
+
} else main.innerHTML = `
|
|
348
|
+
<div class="sk-compat-result-container doto-regular">
|
|
349
|
+
<div class="sk-compat-result-header">
|
|
350
|
+
<div class="sk-compat-header-top">
|
|
351
|
+
<p>Score ${snapshot ? snapshot.overall_score : this.resultsHistory[0].overall_score}</p>
|
|
352
|
+
<p>Arrived</p>
|
|
353
|
+
</div>
|
|
354
|
+
<p>${snapshot ? snapshot.checkedAt : this.resultsHistory[0].checkedAt}</p>
|
|
355
|
+
</div>
|
|
356
|
+
<div id="sk-compat-results" class="sk-compat-results"></div>
|
|
357
|
+
</div>
|
|
358
|
+
`;
|
|
359
|
+
const compatResultsContainer = this.shadowRootRef.getElementById("sk-compat-results");
|
|
360
|
+
const compatResults = (snapshot ? snapshot : this.resultsHistory[0]).lookup_results.map((res, index) => {
|
|
361
|
+
const score = parseInt(res.compat_score, 10);
|
|
362
|
+
const rating = score >= 90 ? "On time" : score >= 60 ? "Delayed" : "Cancelled";
|
|
363
|
+
return `
|
|
364
|
+
<div class="sk-compat-result">
|
|
365
|
+
<div class="sk-general-result">
|
|
366
|
+
<div class="sk-general-result-meta">
|
|
367
|
+
<p>${res.compat_score}</p>
|
|
368
|
+
<p>${index + 1} ${res.name}</p>
|
|
369
|
+
<p ${rating === "Delayed" ? `style="color: var(--sk-results-yellow-foreground)"` : rating === "Cancelled" ? `style="color: var(--sk-results-red-foreground)"` : ""}>${rating}</p>
|
|
370
|
+
</div>
|
|
371
|
+
<div>
|
|
372
|
+
<p>Calling at: ${res.mdn_url ? `<a href="${res.mdn_url}" target="_blank">${res.mdn_url}</a>` : `<span style="color: var(--sk-results-red-foreground)">Missing</span>`}
|
|
373
|
+
</p>
|
|
374
|
+
<p>Browser Score: ${res.browser_score}</p>
|
|
375
|
+
<p>Status Score: ${res.status_score}</p>
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
<details>
|
|
379
|
+
<summary>Show Browser Results</summary>
|
|
380
|
+
<div class="sk-browser-results">
|
|
381
|
+
${this.renderBrowserResults(res)}
|
|
382
|
+
</div>
|
|
383
|
+
</details>
|
|
384
|
+
</div>
|
|
385
|
+
`;
|
|
386
|
+
});
|
|
387
|
+
if (!compatResultsContainer) throw new Error("Could not render compat result item. Container with id 'sk-compat-results' does not exist.");
|
|
388
|
+
else compatResultsContainer.innerHTML = compatResults.join("");
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Renders the content of a browser result for a web feature.
|
|
392
|
+
* @param {LookupResult} lookupResult
|
|
393
|
+
* @returns {string} browser results HTML
|
|
394
|
+
*/
|
|
395
|
+
renderBrowserResults(lookupResult) {
|
|
396
|
+
return lookupResult.browsers.map((browser) => {
|
|
397
|
+
const support = Array.isArray(browser.versions) ? browser.versions : browser.versions;
|
|
398
|
+
let versionParagraphs = [];
|
|
399
|
+
if (support instanceof Array) support.forEach((statement) => {
|
|
400
|
+
versionParagraphs.push(`
|
|
401
|
+
<p>Added in version: ${statement.version_added}</p>
|
|
402
|
+
${statement.version_removed ? `<p>Removed in version: ${statement.version_removed}</p>` : ""}
|
|
403
|
+
${statement.version_last ? `<p>Last in version: ${statement.version_last}</p>` : ""}
|
|
404
|
+
${statement.partial_implementation ? `<p>Partially implemented in version: ${statement.partial_implementation}</p>` : ""}
|
|
405
|
+
`);
|
|
406
|
+
});
|
|
407
|
+
else versionParagraphs.push(`
|
|
408
|
+
<p>Added in version: ${support.version_added}</p>
|
|
409
|
+
${support.version_removed ? `<p>Removed in version: ${support.version_removed}</p>` : ""}
|
|
410
|
+
${support.version_last ? `<p>Last in version: ${support.version_last}</p>` : ""}
|
|
411
|
+
${support.partial_implementation ? `<p>Partially implemented in version: ${support.partial_implementation}</p>` : ""}
|
|
412
|
+
`);
|
|
413
|
+
return `
|
|
414
|
+
<div class="sk-browser-result">
|
|
415
|
+
<div class="sk-browser-result-meta">
|
|
416
|
+
<p style="color: var(--sk-results-blue-foreground)">${browser.browser_name}</p>
|
|
417
|
+
<p>Safety ${browser.score.raw_score}</p>
|
|
418
|
+
<p>Market ${browser.score.weighted_score}</p>
|
|
419
|
+
</div>
|
|
420
|
+
<div>
|
|
421
|
+
${versionParagraphs.join("")}
|
|
422
|
+
</div>
|
|
423
|
+
</div>
|
|
424
|
+
`;
|
|
425
|
+
}).join("");
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Renders the display of the `CompatViewElement`.
|
|
429
|
+
* @param {"show" | "hide"} display
|
|
430
|
+
*/
|
|
431
|
+
renderDisplayTransition(display) {
|
|
432
|
+
const compatView = this.shadowRootRef.getElementById("sk-compat-view-container");
|
|
433
|
+
if (compatView) {
|
|
434
|
+
if (display === "show") compatView.style.display = "block";
|
|
435
|
+
else if (display === "hide") compatView.style.display = "none";
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
//#endregion
|
|
440
|
+
export { CompatViewElement };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shinkom - elements
|
|
3
|
+
* @version 1.1.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - OneilNvM
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
//#region src/core/elements/control-panel-element.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A custom element for the `CompatControlPanel` UI component.
|
|
11
|
+
*
|
|
12
|
+
* An autonomous custom element created via the [Web Components API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
|
|
13
|
+
* This component contains methods for rendering components for the `CompatControlPanel` and providing settings for customization of different
|
|
14
|
+
* UI components.
|
|
15
|
+
*
|
|
16
|
+
* Since this element is defined via the Web Components API, to use this element outside of the `CompatControlPanel`, it must be registered
|
|
17
|
+
* as a custom element on the `window` object.
|
|
18
|
+
* @extends {BaseElement}
|
|
19
|
+
*/
|
|
20
|
+
declare class CompatControlPanelElement extends HTMLElement {
|
|
21
|
+
/**@type {ShadowRoot} */
|
|
22
|
+
shadowRootRef: ShadowRoot;
|
|
23
|
+
shadowHost: HTMLDivElement;
|
|
24
|
+
connectedCallback(): void;
|
|
25
|
+
disconnectedCallback(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Renders the `ControlPanelElement` on a specific tab.
|
|
28
|
+
*
|
|
29
|
+
* Renders the `inspector` tab by default.
|
|
30
|
+
* @param {"inspector" | "compatView" | undefined} tab
|
|
31
|
+
*/
|
|
32
|
+
render(tab?: "inspector" | "compatView" | undefined): void;
|
|
33
|
+
/**
|
|
34
|
+
* Renders content for a specific tab.
|
|
35
|
+
* @param {"inspector" | "compatView"} tab
|
|
36
|
+
*/
|
|
37
|
+
renderTabContent(tab: "inspector" | "compatView"): void;
|
|
38
|
+
/**
|
|
39
|
+
* Renders the display of the `ControlPanelElement`.
|
|
40
|
+
* @param {"show" | "hide"} display
|
|
41
|
+
*/
|
|
42
|
+
renderDisplayTransition(display: "show" | "hide"): void;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CompatControlPanelElement };
|