@lynx-js/web-mainthread-apis 0.13.5 → 0.14.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/CHANGELOG.md CHANGED
@@ -1,5 +1,67 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118))
8
+
9
+ You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view.
10
+
11
+ 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.
12
+
13
+ - 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))
14
+
15
+ `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.
16
+
17
+ 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.
18
+
19
+ ```js
20
+ // ui thread
21
+ lynxView.initI18nResources = [
22
+ {
23
+ options: {
24
+ locale: 'en',
25
+ channel: '1',
26
+ fallback_url: '',
27
+ },
28
+ resource: {
29
+ hello: 'hello',
30
+ lynx: 'lynx web platform1',
31
+ },
32
+ },
33
+ ];
34
+ lynxView.addEventListener('i18nResourceMissed', (e) => {
35
+ console.log(e);
36
+ });
37
+
38
+ // mts
39
+ _I18nResourceTranslation({
40
+ locale: 'en',
41
+ channel: '1',
42
+ fallback_url: '',
43
+ });
44
+ ```
45
+
46
+ - feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088))
47
+
48
+ - `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources:
49
+ - the result of `_I18nResourceTranslation()`
50
+ - lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()`
51
+ - `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution.
52
+
53
+ - feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085))
54
+
55
+ Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result.
56
+
57
+ - fix: `decodeCssInJs` will not throw error. ([#1120](https://github.com/lynx-family/lynx-stack/pull/1120))
58
+
59
+ 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.
60
+
61
+ - 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)]:
62
+ - @lynx-js/web-constants@0.14.0
63
+ - @lynx-js/web-style-transformer@0.3.1
64
+
3
65
  ## 0.13.5
4
66
 
5
67
  ### 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;
@@ -340,6 +340,7 @@ export function createMainThreadGlobalThis(config) {
340
340
  const __GetPageElement = () => {
341
341
  return pageElement;
342
342
  };
343
+ let release = '';
343
344
  const isCSSOG = !pageConfig.enableCSSSelector;
344
345
  const mtsGlobalThis = {
345
346
  __AddEvent,
@@ -400,10 +401,13 @@ export function createMainThreadGlobalThis(config) {
400
401
  ...config.browserConfig,
401
402
  },
402
403
  lynx: createMainThreadLynx(config),
403
- _ReportError: callbacks._ReportError,
404
+ _ReportError: (err, _) => callbacks._ReportError(err, _, release),
405
+ _SetSourceMapRelease: (errInfo) => release = errInfo?.release,
404
406
  __OnLifecycleEvent: callbacks.__OnLifecycleEvent,
405
407
  __FlushElementTree,
406
408
  __lynxGlobalBindingValues: lynxGlobalBindingValues,
409
+ _I18nResourceTranslation: callbacks._I18nResourceTranslation,
410
+ _AddEventListener: () => { },
407
411
  set _updateVars(handler) {
408
412
  varsUpdateHandlers.push(handler);
409
413
  },
@@ -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.0",
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.0",
29
+ "@lynx-js/web-style-transformer": "0.3.1"
30
30
  }
31
31
  }