@lynx-js/web-mainthread-apis 0.8.0 → 0.9.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 +33 -0
- package/dist/MainThreadRuntime.d.ts +12 -7
- package/dist/MainThreadRuntime.js +10 -2
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +0 -1
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +3 -6
- package/dist/elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.d.ts +5 -0
- package/dist/elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.js +13 -0
- package/dist/elementAPI/createOffscreenDocument.js +1 -1
- package/dist/elementAPI/elementCreating/elementCreatingFunctions.d.ts +1 -0
- package/dist/elementAPI/elementCreating/elementCreatingFunctions.js +6 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @lynx-js/web-mainthread-apis
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @lynx-js/web-constants@0.9.1
|
|
9
|
+
|
|
10
|
+
## 0.9.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- refractor: remove entryId concept ([#217](https://github.com/lynx-family/lynx-stack/pull/217))
|
|
15
|
+
|
|
16
|
+
After the PR #198
|
|
17
|
+
All contents are isolated by a shadowroot.
|
|
18
|
+
Therefore we don't need to add the entryId selector to avoid the lynx-view's style taking effect on the whole page.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- refactor: clean the decodeOperations implementation ([#261](https://github.com/lynx-family/lynx-stack/pull/261))
|
|
23
|
+
|
|
24
|
+
- refactor: remove customelement defined detecting logic ([#247](https://github.com/lynx-family/lynx-stack/pull/247))
|
|
25
|
+
|
|
26
|
+
Before this commit, for those element with tag without `-`, we always try to detect if the `x-${tagName}` is defined.
|
|
27
|
+
|
|
28
|
+
After this commit, we pre-define a map(could be override by the `overrideLynxTagToHTMLTagMap`) to make that transformation for tag name.
|
|
29
|
+
|
|
30
|
+
This change is a path to SSR and the MTS support.
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`5b5e090`](https://github.com/lynx-family/lynx-stack/commit/5b5e090fdf0e896f1c38a49bf3ed9889117c4fb8), [`f447811`](https://github.com/lynx-family/lynx-stack/commit/f4478112a08d3cf2d1483b87d591ea4e3b6cc2ea), [`b844e75`](https://github.com/lynx-family/lynx-stack/commit/b844e751f566d924256365d37aec4c86c520ec00), [`6f16827`](https://github.com/lynx-family/lynx-stack/commit/6f16827d1f4d7364870d354fc805a8868c110f1e), [`d2d55ef`](https://github.com/lynx-family/lynx-stack/commit/d2d55ef9fe438c35921d9db0daa40d5228822ecc)]:
|
|
33
|
+
- @lynx-js/web-constants@0.9.0
|
|
34
|
+
- @lynx-js/web-style-transformer@0.2.3
|
|
35
|
+
|
|
3
36
|
## 0.8.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ElementOperation, type
|
|
1
|
+
import { type ElementOperation, type LynxTemplate, type PageConfig, type ProcessDataCallback, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type onLifecycleEventEndpoint, type reportErrorEndpoint, type flushElementTreeEndpoint } from '@lynx-js/web-constants';
|
|
2
2
|
import { type MainThreadLynx } from './MainThreadLynx.js';
|
|
3
|
+
import type { RpcCallType } from '../../web-worker-rpc/src/TypeUtils.js';
|
|
3
4
|
export interface MainThreadRuntimeCallbacks {
|
|
4
5
|
mainChunkReady: () => void;
|
|
5
|
-
flushElementTree:
|
|
6
|
-
_ReportError:
|
|
7
|
-
__OnLifecycleEvent:
|
|
6
|
+
flushElementTree: RpcCallType<typeof flushElementTreeEndpoint>;
|
|
7
|
+
_ReportError: RpcCallType<typeof reportErrorEndpoint>;
|
|
8
|
+
__OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
|
|
8
9
|
markTiming: (pipelineId: string, timingKey: string) => void;
|
|
9
10
|
}
|
|
10
11
|
export interface MainThreadConfig {
|
|
@@ -14,13 +15,17 @@ export interface MainThreadConfig {
|
|
|
14
15
|
styleInfo: StyleInfo;
|
|
15
16
|
customSections: LynxTemplate['customSections'];
|
|
16
17
|
lepusCode: LynxTemplate['lepusCode'];
|
|
17
|
-
entryId: string;
|
|
18
18
|
browserConfig: BrowserConfig;
|
|
19
|
+
tagMap: Record<string, string>;
|
|
19
20
|
}
|
|
20
21
|
export declare class MainThreadRuntime {
|
|
21
22
|
#private;
|
|
22
23
|
private config;
|
|
23
24
|
private isFp;
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
_timingFlags: string[];
|
|
24
29
|
operationsRef: {
|
|
25
30
|
operations: ElementOperation[];
|
|
26
31
|
};
|
|
@@ -35,8 +40,8 @@ export declare class MainThreadRuntime {
|
|
|
35
40
|
__globalProps: unknown;
|
|
36
41
|
processData?: ProcessDataCallback;
|
|
37
42
|
renderPage: (data: unknown) => void;
|
|
38
|
-
_ReportError:
|
|
39
|
-
__OnLifecycleEvent:
|
|
43
|
+
_ReportError: RpcCallType<typeof reportErrorEndpoint>;
|
|
44
|
+
__OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
|
|
40
45
|
__LoadLepusChunk: (path: string) => boolean;
|
|
41
46
|
__FlushElementTree: (_subTree: unknown, options: FlushElementTreeOptions) => void;
|
|
42
47
|
updatePage?: (data: Cloneable, options?: Record<string, string>) => void;
|
|
@@ -10,9 +10,14 @@ import * as domTreeApis from './elementAPI/domTree/domTreeFunctions.js';
|
|
|
10
10
|
import * as eventApis from './elementAPI/event/eventFunctions.js';
|
|
11
11
|
import * as styleApis from './elementAPI/style/styleFunctions.js';
|
|
12
12
|
import { flattenStyleInfo, genCssContent, genCssInJsInfo, transformToWebCss, } from './utils/processStyleInfo.js';
|
|
13
|
+
import { createAttributeAndPropertyFunctionsWithContext } from './elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.js';
|
|
13
14
|
export class MainThreadRuntime {
|
|
14
15
|
config;
|
|
15
16
|
isFp = true;
|
|
17
|
+
/**
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
_timingFlags = [];
|
|
16
21
|
operationsRef = {
|
|
17
22
|
operations: [],
|
|
18
23
|
};
|
|
@@ -25,10 +30,11 @@ export class MainThreadRuntime {
|
|
|
25
30
|
const cssInJs = this.config.pageConfig.enableCSSSelector
|
|
26
31
|
? {}
|
|
27
32
|
: genCssInJsInfo(this.config.styleInfo);
|
|
28
|
-
Object.assign(this, attributeAndPropertyApis, domTreeApis, eventApis, styleApis, initializeElementCreatingFunction({
|
|
33
|
+
Object.assign(this, createAttributeAndPropertyFunctionsWithContext(this), attributeAndPropertyApis, domTreeApis, eventApis, styleApis, initializeElementCreatingFunction({
|
|
29
34
|
operationsRef: this.operationsRef,
|
|
30
35
|
pageConfig: config.pageConfig,
|
|
31
36
|
styleInfo: cssInJs,
|
|
37
|
+
tagMap: config.tagMap,
|
|
32
38
|
}));
|
|
33
39
|
this.__LoadLepusChunk = (path) => {
|
|
34
40
|
try {
|
|
@@ -79,10 +85,12 @@ export class MainThreadRuntime {
|
|
|
79
85
|
__LoadLepusChunk;
|
|
80
86
|
__FlushElementTree = (_subTree, options) => {
|
|
81
87
|
const operations = this.operationsRef.operations;
|
|
88
|
+
const timingFlags = this._timingFlags;
|
|
82
89
|
this.operationsRef.operations = [];
|
|
90
|
+
this._timingFlags = [];
|
|
83
91
|
this.config.callbacks.flushElementTree(operations, options, this.isFp
|
|
84
92
|
? genCssContent(this.config.styleInfo, this.config.pageConfig)
|
|
85
|
-
: undefined);
|
|
93
|
+
: undefined, timingFlags);
|
|
86
94
|
this.isFp = false;
|
|
87
95
|
};
|
|
88
96
|
updatePage;
|
|
@@ -16,7 +16,6 @@ export declare function __GetElementConfig(element: ElementThreadElement): Recor
|
|
|
16
16
|
export declare function __GetElementUniqueID(element: ElementThreadElement | unknown): number;
|
|
17
17
|
export declare function __GetID(element: ElementThreadElement): string;
|
|
18
18
|
export declare function __GetTag(element: ElementThreadElement): string;
|
|
19
|
-
export declare function __SetAttribute(element: ElementThreadElement, key: string, value: string | null | undefined): void;
|
|
20
19
|
export declare function __SetConfig(element: ElementThreadElement, config: Record<string, any>): void;
|
|
21
20
|
export declare function __SetDataset(element: ElementThreadElement, dataset: Record<string, any>): void;
|
|
22
21
|
export declare function __SetID(element: ElementThreadElement, id: string): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
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 { componentIdAttribute } from '@lynx-js/web-constants';
|
|
4
|
+
import { componentIdAttribute, lynxTagAttribute } from '@lynx-js/web-constants';
|
|
5
5
|
import { RefCountType, } from '../ElementThreadElement.js';
|
|
6
6
|
export function __AddConfig(element, type, value) {
|
|
7
7
|
element.property.componentConfig[type] = value;
|
|
@@ -35,10 +35,7 @@ export function __GetID(element) {
|
|
|
35
35
|
return element.attributes.id ?? '';
|
|
36
36
|
}
|
|
37
37
|
export function __GetTag(element) {
|
|
38
|
-
return element.
|
|
39
|
-
}
|
|
40
|
-
export function __SetAttribute(element, key, value) {
|
|
41
|
-
element.setAttribute(key, value ?? null);
|
|
38
|
+
return element.getAttribute(lynxTagAttribute);
|
|
42
39
|
}
|
|
43
40
|
export function __SetConfig(element, config) {
|
|
44
41
|
element.property.componentConfig = config;
|
|
@@ -50,7 +47,7 @@ export function __SetID(element, id) {
|
|
|
50
47
|
element.setAttribute('id', id);
|
|
51
48
|
}
|
|
52
49
|
export function __UpdateComponentID(element, componentID) {
|
|
53
|
-
|
|
50
|
+
element.setAttribute(componentIdAttribute, componentID);
|
|
54
51
|
}
|
|
55
52
|
export function __GetConfig(element) {
|
|
56
53
|
return element.property.componentConfig;
|
package/dist/elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MainThreadRuntime } from '../../MainThreadRuntime.js';
|
|
2
|
+
import type { ElementThreadElement } from '../ElementThreadElement.js';
|
|
3
|
+
export declare function createAttributeAndPropertyFunctionsWithContext(runtime: MainThreadRuntime): {
|
|
4
|
+
__SetAttribute: (element: ElementThreadElement, key: string, value: string | null | undefined) => void;
|
|
5
|
+
};
|
package/dist/elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __lynx_timing_flag } from '@lynx-js/web-constants';
|
|
2
|
+
export function createAttributeAndPropertyFunctionsWithContext(runtime) {
|
|
3
|
+
function __SetAttribute(element, key, value) {
|
|
4
|
+
element.setAttribute(key, value ?? null);
|
|
5
|
+
if (key === __lynx_timing_flag && value) {
|
|
6
|
+
runtime._timingFlags.push(value);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
__SetAttribute,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=createAttributeAndPropertyFunctionsWithContext.js.map
|
|
@@ -4,7 +4,7 @@ export function createOffscreenDocument(options) {
|
|
|
4
4
|
let incrementalUniqueId = 0;
|
|
5
5
|
function createElement(tagName) {
|
|
6
6
|
const uniqueId = incrementalUniqueId++;
|
|
7
|
-
if (tagName === 'list') {
|
|
7
|
+
if (tagName === 'x-list') {
|
|
8
8
|
return new ListElement(tagName, uniqueId, pageConfig, operationsRef, styleInfo);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
@@ -6,6 +6,7 @@ export interface initializeElementCreatingFunctionConfig {
|
|
|
6
6
|
};
|
|
7
7
|
pageConfig: PageConfig;
|
|
8
8
|
styleInfo: CssInJsInfo;
|
|
9
|
+
tagMap: Record<string, string>;
|
|
9
10
|
}
|
|
10
11
|
export declare function initializeElementCreatingFunction(config: initializeElementCreatingFunctionConfig): {
|
|
11
12
|
__CreateView: (parentComponentUniqueId: number) => ElementThreadElement;
|
|
@@ -1,13 +1,13 @@
|
|
|
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, parentComponentUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
4
|
+
import { cssIdAttribute, parentComponentUniqueIdAttribute, lynxTagAttribute, } from '@lynx-js/web-constants';
|
|
5
5
|
import { __UpdateComponentID } from '../attributeAndProperty/attributeAndPropertyFunctions.js';
|
|
6
6
|
import { ListElement, ElementThreadElement, } from '../ElementThreadElement.js';
|
|
7
7
|
import { __SetCSSId } from '../style/styleFunctions.js';
|
|
8
8
|
import { createOffscreenDocument } from '../createOffscreenDocument.js';
|
|
9
9
|
export function initializeElementCreatingFunction(config) {
|
|
10
|
-
const { operationsRef, pageConfig, styleInfo } = config;
|
|
10
|
+
const { operationsRef, pageConfig, styleInfo, tagMap } = config;
|
|
11
11
|
const document = createOffscreenDocument({
|
|
12
12
|
pageConfig,
|
|
13
13
|
operationsRef,
|
|
@@ -16,7 +16,9 @@ export function initializeElementCreatingFunction(config) {
|
|
|
16
16
|
function createLynxElement(tag, parentComponentUniqueId, cssId, componentId,
|
|
17
17
|
// @ts-expect-error
|
|
18
18
|
info) {
|
|
19
|
-
const
|
|
19
|
+
const htmlTag = tagMap[tag] ?? tag;
|
|
20
|
+
const element = document.createElement(htmlTag);
|
|
21
|
+
element.setAttribute(lynxTagAttribute, tag);
|
|
20
22
|
// element.parentComponentUniqueId = parentComponentUniqueId;
|
|
21
23
|
element.setAttribute(parentComponentUniqueIdAttribute, parentComponentUniqueId.toString());
|
|
22
24
|
if (cssId !== undefined)
|
|
@@ -49,6 +51,7 @@ export function initializeElementCreatingFunction(config) {
|
|
|
49
51
|
}
|
|
50
52
|
function __CreatePage(componentID, cssID, info) {
|
|
51
53
|
const page = createLynxElement('page', 0, cssID, componentID, info);
|
|
54
|
+
page.setAttribute('part', 'page');
|
|
52
55
|
page.setAttribute(parentComponentUniqueIdAttribute, page.uniqueId.toString());
|
|
53
56
|
return page;
|
|
54
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-mainthread-apis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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.
|
|
29
|
-
"@lynx-js/web-style-transformer": "0.2.
|
|
28
|
+
"@lynx-js/web-constants": "0.9.1",
|
|
29
|
+
"@lynx-js/web-style-transformer": "0.2.3"
|
|
30
30
|
}
|
|
31
31
|
}
|