@lynx-js/web-mainthread-apis 0.13.2 → 0.13.3

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,25 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.13.3
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897))
8
+
9
+ rename many internal apis to make logic be clear:
10
+
11
+ multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
12
+ all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
13
+
14
+ - perf: improve dom operation performance ([#881](https://github.com/lynx-family/lynx-stack/pull/881))
15
+
16
+ - code clean for offscreen-document, cut down inheritance levels
17
+ - add `appendChild` method for OffscreenElement, improve performance for append one node
18
+ - bypass some JS getter for dumping SSR string
19
+
20
+ - Updated dependencies [[`b6e27da`](https://github.com/lynx-family/lynx-stack/commit/b6e27daf865b0627b1c3238228a4fdf65ad87ee3)]:
21
+ - @lynx-js/web-constants@0.13.3
22
+
3
23
  ## 0.13.2
4
24
 
5
25
  ### Patch Changes
@@ -1,5 +1,5 @@
1
- import { type MainThreadConfig } from './MainThreadRuntime.js';
2
- export declare function createMainThreadLynx(config: MainThreadConfig): {
1
+ import { type MainThreadRuntimeConfig } from './MainThreadRuntime.js';
2
+ export declare function createMainThreadLynx(config: MainThreadRuntimeConfig): {
3
3
  getJSContext(): import("@lynx-js/web-constants").LynxContextEventTarget;
4
4
  requestAnimationFrame(cb: FrameRequestCallback): number;
5
5
  cancelAnimationFrame(handler: number): void;
@@ -11,7 +11,7 @@ export interface MainThreadRuntimeCallbacks {
11
11
  publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
12
12
  postExposure: RpcCallType<typeof postExposureEndpoint>;
13
13
  }
14
- export interface MainThreadConfig {
14
+ export interface MainThreadRuntimeConfig {
15
15
  pageConfig: PageConfig;
16
16
  globalProps: unknown;
17
17
  callbacks: MainThreadRuntimeCallbacks;
@@ -20,7 +20,8 @@ export interface MainThreadConfig {
20
20
  lepusCode: Record<string, LynxJSModule>;
21
21
  browserConfig: BrowserConfig;
22
22
  tagMap: Record<string, string>;
23
- docu: Pick<Document, 'append' | 'createElement' | 'addEventListener'>;
23
+ createElement: Document['createElement'];
24
+ rootDom: Pick<Element, 'append' | 'addEventListener'>;
24
25
  jsContext: LynxContextEventTarget;
25
26
  }
26
27
  export declare const elementToRuntimeInfoMap: unique symbol;
@@ -30,7 +31,7 @@ export declare const lynxUniqueIdToElement: unique symbol;
30
31
  export declare const switchExposureService: unique symbol;
31
32
  export declare class MainThreadRuntime {
32
33
  #private;
33
- config: MainThreadConfig;
34
+ config: MainThreadRuntimeConfig;
34
35
  /**
35
36
  * @private
36
37
  */
@@ -51,6 +52,7 @@ export declare class MainThreadRuntime {
51
52
  * @private the CreatePage will append it to this
52
53
  */
53
54
  _rootDom: Pick<Element, 'append' | 'addEventListener'>;
55
+ _createElement: Document['createElement'];
54
56
  /**
55
57
  * @private
56
58
  */
@@ -59,7 +61,7 @@ export declare class MainThreadRuntime {
59
61
  * @private
60
62
  */
61
63
  [elementToRuntimeInfoMap]: WeakMap<HTMLElement, LynxRuntimeInfo>;
62
- constructor(config: MainThreadConfig);
64
+ constructor(config: MainThreadRuntimeConfig);
63
65
  /**
64
66
  * @private
65
67
  */
@@ -74,7 +76,11 @@ export declare class MainThreadRuntime {
74
76
  lynx: MainThreadLynx;
75
77
  __globalProps: unknown;
76
78
  processData?: ProcessDataCallback;
79
+ ssrEncode?: () => string;
80
+ ssrHydrate?: (encodeData?: string) => void;
77
81
  renderPage: (data: unknown) => void;
82
+ __GetTemplateParts?: () => Record<string, Element> | undefined;
83
+ __GetPageElement: () => HTMLElement | undefined;
78
84
  _ReportError: RpcCallType<typeof reportErrorEndpoint>;
79
85
  __OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
80
86
  __LoadLepusChunk: (path: string) => boolean;
@@ -38,6 +38,7 @@ export class MainThreadRuntime {
38
38
  * @private the CreatePage will append it to this
39
39
  */
40
40
  _rootDom;
41
+ _createElement;
41
42
  /**
42
43
  * @private
43
44
  */
@@ -50,6 +51,8 @@ export class MainThreadRuntime {
50
51
  this.config = config;
51
52
  this.__globalProps = config.globalProps;
52
53
  this.lynx = createMainThreadLynx(config);
54
+ this._rootDom = config.rootDom;
55
+ this._createElement = config.createElement;
53
56
  /**
54
57
  * now create the style content
55
58
  * 1. flatten the styleInfo
@@ -63,9 +66,8 @@ export class MainThreadRuntime {
63
66
  const cssInJsInfo = this.config.pageConfig.enableCSSSelector
64
67
  ? {}
65
68
  : genCssInJsInfo(this.config.styleInfo);
66
- const cardStyleElement = this.config.docu.createElement('style');
69
+ const cardStyleElement = this._createElement('style');
67
70
  cardStyleElement.innerHTML = genCssContent(this.config.styleInfo, this.config.pageConfig);
68
- this._rootDom = this.config.docu;
69
71
  this._rootDom.append(cardStyleElement);
70
72
  /**
71
73
  * now create Element PAPIs
@@ -117,7 +119,7 @@ export class MainThreadRuntime {
117
119
  [updateCSSInJsStyle](uniqueId, newStyles) {
118
120
  let currentElement = this._lynxUniqueIdToStyleSheet[uniqueId]?.deref();
119
121
  if (!currentElement) {
120
- currentElement = this.config.docu.createElement('style');
122
+ currentElement = this._createElement('style');
121
123
  this._lynxUniqueIdToStyleSheet[uniqueId] = new WeakRef(currentElement);
122
124
  this._rootDom.append(currentElement);
123
125
  }
@@ -146,7 +148,13 @@ export class MainThreadRuntime {
146
148
  lynx;
147
149
  __globalProps;
148
150
  processData;
151
+ ssrEncode;
152
+ ssrHydrate;
149
153
  #renderPage;
154
+ __GetTemplateParts;
155
+ __GetPageElement = () => {
156
+ return this._page;
157
+ };
150
158
  _ReportError;
151
159
  __OnLifecycleEvent;
152
160
  __LoadLepusChunk = (path) => {
@@ -2,7 +2,7 @@
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
4
  export function __AppendElement(parent, child) {
5
- parent.append(child);
5
+ parent.appendChild(child);
6
6
  }
7
7
  export function __ElementIsEqual(left, right) {
8
8
  return left === right;
@@ -12,7 +12,7 @@ export function initializeElementCreatingFunction(runtime) {
12
12
  // @ts-expect-error
13
13
  const __SetCSSId = runtime.__SetCSSId;
14
14
  const htmlTag = runtime.config.tagMap[tag] ?? tag;
15
- const element = runtime.config.docu.createElement(htmlTag);
15
+ const element = runtime._createElement(htmlTag);
16
16
  element.setAttribute(lynxTagAttribute, tag);
17
17
  const uniqueId = uniqueIdInc++;
18
18
  const runtimeInfo = {
@@ -101,7 +101,7 @@ export function initializeElementCreatingFunction(runtime) {
101
101
  return element;
102
102
  }
103
103
  function __SwapElement(childA, childB) {
104
- const temp = runtime.config.docu.createElement('div');
104
+ const temp = runtime._createElement('div');
105
105
  childA.replaceWith(temp);
106
106
  childB.replaceWith(childA);
107
107
  temp.replaceWith(childB);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { loadMainThread } from './loadMainThread.js';
1
+ export { prepareMainThreadAPIs } from './prepareMainThreadAPIs.js';
2
2
  export * from './MainThreadRuntime.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
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
- export { loadMainThread } from './loadMainThread.js';
4
+ export { prepareMainThreadAPIs } from './prepareMainThreadAPIs.js';
5
5
  export * from './MainThreadRuntime.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint } from '@lynx-js/web-constants';
2
+ import { MainThreadRuntime } from './MainThreadRuntime.js';
3
+ export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, createElement: Document['createElement'], commitDocument: () => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, reportError: RpcCallType<typeof reportErrorEndpoint>): {
4
+ startMainThread: (config: StartMainThreadContextConfig) => Promise<MainThreadRuntime>;
5
+ };
@@ -6,7 +6,7 @@ import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCa
6
6
  import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerGetCustomSectionHandler.js';
7
7
  import { MainThreadRuntime, switchExposureService, } from './MainThreadRuntime.js';
8
8
  const moduleCache = {};
9
- export function loadMainThread(backgroundThreadRpc, docu, commitDocument, markTimingInternal, reportError) {
9
+ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, reportError) {
10
10
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
11
11
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
12
12
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -48,7 +48,8 @@ export function loadMainThread(backgroundThreadRpc, docu, commitDocument, markTi
48
48
  pageConfig,
49
49
  styleInfo,
50
50
  lepusCode: lepusCodeLoaded,
51
- docu,
51
+ createElement,
52
+ rootDom,
52
53
  callbacks: {
53
54
  mainChunkReady: () => {
54
55
  markTimingInternal('data_processor_start');
@@ -117,4 +118,4 @@ export function loadMainThread(backgroundThreadRpc, docu, commitDocument, markTi
117
118
  }
118
119
  return { startMainThread };
119
120
  }
120
- //# sourceMappingURL=loadMainThread.js.map
121
+ //# sourceMappingURL=prepareMainThreadAPIs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "css-tree": "^3.1.0",
27
27
  "hyphenate-style-name": "^1.1.0",
28
- "@lynx-js/web-constants": "0.13.2",
28
+ "@lynx-js/web-constants": "0.13.3",
29
29
  "@lynx-js/web-style-transformer": "0.3.0"
30
30
  }
31
31
  }
@@ -1,5 +0,0 @@
1
- import { type Rpc, type MainThreadStartConfigs, type RpcCallType, type reportErrorEndpoint } from '@lynx-js/web-constants';
2
- import { MainThreadRuntime } from './MainThreadRuntime.js';
3
- export declare function loadMainThread(backgroundThreadRpc: Rpc, docu: Pick<Document, 'append' | 'createElement' | 'addEventListener'>, commitDocument: () => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, reportError: RpcCallType<typeof reportErrorEndpoint>): {
4
- startMainThread: (config: MainThreadStartConfigs) => Promise<MainThreadRuntime>;
5
- };