@lynx-js/web-constants 0.14.1 → 0.14.2
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 +11 -0
- package/dist/endpoints.d.ts +2 -2
- package/dist/types/MarkTiming.d.ts +5 -0
- package/dist/types/MarkTiming.js +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/LynxCrossThreadContext.js +3 -0
- package/dist/utils/generateTemplate.d.ts +3 -0
- package/dist/utils/generateTemplate.js +123 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/markTiming.d.ts +15 -0
- package/dist/utils/markTiming.js +26 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @lynx-js/web-constants
|
|
2
2
|
|
|
3
|
+
## 0.14.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: merge multiple markTiming RPC communication events together and send them together, which can effectively reduce the number of RPC communications. ([#1178](https://github.com/lynx-family/lynx-stack/pull/1178))
|
|
8
|
+
|
|
9
|
+
- chore: extract shared logic from web-core and web-core-server's loadTemplate into a unified generateTemplate function ([#1211](https://github.com/lynx-family/lynx-stack/pull/1211))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @lynx-js/web-worker-rpc@0.14.2
|
|
13
|
+
|
|
3
14
|
## 0.14.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/endpoints.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Cloneable, CloneableObject } from './types/Cloneable.js';
|
|
|
3
3
|
import type { StartMainThreadContextConfig } from './types/MainThreadStartConfigs.js';
|
|
4
4
|
import type { IdentifierType, InvokeCallbackRes } from './types/NativeApp.js';
|
|
5
5
|
import type { ElementAnimationOptions } from './types/Element.js';
|
|
6
|
-
import type { BackMainThreadContextConfig } from './types/index.js';
|
|
6
|
+
import type { BackMainThreadContextConfig, MarkTiming } from './types/index.js';
|
|
7
7
|
export declare const postExposureEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[{
|
|
8
8
|
exposures: ExposureWorkerEvent[];
|
|
9
9
|
disExposures: ExposureWorkerEvent[];
|
|
@@ -32,7 +32,7 @@ export declare const setNativePropsEndpoint: import("@lynx-js/web-worker-rpc/dis
|
|
|
32
32
|
export declare const nativeModulesCallEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[name: string, data: Cloneable, moduleName: string], any>;
|
|
33
33
|
export declare const napiModulesCallEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncWithTransfer<[name: string, data: Cloneable, moduleName: string], any>;
|
|
34
34
|
export declare const getCustomSectionsEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[string], Cloneable>;
|
|
35
|
-
export declare const markTimingEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[
|
|
35
|
+
export declare const markTimingEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[MarkTiming[]]>;
|
|
36
36
|
export declare const postTimingFlagsEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[timingFlags: string[], pipelineId: string | undefined]>;
|
|
37
37
|
export declare const triggerComponentEventEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[id: string, params: {
|
|
38
38
|
eventDetail: CloneableObject;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
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.
|
|
1
4
|
import { DispatchEventResult, } from '../types/LynxContextEventTarget.js';
|
|
2
5
|
export class LynxCrossThreadContext extends EventTarget {
|
|
3
6
|
_config;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LynxTemplate } from '../types/LynxModule.js';
|
|
2
|
+
export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: (content: string) => string): Promise<LynxTemplate>;
|
|
3
|
+
export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: (content: string, name: string) => Promise<string>, templateName: string): Promise<LynxTemplate>;
|
|
@@ -0,0 +1,123 @@
|
|
|
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 { globalMuteableVars } from '../constants.js';
|
|
5
|
+
const mainThreadInjectVars = [
|
|
6
|
+
'lynx',
|
|
7
|
+
'globalThis',
|
|
8
|
+
'_ReportError',
|
|
9
|
+
'_SetSourceMapRelease',
|
|
10
|
+
'__AddConfig',
|
|
11
|
+
'__AddDataset',
|
|
12
|
+
'__GetAttributes',
|
|
13
|
+
'__GetComponentID',
|
|
14
|
+
'__GetDataByKey',
|
|
15
|
+
'__GetDataset',
|
|
16
|
+
'__GetElementConfig',
|
|
17
|
+
'__GetElementUniqueID',
|
|
18
|
+
'__GetID',
|
|
19
|
+
'__GetTag',
|
|
20
|
+
'__SetAttribute',
|
|
21
|
+
'__SetConfig',
|
|
22
|
+
'__SetDataset',
|
|
23
|
+
'__SetID',
|
|
24
|
+
'__UpdateComponentID',
|
|
25
|
+
'__GetConfig',
|
|
26
|
+
'__UpdateListCallbacks',
|
|
27
|
+
'__AppendElement',
|
|
28
|
+
'__ElementIsEqual',
|
|
29
|
+
'__FirstElement',
|
|
30
|
+
'__GetChildren',
|
|
31
|
+
'__GetParent',
|
|
32
|
+
'__InsertElementBefore',
|
|
33
|
+
'__LastElement',
|
|
34
|
+
'__NextElement',
|
|
35
|
+
'__RemoveElement',
|
|
36
|
+
'__ReplaceElement',
|
|
37
|
+
'__ReplaceElements',
|
|
38
|
+
'__SwapElement',
|
|
39
|
+
'__CreateComponent',
|
|
40
|
+
'__CreateElement',
|
|
41
|
+
'__CreatePage',
|
|
42
|
+
'__CreateView',
|
|
43
|
+
'__CreateText',
|
|
44
|
+
'__CreateRawText',
|
|
45
|
+
'__CreateImage',
|
|
46
|
+
'__CreateScrollView',
|
|
47
|
+
'__CreateWrapperElement',
|
|
48
|
+
'__CreateList',
|
|
49
|
+
'__AddEvent',
|
|
50
|
+
'__GetEvent',
|
|
51
|
+
'__GetEvents',
|
|
52
|
+
'__SetEvents',
|
|
53
|
+
'__AddClass',
|
|
54
|
+
'__SetClasses',
|
|
55
|
+
'__GetClasses',
|
|
56
|
+
'__AddInlineStyle',
|
|
57
|
+
'__SetInlineStyles',
|
|
58
|
+
'__SetCSSId',
|
|
59
|
+
'__OnLifecycleEvent',
|
|
60
|
+
'__FlushElementTree',
|
|
61
|
+
'__LoadLepusChunk',
|
|
62
|
+
'SystemInfo',
|
|
63
|
+
'_I18nResourceTranslation',
|
|
64
|
+
'_AddEventListener',
|
|
65
|
+
];
|
|
66
|
+
const backgroundInjectVars = [
|
|
67
|
+
'NativeModules',
|
|
68
|
+
'globalThis',
|
|
69
|
+
'lynx',
|
|
70
|
+
'lynxCoreInject',
|
|
71
|
+
'SystemInfo',
|
|
72
|
+
];
|
|
73
|
+
const backgroundInjectWithBind = [
|
|
74
|
+
'Card',
|
|
75
|
+
'Component',
|
|
76
|
+
];
|
|
77
|
+
async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, createJsModuleUrl, templateName) {
|
|
78
|
+
injectVars = injectVars.concat(muteableVars);
|
|
79
|
+
const generateModuleContent = (content) => [
|
|
80
|
+
'//# allFunctionsCalledOnLoad\n',
|
|
81
|
+
'globalThis.module.exports = function(lynx_runtime) {',
|
|
82
|
+
'const module= {exports:{}};let exports = module.exports;',
|
|
83
|
+
'var {',
|
|
84
|
+
injectVars.join(','),
|
|
85
|
+
'} = lynx_runtime;',
|
|
86
|
+
...injectWithBind.map(nm => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
|
|
87
|
+
';var globDynamicComponentEntry = \'__Card__\';',
|
|
88
|
+
'var {__globalProps} = lynx;',
|
|
89
|
+
'lynx_runtime._updateVars=()=>{',
|
|
90
|
+
...muteableVars.map(nm => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
|
|
91
|
+
'};\n',
|
|
92
|
+
content,
|
|
93
|
+
'\n return module.exports;}',
|
|
94
|
+
].join('');
|
|
95
|
+
if (!templateName) {
|
|
96
|
+
createJsModuleUrl;
|
|
97
|
+
}
|
|
98
|
+
const processEntry = templateName
|
|
99
|
+
? async ([name, content]) => [
|
|
100
|
+
name,
|
|
101
|
+
await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
|
|
102
|
+
]
|
|
103
|
+
: async ([name, content]) => [
|
|
104
|
+
name,
|
|
105
|
+
await createJsModuleUrl(generateModuleContent(content)),
|
|
106
|
+
];
|
|
107
|
+
return Promise.all(Object.entries(obj).map(processEntry)).then(Object.fromEntries);
|
|
108
|
+
}
|
|
109
|
+
export async function generateTemplate(template, createJsModuleUrl, templateName) {
|
|
110
|
+
if (!templateName) {
|
|
111
|
+
return {
|
|
112
|
+
...template,
|
|
113
|
+
lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl),
|
|
114
|
+
manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
...template,
|
|
119
|
+
lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl, templateName),
|
|
120
|
+
manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl, templateName),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=generateTemplate.js.map
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
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.
|
|
1
4
|
export { LynxCrossThreadContext } from './LynxCrossThreadContext.js';
|
|
5
|
+
export { dispatchMarkTiming, flushMarkTiming } from './markTiming.js';
|
|
6
|
+
export { generateTemplate } from './generateTemplate.js';
|
|
2
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MarkTiming } from '../types/MarkTiming.js';
|
|
2
|
+
export declare const dispatchMarkTiming: ({ timingKey, pipelineId, timeStamp, markTiming, cacheMarkTimings }: {
|
|
3
|
+
timingKey: string;
|
|
4
|
+
pipelineId?: string;
|
|
5
|
+
timeStamp?: number;
|
|
6
|
+
markTiming: (markTimings: MarkTiming[]) => void;
|
|
7
|
+
cacheMarkTimings: {
|
|
8
|
+
records: MarkTiming[];
|
|
9
|
+
timeout: NodeJS.Timeout | null;
|
|
10
|
+
};
|
|
11
|
+
}) => void;
|
|
12
|
+
export declare const flushMarkTiming: (markTiming: (markTimings: MarkTiming[]) => void, cacheMarkTimings: {
|
|
13
|
+
records: MarkTiming[];
|
|
14
|
+
timeout: NodeJS.Timeout | null;
|
|
15
|
+
}) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 const dispatchMarkTiming = ({ timingKey, pipelineId, timeStamp, markTiming, cacheMarkTimings }) => {
|
|
5
|
+
cacheMarkTimings.records.push({
|
|
6
|
+
timingKey,
|
|
7
|
+
pipelineId,
|
|
8
|
+
timeStamp: timeStamp ?? performance.now() + performance.timeOrigin,
|
|
9
|
+
});
|
|
10
|
+
if (!cacheMarkTimings.timeout) {
|
|
11
|
+
cacheMarkTimings.timeout = setTimeout(() => {
|
|
12
|
+
markTiming(cacheMarkTimings.records);
|
|
13
|
+
cacheMarkTimings.records = [];
|
|
14
|
+
cacheMarkTimings.timeout = null;
|
|
15
|
+
}, 500);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export const flushMarkTiming = (markTiming, cacheMarkTimings) => {
|
|
19
|
+
markTiming(cacheMarkTimings.records);
|
|
20
|
+
cacheMarkTimings.records = [];
|
|
21
|
+
if (cacheMarkTimings.timeout) {
|
|
22
|
+
clearTimeout(cacheMarkTimings.timeout);
|
|
23
|
+
cacheMarkTimings.timeout = null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=markTiming.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-constants",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"**/*.css"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@lynx-js/web-worker-rpc": "0.14.
|
|
26
|
+
"@lynx-js/web-worker-rpc": "0.14.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@lynx-js/offscreen-document": "0.1.2"
|