@lynx-js/web-core-wasm-canary 0.0.0 → 0.0.1-canary-20260116-ce265e8f
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/CHANGELOG.md +8 -0
- package/{LICENSE → LICENSE.txt} +1 -1
- package/Notice.txt +1 -0
- package/README.md +1 -0
- package/binary/client/client.d.ts +263 -0
- package/binary/client/client.js +1339 -0
- package/binary/client/client_bg.wasm +0 -0
- package/binary/client/client_bg.wasm.d.ts +70 -0
- package/binary/client/client_debug.d.ts +263 -0
- package/binary/client/client_debug.js +1339 -0
- package/binary/client/client_debug_bg.wasm +0 -0
- package/binary/client/client_debug_bg.wasm.d.ts +70 -0
- package/binary/encode/encode.d.ts +157 -0
- package/binary/encode/encode.js +17 -0
- package/binary/encode/encode_bg.js +749 -0
- package/binary/encode/encode_bg.wasm +0 -0
- package/binary/encode/encode_bg.wasm.d.ts +50 -0
- package/binary/encode/encode_debug.d.ts +157 -0
- package/binary/encode/encode_debug.js +17 -0
- package/binary/encode/encode_debug_bg.js +822 -0
- package/binary/encode/encode_debug_bg.wasm +0 -0
- package/binary/encode/encode_debug_bg.wasm.d.ts +50 -0
- package/binary/encode/package.json +4 -0
- package/css/in_shadow.css +10 -0
- package/css/index.css +119 -0
- package/dist/client/LynxCrossThreadContext.d.ts +22 -0
- package/dist/client/LynxCrossThreadContext.js +44 -0
- package/dist/client/background/background-apis/createBackgroundLynx.d.ts +24 -0
- package/dist/client/background/background-apis/createBackgroundLynx.js +38 -0
- package/dist/client/background/background-apis/createChunkLoading.d.ts +7 -0
- package/dist/client/background/background-apis/createChunkLoading.js +66 -0
- package/dist/client/background/background-apis/createElement.d.ts +5 -0
- package/dist/client/background/background-apis/createElement.js +18 -0
- package/dist/client/background/background-apis/createNapiLoader.d.ts +5 -0
- package/dist/client/background/background-apis/createNapiLoader.js +23 -0
- package/dist/client/background/background-apis/createNativeApp.d.ts +4 -0
- package/dist/client/background/background-apis/createNativeApp.js +98 -0
- package/dist/client/background/background-apis/createNativeModules.d.ts +3 -0
- package/dist/client/background/background-apis/createNativeModules.js +33 -0
- package/dist/client/background/background-apis/createPerformanceApis.d.ts +3 -0
- package/dist/client/background/background-apis/createPerformanceApis.js +47 -0
- package/dist/client/background/background-apis/createTimingSystem.d.ts +8 -0
- package/dist/client/background/background-apis/createTimingSystem.js +86 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.js +14 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.js +23 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.js +24 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.d.ts +2 -0
- package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.js +12 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.js +9 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.js +8 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.js +8 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.js +10 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.js +5 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.js +5 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.d.ts +3 -0
- package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.js +9 -0
- package/dist/client/background/background-apis/startBackgroundThread.d.ts +2 -0
- package/dist/client/background/background-apis/startBackgroundThread.js +42 -0
- package/dist/client/background/index.d.ts +1 -0
- package/dist/client/background/index.js +15 -0
- package/dist/client/decodeWorker/cssLoader.d.ts +12 -0
- package/dist/client/decodeWorker/cssLoader.js +96 -0
- package/dist/client/decodeWorker/decode.worker.d.ts +1 -0
- package/dist/client/decodeWorker/decode.worker.js +338 -0
- package/dist/client/decodeWorker/types.d.ts +32 -0
- package/dist/client/decodeWorker/types.js +2 -0
- package/dist/client/endpoints.d.ts +53 -0
- package/dist/client/endpoints.js +37 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +3 -0
- package/dist/client/mainthread/Background.d.ts +30 -0
- package/dist/client/mainthread/Background.js +207 -0
- package/dist/client/mainthread/ExposureServices.d.ts +11 -0
- package/dist/client/mainthread/ExposureServices.js +211 -0
- package/dist/client/mainthread/I18n.d.ts +9 -0
- package/dist/client/mainthread/I18n.js +44 -0
- package/dist/client/mainthread/LynxView.d.ts +170 -0
- package/dist/client/mainthread/LynxView.js +367 -0
- package/dist/client/mainthread/LynxViewInstance.d.ts +56 -0
- package/dist/client/mainthread/LynxViewInstance.js +196 -0
- package/dist/client/mainthread/StyleManager.d.ts +15 -0
- package/dist/client/mainthread/StyleManager.js +72 -0
- package/dist/client/mainthread/TemplateManager.d.ts +11 -0
- package/dist/client/mainthread/TemplateManager.js +257 -0
- package/dist/client/mainthread/createIFrameRealm.d.ts +6 -0
- package/dist/client/mainthread/createIFrameRealm.js +68 -0
- package/dist/client/mainthread/createMainThreadGlobalAPIs.d.ts +3 -0
- package/dist/client/mainthread/createMainThreadGlobalAPIs.js +82 -0
- package/dist/client/mainthread/crossThreadHandlers/queryNodes.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/queryNodes.js +74 -0
- package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.js +51 -0
- package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.js +49 -0
- package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.js +8 -0
- package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.js +7 -0
- package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.js +20 -0
- package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.js +28 -0
- package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.js +12 -0
- package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.d.ts +3 -0
- package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js +29 -0
- package/dist/client/mainthread/elementAPIs/WASMJSBinding.d.ts +38 -0
- package/dist/client/mainthread/elementAPIs/WASMJSBinding.js +122 -0
- package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.d.ts +2 -0
- package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.js +77 -0
- package/dist/client/mainthread/elementAPIs/createElementAPI.d.ts +3 -0
- package/dist/client/mainthread/elementAPIs/createElementAPI.js +346 -0
- package/dist/client/mainthread/elementAPIs/index.d.ts +2 -0
- package/dist/client/mainthread/elementAPIs/index.js +3 -0
- package/dist/client/mainthread/elementAPIs/pureElementPAPIs.d.ts +26 -0
- package/dist/client/mainthread/elementAPIs/pureElementPAPIs.js +85 -0
- package/dist/client/mainthread/utils/convertLengthToPx.d.ts +1 -0
- package/dist/client/mainthread/utils/convertLengthToPx.js +25 -0
- package/dist/client/wasm.d.ts +11 -0
- package/dist/client/wasm.js +52 -0
- package/dist/client/webElementsDynamicLoader.d.ts +8 -0
- package/dist/client/webElementsDynamicLoader.js +80 -0
- package/dist/client_prod/static/css/async/web-core-main-chunk.css +1 -0
- package/dist/client_prod/static/css/client.css +1 -0
- package/dist/client_prod/static/js/async/lynx-core-chunk.js +3 -0
- package/dist/client_prod/static/js/async/web-core-main-chunk.js +303 -0
- package/dist/client_prod/static/js/async/web-core-template-loader-thread.js +8 -0
- package/dist/client_prod/static/js/async/web-core-worker-chunk.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-audio.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-foldview.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-input.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-list.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-overlay.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-refrshview.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-swiper.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-textarea.js +1 -0
- package/dist/client_prod/static/js/async/web-elements-viewpager.js +1 -0
- package/dist/client_prod/static/js/client.js +2 -0
- package/dist/client_prod/static/wasm/7ff75609.module.wasm +0 -0
- package/dist/constants.d.ts +58 -0
- package/dist/constants.js +114 -0
- package/dist/encode/encodeCSS.d.ts +3 -0
- package/dist/encode/encodeCSS.js +99 -0
- package/dist/encode/encodeElementTemplate.d.ts +2 -0
- package/dist/encode/encodeElementTemplate.js +52 -0
- package/dist/encode/index.d.ts +1 -0
- package/dist/encode/index.js +7 -0
- package/dist/encode/webEncoder.d.ts +21 -0
- package/dist/encode/webEncoder.js +125 -0
- package/dist/types/BTSChunk.d.ts +3 -0
- package/dist/types/BTSChunk.js +5 -0
- package/dist/types/Cloneable.d.ts +2 -0
- package/dist/types/Cloneable.js +2 -0
- package/dist/types/DecodedTemplate.d.ts +10 -0
- package/dist/types/DecodedTemplate.js +7 -0
- package/dist/types/Element.d.ts +35 -0
- package/dist/types/Element.js +5 -0
- package/dist/types/ElementTemplateData.d.ts +15 -0
- package/dist/types/ElementTemplateData.js +7 -0
- package/dist/types/EventType.d.ts +56 -0
- package/dist/types/EventType.js +5 -0
- package/dist/types/I18nTypes.d.ts +21 -0
- package/dist/types/I18nTypes.js +2 -0
- package/dist/types/IElementPAPI.d.ts +184 -0
- package/dist/types/IElementPAPI.js +2 -0
- package/dist/types/IMtsBinding.d.ts +11 -0
- package/dist/types/IMtsBinding.js +7 -0
- package/dist/types/JSRealm.d.ts +5 -0
- package/dist/types/JSRealm.js +7 -0
- package/dist/types/LynxContextEventTarget.d.ts +12 -0
- package/dist/types/LynxContextEventTarget.js +5 -0
- package/dist/types/MainThreadLynx.d.ts +15 -0
- package/dist/types/MainThreadLynx.js +2 -0
- package/dist/types/NapiModules.d.ts +9 -0
- package/dist/types/NapiModules.js +5 -0
- package/dist/types/NativeApp.d.ts +120 -0
- package/dist/types/NativeApp.js +5 -0
- package/dist/types/NativeModules.d.ts +2 -0
- package/dist/types/NativeModules.js +5 -0
- package/dist/types/PageConfig.d.ts +9 -0
- package/dist/types/PageConfig.js +2 -0
- package/dist/types/ProcessDataCallback.d.ts +1 -0
- package/dist/types/ProcessDataCallback.js +2 -0
- package/dist/types/TimingAPIs.d.ts +32 -0
- package/dist/types/TimingAPIs.js +5 -0
- package/dist/types/UpdateDataOptions.d.ts +8 -0
- package/dist/types/UpdateDataOptions.js +6 -0
- package/dist/types/WorkerStartMessage.d.ts +14 -0
- package/dist/types/WorkerStartMessage.js +5 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.js +7 -0
- package/eslint.config.js +34 -0
- package/package.json +87 -4
- package/index.js +0 -1
- package/selfIdentity.plist +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright 2025 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { lynxUniqueIdAttribute } from '../../constants.js';
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
import IN_SHADOW_CSS_MODERN from '../../../css/in_shadow.css?inline';
|
|
7
|
+
const IN_SHADOW_CSS = URL.createObjectURL(new Blob([IN_SHADOW_CSS_MODERN], { type: 'text/css' }));
|
|
8
|
+
const IMPORT_CSS_STMT = `@import url("${IN_SHADOW_CSS}");\n`;
|
|
9
|
+
/**
|
|
10
|
+
* There are two modes to manage styles:
|
|
11
|
+
* 1. CSS Selector mode: styles are injected into a <style>, the style manager won't keep track of which styles are applied to which elements.
|
|
12
|
+
* The browser's native CSS selector engine will handle the style application.
|
|
13
|
+
* 2. Non-CSS Selector mode: styles are managed by the style manager, which keeps track of which styles are applied to which elements.
|
|
14
|
+
* The style manager will inject styles into the style sheet of a <style> element. All classes is calculated
|
|
15
|
+
* based on entry_name, css_id, class_name, and applied by using [unique-id="x"] selectors.
|
|
16
|
+
*/
|
|
17
|
+
export class StyleManager {
|
|
18
|
+
#cssQueryMapByEntryName = new Map();
|
|
19
|
+
#cssOGStyleSheet;
|
|
20
|
+
#uniqueIdToStyleDeclarationsMap;
|
|
21
|
+
#rootNode;
|
|
22
|
+
constructor(rootNode) {
|
|
23
|
+
this.#rootNode = rootNode;
|
|
24
|
+
}
|
|
25
|
+
updateCssOgStyle(uniqueId, cssId, classNames, entryName = '__Card__') {
|
|
26
|
+
const classNamesArray = [...classNames];
|
|
27
|
+
const newDeclarations = this.#cssQueryMapByEntryName.get(entryName)
|
|
28
|
+
?.query_css_og_declarations_by_css_id(cssId, classNamesArray) ?? '';
|
|
29
|
+
if (!this.#cssOGStyleSheet) {
|
|
30
|
+
const cssOgStyleElement = document.createElement('style');
|
|
31
|
+
this.#rootNode.appendChild(cssOgStyleElement);
|
|
32
|
+
this.#cssOGStyleSheet = cssOgStyleElement.sheet;
|
|
33
|
+
}
|
|
34
|
+
// update style declaration
|
|
35
|
+
if (this.#cssOGStyleSheet && this.#cssQueryMapByEntryName) {
|
|
36
|
+
if (!this.#uniqueIdToStyleDeclarationsMap) {
|
|
37
|
+
this.#uniqueIdToStyleDeclarationsMap = new Map();
|
|
38
|
+
}
|
|
39
|
+
const styleDeclaration = this.#uniqueIdToStyleDeclarationsMap.get(uniqueId);
|
|
40
|
+
if (styleDeclaration) {
|
|
41
|
+
styleDeclaration.cssText = newDeclarations;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const ruleIndex = this.#cssOGStyleSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"] {${newDeclarations}}`, this.#cssOGStyleSheet.cssRules.length);
|
|
45
|
+
const rule = this.#cssOGStyleSheet.cssRules[ruleIndex];
|
|
46
|
+
this.#uniqueIdToStyleDeclarationsMap.set(uniqueId, rule.style);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
pushStyleSheet(decodedStyle, entryName) {
|
|
51
|
+
const newStyleElement = document.createElement('style');
|
|
52
|
+
let styleElementContent = entryName ? '' : IMPORT_CSS_STMT;
|
|
53
|
+
if (decodedStyle.style_content) {
|
|
54
|
+
styleElementContent += decodedStyle.style_content;
|
|
55
|
+
if (entryName) {
|
|
56
|
+
newStyleElement.setAttribute('name', entryName);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (decodedStyle.font_face_content) {
|
|
60
|
+
const fontFaceStyleElement = document.createElement('style');
|
|
61
|
+
fontFaceStyleElement.textContent = decodedStyle.font_face_content;
|
|
62
|
+
if (entryName) {
|
|
63
|
+
fontFaceStyleElement.setAttribute('name', entryName);
|
|
64
|
+
}
|
|
65
|
+
this.#rootNode.parentElement.appendChild(fontFaceStyleElement);
|
|
66
|
+
}
|
|
67
|
+
this.#cssQueryMapByEntryName.set(entryName || '__Card__', decodedStyle);
|
|
68
|
+
newStyleElement.textContent = styleElementContent;
|
|
69
|
+
this.#rootNode.appendChild(newStyleElement);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=StyleManager.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LynxViewInstance } from './LynxViewInstance.js';
|
|
2
|
+
import type { DecodedTemplate } from '../../types/index.js';
|
|
3
|
+
export declare class TemplateManager {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
fetchBundle(url: string, lynxViewInstancePromise: Promise<LynxViewInstance>, overrideConfig?: Record<string, string>): Promise<void>;
|
|
7
|
+
createTemplate(url: string): void;
|
|
8
|
+
setElementTemplateSection(url: string, section: any): void;
|
|
9
|
+
getTemplate(url: string): DecodedTemplate | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const templateManager: TemplateManager;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 The Lynx Authors. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
import { TemplateSectionLabel } from '../../constants.js';
|
|
7
|
+
const wasm = import(
|
|
8
|
+
/* webpackMode: "eager" */
|
|
9
|
+
/* webpackChunkName: "wasm-initializer" */
|
|
10
|
+
/* webpackFetchPriority: "high" */
|
|
11
|
+
/* webpackPrefetch: true */
|
|
12
|
+
/* webpackPreload: true */
|
|
13
|
+
'../wasm.js');
|
|
14
|
+
export class TemplateManager {
|
|
15
|
+
#templates = new Map();
|
|
16
|
+
#lynxViewInstancesMap = new Map();
|
|
17
|
+
#pendingResolves = new Map();
|
|
18
|
+
#worker = null;
|
|
19
|
+
#workerReadyPromise = null;
|
|
20
|
+
#resolveWorkerReady = null;
|
|
21
|
+
constructor() {
|
|
22
|
+
this.#ensureWorker();
|
|
23
|
+
}
|
|
24
|
+
fetchBundle(url, lynxViewInstancePromise, overrideConfig) {
|
|
25
|
+
if (this.#templates.has(url) && !overrideConfig) {
|
|
26
|
+
return (async () => {
|
|
27
|
+
const template = this.#templates.get(url);
|
|
28
|
+
const config = (template?.config || {});
|
|
29
|
+
const lynxViewInstance = await lynxViewInstancePromise;
|
|
30
|
+
lynxViewInstance.backgroundThread.markTiming('decode_start');
|
|
31
|
+
lynxViewInstance.onPageConfigReady(config);
|
|
32
|
+
const styleInfo = template?.styleInfo;
|
|
33
|
+
if (styleInfo) {
|
|
34
|
+
lynxViewInstance.onStyleInfoReady(styleInfo, url);
|
|
35
|
+
}
|
|
36
|
+
lynxViewInstance.onMTSScriptsLoaded(url, config.isLazy === 'true');
|
|
37
|
+
lynxViewInstance.onBTSScriptsLoaded(url);
|
|
38
|
+
})();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.createTemplate(url);
|
|
42
|
+
return this.#load(url, lynxViewInstancePromise, overrideConfig);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async #load(url, lynxViewInstancePromise, overrideConfig) {
|
|
46
|
+
const currentTime = performance.now() + performance.timeOrigin;
|
|
47
|
+
lynxViewInstancePromise.then((instance) => {
|
|
48
|
+
instance.backgroundThread.markTiming('fetch_start', undefined, currentTime);
|
|
49
|
+
});
|
|
50
|
+
this.#lynxViewInstancesMap.set(url, lynxViewInstancePromise);
|
|
51
|
+
await this.#ensureWorker();
|
|
52
|
+
const msg = {
|
|
53
|
+
type: 'load',
|
|
54
|
+
url,
|
|
55
|
+
fetchUrl: (new URL(url, location.href)).toString(),
|
|
56
|
+
overrideConfig,
|
|
57
|
+
};
|
|
58
|
+
this.#worker.postMessage(msg);
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
this.#pendingResolves.set(url, { resolve, reject });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
#resolvePromise(url) {
|
|
64
|
+
const promise = this.#pendingResolves.get(url);
|
|
65
|
+
if (promise) {
|
|
66
|
+
promise.resolve();
|
|
67
|
+
this.#pendingResolves.delete(url);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
#rejectPromise(url, reason) {
|
|
71
|
+
const promise = this.#pendingResolves.get(url);
|
|
72
|
+
if (promise) {
|
|
73
|
+
promise.reject(reason);
|
|
74
|
+
this.#pendingResolves.delete(url);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
#ensureWorker() {
|
|
78
|
+
if (!this.#worker) {
|
|
79
|
+
this.#workerReadyPromise = new Promise((resolve) => {
|
|
80
|
+
this.#resolveWorkerReady = resolve;
|
|
81
|
+
});
|
|
82
|
+
this.#worker = new Worker(new URL(
|
|
83
|
+
/* webpackFetchPriority: "high" */
|
|
84
|
+
/* webpackChunkName: "web-core-template-loader-thread" */
|
|
85
|
+
/* webpackPrefetch: true */
|
|
86
|
+
/* webpackPreload: true */
|
|
87
|
+
'../decodeWorker/decode.worker.js', import.meta.url), { type: 'module' });
|
|
88
|
+
this.#worker.onmessage = this.#handleMessage.bind(this);
|
|
89
|
+
this.#workerReadyPromise.then(() => {
|
|
90
|
+
wasm.then(({ wasmModule }) => {
|
|
91
|
+
this.#worker.postMessage({
|
|
92
|
+
type: 'init',
|
|
93
|
+
wasmModule,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return this.#workerReadyPromise;
|
|
98
|
+
}
|
|
99
|
+
else if (this.#workerReadyPromise) {
|
|
100
|
+
return this.#workerReadyPromise;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#handleMessage(event) {
|
|
104
|
+
const msg = event.data;
|
|
105
|
+
if (msg.type === 'ready') {
|
|
106
|
+
if (this.#resolveWorkerReady) {
|
|
107
|
+
this.#resolveWorkerReady();
|
|
108
|
+
this.#resolveWorkerReady = null;
|
|
109
|
+
this.#workerReadyPromise = null;
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const { url } = msg;
|
|
114
|
+
const lynxViewInstancePromise = this.#lynxViewInstancesMap.get(url);
|
|
115
|
+
if (!lynxViewInstancePromise)
|
|
116
|
+
return;
|
|
117
|
+
switch (msg.type) {
|
|
118
|
+
case 'section':
|
|
119
|
+
/**
|
|
120
|
+
* The lynxViewInstance is already awaited the wasm is ready
|
|
121
|
+
*/
|
|
122
|
+
this.#handleSection(msg, lynxViewInstancePromise);
|
|
123
|
+
break;
|
|
124
|
+
case 'error':
|
|
125
|
+
console.error(`Error decoding template ${url}:`, msg.error);
|
|
126
|
+
this.#cleanup(url);
|
|
127
|
+
this.#removeTemplate(url);
|
|
128
|
+
this.#rejectPromise(url, new Error(msg.error));
|
|
129
|
+
break;
|
|
130
|
+
case 'done':
|
|
131
|
+
this.#cleanup(url);
|
|
132
|
+
/* TODO: The promise resolution is deferred inside .then() without error handling.
|
|
133
|
+
*
|
|
134
|
+
*/
|
|
135
|
+
lynxViewInstancePromise.then((instance) => {
|
|
136
|
+
instance.backgroundThread.markTiming('decode_end');
|
|
137
|
+
instance.backgroundThread.markTiming('load_template_start');
|
|
138
|
+
this.#resolvePromise(url);
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async #handleSection(msg, instancePromise) {
|
|
144
|
+
const [instance, { DecodedStyle, ElementTemplateSection },] = await Promise.all([
|
|
145
|
+
instancePromise,
|
|
146
|
+
wasm.then(({ DecodedStyle, wasmInstance }) => ({
|
|
147
|
+
DecodedStyle,
|
|
148
|
+
ElementTemplateSection: wasmInstance.ElementTemplateSection,
|
|
149
|
+
})),
|
|
150
|
+
]);
|
|
151
|
+
const { label, data, url, config } = msg;
|
|
152
|
+
switch (label) {
|
|
153
|
+
case TemplateSectionLabel.Configurations: {
|
|
154
|
+
instance.backgroundThread.markTiming('decode_start');
|
|
155
|
+
this.#setConfig(url, data);
|
|
156
|
+
instance.onPageConfigReady(data);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case TemplateSectionLabel.StyleInfo: {
|
|
160
|
+
const decodedStyle = new DecodedStyle(new Uint8Array(data));
|
|
161
|
+
this.#setStyleInfo(url, decodedStyle);
|
|
162
|
+
instance.onStyleInfoReady(decodedStyle, url);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case TemplateSectionLabel.LepusCode: {
|
|
166
|
+
const blobMap = data;
|
|
167
|
+
this.#setLepusCode(url, blobMap);
|
|
168
|
+
instance.onMTSScriptsLoaded(url, config['isLazy'] === 'true');
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case TemplateSectionLabel.ElementTemplates:
|
|
172
|
+
// data is Uint8Array
|
|
173
|
+
const section = ElementTemplateSection.from_encoded(new Uint8Array(data));
|
|
174
|
+
this.setElementTemplateSection(url, section);
|
|
175
|
+
break;
|
|
176
|
+
case TemplateSectionLabel.CustomSections: {
|
|
177
|
+
this.#setCustomSection(url, data);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case TemplateSectionLabel.Manifest: {
|
|
181
|
+
const blobMap = data;
|
|
182
|
+
this.#setBackgroundCode(url, blobMap);
|
|
183
|
+
instance.onBTSScriptsLoaded(url);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
default:
|
|
187
|
+
throw new Error(`Unknown section label: ${label}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
#cleanup(url) {
|
|
191
|
+
this.#lynxViewInstancesMap.delete(url);
|
|
192
|
+
}
|
|
193
|
+
createTemplate(url) {
|
|
194
|
+
if (this.#templates.has(url)) {
|
|
195
|
+
// remove the template and revoke URLs
|
|
196
|
+
const template = this.#templates.get(url);
|
|
197
|
+
if (template) {
|
|
198
|
+
if (template.lepusCode) {
|
|
199
|
+
for (const blobUrl of Object.values(template.lepusCode)) {
|
|
200
|
+
URL.revokeObjectURL(blobUrl);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (template.backgroundCode) {
|
|
204
|
+
for (const blobUrl of Object.values(template.backgroundCode)) {
|
|
205
|
+
URL.revokeObjectURL(blobUrl);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
this.#templates.delete(url);
|
|
210
|
+
}
|
|
211
|
+
this.#templates.set(url, {});
|
|
212
|
+
}
|
|
213
|
+
#removeTemplate(url) {
|
|
214
|
+
this.#templates.delete(url);
|
|
215
|
+
}
|
|
216
|
+
#setConfig(url, config) {
|
|
217
|
+
const template = this.#templates.get(url);
|
|
218
|
+
if (template) {
|
|
219
|
+
template.config = config;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
#setStyleInfo(url, styleInfo) {
|
|
223
|
+
const template = this.#templates.get(url);
|
|
224
|
+
if (template) {
|
|
225
|
+
template.styleInfo = styleInfo;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
#setLepusCode(url, lepusCode) {
|
|
229
|
+
const template = this.#templates.get(url);
|
|
230
|
+
if (template) {
|
|
231
|
+
template.lepusCode = lepusCode;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
setElementTemplateSection(url, section) {
|
|
235
|
+
const template = this.#templates.get(url);
|
|
236
|
+
if (template) {
|
|
237
|
+
template.elementTemplates = section;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
#setCustomSection(url, customSections) {
|
|
241
|
+
const template = this.#templates.get(url);
|
|
242
|
+
if (template) {
|
|
243
|
+
template.customSections = customSections;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
#setBackgroundCode(url, backgroundCode) {
|
|
247
|
+
const template = this.#templates.get(url);
|
|
248
|
+
if (template) {
|
|
249
|
+
template.backgroundCode = backgroundCode;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
getTemplate(url) {
|
|
253
|
+
return this.#templates.get(url);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export const templateManager = new TemplateManager();
|
|
257
|
+
//# sourceMappingURL=TemplateManager.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2025 The Lynx Authors. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
const existingScript = document.querySelector('script[nonce]');
|
|
7
|
+
const nonce = existingScript?.nonce || existingScript?.getAttribute('nonce');
|
|
8
|
+
/**
|
|
9
|
+
* Creates a isolated JavaScript context for executing mts code.
|
|
10
|
+
* This context has its own global variables and functions.
|
|
11
|
+
*/
|
|
12
|
+
export async function createIFrameRealm(parent) {
|
|
13
|
+
const iframe = document.createElement('iframe');
|
|
14
|
+
const iframeReadyPromise = new Promise((resolve) => {
|
|
15
|
+
const listener = (event) => {
|
|
16
|
+
if (event.data === 'lynx:mtsready' && event.source === iframe.contentWindow) {
|
|
17
|
+
resolve();
|
|
18
|
+
globalThis.removeEventListener('message', listener);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
globalThis.addEventListener('message', listener);
|
|
22
|
+
});
|
|
23
|
+
iframe.style.display = 'none';
|
|
24
|
+
iframe.srcdoc =
|
|
25
|
+
'<!DOCTYPE html><html><head><script>parent.postMessage("lynx:mtsready","*")</script></head><body style="display:none"></body></html>';
|
|
26
|
+
iframe.sandbox = 'allow-same-origin allow-scripts'; // Restrict capabilities for security
|
|
27
|
+
iframe.loading = 'eager';
|
|
28
|
+
parent.appendChild(iframe);
|
|
29
|
+
await iframeReadyPromise;
|
|
30
|
+
const iframeWindow = iframe.contentWindow;
|
|
31
|
+
const loadScript = async (url) => {
|
|
32
|
+
const script = iframe.contentDocument.createElement('script');
|
|
33
|
+
script.fetchPriority = 'high';
|
|
34
|
+
script.defer = true;
|
|
35
|
+
script.async = false;
|
|
36
|
+
script.nonce = nonce || '';
|
|
37
|
+
iframe.contentDocument.head.appendChild(script);
|
|
38
|
+
return new Promise(async (resolve, reject) => {
|
|
39
|
+
script.onload = () => {
|
|
40
|
+
const ret = iframeWindow?.module?.exports;
|
|
41
|
+
iframeWindow.module = { exports: undefined };
|
|
42
|
+
resolve(ret);
|
|
43
|
+
};
|
|
44
|
+
script.onerror = (err) => reject(new Error(`Failed to load script: ${url}`, { cause: err }));
|
|
45
|
+
iframeWindow.module = { exports: undefined };
|
|
46
|
+
script.src = url;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const loadScriptSync = (url) => {
|
|
50
|
+
const xhr = new XMLHttpRequest();
|
|
51
|
+
xhr.open('GET', url, false); // Synchronous request
|
|
52
|
+
xhr.send(null);
|
|
53
|
+
if (xhr.status === 200) {
|
|
54
|
+
const script = iframe.contentDocument.createElement('script');
|
|
55
|
+
script.textContent = xhr.responseText;
|
|
56
|
+
iframeWindow.module = { exports: undefined };
|
|
57
|
+
iframe.contentDocument.head.appendChild(script);
|
|
58
|
+
const ret = iframeWindow?.module?.exports;
|
|
59
|
+
iframeWindow.module = { exports: undefined };
|
|
60
|
+
return ret;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error(`Failed to load script: ${url}`, { cause: xhr });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return { globalWindow: iframeWindow, loadScript, loadScriptSync };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=createIFrameRealm.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 The Lynx Authors. All rights reserved.
|
|
3
|
+
* Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
import { templateManager } from './TemplateManager.js';
|
|
7
|
+
import { systemInfo } from './LynxViewInstance.js';
|
|
8
|
+
function createMainThreadLynx(lynxViewInstance) {
|
|
9
|
+
const requestAnimationFrameBrowserImpl = requestAnimationFrame;
|
|
10
|
+
const cancelAnimationFrameBrowserImpl = cancelAnimationFrame;
|
|
11
|
+
const setTimeoutBrowserImpl = setTimeout;
|
|
12
|
+
const clearTimeoutBrowserImpl = clearTimeout;
|
|
13
|
+
const setIntervalBrowserImpl = setInterval;
|
|
14
|
+
const clearIntervalBrowserImpl = clearInterval;
|
|
15
|
+
return {
|
|
16
|
+
getJSContext() {
|
|
17
|
+
return lynxViewInstance.backgroundThread.jsContext;
|
|
18
|
+
},
|
|
19
|
+
requestAnimationFrame(cb) {
|
|
20
|
+
return requestAnimationFrameBrowserImpl(cb);
|
|
21
|
+
},
|
|
22
|
+
cancelAnimationFrame(handler) {
|
|
23
|
+
return cancelAnimationFrameBrowserImpl(handler);
|
|
24
|
+
},
|
|
25
|
+
__globalProps: lynxViewInstance.globalprops,
|
|
26
|
+
getCustomSectionSync(key) {
|
|
27
|
+
return templateManager.getTemplate(lynxViewInstance.templateUrl)?.customSections?.[key]
|
|
28
|
+
?.content;
|
|
29
|
+
},
|
|
30
|
+
markPipelineTiming: lynxViewInstance.backgroundThread.markTiming.bind(lynxViewInstance.backgroundThread),
|
|
31
|
+
SystemInfo: systemInfo,
|
|
32
|
+
setTimeout: setTimeoutBrowserImpl,
|
|
33
|
+
clearTimeout: clearTimeoutBrowserImpl,
|
|
34
|
+
setInterval: setIntervalBrowserImpl,
|
|
35
|
+
clearInterval: clearIntervalBrowserImpl,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function createMainThreadGlobalAPIs(lynxViewInstance) {
|
|
39
|
+
let releaseSetting = '';
|
|
40
|
+
return {
|
|
41
|
+
__globalProps: lynxViewInstance.globalprops,
|
|
42
|
+
SystemInfo: systemInfo,
|
|
43
|
+
lynx: createMainThreadLynx(lynxViewInstance),
|
|
44
|
+
__OnLifecycleEvent: (data) => {
|
|
45
|
+
lynxViewInstance.backgroundThread.jsContext.dispatchEvent({
|
|
46
|
+
type: '__OnLifecycleEvent',
|
|
47
|
+
data,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
__LoadLepusChunk: (path) => {
|
|
51
|
+
try {
|
|
52
|
+
path = lynxViewInstance.lepusCodeUrls.get(lynxViewInstance.templateUrl)?.[path] ?? path;
|
|
53
|
+
lynxViewInstance.mtsRealm.loadScriptSync(path);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error(`failed to load lepus chunk ${path}`, e);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
_AddEventListener: () => { }, // no-op for main thread
|
|
62
|
+
_ReportError: (err, _) => {
|
|
63
|
+
lynxViewInstance.reportError?.(err, releaseSetting, 'lepus.js');
|
|
64
|
+
},
|
|
65
|
+
_SetSourceMapRelease: (errInfo) => releaseSetting = errInfo?.release,
|
|
66
|
+
_I18nResourceTranslation: lynxViewInstance.i18nManager
|
|
67
|
+
._I18nResourceTranslation.bind(lynxViewInstance.i18nManager),
|
|
68
|
+
__QueryComponent: (url, callback) => {
|
|
69
|
+
lynxViewInstance.queryComponent(url).then((lepusRootChunkExport) => {
|
|
70
|
+
callback?.({
|
|
71
|
+
code: 0,
|
|
72
|
+
data: {
|
|
73
|
+
url,
|
|
74
|
+
evalResult: lepusRootChunkExport,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return null;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=createMainThreadGlobalAPIs.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ErrorCode, IdentifierType } from '../../../constants.js';
|
|
2
|
+
import type { LynxViewInstance } from '../LynxViewInstance.js';
|
|
3
|
+
export declare function queryNodes(lynxViewInstance: LynxViewInstance, type: IdentifierType, identifier: string, component_id: string, first_only: boolean, root_unique_id: number | undefined, callback: (dom: Element) => void, error?: (code: ErrorCode) => void): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { ErrorCode, IdentifierType } from '../../../constants.js';
|
|
5
|
+
export function queryNodes(lynxViewInstance, type, identifier, component_id, first_only, root_unique_id, callback, error) {
|
|
6
|
+
let queryRoot = lynxViewInstance.rootDom;
|
|
7
|
+
if (root_unique_id) {
|
|
8
|
+
const root = lynxViewInstance.mtsWasmBinding.getElementByUniqueId(root_unique_id);
|
|
9
|
+
if (root) {
|
|
10
|
+
queryRoot = root;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.error(`[lynx-web] cannot find dom for root_unique_id: ${root_unique_id}`);
|
|
14
|
+
error?.(ErrorCode.NODE_NOT_FOUND);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (component_id) {
|
|
19
|
+
const root = lynxViewInstance.mtsWasmBinding.getElementByComponentId(component_id);
|
|
20
|
+
if (root) {
|
|
21
|
+
queryRoot = root;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.error(`[lynx-web] cannot find dom for component_id: ${component_id}`);
|
|
25
|
+
error?.(ErrorCode.NODE_NOT_FOUND);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let selector;
|
|
30
|
+
if (type === IdentifierType.ID_SELECTOR) {
|
|
31
|
+
selector = identifier;
|
|
32
|
+
}
|
|
33
|
+
else if (type === IdentifierType.UNIQUE_ID) {
|
|
34
|
+
const element = lynxViewInstance.mtsWasmBinding.getElementByUniqueId(Number(identifier));
|
|
35
|
+
if (element) {
|
|
36
|
+
callback(element);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.error(`[lynx-web] cannot find dom for unique_id: ${identifier}`);
|
|
41
|
+
error?.(ErrorCode.NODE_NOT_FOUND);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error(`[lynx-web] NYI: setnativeprops type ${type}`);
|
|
47
|
+
error?.(ErrorCode.UNKNOWN);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (first_only) {
|
|
51
|
+
let targetElement = null;
|
|
52
|
+
try {
|
|
53
|
+
targetElement = queryRoot.querySelector(selector);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(`[lynx-web] cannot use selector: ${selector}`);
|
|
57
|
+
error?.(ErrorCode.SELECTOR_NOT_SUPPORTED);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (targetElement) {
|
|
61
|
+
callback(targetElement);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.error(`[lynx-web] cannot find from for selector ${identifier} under`, queryRoot);
|
|
65
|
+
error?.(ErrorCode.NODE_NOT_FOUND);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
queryRoot.querySelectorAll(selector).forEach((element) => {
|
|
70
|
+
callback(element);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=queryNodes.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { queryNodes } from './queryNodes.js';
|
|
5
|
+
import { getPathInfoEndpoint } from '../../endpoints.js';
|
|
6
|
+
import { ErrorCode } from '../../../constants.js';
|
|
7
|
+
export function registerGetPathInfoHandler(rpc, lynxViewInstance) {
|
|
8
|
+
rpc.registerHandler(getPathInfoEndpoint, (type, identifier, component_id, first_only, root_unique_id) => {
|
|
9
|
+
let code = ErrorCode.UNKNOWN;
|
|
10
|
+
let data;
|
|
11
|
+
queryNodes(lynxViewInstance, type, identifier, component_id, first_only, root_unique_id, (element) => {
|
|
12
|
+
try {
|
|
13
|
+
const path = [];
|
|
14
|
+
let currentNode = element;
|
|
15
|
+
while (currentNode) {
|
|
16
|
+
const parent = currentNode.parentElement;
|
|
17
|
+
const parentNodeForChildren = parent ?? lynxViewInstance.rootDom;
|
|
18
|
+
const children = Array.from(parentNodeForChildren.children);
|
|
19
|
+
const tag = lynxViewInstance.mainThreadGlobalThis.__GetTag(currentNode);
|
|
20
|
+
const index = tag === 'page' ? 0 : children.indexOf(currentNode);
|
|
21
|
+
const id = currentNode.getAttribute('id') || undefined;
|
|
22
|
+
const className = currentNode.getAttribute('class') || undefined;
|
|
23
|
+
const dataSet = lynxViewInstance.mainThreadGlobalThis
|
|
24
|
+
.__GetDataset(currentNode);
|
|
25
|
+
path.push({
|
|
26
|
+
tag,
|
|
27
|
+
id,
|
|
28
|
+
class: className,
|
|
29
|
+
dataSet,
|
|
30
|
+
index,
|
|
31
|
+
});
|
|
32
|
+
if (tag === 'page'
|
|
33
|
+
|| currentNode.parentNode === lynxViewInstance.rootDom) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
currentNode = parent;
|
|
37
|
+
}
|
|
38
|
+
data = { path };
|
|
39
|
+
code = ErrorCode.SUCCESS;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error('[lynx-web] getPathInfo: failed with', e, element);
|
|
43
|
+
code = ErrorCode.UNKNOWN;
|
|
44
|
+
}
|
|
45
|
+
}, (error) => {
|
|
46
|
+
code = error;
|
|
47
|
+
});
|
|
48
|
+
return { code, data };
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=registerGetPathInfoHandler.js.map
|