@lynx-js/web-core 0.10.1 → 0.12.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 +82 -0
- package/dist/apis/LynxView.d.ts +15 -1
- package/dist/apis/LynxView.js +28 -0
- package/dist/apis/createLynxView.d.ts +2 -1
- package/dist/apis/createLynxView.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/uiThread/bootWorkers.d.ts +1 -1
- package/dist/uiThread/bootWorkers.js +33 -8
- package/dist/uiThread/crossThreadHandlers/registerFlushElementTreeHandler.d.ts +1 -3
- package/dist/uiThread/crossThreadHandlers/registerFlushElementTreeHandler.js +1 -8
- package/dist/uiThread/startUIThread.d.ts +3 -2
- package/dist/uiThread/startUIThread.js +10 -21
- package/dist/utils/loadTemplate.d.ts +1 -1
- package/dist/utils/loadTemplate.js +7 -4
- package/package.json +8 -8
- package/dist/types/LynxExposureModule.d.ts +0 -4
- package/dist/types/LynxExposureModule.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
1
|
# @lynx-js/web-core
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: improve compatibility for chrome 108 & support linear-gradient for nested x-text ([#590](https://github.com/lynx-family/lynx-stack/pull/590))
|
|
8
|
+
|
|
9
|
+
**This is a breaking change**
|
|
10
|
+
|
|
11
|
+
- Please upgrade your `@lynx-js/web-elements` to >=0.6.0
|
|
12
|
+
- Please upgrade your `@lynx-js/web-core` to >=0.12.0
|
|
13
|
+
- The compiled lynx template json won't be impacted.
|
|
14
|
+
|
|
15
|
+
On chrome 108, the `-webkit-background-clip:text` cannot be computed by a `var(--css-var-value-text)`
|
|
16
|
+
|
|
17
|
+
Therefore we move the logic into style transformation logic.
|
|
18
|
+
|
|
19
|
+
Now the following status is supported
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
<text style="color:linear-gradient()">
|
|
23
|
+
<text>
|
|
24
|
+
<text>
|
|
25
|
+
</text>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- feat: allow user to implement custom template load function ([#587](https://github.com/lynx-family/lynx-stack/pull/587))
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
lynxView.customTemplateLoader = (url) => {
|
|
34
|
+
return (await (await fetch(url, {
|
|
35
|
+
method: 'GET',
|
|
36
|
+
})).json());
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- feat: support mts event with target methods ([#564](https://github.com/lynx-family/lynx-stack/pull/564))
|
|
41
|
+
|
|
42
|
+
After this commit, developers are allowed to invoke `event.target.setStyleProperty` in mts handler
|
|
43
|
+
|
|
44
|
+
- fix: crash on removing a id attribute ([#582](https://github.com/lynx-family/lynx-stack/pull/582))
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [[`f1ca29b`](https://github.com/lynx-family/lynx-stack/commit/f1ca29bd766377dd46583f15e1e75bca447699cd)]:
|
|
47
|
+
- @lynx-js/web-worker-runtime@0.12.0
|
|
48
|
+
- @lynx-js/web-constants@0.12.0
|
|
49
|
+
- @lynx-js/web-worker-rpc@0.12.0
|
|
50
|
+
|
|
51
|
+
## 0.11.0
|
|
52
|
+
|
|
53
|
+
### Minor Changes
|
|
54
|
+
|
|
55
|
+
- feat: upgrade @lynx-js/lynx-core to 0.1.2 ([#465](https://github.com/lynx-family/lynx-stack/pull/465))
|
|
56
|
+
|
|
57
|
+
refactor some internal logic
|
|
58
|
+
|
|
59
|
+
- \_\_OnLifeCycleEvent
|
|
60
|
+
- \_\_OnNativeAppReady
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- feat: support mts event handler (1/n) ([#495](https://github.com/lynx-family/lynx-stack/pull/495))
|
|
65
|
+
|
|
66
|
+
now the main-thread:bind handler could be invoked. The params of the handler will be implemented later.
|
|
67
|
+
|
|
68
|
+
- feat: allow multi lynx-view to share bts worker ([#520](https://github.com/lynx-family/lynx-stack/pull/520))
|
|
69
|
+
|
|
70
|
+
Now we allow users to enable so-called "shared-context" feature on the Web Platform.
|
|
71
|
+
|
|
72
|
+
Similar to the same feature for Lynx iOS/Android, this feature let multi lynx cards to share one js context.
|
|
73
|
+
|
|
74
|
+
The `lynx.getSharedData` and `lynx.setSharedData` are also supported in this commit.
|
|
75
|
+
|
|
76
|
+
To enable this feature, set property `lynxGroupId` or attribute `lynx-group-id` before a lynx-view starts rendering. Those card with same context id will share one web worker for the bts scripts.
|
|
77
|
+
|
|
78
|
+
- perf: dispatchLynxViewEventEndpoint is a void call ([#506](https://github.com/lynx-family/lynx-stack/pull/506))
|
|
79
|
+
|
|
80
|
+
- Updated dependencies [[`ea42e62`](https://github.com/lynx-family/lynx-stack/commit/ea42e62fbcd5c743132c3e6e7c4851770742d544), [`a0f5ca4`](https://github.com/lynx-family/lynx-stack/commit/a0f5ca4ea0895ccbaa6aa63f449f53a677a1cf73)]:
|
|
81
|
+
- @lynx-js/web-worker-runtime@0.11.0
|
|
82
|
+
- @lynx-js/web-constants@0.11.0
|
|
83
|
+
- @lynx-js/web-worker-rpc@0.11.0
|
|
84
|
+
|
|
3
85
|
## 0.10.1
|
|
4
86
|
|
|
5
87
|
### Patch Changes
|
package/dist/apis/LynxView.d.ts
CHANGED
|
@@ -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[];
|
|
@@ -21,6 +21,8 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
|
|
|
21
21
|
* @property {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
|
|
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
|
+
* @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 {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
|
|
24
26
|
*
|
|
25
27
|
* @event error lynx card fired an error
|
|
26
28
|
*
|
|
@@ -102,6 +104,12 @@ export declare class LynxView extends HTMLElement {
|
|
|
102
104
|
*/
|
|
103
105
|
get onNapiModulesCall(): NapiModulesCall | undefined;
|
|
104
106
|
set onNapiModulesCall(handler: INapiModulesCall);
|
|
107
|
+
/**
|
|
108
|
+
* @param
|
|
109
|
+
* @property
|
|
110
|
+
*/
|
|
111
|
+
get lynxGroupId(): number | undefined;
|
|
112
|
+
set lynxGroupId(val: number | undefined);
|
|
105
113
|
/**
|
|
106
114
|
* @public
|
|
107
115
|
* @method
|
|
@@ -135,6 +143,12 @@ export declare class LynxView extends HTMLElement {
|
|
|
135
143
|
* @private
|
|
136
144
|
*/
|
|
137
145
|
disconnectedCallback(): void;
|
|
146
|
+
/**
|
|
147
|
+
* @public
|
|
148
|
+
* allow user to customize the template loader
|
|
149
|
+
* @param url the url of the template
|
|
150
|
+
*/
|
|
151
|
+
customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
|
|
138
152
|
/**
|
|
139
153
|
* @private
|
|
140
154
|
*/
|
package/dist/apis/LynxView.js
CHANGED
|
@@ -19,6 +19,8 @@ import { inShadowRootStyles } from './inShadowRootStyles.js';
|
|
|
19
19
|
* @property {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
|
|
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
|
+
* @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 {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
|
|
22
24
|
*
|
|
23
25
|
* @event error lynx card fired an error
|
|
24
26
|
*
|
|
@@ -168,6 +170,23 @@ export class LynxView extends HTMLElement {
|
|
|
168
170
|
return handler(name, data, moduleName, this, dispatchNapiModules);
|
|
169
171
|
};
|
|
170
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* @param
|
|
175
|
+
* @property
|
|
176
|
+
*/
|
|
177
|
+
get lynxGroupId() {
|
|
178
|
+
return this.getAttribute('lynx-group-id')
|
|
179
|
+
? Number(this.getAttribute('lynx-group-id'))
|
|
180
|
+
: undefined;
|
|
181
|
+
}
|
|
182
|
+
set lynxGroupId(val) {
|
|
183
|
+
if (val) {
|
|
184
|
+
this.setAttribute('lynx-group-id', val.toString());
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.removeAttribute('lynx-group-id');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
171
190
|
/**
|
|
172
191
|
* @public
|
|
173
192
|
* @method
|
|
@@ -234,6 +253,12 @@ export class LynxView extends HTMLElement {
|
|
|
234
253
|
this.shadowRoot.innerHTML = '';
|
|
235
254
|
}
|
|
236
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* @public
|
|
258
|
+
* allow user to customize the template loader
|
|
259
|
+
* @param url the url of the template
|
|
260
|
+
*/
|
|
261
|
+
customTemplateLoader;
|
|
237
262
|
/**
|
|
238
263
|
* @private the flag to group all changes into one render operation
|
|
239
264
|
*/
|
|
@@ -262,6 +287,7 @@ export class LynxView extends HTMLElement {
|
|
|
262
287
|
if (!this.shadowRoot) {
|
|
263
288
|
this.attachShadow({ mode: 'open' });
|
|
264
289
|
}
|
|
290
|
+
const lynxGroupId = this.lynxGroupId;
|
|
265
291
|
const lynxView = createLynxView({
|
|
266
292
|
tagMap,
|
|
267
293
|
shadowRoot: this.shadowRoot,
|
|
@@ -270,6 +296,7 @@ export class LynxView extends HTMLElement {
|
|
|
270
296
|
initData: this.#initData,
|
|
271
297
|
nativeModulesMap: this.#nativeModulesMap,
|
|
272
298
|
napiModulesMap: this.#napiModulesMap,
|
|
299
|
+
lynxGroupId,
|
|
273
300
|
callbacks: {
|
|
274
301
|
nativeModulesCall: (...args) => {
|
|
275
302
|
if (this.#onNativeModulesCall) {
|
|
@@ -288,6 +315,7 @@ export class LynxView extends HTMLElement {
|
|
|
288
315
|
onError: () => {
|
|
289
316
|
this.dispatchEvent(new CustomEvent('error', {}));
|
|
290
317
|
},
|
|
318
|
+
customTemplateLoader: this.customTemplateLoader,
|
|
291
319
|
},
|
|
292
320
|
});
|
|
293
321
|
this.#instance = lynxView;
|
|
@@ -6,10 +6,11 @@ export interface LynxViewConfigs {
|
|
|
6
6
|
initData: Cloneable;
|
|
7
7
|
globalProps: Cloneable;
|
|
8
8
|
shadowRoot: ShadowRoot;
|
|
9
|
-
callbacks: Parameters<typeof startUIThread>[
|
|
9
|
+
callbacks: Parameters<typeof startUIThread>[4];
|
|
10
10
|
nativeModulesMap: NativeModulesMap;
|
|
11
11
|
napiModulesMap: NapiModulesMap;
|
|
12
12
|
tagMap: Record<string, string>;
|
|
13
|
+
lynxGroupId: number | undefined;
|
|
13
14
|
}
|
|
14
15
|
export interface LynxView {
|
|
15
16
|
updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { startUIThread } from '../uiThread/startUIThread.js';
|
|
5
5
|
export function createLynxView(configs) {
|
|
6
|
-
const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, } = configs;
|
|
6
|
+
const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, } = configs;
|
|
7
7
|
return startUIThread(templateUrl, {
|
|
8
8
|
tagMap,
|
|
9
9
|
initData,
|
|
@@ -11,6 +11,6 @@ export function createLynxView(configs) {
|
|
|
11
11
|
nativeModulesMap,
|
|
12
12
|
napiModulesMap,
|
|
13
13
|
browserConfig: {},
|
|
14
|
-
}, shadowRoot, callbacks);
|
|
14
|
+
}, shadowRoot, lynxGroupId, callbacks);
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=createLynxView.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -2,24 +2,41 @@
|
|
|
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 { Rpc } from '@lynx-js/web-worker-rpc';
|
|
5
|
+
const backgroundWorkerContextCount = [];
|
|
6
|
+
const contextIdToBackgroundWorker = [];
|
|
5
7
|
let preHeatedMainWorker = createMainWorker();
|
|
6
|
-
export function bootWorkers() {
|
|
8
|
+
export function bootWorkers(lynxGroupId) {
|
|
7
9
|
const curMainWorker = preHeatedMainWorker;
|
|
8
|
-
const curBackgroundWorker = createBackgroundWorker(curMainWorker.channelMainThreadWithBackground);
|
|
9
10
|
preHeatedMainWorker = createMainWorker();
|
|
11
|
+
const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground);
|
|
12
|
+
if (lynxGroupId !== undefined) {
|
|
13
|
+
if (backgroundWorkerContextCount[lynxGroupId]) {
|
|
14
|
+
backgroundWorkerContextCount[lynxGroupId]++;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
backgroundWorkerContextCount[lynxGroupId] = 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
10
20
|
return {
|
|
11
21
|
mainThreadRpc: curMainWorker.mainThreadRpc,
|
|
12
22
|
backgroundRpc: curBackgroundWorker.backgroundRpc,
|
|
13
23
|
terminateWorkers: () => {
|
|
14
24
|
curMainWorker.mainThreadWorker.terminate();
|
|
15
|
-
|
|
25
|
+
if (lynxGroupId === undefined) {
|
|
26
|
+
curBackgroundWorker.backgroundThreadWorker.terminate();
|
|
27
|
+
}
|
|
28
|
+
else if (backgroundWorkerContextCount[lynxGroupId] === 1) {
|
|
29
|
+
curBackgroundWorker.backgroundThreadWorker.terminate();
|
|
30
|
+
backgroundWorkerContextCount[lynxGroupId] = 0;
|
|
31
|
+
contextIdToBackgroundWorker[lynxGroupId] = undefined;
|
|
32
|
+
}
|
|
16
33
|
},
|
|
17
34
|
};
|
|
18
35
|
}
|
|
19
36
|
function createMainWorker() {
|
|
20
37
|
const channelToMainThread = new MessageChannel();
|
|
21
38
|
const channelMainThreadWithBackground = new MessageChannel();
|
|
22
|
-
const mainThreadWorker = createWebWorker();
|
|
39
|
+
const mainThreadWorker = createWebWorker('lynx-main');
|
|
23
40
|
const mainThreadMessage = {
|
|
24
41
|
mode: 'main',
|
|
25
42
|
toUIThread: channelToMainThread.port2,
|
|
@@ -37,9 +54,17 @@ function createMainWorker() {
|
|
|
37
54
|
channelMainThreadWithBackground,
|
|
38
55
|
};
|
|
39
56
|
}
|
|
40
|
-
function createBackgroundWorker(channelMainThreadWithBackground) {
|
|
57
|
+
function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
41
58
|
const channelToBackground = new MessageChannel();
|
|
42
|
-
|
|
59
|
+
let backgroundThreadWorker;
|
|
60
|
+
if (lynxGroupId) {
|
|
61
|
+
backgroundThreadWorker = contextIdToBackgroundWorker[lynxGroupId]
|
|
62
|
+
?? createWebWorker('lynx-bg');
|
|
63
|
+
contextIdToBackgroundWorker[lynxGroupId] = backgroundThreadWorker;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
backgroundThreadWorker = createWebWorker('lynx-bg');
|
|
67
|
+
}
|
|
43
68
|
const backgroundThreadMessage = {
|
|
44
69
|
mode: 'background',
|
|
45
70
|
toUIThread: channelToBackground.port2,
|
|
@@ -53,10 +78,10 @@ function createBackgroundWorker(channelMainThreadWithBackground) {
|
|
|
53
78
|
const backgroundRpc = new Rpc(channelToBackground.port1, 'ui-to-bg');
|
|
54
79
|
return { backgroundRpc, backgroundThreadWorker };
|
|
55
80
|
}
|
|
56
|
-
function createWebWorker() {
|
|
81
|
+
function createWebWorker(name) {
|
|
57
82
|
return new Worker(new URL('@lynx-js/web-worker-runtime', import.meta.url), {
|
|
58
83
|
type: 'module',
|
|
59
|
-
name
|
|
84
|
+
name,
|
|
60
85
|
});
|
|
61
86
|
}
|
|
62
87
|
//# sourceMappingURL=bootWorkers.js.map
|
|
@@ -3,22 +3,15 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { flushElementTreeEndpoint, postOffscreenEventEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { initOffscreenDocument } from '@lynx-js/offscreen-document/main';
|
|
6
|
-
export function registerFlushElementTreeHandler(mainThreadRpc, options
|
|
6
|
+
export function registerFlushElementTreeHandler(mainThreadRpc, options) {
|
|
7
7
|
const { shadowRoot, } = options;
|
|
8
8
|
const onEvent = mainThreadRpc.createCall(postOffscreenEventEndpoint);
|
|
9
9
|
const { decodeOperation } = initOffscreenDocument({
|
|
10
10
|
shadowRoot,
|
|
11
11
|
onEvent,
|
|
12
12
|
});
|
|
13
|
-
let isFP = true;
|
|
14
13
|
mainThreadRpc.registerHandler(flushElementTreeEndpoint, (operations) => {
|
|
15
14
|
decodeOperation(operations);
|
|
16
|
-
onCommit({
|
|
17
|
-
isFP,
|
|
18
|
-
});
|
|
19
|
-
if (isFP) {
|
|
20
|
-
isFP = false;
|
|
21
|
-
}
|
|
22
15
|
});
|
|
23
16
|
}
|
|
24
17
|
//# sourceMappingURL=registerFlushElementTreeHandler.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
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, callbacks: {
|
|
2
|
+
import { type LynxTemplate, 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: {
|
|
4
4
|
nativeModulesCall: NativeModulesCall;
|
|
5
5
|
napiModulesCall: NapiModulesCall;
|
|
6
6
|
onError?: () => void;
|
|
7
|
+
customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
|
|
7
8
|
}): LynxView;
|
|
@@ -10,17 +10,15 @@ import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerF
|
|
|
10
10
|
import { createDispose } from './crossThreadHandlers/createDispose.js';
|
|
11
11
|
import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js';
|
|
12
12
|
import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
|
|
13
|
-
import {
|
|
13
|
+
import { mainThreadStartEndpoint, markTimingEndpoint, sendGlobalEventEndpoint, } from '@lynx-js/web-constants';
|
|
14
14
|
import { loadTemplate } from '../utils/loadTemplate.js';
|
|
15
15
|
import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
|
|
16
16
|
import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
|
|
17
17
|
import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
|
|
18
|
-
export function startUIThread(templateUrl, configs, shadowRoot, callbacks) {
|
|
18
|
+
export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, callbacks) {
|
|
19
19
|
const createLynxStartTiming = performance.now() + performance.timeOrigin;
|
|
20
|
-
const {
|
|
21
|
-
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers();
|
|
20
|
+
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId);
|
|
22
21
|
const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
|
|
23
|
-
const uiThreadFpReady = backgroundRpc.createCall(uiThreadFpReadyEndpoint);
|
|
24
22
|
const mainThreadStart = mainThreadRpc.createCall(mainThreadStartEndpoint);
|
|
25
23
|
const markTiming = backgroundRpc.createCall(markTimingEndpoint);
|
|
26
24
|
const markTimingInternal = (timingKey, pipelineId, timeStamp) => {
|
|
@@ -30,31 +28,22 @@ export function startUIThread(templateUrl, configs, shadowRoot, callbacks) {
|
|
|
30
28
|
};
|
|
31
29
|
markTimingInternal('create_lynx_start', undefined, createLynxStartTiming);
|
|
32
30
|
markTimingInternal('load_template_start');
|
|
33
|
-
loadTemplate(templateUrl).then((template) => {
|
|
31
|
+
loadTemplate(templateUrl, callbacks.customTemplateLoader).then((template) => {
|
|
34
32
|
markTimingInternal('load_template_end');
|
|
35
33
|
mainThreadStart({
|
|
36
34
|
...configs,
|
|
37
35
|
template,
|
|
38
|
-
nativeModulesMap,
|
|
39
|
-
napiModulesMap,
|
|
40
36
|
});
|
|
41
37
|
});
|
|
42
38
|
registerReportErrorHandler(mainThreadRpc, callbacks.onError);
|
|
43
39
|
registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
|
|
44
|
-
mainThreadRpc
|
|
45
|
-
|
|
46
|
-
shadowRoot,
|
|
47
|
-
}, (info) => {
|
|
48
|
-
const { isFP } = info;
|
|
49
|
-
if (isFP) {
|
|
50
|
-
registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
|
|
51
|
-
registerNativePropsHandler(backgroundRpc, shadowRoot);
|
|
52
|
-
registerTriggerComponentEventHandler(backgroundRpc, shadowRoot);
|
|
53
|
-
registerSelectComponentHandler(backgroundRpc, shadowRoot);
|
|
54
|
-
uiThreadFpReady();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
40
|
+
registerFlushElementTreeHandler(mainThreadRpc, {
|
|
41
|
+
shadowRoot,
|
|
57
42
|
});
|
|
43
|
+
registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
|
|
44
|
+
registerNativePropsHandler(backgroundRpc, shadowRoot);
|
|
45
|
+
registerTriggerComponentEventHandler(backgroundRpc, shadowRoot);
|
|
46
|
+
registerSelectComponentHandler(backgroundRpc, shadowRoot);
|
|
58
47
|
registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
|
|
59
48
|
registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
|
|
60
49
|
return {
|
|
@@ -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>;
|
|
@@ -81,6 +81,7 @@ const mainThreadInjectVars = [
|
|
|
81
81
|
'__SetCSSId',
|
|
82
82
|
'__OnLifecycleEvent',
|
|
83
83
|
'__FlushElementTree',
|
|
84
|
+
'__LoadLepusChunk',
|
|
84
85
|
];
|
|
85
86
|
const backgroundInjectVars = [
|
|
86
87
|
'NativeModules',
|
|
@@ -92,13 +93,15 @@ const backgroundInjectWithBind = [
|
|
|
92
93
|
'Card',
|
|
93
94
|
'Component',
|
|
94
95
|
];
|
|
95
|
-
export async function loadTemplate(url) {
|
|
96
|
+
export async function loadTemplate(url, customTemplateLoader) {
|
|
96
97
|
const cachedTemplate = TemplateCache[url];
|
|
97
98
|
if (cachedTemplate)
|
|
98
99
|
return cachedTemplate;
|
|
99
|
-
const template =
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const template = customTemplateLoader
|
|
101
|
+
? await customTemplateLoader(url)
|
|
102
|
+
: (await (await fetch(url, {
|
|
103
|
+
method: 'GET',
|
|
104
|
+
})).json());
|
|
102
105
|
const decodedTemplate = {
|
|
103
106
|
...template,
|
|
104
107
|
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.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@lynx-js/offscreen-document": "0.0.0",
|
|
28
|
-
"@lynx-js/web-constants": "0.
|
|
29
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
30
|
-
"@lynx-js/web-worker-runtime": "0.
|
|
28
|
+
"@lynx-js/web-constants": "0.12.0",
|
|
29
|
+
"@lynx-js/web-worker-rpc": "0.12.0",
|
|
30
|
+
"@lynx-js/web-worker-runtime": "0.12.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@lynx-js/lynx-core": "0.1.
|
|
34
|
-
"@lynx-js/web-elements": "0.
|
|
33
|
+
"@lynx-js/lynx-core": "0.1.2",
|
|
34
|
+
"@lynx-js/web-elements": "0.6.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@lynx-js/lynx-core": "0.1.
|
|
38
|
-
"@lynx-js/web-elements": ">=0.
|
|
37
|
+
"@lynx-js/lynx-core": "0.1.2",
|
|
38
|
+
"@lynx-js/web-elements": ">=0.6.0"
|
|
39
39
|
}
|
|
40
40
|
}
|