@mulsense/xnew 0.4.0 → 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.
@@ -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,12 +20,6 @@ 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;
27
- }
28
-
29
23
  type UnitElement = HTMLElement | SVGElement;
30
24
 
31
25
  interface EventProps {
@@ -65,6 +59,7 @@ interface Snapshot {
65
59
  unit: Unit;
66
60
  context: Context;
67
61
  element: UnitElement;
62
+ component: Function | null;
68
63
  }
69
64
  interface Internal {
70
65
  parent: Unit | null;
@@ -87,10 +82,14 @@ interface Internal {
87
82
  components: Function[];
88
83
  listeners: MapMap<string, Function, {
89
84
  element: UnitElement;
85
+ component: Function | null;
90
86
  execute: Function;
91
87
  }>;
92
88
  defines: Record<string, any>;
93
- systems: Record<string, Function[]>;
89
+ systems: Record<string, {
90
+ listener: Function;
91
+ execute: Function;
92
+ }[]>;
94
93
  eventManager: EventManager;
95
94
  }
96
95
  declare class Unit {
@@ -105,16 +104,16 @@ declare class Unit {
105
104
  static initialize(unit: Unit, anchor: UnitElement | null): void;
106
105
  static finalize(unit: Unit): void;
107
106
  static nest(unit: Unit, tag: string): UnitElement;
107
+ static currentComponent: Function;
108
108
  static extend(unit: Unit, component: Function, props?: Object): {
109
109
  [key: string]: any;
110
110
  };
111
111
  static start(unit: Unit): void;
112
112
  static stop(unit: Unit): void;
113
113
  static update(unit: Unit): void;
114
- static process(unit: Unit): void;
115
- static root: Unit;
116
- static current: Unit;
117
- static ticker: Ticker;
114
+ static render(unit: Unit): void;
115
+ static rootUnit: Unit;
116
+ static currentUnit: Unit;
118
117
  static reset(): void;
119
118
  static wrap(unit: Unit, listener: Function): (...args: any[]) => any;
120
119
  static scope(snapshot: Snapshot, func: Function, ...args: any[]): any;
@@ -125,6 +124,8 @@ declare class Unit {
125
124
  static type2units: MapSet<string, Unit>;
126
125
  on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
127
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;
128
129
  static emit(type: string, ...args: any[]): void;
129
130
  }
130
131
  declare class UnitPromise {
@@ -294,11 +295,11 @@ declare function AccordionFrame(frame: Unit, { open, duration, easing }?: {
294
295
  open(): void;
295
296
  close(): void;
296
297
  };
297
- declare function AccordionHeader(header: Unit, {}?: {}): void;
298
- declare function AccordionBullet(bullet: Unit, { type }?: {
298
+ declare function AccordionHeader(unit: Unit, {}?: {}): void;
299
+ declare function AccordionBullet(unit: Unit, { type }?: {
299
300
  type?: string;
300
301
  }): void;
301
- declare function AccordionContent(content: Unit, {}?: {}): {
302
+ declare function AccordionContent(unit: Unit, {}?: {}): {
302
303
  transition({ element, rate }: {
303
304
  element: HTMLElement;
304
305
  rate: number;
package/dist/xnew.js CHANGED
@@ -104,7 +104,7 @@
104
104
  //----------------------------------------------------------------------------------------------------
105
105
  // ticker
106
106
  //----------------------------------------------------------------------------------------------------
107
- class Ticker {
107
+ class AnimationTicker {
108
108
  constructor(callback, fps = 60) {
109
109
  const self = this;
110
110
  this.id = null;
@@ -135,7 +135,7 @@
135
135
  this.counter = 0;
136
136
  this.offset = 0.0;
137
137
  this.status = 0;
138
- this.ticker = new Ticker((time) => {
138
+ this.ticker = new AnimationTicker((time) => {
139
139
  var _a, _b;
140
140
  let p = Math.min(this.elapsed() / this.options.duration, 1.0);
141
141
  if (this.options.easing === 'ease-out') {
@@ -206,7 +206,7 @@
206
206
  }
207
207
  }
208
208
 
209
- const SYSTEM_EVENTS = ['start', 'process', 'update', 'stop', 'finalize'];
209
+ const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
210
210
 
211
211
  class EventManager {
212
212
  constructor() {
@@ -272,12 +272,12 @@
272
272
  };
273
273
  }
274
274
  resize(props) {
275
- const observer = new ResizeObserver(xnew$1.scope((entries) => {
275
+ const observer = new ResizeObserver((entries) => {
276
276
  for (const entry of entries) {
277
277
  props.listener({ type: 'resize' });
278
278
  break;
279
279
  }
280
- }));
280
+ });
281
281
  observer.observe(props.element);
282
282
  return () => {
283
283
  observer.unobserve(props.element);
@@ -416,7 +416,7 @@
416
416
  const element = props.element;
417
417
  const options = props.options;
418
418
  const dragstart = ({ event, position }) => {
419
- map.set(event.pointerId, Object.assign({}, position));
419
+ map.set(event.pointerId, position);
420
420
  isActive = map.size === 2 ? true : false;
421
421
  if (isActive === true && props.type === 'gesturestart') {
422
422
  props.listener({ event, type: props.type });
@@ -452,11 +452,11 @@
452
452
  map.set(event.pointerId, position);
453
453
  };
454
454
  const dragend = ({ event }) => {
455
- if (isActive === true) {
455
+ map.delete(event.pointerId);
456
+ if (isActive === true && props.type === 'gestureend') {
456
457
  props.listener({ event, type: props.type, scale: 1.0 });
457
458
  }
458
459
  isActive = false;
459
- map.delete(event.pointerId);
460
460
  };
461
461
  this.add({ element, options, type: 'dragstart', listener: dragstart });
462
462
  this.add({ element, options, type: 'dragmove', listener: dragmove });
@@ -598,8 +598,8 @@
598
598
  }
599
599
  static initialize(unit, anchor) {
600
600
  var _a, _b;
601
- const backup = Unit.current;
602
- Unit.current = unit;
601
+ const backup = Unit.currentUnit;
602
+ Unit.currentUnit = unit;
603
603
  unit._ = Object.assign(unit._, {
604
604
  currentElement: unit._.baseElement,
605
605
  currentContext: unit._.baseContext,
@@ -615,7 +615,7 @@
615
615
  components: [],
616
616
  listeners: new MapMap(),
617
617
  defines: {},
618
- systems: { start: [], process: [], update: [], stop: [], finalize: [] },
618
+ systems: { start: [], update: [], render: [], stop: [], finalize: [] },
619
619
  eventManager: new EventManager(),
620
620
  });
621
621
  // nest html element
@@ -626,13 +626,13 @@
626
626
  Unit.extend(unit, unit._.baseComponent, unit._.props);
627
627
  // whether the unit promise was resolved
628
628
  Promise.all(unit._.promises.map(p => p.promise)).then(() => unit._.state = 'initialized');
629
- Unit.current = backup;
629
+ Unit.currentUnit = backup;
630
630
  }
631
631
  static finalize(unit) {
632
632
  if (unit._.state !== 'finalized' && unit._.state !== 'finalizing') {
633
633
  unit._.state = 'finalizing';
634
634
  unit._.children.forEach((child) => child.finalize());
635
- unit._.systems.finalize.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
635
+ unit._.systems.finalize.forEach(({ execute }) => execute());
636
636
  unit.off();
637
637
  unit._.components.forEach((component) => Unit.component2units.delete(component, unit));
638
638
  if (unit._.elements.length > 0) {
@@ -712,7 +712,7 @@
712
712
  if (unit._.state === 'initialized' || unit._.state === 'stopped') {
713
713
  unit._.state = 'started';
714
714
  unit._.children.forEach((child) => Unit.start(child));
715
- unit._.systems.start.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
715
+ unit._.systems.start.forEach(({ execute }) => execute());
716
716
  }
717
717
  else if (unit._.state === 'started') {
718
718
  unit._.children.forEach((child) => Unit.start(child));
@@ -722,31 +722,31 @@
722
722
  if (unit._.state === 'started') {
723
723
  unit._.state = 'stopped';
724
724
  unit._.children.forEach((child) => Unit.stop(child));
725
- unit._.systems.stop.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
725
+ unit._.systems.stop.forEach(({ execute }) => execute());
726
726
  }
727
727
  }
728
728
  static update(unit) {
729
- if (unit._.state === 'started' || unit._.state === 'stopped') {
729
+ if (unit._.state === 'started') {
730
730
  unit._.children.forEach((child) => Unit.update(child));
731
- unit._.systems.update.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
731
+ unit._.systems.update.forEach(({ execute }) => execute());
732
732
  }
733
733
  }
734
- static process(unit) {
735
- if (unit._.state === 'started') {
736
- unit._.children.forEach((child) => Unit.process(child));
737
- unit._.systems.process.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
734
+ static render(unit) {
735
+ if (unit._.state === 'started' || unit._.state === 'started' || unit._.state === 'stopped') {
736
+ unit._.children.forEach((child) => Unit.render(child));
737
+ unit._.systems.render.forEach(({ execute }) => execute());
738
738
  }
739
739
  }
740
740
  static reset() {
741
- var _a, _b;
742
- (_a = Unit.root) === null || _a === void 0 ? void 0 : _a.finalize();
743
- Unit.current = Unit.root = new Unit(null, null);
744
- (_b = Unit.ticker) === null || _b === void 0 ? void 0 : _b.clear();
745
- Unit.ticker = new Ticker(() => {
746
- Unit.start(Unit.root);
747
- Unit.process(Unit.root);
748
- Unit.update(Unit.root);
741
+ var _a;
742
+ (_a = Unit.rootUnit) === null || _a === void 0 ? void 0 : _a.finalize();
743
+ Unit.currentUnit = Unit.rootUnit = new Unit(null, null);
744
+ const ticker = new AnimationTicker(() => {
745
+ Unit.start(Unit.rootUnit);
746
+ Unit.update(Unit.rootUnit);
747
+ Unit.render(Unit.rootUnit);
749
748
  });
749
+ Unit.rootUnit.on('finalize', () => ticker.clear());
750
750
  }
751
751
  static wrap(unit, listener) {
752
752
  const snapshot = Unit.snapshot(unit);
@@ -756,25 +756,27 @@
756
756
  if (snapshot.unit._.state === 'finalized') {
757
757
  return;
758
758
  }
759
- const current = Unit.current;
759
+ const currentUnit = Unit.currentUnit;
760
760
  const backup = Unit.snapshot(snapshot.unit);
761
761
  try {
762
- Unit.current = snapshot.unit;
762
+ Unit.currentUnit = snapshot.unit;
763
763
  snapshot.unit._.currentContext = snapshot.context;
764
764
  snapshot.unit._.currentElement = snapshot.element;
765
+ snapshot.unit._.currentComponent = snapshot.component;
765
766
  return func(...args);
766
767
  }
767
768
  catch (error) {
768
769
  throw error;
769
770
  }
770
771
  finally {
771
- Unit.current = current;
772
+ Unit.currentUnit = currentUnit;
772
773
  snapshot.unit._.currentContext = backup.context;
773
774
  snapshot.unit._.currentElement = backup.element;
775
+ snapshot.unit._.currentComponent = backup.component;
774
776
  }
775
777
  }
776
778
  static snapshot(unit) {
777
- return { unit, context: unit._.currentContext, element: unit._.currentElement };
779
+ return { unit, context: unit._.currentContext, element: unit._.currentElement, component: unit._.currentComponent };
778
780
  }
779
781
  static context(unit, key, value) {
780
782
  if (value !== undefined) {
@@ -792,43 +794,47 @@
792
794
  return [...((_a = Unit.component2units.get(component)) !== null && _a !== void 0 ? _a : [])];
793
795
  }
794
796
  on(type, listener, options) {
795
- type.trim().split(/\s+/).forEach((type) => {
796
- if (SYSTEM_EVENTS.includes(type)) {
797
- this._.systems[type].push(listener);
798
- }
799
- if (this._.listeners.has(type, listener) === false) {
800
- const execute = Unit.wrap(Unit.current, listener);
801
- this._.listeners.set(type, listener, { element: this.element, execute });
802
- Unit.type2units.add(type, this);
803
- if (/^[A-Za-z]/.test(type)) {
804
- this._.eventManager.add({ element: this.element, type, listener: execute, options });
805
- }
806
- }
807
- });
797
+ const types = type.trim().split(/\s+/);
798
+ types.forEach((type) => Unit.on(this, type, listener, options));
808
799
  }
809
800
  off(type, listener) {
810
801
  const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...this._.listeners.keys()];
811
- types.forEach((type) => {
812
- if (SYSTEM_EVENTS.includes(type)) {
813
- this._.systems[type] = this._.systems[type].filter((lis) => listener ? lis !== listener : false);
802
+ types.forEach((type) => Unit.off(this, type, listener));
803
+ }
804
+ static on(unit, type, listener, options) {
805
+ if (SYSTEM_EVENTS.includes(type)) {
806
+ const execute = Unit.wrap(Unit.currentUnit, listener);
807
+ unit._.systems[type].push({ listener, execute });
808
+ }
809
+ if (unit._.listeners.has(type, listener) === false) {
810
+ const execute = Unit.wrap(Unit.currentUnit, listener);
811
+ unit._.listeners.set(type, listener, { element: unit.element, component: unit._.currentComponent, execute });
812
+ Unit.type2units.add(type, unit);
813
+ if (/^[A-Za-z]/.test(type)) {
814
+ unit._.eventManager.add({ element: unit.element, type, listener: execute, options });
814
815
  }
815
- (listener ? [listener] : [...this._.listeners.keys(type)]).forEach((listener) => {
816
- const item = this._.listeners.get(type, listener);
817
- if (item === undefined)
818
- return;
819
- this._.listeners.delete(type, listener);
820
- if (/^[A-Za-z]/.test(type)) {
821
- this._.eventManager.remove({ type, listener: item.execute });
822
- }
823
- });
824
- if (this._.listeners.has(type) === false) {
825
- Unit.type2units.delete(type, this);
816
+ }
817
+ }
818
+ static off(unit, type, listener) {
819
+ if (SYSTEM_EVENTS.includes(type)) {
820
+ unit._.systems[type] = unit._.systems[type].filter(({ listener: lis }) => listener ? lis !== listener : false);
821
+ }
822
+ (listener ? [listener] : [...unit._.listeners.keys(type)]).forEach((listener) => {
823
+ const item = unit._.listeners.get(type, listener);
824
+ if (item === undefined)
825
+ return;
826
+ unit._.listeners.delete(type, listener);
827
+ if (/^[A-Za-z]/.test(type)) {
828
+ unit._.eventManager.remove({ type, listener: item.execute });
826
829
  }
827
830
  });
831
+ if (unit._.listeners.has(type) === false) {
832
+ Unit.type2units.delete(type, unit);
833
+ }
828
834
  }
829
835
  static emit(type, ...args) {
830
836
  var _a, _b;
831
- const current = Unit.current;
837
+ const current = Unit.currentUnit;
832
838
  if (type[0] === '+') {
833
839
  (_a = Unit.type2units.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((unit) => {
834
840
  var _a;
@@ -843,6 +849,7 @@
843
849
  }
844
850
  }
845
851
  }
852
+ Unit.currentComponent = () => { };
846
853
  Unit.component2units = new MapSet();
847
854
  //----------------------------------------------------------------------------------------------------
848
855
  // event
@@ -857,15 +864,15 @@
857
864
  this.component = component;
858
865
  }
859
866
  then(callback) {
860
- this.promise = this.promise.then(Unit.wrap(Unit.current, callback));
867
+ this.promise = this.promise.then(Unit.wrap(Unit.currentUnit, callback));
861
868
  return this;
862
869
  }
863
870
  catch(callback) {
864
- this.promise = this.promise.catch(Unit.wrap(Unit.current, callback));
871
+ this.promise = this.promise.catch(Unit.wrap(Unit.currentUnit, callback));
865
872
  return this;
866
873
  }
867
874
  finally(callback) {
868
- this.promise = this.promise.finally(Unit.wrap(Unit.current, callback));
875
+ this.promise = this.promise.finally(Unit.wrap(Unit.currentUnit, callback));
869
876
  return this;
870
877
  }
871
878
  }
@@ -875,7 +882,7 @@
875
882
  class UnitTimer {
876
883
  constructor(options) {
877
884
  this.stack = [];
878
- this.unit = new Unit(Unit.current, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
885
+ this.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
879
886
  }
880
887
  clear() {
881
888
  this.stack = [];
@@ -895,19 +902,19 @@
895
902
  }
896
903
  static execute(timer, options) {
897
904
  if (timer.unit._.state === 'finalized') {
898
- timer.unit = new Unit(Unit.current, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
905
+ timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
899
906
  }
900
907
  else if (timer.stack.length === 0) {
901
- timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
908
+ timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
902
909
  timer.unit.on('finalize', () => { UnitTimer.next(timer); });
903
910
  }
904
911
  else {
905
- timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
912
+ timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
906
913
  }
907
914
  }
908
915
  static next(timer) {
909
916
  if (timer.stack.length > 0) {
910
- timer.unit = new Unit(Unit.current, UnitTimer.Component, timer.stack.shift());
917
+ timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, timer.stack.shift());
911
918
  timer.unit.on('finalize', () => { UnitTimer.next(timer); });
912
919
  }
913
920
  }
@@ -934,10 +941,10 @@
934
941
  }
935
942
 
936
943
  const xnew$1 = Object.assign(function (...args) {
937
- if (Unit.root === undefined) {
944
+ if (Unit.rootUnit === undefined) {
938
945
  Unit.reset();
939
946
  }
940
- return new Unit(Unit.current, ...args);
947
+ return new Unit(Unit.currentUnit, ...args);
941
948
  }, {
942
949
  /**
943
950
  * Creates a nested HTML/SVG element within the current component
@@ -950,7 +957,7 @@
950
957
  */
951
958
  nest(tag) {
952
959
  try {
953
- return Unit.nest(Unit.current, tag);
960
+ return Unit.nest(Unit.currentUnit, tag);
954
961
  }
955
962
  catch (error) {
956
963
  console.error('xnew.nest(tag: string): ', error);
@@ -968,7 +975,7 @@
968
975
  */
969
976
  extend(component, props) {
970
977
  try {
971
- return Unit.extend(Unit.current, component, props);
978
+ return Unit.extend(Unit.currentUnit, component, props);
972
979
  }
973
980
  catch (error) {
974
981
  console.error('xnew.extend(component: Function, props?: Object): ', error);
@@ -989,7 +996,7 @@
989
996
  */
990
997
  context(key, value = undefined) {
991
998
  try {
992
- return Unit.context(Unit.current, key, value);
999
+ return Unit.context(Unit.currentUnit, key, value);
993
1000
  }
994
1001
  catch (error) {
995
1002
  console.error('xnew.context(key: string, value?: any): ', error);
@@ -1005,9 +1012,9 @@
1005
1012
  */
1006
1013
  promise(promise) {
1007
1014
  try {
1008
- const component = Unit.current._.currentComponent;
1009
- Unit.current._.promises.push(new UnitPromise(promise, component));
1010
- return Unit.current._.promises[Unit.current._.promises.length - 1];
1015
+ const component = Unit.currentUnit._.currentComponent;
1016
+ Unit.currentUnit._.promises.push(new UnitPromise(promise, component));
1017
+ return Unit.currentUnit._.promises[Unit.currentUnit._.promises.length - 1];
1011
1018
  }
1012
1019
  catch (error) {
1013
1020
  console.error('xnew.promise(promise: Promise<any>): ', error);
@@ -1023,8 +1030,8 @@
1023
1030
  */
1024
1031
  then(callback) {
1025
1032
  try {
1026
- const component = Unit.current._.currentComponent;
1027
- const promises = Unit.current._.promises;
1033
+ const component = Unit.currentUnit._.currentComponent;
1034
+ const promises = Unit.currentUnit._.promises;
1028
1035
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1029
1036
  .then((results) => {
1030
1037
  callback(results.filter((_result, index) => promises[index].component !== null && promises[index].component === component));
@@ -1044,7 +1051,7 @@
1044
1051
  */
1045
1052
  catch(callback) {
1046
1053
  try {
1047
- const promises = Unit.current._.promises;
1054
+ const promises = Unit.currentUnit._.promises;
1048
1055
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1049
1056
  .catch(callback);
1050
1057
  }
@@ -1062,7 +1069,7 @@
1062
1069
  */
1063
1070
  finally(callback) {
1064
1071
  try {
1065
- const promises = Unit.current._.promises;
1072
+ const promises = Unit.currentUnit._.promises;
1066
1073
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1067
1074
  .finally(callback);
1068
1075
  }
@@ -1081,7 +1088,7 @@
1081
1088
  * }), 1000)
1082
1089
  */
1083
1090
  scope(callback) {
1084
- const snapshot = Unit.snapshot(Unit.current);
1091
+ const snapshot = Unit.snapshot(Unit.currentUnit);
1085
1092
  return (...args) => Unit.scope(snapshot, callback, ...args);
1086
1093
  },
1087
1094
  /**
@@ -1152,7 +1159,7 @@
1152
1159
  return new UnitTimer({ transition, duration, easing, iterations: 1 });
1153
1160
  },
1154
1161
  protect() {
1155
- Unit.current._.protected = true;
1162
+ Unit.currentUnit._.protected = true;
1156
1163
  }
1157
1164
  });
1158
1165
 
@@ -1187,12 +1194,12 @@
1187
1194
  }
1188
1195
  };
1189
1196
  }
1190
- function AccordionHeader(header, {} = {}) {
1197
+ function AccordionHeader(unit, {} = {}) {
1191
1198
  const internal = xnew$1.context('xnew.accordionframe');
1192
1199
  xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
1193
- header.on('click', () => internal.frame.toggle());
1200
+ unit.on('click', () => internal.frame.toggle());
1194
1201
  }
1195
- function AccordionBullet(bullet, { type = 'arrow' } = {}) {
1202
+ function AccordionBullet(unit, { type = 'arrow' } = {}) {
1196
1203
  const internal = xnew$1.context('xnew.accordionframe');
1197
1204
  xnew$1.nest('<div style="display:inline-block; position: relative; width: 0.55em; margin: 0 0.3em;">');
1198
1205
  if (type === 'arrow') {
@@ -1213,12 +1220,12 @@
1213
1220
  });
1214
1221
  }
1215
1222
  }
1216
- function AccordionContent(content, {} = {}) {
1223
+ function AccordionContent(unit, {} = {}) {
1217
1224
  const internal = xnew$1.context('xnew.accordionframe');
1218
1225
  xnew$1.nest(`<div style="display: ${internal.open ? 'block' : 'none'};">`);
1219
1226
  xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
1220
1227
  internal.on('-transition', ({ rate }) => {
1221
- content.transition({ element: content.element, rate });
1228
+ unit.transition({ element: unit.element, rate });
1222
1229
  });
1223
1230
  return {
1224
1231
  transition({ element, rate }) {
package/dist/xnew.mjs CHANGED
@@ -98,7 +98,7 @@ class MapMap extends Map {
98
98
  //----------------------------------------------------------------------------------------------------
99
99
  // ticker
100
100
  //----------------------------------------------------------------------------------------------------
101
- class Ticker {
101
+ class AnimationTicker {
102
102
  constructor(callback, fps = 60) {
103
103
  const self = this;
104
104
  this.id = null;
@@ -129,7 +129,7 @@ class Timer {
129
129
  this.counter = 0;
130
130
  this.offset = 0.0;
131
131
  this.status = 0;
132
- this.ticker = new Ticker((time) => {
132
+ this.ticker = new AnimationTicker((time) => {
133
133
  var _a, _b;
134
134
  let p = Math.min(this.elapsed() / this.options.duration, 1.0);
135
135
  if (this.options.easing === 'ease-out') {
@@ -200,7 +200,7 @@ class Timer {
200
200
  }
201
201
  }
202
202
 
203
- const SYSTEM_EVENTS = ['start', 'process', 'update', 'stop', 'finalize'];
203
+ const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
204
204
 
205
205
  class EventManager {
206
206
  constructor() {
@@ -266,12 +266,12 @@ class EventManager {
266
266
  };
267
267
  }
268
268
  resize(props) {
269
- const observer = new ResizeObserver(xnew$1.scope((entries) => {
269
+ const observer = new ResizeObserver((entries) => {
270
270
  for (const entry of entries) {
271
271
  props.listener({ type: 'resize' });
272
272
  break;
273
273
  }
274
- }));
274
+ });
275
275
  observer.observe(props.element);
276
276
  return () => {
277
277
  observer.unobserve(props.element);
@@ -410,7 +410,7 @@ class EventManager {
410
410
  const element = props.element;
411
411
  const options = props.options;
412
412
  const dragstart = ({ event, position }) => {
413
- map.set(event.pointerId, Object.assign({}, position));
413
+ map.set(event.pointerId, position);
414
414
  isActive = map.size === 2 ? true : false;
415
415
  if (isActive === true && props.type === 'gesturestart') {
416
416
  props.listener({ event, type: props.type });
@@ -446,11 +446,11 @@ class EventManager {
446
446
  map.set(event.pointerId, position);
447
447
  };
448
448
  const dragend = ({ event }) => {
449
- if (isActive === true) {
449
+ map.delete(event.pointerId);
450
+ if (isActive === true && props.type === 'gestureend') {
450
451
  props.listener({ event, type: props.type, scale: 1.0 });
451
452
  }
452
453
  isActive = false;
453
- map.delete(event.pointerId);
454
454
  };
455
455
  this.add({ element, options, type: 'dragstart', listener: dragstart });
456
456
  this.add({ element, options, type: 'dragmove', listener: dragmove });
@@ -592,8 +592,8 @@ class Unit {
592
592
  }
593
593
  static initialize(unit, anchor) {
594
594
  var _a, _b;
595
- const backup = Unit.current;
596
- Unit.current = unit;
595
+ const backup = Unit.currentUnit;
596
+ Unit.currentUnit = unit;
597
597
  unit._ = Object.assign(unit._, {
598
598
  currentElement: unit._.baseElement,
599
599
  currentContext: unit._.baseContext,
@@ -609,7 +609,7 @@ class Unit {
609
609
  components: [],
610
610
  listeners: new MapMap(),
611
611
  defines: {},
612
- systems: { start: [], process: [], update: [], stop: [], finalize: [] },
612
+ systems: { start: [], update: [], render: [], stop: [], finalize: [] },
613
613
  eventManager: new EventManager(),
614
614
  });
615
615
  // nest html element
@@ -620,13 +620,13 @@ class Unit {
620
620
  Unit.extend(unit, unit._.baseComponent, unit._.props);
621
621
  // whether the unit promise was resolved
622
622
  Promise.all(unit._.promises.map(p => p.promise)).then(() => unit._.state = 'initialized');
623
- Unit.current = backup;
623
+ Unit.currentUnit = backup;
624
624
  }
625
625
  static finalize(unit) {
626
626
  if (unit._.state !== 'finalized' && unit._.state !== 'finalizing') {
627
627
  unit._.state = 'finalizing';
628
628
  unit._.children.forEach((child) => child.finalize());
629
- unit._.systems.finalize.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
629
+ unit._.systems.finalize.forEach(({ execute }) => execute());
630
630
  unit.off();
631
631
  unit._.components.forEach((component) => Unit.component2units.delete(component, unit));
632
632
  if (unit._.elements.length > 0) {
@@ -706,7 +706,7 @@ class Unit {
706
706
  if (unit._.state === 'initialized' || unit._.state === 'stopped') {
707
707
  unit._.state = 'started';
708
708
  unit._.children.forEach((child) => Unit.start(child));
709
- unit._.systems.start.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
709
+ unit._.systems.start.forEach(({ execute }) => execute());
710
710
  }
711
711
  else if (unit._.state === 'started') {
712
712
  unit._.children.forEach((child) => Unit.start(child));
@@ -716,31 +716,31 @@ class Unit {
716
716
  if (unit._.state === 'started') {
717
717
  unit._.state = 'stopped';
718
718
  unit._.children.forEach((child) => Unit.stop(child));
719
- unit._.systems.stop.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
719
+ unit._.systems.stop.forEach(({ execute }) => execute());
720
720
  }
721
721
  }
722
722
  static update(unit) {
723
- if (unit._.state === 'started' || unit._.state === 'stopped') {
723
+ if (unit._.state === 'started') {
724
724
  unit._.children.forEach((child) => Unit.update(child));
725
- unit._.systems.update.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
725
+ unit._.systems.update.forEach(({ execute }) => execute());
726
726
  }
727
727
  }
728
- static process(unit) {
729
- if (unit._.state === 'started') {
730
- unit._.children.forEach((child) => Unit.process(child));
731
- unit._.systems.process.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
728
+ static render(unit) {
729
+ if (unit._.state === 'started' || unit._.state === 'started' || unit._.state === 'stopped') {
730
+ unit._.children.forEach((child) => Unit.render(child));
731
+ unit._.systems.render.forEach(({ execute }) => execute());
732
732
  }
733
733
  }
734
734
  static reset() {
735
- var _a, _b;
736
- (_a = Unit.root) === null || _a === void 0 ? void 0 : _a.finalize();
737
- Unit.current = Unit.root = new Unit(null, null);
738
- (_b = Unit.ticker) === null || _b === void 0 ? void 0 : _b.clear();
739
- Unit.ticker = new Ticker(() => {
740
- Unit.start(Unit.root);
741
- Unit.process(Unit.root);
742
- Unit.update(Unit.root);
735
+ var _a;
736
+ (_a = Unit.rootUnit) === null || _a === void 0 ? void 0 : _a.finalize();
737
+ Unit.currentUnit = Unit.rootUnit = new Unit(null, null);
738
+ const ticker = new AnimationTicker(() => {
739
+ Unit.start(Unit.rootUnit);
740
+ Unit.update(Unit.rootUnit);
741
+ Unit.render(Unit.rootUnit);
743
742
  });
743
+ Unit.rootUnit.on('finalize', () => ticker.clear());
744
744
  }
745
745
  static wrap(unit, listener) {
746
746
  const snapshot = Unit.snapshot(unit);
@@ -750,25 +750,27 @@ class Unit {
750
750
  if (snapshot.unit._.state === 'finalized') {
751
751
  return;
752
752
  }
753
- const current = Unit.current;
753
+ const currentUnit = Unit.currentUnit;
754
754
  const backup = Unit.snapshot(snapshot.unit);
755
755
  try {
756
- Unit.current = snapshot.unit;
756
+ Unit.currentUnit = snapshot.unit;
757
757
  snapshot.unit._.currentContext = snapshot.context;
758
758
  snapshot.unit._.currentElement = snapshot.element;
759
+ snapshot.unit._.currentComponent = snapshot.component;
759
760
  return func(...args);
760
761
  }
761
762
  catch (error) {
762
763
  throw error;
763
764
  }
764
765
  finally {
765
- Unit.current = current;
766
+ Unit.currentUnit = currentUnit;
766
767
  snapshot.unit._.currentContext = backup.context;
767
768
  snapshot.unit._.currentElement = backup.element;
769
+ snapshot.unit._.currentComponent = backup.component;
768
770
  }
769
771
  }
770
772
  static snapshot(unit) {
771
- return { unit, context: unit._.currentContext, element: unit._.currentElement };
773
+ return { unit, context: unit._.currentContext, element: unit._.currentElement, component: unit._.currentComponent };
772
774
  }
773
775
  static context(unit, key, value) {
774
776
  if (value !== undefined) {
@@ -786,43 +788,47 @@ class Unit {
786
788
  return [...((_a = Unit.component2units.get(component)) !== null && _a !== void 0 ? _a : [])];
787
789
  }
788
790
  on(type, listener, options) {
789
- type.trim().split(/\s+/).forEach((type) => {
790
- if (SYSTEM_EVENTS.includes(type)) {
791
- this._.systems[type].push(listener);
792
- }
793
- if (this._.listeners.has(type, listener) === false) {
794
- const execute = Unit.wrap(Unit.current, listener);
795
- this._.listeners.set(type, listener, { element: this.element, execute });
796
- Unit.type2units.add(type, this);
797
- if (/^[A-Za-z]/.test(type)) {
798
- this._.eventManager.add({ element: this.element, type, listener: execute, options });
799
- }
800
- }
801
- });
791
+ const types = type.trim().split(/\s+/);
792
+ types.forEach((type) => Unit.on(this, type, listener, options));
802
793
  }
803
794
  off(type, listener) {
804
795
  const types = typeof type === 'string' ? type.trim().split(/\s+/) : [...this._.listeners.keys()];
805
- types.forEach((type) => {
806
- if (SYSTEM_EVENTS.includes(type)) {
807
- this._.systems[type] = this._.systems[type].filter((lis) => listener ? lis !== listener : false);
796
+ types.forEach((type) => Unit.off(this, type, listener));
797
+ }
798
+ static on(unit, type, listener, options) {
799
+ if (SYSTEM_EVENTS.includes(type)) {
800
+ const execute = Unit.wrap(Unit.currentUnit, listener);
801
+ unit._.systems[type].push({ listener, execute });
802
+ }
803
+ if (unit._.listeners.has(type, listener) === false) {
804
+ const execute = Unit.wrap(Unit.currentUnit, listener);
805
+ unit._.listeners.set(type, listener, { element: unit.element, component: unit._.currentComponent, execute });
806
+ Unit.type2units.add(type, unit);
807
+ if (/^[A-Za-z]/.test(type)) {
808
+ unit._.eventManager.add({ element: unit.element, type, listener: execute, options });
808
809
  }
809
- (listener ? [listener] : [...this._.listeners.keys(type)]).forEach((listener) => {
810
- const item = this._.listeners.get(type, listener);
811
- if (item === undefined)
812
- return;
813
- this._.listeners.delete(type, listener);
814
- if (/^[A-Za-z]/.test(type)) {
815
- this._.eventManager.remove({ type, listener: item.execute });
816
- }
817
- });
818
- if (this._.listeners.has(type) === false) {
819
- Unit.type2units.delete(type, this);
810
+ }
811
+ }
812
+ static off(unit, type, listener) {
813
+ if (SYSTEM_EVENTS.includes(type)) {
814
+ unit._.systems[type] = unit._.systems[type].filter(({ listener: lis }) => listener ? lis !== listener : false);
815
+ }
816
+ (listener ? [listener] : [...unit._.listeners.keys(type)]).forEach((listener) => {
817
+ const item = unit._.listeners.get(type, listener);
818
+ if (item === undefined)
819
+ return;
820
+ unit._.listeners.delete(type, listener);
821
+ if (/^[A-Za-z]/.test(type)) {
822
+ unit._.eventManager.remove({ type, listener: item.execute });
820
823
  }
821
824
  });
825
+ if (unit._.listeners.has(type) === false) {
826
+ Unit.type2units.delete(type, unit);
827
+ }
822
828
  }
823
829
  static emit(type, ...args) {
824
830
  var _a, _b;
825
- const current = Unit.current;
831
+ const current = Unit.currentUnit;
826
832
  if (type[0] === '+') {
827
833
  (_a = Unit.type2units.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((unit) => {
828
834
  var _a;
@@ -837,6 +843,7 @@ class Unit {
837
843
  }
838
844
  }
839
845
  }
846
+ Unit.currentComponent = () => { };
840
847
  Unit.component2units = new MapSet();
841
848
  //----------------------------------------------------------------------------------------------------
842
849
  // event
@@ -851,15 +858,15 @@ class UnitPromise {
851
858
  this.component = component;
852
859
  }
853
860
  then(callback) {
854
- this.promise = this.promise.then(Unit.wrap(Unit.current, callback));
861
+ this.promise = this.promise.then(Unit.wrap(Unit.currentUnit, callback));
855
862
  return this;
856
863
  }
857
864
  catch(callback) {
858
- this.promise = this.promise.catch(Unit.wrap(Unit.current, callback));
865
+ this.promise = this.promise.catch(Unit.wrap(Unit.currentUnit, callback));
859
866
  return this;
860
867
  }
861
868
  finally(callback) {
862
- this.promise = this.promise.finally(Unit.wrap(Unit.current, callback));
869
+ this.promise = this.promise.finally(Unit.wrap(Unit.currentUnit, callback));
863
870
  return this;
864
871
  }
865
872
  }
@@ -869,7 +876,7 @@ class UnitPromise {
869
876
  class UnitTimer {
870
877
  constructor(options) {
871
878
  this.stack = [];
872
- this.unit = new Unit(Unit.current, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
879
+ this.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
873
880
  }
874
881
  clear() {
875
882
  this.stack = [];
@@ -889,19 +896,19 @@ class UnitTimer {
889
896
  }
890
897
  static execute(timer, options) {
891
898
  if (timer.unit._.state === 'finalized') {
892
- timer.unit = new Unit(Unit.current, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
899
+ timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
893
900
  }
894
901
  else if (timer.stack.length === 0) {
895
- timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
902
+ timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
896
903
  timer.unit.on('finalize', () => { UnitTimer.next(timer); });
897
904
  }
898
905
  else {
899
- timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.current) }, options));
906
+ timer.stack.push(Object.assign({ snapshot: Unit.snapshot(Unit.currentUnit) }, options));
900
907
  }
901
908
  }
902
909
  static next(timer) {
903
910
  if (timer.stack.length > 0) {
904
- timer.unit = new Unit(Unit.current, UnitTimer.Component, timer.stack.shift());
911
+ timer.unit = new Unit(Unit.currentUnit, UnitTimer.Component, timer.stack.shift());
905
912
  timer.unit.on('finalize', () => { UnitTimer.next(timer); });
906
913
  }
907
914
  }
@@ -928,10 +935,10 @@ class UnitTimer {
928
935
  }
929
936
 
930
937
  const xnew$1 = Object.assign(function (...args) {
931
- if (Unit.root === undefined) {
938
+ if (Unit.rootUnit === undefined) {
932
939
  Unit.reset();
933
940
  }
934
- return new Unit(Unit.current, ...args);
941
+ return new Unit(Unit.currentUnit, ...args);
935
942
  }, {
936
943
  /**
937
944
  * Creates a nested HTML/SVG element within the current component
@@ -944,7 +951,7 @@ const xnew$1 = Object.assign(function (...args) {
944
951
  */
945
952
  nest(tag) {
946
953
  try {
947
- return Unit.nest(Unit.current, tag);
954
+ return Unit.nest(Unit.currentUnit, tag);
948
955
  }
949
956
  catch (error) {
950
957
  console.error('xnew.nest(tag: string): ', error);
@@ -962,7 +969,7 @@ const xnew$1 = Object.assign(function (...args) {
962
969
  */
963
970
  extend(component, props) {
964
971
  try {
965
- return Unit.extend(Unit.current, component, props);
972
+ return Unit.extend(Unit.currentUnit, component, props);
966
973
  }
967
974
  catch (error) {
968
975
  console.error('xnew.extend(component: Function, props?: Object): ', error);
@@ -983,7 +990,7 @@ const xnew$1 = Object.assign(function (...args) {
983
990
  */
984
991
  context(key, value = undefined) {
985
992
  try {
986
- return Unit.context(Unit.current, key, value);
993
+ return Unit.context(Unit.currentUnit, key, value);
987
994
  }
988
995
  catch (error) {
989
996
  console.error('xnew.context(key: string, value?: any): ', error);
@@ -999,9 +1006,9 @@ const xnew$1 = Object.assign(function (...args) {
999
1006
  */
1000
1007
  promise(promise) {
1001
1008
  try {
1002
- const component = Unit.current._.currentComponent;
1003
- Unit.current._.promises.push(new UnitPromise(promise, component));
1004
- return Unit.current._.promises[Unit.current._.promises.length - 1];
1009
+ const component = Unit.currentUnit._.currentComponent;
1010
+ Unit.currentUnit._.promises.push(new UnitPromise(promise, component));
1011
+ return Unit.currentUnit._.promises[Unit.currentUnit._.promises.length - 1];
1005
1012
  }
1006
1013
  catch (error) {
1007
1014
  console.error('xnew.promise(promise: Promise<any>): ', error);
@@ -1017,8 +1024,8 @@ const xnew$1 = Object.assign(function (...args) {
1017
1024
  */
1018
1025
  then(callback) {
1019
1026
  try {
1020
- const component = Unit.current._.currentComponent;
1021
- const promises = Unit.current._.promises;
1027
+ const component = Unit.currentUnit._.currentComponent;
1028
+ const promises = Unit.currentUnit._.promises;
1022
1029
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1023
1030
  .then((results) => {
1024
1031
  callback(results.filter((_result, index) => promises[index].component !== null && promises[index].component === component));
@@ -1038,7 +1045,7 @@ const xnew$1 = Object.assign(function (...args) {
1038
1045
  */
1039
1046
  catch(callback) {
1040
1047
  try {
1041
- const promises = Unit.current._.promises;
1048
+ const promises = Unit.currentUnit._.promises;
1042
1049
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1043
1050
  .catch(callback);
1044
1051
  }
@@ -1056,7 +1063,7 @@ const xnew$1 = Object.assign(function (...args) {
1056
1063
  */
1057
1064
  finally(callback) {
1058
1065
  try {
1059
- const promises = Unit.current._.promises;
1066
+ const promises = Unit.currentUnit._.promises;
1060
1067
  return new UnitPromise(Promise.all(promises.map(p => p.promise)), null)
1061
1068
  .finally(callback);
1062
1069
  }
@@ -1075,7 +1082,7 @@ const xnew$1 = Object.assign(function (...args) {
1075
1082
  * }), 1000)
1076
1083
  */
1077
1084
  scope(callback) {
1078
- const snapshot = Unit.snapshot(Unit.current);
1085
+ const snapshot = Unit.snapshot(Unit.currentUnit);
1079
1086
  return (...args) => Unit.scope(snapshot, callback, ...args);
1080
1087
  },
1081
1088
  /**
@@ -1146,7 +1153,7 @@ const xnew$1 = Object.assign(function (...args) {
1146
1153
  return new UnitTimer({ transition, duration, easing, iterations: 1 });
1147
1154
  },
1148
1155
  protect() {
1149
- Unit.current._.protected = true;
1156
+ Unit.currentUnit._.protected = true;
1150
1157
  }
1151
1158
  });
1152
1159
 
@@ -1181,12 +1188,12 @@ function AccordionFrame(frame, { open = false, duration = 200, easing = 'ease' }
1181
1188
  }
1182
1189
  };
1183
1190
  }
1184
- function AccordionHeader(header, {} = {}) {
1191
+ function AccordionHeader(unit, {} = {}) {
1185
1192
  const internal = xnew$1.context('xnew.accordionframe');
1186
1193
  xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
1187
- header.on('click', () => internal.frame.toggle());
1194
+ unit.on('click', () => internal.frame.toggle());
1188
1195
  }
1189
- function AccordionBullet(bullet, { type = 'arrow' } = {}) {
1196
+ function AccordionBullet(unit, { type = 'arrow' } = {}) {
1190
1197
  const internal = xnew$1.context('xnew.accordionframe');
1191
1198
  xnew$1.nest('<div style="display:inline-block; position: relative; width: 0.55em; margin: 0 0.3em;">');
1192
1199
  if (type === 'arrow') {
@@ -1207,12 +1214,12 @@ function AccordionBullet(bullet, { type = 'arrow' } = {}) {
1207
1214
  });
1208
1215
  }
1209
1216
  }
1210
- function AccordionContent(content, {} = {}) {
1217
+ function AccordionContent(unit, {} = {}) {
1211
1218
  const internal = xnew$1.context('xnew.accordionframe');
1212
1219
  xnew$1.nest(`<div style="display: ${internal.open ? 'block' : 'none'};">`);
1213
1220
  xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
1214
1221
  internal.on('-transition', ({ rate }) => {
1215
- content.transition({ element: content.element, rate });
1222
+ unit.transition({ element: unit.element, rate });
1216
1223
  });
1217
1224
  return {
1218
1225
  transition({ element, rate }) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mulsense/xnew",
3
- "description": "JavaScript Library for Component-Oriented Programming.",
3
+ "description": "JavaScript / TypeScript library for component-oriented programming.",
4
4
  "keywords": [
5
5
  "Component-Oriented Programming"
6
6
  ],
7
- "version": "0.4.0",
7
+ "version": "0.4.1",
8
8
  "main": "dist/xnew.js",
9
9
  "module": "dist/xnew.mjs",
10
10
  "types": "dist/xnew.d.ts",
@@ -29,6 +29,11 @@
29
29
  "import": "./dist/addons/xrapier2d.mjs",
30
30
  "require": "./dist/addons/xrapier2d.js"
31
31
  },
32
+ "./addons/xrapier3d": {
33
+ "types": "./dist/addons/xrapier3d.d.ts",
34
+ "import": "./dist/addons/xrapier3d.mjs",
35
+ "require": "./dist/addons/xrapier3d.js"
36
+ },
32
37
  "./addons/xthree": {
33
38
  "types": "./dist/addons/xthree.d.ts",
34
39
  "import": "./dist/addons/xthree.mjs",
@@ -53,9 +58,7 @@
53
58
  "scripts": {
54
59
  "test": "jest",
55
60
  "build": "npx rollup --config rollup.config.js --bundleConfigAsCjs",
56
- "dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs",
57
- "build:addons": "npx rollup --config rollup.addons.config.js --bundleConfigAsCjs",
58
- "dev:addons": "npx rollup --config rollup.addons.config.js --watch --bundleConfigAsCjs"
61
+ "dev": "npx rollup --config rollup.config.js --watch --bundleConfigAsCjs"
59
62
  },
60
63
  "devDependencies": {
61
64
  "@babel/core": "^7.26.0",
@@ -72,7 +75,6 @@
72
75
  "jest": "^29.7.0",
73
76
  "jest-environment-jsdom": "^29.7.0",
74
77
  "matter-js": "^0.20.0",
75
- "onchange": "^7.1.0",
76
78
  "pixi.js": "^8.9.2",
77
79
  "rollup": "^3.3.0",
78
80
  "rollup-plugin-dts": "^6.2.1",