@lynx-js/web-mainthread-apis 0.13.3 → 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,14 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.13.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: style loss issue caused by incorrect handling of styleInfo-imports when enableCSSSelector and enableRemoveCSSScope are turned off. ([#931](https://github.com/lynx-family/lynx-stack/pull/931))
8
+
9
+ - Updated dependencies [[`569618d`](https://github.com/lynx-family/lynx-stack/commit/569618d8e2665f5c9e1672f7ee5900ec2a5179a2), [`f9f88d6`](https://github.com/lynx-family/lynx-stack/commit/f9f88d6fb9c42d3370a6622d9d799d671ffcf1a7)]:
10
+ - @lynx-js/web-constants@0.13.4
11
+
3
12
  ## 0.13.3
4
13
 
5
14
  ### Patch Changes
@@ -61,7 +61,7 @@ export class MainThreadRuntime {
61
61
  * 4. create the style element
62
62
  * 5. append the style element to the root dom
63
63
  */
64
- flattenStyleInfo(this.config.styleInfo);
64
+ flattenStyleInfo(this.config.styleInfo, this.config.pageConfig.enableCSSSelector);
65
65
  transformToWebCss(this.config.styleInfo);
66
66
  const cssInJsInfo = this.config.pageConfig.enableCSSSelector
67
67
  ? {}
@@ -5,7 +5,7 @@ import { cssIdAttribute } from '@lynx-js/web-constants';
5
5
  import hyphenateStyleName from 'hyphenate-style-name';
6
6
  import { queryCSSProperty } from './cssPropertyMap.js';
7
7
  import { decodeCssInJs } from '../../utils/decodeCssInJs.js';
8
- import { transformInlineStyleString, transfromParsedStyles, } from './transformInlineStyle.js';
8
+ import { transformInlineStyleString, transformParsedStyles, } from './transformInlineStyle.js';
9
9
  import { elementToRuntimeInfoMap, updateCSSInJsStyle, } from '../../MainThreadRuntime.js';
10
10
  export function createStyleFunctions(runtime, cssInJsInfo) {
11
11
  function __AddClass(element, className) {
@@ -46,7 +46,7 @@ export function createStyleFunctions(runtime, cssInJsInfo) {
46
46
  element.style.removeProperty(dashName);
47
47
  }
48
48
  else {
49
- const { transformedStyle } = transfromParsedStyles([[
49
+ const { transformedStyle } = transformParsedStyles([[
50
50
  dashName,
51
51
  valueStr,
52
52
  ]]);
@@ -60,7 +60,7 @@ export function createStyleFunctions(runtime, cssInJsInfo) {
60
60
  return;
61
61
  const { transformedStyle } = typeof value === 'string'
62
62
  ? transformInlineStyleString(value)
63
- : transfromParsedStyles(Object.entries(value).map(([k, value]) => [
63
+ : transformParsedStyles(Object.entries(value).map(([k, value]) => [
64
64
  hyphenateStyleName(k),
65
65
  value,
66
66
  ]));
@@ -2,7 +2,7 @@ export declare function transformInlineStyleString(str: string): {
2
2
  childStyle: [string, string][];
3
3
  transformedStyle: [string, string][];
4
4
  };
5
- export declare function transfromParsedStyles(hyphenatedStyleObject: [property: string, value: string][]): {
5
+ export declare function transformParsedStyles(hyphenatedStyleObject: [property: string, value: string][]): {
6
6
  childStyle: [string, string][];
7
7
  transformedStyle: [string, string][];
8
8
  };
@@ -5,7 +5,7 @@
5
5
  import * as tokenizer from 'css-tree/tokenizer';
6
6
  import { transformLynxStyles } from '@lynx-js/web-style-transformer';
7
7
  function parseStyleStringToObject(str) {
8
- const hypenNameStyles = [];
8
+ const hyphenNameStyles = [];
9
9
  let beforeColonToken = true;
10
10
  let propertyStart = 0;
11
11
  let propertyEnd = 0;
@@ -14,12 +14,12 @@ function parseStyleStringToObject(str) {
14
14
  tokenizer.tokenize(str + ';', (type, start, end) => {
15
15
  if (type === tokenizer.Semicolon || tokenizer.EOF) {
16
16
  valueEnd = start;
17
- const trimedProperty = str.substring(propertyStart, propertyEnd).trim();
18
- const trimedValue = str.substring(valueStart, valueEnd).trim();
19
- if (!beforeColonToken && trimedValue && trimedProperty) {
20
- hypenNameStyles.push([
21
- trimedProperty,
22
- trimedValue,
17
+ const trimmedProperty = str.substring(propertyStart, propertyEnd).trim();
18
+ const trimmedValue = str.substring(valueStart, valueEnd).trim();
19
+ if (!beforeColonToken && trimmedValue && trimmedProperty) {
20
+ hyphenNameStyles.push([
21
+ trimmedProperty,
22
+ trimmedValue,
23
23
  ]);
24
24
  }
25
25
  beforeColonToken = true;
@@ -31,12 +31,12 @@ function parseStyleStringToObject(str) {
31
31
  propertyEnd = start;
32
32
  }
33
33
  });
34
- return hypenNameStyles;
34
+ return hyphenNameStyles;
35
35
  }
36
36
  export function transformInlineStyleString(str) {
37
- return transfromParsedStyles(parseStyleStringToObject(str));
37
+ return transformParsedStyles(parseStyleStringToObject(str));
38
38
  }
39
- export function transfromParsedStyles(hyphenatedStyleObject) {
39
+ export function transformParsedStyles(hyphenatedStyleObject) {
40
40
  return transformLynxStyles(hyphenatedStyleObject);
41
41
  }
42
42
  //# sourceMappingURL=transformInlineStyle.js.map
@@ -1,5 +1,5 @@
1
1
  import { type StyleInfo, type CssInJsInfo, type PageConfig } from '@lynx-js/web-constants';
2
- export declare function flattenStyleInfo(styleInfo: StyleInfo): void;
2
+ export declare function flattenStyleInfo(styleInfo: StyleInfo, enableCSSSelector: boolean): void;
3
3
  /**
4
4
  * apply the lynx css -> web css transformation
5
5
  */
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { cssIdAttribute, lynxTagAttribute, } from '@lynx-js/web-constants';
5
5
  import { transformLynxStyles } from '@lynx-js/web-style-transformer';
6
- export function flattenStyleInfo(styleInfo) {
6
+ export function flattenStyleInfo(styleInfo, enableCSSSelector) {
7
7
  function flattenOneStyleInfo(cssId) {
8
8
  const oneInfo = styleInfo[cssId];
9
9
  const imports = oneInfo?.imports;
@@ -12,7 +12,12 @@ export function flattenStyleInfo(styleInfo) {
12
12
  const flatInfo = flattenOneStyleInfo(im);
13
13
  if (flatInfo) {
14
14
  oneInfo.content.push(...flatInfo.content);
15
- oneInfo.rules.push(...flatInfo.rules);
15
+ // oneInfo.rules.push(...flatInfo.rules);
16
+ oneInfo.rules.push(...(enableCSSSelector
17
+ ? flatInfo.rules
18
+ // when enableCSSSelector is false, need to make a shallow copy of rules.sel
19
+ // otherwise updating `oneCssInfo.sel` in `genCssInJsInfo()` will affect other imported cssInfo
20
+ : flatInfo.rules.map(i => ({ ...i }))));
16
21
  }
17
22
  }
18
23
  oneInfo.imports = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "css-tree": "^3.1.0",
27
27
  "hyphenate-style-name": "^1.1.0",
28
- "@lynx-js/web-constants": "0.13.3",
28
+ "@lynx-js/web-constants": "0.13.4",
29
29
  "@lynx-js/web-style-transformer": "0.3.0"
30
30
  }
31
31
  }