@mulsense/xnew 0.1.0 → 0.1.2

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/xnew@5.0.x/dist/xnew.js"></script>
16
+ <script src="https://unpkg.com/@mulsense/xnew@0.1.x/dist/xnew.js"></script>
17
17
  ```
18
18
 
19
19
  ### Via CDN (ESM)
@@ -22,13 +22,13 @@ Use the ES module version with an import map:
22
22
  <script type="importmap">
23
23
  {
24
24
  "imports": {
25
- "xnew": "https://unpkg.com/xnew@5.0.x/dist/xnew.mjs"
25
+ "@mulsense/xnew": "https://unpkg.com/@mulsense/xnew@0.1.x/dist/xnew.mjs"
26
26
  }
27
27
  }
28
28
  </script>
29
29
 
30
30
  <script type="module">
31
- import xnew from 'xnew';
31
+ import xnew from '@mulsense/xnew';
32
32
 
33
33
  // Your code here
34
34
  </script>
@@ -37,10 +37,10 @@ import xnew from 'xnew';
37
37
  ### Via npm
38
38
  Install `xnew` using npm:
39
39
  ```bash
40
- npm install xnew@5.0.x
40
+ npm install @mulsense/xnew@0.1.x
41
41
  ```
42
42
 
43
43
  Then import it in your JavaScript file:
44
44
  ```js
45
- import xnew from 'xnew';
45
+ import xnew from '@mulsense/xnew';
46
46
  ```
@@ -1,6 +1,6 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('xnew'), require('matter-js')) :
3
- typeof define === 'function' && define.amd ? define(['xnew', 'matter-js'], 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
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xmatter = factory(global.xnew, global.Matter));
5
5
  })(this, (function (xnew, Matter) { 'use strict';
6
6
 
@@ -1,4 +1,4 @@
1
- import xnew from 'xnew';
1
+ import xnew from '@mulsense/xnew';
2
2
  import Matter from 'matter-js';
3
3
 
4
4
  var xmatter = {
@@ -1,6 +1,6 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('xnew'), require('pixi.js')) :
3
- typeof define === 'function' && define.amd ? define(['xnew', 'pixi.js'], 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
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xpixi = factory(global.xnew, global.PIXI));
5
5
  })(this, (function (xnew, PIXI) { 'use strict';
6
6
 
@@ -1,4 +1,4 @@
1
- import xnew from 'xnew';
1
+ import xnew from '@mulsense/xnew';
2
2
  import * as PIXI from 'pixi.js';
3
3
 
4
4
  var xpixi = {
@@ -1,6 +1,6 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('xnew'), require('@dimforge/rapier2d-compat')) :
3
- typeof define === 'function' && define.amd ? define(['xnew', '@dimforge/rapier2d-compat'], 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
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xrapier2d = factory(global.xnew, global.RAPIER));
5
5
  })(this, (function (xnew, RAPIER) { 'use strict';
6
6
 
@@ -1,4 +1,4 @@
1
- import xnew from 'xnew';
1
+ import xnew from '@mulsense/xnew';
2
2
  import RAPIER from '@dimforge/rapier2d-compat';
3
3
 
4
4
  var xrapier2d = {
@@ -1,6 +1,6 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('xnew'), require('three')) :
3
- typeof define === 'function' && define.amd ? define(['xnew', 'three'], 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
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xthree = factory(global.xnew, global.THREE));
5
5
  })(this, (function (xnew, THREE) { 'use strict';
6
6
 
@@ -56,7 +56,7 @@
56
56
  root.renderer.setClearColor(0x000000, 0);
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
- xnew.extend(Nest, root.scene);
59
+ xnew.context('xthree.object', root.scene);
60
60
  self.on('update', () => {
61
61
  root.renderer.render(root.scene, root.camera);
62
62
  });
@@ -1,4 +1,4 @@
1
- import xnew from 'xnew';
1
+ import xnew from '@mulsense/xnew';
2
2
  import * as THREE from 'three';
3
3
 
4
4
  var xthree = {
@@ -34,7 +34,7 @@ function Root(self, { canvas, camera }) {
34
34
  root.renderer.setClearColor(0x000000, 0);
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
- xnew.extend(Nest, root.scene);
37
+ xnew.context('xthree.object', root.scene);
38
38
  self.on('update', () => {
39
39
  root.renderer.render(root.scene, root.camera);
40
40
  });
@@ -1,34 +1,21 @@
1
- declare class MapEx<Key, Value> {
2
- protected map: Map<Key, Value>;
3
- get size(): number;
4
- forEach(callback: (value: Value, key: Key, map: Map<Key, Value>) => any): void;
5
- clear(): void;
6
- }
7
- export declare class MapSet<Key, Value> extends MapEx<Key, Set<Value>> {
8
- has(key: Key, value?: Value): boolean;
9
- get(key: Key): Set<Value> | undefined;
10
- keys(): IterableIterator<Key>;
1
+ export declare class MapSet<Key, Value> extends Map<Key, Set<Value>> {
2
+ has(key: Key): boolean;
3
+ has(key: Key, value: Value): boolean;
11
4
  add(key: Key, value: Value): MapSet<Key, Value>;
12
- delete(key: Key, value?: Value): boolean;
5
+ keys(): IterableIterator<Key>;
6
+ keys(key: Key): IterableIterator<Value>;
7
+ delete(key: Key): boolean;
8
+ delete(key: Key, value: Value): boolean;
13
9
  }
14
- export declare class MapMap<Key1, Key2, Value> extends MapEx<Key1, Map<Key2, Value>> {
15
- has(key1: Key1, key2?: Key2): boolean;
16
- set(key1: Key1, key2: Key2, value: Value): MapMap<Key1, Key2, Value>;
10
+ export declare class MapMap<Key1, Key2, Value> extends Map<Key1, Map<Key2, Value>> {
11
+ has(key1: Key1): boolean;
12
+ has(key1: Key1, key2: Key2): boolean;
13
+ set(key1: Key1, value: Map<Key2, Value>): this;
14
+ set(key1: Key1, key2: Key2, value: Value): this;
17
15
  get(key1: Key1): Map<Key2, Value> | undefined;
18
16
  get(key1: Key1, key2: Key2): Value | undefined;
19
17
  keys(): IterableIterator<Key1>;
20
18
  keys(key1: Key1): IterableIterator<Key2>;
21
- delete(key1: Key1, key2?: Key2): boolean;
22
- }
23
- export declare class MapMapMap<Key1, Key2, Key3, Value> extends MapEx<Key1, MapMap<Key2, Key3, Value>> {
24
- has(key1: Key1, key2?: Key2, key3?: Key3): boolean;
25
- set(key1: Key1, key2: Key2, key3: Key3, value: Value): MapMapMap<Key1, Key2, Key3, Value>;
26
- get(key1: Key1): MapMap<Key2, Key3, Value> | undefined;
27
- get(key1: Key1, key2: Key2): Map<Key3, Value> | undefined;
28
- get(key1: Key1, key2: Key2, key3: Key3): Value | undefined;
29
- keys(): IterableIterator<Key1>;
30
- keys(key1: Key1): IterableIterator<Key2>;
31
- keys(key1: Key1, key2: Key2): IterableIterator<Key3>;
32
- delete(key1: Key1, key2?: Key2, key3?: Key3): boolean;
19
+ delete(key1: Key1): boolean;
20
+ delete(key1: Key1, key2: Key2): boolean;
33
21
  }
34
- export {};
@@ -1,6 +1,5 @@
1
- import { MapSet, MapMapMap } from './map';
2
- declare const LIFECYCLE_EVENTS: readonly ["start", "update", "stop", "finalize"];
3
- type LifecycleEvent = typeof LIFECYCLE_EVENTS[number];
1
+ import { MapSet, MapMap } from './map';
2
+ export type UnitElement = HTMLElement | SVGElement;
4
3
  interface Context {
5
4
  stack: Context | null;
6
5
  key: string;
@@ -9,88 +8,77 @@ interface Context {
9
8
  interface Snapshot {
10
9
  unit: Unit | null;
11
10
  context: Context | null;
12
- element: HTMLElement | SVGElement | null;
11
+ element: UnitElement | null;
13
12
  }
14
13
  interface Capture {
15
14
  checker: (unit: Unit) => boolean;
16
15
  execute: (unit: Unit) => any;
17
16
  }
18
17
  interface UnitInternal {
19
- root: Unit;
20
18
  parent: Unit | null;
21
19
  children: Unit[];
22
20
  target: Object | null;
23
21
  props?: Object;
22
+ baseElement: UnitElement;
23
+ baseContext: Context | null;
24
+ baseComponent: Function;
25
+ currentElement: UnitElement;
24
26
  nextNest: {
25
- element: HTMLElement | SVGElement;
27
+ element: UnitElement;
26
28
  position: InsertPosition;
27
29
  };
28
- baseElement: HTMLElement | SVGElement;
29
- currentElement: HTMLElement | SVGElement;
30
- baseContext: Context | null;
31
- baseComponent: Function | null;
32
- components: Function[];
30
+ components: Set<Function>;
31
+ listeners: MapMap<string, Function, [UnitElement, Function]>;
32
+ sublisteners: MapMap<string, Function, [UnitElement | Window | Document, Function]>;
33
33
  captures: Capture[];
34
34
  state: string;
35
35
  tostart: boolean;
36
- upcount: number;
37
- resolved: boolean;
38
36
  defines: Record<string, any>;
39
- system: Record<LifecycleEvent, Function[]>;
37
+ system: Record<string, Function[]>;
40
38
  }
41
39
  export declare class Unit {
42
40
  [key: string]: any;
43
41
  _: UnitInternal;
44
42
  static roots: Unit[];
45
43
  constructor(target: Object | null, component?: Function | string, props?: Object);
46
- get element(): HTMLElement | SVGElement;
44
+ get element(): UnitElement;
47
45
  start(): void;
48
46
  stop(): void;
49
47
  finalize(): void;
50
48
  reboot(): void;
51
- get components(): Function[];
52
- on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): Unit;
53
- off(type?: string, listener?: Function): Unit;
54
- emit(type: string, ...args: any[]): void;
55
- static initialize(unit: Unit): void;
49
+ static initialize(unit: Unit, nextNest: {
50
+ element: UnitElement;
51
+ position: InsertPosition;
52
+ }): void;
56
53
  static finalize(unit: Unit): void;
57
- static nest(unit: Unit, tag: string): HTMLElement | SVGElement | null;
54
+ static nest(unit: Unit, tag: string): UnitElement | null;
58
55
  static extend(unit: Unit, component: Function, props?: Object): void;
59
56
  static start(unit: Unit, time: number): void;
60
57
  static stop(unit: Unit): void;
61
58
  static update(unit: Unit, time: number): void;
62
59
  static ticker(time: number): void;
63
60
  static reset(): void;
61
+ static componentUnits: MapSet<Function, Unit>;
62
+ get components(): Set<Function>;
63
+ static find(component: Function): Unit[];
64
+ static typeUnits: MapSet<string, Unit>;
65
+ on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
66
+ off(type?: string, listener?: Function): void;
67
+ emit(type: string, ...args: any[]): void;
68
+ static subon(unit: any, target: UnitElement | Window | Document, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
69
+ static suboff(unit: any, target: UnitElement | Window | Document | null, type?: string, listener?: Function): void;
64
70
  }
65
71
  export declare class UnitScope {
66
72
  static current: Unit | null;
67
73
  static contexts: Map<Unit | null, Context>;
68
74
  static initialize(unit: Unit | null, context: Context | null): void;
69
75
  static finalize(unit: Unit): void;
70
- static set(unit: Unit, context: Context): void;
71
- static get(unit: Unit | null): Context | null;
76
+ static wrap(listener: Function): (...args: any[]) => any;
72
77
  static execute(snapshot: Snapshot | null, func: Function, ...args: any[]): any;
73
78
  static snapshot(unit?: Unit | null): Snapshot | null;
74
79
  static stack(unit: Unit, key: string, value: any): void;
75
80
  static trace(unit: Unit, key: string): any;
76
81
  }
77
- export declare class UnitComponent {
78
- static components: MapSet<Unit, Function>;
79
- static units: MapSet<Function, Unit>;
80
- static finalize(unit: Unit): void;
81
- static add(unit: Unit, component: Function): void;
82
- static find(component: Function): Unit[];
83
- }
84
- export declare class UnitEvent {
85
- static units: MapSet<string, Unit>;
86
- static listeners: MapMapMap<Unit, string, Function, [HTMLElement | SVGElement, (...args: any[]) => void]>;
87
- static on(unit: Unit, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
88
- static off(unit: Unit, type?: string, listener?: Function): void;
89
- static emit(unit: Unit, type: string, ...args: any[]): void;
90
- static sublisteners: MapMapMap<Unit | null, string, Function, [HTMLElement | SVGElement | Window | Document, (...args: any[]) => void]>;
91
- static subon(unit: Unit | null, target: HTMLElement | SVGElement | Window | Document, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
92
- static suboff(unit: Unit | null, target: HTMLElement | SVGElement | Window | Document | null, type?: string, listener?: Function): void;
93
- }
94
82
  export declare class UnitPromise {
95
83
  private promise;
96
84
  constructor(executor: (resolve: (value: any) => void, reject: (reason?: any) => void) => void);
package/dist/xnew.d.ts CHANGED
@@ -1,7 +1,28 @@
1
1
  declare function ResizeEvent(self: any): void;
2
2
 
3
- declare const LIFECYCLE_EVENTS: readonly ["start", "update", "stop", "finalize"];
4
- type LifecycleEvent = typeof LIFECYCLE_EVENTS[number];
3
+ declare class MapSet<Key, Value> extends Map<Key, Set<Value>> {
4
+ has(key: Key): boolean;
5
+ has(key: Key, value: Value): boolean;
6
+ add(key: Key, value: Value): MapSet<Key, Value>;
7
+ keys(): IterableIterator<Key>;
8
+ keys(key: Key): IterableIterator<Value>;
9
+ delete(key: Key): boolean;
10
+ delete(key: Key, value: Value): boolean;
11
+ }
12
+ declare class MapMap<Key1, Key2, Value> extends Map<Key1, Map<Key2, Value>> {
13
+ has(key1: Key1): boolean;
14
+ has(key1: Key1, key2: Key2): boolean;
15
+ set(key1: Key1, value: Map<Key2, Value>): this;
16
+ set(key1: Key1, key2: Key2, value: Value): this;
17
+ get(key1: Key1): Map<Key2, Value> | undefined;
18
+ get(key1: Key1, key2: Key2): Value | undefined;
19
+ keys(): IterableIterator<Key1>;
20
+ keys(key1: Key1): IterableIterator<Key2>;
21
+ delete(key1: Key1): boolean;
22
+ delete(key1: Key1, key2: Key2): boolean;
23
+ }
24
+
25
+ type UnitElement = HTMLElement | SVGElement;
5
26
  interface Context {
6
27
  stack: Context | null;
7
28
  key: string;
@@ -12,51 +33,58 @@ interface Capture {
12
33
  execute: (unit: Unit) => any;
13
34
  }
14
35
  interface UnitInternal {
15
- root: Unit;
16
36
  parent: Unit | null;
17
37
  children: Unit[];
18
38
  target: Object | null;
19
39
  props?: Object;
40
+ baseElement: UnitElement;
41
+ baseContext: Context | null;
42
+ baseComponent: Function;
43
+ currentElement: UnitElement;
20
44
  nextNest: {
21
- element: HTMLElement | SVGElement;
45
+ element: UnitElement;
22
46
  position: InsertPosition;
23
47
  };
24
- baseElement: HTMLElement | SVGElement;
25
- currentElement: HTMLElement | SVGElement;
26
- baseContext: Context | null;
27
- baseComponent: Function | null;
28
- components: Function[];
48
+ components: Set<Function>;
49
+ listeners: MapMap<string, Function, [UnitElement, Function]>;
50
+ sublisteners: MapMap<string, Function, [UnitElement | Window | Document, Function]>;
29
51
  captures: Capture[];
30
52
  state: string;
31
53
  tostart: boolean;
32
- upcount: number;
33
- resolved: boolean;
34
54
  defines: Record<string, any>;
35
- system: Record<LifecycleEvent, Function[]>;
55
+ system: Record<string, Function[]>;
36
56
  }
37
57
  declare class Unit {
38
58
  [key: string]: any;
39
59
  _: UnitInternal;
40
60
  static roots: Unit[];
41
61
  constructor(target: Object | null, component?: Function | string, props?: Object);
42
- get element(): HTMLElement | SVGElement;
62
+ get element(): UnitElement;
43
63
  start(): void;
44
64
  stop(): void;
45
65
  finalize(): void;
46
66
  reboot(): void;
47
- get components(): Function[];
48
- on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): Unit;
49
- off(type?: string, listener?: Function): Unit;
50
- emit(type: string, ...args: any[]): void;
51
- static initialize(unit: Unit): void;
67
+ static initialize(unit: Unit, nextNest: {
68
+ element: UnitElement;
69
+ position: InsertPosition;
70
+ }): void;
52
71
  static finalize(unit: Unit): void;
53
- static nest(unit: Unit, tag: string): HTMLElement | SVGElement | null;
72
+ static nest(unit: Unit, tag: string): UnitElement | null;
54
73
  static extend(unit: Unit, component: Function, props?: Object): void;
55
74
  static start(unit: Unit, time: number): void;
56
75
  static stop(unit: Unit): void;
57
76
  static update(unit: Unit, time: number): void;
58
77
  static ticker(time: number): void;
59
78
  static reset(): void;
79
+ static componentUnits: MapSet<Function, Unit>;
80
+ get components(): Set<Function>;
81
+ static find(component: Function): Unit[];
82
+ static typeUnits: MapSet<string, Unit>;
83
+ on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
84
+ off(type?: string, listener?: Function): void;
85
+ emit(type: string, ...args: any[]): void;
86
+ static subon(unit: any, target: UnitElement | Window | Document, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
87
+ static suboff(unit: any, target: UnitElement | Window | Document | null, type?: string, listener?: Function): void;
60
88
  }
61
89
 
62
90
  interface xnewtype$1 {