@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/dist/createMainThreadGlobalThis.d.ts +25 -0
  3. package/dist/createMainThreadGlobalThis.js +454 -0
  4. package/dist/createMainThreadLynx.d.ts +3 -0
  5. package/dist/{MainThreadLynx.js → createMainThreadLynx.js} +2 -5
  6. package/dist/crossThreadHandlers/registerCallLepusMethodHandler.d.ts +2 -3
  7. package/dist/crossThreadHandlers/registerCallLepusMethodHandler.js +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/prepareMainThreadAPIs.d.ts +3 -4
  11. package/dist/prepareMainThreadAPIs.js +30 -16
  12. package/dist/pureElementPAPIs.d.ts +32 -0
  13. package/dist/pureElementPAPIs.js +140 -0
  14. package/dist/utils/createCrossThreadEvent.d.ts +2 -3
  15. package/dist/utils/createCrossThreadEvent.js +23 -12
  16. package/dist/utils/createExposureService.d.ts +2 -2
  17. package/dist/utils/createExposureService.js +4 -5
  18. package/dist/utils/decodeCssInJs.js +1 -1
  19. package/package.json +3 -3
  20. package/dist/MainThreadLynx.d.ts +0 -10
  21. package/dist/MainThreadRuntime.d.ts +0 -92
  22. package/dist/MainThreadRuntime.js +0 -186
  23. package/dist/elementAPI/ElementThreadElement.d.ts +0 -27
  24. package/dist/elementAPI/ElementThreadElement.js +0 -2
  25. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +0 -30
  26. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +0 -127
  27. package/dist/elementAPI/domTree/domTreeFunctions.d.ts +0 -11
  28. package/dist/elementAPI/domTree/domTreeFunctions.js +0 -49
  29. package/dist/elementAPI/elementCreating/elementCreatingFunctions.d.ts +0 -15
  30. package/dist/elementAPI/elementCreating/elementCreatingFunctions.js +0 -123
  31. package/dist/elementAPI/event/eventFunctions.d.ts +0 -25
  32. package/dist/elementAPI/event/eventFunctions.js +0 -142
  33. package/dist/elementAPI/style/styleFunctions.d.ts +0 -10
  34. package/dist/elementAPI/style/styleFunctions.js +0 -89
  35. /package/dist/{elementAPI/style → style}/cssPropertyMap.d.ts +0 -0
  36. /package/dist/{elementAPI/style → style}/cssPropertyMap.js +0 -0
  37. /package/dist/{elementAPI/style → style}/transformInlineStyle.d.ts +0 -0
  38. /package/dist/{elementAPI/style → style}/transformInlineStyle.js +0 -0
@@ -1,186 +0,0 @@
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, } from '@lynx-js/web-constants';
5
- import { globalMuteableVars } from '@lynx-js/web-constants';
6
- import { createMainThreadLynx } from './MainThreadLynx.js';
7
- import { initializeElementCreatingFunction } from './elementAPI/elementCreating/elementCreatingFunctions.js';
8
- import { createAttributeAndPropertyFunctions } from './elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js';
9
- import * as domTreeApis from './elementAPI/domTree/domTreeFunctions.js';
10
- import { createEventFunctions } from './elementAPI/event/eventFunctions.js';
11
- import { createStyleFunctions } from './elementAPI/style/styleFunctions.js';
12
- import { flattenStyleInfo, genCssContent, genCssInJsInfo, transformToWebCss, } from './utils/processStyleInfo.js';
13
- import { createExposureService } from './utils/createExposureService.js';
14
- export const elementToRuntimeInfoMap = Symbol('elementToRuntimeInfoMap');
15
- export const getElementByUniqueId = Symbol('getElementByUniqueId');
16
- export const updateCSSInJsStyle = Symbol('updateCSSInJsStyle');
17
- export const lynxUniqueIdToElement = Symbol('lynxUniqueIdToElement');
18
- export const switchExposureService = Symbol('switchExposureService');
19
- export class MainThreadRuntime {
20
- config;
21
- /**
22
- * @private
23
- */
24
- [lynxUniqueIdToElement] = [];
25
- /**
26
- * @private
27
- */
28
- [switchExposureService];
29
- /**
30
- * @private
31
- */
32
- _lynxUniqueIdToStyleSheet = [];
33
- /**
34
- * @private
35
- */
36
- _page;
37
- /**
38
- * @private the CreatePage will append it to this
39
- */
40
- _rootDom;
41
- _createElement;
42
- /**
43
- * @private
44
- */
45
- _timingFlags = [];
46
- /**
47
- * @private
48
- */
49
- [elementToRuntimeInfoMap] = new WeakMap();
50
- constructor(config) {
51
- this.config = config;
52
- this.__globalProps = config.globalProps;
53
- this.lynx = createMainThreadLynx(config);
54
- this._rootDom = config.rootDom;
55
- this._createElement = config.createElement;
56
- /**
57
- * now create the style content
58
- * 1. flatten the styleInfo
59
- * 2. transform the styleInfo to web css
60
- * 3. generate the css in js info
61
- * 4. create the style element
62
- * 5. append the style element to the root dom
63
- */
64
- flattenStyleInfo(this.config.styleInfo, this.config.pageConfig.enableCSSSelector);
65
- transformToWebCss(this.config.styleInfo);
66
- const cssInJsInfo = this.config.pageConfig.enableCSSSelector
67
- ? {}
68
- : genCssInJsInfo(this.config.styleInfo);
69
- const cardStyleElement = this._createElement('style');
70
- cardStyleElement.innerHTML = genCssContent(this.config.styleInfo, this.config.pageConfig);
71
- this._rootDom.append(cardStyleElement);
72
- /**
73
- * now create Element PAPIs
74
- */
75
- Object.assign(this, createAttributeAndPropertyFunctions(this), domTreeApis, createEventFunctions(this), createStyleFunctions(this, cssInJsInfo), initializeElementCreatingFunction(this));
76
- this._ReportError = this.config.callbacks._ReportError;
77
- this.__OnLifecycleEvent = this.config.callbacks.__OnLifecycleEvent;
78
- this.SystemInfo = {
79
- ...systemInfo,
80
- ...config.browserConfig,
81
- };
82
- /**
83
- * Start the exposure service
84
- */
85
- this[switchExposureService] =
86
- createExposureService(this).switchExposureService;
87
- /**
88
- * to know when the main thread is ready
89
- */
90
- Object.defineProperty(this, 'renderPage', {
91
- get: () => {
92
- return this.#renderPage;
93
- },
94
- set: (val) => {
95
- this.#renderPage = val;
96
- queueMicrotask(this.config.callbacks.mainChunkReady);
97
- },
98
- });
99
- for (const nm of globalMuteableVars) {
100
- Object.defineProperty(this, nm, {
101
- get: () => {
102
- return this.__lynxGlobalBindingValues[nm];
103
- },
104
- set: (v) => {
105
- this.__lynxGlobalBindingValues[nm] = v;
106
- for (const handler of this.__varsUpdateHandlers) {
107
- handler();
108
- }
109
- },
110
- });
111
- }
112
- }
113
- /**
114
- * @private
115
- */
116
- [getElementByUniqueId](uniqueId) {
117
- return this[lynxUniqueIdToElement][uniqueId]?.deref();
118
- }
119
- [updateCSSInJsStyle](uniqueId, newStyles) {
120
- let currentElement = this._lynxUniqueIdToStyleSheet[uniqueId]?.deref();
121
- if (!currentElement) {
122
- currentElement = this._createElement('style');
123
- this._lynxUniqueIdToStyleSheet[uniqueId] = new WeakRef(currentElement);
124
- this._rootDom.append(currentElement);
125
- }
126
- currentElement.innerHTML =
127
- `[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`;
128
- }
129
- /**
130
- * @private
131
- */
132
- __lynxGlobalBindingValues = {};
133
- globalThis = new Proxy(this, {
134
- get: (target, prop) => {
135
- // @ts-expect-error
136
- return target[prop] ?? globalThis[prop];
137
- },
138
- set: (target, prop, value) => {
139
- // @ts-expect-error
140
- target[prop] = value;
141
- return true;
142
- },
143
- ownKeys(target) {
144
- return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
145
- },
146
- });
147
- SystemInfo;
148
- lynx;
149
- __globalProps;
150
- processData;
151
- ssrEncode;
152
- ssrHydrate;
153
- #renderPage;
154
- __GetTemplateParts;
155
- __GetPageElement = () => {
156
- return this._page;
157
- };
158
- _ReportError;
159
- __OnLifecycleEvent;
160
- __LoadLepusChunk = (path) => {
161
- const lepusModule = this.config.lepusCode[`${path}`];
162
- if (lepusModule) {
163
- const entry = lepusModule.exports;
164
- entry?.(this);
165
- return true;
166
- }
167
- else {
168
- return false;
169
- }
170
- };
171
- __FlushElementTree = (_subTree, options) => {
172
- const timingFlags = this._timingFlags;
173
- this._timingFlags = [];
174
- if (this._page && !this._page.parentNode) {
175
- this._rootDom.append(this._page);
176
- }
177
- this.config.callbacks.flushElementTree(options, timingFlags);
178
- };
179
- updatePage;
180
- runWorklet;
181
- __varsUpdateHandlers = [];
182
- set _updateVars(handler) {
183
- this.__varsUpdateHandlers.push(handler);
184
- }
185
- }
186
- //# sourceMappingURL=MainThreadRuntime.js.map
@@ -1,27 +0,0 @@
1
- import type { LynxEventType, Cloneable } from '@lynx-js/web-constants';
2
- export interface LynxRuntimeInfo {
3
- uniqueId: number;
4
- parentComponentUniqueId: number;
5
- componentConfig: Record<string, Cloneable>;
6
- lynxDataset: Record<string, Cloneable>;
7
- eventHandlerMap: Record<string, {
8
- capture: {
9
- type: LynxEventType;
10
- handler: string | {
11
- type: 'worklet';
12
- value: unknown;
13
- };
14
- } | undefined;
15
- bind: {
16
- type: LynxEventType;
17
- handler: string | {
18
- type: 'worklet';
19
- value: unknown;
20
- };
21
- } | undefined;
22
- }>;
23
- componentAtIndex?: ComponentAtIndexCallback;
24
- enqueueComponent?: EnqueueComponentCallback;
25
- }
26
- export type ComponentAtIndexCallback = (list: HTMLElement, listID: number, cellIndex: number, operationID: number, enableReuseNotification: boolean) => void;
27
- export type EnqueueComponentCallback = (list: HTMLElement, listID: number, sign: number) => void;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ElementThreadElement.js.map
@@ -1,30 +0,0 @@
1
- import { type ComponentAtIndexCallback, type EnqueueComponentCallback } from '../ElementThreadElement.js';
2
- import { type MainThreadRuntime } from '../../MainThreadRuntime.js';
3
- type UpdateListInfoAttributeValue = {
4
- insertAction: {
5
- position: number;
6
- }[];
7
- removeAction: {
8
- position: number;
9
- }[];
10
- };
11
- export declare function createAttributeAndPropertyFunctions(runtime: MainThreadRuntime): {
12
- __AddConfig: (element: HTMLElement, type: string, value: any) => void;
13
- __AddDataset: (element: HTMLElement, key: string, value: string | number | Record<string, any>) => void;
14
- __GetAttributes: (element: HTMLElement) => Record<string, string | null>;
15
- __GetComponentID: (element: HTMLElement) => string | null;
16
- __GetDataByKey: (element: HTMLElement, key: string) => import("@lynx-js/web-constants").Cloneable;
17
- __GetDataset: (element: HTMLElement) => Record<string, any>;
18
- __GetElementConfig: (element: HTMLElement) => Record<string, import("@lynx-js/web-constants").Cloneable>;
19
- __GetElementUniqueID: (element: HTMLElement) => number;
20
- __GetID: (element: HTMLElement) => string;
21
- __GetTag: (element: HTMLElement) => string;
22
- __SetConfig: (element: HTMLElement, config: Record<string, any>) => void;
23
- __SetDataset: (element: HTMLElement, dataset: Record<string, any>) => void;
24
- __SetID: (element: HTMLElement, id: string | null) => void;
25
- __UpdateComponentID: (element: HTMLElement, componentID: string) => void;
26
- __UpdateListCallbacks: (element: HTMLElement, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback) => void;
27
- __GetConfig: (element: HTMLElement) => Record<string, import("@lynx-js/web-constants").Cloneable>;
28
- __SetAttribute: (element: HTMLElement, key: string, value: string | null | undefined | UpdateListInfoAttributeValue) => void;
29
- };
30
- export {};
@@ -1,127 +0,0 @@
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 { __lynx_timing_flag, componentIdAttribute, lynxTagAttribute, } from '@lynx-js/web-constants';
5
- import {} from '../ElementThreadElement.js';
6
- import { elementToRuntimeInfoMap, } from '../../MainThreadRuntime.js';
7
- function setDatasetAttribute(element, key, value) {
8
- if (value !== null && value !== undefined) {
9
- if (typeof value === 'object') {
10
- element.setAttribute('data-' + key, JSON.stringify(value));
11
- }
12
- else {
13
- element.setAttribute('data-' + key, value.toString());
14
- }
15
- }
16
- }
17
- export function createAttributeAndPropertyFunctions(runtime) {
18
- function __AddConfig(element, type, value) {
19
- runtime[elementToRuntimeInfoMap].get(element).componentConfig[type] =
20
- value;
21
- }
22
- function __AddDataset(element, key, value) {
23
- runtime[elementToRuntimeInfoMap].get(element).lynxDataset[key] = value;
24
- setDatasetAttribute(element, key, value);
25
- }
26
- function __GetAttributes(element) {
27
- return Object.fromEntries(element.getAttributeNames().map((attributeName) => [attributeName, element.getAttribute(attributeName)]));
28
- }
29
- function __GetComponentID(element) {
30
- return element.getAttribute(componentIdAttribute);
31
- }
32
- function __GetDataByKey(element, key) {
33
- return runtime[elementToRuntimeInfoMap].get(element).lynxDataset[key];
34
- }
35
- function __GetDataset(element) {
36
- return runtime[elementToRuntimeInfoMap].get(element).lynxDataset;
37
- }
38
- function __GetElementConfig(element) {
39
- return runtime[elementToRuntimeInfoMap].get(element).componentConfig;
40
- }
41
- function __GetElementUniqueID(element) {
42
- return runtime[elementToRuntimeInfoMap].get(element)?.uniqueId ?? -1;
43
- }
44
- function __GetID(element) {
45
- return element.id;
46
- }
47
- function __GetTag(element) {
48
- return element.getAttribute(lynxTagAttribute);
49
- }
50
- function __SetConfig(element, config) {
51
- runtime[elementToRuntimeInfoMap].get(element).componentConfig = config;
52
- }
53
- function __SetDataset(element, dataset) {
54
- runtime[elementToRuntimeInfoMap].get(element).lynxDataset = dataset;
55
- for (const [key, value] of Object.entries(dataset)) {
56
- setDatasetAttribute(element, key, value);
57
- }
58
- }
59
- function __SetID(element, id) {
60
- if (typeof id === 'string') {
61
- element.id = id;
62
- }
63
- else {
64
- element.removeAttribute('id');
65
- }
66
- }
67
- function __UpdateComponentID(element, componentID) {
68
- element.setAttribute(componentIdAttribute, componentID);
69
- }
70
- function __GetConfig(element) {
71
- return runtime[elementToRuntimeInfoMap].get(element).componentConfig;
72
- }
73
- function __UpdateListCallbacks(element, componentAtIndex, enqueueComponent) {
74
- runtime[elementToRuntimeInfoMap].get(element).componentAtIndex =
75
- componentAtIndex;
76
- runtime[elementToRuntimeInfoMap].get(element).enqueueComponent =
77
- enqueueComponent;
78
- }
79
- function __SetAttribute(element, key, value) {
80
- if (value === null || value === undefined) {
81
- element.removeAttribute(key);
82
- }
83
- else {
84
- if (__GetTag(element) === 'list' && key === 'update-list-info') {
85
- const listInfo = value;
86
- const { insertAction, removeAction } = listInfo;
87
- queueMicrotask(() => {
88
- const runtimeInfo = runtime[elementToRuntimeInfoMap].get(element);
89
- const componentAtIndex = runtimeInfo.componentAtIndex;
90
- const enqueueComponent = runtimeInfo.enqueueComponent;
91
- for (const action of insertAction) {
92
- componentAtIndex?.(element, runtimeInfo.uniqueId, action.position, 0, false);
93
- }
94
- for (const action of removeAction) {
95
- enqueueComponent?.(element, runtimeInfo.uniqueId, action.position);
96
- }
97
- });
98
- }
99
- else {
100
- element.setAttribute(key, value.toString());
101
- }
102
- }
103
- if (key === __lynx_timing_flag && value) {
104
- runtime._timingFlags.push(value);
105
- }
106
- }
107
- return {
108
- __AddConfig,
109
- __AddDataset,
110
- __GetAttributes,
111
- __GetComponentID,
112
- __GetDataByKey,
113
- __GetDataset,
114
- __GetElementConfig,
115
- __GetElementUniqueID,
116
- __GetID,
117
- __GetTag,
118
- __SetConfig,
119
- __SetDataset,
120
- __SetID,
121
- __UpdateComponentID,
122
- __UpdateListCallbacks,
123
- __GetConfig,
124
- __SetAttribute,
125
- };
126
- }
127
- //# sourceMappingURL=attributeAndPropertyFunctions.js.map
@@ -1,11 +0,0 @@
1
- export declare function __AppendElement(parent: HTMLElement, child: HTMLElement): void;
2
- export declare function __ElementIsEqual(left: HTMLElement, right: HTMLElement): boolean;
3
- export declare function __FirstElement(element: HTMLElement): HTMLElement | undefined;
4
- export declare function __GetChildren(element: HTMLElement): HTMLElement[];
5
- export declare function __GetParent(element: HTMLElement): HTMLElement | undefined;
6
- export declare function __InsertElementBefore(parent: HTMLElement, child: HTMLElement, ref: HTMLElement | null): HTMLElement;
7
- export declare function __LastElement(element: HTMLElement): HTMLElement | undefined;
8
- export declare function __NextElement(element: HTMLElement): HTMLElement | undefined;
9
- export declare function __RemoveElement(parent: HTMLElement, child: HTMLElement): HTMLElement;
10
- export declare function __ReplaceElement(newElement: HTMLElement, oldElement: HTMLElement): void;
11
- export declare function __ReplaceElements(parent: HTMLElement, newChildren: HTMLElement[] | HTMLElement, oldChildren: HTMLElement[] | HTMLElement | null | undefined): void;
@@ -1,49 +0,0 @@
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 function __AppendElement(parent, child) {
5
- parent.appendChild(child);
6
- }
7
- export function __ElementIsEqual(left, right) {
8
- return left === right;
9
- }
10
- export function __FirstElement(element) {
11
- return element.firstElementChild || undefined;
12
- }
13
- export function __GetChildren(element) {
14
- return element.children;
15
- }
16
- export function __GetParent(element) {
17
- return element.parentElement || undefined;
18
- }
19
- export function __InsertElementBefore(parent, child, ref) {
20
- return parent.insertBefore(child, ref);
21
- }
22
- export function __LastElement(element) {
23
- return element.lastElementChild || undefined;
24
- }
25
- export function __NextElement(element) {
26
- return element.nextElementSibling || undefined;
27
- }
28
- export function __RemoveElement(parent, child) {
29
- parent.removeChild(child);
30
- return child;
31
- }
32
- export function __ReplaceElement(newElement, oldElement) {
33
- oldElement.replaceWith(newElement);
34
- }
35
- export function __ReplaceElements(parent, newChildren, oldChildren) {
36
- newChildren = Array.isArray(newChildren) ? newChildren : [newChildren];
37
- if (!oldChildren || (Array.isArray(oldChildren) && oldChildren?.length === 0)) {
38
- parent.append(...newChildren);
39
- }
40
- else {
41
- oldChildren = Array.isArray(oldChildren) ? oldChildren : [oldChildren];
42
- for (let ii = 1; ii < oldChildren.length; ii++) {
43
- __RemoveElement(parent, oldChildren[ii]);
44
- }
45
- const firstOldChildren = oldChildren[0];
46
- firstOldChildren.replaceWith(...newChildren);
47
- }
48
- }
49
- //# sourceMappingURL=domTreeFunctions.js.map
@@ -1,15 +0,0 @@
1
- import { type ComponentAtIndexCallback, type EnqueueComponentCallback } from '../ElementThreadElement.js';
2
- import { type MainThreadRuntime } from '../../MainThreadRuntime.js';
3
- export declare function initializeElementCreatingFunction(runtime: MainThreadRuntime): {
4
- __CreateView: (parentComponentUniqueId: number) => HTMLElement;
5
- __CreateText: (parentComponentUniqueId: number) => HTMLElement;
6
- __CreateComponent: (componentParentUniqueID: number, componentID: string, cssID: number, entryName: string, name: string, path: string, config: Record<string, any> | null | undefined, info: Record<string, any> | null | undefined) => HTMLElement;
7
- __CreatePage: (componentID: string, cssID: number, info: Record<string, any> | null | undefined) => HTMLElement;
8
- __CreateRawText: (text: string) => HTMLElement;
9
- __CreateImage: (parentComponentUniqueId: number) => HTMLElement;
10
- __CreateScrollView: (parentComponentUniqueId: number) => HTMLElement;
11
- __CreateElement: (tagName: string, parentComponentUniqueId: number, info?: object) => HTMLElement;
12
- __CreateWrapperElement: (parentComponentUniqueId: number) => HTMLElement;
13
- __CreateList: (parentComponentUniqueId: number, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback, info?: any) => HTMLElement;
14
- __SwapElement: (childA: HTMLElement, childB: HTMLElement) => void;
15
- };
@@ -1,123 +0,0 @@
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, lynxUniqueIdAttribute, lynxTagAttribute, lynxDefaultDisplayLinearAttribute, } from '@lynx-js/web-constants';
5
- import {} from '../ElementThreadElement.js';
6
- import { elementToRuntimeInfoMap, getElementByUniqueId, lynxUniqueIdToElement, } from '../../MainThreadRuntime.js';
7
- export function initializeElementCreatingFunction(runtime) {
8
- let uniqueIdInc = 1;
9
- function createLynxElement(tag, parentComponentUniqueId, cssId, componentId,
10
- // @ts-expect-error
11
- info) {
12
- // @ts-expect-error
13
- const __SetCSSId = runtime.__SetCSSId;
14
- const htmlTag = runtime.config.tagMap[tag] ?? tag;
15
- const element = runtime._createElement(htmlTag);
16
- element.setAttribute(lynxTagAttribute, tag);
17
- const uniqueId = uniqueIdInc++;
18
- const runtimeInfo = {
19
- uniqueId,
20
- componentConfig: {},
21
- lynxDataset: {},
22
- eventHandlerMap: {},
23
- parentComponentUniqueId,
24
- };
25
- runtime[elementToRuntimeInfoMap].set(element, runtimeInfo);
26
- runtime[lynxUniqueIdToElement][uniqueId] = new WeakRef(element);
27
- element.setAttribute(lynxUniqueIdAttribute, uniqueId.toString());
28
- if (cssId !== undefined)
29
- __SetCSSId([element], cssId);
30
- else if (parentComponentUniqueId >= 0) { // don't infer for uniqueid === -1
31
- const parentComponent = runtime[getElementByUniqueId](parentComponentUniqueId);
32
- const parentCssId = parentComponent?.getAttribute(cssIdAttribute);
33
- if (parentCssId && parentCssId !== '0') {
34
- __SetCSSId([element], parentCssId);
35
- }
36
- }
37
- if (componentId !== undefined) {
38
- // @ts-expect-error
39
- runtime.__UpdateComponentID(element, componentId);
40
- }
41
- return element;
42
- }
43
- function __CreateComponent(componentParentUniqueID, componentID, cssID,
44
- // @ts-expect-error
45
- entryName, name,
46
- // @ts-expect-error
47
- path, config,
48
- // @ts-expect-error
49
- info) {
50
- const element = createLynxElement('view', componentParentUniqueID, cssID, componentID, config);
51
- element.setAttribute('name', name);
52
- return element;
53
- }
54
- function __CreateElement(tagName, parentComponentUniqueId, info) {
55
- return createLynxElement(tagName, parentComponentUniqueId, undefined, undefined, info);
56
- }
57
- function __CreatePage(componentID, cssID, info) {
58
- const page = createLynxElement('page', 0, cssID, componentID, info);
59
- page.setAttribute('part', 'page');
60
- const runtimeInfo = runtime[elementToRuntimeInfoMap].get(page);
61
- runtimeInfo.parentComponentUniqueId = runtimeInfo.uniqueId;
62
- if (runtime.config.pageConfig.defaultDisplayLinear === false) {
63
- page.setAttribute(lynxDefaultDisplayLinearAttribute, 'false');
64
- }
65
- if (runtime.config.pageConfig.defaultOverflowVisible === true) {
66
- page.setAttribute('lynx-default-overflow-visible', 'true');
67
- }
68
- runtime._page = page;
69
- return page;
70
- }
71
- function __CreateView(parentComponentUniqueId) {
72
- const element = createLynxElement('view', parentComponentUniqueId);
73
- return element;
74
- }
75
- function __CreateText(parentComponentUniqueId) {
76
- const element = createLynxElement('text', parentComponentUniqueId);
77
- return element;
78
- }
79
- function __CreateRawText(text) {
80
- const element = createLynxElement('raw-text', -1);
81
- element.setAttribute('text', text);
82
- return element;
83
- }
84
- function __CreateImage(parentComponentUniqueId) {
85
- const element = createLynxElement('image', parentComponentUniqueId);
86
- return element;
87
- }
88
- function __CreateScrollView(parentComponentUniqueId) {
89
- const element = createLynxElement('scroll-view', parentComponentUniqueId);
90
- return element;
91
- }
92
- function __CreateWrapperElement(parentComponentUniqueId) {
93
- const element = createLynxElement('lynx-wrapper', parentComponentUniqueId);
94
- return element;
95
- }
96
- function __CreateList(parentComponentUniqueId, componentAtIndex, enqueueComponent, info) {
97
- const element = createLynxElement('list', parentComponentUniqueId, undefined, undefined, info);
98
- const runtimeInfo = runtime[elementToRuntimeInfoMap].get(element);
99
- runtimeInfo.componentAtIndex = componentAtIndex;
100
- runtimeInfo.enqueueComponent = enqueueComponent;
101
- return element;
102
- }
103
- function __SwapElement(childA, childB) {
104
- const temp = runtime._createElement('div');
105
- childA.replaceWith(temp);
106
- childB.replaceWith(childA);
107
- temp.replaceWith(childB);
108
- }
109
- return {
110
- __CreateView,
111
- __CreateText,
112
- __CreateComponent,
113
- __CreatePage,
114
- __CreateRawText,
115
- __CreateImage,
116
- __CreateScrollView,
117
- __CreateElement,
118
- __CreateWrapperElement,
119
- __CreateList,
120
- __SwapElement,
121
- };
122
- }
123
- //# sourceMappingURL=elementCreatingFunctions.js.map
@@ -1,25 +0,0 @@
1
- import { type LynxEventType } from '@lynx-js/web-constants';
2
- import { type MainThreadRuntime } from '../../MainThreadRuntime.js';
3
- export declare function createEventFunctions(runtime: MainThreadRuntime): {
4
- __AddEvent: (element: HTMLElement, eventType: LynxEventType, eventName: string, newEventHandler: string | {
5
- type: "worklet";
6
- value: unknown;
7
- } | undefined) => void;
8
- __GetEvent: (element: HTMLElement, eventName: string, eventType: LynxEventType) => string | {
9
- type: "worklet";
10
- value: unknown;
11
- } | undefined;
12
- __GetEvents: (element: HTMLElement) => {
13
- type: LynxEventType;
14
- name: string;
15
- function: string | {
16
- type: "worklet";
17
- value: unknown;
18
- } | undefined;
19
- }[];
20
- __SetEvents: (element: HTMLElement, listeners: {
21
- type: LynxEventType;
22
- name: string;
23
- function: string | undefined;
24
- }[]) => void;
25
- };