@lynx-js/web-core 0.13.4 → 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,127 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - refactor: the default thread-strategy will be all on ui ([#1105](https://github.com/lynx-family/lynx-stack/pull/1105))
8
+
9
+ **This is a breaking change!!!**
10
+
11
+ ### Patch Changes
12
+
13
+ - feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118))
14
+
15
+ You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view.
16
+
17
+ 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.
18
+
19
+ - 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))
20
+
21
+ `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.
22
+
23
+ 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.
24
+
25
+ ```js
26
+ // ui thread
27
+ lynxView.initI18nResources = [
28
+ {
29
+ options: {
30
+ locale: 'en',
31
+ channel: '1',
32
+ fallback_url: '',
33
+ },
34
+ resource: {
35
+ hello: 'hello',
36
+ lynx: 'lynx web platform1',
37
+ },
38
+ },
39
+ ];
40
+ lynxView.addEventListener('i18nResourceMissed', (e) => {
41
+ console.log(e);
42
+ });
43
+
44
+ // mts
45
+ _I18nResourceTranslation({
46
+ locale: 'en',
47
+ channel: '1',
48
+ fallback_url: '',
49
+ });
50
+ ```
51
+
52
+ - fix: lynx-view `updateGlobalProps` method will also update globalProps, so `reload()` will use the latest updated globalProps. ([#1119](https://github.com/lynx-family/lynx-stack/pull/1119))
53
+
54
+ - feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088))
55
+
56
+ - `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources:
57
+ - the result of `_I18nResourceTranslation()`
58
+ - lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()`
59
+ - `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution.
60
+
61
+ - refactor: make the opcode be a plain array ([#1051](https://github.com/lynx-family/lynx-stack/pull/1051))
62
+
63
+ #1042
64
+
65
+ - feat: The error event return value detail of lynx-view adds `sourceMap` value, the type is as follows: ([#1058](https://github.com/lynx-family/lynx-stack/pull/1058))
66
+
67
+ ```
68
+ CustomEvent<{
69
+ error: Error;
70
+ sourceMap: {
71
+ offset: {
72
+ line: number;
73
+ col: number;
74
+ };
75
+ };
76
+ }>;
77
+ ```
78
+
79
+ This is because web-core adds wrapper at runtime, which causes the stack offset to be different. Now you can calculate the real offset based on it.
80
+
81
+ - feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085))
82
+
83
+ Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result.
84
+
85
+ - fix: --lynx-color will be removed, and if color contains `gradient` it will be processed as transparent. ([#1069](https://github.com/lynx-family/lynx-stack/pull/1069))
86
+
87
+ - Updated dependencies [[`42ed2e3`](https://github.com/lynx-family/lynx-stack/commit/42ed2e325ff38f781dc88b92cc56093a7a7164ea), [`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), [`1861cbe`](https://github.com/lynx-family/lynx-stack/commit/1861cbead4b373e0511214999b0e100b6285fa9a)]:
88
+ - @lynx-js/web-worker-runtime@0.14.0
89
+ - @lynx-js/web-mainthread-apis@0.14.0
90
+ - @lynx-js/web-constants@0.14.0
91
+ - @lynx-js/offscreen-document@0.1.2
92
+ - @lynx-js/web-worker-rpc@0.14.0
93
+
94
+ ## 0.13.5
95
+
96
+ ### Patch Changes
97
+
98
+ - refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945))
99
+
100
+ It's essential for SSR
101
+
102
+ - refactor: avoid to create many style element for cssog ([#1026](https://github.com/lynx-family/lynx-stack/pull/1026))
103
+
104
+ - refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984))
105
+
106
+ - fix: ensure render starts after dom connected ([#1020](https://github.com/lynx-family/lynx-stack/pull/1020))
107
+
108
+ - refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981))
109
+
110
+ On lynx, the `data-*` attributes have different behaviors than the HTMLElement has.
111
+
112
+ The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation.
113
+
114
+ Before this commit we use it as a runtime data, but after this commit we will use encodeURI(JSON.stringify(dataset)) to encode it as a string.
115
+
116
+ - refactor: implement mts apis in closure pattern ([#1004](https://github.com/lynx-family/lynx-stack/pull/1004))
117
+
118
+ - Updated dependencies [[`70b82d2`](https://github.com/lynx-family/lynx-stack/commit/70b82d23744d6b6ec945dff9f8895ab3488ba4c8), [`5651e24`](https://github.com/lynx-family/lynx-stack/commit/5651e24827358963c3261252bcc53c2ad981c13e), [`9499ea9`](https://github.com/lynx-family/lynx-stack/commit/9499ea91debdf73b2d31af0b31bcbc216135543b), [`50f0193`](https://github.com/lynx-family/lynx-stack/commit/50f01933942268b697bf5abe790da86c932f1dfc), [`57bf0ef`](https://github.com/lynx-family/lynx-stack/commit/57bf0ef19f1d79bc52ab6a4f0cd2939e7901d98b), [`5651e24`](https://github.com/lynx-family/lynx-stack/commit/5651e24827358963c3261252bcc53c2ad981c13e), [`0525fbf`](https://github.com/lynx-family/lynx-stack/commit/0525fbf38baa7a977a7a8c66e8a4d8bf34cc3b68), [`b6b87fd`](https://github.com/lynx-family/lynx-stack/commit/b6b87fd11dbc76c28f3b5022aa8c6afeb773d90f), [`c014327`](https://github.com/lynx-family/lynx-stack/commit/c014327ad0cf599b32d4182d95116b46c35f5fa5)]:
119
+ - @lynx-js/web-mainthread-apis@0.13.5
120
+ - @lynx-js/web-constants@0.13.5
121
+ - @lynx-js/offscreen-document@0.1.1
122
+ - @lynx-js/web-worker-runtime@0.13.5
123
+ - @lynx-js/web-worker-rpc@0.13.5
124
+
3
125
  ## 0.13.4
4
126
 
5
127
  ### Patch Changes
@@ -1,11 +1,11 @@
1
- import { type Cloneable, type LynxTemplate, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
1
+ import { type Cloneable, type I18nResourceTranslationOptions, type InitI18nResources, type LynxTemplate, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
2
2
  export type INapiModulesCall = (name: string, data: any, moduleName: string, lynxView: LynxView, dispatchNapiModules: (data: Cloneable) => void) => Promise<{
3
3
  data: unknown;
4
4
  transfer?: Transferable[];
5
- }> | {
5
+ } | undefined> | {
6
6
  data: unknown;
7
7
  transfer?: Transferable[];
8
- } | undefined;
8
+ } | undefined | Promise<undefined>;
9
9
  /**
10
10
  * Based on our experiences, these elements are almost used in all lynx cards.
11
11
  */
@@ -25,8 +25,10 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
25
25
  * @property {number} lynxGroupId [optional] (attribute: "lynx-group-id") the background shared context id, which is used to share webworker between different lynx cards
26
26
  * @property {"all-on-ui" | "multi-thread"} threadStrategy [optional] @default "multi-thread" (attribute: "thread-strategy") controls the thread strategy for current lynx view
27
27
  * @property {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
28
+ * @property {InitI18nResources} initI18nResources [optional] (attribute: "init-i18n-resources") the complete set of i18nResources that on the container side, which can be obtained synchronously by _I18nResourceTranslation
28
29
  *
29
30
  * @event error lynx card fired an error
31
+ * @event i18nResourceMissed i18n resource cache miss
30
32
  *
31
33
  * @example
32
34
  * HTML Example
@@ -73,6 +75,19 @@ export declare class LynxView extends HTMLElement {
73
75
  */
74
76
  get initData(): Cloneable;
75
77
  set initData(val: string | Cloneable);
78
+ /**
79
+ * @public
80
+ * @property initI18nResources
81
+ * @default {}
82
+ */
83
+ get initI18nResources(): InitI18nResources;
84
+ set initI18nResources(val: string | InitI18nResources);
85
+ /**
86
+ * @public
87
+ * @method
88
+ * update the `__initData` and trigger essential flow
89
+ */
90
+ updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions): void;
76
91
  /**
77
92
  * @public
78
93
  * @property
@@ -22,8 +22,10 @@ import { inShadowRootStyles, } from '@lynx-js/web-constants';
22
22
  * @property {number} lynxGroupId [optional] (attribute: "lynx-group-id") the background shared context id, which is used to share webworker between different lynx cards
23
23
  * @property {"all-on-ui" | "multi-thread"} threadStrategy [optional] @default "multi-thread" (attribute: "thread-strategy") controls the thread strategy for current lynx view
24
24
  * @property {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
25
+ * @property {InitI18nResources} initI18nResources [optional] (attribute: "init-i18n-resources") the complete set of i18nResources that on the container side, which can be obtained synchronously by _I18nResourceTranslation
25
26
  *
26
27
  * @event error lynx card fired an error
28
+ * @event i18nResourceMissed i18n resource cache miss
27
29
  *
28
30
  * @example
29
31
  * HTML Example
@@ -54,6 +56,7 @@ export class LynxView extends HTMLElement {
54
56
  */
55
57
  static observedAttributes = LynxView.observedAttributeAsProperties.map(nm => nm.toLowerCase());
56
58
  #instance;
59
+ #connected = false;
57
60
  #url;
58
61
  /**
59
62
  * @public
@@ -100,6 +103,31 @@ export class LynxView extends HTMLElement {
100
103
  this.#initData = val;
101
104
  }
102
105
  }
106
+ #initI18nResources = [];
107
+ /**
108
+ * @public
109
+ * @property initI18nResources
110
+ * @default {}
111
+ */
112
+ get initI18nResources() {
113
+ return this.#initI18nResources;
114
+ }
115
+ set initI18nResources(val) {
116
+ if (typeof val === 'string') {
117
+ this.#initI18nResources = JSON.parse(val);
118
+ }
119
+ else {
120
+ this.#initI18nResources = val;
121
+ }
122
+ }
123
+ /**
124
+ * @public
125
+ * @method
126
+ * update the `__initData` and trigger essential flow
127
+ */
128
+ updateI18nResources(data, options) {
129
+ this.#instance?.updateI18nResources(data, options);
130
+ }
103
131
  #overrideLynxTagToHTMLTagMap = { 'page': 'div' };
104
132
  /**
105
133
  * @public
@@ -203,6 +231,7 @@ export class LynxView extends HTMLElement {
203
231
  */
204
232
  updateGlobalProps(data) {
205
233
  this.#instance?.updateGlobalProps(data);
234
+ this.globalProps = data;
206
235
  }
207
236
  /**
208
237
  * @public
@@ -304,7 +333,7 @@ export class LynxView extends HTMLElement {
304
333
  * @private
305
334
  */
306
335
  #render() {
307
- if (!this.#rendering) {
336
+ if (!this.#rendering && this.#connected) {
308
337
  this.#rendering = true;
309
338
  queueMicrotask(() => {
310
339
  this.#rendering = false;
@@ -325,7 +354,7 @@ export class LynxView extends HTMLElement {
325
354
  this.attachShadow({ mode: 'open' });
326
355
  }
327
356
  const lynxGroupId = this.lynxGroupId;
328
- const threadStrategy = (this.threadStrategy ?? 'multi-thread');
357
+ const threadStrategy = (this.threadStrategy ?? 'all-on-ui');
329
358
  const lynxView = createLynxView({
330
359
  threadStrategy,
331
360
  tagMap,
@@ -336,6 +365,7 @@ export class LynxView extends HTMLElement {
336
365
  nativeModulesMap: this.#nativeModulesMap,
337
366
  napiModulesMap: this.#napiModulesMap,
338
367
  lynxGroupId,
368
+ initI18nResources: this.#initI18nResources,
339
369
  callbacks: {
340
370
  nativeModulesCall: (...args) => {
341
371
  if (this.#onNativeModulesCall) {
@@ -351,8 +381,19 @@ export class LynxView extends HTMLElement {
351
381
  napiModulesCall: (...args) => {
352
382
  return this.#onNapiModulesCall?.(...args);
353
383
  },
354
- onError: () => {
355
- this.dispatchEvent(new CustomEvent('error', {}));
384
+ onError: (error, release) => {
385
+ this.dispatchEvent(new CustomEvent('error', {
386
+ detail: {
387
+ sourceMap: {
388
+ offset: {
389
+ line: 2,
390
+ col: 0,
391
+ },
392
+ },
393
+ error,
394
+ release,
395
+ },
396
+ }));
356
397
  },
357
398
  customTemplateLoader: this.customTemplateLoader,
358
399
  },
@@ -382,6 +423,7 @@ export class LynxView extends HTMLElement {
382
423
  * @private
383
424
  */
384
425
  connectedCallback() {
426
+ this.#connected = true;
385
427
  this.#render();
386
428
  }
387
429
  }
@@ -1,4 +1,4 @@
1
- import type { Cloneable, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
1
+ import type { Cloneable, I18nResourceTranslationOptions, InitI18nResources, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
2
2
  import { type StartUIThreadCallbacks } from '../uiThread/startUIThread.js';
3
3
  import type { RpcCallType } from '@lynx-js/web-worker-rpc';
4
4
  export interface LynxViewConfigs {
@@ -12,11 +12,13 @@ export interface LynxViewConfigs {
12
12
  tagMap: Record<string, string>;
13
13
  lynxGroupId: number | undefined;
14
14
  threadStrategy: 'all-on-ui' | 'multi-thread';
15
+ initI18nResources: InitI18nResources;
15
16
  }
16
17
  export interface LynxView {
17
18
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
18
19
  dispose(): Promise<void>;
19
20
  sendGlobalEvent: RpcCallType<typeof sendGlobalEventEndpoint>;
20
21
  updateGlobalProps: (data: Cloneable) => void;
22
+ updateI18nResources: (data: InitI18nResources, options: I18nResourceTranslationOptions) => void;
21
23
  }
22
24
  export declare function createLynxView(configs: LynxViewConfigs): LynxView;
@@ -6,7 +6,7 @@ const pixelRatio = window.devicePixelRatio;
6
6
  const screenWidth = window.screen.availWidth * pixelRatio;
7
7
  const screenHeight = window.screen.availHeight * pixelRatio;
8
8
  export function createLynxView(configs) {
9
- const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, threadStrategy = 'multi-thread', } = configs;
9
+ const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, threadStrategy = 'multi-thread', initI18nResources, } = configs;
10
10
  return startUIThread(templateUrl, {
11
11
  tagMap,
12
12
  initData,
@@ -18,6 +18,7 @@ export function createLynxView(configs) {
18
18
  pixelWidth: screenWidth,
19
19
  pixelHeight: screenHeight,
20
20
  },
21
+ initI18nResources,
21
22
  }, shadowRoot, lynxGroupId, threadStrategy, callbacks);
22
23
  }
23
24
  //# sourceMappingURL=createLynxView.js.map
@@ -1,8 +1,9 @@
1
- import type { StartMainThreadContextConfig } from '@lynx-js/web-constants';
1
+ import { type StartMainThreadContextConfig, type Cloneable } from '@lynx-js/web-constants';
2
2
  import { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, callbacks: {
4
- onError?: () => void;
4
+ onError?: (err: Error, release: string) => void;
5
5
  }): {
6
6
  start: (configs: StartMainThreadContextConfig) => Promise<void>;
7
- updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
7
+ updateDataMainThread: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
8
+ updateI18nResourcesMainThread: (data: Cloneable) => void;
8
9
  };
@@ -1,23 +1,36 @@
1
+ import { i18nResourceMissedEventName, I18nResources, } from '@lynx-js/web-constants';
1
2
  import { Rpc } from '@lynx-js/web-worker-rpc';
3
+ import { dispatchLynxViewEvent } from '../utils/dispatchLynxViewEvent.js';
2
4
  const { prepareMainThreadAPIs, } = await import('@lynx-js/web-mainthread-apis');
3
5
  export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, callbacks) {
4
6
  if (!globalThis.module) {
5
7
  Object.assign(globalThis, { module: {} });
6
8
  }
7
- const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document.createElement.bind(document), () => { }, markTimingInternal, () => {
8
- callbacks.onError?.();
9
+ const triggerI18nResourceFallback = (options) => {
10
+ dispatchLynxViewEvent(shadowRoot, i18nResourceMissedEventName, options);
11
+ };
12
+ const i18nResources = new I18nResources();
13
+ const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document.createElement.bind(document), () => { }, markTimingInternal, (err, _, release) => {
14
+ callbacks.onError?.(err, release);
15
+ }, triggerI18nResourceFallback, (initI18nResources) => {
16
+ i18nResources.setData(initI18nResources);
17
+ return i18nResources;
9
18
  });
10
- let runtime;
19
+ let mtsGlobalThis;
11
20
  const start = async (configs) => {
12
21
  const mainThreadRuntime = startMainThread(configs);
13
- runtime = await mainThreadRuntime;
22
+ mtsGlobalThis = await mainThreadRuntime;
14
23
  };
15
24
  const updateDataMainThread = async (...args) => {
16
- runtime.updatePage?.(...args);
25
+ mtsGlobalThis.updatePage?.(...args);
26
+ };
27
+ const updateI18nResourcesMainThread = (data) => {
28
+ i18nResources.setData(data);
17
29
  };
18
30
  return {
19
31
  start,
20
32
  updateDataMainThread,
33
+ updateI18nResourcesMainThread,
21
34
  };
22
35
  }
23
36
  //# sourceMappingURL=createRenderAllOnUI.js.map
@@ -1,7 +1,8 @@
1
1
  import type { Rpc } from '@lynx-js/web-worker-rpc';
2
2
  export declare function createRenderMultiThread(mainThreadRpc: Rpc, shadowRoot: ShadowRoot, callbacks: {
3
- onError?: () => void;
3
+ onError?: (err: Error, release: string) => void;
4
4
  }): {
5
5
  start: (args_0: import("@lynx-js/web-constants").StartMainThreadContextConfig) => void;
6
6
  updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
7
+ updateI18nResourcesMainThread: (args_0: import("@lynx-js/web-constants").Cloneable) => void;
7
8
  };
@@ -1,16 +1,20 @@
1
- import { mainThreadStartEndpoint, updateDataEndpoint, } from '@lynx-js/web-constants';
1
+ import { mainThreadStartEndpoint, updateDataEndpoint, updateI18nResourcesEndpoint, } from '@lynx-js/web-constants';
2
2
  import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js';
3
3
  import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerFlushElementTreeHandler.js';
4
+ import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
4
5
  export function createRenderMultiThread(mainThreadRpc, shadowRoot, callbacks) {
5
6
  registerReportErrorHandler(mainThreadRpc, callbacks.onError);
6
7
  registerFlushElementTreeHandler(mainThreadRpc, {
7
8
  shadowRoot,
8
9
  });
10
+ registerDispatchLynxViewEventHandler(mainThreadRpc, shadowRoot);
9
11
  const start = mainThreadRpc.createCall(mainThreadStartEndpoint);
10
12
  const updateDataMainThread = mainThreadRpc.createCall(updateDataEndpoint);
13
+ const updateI18nResourcesMainThread = mainThreadRpc.createCall(updateI18nResourcesEndpoint);
11
14
  return {
12
15
  start,
13
16
  updateDataMainThread,
17
+ updateI18nResourcesMainThread,
14
18
  };
15
19
  }
16
20
  //# sourceMappingURL=createRenderMultiThread.js.map
@@ -2,14 +2,10 @@
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
4
  import { dispatchLynxViewEventEndpoint } from '@lynx-js/web-constants';
5
+ import { dispatchLynxViewEvent } from '../../utils/dispatchLynxViewEvent.js';
5
6
  export function registerDispatchLynxViewEventHandler(rpc, shadowRoot) {
6
7
  rpc.registerHandler(dispatchLynxViewEventEndpoint, (eventType, detail) => {
7
- shadowRoot.dispatchEvent(new CustomEvent(eventType, {
8
- detail,
9
- bubbles: true,
10
- cancelable: true,
11
- composed: true,
12
- }));
8
+ dispatchLynxViewEvent(shadowRoot, eventType, detail);
13
9
  });
14
10
  }
15
11
  //# sourceMappingURL=registerDispatchLynxViewEventHandler.js.map
@@ -1,2 +1,2 @@
1
1
  import type { Rpc } from '@lynx-js/web-worker-rpc';
2
- export declare function registerReportErrorHandler(rpc: Rpc, onError?: (e: string) => void): void;
2
+ export declare function registerReportErrorHandler(rpc: Rpc, onError?: (e: Error, release: string) => void): void;
@@ -3,8 +3,8 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { reportErrorEndpoint } from '@lynx-js/web-constants';
5
5
  export function registerReportErrorHandler(rpc, onError) {
6
- rpc.registerHandler(reportErrorEndpoint, (e) => {
7
- onError?.(e);
6
+ rpc.registerHandler(reportErrorEndpoint, (e, _, release) => {
7
+ onError?.(e, release);
8
8
  });
9
9
  }
10
10
  //# sourceMappingURL=registerReportErrorHandler.js.map
@@ -1,10 +1,11 @@
1
- import { type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
1
+ import { type Cloneable, type I18nResourceTranslationOptions, type InitI18nResources, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
2
2
  import type { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  export declare function startBackground(backgroundRpc: Rpc, shadowRoot: ShadowRoot, callbacks: {
4
4
  nativeModulesCall: NativeModulesCall;
5
5
  napiModulesCall: NapiModulesCall;
6
6
  }): {
7
- sendGlobalEvent: (args_0: string, args_1: import("@lynx-js/web-constants").Cloneable[] | undefined) => void;
7
+ sendGlobalEvent: (args_0: string, args_1: Cloneable[] | undefined) => void;
8
8
  markTiming: (timingKey: string, pipelineId: string | undefined, timeStamp: number) => void;
9
- updateDataBackground: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
9
+ updateDataBackground: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
10
+ updateI18nResourceBackground: (data: InitI18nResources, options: I18nResourceTranslationOptions) => void;
10
11
  };
@@ -1,4 +1,4 @@
1
- import { markTimingEndpoint, sendGlobalEventEndpoint, updateDataEndpoint, } from '@lynx-js/web-constants';
1
+ import { getCacheI18nResourcesKey, markTimingEndpoint, sendGlobalEventEndpoint, updateDataEndpoint, updateI18nResourceEndpoint, } from '@lynx-js/web-constants';
2
2
  import { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js';
3
3
  import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js';
4
4
  import { registerNativeModulesCallHandler } from './crossThreadHandlers/registerNativeModulesCallHandler.js';
@@ -19,10 +19,18 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
19
19
  const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
20
20
  const markTiming = backgroundRpc.createCall(markTimingEndpoint);
21
21
  const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint);
22
+ const updateI18nResourceBackground = (data, options) => {
23
+ const matchedResources = data.find(i => getCacheI18nResourcesKey(i.options)
24
+ === getCacheI18nResourcesKey(options));
25
+ backgroundRpc.invoke(updateI18nResourceEndpoint, [
26
+ matchedResources?.resource,
27
+ ]);
28
+ };
22
29
  return {
23
30
  sendGlobalEvent,
24
31
  markTiming,
25
32
  updateDataBackground,
33
+ updateI18nResourceBackground,
26
34
  };
27
35
  }
28
36
  //# sourceMappingURL=startBackground.js.map
@@ -3,7 +3,7 @@ import { type LynxTemplate, type StartMainThreadContextConfig, type NapiModulesC
3
3
  export type StartUIThreadCallbacks = {
4
4
  nativeModulesCall: NativeModulesCall;
5
5
  napiModulesCall: NapiModulesCall;
6
- onError?: () => void;
6
+ onError?: (err: Error, release: string) => void;
7
7
  customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
8
8
  };
9
9
  export declare function startUIThread(templateUrl: string, configs: Omit<StartMainThreadContextConfig, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks): LynxView;
@@ -13,13 +13,13 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
13
13
  const createLynxStartTiming = performance.now() + performance.timeOrigin;
14
14
  const allOnUI = threadStrategy === 'all-on-ui';
15
15
  const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI);
16
- const { markTiming, sendGlobalEvent, updateDataBackground } = startBackground(backgroundRpc, shadowRoot, callbacks);
16
+ const { markTiming, sendGlobalEvent, updateDataBackground, updateI18nResourceBackground, } = startBackground(backgroundRpc, shadowRoot, callbacks);
17
17
  const markTimingInternal = (timingKey, pipelineId, timeStamp) => {
18
18
  if (!timeStamp)
19
19
  timeStamp = performance.now() + performance.timeOrigin;
20
20
  markTiming(timingKey, pipelineId, timeStamp);
21
21
  };
22
- const { start, updateDataMainThread } = allOnUI
22
+ const { start, updateDataMainThread, updateI18nResourcesMainThread } = allOnUI
23
23
  ? createRenderAllOnUI(
24
24
  /* main-to-bg rpc*/ mainThreadRpc, shadowRoot, markTimingInternal, callbacks)
25
25
  : createRenderMultiThread(
@@ -38,6 +38,10 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
38
38
  dispose: createDispose(backgroundRpc, terminateWorkers),
39
39
  sendGlobalEvent,
40
40
  updateGlobalProps: backgroundRpc.createCall(updateGlobalPropsEndpoint),
41
+ updateI18nResources: (...args) => {
42
+ updateI18nResourcesMainThread(args[0]);
43
+ updateI18nResourceBackground(...args);
44
+ },
41
45
  };
42
46
  }
43
47
  //# sourceMappingURL=startUIThread.js.map
@@ -0,0 +1,2 @@
1
+ import type { CloneableObject } from '@lynx-js/web-constants';
2
+ export declare const dispatchLynxViewEvent: (shadowRoot: ShadowRoot, eventType: string, detail: CloneableObject | undefined) => void;
@@ -0,0 +1,9 @@
1
+ export const dispatchLynxViewEvent = (shadowRoot, eventType, detail) => {
2
+ shadowRoot.dispatchEvent(new CustomEvent(eventType, {
3
+ detail,
4
+ bubbles: true,
5
+ cancelable: true,
6
+ composed: true,
7
+ }));
8
+ };
9
+ //# sourceMappingURL=dispatchLynxViewEvent.js.map
@@ -31,6 +31,7 @@ const mainThreadInjectVars = [
31
31
  'lynx',
32
32
  'globalThis',
33
33
  '_ReportError',
34
+ '_SetSourceMapRelease',
34
35
  '__AddConfig',
35
36
  '__AddDataset',
36
37
  '__GetAttributes',
@@ -84,6 +85,8 @@ const mainThreadInjectVars = [
84
85
  '__FlushElementTree',
85
86
  '__LoadLepusChunk',
86
87
  'SystemInfo',
88
+ '_I18nResourceTranslation',
89
+ '_AddEventListener',
87
90
  ];
88
91
  const backgroundInjectVars = [
89
92
  'NativeModules',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.13.4",
3
+ "version": "0.14.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,15 +24,15 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/offscreen-document": "0.1.0",
28
- "@lynx-js/web-constants": "0.13.4",
29
- "@lynx-js/web-mainthread-apis": "0.13.4",
30
- "@lynx-js/web-worker-rpc": "0.13.4",
31
- "@lynx-js/web-worker-runtime": "0.13.4"
27
+ "@lynx-js/offscreen-document": "0.1.2",
28
+ "@lynx-js/web-constants": "0.14.0",
29
+ "@lynx-js/web-mainthread-apis": "0.14.0",
30
+ "@lynx-js/web-worker-rpc": "0.14.0",
31
+ "@lynx-js/web-worker-runtime": "0.14.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.2",
35
- "@lynx-js/web-elements": "0.7.4"
35
+ "@lynx-js/web-elements": "0.7.6"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.2",