@lynx-js/web-core 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,48 @@
1
1
  # @lynx-js/web-core
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-worker-runtime@0.13.4
17
+ - @lynx-js/web-constants@0.13.4
18
+ - @lynx-js/web-worker-rpc@0.13.4
19
+
20
+ ## 0.13.3
21
+
22
+ ### Patch Changes
23
+
24
+ - refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897))
25
+
26
+ rename many internal apis to make logic be clear:
27
+
28
+ multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
29
+ all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
30
+
31
+ - perf: improve dom operation performance ([#881](https://github.com/lynx-family/lynx-stack/pull/881))
32
+
33
+ - code clean for offscreen-document, cut down inheritance levels
34
+ - add `appendChild` method for OffscreenElement, improve performance for append one node
35
+ - bypass some JS getter for dumping SSR string
36
+
37
+ - fix: worker not released when backgroundWorkerContextCount != 1 ([#845](https://github.com/lynx-family/lynx-stack/pull/845))
38
+
39
+ - 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)]:
40
+ - @lynx-js/offscreen-document@0.0.4
41
+ - @lynx-js/web-mainthread-apis@0.13.3
42
+ - @lynx-js/web-worker-runtime@0.13.3
43
+ - @lynx-js/web-constants@0.13.3
44
+ - @lynx-js/web-worker-rpc@0.13.3
45
+
3
46
  ## 0.13.2
4
47
 
5
48
  ### Patch Changes
@@ -29,7 +29,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
29
29
  * @event error lynx card fired an error
30
30
  *
31
31
  * @example
32
- * HTML Exmaple
32
+ * HTML Example
33
33
  *
34
34
  * Note that you should declarae the size of lynx-view
35
35
  *
@@ -41,7 +41,7 @@ export type INapiModulesCall = (name: string, data: any, moduleName: string, lyn
41
41
  * React 19 Example
42
42
  * ```jsx
43
43
  * <lynx-view url={myLynxCardUrl} rawData={{}} globalProps={{}} style={{height:'300px', width:'300px'}}>
44
- * </lynx-vew>
44
+ * </lynx-view>
45
45
  * ```
46
46
  */
47
47
  export declare class LynxView extends HTMLElement {
@@ -118,6 +118,12 @@ export declare class LynxView extends HTMLElement {
118
118
  * update the `__initData` and trigger essential flow
119
119
  */
120
120
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
121
+ /**
122
+ * @public
123
+ * @method
124
+ * update the `__globalProps`
125
+ */
126
+ updateGlobalProps(data: Cloneable): void;
121
127
  /**
122
128
  * @public
123
129
  * @method
@@ -26,7 +26,7 @@ import { inShadowRootStyles, } from '@lynx-js/web-constants';
26
26
  * @event error lynx card fired an error
27
27
  *
28
28
  * @example
29
- * HTML Exmaple
29
+ * HTML Example
30
30
  *
31
31
  * Note that you should declarae the size of lynx-view
32
32
  *
@@ -38,7 +38,7 @@ import { inShadowRootStyles, } from '@lynx-js/web-constants';
38
38
  * React 19 Example
39
39
  * ```jsx
40
40
  * <lynx-view url={myLynxCardUrl} rawData={{}} globalProps={{}} style={{height:'300px', width:'300px'}}>
41
- * </lynx-vew>
41
+ * </lynx-view>
42
42
  * ```
43
43
  */
44
44
  export class LynxView extends HTMLElement {
@@ -196,6 +196,14 @@ export class LynxView extends HTMLElement {
196
196
  updateData(data, updateDataType, callback) {
197
197
  this.#instance?.updateData(data, updateDataType, callback);
198
198
  }
199
+ /**
200
+ * @public
201
+ * @method
202
+ * update the `__globalProps`
203
+ */
204
+ updateGlobalProps(data) {
205
+ this.#instance?.updateGlobalProps(data);
206
+ }
199
207
  /**
200
208
  * @public
201
209
  * @method
@@ -17,5 +17,6 @@ export interface LynxView {
17
17
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
18
18
  dispose(): Promise<void>;
19
19
  sendGlobalEvent: RpcCallType<typeof sendGlobalEventEndpoint>;
20
+ updateGlobalProps: (data: Cloneable) => void;
20
21
  }
21
22
  export declare function createLynxView(configs: LynxViewConfigs): LynxView;
@@ -36,6 +36,10 @@ export function bootWorkers(lynxGroupId, allOnUI) {
36
36
  backgroundWorkerContextCount[lynxGroupId] = 0;
37
37
  contextIdToBackgroundWorker[lynxGroupId] = undefined;
38
38
  }
39
+ else if (typeof backgroundWorkerContextCount[lynxGroupId] === 'number'
40
+ && backgroundWorkerContextCount[lynxGroupId] > 1) {
41
+ backgroundWorkerContextCount[lynxGroupId]--;
42
+ }
39
43
  },
40
44
  };
41
45
  }
@@ -1,8 +1,8 @@
1
- import type { MainThreadStartConfigs } from '@lynx-js/web-constants';
1
+ import type { StartMainThreadContextConfig } from '@lynx-js/web-constants';
2
2
  import { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, callbacks: {
4
4
  onError?: () => void;
5
5
  }): {
6
- start: (configs: MainThreadStartConfigs) => Promise<void>;
6
+ start: (configs: StartMainThreadContextConfig) => Promise<void>;
7
7
  updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
8
8
  };
@@ -1,13 +1,10 @@
1
1
  import { Rpc } from '@lynx-js/web-worker-rpc';
2
- const { loadMainThread, } = await import('@lynx-js/web-mainthread-apis');
2
+ const { prepareMainThreadAPIs, } = await import('@lynx-js/web-mainthread-apis');
3
3
  export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, callbacks) {
4
4
  if (!globalThis.module) {
5
5
  Object.assign(globalThis, { module: {} });
6
6
  }
7
- const docu = Object.assign(shadowRoot, {
8
- createElement: document.createElement.bind(document),
9
- });
10
- const { startMainThread } = loadMainThread(mainToBackgroundRpc, docu, () => { }, markTimingInternal, () => {
7
+ const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document.createElement.bind(document), () => { }, markTimingInternal, () => {
11
8
  callbacks.onError?.();
12
9
  });
13
10
  let runtime;
@@ -2,6 +2,6 @@ import type { Rpc } from '@lynx-js/web-worker-rpc';
2
2
  export declare function createRenderMultiThread(mainThreadRpc: Rpc, shadowRoot: ShadowRoot, callbacks: {
3
3
  onError?: () => void;
4
4
  }): {
5
- start: (args_0: import("@lynx-js/web-constants").MainThreadStartConfigs) => void;
5
+ start: (args_0: import("@lynx-js/web-constants").StartMainThreadContextConfig) => void;
6
6
  updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
7
7
  };
@@ -40,7 +40,7 @@ export function registerInvokeUIMethodHandler(rpc, shadowRoot) {
40
40
  }
41
41
  }
42
42
  catch (e) {
43
- console.error(`[lynx-web] invokeUIMethod: apply method faild with`, e, element);
43
+ console.error(`[lynx-web] invokeUIMethod: apply method failed with`, e, element);
44
44
  code = ErrorCode.PARAM_INVALID;
45
45
  }
46
46
  }, (error) => {
@@ -0,0 +1,2 @@
1
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
2
+ export declare function registerTriggerElementMethodEndpointHandler(rpc: Rpc, shadowRoot: ShadowRoot): void;
@@ -0,0 +1,32 @@
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 {
5
+ // componentIdAttribute,
6
+ triggerElementMethodEndpoint, } from '@lynx-js/web-constants';
7
+ import { AnimationOperation, } from '@lynx-js/web-constants';
8
+ export function registerTriggerElementMethodEndpointHandler(rpc, shadowRoot) {
9
+ const animationMap = new Map();
10
+ rpc.registerHandler(triggerElementMethodEndpoint, (method, id, options) => {
11
+ if (method === 'animate') {
12
+ switch (options.operation) {
13
+ case AnimationOperation.START:
14
+ animationMap.set(options.id, shadowRoot.querySelector(id)?.animate(options.keyframes, options.timingOptions));
15
+ break;
16
+ case AnimationOperation.PLAY:
17
+ animationMap.get(options.id)?.play();
18
+ break;
19
+ case AnimationOperation.PAUSE:
20
+ animationMap.get(options.id)?.pause();
21
+ break;
22
+ case AnimationOperation.CANCEL:
23
+ animationMap.get(options.id)?.cancel();
24
+ break;
25
+ case AnimationOperation.FINISH:
26
+ animationMap.get(options.id)?.finish();
27
+ break;
28
+ }
29
+ }
30
+ });
31
+ }
32
+ //# sourceMappingURL=registerTriggerElementMethodEndpointHandler.js.map
@@ -6,6 +6,7 @@ import { registerTriggerComponentEventHandler } from './crossThreadHandlers/regi
6
6
  import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
7
7
  import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
8
8
  import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
9
+ import { registerTriggerElementMethodEndpointHandler } from './crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js';
9
10
  export function startBackground(backgroundRpc, shadowRoot, callbacks) {
10
11
  registerInvokeUIMethodHandler(backgroundRpc, shadowRoot);
11
12
  registerNativePropsHandler(backgroundRpc, shadowRoot);
@@ -14,6 +15,7 @@ export function startBackground(backgroundRpc, shadowRoot, callbacks) {
14
15
  registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
15
16
  registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
16
17
  registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
18
+ registerTriggerElementMethodEndpointHandler(backgroundRpc, shadowRoot);
17
19
  const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
18
20
  const markTiming = backgroundRpc.createCall(markTimingEndpoint);
19
21
  const updateDataBackground = backgroundRpc.createCall(updateDataEndpoint);
@@ -1,9 +1,9 @@
1
1
  import type { LynxView } from '../apis/createLynxView.js';
2
- import { type LynxTemplate, type MainThreadStartConfigs, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
2
+ import { type LynxTemplate, type StartMainThreadContextConfig, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
3
3
  export type StartUIThreadCallbacks = {
4
4
  nativeModulesCall: NativeModulesCall;
5
5
  napiModulesCall: NapiModulesCall;
6
6
  onError?: () => void;
7
7
  customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
8
8
  };
9
- export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks): LynxView;
9
+ export declare function startUIThread(templateUrl: string, configs: Omit<StartMainThreadContextConfig, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks): LynxView;
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { bootWorkers } from './bootWorkers.js';
5
5
  import { createDispose } from './crossThreadHandlers/createDispose.js';
6
- import {} from '@lynx-js/web-constants';
6
+ import { updateGlobalPropsEndpoint, } from '@lynx-js/web-constants';
7
7
  import { loadTemplate } from '../utils/loadTemplate.js';
8
8
  import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
9
9
  import { startBackground } from './startBackground.js';
@@ -37,6 +37,7 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
37
37
  updateData: createUpdateData(updateDataMainThread, updateDataBackground),
38
38
  dispose: createDispose(backgroundRpc, terminateWorkers),
39
39
  sendGlobalEvent,
40
+ updateGlobalProps: backgroundRpc.createCall(updateGlobalPropsEndpoint),
40
41
  };
41
42
  }
42
43
  //# sourceMappingURL=startUIThread.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,15 +24,15 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/offscreen-document": "0.0.3",
28
- "@lynx-js/web-constants": "0.13.2",
29
- "@lynx-js/web-mainthread-apis": "0.13.2",
30
- "@lynx-js/web-worker-rpc": "0.13.2",
31
- "@lynx-js/web-worker-runtime": "0.13.2"
27
+ "@lynx-js/offscreen-document": "0.1.0",
28
+ "@lynx-js/web-constants": "0.13.4",
29
+ "@lynx-js/web-mainthread-apis": "0.13.4",
30
+ "@lynx-js/web-worker-rpc": "0.13.4",
31
+ "@lynx-js/web-worker-runtime": "0.13.4"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@lynx-js/lynx-core": "0.1.2",
35
- "@lynx-js/web-elements": "0.7.2"
35
+ "@lynx-js/web-elements": "0.7.4"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@lynx-js/lynx-core": "0.1.2",