Skip to content

Testing type definitions (Typescript) #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aframe/build/aframe-ar-nft.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion aframe/build/aframe-ar.js

Large diffs are not rendered by default.

3,143 changes: 3,058 additions & 85 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
"version": "3.4.3",
"description": "Efficient Augmented Reality for the Web",
"main": "./aframe/build/aframe-ar.js",
"types": "./types/aframe/index.d.ts",
"scripts": {
"format-check": "prettier --check .",
"format": "prettier --write .",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/webpack --mode=production",
"build:dev": "./node_modules/.bin/webpack --mode=development --progress --watch",
"build-types": "tsc",
"server": "npx http-server -c -1",
"prepare": "husky install"
},
"files": [
"three.js/build",
"aframe/build"
"aframe/build",
"types"
],
"repository": {
"type": "git",
Expand Down Expand Up @@ -51,17 +54,18 @@
},
"homepage": "https://github.com/AR-js-org/AR.js/",
"devDependencies": {
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"husky": "^8.0.3",
"lint-staged": "^13.1.0",
"prettier": "^2.8.3",
"typescript": "^4.9.4",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"worker-loader": "^3.0.8"
},
"dependencies": {
"@ar-js-org/artoolkit5-js": "^0.2.0",
"aframe": "^1.0.4",
"three": "^0.146.0"
"three": "^0.148.0"
},
"lint-staged": {
"*.js": "prettier --write"
Expand Down
2 changes: 1 addition & 1 deletion three.js/build/ar-threex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion three.js/build/ar.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions three.js/src/location-based/js/device-orientation-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const _q1 = new Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)); // - PI/2 aro

const _changeEvent = { type: "change" };

/**
* @type Class
*/
class DeviceOrientationControls extends EventDispatcher {
constructor(object) {
super();
Expand Down
8 changes: 7 additions & 1 deletion three.js/src/markers-area/arjs-markersareacontrols.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import ArBaseControls from "../threex/threex-arbasecontrols";
import ArMarkerControls from "../threex/arjs-markercontrols";
import ArMultiMarkerControls from "./arjs-markersareacontrols";

/**
* @type Class
* @param {any} arToolkitContext
* @param {any} object3d
* @param {any} parameters
*/
const MarkersAreaControls = function (arToolkitContext, object3d, parameters) {
var _this = this;
ArBaseControls.call(this, object3d);
Expand Down Expand Up @@ -36,7 +42,7 @@ const MarkersAreaControls = function (arToolkitContext, object3d, parameters) {
};

MarkersAreaControls.prototype = Object.create(ArBaseControls.prototype);
MarkersAreaControls.prototype.constructor = MarkersAreaControls;
//MarkersAreaControls.prototype.constructor = MarkersAreaControls;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickw1 this is odd. I think this is an error in the code design. Actually the constructor of the class is created at line 6:

const MarkersAreaControls = function (arToolkitContext, object3d, parameters) {
  var _this = this;
  ArBaseControls.call(this, object3d);

I have to comment out this line because tsc compiler will create another constructor as a property function instead with a resulting error.

Copy link
Member Author

@kalwalt kalwalt Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should convert the code to really ES6 standard before adding type defs.
so converting the above class to:

class MarkersAreaControls extends ArBaseControl {
constructor(arToolkitContext, object3d, parameters) {
// other code here
}

}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalwalt I'm not familiar with this code, but I would strongly support using ES6 classes over older methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that AR.js can be improved a lot in terms of readability if rewritten using ES6 classes. Not sure if this task it can be done before or after adding type definitions. This PR is a kind of test at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway removing that line has no side effect, i recompiled the libs and tested most of the examples with success. I think this was an old bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading in the mdn documentation prototype.constructor is actually the constructor of the created object (class). So not a mistake but maybe it's not needed. Anyway i will continue to convert the code ot Typescript and a more modern standard.


//////////////////////////////////////////////////////////////////////////////
// Code Separator
Expand Down
5 changes: 5 additions & 0 deletions three.js/src/markers-area/arjs-markersarealearning.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import ArMultiMarkerControls from "./arjs-markersareacontrols";

/**
* @type Class
* @param {any} arToolkitContext
* @param {any} subMarkersControls
*/
const MarkersAreaLearning = function (arToolkitContext, subMarkersControls) {
var _this = this;
this._arToolkitContext = arToolkitContext;
Expand Down
2 changes: 1 addition & 1 deletion three.js/src/new-api/arjs-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MarkersAreaUtils from "../markers-area/arjs-markersareautils";

/**
* Create an anchor in the real world
*
* @type Class
* @param {ARjs.Session} arSession - the session on which we create the anchor
* @param {Object} markerParameters - parameter of this anchor
*/
Expand Down
4 changes: 2 additions & 2 deletions three.js/src/new-api/arjs-debugui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Context from "../threex/arjs-context"; // TODO context build-dependent

/**
* Create an debug UI for an ARjs.Anchor
*
* @type Class
* @param {ARjs.Anchor} arAnchor - the anchor to user
*/
const SessionDebugUI = function (arSession) {
Expand Down Expand Up @@ -41,7 +41,7 @@ SessionDebugUI.AugmentedWebsiteURL = "https://webxr.io/augmented-website";

/**
* Create an debug UI for an ARjs.Anchor
*
* @type Class
* @param {ARjs.Anchor} arAnchor - the anchor to user
*/
const AnchorDebugUI = function (arAnchor) {
Expand Down
2 changes: 1 addition & 1 deletion three.js/src/new-api/arjs-hittesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import HitTestingPlane from "../threex/threex-hittesting-plane";

/**
* Create an anchor in the real world
*
* @type Class
* @param {ARjs.Session} arSession - the session on which we create the anchor
* @param {Object} markerParameters - parameter of this anchor
*/
Expand Down
4 changes: 2 additions & 2 deletions three.js/src/new-api/arjs-session-nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Source from "../threex/arjs-source";
import Context from "../threex/arjs-context"; // TODO context build-dependent

/**
* * define a Session
*
* define a Session
* @type Class
* @param {Object} parameters - parameters for this session
*/
const Session = function (parameters) {
Expand Down
4 changes: 2 additions & 2 deletions three.js/src/new-api/arjs-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Source from "../threex/arjs-source";
import Context from "../threex/arjs-context"; // TODO context build-dependent

/**
* * define a Session
*
* define a Session
* @type Class
* @param {Object} parameters - parameters for this session
*/
const Session = function (parameters) {
Expand Down
5 changes: 4 additions & 1 deletion three.js/src/threex/arjs-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as THREE from "three";
import ArMarkerControls from "./arjs-markercontrols";
import jsartoolkit from "jsartoolkit"; // TODO comment explanation
const { ARController } = jsartoolkit;

/**
* @type Class
* @param {object} parameters
*/
const Context = function (parameters) {
var _this = this;

Expand Down
9 changes: 8 additions & 1 deletion three.js/src/threex/arjs-markercontrols.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import Worker from "./arjs-markercontrols-nft.worker.js";
import jsartoolkit from "jsartoolkit"; // TODO comment explanation
const { ARToolkit } = jsartoolkit;

/**
*
* @param {any} context
* @param {any} object3d
* @param {object} parameters
* @type Class
*/
const MarkerControls = function (context, object3d, parameters) {
var _this = this;

Expand Down Expand Up @@ -99,7 +106,7 @@ const MarkerControls = function (context, object3d, parameters) {
};

MarkerControls.prototype = Object.create(ArBaseControls.prototype);
MarkerControls.prototype.constructor = MarkerControls;
//MarkerControls.prototype.constructor = MarkerControls;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


//////////////////////////////////////////////////////////////////////////////
// dispose instance
Expand Down
1 change: 1 addition & 0 deletions three.js/src/threex/arjs-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ArToolkitContext from "./arjs-context"; // TODO context build-dependent
* - all the other classes are still expecting normal parameters
* - you can use this class to understand how to tune your specific usecase
* - it is made to help people to build parameters without understanding all the underlying details.
* @type Class
*/
const Profile = function () {
this.reset();
Expand Down
4 changes: 4 additions & 0 deletions three.js/src/threex/arjs-source.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @type Class
* @param {object} parameters
*/
const Source = function (parameters) {
var _this = this;

Expand Down
4 changes: 4 additions & 0 deletions three.js/src/threex/threex-arbasecontrols.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as THREE from "three";

/**
* @type Class
* @param {any} object3d
*/
const ArBaseControls = function (object3d) {
this.id = ArBaseControls.id++;

Expand Down
2 changes: 2 additions & 0 deletions three.js/src/threex/threex-arclickability.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as THREE from "three";
* - maybe support .onClickFcts in each object3d
* - seems an easy light layer for clickable object
* - up to
* @type Class
* @param {any} sourceElement
*/
const ARClickability = function (sourceElement) {
this._sourceElement = sourceElement;
Expand Down
2 changes: 2 additions & 0 deletions three.js/src/threex/threex-armarkercloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as THREE from "three";
* - cloakHeight
* - cloakSegmentsHeight
* - remove all mentions of cache, for cloak
* @type Class
* @param {any} videoTexture
*/
const ArMarkerCloak = function (videoTexture) {
var updateInShaderEnabled = true;
Expand Down
4 changes: 4 additions & 0 deletions three.js/src/threex/threex-armarkerhelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as THREE from "three";

/**
* @type Class
* @param {any} markerControls
*/
const ArMarkerHelper = function (markerControls) {
this.object3d = new THREE.Group();

Expand Down
7 changes: 4 additions & 3 deletions three.js/src/threex/threex-arsmoothedcontrols.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import ArBaseControls from "./threex-arbasecontrols";
* - lerp position/quaternino/scale
* - minDelayDetected
* - minDelayUndetected
* @param {[type]} object3d [description]
* @param {[type]} parameters [description]
* @type Class
* @param {any} object3d [description]
* @param {any} parameters [description]
*/
const ArSmoothedControls = function (object3d, parameters) {
var _this = this;
Expand Down Expand Up @@ -69,7 +70,7 @@ const ArSmoothedControls = function (object3d, parameters) {
};

ArSmoothedControls.prototype = Object.create(ArBaseControls.prototype);
ArSmoothedControls.prototype.constructor = ArSmoothedControls;
//ArSmoothedControls.prototype.constructor = ArSmoothedControls;

//////////////////////////////////////////////////////////////////////////////
// update function
Expand Down
2 changes: 1 addition & 1 deletion three.js/src/threex/threex-artoolkitprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Profile from "./arjs-profile";
* - all the other classes are still expecting normal parameters
* - you can use this class to understand how to tune your specific usecase
* - it is made to help people to build parameters without understanding all the underlying details.
* @type Class
*/

const ArToolkitProfile = Profile;

export default ArToolkitProfile;
4 changes: 4 additions & 0 deletions three.js/src/threex/threex-arvideoinwebgl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as THREE from "three";

/**
* @type Class
* @param {any} videoTexture
*/
const ArVideoInWebgl = function (videoTexture) {
var _this = this;

Expand Down
2 changes: 2 additions & 0 deletions three.js/src/threex/threex-hittesting-plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as THREE from "three";
* - maybe support .onClickFcts in each object3d
* - seems an easy light layer for clickable object
* - up to
* @type Class
* @param {any} sourceElement
*/
const HitTestingPlane = function (sourceElement) {
this._sourceElement = sourceElement;
Expand Down
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Change this to match your project
"include": ["three.js/src/*", "three.js/src/**/*", "aframe/src/*"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
"allowSyntheticDefaultImports": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": true
}
}
2 changes: 2 additions & 0 deletions types/aframe/src/component-anchor-nft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=component-anchor-nft.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/component-anchor-nft.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/component-anchor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=component-anchor.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/component-anchor.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/component-hit-testing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=component-hit-testing.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/component-hit-testing.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/index-nft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index-nft.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/index-nft.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/location-based/arjs-look-controls.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=arjs-look-controls.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/location-based/arjs-webcam-texture.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=arjs-webcam-texture.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/location-based/gps-camera.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-camera.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/location-based/gps-camera.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/location-based/gps-entity-place.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-entity-place.d.ts.map
1 change: 1 addition & 0 deletions types/aframe/src/location-based/gps-entity-place.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/location-based/gps-projected-camera.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-projected-camera.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-projected-entity-place.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=arjs-device-orientation-controls.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/new-location-based/gps-new-camera.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-new-camera.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/new-location-based/gps-new-entity-place.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=gps-new-entity-place.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/aframe/src/system-arjs-nft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=system-arjs-nft.d.ts.map
Loading