@lynx-js/web-mainthread-apis 0.13.4 → 0.14.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.
- package/CHANGELOG.md +93 -0
- package/dist/createMainThreadGlobalThis.d.ts +25 -0
- package/dist/createMainThreadGlobalThis.js +454 -0
- package/dist/createMainThreadLynx.d.ts +3 -0
- package/dist/{MainThreadLynx.js → createMainThreadLynx.js} +2 -5
- package/dist/crossThreadHandlers/registerCallLepusMethodHandler.d.ts +2 -3
- package/dist/crossThreadHandlers/registerCallLepusMethodHandler.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/prepareMainThreadAPIs.d.ts +3 -4
- package/dist/prepareMainThreadAPIs.js +30 -16
- package/dist/pureElementPAPIs.d.ts +32 -0
- package/dist/pureElementPAPIs.js +140 -0
- package/dist/utils/createCrossThreadEvent.d.ts +2 -3
- package/dist/utils/createCrossThreadEvent.js +23 -12
- package/dist/utils/createExposureService.d.ts +2 -2
- package/dist/utils/createExposureService.js +4 -5
- package/dist/utils/decodeCssInJs.js +1 -1
- package/package.json +3 -3
- package/dist/MainThreadLynx.d.ts +0 -10
- package/dist/MainThreadRuntime.d.ts +0 -92
- package/dist/MainThreadRuntime.js +0 -186
- package/dist/elementAPI/ElementThreadElement.d.ts +0 -27
- package/dist/elementAPI/ElementThreadElement.js +0 -2
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +0 -30
- package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +0 -127
- package/dist/elementAPI/domTree/domTreeFunctions.d.ts +0 -11
- package/dist/elementAPI/domTree/domTreeFunctions.js +0 -49
- package/dist/elementAPI/elementCreating/elementCreatingFunctions.d.ts +0 -15
- package/dist/elementAPI/elementCreating/elementCreatingFunctions.js +0 -123
- package/dist/elementAPI/event/eventFunctions.d.ts +0 -25
- package/dist/elementAPI/event/eventFunctions.js +0 -142
- package/dist/elementAPI/style/styleFunctions.d.ts +0 -10
- package/dist/elementAPI/style/styleFunctions.js +0 -89
- /package/dist/{elementAPI/style → style}/cssPropertyMap.d.ts +0 -0
- /package/dist/{elementAPI/style → style}/cssPropertyMap.js +0 -0
- /package/dist/{elementAPI/style → style}/transformInlineStyle.d.ts +0 -0
- /package/dist/{elementAPI/style → style}/transformInlineStyle.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,98 @@
|
|
|
1
1
|
# @lynx-js/web-mainthread-apis
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: add `_SetSourceMapRelease(errInfo)` MTS API. ([#1118](https://github.com/lynx-family/lynx-stack/pull/1118))
|
|
8
|
+
|
|
9
|
+
You can get `errInfo.release` through `e.detail.release` in the error event callback of lynx-view.
|
|
10
|
+
|
|
11
|
+
The `_SetSourceMapRelease` function is not complete yet, because it is currently limited by the Web platform and some functions and some props such as `err.stack` do not need to be supported for the time being.
|
|
12
|
+
|
|
13
|
+
- feat: add `_I18nResourceTranslation` api in mts && `init-i18n-resources` attr, `i18nResourceMissed` event of lynx-view. ([#1065](https://github.com/lynx-family/lynx-stack/pull/1065))
|
|
14
|
+
|
|
15
|
+
`init-i18n-resource` is the complete set of i18nResources that need to be maintained on the container side. Note: You need to pass this value when lynx-view is initialized.
|
|
16
|
+
|
|
17
|
+
You can use `_I18nResourceTranslation` in MTS to get the corresponding i18nResource from `init-i18n-resources`. If it is undefined, the `i18nResourceMissed` event will be dispatched.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// ui thread
|
|
21
|
+
lynxView.initI18nResources = [
|
|
22
|
+
{
|
|
23
|
+
options: {
|
|
24
|
+
locale: 'en',
|
|
25
|
+
channel: '1',
|
|
26
|
+
fallback_url: '',
|
|
27
|
+
},
|
|
28
|
+
resource: {
|
|
29
|
+
hello: 'hello',
|
|
30
|
+
lynx: 'lynx web platform1',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
lynxView.addEventListener('i18nResourceMissed', (e) => {
|
|
35
|
+
console.log(e);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// mts
|
|
39
|
+
_I18nResourceTranslation({
|
|
40
|
+
locale: 'en',
|
|
41
|
+
channel: '1',
|
|
42
|
+
fallback_url: '',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088))
|
|
47
|
+
|
|
48
|
+
- `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources:
|
|
49
|
+
- the result of `_I18nResourceTranslation()`
|
|
50
|
+
- lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()`
|
|
51
|
+
- `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution.
|
|
52
|
+
|
|
53
|
+
- feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085))
|
|
54
|
+
|
|
55
|
+
Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result.
|
|
56
|
+
|
|
57
|
+
- fix: `decodeCssInJs` will not throw error. ([#1120](https://github.com/lynx-family/lynx-stack/pull/1120))
|
|
58
|
+
|
|
59
|
+
Before this pr, decoding css will be strictly executed according to cssInfo, and an error will be thrown if data that does not meet the requirements is encountered. Now it is changed to console.warn, which will not block rendering.
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [[`25a04c9`](https://github.com/lynx-family/lynx-stack/commit/25a04c9e59f4b893227bdead74f2de69f6615cdb), [`0dbb8b1`](https://github.com/lynx-family/lynx-stack/commit/0dbb8b1f580d0700e2b67b92018a7a00d1494837), [`f99de1e`](https://github.com/lynx-family/lynx-stack/commit/f99de1ef60cc5a11eae4fd0acc70a490787d36c9), [`873a285`](https://github.com/lynx-family/lynx-stack/commit/873a2852fa3df9e32c48a6504160bb243540c7b9), [`afacb2c`](https://github.com/lynx-family/lynx-stack/commit/afacb2cbea7feca46c553651000625d0845b2b00), [`7e73450`](https://github.com/lynx-family/lynx-stack/commit/7e73450f8f5f1153f8a064036f5552c1335c23d7)]:
|
|
62
|
+
- @lynx-js/web-constants@0.14.0
|
|
63
|
+
- @lynx-js/web-style-transformer@0.3.1
|
|
64
|
+
|
|
65
|
+
## 0.13.5
|
|
66
|
+
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945))
|
|
70
|
+
|
|
71
|
+
It's essential for SSR
|
|
72
|
+
|
|
73
|
+
- refactor: avoid to create many style element for cssog ([#1026](https://github.com/lynx-family/lynx-stack/pull/1026))
|
|
74
|
+
|
|
75
|
+
- fix: target.id is undefined ([#1016](https://github.com/lynx-family/lynx-stack/pull/1016))
|
|
76
|
+
|
|
77
|
+
- feat: add new pageConfig configuration: enableJSDataProcessor ([#886](https://github.com/lynx-family/lynx-stack/pull/886))
|
|
78
|
+
|
|
79
|
+
- refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984))
|
|
80
|
+
|
|
81
|
+
- refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981))
|
|
82
|
+
|
|
83
|
+
On lynx, the `data-*` attributes have different behaviors than the HTMLElement has.
|
|
84
|
+
|
|
85
|
+
The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation.
|
|
86
|
+
|
|
87
|
+
Before this commit we use it as a runtime data, but after this commit we will use encodeURI(JSON.stringify(dataset)) to encode it as a string.
|
|
88
|
+
|
|
89
|
+
- refactor: create elements of `elementToRuntimeInfoMap` on demand ([#986](https://github.com/lynx-family/lynx-stack/pull/986))
|
|
90
|
+
|
|
91
|
+
- refactor: implement mts apis in closure pattern ([#1004](https://github.com/lynx-family/lynx-stack/pull/1004))
|
|
92
|
+
|
|
93
|
+
- Updated dependencies [[`70b82d2`](https://github.com/lynx-family/lynx-stack/commit/70b82d23744d6b6ec945dff9f8895ab3488ba4c8), [`9499ea9`](https://github.com/lynx-family/lynx-stack/commit/9499ea91debdf73b2d31af0b31bcbc216135543b), [`50f0193`](https://github.com/lynx-family/lynx-stack/commit/50f01933942268b697bf5abe790da86c932f1dfc), [`57bf0ef`](https://github.com/lynx-family/lynx-stack/commit/57bf0ef19f1d79bc52ab6a4f0cd2939e7901d98b), [`0525fbf`](https://github.com/lynx-family/lynx-stack/commit/0525fbf38baa7a977a7a8c66e8a4d8bf34cc3b68), [`b6b87fd`](https://github.com/lynx-family/lynx-stack/commit/b6b87fd11dbc76c28f3b5022aa8c6afeb773d90f), [`c014327`](https://github.com/lynx-family/lynx-stack/commit/c014327ad0cf599b32d4182d95116b46c35f5fa5)]:
|
|
94
|
+
- @lynx-js/web-constants@0.13.5
|
|
95
|
+
|
|
3
96
|
## 0.13.4
|
|
4
97
|
|
|
5
98
|
### Patch Changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LynxTemplate, type PageConfig, type StyleInfo, type FlushElementTreeOptions, type Cloneable, type BrowserConfig, type publishEventEndpoint, type publicComponentEventEndpoint, type reportErrorEndpoint, type RpcCallType, type LynxContextEventTarget, type LynxJSModule, type MainThreadGlobalThis, type WebFiberElementImpl, type I18nResourceTranslationOptions } from '@lynx-js/web-constants';
|
|
2
|
+
export interface MainThreadRuntimeCallbacks {
|
|
3
|
+
mainChunkReady: () => void;
|
|
4
|
+
flushElementTree: (options: FlushElementTreeOptions, timingFlags: string[]) => void;
|
|
5
|
+
_ReportError: RpcCallType<typeof reportErrorEndpoint>;
|
|
6
|
+
__OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
|
|
7
|
+
markTiming: (pipelineId: string, timingKey: string) => void;
|
|
8
|
+
publishEvent: RpcCallType<typeof publishEventEndpoint>;
|
|
9
|
+
publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
|
|
10
|
+
createElement: (tag: string) => WebFiberElementImpl;
|
|
11
|
+
_I18nResourceTranslation: (options: I18nResourceTranslationOptions) => unknown | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface MainThreadRuntimeConfig {
|
|
14
|
+
pageConfig: PageConfig;
|
|
15
|
+
globalProps: unknown;
|
|
16
|
+
callbacks: MainThreadRuntimeCallbacks;
|
|
17
|
+
styleInfo: StyleInfo;
|
|
18
|
+
customSections: LynxTemplate['customSections'];
|
|
19
|
+
lepusCode: Record<string, LynxJSModule>;
|
|
20
|
+
browserConfig: BrowserConfig;
|
|
21
|
+
tagMap: Record<string, string>;
|
|
22
|
+
rootDom: Pick<Element, 'append' | 'addEventListener'>;
|
|
23
|
+
jsContext: LynxContextEventTarget;
|
|
24
|
+
}
|
|
25
|
+
export declare function createMainThreadGlobalThis(config: MainThreadRuntimeConfig): MainThreadGlobalThis;
|
|
@@ -0,0 +1,454 @@
|
|
|
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 { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, } from '@lynx-js/web-constants';
|
|
5
|
+
import { globalMuteableVars } from '@lynx-js/web-constants';
|
|
6
|
+
import { createMainThreadLynx } from './createMainThreadLynx.js';
|
|
7
|
+
import { flattenStyleInfo, genCssContent, genCssInJsInfo, transformToWebCss, } from './utils/processStyleInfo.js';
|
|
8
|
+
import { __AddClass, __AddConfig, __AddDataset, __AddInlineStyle, __AppendElement, __ElementIsEqual, __FirstElement, __GetAttributes, __GetChildren, __GetClasses, __GetComponentID, __GetDataByKey, __GetDataset, __GetElementConfig, __GetElementUniqueID, __GetID, __GetParent, __GetTag, __InsertElementBefore, __LastElement, __NextElement, __RemoveElement, __ReplaceElement, __ReplaceElements, __SetClasses, __SetConfig, __SetCSSId, __SetDataset, __SetID, __SetInlineStyles, __UpdateComponentID, } from './pureElementPAPIs.js';
|
|
9
|
+
import { createCrossThreadEvent } from './utils/createCrossThreadEvent.js';
|
|
10
|
+
import { decodeCssInJs } from './utils/decodeCssInJs.js';
|
|
11
|
+
export function createMainThreadGlobalThis(config) {
|
|
12
|
+
let pageElement;
|
|
13
|
+
let uniqueIdInc = 1;
|
|
14
|
+
let timingFlags = [];
|
|
15
|
+
let renderPage;
|
|
16
|
+
const { callbacks, tagMap, pageConfig, lepusCode, rootDom, globalProps, styleInfo, } = config;
|
|
17
|
+
const lynxUniqueIdToElement = [];
|
|
18
|
+
const elementToRuntimeInfoMap = new WeakMap();
|
|
19
|
+
const lynxUniqueIdToStyleRulesIndex = [];
|
|
20
|
+
/**
|
|
21
|
+
* for "update" the globalThis.val in the main thread
|
|
22
|
+
*/
|
|
23
|
+
const varsUpdateHandlers = [];
|
|
24
|
+
const lynxGlobalBindingValues = {};
|
|
25
|
+
/**
|
|
26
|
+
* now create the style content
|
|
27
|
+
* 1. flatten the styleInfo
|
|
28
|
+
* 2. transform the styleInfo to web css
|
|
29
|
+
* 3. generate the css in js info
|
|
30
|
+
* 4. create the style element
|
|
31
|
+
* 5. append the style element to the root dom
|
|
32
|
+
*/
|
|
33
|
+
flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
|
|
34
|
+
transformToWebCss(styleInfo);
|
|
35
|
+
const cssInJsInfo = pageConfig.enableCSSSelector
|
|
36
|
+
? {}
|
|
37
|
+
: genCssInJsInfo(styleInfo);
|
|
38
|
+
const cardStyleElement = callbacks.createElement('style');
|
|
39
|
+
cardStyleElement.innerHTML = genCssContent(styleInfo, pageConfig);
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
rootDom.append(cardStyleElement);
|
|
42
|
+
const cardStyleElementSheet = cardStyleElement.sheet;
|
|
43
|
+
const updateCSSInJsStyle = (uniqueId, newStyles) => {
|
|
44
|
+
if (lynxUniqueIdToStyleRulesIndex[uniqueId] !== undefined) {
|
|
45
|
+
const rule = cardStyleElementSheet
|
|
46
|
+
.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
|
|
47
|
+
rule.style.cssText = newStyles;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
|
|
51
|
+
lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const commonHandler = (event) => {
|
|
55
|
+
if (!event.currentTarget) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const currentTarget = event.currentTarget;
|
|
59
|
+
const isCapture = event.eventPhase === Event.CAPTURING_PHASE;
|
|
60
|
+
const lynxEventName = W3cEventNameToLynx[event.type] ?? event.type;
|
|
61
|
+
const runtimeInfo = elementToRuntimeInfoMap.get(currentTarget);
|
|
62
|
+
if (runtimeInfo) {
|
|
63
|
+
const hname = isCapture
|
|
64
|
+
? runtimeInfo.eventHandlerMap[lynxEventName]?.capture
|
|
65
|
+
?.handler
|
|
66
|
+
: runtimeInfo.eventHandlerMap[lynxEventName]?.bind
|
|
67
|
+
?.handler;
|
|
68
|
+
const crossThreadEvent = createCrossThreadEvent(event, lynxEventName);
|
|
69
|
+
if (typeof hname === 'string') {
|
|
70
|
+
const parentComponentUniqueId = Number(currentTarget.getAttribute(parentComponentUniqueIdAttribute));
|
|
71
|
+
const parentComponent = lynxUniqueIdToElement[parentComponentUniqueId]
|
|
72
|
+
.deref();
|
|
73
|
+
const componentId = parentComponent?.getAttribute(lynxTagAttribute) !== 'page'
|
|
74
|
+
? parentComponent?.getAttribute(componentIdAttribute) ?? undefined
|
|
75
|
+
: undefined;
|
|
76
|
+
if (componentId) {
|
|
77
|
+
callbacks.publicComponentEvent(componentId, hname, crossThreadEvent);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
callbacks.publishEvent(hname, crossThreadEvent);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
else if (hname) {
|
|
85
|
+
crossThreadEvent.target.elementRefptr =
|
|
86
|
+
event.target;
|
|
87
|
+
if (crossThreadEvent.currentTarget) {
|
|
88
|
+
crossThreadEvent.currentTarget
|
|
89
|
+
.elementRefptr = event.currentTarget;
|
|
90
|
+
}
|
|
91
|
+
mtsGlobalThis.runWorklet?.(hname.value, [crossThreadEvent]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
};
|
|
96
|
+
const commonCatchHandler = (event) => {
|
|
97
|
+
const handlerTriggered = commonHandler(event);
|
|
98
|
+
if (handlerTriggered)
|
|
99
|
+
event.stopPropagation();
|
|
100
|
+
};
|
|
101
|
+
const __AddEvent = (element, eventType, eventName, newEventHandler) => {
|
|
102
|
+
eventName = eventName.toLowerCase();
|
|
103
|
+
const isCatch = eventType === 'catchEvent' || eventType === 'capture-catch';
|
|
104
|
+
const isCapture = eventType.startsWith('capture');
|
|
105
|
+
const runtimeInfo = elementToRuntimeInfoMap.get(element) ?? {
|
|
106
|
+
eventHandlerMap: {},
|
|
107
|
+
componentAtIndex: undefined,
|
|
108
|
+
enqueueComponent: undefined,
|
|
109
|
+
};
|
|
110
|
+
const currentHandler = isCapture
|
|
111
|
+
? runtimeInfo.eventHandlerMap[eventName]?.capture
|
|
112
|
+
: runtimeInfo.eventHandlerMap[eventName]?.bind;
|
|
113
|
+
const currentRegisteredHandler = isCatch
|
|
114
|
+
? commonCatchHandler
|
|
115
|
+
: commonHandler;
|
|
116
|
+
if (currentHandler) {
|
|
117
|
+
if (!newEventHandler) {
|
|
118
|
+
/**
|
|
119
|
+
* remove handler
|
|
120
|
+
*/
|
|
121
|
+
element.removeEventListener(eventName, currentRegisteredHandler, {
|
|
122
|
+
capture: isCapture,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
/**
|
|
128
|
+
* append new handler
|
|
129
|
+
*/
|
|
130
|
+
if (newEventHandler) {
|
|
131
|
+
const htmlEventName = LynxEventNameToW3cByTagName[element.tagName]?.[eventName]
|
|
132
|
+
?? LynxEventNameToW3cCommon[eventName] ?? eventName;
|
|
133
|
+
element.addEventListener(htmlEventName, currentRegisteredHandler, {
|
|
134
|
+
capture: isCapture,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (newEventHandler) {
|
|
139
|
+
const info = {
|
|
140
|
+
type: eventType,
|
|
141
|
+
handler: newEventHandler,
|
|
142
|
+
};
|
|
143
|
+
if (!runtimeInfo.eventHandlerMap[eventName]) {
|
|
144
|
+
runtimeInfo.eventHandlerMap[eventName] = {
|
|
145
|
+
capture: undefined,
|
|
146
|
+
bind: undefined,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (isCapture) {
|
|
150
|
+
runtimeInfo.eventHandlerMap[eventName].capture = info;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
runtimeInfo.eventHandlerMap[eventName].bind = info;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
elementToRuntimeInfoMap.set(element, runtimeInfo);
|
|
157
|
+
};
|
|
158
|
+
const __GetEvent = (element, eventName, eventType) => {
|
|
159
|
+
const runtimeInfo = elementToRuntimeInfoMap.get(element);
|
|
160
|
+
if (runtimeInfo) {
|
|
161
|
+
eventName = eventName.toLowerCase();
|
|
162
|
+
const isCapture = eventType.startsWith('capture');
|
|
163
|
+
const handler = isCapture
|
|
164
|
+
? runtimeInfo.eventHandlerMap[eventName]?.capture
|
|
165
|
+
: runtimeInfo.eventHandlerMap[eventName]?.bind;
|
|
166
|
+
return handler?.handler;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const __GetEvents = (element) => {
|
|
173
|
+
const eventHandlerMap = elementToRuntimeInfoMap.get(element)?.eventHandlerMap ?? {};
|
|
174
|
+
const eventInfos = [];
|
|
175
|
+
for (const [lynxEventName, info] of Object.entries(eventHandlerMap)) {
|
|
176
|
+
for (const atomInfo of [info.bind, info.capture]) {
|
|
177
|
+
if (atomInfo) {
|
|
178
|
+
const { type, handler } = atomInfo;
|
|
179
|
+
if (handler) {
|
|
180
|
+
eventInfos.push({
|
|
181
|
+
type: type,
|
|
182
|
+
name: lynxEventName,
|
|
183
|
+
function: handler,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return eventInfos;
|
|
190
|
+
};
|
|
191
|
+
const __SetEvents = (element, listeners) => {
|
|
192
|
+
for (const { type: eventType, name: lynxEventName, function: eventHandler } of listeners) {
|
|
193
|
+
__AddEvent(element, eventType, lynxEventName, eventHandler);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const __CreateElement = (tag, parentComponentUniqueId) => {
|
|
197
|
+
const uniqueId = uniqueIdInc++;
|
|
198
|
+
const htmlTag = tagMap[tag] ?? tag;
|
|
199
|
+
const element = callbacks.createElement(htmlTag);
|
|
200
|
+
lynxUniqueIdToElement[uniqueId] = new WeakRef(element);
|
|
201
|
+
const parentComponentCssID = lynxUniqueIdToElement[parentComponentUniqueId]
|
|
202
|
+
?.deref()?.getAttribute(cssIdAttribute);
|
|
203
|
+
parentComponentCssID && parentComponentCssID !== '0'
|
|
204
|
+
&& element.setAttribute(cssIdAttribute, parentComponentCssID);
|
|
205
|
+
element.setAttribute(lynxTagAttribute, tag);
|
|
206
|
+
element.setAttribute(lynxUniqueIdAttribute, uniqueId + '');
|
|
207
|
+
element.setAttribute(parentComponentUniqueIdAttribute, parentComponentUniqueId + '');
|
|
208
|
+
return element;
|
|
209
|
+
};
|
|
210
|
+
const __CreateView = (parentComponentUniqueId) => __CreateElement('view', parentComponentUniqueId);
|
|
211
|
+
const __CreateText = (parentComponentUniqueId) => __CreateElement('text', parentComponentUniqueId);
|
|
212
|
+
const __CreateRawText = (text) => {
|
|
213
|
+
const element = __CreateElement('raw-text', -1);
|
|
214
|
+
element.setAttribute('text', text);
|
|
215
|
+
return element;
|
|
216
|
+
};
|
|
217
|
+
const __CreateImage = (parentComponentUniqueId) => __CreateElement('image', parentComponentUniqueId);
|
|
218
|
+
const __CreateScrollView = (parentComponentUniqueId) => __CreateElement('scroll-view', parentComponentUniqueId);
|
|
219
|
+
const __CreateWrapperElement = (parentComponentUniqueId) => __CreateElement('lynx-wrapper', parentComponentUniqueId);
|
|
220
|
+
const __CreatePage = (componentID, cssID) => {
|
|
221
|
+
const page = __CreateElement('page', 0);
|
|
222
|
+
page.setAttribute('part', 'page');
|
|
223
|
+
page.setAttribute(cssIdAttribute, cssID + '');
|
|
224
|
+
page.setAttribute(parentComponentUniqueIdAttribute, '0');
|
|
225
|
+
page.setAttribute(componentIdAttribute, componentID);
|
|
226
|
+
if (pageConfig.defaultDisplayLinear === false) {
|
|
227
|
+
page.setAttribute(lynxDefaultDisplayLinearAttribute, 'false');
|
|
228
|
+
}
|
|
229
|
+
if (pageConfig.defaultOverflowVisible === true) {
|
|
230
|
+
page.setAttribute('lynx-default-overflow-visible', 'true');
|
|
231
|
+
}
|
|
232
|
+
pageElement = page;
|
|
233
|
+
return page;
|
|
234
|
+
};
|
|
235
|
+
const __CreateList = (parentComponentUniqueId, componentAtIndex, enqueueComponent) => {
|
|
236
|
+
const list = __CreateElement('list', parentComponentUniqueId);
|
|
237
|
+
const runtimeInfo = {
|
|
238
|
+
eventHandlerMap: {},
|
|
239
|
+
componentAtIndex: componentAtIndex,
|
|
240
|
+
enqueueComponent: enqueueComponent,
|
|
241
|
+
};
|
|
242
|
+
elementToRuntimeInfoMap.set(list, runtimeInfo);
|
|
243
|
+
return list;
|
|
244
|
+
};
|
|
245
|
+
const __CreateComponent = (componentParentUniqueID, componentID, cssID, _, name) => {
|
|
246
|
+
const component = __CreateElement('view', componentParentUniqueID);
|
|
247
|
+
component.setAttribute(cssIdAttribute, cssID + '');
|
|
248
|
+
component.setAttribute(componentIdAttribute, componentID);
|
|
249
|
+
component.setAttribute('name', name);
|
|
250
|
+
return component;
|
|
251
|
+
};
|
|
252
|
+
const __SetAttribute = (element, key, value) => {
|
|
253
|
+
const tag = element.getAttribute(lynxTagAttribute);
|
|
254
|
+
if (tag === 'list' && key === 'update-list-info') {
|
|
255
|
+
const listInfo = value;
|
|
256
|
+
const { insertAction, removeAction } = listInfo;
|
|
257
|
+
queueMicrotask(() => {
|
|
258
|
+
const runtimeInfo = elementToRuntimeInfoMap.get(element);
|
|
259
|
+
if (runtimeInfo) {
|
|
260
|
+
const componentAtIndex = runtimeInfo.componentAtIndex;
|
|
261
|
+
const enqueueComponent = runtimeInfo.enqueueComponent;
|
|
262
|
+
const uniqueId = __GetElementUniqueID(element);
|
|
263
|
+
for (const action of insertAction) {
|
|
264
|
+
componentAtIndex?.(element, uniqueId, action.position, 0, false);
|
|
265
|
+
}
|
|
266
|
+
for (const action of removeAction) {
|
|
267
|
+
enqueueComponent?.(element, uniqueId, action.position);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
value == null
|
|
274
|
+
? element.removeAttribute(key)
|
|
275
|
+
: element.setAttribute(key, value + '');
|
|
276
|
+
if (key === __lynx_timing_flag && value) {
|
|
277
|
+
timingFlags.push(value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const __UpdateListCallbacks = (element, componentAtIndex, enqueueComponent) => {
|
|
282
|
+
const runtimeInfo = elementToRuntimeInfoMap.get(element) ?? {
|
|
283
|
+
eventHandlerMap: {},
|
|
284
|
+
componentAtIndex: componentAtIndex,
|
|
285
|
+
enqueueComponent: enqueueComponent,
|
|
286
|
+
uniqueId: __GetElementUniqueID(element),
|
|
287
|
+
};
|
|
288
|
+
runtimeInfo.componentAtIndex = componentAtIndex;
|
|
289
|
+
runtimeInfo.enqueueComponent = enqueueComponent;
|
|
290
|
+
elementToRuntimeInfoMap.set(element, runtimeInfo);
|
|
291
|
+
};
|
|
292
|
+
const __SwapElement = (childA, childB) => {
|
|
293
|
+
const temp = callbacks.createElement('div');
|
|
294
|
+
childA.replaceWith(temp);
|
|
295
|
+
childB.replaceWith(childA);
|
|
296
|
+
temp.replaceWith(childB);
|
|
297
|
+
};
|
|
298
|
+
const __SetCSSIdForCSSOG = (elements, cssId) => {
|
|
299
|
+
for (const element of elements) {
|
|
300
|
+
element.setAttribute(cssIdAttribute, cssId + '');
|
|
301
|
+
const cls = element.getAttribute('class');
|
|
302
|
+
cls && __SetClassesForCSSOG(element, cls);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
const __AddClassForCSSOG = (element, className) => {
|
|
306
|
+
const newClassName = ((element.getAttribute('class') ?? '') + ' ' + className)
|
|
307
|
+
.trim();
|
|
308
|
+
element.setAttribute('class', newClassName);
|
|
309
|
+
const newStyleStr = decodeCssInJs(newClassName, cssInJsInfo, element.getAttribute(cssIdAttribute));
|
|
310
|
+
updateCSSInJsStyle(Number(element.getAttribute(lynxUniqueIdAttribute)), newStyleStr);
|
|
311
|
+
};
|
|
312
|
+
const __SetClassesForCSSOG = (element, classNames) => {
|
|
313
|
+
__SetClasses(element, classNames);
|
|
314
|
+
const newStyleStr = decodeCssInJs(classNames ?? '', cssInJsInfo, element.getAttribute(cssIdAttribute));
|
|
315
|
+
updateCSSInJsStyle(Number(element.getAttribute(lynxUniqueIdAttribute)), newStyleStr ?? '');
|
|
316
|
+
};
|
|
317
|
+
const __LoadLepusChunk = (path) => {
|
|
318
|
+
const lepusModule = lepusCode[`${path}`];
|
|
319
|
+
if (lepusModule) {
|
|
320
|
+
const entry = lepusModule.exports;
|
|
321
|
+
entry?.(mtsGlobalThis);
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const __FlushElementTree = (_subTree, options) => {
|
|
329
|
+
const timingFlagsCopied = timingFlags;
|
|
330
|
+
timingFlags = [];
|
|
331
|
+
if (pageElement && !pageElement.parentNode) {
|
|
332
|
+
// @ts-expect-error
|
|
333
|
+
rootDom.append(pageElement);
|
|
334
|
+
}
|
|
335
|
+
callbacks.flushElementTree(options, timingFlagsCopied);
|
|
336
|
+
};
|
|
337
|
+
const __GetTemplateParts = () => {
|
|
338
|
+
return undefined;
|
|
339
|
+
};
|
|
340
|
+
const __GetPageElement = () => {
|
|
341
|
+
return pageElement;
|
|
342
|
+
};
|
|
343
|
+
let release = '';
|
|
344
|
+
const isCSSOG = !pageConfig.enableCSSSelector;
|
|
345
|
+
const mtsGlobalThis = {
|
|
346
|
+
__AddEvent,
|
|
347
|
+
__GetEvent,
|
|
348
|
+
__GetEvents,
|
|
349
|
+
__SetEvents,
|
|
350
|
+
__AppendElement,
|
|
351
|
+
__ElementIsEqual,
|
|
352
|
+
__FirstElement,
|
|
353
|
+
__GetChildren,
|
|
354
|
+
__GetParent,
|
|
355
|
+
__InsertElementBefore,
|
|
356
|
+
__LastElement,
|
|
357
|
+
__NextElement,
|
|
358
|
+
__RemoveElement,
|
|
359
|
+
__ReplaceElement,
|
|
360
|
+
__ReplaceElements,
|
|
361
|
+
__AddConfig,
|
|
362
|
+
__AddDataset,
|
|
363
|
+
__GetAttributes,
|
|
364
|
+
__GetComponentID,
|
|
365
|
+
__GetDataByKey,
|
|
366
|
+
__GetDataset,
|
|
367
|
+
__GetElementConfig,
|
|
368
|
+
__GetElementUniqueID,
|
|
369
|
+
__GetID,
|
|
370
|
+
__GetTag,
|
|
371
|
+
__SetConfig,
|
|
372
|
+
__SetDataset,
|
|
373
|
+
__SetID,
|
|
374
|
+
__UpdateComponentID,
|
|
375
|
+
__CreateElement,
|
|
376
|
+
__CreateView,
|
|
377
|
+
__CreateText,
|
|
378
|
+
__CreateComponent,
|
|
379
|
+
__CreatePage,
|
|
380
|
+
__CreateRawText,
|
|
381
|
+
__CreateImage,
|
|
382
|
+
__CreateScrollView,
|
|
383
|
+
__CreateWrapperElement,
|
|
384
|
+
__CreateList,
|
|
385
|
+
__SetAttribute,
|
|
386
|
+
__SwapElement,
|
|
387
|
+
__UpdateListCallbacks,
|
|
388
|
+
__GetConfig: __GetElementConfig,
|
|
389
|
+
__GetClasses,
|
|
390
|
+
__AddClass: isCSSOG ? __AddClassForCSSOG : __AddClass,
|
|
391
|
+
__SetClasses: isCSSOG ? __SetClassesForCSSOG : __SetClasses,
|
|
392
|
+
__AddInlineStyle,
|
|
393
|
+
__SetCSSId: isCSSOG ? __SetCSSIdForCSSOG : __SetCSSId,
|
|
394
|
+
__SetInlineStyles,
|
|
395
|
+
__LoadLepusChunk,
|
|
396
|
+
__GetPageElement,
|
|
397
|
+
__GetTemplateParts,
|
|
398
|
+
__globalProps: globalProps,
|
|
399
|
+
SystemInfo: {
|
|
400
|
+
...systemInfo,
|
|
401
|
+
...config.browserConfig,
|
|
402
|
+
},
|
|
403
|
+
lynx: createMainThreadLynx(config),
|
|
404
|
+
_ReportError: (err, _) => callbacks._ReportError(err, _, release),
|
|
405
|
+
_SetSourceMapRelease: (errInfo) => release = errInfo?.release,
|
|
406
|
+
__OnLifecycleEvent: callbacks.__OnLifecycleEvent,
|
|
407
|
+
__FlushElementTree,
|
|
408
|
+
__lynxGlobalBindingValues: lynxGlobalBindingValues,
|
|
409
|
+
_I18nResourceTranslation: callbacks._I18nResourceTranslation,
|
|
410
|
+
_AddEventListener: () => { },
|
|
411
|
+
set _updateVars(handler) {
|
|
412
|
+
varsUpdateHandlers.push(handler);
|
|
413
|
+
},
|
|
414
|
+
set renderPage(foo) {
|
|
415
|
+
renderPage = foo;
|
|
416
|
+
queueMicrotask(callbacks.mainChunkReady);
|
|
417
|
+
},
|
|
418
|
+
get renderPage() {
|
|
419
|
+
return renderPage;
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
mtsGlobalThis.globalThis = new Proxy(mtsGlobalThis, {
|
|
423
|
+
get: (target, prop) => {
|
|
424
|
+
if (prop === 'globalThis') {
|
|
425
|
+
return target;
|
|
426
|
+
}
|
|
427
|
+
// @ts-expect-error
|
|
428
|
+
return target[prop] ?? globalThis[prop];
|
|
429
|
+
},
|
|
430
|
+
set: (target, prop, value) => {
|
|
431
|
+
// @ts-expect-error
|
|
432
|
+
target[prop] = value;
|
|
433
|
+
return true;
|
|
434
|
+
},
|
|
435
|
+
ownKeys(target) {
|
|
436
|
+
return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
for (const nm of globalMuteableVars) {
|
|
440
|
+
Object.defineProperty(mtsGlobalThis, nm, {
|
|
441
|
+
get: () => {
|
|
442
|
+
return lynxGlobalBindingValues[nm];
|
|
443
|
+
},
|
|
444
|
+
set: (v) => {
|
|
445
|
+
lynxGlobalBindingValues[nm] = v;
|
|
446
|
+
for (const handler of varsUpdateHandlers) {
|
|
447
|
+
handler();
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return mtsGlobalThis;
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=createMainThreadGlobalThis.js.map
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
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 {} from './MainThreadRuntime.js';
|
|
1
|
+
import {} from './createMainThreadGlobalThis.js';
|
|
5
2
|
export function createMainThreadLynx(config) {
|
|
6
3
|
return {
|
|
7
4
|
getJSContext() {
|
|
@@ -20,4 +17,4 @@ export function createMainThreadLynx(config) {
|
|
|
20
17
|
markPipelineTiming: config.callbacks.markTiming,
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=createMainThreadLynx.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { type Rpc } from '@lynx-js/web-constants';
|
|
2
|
-
|
|
3
|
-
export declare function registerCallLepusMethodHandler(rpc: Rpc, runtime: MainThreadRuntime): void;
|
|
1
|
+
import { type MainThreadGlobalThis, type Rpc } from '@lynx-js/web-constants';
|
|
2
|
+
export declare function registerCallLepusMethodHandler(rpc: Rpc, runtime: MainThreadGlobalThis): 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 { callLepusMethodEndpoint } from '@lynx-js/web-constants';
|
|
4
|
+
import { callLepusMethodEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
export function registerCallLepusMethodHandler(rpc, runtime) {
|
|
6
6
|
rpc.registerHandler(callLepusMethodEndpoint, (methodName, data) => {
|
|
7
7
|
(runtime[methodName])(data);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { prepareMainThreadAPIs } from './prepareMainThreadAPIs.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './createMainThreadGlobalThis.js';
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
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
4
|
export { prepareMainThreadAPIs } from './prepareMainThreadAPIs.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './createMainThreadGlobalThis.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint } from '@lynx-js/web-constants';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
startMainThread: (config: StartMainThreadContextConfig) => Promise<MainThreadRuntime>;
|
|
1
|
+
import { type Rpc, type StartMainThreadContextConfig, type RpcCallType, type reportErrorEndpoint, type MainThreadGlobalThis, type I18nResourceTranslationOptions, type InitI18nResources, type I18nResources } from '@lynx-js/web-constants';
|
|
2
|
+
export declare function prepareMainThreadAPIs(backgroundThreadRpc: Rpc, rootDom: Document | ShadowRoot, createElement: Document['createElement'], commitDocument: () => Promise<void> | void, markTimingInternal: (timingKey: string, pipelineId?: string) => void, reportError: RpcCallType<typeof reportErrorEndpoint>, triggerI18nResourceFallback: (options: I18nResourceTranslationOptions) => void, initialI18nResources: (data: InitI18nResources) => I18nResources): {
|
|
3
|
+
startMainThread: (config: StartMainThreadContextConfig) => Promise<MainThreadGlobalThis>;
|
|
5
4
|
};
|