@lynx-js/web-core 0.11.0 → 0.13.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,84 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: isolate SystemInfo ([#628](https://github.com/lynx-family/lynx-stack/pull/628))
8
+
9
+ Never assign `SystemInfo` on worker's self object.
10
+
11
+ - feat: support thread strategy `all-on-ui` ([#625](https://github.com/lynx-family/lynx-stack/pull/625))
12
+
13
+ ```html
14
+ <lynx-view thread-strategy="all-on-ui"></lynx-view>
15
+ ```
16
+
17
+ This will make the lynx's main-thread run on the UA's main thread.
18
+
19
+ Note that the `all-on-ui` does not support the HMR & chunk splitting yet.
20
+
21
+ - fix(web): css selector not work for selectors with combinator and pseudo-class on WEB ([#608](https://github.com/lynx-family/lynx-stack/pull/608))
22
+
23
+ like `.parent > :not([hidden]) ~ :not([hidden])`
24
+
25
+ you will need to upgrade your `react-rsbuild-plugin` to fix this issue
26
+
27
+ - Updated dependencies [[`4ee0465`](https://github.com/lynx-family/lynx-stack/commit/4ee0465f6e5846a0d038b49d2a7c95e87c9e5c77), [`74b5bd1`](https://github.com/lynx-family/lynx-stack/commit/74b5bd15339b70107a7c42525494da46e8f8f6bd), [`06bb78a`](https://github.com/lynx-family/lynx-stack/commit/06bb78a6b93d4a7be7177a6269dd4337852ce90d), [`5a3d9af`](https://github.com/lynx-family/lynx-stack/commit/5a3d9afe52ba639987db124ca35580261e0718b5), [`5269cab`](https://github.com/lynx-family/lynx-stack/commit/5269cabef7609159bdd0dd14a03c5da667907424), [`74b5bd1`](https://github.com/lynx-family/lynx-stack/commit/74b5bd15339b70107a7c42525494da46e8f8f6bd), [`2b069f8`](https://github.com/lynx-family/lynx-stack/commit/2b069f8786c95bdb9ac1f35091f05f7fd3b52225)]:
28
+ - @lynx-js/web-mainthread-apis@0.13.0
29
+ - @lynx-js/web-worker-runtime@0.13.0
30
+ - @lynx-js/web-constants@0.13.0
31
+ - @lynx-js/offscreen-document@0.0.1
32
+ - @lynx-js/web-worker-rpc@0.13.0
33
+
34
+ ## 0.12.0
35
+
36
+ ### Minor Changes
37
+
38
+ - feat: improve compatibility for chrome 108 & support linear-gradient for nested x-text ([#590](https://github.com/lynx-family/lynx-stack/pull/590))
39
+
40
+ **This is a breaking change**
41
+
42
+ - Please upgrade your `@lynx-js/web-elements` to >=0.6.0
43
+ - Please upgrade your `@lynx-js/web-core` to >=0.12.0
44
+ - The compiled lynx template json won't be impacted.
45
+
46
+ On chrome 108, the `-webkit-background-clip:text` cannot be computed by a `var(--css-var-value-text)`
47
+
48
+ Therefore we move the logic into style transformation logic.
49
+
50
+ Now the following status is supported
51
+
52
+ ```
53
+ <text style="color:linear-gradient()">
54
+ <text>
55
+ <text>
56
+ </text>
57
+ ```
58
+
59
+ ### Patch Changes
60
+
61
+ - feat: allow user to implement custom template load function ([#587](https://github.com/lynx-family/lynx-stack/pull/587))
62
+
63
+ ```js
64
+ lynxView.customTemplateLoader = (url) => {
65
+ return (await (await fetch(url, {
66
+ method: 'GET',
67
+ })).json());
68
+ };
69
+ ```
70
+
71
+ - feat: support mts event with target methods ([#564](https://github.com/lynx-family/lynx-stack/pull/564))
72
+
73
+ After this commit, developers are allowed to invoke `event.target.setStyleProperty` in mts handler
74
+
75
+ - fix: crash on removing a id attribute ([#582](https://github.com/lynx-family/lynx-stack/pull/582))
76
+
77
+ - Updated dependencies [[`f1ca29b`](https://github.com/lynx-family/lynx-stack/commit/f1ca29bd766377dd46583f15e1e75bca447699cd)]:
78
+ - @lynx-js/web-worker-runtime@0.12.0
79
+ - @lynx-js/web-constants@0.12.0
80
+ - @lynx-js/web-worker-rpc@0.12.0
81
+
3
82
  ## 0.11.0
4
83
 
5
84
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import { type Cloneable, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
1
+ import { type Cloneable, 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[];
@@ -22,6 +22,8 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
22
22
  * @property {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
23
23
  * @property {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
24
24
  * @property {number} lynxGroupId [optional] (attribute: "lynx-group-id") the background shared context id, which is used to share webworker between different lynx cards
25
+ * @property {"all-on-ui" | "multi-thread"} threadStrategy [optional] @default "multi-thread" (attribute: "thread-strategy") controls the thread strategy for current lynx view
26
+ * @property {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
25
27
  *
26
28
  * @event error lynx card fired an error
27
29
  *
@@ -138,10 +140,22 @@ export declare class LynxView extends HTMLElement {
138
140
  * @private
139
141
  */
140
142
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
143
+ /**
144
+ * @param
145
+ * @property
146
+ */
147
+ get threadStrategy(): 'all-on-ui' | 'multi-thread';
148
+ set threadStrategy(val: 'all-on-ui' | 'multi-thread');
141
149
  /**
142
150
  * @private
143
151
  */
144
152
  disconnectedCallback(): void;
153
+ /**
154
+ * @public
155
+ * allow user to customize the template loader
156
+ * @param url the url of the template
157
+ */
158
+ customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
145
159
  /**
146
160
  * @private
147
161
  */
@@ -20,6 +20,8 @@ import { inShadowRootStyles } from './inShadowRootStyles.js';
20
20
  * @property {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
21
21
  * @property {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
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
+ * @property {"all-on-ui" | "multi-thread"} threadStrategy [optional] @default "multi-thread" (attribute: "thread-strategy") controls the thread strategy for current lynx view
24
+ * @property {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
23
25
  *
24
26
  * @event error lynx card fired an error
25
27
  *
@@ -242,6 +244,22 @@ export class LynxView extends HTMLElement {
242
244
  }
243
245
  }
244
246
  }
247
+ /**
248
+ * @param
249
+ * @property
250
+ */
251
+ get threadStrategy() {
252
+ // @ts-expect-error
253
+ return this.getAttribute('thread-strategy');
254
+ }
255
+ set threadStrategy(val) {
256
+ if (val) {
257
+ this.setAttribute('thread-strategy', val);
258
+ }
259
+ else {
260
+ this.removeAttribute('thread-strategy');
261
+ }
262
+ }
245
263
  /**
246
264
  * @private
247
265
  */
@@ -252,6 +270,12 @@ export class LynxView extends HTMLElement {
252
270
  this.shadowRoot.innerHTML = '';
253
271
  }
254
272
  }
273
+ /**
274
+ * @public
275
+ * allow user to customize the template loader
276
+ * @param url the url of the template
277
+ */
278
+ customTemplateLoader;
255
279
  /**
256
280
  * @private the flag to group all changes into one render operation
257
281
  */
@@ -281,7 +305,9 @@ export class LynxView extends HTMLElement {
281
305
  this.attachShadow({ mode: 'open' });
282
306
  }
283
307
  const lynxGroupId = this.lynxGroupId;
308
+ const threadStrategy = (this.threadStrategy ?? 'multi-thread');
284
309
  const lynxView = createLynxView({
310
+ threadStrategy,
285
311
  tagMap,
286
312
  shadowRoot: this.shadowRoot,
287
313
  templateUrl: this.#url,
@@ -308,6 +334,7 @@ export class LynxView extends HTMLElement {
308
334
  onError: () => {
309
335
  this.dispatchEvent(new CustomEvent('error', {}));
310
336
  },
337
+ customTemplateLoader: this.customTemplateLoader,
311
338
  },
312
339
  });
313
340
  this.#instance = lynxView;
@@ -1,16 +1,17 @@
1
1
  import type { Cloneable, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
2
- import { startUIThread } from '../uiThread/startUIThread.js';
2
+ import { type StartUIThreadCallbacks } from '../uiThread/startUIThread.js';
3
3
  import type { RpcCallType } from '@lynx-js/web-worker-rpc';
4
4
  export interface LynxViewConfigs {
5
5
  templateUrl: string;
6
6
  initData: Cloneable;
7
7
  globalProps: Cloneable;
8
8
  shadowRoot: ShadowRoot;
9
- callbacks: Parameters<typeof startUIThread>[4];
9
+ callbacks: StartUIThreadCallbacks;
10
10
  nativeModulesMap: NativeModulesMap;
11
11
  napiModulesMap: NapiModulesMap;
12
12
  tagMap: Record<string, string>;
13
13
  lynxGroupId: number | undefined;
14
+ threadStrategy: 'all-on-ui' | 'multi-thread';
14
15
  }
15
16
  export interface LynxView {
16
17
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
@@ -1,16 +1,18 @@
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 { startUIThread } from '../uiThread/startUIThread.js';
4
+ import { startUIThread, } from '../uiThread/startUIThread.js';
5
5
  export function createLynxView(configs) {
6
- const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, } = configs;
6
+ const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, threadStrategy = 'multi-thread', } = configs;
7
7
  return startUIThread(templateUrl, {
8
8
  tagMap,
9
9
  initData,
10
10
  globalProps,
11
11
  nativeModulesMap,
12
12
  napiModulesMap,
13
- browserConfig: {},
14
- }, shadowRoot, lynxGroupId, callbacks);
13
+ browserConfig: {
14
+ pixelRatio: window.devicePixelRatio,
15
+ },
16
+ }, shadowRoot, lynxGroupId, threadStrategy, callbacks);
15
17
  }
16
18
  //# sourceMappingURL=createLynxView.js.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { createLynxView } from './apis/createLynxView.js';
2
2
  export { LynxView } from './apis/LynxView.js';
3
+ export type { LynxTemplate } from '@lynx-js/web-constants';
@@ -4,5 +4,5 @@ interface LynxViewRpc {
4
4
  backgroundRpc: Rpc;
5
5
  terminateWorkers: () => void;
6
6
  }
7
- export declare function bootWorkers(lynxGroupId: number | undefined): LynxViewRpc;
7
+ export declare function bootWorkers(lynxGroupId: number | undefined, allOnUI?: boolean): LynxViewRpc;
8
8
  export {};
@@ -5,9 +5,15 @@ import { Rpc } from '@lynx-js/web-worker-rpc';
5
5
  const backgroundWorkerContextCount = [];
6
6
  const contextIdToBackgroundWorker = [];
7
7
  let preHeatedMainWorker = createMainWorker();
8
- export function bootWorkers(lynxGroupId) {
9
- const curMainWorker = preHeatedMainWorker;
10
- preHeatedMainWorker = createMainWorker();
8
+ export function bootWorkers(lynxGroupId, allOnUI) {
9
+ let curMainWorker;
10
+ if (allOnUI) {
11
+ curMainWorker = createUIChannel();
12
+ }
13
+ else {
14
+ curMainWorker = preHeatedMainWorker;
15
+ preHeatedMainWorker = createMainWorker();
16
+ }
11
17
  const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground);
12
18
  if (lynxGroupId !== undefined) {
13
19
  if (backgroundWorkerContextCount[lynxGroupId]) {
@@ -21,7 +27,7 @@ export function bootWorkers(lynxGroupId) {
21
27
  mainThreadRpc: curMainWorker.mainThreadRpc,
22
28
  backgroundRpc: curBackgroundWorker.backgroundRpc,
23
29
  terminateWorkers: () => {
24
- curMainWorker.mainThreadWorker.terminate();
30
+ curMainWorker.mainThreadWorker?.terminate();
25
31
  if (lynxGroupId === undefined) {
26
32
  curBackgroundWorker.backgroundThreadWorker.terminate();
27
33
  }
@@ -33,6 +39,14 @@ export function bootWorkers(lynxGroupId) {
33
39
  },
34
40
  };
35
41
  }
42
+ function createUIChannel() {
43
+ const channelMainThreadWithBackground = new MessageChannel();
44
+ const mainThreadRpc = new Rpc(channelMainThreadWithBackground.port1, 'main-to-bg');
45
+ return {
46
+ mainThreadRpc,
47
+ channelMainThreadWithBackground,
48
+ };
49
+ }
36
50
  function createMainWorker() {
37
51
  const channelToMainThread = new MessageChannel();
38
52
  const channelMainThreadWithBackground = new MessageChannel();
@@ -41,7 +55,6 @@ function createMainWorker() {
41
55
  mode: 'main',
42
56
  toUIThread: channelToMainThread.port2,
43
57
  toPeerThread: channelMainThreadWithBackground.port1,
44
- pixelRatio: window.devicePixelRatio,
45
58
  };
46
59
  mainThreadWorker.postMessage(mainThreadMessage, [
47
60
  channelToMainThread.port2,
@@ -69,7 +82,6 @@ function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
69
82
  mode: 'background',
70
83
  toUIThread: channelToBackground.port2,
71
84
  toPeerThread: channelMainThreadWithBackground.port2,
72
- pixelRatio: window.devicePixelRatio,
73
85
  };
74
86
  backgroundThreadWorker.postMessage(backgroundThreadMessage, [
75
87
  channelToBackground.port2,
@@ -0,0 +1,8 @@
1
+ import type { MainThreadStartConfigs } from '@lynx-js/web-constants';
2
+ import { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, callbacks: {
4
+ onError?: () => void;
5
+ }): {
6
+ start: (configs: MainThreadStartConfigs) => Promise<void>;
7
+ updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
8
+ };
@@ -0,0 +1,26 @@
1
+ import { Rpc } from '@lynx-js/web-worker-rpc';
2
+ const { loadMainThread, } = await import('@lynx-js/web-mainthread-apis');
3
+ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, callbacks) {
4
+ if (!globalThis.module) {
5
+ Object.assign(globalThis, { module: {} });
6
+ }
7
+ const docu = Object.assign(shadowRoot, {
8
+ createElement: document.createElement.bind(document),
9
+ });
10
+ const { startMainThread } = loadMainThread(mainToBackgroundRpc, docu, () => { }, markTimingInternal, () => {
11
+ callbacks.onError?.();
12
+ });
13
+ let runtime;
14
+ const start = async (configs) => {
15
+ const mainThreadRuntime = startMainThread(configs);
16
+ runtime = await mainThreadRuntime;
17
+ };
18
+ const updateDataMainThread = async (...args) => {
19
+ runtime.updatePage?.(...args);
20
+ };
21
+ return {
22
+ start,
23
+ updateDataMainThread,
24
+ };
25
+ }
26
+ //# sourceMappingURL=createRenderAllOnUI.js.map
@@ -0,0 +1,7 @@
1
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
2
+ export declare function createRenderMultiThread(mainThreadRpc: Rpc, shadowRoot: ShadowRoot, callbacks: {
3
+ onError?: () => void;
4
+ }): {
5
+ start: (args_0: import("@lynx-js/web-constants").MainThreadStartConfigs) => void;
6
+ updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
7
+ };
@@ -0,0 +1,16 @@
1
+ import { mainThreadStartEndpoint, updateDataEndpoint, } from '@lynx-js/web-constants';
2
+ import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js';
3
+ import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerFlushElementTreeHandler.js';
4
+ export function createRenderMultiThread(mainThreadRpc, shadowRoot, callbacks) {
5
+ registerReportErrorHandler(mainThreadRpc, callbacks.onError);
6
+ registerFlushElementTreeHandler(mainThreadRpc, {
7
+ shadowRoot,
8
+ });
9
+ const start = mainThreadRpc.createCall(mainThreadStartEndpoint);
10
+ const updateDataMainThread = mainThreadRpc.createCall(updateDataEndpoint);
11
+ return {
12
+ start,
13
+ updateDataMainThread,
14
+ };
15
+ }
16
+ //# sourceMappingURL=createRenderMultiThread.js.map
@@ -1,3 +1,4 @@
1
- import type { Rpc } from '@lynx-js/web-worker-rpc';
1
+ import type { RpcCallType } from '@lynx-js/web-worker-rpc';
2
2
  import type { LynxView } from '../../apis/createLynxView.js';
3
- export declare function createUpdateData(mainThreadRpc: Rpc, backgroundRpc: Rpc): LynxView['updateData'];
3
+ import { updateDataEndpoint } from '@lynx-js/web-constants';
4
+ export declare function createUpdateData(updateDataMainThread: RpcCallType<typeof updateDataEndpoint>, updateDataBackground: RpcCallType<typeof updateDataEndpoint>): LynxView['updateData'];
@@ -2,12 +2,12 @@
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 { updateDataEndpoint, } from '@lynx-js/web-constants';
5
- export function createUpdateData(mainThreadRpc, backgroundRpc) {
5
+ export function createUpdateData(updateDataMainThread, updateDataBackground) {
6
6
  return (data, _updateDataType, callback) => {
7
7
  Promise.all([
8
8
  // There is no need to process options for now, as they have default values.
9
- mainThreadRpc.invoke(updateDataEndpoint, [data, {}]),
10
- backgroundRpc.invoke(updateDataEndpoint, [data, {}]),
9
+ updateDataMainThread(data, {}),
10
+ updateDataBackground(data, {}),
11
11
  ]).then(() => callback?.());
12
12
  };
13
13
  }
@@ -0,0 +1,10 @@
1
+ import { type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function startBackground(backgroundRpc: Rpc, shadowRoot: ShadowRoot, callbacks: {
4
+ nativeModulesCall: NativeModulesCall;
5
+ napiModulesCall: NapiModulesCall;
6
+ }): {
7
+ sendGlobalEvent: (args_0: string, args_1: import("@lynx-js/web-constants").Cloneable[] | undefined) => void;
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>;
10
+ };
@@ -0,0 +1,26 @@
1
+ import { markTimingEndpoint, sendGlobalEventEndpoint, updateDataEndpoint, } from '@lynx-js/web-constants';
2
+ import { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js';
3
+ import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js';
4
+ import { registerNativeModulesCallHandler } from './crossThreadHandlers/registerNativeModulesCallHandler.js';
5
+ import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js';
6
+ import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
7
+ import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
8
+ import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
9
+ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
10
+ registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
11
+ registerNativePropsHandler(backgroundRpc, shadowRoot);
12
+ registerTriggerComponentEventHandler(backgroundRpc, shadowRoot);
13
+ registerSelectComponentHandler(backgroundRpc, shadowRoot);
14
+ registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
15
+ registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
16
+ registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
17
+ const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
18
+ const markTiming = backgroundRpc.createCall(markTimingEndpoint);
19
+ const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint);
20
+ return {
21
+ sendGlobalEvent,
22
+ markTiming,
23
+ updateDataBackground,
24
+ };
25
+ }
26
+ //# sourceMappingURL=startBackground.js.map
@@ -1,7 +1,9 @@
1
1
  import type { LynxView } from '../apis/createLynxView.js';
2
- import { type MainThreadStartConfigs, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
3
- export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, callbacks: {
2
+ import { type LynxTemplate, type MainThreadStartConfigs, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
3
+ export type StartUIThreadCallbacks = {
4
4
  nativeModulesCall: NativeModulesCall;
5
5
  napiModulesCall: NapiModulesCall;
6
6
  onError?: () => void;
7
- }): LynxView;
7
+ customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
8
+ };
9
+ export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks): LynxView;
@@ -1,56 +1,40 @@
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 { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js';
5
- import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js';
6
- import { registerNativeModulesCallHandler } from './crossThreadHandlers/registerNativeModulesCallHandler.js';
7
4
  import { bootWorkers } from './bootWorkers.js';
8
- import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js';
9
- import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerFlushElementTreeHandler.js';
10
5
  import { createDispose } from './crossThreadHandlers/createDispose.js';
11
- import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js';
12
- import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
13
- import { mainThreadStartEndpoint, markTimingEndpoint, sendGlobalEventEndpoint, } from '@lynx-js/web-constants';
6
+ import {} from '@lynx-js/web-constants';
14
7
  import { loadTemplate } from '../utils/loadTemplate.js';
15
8
  import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
16
- import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
17
- import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
18
- export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, callbacks) {
9
+ import { startBackground } from './startBackground.js';
10
+ import { createRenderMultiThread } from './createRenderMultiThread.js';
11
+ import { createRenderAllOnUI } from './createRenderAllOnUI.js';
12
+ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, threadStrategy, callbacks) {
19
13
  const createLynxStartTiming = performance.now() + performance.timeOrigin;
20
- const { nativeModulesMap, napiModulesMap } = configs;
21
- const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId);
22
- const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
23
- const mainThreadStart = mainThreadRpc.createCall(mainThreadStartEndpoint);
24
- const markTiming = backgroundRpc.createCall(markTimingEndpoint);
14
+ const allOnUI = threadStrategy === 'all-on-ui';
15
+ const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI);
16
+ const { markTiming, sendGlobalEvent, updateDataBackground } = startBackground(backgroundRpc, shadowRoot, callbacks);
25
17
  const markTimingInternal = (timingKey, pipelineId, timeStamp) => {
26
18
  if (!timeStamp)
27
19
  timeStamp = performance.now() + performance.timeOrigin;
28
20
  markTiming(timingKey, pipelineId, timeStamp);
29
21
  };
22
+ const { start, updateDataMainThread } = allOnUI
23
+ ? createRenderAllOnUI(
24
+ /* main-to-bg rpc*/ mainThreadRpc, shadowRoot, markTimingInternal, callbacks)
25
+ : createRenderMultiThread(
26
+ /* main-to-ui rpc*/ mainThreadRpc, shadowRoot, callbacks);
30
27
  markTimingInternal('create_lynx_start', undefined, createLynxStartTiming);
31
28
  markTimingInternal('load_template_start');
32
- loadTemplate(templateUrl).then((template) => {
29
+ loadTemplate(templateUrl, callbacks.customTemplateLoader).then((template) => {
33
30
  markTimingInternal('load_template_end');
34
- mainThreadStart({
31
+ start({
35
32
  ...configs,
36
33
  template,
37
- nativeModulesMap,
38
- napiModulesMap,
39
34
  });
40
35
  });
41
- registerReportErrorHandler(mainThreadRpc, callbacks.onError);
42
- registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
43
- registerFlushElementTreeHandler(mainThreadRpc, {
44
- shadowRoot,
45
- });
46
- registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
47
- registerNativePropsHandler(backgroundRpc, shadowRoot);
48
- registerTriggerComponentEventHandler(backgroundRpc, shadowRoot);
49
- registerSelectComponentHandler(backgroundRpc, shadowRoot);
50
- registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
51
- registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
52
36
  return {
53
- updateData: createUpdateData(mainThreadRpc, backgroundRpc),
37
+ updateData: createUpdateData(updateDataMainThread, updateDataBackground),
54
38
  dispose: createDispose(backgroundRpc, terminateWorkers),
55
39
  sendGlobalEvent,
56
40
  };
@@ -1,2 +1,2 @@
1
1
  import { type LynxTemplate } from '@lynx-js/web-constants';
2
- export declare function loadTemplate(url: string): Promise<LynxTemplate>;
2
+ export declare function loadTemplate(url: string, customTemplateLoader?: (url: string) => Promise<LynxTemplate>): Promise<LynxTemplate>;
@@ -82,24 +82,28 @@ const mainThreadInjectVars = [
82
82
  '__OnLifecycleEvent',
83
83
  '__FlushElementTree',
84
84
  '__LoadLepusChunk',
85
+ 'SystemInfo',
85
86
  ];
86
87
  const backgroundInjectVars = [
87
88
  'NativeModules',
88
89
  'globalThis',
89
90
  'lynx',
90
91
  'lynxCoreInject',
92
+ 'SystemInfo',
91
93
  ];
92
94
  const backgroundInjectWithBind = [
93
95
  'Card',
94
96
  'Component',
95
97
  ];
96
- export async function loadTemplate(url) {
98
+ export async function loadTemplate(url, customTemplateLoader) {
97
99
  const cachedTemplate = TemplateCache[url];
98
100
  if (cachedTemplate)
99
101
  return cachedTemplate;
100
- const template = (await (await fetch(url, {
101
- method: 'GET',
102
- })).json());
102
+ const template = customTemplateLoader
103
+ ? await customTemplateLoader(url)
104
+ : (await (await fetch(url, {
105
+ method: 'GET',
106
+ })).json());
103
107
  const decodedTemplate = {
104
108
  ...template,
105
109
  lepusCode: generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,17 +24,18 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/offscreen-document": "0.0.0",
28
- "@lynx-js/web-constants": "0.11.0",
29
- "@lynx-js/web-worker-rpc": "0.11.0",
30
- "@lynx-js/web-worker-runtime": "0.11.0"
27
+ "@lynx-js/offscreen-document": "0.0.1",
28
+ "@lynx-js/web-constants": "0.13.0",
29
+ "@lynx-js/web-mainthread-apis": "0.13.0",
30
+ "@lynx-js/web-worker-rpc": "0.13.0",
31
+ "@lynx-js/web-worker-runtime": "0.13.0"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@lynx-js/lynx-core": "0.1.2",
34
- "@lynx-js/web-elements": "0.5.4"
35
+ "@lynx-js/web-elements": "0.7.0"
35
36
  },
36
37
  "peerDependencies": {
37
38
  "@lynx-js/lynx-core": "0.1.2",
38
- "@lynx-js/web-elements": ">=0.3.1"
39
+ "@lynx-js/web-elements": ">=0.6.0"
39
40
  }
40
41
  }
@@ -1,4 +0,0 @@
1
- export interface LynxExposureModule {
2
- resumeExposure: () => void;
3
- stopExposure: () => void;
4
- }
@@ -1,5 +0,0 @@
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
- export {};
5
- //# sourceMappingURL=LynxExposureModule.js.map