@lynx-js/web-mainthread-apis 0.7.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/LICENSE.txt +202 -0
  3. package/Notice.txt +1 -0
  4. package/README.md +3 -0
  5. package/dist/MainThreadLynx.d.ts +11 -0
  6. package/dist/MainThreadLynx.js +36 -0
  7. package/dist/MainThreadRuntime.d.ts +40 -0
  8. package/dist/MainThreadRuntime.js +76 -0
  9. package/dist/elementAPI/ElementThreadElement.d.ts +72 -0
  10. package/dist/elementAPI/ElementThreadElement.js +272 -0
  11. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +25 -0
  12. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +62 -0
  13. package/dist/elementAPI/domTree/domTreeFunctions.d.ts +13 -0
  14. package/dist/elementAPI/domTree/domTreeFunctions.js +52 -0
  15. package/dist/elementAPI/elementCreating/elementCreatingFunctions.d.ts +22 -0
  16. package/dist/elementAPI/elementCreating/elementCreatingFunctions.js +98 -0
  17. package/dist/elementAPI/event/eventFunctions.d.ts +14 -0
  18. package/dist/elementAPI/event/eventFunctions.js +31 -0
  19. package/dist/elementAPI/style/cssPropertyMap.d.ts +13 -0
  20. package/dist/elementAPI/style/cssPropertyMap.js +228 -0
  21. package/dist/elementAPI/style/styleFunctions.d.ts +7 -0
  22. package/dist/elementAPI/style/styleFunctions.js +65 -0
  23. package/dist/elementAPI/style/transformInlineStyle.d.ts +8 -0
  24. package/dist/elementAPI/style/transformInlineStyle.js +42 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +6 -0
  27. package/dist/utils/decodeCssInJs.d.ts +8 -0
  28. package/dist/utils/decodeCssInJs.js +23 -0
  29. package/dist/utils/processStyleInfo.d.ts +14 -0
  30. package/dist/utils/processStyleInfo.js +119 -0
  31. package/package.json +26 -0
@@ -0,0 +1,228 @@
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
+ const cacheForCamelize = {};
5
+ export function camelize(str) {
6
+ if (cacheForCamelize[str]) {
7
+ return cacheForCamelize[str];
8
+ }
9
+ const result = (str + '').replace(/-\D/g, function (match) {
10
+ return match.charAt(1).toUpperCase();
11
+ });
12
+ cacheForCamelize[str] = result;
13
+ return result;
14
+ }
15
+ let index = 1;
16
+ const cssPropertyMap = {};
17
+ const cssPropertyReverseMap = {};
18
+ const V = (name, defaultValue) => {
19
+ const k = index++;
20
+ cssPropertyMap[k] = { name: camelize(name), dashName: name, defaultValue };
21
+ cssPropertyReverseMap[name] = k;
22
+ };
23
+ V('top', 'auto');
24
+ V('left', 'auto');
25
+ V('right', 'auto');
26
+ V('bottom', 'auto');
27
+ V('position', 'relative');
28
+ V('box-sizing', 'auto');
29
+ V('background-color', 'transparent');
30
+ V('border-left-color', 'black');
31
+ V('border-right-color', 'black');
32
+ V('border-top-color', 'black');
33
+ V('border-bottom-color', 'black');
34
+ V('border-radius', '0px');
35
+ V('border-top-left-radius', '0px');
36
+ V('border-bottom-left-radius', '0px');
37
+ V('border-top-right-radius', '0px');
38
+ V('border-bottom-right-radius', '0px');
39
+ V('border-width', '0px');
40
+ V('border-left-width', '0px');
41
+ V('border-right-width', '0px');
42
+ V('border-top-width', '0px');
43
+ V('border-bottom-width', '0px');
44
+ V('color', 'black');
45
+ V('opacity', '1');
46
+ V('display', 'auto');
47
+ V('overflow', 'hidden');
48
+ V('height', 'auto');
49
+ V('width', 'auto');
50
+ V('max-width', 'auto');
51
+ V('min-width', 'auto');
52
+ V('max-height', 'auto');
53
+ V('min-height', 'auto');
54
+ V('padding', '0px');
55
+ V('padding-left', '0px');
56
+ V('padding-right', '0px');
57
+ V('padding-top', '0px');
58
+ V('padding-bottom', '0px');
59
+ V('margin', '0px');
60
+ V('margin-left', '0px');
61
+ V('margin-right', '0px');
62
+ V('margin-top', '0px');
63
+ V('margin-bottom', '0px');
64
+ V('white-space', 'normal');
65
+ V('letter-spacing', '0px');
66
+ V('text-align', 'start');
67
+ V('line-height', '');
68
+ V('text-overflow', 'clip');
69
+ V('font-size', 'medium');
70
+ V('font-weight', 'normal');
71
+ V('flex', '0');
72
+ V('flex-grow', '0');
73
+ V('flex-shrink', '1');
74
+ V('flex-basis', 'auto');
75
+ V('flex-direction', 'row');
76
+ V('flex-wrap', 'nowrap');
77
+ V('align-items', 'stretch');
78
+ V('align-self', 'stretch');
79
+ V('align-content', 'stretch');
80
+ V('justify-content', 'stretch');
81
+ V('background', 'transparent, transparent');
82
+ V('border-color', 'black');
83
+ V('font-family', '');
84
+ V('font-style', 'normal');
85
+ V('transform', '');
86
+ V('animation', '');
87
+ V('animation-name', '');
88
+ V('animation-duration', '');
89
+ V('animation-timing-function', 'linear');
90
+ V('animation-delay', '0s');
91
+ V('animation-iteration-count', '1');
92
+ V('animation-direction', 'normal');
93
+ V('animation-fill-mode', 'none');
94
+ V('animation-play-state', 'running');
95
+ V('line-spacing', '0px');
96
+ V('border-style', 'solid');
97
+ V('order', '0');
98
+ V('box-shadow', '');
99
+ V('transform-origin', '');
100
+ V('linear-orientation', 'vertical');
101
+ V('linear-weight-sum', '0');
102
+ V('linear-weight', '0');
103
+ V('linear-gravity', 'none');
104
+ V('linear-layout-gravity', 'none');
105
+ V('layout-animation-create-duration', '0s');
106
+ V('layout-animation-create-timing-function', 'linear');
107
+ V('layout-animation-create-delay', '0s');
108
+ V('layout-animation-create-property', 'opacity');
109
+ V('layout-animation-delete-duration', '0s');
110
+ V('layout-animation-delete-timing-function', 'linear');
111
+ V('layout-animation-delete-delay', '0s');
112
+ V('layout-animation-delete-property', 'opacity');
113
+ V('layout-animation-update-duration', '0s');
114
+ V('layout-animation-update-timing-function', 'linear');
115
+ V('layout-animation-update-delay', '0s');
116
+ V('adapt-font-size', '0');
117
+ V('aspect-ratio', '');
118
+ V('text-decoration', '');
119
+ V('text-shadow', '');
120
+ V('background-image', '');
121
+ V('background-position', '');
122
+ V('background-origin', 'border-box');
123
+ V('background-repeat', 'no-repeat');
124
+ V('background-size', '');
125
+ V('border', '');
126
+ V('visibility', 'visible');
127
+ V('border-right', '');
128
+ V('border-left', '');
129
+ V('border-top', '');
130
+ V('border-bottom', '');
131
+ V('transition', '');
132
+ V('transition-property', '');
133
+ V('transition-duration', '');
134
+ V('transition-delay', '');
135
+ V('transition-timing-function', '');
136
+ V('content', '');
137
+ V('border-left-style', '');
138
+ V('border-right-style', '');
139
+ V('border-top-style', '');
140
+ V('border-bottom-style', '');
141
+ V('implicit-animation', 'true');
142
+ V('overflow-x', 'hidden');
143
+ V('overflow-y', 'hidden');
144
+ V('word-break', 'normal');
145
+ V('background-clip', 'border-box');
146
+ V('outline', 'medium none black');
147
+ V('outline-color', 'black');
148
+ V('outline-style', 'black');
149
+ V('outline-width', 'medium');
150
+ V('vertical-align', 'default');
151
+ V('caret-color', 'auto');
152
+ V('direction', 'normal');
153
+ V('relative-id', '-1');
154
+ V('relative-align-top', '-1');
155
+ V('relative-align-right', '-1');
156
+ V('relative-align-bottom', '-1');
157
+ V('relative-align-left', '-1');
158
+ V('relative-top-of', '-1');
159
+ V('relative-right-of', '-1');
160
+ V('relative-bottom-of', '-1');
161
+ V('relative-left-of', '-1');
162
+ V('relative-layout-once', 'true');
163
+ V('relative-center', 'none');
164
+ V('enter-transition-name', '');
165
+ V('exit-transition-name', '');
166
+ V('pause-transition-name', '');
167
+ V('resume-transition-name', '');
168
+ V('flex-flow', 'row nowrap');
169
+ V('z-index', '0');
170
+ V('text-decoration-color', 'black');
171
+ V('linear-cross-gravity', 'none');
172
+ V('margin-inline-start', '0px');
173
+ V('margin-inline-end', '0px');
174
+ V('padding-inline-start', '0px');
175
+ V('padding-inline-end', '0px');
176
+ V('border-inline-start-color', 'black');
177
+ V('border-inline-end-color', 'black');
178
+ V('border-inline-start-width', '0px');
179
+ V('border-inline-end-width', '0px');
180
+ V('border-inline-start-style', '');
181
+ V('border-inline-end-style', '');
182
+ V('border-start-start-radius', '0px');
183
+ V('border-end-start-radius', '0px');
184
+ V('border-start-end-radius', '0px');
185
+ V('border-end-end-radius', '0px');
186
+ V('relative-align-inline-start', '-1');
187
+ V('relative-align-inline-end', '-1');
188
+ V('relative-inline-start-of', '-1');
189
+ V('relative-inline-end-of', '-1');
190
+ V('inset-inline-start', '0px');
191
+ V('inset-inline-end', '0px');
192
+ V('mask-image', '');
193
+ V('grid-template-columns', '');
194
+ V('grid-template-rows', '');
195
+ V('grid-auto-columns', '');
196
+ V('grid-auto-rows', '');
197
+ V('grid-column-span', '');
198
+ V('grid-row-span', '');
199
+ V('grid-column-start', '');
200
+ V('grid-column-end', '');
201
+ V('grid-row-start', '');
202
+ V('grid-row-end', '');
203
+ V('grid-column-gap', '');
204
+ V('grid-row-gap', '');
205
+ V('justify-items', 'stretch');
206
+ V('justify-self', 'auto');
207
+ V('grid-auto-flow', 'row');
208
+ V('filter', '');
209
+ V('list-main-axis-gap', '0px');
210
+ V('list-cross-axis-gap', '0px');
211
+ V('linear-direction', 'column');
212
+ V('perspective', 'none');
213
+ V('cursor', 'default');
214
+ V('text-indent', '0px');
215
+ V('clip-path', '');
216
+ V('text-stroke', '0px transparent');
217
+ V('text-stroke-width', '0px');
218
+ V('text-stroke-color', 'transparent');
219
+ V('-x-auto-font-size', 'false');
220
+ V('-x-auto-font-size-preset-sizes', '');
221
+ export function queryCSSProperty(index) {
222
+ return cssPropertyMap[index];
223
+ }
224
+ export function queryCSSPropertyNumber(name) {
225
+ return cssPropertyReverseMap[name];
226
+ }
227
+ export { cssPropertyMap };
228
+ //# sourceMappingURL=cssPropertyMap.js.map
@@ -0,0 +1,7 @@
1
+ import type { ElementThreadElement } from '../ElementThreadElement.js';
2
+ export declare function __AddClass(element: ElementThreadElement, className: string): void;
3
+ export declare function __SetClasses(element: ElementThreadElement, classNames: string | null): void;
4
+ export declare function __GetClasses(element: ElementThreadElement): string[];
5
+ export declare function __AddInlineStyle(element: ElementThreadElement, key: number | string, value: string | undefined): void;
6
+ export declare function __SetInlineStyles(element: ElementThreadElement, value: string | Record<string, string> | undefined): void;
7
+ export declare function __SetCSSId(elements: (ElementThreadElement)[], cssId: string | number): void;
@@ -0,0 +1,65 @@
1
+ import { cssIdAttribute } from '@lynx-js/web-constants';
2
+ import hyphenateStyleName from 'hyphenate-style-name';
3
+ import { queryCSSProperty } from './cssPropertyMap.js';
4
+ import { decodeCssInJs } from '../../utils/decodeCssInJs.js';
5
+ import { transformInlineStyleString, transfromParsedStyles, } from './transformInlineStyle.js';
6
+ function updateInlineStyleForCssInJs(element, newClassNames) {
7
+ const classStyleStr = decodeCssInJs(newClassNames, element.styleInfo, element.attributes[cssIdAttribute]);
8
+ element.updateCssInJsGeneratedStyle(classStyleStr);
9
+ }
10
+ export function __AddClass(element, className) {
11
+ const newClassName = ((element.attributes.class ?? '') + ' ' + className)
12
+ .trim();
13
+ element.setAttribute('class', newClassName);
14
+ if (!element.pageConfig.enableCSSSelector) {
15
+ updateInlineStyleForCssInJs(element, newClassName);
16
+ }
17
+ }
18
+ export function __SetClasses(element, classNames) {
19
+ element.setAttribute('class', classNames);
20
+ if (!element.pageConfig.enableCSSSelector) {
21
+ updateInlineStyleForCssInJs(element, classNames ?? '');
22
+ }
23
+ }
24
+ export function __GetClasses(element) {
25
+ return (element.attributes.class ?? '').split(' ').filter(e => e);
26
+ }
27
+ export function __AddInlineStyle(element, key, value) {
28
+ const lynxStyleInfo = queryCSSProperty(Number(key));
29
+ if (!value) {
30
+ element.setStyleProperty(lynxStyleInfo.dashName, null);
31
+ return;
32
+ }
33
+ const { transformedStyle } = transfromParsedStyles([[
34
+ lynxStyleInfo.dashName,
35
+ value,
36
+ ]]);
37
+ for (const [property, value] of transformedStyle) {
38
+ element.setStyleProperty(property, value);
39
+ }
40
+ }
41
+ export function __SetInlineStyles(element, value) {
42
+ if (!value)
43
+ return;
44
+ const { transformedStyle } = typeof value === 'string'
45
+ ? transformInlineStyleString(value)
46
+ : transfromParsedStyles(Object.entries(value).map(([k, value]) => [
47
+ hyphenateStyleName(k),
48
+ value,
49
+ ]));
50
+ const transformedStyleStr = transformedStyle.map(([property, value]) => `${property}:${value};`).join('');
51
+ element.setAttribute('style', transformedStyleStr);
52
+ }
53
+ export function __SetCSSId(elements, cssId) {
54
+ cssId = cssId.toString();
55
+ for (const element of elements) {
56
+ if (element.getAttribute(cssIdAttribute) === cssId)
57
+ continue; // skip operation
58
+ element.setAttribute(cssIdAttribute, cssId);
59
+ if (!element.pageConfig.enableCSSSelector) {
60
+ const cls = element.getAttribute('class');
61
+ cls && __SetClasses(element, cls);
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=styleFunctions.js.map
@@ -0,0 +1,8 @@
1
+ export declare function transformInlineStyleString(str: string): {
2
+ childStyle: [string, string][];
3
+ transformedStyle: [string, string][];
4
+ };
5
+ export declare function transfromParsedStyles(hyphenatedStyleObject: [property: string, value: string][]): {
6
+ childStyle: [string, string][];
7
+ transformedStyle: [string, string][];
8
+ };
@@ -0,0 +1,42 @@
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
+ // @ts-expect-error
5
+ import * as tokenizer from 'css-tree/tokenizer';
6
+ import { transformLynxStyles } from '@lynx-js/web-style-transformer';
7
+ function parseStyleStringToObject(str) {
8
+ const hypenNameStyles = [];
9
+ let beforeColonToken = true;
10
+ let propertyStart = 0;
11
+ let propertyEnd = 0;
12
+ let valueStart = 0;
13
+ let valueEnd = 0;
14
+ tokenizer.tokenize(str + ';', (type, start, end) => {
15
+ if (type === tokenizer.Semicolon || tokenizer.EOF) {
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,
23
+ ]);
24
+ }
25
+ beforeColonToken = true;
26
+ propertyStart = end;
27
+ }
28
+ else if (type === tokenizer.Colon && beforeColonToken) {
29
+ beforeColonToken = false;
30
+ valueStart = end;
31
+ propertyEnd = start;
32
+ }
33
+ });
34
+ return hypenNameStyles;
35
+ }
36
+ export function transformInlineStyleString(str) {
37
+ return transfromParsedStyles(parseStyleStringToObject(str));
38
+ }
39
+ export function transfromParsedStyles(hyphenatedStyleObject) {
40
+ return transformLynxStyles(hyphenatedStyleObject);
41
+ }
42
+ //# sourceMappingURL=transformInlineStyle.js.map
@@ -0,0 +1,2 @@
1
+ export * from './MainThreadRuntime.js';
2
+ export { ElementThreadElement } from './elementAPI/ElementThreadElement.js';
package/dist/index.js ADDED
@@ -0,0 +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.
4
+ export * from './MainThreadRuntime.js';
5
+ export { ElementThreadElement } from './elementAPI/ElementThreadElement.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { CssInJsInfo } from '@lynx-js/web-constants';
2
+ /**
3
+ * @param classes
4
+ * @param styleInfo it should be flattened, which means there is no imports field in the styleInfo
5
+ * @param cssId
6
+ * @returns
7
+ */
8
+ export declare function decodeCssInJs(classes: string, styleInfo: CssInJsInfo, cssId: string | null): string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @param classes
3
+ * @param styleInfo it should be flattened, which means there is no imports field in the styleInfo
4
+ * @param cssId
5
+ * @returns
6
+ */
7
+ export function decodeCssInJs(classes, styleInfo, cssId) {
8
+ const classList = classes.split(' ').filter(e => e);
9
+ let declarations = [];
10
+ const currentStyleInfo = styleInfo[cssId ?? '0'];
11
+ if (currentStyleInfo) {
12
+ for (const oneClassName of classList) {
13
+ const oneRule = currentStyleInfo[oneClassName];
14
+ if (oneRule)
15
+ declarations.push(...oneRule);
16
+ }
17
+ }
18
+ else {
19
+ throw new Error(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
20
+ }
21
+ return declarations.map(([property, value]) => `${property}:${value};`).join('');
22
+ }
23
+ //# sourceMappingURL=decodeCssInJs.js.map
@@ -0,0 +1,14 @@
1
+ import { type StyleInfo, type CssInJsInfo, type PageConfig, type BrowserConfig } from '@lynx-js/web-constants';
2
+ export declare function flattenStyleInfo(styleInfo: StyleInfo): void;
3
+ /**
4
+ * apply the lynx css -> web css transformation
5
+ */
6
+ export declare function transformToWebCss(styleInfo: StyleInfo): void;
7
+ /**
8
+ * generate those styles applied by <style>...</style>
9
+ */
10
+ export declare function genCssContent(styleInfo: StyleInfo, entryId: string, pageConfig: PageConfig, browserConfig: BrowserConfig): string;
11
+ /**
12
+ * generate the css-in-js data
13
+ */
14
+ export declare function genCssInJsInfo(styleInfo: StyleInfo): CssInJsInfo;
@@ -0,0 +1,119 @@
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 { cssIdAttribute, lynxTagAttribute, cardIdAttribute, } from '@lynx-js/web-constants';
5
+ import { transformLynxStyles } from '@lynx-js/web-style-transformer';
6
+ export function flattenStyleInfo(styleInfo) {
7
+ function flattenOneStyleInfo(cssId) {
8
+ const oneInfo = styleInfo[cssId];
9
+ const imports = oneInfo?.imports;
10
+ if (oneInfo && imports?.length) {
11
+ for (const im of imports) {
12
+ const flatInfo = flattenOneStyleInfo(im);
13
+ if (flatInfo) {
14
+ oneInfo.content.push(...flatInfo.content);
15
+ oneInfo.rules.push(...flatInfo.rules);
16
+ }
17
+ }
18
+ oneInfo.imports = undefined;
19
+ }
20
+ return oneInfo;
21
+ }
22
+ Object.keys(styleInfo).map((cssId) => {
23
+ flattenOneStyleInfo(cssId);
24
+ });
25
+ }
26
+ /**
27
+ * apply the lynx css -> web css transformation
28
+ */
29
+ export function transformToWebCss(styleInfo) {
30
+ for (const cssInfos of Object.values(styleInfo)) {
31
+ for (const rule of cssInfos.rules) {
32
+ const { sel: selectors, decl: declarations } = rule;
33
+ const { transformedStyle, childStyle } = transformLynxStyles(declarations);
34
+ rule.decl = transformedStyle;
35
+ if (childStyle.length > 0) {
36
+ cssInfos.rules.push({
37
+ sel: selectors.map(selector => [
38
+ selector[0].concat(['>', '*']),
39
+ selector[1],
40
+ selector[2],
41
+ ]),
42
+ decl: childStyle,
43
+ });
44
+ }
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * generate those styles applied by <style>...</style>
50
+ */
51
+ export function genCssContent(styleInfo, entryId, pageConfig, browserConfig) {
52
+ function getExtraSelectors(cssId) {
53
+ let prepend = '', suffix = '';
54
+ if (!pageConfig.enableRemoveCSSScope) {
55
+ if (cssId !== undefined) {
56
+ suffix += `[${cssIdAttribute}="${cssId}"]`;
57
+ }
58
+ else {
59
+ // To make sure the Specificity correct
60
+ suffix += `[${lynxTagAttribute}]`;
61
+ }
62
+ }
63
+ if (!browserConfig.supportAtScope) {
64
+ prepend = `[${cardIdAttribute}="${entryId}"] `
65
+ + prepend;
66
+ }
67
+ return { prepend, suffix };
68
+ }
69
+ const finalCssContent = [];
70
+ for (const [cssId, cssInfos] of Object.entries(styleInfo)) {
71
+ const { prepend, suffix } = getExtraSelectors(cssId);
72
+ const declarationContent = cssInfos.rules.map((rule) => {
73
+ const { sel: selectors, decl: declarations } = rule;
74
+ const selectorString = selectors.map(([plainSelectors, pseudoClassSelectors, pseudoElementSelectors]) => {
75
+ return [
76
+ prepend,
77
+ plainSelectors.join(''),
78
+ suffix,
79
+ pseudoClassSelectors.join(''),
80
+ pseudoElementSelectors.join(''),
81
+ ].join('');
82
+ }).join(',');
83
+ const declarationString = declarations.map(([k, v]) => `${k}:${v};`).join('');
84
+ return `${selectorString}{${declarationString}}`;
85
+ }).join('');
86
+ finalCssContent.push(...cssInfos.content, declarationContent);
87
+ }
88
+ return finalCssContent.join('\n');
89
+ }
90
+ /**
91
+ * generate the css-in-js data
92
+ */
93
+ export function genCssInJsInfo(styleInfo) {
94
+ return Object.fromEntries(Object.entries(styleInfo).map(([cssId, cssInfos]) => {
95
+ const oneCssInJsInfo = {};
96
+ cssInfos.rules = cssInfos.rules.filter(oneCssInfo => {
97
+ oneCssInfo.sel = oneCssInfo.sel.filter(selectorList => {
98
+ const [classSelectors, pseudoClassSelectors, pseudoElementSelectors] = selectorList;
99
+ if (classSelectors.length === 1 && classSelectors[0][0] === '.'
100
+ && pseudoClassSelectors.length === 0
101
+ && pseudoElementSelectors.length === 0) {
102
+ const selectorName = classSelectors[0].substring(1);
103
+ const currentDeclarations = oneCssInJsInfo[selectorName];
104
+ if (currentDeclarations) {
105
+ currentDeclarations.push(...oneCssInfo.decl);
106
+ }
107
+ else {
108
+ oneCssInJsInfo[selectorName] = oneCssInfo.decl;
109
+ }
110
+ return false; // remove this selector from style info
111
+ }
112
+ return true;
113
+ });
114
+ return oneCssInfo.sel.length > 0;
115
+ });
116
+ return [cssId, oneCssInJsInfo];
117
+ }));
118
+ }
119
+ //# sourceMappingURL=processStyleInfo.js.map
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@lynx-js/web-mainthread-apis",
3
+ "version": "0.7.0",
4
+ "private": false,
5
+ "description": "",
6
+ "keywords": [],
7
+ "license": "Apache-2.0",
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "typings": "dist/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "!dist/**/*.js.map",
14
+ "LICENSE.txt",
15
+ "Notice.txt",
16
+ "CHANGELOG.md",
17
+ "README.md",
18
+ "**/*.css"
19
+ ],
20
+ "dependencies": {
21
+ "css-tree": "^3.1.0",
22
+ "hyphenate-style-name": "^1.1.0",
23
+ "@lynx-js/web-constants": "0.7.0",
24
+ "@lynx-js/web-style-transformer": "0.2.1"
25
+ }
26
+ }