@mulsense/xnew 0.1.12 → 0.2.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.1.x/dist/xnew.js"></script>
16
+ <script src="https://unpkg.com/@mulsense/xnew@0.2.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.1.x/dist/xnew.mjs"
25
+ "@mulsense/xnew": "https://unpkg.com/@mulsense/xnew@0.2.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.1.x
40
+ npm install @mulsense/xnew@0.2.x
41
41
  ```
42
42
 
43
43
  Then import it in your JavaScript file:
@@ -23,7 +23,7 @@
23
23
  root.isActive = true;
24
24
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
25
25
  xnew.context('xmatter.object', root.engine.world);
26
- self.on('update', () => {
26
+ self.on('-update', () => {
27
27
  if (root.isActive) {
28
28
  Matter.Engine.update(root.engine);
29
29
  }
@@ -33,7 +33,7 @@
33
33
  const parent = xnew.context('xmatter.object');
34
34
  xnew.context('xmatter.object', object);
35
35
  Matter.Composite.add(parent, object);
36
- self.on('finalize', () => {
36
+ self.on('-finalize', () => {
37
37
  Matter.Composite.remove(parent, object);
38
38
  });
39
39
  }
@@ -20,7 +20,7 @@ function Root(self, { engine }) {
20
20
  root.isActive = true;
21
21
  root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
22
22
  xnew.context('xmatter.object', root.engine.world);
23
- self.on('update', () => {
23
+ self.on('-update', () => {
24
24
  if (root.isActive) {
25
25
  Matter.Engine.update(root.engine);
26
26
  }
@@ -30,7 +30,7 @@ function Nest(self, { object }) {
30
30
  const parent = xnew.context('xmatter.object');
31
31
  xnew.context('xmatter.object', object);
32
32
  Matter.Composite.add(parent, object);
33
- self.on('finalize', () => {
33
+ self.on('-finalize', () => {
34
34
  Matter.Composite.remove(parent, object);
35
35
  });
36
36
  }
@@ -6,5 +6,8 @@ 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;
9
12
  };
10
13
  export default _default;
@@ -50,12 +50,10 @@
50
50
  var _a;
51
51
  return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
52
52
  },
53
- capture() {
54
- var _a, _b;
55
- const render = (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.renderer;
56
- const scene = (_b = xnew.context('xpixi.root')) === null || _b === void 0 ? void 0 : _b.scene;
57
- const canvas = render.extract.canvas(scene);
58
- return canvas.toDataURL('image/png', 1.0);
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 });
59
57
  }
60
58
  };
61
59
  function Root(self, { canvas }) {
@@ -76,7 +74,7 @@
76
74
  root.updates = [];
77
75
  root.scene = new PIXI__namespace.Container();
78
76
  xnew.context('xpixi.object', root.scene);
79
- self.on('update', () => {
77
+ self.on('-update', () => {
80
78
  root.updates.forEach((update) => {
81
79
  update();
82
80
  });
@@ -89,14 +87,14 @@
89
87
  const parent = xnew.context('xpixi.object');
90
88
  xnew.context('xpixi.object', object);
91
89
  parent.addChild(object);
92
- self.on('finalize', () => {
90
+ self.on('-finalize', () => {
93
91
  parent.removeChild(object);
94
92
  });
95
93
  }
96
94
  function PreUpdate(self, callback) {
97
95
  const root = xnew.context('xpixi.root');
98
96
  root.updates.push(callback);
99
- self.on('finalize', () => {
97
+ self.on('-finalize', () => {
100
98
  root.updates = root.updates.filter((update) => update !== callback);
101
99
  });
102
100
  }
@@ -28,12 +28,10 @@ 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() {
32
- var _a, _b;
33
- const render = (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.renderer;
34
- const scene = (_b = xnew.context('xpixi.root')) === null || _b === void 0 ? void 0 : _b.scene;
35
- const canvas = render.extract.canvas(scene);
36
- return canvas.toDataURL('image/png', 1.0);
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 });
37
35
  }
38
36
  };
39
37
  function Root(self, { canvas }) {
@@ -54,7 +52,7 @@ function Root(self, { canvas }) {
54
52
  root.updates = [];
55
53
  root.scene = new PIXI.Container();
56
54
  xnew.context('xpixi.object', root.scene);
57
- self.on('update', () => {
55
+ self.on('-update', () => {
58
56
  root.updates.forEach((update) => {
59
57
  update();
60
58
  });
@@ -67,14 +65,14 @@ function Nest(self, { object }) {
67
65
  const parent = xnew.context('xpixi.object');
68
66
  xnew.context('xpixi.object', object);
69
67
  parent.addChild(object);
70
- self.on('finalize', () => {
68
+ self.on('-finalize', () => {
71
69
  parent.removeChild(object);
72
70
  });
73
71
  }
74
72
  function PreUpdate(self, callback) {
75
73
  const root = xnew.context('xpixi.root');
76
74
  root.updates.push(callback);
77
- self.on('finalize', () => {
75
+ self.on('-finalize', () => {
78
76
  root.updates = root.updates.filter((update) => update !== callback);
79
77
  });
80
78
  }
@@ -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') {
@@ -57,7 +57,7 @@
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
+ self.on('-update', () => {
61
61
  root.renderer.render(root.scene, root.camera);
62
62
  });
63
63
  }
@@ -66,7 +66,7 @@
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
+ self.on('-finalize', () => {
70
70
  parent === null || parent === void 0 ? void 0 : parent.remove(object);
71
71
  });
72
72
  }
@@ -35,7 +35,7 @@ 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
+ self.on('-update', () => {
39
39
  root.renderer.render(root.scene, root.camera);
40
40
  });
41
41
  }
@@ -44,7 +44,7 @@ function Nest(self, { 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
+ self.on('-finalize', () => {
48
48
  parent === null || parent === void 0 ? void 0 : parent.remove(object);
49
49
  });
50
50
  }
@@ -1,18 +1,8 @@
1
1
  export declare const audio: {
2
- load(path: string): AudioFile;
2
+ load(path: string): import("../core/unit").UnitPromise;
3
3
  synthesizer(props: SynthProps): Synthesizer;
4
4
  volume: number;
5
5
  };
6
- declare class AudioFile {
7
- buffer?: AudioBuffer;
8
- promise: Promise<void>;
9
- source?: AudioBufferSourceNode;
10
- amp?: GainNode;
11
- start: number | null;
12
- constructor(path: string);
13
- play(offset?: number, loop?: boolean): void;
14
- pause(): number | undefined;
15
- }
16
6
  type SynthProps = {
17
7
  oscillator: OscillatorOptions;
18
8
  amp: AmpOptions;
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,64 @@
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;
7
+ };
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 = {
26
+ oscillator: OscillatorOptions;
27
+ amp: AmpOptions;
28
+ filter?: FilterOptions;
29
+ reverb?: ReverbOptions;
30
+ bpm?: number;
31
+ };
32
+ type OscillatorOptions = {
33
+ type: OscillatorType;
34
+ envelope?: Envelope;
35
+ LFO?: LFO;
36
+ };
37
+ type FilterOptions = {
38
+ type: BiquadFilterType;
39
+ cutoff: number;
40
+ };
41
+ type AmpOptions = {
42
+ envelope: Envelope;
43
+ };
44
+ type ReverbOptions = {
45
+ time: number;
46
+ mix: number;
47
+ };
48
+ type Envelope = {
49
+ amount: number;
50
+ ADSR: [number, number, number, number];
51
+ };
52
+ type LFO = {
53
+ amount: number;
54
+ type: OscillatorType;
55
+ rate: number;
56
+ };
57
+ export declare class Synthesizer {
58
+ props: SynthesizerOptions;
59
+ constructor(props: SynthesizerOptions);
60
+ press(frequency: number | string, duration?: number | string, wait?: number): {
61
+ release: () => void;
62
+ } | undefined;
63
+ }
64
+ export {};
@@ -1,13 +1,13 @@
1
1
  export declare class Ticker {
2
2
  private id;
3
- constructor(callback: Function);
3
+ constructor(callback: Function, fps?: number);
4
4
  clear(): void;
5
5
  }
6
6
  export interface TimerOptions {
7
7
  transition?: Function;
8
8
  timeout?: Function;
9
9
  duration: number;
10
- iterations?: number;
10
+ iterations: number;
11
11
  easing?: string;
12
12
  }
13
13
  export declare class Timer {
@@ -44,7 +44,6 @@ export declare class Unit {
44
44
  stop(): void;
45
45
  finalize(): void;
46
46
  reboot(): void;
47
- append(...args: any[]): void;
48
47
  static initialize(unit: Unit, anchor: UnitElement | null): void;
49
48
  static finalize(unit: Unit): void;
50
49
  static nest(unit: Unit, tag: string): UnitElement;
@@ -82,6 +81,7 @@ export declare class UnitTimer {
82
81
  constructor(options: TimerOptions);
83
82
  clear(): void;
84
83
  timeout(timeout: Function, duration?: number): this;
84
+ iteration(timeout: Function, duration?: number, iterations?: number): this;
85
85
  transition(transition: Function, duration?: number, easing?: string): this;
86
86
  static execute(timer: UnitTimer, options: TimerOptions): void;
87
87
  static next(timer: UnitTimer): void;
@@ -1,4 +1,5 @@
1
1
  import { Unit, UnitPromise } from './unit';
2
+ import { Synthesizer, SynthesizerOptions } from './audio';
2
3
  interface CreateUnit {
3
4
  /**
4
5
  * Creates a new Unit component
@@ -153,6 +154,10 @@ export declare const xnew: CreateUnit & {
153
154
  * }, 300)
154
155
  */
155
156
  transition(transition: Function, duration?: number, easing?: string): any;
156
- style(text: string): void;
157
+ audio: {
158
+ load(path: string): UnitPromise;
159
+ synthesizer(props: SynthesizerOptions): Synthesizer;
160
+ volume: number;
161
+ };
157
162
  };
158
163
  export {};