@lynx-js/web-mainthread-apis 0.13.5 → 0.14.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,76 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.14.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: under the all-on-ui strategy, reload() will add two page elements. ([#1147](https://github.com/lynx-family/lynx-stack/pull/1147))
8
+
9
+ - Updated dependencies [[`a64333e`](https://github.com/lynx-family/lynx-stack/commit/a64333ef28228d6b90c32e027f67bef8acbd8432), [`7751375`](https://github.com/lynx-family/lynx-stack/commit/775137521782ca5445f22029c39163c0a63bbfa5), [`b52a924`](https://github.com/lynx-family/lynx-stack/commit/b52a924a2375cb6f7ebafdd8abfbab0254eb2330)]:
10
+ - @lynx-js/web-constants@0.14.1
11
+
12
+ ## 0.14.0
13
+
14
+ ### Patch Changes
15
+
16
+ - feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118))
17
+
18
+ You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view.
19
+
20
+ The `_SetSourceMapRelease` function is not complete yet, because it is currently limited by the Web platform and some functions and some props such as `err.stack` do not need to be supported for the time being.
21
+
22
+ - feat: add `_I18nResourceTranslation` api in mts && `init-i18n-resources` attr, `i18nResourceMissed` event of lynx-view. ([#1065](https://github.com/lynx-family/lynx-stack/pull/1065))
23
+
24
+ `init-i18n-resource` is the complete set of i18nResources that need to be maintained on the container side. Note: You need to pass this value when lynx-view is initialized.
25
+
26
+ You can use `_I18nResourceTranslation` in MTS to get the corresponding i18nResource from `init-i18n-resources`. If it is undefined, the `i18nResourceMissed` event will be dispatched.
27
+
28
+ ```js
29
+ // ui thread
30
+ lynxView.initI18nResources = [
31
+ {
32
+ options: {
33
+ locale: 'en',
34
+ channel: '1',
35
+ fallback_url: '',
36
+ },
37
+ resource: {
38
+ hello: 'hello',
39
+ lynx: 'lynx web platform1',
40
+ },
41
+ },
42
+ ];
43
+ lynxView.addEventListener('i18nResourceMissed', (e) => {
44
+ console.log(e);
45
+ });
46
+
47
+ // mts
48
+ _I18nResourceTranslation({
49
+ locale: 'en',
50
+ channel: '1',
51
+ fallback_url: '',
52
+ });
53
+ ```
54
+
55
+ - feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088))
56
+
57
+ - `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources:
58
+ - the result of `_I18nResourceTranslation()`
59
+ - lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()`
60
+ - `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution.
61
+
62
+ - feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085))
63
+
64
+ Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result.
65
+
66
+ - fix: `decodeCssInJs` will not throw error. ([#1120](https://github.com/lynx-family/lynx-stack/pull/1120))
67
+
68
+ Before this pr, decoding css will be strictly executed according to cssInfo, and an error will be thrown if data that does not meet the requirements is encountered. Now it is changed to console.warn, which will not block rendering.
69
+
70
+ - Updated dependencies [[`25a04c9`](https://github.com/lynx-family/lynx-stack/commit/25a04c9e59f4b893227bdead74f2de69f6615cdb), [`0dbb8b1`](https://github.com/lynx-family/lynx-stack/commit/0dbb8b1f580d0700e2b67b92018a7a00d1494837), [`f99de1e`](https://github.com/lynx-family/lynx-stack/commit/f99de1ef60cc5a11eae4fd0acc70a490787d36c9), [`873a285`](https://github.com/lynx-family/lynx-stack/commit/873a2852fa3df9e32c48a6504160bb243540c7b9), [`afacb2c`](https://github.com/lynx-family/lynx-stack/commit/afacb2cbea7feca46c553651000625d0845b2b00), [`7e73450`](https://github.com/lynx-family/lynx-stack/commit/7e73450f8f5f1153f8a064036f5552c1335c23d7)]:
71
+ - @lynx-js/web-constants@0.14.0
72
+ - @lynx-js/web-style-transformer@0.3.1
73
+
3
74
  ## 0.13.5
4
75
 
5
76
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { type LynxTemplate, type PageConfig, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type LynxJSModule, type MainThreadGlobalThis, type WebFiberElementImpl } from '@lynx-js/web-constants';
1
+ import { type LynxTemplate, type PageConfig, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type LynxJSModule, type MainThreadGlobalThis, type WebFiberElementImpl, type I18nResourceTranslationOptions } from '@lynx-js/web-constants';
2
2
  export interface MainThreadRuntimeCallbacks {
3
3
  mainChunkReady: () => void;
4
4
  flushElementTree: (options: FlushElementTreeOptions, timingFlags: string[]) => void;
@@ -8,6 +8,7 @@ export interface MainThreadRuntimeCallbacks {
8
8
  publishEvent: RpcCallType<typeof publishEventEndpoint>;
9
9
  publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
10
10
  createElement: (tag: string) => WebFiberElementImpl;
11
+ _I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
11
12
  }
12
13
  export interface MainThreadRuntimeConfig {
13
14
  pageConfig: PageConfig;
@@ -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 { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, } from '@lynx-js/web-constants';
4
+ import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, } from '@lynx-js/web-constants';
5
5
  import { globalMuteableVars } from '@lynx-js/web-constants';
6
6
  import { createMainThreadLynx } from './createMainThreadLynx.js';
7
7
  import { flattenStyleInfo, genCssContent, genCssInJsInfo, transformToWebCss, } from './utils/processStyleInfo.js';
@@ -328,7 +328,8 @@ export function createMainThreadGlobalThis(config) {
328
328
  const __FlushElementTree = (_subTree, options) => {
329
329
  const timingFlagsCopied = timingFlags;
330
330
  timingFlags = [];
331
- if (pageElement && !pageElement.parentNode) {
331
+ if (pageElement && !pageElement.parentNode
332
+ && pageElement.getAttribute(lynxDisposedAttribute) !== '') {
332
333
  // @ts-expect-error
333
334
  rootDom.append(pageElement);
334
335
  }
@@ -340,6 +341,7 @@ export function createMainThreadGlobalThis(config) {
340
341
  const __GetPageElement = () => {
341
342
  return pageElement;
342
343
  };
344
+ let release = '';
343
345
  const isCSSOG = !pageConfig.enableCSSSelector;
344
346
  const mtsGlobalThis = {
345
347
  __AddEvent,
@@ -400,10 +402,13 @@ export function createMainThreadGlobalThis(config) {
400
402
  ...config.browserConfig,
401
403
  },
402
404
  lynx: createMainThreadLynx(config),
403
- _ReportError: callbacks._ReportError,
405
+ _ReportError: (err, _) => callbacks._ReportError(err, _, release),
406
+ _SetSourceMapRelease: (errInfo) => release = errInfo?.release,
404
407
  __OnLifecycleEvent: callbacks.__OnLifecycleEvent,
405
408
  __FlushElementTree,
406
409
  __lynxGlobalBindingValues: lynxGlobalBindingValues,
410
+ _I18nResourceTranslation: callbacks._I18nResourceTranslation,
411
+ _AddEventListener: () => { },
407
412
  set _updateVars(handler) {
408
413
  varsUpdateHandlers.push(handler);
409
414
  },
@@ -1,4 +1,4 @@
1
- import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type MainThreadGlobalThis } from '@lynx-js/web-constants';
2
- export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, createElement: Document['createElement'], commitDocument: () => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, reportError: RpcCallType<typeof reportErrorEndpoint>): {
1
+ import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type MainThreadGlobalThis, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources } from '@lynx-js/web-constants';
2
+ export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, createElement: Document['createElement'], commitDocument: () => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources): {
3
3
  startMainThread: (config: StartMainThreadContextConfig) => Promise<MainThreadGlobalThis>;
4
4
  };
@@ -1,22 +1,23 @@
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 { BackgroundThreadStartEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postTimingFlagsEndpoint, dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, LynxCrossThreadContext, switchExposureServiceEndpoint, } from '@lynx-js/web-constants';
4
+ import { BackgroundThreadStartEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postTimingFlagsEndpoint, dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, LynxCrossThreadContext, switchExposureServiceEndpoint, getCacheI18nResourcesKey, dispatchI18nResourceEndpoint, } from '@lynx-js/web-constants';
5
5
  import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
6
6
  import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerGetCustomSectionHandler.js';
7
7
  import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
8
8
  import { createExposureService } from './utils/createExposureService.js';
9
9
  const moduleCache = {};
10
- export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, reportError) {
10
+ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources) {
11
11
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
12
12
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
13
13
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
14
14
  const publicComponentEvent = backgroundThreadRpc.createCall(publicComponentEventEndpoint);
15
15
  const postExposure = backgroundThreadRpc.createCall(postExposureEndpoint);
16
+ const dispatchI18nResource = backgroundThreadRpc.createCall(dispatchI18nResourceEndpoint);
16
17
  markTimingInternal('lepus_execute_start');
17
18
  async function startMainThread(config) {
18
19
  let isFp = true;
19
- const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, } = config;
20
+ const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources, } = config;
20
21
  const { styleInfo, pageConfig, customSections, cardType, lepusCode } = template;
21
22
  markTimingInternal('decode_start');
22
23
  const lepusCodeEntries = await Promise.all(Object.entries(lepusCode).map(async ([name, url]) => {
@@ -40,6 +41,7 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElemen
40
41
  receiveEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
41
42
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
42
43
  });
44
+ const i18nResources = initialI18nResources(initI18nResources);
43
45
  const mtsGlobalThis = createMainThreadGlobalThis({
44
46
  jsContext,
45
47
  tagMap,
@@ -112,6 +114,15 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElemen
112
114
  publishEvent,
113
115
  publicComponentEvent,
114
116
  createElement,
117
+ _I18nResourceTranslation: (options) => {
118
+ const matchedInitI18nResources = i18nResources.data?.find(i => getCacheI18nResourcesKey(i.options)
119
+ === getCacheI18nResourcesKey(options));
120
+ dispatchI18nResource(matchedInitI18nResources?.resource);
121
+ if (matchedInitI18nResources) {
122
+ return matchedInitI18nResources.resource;
123
+ }
124
+ return triggerI18nResourceFallback(options);
125
+ },
115
126
  },
116
127
  });
117
128
  markTimingInternal('decode_end');
@@ -16,7 +16,7 @@ export function decodeCssInJs(classes, styleInfo, cssId) {
16
16
  }
17
17
  }
18
18
  else {
19
- throw new Error(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
19
+ console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
20
20
  }
21
21
  return declarations.map(([property, value]) => `${property}:${value};`).join('');
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.13.5",
3
+ "version": "0.14.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "css-tree": "^3.1.0",
27
27
  "hyphenate-style-name": "^1.1.0",
28
- "@lynx-js/web-constants": "0.13.5",
29
- "@lynx-js/web-style-transformer": "0.3.0"
28
+ "@lynx-js/web-constants": "0.14.1",
29
+ "@lynx-js/web-style-transformer": "0.3.1"
30
30
  }
31
31
  }