shinkom 1.0.3 → 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 +96 -96
- package/dist/bundles/gen/browser-usage-data.js +671 -671
- 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/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/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 +13 -6
- package/dist/bundles/node_modules/@mdn/browser-compat-data/types.d.ts +0 -78
|
@@ -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
|
*/
|
|
@@ -10,6 +10,14 @@ import { ShinkomState } from "./state-service.js";
|
|
|
10
10
|
import { UISharedState as UISharedState$1, UISharedStateProps as UISharedStateProps$1 } from "../types/public.js";
|
|
11
11
|
|
|
12
12
|
//#region src/core/ui-component.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Base UI component class for Shinkom UI modules.
|
|
15
|
+
*
|
|
16
|
+
* UIComponent is abstract and provides shared integration with the Shinkom
|
|
17
|
+
* event bus and shared state service. Subclasses must implement lifecycle
|
|
18
|
+
* methods for mounting, unmounting, binding state, and responding to state
|
|
19
|
+
* changes.
|
|
20
|
+
*/
|
|
13
21
|
declare class UIComponent {
|
|
14
22
|
/**
|
|
15
23
|
* @param {ShinkomBus} bus
|
|
@@ -17,23 +25,34 @@ declare class UIComponent {
|
|
|
17
25
|
*/
|
|
18
26
|
constructor(bus: ShinkomBus, stateService: ShinkomState);
|
|
19
27
|
bus: ShinkomBus;
|
|
28
|
+
stateService: ShinkomState;
|
|
20
29
|
/**
|
|
21
|
-
*
|
|
30
|
+
* Mounts the component into the DOM.
|
|
31
|
+
*
|
|
32
|
+
* Subclasses must implement this method to create and attach their UI.
|
|
22
33
|
*/
|
|
23
34
|
mount(): void;
|
|
24
35
|
/**
|
|
25
|
-
*
|
|
36
|
+
* Unmounts the component from the DOM.
|
|
37
|
+
*
|
|
38
|
+
* Subclasses must implement this method to remove their UI and cleanup.
|
|
26
39
|
*/
|
|
27
40
|
unmount(): void;
|
|
28
41
|
/**
|
|
29
|
-
*
|
|
42
|
+
* Binds shared UI state to the component instance.
|
|
43
|
+
*
|
|
44
|
+
* Implementations should store the bound state reference and apply any
|
|
45
|
+
* initial state values needed by the component.
|
|
30
46
|
*
|
|
31
|
-
* Sets any initial state defined by the component.
|
|
32
47
|
* @param {UISharedState} _state
|
|
33
48
|
*/
|
|
34
49
|
bindState(_state: UISharedState): void;
|
|
35
50
|
/**
|
|
36
|
-
*
|
|
51
|
+
* Called when a shared state property changes.
|
|
52
|
+
*
|
|
53
|
+
* Components should override this to react to updates from the shared state
|
|
54
|
+
* service.
|
|
55
|
+
*
|
|
37
56
|
* @param {UISharedStateProps} _prop
|
|
38
57
|
* @param {any} _val
|
|
39
58
|
*/
|
|
@@ -1,48 +1,67 @@
|
|
|
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
|
*/
|
|
7
7
|
|
|
8
8
|
//#region src/core/ui-component.js
|
|
9
|
+
/**
|
|
10
|
+
* Base UI component class for Shinkom UI modules.
|
|
11
|
+
*
|
|
12
|
+
* UIComponent is abstract and provides shared integration with the Shinkom
|
|
13
|
+
* event bus and shared state service. Subclasses must implement lifecycle
|
|
14
|
+
* methods for mounting, unmounting, binding state, and responding to state
|
|
15
|
+
* changes.
|
|
16
|
+
*/
|
|
9
17
|
var UIComponent = class UIComponent {
|
|
10
18
|
/**
|
|
11
|
-
* @param {ShinkomBus} bus
|
|
12
|
-
* @param {ShinkomState} stateService
|
|
19
|
+
* @param {ShinkomBus} bus
|
|
20
|
+
* @param {ShinkomState} stateService
|
|
13
21
|
*/
|
|
14
22
|
constructor(bus, stateService) {
|
|
15
23
|
if (this.constructor === UIComponent) throw new Error("UIComponent is an abstract class and cannot be instantiated.");
|
|
16
24
|
this.bus = bus;
|
|
25
|
+
this.stateService = stateService;
|
|
17
26
|
stateService.subscribe((prop, val) => {
|
|
18
27
|
this.onStateChange(prop, val);
|
|
19
28
|
});
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
31
|
+
* Mounts the component into the DOM.
|
|
32
|
+
*
|
|
33
|
+
* Subclasses must implement this method to create and attach their UI.
|
|
23
34
|
*/
|
|
24
35
|
mount() {
|
|
25
36
|
throw new Error("mount() method must be implemented.");
|
|
26
37
|
}
|
|
27
38
|
/**
|
|
28
|
-
*
|
|
39
|
+
* Unmounts the component from the DOM.
|
|
40
|
+
*
|
|
41
|
+
* Subclasses must implement this method to remove their UI and cleanup.
|
|
29
42
|
*/
|
|
30
43
|
unmount() {
|
|
31
44
|
throw new Error("unmount() method must be implemented.");
|
|
32
45
|
}
|
|
33
46
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
47
|
+
* Binds shared UI state to the component instance.
|
|
48
|
+
*
|
|
49
|
+
* Implementations should store the bound state reference and apply any
|
|
50
|
+
* initial state values needed by the component.
|
|
51
|
+
*
|
|
52
|
+
* @param {UISharedState} _state
|
|
38
53
|
*/
|
|
39
54
|
bindState(_state) {
|
|
40
55
|
throw new Error("bindState() method must be implemented.");
|
|
41
56
|
}
|
|
42
57
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
58
|
+
* Called when a shared state property changes.
|
|
59
|
+
*
|
|
60
|
+
* Components should override this to react to updates from the shared state
|
|
61
|
+
* service.
|
|
62
|
+
*
|
|
63
|
+
* @param {UISharedStateProps} _prop
|
|
64
|
+
* @param {any} _val
|
|
46
65
|
*/
|
|
47
66
|
onStateChange(_prop, _val) {
|
|
48
67
|
throw new Error("onStateChange() method must be implemented.");
|
|
@@ -1,56 +1,104 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shinkom - engine
|
|
3
|
-
* @version 1.0
|
|
3
|
+
* @version 1.1.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - OneilNvM
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { ShinkomBus } from "../core/event-bus.js";
|
|
9
|
-
import {
|
|
9
|
+
import { CustomEventEngineDetail as CustomEventEngineDetail$1 } from "../types/types.js";
|
|
10
|
+
import { CompatResult as CompatResult$1 } from "../types/public.js";
|
|
10
11
|
import { CompatEngine } from "../pkg/shinkore.js";
|
|
11
12
|
|
|
12
13
|
//#region src/engine/engine.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* SKEngine wraps the Shinkom compatibility analysis engine.
|
|
16
|
+
*
|
|
17
|
+
* It manages WASM loading, engine initialization, and compatibility checks
|
|
18
|
+
* for single elements, element subtrees, and full pages. When a `ShinkomBus`
|
|
19
|
+
* instance is provided, SKEngine also emits result events and responds to
|
|
20
|
+
* engine commands from the UI.
|
|
21
|
+
*/
|
|
13
22
|
declare class SKEngine {
|
|
14
23
|
/**
|
|
24
|
+
* Clears the instance from memory.
|
|
25
|
+
*/
|
|
26
|
+
static clearInstance(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes the compatibility engine.
|
|
29
|
+
*
|
|
30
|
+
* The engine optionally accepts an event bus to listen for
|
|
31
|
+
* `engine:inspect` and `engine:full` events from UI
|
|
32
|
+
* components.
|
|
33
|
+
*
|
|
15
34
|
* @param {ShinkomBus | null} bus
|
|
16
35
|
*/
|
|
17
36
|
constructor(bus?: ShinkomBus | null);
|
|
37
|
+
initialized: boolean | undefined;
|
|
18
38
|
/**@type {CompatEngine | null} */
|
|
19
39
|
compatEngine: CompatEngine | null;
|
|
20
40
|
/**@type {ShinkomBus | null} */
|
|
21
41
|
bus: ShinkomBus | null;
|
|
42
|
+
/**@type {(() => void)[]} */
|
|
43
|
+
unsubEvents: (() => void)[];
|
|
22
44
|
/**
|
|
23
|
-
*
|
|
45
|
+
* Gets the instance of the engine.
|
|
46
|
+
* @returns {SKEngine} the instance
|
|
47
|
+
*/
|
|
48
|
+
getInstance(): SKEngine;
|
|
49
|
+
/**
|
|
50
|
+
* Loads the WASM runtime and initializes the native Shinkom engine.
|
|
51
|
+
*
|
|
52
|
+
* In Node.js this resolves the module path and loads the WASM binary from
|
|
53
|
+
* the local filesystem. In browser environments it optionally accepts a
|
|
54
|
+
* WASM URL or falls back to the default packaged module loader.
|
|
55
|
+
*
|
|
24
56
|
* @param {string | undefined} wasmURL
|
|
25
57
|
*/
|
|
26
58
|
loadWasm(wasmURL?: string | undefined): Promise<void>;
|
|
27
59
|
/**
|
|
28
|
-
* Initializes Rust
|
|
60
|
+
* Initializes the Rust-based compatibility engine.
|
|
61
|
+
*
|
|
62
|
+
* The engine is created after the WASM runtime has been loaded and is
|
|
63
|
+
* configured with the bundled compatibility data.
|
|
64
|
+
*
|
|
29
65
|
* @param {string | undefined} wasmURL
|
|
30
66
|
*/
|
|
31
67
|
initEngine(wasmURL?: string | undefined): Promise<void>;
|
|
32
68
|
/**
|
|
33
|
-
*
|
|
69
|
+
* Checks compatibility for a single element HTML string.
|
|
70
|
+
*
|
|
71
|
+
* If a bus was provided at construction, the resulting compatibility data
|
|
72
|
+
* is emitted on `results:ready`.
|
|
73
|
+
*
|
|
34
74
|
* @param {string} element
|
|
35
75
|
* @returns {CompatResult | null}
|
|
36
76
|
*/
|
|
37
77
|
checkElement(element: string): CompatResult | null;
|
|
38
78
|
/**
|
|
39
|
-
*
|
|
79
|
+
* Checks compatibility for a subtree of HTML elements.
|
|
80
|
+
*
|
|
81
|
+
* The `depthLevel` controls how deeply nested elements are inspected.
|
|
82
|
+
*
|
|
40
83
|
* @param {string} html
|
|
41
84
|
* @param {number} depthLevel
|
|
42
85
|
* @returns {CompatResult | null}
|
|
43
86
|
*/
|
|
44
87
|
checkElements(html: string, depthLevel: number): CompatResult | null;
|
|
45
88
|
/**
|
|
46
|
-
*
|
|
89
|
+
* Checks compatibility for the current full document page.
|
|
90
|
+
*
|
|
91
|
+
* This method is browser-only because it depends on `document` and
|
|
92
|
+
* inspects the serialized page HTML.
|
|
47
93
|
*
|
|
48
|
-
* Only available in `browser` environments.
|
|
49
94
|
* @returns {CompatResult | null}
|
|
50
95
|
*/
|
|
51
96
|
fullInspect(): CompatResult | null;
|
|
52
97
|
/**
|
|
53
|
-
*
|
|
98
|
+
* Releases WASM resources and destroys the engine instance.
|
|
99
|
+
*
|
|
100
|
+
* After calling this method, the engine must be reinitialized before
|
|
101
|
+
* further compatibility checks can be performed.
|
|
54
102
|
*/
|
|
55
103
|
destroy(): void;
|
|
56
104
|
#private;
|
|
@@ -1,41 +1,98 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shinkom - engine
|
|
3
|
-
* @version 1.0
|
|
3
|
+
* @version 1.1.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - OneilNvM
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { getModulePath } from "../core/helpers.js";
|
|
8
9
|
import { CompatEngine, __wbg_init } from "../pkg/shinkore.js";
|
|
9
10
|
import browser_data_default from "../gen/browser-data.js";
|
|
10
11
|
import browser_usage_data_default from "../gen/browser-usage-data.js";
|
|
11
12
|
import gen_default from "../gen/index.js";
|
|
12
|
-
import { getModulePath } from "../core/helpers.js";
|
|
13
13
|
//#region src/engine/engine.js
|
|
14
|
-
/**@typedef {import('../types/
|
|
14
|
+
/**@typedef {import('../types/types').CustomEventEngineDetail} CustomEventEngineDetail */
|
|
15
15
|
/**@typedef {import('../types/public').CompatResult} CompatResult */
|
|
16
|
-
|
|
16
|
+
/**@type {SKEngine | null} */
|
|
17
|
+
let instance = null;
|
|
18
|
+
/**
|
|
19
|
+
* SKEngine wraps the Shinkom compatibility analysis engine.
|
|
20
|
+
*
|
|
21
|
+
* It manages WASM loading, engine initialization, and compatibility checks
|
|
22
|
+
* for single elements, element subtrees, and full pages. When a `ShinkomBus`
|
|
23
|
+
* instance is provided, SKEngine also emits result events and responds to
|
|
24
|
+
* engine commands from the UI.
|
|
25
|
+
*/
|
|
26
|
+
var SKEngine = class SKEngine {
|
|
17
27
|
/**@type {Promise<void> | null} */
|
|
18
28
|
#wasmLoaded = null;
|
|
19
29
|
/**
|
|
30
|
+
* Initializes the compatibility engine.
|
|
31
|
+
*
|
|
32
|
+
* The engine optionally accepts an event bus to listen for
|
|
33
|
+
* `engine:inspect` and `engine:full` events from UI
|
|
34
|
+
* components.
|
|
35
|
+
*
|
|
20
36
|
* @param {ShinkomBus | null} bus
|
|
21
37
|
*/
|
|
22
38
|
constructor(bus = null) {
|
|
39
|
+
if (instance) return instance;
|
|
40
|
+
this.initialized = false;
|
|
23
41
|
/**@type {CompatEngine | null} */
|
|
24
42
|
this.compatEngine = null;
|
|
25
43
|
/**@type {ShinkomBus | null} */
|
|
26
44
|
this.bus = bus;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
/**@type {(() => void)[]} */
|
|
46
|
+
this.unsubEvents = [];
|
|
47
|
+
instance = this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the instance of the engine.
|
|
51
|
+
* @returns {SKEngine} the instance
|
|
52
|
+
*/
|
|
53
|
+
getInstance() {
|
|
54
|
+
if (!instance) instance = this;
|
|
55
|
+
return instance;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clears the instance from memory.
|
|
59
|
+
*/
|
|
60
|
+
static clearInstance() {
|
|
61
|
+
instance = null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Subscribes the engine to UI-driven bus commands.
|
|
65
|
+
*
|
|
66
|
+
* The engine listens for `engine:inspect` and `engine:full` events and
|
|
67
|
+
* translates them into compatibility checks.
|
|
68
|
+
*/
|
|
69
|
+
#setupEventBusListeners() {
|
|
70
|
+
if (this.bus) this.unsubEvents.push(this.bus.on("engine:inspect", (e) => {
|
|
71
|
+
if (typeof e === "object") if (e.multiElements) this.checkElements(e.elem, e.depthLevel);
|
|
72
|
+
else this.checkElement(e.elem);
|
|
73
|
+
}), this.bus.on("engine:full", () => {
|
|
74
|
+
this.fullInspect();
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Unsubscribes from any registered bus listeners.
|
|
79
|
+
*
|
|
80
|
+
* This is called when the engine is destroyed so that no stale callbacks
|
|
81
|
+
* remain attached to the shared event bus.
|
|
82
|
+
*/
|
|
83
|
+
#cleanupEventBusListeners() {
|
|
84
|
+
if (this.unsubEvents.length > 0) {
|
|
85
|
+
this.unsubEvents.forEach((cleanup) => cleanup());
|
|
86
|
+
this.unsubEvents = [];
|
|
35
87
|
}
|
|
36
88
|
}
|
|
37
89
|
/**
|
|
38
|
-
* Loads WASM
|
|
90
|
+
* Loads the WASM runtime and initializes the native Shinkom engine.
|
|
91
|
+
*
|
|
92
|
+
* In Node.js this resolves the module path and loads the WASM binary from
|
|
93
|
+
* the local filesystem. In browser environments it optionally accepts a
|
|
94
|
+
* WASM URL or falls back to the default packaged module loader.
|
|
95
|
+
*
|
|
39
96
|
* @param {string | undefined} wasmURL
|
|
40
97
|
*/
|
|
41
98
|
async loadWasm(wasmURL = void 0) {
|
|
@@ -70,27 +127,40 @@ var SKEngine = class {
|
|
|
70
127
|
}
|
|
71
128
|
}
|
|
72
129
|
/**
|
|
73
|
-
* Initializes Rust
|
|
130
|
+
* Initializes the Rust-based compatibility engine.
|
|
131
|
+
*
|
|
132
|
+
* The engine is created after the WASM runtime has been loaded and is
|
|
133
|
+
* configured with the bundled compatibility data.
|
|
134
|
+
*
|
|
74
135
|
* @param {string | undefined} wasmURL
|
|
75
136
|
*/
|
|
76
137
|
async initEngine(wasmURL = void 0) {
|
|
138
|
+
if (this.initialized) {
|
|
139
|
+
console.warn("SKEngine is already initialized.");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (this.unsubEvents.length === 0) this.#setupEventBusListeners();
|
|
77
143
|
try {
|
|
78
144
|
if (!this.compatEngine) {
|
|
79
|
-
if (!this.#wasmLoaded)
|
|
80
|
-
|
|
81
|
-
if (wasmURL) await this.loadWasm(wasmURL);
|
|
82
|
-
else await this.loadWasm();
|
|
83
|
-
}
|
|
145
|
+
if (!this.#wasmLoaded) if (wasmURL) await this.loadWasm(wasmURL);
|
|
146
|
+
else await this.loadWasm();
|
|
84
147
|
this.compatEngine = new CompatEngine(gen_default.html, gen_default.svg, browser_data_default, browser_usage_data_default);
|
|
148
|
+
this.initialized = true;
|
|
149
|
+
this.getInstance();
|
|
85
150
|
console.log("initialized engine");
|
|
86
151
|
}
|
|
87
152
|
} catch (error) {
|
|
88
153
|
console.error(`Engine initialization error: ${error}`);
|
|
154
|
+
SKEngine.clearInstance();
|
|
89
155
|
}
|
|
90
156
|
}
|
|
91
157
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
158
|
+
* Checks compatibility for a single element HTML string.
|
|
159
|
+
*
|
|
160
|
+
* If a bus was provided at construction, the resulting compatibility data
|
|
161
|
+
* is emitted on `results:ready`.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} element
|
|
94
164
|
* @returns {CompatResult | null}
|
|
95
165
|
*/
|
|
96
166
|
checkElement(element) {
|
|
@@ -98,6 +168,7 @@ var SKEngine = class {
|
|
|
98
168
|
/**@type {CompatResult} */
|
|
99
169
|
const result = this.compatEngine?.check_element(element);
|
|
100
170
|
console.dir(result);
|
|
171
|
+
if (this.bus) this.bus.emit("results:ready", { detail: result });
|
|
101
172
|
return result;
|
|
102
173
|
} catch (error) {
|
|
103
174
|
console.error(error);
|
|
@@ -105,15 +176,19 @@ var SKEngine = class {
|
|
|
105
176
|
}
|
|
106
177
|
}
|
|
107
178
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
179
|
+
* Checks compatibility for a subtree of HTML elements.
|
|
180
|
+
*
|
|
181
|
+
* The `depthLevel` controls how deeply nested elements are inspected.
|
|
182
|
+
*
|
|
183
|
+
* @param {string} html
|
|
184
|
+
* @param {number} depthLevel
|
|
111
185
|
* @returns {CompatResult | null}
|
|
112
186
|
*/
|
|
113
187
|
checkElements(html, depthLevel) {
|
|
114
188
|
try {
|
|
115
189
|
const result = this.compatEngine?.check_elements(html, depthLevel);
|
|
116
190
|
console.dir(result);
|
|
191
|
+
if (this.bus) this.bus.emit("results:ready", { detail: result });
|
|
117
192
|
return result;
|
|
118
193
|
} catch (error) {
|
|
119
194
|
console.error(error);
|
|
@@ -121,15 +196,18 @@ var SKEngine = class {
|
|
|
121
196
|
}
|
|
122
197
|
}
|
|
123
198
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
199
|
+
* Checks compatibility for the current full document page.
|
|
200
|
+
*
|
|
201
|
+
* This method is browser-only because it depends on `document` and
|
|
202
|
+
* inspects the serialized page HTML.
|
|
203
|
+
*
|
|
127
204
|
* @returns {CompatResult | null}
|
|
128
205
|
*/
|
|
129
206
|
fullInspect() {
|
|
130
207
|
try {
|
|
131
|
-
const result = this.compatEngine?.full_inspect(document.documentElement.outerHTML);
|
|
208
|
+
const result = this.compatEngine?.full_inspect(document.documentElement.outerHTML.replace(/<sk-[\w-]+><\/sk-[\w-]+>/g, ""));
|
|
132
209
|
console.dir(result);
|
|
210
|
+
if (this.bus) this.bus.emit("results:ready", { detail: result });
|
|
133
211
|
return result;
|
|
134
212
|
} catch (error) {
|
|
135
213
|
if (error instanceof ReferenceError) console.error("fullInspect is only available in browser environments");
|
|
@@ -138,16 +216,22 @@ var SKEngine = class {
|
|
|
138
216
|
}
|
|
139
217
|
}
|
|
140
218
|
/**
|
|
141
|
-
*
|
|
219
|
+
* Releases WASM resources and destroys the engine instance.
|
|
220
|
+
*
|
|
221
|
+
* After calling this method, the engine must be reinitialized before
|
|
222
|
+
* further compatibility checks can be performed.
|
|
142
223
|
*/
|
|
143
224
|
destroy() {
|
|
144
|
-
if (!this.
|
|
145
|
-
console.warn("
|
|
225
|
+
if (!this.initialized) {
|
|
226
|
+
console.warn("SKEngine has not been initialized.");
|
|
146
227
|
return;
|
|
147
228
|
}
|
|
148
229
|
this.compatEngine?.free();
|
|
230
|
+
this.#cleanupEventBusListeners();
|
|
149
231
|
this.#wasmLoaded = null;
|
|
150
232
|
this.compatEngine = null;
|
|
233
|
+
this.initialized = false;
|
|
234
|
+
SKEngine.clearInstance();
|
|
151
235
|
}
|
|
152
236
|
};
|
|
153
237
|
//#endregion
|