@lynx-js/web-worker-runtime 0.13.2 → 0.13.4

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,38 @@
1
1
  # @lynx-js/web-worker-runtime
2
2
 
3
+ ## 0.13.4
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: lynx-view supports `updateGlobalProps` method, which can be used to update lynx.\_\_globalProps ([#918](https://github.com/lynx-family/lynx-stack/pull/918))
8
+
9
+ - feat: supports `lynx.getElementById()` && `animate()`. ([#912](https://github.com/lynx-family/lynx-stack/pull/912))
10
+
11
+ After this commit, you can use `lynx.getElementById()` to get the element by id, and use `element.animate()` to animate the element.
12
+
13
+ - Updated dependencies [[`96d3133`](https://github.com/lynx-family/lynx-stack/commit/96d3133b149b61af01c5478f4dc7b0a071137d98), [`75e5b2f`](https://github.com/lynx-family/lynx-stack/commit/75e5b2ff16ecf5f7072a45cd130e653dee747461), [`569618d`](https://github.com/lynx-family/lynx-stack/commit/569618d8e2665f5c9e1672f7ee5900ec2a5179a2), [`f9f88d6`](https://github.com/lynx-family/lynx-stack/commit/f9f88d6fb9c42d3370a6622d9d799d671ffcf1a7)]:
14
+ - @lynx-js/web-mainthread-apis@0.13.4
15
+ - @lynx-js/offscreen-document@0.1.0
16
+ - @lynx-js/web-constants@0.13.4
17
+ - @lynx-js/web-worker-rpc@0.13.4
18
+
19
+ ## 0.13.3
20
+
21
+ ### Patch Changes
22
+
23
+ - refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897))
24
+
25
+ rename many internal apis to make logic be clear:
26
+
27
+ multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
28
+ all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
29
+
30
+ - Updated dependencies [[`bb1f9d8`](https://github.com/lynx-family/lynx-stack/commit/bb1f9d845ef2395a0508666701409972e159389d), [`b6e27da`](https://github.com/lynx-family/lynx-stack/commit/b6e27daf865b0627b1c3238228a4fdf65ad87ee3), [`3d716d7`](https://github.com/lynx-family/lynx-stack/commit/3d716d79ae053b225e9bac2bbb036c968f5261e7)]:
31
+ - @lynx-js/offscreen-document@0.0.4
32
+ - @lynx-js/web-mainthread-apis@0.13.3
33
+ - @lynx-js/web-constants@0.13.3
34
+ - @lynx-js/web-worker-rpc@0.13.3
35
+
3
36
  ## 0.13.2
4
37
 
5
38
  ### Patch Changes
@@ -4,7 +4,7 @@ export interface CreateLynxConfig {
4
4
  globalProps: unknown;
5
5
  customSections: Record<string, Cloneable>;
6
6
  }
7
- export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp: NativeApp, mainThreadRpc: Rpc): {
7
+ export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp: NativeApp, mainThreadRpc: Rpc, uiThreadRpc: Rpc): {
8
8
  __globalProps: unknown;
9
9
  getJSModule(_moduleName: string): any;
10
10
  getNativeApp(): NativeApp;
@@ -12,4 +12,7 @@ export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp
12
12
  getCustomSectionSync(key: string): Cloneable;
13
13
  getCustomSection: (key: string, callback: (object: Cloneable) => void) => void;
14
14
  queueMicrotask: (callback: () => void) => void;
15
+ createElement(_: string, id: string): {
16
+ animate(operation: import("@lynx-js/web-constants").AnimationOperation, id: string, keyframes?: Record<string, any>[], timingOptions?: Record<string, any>): void;
17
+ };
15
18
  };
@@ -3,7 +3,8 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, LynxCrossThreadContext, } from '@lynx-js/web-constants';
5
5
  import { createGetCustomSection } from './crossThreadHandlers/createGetCustomSection.js';
6
- export function createBackgroundLynx(config, nativeApp, mainThreadRpc) {
6
+ import { createElement } from './createElement.js';
7
+ export function createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadRpc) {
7
8
  const coreContext = new LynxCrossThreadContext({
8
9
  rpc: mainThreadRpc,
9
10
  receiveEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
@@ -26,6 +27,9 @@ export function createBackgroundLynx(config, nativeApp, mainThreadRpc) {
26
27
  queueMicrotask: (callback) => {
27
28
  queueMicrotask(callback);
28
29
  },
30
+ createElement(_, id) {
31
+ return createElement(id, uiThreadRpc);
32
+ },
29
33
  };
30
34
  }
31
35
  //# sourceMappingURL=createBackgroundLynx.js.map
@@ -0,0 +1,5 @@
1
+ import type { AnimationOperation } from '@lynx-js/web-constants/src/types/Element.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare const createElement: (elementId: string, uiThreadRpc: Rpc) => {
4
+ animate(operation: AnimationOperation, id: string, keyframes?: Record<string, any>[], timingOptions?: Record<string, any>): void;
5
+ };
@@ -0,0 +1,18 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { triggerElementMethodEndpoint } from '@lynx-js/web-constants';
5
+ export const createElement = (elementId, uiThreadRpc) => {
6
+ const triggerElementMethod = uiThreadRpc.createCall(triggerElementMethodEndpoint);
7
+ return {
8
+ animate(operation, id, keyframes, timingOptions) {
9
+ triggerElementMethod('animate', elementId, {
10
+ operation,
11
+ id,
12
+ keyframes,
13
+ timingOptions,
14
+ });
15
+ },
16
+ };
17
+ };
18
+ //# sourceMappingURL=createElement.js.map
@@ -8,6 +8,7 @@ import { registerPublishEventHandler } from './crossThreadHandlers/registerPubli
8
8
  import { createPerformanceApis } from './createPerformanceApis.js';
9
9
  import { registerSendGlobalEventHandler } from './crossThreadHandlers/registerSendGlobalEvent.js';
10
10
  import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJSObjectDestructionObserver.js';
11
+ import { registerUpdateGlobalPropsHandler } from './crossThreadHandlers/registerUpdateGlobalPropsHandler.js';
11
12
  let nativeAppCount = 0;
12
13
  const sharedData = {};
13
14
  export async function createNativeApp(config) {
@@ -53,9 +54,9 @@ export async function createNativeApp(config) {
53
54
  clearInterval: clearInterval,
54
55
  nativeModuleProxy: await createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap),
55
56
  loadScriptAsync: function (sourceURL, callback) {
56
- const mainfestUrl = template.manifest[`/${sourceURL}`];
57
- if (mainfestUrl)
58
- sourceURL = mainfestUrl;
57
+ const manifestUrl = template.manifest[`/${sourceURL}`];
58
+ if (manifestUrl)
59
+ sourceURL = manifestUrl;
59
60
  import(
60
61
  /* webpackIgnore: true */
61
62
  sourceURL).catch(callback).then(async () => {
@@ -63,9 +64,9 @@ export async function createNativeApp(config) {
63
64
  });
64
65
  },
65
66
  loadScript: (sourceURL) => {
66
- const mainfestUrl = template.manifest[`/${sourceURL}`];
67
- if (mainfestUrl)
68
- sourceURL = mainfestUrl;
67
+ const manifestUrl = template.manifest[`/${sourceURL}`];
68
+ if (manifestUrl)
69
+ sourceURL = manifestUrl;
69
70
  importScripts(sourceURL);
70
71
  return createBundleInitReturnObj();
71
72
  },
@@ -84,6 +85,7 @@ export async function createNativeApp(config) {
84
85
  registerGlobalExposureEventHandler(mainThreadRpc, tt);
85
86
  registerUpdateDataHandler(uiThreadRpc, tt);
86
87
  registerSendGlobalEventHandler(uiThreadRpc, tt);
88
+ registerUpdateGlobalPropsHandler(uiThreadRpc, tt);
87
89
  timingSystem.registerGlobalEmitter(tt.GlobalEventEmitter);
88
90
  tt.lynx.getCoreContext().__start();
89
91
  },
@@ -0,0 +1,3 @@
1
+ import { type NativeTTObject } from '@lynx-js/web-constants';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerUpdateGlobalPropsHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,8 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { updateGlobalPropsEndpoint, } from '@lynx-js/web-constants';
5
+ export function registerUpdateGlobalPropsHandler(rpc, tt) {
6
+ rpc.registerHandlerLazy(updateGlobalPropsEndpoint, tt, 'updateGlobalProps');
7
+ }
8
+ //# sourceMappingURL=registerUpdateGlobalPropsHandler.js.map
@@ -25,7 +25,7 @@ export function startBackgroundThread(uiThreadPort, mainThreadPort) {
25
25
  });
26
26
  globalThis['napiLoaderOnRT' + nativeApp.id] =
27
27
  await createNapiLoader(uiThreadRpc, config.napiModulesMap);
28
- const nativeLynx = createBackgroundLynx(config, nativeApp, mainThreadRpc);
28
+ const nativeLynx = createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadRpc);
29
29
  lynxCore.then(({ loadCard, destroyCard, callDestroyLifetimeFun }) => {
30
30
  loadCard(nativeApp, config, nativeLynx);
31
31
  registerDisposeHandler(uiThreadRpc, nativeApp, destroyCard, callDestroyLifetimeFun);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { startMainThread } from './mainThread/startMainThread.js';
2
1
  export interface WorkerStartMessage {
3
2
  mode: 'main' | 'background';
4
3
  toPeerThread: MessagePort;
5
4
  toUIThread: MessagePort;
6
5
  }
7
- export { startMainThread };
package/dist/index.js CHANGED
@@ -2,12 +2,12 @@
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
  import { startBackgroundThread } from './backgroundThread/index.js';
5
- import { startMainThread } from './mainThread/startMainThread.js';
5
+ import { startMainThreadWorker } from './mainThread/startMainThread.js';
6
6
  globalThis.onmessage = (ev) => {
7
7
  const { mode, toPeerThread, toUIThread } = ev
8
8
  .data;
9
9
  if (mode === 'main') {
10
- startMainThread(toUIThread, toPeerThread);
10
+ startMainThreadWorker(toUIThread, toPeerThread);
11
11
  }
12
12
  else {
13
13
  startBackgroundThread(toUIThread, toPeerThread);
@@ -16,5 +16,4 @@ globalThis.onmessage = (ev) => {
16
16
  Object.assign(globalThis, {
17
17
  module: { exports: null },
18
18
  });
19
- export { startMainThread };
20
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- export { startMainThread } from './startMainThread.js';
1
+ export { startMainThreadWorker } from './startMainThread.js';
@@ -1,5 +1,5 @@
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 { startMainThread } from './startMainThread.js';
4
+ export { startMainThreadWorker } from './startMainThread.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,4 +1 @@
1
- import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
2
- export declare function startMainThread(uiThreadPort: MessagePort, backgroundThreadPort: MessagePort): {
3
- docu: OffscreenDocument;
4
- };
1
+ export declare function startMainThreadWorker(uiThreadPort: MessagePort, backgroundThreadPort: MessagePort): void;
@@ -7,8 +7,8 @@ import { createMarkTimingInternal } from './crossThreadHandlers/createMainthread
7
7
  import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
8
8
  import { _onEvent } from '@lynx-js/offscreen-document/webworker';
9
9
  import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
10
- const { loadMainThread } = await import('@lynx-js/web-mainthread-apis');
11
- export function startMainThread(uiThreadPort, backgroundThreadPort) {
10
+ const { prepareMainThreadAPIs } = await import('@lynx-js/web-mainthread-apis');
11
+ export function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
12
12
  const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
13
13
  const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
14
14
  const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
@@ -18,14 +18,11 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
18
18
  onCommit: uiFlush,
19
19
  });
20
20
  uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
21
- const { startMainThread } = loadMainThread(backgroundThreadRpc, docu, docu.commit.bind(docu), markTimingInternal, reportError);
21
+ const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), docu.commit.bind(docu), markTimingInternal, reportError);
22
22
  uiThreadRpc.registerHandler(mainThreadStartEndpoint, (config) => {
23
23
  startMainThread(config).then((runtime) => {
24
24
  registerUpdateDataHandler(uiThreadRpc, runtime);
25
25
  });
26
26
  });
27
- return {
28
- docu,
29
- };
30
27
  }
31
28
  //# sourceMappingURL=startMainThread.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-worker-runtime",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -22,10 +22,10 @@
22
22
  "README.md"
23
23
  ],
24
24
  "dependencies": {
25
- "@lynx-js/offscreen-document": "0.0.3",
26
- "@lynx-js/web-constants": "0.13.2",
27
- "@lynx-js/web-mainthread-apis": "0.13.2",
28
- "@lynx-js/web-worker-rpc": "0.13.2"
25
+ "@lynx-js/offscreen-document": "0.1.0",
26
+ "@lynx-js/web-constants": "0.13.4",
27
+ "@lynx-js/web-mainthread-apis": "0.13.4",
28
+ "@lynx-js/web-worker-rpc": "0.13.4"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@lynx-js/lynx-core": "0.1.2"