@lynx-js/web-mainthread-apis 0.7.0 → 0.7.1

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,39 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Support NPM provenance. ([#30](https://github.com/lynx-family/lynx-stack/pull/30))
8
+
9
+ - fix: some valus should be updateable by global scope ([#130](https://github.com/lynx-family/lynx-stack/pull/130))
10
+
11
+ Now we add an allowlist to allow some identifiers could be updated by globalThis.
12
+
13
+ For those values in the allowlist:
14
+
15
+ ```
16
+ globalThis.foo = 'xx';
17
+ console.log(foo); //'xx'
18
+ ```
19
+
20
+ - refactor: isolate the globalThis in mts ([#90](https://github.com/lynx-family/lynx-stack/pull/90))
21
+
22
+ After this commit, developers' mts code won't be able to access the globalThis
23
+
24
+ The following usage will NOT work
25
+
26
+ ```
27
+ globalThis.foo = () =>{};
28
+ foo();//crash
29
+ ```
30
+
31
+ - refractor: improve some internal logic for element creating in MTS ([#71](https://github.com/lynx-family/lynx-stack/pull/71))
32
+
33
+ - Updated dependencies [[`c617453`](https://github.com/lynx-family/lynx-stack/commit/c617453aea967aba702967deb2916b5c883f03bb), [`2044571`](https://github.com/lynx-family/lynx-stack/commit/204457166531dae6e9f653db56b14187553b7666), [`399a6d9`](https://github.com/lynx-family/lynx-stack/commit/399a6d973024aa8a46ab2f2f13e7c82214066f9e), [`7da7601`](https://github.com/lynx-family/lynx-stack/commit/7da7601f00407970c485046ad73eeb8534aaa4f6)]:
34
+ - @lynx-js/web-style-transformer@0.2.2
35
+ - @lynx-js/web-constants@0.7.1
36
+
3
37
  ## 0.7.0
4
38
 
5
39
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { MainThreadConfig, MainThreadRuntime } from './MainThreadRuntime.js';
1
+ import { type MainThreadConfig, MainThreadRuntime } from './MainThreadRuntime.js';
2
2
  export declare function createMainThreadLynx(config: MainThreadConfig, lepusRuntime: MainThreadRuntime): {
3
3
  requestAnimationFrame(cb: FrameRequestCallback): number;
4
4
  cancelAnimationFrame(handler: number): void;
@@ -1,3 +1,4 @@
1
+ import { MainThreadRuntime, } from './MainThreadRuntime.js';
1
2
  export function createMainThreadLynx(config, lepusRuntime) {
2
3
  return {
3
4
  requestAnimationFrame(cb) {
@@ -1,5 +1,5 @@
1
- import type { ElementOperation, LynxLifecycleEvent, LynxTemplate, PageConfig, ProcessDataCallback, StyleInfo, FlushElementTreeOptions, Cloneable, BrowserConfig } from '@lynx-js/web-constants';
2
- import { MainThreadLynx } from './MainThreadLynx.js';
1
+ import { type ElementOperation, type LynxLifecycleEvent, type LynxTemplate, type PageConfig, type ProcessDataCallback, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig } from '@lynx-js/web-constants';
2
+ import { type MainThreadLynx } from './MainThreadLynx.js';
3
3
  export interface MainThreadRuntimeCallbacks {
4
4
  mainChunkReady: () => void;
5
5
  onNewTag: (tag: string) => void;
@@ -26,7 +26,11 @@ export declare class MainThreadRuntime {
26
26
  operations: ElementOperation[];
27
27
  };
28
28
  constructor(config: MainThreadConfig);
29
- get globalThis(): typeof globalThis & this;
29
+ /**
30
+ * @private
31
+ */
32
+ __lynxGlobalBindingValues: Record<string, any>;
33
+ get globalThis(): this;
30
34
  lynx: MainThreadLynx;
31
35
  NativeModules: undefined;
32
36
  __globalProps: unknown;
@@ -37,4 +41,5 @@ export declare class MainThreadRuntime {
37
41
  __LoadLepusChunk: (path: string) => boolean;
38
42
  __FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
39
43
  updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
44
+ _updateVars?: () => void;
40
45
  }
@@ -1,6 +1,8 @@
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 {} from '@lynx-js/web-constants';
5
+ import { globalMuteableVars } from '@lynx-js/web-constants';
4
6
  import { createMainThreadLynx } from './MainThreadLynx.js';
5
7
  import { initializeElementCreatingFunction } from './elementAPI/elementCreating/elementCreatingFunctions.js';
6
8
  import * as attributeAndPropertyApis from './elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js';
@@ -49,11 +51,24 @@ export class MainThreadRuntime {
49
51
  queueMicrotask(this.config.callbacks.mainChunkReady);
50
52
  },
51
53
  });
54
+ for (const nm of globalMuteableVars) {
55
+ Object.defineProperty(this, nm, {
56
+ get: () => {
57
+ return this.__lynxGlobalBindingValues[nm];
58
+ },
59
+ set: (v) => {
60
+ this.__lynxGlobalBindingValues[nm] = v;
61
+ this._updateVars?.();
62
+ },
63
+ });
64
+ }
52
65
  }
66
+ /**
67
+ * @private
68
+ */
69
+ __lynxGlobalBindingValues = {};
53
70
  get globalThis() {
54
- const global = Object.assign(globalThis, this);
55
- Object.defineProperty(global, 'renderPage', Object.getOwnPropertyDescriptor(this, 'renderPage'));
56
- return global;
71
+ return this;
57
72
  }
58
73
  lynx;
59
74
  NativeModules = undefined;
@@ -72,5 +87,6 @@ export class MainThreadRuntime {
72
87
  this.isFp = false;
73
88
  };
74
89
  updatePage;
90
+ _updateVars;
75
91
  }
76
92
  //# sourceMappingURL=MainThreadRuntime.js.map
@@ -6,7 +6,6 @@ export declare enum RefCountType {
6
6
  export declare class ElementThreadElement {
7
7
  tag: string;
8
8
  uniqueId: number;
9
- parentComponentUniqueId: number;
10
9
  readonly pageConfig: PageConfig;
11
10
  private operationsRef;
12
11
  styleInfo: CssInJsInfo;
@@ -34,7 +33,7 @@ export declare class ElementThreadElement {
34
33
  };
35
34
  children: ElementThreadElement[];
36
35
  parent?: ElementThreadElement;
37
- constructor(tag: string, uniqueId: number, parentComponentUniqueId: number, pageConfig: PageConfig, operationsRef: {
36
+ constructor(tag: string, uniqueId: number, pageConfig: PageConfig, operationsRef: {
38
37
  operations: ElementOperation[];
39
38
  }, styleInfo: CssInJsInfo);
40
39
  setProperty(key: string, value: any): void;
@@ -18,7 +18,6 @@ export var RefCountType;
18
18
  export class ElementThreadElement {
19
19
  tag;
20
20
  uniqueId;
21
- parentComponentUniqueId;
22
21
  pageConfig;
23
22
  operationsRef;
24
23
  styleInfo;
@@ -50,10 +49,10 @@ export class ElementThreadElement {
50
49
  };
51
50
  children = [];
52
51
  parent;
53
- constructor(tag, uniqueId, parentComponentUniqueId, pageConfig, operationsRef, styleInfo) {
52
+ // public parentComponentUniqueId!: number;
53
+ constructor(tag, uniqueId, pageConfig, operationsRef, styleInfo) {
54
54
  this.tag = tag;
55
55
  this.uniqueId = uniqueId;
56
- this.parentComponentUniqueId = parentComponentUniqueId;
57
56
  this.pageConfig = pageConfig;
58
57
  this.operationsRef = operationsRef;
59
58
  this.styleInfo = styleInfo;
@@ -67,7 +66,6 @@ export class ElementThreadElement {
67
66
  type: OperationType.Create,
68
67
  uid: uniqueId,
69
68
  tag: tag,
70
- puid: parentComponentUniqueId.toString(),
71
69
  });
72
70
  }
73
71
  setProperty(key, value) {
@@ -0,0 +1,13 @@
1
+ import type { CssInJsInfo, ElementOperation, PageConfig } from '@lynx-js/web-constants';
2
+ import { ElementThreadElement } from './ElementThreadElement.js';
3
+ interface OffscreenDocument {
4
+ createElement(tagName: string): ElementThreadElement;
5
+ }
6
+ export declare function createOffscreenDocument(options: {
7
+ pageConfig: PageConfig;
8
+ styleInfo: CssInJsInfo;
9
+ operationsRef: {
10
+ operations: ElementOperation[];
11
+ };
12
+ }): OffscreenDocument;
13
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ListElement, ElementThreadElement } from './ElementThreadElement.js';
2
+ export function createOffscreenDocument(options) {
3
+ const { pageConfig, styleInfo, operationsRef } = options;
4
+ let incrementalUniqueId = 0;
5
+ function createElement(tagName) {
6
+ const uniqueId = incrementalUniqueId++;
7
+ if (tagName === 'list') {
8
+ return new ListElement(tagName, uniqueId, pageConfig, operationsRef, styleInfo);
9
+ }
10
+ else {
11
+ return new ElementThreadElement(tagName, uniqueId, pageConfig, operationsRef, styleInfo);
12
+ }
13
+ }
14
+ return {
15
+ createElement,
16
+ };
17
+ }
18
+ //# sourceMappingURL=createOffscreenDocument.js.map
@@ -1,14 +1,19 @@
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 { cssIdAttribute, } from '@lynx-js/web-constants';
4
+ import { cssIdAttribute, parentComponentUniqueIdAttribute, } from '@lynx-js/web-constants';
5
5
  import { __UpdateComponentID } from '../attributeAndProperty/attributeAndPropertyFunctions.js';
6
6
  import { ListElement, ElementThreadElement, } from '../ElementThreadElement.js';
7
7
  import { __SetCSSId } from '../style/styleFunctions.js';
8
+ import { createOffscreenDocument } from '../createOffscreenDocument.js';
8
9
  export function initializeElementCreatingFunction(config) {
9
- let incrementalUniqueId = 0;
10
10
  const tagSet = new Set();
11
11
  const { operationsRef, pageConfig, styleInfo } = config;
12
+ const document = createOffscreenDocument({
13
+ pageConfig,
14
+ operationsRef,
15
+ styleInfo,
16
+ });
12
17
  function createLynxElement(tag, parentComponentUniqueId, cssId, componentId,
13
18
  // @ts-expect-error
14
19
  info) {
@@ -16,8 +21,9 @@ export function initializeElementCreatingFunction(config) {
16
21
  config.onNewTag(tag);
17
22
  tagSet.add(tag);
18
23
  }
19
- const uniqueId = incrementalUniqueId++;
20
- const element = new (tag === 'list' ? ListElement : ElementThreadElement)(tag, uniqueId, parentComponentUniqueId, pageConfig, operationsRef, styleInfo);
24
+ const element = document.createElement(tag);
25
+ // element.parentComponentUniqueId = parentComponentUniqueId;
26
+ element.setAttribute(parentComponentUniqueIdAttribute, parentComponentUniqueId.toString());
21
27
  if (cssId !== undefined)
22
28
  __SetCSSId([element], cssId);
23
29
  else if (parentComponentUniqueId >= 0) { // don't infer for uniqueid === -1
@@ -48,7 +54,7 @@ export function initializeElementCreatingFunction(config) {
48
54
  }
49
55
  function __CreatePage(componentID, cssID, info) {
50
56
  const page = createLynxElement('page', 0, cssID, componentID, info);
51
- page.parentComponentUniqueId = page.uniqueId;
57
+ page.setAttribute(parentComponentUniqueIdAttribute, page.uniqueId.toString());
52
58
  return page;
53
59
  }
54
60
  function __CreateView(parentComponentUniqueId) {
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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-mainthread-apis"
11
+ },
7
12
  "license": "Apache-2.0",
8
13
  "type": "module",
9
14
  "main": "dist/index.js",
@@ -20,7 +25,7 @@
20
25
  "dependencies": {
21
26
  "css-tree": "^3.1.0",
22
27
  "hyphenate-style-name": "^1.1.0",
23
- "@lynx-js/web-constants": "0.7.0",
24
- "@lynx-js/web-style-transformer": "0.2.1"
28
+ "@lynx-js/web-constants": "0.7.1",
29
+ "@lynx-js/web-style-transformer": "0.2.2"
25
30
  }
26
31
  }