onejs-core 2.0.21 → 3.0.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/bin/oj.js +12 -5
- package/definitions/Assemblies/OneJS.Runtime.d.ts +2 -0
- package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +193 -0
- package/dist/dom/document.d.ts +7 -0
- package/dist/dom/document.js +12 -0
- package/dist/dom/dom.d.ts +8 -4
- package/dist/dom/dom.js +34 -10
- package/dist/index.d.ts +3 -0
- package/dom/document.ts +19 -0
- package/dom/dom.ts +101 -70
- package/index.ts +1 -0
- package/package.json +1 -1
package/bin/oj.js
CHANGED
|
@@ -36,7 +36,7 @@ function findAssetsDir(startDir, explicit) {
|
|
|
36
36
|
if (fs.existsSync(explicit) && fs.statSync(explicit).isDirectory()) return explicit
|
|
37
37
|
return null
|
|
38
38
|
}
|
|
39
|
-
let dir = startDir
|
|
39
|
+
let dir = path.dirname(startDir) // Up a level, preventing `App/assets` getting returned
|
|
40
40
|
const { root } = path.parse(dir)
|
|
41
41
|
while (dir !== root) {
|
|
42
42
|
const probe = path.join(dir, "Assets")
|
|
@@ -80,10 +80,17 @@ async function scanComponents(tarPath) {
|
|
|
80
80
|
await tar.t({
|
|
81
81
|
file: tarPath,
|
|
82
82
|
onentry: (entry) => {
|
|
83
|
-
const p = entry.path
|
|
83
|
+
const p = entry.path.replace(/\\/g, "/")
|
|
84
84
|
if (!p.startsWith("comps/")) return
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
|
|
86
|
+
// Only treat entries inside a top-level folder under comps/
|
|
87
|
+
// e.g. "comps/button/**" → "button"
|
|
88
|
+
const rest = p.slice("comps/".length)
|
|
89
|
+
const firstSlash = rest.indexOf("/")
|
|
90
|
+
if (firstSlash === -1) return // file directly under comps/ → skip
|
|
91
|
+
|
|
92
|
+
const top = rest.slice(0, firstSlash)
|
|
93
|
+
if (top) comps.add(top)
|
|
87
94
|
},
|
|
88
95
|
})
|
|
89
96
|
return comps
|
|
@@ -244,4 +251,4 @@ program
|
|
|
244
251
|
program.parseAsync().catch((err) => {
|
|
245
252
|
console.error(err)
|
|
246
253
|
process.exit(1)
|
|
247
|
-
})
|
|
254
|
+
})
|
|
@@ -356,6 +356,8 @@ declare namespace CS {
|
|
|
356
356
|
public SetColor ($value: UnityEngine.Color) : void
|
|
357
357
|
public SetCursor ($value: UnityEngine.UIElements.Cursor) : void
|
|
358
358
|
public SetDisplay ($value: UnityEngine.UIElements.DisplayStyle) : void
|
|
359
|
+
public SetFilter ($value: System.Collections.Generic.List$1<UnityEngine.UIElements.FilterFunction>) : void
|
|
360
|
+
public SetFilter ($value: UnityEngine.UIElements.FilterFunction) : void
|
|
359
361
|
public SetFlexBasis ($value: UnityEngine.UIElements.StyleLength) : void
|
|
360
362
|
public SetFlexDirection ($value: UnityEngine.UIElements.FlexDirection) : void
|
|
361
363
|
public SetFlexGrow ($value: number) : void
|
|
@@ -21191,6 +21191,189 @@ declare namespace CS {
|
|
|
21191
21191
|
public set startValue(value: T);
|
|
21192
21192
|
public constructor ($drivenField: UnityEngine.UIElements.IValueField$1<T>)
|
|
21193
21193
|
}
|
|
21194
|
+
/**
|
|
21195
|
+
The filter parameter declaration for a FilterFunctionDefinition.
|
|
21196
|
+
*/
|
|
21197
|
+
class FilterParameterDeclaration extends System.ValueType
|
|
21198
|
+
{
|
|
21199
|
+
protected [__keep_incompatibility]: never;
|
|
21200
|
+
/**
|
|
21201
|
+
The parameter name, used for display in the UI Builder.
|
|
21202
|
+
*/
|
|
21203
|
+
public get name(): string;
|
|
21204
|
+
public set name(value: string);
|
|
21205
|
+
/**
|
|
21206
|
+
Default value when interpolating between two filters with missing declarations.
|
|
21207
|
+
*/
|
|
21208
|
+
public get interpolationDefaultValue(): UnityEngine.UIElements.FilterParameter;
|
|
21209
|
+
public set interpolationDefaultValue(value: UnityEngine.UIElements.FilterParameter);
|
|
21210
|
+
}
|
|
21211
|
+
/**
|
|
21212
|
+
Represents a filter parameter for a FilterFunctionDefinition.
|
|
21213
|
+
*/
|
|
21214
|
+
class FilterParameter extends System.ValueType implements System.IEquatable$1<UnityEngine.UIElements.FilterParameter>
|
|
21215
|
+
{
|
|
21216
|
+
protected [__keep_incompatibility]: never;
|
|
21217
|
+
/** The type of the filter parameter.
|
|
21218
|
+
*/
|
|
21219
|
+
public get type(): UnityEngine.UIElements.FilterParameterType;
|
|
21220
|
+
public set type(value: UnityEngine.UIElements.FilterParameterType);
|
|
21221
|
+
/** The float value of the filter parameter.
|
|
21222
|
+
*/
|
|
21223
|
+
public get floatValue(): number;
|
|
21224
|
+
public set floatValue(value: number);
|
|
21225
|
+
/** The color value of the filter parameter.
|
|
21226
|
+
*/
|
|
21227
|
+
public get colorValue(): UnityEngine.Color;
|
|
21228
|
+
public set colorValue(value: UnityEngine.Color);
|
|
21229
|
+
public static op_Equality ($a: UnityEngine.UIElements.FilterParameter, $b: UnityEngine.UIElements.FilterParameter) : boolean
|
|
21230
|
+
public static op_Inequality ($a: UnityEngine.UIElements.FilterParameter, $b: UnityEngine.UIElements.FilterParameter) : boolean
|
|
21231
|
+
public Equals ($obj: any) : boolean
|
|
21232
|
+
public Equals ($other: UnityEngine.UIElements.FilterParameter) : boolean
|
|
21233
|
+
public constructor ($value: number)
|
|
21234
|
+
public constructor ($value: UnityEngine.Color)
|
|
21235
|
+
}
|
|
21236
|
+
/**
|
|
21237
|
+
Represents a filter function definition that holds the parameters and effects of a filter.
|
|
21238
|
+
*/
|
|
21239
|
+
class FilterFunctionDefinition extends UnityEngine.ScriptableObject
|
|
21240
|
+
{
|
|
21241
|
+
protected [__keep_incompatibility]: never;
|
|
21242
|
+
/** The name of the filter function used for display.
|
|
21243
|
+
*/
|
|
21244
|
+
public get filterName(): string;
|
|
21245
|
+
public set filterName(value: string);
|
|
21246
|
+
/** The description of the function parameters.
|
|
21247
|
+
*/
|
|
21248
|
+
public get parameters(): System.Array$1<UnityEngine.UIElements.FilterParameterDeclaration>;
|
|
21249
|
+
public set parameters(value: System.Array$1<UnityEngine.UIElements.FilterParameterDeclaration>);
|
|
21250
|
+
/** The post-processing effects applied by the filter function.
|
|
21251
|
+
*/
|
|
21252
|
+
public get passes(): System.Array$1<UnityEngine.UIElements.PostProcessingPass>;
|
|
21253
|
+
public set passes(value: System.Array$1<UnityEngine.UIElements.PostProcessingPass>);
|
|
21254
|
+
public constructor ()
|
|
21255
|
+
}
|
|
21256
|
+
/**
|
|
21257
|
+
Represents a post-processing effect that can be applied to a visual element.
|
|
21258
|
+
This is used as part of a FilterFunctionDefinition.
|
|
21259
|
+
*/
|
|
21260
|
+
class PostProcessingPass extends System.ValueType
|
|
21261
|
+
{
|
|
21262
|
+
protected [__keep_incompatibility]: never;
|
|
21263
|
+
/** The material to use for the effect.
|
|
21264
|
+
*/
|
|
21265
|
+
public get material(): UnityEngine.Material;
|
|
21266
|
+
public set material(value: UnityEngine.Material);
|
|
21267
|
+
/** The pass index to use in the material.
|
|
21268
|
+
*/
|
|
21269
|
+
public get passIndex(): number;
|
|
21270
|
+
public set passIndex(value: number);
|
|
21271
|
+
/** The parameter bindings for the effect.
|
|
21272
|
+
*/
|
|
21273
|
+
public get parameterBindings(): System.Array$1<UnityEngine.UIElements.ParameterBinding>;
|
|
21274
|
+
public set parameterBindings(value: System.Array$1<UnityEngine.UIElements.ParameterBinding>);
|
|
21275
|
+
/** The extra margins, in points, required for the effect to write to destination texture.
|
|
21276
|
+
*/
|
|
21277
|
+
public get writeMargins(): UnityEngine.UIElements.PostProcessingMargins;
|
|
21278
|
+
public set writeMargins(value: UnityEngine.UIElements.PostProcessingMargins);
|
|
21279
|
+
/** The optional callback to prepare the material property block for the effect.
|
|
21280
|
+
*/
|
|
21281
|
+
public get prepareMaterialPropertyBlockCallback(): UnityEngine.UIElements.PostProcessingPass.PrepareMaterialPropertyBlockDelegate;
|
|
21282
|
+
public set prepareMaterialPropertyBlockCallback(value: UnityEngine.UIElements.PostProcessingPass.PrepareMaterialPropertyBlockDelegate);
|
|
21283
|
+
/** The optional callback to compute the required read margins for the effect.
|
|
21284
|
+
*/
|
|
21285
|
+
public get computeRequiredReadMarginsCallback(): UnityEngine.UIElements.PostProcessingPass.ComputeRequiredMarginsDelegate;
|
|
21286
|
+
public set computeRequiredReadMarginsCallback(value: UnityEngine.UIElements.PostProcessingPass.ComputeRequiredMarginsDelegate);
|
|
21287
|
+
/** The optional callback to compute the required write margins for the effect.
|
|
21288
|
+
*/
|
|
21289
|
+
public get computeRequiredWriteMarginsCallback(): UnityEngine.UIElements.PostProcessingPass.ComputeRequiredMarginsDelegate;
|
|
21290
|
+
public set computeRequiredWriteMarginsCallback(value: UnityEngine.UIElements.PostProcessingPass.ComputeRequiredMarginsDelegate);
|
|
21291
|
+
}
|
|
21292
|
+
/**
|
|
21293
|
+
Represents a binding of a parameter index to a post-processing material property.
|
|
21294
|
+
*/
|
|
21295
|
+
class ParameterBinding extends System.ValueType
|
|
21296
|
+
{
|
|
21297
|
+
protected [__keep_incompatibility]: never;
|
|
21298
|
+
/** The index of the parameter in the filter function.
|
|
21299
|
+
*/
|
|
21300
|
+
public get index(): number;
|
|
21301
|
+
public set index(value: number);
|
|
21302
|
+
/** The name of the material property.
|
|
21303
|
+
*/
|
|
21304
|
+
public get name(): string;
|
|
21305
|
+
public set name(value: string);
|
|
21306
|
+
}
|
|
21307
|
+
/**
|
|
21308
|
+
The post-processing margins required by a FilterFunction.
|
|
21309
|
+
*/
|
|
21310
|
+
class PostProcessingMargins extends System.ValueType
|
|
21311
|
+
{
|
|
21312
|
+
protected [__keep_incompatibility]: never;
|
|
21313
|
+
/** The left margin value.
|
|
21314
|
+
*/
|
|
21315
|
+
public get left(): number;
|
|
21316
|
+
public set left(value: number);
|
|
21317
|
+
/** The top margin value.
|
|
21318
|
+
*/
|
|
21319
|
+
public get top(): number;
|
|
21320
|
+
public set top(value: number);
|
|
21321
|
+
/** The right margin value.
|
|
21322
|
+
*/
|
|
21323
|
+
public get right(): number;
|
|
21324
|
+
public set right(value: number);
|
|
21325
|
+
/** The bottom margin value.
|
|
21326
|
+
*/
|
|
21327
|
+
public get bottom(): number;
|
|
21328
|
+
public set bottom(value: number);
|
|
21329
|
+
}
|
|
21330
|
+
/**
|
|
21331
|
+
Represents a filter function that holds the definition and parameters of a filter.
|
|
21332
|
+
*/
|
|
21333
|
+
class FilterFunction extends System.ValueType implements System.IEquatable$1<UnityEngine.UIElements.FilterFunction>
|
|
21334
|
+
{
|
|
21335
|
+
protected [__keep_incompatibility]: never;
|
|
21336
|
+
/**
|
|
21337
|
+
The type of the filter function.
|
|
21338
|
+
*/
|
|
21339
|
+
public get type(): UnityEngine.UIElements.FilterFunctionType;
|
|
21340
|
+
public set type(value: UnityEngine.UIElements.FilterFunctionType);
|
|
21341
|
+
/** The number of parameters in the filter function.
|
|
21342
|
+
*/
|
|
21343
|
+
public get parameterCount(): number;
|
|
21344
|
+
/**
|
|
21345
|
+
The custom filter function definition, when the filter function type is FilterFunctionType.Custom.
|
|
21346
|
+
*/
|
|
21347
|
+
public get customDefinition(): UnityEngine.UIElements.FilterFunctionDefinition;
|
|
21348
|
+
public set customDefinition(value: UnityEngine.UIElements.FilterFunctionDefinition);
|
|
21349
|
+
/**
|
|
21350
|
+
Adds a parameter to the filter function.
|
|
21351
|
+
* @param $p The parameter to add.
|
|
21352
|
+
*/
|
|
21353
|
+
public AddParameter ($p: UnityEngine.UIElements.FilterParameter) : void
|
|
21354
|
+
/**
|
|
21355
|
+
Sets a parameter to the filter function at the provided index.
|
|
21356
|
+
* @param $index The parameter index.
|
|
21357
|
+
* @param $p The parameter to set.
|
|
21358
|
+
*/
|
|
21359
|
+
public SetParameter ($index: number, $p: UnityEngine.UIElements.FilterParameter) : void
|
|
21360
|
+
/**
|
|
21361
|
+
Gets the parameter at the specified index.
|
|
21362
|
+
* @param $index The parameter index.
|
|
21363
|
+
* @returns The filter parameter at the provided index.
|
|
21364
|
+
*/
|
|
21365
|
+
public GetParameter ($index: number) : UnityEngine.UIElements.FilterParameter
|
|
21366
|
+
/**
|
|
21367
|
+
Clears all parameters from the filter function.
|
|
21368
|
+
*/
|
|
21369
|
+
public ClearParameters () : void
|
|
21370
|
+
public static op_Equality ($lhs: UnityEngine.UIElements.FilterFunction, $rhs: UnityEngine.UIElements.FilterFunction) : boolean
|
|
21371
|
+
public static op_Inequality ($lhs: UnityEngine.UIElements.FilterFunction, $rhs: UnityEngine.UIElements.FilterFunction) : boolean
|
|
21372
|
+
public Equals ($other: UnityEngine.UIElements.FilterFunction) : boolean
|
|
21373
|
+
public Equals ($obj: any) : boolean
|
|
21374
|
+
public constructor ($type: UnityEngine.UIElements.FilterFunctionType)
|
|
21375
|
+
public constructor ($filterDef: UnityEngine.UIElements.FilterFunctionDefinition)
|
|
21376
|
+
}
|
|
21194
21377
|
interface IFocusRing
|
|
21195
21378
|
{
|
|
21196
21379
|
/**
|
|
@@ -22111,6 +22294,16 @@ declare namespace CS {
|
|
|
22111
22294
|
public constructor ($mode: UnityEngine.UIElements.EasingMode)
|
|
22112
22295
|
}
|
|
22113
22296
|
/**
|
|
22297
|
+
The filter function type for a FilterFunction .
|
|
22298
|
+
*/
|
|
22299
|
+
enum FilterFunctionType
|
|
22300
|
+
{ None = 0, Custom = 1, Tint = 2, Opacity = 3, Invert = 4, Grayscale = 5, Sepia = 6, Blur = 7, Contrast = 8, HueRotate = 9, Count = 10 }
|
|
22301
|
+
/**
|
|
22302
|
+
The type of a filter parameter.
|
|
22303
|
+
*/
|
|
22304
|
+
enum FilterParameterType
|
|
22305
|
+
{ Float = 0, Color = 1 }
|
|
22306
|
+
/**
|
|
22114
22307
|
Describes a VisualElement font.
|
|
22115
22308
|
*/
|
|
22116
22309
|
class FontDefinition extends System.ValueType implements System.IEquatable$1<UnityEngine.UIElements.FontDefinition>
|
package/dist/dom/document.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference path="../../definitions/modules.d.ts" />
|
|
1
2
|
import { DomWrapper } from "./dom";
|
|
3
|
+
import { EventBase } from "UnityEngine/UIElements";
|
|
2
4
|
interface ElementCreationOptions {
|
|
3
5
|
is?: string;
|
|
4
6
|
}
|
|
@@ -15,9 +17,14 @@ export declare class DocumentWrapper {
|
|
|
15
17
|
createElement(tagName: string, options?: ElementCreationOptions): DomWrapper;
|
|
16
18
|
createElementNS(ns: string, tagName: string, options?: ElementCreationOptions): DomWrapper;
|
|
17
19
|
createTextNode(text: string): DomWrapper;
|
|
20
|
+
createDocumentFragment(): DomWrapper;
|
|
18
21
|
getElementById(id: string): DomWrapper;
|
|
19
22
|
querySelectorAll(selector: string): DomWrapper[];
|
|
20
23
|
elementFromPoint(x: number, y: number): DomWrapper | null;
|
|
21
24
|
elementsFromPoint(x: number, y: number): DomWrapper[];
|
|
25
|
+
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | {
|
|
26
|
+
once?: boolean;
|
|
27
|
+
}): void;
|
|
28
|
+
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean): void;
|
|
22
29
|
}
|
|
23
30
|
export {};
|
package/dist/dom/document.js
CHANGED
|
@@ -18,6 +18,7 @@ export class DocumentWrapper {
|
|
|
18
18
|
clearRuntimeStyleSheets() {
|
|
19
19
|
this.#doc.clearRuntimeStyleSheets();
|
|
20
20
|
}
|
|
21
|
+
// MARK: Create
|
|
21
22
|
createElement(tagName, options) {
|
|
22
23
|
return new DomWrapper(this.#doc.createElement(tagName));
|
|
23
24
|
}
|
|
@@ -28,6 +29,10 @@ export class DocumentWrapper {
|
|
|
28
29
|
createTextNode(text) {
|
|
29
30
|
return new DomWrapper(this.#doc.createTextNode(text));
|
|
30
31
|
}
|
|
32
|
+
createDocumentFragment() {
|
|
33
|
+
return this.createElement("div");
|
|
34
|
+
}
|
|
35
|
+
// MARK: Query
|
|
31
36
|
getElementById(id) {
|
|
32
37
|
return new DomWrapper(this.#doc.getElementById(id));
|
|
33
38
|
}
|
|
@@ -74,4 +79,11 @@ export class DocumentWrapper {
|
|
|
74
79
|
collect(root);
|
|
75
80
|
return hits; // ordered front‑to‑back (top‑most first)
|
|
76
81
|
}
|
|
82
|
+
// MARK: Event
|
|
83
|
+
addEventListener(type, listener, options) {
|
|
84
|
+
this.body?.addEventListener(type, listener, options);
|
|
85
|
+
}
|
|
86
|
+
removeEventListener(type, listener, useCapture) {
|
|
87
|
+
this.body?.removeEventListener(type, listener, useCapture);
|
|
88
|
+
}
|
|
77
89
|
}
|
package/dist/dom/dom.d.ts
CHANGED
|
@@ -31,19 +31,23 @@ export declare class DomWrapper {
|
|
|
31
31
|
cachedChildNodes: DomWrapper[] | null;
|
|
32
32
|
boundListeners: WeakMap<WeakKey, any>;
|
|
33
33
|
constructor(dom: CS.OneJS.Dom.Dom);
|
|
34
|
-
appendChild(child: DomWrapper):
|
|
34
|
+
appendChild(child: DomWrapper): DomWrapper | undefined;
|
|
35
35
|
removeChild(child: DomWrapper): void;
|
|
36
36
|
insertBefore(a: DomWrapper, b: DomWrapper): void;
|
|
37
37
|
insertAfter(a: DomWrapper, b: DomWrapper): void;
|
|
38
|
-
|
|
38
|
+
before(other: DomWrapper): void;
|
|
39
39
|
clearChildren(): void;
|
|
40
|
+
setAttribute(name: string, value: any): void;
|
|
41
|
+
removeAttribute(name: string): void;
|
|
42
|
+
append(child: DomWrapper): void;
|
|
43
|
+
cloneNode(deep?: boolean): DomWrapper;
|
|
44
|
+
remove(): void;
|
|
45
|
+
contains(child: DomWrapper): boolean;
|
|
40
46
|
focus(): void;
|
|
41
47
|
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | {
|
|
42
48
|
once?: boolean;
|
|
43
49
|
}): void;
|
|
44
50
|
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean): void;
|
|
45
|
-
setAttribute(name: string, value: any): void;
|
|
46
|
-
removeAttribute(name: string): void;
|
|
47
51
|
/**
|
|
48
52
|
* Returns all elements matching the specified selector.
|
|
49
53
|
* Supports basic selectors:
|
package/dist/dom/dom.js
CHANGED
|
@@ -48,11 +48,13 @@ export class DomWrapper {
|
|
|
48
48
|
this.domStyleWrapper = new DomStyleWrapper(dom.style);
|
|
49
49
|
this.domTokenList = new DomTokenList(dom);
|
|
50
50
|
}
|
|
51
|
+
// MARK: Manipulation
|
|
51
52
|
appendChild(child) {
|
|
52
53
|
if (!child)
|
|
53
54
|
return;
|
|
54
55
|
this.dom.appendChild(child.dom);
|
|
55
56
|
this.cachedChildNodes = null;
|
|
57
|
+
return child;
|
|
56
58
|
}
|
|
57
59
|
removeChild(child) {
|
|
58
60
|
if (!child)
|
|
@@ -68,18 +70,46 @@ export class DomWrapper {
|
|
|
68
70
|
this.dom.insertAfter(a?._dom, b?._dom);
|
|
69
71
|
this.cachedChildNodes = null;
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
before(other) {
|
|
74
|
+
if (this.parentNode) {
|
|
75
|
+
this.parentNode.insertBefore(other, this);
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
clearChildren() {
|
|
77
79
|
this.dom.clearChildren();
|
|
78
80
|
this.cachedChildNodes = null;
|
|
79
81
|
}
|
|
82
|
+
setAttribute(name, value) {
|
|
83
|
+
this.dom.setAttribute(name, value);
|
|
84
|
+
}
|
|
85
|
+
removeAttribute(name) {
|
|
86
|
+
this.dom.removeAttribute(name);
|
|
87
|
+
}
|
|
88
|
+
// MARK: Node.prototype
|
|
89
|
+
append(child) {
|
|
90
|
+
if (!child)
|
|
91
|
+
return;
|
|
92
|
+
this.dom.appendChild(child.dom);
|
|
93
|
+
this.cachedChildNodes = null;
|
|
94
|
+
}
|
|
95
|
+
cloneNode(deep = false) {
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
remove() {
|
|
99
|
+
if (this.parentNode) {
|
|
100
|
+
this.parentNode.removeChild(this);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// MARK: Misc
|
|
104
|
+
contains(child) {
|
|
105
|
+
if (!child)
|
|
106
|
+
return false;
|
|
107
|
+
return this.dom.contains(child._dom);
|
|
108
|
+
}
|
|
80
109
|
focus() {
|
|
81
110
|
this.dom.focus();
|
|
82
111
|
}
|
|
112
|
+
// MARK: Event
|
|
83
113
|
addEventListener(type, listener, options) {
|
|
84
114
|
let boundListener = this.boundListeners.get(listener);
|
|
85
115
|
if (!boundListener) {
|
|
@@ -104,12 +134,6 @@ export class DomWrapper {
|
|
|
104
134
|
this.boundListeners.delete(listener); // isn't strictly necessary for WeakMap, but still good practice
|
|
105
135
|
}
|
|
106
136
|
}
|
|
107
|
-
setAttribute(name, value) {
|
|
108
|
-
this.dom.setAttribute(name, value);
|
|
109
|
-
}
|
|
110
|
-
removeAttribute(name) {
|
|
111
|
-
this.dom.removeAttribute(name);
|
|
112
|
-
}
|
|
113
137
|
/**
|
|
114
138
|
* Returns all elements matching the specified selector.
|
|
115
139
|
* Supports basic selectors:
|
package/dist/index.d.ts
CHANGED
package/dom/document.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Vector2 } from "UnityEngine"
|
|
2
2
|
import { DomWrapper } from "./dom"
|
|
3
|
+
import { EventBase } from "UnityEngine/UIElements"
|
|
3
4
|
|
|
4
5
|
interface ElementCreationOptions {
|
|
5
6
|
is?: string
|
|
@@ -29,6 +30,8 @@ export class DocumentWrapper {
|
|
|
29
30
|
this.#doc.clearRuntimeStyleSheets()
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
// MARK: Create
|
|
34
|
+
|
|
32
35
|
createElement(tagName: string, options?: ElementCreationOptions): DomWrapper {
|
|
33
36
|
return new DomWrapper(this.#doc.createElement(tagName))
|
|
34
37
|
}
|
|
@@ -42,6 +45,12 @@ export class DocumentWrapper {
|
|
|
42
45
|
return new DomWrapper(this.#doc.createTextNode(text))
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
createDocumentFragment(): DomWrapper {
|
|
49
|
+
return this.createElement("div")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// MARK: Query
|
|
53
|
+
|
|
45
54
|
getElementById(id: string): DomWrapper {
|
|
46
55
|
return new DomWrapper(this.#doc.getElementById(id))
|
|
47
56
|
}
|
|
@@ -94,4 +103,14 @@ export class DocumentWrapper {
|
|
|
94
103
|
collect(root)
|
|
95
104
|
return hits // ordered front‑to‑back (top‑most first)
|
|
96
105
|
}
|
|
106
|
+
|
|
107
|
+
// MARK: Event
|
|
108
|
+
|
|
109
|
+
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | { once?: boolean }) {
|
|
110
|
+
this.body?.addEventListener(type, listener, options)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
|
|
114
|
+
this.body?.removeEventListener(type, listener, useCapture)
|
|
115
|
+
}
|
|
97
116
|
}
|
package/dom/dom.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventBase } from "UnityEngine/UIElements"
|
|
1
|
+
import { EventBase } from "UnityEngine/UIElements"
|
|
2
2
|
import { DomStyleWrapper } from "./dom-style"
|
|
3
3
|
|
|
4
4
|
export class DomWrapper {
|
|
@@ -6,21 +6,21 @@ export class DomWrapper {
|
|
|
6
6
|
public get ve(): CS.UnityEngine.UIElements.VisualElement { return this.dom.ve }
|
|
7
7
|
public get childNodes(): DomWrapper[] {
|
|
8
8
|
if (this.cachedChildNodes) return this.cachedChildNodes
|
|
9
|
-
this.cachedChildNodes = new Array(this.dom.childNodes.Length) as DomWrapper[]
|
|
10
|
-
var i = this.dom.childNodes.Length
|
|
9
|
+
this.cachedChildNodes = new Array(this.dom.childNodes.Length) as DomWrapper[]
|
|
10
|
+
var i = this.dom.childNodes.Length
|
|
11
11
|
while (i--) {
|
|
12
|
-
this.cachedChildNodes[i] = new DomWrapper(this.dom.childNodes.get_Item(i))
|
|
12
|
+
this.cachedChildNodes[i] = new DomWrapper(this.dom.childNodes.get_Item(i))
|
|
13
13
|
}
|
|
14
14
|
return this.cachedChildNodes
|
|
15
15
|
}
|
|
16
16
|
public get firstChild(): DomWrapper | null {
|
|
17
|
-
return this.dom.firstChild ? new DomWrapper(this.dom.firstChild) : null
|
|
17
|
+
return this.dom.firstChild ? new DomWrapper(this.dom.firstChild) : null
|
|
18
18
|
}
|
|
19
19
|
public get parentNode(): DomWrapper | null {
|
|
20
|
-
return this.dom.parentNode ? new DomWrapper(this.dom.parentNode) : null
|
|
20
|
+
return this.dom.parentNode ? new DomWrapper(this.dom.parentNode) : null
|
|
21
21
|
}
|
|
22
22
|
public get nextSibling(): DomWrapper | null {
|
|
23
|
-
return this.dom.nextSibling ? new DomWrapper(this.dom.nextSibling) : null
|
|
23
|
+
return this.dom.nextSibling ? new DomWrapper(this.dom.nextSibling) : null
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public get nodeType(): number { return this.dom.nodeType }
|
|
@@ -55,10 +55,13 @@ export class DomWrapper {
|
|
|
55
55
|
this.domTokenList = new DomTokenList(dom)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// MARK: Manipulation
|
|
59
|
+
|
|
58
60
|
appendChild(child: DomWrapper) {
|
|
59
61
|
if (!child) return
|
|
60
62
|
this.dom.appendChild(child.dom)
|
|
61
63
|
this.cachedChildNodes = null
|
|
64
|
+
return child
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
removeChild(child: DomWrapper) {
|
|
@@ -77,9 +80,10 @@ export class DomWrapper {
|
|
|
77
80
|
this.cachedChildNodes = null
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
+
before(other: DomWrapper) { // TODO: variable length args
|
|
84
|
+
if (this.parentNode) {
|
|
85
|
+
this.parentNode.insertBefore(other, this)
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
clearChildren() {
|
|
@@ -87,44 +91,71 @@ export class DomWrapper {
|
|
|
87
91
|
this.cachedChildNodes = null
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
setAttribute(name: string, value: any) {
|
|
95
|
+
this.dom.setAttribute(name, value)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
removeAttribute(name: string) {
|
|
99
|
+
this.dom.removeAttribute(name)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// MARK: Node.prototype
|
|
103
|
+
|
|
104
|
+
append(child: DomWrapper) {
|
|
105
|
+
if (!child) return
|
|
106
|
+
this.dom.appendChild(child.dom)
|
|
107
|
+
this.cachedChildNodes = null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
cloneNode(deep: boolean = false): DomWrapper {
|
|
111
|
+
return this
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
remove() {
|
|
115
|
+
if (this.parentNode) {
|
|
116
|
+
this.parentNode.removeChild(this)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// MARK: Misc
|
|
121
|
+
|
|
122
|
+
contains(child: DomWrapper) {
|
|
123
|
+
if (!child) return false
|
|
124
|
+
return this.dom.contains(child._dom)
|
|
125
|
+
}
|
|
126
|
+
|
|
90
127
|
focus() {
|
|
91
128
|
this.dom.focus()
|
|
92
129
|
}
|
|
93
130
|
|
|
131
|
+
// MARK: Event
|
|
132
|
+
|
|
94
133
|
addEventListener(type: string, listener: (event: EventBase) => void, options?: boolean | { once?: boolean }) {
|
|
95
|
-
let boundListener = this.boundListeners.get(listener)
|
|
134
|
+
let boundListener = this.boundListeners.get(listener)
|
|
96
135
|
if (!boundListener) {
|
|
97
|
-
boundListener = listener.bind(this)
|
|
98
|
-
this.boundListeners.set(listener, boundListener)
|
|
136
|
+
boundListener = listener.bind(this)
|
|
137
|
+
this.boundListeners.set(listener, boundListener)
|
|
99
138
|
}
|
|
100
139
|
|
|
101
140
|
if (typeof options === 'object' && options.once) {
|
|
102
141
|
const onceWrapper = (event: EventBase) => {
|
|
103
|
-
boundListener(event)
|
|
104
|
-
this.dom.removeEventListener(type, onceWrapper, false)
|
|
105
|
-
}
|
|
106
|
-
this.dom.addEventListener(type, onceWrapper, false)
|
|
142
|
+
boundListener(event)
|
|
143
|
+
this.dom.removeEventListener(type, onceWrapper, false)
|
|
144
|
+
}
|
|
145
|
+
this.dom.addEventListener(type, onceWrapper, false)
|
|
107
146
|
} else {
|
|
108
|
-
this.dom.addEventListener(type, boundListener, options ? true : false)
|
|
147
|
+
this.dom.addEventListener(type, boundListener, options ? true : false)
|
|
109
148
|
}
|
|
110
149
|
}
|
|
111
150
|
|
|
112
151
|
removeEventListener(type: string, listener: (event: EventBase) => void, useCapture?: boolean) {
|
|
113
|
-
const boundListener = this.boundListeners.get(listener)
|
|
152
|
+
const boundListener = this.boundListeners.get(listener)
|
|
114
153
|
if (boundListener) {
|
|
115
154
|
this.dom.removeEventListener(type, boundListener, useCapture ? true : false)
|
|
116
|
-
this.boundListeners.delete(listener)
|
|
155
|
+
this.boundListeners.delete(listener) // isn't strictly necessary for WeakMap, but still good practice
|
|
117
156
|
}
|
|
118
157
|
}
|
|
119
158
|
|
|
120
|
-
setAttribute(name: string, value: any) {
|
|
121
|
-
this.dom.setAttribute(name, value)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
removeAttribute(name: string) {
|
|
125
|
-
this.dom.removeAttribute(name)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
159
|
/**
|
|
129
160
|
* Returns all elements matching the specified selector.
|
|
130
161
|
* Supports basic selectors:
|
|
@@ -134,21 +165,21 @@ export class DomWrapper {
|
|
|
134
165
|
* - Combinations: 'div.myClass#myId'
|
|
135
166
|
*/
|
|
136
167
|
querySelectorAll(selector: string): DomWrapper[] {
|
|
137
|
-
const selectorInfo = parseSelector(selector)
|
|
138
|
-
const results: DomWrapper[] = []
|
|
168
|
+
const selectorInfo = parseSelector(selector)
|
|
169
|
+
const results: DomWrapper[] = []
|
|
139
170
|
|
|
140
171
|
function traverse(element: DomWrapper) {
|
|
141
172
|
if (elementMatchesSelector(element, selectorInfo)) {
|
|
142
|
-
results.push(element)
|
|
173
|
+
results.push(element)
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
for (const child of element.childNodes) {
|
|
146
|
-
traverse(child)
|
|
177
|
+
traverse(child)
|
|
147
178
|
}
|
|
148
179
|
}
|
|
149
180
|
|
|
150
|
-
traverse(this)
|
|
151
|
-
return results
|
|
181
|
+
traverse(this)
|
|
182
|
+
return results
|
|
152
183
|
}
|
|
153
184
|
|
|
154
185
|
/**
|
|
@@ -156,126 +187,126 @@ export class DomWrapper {
|
|
|
156
187
|
* Supports the same basic selectors as querySelectorAll.
|
|
157
188
|
*/
|
|
158
189
|
querySelector(selector: string): DomWrapper | null {
|
|
159
|
-
const selectorInfo = parseSelector(selector)
|
|
190
|
+
const selectorInfo = parseSelector(selector)
|
|
160
191
|
|
|
161
192
|
function traverse(element: DomWrapper): DomWrapper | null {
|
|
162
193
|
if (elementMatchesSelector(element, selectorInfo)) {
|
|
163
|
-
return element
|
|
194
|
+
return element
|
|
164
195
|
}
|
|
165
196
|
|
|
166
197
|
for (const child of element.childNodes) {
|
|
167
|
-
const match = traverse(child)
|
|
198
|
+
const match = traverse(child)
|
|
168
199
|
if (match) {
|
|
169
|
-
return match
|
|
200
|
+
return match
|
|
170
201
|
}
|
|
171
202
|
}
|
|
172
203
|
|
|
173
|
-
return null
|
|
204
|
+
return null
|
|
174
205
|
}
|
|
175
206
|
|
|
176
|
-
return traverse(this)
|
|
207
|
+
return traverse(this)
|
|
177
208
|
}
|
|
178
209
|
}
|
|
179
210
|
|
|
180
211
|
interface SelectorInfo {
|
|
181
|
-
tag?: string
|
|
182
|
-
id?: string
|
|
183
|
-
classes: string[]
|
|
212
|
+
tag?: string
|
|
213
|
+
id?: string
|
|
214
|
+
classes: string[]
|
|
184
215
|
}
|
|
185
216
|
|
|
186
217
|
function parseSelector(selector: string): SelectorInfo {
|
|
187
218
|
const selectorInfo: SelectorInfo = {
|
|
188
219
|
classes: []
|
|
189
|
-
}
|
|
220
|
+
}
|
|
190
221
|
|
|
191
222
|
// Handle ID
|
|
192
|
-
const idMatch = selector.match(/#([^.#\s]+)/)
|
|
223
|
+
const idMatch = selector.match(/#([^.#\s]+)/)
|
|
193
224
|
if (idMatch) {
|
|
194
|
-
selectorInfo.id = idMatch[1]
|
|
195
|
-
selector = selector.replace(idMatch[0], '')
|
|
225
|
+
selectorInfo.id = idMatch[1]
|
|
226
|
+
selector = selector.replace(idMatch[0], '')
|
|
196
227
|
}
|
|
197
228
|
|
|
198
229
|
// Handle classes
|
|
199
|
-
const classMatches = selector.match(/\.([^.#\s]+)/g)
|
|
230
|
+
const classMatches = selector.match(/\.([^.#\s]+)/g)
|
|
200
231
|
if (classMatches) {
|
|
201
|
-
selectorInfo.classes = classMatches.map(c => c.substring(1))
|
|
202
|
-
selector = selector.replace(/\.[^.#\s]+/g, '')
|
|
232
|
+
selectorInfo.classes = classMatches.map(c => c.substring(1))
|
|
233
|
+
selector = selector.replace(/\.[^.#\s]+/g, '')
|
|
203
234
|
}
|
|
204
235
|
|
|
205
236
|
// Handle tag name (what's left after removing id and classes)
|
|
206
|
-
const tagName = selector.trim()
|
|
237
|
+
const tagName = selector.trim()
|
|
207
238
|
if (tagName) {
|
|
208
|
-
selectorInfo.tag = tagName.toLowerCase()
|
|
239
|
+
selectorInfo.tag = tagName.toLowerCase()
|
|
209
240
|
}
|
|
210
241
|
|
|
211
|
-
return selectorInfo
|
|
242
|
+
return selectorInfo
|
|
212
243
|
}
|
|
213
244
|
|
|
214
245
|
function elementMatchesSelector(element: DomWrapper, selectorInfo: SelectorInfo): boolean {
|
|
215
246
|
// Check tag name
|
|
216
247
|
if (selectorInfo.tag && element.ve.GetType().Name.toLowerCase() !== selectorInfo.tag) {
|
|
217
|
-
return false
|
|
248
|
+
return false
|
|
218
249
|
}
|
|
219
250
|
|
|
220
251
|
// Check ID
|
|
221
252
|
if (selectorInfo.id && element.Id !== selectorInfo.id) {
|
|
222
|
-
return false
|
|
253
|
+
return false
|
|
223
254
|
}
|
|
224
255
|
|
|
225
256
|
// Check classes
|
|
226
257
|
if (selectorInfo.classes.length > 0) {
|
|
227
|
-
const elementClasses = element.className.split(' ').filter(c => c)
|
|
258
|
+
const elementClasses = element.className.split(' ').filter(c => c)
|
|
228
259
|
for (const className of selectorInfo.classes) {
|
|
229
260
|
if (!elementClasses.includes(className)) {
|
|
230
|
-
return false
|
|
261
|
+
return false
|
|
231
262
|
}
|
|
232
263
|
}
|
|
233
264
|
}
|
|
234
265
|
|
|
235
|
-
return true
|
|
266
|
+
return true
|
|
236
267
|
}
|
|
237
268
|
|
|
238
269
|
export function querySelectorAll(root: DomWrapper, selector: string): DomWrapper[] {
|
|
239
|
-
const results: DomWrapper[] = []
|
|
240
|
-
const selectorInfo = parseSelector(selector)
|
|
270
|
+
const results: DomWrapper[] = []
|
|
271
|
+
const selectorInfo = parseSelector(selector)
|
|
241
272
|
|
|
242
273
|
function traverse(element: DomWrapper) {
|
|
243
274
|
// Check if current element matches
|
|
244
275
|
if (elementMatchesSelector(element, selectorInfo)) {
|
|
245
|
-
results.push(element)
|
|
276
|
+
results.push(element)
|
|
246
277
|
}
|
|
247
278
|
|
|
248
279
|
// Recursively check children
|
|
249
280
|
for (const child of element.childNodes) {
|
|
250
|
-
traverse(child)
|
|
281
|
+
traverse(child)
|
|
251
282
|
}
|
|
252
283
|
}
|
|
253
284
|
|
|
254
|
-
traverse(root)
|
|
255
|
-
return results
|
|
285
|
+
traverse(root)
|
|
286
|
+
return results
|
|
256
287
|
}
|
|
257
288
|
|
|
258
289
|
export function querySelector(root: DomWrapper, selector: string): DomWrapper | null {
|
|
259
|
-
const selectorInfo = parseSelector(selector)
|
|
290
|
+
const selectorInfo = parseSelector(selector)
|
|
260
291
|
|
|
261
292
|
function traverse(element: DomWrapper): DomWrapper | null {
|
|
262
293
|
// Check if current element matches
|
|
263
294
|
if (elementMatchesSelector(element, selectorInfo)) {
|
|
264
|
-
return element
|
|
295
|
+
return element
|
|
265
296
|
}
|
|
266
297
|
|
|
267
298
|
// Recursively check children
|
|
268
299
|
for (const child of element.childNodes) {
|
|
269
|
-
const match = traverse(child)
|
|
300
|
+
const match = traverse(child)
|
|
270
301
|
if (match) {
|
|
271
|
-
return match
|
|
302
|
+
return match
|
|
272
303
|
}
|
|
273
304
|
}
|
|
274
305
|
|
|
275
|
-
return null
|
|
306
|
+
return null
|
|
276
307
|
}
|
|
277
308
|
|
|
278
|
-
return traverse(root)
|
|
309
|
+
return traverse(root)
|
|
279
310
|
}
|
|
280
311
|
|
|
281
312
|
class DomTokenList {
|
package/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ declare global {
|
|
|
44
44
|
}
|
|
45
45
|
const newCsArray: <T>(type: { new(...args: any[]): T }, count: number) => CS.System.Array
|
|
46
46
|
const toJsArray: <T>(csArr: CS.System.Array) => T[]
|
|
47
|
+
const toCsArray: <T>(jsArr: T[], type: { new(...args: any[]): T }) => CS.System.Array
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
if (typeof globalThis.___document != "undefined") {
|
package/package.json
CHANGED