@lynx-js/web-constants 0.14.0 → 0.14.2

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,29 @@
1
1
  # @lynx-js/web-constants
2
2
 
3
+ ## 0.14.2
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: merge multiple markTiming RPC communication events together and send them together, which can effectively reduce the number of RPC communications. ([#1178](https://github.com/lynx-family/lynx-stack/pull/1178))
8
+
9
+ - chore: extract shared logic from web-core and web-core-server's loadTemplate into a unified generateTemplate function ([#1211](https://github.com/lynx-family/lynx-stack/pull/1211))
10
+
11
+ - Updated dependencies []:
12
+ - @lynx-js/web-worker-rpc@0.14.2
13
+
14
+ ## 0.14.1
15
+
16
+ ### Patch Changes
17
+
18
+ - feat: support BTS API `lynx.reportError` && `__SetSourceMapRelease`, now you can use it and handle it in lynx-view error event. ([#1059](https://github.com/lynx-family/lynx-stack/pull/1059))
19
+
20
+ - fix: in lynx-view all-on-ui mode, the input event of input and textarea is triggered twice, and the first e.detail is a string, which does not conform to the expected data format. ([#1179](https://github.com/lynx-family/lynx-stack/pull/1179))
21
+
22
+ - fix: under the all-on-ui strategy, reload() will add two page elements. ([#1147](https://github.com/lynx-family/lynx-stack/pull/1147))
23
+
24
+ - Updated dependencies []:
25
+ - @lynx-js/web-worker-rpc@0.14.1
26
+
3
27
  ## 0.14.0
4
28
 
5
29
  ### Patch Changes
@@ -5,6 +5,7 @@ export declare const parentComponentUniqueIdAttribute: "l-p-comp-uid";
5
5
  export declare const lynxTagAttribute: "lynx-tag";
6
6
  export declare const lynxDatasetAttribute: "l-dset";
7
7
  export declare const lynxComponentConfigAttribute: "l-comp-cfg";
8
+ export declare const lynxDisposedAttribute: "l-disposed";
8
9
  export declare const lynxDefaultDisplayLinearAttribute: "lynx-default-display-linear";
9
10
  export declare const lynxDefaultOverflowVisibleAttribute: "lynx-default-overflow-visible";
10
11
  export declare const __lynx_timing_flag: "__lynx_timing_flag";
package/dist/constants.js CHANGED
@@ -8,6 +8,7 @@ export const parentComponentUniqueIdAttribute = 'l-p-comp-uid';
8
8
  export const lynxTagAttribute = 'lynx-tag';
9
9
  export const lynxDatasetAttribute = 'l-dset';
10
10
  export const lynxComponentConfigAttribute = 'l-comp-cfg';
11
+ export const lynxDisposedAttribute = 'l-disposed';
11
12
  export const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
12
13
  export const lynxDefaultOverflowVisibleAttribute = 'lynx-default-overflow-visible';
13
14
  export const __lynx_timing_flag = '__lynx_timing_flag';
@@ -3,7 +3,7 @@ import type { Cloneable, CloneableObject } from './types/Cloneable.js';
3
3
  import type { StartMainThreadContextConfig } from './types/MainThreadStartConfigs.js';
4
4
  import type { IdentifierType, InvokeCallbackRes } from './types/NativeApp.js';
5
5
  import type { ElementAnimationOptions } from './types/Element.js';
6
- import type { BackMainThreadContextConfig } from './types/index.js';
6
+ import type { BackMainThreadContextConfig, MarkTiming } from './types/index.js';
7
7
  export declare const postExposureEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[{
8
8
  exposures: ExposureWorkerEvent[];
9
9
  disExposures: ExposureWorkerEvent[];
@@ -32,7 +32,7 @@ export declare const setNativePropsEndpoint: import("@lynx-js/web-worker-rpc/dis
32
32
  export declare const nativeModulesCallEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[name: string, data: Cloneable, moduleName: string], any>;
33
33
  export declare const napiModulesCallEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncWithTransfer<[name: string, data: Cloneable, moduleName: string], any>;
34
34
  export declare const getCustomSectionsEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[string], Cloneable>;
35
- export declare const markTimingEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[timingKey: string, pipelineId: string | undefined, timeStamp: number]>;
35
+ export declare const markTimingEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[MarkTiming[]]>;
36
36
  export declare const postTimingFlagsEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[timingFlags: string[], pipelineId: string | undefined]>;
37
37
  export declare const triggerComponentEventEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[id: string, params: {
38
38
  eventDetail: CloneableObject;
package/dist/eventName.js CHANGED
@@ -8,15 +8,18 @@ export const W3cEventNameToLynx = {
8
8
  overlaytouch: 'touch',
9
9
  lynxfocus: 'focus',
10
10
  lynxblur: 'blur',
11
+ lynxinput: 'input',
11
12
  };
12
13
  export const LynxEventNameToW3cByTagName = {
13
14
  'X-INPUT': {
14
15
  'blur': 'lynxblur',
15
16
  'focus': 'lynxfocus',
17
+ 'input': 'lynxinput',
16
18
  },
17
19
  'X-TEXTAREA': {
18
20
  'blur': 'lynxblur',
19
21
  'focus': 'lynxfocus',
22
+ 'input': 'lynxinput',
20
23
  },
21
24
  };
22
25
  export const LynxEventNameToW3cCommon = {
@@ -0,0 +1,5 @@
1
+ export interface MarkTiming {
2
+ timingKey: string;
3
+ pipelineId?: string;
4
+ timeStamp: number;
5
+ }
@@ -0,0 +1,5 @@
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
+ export {};
5
+ //# sourceMappingURL=MarkTiming.js.map
@@ -110,4 +110,6 @@ export interface NativeApp {
110
110
  setSharedData<T>(dataKey: string, dataVal: T): void;
111
111
  getSharedData<T = unknown>(dataKey: string): T | undefined;
112
112
  i18nResource: I18nResource;
113
+ reportException: (error: Error, _: unknown) => void;
114
+ __SetSourceMapRelease: (err: Error) => void;
113
115
  }
@@ -17,3 +17,4 @@ export * from './MainThreadGlobalThis.js';
17
17
  export * from './MainThreadLynx.js';
18
18
  export * from './I18n.js';
19
19
  export * from './BackThreadStartConfigs.js';
20
+ export * from './MarkTiming.js';
@@ -17,4 +17,5 @@ export * from './MainThreadGlobalThis.js';
17
17
  export * from './MainThreadLynx.js';
18
18
  export * from './I18n.js';
19
19
  export * from './BackThreadStartConfigs.js';
20
+ export * from './MarkTiming.js';
20
21
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,6 @@
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.
1
4
  import { DispatchEventResult, } from '../types/LynxContextEventTarget.js';
2
5
  export class LynxCrossThreadContext extends EventTarget {
3
6
  _config;
@@ -0,0 +1,3 @@
1
+ import type { LynxTemplate } from '../types/LynxModule.js';
2
+ export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: (content: string) => string): Promise<LynxTemplate>;
3
+ export declare function generateTemplate(template: LynxTemplate, createJsModuleUrl: (content: string, name: string) => Promise<string>, templateName: string): Promise<LynxTemplate>;
@@ -0,0 +1,123 @@
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 { 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
+ '__GetConfig',
26
+ '__UpdateListCallbacks',
27
+ '__AppendElement',
28
+ '__ElementIsEqual',
29
+ '__FirstElement',
30
+ '__GetChildren',
31
+ '__GetParent',
32
+ '__InsertElementBefore',
33
+ '__LastElement',
34
+ '__NextElement',
35
+ '__RemoveElement',
36
+ '__ReplaceElement',
37
+ '__ReplaceElements',
38
+ '__SwapElement',
39
+ '__CreateComponent',
40
+ '__CreateElement',
41
+ '__CreatePage',
42
+ '__CreateView',
43
+ '__CreateText',
44
+ '__CreateRawText',
45
+ '__CreateImage',
46
+ '__CreateScrollView',
47
+ '__CreateWrapperElement',
48
+ '__CreateList',
49
+ '__AddEvent',
50
+ '__GetEvent',
51
+ '__GetEvents',
52
+ '__SetEvents',
53
+ '__AddClass',
54
+ '__SetClasses',
55
+ '__GetClasses',
56
+ '__AddInlineStyle',
57
+ '__SetInlineStyles',
58
+ '__SetCSSId',
59
+ '__OnLifecycleEvent',
60
+ '__FlushElementTree',
61
+ '__LoadLepusChunk',
62
+ 'SystemInfo',
63
+ '_I18nResourceTranslation',
64
+ '_AddEventListener',
65
+ ];
66
+ const backgroundInjectVars = [
67
+ 'NativeModules',
68
+ 'globalThis',
69
+ 'lynx',
70
+ 'lynxCoreInject',
71
+ 'SystemInfo',
72
+ ];
73
+ const backgroundInjectWithBind = [
74
+ 'Card',
75
+ 'Component',
76
+ ];
77
+ async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, createJsModuleUrl, templateName) {
78
+ injectVars = injectVars.concat(muteableVars);
79
+ const generateModuleContent = (content) => [
80
+ '//# allFunctionsCalledOnLoad\n',
81
+ 'globalThis.module.exports = function(lynx_runtime) {',
82
+ 'const module= {exports:{}};let exports = module.exports;',
83
+ 'var {',
84
+ injectVars.join(','),
85
+ '} = lynx_runtime;',
86
+ ...injectWithBind.map(nm => `const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
87
+ ';var globDynamicComponentEntry = \'__Card__\';',
88
+ 'var {__globalProps} = lynx;',
89
+ 'lynx_runtime._updateVars=()=>{',
90
+ ...muteableVars.map(nm => `${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
91
+ '};\n',
92
+ content,
93
+ '\n return module.exports;}',
94
+ ].join('');
95
+ if (!templateName) {
96
+ createJsModuleUrl;
97
+ }
98
+ const processEntry = templateName
99
+ ? async ([name, content]) => [
100
+ name,
101
+ await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
102
+ ]
103
+ : async ([name, content]) => [
104
+ name,
105
+ await createJsModuleUrl(generateModuleContent(content)),
106
+ ];
107
+ return Promise.all(Object.entries(obj).map(processEntry)).then(Object.fromEntries);
108
+ }
109
+ export async function generateTemplate(template, createJsModuleUrl, templateName) {
110
+ if (!templateName) {
111
+ return {
112
+ ...template,
113
+ lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl),
114
+ manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl),
115
+ };
116
+ }
117
+ return {
118
+ ...template,
119
+ lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl, templateName),
120
+ manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl, templateName),
121
+ };
122
+ }
123
+ //# sourceMappingURL=generateTemplate.js.map
@@ -1 +1,3 @@
1
1
  export { LynxCrossThreadContext } from './LynxCrossThreadContext.js';
2
+ export { dispatchMarkTiming, flushMarkTiming } from './markTiming.js';
3
+ export { generateTemplate } from './generateTemplate.js';
@@ -1,2 +1,7 @@
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.
1
4
  export { LynxCrossThreadContext } from './LynxCrossThreadContext.js';
5
+ export { dispatchMarkTiming, flushMarkTiming } from './markTiming.js';
6
+ export { generateTemplate } from './generateTemplate.js';
2
7
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ import type { MarkTiming } from '../types/MarkTiming.js';
2
+ export declare const dispatchMarkTiming: ({ timingKey, pipelineId, timeStamp, markTiming, cacheMarkTimings }: {
3
+ timingKey: string;
4
+ pipelineId?: string;
5
+ timeStamp?: number;
6
+ markTiming: (markTimings: MarkTiming[]) => void;
7
+ cacheMarkTimings: {
8
+ records: MarkTiming[];
9
+ timeout: NodeJS.Timeout | null;
10
+ };
11
+ }) => void;
12
+ export declare const flushMarkTiming: (markTiming: (markTimings: MarkTiming[]) => void, cacheMarkTimings: {
13
+ records: MarkTiming[];
14
+ timeout: NodeJS.Timeout | null;
15
+ }) => void;
@@ -0,0 +1,26 @@
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
+ export const dispatchMarkTiming = ({ timingKey, pipelineId, timeStamp, markTiming, cacheMarkTimings }) => {
5
+ cacheMarkTimings.records.push({
6
+ timingKey,
7
+ pipelineId,
8
+ timeStamp: timeStamp ?? performance.now() + performance.timeOrigin,
9
+ });
10
+ if (!cacheMarkTimings.timeout) {
11
+ cacheMarkTimings.timeout = setTimeout(() => {
12
+ markTiming(cacheMarkTimings.records);
13
+ cacheMarkTimings.records = [];
14
+ cacheMarkTimings.timeout = null;
15
+ }, 500);
16
+ }
17
+ };
18
+ export const flushMarkTiming = (markTiming, cacheMarkTimings) => {
19
+ markTiming(cacheMarkTimings.records);
20
+ cacheMarkTimings.records = [];
21
+ if (cacheMarkTimings.timeout) {
22
+ clearTimeout(cacheMarkTimings.timeout);
23
+ cacheMarkTimings.timeout = null;
24
+ }
25
+ };
26
+ //# sourceMappingURL=markTiming.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-constants",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -23,7 +23,7 @@
23
23
  "**/*.css"
24
24
  ],
25
25
  "dependencies": {
26
- "@lynx-js/web-worker-rpc": "0.14.0"
26
+ "@lynx-js/web-worker-rpc": "0.14.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@lynx-js/offscreen-document": "0.1.2"