@lynx-js/web-mainthread-apis 0.18.4 → 0.19.1

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.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: fix reload lynx-view when `enableCSSSelector` false may cause css style lost ([#1982](https://github.com/lynx-family/lynx-stack/pull/1982))
8
+
9
+ - Updated dependencies []:
10
+ - @lynx-js/web-constants@0.19.1
11
+
12
+ ## 0.19.0
13
+
14
+ ### Patch Changes
15
+
16
+ - fix: capture and bind event listener should be trigger correctly ([#1972](https://github.com/lynx-family/lynx-stack/pull/1972))
17
+
18
+ - fix: the l-p-comp-uid of page should be '1' ([#1970](https://github.com/lynx-family/lynx-stack/pull/1970))
19
+
20
+ - Updated dependencies []:
21
+ - @lynx-js/web-constants@0.19.0
22
+
3
23
  ## 0.18.4
4
24
 
5
25
  ### Patch Changes
Binary file
Binary file
Binary file
@@ -27,12 +27,22 @@ export function createMainThreadGlobalThis(config) {
27
27
  ?.deref();
28
28
  let uniqueIdInc = lynxUniqueIdToElement.length || 1;
29
29
  const exposureChangedElements = new Set();
30
- const commonHandler = (event) => {
30
+ const commonHandler = (event, capture) => {
31
31
  if (!event.currentTarget) {
32
32
  return;
33
33
  }
34
+ // The `capture false` event should not be triggered during the capture-phase
35
+ // The `capture true` event should not be triggered during the bubbling phase
36
+ if ((event.eventPhase === Event.CAPTURING_PHASE && capture === false)
37
+ || (event.eventPhase === Event.BUBBLING_PHASE && capture === true)) {
38
+ return;
39
+ }
34
40
  const currentTarget = event.currentTarget;
35
- const isCapture = event.eventPhase === Event.CAPTURING_PHASE;
41
+ // When the event is triggered by the target element, `event.eventPhase` is always `target`, and the listener type is determined by the passed-in `capture`.
42
+ // When the event is triggered by a non-target element, the listener type is determined by `event.eventPhase` (1, 3).
43
+ const isCapture = event.eventPhase === Event.AT_TARGET
44
+ ? capture
45
+ : event.eventPhase === event.CAPTURING_PHASE;
36
46
  const lynxEventName = W3cEventNameToLynx[event.type] ?? event.type;
37
47
  const runtimeInfo = elementToRuntimeInfoMap.get(currentTarget);
38
48
  if (runtimeInfo) {
@@ -70,11 +80,23 @@ export function createMainThreadGlobalThis(config) {
70
80
  }
71
81
  return false;
72
82
  };
73
- const commonCatchHandler = (event) => {
74
- const handlerTriggered = commonHandler(event);
83
+ const captureHandler = (e) => {
84
+ commonHandler(e, true);
85
+ };
86
+ const defaultHandler = (e) => {
87
+ commonHandler(e, false);
88
+ };
89
+ const commonCatchHandler = (event, isCapture) => {
90
+ const handlerTriggered = commonHandler(event, isCapture);
75
91
  if (handlerTriggered)
76
92
  event.stopPropagation();
77
93
  };
94
+ const catchCaptureHandler = (e) => {
95
+ commonCatchHandler(e, true);
96
+ };
97
+ const defaultCatchHandler = (e) => {
98
+ commonCatchHandler(e, false);
99
+ };
78
100
  const __AddEvent = (element, eventType, eventName, newEventHandler) => {
79
101
  eventName = eventName.toLowerCase();
80
102
  const isCatch = eventType === 'catchEvent' || eventType === 'capture-catch';
@@ -88,8 +110,8 @@ export function createMainThreadGlobalThis(config) {
88
110
  ? runtimeInfo.eventHandlerMap[eventName]?.capture
89
111
  : runtimeInfo.eventHandlerMap[eventName]?.bind;
90
112
  const currentRegisteredHandler = isCatch
91
- ? commonCatchHandler
92
- : commonHandler;
113
+ ? (isCapture ? catchCaptureHandler : defaultCatchHandler)
114
+ : (isCapture ? captureHandler : defaultHandler);
93
115
  if (currentHandler) {
94
116
  if (!newEventHandler) {
95
117
  /**
@@ -210,7 +232,7 @@ export function createMainThreadGlobalThis(config) {
210
232
  const page = __CreateElement('page', 0);
211
233
  page.setAttribute('part', 'page');
212
234
  page.setAttribute(cssIdAttribute, cssID + '');
213
- page.setAttribute(parentComponentUniqueIdAttribute, '0');
235
+ page.setAttribute(parentComponentUniqueIdAttribute, '1');
214
236
  page.setAttribute(componentIdAttribute, componentID);
215
237
  __MarkTemplateElement(page);
216
238
  if (pageConfig.defaultDisplayLinear === false) {
@@ -1,5 +1,5 @@
1
1
  import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources, type Cloneable, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm, type TemplateLoader, type UpdateDataOptions } from '@lynx-js/web-constants';
2
- export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealmPromise: JSRealm | Promise<JSRealm>, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, loadTemplate: TemplateLoader, ssrHooks?: SSRDehydrateHooks): {
2
+ export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, document: Document, mtsRealmPromise: JSRealm | Promise<JSRealm>, commitDocument: (exposureChangedElements: HTMLElement[]) => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, flushMarkTimingInternal: () => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources, loadTemplate: TemplateLoader, ssrHooks?: SSRDehydrateHooks, allOnUI?: boolean): {
3
3
  startMainThread: (config: StartMainThreadContextConfig, ssrHydrateInfo?: SSRHydrateInfo) => Promise<void>;
4
4
  handleUpdatedData: (newData: Cloneable, options: UpdateDataOptions | undefined) => Promise<void>;
5
5
  };
@@ -8,7 +8,7 @@ import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
8
8
  import { createExposureService } from './utils/createExposureService.js';
9
9
  import { appendStyleElement } from './utils/processStyleInfo.js';
10
10
  import { createQueryComponent } from './crossThreadHandlers/createQueryComponent.js';
11
- export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealmPromise, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks) {
11
+ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealmPromise, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks, allOnUI) {
12
12
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
13
13
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
14
14
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -29,7 +29,7 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
29
29
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
30
30
  });
31
31
  const i18nResources = initialI18nResources(initI18nResources);
32
- const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo);
32
+ const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo, allOnUI);
33
33
  const mtsGlobalThisRef = {
34
34
  mtsGlobalThis: undefined,
35
35
  };
@@ -5,7 +5,7 @@ import { type StyleInfo, type CssOGInfo, type PageConfig, type SSRHydrateInfo, t
5
5
  * 2. for each css, find all the importing css files (directly and indirectly)
6
6
  * 3. return the flattened style info, do not modify the content and rules
7
7
  */
8
- export declare function flattenStyleInfo(styleInfo: StyleInfo): FlattenedStyleInfo;
8
+ export declare function flattenStyleInfo(styleInfo: StyleInfo, cloneDeep?: boolean): FlattenedStyleInfo;
9
9
  /**
10
10
  * apply the lynx css -> web css transformation
11
11
  */
@@ -18,7 +18,7 @@ export declare function genCssContent(styleInfo: FlattenedStyleInfo, pageConfig:
18
18
  * generate the css-in-js data
19
19
  */
20
20
  export declare function genCssOGInfo(styleInfo: FlattenedStyleInfo): CssOGInfo;
21
- export declare function appendStyleElement(styleInfo: StyleInfo, pageConfig: PageConfig, rootDom: Node, document: Document, ssrHydrateInfo?: SSRHydrateInfo): {
21
+ export declare function appendStyleElement(styleInfo: StyleInfo, pageConfig: PageConfig, rootDom: Node, document: Document, ssrHydrateInfo?: SSRHydrateInfo, allOnUI?: boolean): {
22
22
  updateCssOGStyle: (uniqueId: number, newClassName: string, cssID: string | null, entryName: string | null) => void;
23
23
  updateLazyComponentStyle: (styleInfo: StyleInfo, entryName: string) => void;
24
24
  };
@@ -64,7 +64,7 @@ function generateImportByMap(styleInfo, sortedCssIds) {
64
64
  * 2. for each css, find all the importing css files (directly and indirectly)
65
65
  * 3. return the flattened style info, do not modify the content and rules
66
66
  */
67
- export function flattenStyleInfo(styleInfo) {
67
+ export function flattenStyleInfo(styleInfo, cloneDeep) {
68
68
  // Step 1. Topological sorting
69
69
  const sortedCssIds = topologicalSort(styleInfo);
70
70
  // Step 2. generate deps;
@@ -75,8 +75,17 @@ export function flattenStyleInfo(styleInfo) {
75
75
  const oneInfo = styleInfo[cssId];
76
76
  const flattenedInfo = oneInfo
77
77
  ? {
78
- content: oneInfo.content,
79
- rules: oneInfo.rules,
78
+ content: cloneDeep
79
+ ? (oneInfo.content ? [...oneInfo.content] : [])
80
+ : (oneInfo.content ?? []),
81
+ rules: cloneDeep
82
+ ? (oneInfo.rules
83
+ ? oneInfo.rules.map(rule => ({
84
+ sel: rule.sel.map(selectors => selectors.map(arr => arr.slice())),
85
+ decl: rule.decl.map(([k, v]) => [k, v]),
86
+ }))
87
+ : [])
88
+ : (oneInfo.rules ?? []),
80
89
  importBy: Array.from(cssIdToImportBy.get(cssId) ?? [cssId]),
81
90
  }
82
91
  : {
@@ -182,7 +191,7 @@ export function genCssOGInfo(styleInfo) {
182
191
  }
183
192
  return cssOGInfo;
184
193
  }
185
- export function appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo) {
194
+ export function appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo, allOnUI) {
186
195
  const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
187
196
  /**
188
197
  * now create the style content
@@ -192,7 +201,7 @@ export function appendStyleElement(styleInfo, pageConfig, rootDom, document, ssr
192
201
  * 4. create the style element
193
202
  * 5. append the style element to the root dom
194
203
  */
195
- const flattenedStyleInfo = flattenStyleInfo(styleInfo);
204
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo, !!allOnUI);
196
205
  transformToWebCss(flattenedStyleInfo);
197
206
  const cssOGInfo = pageConfig.enableCSSSelector
198
207
  ? {}
@@ -224,7 +233,7 @@ export function appendStyleElement(styleInfo, pageConfig, rootDom, document, ssr
224
233
  }
225
234
  };
226
235
  const updateLazyComponentStyle = (styleInfo, entryName) => {
227
- const flattenedStyleInfo = flattenStyleInfo(styleInfo);
236
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo, !!allOnUI);
228
237
  transformToWebCss(flattenedStyleInfo);
229
238
  if (!pageConfig.enableCSSSelector) {
230
239
  lazyCSSOGInfo[entryName] = genCssOGInfo(flattenedStyleInfo);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.18.4",
3
+ "version": "0.19.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "hyphenate-style-name": "^1.1.0",
30
30
  "wasm-feature-detect": "^1.8.0",
31
- "@lynx-js/web-constants": "0.18.4"
31
+ "@lynx-js/web-constants": "0.19.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "binaryen": "^125.0.0",