forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
501 lines (448 loc) · 14.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
// Type definitions for AFRAME 1.2
// Project: https://aframe.io/
// Definitions by: Paul Shannon <https://github.com/devpaul>
// Roberto Ritger <https://github.com/bertoritger>
// Trygve Wastvedt <https://github.com/twastvedt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.6
/**
* Extended tests and examples available at https://github.com/devpaul/aframe-experiments.git
*/
import * as anime from 'animejs';
import * as three from 'three';
import * as threeDeprecated from 'three/examples/jsm/deprecated/Geometry';
export type ThreeLib = typeof three;
export type AnimeLib = typeof anime;
export interface ObjectMap<T = any> {
[key: string]: T;
}
export interface Animation {
attribute: string;
begin: string | number;
delay: number;
direction: 'alternate' | 'alternateReverse' | 'normal' | 'reverse';
dur: number;
easing(): void;
end: string;
fill: 'backwards' | 'both' | 'forwards' | 'none';
from: any; // TODO type
repeat: number | 'indefinite';
to: number;
}
export interface ANode extends HTMLElement {
// Only public APIs added. Many methods intentionally left out.
// createdCallback
// attachedCallback
// attributeChangedCallback
closestScene(): Scene;
closest(selector: string): ANode;
// detachedCallback
hasLoaded: boolean;
load(cb?: () => void, childFilter?: (el: Element) => boolean): void;
// updateMixins
registerMixin(id: string): void;
setAttribute(type: string, newValue: any): void;
unregisterMixin(id: string): void;
removeMixinListener(id: string): void;
attachMixinListener(mixin: HTMLElement): void;
emit(name: string, detail?: any, bubbles?: boolean): void;
emitter(name: string, detail?: any, bubbles?: boolean): () => void;
}
export interface Behavior {
tick(): void;
}
export interface Component<T extends object = any, S extends System = System> {
attrName?: string | undefined;
data: T;
dependencies?: string[] | undefined;
el: Entity;
id: string;
initialized: boolean;
multiple?: boolean | undefined;
name: string;
schema: Schema<T>;
system: S | undefined;
events?: any;
init(data?: T): void;
pause(): void;
play(): void;
remove(): void;
tick?(time: number, timeDelta: number): void;
tock?(time: number, timeDelta: number, camera: THREE.Camera): void;
update(oldData: T): void;
updateSchema?(): void;
extendSchema(update: Schema): void;
flushToDOM(): void;
}
export interface ComponentConstructor<T extends object> {
new (el: Entity, attrValue: string, id: string): T & Component;
prototype: T & {
name: string;
system: System;
play(): void;
pause(): void;
};
}
export interface ComponentDescriptor<T extends Component = Component> {
Component: ComponentConstructor<T>;
dependencies: string[] | undefined;
multiple: boolean | undefined;
// internal APIs2
// parse
// parseAttrValueForCache
// schema
// stringify
// type
}
export interface Coordinate {
x: number;
y: number;
z: number;
}
export interface DefaultComponents {
position: Component<Coordinate>;
rotation: Component<Coordinate>;
scale: Component<Coordinate>;
}
export interface Entity<C = ObjectMap<Component>> extends ANode {
components: C & DefaultComponents;
hasLoaded: boolean;
isPlaying: boolean;
object3D: THREE.Object3D;
object3DMap: ObjectMap<THREE.Object3D>;
sceneEl?: Scene | undefined;
destroy(): void;
addState(name: string): void;
flushToDOM(recursive?: boolean): void;
/**
* @deprecated since 0.4.0
*/
getComputedAttribute(attr: string): Component;
getDOMAttribute(attr: string): any;
getObject3D(type: string): THREE.Object3D;
getOrCreateObject3D(type: string, construct: any): THREE.Object3D;
is(stateName: string): boolean;
pause(): void;
play(): void;
setObject3D(type: string, obj: THREE.Object3D): void;
removeAttribute(attr: string, property?: string): void;
removeObject3D(type: string): void;
removeState(stateName: string): void;
// getAttribute specific usages
getAttribute(type: string): any;
getAttribute(type: 'position' | 'rotation' | 'scale'): Coordinate;
// setAttribute specific usages
setAttribute(attr: string, value: any): void;
setAttribute(attr: string, property: string, componentAttrValue?: any): void;
setAttribute(type: 'position' | 'rotation' | 'scale', value: Coordinate): void;
// addEventListener specific usages
addEventListener<K extends keyof EntityEventMap>(
type: K,
listener: (event: Event & EntityEventMap[K]) => void,
useCapture?: boolean
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
useCapture?: boolean
): void;
}
export type DetailEvent<D> = Event & {
detail: D;
target: EventTarget & Entity;
};
export interface EntityEventMap {
'child-attached': DetailEvent<{ el: Element | Entity }>;
'child-detached': DetailEvent<{ el: Element | Entity }>;
componentchanged: DetailEvent<{
name: string;
id: string;
}>;
componentinitialized: DetailEvent<{
name: string;
id: string;
data: any;
}>;
componentremoved: DetailEvent<{
name: string;
id: string;
newData: any;
oldData: any;
}>;
loaded: EventListener;
pause: EventListener;
play: EventListener;
stateadded: DetailEvent<{ state: string }>;
stateremoved: DetailEvent<{ state: string }>;
schemachanged: DetailEvent<{ componentName: string }>;
}
export interface Geometry<T = any> {
data: T;
name: string;
geometry: threeDeprecated.Geometry;
schema: Schema<any>;
init(data: any): void;
}
export interface GeometryConstructor<T extends object = object> {
new (): T & Geometry;
}
export interface GeometryDescriptor<T extends Geometry = Geometry> {
Geometry: GeometryConstructor<T>;
schema: Schema;
}
export type MultiPropertySchema<T extends object> = {
[P in keyof T]: SinglePropertySchema<T[P]> | T[P]
};
export type PropertyTypes =
| 'array'
| 'asset'
| 'audio'
| 'boolean'
| 'color'
| 'int'
| 'map'
| 'model'
| 'number'
| 'selector'
| 'selectorAll'
| 'string'
| 'vec2'
| 'vec3'
| 'vec4';
export type SceneEvents = 'enter-vr' | 'exit-vr' | 'loaded' | 'renderstart';
export interface Scene extends Entity {
behaviors: Behavior[];
camera: THREE.Camera;
canvas: HTMLCanvasElement;
isMobile: boolean;
object3D: THREE.Scene;
renderer: THREE.WebGLRenderer;
renderStarted: boolean;
effect?: any; // THREE.VREffect
systems: ObjectMap<System>;
time: number;
enterVR(): Promise<void> | void;
exitVR(): Promise<void> | void;
reload(): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
useCapture?: boolean
): void;
addEventListener(type: SceneEvents, listener: EventListener, useCapture?: boolean): void;
}
export type Schema<T extends object = object> = SinglePropertySchema<T> | MultiPropertySchema<T>;
export interface SchemaUtils {
isSingleProperty(schema: Schema): boolean;
process(schema: Schema): boolean;
}
export interface Shader {
name: string;
data: object;
schema: Schema<this['data']>;
material: THREE.Material;
vertexShader: string;
fragmentShader: string;
init(data?: this['data']): void;
tick?(time: number, timeDelta: number): void;
update(oldData: this['data']): void;
}
export interface ShaderConstructor<T extends object> {
new (): T;
}
export interface ShaderDescriptor<T extends Shader = Shader> {
Shader: ShaderConstructor<T>;
schema: Schema;
}
export interface SinglePropertySchema<T> {
type?: PropertyTypes | undefined;
default?: T | undefined;
parse?(value: string): T;
stringify?(value: T): string;
}
export interface System<T extends object = any> {
data: T;
schema: Schema<T>;
el: Entity;
init(): void;
pause(): void;
play(): void;
tick?(t: number, dt: number): void;
}
export interface SystemConstructor<T extends object = object> {
new (scene: Scene): T & System;
}
export interface Utils {
coordinates: {
isCoordinate(value: string): boolean;
parse(value: string): Coordinate;
stringify(coord: Coordinate): string;
};
entity: {
getComponentProperty(entity: Entity, componentName: string, delimiter?: string): any;
setComponentProperty(
entity: Entity,
componentName: string,
value: any,
delimiter?: string
): void;
};
device: {
isWebXRAvailable: boolean;
checkHeadsetConnected(): boolean;
checkHasPositionalTracking(): boolean;
isMobile(): boolean;
isTablet(): boolean;
isIOS(): boolean;
isGearVR(): boolean;
isOculusGo(): boolean;
isR7(): boolean;
isLandscape(): boolean;
isBrowserEnvironment(): boolean;
isNodeEnvironment(): boolean;
PolyfillControls(object3D: THREE.Object3D): void;
};
styleParser: {
parse(value: string): object;
stringify(data: object): string;
};
deepEqual(a: any, b: any): boolean;
diff(a: object, b: object): object;
extend(target: object, ...source: object[]): object;
extendDeep(target: object, ...source: object[]): object;
throttle(
tickFunction: () => void,
minimumInterval: number,
optionalContext?: {}
): (t: number, dt: number) => void;
throttleTick(
tickFunction: (t: number, dt: number) => void,
minimumInterval: number,
optionalContext?: {}
): (t: number, dt: number) => void;
}
// Definitions
// used as mixins to register functions to create classes (newable functions) in A-Frame
export type ComponentDefinition<T extends object = object> = T & Partial<Component> & ThisType<T & Component>;
export type GeometryDefinition<T extends object = object, U = any> = T & Partial<Geometry<U>>;
export type NodeDefinition<T extends object = object> = T & Partial<ANode>;
export interface PrimitiveDefinition {
defaultComponents?: any; // TODO cleanup type
deprecated?: boolean | undefined;
mappings?: any; // TODO cleanup type
transforms?: any; // TODO cleanup type
}
export interface MinimalShaderDefinition {
schema: Shader['schema'];
}
export type ShaderDefinition<T extends object = MinimalShaderDefinition & object> = T &
Partial<Shader>;
export type SystemDefinition<T extends object = object> = T & Partial<System>;
// root export
export interface AFrame {
AComponent: Component;
AEntity: Entity;
ANode: ANode;
AScene: Scene;
components: ObjectMap<ComponentDescriptor>;
geometries: ObjectMap<GeometryDescriptor>;
primitives: {
getMeshMixin(): {
defaultComponents: { material: object };
mappings: { [key: string]: any }; // TODO improve any type
};
primitives: ObjectMap<Entity>;
};
scenes: Scene[];
schema: SchemaUtils;
shaders: ObjectMap<ShaderDescriptor>;
systems: ObjectMap<SystemConstructor>;
THREE: ThreeLib;
ANIME: AnimeLib;
utils: Utils;
version: string;
registerComponent<T extends object>(
name: string,
component: ComponentDefinition<T>
): ComponentConstructor<T>;
registerElement(name: string, element: object): void;
registerGeometry<T extends object>(
name: string,
geometry: GeometryDefinition<T>
): GeometryConstructor<T>;
registerPrimitive(name: string, primitive: PrimitiveDefinition): void;
registerShader<T extends MinimalShaderDefinition & object>(
name: string,
shader: ShaderDefinition<T>
): ShaderConstructor<T>;
registerSystem<T extends object>(
name: string,
definition: SystemDefinition<T>
): SystemConstructor<T>;
}
// module.exports
export const AComponent: AFrame['AComponent'];
export const AEntity: AFrame['AEntity'];
export const ANode: AFrame['ANode'];
export const AScene: AFrame['AScene'];
export const components: AFrame['components'];
export const geometries: AFrame['geometries'];
export const primitives: AFrame['primitives'];
export const scenes: AFrame['scenes'];
export const schema: AFrame['schema'];
export const shaders: AFrame['shaders'];
export const systems: AFrame['systems'];
export const THREE: AFrame['THREE'];
export const ANIME: AFrame['ANIME'];
export const utils: AFrame['utils'];
export const version: AFrame['version'];
export const registerComponent: AFrame['registerComponent'];
export const registerElement: AFrame['registerElement'];
export const registerGeometry: AFrame['registerGeometry'];
export const registerPrimitive: AFrame['registerPrimitive'];
export const registerShader: AFrame['registerShader'];
export const registerSystem: AFrame['registerSystem'];
// global exports
declare global {
var hasNativeWebVRImplementation: boolean;
namespace AFRAME {
const AComponent: AFrame['AComponent'];
const AEntity: AFrame['AEntity'];
const ANode: AFrame['ANode'];
const AScene: AFrame['AScene'];
const components: AFrame['components'];
const geometries: AFrame['geometries'];
const primitives: AFrame['primitives'];
const scenes: AFrame['scenes'];
const schema: AFrame['schema'];
const shaders: AFrame['shaders'];
const systems: AFrame['systems'];
const THREE: AFrame['THREE'];
const ANIME: AFrame['ANIME'];
const utils: AFrame['utils'];
const version: string;
const registerComponent: AFrame['registerComponent'];
const registerElement: AFrame['registerElement'];
const registerGeometry: AFrame['registerGeometry'];
const registerPrimitive: AFrame['registerPrimitive'];
const registerShader: AFrame['registerShader'];
const registerSystem: AFrame['registerSystem'];
}
/**
* Custom elements augment document methods to return custom HTML
*/
interface Document {
createElement(tagName: string): Entity;
querySelector(selectors: 'a-scene'): Scene;
querySelector(selectors: string): Entity<any>;
querySelectorAll(selectors: string): NodeListOf<Entity<any> | Element>;
}
interface HTMLCollection extends HTMLCollectionBase {
/**
* Retrieves a select object or an object from an options collection.
*/
namedItem(name: string): Element | Entity | null;
item(index: number): Element | Entity;
[index: number]: Element | Entity;
}
}