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