@lynx-js/web-constants 0.15.7 → 0.16.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 +23 -0
- package/dist/constants.d.ts +1 -2
- package/dist/constants.js +1 -7
- package/dist/types/BackThreadStartConfigs.d.ts +0 -2
- package/dist/types/Element.d.ts +1 -1
- package/dist/types/JSRealm.d.ts +5 -0
- package/dist/types/JSRealm.js +2 -0
- package/dist/types/LynxModule.d.ts +1 -0
- package/dist/types/MainThreadGlobalThis.d.ts +0 -5
- package/dist/types/MainThreadLynx.d.ts +4 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/generateTemplate.js +72 -100
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @lynx-js/web-constants
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589))
|
|
8
|
+
|
|
9
|
+
Before this change, We create a function wrapper and a fake globalThis for Javascript code.
|
|
10
|
+
|
|
11
|
+
This caused some issues.
|
|
12
|
+
|
|
13
|
+
After this change, we will create an iframe for createing an isolated Javascript context.
|
|
14
|
+
|
|
15
|
+
This means the globalThis will be the real one.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- refactor: add `:not([l-e-name])` at the end of selector for lazy component ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622))
|
|
20
|
+
|
|
21
|
+
- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
24
|
+
- @lynx-js/web-worker-rpc@0.16.0
|
|
25
|
+
|
|
3
26
|
## 0.15.7
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const lynxUniqueIdAttribute: "l-uid";
|
|
|
2
2
|
export declare const cssIdAttribute: "l-css-id";
|
|
3
3
|
export declare const componentIdAttribute: "l-comp-id";
|
|
4
4
|
export declare const parentComponentUniqueIdAttribute: "l-p-comp-uid";
|
|
5
|
+
export declare const lynxEntryNameAttribute: "l-e-name";
|
|
5
6
|
export declare const lynxTagAttribute: "lynx-tag";
|
|
6
7
|
export declare const lynxDatasetAttribute: "l-dset";
|
|
7
8
|
export declare const lynxComponentConfigAttribute: "l-comp-cfg";
|
|
@@ -11,7 +12,5 @@ export declare const lynxPartIdAttribute: "l-part";
|
|
|
11
12
|
export declare const lynxDefaultDisplayLinearAttribute: "lynx-default-display-linear";
|
|
12
13
|
export declare const lynxDefaultOverflowVisibleAttribute: "lynx-default-overflow-visible";
|
|
13
14
|
export declare const __lynx_timing_flag: "__lynx_timing_flag";
|
|
14
|
-
export declare const globalMuteableVars: readonly ["registerDataProcessor", "registerWorkletInternal", "lynxWorkletImpl", "runWorklet"];
|
|
15
15
|
export declare const systemInfo: Record<string, string | number>;
|
|
16
16
|
export declare const inShadowRootStyles: string[];
|
|
17
|
-
export declare const globalDisallowedVars: string[];
|
package/dist/constants.js
CHANGED
|
@@ -5,6 +5,7 @@ export const lynxUniqueIdAttribute = 'l-uid';
|
|
|
5
5
|
export const cssIdAttribute = 'l-css-id';
|
|
6
6
|
export const componentIdAttribute = 'l-comp-id';
|
|
7
7
|
export const parentComponentUniqueIdAttribute = 'l-p-comp-uid';
|
|
8
|
+
export const lynxEntryNameAttribute = 'l-e-name';
|
|
8
9
|
export const lynxTagAttribute = 'lynx-tag';
|
|
9
10
|
export const lynxDatasetAttribute = 'l-dset';
|
|
10
11
|
export const lynxComponentConfigAttribute = 'l-comp-cfg';
|
|
@@ -14,12 +15,6 @@ export const lynxPartIdAttribute = 'l-part';
|
|
|
14
15
|
export const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
|
|
15
16
|
export const lynxDefaultOverflowVisibleAttribute = 'lynx-default-overflow-visible';
|
|
16
17
|
export const __lynx_timing_flag = '__lynx_timing_flag';
|
|
17
|
-
export const globalMuteableVars = [
|
|
18
|
-
'registerDataProcessor',
|
|
19
|
-
'registerWorkletInternal',
|
|
20
|
-
'lynxWorkletImpl',
|
|
21
|
-
'runWorklet',
|
|
22
|
-
];
|
|
23
18
|
export const systemInfo = {
|
|
24
19
|
platform: 'web',
|
|
25
20
|
lynxSdkVersion: '3.0',
|
|
@@ -33,5 +28,4 @@ export const inShadowRootStyles = [
|
|
|
33
28
|
overflow: visible;
|
|
34
29
|
}`,
|
|
35
30
|
];
|
|
36
|
-
export const globalDisallowedVars = ['navigator', 'postMessage'];
|
|
37
31
|
//# sourceMappingURL=constants.js.map
|
|
@@ -2,7 +2,6 @@ import type { Cloneable } from './Cloneable.js';
|
|
|
2
2
|
import type { LynxTemplate } from './LynxModule.js';
|
|
3
3
|
import type { NapiModulesMap } from './NapiModules.js';
|
|
4
4
|
import type { NativeModulesMap } from './NativeModules.js';
|
|
5
|
-
import type { BrowserConfig } from './PageConfig.js';
|
|
6
5
|
export interface BackMainThreadContextConfig {
|
|
7
6
|
initData: unknown;
|
|
8
7
|
globalProps: unknown;
|
|
@@ -11,5 +10,4 @@ export interface BackMainThreadContextConfig {
|
|
|
11
10
|
customSections: Record<string, Cloneable>;
|
|
12
11
|
nativeModulesMap: NativeModulesMap;
|
|
13
12
|
napiModulesMap: NapiModulesMap;
|
|
14
|
-
browserConfig: BrowserConfig;
|
|
15
13
|
}
|
package/dist/types/Element.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface WebFiberElementImpl {
|
|
|
52
52
|
removeEventListener: (type: string, handler: (ev: Event) => void, options?: {
|
|
53
53
|
capture?: boolean;
|
|
54
54
|
}) => void;
|
|
55
|
-
|
|
55
|
+
textContent: string;
|
|
56
56
|
readonly tagName: string;
|
|
57
57
|
readonly firstElementChild: WebFiberElementImpl | null;
|
|
58
58
|
readonly children: WebFiberElementImpl[];
|
|
@@ -161,11 +161,6 @@ export interface MainThreadGlobalThis {
|
|
|
161
161
|
__FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
|
|
162
162
|
_I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
|
|
163
163
|
_AddEventListener: (...args: unknown[]) => void;
|
|
164
|
-
/**
|
|
165
|
-
* private fields
|
|
166
|
-
*/
|
|
167
|
-
_updateVars: () => void;
|
|
168
|
-
__lynxGlobalBindingValues: Record<string, unknown>;
|
|
169
164
|
renderPage: ((data: unknown) => void) | undefined;
|
|
170
165
|
updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
|
|
171
166
|
runWorklet?: (obj: unknown, event: unknown) => void;
|
|
@@ -9,4 +9,8 @@ export interface MainThreadLynx {
|
|
|
9
9
|
getCustomSectionSync: (key: string) => Cloneable;
|
|
10
10
|
markPipelineTiming: (pipelineId: string, timingKey: string) => void;
|
|
11
11
|
SystemInfo: typeof systemInfo;
|
|
12
|
+
setTimeout: typeof setTimeout;
|
|
13
|
+
clearTimeout: typeof clearTimeout;
|
|
14
|
+
setInterval: typeof setInterval;
|
|
15
|
+
clearInterval: typeof clearInterval;
|
|
12
16
|
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1,118 +1,90 @@
|
|
|
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
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
'__SetInlineStyles',
|
|
60
|
-
'__SetCSSId',
|
|
61
|
-
'__OnLifecycleEvent',
|
|
62
|
-
'__FlushElementTree',
|
|
63
|
-
'__LoadLepusChunk',
|
|
64
|
-
'SystemInfo',
|
|
65
|
-
'_I18nResourceTranslation',
|
|
66
|
-
'_AddEventListener',
|
|
67
|
-
'__GetTemplateParts',
|
|
68
|
-
'__MarkPartElement',
|
|
69
|
-
'__MarkTemplateElement',
|
|
70
|
-
'__GetPageElement',
|
|
71
|
-
'__ElementFromBinary',
|
|
4
|
+
const currentSupportedTemplateVersion = 2;
|
|
5
|
+
const globalDisallowedVars = ['navigator', 'postMessage'];
|
|
6
|
+
const templateUpgraders = [
|
|
7
|
+
(template) => {
|
|
8
|
+
const defaultInjectStr = [
|
|
9
|
+
'Card',
|
|
10
|
+
'setTimeout',
|
|
11
|
+
'setInterval',
|
|
12
|
+
'clearInterval',
|
|
13
|
+
'clearTimeout',
|
|
14
|
+
'NativeModules',
|
|
15
|
+
'Component',
|
|
16
|
+
'ReactLynx',
|
|
17
|
+
'nativeAppId',
|
|
18
|
+
'Behavior',
|
|
19
|
+
'LynxJSBI',
|
|
20
|
+
'lynx',
|
|
21
|
+
// BOM API
|
|
22
|
+
'window',
|
|
23
|
+
'document',
|
|
24
|
+
'frames',
|
|
25
|
+
'location',
|
|
26
|
+
'navigator',
|
|
27
|
+
'localStorage',
|
|
28
|
+
'history',
|
|
29
|
+
'Caches',
|
|
30
|
+
'screen',
|
|
31
|
+
'alert',
|
|
32
|
+
'confirm',
|
|
33
|
+
'prompt',
|
|
34
|
+
'fetch',
|
|
35
|
+
'XMLHttpRequest',
|
|
36
|
+
'__WebSocket__', // We would provide `WebSocket` using `ProvidePlugin`
|
|
37
|
+
'webkit',
|
|
38
|
+
'Reporter',
|
|
39
|
+
'print',
|
|
40
|
+
'global',
|
|
41
|
+
// Lynx API
|
|
42
|
+
'requestAnimationFrame',
|
|
43
|
+
'cancelAnimationFrame',
|
|
44
|
+
].join(',');
|
|
45
|
+
/**
|
|
46
|
+
* The template version 1 has no module wrapper for bts code
|
|
47
|
+
*/
|
|
48
|
+
template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value]) => [
|
|
49
|
+
key,
|
|
50
|
+
`{init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:null}; ${value}\n return module.exports; } }`,
|
|
51
|
+
]));
|
|
52
|
+
template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).map(([key, value]) => [
|
|
53
|
+
key,
|
|
54
|
+
`(()=>{${value}\n})();`,
|
|
55
|
+
]));
|
|
56
|
+
template.version = 2;
|
|
57
|
+
return template;
|
|
58
|
+
},
|
|
72
59
|
];
|
|
73
|
-
const
|
|
74
|
-
'NativeModules',
|
|
75
|
-
'globalThis',
|
|
76
|
-
'lynx',
|
|
77
|
-
'lynxCoreInject',
|
|
78
|
-
'SystemInfo',
|
|
79
|
-
];
|
|
80
|
-
const backgroundInjectWithBind = [
|
|
81
|
-
'Card',
|
|
82
|
-
'Component',
|
|
83
|
-
];
|
|
84
|
-
const generateModuleContent = (content, injectVars, injectWithBind, muteableVars, globalDisallowedVars, isESM) => [
|
|
60
|
+
const generateModuleContent = (content) => [
|
|
85
61
|
'//# allFunctionsCalledOnLoad\n',
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
'const module= {exports:{}};let exports = module.exports;',
|
|
89
|
-
'var {',
|
|
90
|
-
injectVars.join(','),
|
|
91
|
-
'} = lynx_runtime;',
|
|
92
|
-
...injectWithBind.map(nm => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
|
|
93
|
-
';var globDynamicComponentEntry = \'__Card__\';',
|
|
94
|
-
globalDisallowedVars.length !== 0
|
|
95
|
-
? `var ${globalDisallowedVars.join('=')}=undefined;`
|
|
96
|
-
: '',
|
|
97
|
-
'var {__globalProps} = lynx;',
|
|
98
|
-
'lynx_runtime._updateVars=()=>{',
|
|
99
|
-
...muteableVars.map(nm => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
|
|
100
|
-
'};\n',
|
|
62
|
+
'"use strict";\n',
|
|
63
|
+
`(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
|
|
101
64
|
content,
|
|
102
|
-
'\n
|
|
65
|
+
'\n})()',
|
|
103
66
|
].join('');
|
|
104
|
-
async function generateJavascriptUrl(obj,
|
|
67
|
+
async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
|
|
105
68
|
const processEntry = async ([name, content]) => [
|
|
106
69
|
name,
|
|
107
|
-
await createJsModuleUrl(generateModuleContent(content
|
|
70
|
+
await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
|
|
108
71
|
];
|
|
109
72
|
return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(processEntry)).then(Object.fromEntries);
|
|
110
73
|
}
|
|
111
74
|
export async function generateTemplate(template, createJsModuleUrl, templateName) {
|
|
75
|
+
template.version = template.version ?? 1;
|
|
76
|
+
if (template.version > currentSupportedTemplateVersion) {
|
|
77
|
+
throw new Error(`Unsupported template, please upgrade your web-platform dependencies`);
|
|
78
|
+
}
|
|
79
|
+
let upgrader;
|
|
80
|
+
while (template.version < currentSupportedTemplateVersion
|
|
81
|
+
&& (upgrader = templateUpgraders[template.version - 1])) {
|
|
82
|
+
template = upgrader(template);
|
|
83
|
+
}
|
|
112
84
|
return {
|
|
113
85
|
...template,
|
|
114
|
-
lepusCode: await generateJavascriptUrl(template.lepusCode,
|
|
115
|
-
manifest: await generateJavascriptUrl(template.manifest,
|
|
86
|
+
lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
|
|
87
|
+
manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName),
|
|
116
88
|
};
|
|
117
89
|
}
|
|
118
90
|
//# sourceMappingURL=generateTemplate.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-constants",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"**/*.css"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
26
|
+
"@lynx-js/web-worker-rpc": "0.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
29
|
+
"@lynx-js/offscreen-document": "0.1.4"
|
|
30
30
|
}
|
|
31
31
|
}
|