onejs-core 0.3.43 → 0.3.45
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/definitions/Assemblies/OneJS.Runtime.d.ts +2 -0
- package/definitions/globals.d.ts +2 -2
- package/dist/dom/dom.d.ts +17 -0
- package/dist/dom/dom.js +123 -0
- package/dist/dom/selector.d.ts +0 -0
- package/dist/dom/selector.js +0 -0
- package/dist/index.js +7 -0
- package/dom/document.ts +6 -4
- package/dom/dom.ts +157 -0
- package/package.json +1 -1
|
@@ -230,6 +230,7 @@ declare namespace CS {
|
|
|
230
230
|
public removeChild ($child: OneJS.Dom.Dom) : void
|
|
231
231
|
public contains ($child: OneJS.Dom.Dom) : boolean
|
|
232
232
|
public insertBefore ($a: OneJS.Dom.Dom, $b: OneJS.Dom.Dom) : void
|
|
233
|
+
public insertAfter ($a: OneJS.Dom.Dom, $b: OneJS.Dom.Dom) : void
|
|
233
234
|
public setAttribute ($name: string, $val: any) : void
|
|
234
235
|
public removeAttribute ($name: string) : void
|
|
235
236
|
public focus () : void
|
|
@@ -261,6 +262,7 @@ declare namespace CS {
|
|
|
261
262
|
public createTextNode ($text: string) : OneJS.Dom.Dom
|
|
262
263
|
public getElementById ($id: string) : OneJS.Dom.Dom
|
|
263
264
|
public querySelectorAll ($selector: string) : System.Array$1<OneJS.Dom.Dom>
|
|
265
|
+
public getDomFromVE ($ve: UnityEngine.UIElements.VisualElement) : OneJS.Dom.Dom
|
|
264
266
|
public loadImage ($path: string, $filterMode?: UnityEngine.FilterMode) : UnityEngine.Texture2D
|
|
265
267
|
public loadFont ($path: string) : UnityEngine.Font
|
|
266
268
|
public loadFontDefinition ($path: string) : UnityEngine.UIElements.FontDefinition
|
package/definitions/globals.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ declare const onejs: {
|
|
|
24
24
|
eventSource: T,
|
|
25
25
|
eventName: K,
|
|
26
26
|
handler: OneJS.EventGenericType<T[K]>
|
|
27
|
-
):
|
|
27
|
+
): CS.System.Action
|
|
28
28
|
|
|
29
|
-
subscribe(eventName: string, handler: () => void):
|
|
29
|
+
subscribe(eventName: string, handler: () => void): CS.System.Action
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
declare function require(name: string): any
|
package/dist/dom/dom.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export declare class DomWrapper {
|
|
|
32
32
|
appendChild(child: DomWrapper): void;
|
|
33
33
|
removeChild(child: DomWrapper): void;
|
|
34
34
|
insertBefore(a: DomWrapper, b: DomWrapper): void;
|
|
35
|
+
insertAfter(a: DomWrapper, b: DomWrapper): void;
|
|
35
36
|
contains(child: DomWrapper): boolean;
|
|
36
37
|
clearChildren(): void;
|
|
37
38
|
focus(): void;
|
|
@@ -39,4 +40,20 @@ export declare class DomWrapper {
|
|
|
39
40
|
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean): void;
|
|
40
41
|
setAttribute(name: string, value: any): void;
|
|
41
42
|
removeAttribute(name: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns all elements matching the specified selector.
|
|
45
|
+
* Supports basic selectors:
|
|
46
|
+
* - Tag names: 'div'
|
|
47
|
+
* - IDs: '#myId'
|
|
48
|
+
* - Classes: '.myClass'
|
|
49
|
+
* - Combinations: 'div.myClass#myId'
|
|
50
|
+
*/
|
|
51
|
+
querySelectorAll(selector: string): DomWrapper[];
|
|
52
|
+
/**
|
|
53
|
+
* Returns the first element matching the specified selector.
|
|
54
|
+
* Supports the same basic selectors as querySelectorAll.
|
|
55
|
+
*/
|
|
56
|
+
querySelector(selector: string): DomWrapper | null;
|
|
42
57
|
}
|
|
58
|
+
export declare function querySelectorAll(root: DomWrapper, selector: string): DomWrapper[];
|
|
59
|
+
export declare function querySelector(root: DomWrapper, selector: string): DomWrapper | null;
|
package/dist/dom/dom.js
CHANGED
|
@@ -61,6 +61,10 @@ export class DomWrapper {
|
|
|
61
61
|
this.dom.insertBefore(a?._dom, b?._dom);
|
|
62
62
|
this.cachedChildNodes = null;
|
|
63
63
|
}
|
|
64
|
+
insertAfter(a, b) {
|
|
65
|
+
this.dom.insertAfter(a?._dom, b?._dom);
|
|
66
|
+
this.cachedChildNodes = null;
|
|
67
|
+
}
|
|
64
68
|
contains(child) {
|
|
65
69
|
if (!child)
|
|
66
70
|
return false;
|
|
@@ -94,4 +98,123 @@ export class DomWrapper {
|
|
|
94
98
|
removeAttribute(name) {
|
|
95
99
|
this.dom.removeAttribute(name);
|
|
96
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns all elements matching the specified selector.
|
|
103
|
+
* Supports basic selectors:
|
|
104
|
+
* - Tag names: 'div'
|
|
105
|
+
* - IDs: '#myId'
|
|
106
|
+
* - Classes: '.myClass'
|
|
107
|
+
* - Combinations: 'div.myClass#myId'
|
|
108
|
+
*/
|
|
109
|
+
querySelectorAll(selector) {
|
|
110
|
+
const selectorInfo = parseSelector(selector);
|
|
111
|
+
const results = [];
|
|
112
|
+
function traverse(element) {
|
|
113
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
114
|
+
results.push(element);
|
|
115
|
+
}
|
|
116
|
+
for (const child of element.childNodes) {
|
|
117
|
+
traverse(child);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
traverse(this);
|
|
121
|
+
return results;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns the first element matching the specified selector.
|
|
125
|
+
* Supports the same basic selectors as querySelectorAll.
|
|
126
|
+
*/
|
|
127
|
+
querySelector(selector) {
|
|
128
|
+
const selectorInfo = parseSelector(selector);
|
|
129
|
+
function traverse(element) {
|
|
130
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
131
|
+
return element;
|
|
132
|
+
}
|
|
133
|
+
for (const child of element.childNodes) {
|
|
134
|
+
const match = traverse(child);
|
|
135
|
+
if (match) {
|
|
136
|
+
return match;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
return traverse(this);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function parseSelector(selector) {
|
|
145
|
+
const selectorInfo = {
|
|
146
|
+
classes: []
|
|
147
|
+
};
|
|
148
|
+
// Handle ID
|
|
149
|
+
const idMatch = selector.match(/#([^.#\s]+)/);
|
|
150
|
+
if (idMatch) {
|
|
151
|
+
selectorInfo.id = idMatch[1];
|
|
152
|
+
selector = selector.replace(idMatch[0], '');
|
|
153
|
+
}
|
|
154
|
+
// Handle classes
|
|
155
|
+
const classMatches = selector.match(/\.([^.#\s]+)/g);
|
|
156
|
+
if (classMatches) {
|
|
157
|
+
selectorInfo.classes = classMatches.map(c => c.substring(1));
|
|
158
|
+
selector = selector.replace(/\.[^.#\s]+/g, '');
|
|
159
|
+
}
|
|
160
|
+
// Handle tag name (what's left after removing id and classes)
|
|
161
|
+
const tagName = selector.trim();
|
|
162
|
+
if (tagName) {
|
|
163
|
+
selectorInfo.tag = tagName.toLowerCase();
|
|
164
|
+
}
|
|
165
|
+
return selectorInfo;
|
|
166
|
+
}
|
|
167
|
+
function elementMatchesSelector(element, selectorInfo) {
|
|
168
|
+
// Check tag name
|
|
169
|
+
if (selectorInfo.tag && element.ve.name.toLowerCase() !== selectorInfo.tag) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
// Check ID
|
|
173
|
+
if (selectorInfo.id && element.Id !== selectorInfo.id) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
// Check classes
|
|
177
|
+
if (selectorInfo.classes.length > 0) {
|
|
178
|
+
const elementClasses = element.classname.split(' ').filter(c => c);
|
|
179
|
+
for (const className of selectorInfo.classes) {
|
|
180
|
+
if (!elementClasses.includes(className)) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
export function querySelectorAll(root, selector) {
|
|
188
|
+
const results = [];
|
|
189
|
+
const selectorInfo = parseSelector(selector);
|
|
190
|
+
function traverse(element) {
|
|
191
|
+
// Check if current element matches
|
|
192
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
193
|
+
results.push(element);
|
|
194
|
+
}
|
|
195
|
+
// Recursively check children
|
|
196
|
+
for (const child of element.childNodes) {
|
|
197
|
+
traverse(child);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
traverse(root);
|
|
201
|
+
return results;
|
|
202
|
+
}
|
|
203
|
+
export function querySelector(root, selector) {
|
|
204
|
+
const selectorInfo = parseSelector(selector);
|
|
205
|
+
function traverse(element) {
|
|
206
|
+
// Check if current element matches
|
|
207
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
208
|
+
return element;
|
|
209
|
+
}
|
|
210
|
+
// Recursively check children
|
|
211
|
+
for (const child of element.childNodes) {
|
|
212
|
+
const match = traverse(child);
|
|
213
|
+
if (match) {
|
|
214
|
+
return match;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
return traverse(root);
|
|
97
220
|
}
|
|
File without changes
|
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -37,3 +37,10 @@ if (typeof ___document != "undefined") {
|
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
globalThis.document = new DocumentWrapper(___document);
|
|
39
39
|
}
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
CS.OneJS.EngineHost.prototype.sub = function (a, b, c) {
|
|
42
|
+
let unsubscribe = c ? this.subscribe(a, b, c) : this.subscribe(a, b);
|
|
43
|
+
return () => {
|
|
44
|
+
unsubscribe.Invoke();
|
|
45
|
+
};
|
|
46
|
+
};
|
package/dom/document.ts
CHANGED
|
@@ -8,14 +8,16 @@ export class DocumentWrapper {
|
|
|
8
8
|
public get _doc(): CS.OneJS.Dom.Document { return this.#doc }
|
|
9
9
|
|
|
10
10
|
#doc: CS.OneJS.Dom.Document;
|
|
11
|
-
#body: DomWrapper;
|
|
11
|
+
#body: DomWrapper | null;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The body/root element of the document. Will be null for Editor documents.
|
|
15
|
+
*/
|
|
16
|
+
public get body(): DomWrapper | null { return this.#body }
|
|
14
17
|
|
|
15
18
|
constructor(doc: CS.OneJS.Dom.Document) {
|
|
16
19
|
this.#doc = doc
|
|
17
|
-
|
|
18
|
-
this.#body = new DomWrapper(doc.body)
|
|
20
|
+
this.#body = doc.body ? new DomWrapper(doc.body) : null
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
addRuntimeUSS(uss: string): void {
|
package/dom/dom.ts
CHANGED
|
@@ -69,6 +69,11 @@ export class DomWrapper {
|
|
|
69
69
|
this.cachedChildNodes = null
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
insertAfter(a: DomWrapper, b: DomWrapper) {
|
|
73
|
+
this.dom.insertAfter(a?._dom, b?._dom)
|
|
74
|
+
this.cachedChildNodes = null
|
|
75
|
+
}
|
|
76
|
+
|
|
72
77
|
contains(child: DomWrapper) {
|
|
73
78
|
if (!child) return false
|
|
74
79
|
return this.dom.contains(child._dom)
|
|
@@ -107,4 +112,156 @@ export class DomWrapper {
|
|
|
107
112
|
removeAttribute(name: string) {
|
|
108
113
|
this.dom.removeAttribute(name)
|
|
109
114
|
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns all elements matching the specified selector.
|
|
118
|
+
* Supports basic selectors:
|
|
119
|
+
* - Tag names: 'div'
|
|
120
|
+
* - IDs: '#myId'
|
|
121
|
+
* - Classes: '.myClass'
|
|
122
|
+
* - Combinations: 'div.myClass#myId'
|
|
123
|
+
*/
|
|
124
|
+
querySelectorAll(selector: string): DomWrapper[] {
|
|
125
|
+
const selectorInfo = parseSelector(selector);
|
|
126
|
+
const results: DomWrapper[] = [];
|
|
127
|
+
|
|
128
|
+
function traverse(element: DomWrapper) {
|
|
129
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
130
|
+
results.push(element);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const child of element.childNodes) {
|
|
134
|
+
traverse(child);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
traverse(this);
|
|
139
|
+
return results;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Returns the first element matching the specified selector.
|
|
144
|
+
* Supports the same basic selectors as querySelectorAll.
|
|
145
|
+
*/
|
|
146
|
+
querySelector(selector: string): DomWrapper | null {
|
|
147
|
+
const selectorInfo = parseSelector(selector);
|
|
148
|
+
|
|
149
|
+
function traverse(element: DomWrapper): DomWrapper | null {
|
|
150
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
151
|
+
return element;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (const child of element.childNodes) {
|
|
155
|
+
const match = traverse(child);
|
|
156
|
+
if (match) {
|
|
157
|
+
return match;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return traverse(this);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface SelectorInfo {
|
|
169
|
+
tag?: string;
|
|
170
|
+
id?: string;
|
|
171
|
+
classes: string[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function parseSelector(selector: string): SelectorInfo {
|
|
175
|
+
const selectorInfo: SelectorInfo = {
|
|
176
|
+
classes: []
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Handle ID
|
|
180
|
+
const idMatch = selector.match(/#([^.#\s]+)/);
|
|
181
|
+
if (idMatch) {
|
|
182
|
+
selectorInfo.id = idMatch[1];
|
|
183
|
+
selector = selector.replace(idMatch[0], '');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Handle classes
|
|
187
|
+
const classMatches = selector.match(/\.([^.#\s]+)/g);
|
|
188
|
+
if (classMatches) {
|
|
189
|
+
selectorInfo.classes = classMatches.map(c => c.substring(1));
|
|
190
|
+
selector = selector.replace(/\.[^.#\s]+/g, '');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Handle tag name (what's left after removing id and classes)
|
|
194
|
+
const tagName = selector.trim();
|
|
195
|
+
if (tagName) {
|
|
196
|
+
selectorInfo.tag = tagName.toLowerCase();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return selectorInfo;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function elementMatchesSelector(element: DomWrapper, selectorInfo: SelectorInfo): boolean {
|
|
203
|
+
// Check tag name
|
|
204
|
+
if (selectorInfo.tag && element.ve.name.toLowerCase() !== selectorInfo.tag) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Check ID
|
|
209
|
+
if (selectorInfo.id && element.Id !== selectorInfo.id) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Check classes
|
|
214
|
+
if (selectorInfo.classes.length > 0) {
|
|
215
|
+
const elementClasses = element.classname.split(' ').filter(c => c);
|
|
216
|
+
for (const className of selectorInfo.classes) {
|
|
217
|
+
if (!elementClasses.includes(className)) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function querySelectorAll(root: DomWrapper, selector: string): DomWrapper[] {
|
|
227
|
+
const results: DomWrapper[] = [];
|
|
228
|
+
const selectorInfo = parseSelector(selector);
|
|
229
|
+
|
|
230
|
+
function traverse(element: DomWrapper) {
|
|
231
|
+
// Check if current element matches
|
|
232
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
233
|
+
results.push(element);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Recursively check children
|
|
237
|
+
for (const child of element.childNodes) {
|
|
238
|
+
traverse(child);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
traverse(root);
|
|
243
|
+
return results;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function querySelector(root: DomWrapper, selector: string): DomWrapper | null {
|
|
247
|
+
const selectorInfo = parseSelector(selector);
|
|
248
|
+
|
|
249
|
+
function traverse(element: DomWrapper): DomWrapper | null {
|
|
250
|
+
// Check if current element matches
|
|
251
|
+
if (elementMatchesSelector(element, selectorInfo)) {
|
|
252
|
+
return element;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Recursively check children
|
|
256
|
+
for (const child of element.childNodes) {
|
|
257
|
+
const match = traverse(child);
|
|
258
|
+
if (match) {
|
|
259
|
+
return match;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return traverse(root);
|
|
110
267
|
}
|
package/package.json
CHANGED