@mulsense/xnew 0.1.8 → 0.1.10

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 (37) hide show
  1. package/README.md +46 -46
  2. package/dist/types/audio/audio.d.ts +55 -2
  3. package/dist/types/audio/loader.d.ts +6 -2
  4. package/dist/types/basics/Event.d.ts +4 -3
  5. package/dist/types/basics/Touch.d.ts +9 -8
  6. package/dist/types/core/time.d.ts +6 -2
  7. package/dist/types/core/unit.d.ts +41 -10
  8. package/dist/types/core/xnew.d.ts +11 -21
  9. package/dist/types/index.d.ts +3 -12
  10. package/dist/xnew.d.ts +48 -63
  11. package/dist/xnew.js +375 -400
  12. package/dist/xnew.mjs +375 -400
  13. package/package.json +78 -78
  14. package/dist/addons/xmatter.d.ts +0 -6
  15. package/dist/addons/xmatter.js +0 -43
  16. package/dist/addons/xmatter.mjs +0 -38
  17. package/dist/addons/xpixi.d.ts +0 -10
  18. package/dist/addons/xpixi.js +0 -99
  19. package/dist/addons/xpixi.mjs +0 -75
  20. package/dist/addons/xrapier2d.d.ts +0 -6
  21. package/dist/addons/xrapier2d.js +0 -69
  22. package/dist/addons/xrapier2d.mjs +0 -64
  23. package/dist/addons/xthree.d.ts +0 -9
  24. package/dist/addons/xthree.js +0 -77
  25. package/dist/addons/xthree.mjs +0 -53
  26. package/dist/types/basics/Block.d.ts +0 -24
  27. package/dist/types/basics/Bullet.d.ts +0 -7
  28. package/dist/types/basics/ControlPanel.d.ts +0 -7
  29. package/dist/types/basics/Navigation.d.ts +0 -1
  30. package/dist/types/basics/Panel.d.ts +0 -6
  31. package/dist/types/basics/Popup.d.ts +0 -8
  32. package/dist/types/basics/TabView.d.ts +0 -18
  33. package/dist/types/basics/Tabs.d.ts +0 -8
  34. package/dist/types/basics/Transition.d.ts +0 -17
  35. package/dist/types/basics/WorkSpace.d.ts +0 -16
  36. package/dist/types/core/util.d.ts +0 -1
  37. package/dist/types/xnew.d.ts +0 -8
package/package.json CHANGED
@@ -1,78 +1,78 @@
1
- {
2
- "name": "@mulsense/xnew",
3
- "description": "JavaScript Library for Component-Oriented Programming.",
4
- "keywords": [
5
- "Component-Oriented Programming"
6
- ],
7
- "version": "0.1.8",
8
- "main": "dist/xnew.js",
9
- "module": "dist/xnew.mjs",
10
- "types": "dist/xnew.d.ts",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/xnew.d.ts",
14
- "import": "./dist/xnew.mjs",
15
- "require": "./dist/xnew.js"
16
- },
17
- "./addons/xmatter": {
18
- "types": "./dist/addons/xmatter.d.ts",
19
- "import": "./dist/addons/xmatter.mjs",
20
- "require": "./dist/addons/xmatter.js"
21
- },
22
- "./addons/xpixi": {
23
- "types": "./dist/addons/xpixi.d.ts",
24
- "import": "./dist/addons/xpixi.mjs",
25
- "require": "./dist/addons/xpixi.js"
26
- },
27
- "./addons/xrapier2d": {
28
- "types": "./dist/addons/xrapier2d.d.ts",
29
- "import": "./dist/addons/xrapier2d.mjs",
30
- "require": "./dist/addons/xrapier2d.js"
31
- },
32
- "./addons/xthree": {
33
- "types": "./dist/addons/xthree.d.ts",
34
- "import": "./dist/addons/xthree.mjs",
35
- "require": "./dist/addons/xthree.js"
36
- }
37
- },
38
- "files": [
39
- "dist",
40
- "LICENSE",
41
- "README.md"
42
- ],
43
- "license": "MIT",
44
- "bugs": {
45
- "url": "https://github.com/mulsense/xnew/issues"
46
- },
47
- "homepage": "https://github.com/mulsense/xnew#readme",
48
- "scripts": {
49
- "test": "jest",
50
- "build": "npx rollup --config rollup.config.js --bundleConfigAsCjs",
51
- "dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs",
52
- "build:addons": "npx rollup --config rollup.addons.config.js --bundleConfigAsCjs",
53
- "dev:addons": "npx rollup --config rollup.addons.config.js --watch --bundleConfigAsCjs"
54
- },
55
- "devDependencies": {
56
- "@babel/core": "^7.26.0",
57
- "@babel/preset-env": "^7.26.0",
58
- "@dimforge/rapier2d-compat": "^0.19.2",
59
- "@mulsense/xnew": "^0.1.0",
60
- "@rollup/plugin-typescript": "^12.1.2",
61
- "@types/jest": "^29.5.14",
62
- "@types/matter-js": "^0.19.8",
63
- "@types/node": "^22.15.17",
64
- "@types/three": "^0.176.0",
65
- "babel-jest": "^29.7.0",
66
- "jest": "^29.7.0",
67
- "jest-environment-jsdom": "^29.7.0",
68
- "matter-js": "^0.20.0",
69
- "onchange": "^7.1.0",
70
- "pixi.js": "^8.9.2",
71
- "rollup": "^3.3.0",
72
- "rollup-plugin-dts": "^6.2.1",
73
- "three": "^0.176.0",
74
- "ts-jest": "^29.3.2",
75
- "tslib": "^2.8.1",
76
- "typescript": "^5.8.3"
77
- }
78
- }
1
+ {
2
+ "name": "@mulsense/xnew",
3
+ "description": "JavaScript Library for Component-Oriented Programming.",
4
+ "keywords": [
5
+ "Component-Oriented Programming"
6
+ ],
7
+ "version": "0.1.10",
8
+ "main": "dist/xnew.js",
9
+ "module": "dist/xnew.mjs",
10
+ "types": "dist/xnew.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/xnew.d.ts",
14
+ "import": "./dist/xnew.mjs",
15
+ "require": "./dist/xnew.js"
16
+ },
17
+ "./addons/xmatter": {
18
+ "types": "./dist/addons/xmatter.d.ts",
19
+ "import": "./dist/addons/xmatter.mjs",
20
+ "require": "./dist/addons/xmatter.js"
21
+ },
22
+ "./addons/xpixi": {
23
+ "types": "./dist/addons/xpixi.d.ts",
24
+ "import": "./dist/addons/xpixi.mjs",
25
+ "require": "./dist/addons/xpixi.js"
26
+ },
27
+ "./addons/xrapier2d": {
28
+ "types": "./dist/addons/xrapier2d.d.ts",
29
+ "import": "./dist/addons/xrapier2d.mjs",
30
+ "require": "./dist/addons/xrapier2d.js"
31
+ },
32
+ "./addons/xthree": {
33
+ "types": "./dist/addons/xthree.d.ts",
34
+ "import": "./dist/addons/xthree.mjs",
35
+ "require": "./dist/addons/xthree.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "LICENSE",
41
+ "README.md"
42
+ ],
43
+ "license": "MIT",
44
+ "bugs": {
45
+ "url": "https://github.com/mulsense/xnew/issues"
46
+ },
47
+ "homepage": "https://github.com/mulsense/xnew#readme",
48
+ "scripts": {
49
+ "test": "jest",
50
+ "build": "npx rollup --config rollup.config.js --bundleConfigAsCjs",
51
+ "dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs",
52
+ "build:addons": "npx rollup --config rollup.addons.config.js --bundleConfigAsCjs",
53
+ "dev:addons": "npx rollup --config rollup.addons.config.js --watch --bundleConfigAsCjs"
54
+ },
55
+ "devDependencies": {
56
+ "@babel/core": "^7.26.0",
57
+ "@babel/preset-env": "^7.26.0",
58
+ "@dimforge/rapier2d-compat": "^0.19.2",
59
+ "@mulsense/xnew": "^0.1.0",
60
+ "@rollup/plugin-typescript": "^12.1.2",
61
+ "@types/jest": "^29.5.14",
62
+ "@types/matter-js": "^0.19.8",
63
+ "@types/node": "^22.15.17",
64
+ "@types/three": "^0.176.0",
65
+ "babel-jest": "^29.7.0",
66
+ "jest": "^29.7.0",
67
+ "jest-environment-jsdom": "^29.7.0",
68
+ "matter-js": "^0.20.0",
69
+ "onchange": "^7.1.0",
70
+ "pixi.js": "^8.9.2",
71
+ "rollup": "^3.3.0",
72
+ "rollup-plugin-dts": "^6.2.1",
73
+ "three": "^0.176.0",
74
+ "ts-jest": "^29.3.2",
75
+ "tslib": "^2.8.1",
76
+ "typescript": "^5.8.3"
77
+ }
78
+ }
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- initialize({ engine }?: any): void;
3
- nest(object: any): any;
4
- readonly engine: any;
5
- };
6
- export default _default;
@@ -1,43 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@mulsense/xnew'), require('matter-js')) :
3
- typeof define === 'function' && define.amd ? define(['@mulsense/xnew', 'matter-js'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xmatter = factory(global.xnew, global.Matter));
5
- })(this, (function (xnew, Matter) { 'use strict';
6
-
7
- var xmatter = {
8
- initialize({ engine = null } = {}) {
9
- xnew.extend(Root, { engine });
10
- },
11
- nest(object) {
12
- xnew.extend(Nest, { object });
13
- return object;
14
- },
15
- get engine() {
16
- var _a;
17
- return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine;
18
- },
19
- };
20
- function Root(self, { engine }) {
21
- const root = {};
22
- xnew.context('xmatter.root', root);
23
- root.isActive = true;
24
- root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
25
- xnew.context('xmatter.object', root.engine.world);
26
- self.on('update', () => {
27
- if (root.isActive) {
28
- Matter.Engine.update(root.engine);
29
- }
30
- });
31
- }
32
- function Nest(self, { object }) {
33
- const parent = xnew.context('xmatter.object');
34
- xnew.context('xmatter.object', object);
35
- Matter.Composite.add(parent, object);
36
- self.on('finalize', () => {
37
- Matter.Composite.remove(parent, object);
38
- });
39
- }
40
-
41
- return xmatter;
42
-
43
- }));
@@ -1,38 +0,0 @@
1
- import xnew from '@mulsense/xnew';
2
- import Matter from 'matter-js';
3
-
4
- var xmatter = {
5
- initialize({ engine = null } = {}) {
6
- xnew.extend(Root, { engine });
7
- },
8
- nest(object) {
9
- xnew.extend(Nest, { object });
10
- return object;
11
- },
12
- get engine() {
13
- var _a;
14
- return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine;
15
- },
16
- };
17
- function Root(self, { engine }) {
18
- const root = {};
19
- xnew.context('xmatter.root', root);
20
- root.isActive = true;
21
- root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
22
- xnew.context('xmatter.object', root.engine.world);
23
- self.on('update', () => {
24
- if (root.isActive) {
25
- Matter.Engine.update(root.engine);
26
- }
27
- });
28
- }
29
- function Nest(self, { object }) {
30
- const parent = xnew.context('xmatter.object');
31
- xnew.context('xmatter.object', object);
32
- Matter.Composite.add(parent, object);
33
- self.on('finalize', () => {
34
- Matter.Composite.remove(parent, object);
35
- });
36
- }
37
-
38
- export { xmatter as default };
@@ -1,10 +0,0 @@
1
- import * as PIXI from 'pixi.js';
2
- declare const _default: {
3
- initialize({ renderer, canvas }?: any): void;
4
- nest(object: any): any;
5
- sync(canvas: any): PIXI.Texture<PIXI.TextureSource<any>>;
6
- readonly renderer: any;
7
- readonly scene: any;
8
- readonly canvas: any;
9
- };
10
- export default _default;
@@ -1,99 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@mulsense/xnew'), require('pixi.js')) :
3
- typeof define === 'function' && define.amd ? define(['@mulsense/xnew', 'pixi.js'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xpixi = factory(global.xnew, global.PIXI));
5
- })(this, (function (xnew, PIXI) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var PIXI__namespace = /*#__PURE__*/_interopNamespaceDefault(PIXI);
25
-
26
- var xpixi = {
27
- initialize({ renderer = null, canvas = null } = {}) {
28
- xnew.extend(Root, { renderer, canvas });
29
- },
30
- nest(object) {
31
- xnew.extend(Nest, { object });
32
- return object;
33
- },
34
- sync(canvas) {
35
- const texture = PIXI__namespace.Texture.from(canvas);
36
- xnew(PreUpdate, () => {
37
- texture.source.update();
38
- });
39
- return texture;
40
- },
41
- get renderer() {
42
- var _a;
43
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.renderer;
44
- },
45
- get scene() {
46
- var _a;
47
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.scene;
48
- },
49
- get canvas() {
50
- var _a;
51
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
52
- }
53
- };
54
- function Root(self, { canvas }) {
55
- const root = {};
56
- xnew.context('xpixi.root', root);
57
- root.canvas = canvas;
58
- const renderer = PIXI__namespace.autoDetectRenderer({
59
- width: canvas.width, height: canvas.height, view: canvas,
60
- antialias: true, backgroundAlpha: 0,
61
- });
62
- root.renderer = null;
63
- if (renderer instanceof Promise) {
64
- xnew.promise(renderer).then((renderer) => root.renderer = renderer);
65
- }
66
- else {
67
- root.renderer = renderer;
68
- }
69
- root.updates = [];
70
- root.scene = new PIXI__namespace.Container();
71
- xnew.context('xpixi.object', root.scene);
72
- self.on('update', () => {
73
- root.updates.forEach((update) => {
74
- update();
75
- });
76
- if (root.renderer && root.scene) {
77
- root.renderer.render(root.scene);
78
- }
79
- });
80
- }
81
- function Nest(self, { object }) {
82
- const parent = xnew.context('xpixi.object');
83
- xnew.context('xpixi.object', object);
84
- parent.addChild(object);
85
- self.on('finalize', () => {
86
- parent.removeChild(object);
87
- });
88
- }
89
- function PreUpdate(self, callback) {
90
- const root = xnew.context('xpixi.root');
91
- root.updates.push(callback);
92
- self.on('finalize', () => {
93
- root.updates = root.updates.filter((update) => update !== callback);
94
- });
95
- }
96
-
97
- return xpixi;
98
-
99
- }));
@@ -1,75 +0,0 @@
1
- import xnew from '@mulsense/xnew';
2
- import * as PIXI from 'pixi.js';
3
-
4
- var xpixi = {
5
- initialize({ renderer = null, canvas = null } = {}) {
6
- xnew.extend(Root, { renderer, canvas });
7
- },
8
- nest(object) {
9
- xnew.extend(Nest, { object });
10
- return object;
11
- },
12
- sync(canvas) {
13
- const texture = PIXI.Texture.from(canvas);
14
- xnew(PreUpdate, () => {
15
- texture.source.update();
16
- });
17
- return texture;
18
- },
19
- get renderer() {
20
- var _a;
21
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.renderer;
22
- },
23
- get scene() {
24
- var _a;
25
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.scene;
26
- },
27
- get canvas() {
28
- var _a;
29
- return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
30
- }
31
- };
32
- function Root(self, { canvas }) {
33
- const root = {};
34
- xnew.context('xpixi.root', root);
35
- root.canvas = canvas;
36
- const renderer = PIXI.autoDetectRenderer({
37
- width: canvas.width, height: canvas.height, view: canvas,
38
- antialias: true, backgroundAlpha: 0,
39
- });
40
- root.renderer = null;
41
- if (renderer instanceof Promise) {
42
- xnew.promise(renderer).then((renderer) => root.renderer = renderer);
43
- }
44
- else {
45
- root.renderer = renderer;
46
- }
47
- root.updates = [];
48
- root.scene = new PIXI.Container();
49
- xnew.context('xpixi.object', root.scene);
50
- self.on('update', () => {
51
- root.updates.forEach((update) => {
52
- update();
53
- });
54
- if (root.renderer && root.scene) {
55
- root.renderer.render(root.scene);
56
- }
57
- });
58
- }
59
- function Nest(self, { object }) {
60
- const parent = xnew.context('xpixi.object');
61
- xnew.context('xpixi.object', object);
62
- parent.addChild(object);
63
- self.on('finalize', () => {
64
- parent.removeChild(object);
65
- });
66
- }
67
- function PreUpdate(self, callback) {
68
- const root = xnew.context('xpixi.root');
69
- root.updates.push(callback);
70
- self.on('finalize', () => {
71
- root.updates = root.updates.filter((update) => update !== callback);
72
- });
73
- }
74
-
75
- export { xpixi as default };
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- initialize({ gravity, timestep }?: any): void;
3
- connect(type: any, object: any): any;
4
- readonly world: any;
5
- };
6
- export default _default;
@@ -1,69 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@mulsense/xnew'), require('@dimforge/rapier2d-compat')) :
3
- typeof define === 'function' && define.amd ? define(['@mulsense/xnew', '@dimforge/rapier2d-compat'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xrapier2d = factory(global.xnew, global.RAPIER));
5
- })(this, (function (xnew, RAPIER) { 'use strict';
6
-
7
- var xrapier2d = {
8
- initialize({ gravity = { x: 0.0, y: 9.81 }, timestep = null } = {}) {
9
- xnew.extend(Root, { gravity, timestep });
10
- },
11
- connect(type, object) {
12
- xnew.extend(Connect, { type, object });
13
- return object;
14
- },
15
- get world() {
16
- var _a;
17
- return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
18
- },
19
- };
20
- function Root(self, { gravity, timestep }) {
21
- const root = {};
22
- xnew.context('xrapier2d.root', root);
23
- xnew.promise(RAPIER.init()).then(() => {
24
- root.world = new RAPIER.World(gravity);
25
- if (timestep !== null) {
26
- root.world.timestep = timestep;
27
- }
28
- // xnew.extend(Nest, root.world);
29
- });
30
- self.on('update', () => {
31
- if (root.world) {
32
- root.world.step();
33
- }
34
- });
35
- }
36
- let count = 0;
37
- function Connect(self, { type, object }) {
38
- const root = xnew.context('xrapier2d.root');
39
- let temp = count++;
40
- console.log(temp, type, object);
41
- // Rapier2D objects (RigidBody, Collider, etc.) are already added to the world
42
- // when created, so we only need to handle removal on finalize
43
- self.on('finalize', () => {
44
- try {
45
- // Check if object is a RigidBody
46
- if (type === 'rigidBody') {
47
- console.log('Removing RigidBody');
48
- root.world.removeRigidBody(object);
49
- }
50
- // Check if object is a Collider
51
- else if (type === 'collider') {
52
- console.log('Removing Collider');
53
- root.world.removeCollider(object);
54
- }
55
- // Check if object is an ImpulseJoint
56
- else if (type === 'impulseJoint') {
57
- console.log('Removing ImpulseJoint');
58
- root.world.removeImpulseJoint(object);
59
- }
60
- }
61
- catch (e) {
62
- // Object may have already been removed
63
- }
64
- });
65
- }
66
-
67
- return xrapier2d;
68
-
69
- }));
@@ -1,64 +0,0 @@
1
- import xnew from '@mulsense/xnew';
2
- import RAPIER from '@dimforge/rapier2d-compat';
3
-
4
- var xrapier2d = {
5
- initialize({ gravity = { x: 0.0, y: 9.81 }, timestep = null } = {}) {
6
- xnew.extend(Root, { gravity, timestep });
7
- },
8
- connect(type, object) {
9
- xnew.extend(Connect, { type, object });
10
- return object;
11
- },
12
- get world() {
13
- var _a;
14
- return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
15
- },
16
- };
17
- function Root(self, { gravity, timestep }) {
18
- const root = {};
19
- xnew.context('xrapier2d.root', root);
20
- xnew.promise(RAPIER.init()).then(() => {
21
- root.world = new RAPIER.World(gravity);
22
- if (timestep !== null) {
23
- root.world.timestep = timestep;
24
- }
25
- // xnew.extend(Nest, root.world);
26
- });
27
- self.on('update', () => {
28
- if (root.world) {
29
- root.world.step();
30
- }
31
- });
32
- }
33
- let count = 0;
34
- function Connect(self, { type, object }) {
35
- const root = xnew.context('xrapier2d.root');
36
- let temp = count++;
37
- console.log(temp, type, object);
38
- // Rapier2D objects (RigidBody, Collider, etc.) are already added to the world
39
- // when created, so we only need to handle removal on finalize
40
- self.on('finalize', () => {
41
- try {
42
- // Check if object is a RigidBody
43
- if (type === 'rigidBody') {
44
- console.log('Removing RigidBody');
45
- root.world.removeRigidBody(object);
46
- }
47
- // Check if object is a Collider
48
- else if (type === 'collider') {
49
- console.log('Removing Collider');
50
- root.world.removeCollider(object);
51
- }
52
- // Check if object is an ImpulseJoint
53
- else if (type === 'impulseJoint') {
54
- console.log('Removing ImpulseJoint');
55
- root.world.removeImpulseJoint(object);
56
- }
57
- }
58
- catch (e) {
59
- // Object may have already been removed
60
- }
61
- });
62
- }
63
-
64
- export { xrapier2d as default };
@@ -1,9 +0,0 @@
1
- declare const _default: {
2
- initialize({ renderer, canvas, camera }?: any): void;
3
- nest(object: any): any;
4
- readonly renderer: any;
5
- readonly camera: any;
6
- readonly scene: any;
7
- readonly canvas: any;
8
- };
9
- export default _default;
@@ -1,77 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@mulsense/xnew'), require('three')) :
3
- typeof define === 'function' && define.amd ? define(['@mulsense/xnew', 'three'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xthree = factory(global.xnew, global.THREE));
5
- })(this, (function (xnew, THREE) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
25
-
26
- var xthree = {
27
- initialize({ renderer = null, canvas = null, camera = null } = {}) {
28
- xnew.extend(Root, { renderer, canvas, camera });
29
- },
30
- nest(object) {
31
- xnew.extend(Nest, { object });
32
- return object;
33
- },
34
- get renderer() {
35
- var _a;
36
- return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.renderer;
37
- },
38
- get camera() {
39
- var _a;
40
- return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.camera;
41
- },
42
- get scene() {
43
- var _a;
44
- return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.scene;
45
- },
46
- get canvas() {
47
- var _a;
48
- return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.canvas;
49
- }
50
- };
51
- function Root(self, { canvas, camera }) {
52
- const root = {};
53
- xnew.context('xthree.root', root);
54
- root.canvas = canvas;
55
- root.renderer = new THREE__namespace.WebGLRenderer({ canvas, alpha: true });
56
- root.renderer.setClearColor(0x000000, 0);
57
- root.camera = camera !== null && camera !== void 0 ? camera : new THREE__namespace.PerspectiveCamera(45, root.renderer.domElement.width / root.renderer.domElement.height);
58
- root.scene = new THREE__namespace.Scene();
59
- xnew.context('xthree.object', root.scene);
60
- self.on('update', () => {
61
- root.renderer.render(root.scene, root.camera);
62
- });
63
- }
64
- function Nest(self, { object }) {
65
- const parent = xnew.context('xthree.object');
66
- xnew.context('xthree.object', object);
67
- if (parent) {
68
- parent === null || parent === void 0 ? void 0 : parent.add(object);
69
- self.on('finalize', () => {
70
- parent === null || parent === void 0 ? void 0 : parent.remove(object);
71
- });
72
- }
73
- }
74
-
75
- return xthree;
76
-
77
- }));