@lynx-js/web-constants 0.16.0 → 0.17.0

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-constants
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: avoid duplicate style transformation ([#1748](https://github.com/lynx-family/lynx-stack/pull/1748))
8
+
9
+ After this commit, we use DAG methods to handle the styleInfos
10
+
11
+ - Updated dependencies []:
12
+ - @lynx-js/web-worker-rpc@0.17.0
13
+
14
+ ## 0.16.1
15
+
16
+ ### Patch Changes
17
+
18
+ - feat: supports lazy bundle. (This feature requires `@lynx-js/lynx-core >= 0.1.3`) ([#1235](https://github.com/lynx-family/lynx-stack/pull/1235))
19
+
20
+ - Updated dependencies []:
21
+ - @lynx-js/web-worker-rpc@0.16.1
22
+
3
23
  ## 0.16.0
4
24
 
5
25
  ### Minor Changes
@@ -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, MarkTiming } from './types/index.js';
6
+ import type { BackMainThreadContextConfig, LynxTemplate, 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[];
@@ -57,3 +57,11 @@ export declare const updateGlobalPropsEndpoint: import("@lynx-js/web-worker-rpc/
57
57
  export declare const updateI18nResourcesEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[Cloneable]>;
58
58
  export declare const updateI18nResourceEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[Cloneable]>;
59
59
  export declare const dispatchI18nResourceEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsyncVoid<[Cloneable]>;
60
+ export declare const queryComponentEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[string], {
61
+ code: number;
62
+ detail: {
63
+ schema: string;
64
+ };
65
+ }>;
66
+ export declare const updateBTSTemplateCacheEndpoint: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[string, LynxTemplate], void>;
67
+ export declare const loadTemplateMultiThread: import("@lynx-js/web-worker-rpc/dist/RpcEndpoint.js").RpcEndpointAsync<[string], LynxTemplate>;
package/dist/endpoints.js CHANGED
@@ -38,4 +38,7 @@ export const updateGlobalPropsEndpoint = createRpcEndpoint('updateGlobalProps',
38
38
  export const updateI18nResourcesEndpoint = createRpcEndpoint('updateI18nResources', false, false);
39
39
  export const updateI18nResourceEndpoint = createRpcEndpoint('updateI18nResource', false, false);
40
40
  export const dispatchI18nResourceEndpoint = createRpcEndpoint('dispatchI18nResource', false, false);
41
+ export const queryComponentEndpoint = createRpcEndpoint('queryComponent', false, true);
42
+ export const updateBTSTemplateCacheEndpoint = createRpcEndpoint('updateBTSTemplateCacheEndpoint', false, true);
43
+ export const loadTemplateMultiThread = createRpcEndpoint('loadTemplateMultiThread', false, true);
41
44
  //# sourceMappingURL=endpoints.js.map
@@ -37,6 +37,7 @@ export interface LynxTemplate {
37
37
  };
38
38
  elementTemplate: Record<string, ElementTemplateData[]>;
39
39
  version?: number;
40
+ appType: 'card' | 'lazy';
40
41
  }
41
42
  export interface LynxJSModule {
42
43
  exports?: (lynx_runtime: any) => unknown;
@@ -80,7 +80,7 @@ export type AddClassPAPI = (element: WebFiberElementImpl, className: string) =>
80
80
  export type SetClassesPAPI = (element: WebFiberElementImpl, classNames: string | null) => void;
81
81
  export type AddInlineStylePAPI = (element: WebFiberElementImpl, key: number | string, value: string | number | null | undefined) => void;
82
82
  export type SetInlineStylesPAPI = (element: WebFiberElementImpl, value: string | Record<string, string> | undefined) => void;
83
- export type SetCSSIdPAPI = (elements: WebFiberElementImpl[], cssId: number | null) => void;
83
+ export type SetCSSIdPAPI = (elements: WebFiberElementImpl[], cssId: number | null, entryName: string | undefined) => void;
84
84
  export type GetPageElementPAPI = () => WebFiberElementImpl | undefined;
85
85
  export type MarkTemplateElementPAPI = (element: WebFiberElementImpl) => void;
86
86
  export type MarkPartElementPAPI = (element: WebFiberElementImpl, partId: string) => void;
@@ -90,6 +90,13 @@ interface JSErrorInfo {
90
90
  }
91
91
  export type ElementFromBinaryPAPI = (templateId: string, parentComponentUniId: number) => WebFiberElementImpl[];
92
92
  export type GetAttributeByNamePAPI = (element: WebFiberElementImpl, name: string) => string | null;
93
+ export type QueryComponentPAPI = (source: string, resultCallback?: (result: {
94
+ code: number;
95
+ data?: {
96
+ url: string;
97
+ evalResult: unknown;
98
+ };
99
+ }) => void) => null;
93
100
  export interface MainThreadGlobalThis {
94
101
  __ElementFromBinary: ElementFromBinaryPAPI;
95
102
  __GetTemplateParts?: GetTemplatePartsPAPI;
@@ -161,6 +168,8 @@ export interface MainThreadGlobalThis {
161
168
  __FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
162
169
  _I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
163
170
  _AddEventListener: (...args: unknown[]) => void;
171
+ __QueryComponent: QueryComponentPAPI;
172
+ processEvalResult?: (exports: unknown, schema: string) => unknown;
164
173
  renderPage: ((data: unknown) => void) | undefined;
165
174
  updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
166
175
  runWorklet?: (obj: unknown, event: unknown) => void;
@@ -3,3 +3,4 @@ export interface MarkTiming {
3
3
  pipelineId?: string;
4
4
  timeStamp: number;
5
5
  }
6
+ export type MarkTimingInternal = (timingKey: string, pipelineId?: string, timeStamp?: number) => void;
@@ -82,7 +82,7 @@ export interface NativeApp {
82
82
  clearInterval: typeof clearInterval;
83
83
  requestAnimationFrame: (cb: () => void) => void;
84
84
  cancelAnimationFrame: (id: number) => void;
85
- loadScript: (sourceURL: string) => BundleInitReturnObj;
85
+ loadScript: (sourceURL: string, entryName?: string) => BundleInitReturnObj;
86
86
  loadScriptAsync(sourceURL: string, callback: (message: string | null, exports?: BundleInitReturnObj) => void): void;
87
87
  nativeModuleProxy: Record<string, any>;
88
88
  setNativeProps: (type: IdentifierType, identifier: string, component_id: string, first_only: boolean, native_props: Record<string, unknown>, root_unique_id: number | undefined) => void;
@@ -125,4 +125,13 @@ export interface NativeApp {
125
125
  i18nResource: I18nResource;
126
126
  reportException: (error: Error, _: unknown) => void;
127
127
  __SetSourceMapRelease: (err: Error) => void;
128
+ queryComponent: (source: string, callback: (ret: {
129
+ __hasReady: boolean;
130
+ } | {
131
+ code: number;
132
+ detail?: {
133
+ schema: string;
134
+ };
135
+ }) => void) => void;
136
+ tt: NativeTTObject | null;
128
137
  }
@@ -16,6 +16,12 @@ export interface OneInfo {
16
16
  export interface StyleInfo {
17
17
  [cssId: string]: OneInfo;
18
18
  }
19
+ export interface FlattenedOneInfo {
20
+ content: string[];
21
+ rules: CSSRule[];
22
+ importBy: string[];
23
+ }
24
+ export type FlattenedStyleInfo = FlattenedOneInfo[];
19
25
  /**
20
26
  * CSS Info for Old Generation CSS System
21
27
  */
@@ -0,0 +1,2 @@
1
+ import type { LynxTemplate } from './LynxModule.js';
2
+ export type TemplateLoader = (url: string) => Promise<LynxTemplate>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TemplateLoader.js.map
@@ -20,3 +20,4 @@ export * from './BackThreadStartConfigs.js';
20
20
  export * from './MarkTiming.js';
21
21
  export * from './SSR.js';
22
22
  export * from './JSRealm.js';
23
+ export * from './TemplateLoader.js';
@@ -20,4 +20,5 @@ export * from './BackThreadStartConfigs.js';
20
20
  export * from './MarkTiming.js';
21
21
  export * from './SSR.js';
22
22
  export * from './JSRealm.js';
23
+ export * from './TemplateLoader.js';
23
24
  //# sourceMappingURL=index.js.map
@@ -42,32 +42,44 @@ const templateUpgraders = [
42
42
  'requestAnimationFrame',
43
43
  'cancelAnimationFrame',
44
44
  ].join(',');
45
+ template.appType = template.appType ?? (template.lepusCode.root.startsWith('(function (globDynamicComponentEntry')
46
+ ? 'lazy'
47
+ : 'card');
45
48
  /**
46
49
  * The template version 1 has no module wrapper for bts code
47
50
  */
48
51
  template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value]) => [
49
52
  key,
50
- `{init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:null}; ${value}\n return module.exports; } }`,
51
- ]));
52
- template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).map(([key, value]) => [
53
- key,
54
- `(()=>{${value}\n})();`,
53
+ `module.exports={init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:{}}; var exports=module.exports; ${value}\n return module.exports; } }`,
55
54
  ]));
56
55
  template.version = 2;
57
56
  return template;
58
57
  },
59
58
  ];
60
- const generateModuleContent = (content) => [
61
- '//# allFunctionsCalledOnLoad\n',
62
- '"use strict";\n',
63
- `(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
59
+ const generateModuleContent = (content, eager, appType) =>
60
+ /**
61
+ * About the `allFunctionsCalledOnLoad` directive:
62
+ * https://v8.dev/blog/preparser#pife
63
+ * https://github.com/WICG/explicit-javascript-compile-hints-file-based?tab=readme-ov-file
64
+ * https://v8.dev/blog/explicit-compile-hints
65
+ * We should ensure the MTS code is parsed eagerly to avoid runtime parse delay.
66
+ * But for BTS code, we should not do this as it would increase the memory usage.
67
+ * JavaScript Engines, like V8, already had optimizations for code starts with "(function"
68
+ * to be parsed eagerly.
69
+ */
70
+ [
71
+ eager ? '//# allFunctionsCalledOnLoad' : '',
72
+ '\n(function() { "use strict"; const ',
73
+ globalDisallowedVars.join('=void 0,'),
74
+ '=void 0;\n',
75
+ appType !== 'card' ? 'module.exports=\n' : '',
64
76
  content,
65
77
  '\n})()',
66
78
  ].join('');
67
- async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
79
+ async function generateJavascriptUrl(obj, createJsModuleUrl, eager, appType, templateName) {
68
80
  const processEntry = async ([name, content]) => [
69
81
  name,
70
- await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`),
82
+ await createJsModuleUrl(generateModuleContent(content, eager, appType), `${templateName}-${name.replaceAll('/', '')}.js`),
71
83
  ];
72
84
  return Promise.all(Object.entries(obj).filter(([_, content]) => typeof content === 'string').map(processEntry)).then(Object.fromEntries);
73
85
  }
@@ -83,8 +95,8 @@ export async function generateTemplate(template, createJsModuleUrl, templateName
83
95
  }
84
96
  return {
85
97
  ...template,
86
- lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
87
- manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName),
98
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, true, template.appType, templateName),
99
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, false, template.appType, templateName),
88
100
  };
89
101
  }
90
102
  //# sourceMappingURL=generateTemplate.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-constants",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
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.16.0"
26
+ "@lynx-js/web-worker-rpc": "0.17.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@lynx-js/offscreen-document": "0.1.4"