@lynx-js/web-constants 0.15.6 → 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 CHANGED
@@ -1,5 +1,37 @@
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
+
26
+ ## 0.15.7
27
+
28
+ ### Patch Changes
29
+
30
+ - fix: globalThis is never accessible in MTS ([#1531](https://github.com/lynx-family/lynx-stack/pull/1531))
31
+
32
+ - Updated dependencies []:
33
+ - @lynx-js/web-worker-rpc@0.15.7
34
+
3
35
  ## 0.15.6
4
36
 
5
37
  ### Patch Changes
@@ -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,6 +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[];
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',
@@ -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
  }
@@ -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
- innerHTML: string;
55
+ textContent: string;
56
56
  readonly tagName: string;
57
57
  readonly firstElementChild: WebFiberElementImpl | null;
58
58
  readonly children: WebFiberElementImpl[];
@@ -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,115 +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 { 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
- 'SystemInfo',
79
- ];
80
- const backgroundInjectWithBind = [
81
- 'Card',
82
- 'Component',
83
- ];
84
- const generateModuleContent = (content, injectVars, injectWithBind, muteableVars, isESM) => [
60
+ const generateModuleContent = (content) => [
85
61
  '//# allFunctionsCalledOnLoad\n',
86
- isESM ? 'export default ' : 'globalThis.module.exports =',
87
- 'function(lynx_runtime) {',
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
- 'var {__globalProps} = lynx;',
95
- 'lynx_runtime._updateVars=()=>{',
96
- ...muteableVars.map(nm => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
97
- '};\n',
62
+ '"use strict";\n',
63
+ `(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
98
64
  content,
99
- '\n return module.exports;}',
65
+ '\n})()',
100
66
  ].join('');
101
- async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, createJsModuleUrl, isESM, templateName) {
67
+ async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
102
68
  const processEntry = async ([name, content]) => [
103
69
  name,
104
- await createJsModuleUrl(generateModuleContent(content, injectVars.concat(muteableVars), injectWithBind, muteableVars, isESM), `${templateName}-${name.replaceAll('/', '')}.js`),
70
+ await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
105
71
  ];
106
72
  return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(processEntry)).then(Object.fromEntries);
107
73
  }
108
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
+ }
109
84
  return {
110
85
  ...template,
111
- lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl, true, templateName),
112
- manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl, false, templateName),
86
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
87
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName),
113
88
  };
114
89
  }
115
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.15.6",
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.15.6"
26
+ "@lynx-js/web-worker-rpc": "0.16.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@lynx-js/offscreen-document": "0.1.3"
29
+ "@lynx-js/offscreen-document": "0.1.4"
30
30
  }
31
31
  }