@lynx-js/web-mainthread-apis-canary 0.16.0-canary-20250828-ff4ede60 → 0.16.0-canary-20250828-1a32dd88
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,6 +1,6 @@
|
|
|
1
1
|
# @lynx-js/web-mainthread-apis
|
|
2
2
|
|
|
3
|
-
## 0.16.0-canary-
|
|
3
|
+
## 0.16.0-canary-20250828095936-1a32dd886fe736c95639f67028cf7685377d9769
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
### Patch Changes
|
|
18
18
|
|
|
19
|
+
- refactor: add `:not([l-e-name])` at the end of selector for lazy component ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622))
|
|
20
|
+
|
|
19
21
|
- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
|
|
20
22
|
|
|
21
|
-
- Updated dependencies [[`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
22
|
-
- @lynx-js/web-constants@0.16.0-canary-
|
|
23
|
-
- @lynx-js/web-style-transformer@0.16.0-canary-
|
|
23
|
+
- Updated dependencies [[`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
24
|
+
- @lynx-js/web-constants@0.16.0-canary-20250828095936-1a32dd886fe736c95639f67028cf7685377d9769
|
|
25
|
+
- @lynx-js/web-style-transformer@0.16.0-canary-20250828095936-1a32dd886fe736c95639f67028cf7685377d9769
|
|
24
26
|
|
|
25
27
|
## 0.15.7
|
|
26
28
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LynxTemplate, type PageConfig, type
|
|
1
|
+
import { type LynxTemplate, type PageConfig, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type MainThreadGlobalThis, type WebFiberElementImpl, type I18nResourceTranslationOptions, type SSRHydrateInfo, type SSRDehydrateHooks, type JSRealm } from '@lynx-js/web-constants';
|
|
2
2
|
export interface MainThreadRuntimeCallbacks {
|
|
3
3
|
mainChunkReady: () => void;
|
|
4
4
|
flushElementTree: (options: FlushElementTreeOptions, timingFlags: string[], exposureChangedElements: WebFiberElementImpl[]) => void;
|
|
@@ -8,12 +8,12 @@ export interface MainThreadRuntimeCallbacks {
|
|
|
8
8
|
publishEvent: RpcCallType<typeof publishEventEndpoint>;
|
|
9
9
|
publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
|
|
10
10
|
_I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
|
|
11
|
+
updateCssOGStyle: (uniqueId: number, newClassName: string, cssID: string | null) => void;
|
|
11
12
|
}
|
|
12
13
|
export interface MainThreadRuntimeConfig {
|
|
13
14
|
pageConfig: PageConfig;
|
|
14
15
|
globalProps: unknown;
|
|
15
16
|
callbacks: MainThreadRuntimeCallbacks;
|
|
16
|
-
styleInfo: StyleInfo;
|
|
17
17
|
lynxTemplate: LynxTemplate;
|
|
18
18
|
browserConfig: BrowserConfig;
|
|
19
19
|
tagMap: Record<string, string>;
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, } from '@lynx-js/web-constants';
|
|
5
5
|
import { createMainThreadLynx } from './createMainThreadLynx.js';
|
|
6
|
-
import { flattenStyleInfo, genCssContent, genCssOGInfo, transformToWebCss, } from './utils/processStyleInfo.js';
|
|
7
6
|
import { __AddClass, __AddConfig, __AddDataset, __AddInlineStyle, __AppendElement, __ElementIsEqual, __FirstElement, __GetAttributes, __GetChildren, __GetClasses, __GetComponentID, __GetDataByKey, __GetDataset, __GetElementConfig, __GetElementUniqueID, __GetID, __GetParent, __GetTag, __GetTemplateParts, __InsertElementBefore, __LastElement, __MarkPartElement, __MarkTemplateElement, __NextElement, __RemoveElement, __ReplaceElement, __ReplaceElements, __SetClasses, __SetConfig, __SetCSSId, __SetDataset, __SetID, __SetInlineStyles, __UpdateComponentID, __UpdateComponentInfo, __GetAttributeByName, } from './pureElementPAPIs.js';
|
|
8
7
|
import { createCrossThreadEvent } from './utils/createCrossThreadEvent.js';
|
|
9
|
-
import { decodeCssOG } from './utils/decodeCssOG.js';
|
|
10
8
|
const exposureRelatedAttributes = new Set([
|
|
11
9
|
'exposure-id',
|
|
12
10
|
'exposure-area',
|
|
@@ -21,49 +19,14 @@ const exposureRelatedAttributes = new Set([
|
|
|
21
19
|
]);
|
|
22
20
|
export function createMainThreadGlobalThis(config) {
|
|
23
21
|
let timingFlags = [];
|
|
24
|
-
const { callbacks, tagMap, pageConfig, lynxTemplate, rootDom, globalProps,
|
|
22
|
+
const { callbacks, tagMap, pageConfig, lynxTemplate, rootDom, globalProps, ssrHydrateInfo, ssrHooks, mtsRealm, document, } = config;
|
|
25
23
|
const { elementTemplate, lepusCode } = lynxTemplate;
|
|
26
24
|
const lynxUniqueIdToElement = ssrHydrateInfo?.lynxUniqueIdToElement ?? [];
|
|
27
|
-
const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
|
|
28
25
|
const elementToRuntimeInfoMap = new WeakMap();
|
|
29
26
|
let pageElement = lynxUniqueIdToElement[1]
|
|
30
27
|
?.deref();
|
|
31
28
|
let uniqueIdInc = lynxUniqueIdToElement.length || 1;
|
|
32
29
|
const exposureChangedElements = new Set();
|
|
33
|
-
/**
|
|
34
|
-
* now create the style content
|
|
35
|
-
* 1. flatten the styleInfo
|
|
36
|
-
* 2. transform the styleInfo to web css
|
|
37
|
-
* 3. generate the css in js info
|
|
38
|
-
* 4. create the style element
|
|
39
|
-
* 5. append the style element to the root dom
|
|
40
|
-
*/
|
|
41
|
-
flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
|
|
42
|
-
transformToWebCss(styleInfo);
|
|
43
|
-
const cssOGInfo = pageConfig.enableCSSSelector
|
|
44
|
-
? {}
|
|
45
|
-
: genCssOGInfo(styleInfo);
|
|
46
|
-
let cardStyleElement;
|
|
47
|
-
if (ssrHydrateInfo?.cardStyleElement) {
|
|
48
|
-
cardStyleElement = ssrHydrateInfo.cardStyleElement;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
cardStyleElement = document.createElement('style');
|
|
52
|
-
cardStyleElement.innerHTML = genCssContent(styleInfo, pageConfig);
|
|
53
|
-
rootDom.append(cardStyleElement);
|
|
54
|
-
}
|
|
55
|
-
const cardStyleElementSheet = cardStyleElement.sheet;
|
|
56
|
-
const updateCssOGStyle = (uniqueId, newStyles) => {
|
|
57
|
-
if (lynxUniqueIdToStyleRulesIndex[uniqueId] !== undefined) {
|
|
58
|
-
const rule = cardStyleElementSheet
|
|
59
|
-
.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
|
|
60
|
-
rule.style.cssText = newStyles;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
|
|
64
|
-
lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
30
|
const commonHandler = (event) => {
|
|
68
31
|
if (!event.currentTarget) {
|
|
69
32
|
return;
|
|
@@ -339,13 +302,15 @@ export function createMainThreadGlobalThis(config) {
|
|
|
339
302
|
const newClassName = ((element.getAttribute('class') ?? '') + ' ' + className)
|
|
340
303
|
.trim();
|
|
341
304
|
element.setAttribute('class', newClassName);
|
|
342
|
-
const
|
|
343
|
-
|
|
305
|
+
const cssId = element.getAttribute(cssIdAttribute);
|
|
306
|
+
const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
|
|
307
|
+
callbacks.updateCssOGStyle(uniqueId, newClassName, cssId);
|
|
344
308
|
};
|
|
345
309
|
const __SetClassesForCSSOG = (element, classNames) => {
|
|
346
310
|
__SetClasses(element, classNames);
|
|
347
|
-
const
|
|
348
|
-
|
|
311
|
+
const cssId = element.getAttribute(cssIdAttribute);
|
|
312
|
+
const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
|
|
313
|
+
callbacks.updateCssOGStyle(uniqueId, classNames ?? '', cssId);
|
|
349
314
|
};
|
|
350
315
|
const __LoadLepusChunk = (path) => {
|
|
351
316
|
try {
|
|
@@ -7,6 +7,7 @@ import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerG
|
|
|
7
7
|
import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
|
|
8
8
|
import { createExposureService } from './utils/createExposureService.js';
|
|
9
9
|
import { initWasm } from '@lynx-js/web-style-transformer';
|
|
10
|
+
import { appendStyleElement } from './utils/processStyleInfo.js';
|
|
10
11
|
const initWasmPromise = initWasm();
|
|
11
12
|
export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
|
|
12
13
|
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
@@ -28,6 +29,7 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
|
|
|
28
29
|
sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
|
|
29
30
|
});
|
|
30
31
|
const i18nResources = initialI18nResources(initI18nResources);
|
|
32
|
+
const { updateCssOGStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, undefined, ssrHydrateInfo);
|
|
31
33
|
const mtsGlobalThis = createMainThreadGlobalThis({
|
|
32
34
|
lynxTemplate: template,
|
|
33
35
|
mtsRealm,
|
|
@@ -36,12 +38,12 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mt
|
|
|
36
38
|
browserConfig,
|
|
37
39
|
globalProps,
|
|
38
40
|
pageConfig,
|
|
39
|
-
styleInfo,
|
|
40
41
|
rootDom,
|
|
41
42
|
ssrHydrateInfo,
|
|
42
43
|
ssrHooks,
|
|
43
44
|
document,
|
|
44
45
|
callbacks: {
|
|
46
|
+
updateCssOGStyle,
|
|
45
47
|
mainChunkReady: () => {
|
|
46
48
|
markTimingInternal('data_processor_start');
|
|
47
49
|
let initData = config.initData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StyleInfo, type CssOGInfo, type PageConfig } from '@lynx-js/web-constants';
|
|
1
|
+
import { type StyleInfo, type CssOGInfo, type PageConfig, type SSRHydrateInfo } from '@lynx-js/web-constants';
|
|
2
2
|
export declare function flattenStyleInfo(styleInfo: StyleInfo, enableCSSSelector: boolean): void;
|
|
3
3
|
/**
|
|
4
4
|
* apply the lynx css -> web css transformation
|
|
@@ -7,8 +7,11 @@ export declare function transformToWebCss(styleInfo: StyleInfo): void;
|
|
|
7
7
|
/**
|
|
8
8
|
* generate those styles applied by <style>...</style>
|
|
9
9
|
*/
|
|
10
|
-
export declare function genCssContent(styleInfo: StyleInfo, pageConfig: PageConfig): string;
|
|
10
|
+
export declare function genCssContent(styleInfo: StyleInfo, pageConfig: PageConfig, entryName?: string): string;
|
|
11
11
|
/**
|
|
12
12
|
* generate the css-in-js data
|
|
13
13
|
*/
|
|
14
14
|
export declare function genCssOGInfo(styleInfo: StyleInfo): CssOGInfo;
|
|
15
|
+
export declare function appendStyleElement(styleInfo: StyleInfo, pageConfig: PageConfig, rootDom: Node, document: Document, entryName?: string, ssrHydrateInfo?: SSRHydrateInfo): {
|
|
16
|
+
updateCssOGStyle: (uniqueId: number, newClassName: string, cssID: string | null) => void;
|
|
17
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { cssIdAttribute, lynxTagAttribute, } from '@lynx-js/web-constants';
|
|
4
|
+
import { cssIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, lynxEntryNameAttribute, } from '@lynx-js/web-constants';
|
|
5
5
|
import { transformParsedStyles } from './tokenizer.js';
|
|
6
|
+
import { decodeCssOG } from './decodeCssOG.js';
|
|
6
7
|
export function flattenStyleInfo(styleInfo, enableCSSSelector) {
|
|
7
8
|
function flattenOneStyleInfo(cssId) {
|
|
8
9
|
const oneInfo = styleInfo[cssId];
|
|
@@ -51,20 +52,26 @@ export function transformToWebCss(styleInfo) {
|
|
|
51
52
|
/**
|
|
52
53
|
* generate those styles applied by <style>...</style>
|
|
53
54
|
*/
|
|
54
|
-
export function genCssContent(styleInfo, pageConfig) {
|
|
55
|
+
export function genCssContent(styleInfo, pageConfig, entryName) {
|
|
55
56
|
function getExtraSelectors(cssId) {
|
|
56
|
-
let suffix
|
|
57
|
+
let suffix;
|
|
57
58
|
if (!pageConfig.enableRemoveCSSScope) {
|
|
58
59
|
if (cssId !== undefined) {
|
|
59
|
-
suffix
|
|
60
|
+
suffix = `[${cssIdAttribute}="${cssId}"]`;
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
63
|
// To make sure the Specificity correct
|
|
63
|
-
suffix
|
|
64
|
+
suffix = `[${lynxTagAttribute}]`;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
|
-
suffix
|
|
68
|
+
suffix = `[${lynxTagAttribute}]`;
|
|
69
|
+
}
|
|
70
|
+
if (entryName) {
|
|
71
|
+
suffix = `${suffix}[${lynxEntryNameAttribute}="${entryName}"]`;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
suffix = `${suffix}:not([${lynxEntryNameAttribute}])`;
|
|
68
75
|
}
|
|
69
76
|
return suffix;
|
|
70
77
|
}
|
|
@@ -116,4 +123,43 @@ export function genCssOGInfo(styleInfo) {
|
|
|
116
123
|
return [cssId, oneCssOGInfo];
|
|
117
124
|
}));
|
|
118
125
|
}
|
|
126
|
+
export function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName, ssrHydrateInfo) {
|
|
127
|
+
const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
|
|
128
|
+
/**
|
|
129
|
+
* now create the style content
|
|
130
|
+
* 1. flatten the styleInfo
|
|
131
|
+
* 2. transform the styleInfo to web css
|
|
132
|
+
* 3. generate the css in js info
|
|
133
|
+
* 4. create the style element
|
|
134
|
+
* 5. append the style element to the root dom
|
|
135
|
+
*/
|
|
136
|
+
flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
|
|
137
|
+
transformToWebCss(styleInfo);
|
|
138
|
+
const cssOGInfo = pageConfig.enableCSSSelector
|
|
139
|
+
? {}
|
|
140
|
+
: genCssOGInfo(styleInfo);
|
|
141
|
+
let cardStyleElement;
|
|
142
|
+
if (ssrHydrateInfo?.cardStyleElement) {
|
|
143
|
+
cardStyleElement = ssrHydrateInfo.cardStyleElement;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
cardStyleElement = document.createElement('style');
|
|
147
|
+
cardStyleElement.textContent = genCssContent(styleInfo, pageConfig, entryName);
|
|
148
|
+
rootDom.appendChild(cardStyleElement);
|
|
149
|
+
}
|
|
150
|
+
const cardStyleElementSheet = cardStyleElement.sheet;
|
|
151
|
+
const updateCssOGStyle = (uniqueId, newClassName, cssID) => {
|
|
152
|
+
const newStyles = decodeCssOG(newClassName, cssOGInfo, cssID);
|
|
153
|
+
if (lynxUniqueIdToStyleRulesIndex[uniqueId] !== undefined) {
|
|
154
|
+
const rule = cardStyleElementSheet
|
|
155
|
+
.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
|
|
156
|
+
rule.style.cssText = newStyles;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
|
|
160
|
+
lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
return { updateCssOGStyle };
|
|
164
|
+
}
|
|
119
165
|
//# sourceMappingURL=processStyleInfo.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-mainthread-apis-canary",
|
|
3
|
-
"version": "0.16.0-canary-20250828-
|
|
3
|
+
"version": "0.16.0-canary-20250828-1a32dd88",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"**/*.css"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.0-canary-20250828-
|
|
28
|
-
"@lynx-js/web-style-transformer": "npm:@lynx-js/web-style-transformer-canary@0.16.0-canary-20250828-
|
|
27
|
+
"@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.0-canary-20250828-1a32dd88",
|
|
28
|
+
"@lynx-js/web-style-transformer": "npm:@lynx-js/web-style-transformer-canary@0.16.0-canary-20250828-1a32dd88",
|
|
29
29
|
"hyphenate-style-name": "^1.1.0"
|
|
30
30
|
}
|
|
31
31
|
}
|