@mulsense/xnew 0.2.1 → 0.3.0

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.2.x/dist/xnew.js"></script>
16
+ <script src="https://unpkg.com/@mulsense/xnew@0.3.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.2.x/dist/xnew.mjs"
25
+ "@mulsense/xnew": "https://unpkg.com/@mulsense/xnew@0.3.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.2.x
40
+ npm install @mulsense/xnew@0.3.x
41
41
  ```
42
42
 
43
43
  Then import it in your JavaScript file:
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  initialize({ engine }?: any): void;
3
- nest(object: any): any;
4
3
  readonly engine: any;
4
+ readonly world: any;
5
5
  };
6
6
  export default _default;
@@ -8,33 +8,21 @@
8
8
  initialize({ engine = null } = {}) {
9
9
  xnew.extend(Root, { engine });
10
10
  },
11
- nest(object) {
12
- xnew.extend(Nest, { object });
13
- return object;
14
- },
15
11
  get engine() {
16
12
  var _a;
17
13
  return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine;
18
14
  },
15
+ get world() {
16
+ var _a;
17
+ return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine.world;
18
+ },
19
19
  };
20
- function Root(self, { engine }) {
20
+ function Root(unit, { engine }) {
21
21
  const root = {};
22
22
  xnew.context('xmatter.root', root);
23
- root.isActive = true;
24
23
  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);
24
+ unit.on('update', () => {
25
+ Matter.Engine.update(root.engine);
38
26
  });
39
27
  }
40
28
 
@@ -5,33 +5,21 @@ var xmatter = {
5
5
  initialize({ engine = null } = {}) {
6
6
  xnew.extend(Root, { engine });
7
7
  },
8
- nest(object) {
9
- xnew.extend(Nest, { object });
10
- return object;
11
- },
12
8
  get engine() {
13
9
  var _a;
14
10
  return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine;
15
11
  },
12
+ get world() {
13
+ var _a;
14
+ return (_a = xnew.context('xmatter.root')) === null || _a === void 0 ? void 0 : _a.engine.world;
15
+ },
16
16
  };
17
- function Root(self, { engine }) {
17
+ function Root(unit, { engine }) {
18
18
  const root = {};
19
19
  xnew.context('xmatter.root', root);
20
- root.isActive = true;
21
20
  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);
21
+ unit.on('update', () => {
22
+ Matter.Engine.update(root.engine);
35
23
  });
36
24
  }
37
25
 
@@ -6,8 +6,5 @@ declare const _default: {
6
6
  readonly renderer: any;
7
7
  readonly scene: any;
8
8
  readonly canvas: any;
9
- capture({ rect }?: {
10
- rect?: number[];
11
- }): any;
12
9
  };
13
10
  export default _default;
@@ -50,11 +50,6 @@
50
50
  var _a;
51
51
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
52
52
  },
53
- capture({ rect } = {}) {
54
- const root = xnew.context('xpixi.root');
55
- const frame = rect ? new PIXI__namespace.Rectangle(rect[0], rect[1], rect[2], rect[3]) : new PIXI__namespace.Rectangle(0, 0, root.canvas.width, root.canvas.height);
56
- return root.renderer.extract.base64({ target: root.scene, frame });
57
- }
58
53
  };
59
54
  function Root(self, { canvas }) {
60
55
  const root = {};
@@ -74,7 +69,7 @@
74
69
  root.updates = [];
75
70
  root.scene = new PIXI__namespace.Container();
76
71
  xnew.context('xpixi.object', root.scene);
77
- self.on('-update', () => {
72
+ self.on('update', () => {
78
73
  root.updates.forEach((update) => {
79
74
  update();
80
75
  });
@@ -87,14 +82,14 @@
87
82
  const parent = xnew.context('xpixi.object');
88
83
  xnew.context('xpixi.object', object);
89
84
  parent.addChild(object);
90
- self.on('-finalize', () => {
85
+ self.on('finalize', () => {
91
86
  parent.removeChild(object);
92
87
  });
93
88
  }
94
89
  function PreUpdate(self, callback) {
95
90
  const root = xnew.context('xpixi.root');
96
91
  root.updates.push(callback);
97
- self.on('-finalize', () => {
92
+ self.on('finalize', () => {
98
93
  root.updates = root.updates.filter((update) => update !== callback);
99
94
  });
100
95
  }
@@ -28,11 +28,6 @@ var xpixi = {
28
28
  var _a;
29
29
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
30
30
  },
31
- capture({ rect } = {}) {
32
- const root = xnew.context('xpixi.root');
33
- const frame = rect ? new PIXI.Rectangle(rect[0], rect[1], rect[2], rect[3]) : new PIXI.Rectangle(0, 0, root.canvas.width, root.canvas.height);
34
- return root.renderer.extract.base64({ target: root.scene, frame });
35
- }
36
31
  };
37
32
  function Root(self, { canvas }) {
38
33
  const root = {};
@@ -52,7 +47,7 @@ function Root(self, { canvas }) {
52
47
  root.updates = [];
53
48
  root.scene = new PIXI.Container();
54
49
  xnew.context('xpixi.object', root.scene);
55
- self.on('-update', () => {
50
+ self.on('update', () => {
56
51
  root.updates.forEach((update) => {
57
52
  update();
58
53
  });
@@ -65,14 +60,14 @@ function Nest(self, { object }) {
65
60
  const parent = xnew.context('xpixi.object');
66
61
  xnew.context('xpixi.object', object);
67
62
  parent.addChild(object);
68
- self.on('-finalize', () => {
63
+ self.on('finalize', () => {
69
64
  parent.removeChild(object);
70
65
  });
71
66
  }
72
67
  function PreUpdate(self, callback) {
73
68
  const root = xnew.context('xpixi.root');
74
69
  root.updates.push(callback);
75
- self.on('-finalize', () => {
70
+ self.on('finalize', () => {
76
71
  root.updates = root.updates.filter((update) => update !== callback);
77
72
  });
78
73
  }
@@ -27,7 +27,7 @@
27
27
  }
28
28
  // xnew.extend(Nest, root.world);
29
29
  });
30
- self.on('-update', () => {
30
+ self.on('update', () => {
31
31
  if (root.world) {
32
32
  root.world.step();
33
33
  }
@@ -40,7 +40,7 @@
40
40
  console.log(temp, type, object);
41
41
  // Rapier2D objects (RigidBody, Collider, etc.) are already added to the world
42
42
  // when created, so we only need to handle removal on finalize
43
- self.on('-finalize', () => {
43
+ self.on('finalize', () => {
44
44
  try {
45
45
  // Check if object is a RigidBody
46
46
  if (type === 'rigidBody') {
@@ -24,7 +24,7 @@ function Root(self, { gravity, timestep }) {
24
24
  }
25
25
  // xnew.extend(Nest, root.world);
26
26
  });
27
- self.on('-update', () => {
27
+ self.on('update', () => {
28
28
  if (root.world) {
29
29
  root.world.step();
30
30
  }
@@ -37,7 +37,7 @@ function Connect(self, { type, object }) {
37
37
  console.log(temp, type, object);
38
38
  // Rapier2D objects (RigidBody, Collider, etc.) are already added to the world
39
39
  // when created, so we only need to handle removal on finalize
40
- self.on('-finalize', () => {
40
+ self.on('finalize', () => {
41
41
  try {
42
42
  // Check if object is a RigidBody
43
43
  if (type === 'rigidBody') {
@@ -48,7 +48,7 @@
48
48
  return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.canvas;
49
49
  }
50
50
  };
51
- function Root(self, { canvas, camera }) {
51
+ function Root(unit, { canvas, camera }) {
52
52
  const root = {};
53
53
  xnew.context('xthree.root', root);
54
54
  root.canvas = canvas;
@@ -57,16 +57,16 @@
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
- self.on('-update', () => {
60
+ unit.on('update', () => {
61
61
  root.renderer.render(root.scene, root.camera);
62
62
  });
63
63
  }
64
- function Nest(self, { object }) {
64
+ function Nest(unit, { object }) {
65
65
  const parent = xnew.context('xthree.object');
66
66
  xnew.context('xthree.object', object);
67
67
  if (parent) {
68
68
  parent === null || parent === void 0 ? void 0 : parent.add(object);
69
- self.on('-finalize', () => {
69
+ unit.on('finalize', () => {
70
70
  parent === null || parent === void 0 ? void 0 : parent.remove(object);
71
71
  });
72
72
  }
@@ -26,7 +26,7 @@ var xthree = {
26
26
  return (_a = xnew.context('xthree.root')) === null || _a === void 0 ? void 0 : _a.canvas;
27
27
  }
28
28
  };
29
- function Root(self, { canvas, camera }) {
29
+ function Root(unit, { canvas, camera }) {
30
30
  const root = {};
31
31
  xnew.context('xthree.root', root);
32
32
  root.canvas = canvas;
@@ -35,16 +35,16 @@ function Root(self, { 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
- self.on('-update', () => {
38
+ unit.on('update', () => {
39
39
  root.renderer.render(root.scene, root.camera);
40
40
  });
41
41
  }
42
- function Nest(self, { object }) {
42
+ function Nest(unit, { object }) {
43
43
  const parent = xnew.context('xthree.object');
44
44
  xnew.context('xthree.object', object);
45
45
  if (parent) {
46
46
  parent === null || parent === void 0 ? void 0 : parent.add(object);
47
- self.on('-finalize', () => {
47
+ unit.on('finalize', () => {
48
48
  parent === null || parent === void 0 ? void 0 : parent.remove(object);
49
49
  });
50
50
  }
@@ -1,9 +1,28 @@
1
- export declare const audio: {
2
- load(path: string): import("../core/unit").UnitPromise;
3
- synthesizer(props: SynthProps): Synthesizer;
4
- volume: number;
1
+ export declare const context: AudioContext;
2
+ export declare const master: GainNode;
3
+ export type AudioFilePlayOptions = {
4
+ offset?: number;
5
+ fade?: number;
6
+ loop?: boolean;
5
7
  };
6
- type SynthProps = {
8
+ export type AudioFilePauseOptions = {
9
+ fade?: number;
10
+ };
11
+ export declare class AudioFile {
12
+ private buffer?;
13
+ private source;
14
+ private amp;
15
+ private fade;
16
+ promise: Promise<void>;
17
+ played: number | null;
18
+ constructor(path: string);
19
+ set volume(value: number);
20
+ get volume(): number;
21
+ play({ offset, fade, loop }?: AudioFilePlayOptions): void;
22
+ pause({ fade }?: AudioFilePauseOptions): number | undefined;
23
+ clear(): void;
24
+ }
25
+ export type SynthesizerOptions = {
7
26
  oscillator: OscillatorOptions;
8
27
  amp: AmpOptions;
9
28
  filter?: FilterOptions;
@@ -35,9 +54,9 @@ type LFO = {
35
54
  type: OscillatorType;
36
55
  rate: number;
37
56
  };
38
- declare class Synthesizer {
39
- props: SynthProps;
40
- constructor(props: SynthProps);
57
+ export declare class Synthesizer {
58
+ props: SynthesizerOptions;
59
+ constructor(props: SynthesizerOptions);
41
60
  press(frequency: number | string, duration?: number | string, wait?: number): {
42
61
  release: () => void;
43
62
  } | undefined;
@@ -1,5 +1,2 @@
1
1
  import { Unit } from '../core/unit';
2
- export declare function VolumeController(unit: Unit, { range, icon }?: {
3
- range?: number | string;
4
- icon?: number | string;
5
- }): void;
2
+ export declare function VolumeController(unit: Unit, {}?: {}): void;
@@ -1,30 +1,19 @@
1
1
  import { Unit } from '../core/unit';
2
- export declare function AnalogStick(self: Unit, { size, fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin }?: {
3
- size?: number;
4
- diagonal?: boolean;
5
- fill?: string;
6
- fillOpacity?: number;
2
+ export declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
7
3
  stroke?: string;
8
4
  strokeOpacity?: number;
9
5
  strokeWidth?: number;
10
6
  strokeLinejoin?: string;
11
- }): void;
12
- export declare function DirectionalPad(self: Unit, { size, diagonal, fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin }?: {
13
- size?: number;
14
7
  diagonal?: boolean;
15
8
  fill?: string;
16
9
  fillOpacity?: number;
10
+ }): void;
11
+ export declare function DirectionalPad(unit: Unit, { diagonal, stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
12
+ diagonal?: boolean;
17
13
  stroke?: string;
18
14
  strokeOpacity?: number;
19
15
  strokeWidth?: number;
20
16
  strokeLinejoin?: string;
21
- }): void;
22
- export declare function TouchButton(self: Unit, { size, fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin }?: {
23
- size?: number | undefined;
24
- fill?: string | undefined;
25
- fillOpacity?: number | undefined;
26
- stroke?: string | undefined;
27
- strokeOpacity?: number | undefined;
28
- strokeWidth?: number | undefined;
29
- strokeLinejoin?: string | undefined;
17
+ fill?: string;
18
+ fillOpacity?: number;
30
19
  }): void;
@@ -1,2 +1,8 @@
1
1
  import { Unit } from '../core/unit';
2
- export declare function InputFrame(frame: Unit, {}?: {}): void;
2
+ export declare function InputRange(frame: Unit, { value, min, max, step, ...attributes }?: {
3
+ value?: number | string;
4
+ min?: number | string;
5
+ max?: number | string;
6
+ step?: number | string;
7
+ attributes?: Object;
8
+ }): void;
@@ -0,0 +1,6 @@
1
+ import { Unit } from '../core/unit';
2
+ export declare function TextStream(unit: Unit, { text, speed, fade }?: {
3
+ text?: string;
4
+ speed?: number;
5
+ fade?: number;
6
+ }): void;
@@ -23,6 +23,8 @@ interface UnitInternal {
23
23
  anchor: UnitElement | null;
24
24
  state: string;
25
25
  tostart: boolean;
26
+ protected: boolean;
27
+ ancestors: Unit[];
26
28
  children: Unit[];
27
29
  promises: Promise<any>[];
28
30
  elements: UnitElement[];
@@ -66,7 +68,7 @@ export declare class Unit {
66
68
  static type2units: MapSet<string, Unit>;
67
69
  on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
68
70
  off(type?: string, listener?: Function): void;
69
- emit(type: string, ...args: any[]): void;
71
+ static emit(type: string, ...args: any[]): void;
70
72
  }
71
73
  export declare class UnitPromise {
72
74
  private promise;
@@ -1,5 +1,4 @@
1
1
  import { Unit, UnitPromise } from './unit';
2
- import { Synthesizer, SynthesizerOptions } from './audio';
3
2
  interface CreateUnit {
4
3
  /**
5
4
  * Creates a new Unit component
@@ -91,15 +90,6 @@ export declare const xnew: CreateUnit & {
91
90
  * xnew.finally(() => console.log('All promises settled'))
92
91
  */
93
92
  finally(callback: Function): UnitPromise;
94
- /**
95
- * Fetches a resource and registers the promise with the current component
96
- * @param url - URL to fetch
97
- * @param options - Optional fetch options (method, headers, body, etc.)
98
- * @returns UnitPromise wrapping the fetch promise
99
- * @example
100
- * xnew.fetch('/api/users').then(res => res.json()).then(data => console.log(data))
101
- */
102
- fetch(url: string, options?: object): UnitPromise;
103
93
  /**
104
94
  * Creates a scoped callback that captures the current component context
105
95
  * @param callback - Function to wrap with current scope
@@ -120,6 +110,7 @@ export declare const xnew: CreateUnit & {
120
110
  * buttons.forEach(btn => btn.finalize())
121
111
  */
122
112
  find(component: Function): Unit[];
113
+ emit(type: string, ...args: any[]): void;
123
114
  /**
124
115
  * Executes a callback once after a delay, managed by component lifecycle
125
116
  * @param timeout - Function to execute after Duration
@@ -154,10 +145,6 @@ export declare const xnew: CreateUnit & {
154
145
  * }, 300)
155
146
  */
156
147
  transition(transition: Function, duration?: number, easing?: string): any;
157
- audio: {
158
- load(path: string): UnitPromise;
159
- synthesizer(props: SynthesizerOptions): Synthesizer;
160
- volume: number;
161
- };
148
+ protect(): void;
162
149
  };
163
150
  export {};
@@ -1,5 +1,5 @@
1
1
  import { xnew as base } from './core/xnew';
2
- import { Unit } from './core/unit';
2
+ import { Unit, UnitPromise } from './core/unit';
3
3
  import { AccordionFrame, AccordionHeader, AccordionBullet, AccordionContent } from './basics/Accordion';
4
4
  import { ResizeEvent, PointerEvent, KeyboardEvent } from './basics/Event';
5
5
  import { Screen } from './basics/Screen';
@@ -7,6 +7,7 @@ import { ModalFrame, ModalContent } from './basics/Modal';
7
7
  import { TabFrame, TabButton, TabContent } from './basics/Tab';
8
8
  import { DragFrame, DragTarget } from './basics/Drag';
9
9
  import { AnalogStick, DirectionalPad } from './basics/Controller';
10
+ import { TextStream } from './basics/Text';
10
11
  import { VolumeController } from './basics/Audio';
11
12
  import { icons } from './icons/icons';
12
13
  declare const basics: {
@@ -23,17 +24,25 @@ declare const basics: {
23
24
  TabFrame: typeof TabFrame;
24
25
  TabButton: typeof TabButton;
25
26
  TabContent: typeof TabContent;
27
+ TextStream: typeof TextStream;
26
28
  DragFrame: typeof DragFrame;
27
29
  DragTarget: typeof DragTarget;
28
30
  AnalogStick: typeof AnalogStick;
29
31
  DirectionalPad: typeof DirectionalPad;
30
32
  VolumeController: typeof VolumeController;
31
33
  };
34
+ import { Synthesizer, SynthesizerOptions } from './audio/audio';
35
+ declare const audio: {
36
+ load(path: string): UnitPromise;
37
+ synthesizer(props: SynthesizerOptions): Synthesizer;
38
+ volume: number;
39
+ };
32
40
  declare namespace xnew {
33
41
  type Unit = InstanceType<typeof Unit>;
34
42
  }
35
43
  declare const xnew: (typeof base) & {
36
44
  basics: typeof basics;
45
+ audio: typeof audio;
37
46
  icons: typeof icons;
38
47
  };
39
48
  export default xnew;