@mulsense/xnew 0.3.7 → 0.4.1

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/README.md CHANGED
@@ -13,7 +13,7 @@ providing a flexible architecture well-suited for applications with dynamic scen
13
13
  ### Via CDN
14
14
  Include the following script in your HTML file:
15
15
  ```html
16
- <script src="https://unpkg.com/@mulsense/xnew@0.3.x/dist/xnew.js"></script>
16
+ <script src="https://unpkg.com/@mulsense/xnew@0.4.x/dist/xnew.js"></script>
17
17
  ```
18
18
 
19
19
  ### Via CDN (ESM)
@@ -22,7 +22,7 @@ Use the ES module version with an import map:
22
22
  <script type="importmap">
23
23
  {
24
24
  "imports": {
25
- "@mulsense/xnew": "https://unpkg.com/@mulsense/xnew@0.3.x/dist/xnew.mjs"
25
+ "@mulsense/xnew": "https://unpkg.com/@mulsense/xnew@0.4.x/dist/xnew.mjs"
26
26
  }
27
27
  }
28
28
  </script>
@@ -37,7 +37,7 @@ import xnew from '@mulsense/xnew';
37
37
  ### Via npm
38
38
  Install `xnew` using npm:
39
39
  ```bash
40
- npm install @mulsense/xnew@0.3.x
40
+ npm install @mulsense/xnew@0.4.x
41
41
  ```
42
42
 
43
43
  Then import it in your JavaScript file:
@@ -21,9 +21,6 @@
21
21
  const root = {};
22
22
  xnew.context('xmatter.root', root);
23
23
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
24
- unit.on('process', () => {
25
- Matter.Engine.update(root.engine);
26
- });
27
24
  }
28
25
 
29
26
  return xmatter;
@@ -18,9 +18,6 @@ function Root(unit, { engine }) {
18
18
  const root = {};
19
19
  xnew.context('xmatter.root', root);
20
20
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
21
- unit.on('process', () => {
22
- Matter.Engine.update(root.engine);
23
- });
24
21
  }
25
22
 
26
23
  export { xmatter as default };
@@ -1,9 +1,10 @@
1
- import * as PIXI from 'pixi.js';
2
-
3
1
  declare const _default: {
4
- initialize({ renderer, canvas }?: any): void;
2
+ initialize({ renderer, canvas }?: {
3
+ renderer?: any;
4
+ canvas?: HTMLCanvasElement | null;
5
+ update?: boolean;
6
+ }): void;
5
7
  nest(object: any): any;
6
- sync(canvas: any): PIXI.Texture<PIXI.TextureSource<any>>;
7
8
  readonly renderer: any;
8
9
  readonly scene: any;
9
10
  readonly canvas: any;
@@ -24,8 +24,8 @@
24
24
  var PIXI__namespace = /*#__PURE__*/_interopNamespaceDefault(PIXI);
25
25
 
26
26
  var xpixi = {
27
- initialize({ renderer = null, canvas = null } = {}) {
28
- xnew.extend(Root, { renderer, canvas });
27
+ initialize({ renderer = null, canvas = null, update = true } = {}) {
28
+ xnew.extend(Root, { renderer, canvas, update });
29
29
  },
30
30
  nest(object) {
31
31
  xnew.extend(Nest, { object });
@@ -51,7 +51,7 @@
51
51
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
52
52
  },
53
53
  };
54
- function Root(unit, { canvas }) {
54
+ function Root(unit, { canvas, update }) {
55
55
  const root = {};
56
56
  xnew.context('xpixi.root', root);
57
57
  root.canvas = canvas;
@@ -63,14 +63,14 @@
63
63
  root.updates = [];
64
64
  root.scene = new PIXI__namespace.Container();
65
65
  xnew.context('xpixi.object', root.scene);
66
- unit.on('update', () => {
67
- root.updates.forEach((update) => {
68
- update();
69
- });
70
- if (root.renderer && root.scene) {
66
+ if (update === true) {
67
+ unit.on('update', () => {
68
+ root.updates.forEach((update) => {
69
+ update();
70
+ });
71
71
  root.renderer.render(root.scene);
72
- }
73
- });
72
+ });
73
+ }
74
74
  }
75
75
  function Nest(unit, { object }) {
76
76
  const parent = xnew.context('xpixi.object');
@@ -2,8 +2,8 @@ import xnew from '@mulsense/xnew';
2
2
  import * as PIXI from 'pixi.js';
3
3
 
4
4
  var xpixi = {
5
- initialize({ renderer = null, canvas = null } = {}) {
6
- xnew.extend(Root, { renderer, canvas });
5
+ initialize({ renderer = null, canvas = null, update = true } = {}) {
6
+ xnew.extend(Root, { renderer, canvas, update });
7
7
  },
8
8
  nest(object) {
9
9
  xnew.extend(Nest, { object });
@@ -29,7 +29,7 @@ var xpixi = {
29
29
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
30
30
  },
31
31
  };
32
- function Root(unit, { canvas }) {
32
+ function Root(unit, { canvas, update }) {
33
33
  const root = {};
34
34
  xnew.context('xpixi.root', root);
35
35
  root.canvas = canvas;
@@ -41,14 +41,14 @@ function Root(unit, { canvas }) {
41
41
  root.updates = [];
42
42
  root.scene = new PIXI.Container();
43
43
  xnew.context('xpixi.object', root.scene);
44
- unit.on('update', () => {
45
- root.updates.forEach((update) => {
46
- update();
47
- });
48
- if (root.renderer && root.scene) {
44
+ if (update === true) {
45
+ unit.on('update', () => {
46
+ root.updates.forEach((update) => {
47
+ update();
48
+ });
49
49
  root.renderer.render(root.scene);
50
- }
51
- });
50
+ });
51
+ }
52
52
  }
53
53
  function Nest(unit, { object }) {
54
54
  const parent = xnew.context('xpixi.object');
@@ -13,15 +13,12 @@
13
13
  return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
14
14
  },
15
15
  };
16
- function Root(self, { gravity }) {
16
+ function Root(unit, { gravity }) {
17
17
  const root = {};
18
18
  xnew.context('xrapier2d.root', root);
19
19
  xnew.promise(RAPIER.init()).then(() => {
20
20
  root.world = new RAPIER.World(gravity);
21
21
  });
22
- self.on('process', () => {
23
- root.world.step();
24
- });
25
22
  }
26
23
 
27
24
  return xrapier2d;
@@ -10,15 +10,12 @@ var xrapier2d = {
10
10
  return (_a = xnew.context('xrapier2d.root')) === null || _a === void 0 ? void 0 : _a.world;
11
11
  },
12
12
  };
13
- function Root(self, { gravity }) {
13
+ function Root(unit, { gravity }) {
14
14
  const root = {};
15
15
  xnew.context('xrapier2d.root', root);
16
16
  xnew.promise(RAPIER.init()).then(() => {
17
17
  root.world = new RAPIER.World(gravity);
18
18
  });
19
- self.on('process', () => {
20
- root.world.step();
21
- });
22
19
  }
23
20
 
24
21
  export { xrapier2d as default };
@@ -13,15 +13,12 @@
13
13
  return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
14
14
  },
15
15
  };
16
- function Root(self, { gravity }) {
16
+ function Root(unit, { gravity }) {
17
17
  const root = {};
18
18
  xnew.context('xrapier3d.root', root);
19
19
  xnew.promise(RAPIER.init()).then(() => {
20
20
  root.world = new RAPIER.World(gravity);
21
21
  });
22
- self.on('process', () => {
23
- root.world.step();
24
- });
25
22
  }
26
23
 
27
24
  return xrapier3d;
@@ -10,15 +10,12 @@ var xrapier3d = {
10
10
  return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
11
11
  },
12
12
  };
13
- function Root(self, { gravity }) {
13
+ function Root(unit, { gravity }) {
14
14
  const root = {};
15
15
  xnew.context('xrapier3d.root', root);
16
16
  xnew.promise(RAPIER.init()).then(() => {
17
17
  root.world = new RAPIER.World(gravity);
18
18
  });
19
- self.on('process', () => {
20
- root.world.step();
21
- });
22
19
  }
23
20
 
24
21
  export { xrapier3d as default };
@@ -1,5 +1,12 @@
1
+ import * as THREE from 'three';
2
+
1
3
  declare const _default: {
2
- initialize({ renderer, canvas, camera }?: any): void;
4
+ initialize({ renderer, canvas, camera, update }?: {
5
+ renderer?: any;
6
+ canvas?: HTMLCanvasElement | null;
7
+ camera?: THREE.Camera | null;
8
+ update?: boolean;
9
+ }): void;
3
10
  nest(object: any): any;
4
11
  readonly renderer: any;
5
12
  readonly camera: any;
@@ -24,8 +24,8 @@
24
24
  var THREE__namespace = /*#__PURE__*/_interopNamespaceDefault(THREE);
25
25
 
26
26
  var xthree = {
27
- initialize({ renderer = null, canvas = null, camera = null } = {}) {
28
- xnew.extend(Root, { renderer, canvas, camera });
27
+ initialize({ renderer = null, canvas = null, camera = null, update = true } = {}) {
28
+ xnew.extend(Root, { renderer, canvas, camera, update });
29
29
  },
30
30
  nest(object) {
31
31
  xnew.extend(Nest, { object });
@@ -46,9 +46,9 @@
46
46
  get canvas() {
47
47
  var _a;
48
48
  return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.canvas;
49
- }
49
+ },
50
50
  };
51
- function Root(unit, { canvas, camera }) {
51
+ function Root(unit, { canvas, camera, update }) {
52
52
  const root = {};
53
53
  xnew.context('xthree.root', root);
54
54
  root.canvas = canvas;
@@ -57,9 +57,11 @@
57
57
  root.camera = camera !== null && camera !== void 0 ? camera : new THREE__namespace.PerspectiveCamera(45, root.renderer.domElement.width / root.renderer.domElement.height);
58
58
  root.scene = new THREE__namespace.Scene();
59
59
  xnew.context('xthree.object', root.scene);
60
- unit.on('update', () => {
61
- root.renderer.render(root.scene, root.camera);
62
- });
60
+ if (update === true) {
61
+ unit.on('update', () => {
62
+ root.renderer.render(root.scene, root.camera);
63
+ });
64
+ }
63
65
  }
64
66
  function Nest(unit, { object }) {
65
67
  const parent = xnew.context('xthree.object');
@@ -2,8 +2,8 @@ import xnew from '@mulsense/xnew';
2
2
  import * as THREE from 'three';
3
3
 
4
4
  var xthree = {
5
- initialize({ renderer = null, canvas = null, camera = null } = {}) {
6
- xnew.extend(Root, { renderer, canvas, camera });
5
+ initialize({ renderer = null, canvas = null, camera = null, update = true } = {}) {
6
+ xnew.extend(Root, { renderer, canvas, camera, update });
7
7
  },
8
8
  nest(object) {
9
9
  xnew.extend(Nest, { object });
@@ -24,9 +24,9 @@ var xthree = {
24
24
  get canvas() {
25
25
  var _a;
26
26
  return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.canvas;
27
- }
27
+ },
28
28
  };
29
- function Root(unit, { canvas, camera }) {
29
+ function Root(unit, { canvas, camera, update }) {
30
30
  const root = {};
31
31
  xnew.context('xthree.root', root);
32
32
  root.canvas = canvas;
@@ -35,9 +35,11 @@ function Root(unit, { canvas, camera }) {
35
35
  root.camera = camera !== null && camera !== void 0 ? camera : new THREE.PerspectiveCamera(45, root.renderer.domElement.width / root.renderer.domElement.height);
36
36
  root.scene = new THREE.Scene();
37
37
  xnew.context('xthree.object', root.scene);
38
- unit.on('update', () => {
39
- root.renderer.render(root.scene, root.camera);
40
- });
38
+ if (update === true) {
39
+ unit.on('update', () => {
40
+ root.renderer.render(root.scene, root.camera);
41
+ });
42
+ }
41
43
  }
42
44
  function Nest(unit, { object }) {
43
45
  const parent = xnew.context('xthree.object');
package/dist/xnew.d.ts CHANGED
@@ -20,13 +20,36 @@ declare class MapMap<Key1, Key2, Value> extends Map<Key1, Map<Key2, Value>> {
20
20
  delete(key1: Key1, key2: Key2): boolean;
21
21
  }
22
22
 
23
- declare class Ticker {
24
- private id;
25
- constructor(callback: Function, fps?: number);
26
- clear(): void;
23
+ type UnitElement = HTMLElement | SVGElement;
24
+
25
+ interface EventProps {
26
+ element: UnitElement;
27
+ type: string;
28
+ listener: Function;
29
+ options?: boolean | AddEventListenerOptions;
30
+ }
31
+ declare class EventManager {
32
+ private map;
33
+ add(props: EventProps): void;
34
+ remove({ type, listener }: {
35
+ type: string;
36
+ listener: Function;
37
+ }): void;
38
+ private basic;
39
+ private resize;
40
+ private click;
41
+ private click_outside;
42
+ private pointer;
43
+ private mouse;
44
+ private touch;
45
+ private pointer_outside;
46
+ private wheel;
47
+ private drag;
48
+ private gesture;
49
+ private key;
50
+ private key_arrow;
27
51
  }
28
52
 
29
- type UnitElement = HTMLElement | SVGElement;
30
53
  interface Context {
31
54
  stack: Context | null;
32
55
  key?: string;
@@ -36,8 +59,9 @@ interface Snapshot {
36
59
  unit: Unit;
37
60
  context: Context;
38
61
  element: UnitElement;
62
+ component: Function | null;
39
63
  }
40
- interface UnitInternal {
64
+ interface Internal {
41
65
  parent: Unit | null;
42
66
  target: Object | null;
43
67
  props?: Object;
@@ -58,14 +82,19 @@ interface UnitInternal {
58
82
  components: Function[];
59
83
  listeners: MapMap<string, Function, {
60
84
  element: UnitElement;
85
+ component: Function | null;
61
86
  execute: Function;
62
87
  }>;
63
88
  defines: Record<string, any>;
64
- systems: Record<string, Function[]>;
89
+ systems: Record<string, {
90
+ listener: Function;
91
+ execute: Function;
92
+ }[]>;
93
+ eventManager: EventManager;
65
94
  }
66
95
  declare class Unit {
67
96
  [key: string]: any;
68
- _: UnitInternal;
97
+ _: Internal;
69
98
  constructor(parent: Unit | null, ...args: any[]);
70
99
  get element(): UnitElement;
71
100
  start(): void;
@@ -75,16 +104,16 @@ declare class Unit {
75
104
  static initialize(unit: Unit, anchor: UnitElement | null): void;
76
105
  static finalize(unit: Unit): void;
77
106
  static nest(unit: Unit, tag: string): UnitElement;
107
+ static currentComponent: Function;
78
108
  static extend(unit: Unit, component: Function, props?: Object): {
79
109
  [key: string]: any;
80
110
  };
81
111
  static start(unit: Unit): void;
82
112
  static stop(unit: Unit): void;
83
113
  static update(unit: Unit): void;
84
- static process(unit: Unit): void;
85
- static root: Unit;
86
- static current: Unit;
87
- static ticker: Ticker;
114
+ static render(unit: Unit): void;
115
+ static rootUnit: Unit;
116
+ static currentUnit: Unit;
88
117
  static reset(): void;
89
118
  static wrap(unit: Unit, listener: Function): (...args: any[]) => any;
90
119
  static scope(snapshot: Snapshot, func: Function, ...args: any[]): any;
@@ -95,6 +124,8 @@ declare class Unit {
95
124
  static type2units: MapSet<string, Unit>;
96
125
  on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
97
126
  off(type?: string, listener?: Function): void;
127
+ static on(unit: Unit, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
128
+ static off(unit: Unit, type: string, listener?: Function): void;
98
129
  static emit(type: string, ...args: any[]): void;
99
130
  }
100
131
  declare class UnitPromise {
@@ -264,21 +295,18 @@ declare function AccordionFrame(frame: Unit, { open, duration, easing }?: {
264
295
  open(): void;
265
296
  close(): void;
266
297
  };
267
- declare function AccordionHeader(header: Unit, {}?: {}): void;
268
- declare function AccordionBullet(bullet: Unit, { type }?: {
298
+ declare function AccordionHeader(unit: Unit, {}?: {}): void;
299
+ declare function AccordionBullet(unit: Unit, { type }?: {
269
300
  type?: string;
270
301
  }): void;
271
- declare function AccordionContent(content: Unit, {}?: {}): {
302
+ declare function AccordionContent(unit: Unit, {}?: {}): {
272
303
  transition({ element, rate }: {
273
304
  element: HTMLElement;
274
305
  rate: number;
275
306
  }): void;
276
307
  };
277
308
 
278
- declare function ResizeEvent(resize: Unit): void;
279
- declare function DirectEvent(unit: Unit): void;
280
-
281
- declare function Screen(screen: Unit, { width, height, fit }?: {
309
+ declare function Screen(unit: Unit, { width, height, fit }?: {
282
310
  width?: number | undefined;
283
311
  height?: number | undefined;
284
312
  fit?: string | undefined;
@@ -330,7 +358,7 @@ declare function DragFrame(frame: Unit, { x, y }?: {
330
358
  x?: number;
331
359
  y?: number;
332
360
  }): void;
333
- declare function DragTarget(target: Unit, {}?: {}): void;
361
+ declare function DragTarget(unit: Unit, {}?: {}): void;
334
362
 
335
363
  declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
336
364
  stroke?: string;
@@ -357,8 +385,6 @@ declare function TextStream(unit: Unit, { text, speed, fade }?: {
357
385
  fade?: number;
358
386
  }): void;
359
387
 
360
- declare function VolumeController(unit: Unit, {}?: {}): void;
361
-
362
388
  declare const icons: {
363
389
  AcademicCap(unit: Unit, props: Object): void;
364
390
  AdjustmentsHorizontal(unit: Unit, props: Object): void;
@@ -728,8 +754,6 @@ declare class Synthesizer {
728
754
 
729
755
  declare const basics: {
730
756
  Screen: typeof Screen;
731
- DirectEvent: typeof DirectEvent;
732
- ResizeEvent: typeof ResizeEvent;
733
757
  ModalFrame: typeof ModalFrame;
734
758
  ModalContent: typeof ModalContent;
735
759
  AccordionFrame: typeof AccordionFrame;
@@ -744,7 +768,6 @@ declare const basics: {
744
768
  DragTarget: typeof DragTarget;
745
769
  AnalogStick: typeof AnalogStick;
746
770
  DirectionalPad: typeof DirectionalPad;
747
- VolumeController: typeof VolumeController;
748
771
  };
749
772
 
750
773
  declare const audio: {