@lynx-js/web-mainthread-apis 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/LICENSE.txt +202 -0
  3. package/Notice.txt +1 -0
  4. package/README.md +3 -0
  5. package/dist/MainThreadLynx.d.ts +11 -0
  6. package/dist/MainThreadLynx.js +36 -0
  7. package/dist/MainThreadRuntime.d.ts +40 -0
  8. package/dist/MainThreadRuntime.js +76 -0
  9. package/dist/elementAPI/ElementThreadElement.d.ts +72 -0
  10. package/dist/elementAPI/ElementThreadElement.js +272 -0
  11. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.d.ts +25 -0
  12. package/dist/elementAPI/attributeAndProperty/attributeAndPropertyFunctions.js +62 -0
  13. package/dist/elementAPI/domTree/domTreeFunctions.d.ts +13 -0
  14. package/dist/elementAPI/domTree/domTreeFunctions.js +52 -0
  15. package/dist/elementAPI/elementCreating/elementCreatingFunctions.d.ts +22 -0
  16. package/dist/elementAPI/elementCreating/elementCreatingFunctions.js +98 -0
  17. package/dist/elementAPI/event/eventFunctions.d.ts +14 -0
  18. package/dist/elementAPI/event/eventFunctions.js +31 -0
  19. package/dist/elementAPI/style/cssPropertyMap.d.ts +13 -0
  20. package/dist/elementAPI/style/cssPropertyMap.js +228 -0
  21. package/dist/elementAPI/style/styleFunctions.d.ts +7 -0
  22. package/dist/elementAPI/style/styleFunctions.js +65 -0
  23. package/dist/elementAPI/style/transformInlineStyle.d.ts +8 -0
  24. package/dist/elementAPI/style/transformInlineStyle.js +42 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +6 -0
  27. package/dist/utils/decodeCssInJs.d.ts +8 -0
  28. package/dist/utils/decodeCssInJs.js +23 -0
  29. package/dist/utils/processStyleInfo.d.ts +14 -0
  30. package/dist/utils/processStyleInfo.js +119 -0
  31. package/package.json +26 -0
@@ -0,0 +1,272 @@
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 { componentIdAttribute, cssIdAttribute, OperationType, } from '@lynx-js/web-constants';
5
+ function getParentIdx(element, parent) {
6
+ parent = parent ?? element.parent;
7
+ const idx = parent.children.findIndex((e) => e === element);
8
+ if (idx === -1) {
9
+ console.error(`[lynx-web]`, element, ` is not a child of`, parent);
10
+ throw new Error(`[lynx-web] ${element} is not a child of ${parent}`);
11
+ }
12
+ return idx;
13
+ }
14
+ export var RefCountType;
15
+ (function (RefCountType) {
16
+ RefCountType[RefCountType["Element"] = 0] = "Element";
17
+ })(RefCountType || (RefCountType = {}));
18
+ export class ElementThreadElement {
19
+ tag;
20
+ uniqueId;
21
+ parentComponentUniqueId;
22
+ pageConfig;
23
+ operationsRef;
24
+ styleInfo;
25
+ static uniqueIdToElement = [];
26
+ static receiveEvent(event) {
27
+ const currentTargetUniqueId = event.currentTarget.uniqueId;
28
+ const target = this.uniqueIdToElement[currentTargetUniqueId]?.deref();
29
+ if (target) {
30
+ const handler = target.eventHandlerMap[event.type]?.handler;
31
+ if (typeof handler === 'function') {
32
+ queueMicrotask(() => {
33
+ handler(event);
34
+ });
35
+ }
36
+ }
37
+ else {
38
+ this.uniqueIdToElement[currentTargetUniqueId] = undefined;
39
+ }
40
+ }
41
+ static getElementByUniqueId(uniqueId) {
42
+ return ElementThreadElement.uniqueIdToElement[uniqueId]?.deref();
43
+ }
44
+ type = RefCountType.Element;
45
+ eventHandlerMap = {};
46
+ attributes;
47
+ property = {
48
+ componentConfig: {},
49
+ dataset: {},
50
+ };
51
+ children = [];
52
+ parent;
53
+ constructor(tag, uniqueId, parentComponentUniqueId, pageConfig, operationsRef, styleInfo) {
54
+ this.tag = tag;
55
+ this.uniqueId = uniqueId;
56
+ this.parentComponentUniqueId = parentComponentUniqueId;
57
+ this.pageConfig = pageConfig;
58
+ this.operationsRef = operationsRef;
59
+ this.styleInfo = styleInfo;
60
+ this.attributes = {
61
+ style: null,
62
+ class: '',
63
+ [cssIdAttribute]: null,
64
+ };
65
+ ElementThreadElement.uniqueIdToElement[this.uniqueId] = new WeakRef(this);
66
+ operationsRef.operations.push({
67
+ type: OperationType.Create,
68
+ uid: uniqueId,
69
+ tag: tag,
70
+ puid: parentComponentUniqueId.toString(),
71
+ });
72
+ }
73
+ setProperty(key, value) {
74
+ this.property[key] = value;
75
+ if (key === 'dataset') {
76
+ this.operationsRef.operations.push({
77
+ uid: this.uniqueId,
78
+ type: OperationType.SetProperty,
79
+ key: key,
80
+ value: value,
81
+ });
82
+ }
83
+ }
84
+ setDatasetProperty(key, value) {
85
+ this.property.dataset[key] = value;
86
+ this.operationsRef.operations.push({
87
+ uid: this.uniqueId,
88
+ type: OperationType.SetDatasetProperty,
89
+ key,
90
+ value,
91
+ });
92
+ }
93
+ setAttribute(key, value) {
94
+ this.attributes[key] = value;
95
+ this.operationsRef.operations.push({
96
+ uid: this.uniqueId,
97
+ type: OperationType.SetAttribute,
98
+ key,
99
+ value,
100
+ });
101
+ }
102
+ getAttribute(key) {
103
+ return this.attributes[key];
104
+ }
105
+ appendChild(children) {
106
+ this.children.push(...children);
107
+ for (const kid of children) {
108
+ if (kid.parent) {
109
+ // note that Node.appendChild() will do `move node` Implicitly.
110
+ const idx = getParentIdx(kid);
111
+ kid.parent.children.splice(idx, 1);
112
+ }
113
+ kid.parent = this;
114
+ }
115
+ this.operationsRef.operations.push({
116
+ uid: this.uniqueId,
117
+ type: OperationType.Append,
118
+ cid: children.map(e => e.uniqueId),
119
+ });
120
+ }
121
+ removeChild(child) {
122
+ const idx = getParentIdx(child, this);
123
+ this.children.splice(idx, 1);
124
+ child.parent = undefined;
125
+ this.operationsRef.operations.push({
126
+ type: OperationType.Remove,
127
+ uid: this.uniqueId,
128
+ cid: [child.uniqueId],
129
+ });
130
+ return child;
131
+ }
132
+ replaceWithElements(newElements) {
133
+ for (const kid of newElements) {
134
+ if (this.parent === kid) {
135
+ console.error(`[lynx-web] cannot replace the element`, this, `by its parent`, kid);
136
+ throw new Error(`[lynx-web] cannot replace `);
137
+ }
138
+ }
139
+ const parent = this.parent;
140
+ if (parent) {
141
+ const currentPosition = getParentIdx(this);
142
+ parent.children.splice(currentPosition, 1);
143
+ this.parent = undefined;
144
+ for (const kid of newElements) {
145
+ if (kid.parent) {
146
+ const idx = getParentIdx(kid);
147
+ kid.parent.children.splice(idx, 1);
148
+ }
149
+ kid.parent = parent;
150
+ }
151
+ parent.children.splice(currentPosition, 0, ...newElements);
152
+ this.operationsRef.operations.push({
153
+ type: OperationType.Replace,
154
+ uid: this.uniqueId,
155
+ nid: newElements.map(e => e.uniqueId),
156
+ });
157
+ }
158
+ }
159
+ swapWith(elementB) {
160
+ const parentA = this.parent;
161
+ const parentB = elementB.parent;
162
+ const idxA = getParentIdx(this);
163
+ const idxB = getParentIdx(elementB);
164
+ parentA.children[idxA] = elementB;
165
+ elementB.parent = parentA;
166
+ parentB.children[idxB] = this;
167
+ this.parent = parentB;
168
+ this.operationsRef.operations.push({
169
+ type: OperationType.SwapElement,
170
+ uid: this.uniqueId,
171
+ tid: elementB.uniqueId,
172
+ });
173
+ }
174
+ insertBefore(child, ref) {
175
+ if (ref) {
176
+ const idx = getParentIdx(ref, this);
177
+ this.children.splice(idx, 0, child);
178
+ child.parent = this;
179
+ this.operationsRef.operations.push({
180
+ type: OperationType.InsertBefore,
181
+ uid: this.uniqueId,
182
+ cid: child.uniqueId,
183
+ ref: ref.uniqueId,
184
+ });
185
+ }
186
+ else {
187
+ this.children.push(child);
188
+ child.parent = this;
189
+ this.operationsRef.operations.push({
190
+ type: OperationType.Append,
191
+ uid: this.uniqueId,
192
+ cid: [child.uniqueId],
193
+ });
194
+ }
195
+ return child;
196
+ }
197
+ updateCssInJsGeneratedStyle(classStyleStr) {
198
+ this.operationsRef.operations.push({
199
+ type: OperationType.UpdateCssInJs,
200
+ uid: this.uniqueId,
201
+ classStyleStr,
202
+ });
203
+ }
204
+ setStyleProperty(key, value, important) {
205
+ this.attributes.style = (this.attributes.style ?? '')
206
+ + `${key}:${value ?? ''}${important ? '!important' : ''};`;
207
+ this.operationsRef.operations.push({
208
+ type: OperationType.SetStyleProperty,
209
+ uid: this.uniqueId,
210
+ key,
211
+ value,
212
+ im: important,
213
+ });
214
+ }
215
+ setEventHandler(ename, handler, eventType) {
216
+ let hname;
217
+ if (handler) {
218
+ this.eventHandlerMap[ename] = { type: eventType, handler };
219
+ if (typeof handler === 'function') {
220
+ hname = null;
221
+ }
222
+ else {
223
+ hname = handler;
224
+ }
225
+ }
226
+ else {
227
+ this.eventHandlerMap[ename] = undefined;
228
+ }
229
+ this.operationsRef.operations.push({
230
+ type: OperationType.RegisterEventHandler,
231
+ uid: this.uniqueId,
232
+ eventType,
233
+ hname,
234
+ ename,
235
+ });
236
+ }
237
+ get firstElementChild() {
238
+ return this.children[0];
239
+ }
240
+ get lastElementChild() {
241
+ const childLength = this.children.length;
242
+ return childLength > 0 ? this.children[childLength - 1] : undefined;
243
+ }
244
+ get nextElementSibling() {
245
+ if (this.parent) {
246
+ const idx = getParentIdx(this);
247
+ return this.parent.children[idx + 1];
248
+ }
249
+ return;
250
+ }
251
+ }
252
+ export class ListElement extends ElementThreadElement {
253
+ componentAtIndex;
254
+ enqueueComponent;
255
+ setAttribute(key, value) {
256
+ if (key === 'update-list-info' && value) {
257
+ const listInfo = value;
258
+ const { insertAction, removeAction } = listInfo;
259
+ queueMicrotask(() => {
260
+ for (const action of insertAction) {
261
+ this.componentAtIndex(this, this.uniqueId, action.position, 0, false);
262
+ }
263
+ for (const action of removeAction) {
264
+ this.enqueueComponent(this, this.uniqueId, action.position);
265
+ }
266
+ });
267
+ value = value.toString();
268
+ }
269
+ super.setAttribute(key, value);
270
+ }
271
+ }
272
+ //# sourceMappingURL=ElementThreadElement.js.map
@@ -0,0 +1,25 @@
1
+ import { type ElementThreadElement, type ComponentAtIndexCallback, type EnqueueComponentCallback, type ListElement } from '../ElementThreadElement.js';
2
+ export declare function __AddConfig(element: ElementThreadElement, type: string, value: any): void;
3
+ export declare function __AddDataset(element: ElementThreadElement, key: string, value: string | number | Record<string, any>): void;
4
+ export declare function __GetAttributes(element: ElementThreadElement): {
5
+ [key: string]: string | null | undefined;
6
+ id?: string;
7
+ style: string | null;
8
+ class: string | null;
9
+ "lynx-component-id"?: string;
10
+ "lynx-css-id": string | null;
11
+ };
12
+ export declare function __GetComponentID(element: ElementThreadElement): string | undefined;
13
+ export declare function __GetDataByKey(element: ElementThreadElement, key: string): unknown;
14
+ export declare function __GetDataset(element: ElementThreadElement): Record<string, any>;
15
+ export declare function __GetElementConfig(element: ElementThreadElement): Record<string, unknown>;
16
+ export declare function __GetElementUniqueID(element: ElementThreadElement | unknown): number;
17
+ export declare function __GetID(element: ElementThreadElement): string;
18
+ export declare function __GetTag(element: ElementThreadElement): string;
19
+ export declare function __SetAttribute(element: ElementThreadElement, key: string, value: string | null | undefined): void;
20
+ export declare function __SetConfig(element: ElementThreadElement, config: Record<string, any>): void;
21
+ export declare function __SetDataset(element: ElementThreadElement, dataset: Record<string, any>): void;
22
+ export declare function __SetID(element: ElementThreadElement, id: string): void;
23
+ export declare function __UpdateComponentID(element: ElementThreadElement, componentID: string): void;
24
+ export declare function __GetConfig(element: ElementThreadElement): Record<string, unknown>;
25
+ export declare function __UpdateListCallbacks(list: ListElement, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback): void;
@@ -0,0 +1,62 @@
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 { componentIdAttribute } from '@lynx-js/web-constants';
5
+ import { RefCountType, } from '../ElementThreadElement.js';
6
+ export function __AddConfig(element, type, value) {
7
+ element.property.componentConfig[type] = value;
8
+ }
9
+ export function __AddDataset(element, key, value) {
10
+ element.setDatasetProperty(key, value);
11
+ }
12
+ export function __GetAttributes(element) {
13
+ return element.attributes;
14
+ }
15
+ export function __GetComponentID(element) {
16
+ return element.attributes[componentIdAttribute];
17
+ }
18
+ export function __GetDataByKey(element, key) {
19
+ return element.property.dataset[key];
20
+ }
21
+ export function __GetDataset(element) {
22
+ return element.property.dataset;
23
+ }
24
+ export function __GetElementConfig(element) {
25
+ return element.property.componentConfig;
26
+ }
27
+ export function __GetElementUniqueID(element) {
28
+ if (element && typeof element === 'object'
29
+ && element.type === RefCountType.Element) {
30
+ return element.uniqueId;
31
+ }
32
+ return -1;
33
+ }
34
+ export function __GetID(element) {
35
+ return element.attributes.id ?? '';
36
+ }
37
+ export function __GetTag(element) {
38
+ return element.tag;
39
+ }
40
+ export function __SetAttribute(element, key, value) {
41
+ element.setAttribute(key, value ?? null);
42
+ }
43
+ export function __SetConfig(element, config) {
44
+ element.property.componentConfig = config;
45
+ }
46
+ export function __SetDataset(element, dataset) {
47
+ element.setProperty('dataset', dataset);
48
+ }
49
+ export function __SetID(element, id) {
50
+ element.setAttribute('id', id);
51
+ }
52
+ export function __UpdateComponentID(element, componentID) {
53
+ __SetAttribute(element, componentIdAttribute, componentID);
54
+ }
55
+ export function __GetConfig(element) {
56
+ return element.property.componentConfig;
57
+ }
58
+ export function __UpdateListCallbacks(list, componentAtIndex, enqueueComponent) {
59
+ list.componentAtIndex = componentAtIndex;
60
+ list.enqueueComponent = enqueueComponent;
61
+ }
62
+ //# sourceMappingURL=attributeAndPropertyFunctions.js.map
@@ -0,0 +1,13 @@
1
+ import type { ElementThreadElement } from '../ElementThreadElement.js';
2
+ export declare function __AppendElement(parent: ElementThreadElement, child: ElementThreadElement): void;
3
+ export declare function __ElementIsEqual(left: ElementThreadElement, right: ElementThreadElement): boolean;
4
+ export declare function __FirstElement(element: ElementThreadElement): ElementThreadElement | undefined;
5
+ export declare function __GetChildren(element: ElementThreadElement): ElementThreadElement[];
6
+ export declare function __GetParent(element: ElementThreadElement): ElementThreadElement | undefined;
7
+ export declare function __InsertElementBefore(parent: ElementThreadElement, child: ElementThreadElement, ref: ElementThreadElement | null): ElementThreadElement;
8
+ export declare function __LastElement(element: ElementThreadElement): ElementThreadElement | undefined;
9
+ export declare function __NextElement(element: ElementThreadElement): ElementThreadElement | undefined;
10
+ export declare function __RemoveElement(parent: ElementThreadElement, child: ElementThreadElement): ElementThreadElement;
11
+ export declare function __ReplaceElement(newElement: ElementThreadElement, oldElement: ElementThreadElement): void;
12
+ export declare function __ReplaceElements(parent: ElementThreadElement, newChildren: ElementThreadElement[] | ElementThreadElement, oldChildren: ElementThreadElement[] | ElementThreadElement | null | undefined): void;
13
+ export declare function __SwapElement(childA: ElementThreadElement, childB: ElementThreadElement): void;
@@ -0,0 +1,52 @@
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;
12
+ }
13
+ export function __GetChildren(element) {
14
+ return element.children;
15
+ }
16
+ export function __GetParent(element) {
17
+ return element.parent;
18
+ }
19
+ export function __InsertElementBefore(parent, child, ref) {
20
+ return parent.insertBefore(child, ref);
21
+ }
22
+ export function __LastElement(element) {
23
+ return element.lastElementChild;
24
+ }
25
+ export function __NextElement(element) {
26
+ return element.nextElementSibling;
27
+ }
28
+ export function __RemoveElement(parent, child) {
29
+ parent.removeChild(child);
30
+ return child;
31
+ }
32
+ export function __ReplaceElement(newElement, oldElement) {
33
+ oldElement.replaceWithElements([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.appendChild(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.replaceWithElements(newChildren);
47
+ }
48
+ }
49
+ export function __SwapElement(childA, childB) {
50
+ childA.swapWith(childB);
51
+ }
52
+ //# sourceMappingURL=domTreeFunctions.js.map
@@ -0,0 +1,22 @@
1
+ import { type PageConfig, type ElementOperation, type CssInJsInfo } from '@lynx-js/web-constants';
2
+ import { type ComponentAtIndexCallback, type EnqueueComponentCallback, ListElement, ElementThreadElement } from '../ElementThreadElement.js';
3
+ export interface initializeElementCreatingFunctionConfig {
4
+ operationsRef: {
5
+ operations: ElementOperation[];
6
+ };
7
+ pageConfig: PageConfig;
8
+ onNewTag: (tag: string) => void;
9
+ styleInfo: CssInJsInfo;
10
+ }
11
+ export declare function initializeElementCreatingFunction(config: initializeElementCreatingFunctionConfig): {
12
+ __CreateView: (parentComponentUniqueId: number) => ElementThreadElement;
13
+ __CreateText: (parentComponentUniqueId: number) => ElementThreadElement;
14
+ __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) => ElementThreadElement;
15
+ __CreatePage: (componentID: string, cssID: number, info: Record<string, any> | null | undefined) => ElementThreadElement;
16
+ __CreateRawText: (text: string) => ElementThreadElement;
17
+ __CreateImage: (parentComponentUniqueId: number) => ElementThreadElement;
18
+ __CreateScrollView: (parentComponentUniqueId: number) => ElementThreadElement;
19
+ __CreateElement: (tagName: string, parentComponentUniqueId: number, info?: object) => ElementThreadElement;
20
+ __CreateWrapperElement: (parentComponentUniqueId: number) => ElementThreadElement;
21
+ __CreateList: (parentComponentUniqueId: number, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback, info?: any) => ListElement;
22
+ };
@@ -0,0 +1,98 @@
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, } from '@lynx-js/web-constants';
5
+ import { __UpdateComponentID } from '../attributeAndProperty/attributeAndPropertyFunctions.js';
6
+ import { ListElement, ElementThreadElement, } from '../ElementThreadElement.js';
7
+ import { __SetCSSId } from '../style/styleFunctions.js';
8
+ export function initializeElementCreatingFunction(config) {
9
+ let incrementalUniqueId = 0;
10
+ const tagSet = new Set();
11
+ const { operationsRef, pageConfig, styleInfo } = config;
12
+ function createLynxElement(tag, parentComponentUniqueId, cssId, componentId,
13
+ // @ts-expect-error
14
+ info) {
15
+ if (!tagSet.has(tag)) {
16
+ config.onNewTag(tag);
17
+ tagSet.add(tag);
18
+ }
19
+ const uniqueId = incrementalUniqueId++;
20
+ const element = new (tag === 'list' ? ListElement : ElementThreadElement)(tag, uniqueId, parentComponentUniqueId, pageConfig, operationsRef, styleInfo);
21
+ if (cssId !== undefined)
22
+ __SetCSSId([element], cssId);
23
+ else if (parentComponentUniqueId >= 0) { // don't infer for uniqueid === -1
24
+ const parentComponent = ElementThreadElement.getElementByUniqueId(parentComponentUniqueId);
25
+ const parentCssId = parentComponent?.getAttribute(cssIdAttribute);
26
+ if (parentCssId && parentCssId !== '0') {
27
+ __SetCSSId([element], parentCssId);
28
+ }
29
+ }
30
+ if (componentId !== undefined) {
31
+ __UpdateComponentID(element, componentId);
32
+ }
33
+ return element;
34
+ }
35
+ function __CreateComponent(componentParentUniqueID, componentID, cssID,
36
+ // @ts-expect-error
37
+ entryName, name,
38
+ // @ts-expect-error
39
+ path, config,
40
+ // @ts-expect-error
41
+ info) {
42
+ const element = createLynxElement('view', componentParentUniqueID, cssID, componentID, config);
43
+ element.setAttribute('name', name);
44
+ return element;
45
+ }
46
+ function __CreateElement(tagName, parentComponentUniqueId, info) {
47
+ return createLynxElement(tagName, parentComponentUniqueId, undefined, undefined, info);
48
+ }
49
+ function __CreatePage(componentID, cssID, info) {
50
+ const page = createLynxElement('page', 0, cssID, componentID, info);
51
+ page.parentComponentUniqueId = page.uniqueId;
52
+ return page;
53
+ }
54
+ function __CreateView(parentComponentUniqueId) {
55
+ const element = createLynxElement('view', parentComponentUniqueId);
56
+ return element;
57
+ }
58
+ function __CreateText(parentComponentUniqueId) {
59
+ const element = createLynxElement('text', parentComponentUniqueId);
60
+ return element;
61
+ }
62
+ function __CreateRawText(text) {
63
+ const element = createLynxElement('raw-text', -1);
64
+ element.setAttribute('text', text);
65
+ return element;
66
+ }
67
+ function __CreateImage(parentComponentUniqueId) {
68
+ const element = createLynxElement('image', parentComponentUniqueId);
69
+ return element;
70
+ }
71
+ function __CreateScrollView(parentComponentUniqueId) {
72
+ const element = createLynxElement('scroll-view', parentComponentUniqueId);
73
+ return element;
74
+ }
75
+ function __CreateWrapperElement(parentComponentUniqueId) {
76
+ const element = createLynxElement('lynx-wrapper', parentComponentUniqueId);
77
+ return element;
78
+ }
79
+ function __CreateList(parentComponentUniqueId, componentAtIndex, enqueueComponent, info) {
80
+ const element = createLynxElement('list', parentComponentUniqueId, undefined, undefined, info);
81
+ element.componentAtIndex = componentAtIndex;
82
+ element.enqueueComponent = enqueueComponent;
83
+ return element;
84
+ }
85
+ return {
86
+ __CreateView,
87
+ __CreateText,
88
+ __CreateComponent,
89
+ __CreatePage,
90
+ __CreateRawText,
91
+ __CreateImage,
92
+ __CreateScrollView,
93
+ __CreateElement,
94
+ __CreateWrapperElement,
95
+ __CreateList,
96
+ };
97
+ }
98
+ //# sourceMappingURL=elementCreatingFunctions.js.map
@@ -0,0 +1,14 @@
1
+ import type { LynxCrossThreadEvent, LynxEventType } from '@lynx-js/web-constants';
2
+ import type { ElementThreadElement } from '../ElementThreadElement.js';
3
+ export declare function __AddEvent(element: ElementThreadElement, eventType: LynxEventType, eventName: string, eventHandler: string | ((ev: LynxCrossThreadEvent) => void) | undefined): void;
4
+ export declare function __GetEvent(element: ElementThreadElement, eventName: string, eventType: string): string | ((ev: LynxCrossThreadEvent) => void) | undefined;
5
+ export declare function __GetEvents(element: ElementThreadElement): {
6
+ type: LynxEventType;
7
+ name: string;
8
+ function: string | ((ev: Event) => void) | undefined;
9
+ }[];
10
+ export declare function __SetEvents(element: ElementThreadElement, listeners: {
11
+ type: LynxEventType;
12
+ name: string;
13
+ function: string | ((ev: LynxCrossThreadEvent) => void) | undefined;
14
+ }[]): void;
@@ -0,0 +1,31 @@
1
+ export function __AddEvent(element, eventType, eventName, eventHandler) {
2
+ element.setEventHandler(eventName, eventHandler, eventType);
3
+ }
4
+ export function __GetEvent(element, eventName, eventType) {
5
+ const lynxEventName = eventName.toLowerCase();
6
+ const eventHandlerMap = element.eventHandlerMap;
7
+ const currentHandlerInfo = eventHandlerMap[lynxEventName];
8
+ if (currentHandlerInfo?.type === eventType) {
9
+ return currentHandlerInfo.handler;
10
+ }
11
+ return;
12
+ }
13
+ export function __GetEvents(element) {
14
+ const eventHandlerMap = element.eventHandlerMap;
15
+ return Object.entries(eventHandlerMap).map(([lynxEventName, info]) => {
16
+ if (info) {
17
+ return {
18
+ type: info.type,
19
+ function: info.handler,
20
+ name: lynxEventName,
21
+ };
22
+ }
23
+ return;
24
+ }).filter(e => e);
25
+ }
26
+ export function __SetEvents(element, listeners) {
27
+ for (const { type: eventType, name: lynxEventName, function: eventHandler } of listeners) {
28
+ __AddEvent(element, eventType, lynxEventName, eventHandler);
29
+ }
30
+ }
31
+ //# sourceMappingURL=eventFunctions.js.map
@@ -0,0 +1,13 @@
1
+ export declare function camelize(str: string): string;
2
+ declare const cssPropertyMap: Record<number, {
3
+ name: string;
4
+ dashName: string;
5
+ defaultValue: string;
6
+ }>;
7
+ export declare function queryCSSProperty(index: number): {
8
+ name: string;
9
+ defaultValue: string;
10
+ dashName: string;
11
+ };
12
+ export declare function queryCSSPropertyNumber(name: string): number;
13
+ export { cssPropertyMap };