@lynx-js/web-constants-canary 0.15.8-canary-20250828-86da1623 → 0.16.0-canary-20250828-09946c26

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,13 +1,25 @@
1
1
  # @lynx-js/web-constants
2
2
 
3
- ## 0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
3
+ ## 0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
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.
4
16
 
5
17
  ### Patch Changes
6
18
 
7
19
  - fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
8
20
 
9
- - Updated dependencies []:
10
- - @lynx-js/web-worker-rpc@0.15.8-canary-20250828061943-86da1623d0bd2cc5fa6dc1642915e5f43a02d350
21
+ - Updated dependencies [[`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
22
+ - @lynx-js/web-worker-rpc@0.16.0-canary-20250828065231-09946c2604c0998eba703eea90904d005a0eb1c9
11
23
 
12
24
  ## 0.15.7
13
25
 
@@ -11,7 +11,5 @@ export declare const lynxPartIdAttribute: "l-part";
11
11
  export declare const lynxDefaultDisplayLinearAttribute: "lynx-default-display-linear";
12
12
  export declare const lynxDefaultOverflowVisibleAttribute: "lynx-default-overflow-visible";
13
13
  export declare const __lynx_timing_flag: "__lynx_timing_flag";
14
- export declare const globalMuteableVars: readonly ["registerDataProcessor", "registerWorkletInternal", "lynxWorkletImpl", "runWorklet"];
15
14
  export declare const systemInfo: Record<string, string | number>;
16
15
  export declare const inShadowRootStyles: string[];
17
- export declare const globalDisallowedVars: string[];
package/dist/constants.js CHANGED
@@ -14,12 +14,6 @@ export const lynxPartIdAttribute = 'l-part';
14
14
  export const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
15
15
  export const lynxDefaultOverflowVisibleAttribute = 'lynx-default-overflow-visible';
16
16
  export const __lynx_timing_flag = '__lynx_timing_flag';
17
- export const globalMuteableVars = [
18
- 'registerDataProcessor',
19
- 'registerWorkletInternal',
20
- 'lynxWorkletImpl',
21
- 'runWorklet',
22
- ];
23
17
  export const systemInfo = {
24
18
  platform: 'web',
25
19
  lynxSdkVersion: '3.0',
@@ -33,5 +27,4 @@ export const inShadowRootStyles = [
33
27
  overflow: visible;
34
28
  }`,
35
29
  ];
36
- export const globalDisallowedVars = ['navigator', 'postMessage'];
37
30
  //# sourceMappingURL=constants.js.map
@@ -0,0 +1,5 @@
1
+ export type JSRealm = {
2
+ globalWindow: typeof globalThis;
3
+ loadScript: (url: string) => Promise<unknown>;
4
+ loadScriptSync: (url: string) => unknown;
5
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=JSRealm.js.map
@@ -36,6 +36,7 @@ export interface LynxTemplate {
36
36
  [key: string]: string;
37
37
  };
38
38
  elementTemplate: Record<string, ElementTemplateData[]>;
39
+ version?: number;
39
40
  }
40
41
  export interface LynxJSModule {
41
42
  exports?: (lynx_runtime: any) => unknown;
@@ -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
  }
@@ -19,3 +19,4 @@ export * from './I18n.js';
19
19
  export * from './BackThreadStartConfigs.js';
20
20
  export * from './MarkTiming.js';
21
21
  export * from './SSR.js';
22
+ export * from './JSRealm.js';
@@ -19,4 +19,5 @@ export * from './I18n.js';
19
19
  export * from './BackThreadStartConfigs.js';
20
20
  export * from './MarkTiming.js';
21
21
  export * from './SSR.js';
22
+ export * from './JSRealm.js';
22
23
  //# sourceMappingURL=index.js.map
@@ -1,117 +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
- import { globalDisallowedVars, 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
- '__UpdateComponentInfo',
26
- '__GetConfig',
27
- '__GetAttributeByName',
28
- '__UpdateListCallbacks',
29
- '__AppendElement',
30
- '__ElementIsEqual',
31
- '__FirstElement',
32
- '__GetChildren',
33
- '__GetParent',
34
- '__InsertElementBefore',
35
- '__LastElement',
36
- '__NextElement',
37
- '__RemoveElement',
38
- '__ReplaceElement',
39
- '__ReplaceElements',
40
- '__SwapElement',
41
- '__CreateComponent',
42
- '__CreateElement',
43
- '__CreatePage',
44
- '__CreateView',
45
- '__CreateText',
46
- '__CreateRawText',
47
- '__CreateImage',
48
- '__CreateScrollView',
49
- '__CreateWrapperElement',
50
- '__CreateList',
51
- '__AddEvent',
52
- '__GetEvent',
53
- '__GetEvents',
54
- '__SetEvents',
55
- '__AddClass',
56
- '__SetClasses',
57
- '__GetClasses',
58
- '__AddInlineStyle',
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 backgroundInjectVars = [
74
- 'NativeModules',
75
- 'globalThis',
76
- 'lynx',
77
- 'lynxCoreInject',
78
- ];
79
- const backgroundInjectWithBind = [
80
- 'Card',
81
- 'Component',
82
- ];
83
- const generateModuleContent = (content, injectVars, injectWithBind, muteableVars, globalDisallowedVars, isESM) => [
60
+ const generateModuleContent = (content) => [
84
61
  '//# allFunctionsCalledOnLoad\n',
85
- isESM ? 'export default ' : 'globalThis.module.exports =',
86
- 'function(lynx_runtime) {',
87
- 'const module= {exports:{}};let exports = module.exports;',
88
- 'var {',
89
- injectVars.join(','),
90
- '} = lynx_runtime;',
91
- ...injectWithBind.map(nm => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
92
- ';var globDynamicComponentEntry = \'__Card__\';',
93
- globalDisallowedVars.length !== 0
94
- ? `var ${globalDisallowedVars.join('=')}=undefined;`
95
- : '',
96
- 'var {__globalProps} = lynx;',
97
- 'lynx_runtime._updateVars=()=>{',
98
- ...muteableVars.map(nm => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
99
- '};\n',
62
+ '"use strict";\n',
63
+ `(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
100
64
  content,
101
- '\n return module.exports;}',
65
+ '\n})()',
102
66
  ].join('');
103
- async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, globalDisallowedVars, createJsModuleUrl, isESM, templateName) {
67
+ async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
104
68
  const processEntry = async ([name, content]) => [
105
69
  name,
106
- await createJsModuleUrl(generateModuleContent(content, injectVars.concat(muteableVars), injectWithBind, muteableVars, globalDisallowedVars, isESM), `${templateName}-${name.replaceAll('/', '')}.js`),
70
+ await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
107
71
  ];
108
72
  return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(processEntry)).then(Object.fromEntries);
109
73
  }
110
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
+ }
111
84
  return {
112
85
  ...template,
113
- lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, templateName ? [] : globalDisallowedVars, createJsModuleUrl, true, templateName),
114
- manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], templateName ? [] : globalDisallowedVars, createJsModuleUrl, false, templateName),
86
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
87
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName),
115
88
  };
116
89
  }
117
90
  //# sourceMappingURL=generateTemplate.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-constants-canary",
3
- "version": "0.15.8-canary-20250828-86da1623",
3
+ "version": "0.16.0-canary-20250828-09946c26",
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": "npm:@lynx-js/web-worker-rpc-canary@0.15.8-canary-20250828-86da1623"
26
+ "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.0-canary-20250828-09946c26"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@lynx-js/offscreen-document": "npm:@lynx-js/offscreen-document-canary@0.1.3"