@lynx-js/web-worker-runtime 0.7.0 → 0.8.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 +117 -0
- package/dist/backgroundThread/background-apis/createNapiLoader.d.ts +5 -0
- package/dist/backgroundThread/background-apis/createNapiLoader.js +15 -0
- package/dist/backgroundThread/background-apis/startBackgroundThread.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/mainThread/startMainThread.js +3 -4
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,122 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- refactor: remove web-elements/lazy and loadNewTag ([#123](https://github.com/lynx-family/lynx-stack/pull/123))
|
|
8
|
+
|
|
9
|
+
- remove @lynx-js/web-elements/lazy
|
|
10
|
+
- remove loadElement
|
|
11
|
+
- remove loadNewTag callback
|
|
12
|
+
|
|
13
|
+
**This is a breaking change**
|
|
14
|
+
|
|
15
|
+
Now we removed the default lazy loading preinstalled in web-core
|
|
16
|
+
|
|
17
|
+
Please add the following statement in your web project
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
import "@lynx-js/web-elements/all";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- feat: add pixelRatio of SystemInfo, now you can use `SystemInfo.pixelRatio`. ([#150](https://github.com/lynx-family/lynx-stack/pull/150))
|
|
26
|
+
|
|
27
|
+
- feat: add two prop of lynx-view about `napiLoader`: ([#173](https://github.com/lynx-family/lynx-stack/pull/173))
|
|
28
|
+
|
|
29
|
+
- `napiModulesMap`: [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
|
|
30
|
+
|
|
31
|
+
- `onNapiModulesCall`: [optional] the NapiModule value handler.
|
|
32
|
+
|
|
33
|
+
**Warning:** This is the internal implementation of `@lynx-js/lynx-core`. In most cases, this API is not required for projects.
|
|
34
|
+
|
|
35
|
+
1. The `napiModulesMap` value should be a esm url which export default a function with two parameters:
|
|
36
|
+
|
|
37
|
+
- `NapiModules`: oriented `napiModulesMap`, which you can use to call other Napi-Modules
|
|
38
|
+
|
|
39
|
+
- `NapiModulesCall`: trigger `onNapiModulesCall`
|
|
40
|
+
|
|
41
|
+
example:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const color_environment = URL.createObjectURL(
|
|
45
|
+
new Blob(
|
|
46
|
+
[
|
|
47
|
+
`export default function(NapiModules, NapiModulesCall) {
|
|
48
|
+
return {
|
|
49
|
+
getColor() {
|
|
50
|
+
NapiModules.color_methods.getColor({ color: 'green' }, color => {
|
|
51
|
+
console.log(color);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
ColorEngine: class ColorEngine {
|
|
55
|
+
getColor(name) {
|
|
56
|
+
NapiModules.color_methods.getColor({ color: 'green' }, color => {
|
|
57
|
+
console.log(color);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};`,
|
|
63
|
+
],
|
|
64
|
+
{ type: 'text/javascript' },
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const color_methods = URL.createObjectURL(
|
|
69
|
+
new Blob(
|
|
70
|
+
[
|
|
71
|
+
`export default function(NapiModules, NapiModulesCall) {
|
|
72
|
+
return {
|
|
73
|
+
async getColor(data, callback) {
|
|
74
|
+
const color = await NapiModulesCall('getColor', data);
|
|
75
|
+
callback(color);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};`,
|
|
79
|
+
],
|
|
80
|
+
{ type: 'text/javascript' },
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
lynxView.napiModuleMap = {
|
|
85
|
+
color_environment: color_environment,
|
|
86
|
+
color_methods: color_methods,
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
2. The `onNapiModulesCall` function has three parameters:
|
|
91
|
+
|
|
92
|
+
- `name`: the first parameter of `NapiModulesCall`, the function name
|
|
93
|
+
- `data`: the second parameter of `NapiModulesCall`, data
|
|
94
|
+
- `moduleName`: the module-name of the called napi-module
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
lynxView.onNapiModulesCall = (name, data, moduleName) => {
|
|
98
|
+
if (name === 'getColor' && moduleName === 'color_methods') {
|
|
99
|
+
return data.color;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- Updated dependencies [[`e9e8370`](https://github.com/lynx-family/lynx-stack/commit/e9e8370e070a50cbf65a4ebc46c2e37ea1e0be40), [`ec4e1ce`](https://github.com/lynx-family/lynx-stack/commit/ec4e1ce0d7612d6c0701792a46c78cd52130bad4), [`f0a717c`](https://github.com/lynx-family/lynx-stack/commit/f0a717c630700e16ab0af7f1fe370fd60ac75b30), [`63fab7b`](https://github.com/lynx-family/lynx-stack/commit/63fab7b515b7456750b5f7e06844f244a20ca4f1)]:
|
|
105
|
+
- @lynx-js/web-mainthread-apis@0.8.0
|
|
106
|
+
- @lynx-js/web-constants@0.8.0
|
|
107
|
+
- @lynx-js/web-worker-rpc@0.8.0
|
|
108
|
+
|
|
109
|
+
## 0.7.1
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- Support NPM provenance. ([#30](https://github.com/lynx-family/lynx-stack/pull/30))
|
|
114
|
+
|
|
115
|
+
- Updated dependencies [[`c617453`](https://github.com/lynx-family/lynx-stack/commit/c617453aea967aba702967deb2916b5c883f03bb), [`2044571`](https://github.com/lynx-family/lynx-stack/commit/204457166531dae6e9f653db56b14187553b7666), [`82285ce`](https://github.com/lynx-family/lynx-stack/commit/82285cefbc87a5b9b9f5b79b082b5030d1a7b772), [`7da7601`](https://github.com/lynx-family/lynx-stack/commit/7da7601f00407970c485046ad73eeb8534aaa4f6)]:
|
|
116
|
+
- @lynx-js/web-mainthread-apis@0.7.1
|
|
117
|
+
- @lynx-js/web-worker-rpc@0.7.1
|
|
118
|
+
- @lynx-js/web-constants@0.7.1
|
|
119
|
+
|
|
3
120
|
## 0.7.0
|
|
4
121
|
|
|
5
122
|
### Minor Changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type NapiModulesMap } from '@lynx-js/web-constants';
|
|
2
|
+
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
+
export declare const createNapiLoader: (rpc: Rpc, napiModulesMap: NapiModulesMap) => Promise<{
|
|
4
|
+
load(moduleName: string): Record<string, any> | undefined;
|
|
5
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import { napiModulesCallEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
+
export const createNapiLoader = async (rpc, napiModulesMap) => {
|
|
6
|
+
const napiModulesCall = rpc.createCall(napiModulesCallEndpoint);
|
|
7
|
+
let napiModules = {};
|
|
8
|
+
await Promise.all(Object.entries(napiModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => napiModules[moduleName] = module?.default?.(napiModules, (name, data) => napiModulesCall(name, data, moduleName)))));
|
|
9
|
+
return {
|
|
10
|
+
load(moduleName) {
|
|
11
|
+
return napiModules[moduleName];
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=createNapiLoader.js.map
|
|
@@ -7,6 +7,7 @@ import { createNativeApp } from './createNativeApp.js';
|
|
|
7
7
|
import { registerDisposeHandler } from './crossThreadHandlers/registerDisposeHandler.js';
|
|
8
8
|
import { createMarkTimingInternal } from './crossThreadHandlers/createBackgroundMarkTimingInternal.js';
|
|
9
9
|
import { BackgroundThreadStartEndpoint } from '@lynx-js/web-constants';
|
|
10
|
+
import { createNapiLoader } from './createNapiLoader.js';
|
|
10
11
|
const lynxCore = import(
|
|
11
12
|
/* webpackMode: "eager" */ '@lynx-js/lynx-core/web');
|
|
12
13
|
export function startBackgroundThread(uiThreadPort, mainThreadPort) {
|
|
@@ -27,6 +28,8 @@ export function startBackgroundThread(uiThreadPort, mainThreadPort) {
|
|
|
27
28
|
markTimingInternal,
|
|
28
29
|
customNativeModules,
|
|
29
30
|
});
|
|
31
|
+
globalThis['napiLoaderOnRT' + nativeApp.id] =
|
|
32
|
+
await createNapiLoader(uiThreadRpc, config.napiModulesMap);
|
|
30
33
|
const nativeLynx = createBackgroundLynx(config, nativeApp, mainThreadRpc);
|
|
31
34
|
lynxCore.then(({ loadCard, destroyCard, callDestroyLifetimeFun }) => {
|
|
32
35
|
loadCard(nativeApp, config, nativeLynx);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
import { startBackgroundThread } from './backgroundThread/index.js';
|
|
5
5
|
import { startMainThread } from './mainThread/startMainThread.js';
|
|
6
6
|
self.onmessage = (ev) => {
|
|
7
|
-
const { mode, toPeerThread, toUIThread } = ev
|
|
7
|
+
const { mode, toPeerThread, toUIThread, pixelRatio } = ev
|
|
8
|
+
.data;
|
|
9
|
+
globalThis.SystemInfo.pixelRatio = pixelRatio;
|
|
8
10
|
if (mode === 'main') {
|
|
9
11
|
startMainThread(toUIThread, toPeerThread);
|
|
10
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint,
|
|
4
|
+
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint, flushElementTreeEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { MainThreadRuntime } from '@lynx-js/web-mainthread-apis';
|
|
7
7
|
import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
|
|
@@ -16,11 +16,10 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
16
16
|
const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
|
|
17
17
|
const __OnLifecycleEvent = backgroundThreadRpc.createCall(onLifecycleEventEndpoint);
|
|
18
18
|
const mainThreadChunkReady = uiThreadRpc.createCall(mainThreadChunkReadyEndpoint);
|
|
19
|
-
const onNewTag = uiThreadRpc.createCall(loadNewTagEndpoint);
|
|
20
19
|
const flushElementTree = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
21
20
|
markTimingInternal('lepus_excute_start');
|
|
22
21
|
uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
|
|
23
|
-
const { globalProps, template, entryId, browserConfig, nativeModulesUrl, } = config;
|
|
22
|
+
const { globalProps, template, entryId, browserConfig, nativeModulesUrl, napiModulesMap, } = config;
|
|
24
23
|
const { styleInfo, pageConfig, customSections, cardType, lepusCode } = template;
|
|
25
24
|
markTimingInternal('decode_start');
|
|
26
25
|
await import(
|
|
@@ -53,11 +52,11 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
53
52
|
cardType: cardType ?? 'react',
|
|
54
53
|
customSections: Object.fromEntries(Object.entries(customSections).filter(([, value]) => value.type !== 'lazy').map(([k, v]) => [k, v.content])),
|
|
55
54
|
nativeModulesUrl,
|
|
55
|
+
napiModulesMap,
|
|
56
56
|
});
|
|
57
57
|
runtime.renderPage(initData);
|
|
58
58
|
runtime.__FlushElementTree(undefined, {});
|
|
59
59
|
},
|
|
60
|
-
onNewTag,
|
|
61
60
|
flushElementTree,
|
|
62
61
|
_ReportError: function (error, info) {
|
|
63
62
|
console.error('main-thread:', error, info);
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/lynx-family/lynx-stack.git",
|
|
10
|
+
"directory": "packages/web-platform/web-worker-runtime"
|
|
11
|
+
},
|
|
7
12
|
"license": "Apache-2.0",
|
|
8
13
|
"type": "module",
|
|
9
14
|
"main": "dist/index.js",
|
|
@@ -17,9 +22,9 @@
|
|
|
17
22
|
"README.md"
|
|
18
23
|
],
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@lynx-js/web-constants": "0.
|
|
21
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
22
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
25
|
+
"@lynx-js/web-constants": "0.8.0",
|
|
26
|
+
"@lynx-js/web-mainthread-apis": "0.8.0",
|
|
27
|
+
"@lynx-js/web-worker-rpc": "0.8.0"
|
|
23
28
|
},
|
|
24
29
|
"devDependencies": {
|
|
25
30
|
"@lynx-js/lynx-core": "0.1.0"
|