shinkom 1.1.0 → 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 (84) hide show
  1. package/dist/bundles/_virtual/_rolldown/runtime.js +14 -14
  2. package/dist/bundles/core/constants.d.ts +15 -15
  3. package/dist/bundles/core/constants.js +23 -23
  4. package/dist/bundles/core/elements/compat-view-element.d.ts +99 -99
  5. package/dist/bundles/core/elements/compat-view-element.js +440 -440
  6. package/dist/bundles/core/elements/control-panel-element.d.ts +44 -44
  7. package/dist/bundles/core/elements/control-panel-element.js +99 -99
  8. package/dist/bundles/core/elements/index.d.ts +12 -12
  9. package/dist/bundles/core/elements/index.js +13 -13
  10. package/dist/bundles/core/elements/inspector-element.d.ts +26 -26
  11. package/dist/bundles/core/elements/inspector-element.js +58 -58
  12. package/dist/bundles/core/elements/recent-result-item.js +46 -46
  13. package/dist/bundles/core/elements/results-history-item.js +46 -46
  14. package/dist/bundles/core/elements/templates/compat-view.templates.js +462 -462
  15. package/dist/bundles/core/elements/templates/control-panel.templates.js +335 -335
  16. package/dist/bundles/core/elements/templates/root-styles.template.js +40 -40
  17. package/dist/bundles/core/event-bus.d.ts +46 -46
  18. package/dist/bundles/core/event-bus.js +49 -49
  19. package/dist/bundles/core/helpers.js +47 -47
  20. package/dist/bundles/core/index.d.ts +14 -14
  21. package/dist/bundles/core/index.js +16 -16
  22. package/dist/bundles/core/state-service.d.ts +56 -56
  23. package/dist/bundles/core/state-service.js +80 -80
  24. package/dist/bundles/core/ui-component.d.ts +63 -63
  25. package/dist/bundles/core/ui-component.js +71 -71
  26. package/dist/bundles/engine/engine.d.ts +108 -108
  27. package/dist/bundles/engine/engine.js +238 -238
  28. package/dist/bundles/engine/index.js +8 -8
  29. package/dist/bundles/gen/index.js +14 -14
  30. package/dist/bundles/index.d.ts +19 -19
  31. package/dist/bundles/index.js +23 -23
  32. package/dist/bundles/pkg/shinkore.d.ts +50 -50
  33. package/dist/bundles/pkg/shinkore.js +465 -465
  34. package/dist/bundles/pkg/shinkore_bg.wasm +0 -0
  35. package/dist/bundles/shinkom.d.ts +41 -41
  36. package/dist/bundles/shinkom.js +80 -80
  37. package/dist/bundles/ui/compat-ui/compat-ui.d.ts +42 -42
  38. package/dist/bundles/ui/compat-ui/compat-ui.js +59 -59
  39. package/dist/bundles/ui/compat-ui/index.js +8 -8
  40. package/dist/bundles/ui/compatibility-view/compatibility-view.d.ts +41 -41
  41. package/dist/bundles/ui/compatibility-view/compatibility-view.js +229 -229
  42. package/dist/bundles/ui/compatibility-view/index.js +8 -8
  43. package/dist/bundles/ui/control-panel/control-panel.d.ts +52 -52
  44. package/dist/bundles/ui/control-panel/control-panel.js +320 -320
  45. package/dist/bundles/ui/control-panel/index.js +8 -8
  46. package/dist/bundles/ui/index.d.ts +11 -11
  47. package/dist/bundles/ui/index.js +16 -16
  48. package/dist/bundles/ui/inspector/index.js +8 -8
  49. package/dist/bundles/ui/inspector/inspector.d.ts +97 -97
  50. package/dist/bundles/ui/inspector/inspector.js +394 -394
  51. package/dist/modules/core/constants.cjs +17 -17
  52. package/dist/modules/core/elements/compat-view-element.cjs +434 -434
  53. package/dist/modules/core/elements/control-panel-element.cjs +93 -93
  54. package/dist/modules/core/elements/index.cjs +11 -11
  55. package/dist/modules/core/elements/inspector-element.cjs +52 -52
  56. package/dist/modules/core/elements/recent-result-item.cjs +39 -39
  57. package/dist/modules/core/elements/results-history-item.cjs +39 -39
  58. package/dist/modules/core/elements/templates/compat-view.templates.cjs +458 -458
  59. package/dist/modules/core/elements/templates/control-panel.templates.cjs +332 -332
  60. package/dist/modules/core/elements/templates/root-styles.template.cjs +33 -33
  61. package/dist/modules/core/event-bus.cjs +43 -43
  62. package/dist/modules/core/helpers.cjs +41 -41
  63. package/dist/modules/core/index.cjs +16 -16
  64. package/dist/modules/core/state-service.cjs +74 -74
  65. package/dist/modules/core/ui-component.cjs +65 -65
  66. package/dist/modules/engine/engine.cjs +232 -232
  67. package/dist/modules/gen/browser-data.cjs +100 -100
  68. package/dist/modules/gen/browser-usage-data.cjs +675 -675
  69. package/dist/modules/gen/compat-data.cjs +31015 -31015
  70. package/dist/modules/gen/index.cjs +7 -7
  71. package/dist/modules/index.cjs +27 -27
  72. package/dist/modules/pkg/shinkore.cjs +459 -459
  73. package/dist/modules/pkg/shinkore_bg.wasm +0 -0
  74. package/dist/modules/shinkom.cjs +73 -73
  75. package/dist/modules/ui/compat-ui/compat-ui.cjs +53 -53
  76. package/dist/modules/ui/compat-ui/index.cjs +1 -1
  77. package/dist/modules/ui/compatibility-view/compatibility-view.cjs +223 -223
  78. package/dist/modules/ui/compatibility-view/index.cjs +1 -1
  79. package/dist/modules/ui/control-panel/control-panel.cjs +314 -314
  80. package/dist/modules/ui/control-panel/index.cjs +1 -1
  81. package/dist/modules/ui/index.cjs +13 -13
  82. package/dist/modules/ui/inspector/index.cjs +1 -1
  83. package/dist/modules/ui/inspector/inspector.cjs +388 -388
  84. package/package.json +1 -1
@@ -1,440 +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 };
1
+ /**
2
+ * Shinkom - elements
3
+ * @version 1.1.1
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.1";
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 };