@lynx-js/web-mainthread-apis-canary 0.16.1-canary-20250915-74388494 → 0.16.1-canary-20250915-608f375e

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 CHANGED
@@ -1,12 +1,14 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
- ## 0.16.1-canary-20250915064132-743884945342f58670e037c1a5dab06b782639c2
3
+ ## 0.16.1-canary-20250915073423-608f375e20732cc4c9f141bfbf9800ba6896100b
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies []:
8
- - @lynx-js/web-constants@0.16.1-canary-20250915064132-743884945342f58670e037c1a5dab06b782639c2
9
- - @lynx-js/web-style-transformer@0.16.1-canary-20250915064132-743884945342f58670e037c1a5dab06b782639c2
7
+ - feat: supports lazy bundle. (This feature requires `@lynx-js/lynx-core >= 0.1.3`) ([#1235](https://github.com/lynx-family/lynx-stack/pull/1235))
8
+
9
+ - Updated dependencies [[`608f375`](https://github.com/lynx-family/lynx-stack/commit/608f375e20732cc4c9f141bfbf9800ba6896100b)]:
10
+ - @lynx-js/web-constants@0.16.1-canary-20250915073423-608f375e20732cc4c9f141bfbf9800ba6896100b
11
+ - @lynx-js/web-style-transformer@0.16.1-canary-20250915073423-608f375e20732cc4c9f141bfbf9800ba6896100b
10
12
 
11
13
  ## 0.16.0
12
14
 
@@ -1,4 +1,4 @@
1
- import { type LynxTemplate, type PageConfig, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type MainThreadGlobalThis, type WebFiberElementImpl, type I18nResourceTranslationOptions, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm } from '@lynx-js/web-constants';
1
+ import { type LynxTemplate, type PageConfig, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type MainThreadGlobalThis, type WebFiberElementImpl, type I18nResourceTranslationOptions, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm, type QueryComponentPAPI } from '@lynx-js/web-constants';
2
2
  export interface MainThreadRuntimeCallbacks {
3
3
  mainChunkReady: () => void;
4
4
  flushElementTree: (options: FlushElementTreeOptions, timingFlags: string[], exposureChangedElements: WebFiberElementImpl[]) => void;
@@ -9,6 +9,7 @@ export interface MainThreadRuntimeCallbacks {
9
9
  publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
10
10
  _I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
11
11
  updateCssOGStyle: (uniqueId: number, newClassName: string, cssID: string | null) => void;
12
+ __QueryComponent: QueryComponentPAPI;
12
13
  }
13
14
  export interface MainThreadRuntimeConfig {
14
15
  pageConfig: PageConfig;
@@ -469,6 +469,7 @@ export function createMainThreadGlobalThis(config) {
469
469
  __LoadLepusChunk,
470
470
  __GetPageElement,
471
471
  __globalProps: globalProps,
472
+ __QueryComponent: callbacks.__QueryComponent,
472
473
  SystemInfo,
473
474
  lynx: createMainThreadLynx(config, SystemInfo),
474
475
  _ReportError: (err, _) => callbacks._ReportError(err, _, release),
@@ -0,0 +1,4 @@
1
+ import { type JSRealm, type LynxCrossThreadContext, type MainThreadGlobalThis, type QueryComponentPAPI, type Rpc, type StyleInfo, type TemplateLoader } from '@lynx-js/web-constants';
2
+ export declare function createQueryComponent(loadTemplate: TemplateLoader, updateLazyComponentStyle: (styleInfo: StyleInfo, entryName: string) => void, backgroundThreadRpc: Rpc, mtsGlobalThisRef: {
3
+ mtsGlobalThis: MainThreadGlobalThis;
4
+ }, jsContext: LynxCrossThreadContext, mtsRealm: JSRealm): QueryComponentPAPI;
@@ -0,0 +1,48 @@
1
+ import { queryComponentEndpoint, updateBTSTemplateCacheEndpoint, } from '@lynx-js/web-constants';
2
+ export function createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm) {
3
+ const updateBTSTemplateCache = backgroundThreadRpc.createCall(updateBTSTemplateCacheEndpoint);
4
+ const __QueryComponentImpl = (url, callback) => {
5
+ loadTemplate(url).then(async (template) => {
6
+ const updateBTSCachePromise = updateBTSTemplateCache(url, template);
7
+ let lepusRootChunkExport = await mtsRealm.loadScript(template.lepusCode.root);
8
+ if (mtsGlobalThisRef.mtsGlobalThis.processEvalResult) {
9
+ lepusRootChunkExport = mtsGlobalThisRef.mtsGlobalThis.processEvalResult(lepusRootChunkExport, url);
10
+ }
11
+ updateLazyComponentStyle(template.styleInfo, url);
12
+ await updateBTSCachePromise;
13
+ jsContext.dispatchEvent({
14
+ type: '__OnDynamicJSSourcePrepared',
15
+ data: url,
16
+ });
17
+ callback?.({
18
+ code: 0,
19
+ data: {
20
+ url,
21
+ evalResult: lepusRootChunkExport,
22
+ },
23
+ });
24
+ }).catch((error) => {
25
+ console.error(`lynx web: lazy bundle load failed:`, error);
26
+ callback?.({
27
+ code: -1,
28
+ data: undefined,
29
+ });
30
+ });
31
+ return null;
32
+ };
33
+ backgroundThreadRpc.registerHandler(queryComponentEndpoint, (url) => {
34
+ const ret = new Promise(resolve => {
35
+ __QueryComponentImpl(url, (result) => {
36
+ resolve({
37
+ code: result.code,
38
+ detail: {
39
+ schema: url,
40
+ },
41
+ });
42
+ });
43
+ });
44
+ return ret;
45
+ });
46
+ return __QueryComponentImpl;
47
+ }
48
+ //# sourceMappingURL=createQueryComponent.js.map
@@ -1,4 +1,4 @@
1
- import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm } from '@lynx-js/web-constants';
2
- export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealm: JSRealm, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, ssrHooks?: SSRDehydrateHooks): {
1
+ import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm, type TemplateLoader } from '@lynx-js/web-constants';
2
+ export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealm: JSRealm, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, loadTemplate: TemplateLoader, ssrHooks?: SSRDehydrateHooks): {
3
3
  startMainThread: (config: StartMainThreadContextConfig, ssrHydrateInfo?: SSRHydrateInfo) => Promise<void>;
4
4
  };
@@ -8,8 +8,9 @@ import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
8
8
  import { createExposureService } from './utils/createExposureService.js';
9
9
  import { initWasm } from '@lynx-js/web-style-transformer';
10
10
  import { appendStyleElement } from './utils/processStyleInfo.js';
11
+ import { createQueryComponent } from './crossThreadHandlers/createQueryComponent.js';
11
12
  const initWasmPromise = initWasm();
12
- export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
13
+ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks) {
13
14
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
14
15
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
15
16
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -29,7 +30,11 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
29
30
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
30
31
  });
31
32
  const i18nResources = initialI18nResources(initI18nResources);
32
- const { updateCssOGStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, undefined, ssrHydrateInfo);
33
+ const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, undefined, ssrHydrateInfo);
34
+ const mtsGlobalThisRef = {
35
+ mtsGlobalThis: undefined,
36
+ };
37
+ const __QueryComponent = createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm);
33
38
  const mtsGlobalThis = createMainThreadGlobalThis({
34
39
  lynxTemplate: template,
35
40
  mtsRealm,
@@ -127,8 +132,10 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
127
132
  }
128
133
  return triggerI18nResourceFallback(options);
129
134
  },
135
+ __QueryComponent,
130
136
  },
131
137
  });
138
+ mtsGlobalThisRef.mtsGlobalThis = mtsGlobalThis;
132
139
  markTimingInternal('decode_end');
133
140
  await mtsRealm.loadScript(template.lepusCode.root);
134
141
  jsContext.__start(); // start the jsContext after the runtime is created
@@ -1,7 +1,7 @@
1
1
  // Copyright 2023 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { componentIdAttribute, cssIdAttribute, lynxComponentConfigAttribute, lynxDatasetAttribute, lynxElementTemplateMarkerAttribute, lynxPartIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
4
+ import { componentIdAttribute, cssIdAttribute, lynxComponentConfigAttribute, lynxDatasetAttribute, lynxElementTemplateMarkerAttribute, lynxEntryNameAttribute, lynxPartIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
5
5
  import { queryCSSProperty } from './style/cssPropertyMap.js';
6
6
  import { transformInlineStyleString, transformParsedStyles, } from './style/transformInlineStyle.js';
7
7
  import hyphenateStyleName from 'hyphenate-style-name';
@@ -92,9 +92,10 @@ export const __UpdateComponentInfo = /*#__PURE__*/ (element, params) => {
92
92
  && element.setAttribute(cssIdAttribute, params.cssID + '');
93
93
  params.name !== undefined && element.setAttribute('name', params.name);
94
94
  };
95
- export const __SetCSSId = /*#__PURE__*/ (elements, cssId) => {
95
+ export const __SetCSSId = /*#__PURE__*/ (elements, cssId, entryName) => {
96
96
  for (const element of elements) {
97
97
  element.setAttribute(cssIdAttribute, cssId + '');
98
+ entryName && element.setAttribute(lynxEntryNameAttribute, entryName);
98
99
  }
99
100
  };
100
101
  export const __SetClasses = /*#__PURE__*/ (element, classname) => {
@@ -14,4 +14,5 @@ export declare function genCssContent(styleInfo: StyleInfo, pageConfig: PageConf
14
14
  export declare function genCssOGInfo(styleInfo: StyleInfo): CssOGInfo;
15
15
  export declare function appendStyleElement(styleInfo: StyleInfo, pageConfig: PageConfig, rootDom: Node, document: Document, entryName?: string, ssrHydrateInfo?: SSRHydrateInfo): {
16
16
  updateCssOGStyle: (uniqueId: number, newClassName: string, cssID: string | null) => void;
17
+ updateLazyComponentStyle: (styleInfo: StyleInfo, entryName: string) => void;
17
18
  };
@@ -68,7 +68,7 @@ export function genCssContent(styleInfo, pageConfig, entryName) {
68
68
  suffix = `[${lynxTagAttribute}]`;
69
69
  }
70
70
  if (entryName) {
71
- suffix = `${suffix}[${lynxEntryNameAttribute}="${entryName}"]`;
71
+ suffix = `${suffix}[${lynxEntryNameAttribute}=${JSON.stringify(entryName)}]`;
72
72
  }
73
73
  else {
74
74
  suffix = `${suffix}:not([${lynxEntryNameAttribute}])`;
@@ -160,6 +160,12 @@ export function appendStyleElement(styleInfo, pageConfig, rootDom, document, ent
160
160
  lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
161
161
  }
162
162
  };
163
- return { updateCssOGStyle };
163
+ const updateLazyComponentStyle = (styleInfo, entryName) => {
164
+ flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
165
+ transformToWebCss(styleInfo);
166
+ const newStyleSheet = genCssContent(styleInfo, pageConfig, entryName);
167
+ cardStyleElement.textContent += newStyleSheet;
168
+ };
169
+ return { updateCssOGStyle, updateLazyComponentStyle };
164
170
  }
165
171
  //# sourceMappingURL=processStyleInfo.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis-canary",
3
- "version": "0.16.1-canary-20250915-74388494",
3
+ "version": "0.16.1-canary-20250915-608f375e",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,8 +24,8 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.1-canary-20250915-74388494",
28
- "@lynx-js/web-style-transformer": "npm:@lynx-js/web-style-transformer-canary@0.16.1-canary-20250915-74388494",
27
+ "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.1-canary-20250915-608f375e",
28
+ "@lynx-js/web-style-transformer": "npm:@lynx-js/web-style-transformer-canary@0.16.1-canary-20250915-608f375e",
29
29
  "hyphenate-style-name": "^1.1.0"
30
30
  }
31
31
  }